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
[Bug]: Omitted spread properties are incorrectly hoisted when using computed properties with template strings #13430
Comments
Hey @tidychips! 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." |
The problem is that in the babel/packages/babel-plugin-transform-destructuring/src/index.js Lines 226 to 243 in 4eda1c8
As this issue shows, it is a wrong approach: we should only do that if we only have literals that do not reference any other variable. The easiest way to do so is probably to add a new variable It also needs to be fixed at
|
@tidychips As a workaround, you can manually extract the computed key: const k = `prefix_${foo}`;
const { [k]: _, ...rest } = obj; Or you can downgrade |
✋ I'll be happy to give a try ^^ |
Ugh, I hate that we called @tony-go: There are some related code locations at:
Be careful that you do not use |
Hi Guys 👋 Thanks a lot for your insights. @jridgewell Can you give me more details about:
I'm not familiar with all terms (deopt) yet ^^ |
Deopt means de-optimize. We currently have an optimization that omitted keys can be hoisted if they're So, essentially: if (allLiteral && !hasTemplateExpression) {
// optimize by hoisting
} else {
// Do nothing, ie, deopt
} |
@lala7573 Do you want to work in this? Ideally we can release a fix in the next patch release. |
@nicolo-ribaudo |
If there are only literals (either template or not) we don't need to call |
@nicolo-ribaudo |
Please open a PR, it's easier to review and comment! |
This still needs to be fixed in object-rest-spread: babel/packages/babel-plugin-proposal-object-rest-spread/src/index.js Lines 103 to 104 in 4eda1c8
|
💻
How are you using Babel?
babel-loader (webpack)
Input code
REPL Link
Configuration file name
No response
Configuration
The copied config is a bit over complicated to reproduce the issue. The repl link above has a minimal config that highlights the issue better.
Current and expected behavior
Current Behavior: The change made in #13384 will incorrectly hoist omitted template string properties to the top level scope of the file when they contain interpolations using locally scoped variables. This causes the file to throw a
ReferenceError
when imported because the variable is not defined in the top level scope.Expected Behavior: Do not hoist omitted keys when they depend on locally scoped variables
Environment
Possible solution
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: