Skip to content

Commit d27d10c

Browse files
committed
Merge pull request microsoft#6884 from Microsoft/emitModulesInLooseMode
Add flag to emit modules in loose mode
2 parents 99fdbc0 + 6f804e4 commit d27d10c

24 files changed

Lines changed: 158 additions & 20 deletions

src/compiler/commandLineParser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@ namespace ts {
320320
name: "allowSyntheticDefaultImports",
321321
type: "boolean",
322322
description: Diagnostics.Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking
323+
},
324+
{
325+
name: "noImplicitUseStrict",
326+
type: "boolean",
327+
description: Diagnostics.Do_not_emit_use_strict_directives_in_module_output
323328
}
324329
];
325330

src/compiler/diagnosticMessages.json

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
1+
{
22
"Unterminated string literal.": {
33
"category": "Error",
44
"code": 1002
@@ -2187,6 +2187,7 @@
21872187
"category": "Error",
21882188
"code": 5062
21892189
},
2190+
21902191
"Concatenate and emit output to single file.": {
21912192
"category": "Message",
21922193
"code": 6001
@@ -2231,10 +2232,10 @@
22312232
"category": "Message",
22322233
"code": 6011
22332234
},
2234-
"Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015' (experimental)": {
2235-
"category": "Message",
2236-
"code": 6015
2237-
},
2235+
"Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015' (experimental)": {
2236+
"category": "Message",
2237+
"code": 6015
2238+
},
22382239
"Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'": {
22392240
"category": "Message",
22402241
"code": 6016
@@ -2571,6 +2572,11 @@
25712572
"category": "Message",
25722573
"code": 6111
25732574
},
2575+
"Do not emit 'use strict' directives in module output.": {
2576+
"category": "Message",
2577+
"code": 6112
2578+
},
2579+
25742580
"Variable '{0}' implicitly has an '{1}' type.": {
25752581
"category": "Error",
25762582
"code": 7005
@@ -2757,23 +2763,23 @@
27572763
"code": 17004
27582764
},
27592765
"A constructor cannot contain a 'super' call when its class extends 'null'": {
2760-
"category": "Error",
2761-
"code": 17005
2766+
"category": "Error",
2767+
"code": 17005
27622768
},
27632769
"An unary expression with the '{0}' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.": {
2764-
"category": "Error",
2765-
"code": 17006
2770+
"category": "Error",
2771+
"code": 17006
27662772
},
27672773
"A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.": {
2768-
"category": "Error",
2769-
"code": 17007
2774+
"category": "Error",
2775+
"code": 17007
27702776
},
27712777
"JSX element '{0}' has no corresponding closing tag.": {
2772-
"category": "Error",
2773-
"code": 17008
2778+
"category": "Error",
2779+
"code": 17008
27742780
},
27752781
"'super' must be called before accessing 'this' in the constructor of a derived class.": {
2776-
"category": "Error",
2777-
"code": 17009
2782+
"category": "Error",
2783+
"code": 17009
27782784
}
2779-
}
2785+
}

src/compiler/emitter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7292,7 +7292,7 @@ const _super = (function (geti, seti) {
72927292
write(`], function(${exportFunctionForFile}, ${contextObjectForFile}) {`);
72937293
writeLine();
72947294
increaseIndent();
7295-
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true);
7295+
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ !compilerOptions.noImplicitUseStrict);
72967296
writeLine();
72977297
write(`var __moduleName = ${contextObjectForFile} && ${contextObjectForFile}.id;`);
72987298
writeLine();
@@ -7398,7 +7398,7 @@ const _super = (function (geti, seti) {
73987398
writeModuleName(node, emitRelativePathAsModuleName);
73997399
emitAMDDependencies(node, /*includeNonAmdDependencies*/ true, emitRelativePathAsModuleName);
74007400
increaseIndent();
7401-
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true);
7401+
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/!compilerOptions.noImplicitUseStrict);
74027402
emitExportStarHelper();
74037403
emitCaptureThisForNodeIfNecessary(node);
74047404
emitLinesStartingAt(node.statements, startIndex);
@@ -7410,7 +7410,7 @@ const _super = (function (geti, seti) {
74107410
}
74117411

74127412
function emitCommonJSModule(node: SourceFile) {
7413-
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false, /*ensureUseStrict*/ true);
7413+
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false, /*ensureUseStrict*/ !compilerOptions.noImplicitUseStrict);
74147414
emitEmitHelpers(node);
74157415
collectExternalModuleInfo(node);
74167416
emitExportStarHelper();
@@ -7439,7 +7439,7 @@ const _super = (function (geti, seti) {
74397439
})(`);
74407440
emitAMDFactoryHeader(dependencyNames);
74417441
increaseIndent();
7442-
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true);
7442+
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ !compilerOptions.noImplicitUseStrict);
74437443
emitExportStarHelper();
74447444
emitCaptureThisForNodeIfNecessary(node);
74457445
emitLinesStartingAt(node.statements, startIndex);

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,6 +2423,7 @@ namespace ts {
24232423
traceModuleResolution?: boolean;
24242424
allowSyntheticDefaultImports?: boolean;
24252425
allowJs?: boolean;
2426+
noImplicitUseStrict?: boolean;
24262427
/* @internal */ stripInternal?: boolean;
24272428

24282429
// Skip checking lib.d.ts to help speed up tests.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [noImplicitUseStrict_amd.ts]
2+
3+
export var x = 0;
4+
5+
//// [noImplicitUseStrict_amd.js]
6+
define(["require", "exports"], function (require, exports) {
7+
exports.x = 0;
8+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/compiler/noImplicitUseStrict_amd.ts ===
2+
3+
export var x = 0;
4+
>x : Symbol(x, Decl(noImplicitUseStrict_amd.ts, 1, 10))
5+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== tests/cases/compiler/noImplicitUseStrict_amd.ts ===
2+
3+
export var x = 0;
4+
>x : number
5+
>0 : number
6+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [noImplicitUseStrict_commonjs.ts]
2+
3+
export var x = 0;
4+
5+
//// [noImplicitUseStrict_commonjs.js]
6+
exports.x = 0;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/compiler/noImplicitUseStrict_commonjs.ts ===
2+
3+
export var x = 0;
4+
>x : Symbol(x, Decl(noImplicitUseStrict_commonjs.ts, 1, 10))
5+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== tests/cases/compiler/noImplicitUseStrict_commonjs.ts ===
2+
3+
export var x = 0;
4+
>x : number
5+
>0 : number
6+

0 commit comments

Comments
 (0)