|
6 | 6 |
|
7 | 7 | // Syntax: https://developer.mozilla.org/en/SpiderMonkey/Parser_API |
8 | 8 |
|
9 | | -const util = require("util"); |
10 | 9 | const acorn = require("acorn-dynamic-import").default; |
11 | 10 | const Tapable = require("tapable"); |
12 | 11 | const json5 = require("json5"); |
13 | 12 | const BasicEvaluatedExpression = require("./BasicEvaluatedExpression"); |
| 13 | +const StackedSetMap = require("./util/StackedSetMap"); |
14 | 14 |
|
15 | 15 | function joinRanges(startRange, endRange) { |
16 | 16 | if(!endRange) return startRange; |
@@ -38,77 +38,6 @@ const POSSIBLE_AST_OPTIONS = [{ |
38 | 38 | } |
39 | 39 | }]; |
40 | 40 |
|
41 | | -class StackedSetMap { |
42 | | - constructor(defaultValue, parentStack) { |
43 | | - this.defaultValue = defaultValue; |
44 | | - this.stack = parentStack === undefined ? [] : parentStack.slice(); |
45 | | - this.map = new Map(); |
46 | | - this.stack.push(this.map); |
47 | | - } |
48 | | - |
49 | | - add(item) { |
50 | | - this.map.set(item, true); |
51 | | - } |
52 | | - |
53 | | - set(item, value) { |
54 | | - this.map.set(item, value); |
55 | | - } |
56 | | - |
57 | | - delete(item) { |
58 | | - this.map.set(item, false); |
59 | | - } |
60 | | - |
61 | | - has(item) { |
62 | | - return this.get(item, false); |
63 | | - } |
64 | | - |
65 | | - get(item) { |
66 | | - const topValue = this.map.get(item); |
67 | | - if(typeof topValue !== "undefined") |
68 | | - return topValue; |
69 | | - for(var i = this.stack.length - 2; i >= 0; i--) { |
70 | | - const value = this.stack[i].get(item); |
71 | | - if(typeof value !== "undefined") { |
72 | | - this.map.set(item, value); |
73 | | - return value; |
74 | | - } |
75 | | - } |
76 | | - this.map.set(item, this.defaultValue); |
77 | | - return this.defaultValue; |
78 | | - } |
79 | | - |
80 | | - _compress() { |
81 | | - this.map = new Map(); |
82 | | - for(const data of this.stack) { |
83 | | - for(const pair of data) { |
84 | | - this.map.set(pair[0], pair[1]); |
85 | | - } |
86 | | - } |
87 | | - this.stack = [this.map]; |
88 | | - } |
89 | | - |
90 | | - asSet() { |
91 | | - this._compress(); |
92 | | - return new Set(Array.from(this.map.entries()).filter(pair => pair[1]).map(pair => pair[0])); |
93 | | - } |
94 | | - |
95 | | - createChild() { |
96 | | - return new StackedSetMap(this.defaultValue, this.stack); |
97 | | - } |
98 | | - |
99 | | - get length() { |
100 | | - throw new Error("Parser.definitions is no longer an Array"); |
101 | | - } |
102 | | - |
103 | | - set length(value) { |
104 | | - throw new Error("Parser.definitions is no longer an Array"); |
105 | | - } |
106 | | -} |
107 | | - |
108 | | -StackedSetMap.prototype.push = util.deprecate(function(item) { |
109 | | - this.add(item); |
110 | | -}, "Parser.definitions is no longer an Array: Use add instead."); |
111 | | - |
112 | 41 | class TrackingSet { |
113 | 42 | constructor(set) { |
114 | 43 | this.set = set; |
|
0 commit comments