Skip to content

Commit

Permalink
Fix microsoft#10758 Add compiler option to parse in strict mode
Browse files Browse the repository at this point in the history
 * fix comment
 * optimize loop
  • Loading branch information
slawomir committed Oct 10, 2016
1 parent ea808f5 commit 8210634
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
7 changes: 2 additions & 5 deletions src/compiler/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 8210634

Please sign in to comment.