Skip to content

[Release 2.1] fix11806 omit use strict #12134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
8 changes: 8 additions & 0 deletions tests/baselines/reference/alwaysStrictModule3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//// [alwaysStrictModule3.ts]

// module ES2015
export const a = 1;

//// [alwaysStrictModule3.js]
// module ES2015
export var a = 1;
6 changes: 6 additions & 0 deletions tests/baselines/reference/alwaysStrictModule3.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
=== tests/cases/compiler/alwaysStrictModule3.ts ===

// module ES2015
export const a = 1;
>a : Symbol(a, Decl(alwaysStrictModule3.ts, 2, 12))

7 changes: 7 additions & 0 deletions tests/baselines/reference/alwaysStrictModule3.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=== tests/cases/compiler/alwaysStrictModule3.ts ===

// module ES2015
export const a = 1;
>a : 1
>1 : 1

9 changes: 9 additions & 0 deletions tests/baselines/reference/alwaysStrictModule4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//// [alwaysStrictModule4.ts]

// Module commonjs
export const a = 1

//// [alwaysStrictModule4.js]
"use strict";
// Module commonjs
exports.a = 1;
6 changes: 6 additions & 0 deletions tests/baselines/reference/alwaysStrictModule4.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
=== tests/cases/compiler/alwaysStrictModule4.ts ===

// Module commonjs
export const a = 1
>a : Symbol(a, Decl(alwaysStrictModule4.ts, 2, 12))

7 changes: 7 additions & 0 deletions tests/baselines/reference/alwaysStrictModule4.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=== tests/cases/compiler/alwaysStrictModule4.ts ===

// Module commonjs
export const a = 1
>a : 1
>1 : 1

8 changes: 8 additions & 0 deletions tests/baselines/reference/alwaysStrictModule5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//// [alwaysStrictModule5.ts]

// Targeting ES6
export const a = 1;

//// [alwaysStrictModule5.js]
// Targeting ES6
export const a = 1;
6 changes: 6 additions & 0 deletions tests/baselines/reference/alwaysStrictModule5.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
=== tests/cases/compiler/alwaysStrictModule5.ts ===

// Targeting ES6
export const a = 1;
>a : Symbol(a, Decl(alwaysStrictModule5.ts, 2, 12))

7 changes: 7 additions & 0 deletions tests/baselines/reference/alwaysStrictModule5.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=== tests/cases/compiler/alwaysStrictModule5.ts ===

// Targeting ES6
export const a = 1;
>a : 1
>1 : 1

9 changes: 9 additions & 0 deletions tests/baselines/reference/alwaysStrictModule6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//// [alwaysStrictModule6.ts]

// Targeting ES5
export const a = 1;

//// [alwaysStrictModule6.js]
"use strict";
// Targeting ES5
exports.a = 1;
6 changes: 6 additions & 0 deletions tests/baselines/reference/alwaysStrictModule6.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
=== tests/cases/compiler/alwaysStrictModule6.ts ===

// Targeting ES5
export const a = 1;
>a : Symbol(a, Decl(alwaysStrictModule6.ts, 2, 12))

7 changes: 7 additions & 0 deletions tests/baselines/reference/alwaysStrictModule6.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=== tests/cases/compiler/alwaysStrictModule6.ts ===

// Targeting ES5
export const a = 1;
>a : 1
>1 : 1

5 changes: 5 additions & 0 deletions tests/cases/compiler/alwaysStrictModule3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @alwaysStrict: true
// @module: es2015

// module ES2015
export const a = 1;
5 changes: 5 additions & 0 deletions tests/cases/compiler/alwaysStrictModule4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @alwaysStrict: true
// @module: commonjs

// Module commonjs
export const a = 1
5 changes: 5 additions & 0 deletions tests/cases/compiler/alwaysStrictModule5.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @alwaysStrict: true
// @target: es6

// Targeting ES6
export const a = 1;
5 changes: 5 additions & 0 deletions tests/cases/compiler/alwaysStrictModule6.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @alwaysStrict: true
// @target: es5

// Targeting ES5
export const a = 1;