Repository navigation
Reorganize the Babel plugin, add support for non-literal template variables - #44
Merged
developit merged 5 commits intoDec 19, 2018
Merged
Conversation
Collaborator
Author
|
Modified For |
developit
self-requested a review
December 19, 2018 17:16
developit
approved these changes
Dec 19, 2018
Owner
|
I'm going to see if I can run the non-babel tests against the babel version. |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request reorganizes the Babel plugin and adds tests, with the following steps:
treeifythe template is evaluated and converted to a object tree withh(tag, props, ...children) { return { tag, props, children }; }.his intentionally as simple as possible, because there's a not-so-pretty trick:Object.assignis temporarily replaced with our own function that doesn't smush its arguments together, but just returns them as an array. This allows us to simplify props handling and do some optimizations to the output.Object.assignback to the value it was before evaluating the template.transform.In
transformthepropsargument is now either an array (from theObject.assigntrick),nullor an object. If it's an array then it's further processed: sometimes we can get rid of the spread altogether (e.g.Object.assign(foo)can just becomefoo). This allows us also to support non-literal template variables in spreads, e.g.<a ...${foo}>now gets transformed to 'h("a",foo,[])`.When we actually need a spread output, like in
<a b=1 ...${foo}>, the output follows (somewhat) what @babel/preset-react does. There's now a new settinguseBuiltInsthat isfalseby default that has the same meaning as in @babel/preset-react. When the flag is true the output for<a b=1 ...${foo}>ish("a",Object.assign({b:"1"},foo),[]), and if the flag is false then Babel'sextends-helper is included in the output.childMapperis now recursive and a bit simpler, ashtmitself does JSX-style whitespace normalization.