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); }