hermes-parser 0.32.1 → 0.33.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/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,294 @@
|
|
|
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
|
+
* Transform record declarations.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
Object.defineProperty(exports, "__esModule", {
|
|
16
|
+
value: true
|
|
17
|
+
});
|
|
18
|
+
exports.transformProgram = transformProgram;
|
|
19
|
+
|
|
20
|
+
var _hermesEstree = require("hermes-estree");
|
|
21
|
+
|
|
22
|
+
var _SimpleTransform = require("../transform/SimpleTransform");
|
|
23
|
+
|
|
24
|
+
var _astNodeMutationHelpers = require("../transform/astNodeMutationHelpers");
|
|
25
|
+
|
|
26
|
+
var _Builders = require("../utils/Builders");
|
|
27
|
+
|
|
28
|
+
var _isReservedWord = _interopRequireDefault(require("../utils/isReservedWord"));
|
|
29
|
+
|
|
30
|
+
var _GenID = _interopRequireDefault(require("../utils/GenID"));
|
|
31
|
+
|
|
32
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
33
|
+
|
|
34
|
+
function nameOfKey(key) {
|
|
35
|
+
switch (key.type) {
|
|
36
|
+
case 'Identifier':
|
|
37
|
+
return key.name;
|
|
38
|
+
|
|
39
|
+
case 'Literal':
|
|
40
|
+
if ((0, _hermesEstree.isBigIntLiteral)(key)) {
|
|
41
|
+
return key.bigint;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return String(key.value);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function mapRecordDeclaration(genID, node) {
|
|
49
|
+
const ownProperties = [];
|
|
50
|
+
const staticProperties = [];
|
|
51
|
+
const methods = [];
|
|
52
|
+
const staticMethods = [];
|
|
53
|
+
|
|
54
|
+
for (const element of node.body.elements) {
|
|
55
|
+
switch (element.type) {
|
|
56
|
+
case 'RecordDeclarationProperty':
|
|
57
|
+
ownProperties.push(element);
|
|
58
|
+
break;
|
|
59
|
+
|
|
60
|
+
case 'RecordDeclarationStaticProperty':
|
|
61
|
+
staticProperties.push(element);
|
|
62
|
+
break;
|
|
63
|
+
|
|
64
|
+
case 'MethodDefinition':
|
|
65
|
+
if (element.static) {
|
|
66
|
+
staticMethods.push(element);
|
|
67
|
+
} else {
|
|
68
|
+
methods.push(element);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const reservedPropNames = new Map(); // Create constructor parameter as an object pattern with all properties
|
|
76
|
+
|
|
77
|
+
const constructorParam = {
|
|
78
|
+
type: 'ObjectPattern',
|
|
79
|
+
properties: ownProperties.map(prop => {
|
|
80
|
+
const {
|
|
81
|
+
key,
|
|
82
|
+
defaultValue
|
|
83
|
+
} = prop;
|
|
84
|
+
const keyName = nameOfKey(key);
|
|
85
|
+
|
|
86
|
+
const getValue = bindingIdent => defaultValue != null ? {
|
|
87
|
+
type: 'AssignmentPattern',
|
|
88
|
+
left: bindingIdent,
|
|
89
|
+
right: (0, _astNodeMutationHelpers.deepCloneNode)(defaultValue),
|
|
90
|
+
...(0, _Builders.etc)()
|
|
91
|
+
} : bindingIdent;
|
|
92
|
+
|
|
93
|
+
switch (key.type) {
|
|
94
|
+
case 'Identifier':
|
|
95
|
+
{
|
|
96
|
+
const needsNewBinding = (0, _isReservedWord.default)(keyName);
|
|
97
|
+
const bindingName = needsNewBinding ? genID.id() : keyName;
|
|
98
|
+
const bindingIdent = (0, _Builders.ident)(bindingName);
|
|
99
|
+
|
|
100
|
+
if (needsNewBinding) {
|
|
101
|
+
reservedPropNames.set(keyName, bindingName);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (needsNewBinding) {
|
|
105
|
+
return {
|
|
106
|
+
type: 'Property',
|
|
107
|
+
kind: 'init',
|
|
108
|
+
key: (0, _astNodeMutationHelpers.shallowCloneNode)(key),
|
|
109
|
+
value: getValue(bindingIdent),
|
|
110
|
+
shorthand: false,
|
|
111
|
+
method: false,
|
|
112
|
+
computed: false,
|
|
113
|
+
...(0, _Builders.etc)(),
|
|
114
|
+
parent: _Builders.EMPTY_PARENT
|
|
115
|
+
};
|
|
116
|
+
} else {
|
|
117
|
+
return {
|
|
118
|
+
type: 'Property',
|
|
119
|
+
kind: 'init',
|
|
120
|
+
key: (0, _astNodeMutationHelpers.shallowCloneNode)(key),
|
|
121
|
+
value: getValue(bindingIdent),
|
|
122
|
+
shorthand: true,
|
|
123
|
+
method: false,
|
|
124
|
+
computed: false,
|
|
125
|
+
...(0, _Builders.etc)(),
|
|
126
|
+
parent: _Builders.EMPTY_PARENT
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
case 'Literal':
|
|
132
|
+
{
|
|
133
|
+
const bindingName = genID.id();
|
|
134
|
+
const bindingIdent = (0, _Builders.ident)(bindingName);
|
|
135
|
+
reservedPropNames.set(keyName, bindingName);
|
|
136
|
+
return {
|
|
137
|
+
type: 'Property',
|
|
138
|
+
kind: 'init',
|
|
139
|
+
key: (0, _astNodeMutationHelpers.shallowCloneNode)(key),
|
|
140
|
+
value: getValue(bindingIdent),
|
|
141
|
+
shorthand: false,
|
|
142
|
+
method: false,
|
|
143
|
+
computed: false,
|
|
144
|
+
...(0, _Builders.etc)(),
|
|
145
|
+
parent: _Builders.EMPTY_PARENT
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}),
|
|
150
|
+
typeAnnotation: null,
|
|
151
|
+
...(0, _Builders.etc)()
|
|
152
|
+
}; // Create the constructor method
|
|
153
|
+
|
|
154
|
+
const constructor = {
|
|
155
|
+
type: 'MethodDefinition',
|
|
156
|
+
key: (0, _Builders.ident)('constructor'),
|
|
157
|
+
kind: 'constructor',
|
|
158
|
+
computed: false,
|
|
159
|
+
static: false,
|
|
160
|
+
value: {
|
|
161
|
+
type: 'FunctionExpression',
|
|
162
|
+
id: null,
|
|
163
|
+
params: [constructorParam],
|
|
164
|
+
body: {
|
|
165
|
+
type: 'BlockStatement',
|
|
166
|
+
body: ownProperties.map(({
|
|
167
|
+
key
|
|
168
|
+
}) => {
|
|
169
|
+
var _reservedPropNames$ge;
|
|
170
|
+
|
|
171
|
+
const keyName = nameOfKey(key);
|
|
172
|
+
const bindingIdent = (0, _Builders.ident)((_reservedPropNames$ge = reservedPropNames.get(keyName)) != null ? _reservedPropNames$ge : keyName);
|
|
173
|
+
const object = {
|
|
174
|
+
type: 'ThisExpression',
|
|
175
|
+
...(0, _Builders.etc)()
|
|
176
|
+
};
|
|
177
|
+
const memberExpression = key.type === 'Identifier' ? {
|
|
178
|
+
type: 'MemberExpression',
|
|
179
|
+
object,
|
|
180
|
+
property: (0, _astNodeMutationHelpers.shallowCloneNode)(key),
|
|
181
|
+
computed: false,
|
|
182
|
+
optional: false,
|
|
183
|
+
...(0, _Builders.etc)()
|
|
184
|
+
} : {
|
|
185
|
+
type: 'MemberExpression',
|
|
186
|
+
object,
|
|
187
|
+
property: (0, _astNodeMutationHelpers.shallowCloneNode)(key),
|
|
188
|
+
computed: true,
|
|
189
|
+
optional: false,
|
|
190
|
+
...(0, _Builders.etc)()
|
|
191
|
+
};
|
|
192
|
+
return {
|
|
193
|
+
type: 'ExpressionStatement',
|
|
194
|
+
expression: {
|
|
195
|
+
type: 'AssignmentExpression',
|
|
196
|
+
operator: '=',
|
|
197
|
+
left: memberExpression,
|
|
198
|
+
right: bindingIdent,
|
|
199
|
+
...(0, _Builders.etc)()
|
|
200
|
+
},
|
|
201
|
+
directive: null,
|
|
202
|
+
...(0, _Builders.etc)()
|
|
203
|
+
};
|
|
204
|
+
}),
|
|
205
|
+
...(0, _Builders.etc)()
|
|
206
|
+
},
|
|
207
|
+
generator: false,
|
|
208
|
+
async: false,
|
|
209
|
+
predicate: null,
|
|
210
|
+
returnType: null,
|
|
211
|
+
typeParameters: null,
|
|
212
|
+
...(0, _Builders.etc)()
|
|
213
|
+
},
|
|
214
|
+
...(0, _Builders.etc)(),
|
|
215
|
+
parent: _Builders.EMPTY_PARENT
|
|
216
|
+
};
|
|
217
|
+
const classStaticProperties = staticProperties.map(prop => ({
|
|
218
|
+
type: 'PropertyDefinition',
|
|
219
|
+
key: (0, _astNodeMutationHelpers.shallowCloneNode)(prop.key),
|
|
220
|
+
value: (0, _astNodeMutationHelpers.deepCloneNode)(prop.value),
|
|
221
|
+
static: true,
|
|
222
|
+
typeAnnotation: null,
|
|
223
|
+
variance: null,
|
|
224
|
+
computed: false,
|
|
225
|
+
declare: false,
|
|
226
|
+
optional: false,
|
|
227
|
+
...(0, _Builders.etc)(),
|
|
228
|
+
parent: _Builders.EMPTY_PARENT
|
|
229
|
+
}));
|
|
230
|
+
const classBodyElements = [constructor, ...methods, ...classStaticProperties, ...staticMethods];
|
|
231
|
+
return {
|
|
232
|
+
type: 'ClassDeclaration',
|
|
233
|
+
id: (0, _astNodeMutationHelpers.shallowCloneNode)(node.id),
|
|
234
|
+
body: {
|
|
235
|
+
type: 'ClassBody',
|
|
236
|
+
body: classBodyElements,
|
|
237
|
+
...(0, _Builders.etc)(),
|
|
238
|
+
parent: _Builders.EMPTY_PARENT
|
|
239
|
+
},
|
|
240
|
+
superClass: null,
|
|
241
|
+
typeParameters: null,
|
|
242
|
+
superTypeArguments: null,
|
|
243
|
+
implements: [],
|
|
244
|
+
decorators: [],
|
|
245
|
+
...(0, _Builders.etc)()
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function mapRecordExpression(node) {
|
|
250
|
+
const obj = {
|
|
251
|
+
type: 'ObjectExpression',
|
|
252
|
+
properties: node.properties.properties,
|
|
253
|
+
...(0, _Builders.etc)()
|
|
254
|
+
};
|
|
255
|
+
return {
|
|
256
|
+
type: 'NewExpression',
|
|
257
|
+
callee: node.recordConstructor,
|
|
258
|
+
arguments: [obj],
|
|
259
|
+
typeArguments: null,
|
|
260
|
+
...(0, _Builders.etc)()
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function transformProgram(program, _options) {
|
|
265
|
+
const genID = new _GenID.default('r');
|
|
266
|
+
return _SimpleTransform.SimpleTransform.transformProgram(program, {
|
|
267
|
+
transform(node) {
|
|
268
|
+
switch (node.type) {
|
|
269
|
+
case 'RecordDeclaration':
|
|
270
|
+
{
|
|
271
|
+
return mapRecordDeclaration(genID, node);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
case 'RecordExpression':
|
|
275
|
+
{
|
|
276
|
+
return mapRecordExpression(node);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
case 'Identifier':
|
|
280
|
+
{
|
|
281
|
+
// A rudimentary check to avoid some collisions with our generated
|
|
282
|
+
// variable names. Ideally, we would have access a scope analyzer
|
|
283
|
+
// inside the transform instead.
|
|
284
|
+
genID.addUsage(node.name);
|
|
285
|
+
return node;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
default:
|
|
289
|
+
return node;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
});
|
|
294
|
+
}
|
|
@@ -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/src/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/src/utils/GenID.js
CHANGED
|
@@ -12,30 +12,35 @@
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", {
|
|
13
13
|
value: true
|
|
14
14
|
});
|
|
15
|
-
exports.
|
|
15
|
+
exports.default = void 0;
|
|
16
16
|
const genPrefix = '$$gen$';
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
18
|
+
class GenID {
|
|
19
|
+
constructor(uniqueTransformPrefix) {
|
|
20
|
+
this.genN = 0;
|
|
21
|
+
this.used = new Set();
|
|
22
|
+
this.prefix = void 0;
|
|
23
|
+
this.prefix = `${genPrefix}${uniqueTransformPrefix}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
id() {
|
|
27
|
+
let name;
|
|
28
|
+
|
|
29
|
+
do {
|
|
30
|
+
name = `${this.prefix}${this.genN}`;
|
|
31
|
+
this.genN++;
|
|
32
|
+
} while (this.used.has(name));
|
|
33
|
+
|
|
34
|
+
this.used.add(name);
|
|
35
|
+
return name;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
addUsage(name) {
|
|
39
|
+
if (name.startsWith(this.prefix)) {
|
|
40
|
+
this.used.add(name);
|
|
38
41
|
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
}
|
|
39
45
|
|
|
40
|
-
|
|
41
|
-
}
|
|
46
|
+
exports.default = GenID;
|
|
@@ -0,0 +1,62 @@
|
|
|
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.default = isReservedWord;
|
|
16
|
+
|
|
17
|
+
function isReservedWord(name) {
|
|
18
|
+
switch (name) {
|
|
19
|
+
case 'await':
|
|
20
|
+
case 'break':
|
|
21
|
+
case 'case':
|
|
22
|
+
case 'catch':
|
|
23
|
+
case 'class':
|
|
24
|
+
case 'const':
|
|
25
|
+
case 'continue':
|
|
26
|
+
case 'debugger':
|
|
27
|
+
case 'default':
|
|
28
|
+
case 'delete':
|
|
29
|
+
case 'do':
|
|
30
|
+
case 'else':
|
|
31
|
+
case 'enum':
|
|
32
|
+
case 'export':
|
|
33
|
+
case 'extends':
|
|
34
|
+
case 'false':
|
|
35
|
+
case 'finally':
|
|
36
|
+
case 'for':
|
|
37
|
+
case 'function':
|
|
38
|
+
case 'if':
|
|
39
|
+
case 'import':
|
|
40
|
+
case 'in':
|
|
41
|
+
case 'instanceof':
|
|
42
|
+
case 'new':
|
|
43
|
+
case 'null':
|
|
44
|
+
case 'return':
|
|
45
|
+
case 'super':
|
|
46
|
+
case 'switch':
|
|
47
|
+
case 'this':
|
|
48
|
+
case 'throw':
|
|
49
|
+
case 'true':
|
|
50
|
+
case 'try':
|
|
51
|
+
case 'typeof':
|
|
52
|
+
case 'var':
|
|
53
|
+
case 'void':
|
|
54
|
+
case 'while':
|
|
55
|
+
case 'with':
|
|
56
|
+
case 'yield':
|
|
57
|
+
return true;
|
|
58
|
+
|
|
59
|
+
default:
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
package/dist/utils/GenID.js
CHANGED
|
@@ -12,30 +12,35 @@
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", {
|
|
13
13
|
value: true
|
|
14
14
|
});
|
|
15
|
-
exports.
|
|
15
|
+
exports.default = void 0;
|
|
16
16
|
const genPrefix = '$$gen$';
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
18
|
+
class GenID {
|
|
19
|
+
constructor(uniqueTransformPrefix) {
|
|
20
|
+
this.genN = 0;
|
|
21
|
+
this.used = new Set();
|
|
22
|
+
this.prefix = void 0;
|
|
23
|
+
this.prefix = `${genPrefix}${uniqueTransformPrefix}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
id() {
|
|
27
|
+
let name;
|
|
28
|
+
|
|
29
|
+
do {
|
|
30
|
+
name = `${this.prefix}${this.genN}`;
|
|
31
|
+
this.genN++;
|
|
32
|
+
} while (this.used.has(name));
|
|
33
|
+
|
|
34
|
+
this.used.add(name);
|
|
35
|
+
return name;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
addUsage(name) {
|
|
39
|
+
if (name.startsWith(this.prefix)) {
|
|
40
|
+
this.used.add(name);
|
|
38
41
|
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
}
|
|
39
45
|
|
|
40
|
-
|
|
41
|
-
}
|
|
46
|
+
exports.default = GenID;
|