terser 5.12.1 → 5.13.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.
- package/CHANGELOG.md +6 -0
- package/dist/bundle.min.js +2312 -758
- package/lib/ast.js +1662 -350
- package/lib/compress/evaluate.js +4 -3
- package/lib/equivalent-to.js +81 -107
- package/lib/mozilla-ast.js +474 -81
- package/lib/propmangle.js +1 -1
- package/package.json +2 -2
- package/tools/domprops.js +11 -0
package/lib/compress/evaluate.js
CHANGED
@@ -128,14 +128,15 @@ def_eval(AST_Constant, function () {
|
|
128
128
|
def_eval(AST_BigInt, return_this);
|
129
129
|
|
130
130
|
def_eval(AST_RegExp, function (compressor) {
|
131
|
-
let evaluated = compressor.evaluated_regexps.get(this);
|
131
|
+
let evaluated = compressor.evaluated_regexps.get(this.value);
|
132
132
|
if (evaluated === undefined) {
|
133
133
|
try {
|
134
|
-
|
134
|
+
const { source, flags } = this.value;
|
135
|
+
evaluated = new RegExp(source, flags);
|
135
136
|
} catch (e) {
|
136
137
|
evaluated = null;
|
137
138
|
}
|
138
|
-
compressor.evaluated_regexps.set(this, evaluated);
|
139
|
+
compressor.evaluated_regexps.set(this.value, evaluated);
|
139
140
|
}
|
140
141
|
return evaluated || this;
|
141
142
|
});
|
package/lib/equivalent-to.js
CHANGED
@@ -97,24 +97,6 @@ export const equivalent_to = (tree1, tree2) => {
|
|
97
97
|
return walk_1_state.length == 0 && walk_2_state.length == 0;
|
98
98
|
};
|
99
99
|
|
100
|
-
// Creates a shallow compare function
|
101
|
-
const mkshallow = (props) => {
|
102
|
-
const comparisons = Object
|
103
|
-
.keys(props)
|
104
|
-
.map(key => {
|
105
|
-
if (props[key] === "eq") {
|
106
|
-
return `this.${key} === other.${key}`;
|
107
|
-
} else if (props[key] === "exist") {
|
108
|
-
return `(this.${key} == null ? other.${key} == null : this.${key} === other.${key})`;
|
109
|
-
} else {
|
110
|
-
throw new Error(`mkshallow: Unexpected instruction: ${props[key]}`);
|
111
|
-
}
|
112
|
-
})
|
113
|
-
.join(" && ");
|
114
|
-
|
115
|
-
return new Function("other", "return " + comparisons);
|
116
|
-
};
|
117
|
-
|
118
100
|
const pass_through = () => true;
|
119
101
|
|
120
102
|
AST_Node.prototype.shallow_cmp = function () {
|
@@ -123,7 +105,9 @@ AST_Node.prototype.shallow_cmp = function () {
|
|
123
105
|
|
124
106
|
AST_Debugger.prototype.shallow_cmp = pass_through;
|
125
107
|
|
126
|
-
AST_Directive.prototype.shallow_cmp =
|
108
|
+
AST_Directive.prototype.shallow_cmp = function(other) {
|
109
|
+
return this.value === other.value;
|
110
|
+
};
|
127
111
|
|
128
112
|
AST_SimpleStatement.prototype.shallow_cmp = pass_through;
|
129
113
|
|
@@ -131,17 +115,17 @@ AST_Block.prototype.shallow_cmp = pass_through;
|
|
131
115
|
|
132
116
|
AST_EmptyStatement.prototype.shallow_cmp = pass_through;
|
133
117
|
|
134
|
-
AST_LabeledStatement.prototype.shallow_cmp =
|
118
|
+
AST_LabeledStatement.prototype.shallow_cmp = function(other) {
|
119
|
+
return this.label.name === other.label.name;
|
120
|
+
};
|
135
121
|
|
136
122
|
AST_Do.prototype.shallow_cmp = pass_through;
|
137
123
|
|
138
124
|
AST_While.prototype.shallow_cmp = pass_through;
|
139
125
|
|
140
|
-
AST_For.prototype.shallow_cmp =
|
141
|
-
init:
|
142
|
-
|
143
|
-
step: "exist"
|
144
|
-
});
|
126
|
+
AST_For.prototype.shallow_cmp = function(other) {
|
127
|
+
return (this.init == null ? other.init == null : this.init === other.init) && (this.condition == null ? other.condition == null : this.condition === other.condition) && (this.step == null ? other.step == null : this.step === other.step);
|
128
|
+
};
|
145
129
|
|
146
130
|
AST_ForIn.prototype.shallow_cmp = pass_through;
|
147
131
|
|
@@ -153,22 +137,21 @@ AST_Toplevel.prototype.shallow_cmp = pass_through;
|
|
153
137
|
|
154
138
|
AST_Expansion.prototype.shallow_cmp = pass_through;
|
155
139
|
|
156
|
-
AST_Lambda.prototype.shallow_cmp =
|
157
|
-
is_generator
|
158
|
-
|
159
|
-
});
|
140
|
+
AST_Lambda.prototype.shallow_cmp = function(other) {
|
141
|
+
return this.is_generator === other.is_generator && this.async === other.async;
|
142
|
+
};
|
160
143
|
|
161
|
-
AST_Destructuring.prototype.shallow_cmp =
|
162
|
-
is_array
|
163
|
-
}
|
144
|
+
AST_Destructuring.prototype.shallow_cmp = function(other) {
|
145
|
+
return this.is_array === other.is_array;
|
146
|
+
};
|
164
147
|
|
165
148
|
AST_PrefixedTemplateString.prototype.shallow_cmp = pass_through;
|
166
149
|
|
167
150
|
AST_TemplateString.prototype.shallow_cmp = pass_through;
|
168
151
|
|
169
|
-
AST_TemplateSegment.prototype.shallow_cmp =
|
170
|
-
|
171
|
-
}
|
152
|
+
AST_TemplateSegment.prototype.shallow_cmp = function(other) {
|
153
|
+
return this.value === other.value;
|
154
|
+
};
|
172
155
|
|
173
156
|
AST_Jump.prototype.shallow_cmp = pass_through;
|
174
157
|
|
@@ -176,51 +159,45 @@ AST_LoopControl.prototype.shallow_cmp = pass_through;
|
|
176
159
|
|
177
160
|
AST_Await.prototype.shallow_cmp = pass_through;
|
178
161
|
|
179
|
-
AST_Yield.prototype.shallow_cmp =
|
180
|
-
is_star
|
181
|
-
}
|
162
|
+
AST_Yield.prototype.shallow_cmp = function(other) {
|
163
|
+
return this.is_star === other.is_star;
|
164
|
+
};
|
182
165
|
|
183
|
-
AST_If.prototype.shallow_cmp =
|
184
|
-
alternative:
|
185
|
-
}
|
166
|
+
AST_If.prototype.shallow_cmp = function(other) {
|
167
|
+
return this.alternative == null ? other.alternative == null : this.alternative === other.alternative;
|
168
|
+
};
|
186
169
|
|
187
170
|
AST_Switch.prototype.shallow_cmp = pass_through;
|
188
171
|
|
189
172
|
AST_SwitchBranch.prototype.shallow_cmp = pass_through;
|
190
173
|
|
191
|
-
AST_Try.prototype.shallow_cmp =
|
192
|
-
bcatch:
|
193
|
-
|
194
|
-
});
|
174
|
+
AST_Try.prototype.shallow_cmp = function(other) {
|
175
|
+
return (this.bcatch == null ? other.bcatch == null : this.bcatch === other.bcatch) && (this.bfinally == null ? other.bfinally == null : this.bfinally === other.bfinally);
|
176
|
+
};
|
195
177
|
|
196
|
-
AST_Catch.prototype.shallow_cmp =
|
197
|
-
argname:
|
198
|
-
}
|
178
|
+
AST_Catch.prototype.shallow_cmp = function(other) {
|
179
|
+
return this.argname == null ? other.argname == null : this.argname === other.argname;
|
180
|
+
};
|
199
181
|
|
200
182
|
AST_Finally.prototype.shallow_cmp = pass_through;
|
201
183
|
|
202
184
|
AST_Definitions.prototype.shallow_cmp = pass_through;
|
203
185
|
|
204
|
-
AST_VarDef.prototype.shallow_cmp =
|
205
|
-
value:
|
206
|
-
}
|
186
|
+
AST_VarDef.prototype.shallow_cmp = function(other) {
|
187
|
+
return this.value == null ? other.value == null : this.value === other.value;
|
188
|
+
};
|
207
189
|
|
208
190
|
AST_NameMapping.prototype.shallow_cmp = pass_through;
|
209
191
|
|
210
|
-
AST_Import.prototype.shallow_cmp =
|
211
|
-
imported_name:
|
212
|
-
|
213
|
-
});
|
192
|
+
AST_Import.prototype.shallow_cmp = function(other) {
|
193
|
+
return (this.imported_name == null ? other.imported_name == null : this.imported_name === other.imported_name) && (this.imported_names == null ? other.imported_names == null : this.imported_names === other.imported_names);
|
194
|
+
};
|
214
195
|
|
215
196
|
AST_ImportMeta.prototype.shallow_cmp = pass_through;
|
216
197
|
|
217
|
-
AST_Export.prototype.shallow_cmp =
|
218
|
-
exported_definition:
|
219
|
-
|
220
|
-
exported_names: "exist",
|
221
|
-
module_name: "eq",
|
222
|
-
is_default: "eq",
|
223
|
-
});
|
198
|
+
AST_Export.prototype.shallow_cmp = function(other) {
|
199
|
+
return (this.exported_definition == null ? other.exported_definition == null : this.exported_definition === other.exported_definition) && (this.exported_value == null ? other.exported_value == null : this.exported_value === other.exported_value) && (this.exported_names == null ? other.exported_names == null : this.exported_names === other.exported_names) && this.module_name === other.module_name && this.is_default === other.is_default;
|
200
|
+
};
|
224
201
|
|
225
202
|
AST_Call.prototype.shallow_cmp = pass_through;
|
226
203
|
|
@@ -230,21 +207,21 @@ AST_PropAccess.prototype.shallow_cmp = pass_through;
|
|
230
207
|
|
231
208
|
AST_Chain.prototype.shallow_cmp = pass_through;
|
232
209
|
|
233
|
-
AST_Dot.prototype.shallow_cmp =
|
234
|
-
property
|
235
|
-
}
|
210
|
+
AST_Dot.prototype.shallow_cmp = function(other) {
|
211
|
+
return this.property === other.property;
|
212
|
+
};
|
236
213
|
|
237
|
-
AST_DotHash.prototype.shallow_cmp =
|
238
|
-
property
|
239
|
-
}
|
214
|
+
AST_DotHash.prototype.shallow_cmp = function(other) {
|
215
|
+
return this.property === other.property;
|
216
|
+
};
|
240
217
|
|
241
|
-
AST_Unary.prototype.shallow_cmp =
|
242
|
-
operator
|
243
|
-
}
|
218
|
+
AST_Unary.prototype.shallow_cmp = function(other) {
|
219
|
+
return this.operator === other.operator;
|
220
|
+
};
|
244
221
|
|
245
|
-
AST_Binary.prototype.shallow_cmp =
|
246
|
-
operator
|
247
|
-
}
|
222
|
+
AST_Binary.prototype.shallow_cmp = function(other) {
|
223
|
+
return this.operator === other.operator;
|
224
|
+
};
|
248
225
|
|
249
226
|
AST_Conditional.prototype.shallow_cmp = pass_through;
|
250
227
|
|
@@ -254,36 +231,33 @@ AST_Object.prototype.shallow_cmp = pass_through;
|
|
254
231
|
|
255
232
|
AST_ObjectProperty.prototype.shallow_cmp = pass_through;
|
256
233
|
|
257
|
-
AST_ObjectKeyVal.prototype.shallow_cmp =
|
258
|
-
key
|
259
|
-
}
|
234
|
+
AST_ObjectKeyVal.prototype.shallow_cmp = function(other) {
|
235
|
+
return this.key === other.key;
|
236
|
+
};
|
260
237
|
|
261
|
-
AST_ObjectSetter.prototype.shallow_cmp =
|
262
|
-
static
|
263
|
-
}
|
238
|
+
AST_ObjectSetter.prototype.shallow_cmp = function(other) {
|
239
|
+
return this.static === other.static;
|
240
|
+
};
|
264
241
|
|
265
|
-
AST_ObjectGetter.prototype.shallow_cmp =
|
266
|
-
static
|
267
|
-
}
|
242
|
+
AST_ObjectGetter.prototype.shallow_cmp = function(other) {
|
243
|
+
return this.static === other.static;
|
244
|
+
};
|
268
245
|
|
269
|
-
AST_ConciseMethod.prototype.shallow_cmp =
|
270
|
-
static
|
271
|
-
|
272
|
-
async: "eq",
|
273
|
-
});
|
246
|
+
AST_ConciseMethod.prototype.shallow_cmp = function(other) {
|
247
|
+
return this.static === other.static && this.is_generator === other.is_generator && this.async === other.async;
|
248
|
+
};
|
274
249
|
|
275
|
-
AST_Class.prototype.shallow_cmp =
|
276
|
-
name:
|
277
|
-
|
278
|
-
});
|
250
|
+
AST_Class.prototype.shallow_cmp = function(other) {
|
251
|
+
return (this.name == null ? other.name == null : this.name === other.name) && (this.extends == null ? other.extends == null : this.extends === other.extends);
|
252
|
+
};
|
279
253
|
|
280
|
-
AST_ClassProperty.prototype.shallow_cmp =
|
281
|
-
static
|
282
|
-
}
|
254
|
+
AST_ClassProperty.prototype.shallow_cmp = function(other) {
|
255
|
+
return this.static === other.static;
|
256
|
+
};
|
283
257
|
|
284
|
-
AST_Symbol.prototype.shallow_cmp =
|
285
|
-
name
|
286
|
-
}
|
258
|
+
AST_Symbol.prototype.shallow_cmp = function(other) {
|
259
|
+
return this.name === other.name;
|
260
|
+
};
|
287
261
|
|
288
262
|
AST_NewTarget.prototype.shallow_cmp = pass_through;
|
289
263
|
|
@@ -291,17 +265,17 @@ AST_This.prototype.shallow_cmp = pass_through;
|
|
291
265
|
|
292
266
|
AST_Super.prototype.shallow_cmp = pass_through;
|
293
267
|
|
294
|
-
AST_String.prototype.shallow_cmp =
|
295
|
-
value
|
296
|
-
}
|
268
|
+
AST_String.prototype.shallow_cmp = function(other) {
|
269
|
+
return this.value === other.value;
|
270
|
+
};
|
297
271
|
|
298
|
-
AST_Number.prototype.shallow_cmp =
|
299
|
-
value
|
300
|
-
}
|
272
|
+
AST_Number.prototype.shallow_cmp = function(other) {
|
273
|
+
return this.value === other.value;
|
274
|
+
};
|
301
275
|
|
302
|
-
AST_BigInt.prototype.shallow_cmp =
|
303
|
-
value
|
304
|
-
}
|
276
|
+
AST_BigInt.prototype.shallow_cmp = function(other) {
|
277
|
+
return this.value === other.value;
|
278
|
+
};
|
305
279
|
|
306
280
|
AST_RegExp.prototype.shallow_cmp = function (other) {
|
307
281
|
return (
|