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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] let
to var
allows forward reference (use in definition)
#15150
Comments
Hey @p51lee! 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. |
We don't enable TDZ checks by default, because they increase the code size by a lot and usually they are not needed. However, if you enable the const code = `
let x = x;
`;
const out = babel.transformSync(code, {
configFile: false,
sourceType: "module",
plugins: [
[require("./packages/babel-plugin-transform-block-scoping"), { tdz: true }],
],
});
console.log(out.code); output: function _tdz(name) { throw new ReferenceError(name + " is not defined - temporal dead zone"); }
var x = _tdz("x"); |
Thank you for your response! However, I found two cases that
|
Thank you for the investigation! The tdz option needs a bit of care; I have started working on it so expect improvements in the next weeks :) |
#15164 fixes the |
馃捇
How are you using Babel?
Other (Next.js, Gatsby, vue-cli, ...)
Input code
Configuration file name
No response
Configuration
No response
Current and expected behavior
Changing let to var incurs hoisting so it changes an erroneous code into normal:
$ node output.js # no error
Environment
Reproduction on Babel's own REPL
Possible solution
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: