benjamn / ast-types

Esprima-compatible implementation of the Mozilla JS Parser API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

In core, Pattern should probably only be implemented by MemberExpression (and Identifier)

xmo-odoo opened this issue · comments

Officially the toplevel "left hand side expression" is defined as:

LeftHandSideExpression :
    NewExpression
    CallExpression

where the two productions implement various permutations of attribute accesses, function calls and new calls, however a valid LHS should also produce a reference object, in theory host objects could produce references on simple function calls but in practice that's never the case (let alone constructors doing that), furthermore

Annex E: Additions and Changes That Introduce Incompatibilities with Prior Editions

6.2.3: In ECMAScript 2015, Function calls are not allowed to return a Reference value.

and finally Firefox already throws a ReferenceError: invalid assignment left-hand side on parsing an assignment to a new call (webkit will parse it but fail at runtime).

Thus, I think the AST would be both clearer and more sensible if it were restricted to Identifier and MemberExpression (again in Core)