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
Spread operator mismatches native behavior when getter is used #8749
Comments
Hey @Draccoz! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
The same here: {
...attributes,
get fullName() {
return `${this.firstName} ${this.lastName}`.trim()
},
} Will transpile to (pseudo code): Object.assign({}, attributes, {
get fullName() {
return `${this.firstName} ${this.lastName}`.trim()
}
}) so all this.* parameters will be undefined. Works well in browser with direct spread operators. |
Actually I found: About this topic. I'm using a brand new create-react-app... 🤔 EDIT: It was reverted in: #9379, and then a new PR was merged 7 days ago (so unreleased for now): #9384. It should be fixed with the next released. |
Bug Report
Current Behavior
When using object spread on an object with a getter, the function is triggered only once, and the result is copied to the output object.
Input Code
Expected behavior/code
Getter should be created in the output object so it can be triggered on each property access, as it happens with native browser implementation.
Babel Configuration (.babelrc, package.json, cli command)
Anything that compiles to ES5.
Environment
Any
Possible Solution
Use
Object.getOwnPropertyDescriptors(input)
to get a configuration of each input object and in case of getters/setters define them in the output object.Additional context/Screenshots
This bug happens in both Babel and TypeScript, looks to be pretty common.
The text was updated successfully, but these errors were encountered: