You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Functions with shadowed this bindings insert this reference before super which can cause runtime or build errors (T7191) #4162
async function foo(value) {
return value;
}
class Base {}
class Test extends Base {
bar = async () => {
return await foo(this.value);
};
}
Description
EDIT: See @loganfsmyth's comment below for a simpler example
The error I get is: SyntaxError: test.js: 'this' is not allowed before super() (This is an error on an internal node. Probably an internal error).
This goes away if I specify both es2015 and stage-0 as a single pass.
I only ran into this in the first place because I was following the Relay example, which currently specifies those two as separate passes.
This could just be a configuration issue with the Relay example, but the repro seemed sufficiently niche-y that it seemed like it might be interesting.
On closer inspection, I actually can't neatly work around this – the Relay plugin stops working if I try to specify es2015, stage-0, and react as a single pass.
Since pass-per-preset does just what it says, a simplified reproduction case to see the reason for this is:
{presets: ['stage-0']}
with
class Test extends (function(){}) {
bar = async () => {
return await foo(this.value);
};
}
which results in
var Test = class Test extends function () {} {
constructor(...args) {
var _temp,
_this = this;
return _temp = super(...args), this.bar = _asyncToGenerator(function* () {
return yield foo(_this.value);
}), _temp;
}
};
That _this = this line is before super(...args), hence the error.
This is an issue with or without passPerPreset though, since this will still happen if someone were using a preset like es2015-node5 along with stage-0. They won't get a Babel error, but the native class support will error out for the same reason Babel does.
Activity
babel-bot commentedon Mar 8, 2016
On closer inspection, I actually can't neatly work around this – the Relay plugin stops working if I try to specify
es2015,stage-0, andreactas a single pass.babel-bot commentedon Mar 8, 2016
Since pass-per-preset does just what it says, a simplified reproduction case to see the reason for this is:
with
which results in
That
_this = thisline is beforesuper(...args), hence the error.This is an issue with or without
passPerPresetthough, since this will still happen if someone were using a preset likees2015-node5along withstage-0. They won't get a Babel error, but the native class support will error out for the same reason Babel does.babel-bot commentedon Mar 8, 2016
Is a workaround possible? My actual
.babelrccurrently looks like:I tried using
But this didn't work (the Relay plugin didn't get applied).
babel-bot commentedon Mar 13, 2016
#3422