musictheory / NilScript

Objective-C-style language superset of JavaScript with a tiny, simple runtime
Other
50 stars 5 forks source link

oj requires more semicolons than pure JS #67

Open iccir opened 8 years ago

iccir commented 8 years ago

I don't have a good fix for this, but I wanted to document the behavior.

JavaScript performs automatic semicolon insertion (ASI), which allows semicolons to be omitted in specific situations:

foo()
foo()

However, this doesn't work in oj:

foo()
[instance foo] // Parse error

In this specific case, the parser thinks that we are in a computed member expression:

foo()
[5]           // "Call foo and then access the 5th member"

parseLeftHandSideExpressionAllowCall(), parseLeftHandSideExpression(), and parseComputedMember() in Esprima would need to be modified to make this possible.