hermes-parser 0.32.1 → 0.33.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 +109 -5
- package/dist/HermesParserWASM.js +1 -1
- package/dist/HermesParserWASM.js.flow +11 -1
- package/dist/ParserOptions.js +1 -1
- package/dist/ParserOptions.js.flow +2 -0
- package/dist/babel/TransformESTreeToBabel.js +76 -3
- package/dist/babel/TransformESTreeToBabel.js.flow +73 -2
- package/dist/estree/StripFlowTypes.js +1 -1
- package/dist/estree/StripFlowTypes.js.flow +1 -1
- package/dist/estree/TransformMatchSyntax.js +124 -56
- package/dist/estree/TransformMatchSyntax.js.flow +124 -46
- package/dist/estree/TransformRecordSyntax.js +294 -0
- package/dist/estree/TransformRecordSyntax.js.flow +308 -0
- package/dist/generated/ESTreeVisitorKeys.js +16 -4
- package/dist/generated/ParserVisitorKeys.js +45 -4
- package/dist/index.js +8 -1
- package/dist/index.js.flow +7 -0
- package/dist/src/HermesParser.js +2 -2
- package/dist/src/HermesParserNodeDeserializers.js +109 -5
- package/dist/src/ParserOptions.js +1 -1
- package/dist/src/babel/TransformESTreeToBabel.js +76 -3
- package/dist/src/estree/StripFlowTypes.js +1 -1
- package/dist/src/estree/TransformMatchSyntax.js +124 -56
- package/dist/src/estree/TransformRecordSyntax.js +294 -0
- package/dist/src/generated/ESTreeVisitorKeys.js +16 -4
- package/dist/src/generated/ParserVisitorKeys.js +45 -4
- package/dist/src/index.js +8 -1
- package/dist/src/utils/GenID.js +28 -23
- package/dist/src/utils/isReservedWord.js +62 -0
- package/dist/utils/GenID.js +28 -23
- package/dist/utils/GenID.js.flow +23 -22
- package/dist/utils/isReservedWord.js +62 -0
- package/dist/utils/isReservedWord.js.flow +57 -0
- package/package.json +2 -2
|
@@ -0,0 +1,308 @@
|
|
|
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
|
+
/**
|
|
14
|
+
* Transform record declarations.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type {ParserOptions} from '../ParserOptions';
|
|
18
|
+
import type {
|
|
19
|
+
AssignmentPattern,
|
|
20
|
+
ClassDeclaration,
|
|
21
|
+
ClassMember,
|
|
22
|
+
ESNode,
|
|
23
|
+
Identifier,
|
|
24
|
+
MemberExpression,
|
|
25
|
+
MethodDefinition,
|
|
26
|
+
NewExpression,
|
|
27
|
+
ObjectExpression,
|
|
28
|
+
ObjectPattern,
|
|
29
|
+
ObjectPropertyKey,
|
|
30
|
+
Program,
|
|
31
|
+
RecordDeclaration,
|
|
32
|
+
RecordDeclarationProperty,
|
|
33
|
+
RecordDeclarationStaticProperty,
|
|
34
|
+
RecordExpression,
|
|
35
|
+
ThisExpression,
|
|
36
|
+
} from 'hermes-estree';
|
|
37
|
+
|
|
38
|
+
import {isBigIntLiteral} from 'hermes-estree';
|
|
39
|
+
import {SimpleTransform} from '../transform/SimpleTransform';
|
|
40
|
+
import {
|
|
41
|
+
deepCloneNode,
|
|
42
|
+
shallowCloneNode,
|
|
43
|
+
} from '../transform/astNodeMutationHelpers';
|
|
44
|
+
import {EMPTY_PARENT, etc, ident} from '../utils/Builders';
|
|
45
|
+
import isReservedWord from '../utils/isReservedWord';
|
|
46
|
+
import GenID from '../utils/GenID';
|
|
47
|
+
|
|
48
|
+
function nameOfKey(key: ObjectPropertyKey): string {
|
|
49
|
+
switch (key.type) {
|
|
50
|
+
case 'Identifier':
|
|
51
|
+
return key.name;
|
|
52
|
+
case 'Literal':
|
|
53
|
+
if (isBigIntLiteral(key)) {
|
|
54
|
+
return key.bigint;
|
|
55
|
+
}
|
|
56
|
+
return String(key.value);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function mapRecordDeclaration(
|
|
61
|
+
genID: GenID,
|
|
62
|
+
node: RecordDeclaration,
|
|
63
|
+
): ClassDeclaration {
|
|
64
|
+
const ownProperties: Array<RecordDeclarationProperty> = [];
|
|
65
|
+
const staticProperties: Array<RecordDeclarationStaticProperty> = [];
|
|
66
|
+
const methods: Array<MethodDefinition> = [];
|
|
67
|
+
const staticMethods: Array<MethodDefinition> = [];
|
|
68
|
+
|
|
69
|
+
for (const element of node.body.elements) {
|
|
70
|
+
switch (element.type) {
|
|
71
|
+
case 'RecordDeclarationProperty':
|
|
72
|
+
ownProperties.push(element);
|
|
73
|
+
break;
|
|
74
|
+
case 'RecordDeclarationStaticProperty':
|
|
75
|
+
staticProperties.push(element);
|
|
76
|
+
break;
|
|
77
|
+
case 'MethodDefinition':
|
|
78
|
+
if (element.static) {
|
|
79
|
+
staticMethods.push(element);
|
|
80
|
+
} else {
|
|
81
|
+
methods.push(element);
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const reservedPropNames = new Map<string, string>();
|
|
88
|
+
|
|
89
|
+
// Create constructor parameter as an object pattern with all properties
|
|
90
|
+
const constructorParam: ObjectPattern = {
|
|
91
|
+
type: 'ObjectPattern',
|
|
92
|
+
properties: ownProperties.map(prop => {
|
|
93
|
+
const {key, defaultValue} = prop;
|
|
94
|
+
const keyName = nameOfKey(key);
|
|
95
|
+
|
|
96
|
+
const getValue = (
|
|
97
|
+
bindingIdent: Identifier,
|
|
98
|
+
): AssignmentPattern | Identifier =>
|
|
99
|
+
defaultValue != null
|
|
100
|
+
? {
|
|
101
|
+
type: 'AssignmentPattern',
|
|
102
|
+
left: bindingIdent,
|
|
103
|
+
right: deepCloneNode(defaultValue),
|
|
104
|
+
...etc(),
|
|
105
|
+
}
|
|
106
|
+
: bindingIdent;
|
|
107
|
+
|
|
108
|
+
switch (key.type) {
|
|
109
|
+
case 'Identifier': {
|
|
110
|
+
const needsNewBinding = isReservedWord(keyName);
|
|
111
|
+
const bindingName = needsNewBinding ? genID.id() : keyName;
|
|
112
|
+
const bindingIdent = ident(bindingName);
|
|
113
|
+
if (needsNewBinding) {
|
|
114
|
+
reservedPropNames.set(keyName, bindingName);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (needsNewBinding) {
|
|
118
|
+
return {
|
|
119
|
+
type: 'Property',
|
|
120
|
+
kind: 'init',
|
|
121
|
+
key: shallowCloneNode(key),
|
|
122
|
+
value: getValue(bindingIdent),
|
|
123
|
+
shorthand: false,
|
|
124
|
+
method: false,
|
|
125
|
+
computed: false,
|
|
126
|
+
...etc(),
|
|
127
|
+
parent: EMPTY_PARENT,
|
|
128
|
+
};
|
|
129
|
+
} else {
|
|
130
|
+
return {
|
|
131
|
+
type: 'Property',
|
|
132
|
+
kind: 'init',
|
|
133
|
+
key: shallowCloneNode(key),
|
|
134
|
+
value: getValue(bindingIdent),
|
|
135
|
+
shorthand: true,
|
|
136
|
+
method: false,
|
|
137
|
+
computed: false,
|
|
138
|
+
...etc(),
|
|
139
|
+
parent: EMPTY_PARENT,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
case 'Literal': {
|
|
144
|
+
const bindingName = genID.id();
|
|
145
|
+
const bindingIdent = ident(bindingName);
|
|
146
|
+
reservedPropNames.set(keyName, bindingName);
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
type: 'Property',
|
|
150
|
+
kind: 'init',
|
|
151
|
+
key: shallowCloneNode(key),
|
|
152
|
+
value: getValue(bindingIdent),
|
|
153
|
+
shorthand: false,
|
|
154
|
+
method: false,
|
|
155
|
+
computed: false,
|
|
156
|
+
...etc(),
|
|
157
|
+
parent: EMPTY_PARENT,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}),
|
|
162
|
+
typeAnnotation: null,
|
|
163
|
+
...etc(),
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// Create the constructor method
|
|
167
|
+
const constructor: MethodDefinition = {
|
|
168
|
+
type: 'MethodDefinition',
|
|
169
|
+
key: ident('constructor'),
|
|
170
|
+
kind: 'constructor',
|
|
171
|
+
computed: false,
|
|
172
|
+
static: false,
|
|
173
|
+
value: {
|
|
174
|
+
type: 'FunctionExpression',
|
|
175
|
+
id: null,
|
|
176
|
+
params: [constructorParam],
|
|
177
|
+
body: {
|
|
178
|
+
type: 'BlockStatement',
|
|
179
|
+
body: ownProperties.map(({key}) => {
|
|
180
|
+
const keyName = nameOfKey(key);
|
|
181
|
+
const bindingIdent = ident(reservedPropNames.get(keyName) ?? keyName);
|
|
182
|
+
const object: ThisExpression = {type: 'ThisExpression', ...etc()};
|
|
183
|
+
const memberExpression: MemberExpression =
|
|
184
|
+
key.type === 'Identifier'
|
|
185
|
+
? {
|
|
186
|
+
type: 'MemberExpression',
|
|
187
|
+
object,
|
|
188
|
+
property: shallowCloneNode(key),
|
|
189
|
+
computed: false,
|
|
190
|
+
optional: false,
|
|
191
|
+
...etc(),
|
|
192
|
+
}
|
|
193
|
+
: {
|
|
194
|
+
type: 'MemberExpression',
|
|
195
|
+
object,
|
|
196
|
+
property: shallowCloneNode(key),
|
|
197
|
+
computed: true,
|
|
198
|
+
optional: false,
|
|
199
|
+
...etc(),
|
|
200
|
+
};
|
|
201
|
+
return {
|
|
202
|
+
type: 'ExpressionStatement',
|
|
203
|
+
expression: {
|
|
204
|
+
type: 'AssignmentExpression',
|
|
205
|
+
operator: '=',
|
|
206
|
+
left: memberExpression,
|
|
207
|
+
right: bindingIdent,
|
|
208
|
+
...etc(),
|
|
209
|
+
},
|
|
210
|
+
directive: null,
|
|
211
|
+
...etc(),
|
|
212
|
+
};
|
|
213
|
+
}),
|
|
214
|
+
...etc(),
|
|
215
|
+
},
|
|
216
|
+
generator: false,
|
|
217
|
+
async: false,
|
|
218
|
+
predicate: null,
|
|
219
|
+
returnType: null,
|
|
220
|
+
typeParameters: null,
|
|
221
|
+
...etc(),
|
|
222
|
+
},
|
|
223
|
+
...etc(),
|
|
224
|
+
parent: EMPTY_PARENT,
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const classStaticProperties: ReadonlyArray<ClassMember> =
|
|
228
|
+
staticProperties.map(prop => ({
|
|
229
|
+
type: 'PropertyDefinition',
|
|
230
|
+
key: shallowCloneNode(prop.key),
|
|
231
|
+
value: deepCloneNode(prop.value),
|
|
232
|
+
static: true,
|
|
233
|
+
typeAnnotation: null,
|
|
234
|
+
variance: null,
|
|
235
|
+
computed: false,
|
|
236
|
+
declare: false,
|
|
237
|
+
optional: false,
|
|
238
|
+
...etc(),
|
|
239
|
+
parent: EMPTY_PARENT,
|
|
240
|
+
}));
|
|
241
|
+
|
|
242
|
+
const classBodyElements: ReadonlyArray<ClassMember> = [
|
|
243
|
+
constructor,
|
|
244
|
+
...methods,
|
|
245
|
+
...classStaticProperties,
|
|
246
|
+
...staticMethods,
|
|
247
|
+
];
|
|
248
|
+
|
|
249
|
+
return {
|
|
250
|
+
type: 'ClassDeclaration',
|
|
251
|
+
id: shallowCloneNode(node.id),
|
|
252
|
+
body: {
|
|
253
|
+
type: 'ClassBody',
|
|
254
|
+
body: classBodyElements,
|
|
255
|
+
...etc(),
|
|
256
|
+
parent: EMPTY_PARENT,
|
|
257
|
+
},
|
|
258
|
+
superClass: null,
|
|
259
|
+
typeParameters: null,
|
|
260
|
+
superTypeArguments: null,
|
|
261
|
+
implements: [],
|
|
262
|
+
decorators: [],
|
|
263
|
+
...etc(),
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function mapRecordExpression(node: RecordExpression): NewExpression {
|
|
268
|
+
const obj: ObjectExpression = {
|
|
269
|
+
type: 'ObjectExpression',
|
|
270
|
+
properties: node.properties.properties,
|
|
271
|
+
...etc(),
|
|
272
|
+
};
|
|
273
|
+
return {
|
|
274
|
+
type: 'NewExpression',
|
|
275
|
+
callee: node.recordConstructor,
|
|
276
|
+
arguments: [obj],
|
|
277
|
+
typeArguments: null,
|
|
278
|
+
...etc(),
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export function transformProgram(
|
|
283
|
+
program: Program,
|
|
284
|
+
_options: ParserOptions,
|
|
285
|
+
): Program {
|
|
286
|
+
const genID = new GenID('r');
|
|
287
|
+
return SimpleTransform.transformProgram(program, {
|
|
288
|
+
transform(node: ESNode) {
|
|
289
|
+
switch (node.type) {
|
|
290
|
+
case 'RecordDeclaration': {
|
|
291
|
+
return mapRecordDeclaration(genID, node);
|
|
292
|
+
}
|
|
293
|
+
case 'RecordExpression': {
|
|
294
|
+
return mapRecordExpression(node);
|
|
295
|
+
}
|
|
296
|
+
case 'Identifier': {
|
|
297
|
+
// A rudimentary check to avoid some collisions with our generated
|
|
298
|
+
// variable names. Ideally, we would have access a scope analyzer
|
|
299
|
+
// inside the transform instead.
|
|
300
|
+
genID.addUsage(node.name);
|
|
301
|
+
return node;
|
|
302
|
+
}
|
|
303
|
+
default:
|
|
304
|
+
return node;
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
});
|
|
308
|
+
}
|
|
@@ -26,7 +26,7 @@ module.exports = {
|
|
|
26
26
|
ArrayExpression: ['elements'],
|
|
27
27
|
ArrayPattern: ['elements', 'typeAnnotation'],
|
|
28
28
|
ArrayTypeAnnotation: ['elementType'],
|
|
29
|
-
ArrowFunctionExpression: ['
|
|
29
|
+
ArrowFunctionExpression: ['params', 'body', 'typeParameters', 'returnType', 'predicate'],
|
|
30
30
|
AsConstExpression: ['expression'],
|
|
31
31
|
AsExpression: ['expression', 'typeAnnotation'],
|
|
32
32
|
AssignmentExpression: ['left', 'right'],
|
|
@@ -43,8 +43,8 @@ module.exports = {
|
|
|
43
43
|
CatchClause: ['param', 'body'],
|
|
44
44
|
ChainExpression: ['expression'],
|
|
45
45
|
ClassBody: ['body'],
|
|
46
|
-
ClassDeclaration: ['id', 'typeParameters', 'superClass', '
|
|
47
|
-
ClassExpression: ['id', 'typeParameters', 'superClass', '
|
|
46
|
+
ClassDeclaration: ['id', 'typeParameters', 'superClass', 'superTypeArguments', 'implements', 'decorators', 'body'],
|
|
47
|
+
ClassExpression: ['id', 'typeParameters', 'superClass', 'superTypeArguments', 'implements', 'decorators', 'body'],
|
|
48
48
|
ClassImplements: ['id', 'typeParameters'],
|
|
49
49
|
ComponentDeclaration: ['id', 'params', 'body', 'typeParameters', 'rendersType'],
|
|
50
50
|
ComponentParameter: ['name', 'local'],
|
|
@@ -138,6 +138,8 @@ module.exports = {
|
|
|
138
138
|
MatchExpression: ['argument', 'cases'],
|
|
139
139
|
MatchExpressionCase: ['pattern', 'body', 'guard'],
|
|
140
140
|
MatchIdentifierPattern: ['id'],
|
|
141
|
+
MatchInstanceObjectPattern: ['properties', 'rest'],
|
|
142
|
+
MatchInstancePattern: ['targetConstructor', 'properties'],
|
|
141
143
|
MatchLiteralPattern: ['literal'],
|
|
142
144
|
MatchMemberPattern: ['base', 'property'],
|
|
143
145
|
MatchObjectPattern: ['properties', 'rest'],
|
|
@@ -152,6 +154,7 @@ module.exports = {
|
|
|
152
154
|
MetaProperty: ['meta', 'property'],
|
|
153
155
|
MethodDefinition: ['key', 'value'],
|
|
154
156
|
MixedTypeAnnotation: [],
|
|
157
|
+
NeverTypeAnnotation: [],
|
|
155
158
|
NewExpression: ['callee', 'typeArguments', 'arguments'],
|
|
156
159
|
NullableTypeAnnotation: ['typeAnnotation'],
|
|
157
160
|
NullLiteralTypeAnnotation: [],
|
|
@@ -174,6 +177,13 @@ module.exports = {
|
|
|
174
177
|
PropertyDefinition: ['key', 'value', 'variance', 'typeAnnotation'],
|
|
175
178
|
QualifiedTypeIdentifier: ['qualification', 'id'],
|
|
176
179
|
QualifiedTypeofIdentifier: ['qualification', 'id'],
|
|
180
|
+
RecordDeclaration: ['id', 'typeParameters', 'implements', 'body'],
|
|
181
|
+
RecordDeclarationBody: ['elements'],
|
|
182
|
+
RecordDeclarationImplements: ['id', 'typeArguments'],
|
|
183
|
+
RecordDeclarationProperty: ['key', 'typeAnnotation', 'defaultValue'],
|
|
184
|
+
RecordDeclarationStaticProperty: ['key', 'typeAnnotation', 'value'],
|
|
185
|
+
RecordExpression: ['recordConstructor', 'typeArguments', 'properties'],
|
|
186
|
+
RecordExpressionProperties: ['properties'],
|
|
177
187
|
RestElement: ['argument'],
|
|
178
188
|
ReturnStatement: ['argument'],
|
|
179
189
|
SequenceExpression: ['expressions'],
|
|
@@ -192,7 +202,7 @@ module.exports = {
|
|
|
192
202
|
ThisTypeAnnotation: [],
|
|
193
203
|
ThrowStatement: ['argument'],
|
|
194
204
|
TryStatement: ['block', 'handler', 'finalizer'],
|
|
195
|
-
TupleTypeAnnotation: ['
|
|
205
|
+
TupleTypeAnnotation: ['elementTypes'],
|
|
196
206
|
TupleTypeLabeledElement: ['label', 'elementType', 'variance'],
|
|
197
207
|
TupleTypeSpreadElement: ['label', 'typeAnnotation'],
|
|
198
208
|
TypeAlias: ['id', 'typeParameters', 'right'],
|
|
@@ -205,7 +215,9 @@ module.exports = {
|
|
|
205
215
|
TypeParameterInstantiation: ['params'],
|
|
206
216
|
TypePredicate: ['parameterName', 'typeAnnotation'],
|
|
207
217
|
UnaryExpression: ['argument'],
|
|
218
|
+
UndefinedTypeAnnotation: [],
|
|
208
219
|
UnionTypeAnnotation: ['types'],
|
|
220
|
+
UnknownTypeAnnotation: [],
|
|
209
221
|
UpdateExpression: ['argument'],
|
|
210
222
|
VariableDeclaration: ['declarations'],
|
|
211
223
|
VariableDeclarator: ['id', 'init'],
|
|
@@ -42,7 +42,6 @@ const HERMES_AST_VISITOR_KEYS = {
|
|
|
42
42
|
elementType: 'Node'
|
|
43
43
|
},
|
|
44
44
|
ArrowFunctionExpression: {
|
|
45
|
-
id: 'Node',
|
|
46
45
|
params: 'NodeList',
|
|
47
46
|
body: 'Node',
|
|
48
47
|
typeParameters: 'Node',
|
|
@@ -102,7 +101,7 @@ const HERMES_AST_VISITOR_KEYS = {
|
|
|
102
101
|
id: 'Node',
|
|
103
102
|
typeParameters: 'Node',
|
|
104
103
|
superClass: 'Node',
|
|
105
|
-
|
|
104
|
+
superTypeArguments: 'Node',
|
|
106
105
|
implements: 'NodeList',
|
|
107
106
|
decorators: 'NodeList',
|
|
108
107
|
body: 'Node'
|
|
@@ -111,7 +110,7 @@ const HERMES_AST_VISITOR_KEYS = {
|
|
|
111
110
|
id: 'Node',
|
|
112
111
|
typeParameters: 'Node',
|
|
113
112
|
superClass: 'Node',
|
|
114
|
-
|
|
113
|
+
superTypeArguments: 'Node',
|
|
115
114
|
implements: 'NodeList',
|
|
116
115
|
decorators: 'NodeList',
|
|
117
116
|
body: 'Node'
|
|
@@ -484,6 +483,14 @@ const HERMES_AST_VISITOR_KEYS = {
|
|
|
484
483
|
MatchIdentifierPattern: {
|
|
485
484
|
id: 'Node'
|
|
486
485
|
},
|
|
486
|
+
MatchInstanceObjectPattern: {
|
|
487
|
+
properties: 'NodeList',
|
|
488
|
+
rest: 'Node'
|
|
489
|
+
},
|
|
490
|
+
MatchInstancePattern: {
|
|
491
|
+
targetConstructor: 'Node',
|
|
492
|
+
properties: 'Node'
|
|
493
|
+
},
|
|
487
494
|
MatchLiteralPattern: {
|
|
488
495
|
literal: 'Node'
|
|
489
496
|
},
|
|
@@ -531,6 +538,7 @@ const HERMES_AST_VISITOR_KEYS = {
|
|
|
531
538
|
value: 'Node'
|
|
532
539
|
},
|
|
533
540
|
MixedTypeAnnotation: {},
|
|
541
|
+
NeverTypeAnnotation: {},
|
|
534
542
|
NewExpression: {
|
|
535
543
|
callee: 'Node',
|
|
536
544
|
typeArguments: 'Node',
|
|
@@ -618,6 +626,37 @@ const HERMES_AST_VISITOR_KEYS = {
|
|
|
618
626
|
qualification: 'Node',
|
|
619
627
|
id: 'Node'
|
|
620
628
|
},
|
|
629
|
+
RecordDeclaration: {
|
|
630
|
+
id: 'Node',
|
|
631
|
+
typeParameters: 'Node',
|
|
632
|
+
implements: 'NodeList',
|
|
633
|
+
body: 'Node'
|
|
634
|
+
},
|
|
635
|
+
RecordDeclarationBody: {
|
|
636
|
+
elements: 'NodeList'
|
|
637
|
+
},
|
|
638
|
+
RecordDeclarationImplements: {
|
|
639
|
+
id: 'Node',
|
|
640
|
+
typeArguments: 'Node'
|
|
641
|
+
},
|
|
642
|
+
RecordDeclarationProperty: {
|
|
643
|
+
key: 'Node',
|
|
644
|
+
typeAnnotation: 'Node',
|
|
645
|
+
defaultValue: 'Node'
|
|
646
|
+
},
|
|
647
|
+
RecordDeclarationStaticProperty: {
|
|
648
|
+
key: 'Node',
|
|
649
|
+
typeAnnotation: 'Node',
|
|
650
|
+
value: 'Node'
|
|
651
|
+
},
|
|
652
|
+
RecordExpression: {
|
|
653
|
+
recordConstructor: 'Node',
|
|
654
|
+
typeArguments: 'Node',
|
|
655
|
+
properties: 'Node'
|
|
656
|
+
},
|
|
657
|
+
RecordExpressionProperties: {
|
|
658
|
+
properties: 'NodeList'
|
|
659
|
+
},
|
|
621
660
|
RegExpLiteral: {},
|
|
622
661
|
RestElement: {
|
|
623
662
|
argument: 'Node'
|
|
@@ -667,7 +706,7 @@ const HERMES_AST_VISITOR_KEYS = {
|
|
|
667
706
|
finalizer: 'Node'
|
|
668
707
|
},
|
|
669
708
|
TupleTypeAnnotation: {
|
|
670
|
-
|
|
709
|
+
elementTypes: 'NodeList'
|
|
671
710
|
},
|
|
672
711
|
TupleTypeLabeledElement: {
|
|
673
712
|
label: 'Node',
|
|
@@ -715,9 +754,11 @@ const HERMES_AST_VISITOR_KEYS = {
|
|
|
715
754
|
UnaryExpression: {
|
|
716
755
|
argument: 'Node'
|
|
717
756
|
},
|
|
757
|
+
UndefinedTypeAnnotation: {},
|
|
718
758
|
UnionTypeAnnotation: {
|
|
719
759
|
types: 'NodeList'
|
|
720
760
|
},
|
|
761
|
+
UnknownTypeAnnotation: {},
|
|
721
762
|
UpdateExpression: {
|
|
722
763
|
argument: 'Node'
|
|
723
764
|
},
|
package/dist/index.js
CHANGED
|
@@ -37,6 +37,8 @@ var TransformEnumSyntax = _interopRequireWildcard(require("./estree/TransformEnu
|
|
|
37
37
|
|
|
38
38
|
var TransformMatchSyntax = _interopRequireWildcard(require("./estree/TransformMatchSyntax"));
|
|
39
39
|
|
|
40
|
+
var TransformRecordSyntax = _interopRequireWildcard(require("./estree/TransformRecordSyntax"));
|
|
41
|
+
|
|
40
42
|
var StripFlowTypesForBabel = _interopRequireWildcard(require("./estree/StripFlowTypesForBabel"));
|
|
41
43
|
|
|
42
44
|
var TransformESTreeToBabel = _interopRequireWildcard(require("./babel/TransformESTreeToBabel"));
|
|
@@ -126,6 +128,10 @@ function getOptions(options = { ...DEFAULTS
|
|
|
126
128
|
options.enableExperimentalFlowMatchSyntax = true; // Enable by default
|
|
127
129
|
}
|
|
128
130
|
|
|
131
|
+
if (options.enableExperimentalFlowRecordSyntax == null) {
|
|
132
|
+
options.enableExperimentalFlowRecordSyntax = true; // Enable by default
|
|
133
|
+
}
|
|
134
|
+
|
|
129
135
|
options.tokens = options.tokens === true;
|
|
130
136
|
options.allowReturnOutsideFunction = options.allowReturnOutsideFunction === true;
|
|
131
137
|
return options;
|
|
@@ -142,7 +148,7 @@ function parse(code, opts) {
|
|
|
142
148
|
return estreeAST;
|
|
143
149
|
}
|
|
144
150
|
|
|
145
|
-
const loweredESTreeAST = [TransformEnumSyntax.transformProgram, TransformMatchSyntax.transformProgram, TransformComponentSyntax.transformProgram, StripFlowTypesForBabel.transformProgram].reduce((ast, transform) => transform(ast, options), estreeAST);
|
|
151
|
+
const loweredESTreeAST = [TransformEnumSyntax.transformProgram, TransformMatchSyntax.transformProgram, TransformComponentSyntax.transformProgram, TransformRecordSyntax.transformProgram, StripFlowTypesForBabel.transformProgram].reduce((ast, transform) => transform(ast, options), estreeAST);
|
|
146
152
|
return TransformESTreeToBabel.transformProgram(loweredESTreeAST, options);
|
|
147
153
|
}
|
|
148
154
|
|
|
@@ -150,6 +156,7 @@ const Transforms = {
|
|
|
150
156
|
transformEnumSyntax: TransformEnumSyntax.transformProgram,
|
|
151
157
|
transformMatchSyntax: TransformMatchSyntax.transformProgram,
|
|
152
158
|
transformComponentSyntax: TransformComponentSyntax.transformProgram,
|
|
159
|
+
transformRecordSyntax: TransformRecordSyntax.transformProgram,
|
|
153
160
|
stripFlowTypesForBabel: StripFlowTypesForBabel.transformProgram,
|
|
154
161
|
stripFlowTypes: StripFlowTypes.transformProgram
|
|
155
162
|
};
|
package/dist/index.js.flow
CHANGED
|
@@ -20,6 +20,7 @@ import FlowVisitorKeys from './generated/ESTreeVisitorKeys';
|
|
|
20
20
|
import * as TransformComponentSyntax from './estree/TransformComponentSyntax';
|
|
21
21
|
import * as TransformEnumSyntax from './estree/TransformEnumSyntax';
|
|
22
22
|
import * as TransformMatchSyntax from './estree/TransformMatchSyntax';
|
|
23
|
+
import * as TransformRecordSyntax from './estree/TransformRecordSyntax';
|
|
23
24
|
import * as StripFlowTypesForBabel from './estree/StripFlowTypesForBabel';
|
|
24
25
|
import * as TransformESTreeToBabel from './babel/TransformESTreeToBabel';
|
|
25
26
|
import * as StripFlowTypes from './estree/StripFlowTypes';
|
|
@@ -58,6 +59,10 @@ function getOptions(options?: ParserOptions = {...DEFAULTS}) {
|
|
|
58
59
|
options.enableExperimentalFlowMatchSyntax = true; // Enable by default
|
|
59
60
|
}
|
|
60
61
|
|
|
62
|
+
if (options.enableExperimentalFlowRecordSyntax == null) {
|
|
63
|
+
options.enableExperimentalFlowRecordSyntax = true; // Enable by default
|
|
64
|
+
}
|
|
65
|
+
|
|
61
66
|
options.tokens = options.tokens === true;
|
|
62
67
|
options.allowReturnOutsideFunction =
|
|
63
68
|
options.allowReturnOutsideFunction === true;
|
|
@@ -96,6 +101,7 @@ export function parse(
|
|
|
96
101
|
TransformEnumSyntax.transformProgram,
|
|
97
102
|
TransformMatchSyntax.transformProgram,
|
|
98
103
|
TransformComponentSyntax.transformProgram,
|
|
104
|
+
TransformRecordSyntax.transformProgram,
|
|
99
105
|
StripFlowTypesForBabel.transformProgram,
|
|
100
106
|
].reduce((ast, transform) => transform(ast, options), estreeAST);
|
|
101
107
|
|
|
@@ -116,6 +122,7 @@ const Transforms = {
|
|
|
116
122
|
transformEnumSyntax: TransformEnumSyntax.transformProgram,
|
|
117
123
|
transformMatchSyntax: TransformMatchSyntax.transformProgram,
|
|
118
124
|
transformComponentSyntax: TransformComponentSyntax.transformProgram,
|
|
125
|
+
transformRecordSyntax: TransformRecordSyntax.transformProgram,
|
|
119
126
|
stripFlowTypesForBabel: StripFlowTypesForBabel.transformProgram,
|
|
120
127
|
stripFlowTypes: StripFlowTypes.transformProgram,
|
|
121
128
|
};
|
package/dist/src/HermesParser.js
CHANGED
|
@@ -51,7 +51,7 @@ function initHermesParserWASM() {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
});
|
|
54
|
-
hermesParse = HermesParserWASM.cwrap('hermesParse', 'number', ['number', 'number', 'number', 'number', 'number', 'number', 'number']);
|
|
54
|
+
hermesParse = HermesParserWASM.cwrap('hermesParse', 'number', ['number', 'number', 'number', 'number', 'number', 'number', 'number', 'number']);
|
|
55
55
|
hermesParseResult_free = HermesParserWASM.cwrap('hermesParseResult_free', 'void', ['number']);
|
|
56
56
|
hermesParseResult_getError = HermesParserWASM.cwrap('hermesParseResult_getError', 'string', ['number']);
|
|
57
57
|
hermesParseResult_getErrorLine = HermesParserWASM.cwrap('hermesParseResult_getErrorLine', 'number', ['number']);
|
|
@@ -81,7 +81,7 @@ function parse(source, options) {
|
|
|
81
81
|
try {
|
|
82
82
|
// Copy source text onto WASM heap
|
|
83
83
|
copyToHeap(sourceBuffer, sourceAddr);
|
|
84
|
-
const parseResult = hermesParse(sourceAddr, sourceBuffer.length + 1, options.flow === 'detect', options.enableExperimentalComponentSyntax, options.enableExperimentalFlowMatchSyntax, options.tokens, options.allowReturnOutsideFunction);
|
|
84
|
+
const parseResult = hermesParse(sourceAddr, sourceBuffer.length + 1, options.flow === 'detect', options.enableExperimentalComponentSyntax, options.enableExperimentalFlowMatchSyntax, options.enableExperimentalFlowRecordSyntax, options.tokens, options.allowReturnOutsideFunction);
|
|
85
85
|
|
|
86
86
|
try {
|
|
87
87
|
// Extract and throw error from parse result if parsing failed
|