[Bug]: Babel does not throw duplicated __proto__ when followed by a property whose value is an assignment expression
See original GitHub issue💻
- Would you like to work on a fix?
How are you using Babel?
Programmatic API (babel.transform
, babel.parse
)
Input code
({
__proto__: a,
__proto__: a,
a: a = 1
})
Configuration file name
No response
Configuration
N. A.
Current and expected behavior
Currently Babel parses it without errors.
It should throw
Redefinition of __proto__ property.
just like Babel correctly throws in the following example:
({
__proto__: a,
__proto__: a,
})
Environment
REPL
Possible solution
This issue is very similar to https://github.com/babel/babel/issues/10262.
Like how we handle shorthandAssign
we should reset doubleProto
only when it is used correctly.
Additional context
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
babel/6to5 - duplicated code when exporting modules
babel /6to5 - duplicated code when exporting modules ... I'm using Babel to transpile ES6 to ES5 and it works great. The only...
Read more >babel/CHANGELOG.md at main - GitHub
#15106 Do not mark in and instanceof as constant expressions (@nicolo-ribaudo) ... #13951 Throw on duplicate __proto__ props followed by assignment ...
Read more >@babel/plugin-proposal-logical-assignment-operators | Yarn
Transforms logical assignment operators into short-circuited assignments. babel-plugin. readme. babel. The compiler for writing next generation JavaScript.
Read more >babel/plugin-proposal-class-properties
When true , class properties are compiled to use an assignment expression instead of Object.defineProperty . ⚠️ Consider migrating to the top level ......
Read more >Rules - ESLint - Pluggable JavaScript Linter
Disallow expressions where the operation doesn't affect the value ... names to match the name of the variable or property to which they...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@JLHwung Thank you for helping, I’m soon opening a PR.
A doubleProto assignment is an object literal with duplicate
__proto__
key:However, the duplicate
__proto__
key is allowed in destructuring:so we should track such errors in
refExpressionErrors
, and then throw later when we are sure it is a pattern. In this issue, thea = 1
tricks the parser to think__proto__: a, __proto__: a,
has been in a pattern, so we should check how assignment expression is parsed.