hermes-parser 0.25.1 → 0.26.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/HermesParser.js +2 -2
- package/dist/HermesParser.js.flow +2 -0
- package/dist/HermesParserNodeDeserializers.js +159 -1
- package/dist/HermesParserWASM.js +1 -1
- package/dist/HermesParserWASM.js.flow +10 -2
- package/dist/ParserOptions.js +1 -1
- package/dist/ParserOptions.js.flow +2 -0
- package/dist/estree/TransformMatchSyntax.js +979 -0
- package/dist/estree/TransformMatchSyntax.js.flow +886 -0
- package/dist/generated/ESTreeVisitorKeys.js +17 -0
- package/dist/generated/ParserVisitorKeys.js +60 -0
- package/dist/index.js +4 -1
- package/dist/index.js.flow +3 -0
- package/dist/utils/Builders.js +174 -0
- package/dist/utils/Builders.js.flow +198 -0
- package/dist/utils/GenID.js +41 -0
- package/dist/utils/GenID.js.flow +38 -0
- package/package.json +2 -2
|
@@ -132,6 +132,22 @@ module.exports = {
|
|
|
132
132
|
KeyofTypeAnnotation: ['argument'],
|
|
133
133
|
LabeledStatement: ['label', 'body'],
|
|
134
134
|
LogicalExpression: ['left', 'right'],
|
|
135
|
+
MatchArrayPattern: ['elements', 'rest'],
|
|
136
|
+
MatchAsPattern: ['pattern', 'target'],
|
|
137
|
+
MatchBindingPattern: ['id'],
|
|
138
|
+
MatchExpression: ['argument', 'cases'],
|
|
139
|
+
MatchExpressionCase: ['pattern', 'body', 'guard'],
|
|
140
|
+
MatchIdentifierPattern: ['id'],
|
|
141
|
+
MatchLiteralPattern: ['literal'],
|
|
142
|
+
MatchMemberPattern: ['base', 'property'],
|
|
143
|
+
MatchObjectPattern: ['properties', 'rest'],
|
|
144
|
+
MatchObjectPatternProperty: ['key', 'pattern'],
|
|
145
|
+
MatchOrPattern: ['patterns'],
|
|
146
|
+
MatchRestPattern: ['argument'],
|
|
147
|
+
MatchStatement: ['argument', 'cases'],
|
|
148
|
+
MatchStatementCase: ['pattern', 'body', 'guard'],
|
|
149
|
+
MatchUnaryPattern: ['argument'],
|
|
150
|
+
MatchWildcardPattern: [],
|
|
135
151
|
MemberExpression: ['object', 'property'],
|
|
136
152
|
MetaProperty: ['meta', 'property'],
|
|
137
153
|
MethodDefinition: ['key', 'value'],
|
|
@@ -162,6 +178,7 @@ module.exports = {
|
|
|
162
178
|
ReturnStatement: ['argument'],
|
|
163
179
|
SequenceExpression: ['expressions'],
|
|
164
180
|
SpreadElement: ['argument'],
|
|
181
|
+
StaticBlock: ['body'],
|
|
165
182
|
StringLiteralTypeAnnotation: [],
|
|
166
183
|
StringTypeAnnotation: [],
|
|
167
184
|
Super: [],
|
|
@@ -459,6 +459,63 @@ const HERMES_AST_VISITOR_KEYS = {
|
|
|
459
459
|
left: 'Node',
|
|
460
460
|
right: 'Node'
|
|
461
461
|
},
|
|
462
|
+
MatchArrayPattern: {
|
|
463
|
+
elements: 'NodeList',
|
|
464
|
+
rest: 'Node'
|
|
465
|
+
},
|
|
466
|
+
MatchAsPattern: {
|
|
467
|
+
pattern: 'Node',
|
|
468
|
+
target: 'Node'
|
|
469
|
+
},
|
|
470
|
+
MatchBindingPattern: {
|
|
471
|
+
id: 'Node'
|
|
472
|
+
},
|
|
473
|
+
MatchExpression: {
|
|
474
|
+
argument: 'Node',
|
|
475
|
+
cases: 'NodeList'
|
|
476
|
+
},
|
|
477
|
+
MatchExpressionCase: {
|
|
478
|
+
pattern: 'Node',
|
|
479
|
+
body: 'Node',
|
|
480
|
+
guard: 'Node'
|
|
481
|
+
},
|
|
482
|
+
MatchIdentifierPattern: {
|
|
483
|
+
id: 'Node'
|
|
484
|
+
},
|
|
485
|
+
MatchLiteralPattern: {
|
|
486
|
+
literal: 'Node'
|
|
487
|
+
},
|
|
488
|
+
MatchMemberPattern: {
|
|
489
|
+
base: 'Node',
|
|
490
|
+
property: 'Node'
|
|
491
|
+
},
|
|
492
|
+
MatchObjectPattern: {
|
|
493
|
+
properties: 'NodeList',
|
|
494
|
+
rest: 'Node'
|
|
495
|
+
},
|
|
496
|
+
MatchObjectPatternProperty: {
|
|
497
|
+
key: 'Node',
|
|
498
|
+
pattern: 'Node'
|
|
499
|
+
},
|
|
500
|
+
MatchOrPattern: {
|
|
501
|
+
patterns: 'NodeList'
|
|
502
|
+
},
|
|
503
|
+
MatchRestPattern: {
|
|
504
|
+
argument: 'Node'
|
|
505
|
+
},
|
|
506
|
+
MatchStatement: {
|
|
507
|
+
argument: 'Node',
|
|
508
|
+
cases: 'NodeList'
|
|
509
|
+
},
|
|
510
|
+
MatchStatementCase: {
|
|
511
|
+
pattern: 'Node',
|
|
512
|
+
body: 'Node',
|
|
513
|
+
guard: 'Node'
|
|
514
|
+
},
|
|
515
|
+
MatchUnaryPattern: {
|
|
516
|
+
argument: 'Node'
|
|
517
|
+
},
|
|
518
|
+
MatchWildcardPattern: {},
|
|
462
519
|
MemberExpression: {
|
|
463
520
|
object: 'Node',
|
|
464
521
|
property: 'Node'
|
|
@@ -570,6 +627,9 @@ const HERMES_AST_VISITOR_KEYS = {
|
|
|
570
627
|
SpreadElement: {
|
|
571
628
|
argument: 'Node'
|
|
572
629
|
},
|
|
630
|
+
StaticBlock: {
|
|
631
|
+
body: 'NodeList'
|
|
632
|
+
},
|
|
573
633
|
StringLiteral: {},
|
|
574
634
|
StringLiteralTypeAnnotation: {},
|
|
575
635
|
StringTypeAnnotation: {},
|
package/dist/index.js
CHANGED
|
@@ -33,6 +33,8 @@ exports.FlowVisitorKeys = _ESTreeVisitorKeys.default;
|
|
|
33
33
|
|
|
34
34
|
var StripComponentSyntax = _interopRequireWildcard(require("./estree/StripComponentSyntax"));
|
|
35
35
|
|
|
36
|
+
var TransformMatchSyntax = _interopRequireWildcard(require("./estree/TransformMatchSyntax"));
|
|
37
|
+
|
|
36
38
|
var StripFlowTypesForBabel = _interopRequireWildcard(require("./estree/StripFlowTypesForBabel"));
|
|
37
39
|
|
|
38
40
|
var TransformESTreeToBabel = _interopRequireWildcard(require("./babel/TransformESTreeToBabel"));
|
|
@@ -134,11 +136,12 @@ function parse(code, opts) {
|
|
|
134
136
|
return estreeAST;
|
|
135
137
|
}
|
|
136
138
|
|
|
137
|
-
const loweredESTreeAST = [StripComponentSyntax.transformProgram, StripFlowTypesForBabel.transformProgram].reduce((ast, transform) => transform(ast, options), estreeAST);
|
|
139
|
+
const loweredESTreeAST = [TransformMatchSyntax.transformProgram, StripComponentSyntax.transformProgram, StripFlowTypesForBabel.transformProgram].reduce((ast, transform) => transform(ast, options), estreeAST);
|
|
138
140
|
return TransformESTreeToBabel.transformProgram(loweredESTreeAST, options);
|
|
139
141
|
}
|
|
140
142
|
|
|
141
143
|
const Transforms = {
|
|
144
|
+
transformMatchSyntax: TransformMatchSyntax.transformProgram,
|
|
142
145
|
stripComponentSyntax: StripComponentSyntax.transformProgram,
|
|
143
146
|
stripFlowTypesForBabel: StripFlowTypesForBabel.transformProgram,
|
|
144
147
|
stripFlowTypes: StripFlowTypes.transformProgram
|
package/dist/index.js.flow
CHANGED
|
@@ -18,6 +18,7 @@ import * as HermesParser from './HermesParser';
|
|
|
18
18
|
import HermesToESTreeAdapter from './HermesToESTreeAdapter';
|
|
19
19
|
import FlowVisitorKeys from './generated/ESTreeVisitorKeys';
|
|
20
20
|
import * as StripComponentSyntax from './estree/StripComponentSyntax';
|
|
21
|
+
import * as TransformMatchSyntax from './estree/TransformMatchSyntax';
|
|
21
22
|
import * as StripFlowTypesForBabel from './estree/StripFlowTypesForBabel';
|
|
22
23
|
import * as TransformESTreeToBabel from './babel/TransformESTreeToBabel';
|
|
23
24
|
import * as StripFlowTypes from './estree/StripFlowTypes';
|
|
@@ -87,6 +88,7 @@ export function parse(
|
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
const loweredESTreeAST = [
|
|
91
|
+
TransformMatchSyntax.transformProgram,
|
|
90
92
|
StripComponentSyntax.transformProgram,
|
|
91
93
|
StripFlowTypesForBabel.transformProgram,
|
|
92
94
|
].reduce((ast, transform) => transform(ast, options), estreeAST);
|
|
@@ -105,6 +107,7 @@ export * as astNodeMutationHelpers from './transform/astNodeMutationHelpers';
|
|
|
105
107
|
export {default as mutateESTreeASTForPrettier} from './utils/mutateESTreeASTForPrettier';
|
|
106
108
|
|
|
107
109
|
const Transforms = {
|
|
110
|
+
transformMatchSyntax: TransformMatchSyntax.transformProgram,
|
|
108
111
|
stripComponentSyntax: StripComponentSyntax.transformProgram,
|
|
109
112
|
stripFlowTypesForBabel: StripFlowTypesForBabel.transformProgram,
|
|
110
113
|
stripFlowTypes: StripFlowTypes.transformProgram,
|
|
@@ -0,0 +1,174 @@
|
|
|
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
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, "__esModule", {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
exports.EMPTY_PARENT = void 0;
|
|
16
|
+
exports.callExpression = callExpression;
|
|
17
|
+
exports.conjunction = conjunction;
|
|
18
|
+
exports.createDefaultPosition = createDefaultPosition;
|
|
19
|
+
exports.disjunction = disjunction;
|
|
20
|
+
exports.etc = etc;
|
|
21
|
+
exports.ident = ident;
|
|
22
|
+
exports.iife = iife;
|
|
23
|
+
exports.nullLiteral = nullLiteral;
|
|
24
|
+
exports.numberLiteral = numberLiteral;
|
|
25
|
+
exports.stringLiteral = stringLiteral;
|
|
26
|
+
exports.throwStatement = throwStatement;
|
|
27
|
+
exports.variableDeclaration = variableDeclaration;
|
|
28
|
+
// Rely on the mapper to fix up parent relationships.
|
|
29
|
+
const EMPTY_PARENT = null;
|
|
30
|
+
exports.EMPTY_PARENT = EMPTY_PARENT;
|
|
31
|
+
|
|
32
|
+
function createDefaultPosition() {
|
|
33
|
+
return {
|
|
34
|
+
line: 1,
|
|
35
|
+
column: 0
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function etc({
|
|
40
|
+
loc,
|
|
41
|
+
range,
|
|
42
|
+
parent
|
|
43
|
+
} = {}) {
|
|
44
|
+
return {
|
|
45
|
+
loc: {
|
|
46
|
+
start: (loc == null ? void 0 : loc.start) != null ? loc.start : createDefaultPosition(),
|
|
47
|
+
end: (loc == null ? void 0 : loc.end) != null ? loc.end : createDefaultPosition()
|
|
48
|
+
},
|
|
49
|
+
range: range != null ? range : [0, 0],
|
|
50
|
+
parent: parent != null ? parent : EMPTY_PARENT
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function ident(name, info) {
|
|
55
|
+
return {
|
|
56
|
+
type: 'Identifier',
|
|
57
|
+
name,
|
|
58
|
+
optional: false,
|
|
59
|
+
typeAnnotation: null,
|
|
60
|
+
...etc(info)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function stringLiteral(value, info) {
|
|
65
|
+
return {
|
|
66
|
+
type: 'Literal',
|
|
67
|
+
value,
|
|
68
|
+
raw: `"${value}"`,
|
|
69
|
+
literalType: 'string',
|
|
70
|
+
...etc(info)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function numberLiteral(value, info) {
|
|
75
|
+
return {
|
|
76
|
+
type: 'Literal',
|
|
77
|
+
value,
|
|
78
|
+
raw: String(value),
|
|
79
|
+
literalType: 'numeric',
|
|
80
|
+
...etc(info)
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function nullLiteral(info) {
|
|
85
|
+
return {
|
|
86
|
+
type: 'Literal',
|
|
87
|
+
value: null,
|
|
88
|
+
raw: 'null',
|
|
89
|
+
literalType: 'null',
|
|
90
|
+
...etc(info)
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function conjunction(tests) {
|
|
95
|
+
if (tests.length === 0) {
|
|
96
|
+
throw new Error('Must have at least one test.');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return tests.reduce((acc, test) => ({
|
|
100
|
+
type: 'LogicalExpression',
|
|
101
|
+
left: acc,
|
|
102
|
+
right: test,
|
|
103
|
+
operator: '&&',
|
|
104
|
+
...etc()
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function disjunction(tests) {
|
|
109
|
+
if (tests.length === 0) {
|
|
110
|
+
throw new Error('Must have at least one test.');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return tests.reduce((acc, test) => ({
|
|
114
|
+
type: 'LogicalExpression',
|
|
115
|
+
left: acc,
|
|
116
|
+
right: test,
|
|
117
|
+
operator: '||',
|
|
118
|
+
...etc()
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function variableDeclaration(kind, id, init, info) {
|
|
123
|
+
return {
|
|
124
|
+
type: 'VariableDeclaration',
|
|
125
|
+
kind,
|
|
126
|
+
declarations: [{
|
|
127
|
+
type: 'VariableDeclarator',
|
|
128
|
+
init,
|
|
129
|
+
id,
|
|
130
|
+
...etc(),
|
|
131
|
+
parent: EMPTY_PARENT
|
|
132
|
+
}],
|
|
133
|
+
...etc(info)
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function callExpression(callee, args, info) {
|
|
138
|
+
return {
|
|
139
|
+
type: 'CallExpression',
|
|
140
|
+
callee,
|
|
141
|
+
arguments: args,
|
|
142
|
+
typeArguments: null,
|
|
143
|
+
optional: false,
|
|
144
|
+
...etc(info)
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function throwStatement(arg, info) {
|
|
149
|
+
return {
|
|
150
|
+
type: 'ThrowStatement',
|
|
151
|
+
argument: callExpression(ident('Error'), [arg]),
|
|
152
|
+
...etc(info)
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function iife(statements, params = [], args = []) {
|
|
157
|
+
const callee = {
|
|
158
|
+
type: 'ArrowFunctionExpression',
|
|
159
|
+
params,
|
|
160
|
+
expression: false,
|
|
161
|
+
async: false,
|
|
162
|
+
predicate: null,
|
|
163
|
+
returnType: null,
|
|
164
|
+
typeParameters: null,
|
|
165
|
+
id: null,
|
|
166
|
+
body: {
|
|
167
|
+
type: 'BlockStatement',
|
|
168
|
+
body: statements,
|
|
169
|
+
...etc()
|
|
170
|
+
},
|
|
171
|
+
...etc()
|
|
172
|
+
};
|
|
173
|
+
return callExpression(callee, args);
|
|
174
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
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
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
import type {
|
|
14
|
+
ArrowFunctionExpression,
|
|
15
|
+
BindingName,
|
|
16
|
+
CallExpression,
|
|
17
|
+
ESNode,
|
|
18
|
+
Expression,
|
|
19
|
+
Identifier,
|
|
20
|
+
LogicalExpression,
|
|
21
|
+
NullLiteral,
|
|
22
|
+
NumericLiteral,
|
|
23
|
+
Position,
|
|
24
|
+
Range,
|
|
25
|
+
SourceLocation,
|
|
26
|
+
SpreadElement,
|
|
27
|
+
Statement,
|
|
28
|
+
StringLiteral,
|
|
29
|
+
Super,
|
|
30
|
+
ThrowStatement,
|
|
31
|
+
VariableDeclaration,
|
|
32
|
+
} from 'hermes-estree';
|
|
33
|
+
|
|
34
|
+
// Rely on the mapper to fix up parent relationships.
|
|
35
|
+
export const EMPTY_PARENT: $FlowFixMe = null;
|
|
36
|
+
|
|
37
|
+
export function createDefaultPosition(): Position {
|
|
38
|
+
return {
|
|
39
|
+
line: 1,
|
|
40
|
+
column: 0,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type Etc = {
|
|
45
|
+
parent?: ESNode,
|
|
46
|
+
loc?: SourceLocation,
|
|
47
|
+
range?: Range,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export function etc({loc, range, parent}: Etc = {}): {
|
|
51
|
+
parent: ESNode,
|
|
52
|
+
loc: SourceLocation,
|
|
53
|
+
range: Range,
|
|
54
|
+
} {
|
|
55
|
+
return {
|
|
56
|
+
loc: {
|
|
57
|
+
start: loc?.start != null ? loc.start : createDefaultPosition(),
|
|
58
|
+
end: loc?.end != null ? loc.end : createDefaultPosition(),
|
|
59
|
+
},
|
|
60
|
+
range: range ?? [0, 0],
|
|
61
|
+
parent: parent ?? EMPTY_PARENT,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function ident(name: string, info?: Etc): Identifier {
|
|
66
|
+
return {
|
|
67
|
+
type: 'Identifier',
|
|
68
|
+
name,
|
|
69
|
+
optional: false,
|
|
70
|
+
typeAnnotation: null,
|
|
71
|
+
...etc(info),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function stringLiteral(value: string, info?: Etc): StringLiteral {
|
|
76
|
+
return {
|
|
77
|
+
type: 'Literal',
|
|
78
|
+
value,
|
|
79
|
+
raw: `"${value}"`,
|
|
80
|
+
literalType: 'string',
|
|
81
|
+
...etc(info),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function numberLiteral(value: number, info?: Etc): NumericLiteral {
|
|
86
|
+
return {
|
|
87
|
+
type: 'Literal',
|
|
88
|
+
value,
|
|
89
|
+
raw: String(value),
|
|
90
|
+
literalType: 'numeric',
|
|
91
|
+
...etc(info),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function nullLiteral(info?: Etc): NullLiteral {
|
|
96
|
+
return {
|
|
97
|
+
type: 'Literal',
|
|
98
|
+
value: null,
|
|
99
|
+
raw: 'null',
|
|
100
|
+
literalType: 'null',
|
|
101
|
+
...etc(info),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function conjunction(tests: $ReadOnlyArray<Expression>): Expression {
|
|
106
|
+
if (tests.length === 0) {
|
|
107
|
+
throw new Error('Must have at least one test.');
|
|
108
|
+
}
|
|
109
|
+
return tests.reduce((acc, test): LogicalExpression => ({
|
|
110
|
+
type: 'LogicalExpression',
|
|
111
|
+
left: acc,
|
|
112
|
+
right: test,
|
|
113
|
+
operator: '&&',
|
|
114
|
+
...etc(),
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function disjunction(tests: $ReadOnlyArray<Expression>): Expression {
|
|
119
|
+
if (tests.length === 0) {
|
|
120
|
+
throw new Error('Must have at least one test.');
|
|
121
|
+
}
|
|
122
|
+
return tests.reduce((acc, test): LogicalExpression => ({
|
|
123
|
+
type: 'LogicalExpression',
|
|
124
|
+
left: acc,
|
|
125
|
+
right: test,
|
|
126
|
+
operator: '||',
|
|
127
|
+
...etc(),
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function variableDeclaration(
|
|
132
|
+
kind: VariableDeclaration['kind'],
|
|
133
|
+
id: BindingName,
|
|
134
|
+
init: Expression,
|
|
135
|
+
info?: Etc,
|
|
136
|
+
): VariableDeclaration {
|
|
137
|
+
return {
|
|
138
|
+
type: 'VariableDeclaration',
|
|
139
|
+
kind,
|
|
140
|
+
declarations: [
|
|
141
|
+
{
|
|
142
|
+
type: 'VariableDeclarator',
|
|
143
|
+
init,
|
|
144
|
+
id,
|
|
145
|
+
...etc(),
|
|
146
|
+
parent: EMPTY_PARENT,
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
...etc(info),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function callExpression(
|
|
154
|
+
callee: Expression | Super,
|
|
155
|
+
args: $ReadOnlyArray<Expression | SpreadElement>,
|
|
156
|
+
info?: Etc,
|
|
157
|
+
): CallExpression {
|
|
158
|
+
return {
|
|
159
|
+
type: 'CallExpression',
|
|
160
|
+
callee,
|
|
161
|
+
arguments: args,
|
|
162
|
+
typeArguments: null,
|
|
163
|
+
optional: false,
|
|
164
|
+
...etc(info),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function throwStatement(arg: Expression, info?: Etc): ThrowStatement {
|
|
169
|
+
return {
|
|
170
|
+
type: 'ThrowStatement',
|
|
171
|
+
argument: callExpression(ident('Error'), [arg]),
|
|
172
|
+
...etc(info),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function iife(
|
|
177
|
+
statements: $ReadOnlyArray<Statement>,
|
|
178
|
+
params: $ReadOnlyArray<BindingName> = [],
|
|
179
|
+
args: $ReadOnlyArray<Expression> = [],
|
|
180
|
+
): CallExpression {
|
|
181
|
+
const callee: ArrowFunctionExpression = {
|
|
182
|
+
type: 'ArrowFunctionExpression',
|
|
183
|
+
params,
|
|
184
|
+
expression: false,
|
|
185
|
+
async: false,
|
|
186
|
+
predicate: null,
|
|
187
|
+
returnType: null,
|
|
188
|
+
typeParameters: null,
|
|
189
|
+
id: null,
|
|
190
|
+
body: {
|
|
191
|
+
type: 'BlockStatement',
|
|
192
|
+
body: statements,
|
|
193
|
+
...etc(),
|
|
194
|
+
},
|
|
195
|
+
...etc(),
|
|
196
|
+
};
|
|
197
|
+
return callExpression(callee, args);
|
|
198
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, "__esModule", {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
exports.createGenID = createGenID;
|
|
16
|
+
const genPrefix = '$$gen$';
|
|
17
|
+
|
|
18
|
+
function createGenID(uniqueTransformPrefix) {
|
|
19
|
+
let genN = 0;
|
|
20
|
+
const used = new Set();
|
|
21
|
+
return {
|
|
22
|
+
genID() {
|
|
23
|
+
let name;
|
|
24
|
+
|
|
25
|
+
do {
|
|
26
|
+
name = `${genPrefix}${uniqueTransformPrefix}${genN}`;
|
|
27
|
+
genN++;
|
|
28
|
+
} while (used.has(name));
|
|
29
|
+
|
|
30
|
+
used.add(name);
|
|
31
|
+
return name;
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
addUsage(name) {
|
|
35
|
+
if (name.startsWith(genPrefix)) {
|
|
36
|
+
used.add(name);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const genPrefix = '$$gen$';
|
|
14
|
+
|
|
15
|
+
export function createGenID(uniqueTransformPrefix: string): {
|
|
16
|
+
genID(): string,
|
|
17
|
+
addUsage(string): void,
|
|
18
|
+
} {
|
|
19
|
+
let genN: number = 0;
|
|
20
|
+
const used = new Set<string>();
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
genID(): string {
|
|
24
|
+
let name;
|
|
25
|
+
do {
|
|
26
|
+
name = `${genPrefix}${uniqueTransformPrefix}${genN}`;
|
|
27
|
+
genN++;
|
|
28
|
+
} while (used.has(name));
|
|
29
|
+
used.add(name);
|
|
30
|
+
return name;
|
|
31
|
+
},
|
|
32
|
+
addUsage(name: string): void {
|
|
33
|
+
if (name.startsWith(genPrefix)) {
|
|
34
|
+
used.add(name);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hermes-parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.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.26.0"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@babel/parser": "7.7.4",
|