forked from facebook/flow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parser: add parse-only support for "import.meta"
Summary: Resolves facebook#6913. As with `new.target`, we can parse the expression, but we fail to typecheck it. Clients can use a suppression comment to ignore uses of `import.meta` in an otherwise valid file. The parse error message on inputs like `import.notMeta` was chosen to be consistent with the message emitted by Babylon. Test Plan: Unit tests added, and all existing tests pass. wchargin-branch: parse-import-meta
- Loading branch information
Showing
8 changed files
with
113 additions
and
5 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,3 @@ | ||
[options] | ||
module.system=haste | ||
no_flowlib=false |
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,42 @@ | ||
Error ----------------------------------------------------------------------------------------------- import_meta.js:9:1 | ||
|
||
Not supported. | ||
|
||
9| import.meta; | ||
^^^^^^^^^^^ | ||
|
||
|
||
Error ---------------------------------------------------------------------------------------------- import_meta.js:12:1 | ||
|
||
Not supported. | ||
|
||
12| import.meta.hello = "world"; | ||
^^^^^^^^^^^ | ||
|
||
|
||
Error --------------------------------------------------------------------------------------------- import_meta.js:15:14 | ||
|
||
Not supported. | ||
|
||
15| const meta = import.meta; | ||
^^^^^^^^^^^ | ||
|
||
|
||
Error ---------------------------------------------------------------------------------- no_assign_to_import_meta.js:4:1 | ||
|
||
Invalid left-hand side in assignment | ||
|
||
4| import.meta = {wat: "wat"}; // parse error | ||
^^^^^^^^^^^ | ||
|
||
|
||
Error ----------------------------------------------------------------------------------- no_other_metaproperties.js:4:1 | ||
|
||
The only valid meta property for import is import.meta | ||
|
||
4| import.atem; // parse error | ||
^^^^^^ | ||
|
||
|
||
|
||
Found 5 errors |
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,22 @@ | ||
// @flow | ||
|
||
// NOTE: The following tests all currently yield a "Not supported." | ||
// error because Flow does not process MetaProperty expressions at all. | ||
// The comments above each test case describe what the behavior _should_ | ||
// be once typechecking is implemented. | ||
|
||
// You can access `import.meta` at the root of the module. | ||
import.meta; | ||
|
||
// You can write to `import.meta` at the root of the module. | ||
import.meta.hello = "world"; | ||
|
||
// You can use `import.meta` in a normal expression context. | ||
const meta = import.meta; | ||
|
||
// All properties are `mixed`. | ||
(meta.whatever: mixed); | ||
(meta.whatnever: number); // error | ||
|
||
// Properties are writable. | ||
meta.writeable = "definitely"; |
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,4 @@ | ||
// @flow | ||
|
||
// You can't assign to it. | ||
import.meta = {wat: "wat"}; // parse error |
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,4 @@ | ||
// @flow | ||
|
||
// You can't access any other metaproperties on `import`. | ||
import.atem; // parse error |