hermes-estree 0.10.1 → 0.11.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.
Files changed (39) hide show
  1. package/dist/generated/HermesESTreeSelectorTypes.js.flow +445 -0
  2. package/dist/generated/predicates.js +70 -0
  3. package/dist/generated/predicates.js.flow +70 -0
  4. package/dist/types.js.flow +132 -5
  5. package/package.json +1 -1
  6. package/dist/HermesAST.js.flow +0 -57
  7. package/dist/HermesASTAdapter.js +0 -186
  8. package/dist/HermesASTAdapter.js.flow +0 -183
  9. package/dist/HermesParser.js +0 -83
  10. package/dist/HermesParser.js.flow +0 -123
  11. package/dist/HermesParserDecodeUTF8String.js +0 -68
  12. package/dist/HermesParserDecodeUTF8String.js.flow +0 -65
  13. package/dist/HermesParserDeserializer.js +0 -243
  14. package/dist/HermesParserDeserializer.js.flow +0 -261
  15. package/dist/HermesParserNodeDeserializers.js +0 -2008
  16. package/dist/HermesParserNodeDeserializers.js.flow +0 -16
  17. package/dist/HermesParserWASM.js +0 -6
  18. package/dist/HermesParserWASM.js.flow +0 -75
  19. package/dist/HermesToBabelAdapter.js +0 -514
  20. package/dist/HermesToBabelAdapter.js.flow +0 -490
  21. package/dist/HermesToESTreeAdapter.js +0 -439
  22. package/dist/HermesToESTreeAdapter.js.flow +0 -422
  23. package/dist/ParserOptions.js.flow +0 -18
  24. package/dist/generated/ESTreeVisitorKeys.js +0 -180
  25. package/dist/generated/ESTreeVisitorKeys.js.flow +0 -15
  26. package/dist/generated/ParserVisitorKeys.js +0 -622
  27. package/dist/generated/ParserVisitorKeys.js.flow +0 -17
  28. package/dist/getModuleDocblock.js +0 -112
  29. package/dist/getModuleDocblock.js.flow +0 -118
  30. package/dist/transform/SimpleTransform.js +0 -92
  31. package/dist/transform/SimpleTransform.js.flow +0 -104
  32. package/dist/transform/astArrayMutationHelpers.js +0 -62
  33. package/dist/transform/astArrayMutationHelpers.js.flow +0 -71
  34. package/dist/transform/astNodeMutationHelpers.js +0 -186
  35. package/dist/transform/astNodeMutationHelpers.js.flow +0 -205
  36. package/dist/traverse/SimpleTraverser.js +0 -138
  37. package/dist/traverse/SimpleTraverser.js.flow +0 -132
  38. package/dist/traverse/getVisitorKeys.js +0 -35
  39. package/dist/traverse/getVisitorKeys.js.flow +0 -36
@@ -1,75 +0,0 @@
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
- type INTENTIONAL_ANY = $FlowFixMe;
12
- type JSType = 'number' | 'string' | 'array' | 'boolean';
13
- type CBoolean = ?(number | boolean);
14
-
15
- type HermesParserWASM = $ReadOnly<{
16
- HEAP8: Int8Array,
17
- HEAP16: Int16Array,
18
- HEAP32: Int32Array,
19
- HEAPU8: Uint8Array,
20
- HEAPU16: Uint16Array,
21
- HEAPU32: Uint32Array,
22
- HEAPF32: Float32Array,
23
- HEAPF64: Float64Array,
24
-
25
- _malloc(size: number): number,
26
- _free(ptr: number): void,
27
-
28
- ccall(
29
- ident: string,
30
- returnType: JSType | null,
31
- argTypes: $ReadOnlyArray<JSType>,
32
- args: $ReadOnlyArray<
33
- number | string | $ReadOnlyArray<INTENTIONAL_ANY> | boolean,
34
- >,
35
- opts?: $ReadOnly<{
36
- async?: boolean | void,
37
- }>,
38
- ): INTENTIONAL_ANY,
39
- cwrap: {
40
- (
41
- 'hermesParse',
42
- 'number',
43
- ['number', 'number', 'number', 'number', 'number'],
44
- ): (number, number, CBoolean, CBoolean, CBoolean) => number,
45
- ('hermesParseResult_free', 'void', ['number']): number => void,
46
- ('hermesParseResult_getError', 'string', ['number']): number => string,
47
- ('hermesParseResult_getErrorLine', 'number', ['number']): number => number,
48
- (
49
- 'hermesParseResult_getErrorColumn',
50
- 'number',
51
- ['number'],
52
- ): number => number,
53
- (
54
- 'hermesParseResult_getProgramBuffer',
55
- 'number',
56
- ['number'],
57
- ): number => number,
58
- (
59
- 'hermesParseResult_getPositionBuffer',
60
- 'number',
61
- ['number'],
62
- ): number => number,
63
- (
64
- 'hermesParseResult_getPositionBufferSize',
65
- 'number',
66
- ['number'],
67
- ): number => number,
68
- },
69
-
70
- stackAlloc(size: number): number,
71
- stackSave(): number,
72
- stackRestore(ptr: number): void,
73
- }>;
74
-
75
- declare module.exports: HermesParserWASM;
@@ -1,514 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _HermesASTAdapter = _interopRequireDefault(require("./HermesASTAdapter"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- /**
13
- * Copyright (c) Meta Platforms, Inc. and affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- *
18
- *
19
- * @format
20
- */
21
- class HermesToBabelAdapter extends _HermesASTAdapter.default {
22
- fixSourceLocation(node) {
23
- var _this$sourceFilename;
24
-
25
- const loc = node.loc;
26
-
27
- if (loc == null) {
28
- return;
29
- }
30
-
31
- node.loc = {
32
- source: (_this$sourceFilename = this.sourceFilename) != null ? _this$sourceFilename : null,
33
- start: loc.start,
34
- end: loc.end
35
- };
36
- node.start = loc.rangeStart;
37
- node.end = loc.rangeEnd;
38
- }
39
-
40
- mapNode(node) {
41
- this.fixSourceLocation(node);
42
-
43
- switch (node.type) {
44
- case 'Program':
45
- return this.mapProgram(node);
46
-
47
- case 'BlockStatement':
48
- return this.mapNodeWithDirectives(node);
49
-
50
- case 'Empty':
51
- return this.mapEmpty(node);
52
-
53
- case 'Identifier':
54
- return this.mapIdentifier(node);
55
-
56
- case 'TemplateElement':
57
- return this.mapTemplateElement(node);
58
-
59
- case 'GenericTypeAnnotation':
60
- return this.mapGenericTypeAnnotation(node);
61
-
62
- case 'SymbolTypeAnnotation':
63
- return this.mapSymbolTypeAnnotation(node);
64
-
65
- case 'Property':
66
- return this.mapProperty(node);
67
-
68
- case 'MethodDefinition':
69
- return this.mapMethodDefinition(node);
70
-
71
- case 'ImportDeclaration':
72
- return this.mapImportDeclaration(node);
73
-
74
- case 'ImportSpecifier':
75
- return this.mapImportSpecifier(node);
76
-
77
- case 'ExportDefaultDeclaration':
78
- return this.mapExportDefaultDeclaration(node);
79
-
80
- case 'ExportNamedDeclaration':
81
- return this.mapExportNamedDeclaration(node);
82
-
83
- case 'ExportNamespaceSpecifier':
84
- return this.mapExportNamespaceSpecifier(node);
85
-
86
- case 'ExportAllDeclaration':
87
- return this.mapExportAllDeclaration(node);
88
-
89
- case 'RestElement':
90
- return this.mapRestElement(node);
91
-
92
- case 'ImportExpression':
93
- return this.mapImportExpression(node);
94
-
95
- case 'JSXStringLiteral':
96
- return this.mapJSXStringLiteral(node);
97
-
98
- case 'PrivateName':
99
- return this.mapPrivateName(node);
100
-
101
- case 'ClassPrivateProperty':
102
- return this.mapPrivateProperty(node);
103
-
104
- case 'FunctionDeclaration':
105
- case 'FunctionExpression':
106
- return this.mapFunction(node);
107
-
108
- case 'IndexedAccessType':
109
- case 'OptionalIndexedAccessType':
110
- return this.mapUnsupportedTypeAnnotation(node);
111
-
112
- case 'BigIntLiteral':
113
- return this.mapBigIntLiteral(node);
114
-
115
- case 'BigIntLiteralTypeAnnotation':
116
- return this.mapBigIntLiteralTypeAnnotation(node);
117
-
118
- case 'BigIntTypeAnnotation':
119
- return this.mapBigIntTypeAnnotation(node);
120
-
121
- default:
122
- return this.mapNodeDefault(node);
123
- }
124
- }
125
-
126
- mapProgram(node) {
127
- // Visit child nodes and convert to directives
128
- const {
129
- comments,
130
- ...program
131
- } = this.mapNodeWithDirectives(node);
132
- program.sourceType = this.getSourceType(); // Adjust start loc to beginning of file
133
-
134
- program.loc.start = {
135
- line: 1,
136
- column: 0
137
- };
138
- program.start = 0; // Adjust end loc to include last comment if program ends with a comment
139
-
140
- if (comments.length > 0) {
141
- const lastComment = comments[comments.length - 1];
142
-
143
- if (lastComment.end > program.end) {
144
- program.loc.end = lastComment.loc.end;
145
- program.end = lastComment.end;
146
- }
147
- } // Rename root node to File node and move Program node under program property
148
-
149
-
150
- return {
151
- type: 'File',
152
- loc: program.loc,
153
- start: program.start,
154
- end: program.end,
155
- program,
156
- comments
157
- };
158
- }
159
-
160
- mapNodeWithDirectives(node) {
161
- const directives = [];
162
-
163
- for (const child of node.body) {
164
- if (child.type === 'ExpressionStatement' && child.directive != null) {
165
- // Visit directive children
166
- const directiveChild = this.mapNode(child); // Modify string literal node to be DirectiveLiteral node
167
-
168
- directiveChild.expression.type = 'DirectiveLiteral'; // Construct Directive node with DirectiveLiteral value
169
-
170
- directives.push({
171
- type: 'Directive',
172
- loc: directiveChild.loc,
173
- start: directiveChild.start,
174
- end: directiveChild.end,
175
- value: directiveChild.expression
176
- });
177
- } else {
178
- // Once we have found the first non-directive node we know there cannot be any more directives
179
- break;
180
- }
181
- } // Move directives from body to new directives array
182
-
183
-
184
- node.directives = directives;
185
-
186
- if (directives.length !== 0) {
187
- node.body = node.body.slice(directives.length);
188
- } // Visit expression statement children
189
-
190
-
191
- const body = node.body;
192
-
193
- for (let i = 0; i < body.length; i++) {
194
- const child = body[i];
195
-
196
- if (child != null) {
197
- body[i] = this.mapNode(child);
198
- }
199
- }
200
-
201
- return node;
202
- }
203
-
204
- mapIdentifier(node) {
205
- node.loc.identifierName = node.name;
206
- return this.mapNodeDefault(node);
207
- }
208
-
209
- mapTemplateElement(node) {
210
- // Adjust start loc to exclude "`" at beginning of template literal if this is the first quasi,
211
- // otherwise exclude "}" from previous expression.
212
- const startCharsToExclude = 1; // Adjust end loc to exclude "`" at end of template literal if this is the last quasi,
213
- // otherwise exclude "${" from next expression.
214
-
215
- const endCharsToExclude = node.tail ? 1 : 2;
216
- return {
217
- type: 'TemplateElement',
218
- loc: {
219
- start: {
220
- line: node.loc.start.line,
221
- column: node.loc.start.column + startCharsToExclude
222
- },
223
- end: {
224
- line: node.loc.end.line,
225
- column: node.loc.end.column - endCharsToExclude
226
- }
227
- },
228
- start: node.start + startCharsToExclude,
229
- end: node.end - endCharsToExclude,
230
- tail: node.tail,
231
- value: {
232
- cooked: node.cooked,
233
- raw: node.raw
234
- }
235
- };
236
- }
237
-
238
- mapGenericTypeAnnotation(node) {
239
- // Convert simple `this` generic type to ThisTypeAnnotation
240
- if (node.typeParameters == null && node.id.type === 'Identifier' && node.id.name === 'this') {
241
- return {
242
- type: 'ThisTypeAnnotation',
243
- loc: node.loc,
244
- start: node.start,
245
- end: node.end
246
- };
247
- }
248
-
249
- return this.mapNodeDefault(node);
250
- }
251
-
252
- mapSymbolTypeAnnotation(node) {
253
- return {
254
- type: 'GenericTypeAnnotation',
255
- loc: node.loc,
256
- start: node.start,
257
- end: node.end,
258
- id: {
259
- type: 'Identifier',
260
- loc: node.loc,
261
- start: node.start,
262
- end: node.end,
263
- name: 'symbol'
264
- },
265
- typeParameters: null
266
- };
267
- }
268
-
269
- mapProperty(node) {
270
- const key = this.mapNode(node.key);
271
- const value = this.mapNode(node.value); // Convert methods, getters, and setters to ObjectMethod nodes
272
-
273
- if (node.method || node.kind !== 'init') {
274
- // Properties under the FunctionExpression value that should be moved
275
- // to the ObjectMethod node itself.
276
- const {
277
- id,
278
- params,
279
- body,
280
- async,
281
- generator,
282
- returnType,
283
- typeParameters,
284
- predicate
285
- } = value;
286
- const newNode = {
287
- type: 'ObjectMethod',
288
- loc: node.loc,
289
- start: node.start,
290
- end: node.end,
291
- // Non getter or setter methods have `kind = method`
292
- kind: node.kind === 'init' ? 'method' : node.kind,
293
- method: node.kind === 'init' ? true : false,
294
- computed: node.computed,
295
- key,
296
- id,
297
- params,
298
- body,
299
- async,
300
- generator,
301
- returnType,
302
- typeParameters,
303
- predicate
304
- };
305
-
306
- if (node.kind !== 'init') {
307
- // babel emits an empty variance property on accessors for some reason
308
- newNode.variance = null;
309
- }
310
-
311
- return newNode;
312
- } else {
313
- // Non-method property nodes should be renamed to ObjectProperty
314
- node.type = 'ObjectProperty';
315
- return node;
316
- }
317
- }
318
-
319
- mapMethodDefinition(node) {
320
- const key = this.mapNode(node.key);
321
- const value = this.mapNode(node.value); // Properties under the FunctionExpression value that should be moved
322
- // to the ClassMethod node itself.
323
-
324
- const {
325
- id,
326
- params,
327
- body,
328
- async,
329
- generator,
330
- returnType,
331
- typeParameters,
332
- predicate
333
- } = value;
334
- return {
335
- type: 'ClassMethod',
336
- loc: node.loc,
337
- start: node.start,
338
- end: node.end,
339
- kind: node.kind,
340
- computed: node.computed,
341
- static: node.static,
342
- key,
343
- id,
344
- params,
345
- body,
346
- async,
347
- generator,
348
- returnType,
349
- typeParameters,
350
- predicate
351
- };
352
- }
353
-
354
- mapRestElement(node) {
355
- const restElement = this.mapNodeDefault(node); // Hermes puts type annotations on rest elements on the argument node,
356
- // but Babel expects type annotations on the rest element node itself.
357
-
358
- const annotation = restElement.argument.typeAnnotation;
359
-
360
- if (annotation != null) {
361
- restElement.typeAnnotation = annotation;
362
- restElement.argument.typeAnnotation = null; // Unfortunately there's no way for us to recover the end location of
363
- // the argument for the general case
364
-
365
- if (restElement.argument.type === 'Identifier') {
366
- restElement.argument.end = restElement.argument.start + restElement.argument.name.length;
367
- restElement.argument.loc.end = { ...restElement.argument.loc.start,
368
- column: restElement.argument.loc.start.column + restElement.argument.name.length
369
- };
370
- }
371
- }
372
-
373
- return restElement;
374
- }
375
-
376
- mapImportExpression(node) {
377
- // Babel expects ImportExpression to be structued as a regular
378
- // CallExpression where the callee is an Import node.
379
- return {
380
- type: 'CallExpression',
381
- loc: node.loc,
382
- start: node.start,
383
- end: node.end,
384
- callee: {
385
- type: 'Import',
386
- loc: { ...node.loc,
387
- end: { ...node.loc.start,
388
- column: node.loc.start.column + 'import'.length
389
- }
390
- },
391
- start: node.start,
392
- end: node.start + 'import'.length
393
- },
394
- arguments: [this.mapNode(node.source)]
395
- };
396
- }
397
-
398
- mapJSXStringLiteral(node) {
399
- // Babel expects StringLiterals in JSX,
400
- // but Hermes uses JSXStringLiteral to attach the raw value without
401
- // having to internally attach it to every single string literal.
402
- return {
403
- type: 'StringLiteral',
404
- loc: node.loc,
405
- start: node.start,
406
- end: node.end,
407
- value: node.value
408
- };
409
- }
410
-
411
- mapFunction(node) {
412
- // Remove the first parameter if it is a this-type annotation,
413
- // which is not recognized by Babel.
414
- if (node.params.length !== 0 && node.params[0].name === 'this') {
415
- node.params.shift();
416
- }
417
-
418
- return this.mapNodeDefault(node);
419
- }
420
- /**
421
- * If Babel (the version we target) does not support a type annotation we
422
- * parse, we need to return some other valid type annotation in its place.
423
- */
424
-
425
-
426
- mapUnsupportedTypeAnnotation(node) {
427
- return {
428
- type: 'AnyTypeAnnotation',
429
- loc: node.loc,
430
- start: node.start,
431
- end: node.end
432
- };
433
- }
434
-
435
- mapBigIntLiteral(node) {
436
- node.value = this.getBigIntLiteralValue(node.bigint).value;
437
- return node;
438
- }
439
-
440
- mapBigIntLiteralTypeAnnotation(node) {
441
- node.value = this.getBigIntLiteralValue(node.raw).value;
442
- return node;
443
- }
444
- /**
445
- * Babel does not parse the bigint keyword type as the keyword node.
446
- * So we need to down-level the AST to a plain GenericTypeAnnotation
447
- */
448
-
449
-
450
- mapBigIntTypeAnnotation(node) {
451
- return {
452
- type: 'GenericTypeAnnotation',
453
- id: {
454
- type: 'Identifier',
455
- name: 'bigint',
456
- loc: node.loc,
457
- start: node.start,
458
- end: node.end
459
- },
460
- typeParameters: null,
461
- loc: node.loc,
462
- start: node.start,
463
- end: node.end
464
- };
465
- }
466
-
467
- mapPrivateProperty(nodeUnprocessed) {
468
- const node = this.mapNodeDefault(nodeUnprocessed);
469
- node.key = {
470
- type: 'PrivateName',
471
- id: { ...node.key,
472
- // babel doesn't include the hash in the identifier
473
- start: node.key.start + 1,
474
- loc: { ...node.key.loc,
475
- start: { ...node.key.loc.start,
476
- column: node.key.loc.start.column + 1
477
- }
478
- }
479
- },
480
- start: node.key.start,
481
- end: node.key.end,
482
- loc: node.key.loc
483
- };
484
- return node;
485
- }
486
-
487
- mapPrivateName(node) {
488
- // babel doesn't include the hash in the identifier
489
- node.id.start += 1;
490
- node.id.loc.start.column += 1;
491
- return node;
492
- }
493
-
494
- mapExportNamespaceSpecifier(nodeUnprocessed) {
495
- const node = this.mapNodeDefault(nodeUnprocessed); // the hermes AST emits the location as the location of the entire export
496
- // but babel emits the location as *just* the "* as id" bit
497
- // the end will always align with the end of the identifier (ezpz)
498
- // but the start will align with the "*" token - which we can't recover from just the AST
499
- // so we just fudge the start location a bit to get it "good enough"
500
- // it will be wrong if the AST is anything like "export * as x from 'y'"... but oh well
501
-
502
- node.start = node.start + 'export '.length;
503
- node.loc.start.column = node.loc.start.column + 'export '.length;
504
- node.end = node.exported.end;
505
- node.loc.end = {
506
- column: node.exported.loc.end.column,
507
- line: node.exported.loc.end.line
508
- };
509
- return node;
510
- }
511
-
512
- }
513
-
514
- exports.default = HermesToBabelAdapter;