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,89 +0,0 @@
1
- 'use strict';
2
-
3
- function isBlockComment(comment) {
4
- return comment.type === 'Block' || comment.type === 'CommentBlock' || comment.type === 'MultiLine';
5
- }
6
-
7
- function isLineComment(comment) {
8
- return comment.type === 'Line' || comment.type === 'CommentLine' || comment.type === 'SingleLine' || comment.type === 'HashbangComment' || comment.type === 'HTMLOpen' || comment.type === 'HTMLClose';
9
- }
10
-
11
- function isCallExpression(node) {
12
- return node && (node.type === 'CallExpression' || node.type === 'OptionalCallExpression');
13
- }
14
-
15
- function isMemberExpression(node) {
16
- return node && (node.type === 'MemberExpression' || node.type === 'OptionalMemberExpression');
17
- }
18
-
19
- const functionParametersCache = new WeakMap();
20
-
21
- function getFunctionParameters(node) {
22
- if (functionParametersCache.has(node)) {
23
- return functionParametersCache.get(node);
24
- }
25
-
26
- const parameters = [];
27
-
28
- if (node.this) {
29
- parameters.push(node.this);
30
- }
31
-
32
- if (Array.isArray(node.parameters)) {
33
- parameters.push(...node.parameters);
34
- } else if (Array.isArray(node.params)) {
35
- parameters.push(...node.params);
36
- }
37
-
38
- if (node.rest) {
39
- parameters.push(node.rest);
40
- }
41
-
42
- functionParametersCache.set(node, parameters);
43
- return parameters;
44
- }
45
-
46
- const callArgumentsCache = new WeakMap();
47
-
48
- function getCallArguments(node) {
49
- if (callArgumentsCache.has(node)) {
50
- return callArgumentsCache.get(node);
51
- }
52
-
53
- let args = node.arguments;
54
-
55
- if (node.type === 'ImportExpression') {
56
- args = [node.source];
57
-
58
- if (node.attributes) {
59
- args.push(node.attributes);
60
- }
61
- }
62
-
63
- callArgumentsCache.set(node, args);
64
- return args;
65
- }
66
-
67
- function isPrettierIgnoreComment(comment) {
68
- return comment.value.trim() === 'prettier-ignore' && !comment.unignore;
69
- }
70
-
71
- function isCallLikeExpression(node) {
72
- return isCallExpression(node) || node.type === 'NewExpression' || node.type === 'ImportExpression';
73
- }
74
-
75
- function isObjectProperty(node) {
76
- return node && (node.type === 'ObjectProperty' || node.type === 'Property' && !node.method && node.kind === 'init');
77
- }
78
-
79
- module.exports = {
80
- getFunctionParameters,
81
- getCallArguments,
82
- isBlockComment,
83
- isCallLikeExpression,
84
- isLineComment,
85
- isPrettierIgnoreComment,
86
- isCallExpression,
87
- isMemberExpression,
88
- isObjectProperty
89
- };
@@ -1,374 +0,0 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
-
5
- const {
6
- hasNewline,
7
- addLeadingComment,
8
- addDanglingComment,
9
- addTrailingComment
10
- } = require('../common/util.js');
11
-
12
- const childNodesCache = new WeakMap();
13
-
14
- function getSortedChildNodes(node, options, resultArray) {
15
- if (!node) {
16
- return;
17
- }
18
-
19
- const {
20
- printer,
21
- locStart,
22
- locEnd
23
- } = options;
24
-
25
- if (resultArray) {
26
- if (printer.canAttachComment && printer.canAttachComment(node)) {
27
- let i;
28
-
29
- for (i = resultArray.length - 1; i >= 0; --i) {
30
- if (locStart(resultArray[i]) <= locStart(node) && locEnd(resultArray[i]) <= locEnd(node)) {
31
- break;
32
- }
33
- }
34
-
35
- resultArray.splice(i + 1, 0, node);
36
- return;
37
- }
38
- } else if (childNodesCache.has(node)) {
39
- return childNodesCache.get(node);
40
- }
41
-
42
- const childNodes = printer.getCommentChildNodes && printer.getCommentChildNodes(node, options) || typeof node === 'object' && Object.entries(node).filter(([key]) => key !== 'enclosingNode' && key !== 'precedingNode' && key !== 'followingNode' && key !== 'tokens' && key !== 'comments' && key !== 'parent').map(([, value]) => value);
43
-
44
- if (!childNodes) {
45
- return;
46
- }
47
-
48
- if (!resultArray) {
49
- resultArray = [];
50
- childNodesCache.set(node, resultArray);
51
- }
52
-
53
- for (const childNode of childNodes) {
54
- getSortedChildNodes(childNode, options, resultArray);
55
- }
56
-
57
- return resultArray;
58
- }
59
-
60
- function decorateComment(node, comment, options, enclosingNode) {
61
- const {
62
- locStart,
63
- locEnd
64
- } = options;
65
- const commentStart = locStart(comment);
66
- const commentEnd = locEnd(comment);
67
- const childNodes = getSortedChildNodes(node, options);
68
- let precedingNode;
69
- let followingNode;
70
- let left = 0;
71
- let right = childNodes.length;
72
-
73
- while (left < right) {
74
- const middle = left + right >> 1;
75
- const child = childNodes[middle];
76
- const start = locStart(child);
77
- const end = locEnd(child);
78
-
79
- if (start <= commentStart && commentEnd <= end) {
80
- return decorateComment(child, comment, options, child);
81
- }
82
-
83
- if (end <= commentStart) {
84
- precedingNode = child;
85
- left = middle + 1;
86
- continue;
87
- }
88
-
89
- if (commentEnd <= start) {
90
- followingNode = child;
91
- right = middle;
92
- continue;
93
- }
94
-
95
- throw new Error('Comment location overlaps with node location');
96
- }
97
-
98
- if (enclosingNode && enclosingNode.type === 'TemplateLiteral') {
99
- const {
100
- quasis
101
- } = enclosingNode;
102
- const commentIndex = findExpressionIndexForComment(quasis, comment, options);
103
-
104
- if (precedingNode && findExpressionIndexForComment(quasis, precedingNode, options) !== commentIndex) {
105
- precedingNode = null;
106
- }
107
-
108
- if (followingNode && findExpressionIndexForComment(quasis, followingNode, options) !== commentIndex) {
109
- followingNode = null;
110
- }
111
- }
112
-
113
- return {
114
- enclosingNode,
115
- precedingNode,
116
- followingNode
117
- };
118
- }
119
-
120
- const returnFalse = () => false;
121
-
122
- function attach(comments, ast, text, options) {
123
- if (!Array.isArray(comments)) {
124
- return;
125
- }
126
-
127
- const tiesToBreak = [];
128
- const {
129
- locStart,
130
- locEnd,
131
- printer: {
132
- handleComments = {}
133
- }
134
- } = options;
135
- const {
136
- avoidAstMutation,
137
- ownLine: handleOwnLineComment = returnFalse,
138
- endOfLine: handleEndOfLineComment = returnFalse,
139
- remaining: handleRemainingComment = returnFalse
140
- } = handleComments;
141
- const decoratedComments = comments.map((comment, index) => ({ ...decorateComment(ast, comment, options),
142
- comment,
143
- text,
144
- options,
145
- ast,
146
- isLastComment: comments.length - 1 === index
147
- }));
148
-
149
- for (const [index, context] of decoratedComments.entries()) {
150
- const {
151
- comment,
152
- precedingNode,
153
- enclosingNode,
154
- followingNode,
155
- text,
156
- options,
157
- ast,
158
- isLastComment
159
- } = context;
160
-
161
- if (options.parser === 'json' || options.parser === 'json5' || options.parser === '__js_expression' || options.parser === '__vue_expression') {
162
- if (locStart(comment) - locStart(ast) <= 0) {
163
- addLeadingComment(ast, comment);
164
- continue;
165
- }
166
-
167
- if (locEnd(comment) - locEnd(ast) >= 0) {
168
- addTrailingComment(ast, comment);
169
- continue;
170
- }
171
- }
172
-
173
- let args;
174
-
175
- if (avoidAstMutation) {
176
- args = [context];
177
- } else {
178
- comment.enclosingNode = enclosingNode;
179
- comment.precedingNode = precedingNode;
180
- comment.followingNode = followingNode;
181
- args = [comment, text, options, ast, isLastComment];
182
- }
183
-
184
- if (isOwnLineComment(text, options, decoratedComments, index)) {
185
- comment.placement = 'ownLine';
186
-
187
- if (handleOwnLineComment(...args)) {} else if (followingNode) {
188
- addLeadingComment(followingNode, comment);
189
- } else if (precedingNode) {
190
- addTrailingComment(precedingNode, comment);
191
- } else if (enclosingNode) {
192
- addDanglingComment(enclosingNode, comment);
193
- } else {
194
- addDanglingComment(ast, comment);
195
- }
196
- } else if (isEndOfLineComment(text, options, decoratedComments, index)) {
197
- comment.placement = 'endOfLine';
198
-
199
- if (handleEndOfLineComment(...args)) {} else if (precedingNode) {
200
- addTrailingComment(precedingNode, comment);
201
- } else if (followingNode) {
202
- addLeadingComment(followingNode, comment);
203
- } else if (enclosingNode) {
204
- addDanglingComment(enclosingNode, comment);
205
- } else {
206
- addDanglingComment(ast, comment);
207
- }
208
- } else {
209
- comment.placement = 'remaining';
210
-
211
- if (handleRemainingComment(...args)) {} else if (precedingNode && followingNode) {
212
- const tieCount = tiesToBreak.length;
213
-
214
- if (tieCount > 0) {
215
- const lastTie = tiesToBreak[tieCount - 1];
216
-
217
- if (lastTie.followingNode !== followingNode) {
218
- breakTies(tiesToBreak, text, options);
219
- }
220
- }
221
-
222
- tiesToBreak.push(context);
223
- } else if (precedingNode) {
224
- addTrailingComment(precedingNode, comment);
225
- } else if (followingNode) {
226
- addLeadingComment(followingNode, comment);
227
- } else if (enclosingNode) {
228
- addDanglingComment(enclosingNode, comment);
229
- } else {
230
- addDanglingComment(ast, comment);
231
- }
232
- }
233
- }
234
-
235
- breakTies(tiesToBreak, text, options);
236
-
237
- if (!avoidAstMutation) {
238
- for (const comment of comments) {
239
- delete comment.precedingNode;
240
- delete comment.enclosingNode;
241
- delete comment.followingNode;
242
- }
243
- }
244
- }
245
-
246
- const isAllEmptyAndNoLineBreak = text => !/[\S\n\u2028\u2029]/.test(text);
247
-
248
- function isOwnLineComment(text, options, decoratedComments, commentIndex) {
249
- const {
250
- comment,
251
- precedingNode
252
- } = decoratedComments[commentIndex];
253
- const {
254
- locStart,
255
- locEnd
256
- } = options;
257
- let start = locStart(comment);
258
-
259
- if (precedingNode) {
260
- for (let index = commentIndex - 1; index >= 0; index--) {
261
- const {
262
- comment,
263
- precedingNode: currentCommentPrecedingNode
264
- } = decoratedComments[index];
265
-
266
- if (currentCommentPrecedingNode !== precedingNode || !isAllEmptyAndNoLineBreak(text.slice(locEnd(comment), start))) {
267
- break;
268
- }
269
-
270
- start = locStart(comment);
271
- }
272
- }
273
-
274
- return hasNewline(text, start, {
275
- backwards: true
276
- });
277
- }
278
-
279
- function isEndOfLineComment(text, options, decoratedComments, commentIndex) {
280
- const {
281
- comment,
282
- followingNode
283
- } = decoratedComments[commentIndex];
284
- const {
285
- locStart,
286
- locEnd
287
- } = options;
288
- let end = locEnd(comment);
289
-
290
- if (followingNode) {
291
- for (let index = commentIndex + 1; index < decoratedComments.length; index++) {
292
- const {
293
- comment,
294
- followingNode: currentCommentFollowingNode
295
- } = decoratedComments[index];
296
-
297
- if (currentCommentFollowingNode !== followingNode || !isAllEmptyAndNoLineBreak(text.slice(end, locStart(comment)))) {
298
- break;
299
- }
300
-
301
- end = locEnd(comment);
302
- }
303
- }
304
-
305
- return hasNewline(text, end);
306
- }
307
-
308
- function breakTies(tiesToBreak, text, options) {
309
- const tieCount = tiesToBreak.length;
310
-
311
- if (tieCount === 0) {
312
- return;
313
- }
314
-
315
- const {
316
- precedingNode,
317
- followingNode,
318
- enclosingNode
319
- } = tiesToBreak[0];
320
- const gapRegExp = options.printer.getGapRegex && options.printer.getGapRegex(enclosingNode) || /^[\s(]*$/;
321
- let gapEndPos = options.locStart(followingNode);
322
- let indexOfFirstLeadingComment;
323
-
324
- for (indexOfFirstLeadingComment = tieCount; indexOfFirstLeadingComment > 0; --indexOfFirstLeadingComment) {
325
- const {
326
- comment,
327
- precedingNode: currentCommentPrecedingNode,
328
- followingNode: currentCommentFollowingNode
329
- } = tiesToBreak[indexOfFirstLeadingComment - 1];
330
- assert.strictEqual(currentCommentPrecedingNode, precedingNode);
331
- assert.strictEqual(currentCommentFollowingNode, followingNode);
332
- const gap = text.slice(options.locEnd(comment), gapEndPos);
333
-
334
- if (gapRegExp.test(gap)) {
335
- gapEndPos = options.locStart(comment);
336
- } else {
337
- break;
338
- }
339
- }
340
-
341
- for (const [i, {
342
- comment
343
- }] of tiesToBreak.entries()) {
344
- if (i < indexOfFirstLeadingComment) {
345
- addTrailingComment(precedingNode, comment);
346
- } else {
347
- addLeadingComment(followingNode, comment);
348
- }
349
- }
350
-
351
- for (const node of [precedingNode, followingNode]) {
352
- if (node.comments && node.comments.length > 1) {
353
- node.comments.sort((a, b) => options.locStart(a) - options.locStart(b));
354
- }
355
- }
356
-
357
- tiesToBreak.length = 0;
358
- }
359
-
360
- function findExpressionIndexForComment(quasis, comment, options) {
361
- const startPos = options.locStart(comment) - 1;
362
-
363
- for (let i = 1; i < quasis.length; ++i) {
364
- if (startPos < options.locStart(quasis[i])) {
365
- return i - 1;
366
- }
367
- }
368
-
369
- return 0;
370
- }
371
-
372
- module.exports = {
373
- attach
374
- };
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- const getLast = arr => arr[arr.length - 1];
4
-
5
- module.exports = getLast;
@@ -1 +0,0 @@
1
- 'use strict';
@@ -1,90 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.SimpleTraverserSkip = exports.SimpleTraverserBreak = exports.SimpleTraverser = void 0;
7
-
8
- var _getVisitorKeys = require("./getVisitorKeys");
9
-
10
- const SimpleTraverserSkip = new Error();
11
- exports.SimpleTraverserSkip = SimpleTraverserSkip;
12
- const SimpleTraverserBreak = new Error();
13
- exports.SimpleTraverserBreak = SimpleTraverserBreak;
14
-
15
- class SimpleTraverser {
16
- traverse(node, options) {
17
- try {
18
- this._traverse(node, null, options);
19
- } catch (ex) {
20
- if (ex === SimpleTraverserBreak) {
21
- return;
22
- }
23
-
24
- throw ex;
25
- }
26
- }
27
-
28
- _traverse(node, parent, options) {
29
- if (!(0, _getVisitorKeys.isNode)(node)) {
30
- return;
31
- }
32
-
33
- try {
34
- options.enter(node, parent);
35
- } catch (ex) {
36
- if (ex === SimpleTraverserSkip) {
37
- return;
38
- }
39
-
40
- this._setErrorContext(ex, node);
41
-
42
- throw ex;
43
- }
44
-
45
- const keys = (0, _getVisitorKeys.getVisitorKeys)(node, options.visitorKeys);
46
-
47
- for (const key of keys) {
48
- const lookupKey = key;
49
- const childAny = node[lookupKey];
50
- const child = childAny;
51
-
52
- if (Array.isArray(child)) {
53
- for (let j = 0; j < child.length; ++j) {
54
- this._traverse(child[j], node, options);
55
- }
56
- } else {
57
- this._traverse(child, node, options);
58
- }
59
- }
60
-
61
- try {
62
- options.leave(node, parent);
63
- } catch (ex) {
64
- if (ex === SimpleTraverserSkip) {
65
- return;
66
- }
67
-
68
- this._setErrorContext(ex, node);
69
-
70
- throw ex;
71
- }
72
- }
73
-
74
- _setErrorContext(ex, node) {
75
- ex.currentNode = {
76
- type: node.type,
77
- range: node.range,
78
- loc: node.loc
79
- };
80
- }
81
-
82
- static traverse(node, options) {
83
- new SimpleTraverser().traverse(node, options);
84
- }
85
-
86
- }
87
-
88
- exports.SimpleTraverser = SimpleTraverser;
89
- SimpleTraverser.Break = SimpleTraverserBreak;
90
- SimpleTraverser.Skip = SimpleTraverserSkip;
@@ -1,29 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getVisitorKeys = getVisitorKeys;
7
- exports.isNode = isNode;
8
-
9
- var _ESTreeVisitorKeys = _interopRequireDefault(require("../generated/ESTreeVisitorKeys"));
10
-
11
- function _interopRequireDefault(obj) {
12
- return obj && obj.__esModule ? obj : {
13
- default: obj
14
- };
15
- }
16
-
17
- function isNode(thing) {
18
- return typeof thing === 'object' && thing != null && typeof thing.type === 'string';
19
- }
20
-
21
- function getVisitorKeys(node, visitorKeys) {
22
- const keys = (visitorKeys != null ? visitorKeys : _ESTreeVisitorKeys.default)[node.type];
23
-
24
- if (keys == null) {
25
- throw new Error(`No visitor keys found for node type "${node.type}".`);
26
- }
27
-
28
- return keys;
29
- }