question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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
})

REPL

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

https://github.com/babel/babel/blob/7250d2562be881f9cdc24c6646468e0f3afcaf9d/packages/babel-parser/src/parser/expression.js#L317-L319

we should reset doubleProto only when it is used correctly.

https://github.com/babel/babel/blob/7250d2562be881f9cdc24c6646468e0f3afcaf9d/packages/babel-parser/src/parser/expression.js#L312

Additional context

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
The-x-Theoristcommented, Nov 11, 2021

@JLHwung Thank you for helping, I’m soon opening a PR.

0reactions
JLHwungcommented, Nov 10, 2021

A doubleProto assignment is an object literal with duplicate __proto__ key:

// invalid
({
  __proto__: a,
  __proto__: a,
})

However, the duplicate __proto__ key is allowed in destructuring:

// valid
({
  __proto__: a,
  __proto__: b
}) => {}

so we should track such errors in refExpressionErrors, and then throw later when we are sure it is a pattern. In this issue, the a = 1 tricks the parser to think __proto__: a, __proto__: a, has been in a pattern, so we should check how assignment expression is parsed.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found