terser 5.18.2 → 5.19.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 +3 -0
- package/dist/bundle.min.js +50 -43
- package/lib/ast.js +2 -0
- package/lib/minify.js +6 -1
- package/lib/parse.js +8 -8
- package/lib/propmangle.js +38 -36
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/bundle.min.js
CHANGED
@@ -3283,25 +3283,25 @@ function parse($TEXT, options) {
|
|
3283
3283
|
if(is("privatename") && !S.in_class)
|
3284
3284
|
croak("Private field must be used in an enclosing class");
|
3285
3285
|
const AST_DotVariant = is("privatename") ? AST_DotHash : AST_Dot;
|
3286
|
-
return subscripts(new AST_DotVariant({
|
3286
|
+
return annotate(subscripts(new AST_DotVariant({
|
3287
3287
|
start : start,
|
3288
3288
|
expression : expr,
|
3289
3289
|
optional : false,
|
3290
3290
|
property : as_name(),
|
3291
3291
|
end : prev()
|
3292
|
-
}), allow_calls, is_chain);
|
3292
|
+
}), allow_calls, is_chain));
|
3293
3293
|
}
|
3294
3294
|
if (is("punc", "[")) {
|
3295
3295
|
next();
|
3296
3296
|
var prop = expression(true);
|
3297
3297
|
expect("]");
|
3298
|
-
return subscripts(new AST_Sub({
|
3298
|
+
return annotate(subscripts(new AST_Sub({
|
3299
3299
|
start : start,
|
3300
3300
|
expression : expr,
|
3301
3301
|
optional : false,
|
3302
3302
|
property : prop,
|
3303
3303
|
end : prev()
|
3304
|
-
}), allow_calls, is_chain);
|
3304
|
+
}), allow_calls, is_chain));
|
3305
3305
|
}
|
3306
3306
|
if (allow_calls && is("punc", "(")) {
|
3307
3307
|
next();
|
@@ -3338,24 +3338,24 @@ function parse($TEXT, options) {
|
|
3338
3338
|
if(is("privatename") && !S.in_class)
|
3339
3339
|
croak("Private field must be used in an enclosing class");
|
3340
3340
|
const AST_DotVariant = is("privatename") ? AST_DotHash : AST_Dot;
|
3341
|
-
chain_contents = subscripts(new AST_DotVariant({
|
3341
|
+
chain_contents = annotate(subscripts(new AST_DotVariant({
|
3342
3342
|
start,
|
3343
3343
|
expression: expr,
|
3344
3344
|
optional: true,
|
3345
3345
|
property: as_name(),
|
3346
3346
|
end: prev()
|
3347
|
-
}), allow_calls, true);
|
3347
|
+
}), allow_calls, true));
|
3348
3348
|
} else if (is("punc", "[")) {
|
3349
3349
|
next();
|
3350
3350
|
const property = expression(true);
|
3351
3351
|
expect("]");
|
3352
|
-
chain_contents = subscripts(new AST_Sub({
|
3352
|
+
chain_contents = annotate(subscripts(new AST_Sub({
|
3353
3353
|
start,
|
3354
3354
|
expression: expr,
|
3355
3355
|
optional: true,
|
3356
3356
|
property,
|
3357
3357
|
end: prev()
|
3358
|
-
}), allow_calls, true);
|
3358
|
+
}), allow_calls, true));
|
3359
3359
|
}
|
3360
3360
|
|
3361
3361
|
if (!chain_contents) unexpected();
|
@@ -5333,6 +5333,7 @@ var AST_Dot = DEFNODE("Dot", "quote", function AST_Dot(props) {
|
|
5333
5333
|
this.expression = props.expression;
|
5334
5334
|
this.property = props.property;
|
5335
5335
|
this.optional = props.optional;
|
5336
|
+
this._annotations = props._annotations;
|
5336
5337
|
this.start = props.start;
|
5337
5338
|
this.end = props.end;
|
5338
5339
|
}
|
@@ -5380,6 +5381,7 @@ var AST_Sub = DEFNODE("Sub", null, function AST_Sub(props) {
|
|
5380
5381
|
this.expression = props.expression;
|
5381
5382
|
this.property = props.property;
|
5382
5383
|
this.optional = props.optional;
|
5384
|
+
this._annotations = props._annotations;
|
5383
5385
|
this.start = props.start;
|
5384
5386
|
this.end = props.end;
|
5385
5387
|
}
|
@@ -29872,7 +29874,38 @@ function mangle_private_properties(ast, options) {
|
|
29872
29874
|
}
|
29873
29875
|
}
|
29874
29876
|
|
29875
|
-
function
|
29877
|
+
function find_annotated_props(ast) {
|
29878
|
+
var annotated_props = new Set();
|
29879
|
+
walk(ast, node => {
|
29880
|
+
if (
|
29881
|
+
node instanceof AST_ClassPrivateProperty
|
29882
|
+
|| node instanceof AST_PrivateMethod
|
29883
|
+
|| node instanceof AST_PrivateGetter
|
29884
|
+
|| node instanceof AST_PrivateSetter
|
29885
|
+
|| node instanceof AST_DotHash
|
29886
|
+
) ; else if (node instanceof AST_ObjectKeyVal) {
|
29887
|
+
if (typeof node.key == "string" && has_annotation(node, _MANGLEPROP)) {
|
29888
|
+
annotated_props.add(node.key);
|
29889
|
+
}
|
29890
|
+
} else if (node instanceof AST_ObjectProperty) {
|
29891
|
+
// setter or getter, since KeyVal is handled above
|
29892
|
+
if (has_annotation(node, _MANGLEPROP)) {
|
29893
|
+
annotated_props.add(node.key.name);
|
29894
|
+
}
|
29895
|
+
} else if (node instanceof AST_Dot) {
|
29896
|
+
if (has_annotation(node, _MANGLEPROP)) {
|
29897
|
+
annotated_props.add(node.property);
|
29898
|
+
}
|
29899
|
+
} else if (node instanceof AST_Sub) {
|
29900
|
+
if (node.property instanceof AST_String && has_annotation(node, _MANGLEPROP)) {
|
29901
|
+
annotated_props.add(node.property.value);
|
29902
|
+
}
|
29903
|
+
}
|
29904
|
+
});
|
29905
|
+
return annotated_props;
|
29906
|
+
}
|
29907
|
+
|
29908
|
+
function mangle_properties(ast, options, annotated_props = find_annotated_props(ast)) {
|
29876
29909
|
options = defaults(options, {
|
29877
29910
|
builtins: false,
|
29878
29911
|
cache: null,
|
@@ -29914,7 +29947,6 @@ function mangle_properties(ast, options) {
|
|
29914
29947
|
debug_name_suffix = (options.debug === true ? "" : options.debug);
|
29915
29948
|
}
|
29916
29949
|
|
29917
|
-
var annotated_names = new Set();
|
29918
29950
|
var names_to_mangle = new Set();
|
29919
29951
|
var unmangleable = new Set();
|
29920
29952
|
// Track each already-mangled name to prevent nth_identifier from generating
|
@@ -29923,36 +29955,7 @@ function mangle_properties(ast, options) {
|
|
29923
29955
|
|
29924
29956
|
var keep_quoted = !!options.keep_quoted;
|
29925
29957
|
|
29926
|
-
//
|
29927
|
-
walk(ast, node => {
|
29928
|
-
if (
|
29929
|
-
node instanceof AST_ClassPrivateProperty
|
29930
|
-
|| node instanceof AST_PrivateMethod
|
29931
|
-
|| node instanceof AST_PrivateGetter
|
29932
|
-
|| node instanceof AST_PrivateSetter
|
29933
|
-
|| node instanceof AST_DotHash
|
29934
|
-
) ; else if (node instanceof AST_ObjectKeyVal) {
|
29935
|
-
if (
|
29936
|
-
typeof node.key == "string"
|
29937
|
-
&& has_annotation(node, _MANGLEPROP)
|
29938
|
-
&& can_mangle(node.key)
|
29939
|
-
) {
|
29940
|
-
annotated_names.add(node.key);
|
29941
|
-
clear_annotation(node, _MANGLEPROP);
|
29942
|
-
}
|
29943
|
-
} else if (node instanceof AST_ObjectProperty) {
|
29944
|
-
// setter or getter, since KeyVal is handled above
|
29945
|
-
if (
|
29946
|
-
has_annotation(node, _MANGLEPROP)
|
29947
|
-
&& can_mangle(node.key.name)
|
29948
|
-
) {
|
29949
|
-
annotated_names.add(node.key.name);
|
29950
|
-
clear_annotation(node, _MANGLEPROP);
|
29951
|
-
}
|
29952
|
-
}
|
29953
|
-
});
|
29954
|
-
|
29955
|
-
// step 2: find candidates to mangle
|
29958
|
+
// step 1: find candidates to mangle
|
29956
29959
|
ast.walk(new TreeWalker(function(node) {
|
29957
29960
|
if (
|
29958
29961
|
node instanceof AST_ClassPrivateProperty
|
@@ -30044,9 +30047,9 @@ function mangle_properties(ast, options) {
|
|
30044
30047
|
}
|
30045
30048
|
|
30046
30049
|
function should_mangle(name) {
|
30047
|
-
if (only_annotated && !
|
30050
|
+
if (only_annotated && !annotated_props.has(name)) return false;
|
30048
30051
|
if (regex && !regex.test(name)) {
|
30049
|
-
return
|
30052
|
+
return annotated_props.has(name);
|
30050
30053
|
}
|
30051
30054
|
if (reserved.has(name)) return false;
|
30052
30055
|
return cache.has(name)
|
@@ -30325,6 +30328,10 @@ async function minify(files, options, _fs_module) {
|
|
30325
30328
|
if (quoted_props && options.mangle.properties.keep_quoted !== "strict") {
|
30326
30329
|
reserve_quoted_keys(toplevel, quoted_props);
|
30327
30330
|
}
|
30331
|
+
var annotated_props;
|
30332
|
+
if (options.mangle && options.mangle.properties) {
|
30333
|
+
annotated_props = find_annotated_props(toplevel);
|
30334
|
+
}
|
30328
30335
|
if (options.wrap) {
|
30329
30336
|
toplevel = toplevel.wrap_commonjs(options.wrap);
|
30330
30337
|
}
|
@@ -30352,7 +30359,7 @@ async function minify(files, options, _fs_module) {
|
|
30352
30359
|
}
|
30353
30360
|
if (timings) timings.properties = Date.now();
|
30354
30361
|
if (options.mangle && options.mangle.properties) {
|
30355
|
-
toplevel = mangle_properties(toplevel, options.mangle.properties);
|
30362
|
+
toplevel = mangle_properties(toplevel, options.mangle.properties, annotated_props);
|
30356
30363
|
}
|
30357
30364
|
|
30358
30365
|
// Format phase
|
package/lib/ast.js
CHANGED
@@ -1714,6 +1714,7 @@ var AST_Dot = DEFNODE("Dot", "quote", function AST_Dot(props) {
|
|
1714
1714
|
this.expression = props.expression;
|
1715
1715
|
this.property = props.property;
|
1716
1716
|
this.optional = props.optional;
|
1717
|
+
this._annotations = props._annotations;
|
1717
1718
|
this.start = props.start;
|
1718
1719
|
this.end = props.end;
|
1719
1720
|
}
|
@@ -1761,6 +1762,7 @@ var AST_Sub = DEFNODE("Sub", null, function AST_Sub(props) {
|
|
1761
1762
|
this.expression = props.expression;
|
1762
1763
|
this.property = props.property;
|
1763
1764
|
this.optional = props.optional;
|
1765
|
+
this._annotations = props._annotations;
|
1764
1766
|
this.start = props.start;
|
1765
1767
|
this.end = props.end;
|
1766
1768
|
}
|
package/lib/minify.js
CHANGED
@@ -17,6 +17,7 @@ import {
|
|
17
17
|
mangle_properties,
|
18
18
|
mangle_private_properties,
|
19
19
|
reserve_quoted_keys,
|
20
|
+
find_annotated_props,
|
20
21
|
} from "./propmangle.js";
|
21
22
|
|
22
23
|
// to/from base64 functions
|
@@ -235,6 +236,10 @@ async function minify(files, options, _fs_module) {
|
|
235
236
|
if (quoted_props && options.mangle.properties.keep_quoted !== "strict") {
|
236
237
|
reserve_quoted_keys(toplevel, quoted_props);
|
237
238
|
}
|
239
|
+
var annotated_props;
|
240
|
+
if (options.mangle && options.mangle.properties) {
|
241
|
+
annotated_props = find_annotated_props(toplevel);
|
242
|
+
}
|
238
243
|
if (options.wrap) {
|
239
244
|
toplevel = toplevel.wrap_commonjs(options.wrap);
|
240
245
|
}
|
@@ -268,7 +273,7 @@ async function minify(files, options, _fs_module) {
|
|
268
273
|
}
|
269
274
|
if (timings) timings.properties = Date.now();
|
270
275
|
if (options.mangle && options.mangle.properties) {
|
271
|
-
toplevel = mangle_properties(toplevel, options.mangle.properties);
|
276
|
+
toplevel = mangle_properties(toplevel, options.mangle.properties, annotated_props);
|
272
277
|
}
|
273
278
|
|
274
279
|
// Format phase
|
package/lib/parse.js
CHANGED
@@ -3138,25 +3138,25 @@ function parse($TEXT, options) {
|
|
3138
3138
|
if(is("privatename") && !S.in_class)
|
3139
3139
|
croak("Private field must be used in an enclosing class");
|
3140
3140
|
const AST_DotVariant = is("privatename") ? AST_DotHash : AST_Dot;
|
3141
|
-
return subscripts(new AST_DotVariant({
|
3141
|
+
return annotate(subscripts(new AST_DotVariant({
|
3142
3142
|
start : start,
|
3143
3143
|
expression : expr,
|
3144
3144
|
optional : false,
|
3145
3145
|
property : as_name(),
|
3146
3146
|
end : prev()
|
3147
|
-
}), allow_calls, is_chain);
|
3147
|
+
}), allow_calls, is_chain));
|
3148
3148
|
}
|
3149
3149
|
if (is("punc", "[")) {
|
3150
3150
|
next();
|
3151
3151
|
var prop = expression(true);
|
3152
3152
|
expect("]");
|
3153
|
-
return subscripts(new AST_Sub({
|
3153
|
+
return annotate(subscripts(new AST_Sub({
|
3154
3154
|
start : start,
|
3155
3155
|
expression : expr,
|
3156
3156
|
optional : false,
|
3157
3157
|
property : prop,
|
3158
3158
|
end : prev()
|
3159
|
-
}), allow_calls, is_chain);
|
3159
|
+
}), allow_calls, is_chain));
|
3160
3160
|
}
|
3161
3161
|
if (allow_calls && is("punc", "(")) {
|
3162
3162
|
next();
|
@@ -3193,24 +3193,24 @@ function parse($TEXT, options) {
|
|
3193
3193
|
if(is("privatename") && !S.in_class)
|
3194
3194
|
croak("Private field must be used in an enclosing class");
|
3195
3195
|
const AST_DotVariant = is("privatename") ? AST_DotHash : AST_Dot;
|
3196
|
-
chain_contents = subscripts(new AST_DotVariant({
|
3196
|
+
chain_contents = annotate(subscripts(new AST_DotVariant({
|
3197
3197
|
start,
|
3198
3198
|
expression: expr,
|
3199
3199
|
optional: true,
|
3200
3200
|
property: as_name(),
|
3201
3201
|
end: prev()
|
3202
|
-
}), allow_calls, true);
|
3202
|
+
}), allow_calls, true));
|
3203
3203
|
} else if (is("punc", "[")) {
|
3204
3204
|
next();
|
3205
3205
|
const property = expression(true);
|
3206
3206
|
expect("]");
|
3207
|
-
chain_contents = subscripts(new AST_Sub({
|
3207
|
+
chain_contents = annotate(subscripts(new AST_Sub({
|
3208
3208
|
start,
|
3209
3209
|
expression: expr,
|
3210
3210
|
optional: true,
|
3211
3211
|
property,
|
3212
3212
|
end: prev()
|
3213
|
-
}), allow_calls, true);
|
3213
|
+
}), allow_calls, true));
|
3214
3214
|
}
|
3215
3215
|
|
3216
3216
|
if (!chain_contents) unexpected();
|
package/lib/propmangle.js
CHANGED
@@ -180,7 +180,40 @@ function mangle_private_properties(ast, options) {
|
|
180
180
|
}
|
181
181
|
}
|
182
182
|
|
183
|
-
function
|
183
|
+
function find_annotated_props(ast) {
|
184
|
+
var annotated_props = new Set();
|
185
|
+
walk(ast, node => {
|
186
|
+
if (
|
187
|
+
node instanceof AST_ClassPrivateProperty
|
188
|
+
|| node instanceof AST_PrivateMethod
|
189
|
+
|| node instanceof AST_PrivateGetter
|
190
|
+
|| node instanceof AST_PrivateSetter
|
191
|
+
|| node instanceof AST_DotHash
|
192
|
+
) {
|
193
|
+
// handled by mangle_private_properties
|
194
|
+
} else if (node instanceof AST_ObjectKeyVal) {
|
195
|
+
if (typeof node.key == "string" && has_annotation(node, _MANGLEPROP)) {
|
196
|
+
annotated_props.add(node.key);
|
197
|
+
}
|
198
|
+
} else if (node instanceof AST_ObjectProperty) {
|
199
|
+
// setter or getter, since KeyVal is handled above
|
200
|
+
if (has_annotation(node, _MANGLEPROP)) {
|
201
|
+
annotated_props.add(node.key.name);
|
202
|
+
}
|
203
|
+
} else if (node instanceof AST_Dot) {
|
204
|
+
if (has_annotation(node, _MANGLEPROP)) {
|
205
|
+
annotated_props.add(node.property);
|
206
|
+
}
|
207
|
+
} else if (node instanceof AST_Sub) {
|
208
|
+
if (node.property instanceof AST_String && has_annotation(node, _MANGLEPROP)) {
|
209
|
+
annotated_props.add(node.property.value);
|
210
|
+
}
|
211
|
+
}
|
212
|
+
});
|
213
|
+
return annotated_props;
|
214
|
+
}
|
215
|
+
|
216
|
+
function mangle_properties(ast, options, annotated_props = find_annotated_props(ast)) {
|
184
217
|
options = defaults(options, {
|
185
218
|
builtins: false,
|
186
219
|
cache: null,
|
@@ -222,7 +255,6 @@ function mangle_properties(ast, options) {
|
|
222
255
|
debug_name_suffix = (options.debug === true ? "" : options.debug);
|
223
256
|
}
|
224
257
|
|
225
|
-
var annotated_names = new Set();
|
226
258
|
var names_to_mangle = new Set();
|
227
259
|
var unmangleable = new Set();
|
228
260
|
// Track each already-mangled name to prevent nth_identifier from generating
|
@@ -231,38 +263,7 @@ function mangle_properties(ast, options) {
|
|
231
263
|
|
232
264
|
var keep_quoted = !!options.keep_quoted;
|
233
265
|
|
234
|
-
//
|
235
|
-
walk(ast, node => {
|
236
|
-
if (
|
237
|
-
node instanceof AST_ClassPrivateProperty
|
238
|
-
|| node instanceof AST_PrivateMethod
|
239
|
-
|| node instanceof AST_PrivateGetter
|
240
|
-
|| node instanceof AST_PrivateSetter
|
241
|
-
|| node instanceof AST_DotHash
|
242
|
-
) {
|
243
|
-
// handled by mangle_private_properties
|
244
|
-
} else if (node instanceof AST_ObjectKeyVal) {
|
245
|
-
if (
|
246
|
-
typeof node.key == "string"
|
247
|
-
&& has_annotation(node, _MANGLEPROP)
|
248
|
-
&& can_mangle(node.key)
|
249
|
-
) {
|
250
|
-
annotated_names.add(node.key);
|
251
|
-
clear_annotation(node, _MANGLEPROP);
|
252
|
-
}
|
253
|
-
} else if (node instanceof AST_ObjectProperty) {
|
254
|
-
// setter or getter, since KeyVal is handled above
|
255
|
-
if (
|
256
|
-
has_annotation(node, _MANGLEPROP)
|
257
|
-
&& can_mangle(node.key.name)
|
258
|
-
) {
|
259
|
-
annotated_names.add(node.key.name);
|
260
|
-
clear_annotation(node, _MANGLEPROP);
|
261
|
-
}
|
262
|
-
}
|
263
|
-
});
|
264
|
-
|
265
|
-
// step 2: find candidates to mangle
|
266
|
+
// step 1: find candidates to mangle
|
266
267
|
ast.walk(new TreeWalker(function(node) {
|
267
268
|
if (
|
268
269
|
node instanceof AST_ClassPrivateProperty
|
@@ -358,9 +359,9 @@ function mangle_properties(ast, options) {
|
|
358
359
|
}
|
359
360
|
|
360
361
|
function should_mangle(name) {
|
361
|
-
if (only_annotated && !
|
362
|
+
if (only_annotated && !annotated_props.has(name)) return false;
|
362
363
|
if (regex && !regex.test(name)) {
|
363
|
-
return
|
364
|
+
return annotated_props.has(name);
|
364
365
|
}
|
365
366
|
if (reserved.has(name)) return false;
|
366
367
|
return cache.has(name)
|
@@ -427,4 +428,5 @@ export {
|
|
427
428
|
reserve_quoted_keys,
|
428
429
|
mangle_properties,
|
429
430
|
mangle_private_properties,
|
431
|
+
find_annotated_props,
|
430
432
|
};
|