Skip to content

Commit e127694

Browse files
committed
Fix edge cases with type imports
1 parent c6e56d4 commit e127694

File tree

6 files changed

+234262
-234065
lines changed

6 files changed

+234262
-234065
lines changed

common/corpus/types.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ import {type UserID, type User} from "./User.js";
317317
import typeof {jimiguitar as GuitarT} from "./User.js";
318318
import type UserID, {addUser, removeUser} from './User.js';
319319

320+
import type from './User.js';
321+
import type, {addUser} from './User.js';
322+
import type, {addUser, type User} from './User.js';
323+
320324
---
321325

322326
(program
@@ -329,6 +333,14 @@ import type UserID, {addUser, removeUser} from './User.js';
329333
(import_statement
330334
(import_clause
331335
(named_imports (import_specifier (identifier) (identifier)))) (string (string_fragment)))
336+
(import_statement
337+
(import_clause (identifier)
338+
(named_imports (import_specifier (identifier)) (import_specifier (identifier)))) (string (string_fragment)))
339+
(import_statement
340+
(import_clause (identifier)) (string (string_fragment)))
341+
(import_statement
342+
(import_clause (identifier)
343+
(named_imports (import_specifier (identifier)))) (string (string_fragment)))
332344
(import_statement
333345
(import_clause (identifier)
334346
(named_imports (import_specifier (identifier)) (import_specifier (identifier)))) (string (string_fragment))))

common/define-grammar.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,21 @@ module.exports = function defineGrammar(dialect) {
267267
previous
268268
),
269269

270+
import_clause: ($, previous) => choice(
271+
$.namespace_import,
272+
$.named_imports,
273+
seq(
274+
choice($.identifier, alias('type', $.identifier)),
275+
optional(seq(
276+
',',
277+
choice(
278+
$.namespace_import,
279+
$.named_imports
280+
)
281+
))
282+
)
283+
),
284+
270285
import_statement: $ => seq(
271286
'import',
272287
optional(choice('type', 'typeof')),

tsx/src/grammar.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,22 @@
560560
"type": "SEQ",
561561
"members": [
562562
{
563-
"type": "SYMBOL",
564-
"name": "identifier"
563+
"type": "CHOICE",
564+
"members": [
565+
{
566+
"type": "SYMBOL",
567+
"name": "identifier"
568+
},
569+
{
570+
"type": "ALIAS",
571+
"content": {
572+
"type": "STRING",
573+
"value": "type"
574+
},
575+
"named": true,
576+
"value": "identifier"
577+
}
578+
]
565579
},
566580
{
567581
"type": "CHOICE",

0 commit comments

Comments
 (0)