mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Fix #10758 Add compiler option to parse in strict mode
* fix comment * optimize loop
This commit is contained in:
@@ -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[] = [];
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user