Repository navigation
Fix #10758 Add compiler option to parse in strict mode - #11473
Conversation
* add compiler option alwaysStrict * compile in strict mode when option is set * emit "use strict"
|
Hi Sławomir Sadziak (@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.
alwaysStrict overrides noImplicitUseStrict
There was a problem hiding this comment.
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
Ryan Cavanaugh (RyanCavanaugh)
left a comment
There was a problem hiding this comment.
Looking good overall, just a few minor changes.
| export function ensureUseStrict(node: SourceFile): SourceFile { | ||
| let foundUseStrict = false; | ||
| let statementOffset = 0; | ||
| const numStatements = node.statements.length; |
There was a problem hiding this comment.
Why isn't this a for or for / of loop?
There was a problem hiding this comment.
Seems like you were planning to use statementOffset later and then didn't
There was a problem hiding this comment.
It's now updated in the next commit
| function visitSourceFile(node: SourceFile) { | ||
| currentSourceFile = node; | ||
|
|
||
| // ensure "use strict"" is emitted in all scenarios in alwaysStrict mode |
There was a problem hiding this comment.
nit: extra quote
There was a problem hiding this comment.
Fixed
|
Ryan Cavanaugh (@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