-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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 transformFiles API for tree transformations #6986
Conversation
Paging for review: @mhegazy, @ahejlsberg, @yuit, @DanielRosenwasser, @RyanCavanaugh, @vladima |
} | ||
} | ||
|
||
function coerceExpression(value: string | number | boolean | Expression): Expression { |
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.
I don't understand the purpose of this one.
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.
I will most likely remove these and inline them where necessary. All of the "coerce" functions are helpers internal to "factory.ts" that allow you to write createParameter("args")
instead of createParameter(createIdentifier("args"))
, etc.
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
The
transformFiles
function will take on some of the responsibilities of the existing emitter, and integrates it with our new visitor pattern.This function takes in an array of
Transformer
callbacks, which have the following signature (found intypes.ts
):The
TransformationContext
is allocated at the start oftransformFiles
, and eachTransformer
is called sequentially with this context to initialize each transformer. The result of each initialization is a callback that will be used to transform eachSourceFile
.The
TransformationContext
provides the following information/capabilities to aTransformer
:While
TransformFlags
provides us the ability to quickly make decisions about whether (and how) to transform a node, there are some transformations that would still require a full walk of the tree. This includes situations such as renaming block-scopedlet
/const
declarations. As we do not want to do a full walk of the tree for every transformation phase, we save these final transformations until the last possible moment before we emit. We can do this by using theidentifierSubstitution
andexpressionSubstitution
hooks provided on theTransformationContext
. The final print phase will then evaluate these substitutions on a just-in-time basis immediately before printing the node.The following example builds on the examples in #6892 and #6983:
Related Pull Requests: