Skip to content
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

Join assignment #226

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Join assignment #226

wants to merge 4 commits into from

Conversation

thejh
Copy link
Contributor

@thejh thejh commented Sep 9, 2011

See #223 - basically, this is about joining assignment statements into expressions when appropriate:

a=1;f(2,5,1)
f(2,5,a=1)

return [ this[0], op, walk(lvalue), walk(rvalue) ];
rvalue = walk(rvalue)
lvalue = walk(lvalue)
return [ this[0], op, lvalue, rvalue ];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this change to me? Why do you have to walk the rvalue before the lvalue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michaelficarra consider this example:

a.b = 3;
c.d = 3;

If I'd walk lvalue first, c.d would prevent me from joining those two because my code would (incorrectly) assume that c.d gets evaluated before the second 3 and therefore could trigger a setter that alters state or so. My code depends on the walkers going through the code in the order the code would be evaluated in.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, alright. Thanks.

@mishoo
Copy link
Owner

mishoo commented Sep 11, 2011

This one is buggy:

// problem 1: this.foo is dropped
this.foo = 0;
this.bar = 0;
this.baz = 0;
// problem 2: b -= b += 5?
if (a < 0) b += 5;
else b -= 5;

===> uglified:

this.baz = this.bar = 0, a < 0 && (b -= b += 5);

@thejh
Copy link
Contributor Author

thejh commented Sep 11, 2011

Fixed one easy bug, only simple assignments (=) are treated this way now, but the problems with this.foo being dropped and if (a) b=2; else c=2 getting compiled to a&&(c=b=2) still remain. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants