Skip to content

Commit da26d27

Browse files
committed
fix: 🐛the scope flag between type value and ident
1 parent 8551639 commit da26d27

File tree

4 files changed

+382
-71
lines changed

4 files changed

+382
-71
lines changed
Lines changed: 205 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,167 +1,314 @@
11
const NormalIdentifierSnapshot = {
2+
Issue50: {
3+
'type': 'Program',
4+
'start': 0,
5+
'end': 25,
6+
'loc': {
7+
'start': {
8+
'line': 1,
9+
'column': 0,
10+
'index': 0
11+
},
12+
'end': {
13+
'line': 2,
14+
'column': 8,
15+
'index': 25
16+
}
17+
},
18+
'body': [
19+
{
20+
'type': 'TSTypeAliasDeclaration',
21+
'start': 0,
22+
'end': 16,
23+
'loc': {
24+
'start': {
25+
'line': 1,
26+
'column': 0,
27+
'index': 0
28+
},
29+
'end': {
30+
'line': 1,
31+
'column': 16,
32+
'index': 16
33+
}
34+
},
35+
'id': {
36+
'type': 'Identifier',
37+
'start': 5,
38+
'end': 8,
39+
'loc': {
40+
'start': {
41+
'line': 1,
42+
'column': 5,
43+
'index': 5
44+
},
45+
'end': {
46+
'line': 1,
47+
'column': 8,
48+
'index': 8
49+
}
50+
},
51+
'name': 'abc'
52+
},
53+
'typeAnnotation': {
54+
'type': 'TSLiteralType',
55+
'start': 11,
56+
'end': 15,
57+
'loc': {
58+
'start': {
59+
'line': 1,
60+
'column': 11,
61+
'index': 11
62+
},
63+
'end': {
64+
'line': 1,
65+
'column': 15,
66+
'index': 15
67+
}
68+
},
69+
'literal': {
70+
'type': 'Literal',
71+
'start': 11,
72+
'end': 15,
73+
'loc': {
74+
'start': {
75+
'line': 1,
76+
'column': 11,
77+
'index': 11
78+
},
79+
'end': {
80+
'line': 1,
81+
'column': 15,
82+
'index': 15
83+
}
84+
},
85+
'value': 1234,
86+
'raw': '1234'
87+
}
88+
}
89+
},
90+
{
91+
'type': 'VariableDeclaration',
92+
'start': 17,
93+
'end': 25,
94+
'loc': {
95+
'start': {
96+
'line': 2,
97+
'column': 0,
98+
'index': 17
99+
},
100+
'end': {
101+
'line': 2,
102+
'column': 8,
103+
'index': 25
104+
}
105+
},
106+
'declarations': [
107+
{
108+
'type': 'VariableDeclarator',
109+
'start': 21,
110+
'end': 24,
111+
'loc': {
112+
'start': {
113+
'line': 2,
114+
'column': 4,
115+
'index': 21
116+
},
117+
'end': {
118+
'line': 2,
119+
'column': 7,
120+
'index': 24
121+
}
122+
},
123+
'id': {
124+
'type': 'Identifier',
125+
'start': 21,
126+
'end': 24,
127+
'loc': {
128+
'start': {
129+
'line': 2,
130+
'column': 4,
131+
'index': 21
132+
},
133+
'end': {
134+
'line': 2,
135+
'column': 7,
136+
'index': 24
137+
}
138+
},
139+
'name': 'abc'
140+
},
141+
'init': null
142+
}
143+
],
144+
'kind': 'var'
145+
}
146+
],
147+
'sourceType': 'module'
148+
},
2149
ExportIdentifierAs: {
3-
type: "Program",
150+
type: 'Program',
4151
start: 0,
5152
end: 34,
6153
loc: {
7154
start: { line: 1, column: 0, index: 0 },
8-
end: { line: 2, column: 21, index: 34 },
155+
end: { line: 2, column: 21, index: 34 }
9156
},
10157
body: [
11158
{
12-
type: "VariableDeclaration",
159+
type: 'VariableDeclaration',
13160
start: 0,
14161
end: 12,
15162
loc: {
16163
start: { line: 1, column: 0, index: 0 },
17-
end: { line: 1, column: 12, index: 12 },
164+
end: { line: 1, column: 12, index: 12 }
18165
},
19166
declarations: [
20167
{
21-
type: "VariableDeclarator",
168+
type: 'VariableDeclarator',
22169
start: 4,
23170
end: 11,
24171
loc: {
25172
start: { line: 1, column: 4, index: 4 },
26-
end: { line: 1, column: 11, index: 11 },
173+
end: { line: 1, column: 11, index: 11 }
27174
},
28175
id: {
29-
type: "Identifier",
176+
type: 'Identifier',
30177
start: 4,
31178
end: 7,
32179
loc: {
33180
start: { line: 1, column: 4, index: 4 },
34-
end: { line: 1, column: 7, index: 7 },
181+
end: { line: 1, column: 7, index: 7 }
35182
},
36-
name: "foo",
183+
name: 'foo'
37184
},
38185
init: {
39-
type: "Literal",
186+
type: 'Literal',
40187
start: 10,
41188
end: 11,
42189
loc: {
43190
start: { line: 1, column: 10, index: 10 },
44-
end: { line: 1, column: 11, index: 11 },
191+
end: { line: 1, column: 11, index: 11 }
45192
},
46193
value: 8,
47-
raw: "8",
48-
},
49-
},
194+
raw: '8'
195+
}
196+
}
50197
],
51-
kind: "var",
198+
kind: 'var'
52199
},
53200
{
54-
type: "ExportNamedDeclaration",
201+
type: 'ExportNamedDeclaration',
55202
start: 13,
56203
end: 34,
57204
loc: {
58205
start: { line: 2, column: 0, index: 13 },
59-
end: { line: 2, column: 21, index: 34 },
206+
end: { line: 2, column: 21, index: 34 }
60207
},
61-
exportKind: "value",
208+
exportKind: 'value',
62209
declaration: null,
63210
specifiers: [
64211
{
65-
type: "ExportSpecifier",
212+
type: 'ExportSpecifier',
66213
start: 22,
67214
end: 31,
68215
loc: {
69216
start: { line: 2, column: 9, index: 22 },
70-
end: { line: 2, column: 18, index: 31 },
217+
end: { line: 2, column: 18, index: 31 }
71218
},
72219
local: {
73-
type: "Identifier",
220+
type: 'Identifier',
74221
start: 22,
75222
end: 25,
76223
loc: {
77224
start: { line: 2, column: 9, index: 22 },
78-
end: { line: 2, column: 12, index: 25 },
225+
end: { line: 2, column: 12, index: 25 }
79226
},
80-
name: "foo",
227+
name: 'foo'
81228
},
82-
exportKind: "value",
229+
exportKind: 'value',
83230
exported: {
84-
type: "Identifier",
231+
type: 'Identifier',
85232
start: 29,
86233
end: 31,
87234
loc: {
88235
start: { line: 2, column: 16, index: 29 },
89-
end: { line: 2, column: 18, index: 31 },
236+
end: { line: 2, column: 18, index: 31 }
90237
},
91-
name: "as",
92-
},
93-
},
238+
name: 'as'
239+
}
240+
}
94241
],
95-
source: null,
96-
},
242+
source: null
243+
}
97244
],
98-
sourceType: "module",
245+
sourceType: 'module'
99246
},
100247
ImportIdentifierAs: {
101-
type: "Program",
248+
type: 'Program',
102249
start: 0,
103250
end: 36,
104251
loc: {
105252
start: { line: 1, column: 0, index: 0 },
106-
end: { line: 1, column: 36, index: 36 },
253+
end: { line: 1, column: 36, index: 36 }
107254
},
108255
body: [
109256
{
110-
type: "ImportDeclaration",
257+
type: 'ImportDeclaration',
111258
start: 0,
112259
end: 36,
113260
loc: {
114261
start: { line: 1, column: 0, index: 0 },
115-
end: { line: 1, column: 36, index: 36 },
262+
end: { line: 1, column: 36, index: 36 }
116263
},
117-
importKind: "value",
264+
importKind: 'value',
118265
specifiers: [
119266
{
120-
type: "ImportSpecifier",
267+
type: 'ImportSpecifier',
121268
start: 9,
122269
end: 17,
123270
loc: {
124271
start: { line: 1, column: 9, index: 9 },
125-
end: { line: 1, column: 17, index: 17 },
272+
end: { line: 1, column: 17, index: 17 }
126273
},
127274
imported: {
128-
type: "Identifier",
275+
type: 'Identifier',
129276
start: 9,
130277
end: 11,
131278
loc: {
132279
start: { line: 1, column: 9, index: 9 },
133-
end: { line: 1, column: 11, index: 11 },
280+
end: { line: 1, column: 11, index: 11 }
134281
},
135-
name: "as",
282+
name: 'as'
136283
},
137-
importKind: "value",
284+
importKind: 'value',
138285
local: {
139-
type: "Identifier",
286+
type: 'Identifier',
140287
start: 15,
141288
end: 17,
142289
loc: {
143290
start: { line: 1, column: 15, index: 15 },
144-
end: { line: 1, column: 17, index: 17 },
291+
end: { line: 1, column: 17, index: 17 }
145292
},
146-
name: "as",
147-
},
148-
},
293+
name: 'as'
294+
}
295+
}
149296
],
150297
source: {
151-
type: "Literal",
298+
type: 'Literal',
152299
start: 25,
153300
end: 35,
154301
loc: {
155302
start: { line: 1, column: 25, index: 25 },
156-
end: { line: 1, column: 35, index: 35 },
303+
end: { line: 1, column: 35, index: 35 }
157304
},
158-
value: "./foo.js",
159-
raw: "'./foo.js'",
160-
},
161-
},
305+
value: './foo.js',
306+
raw: '\'./foo.js\''
307+
}
308+
}
162309
],
163-
sourceType: "module",
164-
},
165-
};
310+
sourceType: 'module'
311+
}
312+
}
166313

167-
export default NormalIdentifierSnapshot;
314+
export default NormalIdentifierSnapshot

__test__/identifier/normal.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,12 @@ describe("normal identifier test", () => {
1717

1818
equalNode(node, NormalIdentifierSnapshot.ImportIdentifierAs);
1919
});
20+
21+
it('issue 50', () => {
22+
const node = parseSource(
23+
generateSource([`type abc = 1234;`, `var abc;`])
24+
);
25+
26+
equalNode(node, NormalIdentifierSnapshot.Issue50);
27+
})
2028
});

0 commit comments

Comments
 (0)