From afea1105c3e3d27ed6a89606a1cd1e2adf059784 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Wed, 9 Nov 2016 15:30:15 -0800 Subject: [PATCH] Do not emit "use strict" when targeting es6 or higher or module kind is es2015 and the file is external module --- src/compiler/transformers/ts.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 925869da385..b7d13af2733 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -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); }