hermes-parser 0.12.1 → 0.13.1
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.
- package/dist/HermesAST.js.flow +4 -4
- package/dist/HermesParserWASM.js +1 -1
- package/dist/HermesToBabelAdapter.js +116 -98
- package/dist/HermesToBabelAdapter.js.flow +148 -119
- package/dist/ParserOptions.js +18 -0
- package/dist/ParserOptions.js.flow +10 -0
- package/dist/generated/ESTreeVisitorKeys.js +1 -1
- package/dist/generated/ParserVisitorKeys.js +1 -2
- package/dist/index.js +9 -0
- package/dist/index.js.flow +1 -0
- package/dist/transform/astNodeMutationHelpers.js +3 -3
- package/dist/transform/astNodeMutationHelpers.js.flow +3 -7
- package/dist/traverse/SimpleTraverser.js +0 -1
- package/dist/traverse/SimpleTraverser.js.flow +3 -2
- package/package.json +3 -2
|
@@ -18,6 +18,13 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
18
18
|
*
|
|
19
19
|
* @format
|
|
20
20
|
*/
|
|
21
|
+
function createDefaultPosition() {
|
|
22
|
+
return {
|
|
23
|
+
line: 1,
|
|
24
|
+
column: 0
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
21
28
|
function createSyntaxError(node, err) {
|
|
22
29
|
const syntaxError = new SyntaxError(err); // $FlowExpectedError[prop-missing]
|
|
23
30
|
|
|
@@ -118,8 +125,8 @@ class HermesToBabelAdapter extends _HermesASTAdapter.default {
|
|
|
118
125
|
case 'IndexedAccessType':
|
|
119
126
|
case 'OptionalIndexedAccessType':
|
|
120
127
|
case 'KeyofTypeAnnotation':
|
|
121
|
-
case '
|
|
122
|
-
case '
|
|
128
|
+
case 'ConditionalTypeAnnotation':
|
|
129
|
+
case 'InferTypeAnnotation':
|
|
123
130
|
case 'TupleTypeLabeledElement':
|
|
124
131
|
case 'TupleTypeSpreadElement':
|
|
125
132
|
case 'ObjectTypeMappedTypeProperty':
|
|
@@ -606,21 +613,25 @@ class HermesToBabelAdapter extends _HermesASTAdapter.default {
|
|
|
606
613
|
});
|
|
607
614
|
|
|
608
615
|
rendersType = {
|
|
609
|
-
type: '
|
|
610
|
-
|
|
611
|
-
type: '
|
|
612
|
-
qualification: {
|
|
613
|
-
type: 'Identifier',
|
|
614
|
-
name: 'React',
|
|
615
|
-
...createRendersTypeLoc()
|
|
616
|
-
},
|
|
616
|
+
type: 'TypeAnnotation',
|
|
617
|
+
typeAnnotation: {
|
|
618
|
+
type: 'GenericTypeAnnotation',
|
|
617
619
|
id: {
|
|
618
|
-
type: '
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
620
|
+
type: 'QualifiedTypeIdentifier',
|
|
621
|
+
qualification: {
|
|
622
|
+
type: 'Identifier',
|
|
623
|
+
name: 'React',
|
|
624
|
+
...createRendersTypeLoc()
|
|
625
|
+
},
|
|
626
|
+
id: {
|
|
627
|
+
type: 'Identifier',
|
|
628
|
+
name: 'Node',
|
|
629
|
+
...createRendersTypeLoc()
|
|
630
|
+
}
|
|
631
|
+
},
|
|
632
|
+
typeParameters: null,
|
|
633
|
+
...createRendersTypeLoc()
|
|
622
634
|
},
|
|
623
|
-
typeParameters: null,
|
|
624
635
|
...createRendersTypeLoc()
|
|
625
636
|
};
|
|
626
637
|
}
|
|
@@ -638,88 +649,20 @@ class HermesToBabelAdapter extends _HermesASTAdapter.default {
|
|
|
638
649
|
}
|
|
639
650
|
}
|
|
640
651
|
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
if (param.name.type === 'Identifier') {
|
|
656
|
-
delete param.name.typeAnnotation;
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
if (param.local.type === 'AssignmentPattern') {
|
|
660
|
-
delete param.local.left.typeAnnotation;
|
|
661
|
-
delete param.local.left.optional;
|
|
662
|
-
} else {
|
|
663
|
-
delete param.local.typeAnnotation;
|
|
664
|
-
delete param.local.optional;
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
return {
|
|
668
|
-
type: 'ObjectProperty',
|
|
669
|
-
key: param.name,
|
|
670
|
-
value: param.local,
|
|
671
|
-
method: false,
|
|
672
|
-
shorthand: param.shorthand,
|
|
673
|
-
computed: false,
|
|
674
|
-
loc: param.loc,
|
|
675
|
-
start: param.start,
|
|
676
|
-
end: param.end
|
|
677
|
-
};
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
default:
|
|
681
|
-
{
|
|
682
|
-
throw createSyntaxError(param, `Unknown Component parameter type of "${param.type}"`);
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
});
|
|
686
|
-
|
|
687
|
-
const paramsLoc = (() => {
|
|
688
|
-
if (properties.length === 0) {
|
|
689
|
-
// No props, approximate range via existing nodes.
|
|
690
|
-
const startLoc = nodeUnprocessed.typeParameters != null ? nodeUnprocessed.typeParameters.loc : nodeUnprocessed.id.loc;
|
|
691
|
-
return {
|
|
692
|
-
start: startLoc.end,
|
|
693
|
-
end: rendersType.loc.start,
|
|
694
|
-
startRange: startLoc.endRange,
|
|
695
|
-
endRange: rendersType.loc.startRange
|
|
696
|
-
};
|
|
697
|
-
}
|
|
652
|
+
function createPropsTypeAnnotation(loc) {
|
|
653
|
+
// Create empty loc for type annotation nodes
|
|
654
|
+
const createParamsTypeLoc = () => ({
|
|
655
|
+
loc: {
|
|
656
|
+
start: loc.start != null ? { ...loc.start
|
|
657
|
+
} : createDefaultPosition(),
|
|
658
|
+
end: loc.end != null ? { ...loc.end
|
|
659
|
+
} : createDefaultPosition(),
|
|
660
|
+
rangeStart: loc.rangeStart,
|
|
661
|
+
rangeEnd: loc.rangeEnd
|
|
662
|
+
}
|
|
663
|
+
});
|
|
698
664
|
|
|
699
665
|
return {
|
|
700
|
-
start: properties[0].loc.start,
|
|
701
|
-
end: properties[properties.length - 1].loc.end,
|
|
702
|
-
startRange: properties[0].loc.startRange,
|
|
703
|
-
endRange: properties[properties.length - 1].loc.endRange
|
|
704
|
-
};
|
|
705
|
-
})(); // Create empty loc for type annotation nodes
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
const createParamsTypeLoc = () => ({
|
|
709
|
-
loc: {
|
|
710
|
-
start: { ...paramsLoc.end
|
|
711
|
-
},
|
|
712
|
-
end: { ...paramsLoc.end
|
|
713
|
-
},
|
|
714
|
-
startRange: paramsLoc.endRange,
|
|
715
|
-
endRange: paramsLoc.endRange
|
|
716
|
-
}
|
|
717
|
-
});
|
|
718
|
-
|
|
719
|
-
const params = [{
|
|
720
|
-
type: 'ObjectPattern',
|
|
721
|
-
properties,
|
|
722
|
-
typeAnnotation: {
|
|
723
666
|
type: 'TypeAnnotation',
|
|
724
667
|
typeAnnotation: {
|
|
725
668
|
type: 'GenericTypeAnnotation',
|
|
@@ -745,9 +688,84 @@ class HermesToBabelAdapter extends _HermesASTAdapter.default {
|
|
|
745
688
|
...createParamsTypeLoc()
|
|
746
689
|
},
|
|
747
690
|
...createParamsTypeLoc()
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
const params = (() => {
|
|
695
|
+
if (nodeUnprocessed.params.length === 0) {
|
|
696
|
+
return [];
|
|
697
|
+
} // Optimize `component Foo(...props: Props) {}` to `function Foo(props: Props) {}
|
|
698
|
+
|
|
699
|
+
|
|
700
|
+
if (nodeUnprocessed.params.length === 1 && nodeUnprocessed.params[0].type === 'RestElement') {
|
|
701
|
+
const restElement = nodeUnprocessed.params[0];
|
|
702
|
+
return [{ ...restElement.argument,
|
|
703
|
+
typeAnnotation: createPropsTypeAnnotation(restElement.argument.typeAnnotation.loc)
|
|
704
|
+
}];
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
const properties = nodeUnprocessed.params.map(param => {
|
|
708
|
+
switch (param.type) {
|
|
709
|
+
case 'RestElement':
|
|
710
|
+
{
|
|
711
|
+
delete param.typeAnnotation;
|
|
712
|
+
return param;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
case 'ComponentParameter':
|
|
716
|
+
{
|
|
717
|
+
if (getParamName(param.name) === 'ref') {
|
|
718
|
+
throw createSyntaxError(param, 'Component parameters named "ref" are currently not supported');
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
if (param.name.type === 'Identifier') {
|
|
722
|
+
delete param.name.typeAnnotation;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
if (param.local.type === 'AssignmentPattern') {
|
|
726
|
+
delete param.local.left.typeAnnotation;
|
|
727
|
+
delete param.local.left.optional;
|
|
728
|
+
} else {
|
|
729
|
+
delete param.local.typeAnnotation;
|
|
730
|
+
delete param.local.optional;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
return {
|
|
734
|
+
type: 'ObjectProperty',
|
|
735
|
+
key: param.name,
|
|
736
|
+
value: param.local,
|
|
737
|
+
method: false,
|
|
738
|
+
shorthand: param.shorthand,
|
|
739
|
+
computed: false,
|
|
740
|
+
loc: param.loc,
|
|
741
|
+
start: param.start,
|
|
742
|
+
end: param.end
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
default:
|
|
747
|
+
{
|
|
748
|
+
throw createSyntaxError(param, `Unknown Component parameter type of "${param.type}"`);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
});
|
|
752
|
+
const paramsLoc = {
|
|
753
|
+
start: properties[0].loc.start,
|
|
754
|
+
end: properties[properties.length - 1].loc.end,
|
|
755
|
+
rangeStart: properties[0].loc.rangeStart,
|
|
756
|
+
rangeEnd: properties[properties.length - 1].loc.rangeEnd
|
|
757
|
+
};
|
|
758
|
+
return [{
|
|
759
|
+
type: 'ObjectPattern',
|
|
760
|
+
properties,
|
|
761
|
+
typeAnnotation: createPropsTypeAnnotation({ ...paramsLoc,
|
|
762
|
+
start: paramsLoc.end,
|
|
763
|
+
rangeStart: paramsLoc.rangeEnd
|
|
764
|
+
}),
|
|
765
|
+
loc: paramsLoc
|
|
766
|
+
}];
|
|
767
|
+
})();
|
|
768
|
+
|
|
751
769
|
const functionComponent = {
|
|
752
770
|
type: 'FunctionDeclaration',
|
|
753
771
|
id: nodeUnprocessed.id,
|
|
@@ -8,12 +8,23 @@
|
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
HermesNode,
|
|
13
|
+
HermesSourceLocation,
|
|
14
|
+
HermesPosition,
|
|
15
|
+
} from './HermesAST';
|
|
12
16
|
|
|
13
17
|
import HermesASTAdapter from './HermesASTAdapter';
|
|
14
18
|
|
|
15
19
|
declare var BigInt: ?(value: $FlowFixMe) => mixed;
|
|
16
20
|
|
|
21
|
+
function createDefaultPosition(): HermesPosition {
|
|
22
|
+
return {
|
|
23
|
+
line: 1,
|
|
24
|
+
column: 0,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
17
28
|
function createSyntaxError(node: HermesNode, err: string): SyntaxError {
|
|
18
29
|
const syntaxError = new SyntaxError(err);
|
|
19
30
|
// $FlowExpectedError[prop-missing]
|
|
@@ -91,8 +102,8 @@ export default class HermesToBabelAdapter extends HermesASTAdapter {
|
|
|
91
102
|
case 'IndexedAccessType':
|
|
92
103
|
case 'OptionalIndexedAccessType':
|
|
93
104
|
case 'KeyofTypeAnnotation':
|
|
94
|
-
case '
|
|
95
|
-
case '
|
|
105
|
+
case 'ConditionalTypeAnnotation':
|
|
106
|
+
case 'InferTypeAnnotation':
|
|
96
107
|
case 'TupleTypeLabeledElement':
|
|
97
108
|
case 'TupleTypeSpreadElement':
|
|
98
109
|
case 'ObjectTypeMappedTypeProperty':
|
|
@@ -588,21 +599,25 @@ export default class HermesToBabelAdapter extends HermesASTAdapter {
|
|
|
588
599
|
});
|
|
589
600
|
|
|
590
601
|
rendersType = {
|
|
591
|
-
type: '
|
|
592
|
-
|
|
593
|
-
type: '
|
|
594
|
-
qualification: {
|
|
595
|
-
type: 'Identifier',
|
|
596
|
-
name: 'React',
|
|
597
|
-
...createRendersTypeLoc(),
|
|
598
|
-
},
|
|
602
|
+
type: 'TypeAnnotation',
|
|
603
|
+
typeAnnotation: {
|
|
604
|
+
type: 'GenericTypeAnnotation',
|
|
599
605
|
id: {
|
|
600
|
-
type: '
|
|
601
|
-
|
|
602
|
-
|
|
606
|
+
type: 'QualifiedTypeIdentifier',
|
|
607
|
+
qualification: {
|
|
608
|
+
type: 'Identifier',
|
|
609
|
+
name: 'React',
|
|
610
|
+
...createRendersTypeLoc(),
|
|
611
|
+
},
|
|
612
|
+
id: {
|
|
613
|
+
type: 'Identifier',
|
|
614
|
+
name: 'Node',
|
|
615
|
+
...createRendersTypeLoc(),
|
|
616
|
+
},
|
|
603
617
|
},
|
|
618
|
+
typeParameters: null,
|
|
619
|
+
...createRendersTypeLoc(),
|
|
604
620
|
},
|
|
605
|
-
typeParameters: null,
|
|
606
621
|
...createRendersTypeLoc(),
|
|
607
622
|
};
|
|
608
623
|
}
|
|
@@ -621,121 +636,135 @@ export default class HermesToBabelAdapter extends HermesASTAdapter {
|
|
|
621
636
|
}
|
|
622
637
|
}
|
|
623
638
|
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
639
|
+
function createPropsTypeAnnotation(loc: HermesSourceLocation) {
|
|
640
|
+
// Create empty loc for type annotation nodes
|
|
641
|
+
const createParamsTypeLoc = () => ({
|
|
642
|
+
loc: {
|
|
643
|
+
start: loc.start != null ? {...loc.start} : createDefaultPosition(),
|
|
644
|
+
end: loc.end != null ? {...loc.end} : createDefaultPosition(),
|
|
645
|
+
rangeStart: loc.rangeStart,
|
|
646
|
+
rangeEnd: loc.rangeEnd,
|
|
647
|
+
},
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
return {
|
|
651
|
+
type: 'TypeAnnotation',
|
|
652
|
+
typeAnnotation: {
|
|
653
|
+
type: 'GenericTypeAnnotation',
|
|
654
|
+
id: {
|
|
655
|
+
type: 'Identifier',
|
|
656
|
+
name: '$ReadOnly',
|
|
657
|
+
...createParamsTypeLoc(),
|
|
658
|
+
},
|
|
659
|
+
typeParameters: {
|
|
660
|
+
type: 'TypeParameterInstantiation',
|
|
661
|
+
params: [
|
|
662
|
+
{
|
|
663
|
+
type: 'ObjectTypeAnnotation',
|
|
664
|
+
callProperties: [],
|
|
665
|
+
properties: [],
|
|
666
|
+
indexers: [],
|
|
667
|
+
internalSlots: [],
|
|
668
|
+
exact: false,
|
|
669
|
+
inexact: true,
|
|
670
|
+
...createParamsTypeLoc(),
|
|
671
|
+
},
|
|
672
|
+
],
|
|
673
|
+
...createParamsTypeLoc(),
|
|
674
|
+
},
|
|
675
|
+
...createParamsTypeLoc(),
|
|
676
|
+
},
|
|
677
|
+
...createParamsTypeLoc(),
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
const params = (() => {
|
|
682
|
+
if (nodeUnprocessed.params.length === 0) {
|
|
683
|
+
return [];
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// Optimize `component Foo(...props: Props) {}` to `function Foo(props: Props) {}
|
|
687
|
+
if (
|
|
688
|
+
nodeUnprocessed.params.length === 1 &&
|
|
689
|
+
nodeUnprocessed.params[0].type === 'RestElement'
|
|
690
|
+
) {
|
|
691
|
+
const restElement = nodeUnprocessed.params[0];
|
|
692
|
+
return [
|
|
693
|
+
{
|
|
694
|
+
...restElement.argument,
|
|
695
|
+
typeAnnotation: createPropsTypeAnnotation(
|
|
696
|
+
restElement.argument.typeAnnotation.loc,
|
|
697
|
+
),
|
|
698
|
+
},
|
|
699
|
+
];
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
const properties = nodeUnprocessed.params.map(param => {
|
|
703
|
+
switch (param.type) {
|
|
704
|
+
case 'RestElement': {
|
|
705
|
+
delete param.typeAnnotation;
|
|
706
|
+
return param;
|
|
707
|
+
}
|
|
708
|
+
case 'ComponentParameter': {
|
|
709
|
+
if (getParamName(param.name) === 'ref') {
|
|
710
|
+
throw createSyntaxError(
|
|
711
|
+
param,
|
|
712
|
+
'Component parameters named "ref" are currently not supported',
|
|
713
|
+
);
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
if (param.name.type === 'Identifier') {
|
|
717
|
+
delete param.name.typeAnnotation;
|
|
718
|
+
}
|
|
719
|
+
if (param.local.type === 'AssignmentPattern') {
|
|
720
|
+
delete param.local.left.typeAnnotation;
|
|
721
|
+
delete param.local.left.optional;
|
|
722
|
+
} else {
|
|
723
|
+
delete param.local.typeAnnotation;
|
|
724
|
+
delete param.local.optional;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
return {
|
|
728
|
+
type: 'ObjectProperty',
|
|
729
|
+
key: param.name,
|
|
730
|
+
value: param.local,
|
|
731
|
+
method: false,
|
|
732
|
+
shorthand: param.shorthand,
|
|
733
|
+
computed: false,
|
|
734
|
+
loc: param.loc,
|
|
735
|
+
start: param.start,
|
|
736
|
+
end: param.end,
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
default: {
|
|
632
740
|
throw createSyntaxError(
|
|
633
741
|
param,
|
|
634
|
-
|
|
742
|
+
`Unknown Component parameter type of "${param.type}"`,
|
|
635
743
|
);
|
|
636
744
|
}
|
|
637
|
-
|
|
638
|
-
if (param.name.type === 'Identifier') {
|
|
639
|
-
delete param.name.typeAnnotation;
|
|
640
|
-
}
|
|
641
|
-
if (param.local.type === 'AssignmentPattern') {
|
|
642
|
-
delete param.local.left.typeAnnotation;
|
|
643
|
-
delete param.local.left.optional;
|
|
644
|
-
} else {
|
|
645
|
-
delete param.local.typeAnnotation;
|
|
646
|
-
delete param.local.optional;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
return {
|
|
650
|
-
type: 'ObjectProperty',
|
|
651
|
-
key: param.name,
|
|
652
|
-
value: param.local,
|
|
653
|
-
method: false,
|
|
654
|
-
shorthand: param.shorthand,
|
|
655
|
-
computed: false,
|
|
656
|
-
loc: param.loc,
|
|
657
|
-
start: param.start,
|
|
658
|
-
end: param.end,
|
|
659
|
-
};
|
|
660
|
-
}
|
|
661
|
-
default: {
|
|
662
|
-
throw createSyntaxError(
|
|
663
|
-
param,
|
|
664
|
-
`Unknown Component parameter type of "${param.type}"`,
|
|
665
|
-
);
|
|
666
745
|
}
|
|
667
|
-
}
|
|
668
|
-
});
|
|
669
|
-
|
|
670
|
-
const paramsLoc = (() => {
|
|
671
|
-
if (properties.length === 0) {
|
|
672
|
-
// No props, approximate range via existing nodes.
|
|
673
|
-
const startLoc =
|
|
674
|
-
nodeUnprocessed.typeParameters != null
|
|
675
|
-
? nodeUnprocessed.typeParameters.loc
|
|
676
|
-
: nodeUnprocessed.id.loc;
|
|
677
|
-
return {
|
|
678
|
-
start: startLoc.end,
|
|
679
|
-
end: rendersType.loc.start,
|
|
680
|
-
startRange: startLoc.endRange,
|
|
681
|
-
endRange: rendersType.loc.startRange,
|
|
682
|
-
};
|
|
683
|
-
}
|
|
746
|
+
});
|
|
684
747
|
|
|
685
|
-
|
|
748
|
+
const paramsLoc = {
|
|
686
749
|
start: properties[0].loc.start,
|
|
687
750
|
end: properties[properties.length - 1].loc.end,
|
|
688
|
-
|
|
689
|
-
|
|
751
|
+
rangeStart: properties[0].loc.rangeStart,
|
|
752
|
+
rangeEnd: properties[properties.length - 1].loc.rangeEnd,
|
|
690
753
|
};
|
|
691
|
-
})();
|
|
692
|
-
|
|
693
|
-
// Create empty loc for type annotation nodes
|
|
694
|
-
const createParamsTypeLoc = () => ({
|
|
695
|
-
loc: {
|
|
696
|
-
start: {...paramsLoc.end},
|
|
697
|
-
end: {...paramsLoc.end},
|
|
698
|
-
startRange: paramsLoc.endRange,
|
|
699
|
-
endRange: paramsLoc.endRange,
|
|
700
|
-
},
|
|
701
|
-
});
|
|
702
754
|
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
name: '$ReadOnly',
|
|
714
|
-
...createParamsTypeLoc(),
|
|
715
|
-
},
|
|
716
|
-
typeParameters: {
|
|
717
|
-
type: 'TypeParameterInstantiation',
|
|
718
|
-
params: [
|
|
719
|
-
{
|
|
720
|
-
type: 'ObjectTypeAnnotation',
|
|
721
|
-
callProperties: [],
|
|
722
|
-
properties: [],
|
|
723
|
-
indexers: [],
|
|
724
|
-
internalSlots: [],
|
|
725
|
-
exact: false,
|
|
726
|
-
inexact: true,
|
|
727
|
-
...createParamsTypeLoc(),
|
|
728
|
-
},
|
|
729
|
-
],
|
|
730
|
-
...createParamsTypeLoc(),
|
|
731
|
-
},
|
|
732
|
-
...createParamsTypeLoc(),
|
|
733
|
-
},
|
|
734
|
-
...createParamsTypeLoc(),
|
|
755
|
+
return [
|
|
756
|
+
{
|
|
757
|
+
type: 'ObjectPattern',
|
|
758
|
+
properties,
|
|
759
|
+
typeAnnotation: createPropsTypeAnnotation({
|
|
760
|
+
...paramsLoc,
|
|
761
|
+
start: paramsLoc.end,
|
|
762
|
+
rangeStart: paramsLoc.rangeEnd,
|
|
763
|
+
}),
|
|
764
|
+
loc: paramsLoc,
|
|
735
765
|
},
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
];
|
|
766
|
+
];
|
|
767
|
+
})();
|
|
739
768
|
|
|
740
769
|
const functionComponent = {
|
|
741
770
|
type: 'FunctionDeclaration',
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ParserOptionsKeys = void 0;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
10
|
+
*
|
|
11
|
+
* This source code is licensed under the MIT license found in the
|
|
12
|
+
* LICENSE file in the root directory of this source tree.
|
|
13
|
+
*
|
|
14
|
+
*
|
|
15
|
+
* @format
|
|
16
|
+
*/
|
|
17
|
+
const ParserOptionsKeys = new Set(['allowReturnOutsideFunction', 'babel', 'flow', 'enableExperimentalComponentSyntax', 'sourceFilename', 'sourceType', 'tokens']);
|
|
18
|
+
exports.ParserOptionsKeys = ParserOptionsKeys;
|
|
@@ -17,3 +17,13 @@ export type ParserOptions = {
|
|
|
17
17
|
sourceType?: 'module' | 'script' | 'unambiguous',
|
|
18
18
|
tokens?: boolean,
|
|
19
19
|
};
|
|
20
|
+
|
|
21
|
+
export const ParserOptionsKeys: $ReadOnlySet<$Keys<ParserOptions>> = new Set([
|
|
22
|
+
'allowReturnOutsideFunction',
|
|
23
|
+
'babel',
|
|
24
|
+
'flow',
|
|
25
|
+
'enableExperimentalComponentSyntax',
|
|
26
|
+
'sourceFilename',
|
|
27
|
+
'sourceType',
|
|
28
|
+
'tokens',
|
|
29
|
+
]);
|
|
@@ -147,7 +147,7 @@ module.exports = {
|
|
|
147
147
|
PrivateIdentifier: [],
|
|
148
148
|
Program: ['body'],
|
|
149
149
|
Property: ['key', 'value'],
|
|
150
|
-
PropertyDefinition: ['key', 'value', 'variance', 'typeAnnotation'
|
|
150
|
+
PropertyDefinition: ['key', 'value', 'variance', 'typeAnnotation'],
|
|
151
151
|
QualifiedTypeIdentifier: ['qualification', 'id'],
|
|
152
152
|
QualifiedTypeofIdentifier: ['qualification', 'id'],
|
|
153
153
|
RestElement: ['argument'],
|
package/dist/index.js
CHANGED
|
@@ -32,6 +32,15 @@ var _ESTreeVisitorKeys = _interopRequireDefault(require("./generated/ESTreeVisit
|
|
|
32
32
|
|
|
33
33
|
exports.FlowVisitorKeys = _ESTreeVisitorKeys.default;
|
|
34
34
|
|
|
35
|
+
var _ParserOptions = require("./ParserOptions");
|
|
36
|
+
|
|
37
|
+
Object.keys(_ParserOptions).forEach(function (key) {
|
|
38
|
+
if (key === "default" || key === "__esModule") return;
|
|
39
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
40
|
+
if (key in exports && exports[key] === _ParserOptions[key]) return;
|
|
41
|
+
exports[key] = _ParserOptions[key];
|
|
42
|
+
});
|
|
43
|
+
|
|
35
44
|
var _SimpleTraverser = require("./traverse/SimpleTraverser");
|
|
36
45
|
|
|
37
46
|
Object.keys(_SimpleTraverser).forEach(function (key) {
|
package/dist/index.js.flow
CHANGED
|
@@ -84,6 +84,7 @@ export function parse(
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
export type {ParserOptions} from './ParserOptions';
|
|
87
|
+
export * from './ParserOptions';
|
|
87
88
|
export * from './traverse/SimpleTraverser';
|
|
88
89
|
export * from './transform/SimpleTransform';
|
|
89
90
|
export * from './traverse/getVisitorKeys';
|
|
@@ -103,8 +103,7 @@ function removeNodeOnParent(originalNode, originalNodeParent) {
|
|
|
103
103
|
|
|
104
104
|
function setParentPointersInDirectChildren(node) {
|
|
105
105
|
for (const key of (0, _getVisitorKeys.getVisitorKeys)(node)) {
|
|
106
|
-
if ((0, _getVisitorKeys.isNode)(
|
|
107
|
-
node[key])) {
|
|
106
|
+
if ((0, _getVisitorKeys.isNode)(node[key])) {
|
|
108
107
|
node[key].parent = node;
|
|
109
108
|
} else if (Array.isArray(node[key])) {
|
|
110
109
|
for (const child of node[key]) {
|
|
@@ -138,7 +137,8 @@ function updateAllParentPointers(node) {
|
|
|
138
137
|
|
|
139
138
|
function nodeWith(node, overrideProps) {
|
|
140
139
|
// Check if this will actually result in a change, maintaining referential equality is important.
|
|
141
|
-
const willBeUnchanged = Object.entries(overrideProps).every(([key, value]) => // $FlowExpectedError[
|
|
140
|
+
const willBeUnchanged = Object.entries(overrideProps).every(([key, value]) => // $FlowExpectedError[incompatible-call]
|
|
141
|
+
// $FlowExpectedError[prop-missing]
|
|
142
142
|
Array.isArray(value) ? (0, _astArrayMutationHelpers.arrayIsEqual)(node[key], value) : node[key] === value);
|
|
143
143
|
|
|
144
144
|
if (willBeUnchanged) {
|
|
@@ -115,13 +115,8 @@ export function removeNodeOnParent(
|
|
|
115
115
|
* Corrects the parent pointers in direct children of the given node.
|
|
116
116
|
*/
|
|
117
117
|
export function setParentPointersInDirectChildren(node: ESNode): void {
|
|
118
|
-
for (const key of getVisitorKeys(node)) {
|
|
119
|
-
if (
|
|
120
|
-
isNode(
|
|
121
|
-
// $FlowExpectedError[prop-missing]
|
|
122
|
-
node[key],
|
|
123
|
-
)
|
|
124
|
-
) {
|
|
118
|
+
for (const key: $FlowFixMe of getVisitorKeys(node)) {
|
|
119
|
+
if (isNode(node[key])) {
|
|
125
120
|
node[key].parent = node;
|
|
126
121
|
} else if (Array.isArray(node[key])) {
|
|
127
122
|
for (const child of node[key]) {
|
|
@@ -152,6 +147,7 @@ export function updateAllParentPointers(node: ESNode) {
|
|
|
152
147
|
export function nodeWith<T: ESNode>(node: T, overrideProps: Partial<T>): T {
|
|
153
148
|
// Check if this will actually result in a change, maintaining referential equality is important.
|
|
154
149
|
const willBeUnchanged = Object.entries(overrideProps).every(([key, value]) =>
|
|
150
|
+
// $FlowExpectedError[incompatible-call]
|
|
155
151
|
// $FlowExpectedError[prop-missing]
|
|
156
152
|
Array.isArray(value) ? arrayIsEqual(node[key], value) : node[key] === value,
|
|
157
153
|
);
|