Adds the Transform Flags concept for tree transformations#6983
Merged
rbuckton merged 121 commits intotransforms-visitorfrom Mar 18, 2016
Merged
Adds the Transform Flags concept for tree transformations#6983rbuckton merged 121 commits intotransforms-visitorfrom
rbuckton merged 121 commits intotransforms-visitorfrom
Conversation
Contributor
Author
|
Paging for review: @mhegazy, @ahejlsberg, @yuit, @DanielRosenwasser, @RyanCavanaugh, @vladima |
This was referenced Feb 9, 2016
| case SyntaxKind.AbstractKeyword: | ||
| case SyntaxKind.DeclareKeyword: | ||
| case SyntaxKind.AsyncKeyword: | ||
| case SyntaxKind.ConstKeyword: |
Member
There was a problem hiding this comment.
Does this trigger false positives for const x = ... variable declarations?
Contributor
Author
There was a problem hiding this comment.
No, we don't treat const as a modifier for variable declarations.
Contributor
There was a problem hiding this comment.
how is 'const' has flag of AssertTypeScript should it be under es6?
Contributor
Author
There was a problem hiding this comment.
The only ES6 const is for VariableDeclarationList, which is not stored as a modifier. The only time const is a Modifier is for a const enum, which is TypeScript only.
Adds the Module transformers
Adds the ES6 transformer
Adds the ES7 transformer
Adds the JSX transformer
Adds the TypeScript transformer
Adds a simplified pretty printer for tree transformations
Adds the transformFiles API for tree transformations
rbuckton
added a commit
that referenced
this pull request
Mar 18, 2016
Adds the Transform Flags concept for tree transformations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To ensure tree transformations in the TypeScript compiler are efficient, we compute information about various required transformations for each node. Transform flags are aggregated in a bottom-up fashion, so that we already have information about a node's subtree when we compute the transform flags for the node. These transform flags are initially computed during the bind phase of the compiler, as at that point we guarantee a full walk of the tree.
The values in the
TransformFlagsenum fall into several categories:computeTransformFlagsForNodefunction inbinder.ts.As a result, the
Nodeinterface is extended to include two additional properties:transformFlags- Contains theTransformFlagsthat pertain to this specific node.excludeTransformFlags- Contains a bitmask ofTransformFlagsthat should be excluded from this node'stransformFlagswhen aggregating the transform flags of a subtree containing this node.The binder is modified to compute the transform flags for each node as it walks the tree. As a performance optimization, we skip transform flag aggregation for ambient nodes, type nodes, and declaration files.
Each transformation phase will likely introduce new nodes. As a result, the
visitNodeandvisitNodesfunctions invisitor.tsperform supplemental aggregation of transform flags to ensure successive transformation phases have the requisite information to perform additional transformations.For example, it is possible that during the transformation from TypeScript to ES6 we may introduce an arrow function a for more idiomatic ES6 emit. This may then result in a new
thiscapture which we would then need to know about during the next transformation. Rather than send the new tree through another pass of the checker, we will instead leverage theTransformFlags.ContainsLexicalThisandTransformFlags.ContainsCapturedLexicalThisflags to determine whether we need further transformation.These flags will enable us to have more efficient transformers in the long term, that can make decisions about whether to continue to walk a subtree based on querying these flags. The following example builds on the one found in #6892:
Related Pull Requests: