Do not emit "use strict" when targeting es6 or higher or module kind is es2015 and the file is external module

This commit is contained in:
Kanchalai Tanglertsampan 2016-11-09 15:30:15 -08:00
parent 34d41de06f
commit afea1105c3

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