hermes-estree 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.
Files changed (87) hide show
  1. package/dist/generated/HermesESTreeSelectorTypes.js.flow +262 -27
  2. package/dist/generated/predicates.js +120 -0
  3. package/dist/generated/predicates.js.flow +72 -0
  4. package/dist/predicates.js +2 -4
  5. package/dist/predicates.js.flow +5 -4
  6. package/dist/src/generated/predicates.js +120 -0
  7. package/dist/src/predicates.js +2 -4
  8. package/dist/types.js.flow +103 -11
  9. package/package.json +1 -1
  10. package/dist/HermesAST.js.flow +0 -57
  11. package/dist/HermesASTAdapter.js +0 -192
  12. package/dist/HermesASTAdapter.js.flow +0 -189
  13. package/dist/HermesParser.js +0 -108
  14. package/dist/HermesParser.js.flow +0 -161
  15. package/dist/HermesParserDecodeUTF8String.js +0 -68
  16. package/dist/HermesParserDecodeUTF8String.js.flow +0 -65
  17. package/dist/HermesParserDeserializer.js +0 -242
  18. package/dist/HermesParserDeserializer.js.flow +0 -260
  19. package/dist/HermesParserNodeDeserializers.js +0 -2477
  20. package/dist/HermesParserNodeDeserializers.js.flow +0 -16
  21. package/dist/HermesParserWASM.js +0 -6
  22. package/dist/HermesParserWASM.js.flow +0 -87
  23. package/dist/HermesToESTreeAdapter.js +0 -439
  24. package/dist/HermesToESTreeAdapter.js.flow +0 -421
  25. package/dist/ParserOptions.js +0 -18
  26. package/dist/ParserOptions.js.flow +0 -41
  27. package/dist/babel/TransformESTreeToBabel.js +0 -1123
  28. package/dist/babel/TransformESTreeToBabel.js.flow +0 -1277
  29. package/dist/estree/StripFlowTypes.js +0 -175
  30. package/dist/estree/StripFlowTypes.js.flow +0 -158
  31. package/dist/estree/StripFlowTypesForBabel.js +0 -215
  32. package/dist/estree/StripFlowTypesForBabel.js.flow +0 -216
  33. package/dist/estree/TransformComponentSyntax.js +0 -788
  34. package/dist/estree/TransformComponentSyntax.js.flow +0 -864
  35. package/dist/estree/TransformEnumSyntax.js +0 -106
  36. package/dist/estree/TransformEnumSyntax.js.flow +0 -125
  37. package/dist/estree/TransformMatchSyntax.js +0 -1006
  38. package/dist/estree/TransformMatchSyntax.js.flow +0 -912
  39. package/dist/generated/ESTreeVisitorKeys.js +0 -220
  40. package/dist/generated/ESTreeVisitorKeys.js.flow +0 -15
  41. package/dist/generated/ParserVisitorKeys.js +0 -794
  42. package/dist/generated/ParserVisitorKeys.js.flow +0 -17
  43. package/dist/getModuleDocblock.js +0 -112
  44. package/dist/getModuleDocblock.js.flow +0 -118
  45. package/dist/src/HermesASTAdapter.js +0 -192
  46. package/dist/src/HermesParser.js +0 -108
  47. package/dist/src/HermesParserDecodeUTF8String.js +0 -68
  48. package/dist/src/HermesParserDeserializer.js +0 -242
  49. package/dist/src/HermesParserNodeDeserializers.js +0 -2477
  50. package/dist/src/HermesToESTreeAdapter.js +0 -439
  51. package/dist/src/ParserOptions.js +0 -18
  52. package/dist/src/babel/TransformESTreeToBabel.js +0 -1123
  53. package/dist/src/estree/StripFlowTypes.js +0 -175
  54. package/dist/src/estree/StripFlowTypesForBabel.js +0 -215
  55. package/dist/src/estree/TransformComponentSyntax.js +0 -788
  56. package/dist/src/estree/TransformEnumSyntax.js +0 -106
  57. package/dist/src/estree/TransformMatchSyntax.js +0 -1006
  58. package/dist/src/generated/ESTreeVisitorKeys.js +0 -220
  59. package/dist/src/generated/ParserVisitorKeys.js +0 -794
  60. package/dist/src/getModuleDocblock.js +0 -112
  61. package/dist/src/transform/SimpleTransform.js +0 -136
  62. package/dist/src/transform/astArrayMutationHelpers.js +0 -62
  63. package/dist/src/transform/astNodeMutationHelpers.js +0 -200
  64. package/dist/src/traverse/SimpleTraverser.js +0 -137
  65. package/dist/src/traverse/getVisitorKeys.js +0 -37
  66. package/dist/src/utils/Builders.js +0 -191
  67. package/dist/src/utils/GenID.js +0 -41
  68. package/dist/src/utils/createSyntaxError.js +0 -25
  69. package/dist/src/utils/mutateESTreeASTForPrettier.js +0 -127
  70. package/dist/transform/SimpleTransform.js +0 -136
  71. package/dist/transform/SimpleTransform.js.flow +0 -169
  72. package/dist/transform/astArrayMutationHelpers.js +0 -62
  73. package/dist/transform/astArrayMutationHelpers.js.flow +0 -71
  74. package/dist/transform/astNodeMutationHelpers.js +0 -200
  75. package/dist/transform/astNodeMutationHelpers.js.flow +0 -246
  76. package/dist/traverse/SimpleTraverser.js +0 -137
  77. package/dist/traverse/SimpleTraverser.js.flow +0 -133
  78. package/dist/traverse/getVisitorKeys.js +0 -37
  79. package/dist/traverse/getVisitorKeys.js.flow +0 -36
  80. package/dist/utils/Builders.js +0 -191
  81. package/dist/utils/Builders.js.flow +0 -218
  82. package/dist/utils/GenID.js +0 -41
  83. package/dist/utils/GenID.js.flow +0 -38
  84. package/dist/utils/createSyntaxError.js +0 -25
  85. package/dist/utils/createSyntaxError.js.flow +0 -24
  86. package/dist/utils/mutateESTreeASTForPrettier.js +0 -127
  87. package/dist/utils/mutateESTreeASTForPrettier.js.flow +0 -130
@@ -1,260 +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
- 'use strict';
12
-
13
- import type {
14
- HermesSourceLocation,
15
- HermesNode,
16
- HermesToken,
17
- HermesComment,
18
- } from './HermesAST';
19
- import type {HermesParserWASM} from './HermesParserWASM';
20
- import type {ParserOptions} from './ParserOptions';
21
-
22
- import HermesParserDecodeUTF8String from './HermesParserDecodeUTF8String';
23
- import NODE_DESERIALIZERS from './HermesParserNodeDeserializers';
24
-
25
- export default class HermesParserDeserializer {
26
- programBufferIdx: number;
27
- positionBufferIdx: number;
28
- +positionBufferSize: number;
29
- +locMap: {[number]: HermesSourceLocation};
30
- +HEAPU8: HermesParserWASM['HEAPU8'];
31
- +HEAPU32: HermesParserWASM['HEAPU32'];
32
- +HEAPF64: HermesParserWASM['HEAPF64'];
33
- +options: ParserOptions;
34
-
35
- // Matches StoredComment::Kind enum in JSLexer.h
36
- +commentTypes: $ReadOnlyArray<HermesComment['type']> = [
37
- 'CommentLine',
38
- 'CommentBlock',
39
- 'InterpreterDirective',
40
- ];
41
-
42
- // Matches TokenType enum in HermesParserJSSerializer.h
43
- +tokenTypes: $ReadOnlyArray<HermesToken['type']> = [
44
- 'Boolean',
45
- 'Identifier',
46
- 'Keyword',
47
- 'Null',
48
- 'Numeric',
49
- 'BigInt',
50
- 'Punctuator',
51
- 'String',
52
- 'RegularExpression',
53
- 'Template',
54
- 'JSXText',
55
- ];
56
-
57
- constructor(
58
- programBuffer: number,
59
- positionBuffer: number,
60
- positionBufferSize: number,
61
- wasmParser: HermesParserWASM,
62
- options: ParserOptions,
63
- ) {
64
- // Program and position buffer are memory addresses, so we must convert
65
- // into indices into HEAPU32 (an array of 4-byte integers).
66
- this.programBufferIdx = programBuffer / 4;
67
- this.positionBufferIdx = positionBuffer / 4;
68
-
69
- this.positionBufferSize = positionBufferSize;
70
- this.locMap = {};
71
-
72
- this.HEAPU8 = wasmParser.HEAPU8;
73
- this.HEAPU32 = wasmParser.HEAPU32;
74
- this.HEAPF64 = wasmParser.HEAPF64;
75
-
76
- this.options = options;
77
- }
78
-
79
- /**
80
- * Consume and return the next 4 bytes in the program buffer.
81
- */
82
- next(): number {
83
- const num = this.HEAPU32[this.programBufferIdx++];
84
- return num;
85
- }
86
-
87
- deserialize(): HermesNode {
88
- const program: HermesNode = {
89
- type: 'Program',
90
- loc: this.addEmptyLoc(),
91
- body: this.deserializeNodeList(),
92
- comments: this.deserializeComments(),
93
- };
94
-
95
- if (this.options.tokens === true) {
96
- program.tokens = this.deserializeTokens();
97
- }
98
-
99
- this.fillLocs();
100
-
101
- return program;
102
- }
103
-
104
- /**
105
- * Booleans are serialized as a single 4-byte integer.
106
- */
107
- deserializeBoolean(): boolean {
108
- return Boolean(this.next());
109
- }
110
-
111
- /**
112
- * Numbers are serialized directly into program buffer, taking up 8 bytes
113
- * preceded by 4 bytes of alignment padding if necessary.
114
- */
115
- deserializeNumber(): number {
116
- let floatIdx;
117
-
118
- // Numbers are aligned on 8-byte boundaries, so skip padding if we are at
119
- // an odd index into the 4-byte aligned program buffer.
120
- if (this.programBufferIdx % 2 === 0) {
121
- floatIdx = this.programBufferIdx / 2;
122
- this.programBufferIdx += 2;
123
- } else {
124
- floatIdx = (this.programBufferIdx + 1) / 2;
125
- this.programBufferIdx += 3;
126
- }
127
-
128
- return this.HEAPF64[floatIdx];
129
- }
130
-
131
- /**
132
- * Strings are serialized as a 4-byte pointer into the heap, followed
133
- * by their size as a 4-byte integer. The size is only present if the
134
- * pointer is non-null.
135
- */
136
- deserializeString(): ?string {
137
- const ptr = this.next();
138
- if (ptr === 0) {
139
- return null;
140
- }
141
-
142
- const size = this.next();
143
-
144
- return HermesParserDecodeUTF8String(ptr, size, this.HEAPU8);
145
- }
146
-
147
- /**
148
- * Nodes are serialized as a 4-byte integer denoting their node kind,
149
- * followed by a 4-byte loc ID, followed by serialized node properties.
150
- *
151
- * If the node kind is 0 the node is null, otherwise the node kind - 1 is an
152
- * index into the array of node deserialization functions.
153
- */
154
- deserializeNode(): ?HermesNode {
155
- const nodeType = this.next();
156
- if (nodeType === 0) {
157
- return null;
158
- }
159
-
160
- const nodeDeserializer = NODE_DESERIALIZERS[nodeType - 1].bind(this);
161
- return nodeDeserializer();
162
- }
163
-
164
- /**
165
- * Node lists are serialized as a 4-byte integer denoting the number of
166
- * elements in the list, followed by the serialized elements.
167
- */
168
- deserializeNodeList(): Array<?HermesNode> {
169
- const size = this.next();
170
- const nodeList = [];
171
-
172
- for (let i = 0; i < size; i++) {
173
- nodeList.push(this.deserializeNode());
174
- }
175
-
176
- return nodeList;
177
- }
178
-
179
- /**
180
- * Comments are serialized as a node list, where each comment is serialized
181
- * as a 4-byte integer denoting comment type, followed by a 4-byte value
182
- * denoting the loc ID, followed by a serialized string for the comment value.
183
- */
184
- deserializeComments(): Array<HermesComment> {
185
- const size = this.next();
186
- const comments = [];
187
-
188
- for (let i = 0; i < size; i++) {
189
- const commentType = this.commentTypes[this.next()];
190
- const loc = this.addEmptyLoc();
191
- const value = this.deserializeString();
192
- comments.push({
193
- type: commentType,
194
- loc,
195
- value,
196
- });
197
- }
198
-
199
- return comments;
200
- }
201
-
202
- deserializeTokens(): Array<HermesToken> {
203
- const size = this.next();
204
- const tokens = [];
205
-
206
- for (let i = 0; i < size; i++) {
207
- const tokenType = this.tokenTypes[this.next()];
208
- const loc = this.addEmptyLoc();
209
- const value = this.deserializeString();
210
- tokens.push({
211
- type: tokenType,
212
- loc,
213
- value,
214
- });
215
- }
216
-
217
- return tokens;
218
- }
219
-
220
- /**
221
- * While deserializing the AST locations are represented by
222
- * a 4-byte loc ID. This is used to create a map of loc IDs to empty loc
223
- * objects that are filled after the AST has been deserialized.
224
- */
225
- addEmptyLoc(): HermesSourceLocation {
226
- const loc: HermesSourceLocation = {};
227
- this.locMap[this.next()] = loc;
228
- return loc;
229
- }
230
-
231
- /**
232
- * Positions are serialized as a loc ID which denotes which loc it is associated with,
233
- * followed by kind which denotes whether it is a start or end position,
234
- * followed by line, column, and offset (4-bytes each).
235
- */
236
- fillLocs(): void {
237
- for (let i = 0; i < this.positionBufferSize; i++) {
238
- const locId = this.HEAPU32[this.positionBufferIdx++];
239
- const kind = this.HEAPU32[this.positionBufferIdx++];
240
- const line = this.HEAPU32[this.positionBufferIdx++];
241
- const column = this.HEAPU32[this.positionBufferIdx++];
242
- const offset = this.HEAPU32[this.positionBufferIdx++];
243
-
244
- const loc = this.locMap[locId];
245
- if (kind === 0) {
246
- loc.start = {
247
- line,
248
- column,
249
- };
250
- loc.rangeStart = offset;
251
- } else {
252
- loc.end = {
253
- line,
254
- column,
255
- };
256
- loc.rangeEnd = offset;
257
- }
258
- }
259
- }
260
- }