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.
Files changed (105) hide show
  1. package/README.md +14 -26
  2. package/{oxidized/oxidized-src → dist}/FlowParser.js +3 -53
  3. package/{oxidized/oxidized-src → dist}/FlowParserDeserializer.js +3 -41
  4. package/{oxidized → dist}/FlowParserNodeDeserializers.js +0 -7
  5. package/{oxidized → dist}/FlowParserWASM.js +1 -1
  6. package/{oxidized/oxidized-src → dist}/HermesParserDecodeUTF8String.js +0 -9
  7. package/dist/ParserOptions.js +7 -0
  8. package/{oxidized → dist}/babel/TransformESTreeToBabel.js +9 -157
  9. package/{oxidized → dist}/estree/StripFlowTypes.js +0 -26
  10. package/{oxidized/oxidized-src → dist}/estree/StripFlowTypesForBabel.js +0 -24
  11. package/{oxidized/oxidized-src → dist}/estree/TransformComponentSyntax.js +0 -87
  12. package/{oxidized/oxidized-src → dist}/estree/TransformEnumSyntax.js +0 -12
  13. package/{oxidized/oxidized-src → dist}/estree/TransformMatchSyntax.js +3 -99
  14. package/{oxidized → dist}/estree/TransformRecordSyntax.js +3 -31
  15. package/{oxidized → dist}/getModuleDocblock.js +0 -21
  16. package/{oxidized → dist}/index.js +25 -99
  17. package/{oxidized → dist}/transform/SimpleTransform.js +0 -21
  18. package/{oxidized → dist}/transform/astArrayMutationHelpers.js +0 -9
  19. package/{oxidized/oxidized-src → dist}/transform/astNodeMutationHelpers.js +4 -26
  20. package/{oxidized/oxidized-src → dist}/transform/print/comments/comments.js +2 -51
  21. package/{oxidized → dist}/transform/print/comments/prettier/common/util.js +0 -49
  22. package/{oxidized → dist}/transform/print/comments/prettier/language-js/comments.js +0 -111
  23. package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/language-js/loc.js +0 -6
  24. package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/language-js/printer-estree.js +0 -3
  25. package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/language-js/utils.js +0 -20
  26. package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/main/comments.js +2 -63
  27. package/{oxidized/oxidized-src → dist}/transform/print/comments/prettier/utils/get-last.js +0 -1
  28. package/{oxidized → dist}/transform/print/print.js +6 -22
  29. package/{oxidized/oxidized-src → dist}/traverse/SimpleTraverser.js +2 -22
  30. package/{oxidized/oxidized-src → dist}/traverse/getVisitorKeys.js +3 -9
  31. package/{oxidized/oxidized-src → dist}/utils/Builders.js +1 -17
  32. package/{oxidized → dist}/utils/GenID.js +0 -7
  33. package/{oxidized/oxidized-src → dist}/utils/createSyntaxError.js +0 -1
  34. package/{oxidized → dist}/utils/isReservedWord.js +0 -2
  35. package/{oxidized → dist}/utils/mutateESTreeASTForPrettier.js +6 -21
  36. package/package.json +6 -7
  37. package/flow_parser.js +0 -14585
  38. package/oxidized/FlowParser.js +0 -249
  39. package/oxidized/FlowParserDeserializer.js +0 -209
  40. package/oxidized/HermesParserDecodeUTF8String.js +0 -45
  41. package/oxidized/ParserOptions.js +0 -8
  42. package/oxidized/estree/StripFlowTypesForBabel.js +0 -191
  43. package/oxidized/estree/TransformComponentSyntax.js +0 -764
  44. package/oxidized/estree/TransformEnumSyntax.js +0 -92
  45. package/oxidized/estree/TransformMatchSyntax.js +0 -990
  46. package/oxidized/oxidized-src/FlowParserNodeDeserializers.js +0 -1781
  47. package/oxidized/oxidized-src/ParserOptions.js +0 -8
  48. package/oxidized/oxidized-src/babel/TransformESTreeToBabel.js +0 -1063
  49. package/oxidized/oxidized-src/estree/StripFlowTypes.js +0 -158
  50. package/oxidized/oxidized-src/estree/TransformRecordSyntax.js +0 -283
  51. package/oxidized/oxidized-src/generated/ESTreeVisitorKeys.js +0 -234
  52. package/oxidized/oxidized-src/getModuleDocblock.js +0 -87
  53. package/oxidized/oxidized-src/index.js +0 -220
  54. package/oxidized/oxidized-src/transform/SimpleTransform.js +0 -95
  55. package/oxidized/oxidized-src/transform/astArrayMutationHelpers.js +0 -52
  56. package/oxidized/oxidized-src/transform/print/comments/prettier/common/util.js +0 -235
  57. package/oxidized/oxidized-src/transform/print/comments/prettier/language-js/comments.js +0 -663
  58. package/oxidized/oxidized-src/transform/print/print.js +0 -68
  59. package/oxidized/oxidized-src/utils/GenID.js +0 -37
  60. package/oxidized/oxidized-src/utils/isReservedWord.js +0 -53
  61. package/oxidized/oxidized-src/utils/mutateESTreeASTForPrettier.js +0 -85
  62. package/oxidized/transform/astNodeMutationHelpers.js +0 -142
  63. package/oxidized/transform/print/comments/comments.js +0 -245
  64. package/oxidized/transform/print/comments/prettier/language-js/loc.js +0 -30
  65. package/oxidized/transform/print/comments/prettier/language-js/printer-estree.js +0 -23
  66. package/oxidized/transform/print/comments/prettier/language-js/utils.js +0 -89
  67. package/oxidized/transform/print/comments/prettier/main/comments.js +0 -374
  68. package/oxidized/transform/print/comments/prettier/utils/get-last.js +0 -5
  69. package/oxidized/transform/print/detachedNodeTypes.js +0 -1
  70. package/oxidized/traverse/SimpleTraverser.js +0 -90
  71. package/oxidized/traverse/getVisitorKeys.js +0 -29
  72. package/oxidized/utils/Builders.js +0 -181
  73. package/oxidized/utils/createSyntaxError.js +0 -15
  74. /package/{oxidized → dist}/FlowParser.js.flow +0 -0
  75. /package/{oxidized → dist}/FlowParserDeserializer.js.flow +0 -0
  76. /package/{oxidized → dist}/FlowParserNodeDeserializers.js.flow +0 -0
  77. /package/{oxidized → dist}/FlowParserWASM.js.flow +0 -0
  78. /package/{oxidized → dist}/HermesAST.js.flow +0 -0
  79. /package/{oxidized → dist}/HermesParserDecodeUTF8String.js.flow +0 -0
  80. /package/{oxidized → dist}/ParserOptions.js.flow +0 -0
  81. /package/{oxidized → dist}/babel/TransformESTreeToBabel.js.flow +0 -0
  82. /package/{oxidized → dist}/estree/StripFlowTypes.js.flow +0 -0
  83. /package/{oxidized → dist}/estree/StripFlowTypesForBabel.js.flow +0 -0
  84. /package/{oxidized → dist}/estree/TransformComponentSyntax.js.flow +0 -0
  85. /package/{oxidized → dist}/estree/TransformEnumSyntax.js.flow +0 -0
  86. /package/{oxidized → dist}/estree/TransformMatchSyntax.js.flow +0 -0
  87. /package/{oxidized → dist}/estree/TransformRecordSyntax.js.flow +0 -0
  88. /package/{oxidized → dist}/generated/ESTreeVisitorKeys.js +0 -0
  89. /package/{oxidized → dist}/generated/ESTreeVisitorKeys.js.flow +0 -0
  90. /package/{oxidized → dist}/getModuleDocblock.js.flow +0 -0
  91. /package/{oxidized → dist}/index.js.flow +0 -0
  92. /package/{oxidized → dist}/transform/SimpleTransform.js.flow +0 -0
  93. /package/{oxidized → dist}/transform/astArrayMutationHelpers.js.flow +0 -0
  94. /package/{oxidized → dist}/transform/astNodeMutationHelpers.js.flow +0 -0
  95. /package/{oxidized → dist}/transform/print/comments/comments.js.flow +0 -0
  96. /package/{oxidized/oxidized-src → dist}/transform/print/detachedNodeTypes.js +0 -0
  97. /package/{oxidized → dist}/transform/print/detachedNodeTypes.js.flow +0 -0
  98. /package/{oxidized → dist}/transform/print/print.js.flow +0 -0
  99. /package/{oxidized → dist}/traverse/SimpleTraverser.js.flow +0 -0
  100. /package/{oxidized → dist}/traverse/getVisitorKeys.js.flow +0 -0
  101. /package/{oxidized → dist}/utils/Builders.js.flow +0 -0
  102. /package/{oxidized → dist}/utils/GenID.js.flow +0 -0
  103. /package/{oxidized → dist}/utils/createSyntaxError.js.flow +0 -0
  104. /package/{oxidized → dist}/utils/isReservedWord.js.flow +0 -0
  105. /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;
@@ -1,45 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = HermesParserDecodeUTF8String;
7
-
8
- function HermesParserDecodeUTF8String(ptrIn, length, heap) {
9
- let ptr = ptrIn;
10
- const endPtr = ptr + length;
11
- let str = '';
12
-
13
- while (ptr < endPtr) {
14
- let u0 = heap[ptr++];
15
-
16
- if (!(u0 & 0x80)) {
17
- str += String.fromCharCode(u0);
18
- continue;
19
- }
20
-
21
- const u1 = heap[ptr++] & 0x3f;
22
-
23
- if ((u0 & 0xe0) === 0xc0) {
24
- str += String.fromCharCode((u0 & 0x1f) << 6 | u1);
25
- continue;
26
- }
27
-
28
- const u2 = heap[ptr++] & 0x3f;
29
-
30
- if ((u0 & 0xf0) === 0xe0) {
31
- u0 = (u0 & 0x0f) << 12 | u1 << 6 | u2;
32
- } else {
33
- u0 = (u0 & 0x07) << 18 | u1 << 12 | u2 << 6 | heap[ptr++] & 0x3f;
34
- }
35
-
36
- if (u0 < 0x10000) {
37
- str += String.fromCharCode(u0);
38
- } else {
39
- u0 -= 0x10000;
40
- str += String.fromCharCode(0xd800 | u0 >> 10, 0xdc00 | u0 & 0x3ff);
41
- }
42
- }
43
-
44
- return str;
45
- }
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ParserOptionsKeys = void 0;
7
- const ParserOptionsKeys = new Set(['allowReturnOutsideFunction', 'assertOperator', 'babel', 'flow', 'enableExperimentalComponentSyntax', 'enableExperimentalFlowMatchSyntax', 'enableExperimentalFlowRecordSyntax', 'reactRuntimeTarget', 'sourceFilename', 'sourceType', 'throwOnParseErrors', 'tokens', 'transformOptions']);
8
- exports.ParserOptionsKeys = ParserOptionsKeys;
@@ -1,191 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.transformProgram = transformProgram;
7
-
8
- var _SimpleTransform = require("../transform/SimpleTransform");
9
-
10
- var _createSyntaxError = require("../utils/createSyntaxError");
11
-
12
- const nodeWith = _SimpleTransform.SimpleTransform.nodeWith;
13
- const EMPTY_PARENT = null;
14
-
15
- function createSimpleGenericTypeAnnotation(name, nodeForLoc) {
16
- return {
17
- type: 'GenericTypeAnnotation',
18
- id: {
19
- type: 'Identifier',
20
- name,
21
- optional: false,
22
- typeAnnotation: null,
23
- loc: nodeForLoc.loc,
24
- range: nodeForLoc.range,
25
- parent: EMPTY_PARENT
26
- },
27
- typeParameters: null,
28
- loc: nodeForLoc.loc,
29
- range: nodeForLoc.range,
30
- parent: nodeForLoc.parent
31
- };
32
- }
33
-
34
- function createAnyTypeAnnotation(node) {
35
- return {
36
- type: 'AnyTypeAnnotation',
37
- loc: node.loc,
38
- range: node.range,
39
- parent: node.parent
40
- };
41
- }
42
-
43
- function declareVariableDeclarator(id, node) {
44
- return {
45
- type: 'VariableDeclarator',
46
- id,
47
- init: null,
48
- loc: node.loc,
49
- range: node.range,
50
- parent: EMPTY_PARENT
51
- };
52
- }
53
-
54
- function mapDeclareEnum(node) {
55
- const id = nodeWith(node.id, {
56
- typeAnnotation: {
57
- type: 'TypeAnnotation',
58
- typeAnnotation: createAnyTypeAnnotation(node.body),
59
- loc: node.body.loc,
60
- range: node.body.range,
61
- parent: EMPTY_PARENT
62
- }
63
- });
64
- return {
65
- type: 'DeclareVariable',
66
- kind: 'const',
67
- declarations: [declareVariableDeclarator(id, node)],
68
- implicitDeclare: false,
69
- loc: node.loc,
70
- range: node.range,
71
- parent: node.parent
72
- };
73
- }
74
-
75
- function mapDeclareNamespace(node) {
76
- const id = nodeWith(node.id, {
77
- typeAnnotation: {
78
- type: 'TypeAnnotation',
79
- typeAnnotation: createAnyTypeAnnotation(node.body),
80
- loc: node.body.loc,
81
- range: node.body.range,
82
- parent: EMPTY_PARENT
83
- }
84
- });
85
- return {
86
- type: 'DeclareVariable',
87
- kind: 'const',
88
- declarations: [declareVariableDeclarator(id, node)],
89
- implicitDeclare: false,
90
- loc: node.loc,
91
- range: node.range,
92
- parent: node.parent
93
- };
94
- }
95
-
96
- function mapFunction(node) {
97
- if (node.params.length !== 0 && node.params[0].name === 'this') {
98
- return nodeWith(node, {
99
- params: node.params.slice(1)
100
- });
101
- }
102
-
103
- return node;
104
- }
105
-
106
- function mapQualifiedTypeofIdentifier(node) {
107
- return {
108
- type: 'QualifiedTypeIdentifier',
109
- qualification: node.qualification.type === 'QualifiedTypeofIdentifier' ? mapQualifiedTypeofIdentifier(node.qualification) : node.qualification,
110
- id: node.id,
111
- loc: node.loc,
112
- range: node.range,
113
- parent: node.parent
114
- };
115
- }
116
-
117
- function transformProgram(program, _options) {
118
- return _SimpleTransform.SimpleTransform.transformProgram(program, {
119
- transform(node) {
120
- switch (node.type) {
121
- case 'SymbolTypeAnnotation':
122
- {
123
- return createSimpleGenericTypeAnnotation('symbol', node);
124
- }
125
-
126
- case 'BigIntTypeAnnotation':
127
- {
128
- return createSimpleGenericTypeAnnotation('bigint', node);
129
- }
130
-
131
- case 'ObjectTypeAnnotation':
132
- {
133
- const shouldStrip = node.properties.some(prop => prop.type === 'ObjectTypeMappedTypeProperty');
134
-
135
- if (shouldStrip) {
136
- return createAnyTypeAnnotation(node);
137
- }
138
-
139
- return node;
140
- }
141
-
142
- case 'ObjectTypeMappedTypeProperty':
143
- {
144
- throw (0, _createSyntaxError.createSyntaxError)(node, `Invalid AST structure, ObjectTypeMappedTypeProperty found outside of an ObjectTypeAnnotation`);
145
- }
146
-
147
- case 'IndexedAccessType':
148
- case 'OptionalIndexedAccessType':
149
- case 'KeyofTypeAnnotation':
150
- case 'ConditionalTypeAnnotation':
151
- case 'InferTypeAnnotation':
152
- case 'TupleTypeLabeledElement':
153
- case 'TupleTypeSpreadElement':
154
- case 'ComponentTypeAnnotation':
155
- case 'HookTypeAnnotation':
156
- case 'TypeOperator':
157
- case 'TypePredicate':
158
- {
159
- return createAnyTypeAnnotation(node);
160
- }
161
-
162
- case 'QualifiedTypeofIdentifier':
163
- {
164
- return mapQualifiedTypeofIdentifier(node);
165
- }
166
-
167
- case 'DeclareEnum':
168
- {
169
- return mapDeclareEnum(node);
170
- }
171
-
172
- case 'DeclareNamespace':
173
- {
174
- return mapDeclareNamespace(node);
175
- }
176
-
177
- case 'FunctionDeclaration':
178
- case 'FunctionExpression':
179
- {
180
- return mapFunction(node);
181
- }
182
-
183
- default:
184
- {
185
- return node;
186
- }
187
- }
188
- }
189
-
190
- });
191
- }