From 8210634e8dbc9a1bc41c108b21c19b4cfac4d91c Mon Sep 17 00:00:00 2001 From: Slawomir Sadziak Date: Mon, 10 Oct 2016 23:03:07 +0200 Subject: [PATCH] Fix #10758 Add compiler option to parse in strict mode * fix comment * optimize loop --- src/compiler/factory.ts | 7 ++----- src/compiler/transformers/ts.ts | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 6bf6259c364e8..5a95600d08931 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -2242,19 +2242,16 @@ namespace ts { */ export function ensureUseStrict(node: SourceFile): SourceFile { let foundUseStrict = false; - let statementOffset = 0; - const numStatements = node.statements.length; - while (statementOffset < numStatements) { - const statement = node.statements[statementOffset]; + for (const statement of node.statements) { if (isPrologueDirective(statement)) { if (isUseStrictPrologue(statement as ExpressionStatement)) { foundUseStrict = true; + break; } } else { break; } - statementOffset++; } if (!foundUseStrict) { const statements: Statement[] = []; diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 112f838a3704e..2c146c91bc3ac 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -436,7 +436,7 @@ namespace ts { function visitSourceFile(node: SourceFile) { currentSourceFile = node; - // ensure "use strict"" is emitted in all scenarios in alwaysStrict mode + // ensure "use strict" is emitted in all scenarios in alwaysStrict mode if (compilerOptions.alwaysStrict) { node = ensureUseStrict(node); }