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