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

Commit 175bec4

Browse files
committed
sem: skip mapping function's comments
Signed-off-by: Alexander Bezzubov <[email protected]>
1 parent f20563e commit 175bec4

5 files changed

+364
-177
lines changed

driver/normalizer/normalizer.go

+4
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ var Normalizers = []Mapping{
249249
{Name: "local", Op: Var("local")},
250250
//FIXME(bzz): save this once we agree how
251251
{Name: "leadingComments", Drop: true, Op: Any()},
252+
{Name: "trailingComments", Drop: true, Op: Any()},
252253
},
253254
Obj{
254255
"Name": Var("local"),
@@ -270,6 +271,9 @@ var Normalizers = []Mapping{
270271
{Name: "returnType", Drop: true, Op: Any()},
271272
//FIXME(bzz): map Flow argument type annotations
272273
{Name: "typeParameters", Drop: true, Op: Any()},
274+
// FIXME(bzz): make sure such comments are linked properly
275+
{Name: "leadingComments", Drop: true, Op: Any()},
276+
{Name: "trailingComments", Drop: true, Op: Any()},
273277
{Name: "params", Op: Each("params", Cases("param_case",
274278
// Identifier
275279
Check(

fixtures/function-declaration.js

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
// comment before
12
function f(a, b = 0, ...rest) { let x = a; }
3+
// comment after

fixtures/function-declaration.js.native

+130-59
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
11
{
2-
comments: [],
3-
end: 45,
2+
comments: [
3+
{
4+
end: 17,
5+
loc: {
6+
end: {
7+
column: 17,
8+
line: 1,
9+
},
10+
start: {
11+
column: 0,
12+
line: 1,
13+
},
14+
},
15+
start: 0,
16+
type: "CommentLine",
17+
value: " comment before",
18+
},
19+
{
20+
end: 79,
21+
loc: {
22+
end: {
23+
column: 16,
24+
line: 3,
25+
},
26+
start: {
27+
column: 0,
28+
line: 3,
29+
},
30+
},
31+
start: 63,
32+
type: "CommentLine",
33+
value: " comment after",
34+
},
35+
],
36+
end: 79,
437
loc: {
538
end: {
6-
column: 0,
7-
line: 2,
39+
column: 16,
40+
line: 3,
841
},
942
start: {
1043
column: 0,
@@ -20,228 +53,266 @@
2053
{
2154
declarations: [
2255
{
23-
end: 41,
56+
end: 59,
2457
id: {
25-
end: 37,
58+
end: 55,
2659
loc: {
2760
end: {
2861
column: 37,
29-
line: 1,
62+
line: 2,
3063
},
3164
identifierName: "x",
3265
start: {
3366
column: 36,
34-
line: 1,
67+
line: 2,
3568
},
3669
},
3770
name: "x",
38-
start: 36,
71+
start: 54,
3972
type: "Identifier",
4073
},
4174
init: {
42-
end: 41,
75+
end: 59,
4376
loc: {
4477
end: {
4578
column: 41,
46-
line: 1,
79+
line: 2,
4780
},
4881
identifierName: "a",
4982
start: {
5083
column: 40,
51-
line: 1,
84+
line: 2,
5285
},
5386
},
5487
name: "a",
55-
start: 40,
88+
start: 58,
5689
type: "Identifier",
5790
},
5891
loc: {
5992
end: {
6093
column: 41,
61-
line: 1,
94+
line: 2,
6295
},
6396
start: {
6497
column: 36,
65-
line: 1,
98+
line: 2,
6699
},
67100
},
68-
start: 36,
101+
start: 54,
69102
type: "VariableDeclarator",
70103
},
71104
],
72-
end: 42,
105+
end: 60,
73106
kind: "let",
74107
loc: {
75108
end: {
76109
column: 42,
77-
line: 1,
110+
line: 2,
78111
},
79112
start: {
80113
column: 32,
81-
line: 1,
114+
line: 2,
82115
},
83116
},
84-
start: 32,
117+
start: 50,
85118
type: "VariableDeclaration",
86119
},
87120
],
88121
directives: [],
89-
end: 44,
122+
end: 62,
90123
loc: {
91124
end: {
92125
column: 44,
93-
line: 1,
126+
line: 2,
94127
},
95128
start: {
96129
column: 30,
97-
line: 1,
130+
line: 2,
98131
},
99132
},
100-
start: 30,
133+
start: 48,
134+
trailingComments: ~,
101135
type: "BlockStatement",
102136
},
103-
end: 44,
137+
end: 62,
104138
generator: false,
105139
id: {
106-
end: 10,
140+
end: 28,
141+
leadingComments: ~,
107142
loc: {
108143
end: {
109144
column: 10,
110-
line: 1,
145+
line: 2,
111146
},
112147
identifierName: "f",
113148
start: {
114149
column: 9,
115-
line: 1,
150+
line: 2,
116151
},
117152
},
118153
name: "f",
119-
start: 9,
154+
start: 27,
120155
type: "Identifier",
121156
},
157+
leadingComments: [
158+
{
159+
end: 17,
160+
loc: {
161+
end: {
162+
column: 17,
163+
line: 1,
164+
},
165+
start: {
166+
column: 0,
167+
line: 1,
168+
},
169+
},
170+
start: 0,
171+
type: "CommentLine",
172+
value: " comment before",
173+
},
174+
],
122175
loc: {
123176
end: {
124177
column: 44,
125-
line: 1,
178+
line: 2,
126179
},
127180
start: {
128181
column: 0,
129-
line: 1,
182+
line: 2,
130183
},
131184
},
132185
params: [
133186
{
134-
end: 12,
187+
end: 30,
135188
loc: {
136189
end: {
137190
column: 12,
138-
line: 1,
191+
line: 2,
139192
},
140193
identifierName: "a",
141194
start: {
142195
column: 11,
143-
line: 1,
196+
line: 2,
144197
},
145198
},
146199
name: "a",
147-
start: 11,
200+
start: 29,
148201
type: "Identifier",
149202
},
150203
{
151-
end: 19,
204+
end: 37,
152205
left: {
153-
end: 15,
206+
end: 33,
154207
loc: {
155208
end: {
156209
column: 15,
157-
line: 1,
210+
line: 2,
158211
},
159212
identifierName: "b",
160213
start: {
161214
column: 14,
162-
line: 1,
215+
line: 2,
163216
},
164217
},
165218
name: "b",
166-
start: 14,
219+
start: 32,
167220
type: "Identifier",
168221
},
169222
loc: {
170223
end: {
171224
column: 19,
172-
line: 1,
225+
line: 2,
173226
},
174227
start: {
175228
column: 14,
176-
line: 1,
229+
line: 2,
177230
},
178231
},
179232
right: {
180-
end: 19,
233+
end: 37,
181234
extra: {
182235
raw: "0",
183236
rawValue: 0,
184237
},
185238
loc: {
186239
end: {
187240
column: 19,
188-
line: 1,
241+
line: 2,
189242
},
190243
start: {
191244
column: 18,
192-
line: 1,
245+
line: 2,
193246
},
194247
},
195-
start: 18,
248+
start: 36,
196249
type: "NumericLiteral",
197250
value: 0,
198251
},
199-
start: 14,
252+
start: 32,
200253
type: "AssignmentPattern",
201254
},
202255
{
203256
argument: {
204-
end: 28,
257+
end: 46,
205258
loc: {
206259
end: {
207260
column: 28,
208-
line: 1,
261+
line: 2,
209262
},
210263
identifierName: "rest",
211264
start: {
212265
column: 24,
213-
line: 1,
266+
line: 2,
214267
},
215268
},
216269
name: "rest",
217-
start: 24,
270+
start: 42,
218271
type: "Identifier",
219272
},
220-
end: 28,
273+
end: 46,
221274
loc: {
222275
end: {
223276
column: 28,
224-
line: 1,
277+
line: 2,
225278
},
226279
start: {
227280
column: 21,
228-
line: 1,
281+
line: 2,
229282
},
230283
},
231-
start: 21,
284+
start: 39,
232285
type: "RestElement",
233286
},
234287
],
235-
start: 0,
288+
start: 18,
289+
trailingComments: [
290+
{
291+
end: 79,
292+
loc: {
293+
end: {
294+
column: 16,
295+
line: 3,
296+
},
297+
start: {
298+
column: 0,
299+
line: 3,
300+
},
301+
},
302+
start: 63,
303+
type: "CommentLine",
304+
value: " comment after",
305+
},
306+
],
236307
type: "FunctionDeclaration",
237308
},
238309
],
239310
directives: [],
240-
end: 45,
311+
end: 79,
241312
loc: {
242313
end: {
243-
column: 0,
244-
line: 2,
314+
column: 16,
315+
line: 3,
245316
},
246317
start: {
247318
column: 0,

0 commit comments

Comments
 (0)