flow-parser 0.319.0 → 0.321.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/README.md +14 -26
- package/{oxidized → dist}/FlowParserNodeDeserializers.js +26 -12
- package/dist/FlowParserWASM.js +1 -0
- package/{oxidized → dist}/babel/TransformESTreeToBabel.js +11 -3
- package/{oxidized → dist}/babel/TransformESTreeToBabel.js.flow +12 -4
- package/{oxidized/oxidized-src → dist}/estree/StripFlowTypesForBabel.js +33 -18
- package/{oxidized → dist}/estree/StripFlowTypesForBabel.js.flow +40 -18
- package/{oxidized/oxidized-src → dist}/estree/TransformComponentSyntax.js +25 -12
- package/{oxidized → dist}/estree/TransformComponentSyntax.js.flow +29 -11
- package/{oxidized → dist}/generated/ESTreeVisitorKeys.js +1 -1
- package/package.json +6 -7
- package/flow_parser.js +0 -14575
- package/oxidized/FlowParserWASM.js +0 -1
- package/oxidized/estree/StripFlowTypesForBabel.js +0 -176
- package/oxidized/estree/TransformComponentSyntax.js +0 -751
- package/oxidized/oxidized-src/FlowParser.js +0 -249
- package/oxidized/oxidized-src/FlowParserDeserializer.js +0 -209
- package/oxidized/oxidized-src/FlowParserNodeDeserializers.js +0 -1767
- package/oxidized/oxidized-src/HermesParserDecodeUTF8String.js +0 -45
- package/oxidized/oxidized-src/ParserOptions.js +0 -8
- package/oxidized/oxidized-src/babel/TransformESTreeToBabel.js +0 -1055
- package/oxidized/oxidized-src/estree/StripFlowTypes.js +0 -158
- package/oxidized/oxidized-src/estree/TransformEnumSyntax.js +0 -92
- package/oxidized/oxidized-src/estree/TransformMatchSyntax.js +0 -990
- package/oxidized/oxidized-src/estree/TransformRecordSyntax.js +0 -283
- package/oxidized/oxidized-src/generated/ESTreeVisitorKeys.js +0 -234
- package/oxidized/oxidized-src/getModuleDocblock.js +0 -87
- package/oxidized/oxidized-src/index.js +0 -220
- package/oxidized/transform/SimpleTransform.js +0 -95
- package/oxidized/transform/astArrayMutationHelpers.js +0 -52
- package/oxidized/transform/astNodeMutationHelpers.js +0 -142
- package/oxidized/transform/print/comments/comments.js +0 -245
- package/oxidized/transform/print/comments/prettier/common/util.js +0 -235
- package/oxidized/transform/print/comments/prettier/language-js/comments.js +0 -663
- package/oxidized/transform/print/comments/prettier/language-js/loc.js +0 -30
- package/oxidized/transform/print/comments/prettier/language-js/printer-estree.js +0 -23
- package/oxidized/transform/print/comments/prettier/language-js/utils.js +0 -89
- package/oxidized/transform/print/comments/prettier/main/comments.js +0 -374
- package/oxidized/transform/print/comments/prettier/utils/get-last.js +0 -5
- package/oxidized/transform/print/detachedNodeTypes.js +0 -1
- package/oxidized/transform/print/print.js +0 -68
- package/oxidized/traverse/SimpleTraverser.js +0 -90
- package/oxidized/traverse/getVisitorKeys.js +0 -29
- package/oxidized/utils/Builders.js +0 -181
- package/oxidized/utils/GenID.js +0 -37
- package/oxidized/utils/createSyntaxError.js +0 -15
- package/oxidized/utils/isReservedWord.js +0 -53
- package/oxidized/utils/mutateESTreeASTForPrettier.js +0 -85
- /package/{oxidized → dist}/FlowParser.js +0 -0
- /package/{oxidized → dist}/FlowParser.js.flow +0 -0
- /package/{oxidized → dist}/FlowParserDeserializer.js +0 -0
- /package/{oxidized → dist}/FlowParserDeserializer.js.flow +0 -0
- /package/{oxidized → dist}/FlowParserNodeDeserializers.js.flow +0 -0
- /package/{oxidized → dist}/FlowParserWASM.js.flow +0 -0
- /package/{oxidized → dist}/HermesAST.js.flow +0 -0
- /package/{oxidized → dist}/HermesParserDecodeUTF8String.js +0 -0
- /package/{oxidized → dist}/HermesParserDecodeUTF8String.js.flow +0 -0
- /package/{oxidized → dist}/ParserOptions.js +0 -0
- /package/{oxidized → dist}/ParserOptions.js.flow +0 -0
- /package/{oxidized → dist}/estree/StripFlowTypes.js +0 -0
- /package/{oxidized → dist}/estree/StripFlowTypes.js.flow +0 -0
- /package/{oxidized → dist}/estree/TransformEnumSyntax.js +0 -0
- /package/{oxidized → dist}/estree/TransformEnumSyntax.js.flow +0 -0
- /package/{oxidized → dist}/estree/TransformMatchSyntax.js +0 -0
- /package/{oxidized → dist}/estree/TransformMatchSyntax.js.flow +0 -0
- /package/{oxidized → dist}/estree/TransformRecordSyntax.js +0 -0
- /package/{oxidized → dist}/estree/TransformRecordSyntax.js.flow +0 -0
- /package/{oxidized → dist}/generated/ESTreeVisitorKeys.js.flow +0 -0
- /package/{oxidized → dist}/getModuleDocblock.js +0 -0
- /package/{oxidized → dist}/getModuleDocblock.js.flow +0 -0
- /package/{oxidized → dist}/index.js +0 -0
- /package/{oxidized → dist}/index.js.flow +0 -0
- /package/{oxidized/oxidized-src → dist}/transform/SimpleTransform.js +0 -0
- /package/{oxidized → dist}/transform/SimpleTransform.js.flow +0 -0
- /package/{oxidized/oxidized-src → dist}/transform/astArrayMutationHelpers.js +0 -0
- /package/{oxidized → dist}/transform/astArrayMutationHelpers.js.flow +0 -0
- /package/{oxidized/oxidized-src → dist}/transform/astNodeMutationHelpers.js +0 -0
- /package/{oxidized → dist}/transform/astNodeMutationHelpers.js.flow +0 -0
- /package/{oxidized/oxidized-src → dist}/transform/print/comments/comments.js +0 -0
- /package/{oxidized → dist}/transform/print/comments/comments.js.flow +0 -0
- /package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/common/util.js +0 -0
- /package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/language-js/comments.js +0 -0
- /package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/language-js/loc.js +0 -0
- /package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/language-js/printer-estree.js +0 -0
- /package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/language-js/utils.js +0 -0
- /package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/main/comments.js +0 -0
- /package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/utils/get-last.js +0 -0
- /package/{oxidized/oxidized-src → dist}/transform/print/detachedNodeTypes.js +0 -0
- /package/{oxidized → dist}/transform/print/detachedNodeTypes.js.flow +0 -0
- /package/{oxidized/oxidized-src → dist}/transform/print/print.js +0 -0
- /package/{oxidized → dist}/transform/print/print.js.flow +0 -0
- /package/{oxidized/oxidized-src → dist}/traverse/SimpleTraverser.js +0 -0
- /package/{oxidized → dist}/traverse/SimpleTraverser.js.flow +0 -0
- /package/{oxidized/oxidized-src → dist}/traverse/getVisitorKeys.js +0 -0
- /package/{oxidized → dist}/traverse/getVisitorKeys.js.flow +0 -0
- /package/{oxidized/oxidized-src → dist}/utils/Builders.js +0 -0
- /package/{oxidized → dist}/utils/Builders.js.flow +0 -0
- /package/{oxidized/oxidized-src → dist}/utils/GenID.js +0 -0
- /package/{oxidized → dist}/utils/GenID.js.flow +0 -0
- /package/{oxidized/oxidized-src → dist}/utils/createSyntaxError.js +0 -0
- /package/{oxidized → dist}/utils/createSyntaxError.js.flow +0 -0
- /package/{oxidized/oxidized-src → dist}/utils/isReservedWord.js +0 -0
- /package/{oxidized → dist}/utils/isReservedWord.js.flow +0 -0
- /package/{oxidized/oxidized-src → dist}/utils/mutateESTreeASTForPrettier.js +0 -0
- /package/{oxidized → dist}/utils/mutateESTreeASTForPrettier.js.flow +0 -0
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.parse = parse;
|
|
7
|
-
|
|
8
|
-
var _FlowParserDeserializer = _interopRequireDefault(require("./FlowParserDeserializer"));
|
|
9
|
-
|
|
10
|
-
var _FlowParserWASM = _interopRequireDefault(require("./FlowParserWASM"));
|
|
11
|
-
|
|
12
|
-
var _getModuleDocblock = require("./getModuleDocblock");
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) {
|
|
15
|
-
return obj && obj.__esModule ? obj : {
|
|
16
|
-
default: obj
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
let FlowParserWASM;
|
|
21
|
-
let flowParse;
|
|
22
|
-
let flowParseResult_free;
|
|
23
|
-
let flowParseResult_getError;
|
|
24
|
-
let flowParseResult_getErrorLine;
|
|
25
|
-
let flowParseResult_getErrorColumn;
|
|
26
|
-
let flowParseResult_getProgramBuffer;
|
|
27
|
-
let flowParseResult_getPositionBuffer;
|
|
28
|
-
let flowParseResult_getPositionBufferSize;
|
|
29
|
-
let flowParseResult_getStringBuffer;
|
|
30
|
-
|
|
31
|
-
function initFlowParserWASM() {
|
|
32
|
-
if (FlowParserWASM != null) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
FlowParserWASM = (0, _FlowParserWASM.default)({
|
|
37
|
-
quit(_status, toThrow) {
|
|
38
|
-
throw toThrow;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
});
|
|
42
|
-
flowParse = FlowParserWASM.cwrap('hermesParse', 'number', ['number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number']);
|
|
43
|
-
flowParseResult_free = FlowParserWASM.cwrap('hermesParseResult_free', 'void', ['number']);
|
|
44
|
-
flowParseResult_getError = FlowParserWASM.cwrap('hermesParseResult_getError', 'string', ['number']);
|
|
45
|
-
flowParseResult_getErrorLine = FlowParserWASM.cwrap('hermesParseResult_getErrorLine', 'number', ['number']);
|
|
46
|
-
flowParseResult_getErrorColumn = FlowParserWASM.cwrap('hermesParseResult_getErrorColumn', 'number', ['number']);
|
|
47
|
-
flowParseResult_getProgramBuffer = FlowParserWASM.cwrap('hermesParseResult_getProgramBuffer', 'number', ['number']);
|
|
48
|
-
flowParseResult_getPositionBuffer = FlowParserWASM.cwrap('hermesParseResult_getPositionBuffer', 'number', ['number']);
|
|
49
|
-
flowParseResult_getPositionBufferSize = FlowParserWASM.cwrap('hermesParseResult_getPositionBufferSize', 'number', ['number']);
|
|
50
|
-
flowParseResult_getStringBuffer = FlowParserWASM.cwrap('hermesParseResult_getStringBuffer', 'number', ['number']);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function copyToHeap(buffer, addr) {
|
|
54
|
-
FlowParserWASM.HEAP8.set(buffer, addr);
|
|
55
|
-
FlowParserWASM.HEAP8[addr + buffer.length] = 0;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function flag(v) {
|
|
59
|
-
return v === true ? 1 : 0;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function parse(source, options) {
|
|
63
|
-
initFlowParserWASM();
|
|
64
|
-
const sourceBuffer = Buffer.from(source, 'utf8');
|
|
65
|
-
const filename = typeof options.sourceFilename === 'string' ? options.sourceFilename : '';
|
|
66
|
-
const filenameBuffer = filename.length > 0 ? Buffer.from(filename, 'utf8') : null;
|
|
67
|
-
let sourceAddr = 0;
|
|
68
|
-
let filenameAddr = 0;
|
|
69
|
-
let filenameLen = 0;
|
|
70
|
-
let parseResult = 0;
|
|
71
|
-
|
|
72
|
-
try {
|
|
73
|
-
sourceAddr = FlowParserWASM._malloc(sourceBuffer.length + 1);
|
|
74
|
-
|
|
75
|
-
if (!sourceAddr) {
|
|
76
|
-
throw new Error('Parser out of memory');
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (filenameBuffer != null) {
|
|
80
|
-
filenameAddr = FlowParserWASM._malloc(filenameBuffer.length + 1);
|
|
81
|
-
|
|
82
|
-
if (!filenameAddr) {
|
|
83
|
-
throw new Error('Parser out of memory');
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
copyToHeap(filenameBuffer, filenameAddr);
|
|
87
|
-
filenameLen = filenameBuffer.length + 1;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
copyToHeap(sourceBuffer, sourceAddr);
|
|
91
|
-
const enableTypes = options.enableTypes === false ? 0 : 1;
|
|
92
|
-
const sourceTypeCode = options.sourceType === 'script' ? 1 : options.sourceType === 'module' ? 2 : 0;
|
|
93
|
-
parseResult = flowParse(sourceAddr, sourceBuffer.length + 1, filenameAddr, filenameLen, flag(options.enableExperimentalComponentSyntax), flag(options.enableExperimentalFlowMatchSyntax), flag(options.enableExperimentalDecorators), flag(options.tokens), flag(options.allowReturnOutsideFunction), flag(options.assertOperator), flag(options.enableEnums), flag(options.enableRecords), enableTypes, sourceTypeCode, flag(options.enableTypesPragmaDetection), 0);
|
|
94
|
-
const programBuffer = flowParseResult_getProgramBuffer(parseResult);
|
|
95
|
-
|
|
96
|
-
if (!programBuffer) {
|
|
97
|
-
const err = flowParseResult_getError(parseResult);
|
|
98
|
-
const syntaxError = new SyntaxError(err || 'unknown parse error');
|
|
99
|
-
syntaxError.loc = {
|
|
100
|
-
line: flowParseResult_getErrorLine(parseResult),
|
|
101
|
-
column: flowParseResult_getErrorColumn(parseResult)
|
|
102
|
-
};
|
|
103
|
-
throw syntaxError;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const deserializer = new _FlowParserDeserializer.default(programBuffer, flowParseResult_getPositionBuffer(parseResult), flowParseResult_getPositionBufferSize(parseResult), flowParseResult_getStringBuffer(parseResult), FlowParserWASM, options);
|
|
107
|
-
const ast = deserializer.deserialize();
|
|
108
|
-
|
|
109
|
-
if (ast.type !== 'Program') {
|
|
110
|
-
throw new Error(`Expected Program, got ${ast.type}`);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const sourceFilename = typeof options.sourceFilename === 'string' ? options.sourceFilename : null;
|
|
114
|
-
const visitedNodes = new WeakSet();
|
|
115
|
-
const locRanges = new WeakMap();
|
|
116
|
-
|
|
117
|
-
function fixLocs(node) {
|
|
118
|
-
if (node == null || typeof node !== 'object') {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const wireNode = node;
|
|
123
|
-
|
|
124
|
-
if (visitedNodes.has(wireNode)) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
visitedNodes.add(wireNode);
|
|
129
|
-
|
|
130
|
-
if (wireNode.loc != null) {
|
|
131
|
-
const loc = wireNode.loc;
|
|
132
|
-
let range = locRanges.get(loc);
|
|
133
|
-
|
|
134
|
-
if (range == null) {
|
|
135
|
-
const rangeStart = loc.rangeStart;
|
|
136
|
-
const rangeEnd = loc.rangeEnd;
|
|
137
|
-
|
|
138
|
-
if (rangeStart == null || rangeEnd == null) {
|
|
139
|
-
throw new Error('Expected serialized source range');
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
loc.source = sourceFilename;
|
|
143
|
-
range = [rangeStart, rangeEnd];
|
|
144
|
-
locRanges.set(loc, range);
|
|
145
|
-
delete loc.rangeStart;
|
|
146
|
-
delete loc.rangeEnd;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
wireNode.range = range;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
for (const key of Object.keys(wireNode)) {
|
|
153
|
-
const val = wireNode[key];
|
|
154
|
-
|
|
155
|
-
if (Array.isArray(val)) {
|
|
156
|
-
for (const child of val) {
|
|
157
|
-
fixLocs(child);
|
|
158
|
-
}
|
|
159
|
-
} else {
|
|
160
|
-
fixLocs(val);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
fixLocs(ast);
|
|
166
|
-
|
|
167
|
-
if (options.throwOnParseErrors !== false) {
|
|
168
|
-
const errors = ast.errors;
|
|
169
|
-
|
|
170
|
-
if (errors != null && errors.length > 0) {
|
|
171
|
-
const first = errors[0];
|
|
172
|
-
const start = first.loc.start;
|
|
173
|
-
|
|
174
|
-
if (start == null) {
|
|
175
|
-
throw new Error('Expected serialized parser error start location');
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const line = start.line;
|
|
179
|
-
const column = start.column;
|
|
180
|
-
const syntaxError = new SyntaxError(`${first.message} (${line}:${column})`);
|
|
181
|
-
syntaxError.loc = {
|
|
182
|
-
line,
|
|
183
|
-
column
|
|
184
|
-
};
|
|
185
|
-
throw syntaxError;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (options.sourceType === 'script' || options.sourceType === 'module') {
|
|
190
|
-
ast.sourceType = options.sourceType;
|
|
191
|
-
} else {
|
|
192
|
-
ast.sourceType = detectSourceType(ast);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
ast.docblock = (0, _getModuleDocblock.getModuleDocblock)(ast);
|
|
196
|
-
return asProgram(ast);
|
|
197
|
-
} finally {
|
|
198
|
-
if (parseResult !== 0) {
|
|
199
|
-
flowParseResult_free(parseResult);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (sourceAddr !== 0) {
|
|
203
|
-
FlowParserWASM._free(sourceAddr);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (filenameAddr !== 0) {
|
|
207
|
-
FlowParserWASM._free(filenameAddr);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function asProgram(ast) {
|
|
213
|
-
const program = ast;
|
|
214
|
-
return program;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
function detectSourceType(program) {
|
|
218
|
-
if (!Array.isArray(program.body)) {
|
|
219
|
-
return 'script';
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
for (const stmt of program.body) {
|
|
223
|
-
if (stmt == null) {
|
|
224
|
-
continue;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
switch (stmt.type) {
|
|
228
|
-
case 'ImportDeclaration':
|
|
229
|
-
if (stmt.importKind === 'value' || stmt.importKind == null) {
|
|
230
|
-
return 'module';
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
break;
|
|
234
|
-
|
|
235
|
-
case 'ExportDefaultDeclaration':
|
|
236
|
-
return 'module';
|
|
237
|
-
|
|
238
|
-
case 'ExportNamedDeclaration':
|
|
239
|
-
case 'ExportAllDeclaration':
|
|
240
|
-
if (stmt.exportKind === 'value' || stmt.exportKind == null) {
|
|
241
|
-
return 'module';
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
break;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return 'script';
|
|
249
|
-
}
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _HermesParserDecodeUTF8String = _interopRequireDefault(require("./HermesParserDecodeUTF8String"));
|
|
9
|
-
|
|
10
|
-
var _FlowParserNodeDeserializers = _interopRequireDefault(require("./FlowParserNodeDeserializers"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) {
|
|
13
|
-
return obj && obj.__esModule ? obj : {
|
|
14
|
-
default: obj
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
class FlowParserDeserializer {
|
|
19
|
-
constructor(programBuffer, positionBuffer, positionBufferSize, stringBufferBase, wasmParser, options) {
|
|
20
|
-
this.programBufferIdx = void 0;
|
|
21
|
-
this.positionBufferIdx = void 0;
|
|
22
|
-
this.positionBufferSize = void 0;
|
|
23
|
-
this.stringBufferBase = void 0;
|
|
24
|
-
this.locMap = void 0;
|
|
25
|
-
this.HEAPU8 = void 0;
|
|
26
|
-
this.HEAPU32 = void 0;
|
|
27
|
-
this.HEAPF64 = void 0;
|
|
28
|
-
this.options = void 0;
|
|
29
|
-
this.commentTypes = ['Block', 'Line'];
|
|
30
|
-
this.tokenTypes = ['Boolean', 'Identifier', 'Keyword', 'Null', 'Numeric', 'BigInt', 'Punctuator', 'String', 'RegularExpression', 'Template', 'JSXText'];
|
|
31
|
-
this.programBufferIdx = programBuffer / 4;
|
|
32
|
-
this.positionBufferIdx = positionBuffer / 4;
|
|
33
|
-
this.positionBufferSize = positionBufferSize;
|
|
34
|
-
this.stringBufferBase = stringBufferBase;
|
|
35
|
-
this.locMap = {};
|
|
36
|
-
this.HEAPU8 = wasmParser.HEAPU8;
|
|
37
|
-
this.HEAPU32 = wasmParser.HEAPU32;
|
|
38
|
-
this.HEAPF64 = wasmParser.HEAPF64;
|
|
39
|
-
this.options = options;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
next() {
|
|
43
|
-
const num = this.HEAPU32[this.programBufferIdx++];
|
|
44
|
-
return num;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
deserialize() {
|
|
48
|
-
const program = {
|
|
49
|
-
type: 'Program',
|
|
50
|
-
loc: this.addEmptyLoc(),
|
|
51
|
-
body: this.deserializeNodeList(),
|
|
52
|
-
comments: this.deserializeComments()
|
|
53
|
-
};
|
|
54
|
-
program.interpreter = this.deserializeNode();
|
|
55
|
-
|
|
56
|
-
if (this.options.tokens === true) {
|
|
57
|
-
program.tokens = this.deserializeTokens();
|
|
58
|
-
} else {
|
|
59
|
-
this.deserializeTokens();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
program.errors = this.deserializeErrors();
|
|
63
|
-
this.fillLocs();
|
|
64
|
-
return program;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
deserializeErrors() {
|
|
68
|
-
const size = this.next();
|
|
69
|
-
const errors = [];
|
|
70
|
-
|
|
71
|
-
for (let i = 0; i < size; i++) {
|
|
72
|
-
const loc = this.addEmptyLoc();
|
|
73
|
-
const message = this.deserializeString();
|
|
74
|
-
|
|
75
|
-
if (message == null) {
|
|
76
|
-
throw new Error('Expected serialized parser error message');
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
errors.push({
|
|
80
|
-
loc,
|
|
81
|
-
message
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return errors;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
deserializeBoolean() {
|
|
89
|
-
return Boolean(this.next());
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
deserializeNumber() {
|
|
93
|
-
let floatIdx;
|
|
94
|
-
|
|
95
|
-
if (this.programBufferIdx % 2 === 0) {
|
|
96
|
-
floatIdx = this.programBufferIdx / 2;
|
|
97
|
-
this.programBufferIdx += 2;
|
|
98
|
-
} else {
|
|
99
|
-
floatIdx = (this.programBufferIdx + 1) / 2;
|
|
100
|
-
this.programBufferIdx += 3;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return this.HEAPF64[floatIdx];
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
deserializeString() {
|
|
107
|
-
const offsetPlusOne = this.next();
|
|
108
|
-
|
|
109
|
-
if (offsetPlusOne === 0) {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const size = this.next();
|
|
114
|
-
return (0, _HermesParserDecodeUTF8String.default)(this.stringBufferBase + offsetPlusOne - 1, size, this.HEAPU8);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
deserializeNode() {
|
|
118
|
-
const nodeType = this.next();
|
|
119
|
-
|
|
120
|
-
if (nodeType === 0) {
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const nodeDeserializer = _FlowParserNodeDeserializers.default[nodeType - 1].bind(this);
|
|
125
|
-
|
|
126
|
-
return nodeDeserializer();
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
deserializeNodeList() {
|
|
130
|
-
const size = this.next();
|
|
131
|
-
const nodeList = [];
|
|
132
|
-
|
|
133
|
-
for (let i = 0; i < size; i++) {
|
|
134
|
-
nodeList.push(this.deserializeNode());
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return nodeList;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
deserializeComments() {
|
|
141
|
-
const size = this.next();
|
|
142
|
-
const comments = [];
|
|
143
|
-
|
|
144
|
-
for (let i = 0; i < size; i++) {
|
|
145
|
-
const commentType = this.commentTypes[this.next()];
|
|
146
|
-
const loc = this.addEmptyLoc();
|
|
147
|
-
const value = this.deserializeString();
|
|
148
|
-
comments.push({
|
|
149
|
-
type: commentType,
|
|
150
|
-
loc,
|
|
151
|
-
value
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return comments;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
deserializeTokens() {
|
|
159
|
-
const size = this.next();
|
|
160
|
-
const tokens = [];
|
|
161
|
-
|
|
162
|
-
for (let i = 0; i < size; i++) {
|
|
163
|
-
const tokenType = this.tokenTypes[this.next()];
|
|
164
|
-
const loc = this.addEmptyLoc();
|
|
165
|
-
const value = this.deserializeString();
|
|
166
|
-
tokens.push({
|
|
167
|
-
type: tokenType,
|
|
168
|
-
loc,
|
|
169
|
-
value
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return tokens;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
addEmptyLoc() {
|
|
177
|
-
const loc = {};
|
|
178
|
-
this.locMap[this.next()] = loc;
|
|
179
|
-
return loc;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
fillLocs() {
|
|
183
|
-
for (let i = 0; i < this.positionBufferSize; i++) {
|
|
184
|
-
const locId = this.HEAPU32[this.positionBufferIdx++];
|
|
185
|
-
const kind = this.HEAPU32[this.positionBufferIdx++];
|
|
186
|
-
const line = this.HEAPU32[this.positionBufferIdx++];
|
|
187
|
-
const column = this.HEAPU32[this.positionBufferIdx++];
|
|
188
|
-
const offset = this.HEAPU32[this.positionBufferIdx++];
|
|
189
|
-
const loc = this.locMap[locId];
|
|
190
|
-
|
|
191
|
-
if (kind === 0) {
|
|
192
|
-
loc.start = {
|
|
193
|
-
line,
|
|
194
|
-
column
|
|
195
|
-
};
|
|
196
|
-
loc.rangeStart = offset;
|
|
197
|
-
} else {
|
|
198
|
-
loc.end = {
|
|
199
|
-
line,
|
|
200
|
-
column
|
|
201
|
-
};
|
|
202
|
-
loc.rangeEnd = offset;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
exports.default = FlowParserDeserializer;
|