Skip to content

Commit 0619eb0

Browse files
committed
Merge pull request #6944 from Microsoft/portNoImplicitStrictTo1.8
Port noImplicitStrict to release-1.8
2 parents 0e6102a + 622f469 commit 0619eb0

24 files changed

+157
-20
lines changed

src/compiler/commandLineParser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,11 @@ namespace ts {
294294
name: "allowJs",
295295
type: "boolean",
296296
description: Diagnostics.Allow_javascript_files_to_be_compiled
297+
},
298+
{
299+
name: "noImplicitUseStrict",
300+
type: "boolean",
301+
description: Diagnostics.Do_not_emit_use_strict_directives_in_module_output
297302
}
298303
];
299304

src/compiler/diagnosticMessages.json

Lines changed: 21 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
@@ -2171,6 +2171,7 @@
21712171
"category": "Error",
21722172
"code": 5059
21732173
},
2174+
21742175

21752176
"Concatenate and emit output to single file.": {
21762177
"category": "Message",
@@ -2216,10 +2217,10 @@
22162217
"category": "Message",
22172218
"code": 6011
22182219
},
2219-
"Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015' (experimental)": {
2220-
"category": "Message",
2221-
"code": 6015
2222-
},
2220+
"Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015' (experimental)": {
2221+
"category": "Message",
2222+
"code": 6015
2223+
},
22232224
"Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'": {
22242225
"category": "Message",
22252226
"code": 6016
@@ -2445,6 +2446,10 @@
24452446
"category": "Message",
24462447
"code": 6084
24472448
},
2449+
"Do not emit 'use strict' directives in module output.": {
2450+
"category": "Message",
2451+
"code": 6112
2452+
},
24482453

24492454
"Variable '{0}' implicitly has an '{1}' type.": {
24502455
"category": "Error",
@@ -2632,23 +2637,23 @@
26322637
"code": 17004
26332638
},
26342639
"A constructor cannot contain a 'super' call when its class extends 'null'": {
2635-
"category": "Error",
2636-
"code": 17005
2640+
"category": "Error",
2641+
"code": 17005
26372642
},
26382643
"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.": {
2639-
"category": "Error",
2640-
"code": 17006
2644+
"category": "Error",
2645+
"code": 17006
26412646
},
26422647
"A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.": {
2643-
"category": "Error",
2644-
"code": 17007
2648+
"category": "Error",
2649+
"code": 17007
26452650
},
26462651
"JSX element '{0}' has no corresponding closing tag.": {
2647-
"category": "Error",
2648-
"code": 17008
2652+
"category": "Error",
2653+
"code": 17008
26492654
},
26502655
"'super' must be called before accessing 'this' in the constructor of a derived class.": {
2651-
"category": "Error",
2652-
"code": 17009
2656+
"category": "Error",
2657+
"code": 17009
26532658
}
2654-
}
2659+
}

src/compiler/emitter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7268,7 +7268,7 @@ const _super = (function (geti, seti) {
72687268
write(`], function(${exportFunctionForFile}, ${contextObjectForFile}) {`);
72697269
writeLine();
72707270
increaseIndent();
7271-
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true);
7271+
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ !compilerOptions.noImplicitUseStrict);
72727272
writeLine();
72737273
write(`var __moduleName = ${contextObjectForFile} && ${contextObjectForFile}.id;`);
72747274
writeLine();
@@ -7374,7 +7374,7 @@ const _super = (function (geti, seti) {
73747374
writeModuleName(node, emitRelativePathAsModuleName);
73757375
emitAMDDependencies(node, /*includeNonAmdDependencies*/ true, emitRelativePathAsModuleName);
73767376
increaseIndent();
7377-
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true);
7377+
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/!compilerOptions.noImplicitUseStrict);
73787378
emitExportStarHelper();
73797379
emitCaptureThisForNodeIfNecessary(node);
73807380
emitLinesStartingAt(node.statements, startIndex);
@@ -7386,7 +7386,7 @@ const _super = (function (geti, seti) {
73867386
}
73877387

73887388
function emitCommonJSModule(node: SourceFile) {
7389-
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false, /*ensureUseStrict*/ true);
7389+
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false, /*ensureUseStrict*/ !compilerOptions.noImplicitUseStrict);
73907390
emitEmitHelpers(node);
73917391
collectExternalModuleInfo(node);
73927392
emitExportStarHelper();
@@ -7415,7 +7415,7 @@ const _super = (function (geti, seti) {
74157415
})(`);
74167416
emitAMDFactoryHeader(dependencyNames);
74177417
increaseIndent();
7418-
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true);
7418+
const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ !compilerOptions.noImplicitUseStrict);
74197419
emitExportStarHelper();
74207420
emitCaptureThisForNodeIfNecessary(node);
74217421
emitLinesStartingAt(node.statements, startIndex);

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,6 +2435,7 @@ namespace ts {
24352435
forceConsistentCasingInFileNames?: boolean;
24362436
allowSyntheticDefaultImports?: boolean;
24372437
allowJs?: boolean;
2438+
noImplicitUseStrict?: boolean;
24382439
/* @internal */ stripInternal?: boolean;
24392440

24402441
// 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)