PaperScript compiler produces invalid JavaScript (ReferenceError: invalid assignment left-hand side) #1151

Closed
nebaughman opened this Issue Aug 28, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@nebaughman

Version: Paper.js v0.10.2-develop

Problem: PaperScript compiler produces invalid JavaScript

This is valid JavaScript:

1 < a.count && (a.radius += 2.0);

PaperScript compiler (probably around PaperScript.js Line#255) turns this into invalid JavaScript:

1 < a.count && a.radius = __$__(a.radius, "+", 2.0);

Browser console shows this error:

ReferenceError: invalid assignment left-hand side

Workaround: Don't code this way.

Background: I discovered this after compiling some PaperScript code with ClosureCompiler, which minified this if-statement: if (a.count > 1) a.radius += 2.0; into 1 < a.count && (a.radius += 2.0);

Overall, supporting the offending syntax would make PaperScript code more compatible with ClosureCompiler, and avoid producing invalid JavaScript (in this otherwise rather esoteric case).

(PS Thanks for this fantastic library!)

@lehni

This comment has been minimized.

Show comment
Hide comment
@lehni

lehni Nov 21, 2016

Member

Thanks for spotting this! It looks like the problem is that the parenthesis are being dropped, correct?

Member

lehni commented Nov 21, 2016

Thanks for spotting this! It looks like the problem is that the parenthesis are being dropped, correct?

@lehni

This comment has been minimized.

Show comment
Hide comment
@lehni

lehni Nov 21, 2016

Member

Here a sketch to reproduce the issue.

Member

lehni commented Nov 21, 2016

Here a sketch to reproduce the issue.

@lehni lehni closed this in d779789 Nov 21, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment