flow-parser 0.320.0 → 0.322.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/oxidized-src → dist}/FlowParser.js +3 -53
- package/{oxidized/oxidized-src → dist}/FlowParserDeserializer.js +3 -41
- package/{oxidized → dist}/FlowParserNodeDeserializers.js +0 -7
- package/{oxidized → dist}/FlowParserWASM.js +1 -1
- package/{oxidized/oxidized-src → dist}/HermesParserDecodeUTF8String.js +0 -9
- package/dist/ParserOptions.js +7 -0
- package/{oxidized → dist}/babel/TransformESTreeToBabel.js +9 -157
- package/{oxidized → dist}/estree/StripFlowTypes.js +0 -26
- package/{oxidized/oxidized-src → dist}/estree/StripFlowTypesForBabel.js +0 -24
- package/{oxidized/oxidized-src → dist}/estree/TransformComponentSyntax.js +0 -87
- package/{oxidized/oxidized-src → dist}/estree/TransformEnumSyntax.js +0 -12
- package/{oxidized/oxidized-src → dist}/estree/TransformMatchSyntax.js +3 -99
- package/{oxidized → dist}/estree/TransformRecordSyntax.js +3 -31
- package/{oxidized → dist}/getModuleDocblock.js +0 -21
- package/{oxidized → dist}/index.js +25 -99
- package/{oxidized → dist}/transform/SimpleTransform.js +0 -21
- package/{oxidized → dist}/transform/astArrayMutationHelpers.js +0 -9
- package/{oxidized/oxidized-src → dist}/transform/astNodeMutationHelpers.js +4 -26
- package/{oxidized/oxidized-src → dist}/transform/print/comments/comments.js +2 -51
- package/{oxidized → dist}/transform/print/comments/prettier/common/util.js +0 -49
- package/{oxidized → dist}/transform/print/comments/prettier/language-js/comments.js +0 -111
- package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/language-js/loc.js +0 -6
- package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/language-js/printer-estree.js +0 -3
- package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/language-js/utils.js +0 -20
- package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/main/comments.js +2 -63
- package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/utils/get-last.js +0 -1
- package/{oxidized → dist}/transform/print/print.js +6 -22
- package/{oxidized/oxidized-src → dist}/traverse/SimpleTraverser.js +2 -22
- package/{oxidized/oxidized-src → dist}/traverse/getVisitorKeys.js +3 -9
- package/{oxidized/oxidized-src → dist}/utils/Builders.js +1 -17
- package/{oxidized → dist}/utils/GenID.js +0 -7
- package/{oxidized/oxidized-src → dist}/utils/createSyntaxError.js +0 -1
- package/{oxidized → dist}/utils/isReservedWord.js +0 -2
- package/{oxidized → dist}/utils/mutateESTreeASTForPrettier.js +6 -21
- package/package.json +6 -7
- package/flow_parser.js +0 -14585
- package/oxidized/FlowParser.js +0 -249
- package/oxidized/FlowParserDeserializer.js +0 -209
- package/oxidized/HermesParserDecodeUTF8String.js +0 -45
- package/oxidized/ParserOptions.js +0 -8
- package/oxidized/estree/StripFlowTypesForBabel.js +0 -191
- package/oxidized/estree/TransformComponentSyntax.js +0 -764
- package/oxidized/estree/TransformEnumSyntax.js +0 -92
- package/oxidized/estree/TransformMatchSyntax.js +0 -990
- package/oxidized/oxidized-src/FlowParserNodeDeserializers.js +0 -1781
- package/oxidized/oxidized-src/ParserOptions.js +0 -8
- package/oxidized/oxidized-src/babel/TransformESTreeToBabel.js +0 -1063
- package/oxidized/oxidized-src/estree/StripFlowTypes.js +0 -158
- 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/oxidized-src/transform/SimpleTransform.js +0 -95
- package/oxidized/oxidized-src/transform/astArrayMutationHelpers.js +0 -52
- package/oxidized/oxidized-src/transform/print/comments/prettier/common/util.js +0 -235
- package/oxidized/oxidized-src/transform/print/comments/prettier/language-js/comments.js +0 -663
- package/oxidized/oxidized-src/transform/print/print.js +0 -68
- package/oxidized/oxidized-src/utils/GenID.js +0 -37
- package/oxidized/oxidized-src/utils/isReservedWord.js +0 -53
- package/oxidized/oxidized-src/utils/mutateESTreeASTForPrettier.js +0 -85
- package/oxidized/transform/astNodeMutationHelpers.js +0 -142
- package/oxidized/transform/print/comments/comments.js +0 -245
- 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/traverse/SimpleTraverser.js +0 -90
- package/oxidized/traverse/getVisitorKeys.js +0 -29
- package/oxidized/utils/Builders.js +0 -181
- package/oxidized/utils/createSyntaxError.js +0 -15
- /package/{oxidized → dist}/FlowParser.js.flow +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.flow +0 -0
- /package/{oxidized → dist}/ParserOptions.js.flow +0 -0
- /package/{oxidized → dist}/babel/TransformESTreeToBabel.js.flow +0 -0
- /package/{oxidized → dist}/estree/StripFlowTypes.js.flow +0 -0
- /package/{oxidized → dist}/estree/StripFlowTypesForBabel.js.flow +0 -0
- /package/{oxidized → dist}/estree/TransformComponentSyntax.js.flow +0 -0
- /package/{oxidized → dist}/estree/TransformEnumSyntax.js.flow +0 -0
- /package/{oxidized → dist}/estree/TransformMatchSyntax.js.flow +0 -0
- /package/{oxidized → dist}/estree/TransformRecordSyntax.js.flow +0 -0
- /package/{oxidized → dist}/generated/ESTreeVisitorKeys.js +0 -0
- /package/{oxidized → dist}/generated/ESTreeVisitorKeys.js.flow +0 -0
- /package/{oxidized → dist}/getModuleDocblock.js.flow +0 -0
- /package/{oxidized → dist}/index.js.flow +0 -0
- /package/{oxidized → dist}/transform/SimpleTransform.js.flow +0 -0
- /package/{oxidized → dist}/transform/astArrayMutationHelpers.js.flow +0 -0
- /package/{oxidized → dist}/transform/astNodeMutationHelpers.js.flow +0 -0
- /package/{oxidized → dist}/transform/print/comments/comments.js.flow +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 → dist}/transform/print/print.js.flow +0 -0
- /package/{oxidized → dist}/traverse/SimpleTraverser.js.flow +0 -0
- /package/{oxidized → dist}/traverse/getVisitorKeys.js.flow +0 -0
- /package/{oxidized → dist}/utils/Builders.js.flow +0 -0
- /package/{oxidized → dist}/utils/GenID.js.flow +0 -0
- /package/{oxidized → dist}/utils/createSyntaxError.js.flow +0 -0
- /package/{oxidized → dist}/utils/isReservedWord.js.flow +0 -0
- /package/{oxidized → dist}/utils/mutateESTreeASTForPrettier.js.flow +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# The flow-parser package
|
|
2
2
|
|
|
3
|
-
This package contains the Flow parser in its
|
|
3
|
+
This package contains the Flow parser in its JavaScript package form.
|
|
4
4
|
|
|
5
5
|
# What is Flow
|
|
6
6
|
|
|
@@ -8,42 +8,30 @@ See [flow.org](https://flow.org/). The code for the Flow parser [lives on GitHub
|
|
|
8
8
|
|
|
9
9
|
# What is the Flow Parser
|
|
10
10
|
|
|
11
|
-
The Flow Parser is a JavaScript parser
|
|
11
|
+
The Flow Parser is a JavaScript parser for Flow syntax. It produces an AST that conforms to the [ESTree spec](https://github.com/estree/estree). This npm package contains the Flow Rust parser compiled to WASM with JavaScript bindings.
|
|
12
12
|
|
|
13
13
|
# Usage
|
|
14
14
|
|
|
15
|
-
You can use the Flow parser in
|
|
15
|
+
You can use the Flow parser in node:
|
|
16
16
|
|
|
17
17
|
```JavaScript
|
|
18
|
-
require('flow-parser')
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
To use in the browser, you can add
|
|
22
|
-
|
|
23
|
-
```HTML
|
|
24
|
-
<script src="flow_parser.js"></script>
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
which will make the `flow` object available to use like so:
|
|
28
|
-
|
|
29
|
-
```JavaScript
|
|
30
|
-
flow.parse('1+1', {});
|
|
18
|
+
const {parse} = require('flow-parser');
|
|
19
|
+
parse('1+1', {});
|
|
31
20
|
```
|
|
32
21
|
|
|
33
22
|
## Options
|
|
34
23
|
|
|
35
|
-
The second argument to `
|
|
24
|
+
The second argument to `parse` is the options object. Common options:
|
|
36
25
|
|
|
37
26
|
### Basic options
|
|
38
|
-
* `
|
|
39
|
-
* `
|
|
40
|
-
* `comments` (boolean, default `true`) - attach comments to AST nodes (`leadingComments` and `trailingComments`)
|
|
41
|
-
* `all_comments` (boolean, default `true`) - include a list of all comments from the whole program
|
|
27
|
+
* `flow` (`'detect'` or `'all'`, default `'detect'`) - parse Flow syntax only with an `@flow` pragma, or always parse Flow syntax
|
|
28
|
+
* `sourceType` (`'module'`, `'script'`, or `'unambiguous'`) - parse the file as a module, script, or infer it from the contents
|
|
42
29
|
* `tokens` (boolean, default `false`) - include a list of all parsed tokens in a top-level `tokens` property
|
|
30
|
+
* `babel` (boolean, default `false`) - return a Babel-shaped AST
|
|
43
31
|
|
|
44
32
|
### Language features
|
|
45
|
-
* `
|
|
46
|
-
* `
|
|
47
|
-
* `
|
|
48
|
-
* `
|
|
49
|
-
* `
|
|
33
|
+
* `enableEnums` (boolean, default `true`) - enable parsing of [enums](https://flow.org/en/docs/enums/)
|
|
34
|
+
* `enableExperimentalFlowMatchSyntax` (boolean, default `true`) - enable parsing of [match expressions and match statements](https://flow.org/en/docs/match/)
|
|
35
|
+
* `enableExperimentalComponentSyntax` (boolean, default `true`) - enable parsing of [component syntax](https://flow.org/en/docs/react/component-syntax/)
|
|
36
|
+
* `assertOperator` (boolean, default `false`) - enable parsing of the assert operator
|
|
37
|
+
* `enableExperimentalDecorators` (boolean, default `true`) - enable parsing of decorators
|
|
@@ -4,19 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.parse = parse;
|
|
7
|
-
|
|
8
7
|
var _FlowParserDeserializer = _interopRequireDefault(require("./FlowParserDeserializer"));
|
|
9
|
-
|
|
10
8
|
var _FlowParserWASM = _interopRequireDefault(require("./FlowParserWASM"));
|
|
11
|
-
|
|
12
9
|
var _getModuleDocblock = require("./getModuleDocblock");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
default: obj
|
|
10
|
+
function _interopRequireDefault(e) {
|
|
11
|
+
return e && e.__esModule ? e : {
|
|
12
|
+
default: e
|
|
17
13
|
};
|
|
18
14
|
}
|
|
19
|
-
|
|
20
15
|
let FlowParserWASM;
|
|
21
16
|
let flowParse;
|
|
22
17
|
let flowParseResult_free;
|
|
@@ -27,17 +22,14 @@ let flowParseResult_getProgramBuffer;
|
|
|
27
22
|
let flowParseResult_getPositionBuffer;
|
|
28
23
|
let flowParseResult_getPositionBufferSize;
|
|
29
24
|
let flowParseResult_getStringBuffer;
|
|
30
|
-
|
|
31
25
|
function initFlowParserWASM() {
|
|
32
26
|
if (FlowParserWASM != null) {
|
|
33
27
|
return;
|
|
34
28
|
}
|
|
35
|
-
|
|
36
29
|
FlowParserWASM = (0, _FlowParserWASM.default)({
|
|
37
30
|
quit(_status, toThrow) {
|
|
38
31
|
throw toThrow;
|
|
39
32
|
}
|
|
40
|
-
|
|
41
33
|
});
|
|
42
34
|
flowParse = FlowParserWASM.cwrap('hermesParse', 'number', ['number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number']);
|
|
43
35
|
flowParseResult_free = FlowParserWASM.cwrap('hermesParseResult_free', 'void', ['number']);
|
|
@@ -49,16 +41,13 @@ function initFlowParserWASM() {
|
|
|
49
41
|
flowParseResult_getPositionBufferSize = FlowParserWASM.cwrap('hermesParseResult_getPositionBufferSize', 'number', ['number']);
|
|
50
42
|
flowParseResult_getStringBuffer = FlowParserWASM.cwrap('hermesParseResult_getStringBuffer', 'number', ['number']);
|
|
51
43
|
}
|
|
52
|
-
|
|
53
44
|
function copyToHeap(buffer, addr) {
|
|
54
45
|
FlowParserWASM.HEAP8.set(buffer, addr);
|
|
55
46
|
FlowParserWASM.HEAP8[addr + buffer.length] = 0;
|
|
56
47
|
}
|
|
57
|
-
|
|
58
48
|
function flag(v) {
|
|
59
49
|
return v === true ? 1 : 0;
|
|
60
50
|
}
|
|
61
|
-
|
|
62
51
|
function parse(source, options) {
|
|
63
52
|
initFlowParserWASM();
|
|
64
53
|
const sourceBuffer = Buffer.from(source, 'utf8');
|
|
@@ -68,31 +57,24 @@ function parse(source, options) {
|
|
|
68
57
|
let filenameAddr = 0;
|
|
69
58
|
let filenameLen = 0;
|
|
70
59
|
let parseResult = 0;
|
|
71
|
-
|
|
72
60
|
try {
|
|
73
61
|
sourceAddr = FlowParserWASM._malloc(sourceBuffer.length + 1);
|
|
74
|
-
|
|
75
62
|
if (!sourceAddr) {
|
|
76
63
|
throw new Error('Parser out of memory');
|
|
77
64
|
}
|
|
78
|
-
|
|
79
65
|
if (filenameBuffer != null) {
|
|
80
66
|
filenameAddr = FlowParserWASM._malloc(filenameBuffer.length + 1);
|
|
81
|
-
|
|
82
67
|
if (!filenameAddr) {
|
|
83
68
|
throw new Error('Parser out of memory');
|
|
84
69
|
}
|
|
85
|
-
|
|
86
70
|
copyToHeap(filenameBuffer, filenameAddr);
|
|
87
71
|
filenameLen = filenameBuffer.length + 1;
|
|
88
72
|
}
|
|
89
|
-
|
|
90
73
|
copyToHeap(sourceBuffer, sourceAddr);
|
|
91
74
|
const enableTypes = options.enableTypes === false ? 0 : 1;
|
|
92
75
|
const sourceTypeCode = options.sourceType === 'script' ? 1 : options.sourceType === 'module' ? 2 : 0;
|
|
93
76
|
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
77
|
const programBuffer = flowParseResult_getProgramBuffer(parseResult);
|
|
95
|
-
|
|
96
78
|
if (!programBuffer) {
|
|
97
79
|
const err = flowParseResult_getError(parseResult);
|
|
98
80
|
const syntaxError = new SyntaxError(err || 'unknown parse error');
|
|
@@ -102,56 +84,42 @@ function parse(source, options) {
|
|
|
102
84
|
};
|
|
103
85
|
throw syntaxError;
|
|
104
86
|
}
|
|
105
|
-
|
|
106
87
|
const deserializer = new _FlowParserDeserializer.default(programBuffer, flowParseResult_getPositionBuffer(parseResult), flowParseResult_getPositionBufferSize(parseResult), flowParseResult_getStringBuffer(parseResult), FlowParserWASM, options);
|
|
107
88
|
const ast = deserializer.deserialize();
|
|
108
|
-
|
|
109
89
|
if (ast.type !== 'Program') {
|
|
110
90
|
throw new Error(`Expected Program, got ${ast.type}`);
|
|
111
91
|
}
|
|
112
|
-
|
|
113
92
|
const sourceFilename = typeof options.sourceFilename === 'string' ? options.sourceFilename : null;
|
|
114
93
|
const visitedNodes = new WeakSet();
|
|
115
94
|
const locRanges = new WeakMap();
|
|
116
|
-
|
|
117
95
|
function fixLocs(node) {
|
|
118
96
|
if (node == null || typeof node !== 'object') {
|
|
119
97
|
return;
|
|
120
98
|
}
|
|
121
|
-
|
|
122
99
|
const wireNode = node;
|
|
123
|
-
|
|
124
100
|
if (visitedNodes.has(wireNode)) {
|
|
125
101
|
return;
|
|
126
102
|
}
|
|
127
|
-
|
|
128
103
|
visitedNodes.add(wireNode);
|
|
129
|
-
|
|
130
104
|
if (wireNode.loc != null) {
|
|
131
105
|
const loc = wireNode.loc;
|
|
132
106
|
let range = locRanges.get(loc);
|
|
133
|
-
|
|
134
107
|
if (range == null) {
|
|
135
108
|
const rangeStart = loc.rangeStart;
|
|
136
109
|
const rangeEnd = loc.rangeEnd;
|
|
137
|
-
|
|
138
110
|
if (rangeStart == null || rangeEnd == null) {
|
|
139
111
|
throw new Error('Expected serialized source range');
|
|
140
112
|
}
|
|
141
|
-
|
|
142
113
|
loc.source = sourceFilename;
|
|
143
114
|
range = [rangeStart, rangeEnd];
|
|
144
115
|
locRanges.set(loc, range);
|
|
145
116
|
delete loc.rangeStart;
|
|
146
117
|
delete loc.rangeEnd;
|
|
147
118
|
}
|
|
148
|
-
|
|
149
119
|
wireNode.range = range;
|
|
150
120
|
}
|
|
151
|
-
|
|
152
121
|
for (const key of Object.keys(wireNode)) {
|
|
153
122
|
const val = wireNode[key];
|
|
154
|
-
|
|
155
123
|
if (Array.isArray(val)) {
|
|
156
124
|
for (const child of val) {
|
|
157
125
|
fixLocs(child);
|
|
@@ -161,20 +129,15 @@ function parse(source, options) {
|
|
|
161
129
|
}
|
|
162
130
|
}
|
|
163
131
|
}
|
|
164
|
-
|
|
165
132
|
fixLocs(ast);
|
|
166
|
-
|
|
167
133
|
if (options.throwOnParseErrors !== false) {
|
|
168
134
|
const errors = ast.errors;
|
|
169
|
-
|
|
170
135
|
if (errors != null && errors.length > 0) {
|
|
171
136
|
const first = errors[0];
|
|
172
137
|
const start = first.loc.start;
|
|
173
|
-
|
|
174
138
|
if (start == null) {
|
|
175
139
|
throw new Error('Expected serialized parser error start location');
|
|
176
140
|
}
|
|
177
|
-
|
|
178
141
|
const line = start.line;
|
|
179
142
|
const column = start.column;
|
|
180
143
|
const syntaxError = new SyntaxError(`${first.message} (${line}:${column})`);
|
|
@@ -185,65 +148,52 @@ function parse(source, options) {
|
|
|
185
148
|
throw syntaxError;
|
|
186
149
|
}
|
|
187
150
|
}
|
|
188
|
-
|
|
189
151
|
if (options.sourceType === 'script' || options.sourceType === 'module') {
|
|
190
152
|
ast.sourceType = options.sourceType;
|
|
191
153
|
} else {
|
|
192
154
|
ast.sourceType = detectSourceType(ast);
|
|
193
155
|
}
|
|
194
|
-
|
|
195
156
|
ast.docblock = (0, _getModuleDocblock.getModuleDocblock)(ast);
|
|
196
157
|
return asProgram(ast);
|
|
197
158
|
} finally {
|
|
198
159
|
if (parseResult !== 0) {
|
|
199
160
|
flowParseResult_free(parseResult);
|
|
200
161
|
}
|
|
201
|
-
|
|
202
162
|
if (sourceAddr !== 0) {
|
|
203
163
|
FlowParserWASM._free(sourceAddr);
|
|
204
164
|
}
|
|
205
|
-
|
|
206
165
|
if (filenameAddr !== 0) {
|
|
207
166
|
FlowParserWASM._free(filenameAddr);
|
|
208
167
|
}
|
|
209
168
|
}
|
|
210
169
|
}
|
|
211
|
-
|
|
212
170
|
function asProgram(ast) {
|
|
213
171
|
const program = ast;
|
|
214
172
|
return program;
|
|
215
173
|
}
|
|
216
|
-
|
|
217
174
|
function detectSourceType(program) {
|
|
218
175
|
if (!Array.isArray(program.body)) {
|
|
219
176
|
return 'script';
|
|
220
177
|
}
|
|
221
|
-
|
|
222
178
|
for (const stmt of program.body) {
|
|
223
179
|
if (stmt == null) {
|
|
224
180
|
continue;
|
|
225
181
|
}
|
|
226
|
-
|
|
227
182
|
switch (stmt.type) {
|
|
228
183
|
case 'ImportDeclaration':
|
|
229
184
|
if (stmt.importKind === 'value' || stmt.importKind == null) {
|
|
230
185
|
return 'module';
|
|
231
186
|
}
|
|
232
|
-
|
|
233
187
|
break;
|
|
234
|
-
|
|
235
188
|
case 'ExportDefaultDeclaration':
|
|
236
189
|
return 'module';
|
|
237
|
-
|
|
238
190
|
case 'ExportNamedDeclaration':
|
|
239
191
|
case 'ExportAllDeclaration':
|
|
240
192
|
if (stmt.exportKind === 'value' || stmt.exportKind == null) {
|
|
241
193
|
return 'module';
|
|
242
194
|
}
|
|
243
|
-
|
|
244
195
|
break;
|
|
245
196
|
}
|
|
246
197
|
}
|
|
247
|
-
|
|
248
198
|
return 'script';
|
|
249
199
|
}
|
|
@@ -4,17 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _HermesParserDecodeUTF8String = _interopRequireDefault(require("./HermesParserDecodeUTF8String"));
|
|
9
|
-
|
|
10
8
|
var _FlowParserNodeDeserializers = _interopRequireDefault(require("./FlowParserNodeDeserializers"));
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
default: obj
|
|
9
|
+
function _interopRequireDefault(e) {
|
|
10
|
+
return e && e.__esModule ? e : {
|
|
11
|
+
default: e
|
|
15
12
|
};
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
class FlowParserDeserializer {
|
|
19
15
|
constructor(programBuffer, positionBuffer, positionBufferSize, stringBufferBase, wasmParser, options) {
|
|
20
16
|
this.programBufferIdx = void 0;
|
|
@@ -38,12 +34,10 @@ class FlowParserDeserializer {
|
|
|
38
34
|
this.HEAPF64 = wasmParser.HEAPF64;
|
|
39
35
|
this.options = options;
|
|
40
36
|
}
|
|
41
|
-
|
|
42
37
|
next() {
|
|
43
38
|
const num = this.HEAPU32[this.programBufferIdx++];
|
|
44
39
|
return num;
|
|
45
40
|
}
|
|
46
|
-
|
|
47
41
|
deserialize() {
|
|
48
42
|
const program = {
|
|
49
43
|
type: 'Program',
|
|
@@ -52,46 +46,36 @@ class FlowParserDeserializer {
|
|
|
52
46
|
comments: this.deserializeComments()
|
|
53
47
|
};
|
|
54
48
|
program.interpreter = this.deserializeNode();
|
|
55
|
-
|
|
56
49
|
if (this.options.tokens === true) {
|
|
57
50
|
program.tokens = this.deserializeTokens();
|
|
58
51
|
} else {
|
|
59
52
|
this.deserializeTokens();
|
|
60
53
|
}
|
|
61
|
-
|
|
62
54
|
program.errors = this.deserializeErrors();
|
|
63
55
|
this.fillLocs();
|
|
64
56
|
return program;
|
|
65
57
|
}
|
|
66
|
-
|
|
67
58
|
deserializeErrors() {
|
|
68
59
|
const size = this.next();
|
|
69
60
|
const errors = [];
|
|
70
|
-
|
|
71
61
|
for (let i = 0; i < size; i++) {
|
|
72
62
|
const loc = this.addEmptyLoc();
|
|
73
63
|
const message = this.deserializeString();
|
|
74
|
-
|
|
75
64
|
if (message == null) {
|
|
76
65
|
throw new Error('Expected serialized parser error message');
|
|
77
66
|
}
|
|
78
|
-
|
|
79
67
|
errors.push({
|
|
80
68
|
loc,
|
|
81
69
|
message
|
|
82
70
|
});
|
|
83
71
|
}
|
|
84
|
-
|
|
85
72
|
return errors;
|
|
86
73
|
}
|
|
87
|
-
|
|
88
74
|
deserializeBoolean() {
|
|
89
75
|
return Boolean(this.next());
|
|
90
76
|
}
|
|
91
|
-
|
|
92
77
|
deserializeNumber() {
|
|
93
78
|
let floatIdx;
|
|
94
|
-
|
|
95
79
|
if (this.programBufferIdx % 2 === 0) {
|
|
96
80
|
floatIdx = this.programBufferIdx / 2;
|
|
97
81
|
this.programBufferIdx += 2;
|
|
@@ -99,48 +83,35 @@ class FlowParserDeserializer {
|
|
|
99
83
|
floatIdx = (this.programBufferIdx + 1) / 2;
|
|
100
84
|
this.programBufferIdx += 3;
|
|
101
85
|
}
|
|
102
|
-
|
|
103
86
|
return this.HEAPF64[floatIdx];
|
|
104
87
|
}
|
|
105
|
-
|
|
106
88
|
deserializeString() {
|
|
107
89
|
const offsetPlusOne = this.next();
|
|
108
|
-
|
|
109
90
|
if (offsetPlusOne === 0) {
|
|
110
91
|
return null;
|
|
111
92
|
}
|
|
112
|
-
|
|
113
93
|
const size = this.next();
|
|
114
94
|
return (0, _HermesParserDecodeUTF8String.default)(this.stringBufferBase + offsetPlusOne - 1, size, this.HEAPU8);
|
|
115
95
|
}
|
|
116
|
-
|
|
117
96
|
deserializeNode() {
|
|
118
97
|
const nodeType = this.next();
|
|
119
|
-
|
|
120
98
|
if (nodeType === 0) {
|
|
121
99
|
return null;
|
|
122
100
|
}
|
|
123
|
-
|
|
124
101
|
const nodeDeserializer = _FlowParserNodeDeserializers.default[nodeType - 1].bind(this);
|
|
125
|
-
|
|
126
102
|
return nodeDeserializer();
|
|
127
103
|
}
|
|
128
|
-
|
|
129
104
|
deserializeNodeList() {
|
|
130
105
|
const size = this.next();
|
|
131
106
|
const nodeList = [];
|
|
132
|
-
|
|
133
107
|
for (let i = 0; i < size; i++) {
|
|
134
108
|
nodeList.push(this.deserializeNode());
|
|
135
109
|
}
|
|
136
|
-
|
|
137
110
|
return nodeList;
|
|
138
111
|
}
|
|
139
|
-
|
|
140
112
|
deserializeComments() {
|
|
141
113
|
const size = this.next();
|
|
142
114
|
const comments = [];
|
|
143
|
-
|
|
144
115
|
for (let i = 0; i < size; i++) {
|
|
145
116
|
const commentType = this.commentTypes[this.next()];
|
|
146
117
|
const loc = this.addEmptyLoc();
|
|
@@ -151,14 +122,11 @@ class FlowParserDeserializer {
|
|
|
151
122
|
value
|
|
152
123
|
});
|
|
153
124
|
}
|
|
154
|
-
|
|
155
125
|
return comments;
|
|
156
126
|
}
|
|
157
|
-
|
|
158
127
|
deserializeTokens() {
|
|
159
128
|
const size = this.next();
|
|
160
129
|
const tokens = [];
|
|
161
|
-
|
|
162
130
|
for (let i = 0; i < size; i++) {
|
|
163
131
|
const tokenType = this.tokenTypes[this.next()];
|
|
164
132
|
const loc = this.addEmptyLoc();
|
|
@@ -169,16 +137,13 @@ class FlowParserDeserializer {
|
|
|
169
137
|
value
|
|
170
138
|
});
|
|
171
139
|
}
|
|
172
|
-
|
|
173
140
|
return tokens;
|
|
174
141
|
}
|
|
175
|
-
|
|
176
142
|
addEmptyLoc() {
|
|
177
143
|
const loc = {};
|
|
178
144
|
this.locMap[this.next()] = loc;
|
|
179
145
|
return loc;
|
|
180
146
|
}
|
|
181
|
-
|
|
182
147
|
fillLocs() {
|
|
183
148
|
for (let i = 0; i < this.positionBufferSize; i++) {
|
|
184
149
|
const locId = this.HEAPU32[this.positionBufferIdx++];
|
|
@@ -187,7 +152,6 @@ class FlowParserDeserializer {
|
|
|
187
152
|
const column = this.HEAPU32[this.positionBufferIdx++];
|
|
188
153
|
const offset = this.HEAPU32[this.positionBufferIdx++];
|
|
189
154
|
const loc = this.locMap[locId];
|
|
190
|
-
|
|
191
155
|
if (kind === 0) {
|
|
192
156
|
loc.start = {
|
|
193
157
|
line,
|
|
@@ -203,7 +167,5 @@ class FlowParserDeserializer {
|
|
|
203
167
|
}
|
|
204
168
|
}
|
|
205
169
|
}
|
|
206
|
-
|
|
207
170
|
}
|
|
208
|
-
|
|
209
171
|
exports.default = FlowParserDeserializer;
|
|
@@ -590,31 +590,26 @@ module.exports = [function () {
|
|
|
590
590
|
raw,
|
|
591
591
|
literalType
|
|
592
592
|
};
|
|
593
|
-
|
|
594
593
|
if (bigint != null) {
|
|
595
594
|
node.bigint = bigint;
|
|
596
|
-
|
|
597
595
|
try {
|
|
598
596
|
node.value = typeof BigInt === 'function' ? BigInt(bigint) : null;
|
|
599
597
|
} catch (e) {
|
|
600
598
|
node.value = null;
|
|
601
599
|
}
|
|
602
600
|
}
|
|
603
|
-
|
|
604
601
|
if (regexPattern != null) {
|
|
605
602
|
const flags = regexFlags != null ? regexFlags : '';
|
|
606
603
|
node.regex = {
|
|
607
604
|
pattern: regexPattern,
|
|
608
605
|
flags
|
|
609
606
|
};
|
|
610
|
-
|
|
611
607
|
try {
|
|
612
608
|
node.value = new RegExp(regexPattern, flags);
|
|
613
609
|
} catch (e) {
|
|
614
610
|
node.value = null;
|
|
615
611
|
}
|
|
616
612
|
}
|
|
617
|
-
|
|
618
613
|
return node;
|
|
619
614
|
}, function () {
|
|
620
615
|
return {
|
|
@@ -1059,7 +1054,6 @@ module.exports = [function () {
|
|
|
1059
1054
|
const raw = this.deserializeString();
|
|
1060
1055
|
const bigint = this.deserializeString();
|
|
1061
1056
|
let value = null;
|
|
1062
|
-
|
|
1063
1057
|
if (bigint != null && typeof BigInt === 'function') {
|
|
1064
1058
|
try {
|
|
1065
1059
|
value = BigInt(bigint);
|
|
@@ -1067,7 +1061,6 @@ module.exports = [function () {
|
|
|
1067
1061
|
value = null;
|
|
1068
1062
|
}
|
|
1069
1063
|
}
|
|
1070
|
-
|
|
1071
1064
|
return {
|
|
1072
1065
|
type: 'BigIntLiteralTypeAnnotation',
|
|
1073
1066
|
loc,
|