@saasmakers/eslint 0.2.5 → 0.2.7

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 (65) hide show
  1. package/dist/chunks/formatters.cjs +248 -0
  2. package/dist/chunks/formatters.mjs +246 -0
  3. package/dist/chunks/import.cjs +53 -0
  4. package/dist/chunks/import.mjs +51 -0
  5. package/dist/chunks/index.cjs +120 -0
  6. package/dist/chunks/index.mjs +101 -0
  7. package/dist/chunks/index2.cjs +880 -0
  8. package/dist/chunks/index2.mjs +868 -0
  9. package/dist/chunks/index3.cjs +982 -0
  10. package/dist/chunks/index3.mjs +979 -0
  11. package/dist/chunks/index4.cjs +12099 -0
  12. package/dist/chunks/index4.mjs +12077 -0
  13. package/dist/chunks/jsdoc.cjs +38398 -0
  14. package/dist/chunks/jsdoc.mjs +38391 -0
  15. package/dist/chunks/regexp.cjs +18518 -0
  16. package/dist/chunks/regexp.mjs +18511 -0
  17. package/dist/chunks/stylistic.cjs +23935 -0
  18. package/dist/chunks/stylistic.mjs +23932 -0
  19. package/dist/chunks/typescript.cjs +56168 -0
  20. package/dist/chunks/typescript.mjs +56154 -0
  21. package/dist/chunks/unicorn.cjs +82775 -0
  22. package/dist/chunks/unicorn.mjs +82764 -0
  23. package/dist/chunks/vue.cjs +96233 -0
  24. package/dist/chunks/vue.mjs +96220 -0
  25. package/dist/eslint.config.cjs +19 -10874
  26. package/dist/eslint.config.d.cts +3900 -18
  27. package/dist/eslint.config.d.mts +3900 -18
  28. package/dist/eslint.config.d.ts +3900 -18
  29. package/dist/eslint.config.mjs +18 -10852
  30. package/dist/index.cjs +1 -1
  31. package/dist/index.d.cts +6 -2
  32. package/dist/index.d.mts +6 -2
  33. package/dist/index.d.ts +6 -2
  34. package/dist/index.mjs +1 -1
  35. package/dist/shared/eslint.05nu4VbT.mjs +9 -0
  36. package/dist/shared/eslint.07qTxm9w.mjs +3352 -0
  37. package/dist/shared/eslint.6MAvpL4q.cjs +2141 -0
  38. package/dist/shared/{eslint.CohBuu1-.mjs → eslint.B3ywQ3NK.mjs} +157 -331
  39. package/dist/shared/eslint.BGpVg2tt.cjs +13 -0
  40. package/dist/shared/eslint.BL4sYiVQ.cjs +820 -0
  41. package/dist/shared/eslint.BOOP2x9L.cjs +67 -0
  42. package/dist/shared/eslint.Bf7aat-e.mjs +10 -0
  43. package/dist/shared/eslint.Bh1W2iVQ.cjs +37181 -0
  44. package/dist/shared/eslint.Bl69eiyD.cjs +7073 -0
  45. package/dist/shared/eslint.BtkqW7nC.mjs +818 -0
  46. package/dist/shared/eslint.C12_M0Cw.cjs +9 -0
  47. package/dist/shared/eslint.CMfxPSSy.cjs +14 -0
  48. package/dist/shared/eslint.COweQ1RR.mjs +5 -0
  49. package/dist/shared/eslint.CUi9znUC.mjs +13 -0
  50. package/dist/shared/eslint.Cg6Ty7p7.mjs +2699 -0
  51. package/dist/shared/eslint.CxAZpd0w.cjs +3365 -0
  52. package/dist/shared/eslint.CyJA7jO6.cjs +3813 -0
  53. package/dist/shared/eslint.DDD2xc4l.cjs +25 -0
  54. package/dist/shared/eslint.DI7QBrVD.mjs +6 -0
  55. package/dist/shared/eslint.DUamuDzp.cjs +7 -0
  56. package/dist/shared/eslint.DV_fpPxQ.mjs +3805 -0
  57. package/dist/shared/{eslint.DhFjwkxh.cjs → eslint.Dhg0jKDi.cjs} +167 -330
  58. package/dist/shared/eslint.Difk5awg.mjs +2139 -0
  59. package/dist/shared/eslint.Dlgr3LGM.mjs +7070 -0
  60. package/dist/shared/eslint.DoYGbUIG.cjs +2724 -0
  61. package/dist/shared/eslint.Dprsk9zl.mjs +65 -0
  62. package/dist/shared/eslint.DuJbNenz.mjs +37140 -0
  63. package/dist/shared/eslint.MfgVmFE7.cjs +3054 -0
  64. package/dist/shared/eslint.W7RM7aEw.mjs +3052 -0
  65. package/package.json +2 -1
@@ -0,0 +1,818 @@
1
+ var estraverse = {};
2
+
3
+ /*
4
+ Copyright (C) 2012-2013 Yusuke Suzuki <utatane.tea@gmail.com>
5
+ Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
6
+
7
+ Redistribution and use in source and binary forms, with or without
8
+ modification, are permitted provided that the following conditions are met:
9
+
10
+ * Redistributions of source code must retain the above copyright
11
+ notice, this list of conditions and the following disclaimer.
12
+ * Redistributions in binary form must reproduce the above copyright
13
+ notice, this list of conditions and the following disclaimer in the
14
+ documentation and/or other materials provided with the distribution.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ */
27
+
28
+ var hasRequiredEstraverse;
29
+
30
+ function requireEstraverse () {
31
+ if (hasRequiredEstraverse) return estraverse;
32
+ hasRequiredEstraverse = 1;
33
+ (function (exports$1) {
34
+ /*jslint vars:false, bitwise:true*/
35
+ /*jshint indent:4*/
36
+ /*global exports:true*/
37
+ (function clone(exports$1) {
38
+
39
+ var Syntax,
40
+ VisitorOption,
41
+ VisitorKeys,
42
+ BREAK,
43
+ SKIP,
44
+ REMOVE;
45
+
46
+ function deepCopy(obj) {
47
+ var ret = {}, key, val;
48
+ for (key in obj) {
49
+ if (obj.hasOwnProperty(key)) {
50
+ val = obj[key];
51
+ if (typeof val === 'object' && val !== null) {
52
+ ret[key] = deepCopy(val);
53
+ } else {
54
+ ret[key] = val;
55
+ }
56
+ }
57
+ }
58
+ return ret;
59
+ }
60
+
61
+ // based on LLVM libc++ upper_bound / lower_bound
62
+ // MIT License
63
+
64
+ function upperBound(array, func) {
65
+ var diff, len, i, current;
66
+
67
+ len = array.length;
68
+ i = 0;
69
+
70
+ while (len) {
71
+ diff = len >>> 1;
72
+ current = i + diff;
73
+ if (func(array[current])) {
74
+ len = diff;
75
+ } else {
76
+ i = current + 1;
77
+ len -= diff + 1;
78
+ }
79
+ }
80
+ return i;
81
+ }
82
+
83
+ Syntax = {
84
+ AssignmentExpression: 'AssignmentExpression',
85
+ AssignmentPattern: 'AssignmentPattern',
86
+ ArrayExpression: 'ArrayExpression',
87
+ ArrayPattern: 'ArrayPattern',
88
+ ArrowFunctionExpression: 'ArrowFunctionExpression',
89
+ AwaitExpression: 'AwaitExpression', // CAUTION: It's deferred to ES7.
90
+ BlockStatement: 'BlockStatement',
91
+ BinaryExpression: 'BinaryExpression',
92
+ BreakStatement: 'BreakStatement',
93
+ CallExpression: 'CallExpression',
94
+ CatchClause: 'CatchClause',
95
+ ChainExpression: 'ChainExpression',
96
+ ClassBody: 'ClassBody',
97
+ ClassDeclaration: 'ClassDeclaration',
98
+ ClassExpression: 'ClassExpression',
99
+ ComprehensionBlock: 'ComprehensionBlock', // CAUTION: It's deferred to ES7.
100
+ ComprehensionExpression: 'ComprehensionExpression', // CAUTION: It's deferred to ES7.
101
+ ConditionalExpression: 'ConditionalExpression',
102
+ ContinueStatement: 'ContinueStatement',
103
+ DebuggerStatement: 'DebuggerStatement',
104
+ DirectiveStatement: 'DirectiveStatement',
105
+ DoWhileStatement: 'DoWhileStatement',
106
+ EmptyStatement: 'EmptyStatement',
107
+ ExportAllDeclaration: 'ExportAllDeclaration',
108
+ ExportDefaultDeclaration: 'ExportDefaultDeclaration',
109
+ ExportNamedDeclaration: 'ExportNamedDeclaration',
110
+ ExportSpecifier: 'ExportSpecifier',
111
+ ExpressionStatement: 'ExpressionStatement',
112
+ ForStatement: 'ForStatement',
113
+ ForInStatement: 'ForInStatement',
114
+ ForOfStatement: 'ForOfStatement',
115
+ FunctionDeclaration: 'FunctionDeclaration',
116
+ FunctionExpression: 'FunctionExpression',
117
+ GeneratorExpression: 'GeneratorExpression', // CAUTION: It's deferred to ES7.
118
+ Identifier: 'Identifier',
119
+ IfStatement: 'IfStatement',
120
+ ImportExpression: 'ImportExpression',
121
+ ImportDeclaration: 'ImportDeclaration',
122
+ ImportDefaultSpecifier: 'ImportDefaultSpecifier',
123
+ ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
124
+ ImportSpecifier: 'ImportSpecifier',
125
+ Literal: 'Literal',
126
+ LabeledStatement: 'LabeledStatement',
127
+ LogicalExpression: 'LogicalExpression',
128
+ MemberExpression: 'MemberExpression',
129
+ MetaProperty: 'MetaProperty',
130
+ MethodDefinition: 'MethodDefinition',
131
+ ModuleSpecifier: 'ModuleSpecifier',
132
+ NewExpression: 'NewExpression',
133
+ ObjectExpression: 'ObjectExpression',
134
+ ObjectPattern: 'ObjectPattern',
135
+ PrivateIdentifier: 'PrivateIdentifier',
136
+ Program: 'Program',
137
+ Property: 'Property',
138
+ PropertyDefinition: 'PropertyDefinition',
139
+ RestElement: 'RestElement',
140
+ ReturnStatement: 'ReturnStatement',
141
+ SequenceExpression: 'SequenceExpression',
142
+ SpreadElement: 'SpreadElement',
143
+ Super: 'Super',
144
+ SwitchStatement: 'SwitchStatement',
145
+ SwitchCase: 'SwitchCase',
146
+ TaggedTemplateExpression: 'TaggedTemplateExpression',
147
+ TemplateElement: 'TemplateElement',
148
+ TemplateLiteral: 'TemplateLiteral',
149
+ ThisExpression: 'ThisExpression',
150
+ ThrowStatement: 'ThrowStatement',
151
+ TryStatement: 'TryStatement',
152
+ UnaryExpression: 'UnaryExpression',
153
+ UpdateExpression: 'UpdateExpression',
154
+ VariableDeclaration: 'VariableDeclaration',
155
+ VariableDeclarator: 'VariableDeclarator',
156
+ WhileStatement: 'WhileStatement',
157
+ WithStatement: 'WithStatement',
158
+ YieldExpression: 'YieldExpression'
159
+ };
160
+
161
+ VisitorKeys = {
162
+ AssignmentExpression: ['left', 'right'],
163
+ AssignmentPattern: ['left', 'right'],
164
+ ArrayExpression: ['elements'],
165
+ ArrayPattern: ['elements'],
166
+ ArrowFunctionExpression: ['params', 'body'],
167
+ AwaitExpression: ['argument'], // CAUTION: It's deferred to ES7.
168
+ BlockStatement: ['body'],
169
+ BinaryExpression: ['left', 'right'],
170
+ BreakStatement: ['label'],
171
+ CallExpression: ['callee', 'arguments'],
172
+ CatchClause: ['param', 'body'],
173
+ ChainExpression: ['expression'],
174
+ ClassBody: ['body'],
175
+ ClassDeclaration: ['id', 'superClass', 'body'],
176
+ ClassExpression: ['id', 'superClass', 'body'],
177
+ ComprehensionBlock: ['left', 'right'], // CAUTION: It's deferred to ES7.
178
+ ComprehensionExpression: ['blocks', 'filter', 'body'], // CAUTION: It's deferred to ES7.
179
+ ConditionalExpression: ['test', 'consequent', 'alternate'],
180
+ ContinueStatement: ['label'],
181
+ DebuggerStatement: [],
182
+ DirectiveStatement: [],
183
+ DoWhileStatement: ['body', 'test'],
184
+ EmptyStatement: [],
185
+ ExportAllDeclaration: ['source'],
186
+ ExportDefaultDeclaration: ['declaration'],
187
+ ExportNamedDeclaration: ['declaration', 'specifiers', 'source'],
188
+ ExportSpecifier: ['exported', 'local'],
189
+ ExpressionStatement: ['expression'],
190
+ ForStatement: ['init', 'test', 'update', 'body'],
191
+ ForInStatement: ['left', 'right', 'body'],
192
+ ForOfStatement: ['left', 'right', 'body'],
193
+ FunctionDeclaration: ['id', 'params', 'body'],
194
+ FunctionExpression: ['id', 'params', 'body'],
195
+ GeneratorExpression: ['blocks', 'filter', 'body'], // CAUTION: It's deferred to ES7.
196
+ Identifier: [],
197
+ IfStatement: ['test', 'consequent', 'alternate'],
198
+ ImportExpression: ['source'],
199
+ ImportDeclaration: ['specifiers', 'source'],
200
+ ImportDefaultSpecifier: ['local'],
201
+ ImportNamespaceSpecifier: ['local'],
202
+ ImportSpecifier: ['imported', 'local'],
203
+ Literal: [],
204
+ LabeledStatement: ['label', 'body'],
205
+ LogicalExpression: ['left', 'right'],
206
+ MemberExpression: ['object', 'property'],
207
+ MetaProperty: ['meta', 'property'],
208
+ MethodDefinition: ['key', 'value'],
209
+ ModuleSpecifier: [],
210
+ NewExpression: ['callee', 'arguments'],
211
+ ObjectExpression: ['properties'],
212
+ ObjectPattern: ['properties'],
213
+ PrivateIdentifier: [],
214
+ Program: ['body'],
215
+ Property: ['key', 'value'],
216
+ PropertyDefinition: ['key', 'value'],
217
+ RestElement: [ 'argument' ],
218
+ ReturnStatement: ['argument'],
219
+ SequenceExpression: ['expressions'],
220
+ SpreadElement: ['argument'],
221
+ Super: [],
222
+ SwitchStatement: ['discriminant', 'cases'],
223
+ SwitchCase: ['test', 'consequent'],
224
+ TaggedTemplateExpression: ['tag', 'quasi'],
225
+ TemplateElement: [],
226
+ TemplateLiteral: ['quasis', 'expressions'],
227
+ ThisExpression: [],
228
+ ThrowStatement: ['argument'],
229
+ TryStatement: ['block', 'handler', 'finalizer'],
230
+ UnaryExpression: ['argument'],
231
+ UpdateExpression: ['argument'],
232
+ VariableDeclaration: ['declarations'],
233
+ VariableDeclarator: ['id', 'init'],
234
+ WhileStatement: ['test', 'body'],
235
+ WithStatement: ['object', 'body'],
236
+ YieldExpression: ['argument']
237
+ };
238
+
239
+ // unique id
240
+ BREAK = {};
241
+ SKIP = {};
242
+ REMOVE = {};
243
+
244
+ VisitorOption = {
245
+ Break: BREAK,
246
+ Skip: SKIP,
247
+ Remove: REMOVE
248
+ };
249
+
250
+ function Reference(parent, key) {
251
+ this.parent = parent;
252
+ this.key = key;
253
+ }
254
+
255
+ Reference.prototype.replace = function replace(node) {
256
+ this.parent[this.key] = node;
257
+ };
258
+
259
+ Reference.prototype.remove = function remove() {
260
+ if (Array.isArray(this.parent)) {
261
+ this.parent.splice(this.key, 1);
262
+ return true;
263
+ } else {
264
+ this.replace(null);
265
+ return false;
266
+ }
267
+ };
268
+
269
+ function Element(node, path, wrap, ref) {
270
+ this.node = node;
271
+ this.path = path;
272
+ this.wrap = wrap;
273
+ this.ref = ref;
274
+ }
275
+
276
+ function Controller() { }
277
+
278
+ // API:
279
+ // return property path array from root to current node
280
+ Controller.prototype.path = function path() {
281
+ var i, iz, j, jz, result, element;
282
+
283
+ function addToPath(result, path) {
284
+ if (Array.isArray(path)) {
285
+ for (j = 0, jz = path.length; j < jz; ++j) {
286
+ result.push(path[j]);
287
+ }
288
+ } else {
289
+ result.push(path);
290
+ }
291
+ }
292
+
293
+ // root node
294
+ if (!this.__current.path) {
295
+ return null;
296
+ }
297
+
298
+ // first node is sentinel, second node is root element
299
+ result = [];
300
+ for (i = 2, iz = this.__leavelist.length; i < iz; ++i) {
301
+ element = this.__leavelist[i];
302
+ addToPath(result, element.path);
303
+ }
304
+ addToPath(result, this.__current.path);
305
+ return result;
306
+ };
307
+
308
+ // API:
309
+ // return type of current node
310
+ Controller.prototype.type = function () {
311
+ var node = this.current();
312
+ return node.type || this.__current.wrap;
313
+ };
314
+
315
+ // API:
316
+ // return array of parent elements
317
+ Controller.prototype.parents = function parents() {
318
+ var i, iz, result;
319
+
320
+ // first node is sentinel
321
+ result = [];
322
+ for (i = 1, iz = this.__leavelist.length; i < iz; ++i) {
323
+ result.push(this.__leavelist[i].node);
324
+ }
325
+
326
+ return result;
327
+ };
328
+
329
+ // API:
330
+ // return current node
331
+ Controller.prototype.current = function current() {
332
+ return this.__current.node;
333
+ };
334
+
335
+ Controller.prototype.__execute = function __execute(callback, element) {
336
+ var previous, result;
337
+
338
+ result = undefined;
339
+
340
+ previous = this.__current;
341
+ this.__current = element;
342
+ this.__state = null;
343
+ if (callback) {
344
+ result = callback.call(this, element.node, this.__leavelist[this.__leavelist.length - 1].node);
345
+ }
346
+ this.__current = previous;
347
+
348
+ return result;
349
+ };
350
+
351
+ // API:
352
+ // notify control skip / break
353
+ Controller.prototype.notify = function notify(flag) {
354
+ this.__state = flag;
355
+ };
356
+
357
+ // API:
358
+ // skip child nodes of current node
359
+ Controller.prototype.skip = function () {
360
+ this.notify(SKIP);
361
+ };
362
+
363
+ // API:
364
+ // break traversals
365
+ Controller.prototype['break'] = function () {
366
+ this.notify(BREAK);
367
+ };
368
+
369
+ // API:
370
+ // remove node
371
+ Controller.prototype.remove = function () {
372
+ this.notify(REMOVE);
373
+ };
374
+
375
+ Controller.prototype.__initialize = function(root, visitor) {
376
+ this.visitor = visitor;
377
+ this.root = root;
378
+ this.__worklist = [];
379
+ this.__leavelist = [];
380
+ this.__current = null;
381
+ this.__state = null;
382
+ this.__fallback = null;
383
+ if (visitor.fallback === 'iteration') {
384
+ this.__fallback = Object.keys;
385
+ } else if (typeof visitor.fallback === 'function') {
386
+ this.__fallback = visitor.fallback;
387
+ }
388
+
389
+ this.__keys = VisitorKeys;
390
+ if (visitor.keys) {
391
+ this.__keys = Object.assign(Object.create(this.__keys), visitor.keys);
392
+ }
393
+ };
394
+
395
+ function isNode(node) {
396
+ if (node == null) {
397
+ return false;
398
+ }
399
+ return typeof node === 'object' && typeof node.type === 'string';
400
+ }
401
+
402
+ function isProperty(nodeType, key) {
403
+ return (nodeType === Syntax.ObjectExpression || nodeType === Syntax.ObjectPattern) && 'properties' === key;
404
+ }
405
+
406
+ function candidateExistsInLeaveList(leavelist, candidate) {
407
+ for (var i = leavelist.length - 1; i >= 0; --i) {
408
+ if (leavelist[i].node === candidate) {
409
+ return true;
410
+ }
411
+ }
412
+ return false;
413
+ }
414
+
415
+ Controller.prototype.traverse = function traverse(root, visitor) {
416
+ var worklist,
417
+ leavelist,
418
+ element,
419
+ node,
420
+ nodeType,
421
+ ret,
422
+ key,
423
+ current,
424
+ current2,
425
+ candidates,
426
+ candidate,
427
+ sentinel;
428
+
429
+ this.__initialize(root, visitor);
430
+
431
+ sentinel = {};
432
+
433
+ // reference
434
+ worklist = this.__worklist;
435
+ leavelist = this.__leavelist;
436
+
437
+ // initialize
438
+ worklist.push(new Element(root, null, null, null));
439
+ leavelist.push(new Element(null, null, null, null));
440
+
441
+ while (worklist.length) {
442
+ element = worklist.pop();
443
+
444
+ if (element === sentinel) {
445
+ element = leavelist.pop();
446
+
447
+ ret = this.__execute(visitor.leave, element);
448
+
449
+ if (this.__state === BREAK || ret === BREAK) {
450
+ return;
451
+ }
452
+ continue;
453
+ }
454
+
455
+ if (element.node) {
456
+
457
+ ret = this.__execute(visitor.enter, element);
458
+
459
+ if (this.__state === BREAK || ret === BREAK) {
460
+ return;
461
+ }
462
+
463
+ worklist.push(sentinel);
464
+ leavelist.push(element);
465
+
466
+ if (this.__state === SKIP || ret === SKIP) {
467
+ continue;
468
+ }
469
+
470
+ node = element.node;
471
+ nodeType = node.type || element.wrap;
472
+ candidates = this.__keys[nodeType];
473
+ if (!candidates) {
474
+ if (this.__fallback) {
475
+ candidates = this.__fallback(node);
476
+ } else {
477
+ throw new Error('Unknown node type ' + nodeType + '.');
478
+ }
479
+ }
480
+
481
+ current = candidates.length;
482
+ while ((current -= 1) >= 0) {
483
+ key = candidates[current];
484
+ candidate = node[key];
485
+ if (!candidate) {
486
+ continue;
487
+ }
488
+
489
+ if (Array.isArray(candidate)) {
490
+ current2 = candidate.length;
491
+ while ((current2 -= 1) >= 0) {
492
+ if (!candidate[current2]) {
493
+ continue;
494
+ }
495
+
496
+ if (candidateExistsInLeaveList(leavelist, candidate[current2])) {
497
+ continue;
498
+ }
499
+
500
+ if (isProperty(nodeType, candidates[current])) {
501
+ element = new Element(candidate[current2], [key, current2], 'Property', null);
502
+ } else if (isNode(candidate[current2])) {
503
+ element = new Element(candidate[current2], [key, current2], null, null);
504
+ } else {
505
+ continue;
506
+ }
507
+ worklist.push(element);
508
+ }
509
+ } else if (isNode(candidate)) {
510
+ if (candidateExistsInLeaveList(leavelist, candidate)) {
511
+ continue;
512
+ }
513
+
514
+ worklist.push(new Element(candidate, key, null, null));
515
+ }
516
+ }
517
+ }
518
+ }
519
+ };
520
+
521
+ Controller.prototype.replace = function replace(root, visitor) {
522
+ var worklist,
523
+ leavelist,
524
+ node,
525
+ nodeType,
526
+ target,
527
+ element,
528
+ current,
529
+ current2,
530
+ candidates,
531
+ candidate,
532
+ sentinel,
533
+ outer,
534
+ key;
535
+
536
+ function removeElem(element) {
537
+ var i,
538
+ key,
539
+ nextElem,
540
+ parent;
541
+
542
+ if (element.ref.remove()) {
543
+ // When the reference is an element of an array.
544
+ key = element.ref.key;
545
+ parent = element.ref.parent;
546
+
547
+ // If removed from array, then decrease following items' keys.
548
+ i = worklist.length;
549
+ while (i--) {
550
+ nextElem = worklist[i];
551
+ if (nextElem.ref && nextElem.ref.parent === parent) {
552
+ if (nextElem.ref.key < key) {
553
+ break;
554
+ }
555
+ --nextElem.ref.key;
556
+ }
557
+ }
558
+ }
559
+ }
560
+
561
+ this.__initialize(root, visitor);
562
+
563
+ sentinel = {};
564
+
565
+ // reference
566
+ worklist = this.__worklist;
567
+ leavelist = this.__leavelist;
568
+
569
+ // initialize
570
+ outer = {
571
+ root: root
572
+ };
573
+ element = new Element(root, null, null, new Reference(outer, 'root'));
574
+ worklist.push(element);
575
+ leavelist.push(element);
576
+
577
+ while (worklist.length) {
578
+ element = worklist.pop();
579
+
580
+ if (element === sentinel) {
581
+ element = leavelist.pop();
582
+
583
+ target = this.__execute(visitor.leave, element);
584
+
585
+ // node may be replaced with null,
586
+ // so distinguish between undefined and null in this place
587
+ if (target !== undefined && target !== BREAK && target !== SKIP && target !== REMOVE) {
588
+ // replace
589
+ element.ref.replace(target);
590
+ }
591
+
592
+ if (this.__state === REMOVE || target === REMOVE) {
593
+ removeElem(element);
594
+ }
595
+
596
+ if (this.__state === BREAK || target === BREAK) {
597
+ return outer.root;
598
+ }
599
+ continue;
600
+ }
601
+
602
+ target = this.__execute(visitor.enter, element);
603
+
604
+ // node may be replaced with null,
605
+ // so distinguish between undefined and null in this place
606
+ if (target !== undefined && target !== BREAK && target !== SKIP && target !== REMOVE) {
607
+ // replace
608
+ element.ref.replace(target);
609
+ element.node = target;
610
+ }
611
+
612
+ if (this.__state === REMOVE || target === REMOVE) {
613
+ removeElem(element);
614
+ element.node = null;
615
+ }
616
+
617
+ if (this.__state === BREAK || target === BREAK) {
618
+ return outer.root;
619
+ }
620
+
621
+ // node may be null
622
+ node = element.node;
623
+ if (!node) {
624
+ continue;
625
+ }
626
+
627
+ worklist.push(sentinel);
628
+ leavelist.push(element);
629
+
630
+ if (this.__state === SKIP || target === SKIP) {
631
+ continue;
632
+ }
633
+
634
+ nodeType = node.type || element.wrap;
635
+ candidates = this.__keys[nodeType];
636
+ if (!candidates) {
637
+ if (this.__fallback) {
638
+ candidates = this.__fallback(node);
639
+ } else {
640
+ throw new Error('Unknown node type ' + nodeType + '.');
641
+ }
642
+ }
643
+
644
+ current = candidates.length;
645
+ while ((current -= 1) >= 0) {
646
+ key = candidates[current];
647
+ candidate = node[key];
648
+ if (!candidate) {
649
+ continue;
650
+ }
651
+
652
+ if (Array.isArray(candidate)) {
653
+ current2 = candidate.length;
654
+ while ((current2 -= 1) >= 0) {
655
+ if (!candidate[current2]) {
656
+ continue;
657
+ }
658
+ if (isProperty(nodeType, candidates[current])) {
659
+ element = new Element(candidate[current2], [key, current2], 'Property', new Reference(candidate, current2));
660
+ } else if (isNode(candidate[current2])) {
661
+ element = new Element(candidate[current2], [key, current2], null, new Reference(candidate, current2));
662
+ } else {
663
+ continue;
664
+ }
665
+ worklist.push(element);
666
+ }
667
+ } else if (isNode(candidate)) {
668
+ worklist.push(new Element(candidate, key, null, new Reference(node, key)));
669
+ }
670
+ }
671
+ }
672
+
673
+ return outer.root;
674
+ };
675
+
676
+ function traverse(root, visitor) {
677
+ var controller = new Controller();
678
+ return controller.traverse(root, visitor);
679
+ }
680
+
681
+ function replace(root, visitor) {
682
+ var controller = new Controller();
683
+ return controller.replace(root, visitor);
684
+ }
685
+
686
+ function extendCommentRange(comment, tokens) {
687
+ var target;
688
+
689
+ target = upperBound(tokens, function search(token) {
690
+ return token.range[0] > comment.range[0];
691
+ });
692
+
693
+ comment.extendedRange = [comment.range[0], comment.range[1]];
694
+
695
+ if (target !== tokens.length) {
696
+ comment.extendedRange[1] = tokens[target].range[0];
697
+ }
698
+
699
+ target -= 1;
700
+ if (target >= 0) {
701
+ comment.extendedRange[0] = tokens[target].range[1];
702
+ }
703
+
704
+ return comment;
705
+ }
706
+
707
+ function attachComments(tree, providedComments, tokens) {
708
+ // At first, we should calculate extended comment ranges.
709
+ var comments = [], comment, len, i, cursor;
710
+
711
+ if (!tree.range) {
712
+ throw new Error('attachComments needs range information');
713
+ }
714
+
715
+ // tokens array is empty, we attach comments to tree as 'leadingComments'
716
+ if (!tokens.length) {
717
+ if (providedComments.length) {
718
+ for (i = 0, len = providedComments.length; i < len; i += 1) {
719
+ comment = deepCopy(providedComments[i]);
720
+ comment.extendedRange = [0, tree.range[0]];
721
+ comments.push(comment);
722
+ }
723
+ tree.leadingComments = comments;
724
+ }
725
+ return tree;
726
+ }
727
+
728
+ for (i = 0, len = providedComments.length; i < len; i += 1) {
729
+ comments.push(extendCommentRange(deepCopy(providedComments[i]), tokens));
730
+ }
731
+
732
+ // This is based on John Freeman's implementation.
733
+ cursor = 0;
734
+ traverse(tree, {
735
+ enter: function (node) {
736
+ var comment;
737
+
738
+ while (cursor < comments.length) {
739
+ comment = comments[cursor];
740
+ if (comment.extendedRange[1] > node.range[0]) {
741
+ break;
742
+ }
743
+
744
+ if (comment.extendedRange[1] === node.range[0]) {
745
+ if (!node.leadingComments) {
746
+ node.leadingComments = [];
747
+ }
748
+ node.leadingComments.push(comment);
749
+ comments.splice(cursor, 1);
750
+ } else {
751
+ cursor += 1;
752
+ }
753
+ }
754
+
755
+ // already out of owned node
756
+ if (cursor === comments.length) {
757
+ return VisitorOption.Break;
758
+ }
759
+
760
+ if (comments[cursor].extendedRange[0] > node.range[1]) {
761
+ return VisitorOption.Skip;
762
+ }
763
+ }
764
+ });
765
+
766
+ cursor = 0;
767
+ traverse(tree, {
768
+ leave: function (node) {
769
+ var comment;
770
+
771
+ while (cursor < comments.length) {
772
+ comment = comments[cursor];
773
+ if (node.range[1] < comment.extendedRange[0]) {
774
+ break;
775
+ }
776
+
777
+ if (node.range[1] === comment.extendedRange[0]) {
778
+ if (!node.trailingComments) {
779
+ node.trailingComments = [];
780
+ }
781
+ node.trailingComments.push(comment);
782
+ comments.splice(cursor, 1);
783
+ } else {
784
+ cursor += 1;
785
+ }
786
+ }
787
+
788
+ // already out of owned node
789
+ if (cursor === comments.length) {
790
+ return VisitorOption.Break;
791
+ }
792
+
793
+ if (comments[cursor].extendedRange[0] > node.range[1]) {
794
+ return VisitorOption.Skip;
795
+ }
796
+ }
797
+ });
798
+
799
+ return tree;
800
+ }
801
+
802
+ exports$1.Syntax = Syntax;
803
+ exports$1.traverse = traverse;
804
+ exports$1.replace = replace;
805
+ exports$1.attachComments = attachComments;
806
+ exports$1.VisitorKeys = VisitorKeys;
807
+ exports$1.VisitorOption = VisitorOption;
808
+ exports$1.Controller = Controller;
809
+ exports$1.cloneEnvironment = function () { return clone({}); };
810
+
811
+ return exports$1;
812
+ }(exports$1));
813
+ /* vim: set sw=4 ts=4 et tw=80 : */
814
+ } (estraverse));
815
+ return estraverse;
816
+ }
817
+
818
+ export { requireEstraverse as r };