hermes-parser 0.17.1 → 0.18.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.
|
@@ -129,7 +129,7 @@ function mapComponentParameters(params) {
|
|
|
129
129
|
} // Optimize `component Foo(...props: Props) {}` to `function Foo(props: Props) {}
|
|
130
130
|
|
|
131
131
|
|
|
132
|
-
if (params.length === 1 && params[0].type === 'RestElement' &&
|
|
132
|
+
if (params.length === 1 && params[0].type === 'RestElement' && params[0].argument.type === 'Identifier') {
|
|
133
133
|
var _restElementArgument$, _restElementArgument$2;
|
|
134
134
|
|
|
135
135
|
const restElementArgument = params[0].argument;
|
|
@@ -151,7 +151,7 @@ function mapComponentParameters(params) {
|
|
|
151
151
|
|
|
152
152
|
return true;
|
|
153
153
|
});
|
|
154
|
-
const propsProperties = paramsWithoutRef.
|
|
154
|
+
const propsProperties = paramsWithoutRef.flatMap(mapComponentParameter);
|
|
155
155
|
let props = null;
|
|
156
156
|
|
|
157
157
|
if (propsProperties.length === 0) {
|
|
@@ -208,13 +208,32 @@ function mapComponentParameter(param) {
|
|
|
208
208
|
switch (param.type) {
|
|
209
209
|
case 'RestElement':
|
|
210
210
|
{
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
211
|
+
switch (param.argument.type) {
|
|
212
|
+
case 'Identifier':
|
|
213
|
+
{
|
|
214
|
+
const a = nodeWith(param, {
|
|
215
|
+
typeAnnotation: null,
|
|
216
|
+
argument: nodeWith(param.argument, {
|
|
217
|
+
typeAnnotation: null
|
|
218
|
+
})
|
|
219
|
+
});
|
|
220
|
+
return [a];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
case 'ObjectPattern':
|
|
224
|
+
{
|
|
225
|
+
return param.argument.properties.map(property => {
|
|
226
|
+
return nodeWith(property, {
|
|
227
|
+
typeAnnotation: null
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
default:
|
|
233
|
+
{
|
|
234
|
+
throw (0, _createSyntaxError.createSyntaxError)(param, `Unhandled ${param.argument.type} encountered in restParameter`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
218
237
|
}
|
|
219
238
|
|
|
220
239
|
case 'ComponentParameter':
|
|
@@ -237,7 +256,7 @@ function mapComponentParameter(param) {
|
|
|
237
256
|
|
|
238
257
|
|
|
239
258
|
if (param.name.type === 'Identifier' && param.shorthand && (value.type === 'Identifier' || value.type === 'AssignmentPattern')) {
|
|
240
|
-
return {
|
|
259
|
+
return [{
|
|
241
260
|
type: 'Property',
|
|
242
261
|
key: param.name,
|
|
243
262
|
kind: 'init',
|
|
@@ -248,11 +267,11 @@ function mapComponentParameter(param) {
|
|
|
248
267
|
loc: param.loc,
|
|
249
268
|
range: param.range,
|
|
250
269
|
parent: EMPTY_PARENT
|
|
251
|
-
};
|
|
270
|
+
}];
|
|
252
271
|
} // Complex params
|
|
253
272
|
|
|
254
273
|
|
|
255
|
-
return {
|
|
274
|
+
return [{
|
|
256
275
|
type: 'Property',
|
|
257
276
|
key: param.name,
|
|
258
277
|
kind: 'init',
|
|
@@ -263,7 +282,7 @@ function mapComponentParameter(param) {
|
|
|
263
282
|
loc: param.loc,
|
|
264
283
|
range: param.range,
|
|
265
284
|
parent: EMPTY_PARENT
|
|
266
|
-
};
|
|
285
|
+
}];
|
|
267
286
|
}
|
|
268
287
|
|
|
269
288
|
default:
|
|
@@ -160,8 +160,7 @@ function mapComponentParameters(
|
|
|
160
160
|
if (
|
|
161
161
|
params.length === 1 &&
|
|
162
162
|
params[0].type === 'RestElement' &&
|
|
163
|
-
|
|
164
|
-
params[0].argument.type === 'ObjectPattern')
|
|
163
|
+
params[0].argument.type === 'Identifier'
|
|
165
164
|
) {
|
|
166
165
|
const restElementArgument = params[0].argument;
|
|
167
166
|
return {
|
|
@@ -189,7 +188,7 @@ function mapComponentParameters(
|
|
|
189
188
|
return true;
|
|
190
189
|
});
|
|
191
190
|
|
|
192
|
-
const propsProperties = paramsWithoutRef.
|
|
191
|
+
const propsProperties = paramsWithoutRef.flatMap(mapComponentParameter);
|
|
193
192
|
|
|
194
193
|
let props = null;
|
|
195
194
|
if (propsProperties.length === 0) {
|
|
@@ -250,14 +249,31 @@ function mapComponentParameters(
|
|
|
250
249
|
|
|
251
250
|
function mapComponentParameter(
|
|
252
251
|
param: ComponentParameter | RestElement,
|
|
253
|
-
): DestructuringObjectProperty | RestElement {
|
|
252
|
+
): Array<DestructuringObjectProperty | RestElement> {
|
|
254
253
|
switch (param.type) {
|
|
255
254
|
case 'RestElement': {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
255
|
+
switch (param.argument.type) {
|
|
256
|
+
case 'Identifier': {
|
|
257
|
+
const a = nodeWith(param, {
|
|
258
|
+
typeAnnotation: null,
|
|
259
|
+
argument: nodeWith(param.argument, {typeAnnotation: null}),
|
|
260
|
+
});
|
|
261
|
+
return [a];
|
|
262
|
+
}
|
|
263
|
+
case 'ObjectPattern': {
|
|
264
|
+
return param.argument.properties.map(property => {
|
|
265
|
+
return nodeWith(property, {
|
|
266
|
+
typeAnnotation: null,
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
default: {
|
|
271
|
+
throw createSyntaxError(
|
|
272
|
+
param,
|
|
273
|
+
`Unhandled ${param.argument.type} encountered in restParameter`,
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
261
277
|
}
|
|
262
278
|
case 'ComponentParameter': {
|
|
263
279
|
let value;
|
|
@@ -281,33 +297,37 @@ function mapComponentParameter(
|
|
|
281
297
|
param.shorthand &&
|
|
282
298
|
(value.type === 'Identifier' || value.type === 'AssignmentPattern')
|
|
283
299
|
) {
|
|
284
|
-
return
|
|
300
|
+
return [
|
|
301
|
+
{
|
|
302
|
+
type: 'Property',
|
|
303
|
+
key: param.name,
|
|
304
|
+
kind: 'init',
|
|
305
|
+
value,
|
|
306
|
+
method: false,
|
|
307
|
+
shorthand: true,
|
|
308
|
+
computed: false,
|
|
309
|
+
loc: param.loc,
|
|
310
|
+
range: param.range,
|
|
311
|
+
parent: EMPTY_PARENT,
|
|
312
|
+
},
|
|
313
|
+
];
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Complex params
|
|
317
|
+
return [
|
|
318
|
+
{
|
|
285
319
|
type: 'Property',
|
|
286
320
|
key: param.name,
|
|
287
321
|
kind: 'init',
|
|
288
322
|
value,
|
|
289
323
|
method: false,
|
|
290
|
-
shorthand:
|
|
324
|
+
shorthand: false,
|
|
291
325
|
computed: false,
|
|
292
326
|
loc: param.loc,
|
|
293
327
|
range: param.range,
|
|
294
328
|
parent: EMPTY_PARENT,
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
// Complex params
|
|
299
|
-
return {
|
|
300
|
-
type: 'Property',
|
|
301
|
-
key: param.name,
|
|
302
|
-
kind: 'init',
|
|
303
|
-
value,
|
|
304
|
-
method: false,
|
|
305
|
-
shorthand: false,
|
|
306
|
-
computed: false,
|
|
307
|
-
loc: param.loc,
|
|
308
|
-
range: param.range,
|
|
309
|
-
parent: EMPTY_PARENT,
|
|
310
|
-
};
|
|
329
|
+
},
|
|
330
|
+
];
|
|
311
331
|
}
|
|
312
332
|
default: {
|
|
313
333
|
throw createSyntaxError(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hermes-parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.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.18.0"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@babel/parser": "7.7.4",
|