Merge pull request #12134 from Microsoft/release-2.1_fix11806_omitUseStrict

[Release 2.1] fix11806 omit use strict
This commit is contained in:
Yui 2016-11-09 17:12:42 -08:00 committed by GitHub
commit 6ba4b87dc7
17 changed files with 111 additions and 1 deletions

View file

@ -457,7 +457,11 @@ namespace ts {
currentSourceFile = node;
// ensure "use strict" is emitted in all scenarios in alwaysStrict mode
if (compilerOptions.alwaysStrict) {
// There is no need to emit "use strict" in the following cases:
// 1. The file is an external module and target is es2015 or higher
// or 2. The file is an external module and module-kind is es6 or es2015 as such value is not allowed when targeting es5 or lower
if (compilerOptions.alwaysStrict &&
!(isExternalModule(node) && (compilerOptions.target >= ScriptTarget.ES2015 || compilerOptions.module === ModuleKind.ES2015))) {
node = ensureUseStrict(node);
}

View file

@ -0,0 +1,8 @@
//// [alwaysStrictModule3.ts]
// module ES2015
export const a = 1;
//// [alwaysStrictModule3.js]
// module ES2015
export var a = 1;

View file

@ -0,0 +1,6 @@
=== tests/cases/compiler/alwaysStrictModule3.ts ===
// module ES2015
export const a = 1;
>a : Symbol(a, Decl(alwaysStrictModule3.ts, 2, 12))

View file

@ -0,0 +1,7 @@
=== tests/cases/compiler/alwaysStrictModule3.ts ===
// module ES2015
export const a = 1;
>a : 1
>1 : 1

View file

@ -0,0 +1,9 @@
//// [alwaysStrictModule4.ts]
// Module commonjs
export const a = 1
//// [alwaysStrictModule4.js]
"use strict";
// Module commonjs
exports.a = 1;

View file

@ -0,0 +1,6 @@
=== tests/cases/compiler/alwaysStrictModule4.ts ===
// Module commonjs
export const a = 1
>a : Symbol(a, Decl(alwaysStrictModule4.ts, 2, 12))

View file

@ -0,0 +1,7 @@
=== tests/cases/compiler/alwaysStrictModule4.ts ===
// Module commonjs
export const a = 1
>a : 1
>1 : 1

View file

@ -0,0 +1,8 @@
//// [alwaysStrictModule5.ts]
// Targeting ES6
export const a = 1;
//// [alwaysStrictModule5.js]
// Targeting ES6
export const a = 1;

View file

@ -0,0 +1,6 @@
=== tests/cases/compiler/alwaysStrictModule5.ts ===
// Targeting ES6
export const a = 1;
>a : Symbol(a, Decl(alwaysStrictModule5.ts, 2, 12))

View file

@ -0,0 +1,7 @@
=== tests/cases/compiler/alwaysStrictModule5.ts ===
// Targeting ES6
export const a = 1;
>a : 1
>1 : 1

View file

@ -0,0 +1,9 @@
//// [alwaysStrictModule6.ts]
// Targeting ES5
export const a = 1;
//// [alwaysStrictModule6.js]
"use strict";
// Targeting ES5
exports.a = 1;

View file

@ -0,0 +1,6 @@
=== tests/cases/compiler/alwaysStrictModule6.ts ===
// Targeting ES5
export const a = 1;
>a : Symbol(a, Decl(alwaysStrictModule6.ts, 2, 12))

View file

@ -0,0 +1,7 @@
=== tests/cases/compiler/alwaysStrictModule6.ts ===
// Targeting ES5
export const a = 1;
>a : 1
>1 : 1

View file

@ -0,0 +1,5 @@
// @alwaysStrict: true
// @module: es2015
// module ES2015
export const a = 1;

View file

@ -0,0 +1,5 @@
// @alwaysStrict: true
// @module: commonjs
// Module commonjs
export const a = 1

View file

@ -0,0 +1,5 @@
// @alwaysStrict: true
// @target: es6
// Targeting ES6
export const a = 1;

View file

@ -0,0 +1,5 @@
// @alwaysStrict: true
// @target: es5
// Targeting ES5
export const a = 1;