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.

isReferenced is false for the left hand of AssignmentExpressions (revist #2557)

See original GitHub issue

Bug Report

  • [ x ] I’d be open to it if you think this is worth looking into

Current Behavior I apologize if this is already being discussed elsewhere, but I’d like to revisit bug #2557. If I can paraphrase that bug, after traversing the following code:

let x = 0;
let y = 0;

x += 1;
y++;

the x binding would not be considered referenced, while y would.

If I’m understanding the purpose of referenced correctly, I believe we would want these two behaviors (++ and +=) to be consistent with each other.

In the JS Packager Parcel, they use this reference counter in their scope hoisting functionality, which causes incorrect tree shaking behavior for variables in += AssigmentExpressions. Bug.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
mischniccommented, Mar 22, 2020

There is some logic behind this:

// causes binding.constant to be false, is a constantViolation, not a referencePath
x = 2; 

// causes binding.constant to be false, is a constantViolation, not a referencePath
x += 2;

// causes binding.referenced to be true and constant to be false,
// is a referencePath **and** a constantViolation
x++; 

// causes binding.referenced to be true, is a referencePath, not a constantViolation
console.log(x);

Would be great to get some feedback, but I guess this is per design and we’ll fix it in Parcel.

1reaction
nicolo-ribaudocommented, Apr 7, 2022

We have “references” that are “reads”, and “constantViolations” that are “writes”.

Actually, I’m curious how does Babel even rewrite that correctly?

Maybe you are calling replaceWith on both identifiers?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - isReferenced is false for the left hand of ...
isReferenced is false for the left hand of AssignmentExpressions (revist #2557)
Read more >
SyntaxError: invalid assignment left-hand side - MDN Web Docs
The JavaScript exception "invalid assignment left-hand side" occurs when there was an unexpected assignment somewhere.
Read more >
Boolean if statement has Invalid left-hand side in assignment ...
But I get a parsing error saying: Invalid left-hand side in assignment expression. Any ideas where I am going wrong?
Read more >
PEP 572 – Assignment Expressions
Unparenthesized assignment expressions are prohibited at the top level of the right hand side of an assignment statement. Example:.
Read more >
HANDBOOK OF MAGMA FUNCTIONS
resentations of a Lie algebra has been written by Dan Roozemond ... the xi are identifiers, and the right hand side expression must...
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