Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 0be5d4a

Browse files
committed
sem: re-work ImportNamespaceSpecifier comments
Instead of dropping comments of ImportNamespaceSpecifier as implemented in #60, we just skip both, leading and trailing comments now. This avoids loosing a Comment node in UAST. Signed-off-by: Alexander Bezzubov <[email protected]>
1 parent 70ce5c1 commit 0be5d4a

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

driver/normalizer/normalizer.go

+7-14
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,6 @@ var Preprocessors = []Mapping{
7070
Part("_", Obj{"extra": Any()}),
7171
Part("_", Obj{}),
7272
),
73-
// FIXME(bzz): make sure such comments are mapped properly
74-
Map(
75-
Part("_", Obj{
76-
uast.KeyType: String("ImportNamespaceSpecifier"),
77-
"leadingComments": Any(),
78-
}),
79-
Part("_", Obj{
80-
uast.KeyType: String("ImportNamespaceSpecifier"),
81-
}),
82-
),
8373
}
8474

8575
// Normalizers is the main block of normalization rules to convert native AST to semantic UAST.
@@ -174,11 +164,14 @@ var Normalizers = []Mapping{
174164
// namespace
175165
{
176166
"importKind": String("value"),
177-
"specifiers": ArrWith(Var("names"), Obj{
167+
"specifiers": ArrWith(Var("names"), Fields{
178168
//uast.KeyType: Var("spec_type"),
179-
uast.KeyType: String("ImportNamespaceSpecifier"),
180-
uast.KeyPos: Var("local_pos"),
181-
"local": Var("local"),
169+
{Name: uast.KeyType, Op: String("ImportNamespaceSpecifier")},
170+
{Name: uast.KeyPos, Op: Var("local_pos")},
171+
{Name: "local", Op: Var("local")},
172+
// FIXME(bzz): make sure such comments are linked properly
173+
{Name: "leadingComments", Drop: true, Op: Any()},
174+
{Name: "trailingComments", Drop: true, Op: Any()},
182175
}),
183176
},
184177
// specific type

fixtures/59-jsx-flow.js.uast

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
col: 18,
126126
},
127127
},
128+
leadingComments: ~,
128129
local: { '@type': "Identifier",
129130
'@token': "React",
130131
'@role': [Expression, Identifier, Import],

0 commit comments

Comments
 (0)