Skip to content

Fix per-iteration bindings in for-loop head#27204

Merged
rbuckton merged 1 commit intomasterfrom
fixPerIteration
Sep 27, 2018
Merged

Fix per-iteration bindings in for-loop head#27204
rbuckton merged 1 commit intomasterfrom
fixPerIteration

Conversation

@rbuckton
Copy link
Copy Markdown
Contributor

@rbuckton rbuckton commented Sep 18, 2018

The ES2015 (and later) specification indicates that a fresh "per-iteration environment" is created in a for-loop immediately after the initializer is run, and immediately before the incrementor evaluates. This means that block-scoped variables defined in the initializer of a for loop and captured in the initializer, condition, or incrementor need to have the correct closure environment to align with ES2015 semantics.

Fixes #17632

@rbuckton
Copy link
Copy Markdown
Contributor Author

@weswigham, @sandersn: can you take a look?

}

function shouldConvertPartOfIterationStatement(node: Node) {
return (resolver.getNodeCheckFlags(node) & NodeCheckFlags.ContainsCapturedBlockScopeBinding) !== 0;
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.

I dislike a non-TS transform relying on typechecking information to be correct. Especially since this means that in the presence of a before transformer, it's very possible that we'll fail to convert something which needs to be.

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.

We do this in other places, which is the reason we have original pointers for nodes to begin with.

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.

Geh, you're right. It's actually only a few transforms that can operate without a typechecker available.

@rbuckton rbuckton merged commit 9cf201c into master Sep 27, 2018
@rbuckton rbuckton deleted the fixPerIteration branch September 27, 2018 20:23
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
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.

3 participants