-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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]: Wrong transpilling @babel/[email protected] when destructuring to a new object #16378
Comments
Hey @marionicolas! 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. |
Why do you want to transpile es2015 features, sich as computed keys, but no newer features, such as object spread? I don't think this case matters much, because all browser that supports |
I dont, maybe Im doing something wrong? |
馃捇
How are you using Babel?
Programmatic API (
babel.transform
,babel.parse
)Input code
Using https://unpkg.com/@babel/[email protected]/babel.min.js
<script type="text/babel" data-type="module" data-presets="react"> ....... .....Some react app stuff here .... console.log({...tags,[newTag.current.key]:newTag.current.val}) //This is the important line, the thing here is to construct a new object from tags props adding a new key:value to the new object .... </script>...
(sorry for jQuery use here, its just a test case)
const c = $('script[type="text/babel"]').text()
var js = Babel.transform(c, { presets: ["react","es2015-no-commonjs"] }).code;
$("body").append($('<script type="module">').text(js))
...
This line is transpilled to:
console.log(_defineProperty({}, newTag.current.key, newTag.current.val));
loosing the prev tags object props...
I had to change this line to this in order to be well transpilled:
setTags({...tags,...{[newTag.current.key]:newTag.current.val}}) //Notice that now the new prop is encapsulated in a seconly destructured object, and now this is well interpreted as:
setTags({
...tags,
..._defineProperty({}, newTag.current.key, newTag.current.val)
});
Configuration file name
No response
Configuration
No response
Current and expected behavior
Tested the code widthout transpilling and works well so I supouse it is well formed.
Environment
Chrome Versi贸n 122.0.6261.129 (Build oficial) (64 bits)
Possible solution
No response
Additional context
Sorry if i dont make the ticket well, I just worked around, but think this could be a problem for someon else and too dificult to describe in a search engine.
Thnx in advance.
The text was updated successfully, but these errors were encountered: