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
the var
declaration is missing with the default function parameters scope
#10798
Comments
Hey @guox191! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly. If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite." |
I'm trying to research and solve it |
I think that I've found the reason:
@nicolo-ribaudo I have a question here (cause, for now, I'm not so familiar with babel internals): Thanks |
This code, which is passed as a parameter to |
@smelukov Looking into the code
and
I think the timing of registering declaration is incorrect. While
it is actually executed before the We can delay the timing of I composed a unit test when digging this issue, you may work from this branch: https://github.com/JLHwung/babel/tree/add-test-10798 |
@homobel Thanks for the reproduction case! Yes it is the same issue. |
@smelukov Are you still working on this issue? If you have any questions about developing a fix, feel free to ask in |
Tried on this pr #11158, and got this which should be right: function test() {
var func = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {
var a = 1;
console.log(a);
};
return function () {
var previous = 0;
}();
}
; |
@nicolo-ribaudo @JLHwung Unfortunately #11158 fix not resolved issue with default parameter with "this"(7.9.6) I've mentioned above.
Produces:
With same "_this is not defined" error. I'm not sure about approaches here used but I've checked example on playground with only @babel/plugin-transform-classes enabled and it produces also invalid code(same error):
|
Bug Report
Current Behavior
Playground:
https://babeljs.io/repl#?browsers=&build=&builtIns=false&spec=false&loose=false&code_lz=GYVwdgxgLglg9mABFApgZygClJRBeRTASnwD5EBvAKEUQDcBDAJ0Qf0QEYBuGxCBNHAA2KAHRC4Ac0wMiPAL4lqtRiwAOTFHXgg07AAwKuQA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=es2015&prettier=false&targets=&version=7.7.4&externalPlugins=
Input Code
Translate these with es2015 presets, the result is:
We can see that the generated function returns a closure, and the various
previous
is not declared in the closure.in strict mode, we will get the exception:
Uncaught ReferenceError: previous is not defined
Expected behavior/code
The
var
expression won't be removed.Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)
Babel playground with es2015 preset config.
Additional context/Screenshots
The text was updated successfully, but these errors were encountered: