terser 5.46.1 → 5.47.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 +11 -0
- package/README.md +4 -0
- package/dist/bundle.min.js +425 -57
- package/lib/compress/drop-side-effect-free.js +2 -2
- package/lib/compress/drop-unused.js +2 -0
- package/lib/compress/evaluate.js +3 -4
- package/lib/compress/index.js +10 -2
- package/lib/compress/inference.js +5 -9
- package/lib/compress/native-objects.js +372 -40
- package/lib/equivalent-to.js +4 -1
- package/lib/utils/index.js +1 -1
- package/package.json +1 -1
- package/tools/domprops.js +30 -0
- package/tools/terser.d.ts +3 -1
package/dist/bundle.min.js
CHANGED
|
@@ -81,7 +81,7 @@ function defaults(args, defs, croak) {
|
|
|
81
81
|
for (const i in defs) if (HOP(defs, i)) {
|
|
82
82
|
if (!args || !HOP(args, i)) {
|
|
83
83
|
ret[i] = defs[i];
|
|
84
|
-
} else if (i === "ecma") {
|
|
84
|
+
} else if (i === "ecma" || i === "builtins_ecma") {
|
|
85
85
|
let ecma = args[i] | 0;
|
|
86
86
|
if (ecma > 5 && ecma < 2015) ecma += 2009;
|
|
87
87
|
ret[i] = ecma;
|
|
@@ -11913,7 +11913,10 @@ AST_PropAccess.prototype.shallow_cmp = pass_through;
|
|
|
11913
11913
|
AST_Chain.prototype.shallow_cmp = pass_through;
|
|
11914
11914
|
|
|
11915
11915
|
AST_Dot.prototype.shallow_cmp = function(other) {
|
|
11916
|
-
return
|
|
11916
|
+
return (
|
|
11917
|
+
this.property === other.property
|
|
11918
|
+
&& !!this.quote === !!other.quote
|
|
11919
|
+
);
|
|
11917
11920
|
};
|
|
11918
11921
|
|
|
11919
11922
|
AST_DotHash.prototype.shallow_cmp = function(other) {
|
|
@@ -13848,10 +13851,14 @@ function retain_top_func(fn, compressor) {
|
|
|
13848
13851
|
// Note: Lots of methods and functions are missing here, in case they aren't pure
|
|
13849
13852
|
// or not available in all JS environments.
|
|
13850
13853
|
|
|
13851
|
-
|
|
13854
|
+
const make_nested_lookup = (feature_callback) => (compressor) => {
|
|
13855
|
+
const obj = feature_callback(feature_variables(compressor));
|
|
13856
|
+
|
|
13852
13857
|
const out = new Map();
|
|
13853
13858
|
for (var key of Object.keys(obj)) {
|
|
13854
|
-
|
|
13859
|
+
if (obj[key]) {
|
|
13860
|
+
out.set(key, makePredicate(remove_false(obj[key])));
|
|
13861
|
+
}
|
|
13855
13862
|
}
|
|
13856
13863
|
|
|
13857
13864
|
const does_have = (global_name, fname) => {
|
|
@@ -13859,8 +13866,74 @@ function make_nested_lookup(obj) {
|
|
|
13859
13866
|
return inner_map != null && inner_map.has(fname);
|
|
13860
13867
|
};
|
|
13861
13868
|
return does_have;
|
|
13869
|
+
};
|
|
13870
|
+
|
|
13871
|
+
const make_lookup = (feature_callback) => (compressor) => {
|
|
13872
|
+
const obj = feature_callback(feature_variables(compressor));
|
|
13873
|
+
|
|
13874
|
+
const predicate = makePredicate(remove_false(obj));
|
|
13875
|
+
const does_have = (global_name) => {
|
|
13876
|
+
return predicate.has(global_name);
|
|
13877
|
+
};
|
|
13878
|
+
return does_have;
|
|
13879
|
+
};
|
|
13880
|
+
|
|
13881
|
+
function remove_false(arr) {
|
|
13882
|
+
for (let i = 0; i < arr.length; i++) {
|
|
13883
|
+
if (arr[i] === false) {
|
|
13884
|
+
arr.splice(i, 1);
|
|
13885
|
+
i--;
|
|
13886
|
+
}
|
|
13887
|
+
}
|
|
13888
|
+
return arr;
|
|
13862
13889
|
}
|
|
13863
13890
|
|
|
13891
|
+
/** Generate the object with arguments seen below */
|
|
13892
|
+
function feature_variables(compressor) {
|
|
13893
|
+
return {
|
|
13894
|
+
sloppy: compressor.option("unsafe"),
|
|
13895
|
+
es: compressor.option("builtins_ecma"),
|
|
13896
|
+
};
|
|
13897
|
+
}
|
|
13898
|
+
|
|
13899
|
+
// eslint-disable-next-line no-unused-vars
|
|
13900
|
+
const pure_access_globals = make_lookup(({ sloppy, es }) => [
|
|
13901
|
+
"Array",
|
|
13902
|
+
"Boolean",
|
|
13903
|
+
"clearInterval",
|
|
13904
|
+
"clearTimeout",
|
|
13905
|
+
"console",
|
|
13906
|
+
"Date",
|
|
13907
|
+
"decodeURI",
|
|
13908
|
+
"decodeURIComponent",
|
|
13909
|
+
"encodeURI",
|
|
13910
|
+
"encodeURIComponent",
|
|
13911
|
+
"Error",
|
|
13912
|
+
"escape",
|
|
13913
|
+
"eval",
|
|
13914
|
+
"EvalError",
|
|
13915
|
+
"Function",
|
|
13916
|
+
es >= 2020 && "globalThis",
|
|
13917
|
+
"isFinite",
|
|
13918
|
+
"isNaN",
|
|
13919
|
+
"JSON",
|
|
13920
|
+
"Math",
|
|
13921
|
+
"Number",
|
|
13922
|
+
"parseFloat",
|
|
13923
|
+
"parseInt",
|
|
13924
|
+
"RangeError",
|
|
13925
|
+
"ReferenceError",
|
|
13926
|
+
"RegExp",
|
|
13927
|
+
"Object",
|
|
13928
|
+
"setInterval",
|
|
13929
|
+
"setTimeout",
|
|
13930
|
+
"String",
|
|
13931
|
+
"SyntaxError",
|
|
13932
|
+
"TypeError",
|
|
13933
|
+
"unescape",
|
|
13934
|
+
"URIError",
|
|
13935
|
+
]);
|
|
13936
|
+
|
|
13864
13937
|
// Objects which are safe to access without throwing or causing a side effect.
|
|
13865
13938
|
// Usually we'd check the `unsafe` option first but these are way too common for that
|
|
13866
13939
|
const pure_prop_access_globals = new Set([
|
|
@@ -13872,17 +13945,90 @@ const pure_prop_access_globals = new Set([
|
|
|
13872
13945
|
"Promise",
|
|
13873
13946
|
]);
|
|
13874
13947
|
|
|
13948
|
+
// eslint-disable-next-line no-unused-vars
|
|
13949
|
+
const is_pure_native_fn = make_lookup(({ sloppy, es }) => [
|
|
13950
|
+
sloppy && es >= 2021 && "AggregateError",
|
|
13951
|
+
"Array",
|
|
13952
|
+
"ArrayBuffer",
|
|
13953
|
+
es >= 2020 && "BigInt",
|
|
13954
|
+
es >= 2020 && "BigInt64Array",
|
|
13955
|
+
es >= 2020 && "BigUint64Array",
|
|
13956
|
+
"Boolean",
|
|
13957
|
+
"Date",
|
|
13958
|
+
sloppy && "decodeURI",
|
|
13959
|
+
sloppy && "decodeURIComponent",
|
|
13960
|
+
sloppy && "encodeURI",
|
|
13961
|
+
sloppy && "encodeURIComponent",
|
|
13962
|
+
"Error",
|
|
13963
|
+
"escape",
|
|
13964
|
+
"EvalError",
|
|
13965
|
+
es >= 2021 && "FinalizationRegistry",
|
|
13966
|
+
es >= 2026 && "Float16Array",
|
|
13967
|
+
"Float32Array",
|
|
13968
|
+
"Float64Array",
|
|
13969
|
+
"Int16Array",
|
|
13970
|
+
"Int32Array",
|
|
13971
|
+
"Int8Array",
|
|
13972
|
+
"isFinite",
|
|
13973
|
+
"isNaN",
|
|
13974
|
+
es >= 2026 && "Iterator",
|
|
13975
|
+
es >= 2015 && "Map",
|
|
13976
|
+
"Number",
|
|
13977
|
+
"parseFloat",
|
|
13978
|
+
"parseInt",
|
|
13979
|
+
es >= 2015 && "Promise",
|
|
13980
|
+
es >= 2015 && "Proxy",
|
|
13981
|
+
"RangeError",
|
|
13982
|
+
"ReferenceError",
|
|
13983
|
+
sloppy && "RegExp",
|
|
13984
|
+
es >= 2015 && "Set",
|
|
13985
|
+
"String",
|
|
13986
|
+
es >= 2015 && "Symbol",
|
|
13987
|
+
"SyntaxError",
|
|
13988
|
+
"TypeError",
|
|
13989
|
+
"Uint16Array",
|
|
13990
|
+
"Uint32Array",
|
|
13991
|
+
"Uint8Array",
|
|
13992
|
+
"Uint8ClampedArray",
|
|
13993
|
+
sloppy && "unescape",
|
|
13994
|
+
"URIError",
|
|
13995
|
+
sloppy && es >= 2015 && "WeakMap",
|
|
13996
|
+
sloppy && es >= 2021 && "WeakRef",
|
|
13997
|
+
sloppy && es >= 2015 && "WeakSet",
|
|
13998
|
+
]);
|
|
13999
|
+
|
|
14000
|
+
const arg1_is_iterable = new Set([
|
|
14001
|
+
"Map",
|
|
14002
|
+
"Set",
|
|
14003
|
+
"WeakMap",
|
|
14004
|
+
"WeakSet",
|
|
14005
|
+
]);
|
|
14006
|
+
const arg1_is_range_or_iterable = new Set([
|
|
14007
|
+
"ArrayBuffer",
|
|
14008
|
+
"Float32Array",
|
|
14009
|
+
"Float64Array",
|
|
14010
|
+
"Int16Array",
|
|
14011
|
+
"Int32Array",
|
|
14012
|
+
"Int8Array",
|
|
14013
|
+
"Uint16Array",
|
|
14014
|
+
"Uint32Array",
|
|
14015
|
+
"Uint8Array",
|
|
14016
|
+
"Uint8ClampedArray",
|
|
14017
|
+
]);
|
|
14018
|
+
const lone_arg_is_range = new Set(["Array"]);
|
|
14019
|
+
|
|
13875
14020
|
const object_methods = [
|
|
13876
14021
|
"constructor",
|
|
13877
14022
|
"toString",
|
|
13878
14023
|
"valueOf",
|
|
13879
14024
|
];
|
|
13880
14025
|
|
|
13881
|
-
|
|
14026
|
+
// eslint-disable-next-line no-unused-vars
|
|
14027
|
+
const is_pure_native_method = make_nested_lookup(({ sloppy, es }) => ({
|
|
13882
14028
|
Array: [
|
|
13883
|
-
"at",
|
|
13884
|
-
"flat",
|
|
13885
|
-
"includes",
|
|
14029
|
+
es >= 2022 && "at",
|
|
14030
|
+
es >= 2019 && "flat",
|
|
14031
|
+
es >= 2016 && "includes",
|
|
13886
14032
|
"indexOf",
|
|
13887
14033
|
"join",
|
|
13888
14034
|
"lastIndexOf",
|
|
@@ -13903,90 +14049,160 @@ const is_pure_native_method = make_nested_lookup({
|
|
|
13903
14049
|
...object_methods,
|
|
13904
14050
|
],
|
|
13905
14051
|
String: [
|
|
13906
|
-
"at",
|
|
14052
|
+
es >= 2022 && "at",
|
|
13907
14053
|
"charAt",
|
|
13908
14054
|
"charCodeAt",
|
|
13909
|
-
"
|
|
14055
|
+
es >= 2015 && "codePointAt",
|
|
13910
14056
|
"concat",
|
|
13911
|
-
"endsWith",
|
|
13912
|
-
"
|
|
13913
|
-
"fromCodePoint",
|
|
13914
|
-
"includes",
|
|
14057
|
+
es >= 2025 && "endsWith",
|
|
14058
|
+
es >= 2015 && "includes",
|
|
13915
14059
|
"indexOf",
|
|
13916
14060
|
"italics",
|
|
13917
14061
|
"lastIndexOf",
|
|
13918
|
-
"localeCompare",
|
|
14062
|
+
es >= 2020 && "localeCompare",
|
|
13919
14063
|
"match",
|
|
13920
|
-
"matchAll",
|
|
13921
|
-
"normalize",
|
|
13922
|
-
"padStart",
|
|
13923
|
-
"padEnd",
|
|
13924
|
-
"repeat",
|
|
14064
|
+
es >= 2020 && "matchAll",
|
|
14065
|
+
es >= 2015 && "normalize",
|
|
14066
|
+
es >= 2017 && "padStart",
|
|
14067
|
+
es >= 2017 && "padEnd",
|
|
14068
|
+
es >= 2015 && sloppy && "repeat",
|
|
13925
14069
|
"replace",
|
|
13926
|
-
"replaceAll",
|
|
14070
|
+
es >= 2021 && "replaceAll",
|
|
13927
14071
|
"search",
|
|
13928
14072
|
"slice",
|
|
13929
14073
|
"split",
|
|
13930
|
-
"startsWith",
|
|
14074
|
+
es >= 2015 && "startsWith",
|
|
13931
14075
|
"substr",
|
|
13932
14076
|
"substring",
|
|
13933
|
-
"repeat",
|
|
14077
|
+
es >= 2015 && "repeat",
|
|
13934
14078
|
"toLocaleLowerCase",
|
|
13935
14079
|
"toLocaleUpperCase",
|
|
13936
14080
|
"toLowerCase",
|
|
13937
14081
|
"toUpperCase",
|
|
13938
14082
|
"trim",
|
|
13939
|
-
"trimEnd",
|
|
13940
|
-
"trimStart",
|
|
14083
|
+
es >= 2019 && "trimEnd",
|
|
14084
|
+
es >= 2019 && "trimStart",
|
|
14085
|
+
es >= 2019 && "trimLeft",
|
|
14086
|
+
es >= 2019 && "trimRight",
|
|
13941
14087
|
...object_methods,
|
|
13942
14088
|
],
|
|
13943
|
-
});
|
|
14089
|
+
}));
|
|
13944
14090
|
|
|
13945
|
-
|
|
14091
|
+
// eslint-disable-next-line no-unused-vars
|
|
14092
|
+
const is_pure_native_static_fn = make_nested_lookup(({ sloppy, es }) => ({
|
|
13946
14093
|
Array: [
|
|
13947
14094
|
"isArray",
|
|
14095
|
+
es >= 2015 && "of",
|
|
14096
|
+
],
|
|
14097
|
+
ArrayBuffer: [
|
|
14098
|
+
"isView",
|
|
14099
|
+
],
|
|
14100
|
+
BigInt: es >= 2020 && [
|
|
14101
|
+
sloppy && "asIntN",
|
|
14102
|
+
sloppy && "asUintN",
|
|
14103
|
+
],
|
|
14104
|
+
BigInt64Array: sloppy && es >= 2020 && ["of"],
|
|
14105
|
+
BigUint64Array: sloppy && es >= 2020 && ["of"],
|
|
14106
|
+
Date: [
|
|
14107
|
+
"now",
|
|
14108
|
+
"parse",
|
|
14109
|
+
"UTC",
|
|
13948
14110
|
],
|
|
14111
|
+
Error: [
|
|
14112
|
+
es >= 2026 && "isError",
|
|
14113
|
+
],
|
|
14114
|
+
Float16Array: sloppy && es >= 2026 && ["of"],
|
|
14115
|
+
Float32Array: sloppy && ["of"],
|
|
14116
|
+
Float64Array: sloppy && ["of"],
|
|
14117
|
+
Int16Array: sloppy && ["of"],
|
|
14118
|
+
Int32Array: sloppy && ["of"],
|
|
14119
|
+
Int8Array: sloppy && ["of"],
|
|
13949
14120
|
Math: [
|
|
13950
14121
|
"abs",
|
|
13951
14122
|
"acos",
|
|
14123
|
+
es >= 2015 && "acosh",
|
|
13952
14124
|
"asin",
|
|
14125
|
+
es >= 2015 && "asinh",
|
|
13953
14126
|
"atan",
|
|
14127
|
+
"atan2",
|
|
14128
|
+
es >= 2015 && "atanh",
|
|
14129
|
+
es >= 2015 && "cbrt",
|
|
13954
14130
|
"ceil",
|
|
14131
|
+
es >= 2015 && "clz32",
|
|
13955
14132
|
"cos",
|
|
14133
|
+
es >= 2015 && "cosh",
|
|
13956
14134
|
"exp",
|
|
14135
|
+
es >= 2015 && "expm1",
|
|
13957
14136
|
"floor",
|
|
14137
|
+
es >= 2026 && "f16round",
|
|
14138
|
+
es >= 2015 && "fround",
|
|
14139
|
+
es >= 2015 && "hypot",
|
|
14140
|
+
es >= 2015 && "imul",
|
|
13958
14141
|
"log",
|
|
14142
|
+
es >= 2015 && "log10",
|
|
14143
|
+
es >= 2015 && "log1p",
|
|
14144
|
+
es >= 2015 && "log2",
|
|
14145
|
+
"max",
|
|
14146
|
+
"min",
|
|
14147
|
+
"pow",
|
|
13959
14148
|
"round",
|
|
14149
|
+
es >= 2015 && "sign",
|
|
13960
14150
|
"sin",
|
|
14151
|
+
es >= 2015 && "sinh",
|
|
13961
14152
|
"sqrt",
|
|
13962
14153
|
"tan",
|
|
13963
|
-
"
|
|
13964
|
-
"
|
|
13965
|
-
"max",
|
|
13966
|
-
"min",
|
|
14154
|
+
es >= 2015 && "tanh",
|
|
14155
|
+
es >= 2015 && "trunc",
|
|
13967
14156
|
],
|
|
13968
14157
|
Number: [
|
|
13969
|
-
"isFinite",
|
|
13970
|
-
"
|
|
14158
|
+
es >= 2015 && "isFinite",
|
|
14159
|
+
es >= 2015 && "isInteger",
|
|
14160
|
+
es >= 2015 && "isSafeInteger",
|
|
14161
|
+
es >= 2015 && "isNaN",
|
|
14162
|
+
es >= 2015 && "parseFloat",
|
|
14163
|
+
es >= 2015 && "parseInt",
|
|
13971
14164
|
],
|
|
13972
14165
|
Object: [
|
|
13973
|
-
"create",
|
|
13974
|
-
"getOwnPropertyDescriptor",
|
|
13975
|
-
"
|
|
13976
|
-
"
|
|
14166
|
+
sloppy && "create",
|
|
14167
|
+
sloppy && "getOwnPropertyDescriptor",
|
|
14168
|
+
es >= 2017 && sloppy && "getOwnPropertyDescriptors",
|
|
14169
|
+
sloppy && "getOwnPropertyNames",
|
|
14170
|
+
es >= 2015 && sloppy && "getOwnPropertySymbols",
|
|
14171
|
+
sloppy && "getPrototypeOf",
|
|
14172
|
+
es >= 2022 && sloppy && "hasOwn",
|
|
14173
|
+
es >= 2015 && "is",
|
|
13977
14174
|
"isExtensible",
|
|
13978
14175
|
"isFrozen",
|
|
13979
14176
|
"isSealed",
|
|
13980
|
-
"
|
|
13981
|
-
|
|
14177
|
+
es >= 2015 && sloppy && "keys",
|
|
14178
|
+
],
|
|
14179
|
+
Promise: es >= 2015 && [
|
|
14180
|
+
es >= 2024 && "withResolvers",
|
|
14181
|
+
],
|
|
14182
|
+
Proxy: es >= 2015 && [
|
|
14183
|
+
sloppy && "revocable",
|
|
14184
|
+
],
|
|
14185
|
+
Reflect: es >= 2015 && [
|
|
14186
|
+
sloppy && "has",
|
|
14187
|
+
sloppy && "isExtensible",
|
|
14188
|
+
sloppy && "ownKeys",
|
|
14189
|
+
],
|
|
14190
|
+
RegExp: [
|
|
14191
|
+
es >= 2026 && sloppy && "escape",
|
|
13982
14192
|
],
|
|
13983
14193
|
String: [
|
|
13984
14194
|
"fromCharCode",
|
|
14195
|
+
sloppy && es >= 2025 && "fromCodePoint",
|
|
13985
14196
|
],
|
|
13986
|
-
|
|
14197
|
+
Uint16Array: ["of"],
|
|
14198
|
+
Uint32Array: ["of"],
|
|
14199
|
+
Uint8Array: ["of"],
|
|
14200
|
+
Uint8ClampedArray: ["of"],
|
|
14201
|
+
}));
|
|
13987
14202
|
|
|
13988
14203
|
// Known numeric values which come with JS environments
|
|
13989
|
-
|
|
14204
|
+
// eslint-disable-next-line no-unused-vars
|
|
14205
|
+
const is_pure_native_static_property = make_nested_lookup(({ sloppy, es }) => ({
|
|
13990
14206
|
Math: [
|
|
13991
14207
|
"E",
|
|
13992
14208
|
"LN10",
|
|
@@ -13998,13 +14214,130 @@ const is_pure_native_value = make_nested_lookup({
|
|
|
13998
14214
|
"SQRT2",
|
|
13999
14215
|
],
|
|
14000
14216
|
Number: [
|
|
14217
|
+
es >= 2015 && "EPSILON",
|
|
14218
|
+
es >= 2015 && "MAX_SAFE_VALUE",
|
|
14001
14219
|
"MAX_VALUE",
|
|
14220
|
+
es >= 2015 && "MIN_SAFE_VALUE",
|
|
14002
14221
|
"MIN_VALUE",
|
|
14003
14222
|
"NaN",
|
|
14004
14223
|
"NEGATIVE_INFINITY",
|
|
14005
14224
|
"POSITIVE_INFINITY",
|
|
14006
14225
|
],
|
|
14007
|
-
|
|
14226
|
+
RegExp: [
|
|
14227
|
+
"$_",
|
|
14228
|
+
"$0",
|
|
14229
|
+
"$1",
|
|
14230
|
+
"$2",
|
|
14231
|
+
"$3",
|
|
14232
|
+
"$4",
|
|
14233
|
+
"$5",
|
|
14234
|
+
"$6",
|
|
14235
|
+
"$7",
|
|
14236
|
+
"$8",
|
|
14237
|
+
"$9",
|
|
14238
|
+
"input",
|
|
14239
|
+
"lastMatch",
|
|
14240
|
+
"lastParen",
|
|
14241
|
+
"leftContext",
|
|
14242
|
+
"rightContext",
|
|
14243
|
+
],
|
|
14244
|
+
}));
|
|
14245
|
+
|
|
14246
|
+
const re_uppercase_first_letter = /^[A-Z]/;
|
|
14247
|
+
function is_pure_builtin_call(compressor, call) {
|
|
14248
|
+
let builtin = "";
|
|
14249
|
+
let method = "";
|
|
14250
|
+
|
|
14251
|
+
let exp = call.expression;
|
|
14252
|
+
if (is_undeclared_ref(exp)) {
|
|
14253
|
+
builtin = exp.name;
|
|
14254
|
+
} else if (exp instanceof AST_Dot) {
|
|
14255
|
+
method = exp.property;
|
|
14256
|
+
|
|
14257
|
+
exp = exp.expression;
|
|
14258
|
+
if (is_undeclared_ref(exp)) {
|
|
14259
|
+
if (
|
|
14260
|
+
// globalThis.pureFunc()
|
|
14261
|
+
exp.name === "globalThis"
|
|
14262
|
+
&& compressor.option("builtins_ecma") >= 2020
|
|
14263
|
+
) {
|
|
14264
|
+
builtin = method;
|
|
14265
|
+
method = "";
|
|
14266
|
+
} else {
|
|
14267
|
+
// SomeBuiltin.pureFunc()
|
|
14268
|
+
builtin = exp.name;
|
|
14269
|
+
}
|
|
14270
|
+
} else if (exp instanceof AST_Dot) {
|
|
14271
|
+
if (
|
|
14272
|
+
is_undeclared_ref(exp.expression)
|
|
14273
|
+
&& exp.expression.name === "globalThis"
|
|
14274
|
+
&& compressor.option("builtins_ecma") >= 2020
|
|
14275
|
+
) {
|
|
14276
|
+
// globalThis.SomeBuiltin.pureFunc()
|
|
14277
|
+
builtin = exp.property;
|
|
14278
|
+
} else {
|
|
14279
|
+
return false;
|
|
14280
|
+
}
|
|
14281
|
+
} else {
|
|
14282
|
+
return false;
|
|
14283
|
+
}
|
|
14284
|
+
} else {
|
|
14285
|
+
return false;
|
|
14286
|
+
}
|
|
14287
|
+
|
|
14288
|
+
if (!method) {
|
|
14289
|
+
if (compressor.is_pure_native_fn(builtin)) {
|
|
14290
|
+
// some require `new`, others throw if you use it
|
|
14291
|
+
const is_new = call instanceof AST_New;
|
|
14292
|
+
const should_be_new = re_uppercase_first_letter.test(builtin); // true of all `is_pure_native_fn`
|
|
14293
|
+
if (is_new !== should_be_new) return false;
|
|
14294
|
+
|
|
14295
|
+
if (!is_builtin_pure_with_these_args(builtin, call.args)) {
|
|
14296
|
+
return false;
|
|
14297
|
+
}
|
|
14298
|
+
|
|
14299
|
+
return true;
|
|
14300
|
+
}
|
|
14301
|
+
|
|
14302
|
+
return false;
|
|
14303
|
+
} else {
|
|
14304
|
+
return compressor.is_pure_native_static_fn(builtin, method);
|
|
14305
|
+
}
|
|
14306
|
+
}
|
|
14307
|
+
|
|
14308
|
+
/** Some builtins are listed above but their purity is subject to some conditions */
|
|
14309
|
+
function is_builtin_pure_with_these_args(builtin, args) {
|
|
14310
|
+
// all the builtins we deal with here are ok with getting 0 args
|
|
14311
|
+
if (args.length === 0) return true;
|
|
14312
|
+
|
|
14313
|
+
let arg1 = args[0];
|
|
14314
|
+
if (arg1 instanceof AST_SymbolRef) {
|
|
14315
|
+
arg1 = arg1.fixed_value();
|
|
14316
|
+
}
|
|
14317
|
+
|
|
14318
|
+
if (lone_arg_is_range.has(builtin)) { // new Array(number)
|
|
14319
|
+
const arg_valid = args.length > 1
|
|
14320
|
+
|| arg1 instanceof AST_Number
|
|
14321
|
+
&& arg1.value >= 0 && arg1.value <= 0xffffffff;
|
|
14322
|
+
// TODO: or, we are asked to ignore TypeError
|
|
14323
|
+
if (!arg_valid) return false;
|
|
14324
|
+
}
|
|
14325
|
+
|
|
14326
|
+
if (arg1_is_range_or_iterable.has(builtin)) { // new Float32Array(number | Array)
|
|
14327
|
+
const arg_valid = args.length === 0
|
|
14328
|
+
|| arg1 instanceof AST_Array
|
|
14329
|
+
|| arg1 instanceof AST_Number
|
|
14330
|
+
&& arg1.value >= 0 && arg1.value <= 0xffffffff;
|
|
14331
|
+
if (!arg_valid) return false;
|
|
14332
|
+
}
|
|
14333
|
+
|
|
14334
|
+
if (arg1_is_iterable.has(builtin)) { // new Set(iterable)
|
|
14335
|
+
const arg_valid = args.length === 0 || arg1 instanceof AST_Array;
|
|
14336
|
+
if (!arg_valid) return false;
|
|
14337
|
+
}
|
|
14338
|
+
|
|
14339
|
+
return true;
|
|
14340
|
+
}
|
|
14008
14341
|
|
|
14009
14342
|
/***********************************************************************
|
|
14010
14343
|
|
|
@@ -14888,13 +15221,9 @@ AST_Call.DEFMETHOD("is_callee_pure", function(compressor) {
|
|
|
14888
15221
|
return false;
|
|
14889
15222
|
}
|
|
14890
15223
|
if (is_undeclared_ref(expr) && global_pure_fns.has(expr.name)) return true;
|
|
14891
|
-
if (
|
|
14892
|
-
|
|
14893
|
-
|
|
14894
|
-
&& is_pure_native_fn(expr.expression.name, expr.property)
|
|
14895
|
-
) {
|
|
14896
|
-
return true;
|
|
14897
|
-
}
|
|
15224
|
+
if (is_pure_builtin_call(compressor, this)) return true;
|
|
15225
|
+
} else if (compressor.option("builtins_pure")) {
|
|
15226
|
+
if (is_pure_builtin_call(compressor, this)) return true;
|
|
14898
15227
|
}
|
|
14899
15228
|
if ((this instanceof AST_New) && compressor.option("pure_new")) {
|
|
14900
15229
|
return true;
|
|
@@ -14925,7 +15254,7 @@ AST_Dot.DEFMETHOD("is_call_pure", function(compressor) {
|
|
|
14925
15254
|
} else if (!this.may_throw_on_access(compressor)) {
|
|
14926
15255
|
native_obj = "Object";
|
|
14927
15256
|
}
|
|
14928
|
-
return native_obj != null && is_pure_native_method(native_obj, this.property);
|
|
15257
|
+
return native_obj != null && compressor.is_pure_native_method(native_obj, this.property);
|
|
14929
15258
|
});
|
|
14930
15259
|
|
|
14931
15260
|
// tell me if a statement aborts
|
|
@@ -15454,7 +15783,7 @@ def_eval(AST_PropAccess, function (compressor, depth, ast_chain) {
|
|
|
15454
15783
|
if (first_arg == null || first_arg.thedef && first_arg.thedef.undeclared) {
|
|
15455
15784
|
return this.clone();
|
|
15456
15785
|
}
|
|
15457
|
-
if (!
|
|
15786
|
+
if (!compressor.is_pure_native_static_property(exp.name, key))
|
|
15458
15787
|
return this;
|
|
15459
15788
|
obj = global_objs[exp.name];
|
|
15460
15789
|
} else {
|
|
@@ -15510,14 +15839,14 @@ def_eval(AST_Call, function (compressor, depth, ast_chain) {
|
|
|
15510
15839
|
if ((first_arg == null || first_arg.thedef && first_arg.thedef.undeclared)) {
|
|
15511
15840
|
return this.clone();
|
|
15512
15841
|
}
|
|
15513
|
-
if (!
|
|
15842
|
+
if (!compressor.is_pure_native_static_fn(e.name, key)) return this;
|
|
15514
15843
|
val = global_objs[e.name];
|
|
15515
15844
|
} else {
|
|
15516
15845
|
val = e._eval(compressor, depth + 1, /* don't pass ast_chain (exponential work) */);
|
|
15517
15846
|
|
|
15518
15847
|
if (val === e || !val)
|
|
15519
15848
|
return this;
|
|
15520
|
-
if (!is_pure_native_method(val.constructor.name, key))
|
|
15849
|
+
if (!compressor.is_pure_native_method(val.constructor.name, key))
|
|
15521
15850
|
return this;
|
|
15522
15851
|
}
|
|
15523
15852
|
var args = [];
|
|
@@ -15809,8 +16138,8 @@ def_drop_side_effect_free([
|
|
|
15809
16138
|
AST_ConciseMethod,
|
|
15810
16139
|
AST_ObjectGetter,
|
|
15811
16140
|
AST_ObjectSetter,
|
|
15812
|
-
], function () {
|
|
15813
|
-
return this.computed_key() ? this.key : null;
|
|
16141
|
+
], function (compressor, first_in_statement) {
|
|
16142
|
+
return this.computed_key() ? this.key.drop_side_effect_free(compressor, first_in_statement) : null;
|
|
15814
16143
|
});
|
|
15815
16144
|
|
|
15816
16145
|
def_drop_side_effect_free([
|
|
@@ -16032,6 +16361,7 @@ AST_Scope.DEFMETHOD("drop_unused", function(compressor) {
|
|
|
16032
16361
|
return scan_ref_scoped(node, descend);
|
|
16033
16362
|
});
|
|
16034
16363
|
self.walk(tw);
|
|
16364
|
+
|
|
16035
16365
|
// pass 2: for every used symbol we need to walk its
|
|
16036
16366
|
// initialization code to figure out if it uses other
|
|
16037
16367
|
// symbols (that may not be in_use).
|
|
@@ -16042,6 +16372,7 @@ AST_Scope.DEFMETHOD("drop_unused", function(compressor) {
|
|
|
16042
16372
|
init.walk(tw);
|
|
16043
16373
|
});
|
|
16044
16374
|
});
|
|
16375
|
+
|
|
16045
16376
|
// pass 3: we should drop declarations not in_use
|
|
16046
16377
|
var tt = new TreeTransformer(
|
|
16047
16378
|
function before(node, descend, in_list) {
|
|
@@ -19301,6 +19632,8 @@ class Compressor extends TreeWalker {
|
|
|
19301
19632
|
drop_console : false,
|
|
19302
19633
|
drop_debugger : !false_by_default,
|
|
19303
19634
|
ecma : 5,
|
|
19635
|
+
builtins_ecma : 5,
|
|
19636
|
+
builtins_pure : false,
|
|
19304
19637
|
evaluate : !false_by_default,
|
|
19305
19638
|
expression : false,
|
|
19306
19639
|
global_defs : false,
|
|
@@ -19396,6 +19729,12 @@ class Compressor extends TreeWalker {
|
|
|
19396
19729
|
this._mangle_options = mangle_options
|
|
19397
19730
|
? format_mangler_options(mangle_options)
|
|
19398
19731
|
: mangle_options;
|
|
19732
|
+
|
|
19733
|
+
this.pure_access_globals = pure_access_globals(this);
|
|
19734
|
+
this.is_pure_native_fn = is_pure_native_fn(this);
|
|
19735
|
+
this.is_pure_native_method = is_pure_native_method(this);
|
|
19736
|
+
this.is_pure_native_static_fn = is_pure_native_static_fn(this);
|
|
19737
|
+
this.is_pure_native_static_property = is_pure_native_static_property(this);
|
|
19399
19738
|
}
|
|
19400
19739
|
|
|
19401
19740
|
mangle_options() {
|
|
@@ -19730,10 +20069,9 @@ function find_variable(compressor, name) {
|
|
|
19730
20069
|
return scope.find_variable(name);
|
|
19731
20070
|
}
|
|
19732
20071
|
|
|
19733
|
-
var global_names = makePredicate("Array Boolean clearInterval clearTimeout console Date decodeURI decodeURIComponent encodeURI encodeURIComponent Error escape eval EvalError Function isFinite isNaN JSON Math Number parseFloat parseInt RangeError ReferenceError RegExp Object setInterval setTimeout String SyntaxError TypeError unescape URIError");
|
|
19734
20072
|
AST_SymbolRef.DEFMETHOD("is_declared", function(compressor) {
|
|
19735
20073
|
return !this.definition().undeclared
|
|
19736
|
-
|| compressor.option("unsafe") &&
|
|
20074
|
+
|| (compressor.option("unsafe") || compressor.option("builtins_pure")) && compressor.pure_access_globals(this.name);
|
|
19737
20075
|
});
|
|
19738
20076
|
|
|
19739
20077
|
/* -----[ optimizers ]----- */
|
|
@@ -27074,6 +27412,7 @@ var domprops = [
|
|
|
27074
27412
|
"c",
|
|
27075
27413
|
"cache",
|
|
27076
27414
|
"caches",
|
|
27415
|
+
"calendar",
|
|
27077
27416
|
"call",
|
|
27078
27417
|
"caller",
|
|
27079
27418
|
"camera",
|
|
@@ -27128,6 +27467,7 @@ var domprops = [
|
|
|
27128
27467
|
"cast",
|
|
27129
27468
|
"catch",
|
|
27130
27469
|
"category",
|
|
27470
|
+
"cause",
|
|
27131
27471
|
"cbrt",
|
|
27132
27472
|
"cd",
|
|
27133
27473
|
"ceil",
|
|
@@ -27672,7 +28012,11 @@ var domprops = [
|
|
|
27672
28012
|
"databases",
|
|
27673
28013
|
"datagrams",
|
|
27674
28014
|
"dataset",
|
|
28015
|
+
"dateStyle",
|
|
27675
28016
|
"dateTime",
|
|
28017
|
+
"day",
|
|
28018
|
+
"dayPeriod",
|
|
28019
|
+
"days",
|
|
27676
28020
|
"db",
|
|
27677
28021
|
"debug",
|
|
27678
28022
|
"debuggerEnabled",
|
|
@@ -28025,6 +28369,7 @@ var domprops = [
|
|
|
28025
28369
|
"enumerateEditable",
|
|
28026
28370
|
"environmentBlendMode",
|
|
28027
28371
|
"equals",
|
|
28372
|
+
"era",
|
|
28028
28373
|
"error",
|
|
28029
28374
|
"errorCode",
|
|
28030
28375
|
"errorDetail",
|
|
@@ -28270,6 +28615,7 @@ var domprops = [
|
|
|
28270
28615
|
"forwardZ",
|
|
28271
28616
|
"foundation",
|
|
28272
28617
|
"fr",
|
|
28618
|
+
"fractionalSecondDigits",
|
|
28273
28619
|
"fragment",
|
|
28274
28620
|
"fragmentDirective",
|
|
28275
28621
|
"frame",
|
|
@@ -28800,6 +29146,10 @@ var domprops = [
|
|
|
28800
29146
|
"host",
|
|
28801
29147
|
"hostCandidate",
|
|
28802
29148
|
"hostname",
|
|
29149
|
+
"hour",
|
|
29150
|
+
"hour12",
|
|
29151
|
+
"hourCycle",
|
|
29152
|
+
"hours",
|
|
28803
29153
|
"href",
|
|
28804
29154
|
"hrefTranslate",
|
|
28805
29155
|
"hreflang",
|
|
@@ -29487,7 +29837,9 @@ var domprops = [
|
|
|
29487
29837
|
"method",
|
|
29488
29838
|
"methodDetails",
|
|
29489
29839
|
"methodName",
|
|
29840
|
+
"microseconds",
|
|
29490
29841
|
"mid",
|
|
29842
|
+
"milliseconds",
|
|
29491
29843
|
"mimeType",
|
|
29492
29844
|
"mimeTypes",
|
|
29493
29845
|
"min",
|
|
@@ -29507,6 +29859,8 @@ var domprops = [
|
|
|
29507
29859
|
"minValue",
|
|
29508
29860
|
"minWidth",
|
|
29509
29861
|
"minimumLatency",
|
|
29862
|
+
"minute",
|
|
29863
|
+
"minutes",
|
|
29510
29864
|
"mipLevel",
|
|
29511
29865
|
"mipLevelCount",
|
|
29512
29866
|
"mipmapFilter",
|
|
@@ -29519,6 +29873,8 @@ var domprops = [
|
|
|
29519
29873
|
"model",
|
|
29520
29874
|
"modify",
|
|
29521
29875
|
"module",
|
|
29876
|
+
"month",
|
|
29877
|
+
"months",
|
|
29522
29878
|
"mount",
|
|
29523
29879
|
"move",
|
|
29524
29880
|
"moveBefore",
|
|
@@ -29785,6 +30141,7 @@ var domprops = [
|
|
|
29785
30141
|
"names",
|
|
29786
30142
|
"namespaceURI",
|
|
29787
30143
|
"namespaces",
|
|
30144
|
+
"nanoseconds",
|
|
29788
30145
|
"nativeApplication",
|
|
29789
30146
|
"nativeMap",
|
|
29790
30147
|
"nativeObjectCreate",
|
|
@@ -29855,6 +30212,8 @@ var domprops = [
|
|
|
29855
30212
|
"numberOfItems",
|
|
29856
30213
|
"numberOfOutputs",
|
|
29857
30214
|
"numberValue",
|
|
30215
|
+
"numberingSystem",
|
|
30216
|
+
"numeric",
|
|
29858
30217
|
"oMatchesSelector",
|
|
29859
30218
|
"object",
|
|
29860
30219
|
"object-fit",
|
|
@@ -31202,6 +31561,8 @@ var domprops = [
|
|
|
31202
31561
|
"searchBox",
|
|
31203
31562
|
"searchBoxJavaBridge_",
|
|
31204
31563
|
"searchParams",
|
|
31564
|
+
"second",
|
|
31565
|
+
"seconds",
|
|
31205
31566
|
"sectionRowIndex",
|
|
31206
31567
|
"secureConnectionStart",
|
|
31207
31568
|
"securePaymentConfirmationAvailability",
|
|
@@ -31850,6 +32211,9 @@ var domprops = [
|
|
|
31850
32211
|
"timeOrigin",
|
|
31851
32212
|
"timeRemaining",
|
|
31852
32213
|
"timeStamp",
|
|
32214
|
+
"timeStyle",
|
|
32215
|
+
"timeZone",
|
|
32216
|
+
"timeZoneName",
|
|
31853
32217
|
"timecode",
|
|
31854
32218
|
"timeline",
|
|
31855
32219
|
"timelineTime",
|
|
@@ -32439,6 +32803,8 @@ var domprops = [
|
|
|
32439
32803
|
"webkitdirectory",
|
|
32440
32804
|
"webkitdropzone",
|
|
32441
32805
|
"webstore",
|
|
32806
|
+
"weekday",
|
|
32807
|
+
"weeks",
|
|
32442
32808
|
"weight",
|
|
32443
32809
|
"wgslLanguageFeatures",
|
|
32444
32810
|
"whatToShow",
|
|
@@ -32515,6 +32881,8 @@ var domprops = [
|
|
|
32515
32881
|
"y2",
|
|
32516
32882
|
"yChannelSelector",
|
|
32517
32883
|
"yandex",
|
|
32884
|
+
"year",
|
|
32885
|
+
"years",
|
|
32518
32886
|
"yield",
|
|
32519
32887
|
"z",
|
|
32520
32888
|
"z-index",
|