terser 5.17.6 → 5.18.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 +8 -0
- package/README.md +2 -0
- package/dist/bundle.min.js +90 -37
- package/lib/ast.js +12 -4
- package/lib/parse.js +38 -28
- package/lib/propmangle.js +44 -3
- package/lib/utils/index.js +1 -1
- package/package.json +8 -9
- package/tools/domprops.js +1 -0
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v7.18.0
|
4
|
+
- Add new `/*@__MANGLE_PROP__*/` annotation, to mark properties that should be mangled.
|
5
|
+
|
6
|
+
## v5.17.7
|
7
|
+
- Update some dependencies
|
8
|
+
- Add consistent sorting for `v` RegExp flag
|
9
|
+
- Add `inert` DOM attribute to domprops
|
10
|
+
|
3
11
|
## v5.17.6
|
4
12
|
- Fixes to mozilla AST input and output, for class properties, private properties and static blocks
|
5
13
|
- Fix outputting a shorthand property in quotes when safari10 and ecma=2015 options are enabled
|
package/README.md
CHANGED
@@ -106,6 +106,7 @@ a double dash to prevent input files being used as option arguments:
|
|
106
106
|
`strict` disables quoted properties
|
107
107
|
being automatically reserved.
|
108
108
|
`regex` Only mangle matched property names.
|
109
|
+
`only_annotated` Only mangle properties defined with /*@__MANGLE_PROP__*/.
|
109
110
|
`reserved` List of names that should not be mangled.
|
110
111
|
-f, --format [options] Specify format options.
|
111
112
|
`preamble` Preamble to prepend to the output. You
|
@@ -1189,6 +1190,7 @@ Annotations in Terser are a way to tell it to treat a certain function call diff
|
|
1189
1190
|
* `/*@__NOINLINE__*/` - Makes sure the called function is not inlined into the call site.
|
1190
1191
|
* `/*@__PURE__*/` - Marks a function call as pure. That means, it can safely be dropped.
|
1191
1192
|
* `/*@__KEY__*/` - Marks a string literal as a property to also mangle it when mangling properties.
|
1193
|
+
* `/*@__MANGLE_PROP__*/` - Opts-in an object property (or class field) for mangling, when the property mangler is enabled.
|
1192
1194
|
|
1193
1195
|
You can use either a `@` sign at the start, or a `#`.
|
1194
1196
|
|
package/dist/bundle.min.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@jridgewell/source-map')) :
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', '@jridgewell/source-map'], factory) :
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Terser = {}, global.sourceMap));
|
5
|
-
}(this, (function (exports, sourceMap) { 'use strict';
|
5
|
+
})(this, (function (exports, sourceMap) { 'use strict';
|
6
6
|
|
7
7
|
/***********************************************************************
|
8
8
|
|
@@ -239,7 +239,7 @@ const re_safe_regexp = /^[\\/|\0\s\w^$.[\]()]*$/;
|
|
239
239
|
/** Check if the regexp is safe for Terser to create without risking a RegExp DOS */
|
240
240
|
const regexp_is_safe = (source) => re_safe_regexp.test(source);
|
241
241
|
|
242
|
-
const all_flags = "
|
242
|
+
const all_flags = "dgimsuyv";
|
243
243
|
function sort_regexp_flags(flags) {
|
244
244
|
const existing_flags = new Set(flags.split(""));
|
245
245
|
let out = "";
|
@@ -2372,7 +2372,7 @@ function parse($TEXT, options) {
|
|
2372
2372
|
value : tok.value,
|
2373
2373
|
quote : tok.quote
|
2374
2374
|
});
|
2375
|
-
annotate(ret);
|
2375
|
+
annotate(ret);
|
2376
2376
|
break;
|
2377
2377
|
case "regexp":
|
2378
2378
|
const [_, source, flags] = tok.value.match(/^\/(.*)\/(\w*)$/);
|
@@ -2684,13 +2684,14 @@ function parse($TEXT, options) {
|
|
2684
2684
|
}
|
2685
2685
|
|
2686
2686
|
// Create property
|
2687
|
-
|
2687
|
+
const kv = new AST_ObjectKeyVal({
|
2688
2688
|
start: start,
|
2689
2689
|
quote: start.quote,
|
2690
2690
|
key: name instanceof AST_Node ? name : "" + name,
|
2691
2691
|
value: value,
|
2692
2692
|
end: prev()
|
2693
|
-
})
|
2693
|
+
});
|
2694
|
+
a.push(annotate(kv));
|
2694
2695
|
}
|
2695
2696
|
next();
|
2696
2697
|
return new AST_Object({ properties: a });
|
@@ -2803,26 +2804,26 @@ function parse($TEXT, options) {
|
|
2803
2804
|
: AST_ObjectSetter;
|
2804
2805
|
|
2805
2806
|
name = get_symbol_ast(name);
|
2806
|
-
return new AccessorClass({
|
2807
|
+
return annotate(new AccessorClass({
|
2807
2808
|
start,
|
2808
2809
|
static: is_static,
|
2809
2810
|
key: name,
|
2810
2811
|
quote: name instanceof AST_SymbolMethod ? property_token.quote : undefined,
|
2811
2812
|
value: create_accessor(),
|
2812
2813
|
end: prev()
|
2813
|
-
});
|
2814
|
+
}));
|
2814
2815
|
} else {
|
2815
2816
|
const AccessorClass = accessor_type === "get"
|
2816
2817
|
? AST_PrivateGetter
|
2817
2818
|
: AST_PrivateSetter;
|
2818
2819
|
|
2819
|
-
return new AccessorClass({
|
2820
|
+
return annotate(new AccessorClass({
|
2820
2821
|
start,
|
2821
2822
|
static: is_static,
|
2822
2823
|
key: get_symbol_ast(name),
|
2823
2824
|
value: create_accessor(),
|
2824
2825
|
end: prev(),
|
2825
|
-
});
|
2826
|
+
}));
|
2826
2827
|
}
|
2827
2828
|
}
|
2828
2829
|
|
@@ -2842,7 +2843,7 @@ function parse($TEXT, options) {
|
|
2842
2843
|
value : create_accessor(is_generator, is_async),
|
2843
2844
|
end : prev()
|
2844
2845
|
});
|
2845
|
-
return node;
|
2846
|
+
return annotate(node);
|
2846
2847
|
}
|
2847
2848
|
|
2848
2849
|
if (is_class) {
|
@@ -2855,14 +2856,16 @@ function parse($TEXT, options) {
|
|
2855
2856
|
: AST_ClassProperty;
|
2856
2857
|
if (is("operator", "=")) {
|
2857
2858
|
next();
|
2858
|
-
return
|
2859
|
-
|
2860
|
-
|
2861
|
-
|
2862
|
-
|
2863
|
-
|
2864
|
-
|
2865
|
-
|
2859
|
+
return annotate(
|
2860
|
+
new AST_ClassPropertyVariant({
|
2861
|
+
start,
|
2862
|
+
static: is_static,
|
2863
|
+
quote,
|
2864
|
+
key,
|
2865
|
+
value: expression(false),
|
2866
|
+
end: prev()
|
2867
|
+
})
|
2868
|
+
);
|
2866
2869
|
} else if (
|
2867
2870
|
is("name")
|
2868
2871
|
|| is("privatename")
|
@@ -2870,13 +2873,15 @@ function parse($TEXT, options) {
|
|
2870
2873
|
|| is("punc", ";")
|
2871
2874
|
|| is("punc", "}")
|
2872
2875
|
) {
|
2873
|
-
return
|
2874
|
-
|
2875
|
-
|
2876
|
-
|
2877
|
-
|
2878
|
-
|
2879
|
-
|
2876
|
+
return annotate(
|
2877
|
+
new AST_ClassPropertyVariant({
|
2878
|
+
start,
|
2879
|
+
static: is_static,
|
2880
|
+
quote,
|
2881
|
+
key,
|
2882
|
+
end: prev()
|
2883
|
+
})
|
2884
|
+
);
|
2880
2885
|
}
|
2881
2886
|
}
|
2882
2887
|
}
|
@@ -3239,10 +3244,9 @@ function parse($TEXT, options) {
|
|
3239
3244
|
}
|
3240
3245
|
|
3241
3246
|
// Annotate AST_Call, AST_Lambda or AST_New with the special comments
|
3242
|
-
function annotate(node) {
|
3243
|
-
var
|
3244
|
-
|
3245
|
-
const comments_outside_parens = outer_comments_before_counts.get(start);
|
3247
|
+
function annotate(node, before_token = node.start) {
|
3248
|
+
var comments = before_token.comments_before;
|
3249
|
+
const comments_outside_parens = outer_comments_before_counts.get(before_token);
|
3246
3250
|
var i = comments_outside_parens != null ? comments_outside_parens : comments.length;
|
3247
3251
|
while (--i >= 0) {
|
3248
3252
|
var comment = comments[i];
|
@@ -3263,8 +3267,13 @@ function parse($TEXT, options) {
|
|
3263
3267
|
set_annotation(node, _KEY);
|
3264
3268
|
break;
|
3265
3269
|
}
|
3270
|
+
if (/[@#]__MANGLE_PROP__/.test(comment.value)) {
|
3271
|
+
set_annotation(node, _MANGLEPROP);
|
3272
|
+
break;
|
3273
|
+
}
|
3266
3274
|
}
|
3267
3275
|
}
|
3276
|
+
return node;
|
3268
3277
|
}
|
3269
3278
|
|
3270
3279
|
var subscripts = function(expr, allow_calls, is_chain) {
|
@@ -5623,6 +5632,7 @@ var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", function AST_Obj
|
|
5623
5632
|
this.value = props.value;
|
5624
5633
|
this.start = props.start;
|
5625
5634
|
this.end = props.end;
|
5635
|
+
this._annotations = props._annotations;
|
5626
5636
|
}
|
5627
5637
|
|
5628
5638
|
this.flags = 0;
|
@@ -5652,6 +5662,7 @@ var AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", "quote", function AST_ObjectKeyVa
|
|
5652
5662
|
this.value = props.value;
|
5653
5663
|
this.start = props.start;
|
5654
5664
|
this.end = props.end;
|
5665
|
+
this._annotations = props._annotations;
|
5655
5666
|
}
|
5656
5667
|
|
5657
5668
|
this.flags = 0;
|
@@ -5713,6 +5724,7 @@ var AST_ObjectSetter = DEFNODE("ObjectSetter", "quote static", function AST_Obje
|
|
5713
5724
|
this.value = props.value;
|
5714
5725
|
this.start = props.start;
|
5715
5726
|
this.end = props.end;
|
5727
|
+
this._annotations = props._annotations;
|
5716
5728
|
}
|
5717
5729
|
|
5718
5730
|
this.flags = 0;
|
@@ -5735,6 +5747,7 @@ var AST_ObjectGetter = DEFNODE("ObjectGetter", "quote static", function AST_Obje
|
|
5735
5747
|
this.value = props.value;
|
5736
5748
|
this.start = props.start;
|
5737
5749
|
this.end = props.end;
|
5750
|
+
this._annotations = props._annotations;
|
5738
5751
|
}
|
5739
5752
|
|
5740
5753
|
this.flags = 0;
|
@@ -5762,6 +5775,7 @@ var AST_ConciseMethod = DEFNODE(
|
|
5762
5775
|
this.value = props.value;
|
5763
5776
|
this.start = props.start;
|
5764
5777
|
this.end = props.end;
|
5778
|
+
this._annotations = props._annotations;
|
5765
5779
|
}
|
5766
5780
|
|
5767
5781
|
this.flags = 0;
|
@@ -5884,6 +5898,7 @@ var AST_ClassProperty = DEFNODE("ClassProperty", "static quote", function AST_Cl
|
|
5884
5898
|
this.value = props.value;
|
5885
5899
|
this.start = props.start;
|
5886
5900
|
this.end = props.end;
|
5901
|
+
this._annotations = props._annotations;
|
5887
5902
|
}
|
5888
5903
|
|
5889
5904
|
this.flags = 0;
|
@@ -6787,10 +6802,11 @@ class TreeTransformer extends TreeWalker {
|
|
6787
6802
|
}
|
6788
6803
|
}
|
6789
6804
|
|
6790
|
-
const _PURE
|
6791
|
-
const _INLINE
|
6792
|
-
const _NOINLINE
|
6793
|
-
const _KEY
|
6805
|
+
const _PURE = 0b00000001;
|
6806
|
+
const _INLINE = 0b00000010;
|
6807
|
+
const _NOINLINE = 0b00000100;
|
6808
|
+
const _KEY = 0b00001000;
|
6809
|
+
const _MANGLEPROP = 0b00010000;
|
6794
6810
|
|
6795
6811
|
/***********************************************************************
|
6796
6812
|
|
@@ -26641,6 +26657,7 @@ var domprops = [
|
|
26641
26657
|
"indexOf",
|
26642
26658
|
"indexedDB",
|
26643
26659
|
"indicate",
|
26660
|
+
"inert",
|
26644
26661
|
"inertiaDestinationX",
|
26645
26662
|
"inertiaDestinationY",
|
26646
26663
|
"info",
|
@@ -29818,6 +29835,7 @@ function mangle_properties(ast, options) {
|
|
29818
29835
|
regex: null,
|
29819
29836
|
reserved: null,
|
29820
29837
|
undeclared: false,
|
29838
|
+
only_annotated: false,
|
29821
29839
|
}, true);
|
29822
29840
|
|
29823
29841
|
var nth_identifier = options.nth_identifier;
|
@@ -29836,6 +29854,7 @@ function mangle_properties(ast, options) {
|
|
29836
29854
|
cache = new Map();
|
29837
29855
|
}
|
29838
29856
|
|
29857
|
+
var only_annotated = options.only_annotated;
|
29839
29858
|
var regex = options.regex && new RegExp(options.regex);
|
29840
29859
|
|
29841
29860
|
// note debug is either false (disabled), or a string of the debug suffix to use (enabled).
|
@@ -29847,6 +29866,7 @@ function mangle_properties(ast, options) {
|
|
29847
29866
|
debug_name_suffix = (options.debug === true ? "" : options.debug);
|
29848
29867
|
}
|
29849
29868
|
|
29869
|
+
var annotated_names = new Set();
|
29850
29870
|
var names_to_mangle = new Set();
|
29851
29871
|
var unmangleable = new Set();
|
29852
29872
|
// Track each already-mangled name to prevent nth_identifier from generating
|
@@ -29855,7 +29875,36 @@ function mangle_properties(ast, options) {
|
|
29855
29875
|
|
29856
29876
|
var keep_quoted = !!options.keep_quoted;
|
29857
29877
|
|
29858
|
-
//
|
29878
|
+
// Step 1: Find all annotated /*@__MANGLEPROP__*/
|
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 (
|
29888
|
+
typeof node.key == "string"
|
29889
|
+
&& has_annotation(node, _MANGLEPROP)
|
29890
|
+
&& can_mangle(node.key)
|
29891
|
+
) {
|
29892
|
+
annotated_names.add(node.key);
|
29893
|
+
clear_annotation(node, _MANGLEPROP);
|
29894
|
+
}
|
29895
|
+
} else if (node instanceof AST_ObjectProperty) {
|
29896
|
+
// setter or getter, since KeyVal is handled above
|
29897
|
+
if (
|
29898
|
+
has_annotation(node, _MANGLEPROP)
|
29899
|
+
&& can_mangle(node.key.name)
|
29900
|
+
) {
|
29901
|
+
annotated_names.add(node.key.name);
|
29902
|
+
clear_annotation(node, _MANGLEPROP);
|
29903
|
+
}
|
29904
|
+
}
|
29905
|
+
});
|
29906
|
+
|
29907
|
+
// step 2: find candidates to mangle
|
29859
29908
|
ast.walk(new TreeWalker(function(node) {
|
29860
29909
|
if (
|
29861
29910
|
node instanceof AST_ClassPrivateProperty
|
@@ -29947,15 +29996,19 @@ function mangle_properties(ast, options) {
|
|
29947
29996
|
}
|
29948
29997
|
|
29949
29998
|
function should_mangle(name) {
|
29950
|
-
if (
|
29999
|
+
if (only_annotated && !annotated_names.has(name)) return false;
|
30000
|
+
if (regex && !regex.test(name)) {
|
30001
|
+
return annotated_names.has(name);
|
30002
|
+
}
|
29951
30003
|
if (reserved.has(name)) return false;
|
29952
30004
|
return cache.has(name)
|
29953
30005
|
|| names_to_mangle.has(name);
|
29954
30006
|
}
|
29955
30007
|
|
29956
30008
|
function add(name) {
|
29957
|
-
if (can_mangle(name))
|
30009
|
+
if (can_mangle(name)) {
|
29958
30010
|
names_to_mangle.add(name);
|
30011
|
+
}
|
29959
30012
|
|
29960
30013
|
if (!should_mangle(name)) {
|
29961
30014
|
unmangleable.add(name);
|
@@ -30842,4 +30895,4 @@ exports._default_options = _default_options;
|
|
30842
30895
|
exports._run_cli = run_cli;
|
30843
30896
|
exports.minify = minify;
|
30844
30897
|
|
30845
|
-
}))
|
30898
|
+
}));
|
package/lib/ast.js
CHANGED
@@ -2013,6 +2013,7 @@ var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", function AST_Obj
|
|
2013
2013
|
this.value = props.value;
|
2014
2014
|
this.start = props.start;
|
2015
2015
|
this.end = props.end;
|
2016
|
+
this._annotations = props._annotations;
|
2016
2017
|
}
|
2017
2018
|
|
2018
2019
|
this.flags = 0;
|
@@ -2042,6 +2043,7 @@ var AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", "quote", function AST_ObjectKeyVa
|
|
2042
2043
|
this.value = props.value;
|
2043
2044
|
this.start = props.start;
|
2044
2045
|
this.end = props.end;
|
2046
|
+
this._annotations = props._annotations;
|
2045
2047
|
}
|
2046
2048
|
|
2047
2049
|
this.flags = 0;
|
@@ -2103,6 +2105,7 @@ var AST_ObjectSetter = DEFNODE("ObjectSetter", "quote static", function AST_Obje
|
|
2103
2105
|
this.value = props.value;
|
2104
2106
|
this.start = props.start;
|
2105
2107
|
this.end = props.end;
|
2108
|
+
this._annotations = props._annotations;
|
2106
2109
|
}
|
2107
2110
|
|
2108
2111
|
this.flags = 0;
|
@@ -2125,6 +2128,7 @@ var AST_ObjectGetter = DEFNODE("ObjectGetter", "quote static", function AST_Obje
|
|
2125
2128
|
this.value = props.value;
|
2126
2129
|
this.start = props.start;
|
2127
2130
|
this.end = props.end;
|
2131
|
+
this._annotations = props._annotations;
|
2128
2132
|
}
|
2129
2133
|
|
2130
2134
|
this.flags = 0;
|
@@ -2152,6 +2156,7 @@ var AST_ConciseMethod = DEFNODE(
|
|
2152
2156
|
this.value = props.value;
|
2153
2157
|
this.start = props.start;
|
2154
2158
|
this.end = props.end;
|
2159
|
+
this._annotations = props._annotations;
|
2155
2160
|
}
|
2156
2161
|
|
2157
2162
|
this.flags = 0;
|
@@ -2274,6 +2279,7 @@ var AST_ClassProperty = DEFNODE("ClassProperty", "static quote", function AST_Cl
|
|
2274
2279
|
this.value = props.value;
|
2275
2280
|
this.start = props.start;
|
2276
2281
|
this.end = props.end;
|
2282
|
+
this._annotations = props._annotations;
|
2277
2283
|
}
|
2278
2284
|
|
2279
2285
|
this.flags = 0;
|
@@ -3177,10 +3183,11 @@ class TreeTransformer extends TreeWalker {
|
|
3177
3183
|
}
|
3178
3184
|
}
|
3179
3185
|
|
3180
|
-
const _PURE
|
3181
|
-
const _INLINE
|
3182
|
-
const _NOINLINE
|
3183
|
-
const _KEY
|
3186
|
+
const _PURE = 0b00000001;
|
3187
|
+
const _INLINE = 0b00000010;
|
3188
|
+
const _NOINLINE = 0b00000100;
|
3189
|
+
const _KEY = 0b00001000;
|
3190
|
+
const _MANGLEPROP = 0b00010000;
|
3184
3191
|
|
3185
3192
|
export {
|
3186
3193
|
AST_Accessor,
|
@@ -3326,4 +3333,5 @@ export {
|
|
3326
3333
|
_NOINLINE,
|
3327
3334
|
_PURE,
|
3328
3335
|
_KEY,
|
3336
|
+
_MANGLEPROP,
|
3329
3337
|
};
|
package/lib/parse.js
CHANGED
@@ -163,7 +163,8 @@ import {
|
|
163
163
|
_INLINE,
|
164
164
|
_NOINLINE,
|
165
165
|
_PURE,
|
166
|
-
_KEY
|
166
|
+
_KEY,
|
167
|
+
_MANGLEPROP,
|
167
168
|
} from "./ast.js";
|
168
169
|
|
169
170
|
var LATEST_RAW = ""; // Only used for numbers and template strings
|
@@ -2226,7 +2227,7 @@ function parse($TEXT, options) {
|
|
2226
2227
|
value : tok.value,
|
2227
2228
|
quote : tok.quote
|
2228
2229
|
});
|
2229
|
-
annotate(ret);
|
2230
|
+
annotate(ret);
|
2230
2231
|
break;
|
2231
2232
|
case "regexp":
|
2232
2233
|
const [_, source, flags] = tok.value.match(/^\/(.*)\/(\w*)$/);
|
@@ -2538,13 +2539,14 @@ function parse($TEXT, options) {
|
|
2538
2539
|
}
|
2539
2540
|
|
2540
2541
|
// Create property
|
2541
|
-
|
2542
|
+
const kv = new AST_ObjectKeyVal({
|
2542
2543
|
start: start,
|
2543
2544
|
quote: start.quote,
|
2544
2545
|
key: name instanceof AST_Node ? name : "" + name,
|
2545
2546
|
value: value,
|
2546
2547
|
end: prev()
|
2547
|
-
})
|
2548
|
+
});
|
2549
|
+
a.push(annotate(kv));
|
2548
2550
|
}
|
2549
2551
|
next();
|
2550
2552
|
return new AST_Object({ properties: a });
|
@@ -2657,26 +2659,26 @@ function parse($TEXT, options) {
|
|
2657
2659
|
: AST_ObjectSetter;
|
2658
2660
|
|
2659
2661
|
name = get_symbol_ast(name);
|
2660
|
-
return new AccessorClass({
|
2662
|
+
return annotate(new AccessorClass({
|
2661
2663
|
start,
|
2662
2664
|
static: is_static,
|
2663
2665
|
key: name,
|
2664
2666
|
quote: name instanceof AST_SymbolMethod ? property_token.quote : undefined,
|
2665
2667
|
value: create_accessor(),
|
2666
2668
|
end: prev()
|
2667
|
-
});
|
2669
|
+
}));
|
2668
2670
|
} else {
|
2669
2671
|
const AccessorClass = accessor_type === "get"
|
2670
2672
|
? AST_PrivateGetter
|
2671
2673
|
: AST_PrivateSetter;
|
2672
2674
|
|
2673
|
-
return new AccessorClass({
|
2675
|
+
return annotate(new AccessorClass({
|
2674
2676
|
start,
|
2675
2677
|
static: is_static,
|
2676
2678
|
key: get_symbol_ast(name),
|
2677
2679
|
value: create_accessor(),
|
2678
2680
|
end: prev(),
|
2679
|
-
});
|
2681
|
+
}));
|
2680
2682
|
}
|
2681
2683
|
}
|
2682
2684
|
|
@@ -2696,7 +2698,7 @@ function parse($TEXT, options) {
|
|
2696
2698
|
value : create_accessor(is_generator, is_async),
|
2697
2699
|
end : prev()
|
2698
2700
|
});
|
2699
|
-
return node;
|
2701
|
+
return annotate(node);
|
2700
2702
|
}
|
2701
2703
|
|
2702
2704
|
if (is_class) {
|
@@ -2709,14 +2711,16 @@ function parse($TEXT, options) {
|
|
2709
2711
|
: AST_ClassProperty;
|
2710
2712
|
if (is("operator", "=")) {
|
2711
2713
|
next();
|
2712
|
-
return
|
2713
|
-
|
2714
|
-
|
2715
|
-
|
2716
|
-
|
2717
|
-
|
2718
|
-
|
2719
|
-
|
2714
|
+
return annotate(
|
2715
|
+
new AST_ClassPropertyVariant({
|
2716
|
+
start,
|
2717
|
+
static: is_static,
|
2718
|
+
quote,
|
2719
|
+
key,
|
2720
|
+
value: expression(false),
|
2721
|
+
end: prev()
|
2722
|
+
})
|
2723
|
+
);
|
2720
2724
|
} else if (
|
2721
2725
|
is("name")
|
2722
2726
|
|| is("privatename")
|
@@ -2724,13 +2728,15 @@ function parse($TEXT, options) {
|
|
2724
2728
|
|| is("punc", ";")
|
2725
2729
|
|| is("punc", "}")
|
2726
2730
|
) {
|
2727
|
-
return
|
2728
|
-
|
2729
|
-
|
2730
|
-
|
2731
|
-
|
2732
|
-
|
2733
|
-
|
2731
|
+
return annotate(
|
2732
|
+
new AST_ClassPropertyVariant({
|
2733
|
+
start,
|
2734
|
+
static: is_static,
|
2735
|
+
quote,
|
2736
|
+
key,
|
2737
|
+
end: prev()
|
2738
|
+
})
|
2739
|
+
);
|
2734
2740
|
}
|
2735
2741
|
}
|
2736
2742
|
}
|
@@ -3093,10 +3099,9 @@ function parse($TEXT, options) {
|
|
3093
3099
|
}
|
3094
3100
|
|
3095
3101
|
// Annotate AST_Call, AST_Lambda or AST_New with the special comments
|
3096
|
-
function annotate(node) {
|
3097
|
-
var
|
3098
|
-
|
3099
|
-
const comments_outside_parens = outer_comments_before_counts.get(start);
|
3102
|
+
function annotate(node, before_token = node.start) {
|
3103
|
+
var comments = before_token.comments_before;
|
3104
|
+
const comments_outside_parens = outer_comments_before_counts.get(before_token);
|
3100
3105
|
var i = comments_outside_parens != null ? comments_outside_parens : comments.length;
|
3101
3106
|
while (--i >= 0) {
|
3102
3107
|
var comment = comments[i];
|
@@ -3117,8 +3122,13 @@ function parse($TEXT, options) {
|
|
3117
3122
|
set_annotation(node, _KEY);
|
3118
3123
|
break;
|
3119
3124
|
}
|
3125
|
+
if (/[@#]__MANGLE_PROP__/.test(comment.value)) {
|
3126
|
+
set_annotation(node, _MANGLEPROP);
|
3127
|
+
break;
|
3128
|
+
}
|
3120
3129
|
}
|
3121
3130
|
}
|
3131
|
+
return node;
|
3122
3132
|
}
|
3123
3133
|
|
3124
3134
|
var subscripts = function(expr, allow_calls, is_chain) {
|
package/lib/propmangle.js
CHANGED
@@ -70,6 +70,9 @@ import {
|
|
70
70
|
TreeTransformer,
|
71
71
|
TreeWalker,
|
72
72
|
_KEY,
|
73
|
+
_MANGLEPROP,
|
74
|
+
|
75
|
+
walk,
|
73
76
|
} from "./ast.js";
|
74
77
|
import { domprops } from "../tools/domprops.js";
|
75
78
|
|
@@ -188,6 +191,7 @@ function mangle_properties(ast, options) {
|
|
188
191
|
regex: null,
|
189
192
|
reserved: null,
|
190
193
|
undeclared: false,
|
194
|
+
only_annotated: false,
|
191
195
|
}, true);
|
192
196
|
|
193
197
|
var nth_identifier = options.nth_identifier;
|
@@ -206,6 +210,7 @@ function mangle_properties(ast, options) {
|
|
206
210
|
cache = new Map();
|
207
211
|
}
|
208
212
|
|
213
|
+
var only_annotated = options.only_annotated;
|
209
214
|
var regex = options.regex && new RegExp(options.regex);
|
210
215
|
|
211
216
|
// note debug is either false (disabled), or a string of the debug suffix to use (enabled).
|
@@ -217,6 +222,7 @@ function mangle_properties(ast, options) {
|
|
217
222
|
debug_name_suffix = (options.debug === true ? "" : options.debug);
|
218
223
|
}
|
219
224
|
|
225
|
+
var annotated_names = new Set();
|
220
226
|
var names_to_mangle = new Set();
|
221
227
|
var unmangleable = new Set();
|
222
228
|
// Track each already-mangled name to prevent nth_identifier from generating
|
@@ -225,7 +231,38 @@ function mangle_properties(ast, options) {
|
|
225
231
|
|
226
232
|
var keep_quoted = !!options.keep_quoted;
|
227
233
|
|
228
|
-
//
|
234
|
+
// Step 1: Find all annotated /*@__MANGLEPROP__*/
|
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
|
229
266
|
ast.walk(new TreeWalker(function(node) {
|
230
267
|
if (
|
231
268
|
node instanceof AST_ClassPrivateProperty
|
@@ -321,15 +358,19 @@ function mangle_properties(ast, options) {
|
|
321
358
|
}
|
322
359
|
|
323
360
|
function should_mangle(name) {
|
324
|
-
if (
|
361
|
+
if (only_annotated && !annotated_names.has(name)) return false;
|
362
|
+
if (regex && !regex.test(name)) {
|
363
|
+
return annotated_names.has(name);
|
364
|
+
}
|
325
365
|
if (reserved.has(name)) return false;
|
326
366
|
return cache.has(name)
|
327
367
|
|| names_to_mangle.has(name);
|
328
368
|
}
|
329
369
|
|
330
370
|
function add(name) {
|
331
|
-
if (can_mangle(name))
|
371
|
+
if (can_mangle(name)) {
|
332
372
|
names_to_mangle.add(name);
|
373
|
+
}
|
333
374
|
|
334
375
|
if (!should_mangle(name)) {
|
335
376
|
unmangleable.add(name);
|
package/lib/utils/index.js
CHANGED
@@ -237,7 +237,7 @@ const re_safe_regexp = /^[\\/|\0\s\w^$.[\]()]*$/;
|
|
237
237
|
/** Check if the regexp is safe for Terser to create without risking a RegExp DOS */
|
238
238
|
export const regexp_is_safe = (source) => re_safe_regexp.test(source);
|
239
239
|
|
240
|
-
const all_flags = "
|
240
|
+
const all_flags = "dgimsuyv";
|
241
241
|
function sort_regexp_flags(flags) {
|
242
242
|
const existing_flags = new Set(flags.split(""));
|
243
243
|
let out = "";
|
package/package.json
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
"homepage": "https://terser.org",
|
5
5
|
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
6
6
|
"license": "BSD-2-Clause",
|
7
|
-
"version": "5.
|
7
|
+
"version": "5.18.0",
|
8
8
|
"engines": {
|
9
9
|
"node": ">=10"
|
10
10
|
},
|
@@ -44,22 +44,21 @@
|
|
44
44
|
"main.js"
|
45
45
|
],
|
46
46
|
"dependencies": {
|
47
|
-
"@jridgewell/source-map": "^0.3.
|
48
|
-
"acorn": "^8.
|
47
|
+
"@jridgewell/source-map": "^0.3.3",
|
48
|
+
"acorn": "^8.8.2",
|
49
49
|
"commander": "^2.20.0",
|
50
50
|
"source-map-support": "~0.5.20"
|
51
51
|
},
|
52
52
|
"devDependencies": {
|
53
|
-
"@ls-lint/ls-lint": "^1.
|
54
|
-
"astring": "^1.
|
53
|
+
"@ls-lint/ls-lint": "^1.11.2",
|
54
|
+
"astring": "^1.8.5",
|
55
55
|
"eslint": "^7.32.0",
|
56
56
|
"eslump": "^3.0.0",
|
57
57
|
"esm": "^3.2.25",
|
58
58
|
"mocha": "^9.2.0",
|
59
59
|
"pre-commit": "^1.2.2",
|
60
|
-
"
|
61
|
-
"
|
62
|
-
"semver": "^7.3.4",
|
60
|
+
"rollup": "^2.56.3",
|
61
|
+
"semver": "^7.5.1",
|
63
62
|
"source-map": "~0.8.0-beta.0"
|
64
63
|
},
|
65
64
|
"scripts": {
|
@@ -69,7 +68,7 @@
|
|
69
68
|
"lint": "eslint lib",
|
70
69
|
"lint-fix": "eslint --fix lib",
|
71
70
|
"ls-lint": "ls-lint",
|
72
|
-
"build": "
|
71
|
+
"build": "rollup --config --silent",
|
73
72
|
"prepare": "npm run build",
|
74
73
|
"postversion": "echo 'Remember to update the changelog!'"
|
75
74
|
},
|