Skip to content

Fix #10758 Add compiler option to parse in strict mode - #11473

Merged
Mohamed Hegazy (mhegazy) merged 3 commits into
microsoft:masterfrom
slawomir:10758-always-strict
Oct 14, 2016
Merged

Mohamed Hegazy (mhegazy) merged 3 commits into
microsoft:masterfrom
slawomir:10758-always-strict

Conversation

@slawomir

Copy link
Copy Markdown
Contributor

Fixes #10758

  • add compiler option alwaysStrict
  • compile in strict mode when option is set
  • emit "use strict"

 * add compiler option alwaysStrict
 * compile in strict mode when option is set
 * emit "use strict"
@msftclas

Hi Sławomir Sadziak (@slawomir), I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!


It looks like you're a Microsoft contributor (Slawomir Sadziak). If you're full-time, we DON'T require a Contribution License Agreement. If you are a vendor, please DO sign the electronic Contribution License Agreement. It will take 2 minutes and there's no faxing! https://cla.microsoft.com.

TTYL, MSBOT;

}

//// [alwaysStrictNoImplicitUseStrict.js]
"use strict";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alwaysStrict overrides noImplicitUseStrict

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Member

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.

Comment thread src/compiler/factory.ts Outdated
export function ensureUseStrict(node: SourceFile): SourceFile {
let foundUseStrict = false;
let statementOffset = 0;
const numStatements = node.statements.length;

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Contributor Author

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

Comment thread src/compiler/transformers/ts.ts Outdated
function visitSourceFile(node: SourceFile) {
currentSourceFile = node;

// ensure "use strict"" is emitted in all scenarios in alwaysStrict mode

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra quote

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@slawomir

Copy link
Copy Markdown
Contributor Author

Ryan Cavanaugh (@RyanCavanaugh) thanks for analysing. I will send next iteration.

@mhegazy

Copy link
Copy Markdown
Contributor

Looks good. one comment for flagging invalid combinations.

@mhegazy

Copy link
Copy Markdown
Contributor

also can you add a test for --outFile concatenating multiple files.

@mhegazy
Mohamed Hegazy (mhegazy) merged commit 8210634 into microsoft:master Oct 14, 2016
@microsoft Microsoft (microsoft) locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants