-
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.
Summary: Allows parsing of `import.meta`, which is in the latest standard (from ES2020). While we don't type-check it or other `MetaProperty`s (e.g. `new.target`), at least it's not a parse error so someone can just use `$FlowFixMe` now. There was a PR for this but it was 3 years old, didn't have parser tests, so I just implemented from scratch myself here instead. Fixes #6913 Closes #6958 Changelog: [feature] Added parser support for `import.meta` Reviewed By: mroch Differential Revision: D30716916 fbshipit-source-id: eb5c5ec53d34d46c228e89137d6a4da8d0839e84
- Loading branch information
1 parent
39f67db
commit 0851b3e
Showing
8 changed files
with
177 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import.meta; |
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,35 @@ | ||
{ | ||
"type":"Program", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":12}}, | ||
"range":[0,12], | ||
"body":[ | ||
{ | ||
"type":"ExpressionStatement", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":12}}, | ||
"range":[0,12], | ||
"expression":{ | ||
"type":"MetaProperty", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":11}}, | ||
"range":[0,11], | ||
"meta":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":6}}, | ||
"range":[0,6], | ||
"name":"import", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"property":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":7},"end":{"line":1,"column":11}}, | ||
"range":[7,11], | ||
"name":"meta", | ||
"typeAnnotation":null, | ||
"optional":false | ||
} | ||
}, | ||
"directive":null | ||
} | ||
], | ||
"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 @@ | ||
import.meta = 1; |
54 changes: 54 additions & 0 deletions
54
src/parser/test/flow/meta_property/import_meta_assign.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,54 @@ | ||
{ | ||
"errors":[ | ||
{ | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":11}}, | ||
"message":"Invalid left-hand side in assignment" | ||
} | ||
], | ||
"type":"Program", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":16}}, | ||
"range":[0,16], | ||
"body":[ | ||
{ | ||
"type":"ExpressionStatement", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":16}}, | ||
"range":[0,16], | ||
"expression":{ | ||
"type":"AssignmentExpression", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":15}}, | ||
"range":[0,15], | ||
"operator":"=", | ||
"left":{ | ||
"type":"MetaProperty", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":11}}, | ||
"range":[0,11], | ||
"meta":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":6}}, | ||
"range":[0,6], | ||
"name":"import", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"property":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":7},"end":{"line":1,"column":11}}, | ||
"range":[7,11], | ||
"name":"meta", | ||
"typeAnnotation":null, | ||
"optional":false | ||
} | ||
}, | ||
"right":{ | ||
"type":"Literal", | ||
"loc":{"source":null,"start":{"line":1,"column":14},"end":{"line":1,"column":15}}, | ||
"range":[14,15], | ||
"value":1, | ||
"raw":"1" | ||
} | ||
}, | ||
"directive":null | ||
} | ||
], | ||
"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 @@ | ||
import.foo; |
41 changes: 41 additions & 0 deletions
41
src/parser/test/flow/meta_property/import_not_meta.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,41 @@ | ||
{ | ||
"errors":[ | ||
{ | ||
"loc":{"source":null,"start":{"line":1,"column":7},"end":{"line":1,"column":10}}, | ||
"message":"Unexpected identifier, expected the identifier `meta`" | ||
} | ||
], | ||
"type":"Program", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":11}}, | ||
"range":[0,11], | ||
"body":[ | ||
{ | ||
"type":"ExpressionStatement", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":11}}, | ||
"range":[0,11], | ||
"expression":{ | ||
"type":"MetaProperty", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":10}}, | ||
"range":[0,10], | ||
"meta":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":6}}, | ||
"range":[0,6], | ||
"name":"import", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"property":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":7},"end":{"line":1,"column":10}}, | ||
"range":[7,10], | ||
"name":"meta", | ||
"typeAnnotation":null, | ||
"optional":false | ||
} | ||
}, | ||
"directive":null | ||
} | ||
], | ||
"comments":[] | ||
} |