-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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]: Getter should be shadowed by shorthand property #15140
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. |
Currently Babel transform var x =
((_x = {
x: x
}),
(_x2 = "x"),
(_mutatorMap = {}),
(_mutatorMap[_x2] = _mutatorMap[_x2] || {}),
(_mutatorMap[_x2].get = function () {
return 0;
}),
_defineProperty(_x, "x", x),
_defineEnumerableProperties(_x, _mutatorMap),
_x); The getter is setted by Maybe we should transform it into this? // Other helper functions...
function _defineGetter(obj, key, get) {
Object.defineProperty(obj, key, {
get: get,
enumerable: true,
configurable: true
});
return obj;
}
// Add a _defineSetter if setter is used
var x =
((_x = {
x: x
}),
_defineGetter(_x, "x", function () {
return 0;
}),
_defineProperty(_x, "x", x),
_x);
x.x = 1;
console.log(x.x); This can also helps us having the correct order when enumerating properties, for example: var x = { get ["y"]() { return 0; }, x } ;
for(var k in x) console.log(k); Should output |
This can be reproduced using this code: var a = {
get ["x"]() {
return 0;
},
["x"]: 1
}; and with only Using function _defineAccessor(type, obj, key, fn) {
return Object.defineProperty(
obj,
key,
_defineProperty({ enumerable: true, configurable: true }, type, fn)
);
} |
Co-authored-by: Nicolò Ribaudo <[email protected]> Co-authored-by: liuxingbaoyu <[email protected]> Fixes #15140
💻
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
x
's propertyx.x
should be writable in the input code but it is not in the transpiled code.Current behavior
x.x
is not writable:Expected behavior
x.x
is writable: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: