1- // @deno -types="../../../../acorn.d.ts"
21import type { AnyNode , ClassDeclaration , ExpressionStatement , FunctionDeclaration , VariableDeclaration } from 'acorn' ;
32
43/**
@@ -9,16 +8,19 @@ import type { AnyNode, ClassDeclaration, ExpressionStatement, FunctionDeclaratio
98type TestNodeExcerpt < N extends AnyNode = AnyNode > = {
109 code : string ;
1110 // start/end are omitted from test fixtures for brevity; cast to any to allow partial node objects
12- node : any ;
11+ node : N ;
1312} ;
1413
14+ const startEnd = { start : 0 , end : 0 } ;
15+
1516export const FunctionDeclarationFoo : TestNodeExcerpt < FunctionDeclaration > = {
1617 code : 'function foo() {}' ,
1718 node : {
1819 type : 'FunctionDeclaration' ,
1920 id : {
2021 type : 'Identifier' ,
2122 name : 'foo' ,
23+ ...startEnd ,
2224 } ,
2325 expression : false ,
2426 generator : false ,
@@ -27,7 +29,9 @@ export const FunctionDeclarationFoo: TestNodeExcerpt<FunctionDeclaration> = {
2729 body : {
2830 type : 'BlockStatement' ,
2931 body : [ ] ,
32+ ...startEnd ,
3033 } ,
34+ ...startEnd ,
3135 } ,
3236} ;
3337
@@ -42,6 +46,7 @@ export const ConstFooAssignedFunctionExpression: TestNodeExcerpt<VariableDeclara
4246 id : {
4347 type : 'Identifier' ,
4448 name : 'foo' ,
49+ ...startEnd ,
4550 } ,
4651 init : {
4752 type : 'FunctionExpression' ,
@@ -53,10 +58,14 @@ export const ConstFooAssignedFunctionExpression: TestNodeExcerpt<VariableDeclara
5358 body : {
5459 type : 'BlockStatement' ,
5560 body : [ ] ,
61+ ...startEnd ,
5662 } ,
63+ ...startEnd ,
5764 } ,
65+ ...startEnd ,
5866 } ,
5967 ] ,
68+ ...startEnd ,
6069 } ,
6170} ;
6271
@@ -70,6 +79,7 @@ export const AssignmentExpressionOfArrowFunctionToFooIdentifier: TestNodeExcerpt
7079 left : {
7180 type : 'Identifier' ,
7281 name : 'foo' ,
82+ ...startEnd ,
7383 } ,
7484 right : {
7585 type : 'ArrowFunctionExpression' ,
@@ -81,9 +91,13 @@ export const AssignmentExpressionOfArrowFunctionToFooIdentifier: TestNodeExcerpt
8191 body : {
8292 type : 'BlockStatement' ,
8393 body : [ ] ,
94+ ...startEnd ,
8495 } ,
96+ ...startEnd ,
8597 } ,
98+ ...startEnd ,
8699 } ,
100+ ...startEnd ,
87101 } ,
88102} ;
89103
@@ -99,13 +113,16 @@ export const AssignmentExpressionOfNamedFunctionToFooMemberExpression: TestNodeE
99113 object : {
100114 type : 'Identifier' ,
101115 name : 'a' ,
116+ ...startEnd ,
102117 } ,
103118 property : {
104119 type : 'Identifier' ,
105120 name : 'foo' ,
121+ ...startEnd ,
106122 } ,
107123 computed : false ,
108124 optional : false ,
125+ ...startEnd ,
109126 } ,
110127 right : {
111128 type : 'FunctionExpression' ,
@@ -117,9 +134,13 @@ export const AssignmentExpressionOfNamedFunctionToFooMemberExpression: TestNodeE
117134 body : {
118135 type : 'BlockStatement' ,
119136 body : [ ] ,
137+ ...startEnd ,
120138 } ,
139+ ...startEnd ,
121140 } ,
141+ ...startEnd ,
122142 } ,
143+ ...startEnd ,
123144 } ,
124145} ;
125146
@@ -130,6 +151,7 @@ export const MethodDefinitionOfFooInClassBar: TestNodeExcerpt<ClassDeclaration>
130151 id : {
131152 type : 'Identifier' ,
132153 name : 'Bar' ,
154+ ...startEnd ,
133155 } ,
134156 superClass : null ,
135157 body : {
@@ -140,6 +162,7 @@ export const MethodDefinitionOfFooInClassBar: TestNodeExcerpt<ClassDeclaration>
140162 key : {
141163 type : 'Identifier' ,
142164 name : 'foo' ,
165+ ...startEnd ,
143166 } ,
144167 value : {
145168 type : 'FunctionExpression' ,
@@ -151,14 +174,19 @@ export const MethodDefinitionOfFooInClassBar: TestNodeExcerpt<ClassDeclaration>
151174 body : {
152175 type : 'BlockStatement' ,
153176 body : [ ] ,
177+ ...startEnd ,
154178 } ,
179+ ...startEnd ,
155180 } ,
156181 kind : 'method' ,
157182 computed : false ,
158183 static : false ,
184+ ...startEnd ,
159185 } ,
160186 ] ,
187+ ...startEnd ,
161188 } ,
189+ ...startEnd ,
162190 } ,
163191} ;
164192
@@ -171,10 +199,13 @@ export const SimpleCallExpressionOfFoo: TestNodeExcerpt<ExpressionStatement> = {
171199 callee : {
172200 type : 'Identifier' ,
173201 name : 'foo' ,
202+ ...startEnd ,
174203 } ,
175204 arguments : [ ] ,
176205 optional : false ,
206+ ...startEnd ,
177207 } ,
208+ ...startEnd ,
178209 } ,
179210} ;
180211
@@ -188,6 +219,7 @@ export const SyncFunctionDeclarationWithAsyncCallExpression: TestNodeExcerpt<Fun
188219 id : {
189220 type : 'Identifier' ,
190221 name : 'foo' ,
222+ ...startEnd ,
191223 } ,
192224 expression : false ,
193225 generator : false ,
@@ -212,15 +244,22 @@ export const SyncFunctionDeclarationWithAsyncCallExpression: TestNodeExcerpt<Fun
212244 callee : {
213245 type : 'Identifier' ,
214246 name : 'bar' ,
247+ ...startEnd ,
215248 } ,
216249 arguments : [ ] ,
217250 optional : false ,
251+ ...startEnd ,
218252 } ,
253+ ...startEnd ,
219254 } ,
255+ ...startEnd ,
220256 } ,
257+ ...startEnd ,
221258 } ,
222259 ] ,
260+ ...startEnd ,
223261 } ,
262+ ...startEnd ,
224263 } ,
225264} ;
226265
@@ -234,12 +273,16 @@ export const AssignmentOfFooToBar: TestNodeExcerpt<ExpressionStatement> = {
234273 left : {
235274 type : 'Identifier' ,
236275 name : 'bar' ,
276+ ...startEnd ,
237277 } ,
238278 right : {
239279 type : 'Identifier' ,
240280 name : 'foo' ,
281+ ...startEnd ,
241282 } ,
283+ ...startEnd ,
242284 } ,
285+ ...startEnd ,
243286 } ,
244287} ;
245288
@@ -257,17 +300,23 @@ export const AssignmentOfFooToBarMemberExpression: TestNodeExcerpt<ExpressionSta
257300 object : {
258301 type : 'Identifier' ,
259302 name : 'obj' ,
303+ ...startEnd ,
260304 } ,
261305 property : {
262306 type : 'Identifier' ,
263307 name : 'bar' ,
308+ ...startEnd ,
264309 } ,
310+ ...startEnd ,
265311 } ,
266312 right : {
267313 type : 'Identifier' ,
268314 name : 'foo' ,
315+ ...startEnd ,
269316 } ,
317+ ...startEnd ,
270318 } ,
319+ ...startEnd ,
271320 } ,
272321} ;
273322
@@ -282,13 +331,17 @@ export const AssignmentOfFooToBarVariableDeclarator: TestNodeExcerpt<VariableDec
282331 id : {
283332 type : 'Identifier' ,
284333 name : 'bar' ,
334+ ...startEnd ,
285335 } ,
286336 init : {
287337 type : 'Identifier' ,
288338 name : 'foo' ,
339+ ...startEnd ,
289340 } ,
341+ ...startEnd ,
290342 } ,
291343 ] ,
344+ ...startEnd ,
292345 } ,
293346} ;
294347
@@ -299,6 +352,7 @@ export const AssignmentOfFooToBarPropertyDefinition: TestNodeExcerpt<ClassDeclar
299352 id : {
300353 type : 'Identifier' ,
301354 name : 'baz' ,
355+ ...startEnd ,
302356 } ,
303357 superClass : null ,
304358 body : {
@@ -311,14 +365,19 @@ export const AssignmentOfFooToBarPropertyDefinition: TestNodeExcerpt<ClassDeclar
311365 key : {
312366 type : 'Identifier' ,
313367 name : 'bar' ,
368+ ...startEnd ,
314369 } ,
315370 value : {
316371 type : 'Identifier' ,
317372 name : 'foo' ,
373+ ...startEnd ,
318374 } ,
375+ ...startEnd ,
319376 } ,
320377 ] ,
378+ ...startEnd ,
321379 } ,
380+ ...startEnd ,
322381 } ,
323382} ;
324383
@@ -336,6 +395,7 @@ export const FixSimpleCallExpression: TestNodeExcerpt<FunctionDeclaration> = {
336395 id : {
337396 type : 'Identifier' ,
338397 name : 'bar' ,
398+ ...startEnd ,
339399 } ,
340400 expression : false ,
341401 generator : false ,
@@ -353,28 +413,37 @@ export const FixSimpleCallExpression: TestNodeExcerpt<FunctionDeclaration> = {
353413 id : {
354414 type : 'Identifier' ,
355415 name : 'a' ,
416+ ...startEnd ,
356417 } ,
357418 init : {
358419 type : 'CallExpression' ,
359420 callee : {
360421 type : 'Identifier' ,
361422 name : 'foo' ,
423+ ...startEnd ,
362424 } ,
363425 arguments : [ ] ,
364426 optional : false ,
427+ ...startEnd ,
365428 } ,
429+ ...startEnd ,
366430 } ,
367431 ] ,
432+ ...startEnd ,
368433 } ,
369434 {
370435 type : 'ReturnStatement' ,
371436 argument : {
372437 type : 'Identifier' ,
373438 name : 'a' ,
439+ ...startEnd ,
374440 } ,
441+ ...startEnd ,
375442 } ,
376443 ] ,
444+ ...startEnd ,
377445 } ,
446+ ...startEnd ,
378447 } ,
379448} ;
380449
@@ -395,6 +464,7 @@ export const ArrowFunctionDerefCallExpression: TestNodeExcerpt<VariableDeclarati
395464 id : {
396465 type : 'Identifier' ,
397466 name : 'bar' ,
467+ ...startEnd ,
398468 } ,
399469 init : {
400470 type : 'ArrowFunctionExpression' ,
@@ -413,25 +483,34 @@ export const ArrowFunctionDerefCallExpression: TestNodeExcerpt<VariableDeclarati
413483 {
414484 type : 'Literal' ,
415485 value : 0 ,
486+ ...startEnd ,
416487 } ,
417488 {
418489 type : 'MemberExpression' ,
419490 object : {
420491 type : 'Identifier' ,
421492 name : 'e' ,
493+ ...startEnd ,
422494 } ,
423495 property : {
424496 type : 'Identifier' ,
425497 name : 'foo' ,
498+ ...startEnd ,
426499 } ,
427500 computed : false ,
428501 optional : false ,
502+ ...startEnd ,
429503 } ,
430504 ] ,
505+ ...startEnd ,
431506 } ,
507+ ...startEnd ,
432508 } ,
509+ ...startEnd ,
433510 } ,
511+ ...startEnd ,
434512 } ,
435513 ] ,
514+ ...startEnd ,
436515 } ,
437516} ;
0 commit comments