hermes-parser 0.29.0 → 0.30.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.
- package/dist/HermesParserNodeDeserializers.js +4 -0
- package/dist/HermesParserWASM.js +1 -1
- package/dist/HermesToESTreeAdapter.js +0 -14
- package/dist/HermesToESTreeAdapter.js.flow +0 -16
- package/dist/babel/TransformESTreeToBabel.js +16 -0
- package/dist/babel/TransformESTreeToBabel.js.flow +12 -0
- package/dist/estree/StripComponentSyntax.js.flow +2 -2
- package/dist/estree/TransformMatchSyntax.js +4 -3
- package/dist/estree/TransformMatchSyntax.js.flow +4 -4
- package/dist/generated/ESTreeVisitorKeys.js +2 -2
- package/dist/generated/ParserVisitorKeys.js +4 -0
- package/dist/index.js.flow +3 -3
- package/dist/src/HermesParserNodeDeserializers.js +4 -0
- package/dist/src/HermesToESTreeAdapter.js +0 -14
- package/dist/src/babel/TransformESTreeToBabel.js +16 -0
- package/dist/src/estree/TransformMatchSyntax.js +4 -3
- package/dist/src/generated/ESTreeVisitorKeys.js +2 -2
- package/dist/src/generated/ParserVisitorKeys.js +4 -0
- package/package.json +2 -2
|
@@ -95,9 +95,6 @@ class HermesToESTreeAdapter extends _HermesASTAdapter.default {
|
|
|
95
95
|
case 'ExportAllDeclaration':
|
|
96
96
|
return this.mapExportAllDeclaration(node);
|
|
97
97
|
|
|
98
|
-
case 'Property':
|
|
99
|
-
return this.mapProperty(node);
|
|
100
|
-
|
|
101
98
|
case 'FunctionDeclaration':
|
|
102
99
|
case 'FunctionExpression':
|
|
103
100
|
case 'ArrowFunctionExpression':
|
|
@@ -233,17 +230,6 @@ class HermesToESTreeAdapter extends _HermesASTAdapter.default {
|
|
|
233
230
|
return this.mapNodeDefault(node);
|
|
234
231
|
}
|
|
235
232
|
|
|
236
|
-
mapProperty(nodeUnprocessed) {
|
|
237
|
-
const node = this.mapNodeDefault(nodeUnprocessed);
|
|
238
|
-
|
|
239
|
-
if (node.value.type === 'FunctionExpression' && (node.method || node.kind !== 'init')) {
|
|
240
|
-
node.value.loc.start = node.key.loc.end;
|
|
241
|
-
node.value.range[0] = node.key.range[1];
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return node;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
233
|
mapComment(node) {
|
|
248
234
|
if (node.type === 'CommentBlock') {
|
|
249
235
|
node.type = 'Block';
|
|
@@ -76,8 +76,6 @@ export default class HermesToESTreeAdapter extends HermesASTAdapter {
|
|
|
76
76
|
return this.mapExportNamedDeclaration(node);
|
|
77
77
|
case 'ExportAllDeclaration':
|
|
78
78
|
return this.mapExportAllDeclaration(node);
|
|
79
|
-
case 'Property':
|
|
80
|
-
return this.mapProperty(node);
|
|
81
79
|
case 'FunctionDeclaration':
|
|
82
80
|
case 'FunctionExpression':
|
|
83
81
|
case 'ArrowFunctionExpression':
|
|
@@ -214,20 +212,6 @@ export default class HermesToESTreeAdapter extends HermesASTAdapter {
|
|
|
214
212
|
return this.mapNodeDefault(node);
|
|
215
213
|
}
|
|
216
214
|
|
|
217
|
-
mapProperty(nodeUnprocessed: HermesNode): HermesNode {
|
|
218
|
-
const node = this.mapNodeDefault(nodeUnprocessed);
|
|
219
|
-
|
|
220
|
-
if (
|
|
221
|
-
node.value.type === 'FunctionExpression' &&
|
|
222
|
-
(node.method || node.kind !== 'init')
|
|
223
|
-
) {
|
|
224
|
-
node.value.loc.start = node.key.loc.end;
|
|
225
|
-
node.value.range[0] = node.key.range[1];
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return node;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
215
|
mapComment(node: HermesNode): HermesNode {
|
|
232
216
|
if (node.type === 'CommentBlock') {
|
|
233
217
|
node.type = 'Block';
|
|
@@ -1065,6 +1065,22 @@ function transformNode(node) {
|
|
|
1065
1065
|
return node;
|
|
1066
1066
|
}
|
|
1067
1067
|
|
|
1068
|
+
case 'DeclareOpaqueType':
|
|
1069
|
+
case 'OpaqueType':
|
|
1070
|
+
{
|
|
1071
|
+
if (node.lowerBound != null) {
|
|
1072
|
+
// $FlowExpectedError[cannot-write]
|
|
1073
|
+
delete node.lowerBound;
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
if (node.upperBound != null) {
|
|
1077
|
+
// $FlowExpectedError[cannot-write]
|
|
1078
|
+
delete node.upperBound;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
return node;
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1068
1084
|
default:
|
|
1069
1085
|
{
|
|
1070
1086
|
return node;
|
|
@@ -1223,6 +1223,18 @@ function transformNode(node: ESNodeOrBabelNode): ESNodeOrBabelNode | null {
|
|
|
1223
1223
|
}
|
|
1224
1224
|
return node;
|
|
1225
1225
|
}
|
|
1226
|
+
case 'DeclareOpaqueType':
|
|
1227
|
+
case 'OpaqueType': {
|
|
1228
|
+
if (node.lowerBound != null) {
|
|
1229
|
+
// $FlowExpectedError[cannot-write]
|
|
1230
|
+
delete node.lowerBound;
|
|
1231
|
+
}
|
|
1232
|
+
if (node.upperBound != null) {
|
|
1233
|
+
// $FlowExpectedError[cannot-write]
|
|
1234
|
+
delete node.upperBound;
|
|
1235
|
+
}
|
|
1236
|
+
return node;
|
|
1237
|
+
}
|
|
1226
1238
|
default: {
|
|
1227
1239
|
return node;
|
|
1228
1240
|
}
|
|
@@ -311,8 +311,8 @@ function mapComponentParameterType(
|
|
|
311
311
|
param.local.type === 'AssignmentPattern'
|
|
312
312
|
? true
|
|
313
313
|
: param.local.type === 'Identifier'
|
|
314
|
-
|
|
315
|
-
|
|
314
|
+
? param.local.optional
|
|
315
|
+
: false;
|
|
316
316
|
|
|
317
317
|
return {
|
|
318
318
|
type: 'ObjectTypeProperty',
|
|
@@ -784,12 +784,12 @@ function mapMatchExpression(node) {
|
|
|
784
784
|
hasWildcard,
|
|
785
785
|
analyses
|
|
786
786
|
} = analyzeCases(cases);
|
|
787
|
-
const isSimpleArgument = calculateSimpleArgument(argument);
|
|
787
|
+
const isSimpleArgument = !hasBindings && calculateSimpleArgument(argument);
|
|
788
788
|
const genRoot = !isSimpleArgument ? genIdent() : null;
|
|
789
789
|
const root = genRoot == null ? argument : genRoot; // No bindings and a simple argument means we can use nested conditional
|
|
790
790
|
// expressions.
|
|
791
791
|
|
|
792
|
-
if (
|
|
792
|
+
if (isSimpleArgument) {
|
|
793
793
|
const wildcardAnalaysis = hasWildcard ? analyses.pop() : null;
|
|
794
794
|
const lastBody = wildcardAnalaysis != null ? wildcardAnalaysis.body : (0, _Builders.iife)([fallthroughError((0, _astNodeMutationHelpers.shallowCloneNode)(root))]);
|
|
795
795
|
return analyses.reverse().reduce((acc, analysis) => {
|
|
@@ -886,11 +886,12 @@ function mapMatchStatement(node) {
|
|
|
886
886
|
cases
|
|
887
887
|
} = node;
|
|
888
888
|
const {
|
|
889
|
+
hasBindings,
|
|
889
890
|
hasWildcard,
|
|
890
891
|
analyses
|
|
891
892
|
} = analyzeCases(cases);
|
|
892
893
|
const topLabel = genIdent();
|
|
893
|
-
const isSimpleArgument = calculateSimpleArgument(argument);
|
|
894
|
+
const isSimpleArgument = !hasBindings && calculateSimpleArgument(argument);
|
|
894
895
|
const genRoot = !isSimpleArgument ? genIdent() : null;
|
|
895
896
|
const root = genRoot == null ? argument : genRoot;
|
|
896
897
|
const statements = [];
|
|
@@ -701,13 +701,13 @@ function mapMatchExpression(node: MatchExpression): Expression {
|
|
|
701
701
|
const {argument, cases} = node;
|
|
702
702
|
const {hasBindings, hasWildcard, analyses} = analyzeCases(cases);
|
|
703
703
|
|
|
704
|
-
const isSimpleArgument = calculateSimpleArgument(argument);
|
|
704
|
+
const isSimpleArgument = !hasBindings && calculateSimpleArgument(argument);
|
|
705
705
|
const genRoot: Identifier | null = !isSimpleArgument ? genIdent() : null;
|
|
706
706
|
const root: Expression = genRoot == null ? argument : genRoot;
|
|
707
707
|
|
|
708
708
|
// No bindings and a simple argument means we can use nested conditional
|
|
709
709
|
// expressions.
|
|
710
|
-
if (
|
|
710
|
+
if (isSimpleArgument) {
|
|
711
711
|
const wildcardAnalaysis = hasWildcard ? analyses.pop() : null;
|
|
712
712
|
const lastBody =
|
|
713
713
|
wildcardAnalaysis != null
|
|
@@ -798,10 +798,10 @@ function mapMatchExpression(node: MatchExpression): Expression {
|
|
|
798
798
|
*/
|
|
799
799
|
function mapMatchStatement(node: MatchStatement): Statement {
|
|
800
800
|
const {argument, cases} = node;
|
|
801
|
-
const {hasWildcard, analyses} = analyzeCases(cases);
|
|
801
|
+
const {hasBindings, hasWildcard, analyses} = analyzeCases(cases);
|
|
802
802
|
|
|
803
803
|
const topLabel: Identifier = genIdent();
|
|
804
|
-
const isSimpleArgument = calculateSimpleArgument(argument);
|
|
804
|
+
const isSimpleArgument = !hasBindings && calculateSimpleArgument(argument);
|
|
805
805
|
const genRoot: Identifier | null = !isSimpleArgument ? genIdent() : null;
|
|
806
806
|
const root: Expression = genRoot == null ? argument : genRoot;
|
|
807
807
|
|
|
@@ -66,7 +66,7 @@ module.exports = {
|
|
|
66
66
|
DeclareModule: ['id', 'body'],
|
|
67
67
|
DeclareModuleExports: ['typeAnnotation'],
|
|
68
68
|
DeclareNamespace: ['id', 'body'],
|
|
69
|
-
DeclareOpaqueType: ['id', 'typeParameters', 'impltype', 'supertype'],
|
|
69
|
+
DeclareOpaqueType: ['id', 'typeParameters', 'impltype', 'lowerBound', 'upperBound', 'supertype'],
|
|
70
70
|
DeclareTypeAlias: ['id', 'typeParameters', 'right'],
|
|
71
71
|
DeclareVariable: ['id'],
|
|
72
72
|
DoWhileStatement: ['body', 'test'],
|
|
@@ -166,7 +166,7 @@ module.exports = {
|
|
|
166
166
|
ObjectTypeMappedTypeProperty: ['keyTparam', 'propType', 'sourceType', 'variance'],
|
|
167
167
|
ObjectTypeProperty: ['key', 'value', 'variance'],
|
|
168
168
|
ObjectTypeSpreadProperty: ['argument'],
|
|
169
|
-
OpaqueType: ['id', 'typeParameters', 'impltype', 'supertype'],
|
|
169
|
+
OpaqueType: ['id', 'typeParameters', 'impltype', 'lowerBound', 'upperBound', 'supertype'],
|
|
170
170
|
OptionalIndexedAccessType: ['objectType', 'indexType'],
|
|
171
171
|
PrivateIdentifier: [],
|
|
172
172
|
Program: ['body'],
|
|
@@ -214,6 +214,8 @@ const HERMES_AST_VISITOR_KEYS = {
|
|
|
214
214
|
id: 'Node',
|
|
215
215
|
typeParameters: 'Node',
|
|
216
216
|
impltype: 'Node',
|
|
217
|
+
lowerBound: 'Node',
|
|
218
|
+
upperBound: 'Node',
|
|
217
219
|
supertype: 'Node'
|
|
218
220
|
},
|
|
219
221
|
DeclareTypeAlias: {
|
|
@@ -586,6 +588,8 @@ const HERMES_AST_VISITOR_KEYS = {
|
|
|
586
588
|
id: 'Node',
|
|
587
589
|
typeParameters: 'Node',
|
|
588
590
|
impltype: 'Node',
|
|
591
|
+
lowerBound: 'Node',
|
|
592
|
+
upperBound: 'Node',
|
|
589
593
|
supertype: 'Node'
|
|
590
594
|
},
|
|
591
595
|
OptionalIndexedAccessType: {
|
package/dist/index.js.flow
CHANGED
|
@@ -66,14 +66,14 @@ function getOptions(options?: ParserOptions = {...DEFAULTS}) {
|
|
|
66
66
|
|
|
67
67
|
declare function parse(
|
|
68
68
|
code: string,
|
|
69
|
-
opts: {...ParserOptions, babel: true}
|
|
69
|
+
opts: $ReadOnly<{...ParserOptions, babel: true}>,
|
|
70
70
|
): BabelFile;
|
|
71
71
|
// eslint-disable-next-line no-redeclare
|
|
72
72
|
declare function parse(
|
|
73
73
|
code: string,
|
|
74
74
|
opts?:
|
|
75
|
-
| {...ParserOptions, babel?: false | void}
|
|
76
|
-
| {...ParserOptions, babel: false}
|
|
75
|
+
| $ReadOnly<{...ParserOptions, babel?: false | void}>
|
|
76
|
+
| $ReadOnly<{...ParserOptions, babel: false}>,
|
|
77
77
|
): ESTreeProgram;
|
|
78
78
|
|
|
79
79
|
// eslint-disable-next-line no-redeclare
|
|
@@ -1547,6 +1547,8 @@ function deserializeOpaqueType() {
|
|
|
1547
1547
|
id: this.deserializeNode(),
|
|
1548
1548
|
typeParameters: this.deserializeNode(),
|
|
1549
1549
|
impltype: this.deserializeNode(),
|
|
1550
|
+
lowerBound: this.deserializeNode(),
|
|
1551
|
+
upperBound: this.deserializeNode(),
|
|
1550
1552
|
supertype: this.deserializeNode()
|
|
1551
1553
|
};
|
|
1552
1554
|
}
|
|
@@ -1579,6 +1581,8 @@ function deserializeDeclareOpaqueType() {
|
|
|
1579
1581
|
id: this.deserializeNode(),
|
|
1580
1582
|
typeParameters: this.deserializeNode(),
|
|
1581
1583
|
impltype: this.deserializeNode(),
|
|
1584
|
+
lowerBound: this.deserializeNode(),
|
|
1585
|
+
upperBound: this.deserializeNode(),
|
|
1582
1586
|
supertype: this.deserializeNode()
|
|
1583
1587
|
};
|
|
1584
1588
|
}
|
|
@@ -95,9 +95,6 @@ class HermesToESTreeAdapter extends _HermesASTAdapter.default {
|
|
|
95
95
|
case 'ExportAllDeclaration':
|
|
96
96
|
return this.mapExportAllDeclaration(node);
|
|
97
97
|
|
|
98
|
-
case 'Property':
|
|
99
|
-
return this.mapProperty(node);
|
|
100
|
-
|
|
101
98
|
case 'FunctionDeclaration':
|
|
102
99
|
case 'FunctionExpression':
|
|
103
100
|
case 'ArrowFunctionExpression':
|
|
@@ -233,17 +230,6 @@ class HermesToESTreeAdapter extends _HermesASTAdapter.default {
|
|
|
233
230
|
return this.mapNodeDefault(node);
|
|
234
231
|
}
|
|
235
232
|
|
|
236
|
-
mapProperty(nodeUnprocessed) {
|
|
237
|
-
const node = this.mapNodeDefault(nodeUnprocessed);
|
|
238
|
-
|
|
239
|
-
if (node.value.type === 'FunctionExpression' && (node.method || node.kind !== 'init')) {
|
|
240
|
-
node.value.loc.start = node.key.loc.end;
|
|
241
|
-
node.value.range[0] = node.key.range[1];
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return node;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
233
|
mapComment(node) {
|
|
248
234
|
if (node.type === 'CommentBlock') {
|
|
249
235
|
node.type = 'Block';
|
|
@@ -1065,6 +1065,22 @@ function transformNode(node) {
|
|
|
1065
1065
|
return node;
|
|
1066
1066
|
}
|
|
1067
1067
|
|
|
1068
|
+
case 'DeclareOpaqueType':
|
|
1069
|
+
case 'OpaqueType':
|
|
1070
|
+
{
|
|
1071
|
+
if (node.lowerBound != null) {
|
|
1072
|
+
// $FlowExpectedError[cannot-write]
|
|
1073
|
+
delete node.lowerBound;
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
if (node.upperBound != null) {
|
|
1077
|
+
// $FlowExpectedError[cannot-write]
|
|
1078
|
+
delete node.upperBound;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
return node;
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1068
1084
|
default:
|
|
1069
1085
|
{
|
|
1070
1086
|
return node;
|
|
@@ -784,12 +784,12 @@ function mapMatchExpression(node) {
|
|
|
784
784
|
hasWildcard,
|
|
785
785
|
analyses
|
|
786
786
|
} = analyzeCases(cases);
|
|
787
|
-
const isSimpleArgument = calculateSimpleArgument(argument);
|
|
787
|
+
const isSimpleArgument = !hasBindings && calculateSimpleArgument(argument);
|
|
788
788
|
const genRoot = !isSimpleArgument ? genIdent() : null;
|
|
789
789
|
const root = genRoot == null ? argument : genRoot; // No bindings and a simple argument means we can use nested conditional
|
|
790
790
|
// expressions.
|
|
791
791
|
|
|
792
|
-
if (
|
|
792
|
+
if (isSimpleArgument) {
|
|
793
793
|
const wildcardAnalaysis = hasWildcard ? analyses.pop() : null;
|
|
794
794
|
const lastBody = wildcardAnalaysis != null ? wildcardAnalaysis.body : (0, _Builders.iife)([fallthroughError((0, _astNodeMutationHelpers.shallowCloneNode)(root))]);
|
|
795
795
|
return analyses.reverse().reduce((acc, analysis) => {
|
|
@@ -886,11 +886,12 @@ function mapMatchStatement(node) {
|
|
|
886
886
|
cases
|
|
887
887
|
} = node;
|
|
888
888
|
const {
|
|
889
|
+
hasBindings,
|
|
889
890
|
hasWildcard,
|
|
890
891
|
analyses
|
|
891
892
|
} = analyzeCases(cases);
|
|
892
893
|
const topLabel = genIdent();
|
|
893
|
-
const isSimpleArgument = calculateSimpleArgument(argument);
|
|
894
|
+
const isSimpleArgument = !hasBindings && calculateSimpleArgument(argument);
|
|
894
895
|
const genRoot = !isSimpleArgument ? genIdent() : null;
|
|
895
896
|
const root = genRoot == null ? argument : genRoot;
|
|
896
897
|
const statements = [];
|
|
@@ -66,7 +66,7 @@ module.exports = {
|
|
|
66
66
|
DeclareModule: ['id', 'body'],
|
|
67
67
|
DeclareModuleExports: ['typeAnnotation'],
|
|
68
68
|
DeclareNamespace: ['id', 'body'],
|
|
69
|
-
DeclareOpaqueType: ['id', 'typeParameters', 'impltype', 'supertype'],
|
|
69
|
+
DeclareOpaqueType: ['id', 'typeParameters', 'impltype', 'lowerBound', 'upperBound', 'supertype'],
|
|
70
70
|
DeclareTypeAlias: ['id', 'typeParameters', 'right'],
|
|
71
71
|
DeclareVariable: ['id'],
|
|
72
72
|
DoWhileStatement: ['body', 'test'],
|
|
@@ -166,7 +166,7 @@ module.exports = {
|
|
|
166
166
|
ObjectTypeMappedTypeProperty: ['keyTparam', 'propType', 'sourceType', 'variance'],
|
|
167
167
|
ObjectTypeProperty: ['key', 'value', 'variance'],
|
|
168
168
|
ObjectTypeSpreadProperty: ['argument'],
|
|
169
|
-
OpaqueType: ['id', 'typeParameters', 'impltype', 'supertype'],
|
|
169
|
+
OpaqueType: ['id', 'typeParameters', 'impltype', 'lowerBound', 'upperBound', 'supertype'],
|
|
170
170
|
OptionalIndexedAccessType: ['objectType', 'indexType'],
|
|
171
171
|
PrivateIdentifier: [],
|
|
172
172
|
Program: ['body'],
|
|
@@ -214,6 +214,8 @@ const HERMES_AST_VISITOR_KEYS = {
|
|
|
214
214
|
id: 'Node',
|
|
215
215
|
typeParameters: 'Node',
|
|
216
216
|
impltype: 'Node',
|
|
217
|
+
lowerBound: 'Node',
|
|
218
|
+
upperBound: 'Node',
|
|
217
219
|
supertype: 'Node'
|
|
218
220
|
},
|
|
219
221
|
DeclareTypeAlias: {
|
|
@@ -586,6 +588,8 @@ const HERMES_AST_VISITOR_KEYS = {
|
|
|
586
588
|
id: 'Node',
|
|
587
589
|
typeParameters: 'Node',
|
|
588
590
|
impltype: 'Node',
|
|
591
|
+
lowerBound: 'Node',
|
|
592
|
+
upperBound: 'Node',
|
|
589
593
|
supertype: 'Node'
|
|
590
594
|
},
|
|
591
595
|
OptionalIndexedAccessType: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hermes-parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"description": "A JavaScript parser built from the Hermes engine",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"url": "git@github.com:facebook/hermes.git"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"hermes-estree": "0.
|
|
12
|
+
"hermes-estree": "0.30.0"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@babel/parser": "7.7.4",
|