-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
Adds the Transform Flags concept for tree transformations #6983
Conversation
Paging for review: @mhegazy, @ahejlsberg, @yuit, @DanielRosenwasser, @RyanCavanaugh, @vladima |
case SyntaxKind.AbstractKeyword: | ||
case SyntaxKind.DeclareKeyword: | ||
case SyntaxKind.AsyncKeyword: | ||
case SyntaxKind.ConstKeyword: |
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.
Does this trigger false positives for const x = ...
variable declarations?
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.
No, we don't treat const
as a modifier for variable declarations.
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.
how is 'const' has flag of AssertTypeScript
should it be under es6
?
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.
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
Adds the Transform Flags concept for tree transformations
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
TransformFlags
enum fall into several categories:computeTransformFlagsForNode
function inbinder.ts
.As a result, the
Node
interface is extended to include two additional properties:transformFlags
- Contains theTransformFlags
that pertain to this specific node.excludeTransformFlags
- Contains a bitmask ofTransformFlags
that should be excluded from this node'stransformFlags
when 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
visitNode
andvisitNodes
functions invisitor.ts
perform 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
this
capture 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.ContainsLexicalThis
andTransformFlags.ContainsCapturedLexicalThis
flags 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: