-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Various updates to Babel 7 branch #1958
Conversation
… hasConfig to handle arrays to check babel6 and 7
@@ -225,12 +225,11 @@ class JSPackager extends Packager { | |||
// Add source map url if a map bundle exists | |||
let mapBundle = this.bundle.siblingBundlesMap.get('map'); | |||
if (mapBundle) { | |||
await this.write( |
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.
Discovered a potential bug with template strings in Babel 7. But I think it has already been reported. Feel free to check if anyone is up for it :)
It might have been an issue in the babel config I wrote, not sure.
Codecov Report
@@ Coverage Diff @@
## babel7 #1958 +/- ##
=========================================
Coverage ? 55.54%
=========================================
Files ? 78
Lines ? 5226
Branches ? 0
=========================================
Hits ? 2903
Misses ? 2323
Partials ? 0
Continue to review full report at Codecov.
|
package.json
Outdated
"babel-preset-env": "^1.7.0", | ||
"babel-template": "^6.26.0", | ||
"babel-traverse": "^6.26.0", | ||
"babel-types": "^6.26.0", | ||
"babylon": "^6.17.4", |
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.
remove this too?
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.
Forgot that one, thanks :)
src/transforms/babel.js
Outdated
@@ -203,21 +245,31 @@ async function getBabelRc(asset, isSource) { | |||
|
|||
// If specified as an array, override the config with the one specified | |||
if (Array.isArray(babelify) && babelify[1]) { | |||
return babelify[1]; | |||
return { | |||
version: 6, |
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 guess we should test this the same way as above - it's possible that there could be babel 7 plugins in here too.
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.
Alright, just thought legacy, people won't use that for babel 7. But sure I'll make it check the plugins
} | ||
|
||
function getPluginName(p) { | ||
return Array.isArray(p) ? p[0] : p; | ||
} | ||
|
||
function testPluginArrayForBabelScope(plugins) { | ||
for (let plugin of plugins) { | ||
if (getPluginName(plugin).startsWith('@babel/')) { |
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 babel 7 require the scope or will they automatically add it if you just write env
? If so, then this check won't work.
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.
Babel docs:
You can still use the shorthand way of specifying a preset or plugin. However because of the switch to scoped packages, you still have to specify the @babel/ just like if you had your own preset to add to the config.
So yes it's required, although it's not 100% reliable as third party libraries will still have babel-....
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.
ok
"babel-template": "^6.26.0", | ||
"babel-traverse": "^6.26.0", | ||
"babel-types": "^6.26.0", | ||
"babylon": "^6.17.4", | ||
"babylon-walk": "^1.0.2", |
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.
Should we remove this, or do a PR to their branch to update to @babel/types
instead of babel-types
It might cause issues in certain cases, as babel-types has changed slightly
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.
worth doing some perf testing. babylon-walk was WAY faster than babel-traverse for some cases where we don't need scope tracking and things.
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'm pretty sure it will still be slower, haven't tested it. I did however open up a PR to babylon-walk pugjs/babel-walk#2
I'm probably not gonna be adding any more features to this PR, as it's becoming quite big. (Might open up a new one to figure out the config things) Feel free to merge whenever. (or request changes) |
return babelCore.parse(code, options); | ||
|
||
if (options.babelVersion === 6) { | ||
let babylon = await localRequire('babylon', this.name); |
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.
Why do we still need babylon? I think we should always parse with babel 7 and convert the AST as needed. Our internal plugins will all be using babel 7, and some of them run before custom babel transforms.
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 left it there for plugins that run on ast creation. Not sure if that's really necessary
|
||
asset.ast = babelASTConverter(asset.ast, 6); | ||
|
||
return babelTransform(asset, 7); |
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.
Won't this result in transforming every file twice?
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.
Yes, but it will only run babel 6 transforms on the first run, convert to babel 7 and run the internal config. Thought this was the expected behaviour.
I might have made a mistake though, not entirely sure this is the proper way to do this.
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.
oh I see. yeah that's how it should work.
matches-pattern
file and update references to@babel/types.matchesPattern
Items from #1955's todo list implemented in this PR: