Skip to content

Commit 677e45c

Browse files
authored
Dont add "use strict" prologue in json emit (#36380)
* Add test for strict with isolated modules and resolveJson Test for #36372 * Dont add "use strict" prologue in json emit Fixes #36372
1 parent b05dde7 commit 677e45c

5 files changed

+42
-1
lines changed

src/compiler/transformers/module/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ namespace ts {
9191

9292
const statements: Statement[] = [];
9393
const ensureUseStrict = getStrictOptionValue(compilerOptions, "alwaysStrict") || (!compilerOptions.noImplicitUseStrict && isExternalModule(currentSourceFile));
94-
const statementOffset = addPrologue(statements, node.statements, ensureUseStrict, sourceElementVisitor);
94+
const statementOffset = addPrologue(statements, node.statements, ensureUseStrict && !isJsonSourceFile(node), sourceElementVisitor);
9595

9696
if (shouldEmitUnderscoreUnderscoreESModule()) {
9797
append(statements, createUnderscoreUnderscoreESModule());
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [tests/cases/compiler/isolatedModules_resolveJsonModule_strict_outDir_commonJs.ts] ////
2+
3+
//// [a.ts]
4+
import * as j from "./j.json";
5+
6+
//// [j.json]
7+
{}
8+
9+
10+
//// [j.json]
11+
{}
12+
//// [a.js]
13+
"use strict";
14+
exports.__esModule = true;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== /a.ts ===
2+
import * as j from "./j.json";
3+
>j : Symbol(j, Decl(a.ts, 0, 6))
4+
5+
=== /j.json ===
6+
{}
7+
No type information for this code.
8+
No type information for this code.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== /a.ts ===
2+
import * as j from "./j.json";
3+
>j : {}
4+
5+
=== /j.json ===
6+
{}
7+
>{} : {}
8+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @isolatedModules: true
2+
// @resolveJsonModule: true
3+
// @strict: true
4+
// @outDir: /dist
5+
// @module: commonjs
6+
7+
// @Filename: /a.ts
8+
import * as j from "./j.json";
9+
10+
// @Filename: /j.json
11+
{}

0 commit comments

Comments
 (0)