-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fix #10758 Add compiler option to parse in strict mode #11473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
* add compiler option alwaysStrict * compile in strict mode when option is set * emit "use strict"
Hi @slawomir, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
TTYL, MSBOT; |
} | ||
|
||
//// [alwaysStrictNoImplicitUseStrict.js] | ||
"use strict"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alwaysStrict overrides noImplicitUseStrict
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a check in program.ts::verifyCompilerOptions to flag teh use of --noImplicitUseStrict
and --alwaysStrict
as invalid combination.. so somthing like
if (options.noImplicitUseStrict && options.alwaysStrict) {
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noImplicitUseStrict ", "alwaysStrict"));
}
* add unit test to ensure "use strict" is not added twice * fix code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good overall, just a few minor changes.
let foundUseStrict = false; | ||
let statementOffset = 0; | ||
const numStatements = node.statements.length; | ||
while (statementOffset < numStatements) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why isn't this a for
or for / of
loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like you were planning to use statementOffset
later and then didn't
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's now updated in the next commit
@@ -436,6 +436,11 @@ namespace ts { | |||
function visitSourceFile(node: SourceFile) { | |||
currentSourceFile = node; | |||
|
|||
// ensure "use strict"" is emitted in all scenarios in alwaysStrict mode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: extra quote
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
@RyanCavanaugh thanks for analysing. I will send next iteration. |
* fix comment * optimize loop
Looks good. one comment for flagging invalid combinations. |
also can you add a test for |
Fixes #10758