-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Feature - scope babel 7 support #252
Conversation
It seems I have a bug with this PR. Your I worked around by modifying the following line: return function (filename) {
var extname = path.extname(filename)
if (extensions.indexOf(function (ext) {return ext === extname}) > -1) {
return stream.PassThrough();
}
var _opts = sourceMapsAbsolute
? Object.assign({sourceFileName: filename}, opts)
: Object.assign({}, opts); // <-- this was previously `opts`
return new Babelify(filename, _opts);
}; |
Seeing the same problem as @tex0l . Another, cleaner option would be to modify the constructor as such : function Babelify(filename, opts) {
opts = Object.assign({}, opts); // <-- adding this
if (!(this instanceof Babelify)) {
return Babelify.configure(opts)(filename);
}
stream.Transform.call(this);
this._data = "";
this._filename = filename;
this._babel = opts.babel || babel
delete opts.babel
this._opts = Object.assign({filename: filename}, opts);
} so that the function does not have side-effects on its arguments, which is very ugly |
@tex0l @arantes555 , missed that - I only work with single file. I've added the bugfix, can you check it out? |
@noygal works for me :) thanks! |
package.json
Outdated
@@ -16,6 +16,8 @@ | |||
"babel-core": "6 || 7 || ^7.0.0-alpha || ^7.0.0-beta || ^7.0.0-rc" |
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.
It seems like if we're going to update this for 7.x, we might as well change this to @babel/core
directly as a breaking change.
```js | ||
browserify().transform("babelify", { | ||
presets: ["@babel/preset-env"], | ||
babel: require("@babel/core") |
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 think this is a good idea. If we're going to support 7, we should just add it directly. The utilities that were removed can easily be implemented inside this module on their own, if we actually want to support them.
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 didn't want to break the current implementation as there were breaking changes in babel 7 (everything became scope), maybe we can add it to the next major version.
index.js
Outdated
@@ -23,7 +27,7 @@ Babelify.prototype._transform = function (buf, enc, callback) { | |||
|
|||
Babelify.prototype._flush = function (callback) { | |||
try { | |||
var result = babel.transform(this._data, this._opts); | |||
var result = this._babel.transform(this._data, this._opts) |
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.
It'd be great to update this to use the callback version that landed in beta.32
. e.g.
babel.transform(this._data, this._opts, (err, result) => {
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.
nice, but will need to check babel version before using the new API, I'll update it and run the tests.
index.js
Outdated
@@ -62,7 +68,8 @@ Babelify.configure = function (opts) { | |||
if (opts.presets && opts.presets._) opts.presets = opts.presets._; | |||
|
|||
return function (filename) { | |||
if (!babel.util.canCompile(filename, extensions)) { | |||
var extname = path.extname(filename) | |||
if (extensions.indexOf(function (ext) {return ext === extname}) > -1) { |
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.
Is this intended to be .filter
?
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 believe it should be extensions.includes(path.extname(filename))
, right?
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.
Node 4 is still supported by Babel, so we'll want to stick to features that work there.
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.
That's what I was just checking...
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.
that why I went with indexOf
, I don't think there's any node/browser version that don't support that.
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.
@noygal except indexOf takes a value, not a function, as argument :/
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.
😳 ...
didn't use for a while now
Can we have this merged yet please? Thank you |
@noygal you need to update e.g. ladjs@a76a30c |
Also need to update the top of the file to use |
Sorry for the super long delay 😅, going to go with #255 instead! Thanks again. |
I've expended the options to support
babel
option, this options apply only to thetransform
function as the other two uses were removed for babel 7,this is not the best approach as we have two separate babel packages running in the package -babel-core
for configuration setup and the optional babel for transform, but I think that the solution would come from a proper babel 7 integration.For the time being, it is a pretty simple solution for early babel 7 adaptors.
Added:
devDependancies
- for testing (@babel/core
,@babel/preset-env
)Update: I've noticed this PR - #244, and removed the
babel-core
dependancies.