hermes-parser 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,785 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow strict
8
- * @format
9
- */
10
-
11
- import type {
12
- HermesNode,
13
- HermesSourceLocation,
14
- HermesPosition,
15
- } from './HermesAST';
16
-
17
- import HermesASTAdapter from './HermesASTAdapter';
18
-
19
- declare var BigInt: ?(value: $FlowFixMe) => mixed;
20
-
21
- function createDefaultPosition(): HermesPosition {
22
- return {
23
- line: 1,
24
- column: 0,
25
- };
26
- }
27
-
28
- function createSyntaxError(node: HermesNode, err: string): SyntaxError {
29
- const syntaxError = new SyntaxError(err);
30
- // $FlowExpectedError[prop-missing]
31
- syntaxError.loc = {
32
- line: node.loc.start.line,
33
- column: node.loc.start.column,
34
- };
35
-
36
- return syntaxError;
37
- }
38
-
39
- export default class HermesToBabelAdapter extends HermesASTAdapter {
40
- fixSourceLocation(node: HermesNode): void {
41
- const loc = node.loc;
42
- if (loc == null) {
43
- return;
44
- }
45
-
46
- node.loc = {
47
- source: this.sourceFilename ?? null,
48
- start: loc.start,
49
- end: loc.end,
50
- };
51
-
52
- node.start = loc.rangeStart;
53
- node.end = loc.rangeEnd;
54
- }
55
-
56
- mapNode(node: HermesNode): HermesNode {
57
- this.fixSourceLocation(node);
58
- switch (node.type) {
59
- case 'Program':
60
- return this.mapProgram(node);
61
- case 'BlockStatement':
62
- return this.mapNodeWithDirectives(node);
63
- case 'Empty':
64
- return this.mapEmpty(node);
65
- case 'Identifier':
66
- return this.mapIdentifier(node);
67
- case 'TemplateElement':
68
- return this.mapTemplateElement(node);
69
- case 'GenericTypeAnnotation':
70
- return this.mapGenericTypeAnnotation(node);
71
- case 'SymbolTypeAnnotation':
72
- return this.mapSymbolTypeAnnotation(node);
73
- case 'Property':
74
- return this.mapProperty(node);
75
- case 'MethodDefinition':
76
- return this.mapMethodDefinition(node);
77
- case 'ImportDeclaration':
78
- return this.mapImportDeclaration(node);
79
- case 'ImportSpecifier':
80
- return this.mapImportSpecifier(node);
81
- case 'ExportDefaultDeclaration':
82
- return this.mapExportDefaultDeclaration(node);
83
- case 'ExportNamedDeclaration':
84
- return this.mapExportNamedDeclaration(node);
85
- case 'ExportNamespaceSpecifier':
86
- return this.mapExportNamespaceSpecifier(node);
87
- case 'ExportAllDeclaration':
88
- return this.mapExportAllDeclaration(node);
89
- case 'RestElement':
90
- return this.mapRestElement(node);
91
- case 'ImportExpression':
92
- return this.mapImportExpression(node);
93
- case 'JSXStringLiteral':
94
- return this.mapJSXStringLiteral(node);
95
- case 'PrivateName':
96
- return this.mapPrivateName(node);
97
- case 'ClassPrivateProperty':
98
- return this.mapPrivateProperty(node);
99
- case 'FunctionDeclaration':
100
- case 'FunctionExpression':
101
- return this.mapFunction(node);
102
- case 'IndexedAccessType':
103
- case 'OptionalIndexedAccessType':
104
- case 'KeyofTypeAnnotation':
105
- case 'ConditionalTypeAnnotation':
106
- case 'InferTypeAnnotation':
107
- case 'TupleTypeLabeledElement':
108
- case 'TupleTypeSpreadElement':
109
- case 'ObjectTypeMappedTypeProperty':
110
- case 'ComponentTypeAnnotation':
111
- case 'TypePredicate':
112
- return this.mapUnsupportedTypeAnnotation(node);
113
- case 'BigIntLiteral':
114
- return this.mapBigIntLiteral(node);
115
- case 'BigIntLiteralTypeAnnotation':
116
- return this.mapBigIntLiteralTypeAnnotation(node);
117
- case 'BigIntTypeAnnotation':
118
- return this.mapBigIntTypeAnnotation(node);
119
- case 'TypeofTypeAnnotation':
120
- return this.mapTypeofTypeAnnotation(node);
121
- case 'QualifiedTypeofIdentifier':
122
- return this.mapQualifiedTypeofIdentifier(node);
123
- case 'DeclareVariable':
124
- return this.mapDeclareVariable(node);
125
- case 'DeclareEnum':
126
- return this.mapDeclareEnum(node);
127
- case 'DeclareComponent':
128
- return this.mapDeclareComponent(node);
129
- case 'JSXElement':
130
- return this.mapJSXElement(node);
131
- case 'ComponentDeclaration':
132
- return this.mapComponentDeclaration(node);
133
- default:
134
- return this.mapNodeDefault(node);
135
- }
136
- }
137
-
138
- mapProgram(node: HermesNode): HermesNode {
139
- // Visit child nodes and convert to directives
140
- const {comments, ...program} = this.mapNodeWithDirectives(node);
141
-
142
- program.sourceType = this.getSourceType();
143
-
144
- // Adjust start loc to beginning of file
145
- program.loc.start = {line: 1, column: 0};
146
- program.start = 0;
147
-
148
- // Adjust end loc to include last comment if program ends with a comment
149
- if (comments.length > 0) {
150
- const lastComment = comments[comments.length - 1];
151
- if (lastComment.end > program.end) {
152
- program.loc.end = lastComment.loc.end;
153
- program.end = lastComment.end;
154
- }
155
- }
156
-
157
- // Rename root node to File node and move Program node under program property
158
- return {
159
- type: 'File',
160
- loc: program.loc,
161
- start: program.start,
162
- end: program.end,
163
- program,
164
- comments,
165
- };
166
- }
167
-
168
- mapNodeWithDirectives(node: HermesNode): HermesNode {
169
- const directives = [];
170
- for (const child of node.body) {
171
- if (child.type === 'ExpressionStatement' && child.directive != null) {
172
- // Visit directive children
173
- const directiveChild = this.mapNode(child);
174
-
175
- // Modify string literal node to be DirectiveLiteral node
176
- directiveChild.expression.type = 'DirectiveLiteral';
177
-
178
- // Construct Directive node with DirectiveLiteral value
179
- directives.push({
180
- type: 'Directive',
181
- loc: directiveChild.loc,
182
- start: directiveChild.start,
183
- end: directiveChild.end,
184
- value: directiveChild.expression,
185
- });
186
- } else {
187
- // Once we have found the first non-directive node we know there cannot be any more directives
188
- break;
189
- }
190
- }
191
-
192
- // Move directives from body to new directives array
193
- node.directives = directives;
194
- if (directives.length !== 0) {
195
- node.body = node.body.slice(directives.length);
196
- }
197
-
198
- // Visit expression statement children
199
- const body = node.body;
200
- for (let i = 0; i < body.length; i++) {
201
- const child = body[i];
202
- if (child != null) {
203
- body[i] = this.mapNode(child);
204
- }
205
- }
206
-
207
- return node;
208
- }
209
-
210
- mapIdentifier(node: HermesNode): HermesNode {
211
- node.loc.identifierName = node.name;
212
- return this.mapNodeDefault(node);
213
- }
214
-
215
- mapTemplateElement(node: HermesNode): HermesNode {
216
- // Adjust start loc to exclude "`" at beginning of template literal if this is the first quasi,
217
- // otherwise exclude "}" from previous expression.
218
- const startCharsToExclude = 1;
219
-
220
- // Adjust end loc to exclude "`" at end of template literal if this is the last quasi,
221
- // otherwise exclude "${" from next expression.
222
- const endCharsToExclude = node.tail ? 1 : 2;
223
-
224
- return {
225
- type: 'TemplateElement',
226
- loc: {
227
- start: {
228
- line: node.loc.start.line,
229
- column: node.loc.start.column + startCharsToExclude,
230
- },
231
- end: {
232
- line: node.loc.end.line,
233
- column: node.loc.end.column - endCharsToExclude,
234
- },
235
- },
236
- start: node.start + startCharsToExclude,
237
- end: node.end - endCharsToExclude,
238
- tail: node.tail,
239
- value: {
240
- cooked: node.cooked,
241
- raw: node.raw,
242
- },
243
- };
244
- }
245
-
246
- mapGenericTypeAnnotation(node: HermesNode): HermesNode {
247
- // Convert simple `this` generic type to ThisTypeAnnotation
248
- if (
249
- node.typeParameters == null &&
250
- node.id.type === 'Identifier' &&
251
- node.id.name === 'this'
252
- ) {
253
- return {
254
- type: 'ThisTypeAnnotation',
255
- loc: node.loc,
256
- start: node.start,
257
- end: node.end,
258
- };
259
- }
260
-
261
- return this.mapNodeDefault(node);
262
- }
263
-
264
- mapSymbolTypeAnnotation(node: HermesNode): HermesNode {
265
- return {
266
- type: 'GenericTypeAnnotation',
267
- loc: node.loc,
268
- start: node.start,
269
- end: node.end,
270
- id: {
271
- type: 'Identifier',
272
- loc: node.loc,
273
- start: node.start,
274
- end: node.end,
275
- name: 'symbol',
276
- },
277
- typeParameters: null,
278
- };
279
- }
280
-
281
- mapProperty(node: HermesNode): HermesNode {
282
- const key = this.mapNode(node.key);
283
- const value = this.mapNode(node.value);
284
-
285
- // Convert methods, getters, and setters to ObjectMethod nodes
286
- if (node.method || node.kind !== 'init') {
287
- // Properties under the FunctionExpression value that should be moved
288
- // to the ObjectMethod node itself.
289
- const {
290
- id,
291
- params,
292
- body,
293
- async,
294
- generator,
295
- returnType,
296
- typeParameters,
297
- predicate,
298
- } = value;
299
-
300
- const newNode: HermesNode = {
301
- type: 'ObjectMethod',
302
- loc: node.loc,
303
- start: node.start,
304
- end: node.end,
305
- // Non getter or setter methods have `kind = method`
306
- kind: node.kind === 'init' ? 'method' : node.kind,
307
- method: node.kind === 'init' ? true : false,
308
- computed: node.computed,
309
- key,
310
- id,
311
- params,
312
- body,
313
- async,
314
- generator,
315
- returnType,
316
- typeParameters,
317
- predicate,
318
- };
319
- if (node.kind !== 'init') {
320
- // babel emits an empty variance property on accessors for some reason
321
- newNode.variance = null;
322
- }
323
- return newNode;
324
- } else {
325
- // Non-method property nodes should be renamed to ObjectProperty
326
- node.type = 'ObjectProperty';
327
- return node;
328
- }
329
- }
330
-
331
- mapMethodDefinition(node: HermesNode): HermesNode {
332
- const key = this.mapNode(node.key);
333
- const value = this.mapNode(node.value);
334
-
335
- // Properties under the FunctionExpression value that should be moved
336
- // to the ClassMethod node itself.
337
- const {
338
- id,
339
- params,
340
- body,
341
- async,
342
- generator,
343
- returnType,
344
- typeParameters,
345
- predicate,
346
- } = value;
347
-
348
- return {
349
- type: key.type === 'PrivateName' ? 'ClassPrivateMethod' : 'ClassMethod',
350
- loc: node.loc,
351
- start: node.start,
352
- end: node.end,
353
- kind: node.kind,
354
- computed: node.computed,
355
- static: node.static,
356
- key,
357
- id,
358
- params,
359
- body,
360
- async,
361
- generator,
362
- returnType,
363
- typeParameters,
364
- predicate,
365
- };
366
- }
367
-
368
- mapRestElement(node: HermesNode): HermesNode {
369
- const restElement = this.mapNodeDefault(node);
370
-
371
- // Hermes puts type annotations on rest elements on the argument node,
372
- // but Babel expects type annotations on the rest element node itself.
373
- const annotation = restElement.argument.typeAnnotation;
374
- if (annotation != null) {
375
- restElement.typeAnnotation = annotation;
376
- restElement.argument.typeAnnotation = null;
377
- // Unfortunately there's no way for us to recover the end location of
378
- // the argument for the general case
379
- if (restElement.argument.type === 'Identifier') {
380
- restElement.argument.end =
381
- restElement.argument.start + restElement.argument.name.length;
382
- restElement.argument.loc.end = {
383
- ...restElement.argument.loc.start,
384
- column:
385
- restElement.argument.loc.start.column +
386
- restElement.argument.name.length,
387
- };
388
- }
389
- }
390
-
391
- return restElement;
392
- }
393
-
394
- mapImportExpression(node: HermesNode): HermesNode {
395
- // Babel expects ImportExpression to be structued as a regular
396
- // CallExpression where the callee is an Import node.
397
- return {
398
- type: 'CallExpression',
399
- loc: node.loc,
400
- start: node.start,
401
- end: node.end,
402
- callee: {
403
- type: 'Import',
404
- loc: {
405
- ...node.loc,
406
- end: {
407
- ...node.loc.start,
408
- column: node.loc.start.column + 'import'.length,
409
- },
410
- },
411
- start: node.start,
412
- end: node.start + 'import'.length,
413
- },
414
- arguments: [this.mapNode(node.source)],
415
- };
416
- }
417
-
418
- mapJSXStringLiteral(node: HermesNode): HermesNode {
419
- // Babel expects StringLiterals in JSX,
420
- // but Hermes uses JSXStringLiteral to attach the raw value without
421
- // having to internally attach it to every single string literal.
422
- return {
423
- type: 'StringLiteral',
424
- loc: node.loc,
425
- start: node.start,
426
- end: node.end,
427
- value: node.value,
428
- };
429
- }
430
-
431
- mapFunction(node: HermesNode): HermesNode {
432
- // Remove the first parameter if it is a this-type annotation,
433
- // which is not recognized by Babel.
434
- if (node.params.length !== 0 && node.params[0].name === 'this') {
435
- node.params.shift();
436
- }
437
-
438
- return this.mapNodeDefault(node);
439
- }
440
-
441
- /**
442
- * If Babel (the version we target) does not support a type annotation we
443
- * parse, we need to return some other valid type annotation in its place.
444
- */
445
- mapUnsupportedTypeAnnotation(node: HermesNode): HermesNode {
446
- return {
447
- type: 'AnyTypeAnnotation',
448
- loc: node.loc,
449
- start: node.start,
450
- end: node.end,
451
- };
452
- }
453
-
454
- mapBigIntLiteral(node: HermesNode): HermesNode {
455
- node.value = this.getBigIntLiteralValue(node.bigint).value;
456
- return node;
457
- }
458
- mapBigIntLiteralTypeAnnotation(node: HermesNode): HermesNode {
459
- node.value = this.getBigIntLiteralValue(node.raw).value;
460
- return node;
461
- }
462
- /**
463
- * Babel does not parse the bigint keyword type as the keyword node.
464
- * So we need to down-level the AST to a plain GenericTypeAnnotation
465
- */
466
- mapBigIntTypeAnnotation(node: HermesNode): HermesNode {
467
- return {
468
- type: 'GenericTypeAnnotation',
469
- id: {
470
- type: 'Identifier',
471
- name: 'bigint',
472
- loc: node.loc,
473
- start: node.start,
474
- end: node.end,
475
- },
476
- typeParameters: null,
477
- loc: node.loc,
478
- start: node.start,
479
- end: node.end,
480
- };
481
- }
482
-
483
- mapPrivateProperty(nodeUnprocessed: HermesNode): HermesNode {
484
- const node = this.mapNodeDefault(nodeUnprocessed);
485
- node.key = {
486
- type: 'PrivateName',
487
- id: {
488
- ...node.key,
489
- // babel doesn't include the hash in the identifier
490
- start: node.key.start + 1,
491
- loc: {
492
- ...node.key.loc,
493
- start: {
494
- ...node.key.loc.start,
495
- column: node.key.loc.start.column + 1,
496
- },
497
- },
498
- },
499
- start: node.key.start,
500
- end: node.key.end,
501
- loc: node.key.loc,
502
- };
503
-
504
- return node;
505
- }
506
-
507
- mapPrivateName(node: HermesNode): HermesNode {
508
- // babel doesn't include the hash in the identifier
509
- node.id.start += 1;
510
- node.id.loc.start.column += 1;
511
- return node;
512
- }
513
-
514
- mapExportNamespaceSpecifier(nodeUnprocessed: HermesNode): HermesNode {
515
- const node = this.mapNodeDefault(nodeUnprocessed);
516
-
517
- // the hermes AST emits the location as the location of the entire export
518
- // but babel emits the location as *just* the "* as id" bit
519
-
520
- // the end will always align with the end of the identifier (ezpz)
521
- // but the start will align with the "*" token - which we can't recover from just the AST
522
- // so we just fudge the start location a bit to get it "good enough"
523
- // it will be wrong if the AST is anything like "export * as x from 'y'"... but oh well
524
- node.start = node.start + 'export '.length;
525
- node.loc.start.column = node.loc.start.column + 'export '.length;
526
- node.end = node.exported.end;
527
- node.loc.end = {
528
- column: node.exported.loc.end.column,
529
- line: node.exported.loc.end.line,
530
- };
531
-
532
- return node;
533
- }
534
-
535
- mapTypeofTypeAnnotation(nodeUnprocessed: HermesNode): HermesNode {
536
- nodeUnprocessed.argument = {
537
- type: 'GenericTypeAnnotation',
538
- id: nodeUnprocessed.argument,
539
- typeParameters: null,
540
- loc: nodeUnprocessed.argument.loc,
541
- };
542
-
543
- return this.mapNodeDefault(nodeUnprocessed);
544
- }
545
-
546
- mapQualifiedTypeofIdentifier(nodeUnprocessed: HermesNode): HermesNode {
547
- nodeUnprocessed.type = 'QualifiedTypeIdentifier';
548
-
549
- return this.mapNodeDefault(nodeUnprocessed);
550
- }
551
-
552
- mapDeclareVariable(nodeUnprocessed: HermesNode): HermesNode {
553
- delete nodeUnprocessed.kind;
554
-
555
- return this.mapNodeDefault(nodeUnprocessed);
556
- }
557
-
558
- mapDeclareEnum(nodeUnprocessed: HermesNode): HermesNode {
559
- nodeUnprocessed.id.typeAnnotation = this.mapUnsupportedTypeAnnotation(
560
- nodeUnprocessed.body,
561
- );
562
-
563
- delete nodeUnprocessed.body;
564
-
565
- nodeUnprocessed.type = 'DeclareVariable';
566
-
567
- return this.mapDeclareVariable(nodeUnprocessed);
568
- }
569
-
570
- mapDeclareComponent(nodeUnprocessed: HermesNode): HermesNode {
571
- nodeUnprocessed.id.typeAnnotation =
572
- this.mapUnsupportedTypeAnnotation(nodeUnprocessed);
573
-
574
- delete nodeUnprocessed.params;
575
- delete nodeUnprocessed.rest;
576
- delete nodeUnprocessed.typeParameters;
577
- delete nodeUnprocessed.rendersType;
578
-
579
- nodeUnprocessed.type = 'DeclareVariable';
580
-
581
- return this.mapDeclareVariable(nodeUnprocessed);
582
- }
583
-
584
- mapJSXElement(nodeUnprocessed: HermesNode): HermesNode {
585
- delete nodeUnprocessed.openingElement.typeArguments;
586
- return this.mapNodeDefault(nodeUnprocessed);
587
- }
588
-
589
- mapComponentDeclaration(nodeUnprocessed: HermesNode): HermesNode {
590
- let rendersType = nodeUnprocessed.rendersType;
591
- if (rendersType == null) {
592
- // Create empty loc for return type annotation nodes
593
- const createRendersTypeLoc = () => ({
594
- loc: {
595
- start: {...nodeUnprocessed.body.loc.end},
596
- end: {...nodeUnprocessed.body.loc.end},
597
- rangeStart: nodeUnprocessed.body.loc.rangeStart,
598
- rangeEnd: nodeUnprocessed.body.loc.rangeEnd,
599
- },
600
- });
601
-
602
- rendersType = {
603
- type: 'TypeAnnotation',
604
- typeAnnotation: {
605
- type: 'GenericTypeAnnotation',
606
- id: {
607
- type: 'QualifiedTypeIdentifier',
608
- qualification: {
609
- type: 'Identifier',
610
- name: 'React',
611
- ...createRendersTypeLoc(),
612
- },
613
- id: {
614
- type: 'Identifier',
615
- name: 'Node',
616
- ...createRendersTypeLoc(),
617
- },
618
- },
619
- typeParameters: null,
620
- ...createRendersTypeLoc(),
621
- },
622
- ...createRendersTypeLoc(),
623
- };
624
- }
625
-
626
- function getParamName(paramName: HermesNode): string {
627
- switch (paramName.type) {
628
- case 'Identifier':
629
- return paramName.name;
630
- case 'StringLiteral':
631
- return paramName.value;
632
- default:
633
- throw createSyntaxError(
634
- paramName,
635
- `Unknown Component parameter name type of "${paramName.type}"`,
636
- );
637
- }
638
- }
639
-
640
- function createPropsTypeAnnotation(loc: HermesSourceLocation) {
641
- // Create empty loc for type annotation nodes
642
- const createParamsTypeLoc = () => ({
643
- loc: {
644
- start: loc.start != null ? {...loc.start} : createDefaultPosition(),
645
- end: loc.end != null ? {...loc.end} : createDefaultPosition(),
646
- rangeStart: loc.rangeStart,
647
- rangeEnd: loc.rangeEnd,
648
- },
649
- });
650
-
651
- return {
652
- type: 'TypeAnnotation',
653
- typeAnnotation: {
654
- type: 'GenericTypeAnnotation',
655
- id: {
656
- type: 'Identifier',
657
- name: '$ReadOnly',
658
- ...createParamsTypeLoc(),
659
- },
660
- typeParameters: {
661
- type: 'TypeParameterInstantiation',
662
- params: [
663
- {
664
- type: 'ObjectTypeAnnotation',
665
- callProperties: [],
666
- properties: [],
667
- indexers: [],
668
- internalSlots: [],
669
- exact: false,
670
- inexact: true,
671
- ...createParamsTypeLoc(),
672
- },
673
- ],
674
- ...createParamsTypeLoc(),
675
- },
676
- ...createParamsTypeLoc(),
677
- },
678
- ...createParamsTypeLoc(),
679
- };
680
- }
681
-
682
- const params = (() => {
683
- if (nodeUnprocessed.params.length === 0) {
684
- return [];
685
- }
686
-
687
- // Optimize `component Foo(...props: Props) {}` to `function Foo(props: Props) {}
688
- if (
689
- nodeUnprocessed.params.length === 1 &&
690
- nodeUnprocessed.params[0].type === 'RestElement'
691
- ) {
692
- const restElement = nodeUnprocessed.params[0];
693
- return [
694
- {
695
- ...restElement.argument,
696
- typeAnnotation: createPropsTypeAnnotation(
697
- restElement.argument.typeAnnotation.loc,
698
- ),
699
- },
700
- ];
701
- }
702
-
703
- const properties = nodeUnprocessed.params.map(param => {
704
- switch (param.type) {
705
- case 'RestElement': {
706
- delete param.typeAnnotation;
707
- return param;
708
- }
709
- case 'ComponentParameter': {
710
- if (getParamName(param.name) === 'ref') {
711
- throw createSyntaxError(
712
- param,
713
- 'Component parameters named "ref" are currently not supported',
714
- );
715
- }
716
-
717
- if (param.name.type === 'Identifier') {
718
- delete param.name.typeAnnotation;
719
- }
720
- if (param.local.type === 'AssignmentPattern') {
721
- delete param.local.left.typeAnnotation;
722
- delete param.local.left.optional;
723
- } else {
724
- delete param.local.typeAnnotation;
725
- delete param.local.optional;
726
- }
727
-
728
- return {
729
- type: 'ObjectProperty',
730
- key: param.name,
731
- value: param.local,
732
- method: false,
733
- shorthand: param.shorthand,
734
- computed: false,
735
- loc: param.loc,
736
- start: param.start,
737
- end: param.end,
738
- };
739
- }
740
- default: {
741
- throw createSyntaxError(
742
- param,
743
- `Unknown Component parameter type of "${param.type}"`,
744
- );
745
- }
746
- }
747
- });
748
-
749
- const paramsLoc = {
750
- start: properties[0].loc.start,
751
- end: properties[properties.length - 1].loc.end,
752
- rangeStart: properties[0].loc.rangeStart,
753
- rangeEnd: properties[properties.length - 1].loc.rangeEnd,
754
- };
755
-
756
- return [
757
- {
758
- type: 'ObjectPattern',
759
- properties,
760
- typeAnnotation: createPropsTypeAnnotation({
761
- ...paramsLoc,
762
- start: paramsLoc.end,
763
- rangeStart: paramsLoc.rangeEnd,
764
- }),
765
- loc: paramsLoc,
766
- },
767
- ];
768
- })();
769
-
770
- const functionComponent = {
771
- type: 'FunctionDeclaration',
772
- id: nodeUnprocessed.id,
773
- typeParameters: nodeUnprocessed.typeParameters,
774
- params,
775
- returnType: rendersType,
776
- body: nodeUnprocessed.body,
777
- async: false,
778
- generator: false,
779
- predicate: null,
780
- loc: nodeUnprocessed.loc,
781
- };
782
-
783
- return this.mapNodeDefault(functionComponent);
784
- }
785
- }