-
Notifications
You must be signed in to change notification settings - Fork 90
Description
Playing a little fast and loose with the metagrammar, I think this proposal should be simplified to
A.1 Expressions
-
PrimaryExpr:
- //... existing stuff
- MatchExpr // Like in proposal
-
RelationalExpr: // unchanged, but useful below
- //... existing stuff
- RelationalExpr (
<|<=|>=|>) ShiftExpr - RelationalExpr (
instanceof|in) ShiftExpr
-
EqualityExpr:
- //... existing stuff
- EqualityExpr (
==|!=|===|!==) RelationalExpr - EqualityExpr
~=MatchPattern // like the proposedis
-
MatchPattern:
- // Like in proposal and like destructuring
void// I'm a fan, and allows...void- MatchPattern
=AssignmentExpr // can we make defaults this simple? [(MatchPattern,)* (...MatchPattern)?]{(Prop:MatchPattern,)* (...MatchPattern)?}- Extractor
- // Nice-to-have, unless Extractors can subsume these?
- MatchPattern
andMatchPattern // consider&&? - MatchPattern
orMatchPattern // consider||? notMatchPattern // consider!?if(Expr)
- MatchPattern
- // Different!
- Identifier // Binding occurrence, like destructuring
- (
<|<=|>=|>) ShiftExpr - (
===|!==) RelationalExpr ~=MatchPattern
- // Like in proposal and like destructuring
-
Left-Hand-Side Exprs: // enhance destructuring
- //... existing stuff
void- Extractor // refutable
~=MatchPattern // refutable- // How much more from MatchPattern could we add here?
The main change is how the distinction between comparing against values is expressed vs how bindings are introduced. The existing proposal treats a bare Identifier as a lexical reference to a variable from the enclosing scope, so it introduces bindings with a let, const, or var prefix. This is not at all like destructuring. IMO people will be confused by this asymmetry.
I saw in the proposal a suggestion of a pattern to be able to start with a (normally binary) relational operator followed by an expression. This is the opportunity to restore the symmetry with destructuring! This gives a way to introduce expressions whose value can be compared, including expressions using variables from outer scopes. Any Identifier appearing normally in a pattern is binding occurrence, just as one expects from destructuring.