-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flow][match] Add better parse error for multiple match args
Summary: We don't allow multple match args (parsing as AssignmentExpression rather than Expression), to reserve the future possibilty for allowing multiple args (where they would mean the same as `match ([a, b]) {}`. This is currently a parse error, but working on the Hermes parser version, I realized we can have a better parse error here. Rather than attempting in parse as a `match` call and then failing on the `{`, we can have a better parse error when a single argument is not supplied. Changelog: [internal] Reviewed By: SamChou19815 Differential Revision: D65851645 fbshipit-source-id: 5025e0db5c14cd9b46b7c7fc91e5a46b1c911a74
- Loading branch information
1 parent
870e4cc
commit efcd4dc
Showing
9 changed files
with
115 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const e = match (a, b) {}; |
3 changes: 3 additions & 0 deletions
3
src/parser/test/flow/match/expression-multiple-args.options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"pattern_matching": true | ||
} |
47 changes: 47 additions & 0 deletions
47
src/parser/test/flow/match/expression-multiple-args.tree.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"errors":[ | ||
{ | ||
"loc":{"source":null,"start":{"line":1,"column":16},"end":{"line":1,"column":22}}, | ||
"message":"`match` only supports one argument" | ||
} | ||
], | ||
"type":"Program", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":26}}, | ||
"range":[0,26], | ||
"body":[ | ||
{ | ||
"type":"VariableDeclaration", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":26}}, | ||
"range":[0,26], | ||
"declarations":[ | ||
{ | ||
"type":"VariableDeclarator", | ||
"loc":{"source":null,"start":{"line":1,"column":6},"end":{"line":1,"column":25}}, | ||
"range":[6,25], | ||
"id":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":6},"end":{"line":1,"column":7}}, | ||
"range":[6,7], | ||
"name":"e", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"init":{ | ||
"type":"MatchExpression", | ||
"loc":{"source":null,"start":{"line":1,"column":10},"end":{"line":1,"column":25}}, | ||
"range":[10,25], | ||
"argument":{ | ||
"type":"SequenceExpression", | ||
"loc":{"source":null,"start":{"line":1,"column":16},"end":{"line":1,"column":22}}, | ||
"range":[16,22], | ||
"expressions":[] | ||
}, | ||
"cases":[] | ||
} | ||
} | ||
], | ||
"kind":"const" | ||
} | ||
], | ||
"comments":[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
match (a, b) {} |
3 changes: 3 additions & 0 deletions
3
src/parser/test/flow/match/statement-multiple-args.options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"pattern_matching": true | ||
} |
26 changes: 26 additions & 0 deletions
26
src/parser/test/flow/match/statement-multiple-args.tree.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"errors":[ | ||
{ | ||
"loc":{"source":null,"start":{"line":1,"column":6},"end":{"line":1,"column":12}}, | ||
"message":"`match` only supports one argument" | ||
} | ||
], | ||
"type":"Program", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":15}}, | ||
"range":[0,15], | ||
"body":[ | ||
{ | ||
"type":"MatchStatement", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":15}}, | ||
"range":[0,15], | ||
"argument":{ | ||
"type":"SequenceExpression", | ||
"loc":{"source":null,"start":{"line":1,"column":6},"end":{"line":1,"column":12}}, | ||
"range":[6,12], | ||
"expressions":[] | ||
}, | ||
"cases":[] | ||
} | ||
], | ||
"comments":[] | ||
} |