Skip to content

Commit 45ea26b

Browse files
committed
Refactor alias as _import_identifier
1 parent c60846c commit 45ea26b

File tree

5 files changed

+240356
-240496
lines changed

5 files changed

+240356
-240496
lines changed

common/define-grammar.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,22 +262,24 @@ module.exports = function defineGrammar(dialect) {
262262
previous
263263
),
264264

265+
_import_identifier: $ => choice($.identifier, alias('type', $.identifier)),
266+
265267
import_specifier: ($, previous) => seq(
266268
optional(choice('type', 'typeof')),
267269
choice(
268-
field('name', choice($.identifier, alias('type', $.identifier))),
270+
field('name', $._import_identifier),
269271
seq(
270272
field('name', choice($._module_export_name, alias('type', $.identifier))),
271273
'as',
272-
field('alias', choice($.identifier, alias('type', $.identifier)))
274+
field('alias', $._import_identifier)
273275
),
274276
)),
275277

276278
import_clause: ($, previous) => choice(
277279
$.namespace_import,
278280
$.named_imports,
279281
seq(
280-
choice($.identifier, alias('type', $.identifier)),
282+
$._import_identifier,
281283
optional(seq(
282284
',',
283285
choice(

tsx/src/grammar.json

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -560,22 +560,8 @@
560560
"type": "SEQ",
561561
"members": [
562562
{
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-
]
563+
"type": "SYMBOL",
564+
"name": "_import_identifier"
579565
},
580566
{
581567
"type": "CHOICE",
@@ -734,22 +720,8 @@
734720
"type": "FIELD",
735721
"name": "name",
736722
"content": {
737-
"type": "CHOICE",
738-
"members": [
739-
{
740-
"type": "SYMBOL",
741-
"name": "identifier"
742-
},
743-
{
744-
"type": "ALIAS",
745-
"content": {
746-
"type": "STRING",
747-
"value": "type"
748-
},
749-
"named": true,
750-
"value": "identifier"
751-
}
752-
]
723+
"type": "SYMBOL",
724+
"name": "_import_identifier"
753725
}
754726
},
755727
{
@@ -785,22 +757,8 @@
785757
"type": "FIELD",
786758
"name": "alias",
787759
"content": {
788-
"type": "CHOICE",
789-
"members": [
790-
{
791-
"type": "SYMBOL",
792-
"name": "identifier"
793-
},
794-
{
795-
"type": "ALIAS",
796-
"content": {
797-
"type": "STRING",
798-
"value": "type"
799-
},
800-
"named": true,
801-
"value": "identifier"
802-
}
803-
]
760+
"type": "SYMBOL",
761+
"name": "_import_identifier"
804762
}
805763
}
806764
]
@@ -7325,6 +7283,24 @@
73257283
}
73267284
]
73277285
},
7286+
"_import_identifier": {
7287+
"type": "CHOICE",
7288+
"members": [
7289+
{
7290+
"type": "SYMBOL",
7291+
"name": "identifier"
7292+
},
7293+
{
7294+
"type": "ALIAS",
7295+
"content": {
7296+
"type": "STRING",
7297+
"value": "type"
7298+
},
7299+
"named": true,
7300+
"value": "identifier"
7301+
}
7302+
]
7303+
},
73287304
"non_null_expression": {
73297305
"type": "PREC_LEFT",
73307306
"value": "unary",

0 commit comments

Comments
 (0)