Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[parser] reserved types in import-typeof declarations should error
Summary: `import typeof { string } from ...` would define a type named `string`, which is reserved. `import { typeof string } from ...` already errors. Reviewed By: samwgoldman Differential Revision: D6197490 fbshipit-source-id: 9ed1722df19a1324ff797326b4046fa5320ffe03
- Loading branch information
1 parent
2a8bc50
commit a3e936a
Showing
10 changed files
with
190 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
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
src/parser/test/flow/types/import_type_shorthand/typeof_in_typeof_reserved_type.js
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,2 @@ | ||
// 2 errors: typeof specifier in typeof declaration, and `string` is reserved | ||
import typeof {typeof string} from "foo"; |
62 changes: 62 additions & 0 deletions
62
src/parser/test/flow/types/import_type_shorthand/typeof_in_typeof_reserved_type.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,62 @@ | ||
{ | ||
"errors":[ | ||
{ | ||
"loc":{"source":null,"start":{"line":2,"column":15},"end":{"line":2,"column":21}}, | ||
"message":"The `type` and `typeof` keywords on named imports can only be used on regular `import` statements. It cannot be used with `import type` or `import typeof` statements" | ||
}, | ||
{ | ||
"loc":{"source":null,"start":{"line":2,"column":22},"end":{"line":2,"column":28}}, | ||
"message":"Unexpected reserved type" | ||
} | ||
], | ||
"type":"Program", | ||
"loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":41}}, | ||
"range":[78,119], | ||
"body":[ | ||
{ | ||
"type":"ImportDeclaration", | ||
"loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":41}}, | ||
"range":[78,119], | ||
"specifiers":[ | ||
{ | ||
"type":"ImportSpecifier", | ||
"loc":{"source":null,"start":{"line":2,"column":22},"end":{"line":2,"column":28}}, | ||
"range":[100,106], | ||
"imported":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":2,"column":22},"end":{"line":2,"column":28}}, | ||
"range":[100,106], | ||
"name":"string", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"local":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":2,"column":22},"end":{"line":2,"column":28}}, | ||
"range":[100,106], | ||
"name":"string", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"importKind":null | ||
} | ||
], | ||
"source":{ | ||
"type":"Literal", | ||
"loc":{"source":null,"start":{"line":2,"column":35},"end":{"line":2,"column":40}}, | ||
"range":[113,118], | ||
"value":"foo", | ||
"raw":"\"foo\"" | ||
}, | ||
"importKind":"typeof" | ||
} | ||
], | ||
"comments":[ | ||
{ | ||
"type":"Line", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":77}}, | ||
"range":[0,77], | ||
"value":" 2 errors: typeof specifier in typeof declaration, and `string` is reserved" | ||
} | ||
] | ||
} |
2 changes: 2 additions & 0 deletions
2
src/parser/test/flow/types/import_type_shorthand/typeof_in_typeof_reserved_value.js
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,2 @@ | ||
// error: typeof specifier in typeof declaration | ||
import typeof {typeof switch} from "foo"; |
58 changes: 58 additions & 0 deletions
58
src/parser/test/flow/types/import_type_shorthand/typeof_in_typeof_reserved_value.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,58 @@ | ||
{ | ||
"errors":[ | ||
{ | ||
"loc":{"source":null,"start":{"line":2,"column":15},"end":{"line":2,"column":21}}, | ||
"message":"The `type` and `typeof` keywords on named imports can only be used on regular `import` statements. It cannot be used with `import type` or `import typeof` statements" | ||
} | ||
], | ||
"type":"Program", | ||
"loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":41}}, | ||
"range":[49,90], | ||
"body":[ | ||
{ | ||
"type":"ImportDeclaration", | ||
"loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":41}}, | ||
"range":[49,90], | ||
"specifiers":[ | ||
{ | ||
"type":"ImportSpecifier", | ||
"loc":{"source":null,"start":{"line":2,"column":22},"end":{"line":2,"column":28}}, | ||
"range":[71,77], | ||
"imported":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":2,"column":22},"end":{"line":2,"column":28}}, | ||
"range":[71,77], | ||
"name":"switch", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"local":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":2,"column":22},"end":{"line":2,"column":28}}, | ||
"range":[71,77], | ||
"name":"switch", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"importKind":null | ||
} | ||
], | ||
"source":{ | ||
"type":"Literal", | ||
"loc":{"source":null,"start":{"line":2,"column":35},"end":{"line":2,"column":40}}, | ||
"range":[84,89], | ||
"value":"foo", | ||
"raw":"\"foo\"" | ||
}, | ||
"importKind":"typeof" | ||
} | ||
], | ||
"comments":[ | ||
{ | ||
"type":"Line", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":48}}, | ||
"range":[0,48], | ||
"value":" error: typeof specifier in typeof declaration" | ||
} | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
src/parser/test/flow/types/import_types/typeof_named_reserved_type.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
2 changes: 2 additions & 0 deletions
2
src/parser/test/flow/types/import_types/typeof_named_reserved_type_alias.js
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,2 @@ | ||
// ok, `string` is a reserved type but it's renamed | ||
import typeof { string as StringT } from 'foo'; |
52 changes: 52 additions & 0 deletions
52
src/parser/test/flow/types/import_types/typeof_named_reserved_type_alias.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,52 @@ | ||
{ | ||
"type":"Program", | ||
"loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":47}}, | ||
"range":[52,99], | ||
"body":[ | ||
{ | ||
"type":"ImportDeclaration", | ||
"loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":47}}, | ||
"range":[52,99], | ||
"specifiers":[ | ||
{ | ||
"type":"ImportSpecifier", | ||
"loc":{"source":null,"start":{"line":2,"column":16},"end":{"line":2,"column":33}}, | ||
"range":[68,85], | ||
"imported":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":2,"column":16},"end":{"line":2,"column":22}}, | ||
"range":[68,74], | ||
"name":"string", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"local":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":2,"column":26},"end":{"line":2,"column":33}}, | ||
"range":[78,85], | ||
"name":"StringT", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"importKind":null | ||
} | ||
], | ||
"source":{ | ||
"type":"Literal", | ||
"loc":{"source":null,"start":{"line":2,"column":41},"end":{"line":2,"column":46}}, | ||
"range":[93,98], | ||
"value":"foo", | ||
"raw":"'foo'" | ||
}, | ||
"importKind":"typeof" | ||
} | ||
], | ||
"comments":[ | ||
{ | ||
"type":"Line", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":51}}, | ||
"range":[0,51], | ||
"value":" ok, `string` is a reserved type but it's renamed" | ||
} | ||
] | ||
} |