terser 5.46.2 → 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 +5 -0
- package/README.md +4 -0
- package/dist/bundle.min.js +416 -54
- 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/utils/index.js +1 -1
- package/package.json +1 -1
- package/tools/domprops.js +29 -0
- package/tools/terser.d.ts +3 -1
- package/lib/compress/import-export.js +0 -121
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;
|
|
@@ -13851,10 +13851,14 @@ function retain_top_func(fn, compressor) {
|
|
|
13851
13851
|
// Note: Lots of methods and functions are missing here, in case they aren't pure
|
|
13852
13852
|
// or not available in all JS environments.
|
|
13853
13853
|
|
|
13854
|
-
|
|
13854
|
+
const make_nested_lookup = (feature_callback) => (compressor) => {
|
|
13855
|
+
const obj = feature_callback(feature_variables(compressor));
|
|
13856
|
+
|
|
13855
13857
|
const out = new Map();
|
|
13856
13858
|
for (var key of Object.keys(obj)) {
|
|
13857
|
-
|
|
13859
|
+
if (obj[key]) {
|
|
13860
|
+
out.set(key, makePredicate(remove_false(obj[key])));
|
|
13861
|
+
}
|
|
13858
13862
|
}
|
|
13859
13863
|
|
|
13860
13864
|
const does_have = (global_name, fname) => {
|
|
@@ -13862,8 +13866,74 @@ function make_nested_lookup(obj) {
|
|
|
13862
13866
|
return inner_map != null && inner_map.has(fname);
|
|
13863
13867
|
};
|
|
13864
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;
|
|
13889
|
+
}
|
|
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
|
+
};
|
|
13865
13897
|
}
|
|
13866
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
|
+
|
|
13867
13937
|
// Objects which are safe to access without throwing or causing a side effect.
|
|
13868
13938
|
// Usually we'd check the `unsafe` option first but these are way too common for that
|
|
13869
13939
|
const pure_prop_access_globals = new Set([
|
|
@@ -13875,17 +13945,90 @@ const pure_prop_access_globals = new Set([
|
|
|
13875
13945
|
"Promise",
|
|
13876
13946
|
]);
|
|
13877
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
|
+
|
|
13878
14020
|
const object_methods = [
|
|
13879
14021
|
"constructor",
|
|
13880
14022
|
"toString",
|
|
13881
14023
|
"valueOf",
|
|
13882
14024
|
];
|
|
13883
14025
|
|
|
13884
|
-
|
|
14026
|
+
// eslint-disable-next-line no-unused-vars
|
|
14027
|
+
const is_pure_native_method = make_nested_lookup(({ sloppy, es }) => ({
|
|
13885
14028
|
Array: [
|
|
13886
|
-
"at",
|
|
13887
|
-
"flat",
|
|
13888
|
-
"includes",
|
|
14029
|
+
es >= 2022 && "at",
|
|
14030
|
+
es >= 2019 && "flat",
|
|
14031
|
+
es >= 2016 && "includes",
|
|
13889
14032
|
"indexOf",
|
|
13890
14033
|
"join",
|
|
13891
14034
|
"lastIndexOf",
|
|
@@ -13906,90 +14049,160 @@ const is_pure_native_method = make_nested_lookup({
|
|
|
13906
14049
|
...object_methods,
|
|
13907
14050
|
],
|
|
13908
14051
|
String: [
|
|
13909
|
-
"at",
|
|
14052
|
+
es >= 2022 && "at",
|
|
13910
14053
|
"charAt",
|
|
13911
14054
|
"charCodeAt",
|
|
13912
|
-
"
|
|
14055
|
+
es >= 2015 && "codePointAt",
|
|
13913
14056
|
"concat",
|
|
13914
|
-
"endsWith",
|
|
13915
|
-
"
|
|
13916
|
-
"fromCodePoint",
|
|
13917
|
-
"includes",
|
|
14057
|
+
es >= 2025 && "endsWith",
|
|
14058
|
+
es >= 2015 && "includes",
|
|
13918
14059
|
"indexOf",
|
|
13919
14060
|
"italics",
|
|
13920
14061
|
"lastIndexOf",
|
|
13921
|
-
"localeCompare",
|
|
14062
|
+
es >= 2020 && "localeCompare",
|
|
13922
14063
|
"match",
|
|
13923
|
-
"matchAll",
|
|
13924
|
-
"normalize",
|
|
13925
|
-
"padStart",
|
|
13926
|
-
"padEnd",
|
|
13927
|
-
"repeat",
|
|
14064
|
+
es >= 2020 && "matchAll",
|
|
14065
|
+
es >= 2015 && "normalize",
|
|
14066
|
+
es >= 2017 && "padStart",
|
|
14067
|
+
es >= 2017 && "padEnd",
|
|
14068
|
+
es >= 2015 && sloppy && "repeat",
|
|
13928
14069
|
"replace",
|
|
13929
|
-
"replaceAll",
|
|
14070
|
+
es >= 2021 && "replaceAll",
|
|
13930
14071
|
"search",
|
|
13931
14072
|
"slice",
|
|
13932
14073
|
"split",
|
|
13933
|
-
"startsWith",
|
|
14074
|
+
es >= 2015 && "startsWith",
|
|
13934
14075
|
"substr",
|
|
13935
14076
|
"substring",
|
|
13936
|
-
"repeat",
|
|
14077
|
+
es >= 2015 && "repeat",
|
|
13937
14078
|
"toLocaleLowerCase",
|
|
13938
14079
|
"toLocaleUpperCase",
|
|
13939
14080
|
"toLowerCase",
|
|
13940
14081
|
"toUpperCase",
|
|
13941
14082
|
"trim",
|
|
13942
|
-
"trimEnd",
|
|
13943
|
-
"trimStart",
|
|
14083
|
+
es >= 2019 && "trimEnd",
|
|
14084
|
+
es >= 2019 && "trimStart",
|
|
14085
|
+
es >= 2019 && "trimLeft",
|
|
14086
|
+
es >= 2019 && "trimRight",
|
|
13944
14087
|
...object_methods,
|
|
13945
14088
|
],
|
|
13946
|
-
});
|
|
14089
|
+
}));
|
|
13947
14090
|
|
|
13948
|
-
|
|
14091
|
+
// eslint-disable-next-line no-unused-vars
|
|
14092
|
+
const is_pure_native_static_fn = make_nested_lookup(({ sloppy, es }) => ({
|
|
13949
14093
|
Array: [
|
|
13950
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",
|
|
13951
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"],
|
|
13952
14120
|
Math: [
|
|
13953
14121
|
"abs",
|
|
13954
14122
|
"acos",
|
|
14123
|
+
es >= 2015 && "acosh",
|
|
13955
14124
|
"asin",
|
|
14125
|
+
es >= 2015 && "asinh",
|
|
13956
14126
|
"atan",
|
|
14127
|
+
"atan2",
|
|
14128
|
+
es >= 2015 && "atanh",
|
|
14129
|
+
es >= 2015 && "cbrt",
|
|
13957
14130
|
"ceil",
|
|
14131
|
+
es >= 2015 && "clz32",
|
|
13958
14132
|
"cos",
|
|
14133
|
+
es >= 2015 && "cosh",
|
|
13959
14134
|
"exp",
|
|
14135
|
+
es >= 2015 && "expm1",
|
|
13960
14136
|
"floor",
|
|
14137
|
+
es >= 2026 && "f16round",
|
|
14138
|
+
es >= 2015 && "fround",
|
|
14139
|
+
es >= 2015 && "hypot",
|
|
14140
|
+
es >= 2015 && "imul",
|
|
13961
14141
|
"log",
|
|
14142
|
+
es >= 2015 && "log10",
|
|
14143
|
+
es >= 2015 && "log1p",
|
|
14144
|
+
es >= 2015 && "log2",
|
|
14145
|
+
"max",
|
|
14146
|
+
"min",
|
|
14147
|
+
"pow",
|
|
13962
14148
|
"round",
|
|
14149
|
+
es >= 2015 && "sign",
|
|
13963
14150
|
"sin",
|
|
14151
|
+
es >= 2015 && "sinh",
|
|
13964
14152
|
"sqrt",
|
|
13965
14153
|
"tan",
|
|
13966
|
-
"
|
|
13967
|
-
"
|
|
13968
|
-
"max",
|
|
13969
|
-
"min",
|
|
14154
|
+
es >= 2015 && "tanh",
|
|
14155
|
+
es >= 2015 && "trunc",
|
|
13970
14156
|
],
|
|
13971
14157
|
Number: [
|
|
13972
|
-
"isFinite",
|
|
13973
|
-
"
|
|
14158
|
+
es >= 2015 && "isFinite",
|
|
14159
|
+
es >= 2015 && "isInteger",
|
|
14160
|
+
es >= 2015 && "isSafeInteger",
|
|
14161
|
+
es >= 2015 && "isNaN",
|
|
14162
|
+
es >= 2015 && "parseFloat",
|
|
14163
|
+
es >= 2015 && "parseInt",
|
|
13974
14164
|
],
|
|
13975
14165
|
Object: [
|
|
13976
|
-
"create",
|
|
13977
|
-
"getOwnPropertyDescriptor",
|
|
13978
|
-
"
|
|
13979
|
-
"
|
|
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",
|
|
13980
14174
|
"isExtensible",
|
|
13981
14175
|
"isFrozen",
|
|
13982
14176
|
"isSealed",
|
|
13983
|
-
"
|
|
13984
|
-
|
|
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",
|
|
13985
14192
|
],
|
|
13986
14193
|
String: [
|
|
13987
14194
|
"fromCharCode",
|
|
14195
|
+
sloppy && es >= 2025 && "fromCodePoint",
|
|
13988
14196
|
],
|
|
13989
|
-
|
|
14197
|
+
Uint16Array: ["of"],
|
|
14198
|
+
Uint32Array: ["of"],
|
|
14199
|
+
Uint8Array: ["of"],
|
|
14200
|
+
Uint8ClampedArray: ["of"],
|
|
14201
|
+
}));
|
|
13990
14202
|
|
|
13991
14203
|
// Known numeric values which come with JS environments
|
|
13992
|
-
|
|
14204
|
+
// eslint-disable-next-line no-unused-vars
|
|
14205
|
+
const is_pure_native_static_property = make_nested_lookup(({ sloppy, es }) => ({
|
|
13993
14206
|
Math: [
|
|
13994
14207
|
"E",
|
|
13995
14208
|
"LN10",
|
|
@@ -14001,13 +14214,130 @@ const is_pure_native_value = make_nested_lookup({
|
|
|
14001
14214
|
"SQRT2",
|
|
14002
14215
|
],
|
|
14003
14216
|
Number: [
|
|
14217
|
+
es >= 2015 && "EPSILON",
|
|
14218
|
+
es >= 2015 && "MAX_SAFE_VALUE",
|
|
14004
14219
|
"MAX_VALUE",
|
|
14220
|
+
es >= 2015 && "MIN_SAFE_VALUE",
|
|
14005
14221
|
"MIN_VALUE",
|
|
14006
14222
|
"NaN",
|
|
14007
14223
|
"NEGATIVE_INFINITY",
|
|
14008
14224
|
"POSITIVE_INFINITY",
|
|
14009
14225
|
],
|
|
14010
|
-
|
|
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
|
+
}
|
|
14011
14341
|
|
|
14012
14342
|
/***********************************************************************
|
|
14013
14343
|
|
|
@@ -14891,13 +15221,9 @@ AST_Call.DEFMETHOD("is_callee_pure", function(compressor) {
|
|
|
14891
15221
|
return false;
|
|
14892
15222
|
}
|
|
14893
15223
|
if (is_undeclared_ref(expr) && global_pure_fns.has(expr.name)) return true;
|
|
14894
|
-
if (
|
|
14895
|
-
|
|
14896
|
-
|
|
14897
|
-
&& is_pure_native_fn(expr.expression.name, expr.property)
|
|
14898
|
-
) {
|
|
14899
|
-
return true;
|
|
14900
|
-
}
|
|
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;
|
|
14901
15227
|
}
|
|
14902
15228
|
if ((this instanceof AST_New) && compressor.option("pure_new")) {
|
|
14903
15229
|
return true;
|
|
@@ -14928,7 +15254,7 @@ AST_Dot.DEFMETHOD("is_call_pure", function(compressor) {
|
|
|
14928
15254
|
} else if (!this.may_throw_on_access(compressor)) {
|
|
14929
15255
|
native_obj = "Object";
|
|
14930
15256
|
}
|
|
14931
|
-
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);
|
|
14932
15258
|
});
|
|
14933
15259
|
|
|
14934
15260
|
// tell me if a statement aborts
|
|
@@ -15457,7 +15783,7 @@ def_eval(AST_PropAccess, function (compressor, depth, ast_chain) {
|
|
|
15457
15783
|
if (first_arg == null || first_arg.thedef && first_arg.thedef.undeclared) {
|
|
15458
15784
|
return this.clone();
|
|
15459
15785
|
}
|
|
15460
|
-
if (!
|
|
15786
|
+
if (!compressor.is_pure_native_static_property(exp.name, key))
|
|
15461
15787
|
return this;
|
|
15462
15788
|
obj = global_objs[exp.name];
|
|
15463
15789
|
} else {
|
|
@@ -15513,14 +15839,14 @@ def_eval(AST_Call, function (compressor, depth, ast_chain) {
|
|
|
15513
15839
|
if ((first_arg == null || first_arg.thedef && first_arg.thedef.undeclared)) {
|
|
15514
15840
|
return this.clone();
|
|
15515
15841
|
}
|
|
15516
|
-
if (!
|
|
15842
|
+
if (!compressor.is_pure_native_static_fn(e.name, key)) return this;
|
|
15517
15843
|
val = global_objs[e.name];
|
|
15518
15844
|
} else {
|
|
15519
15845
|
val = e._eval(compressor, depth + 1, /* don't pass ast_chain (exponential work) */);
|
|
15520
15846
|
|
|
15521
15847
|
if (val === e || !val)
|
|
15522
15848
|
return this;
|
|
15523
|
-
if (!is_pure_native_method(val.constructor.name, key))
|
|
15849
|
+
if (!compressor.is_pure_native_method(val.constructor.name, key))
|
|
15524
15850
|
return this;
|
|
15525
15851
|
}
|
|
15526
15852
|
var args = [];
|
|
@@ -19306,6 +19632,8 @@ class Compressor extends TreeWalker {
|
|
|
19306
19632
|
drop_console : false,
|
|
19307
19633
|
drop_debugger : !false_by_default,
|
|
19308
19634
|
ecma : 5,
|
|
19635
|
+
builtins_ecma : 5,
|
|
19636
|
+
builtins_pure : false,
|
|
19309
19637
|
evaluate : !false_by_default,
|
|
19310
19638
|
expression : false,
|
|
19311
19639
|
global_defs : false,
|
|
@@ -19401,6 +19729,12 @@ class Compressor extends TreeWalker {
|
|
|
19401
19729
|
this._mangle_options = mangle_options
|
|
19402
19730
|
? format_mangler_options(mangle_options)
|
|
19403
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);
|
|
19404
19738
|
}
|
|
19405
19739
|
|
|
19406
19740
|
mangle_options() {
|
|
@@ -19735,10 +20069,9 @@ function find_variable(compressor, name) {
|
|
|
19735
20069
|
return scope.find_variable(name);
|
|
19736
20070
|
}
|
|
19737
20071
|
|
|
19738
|
-
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");
|
|
19739
20072
|
AST_SymbolRef.DEFMETHOD("is_declared", function(compressor) {
|
|
19740
20073
|
return !this.definition().undeclared
|
|
19741
|
-
|| compressor.option("unsafe") &&
|
|
20074
|
+
|| (compressor.option("unsafe") || compressor.option("builtins_pure")) && compressor.pure_access_globals(this.name);
|
|
19742
20075
|
});
|
|
19743
20076
|
|
|
19744
20077
|
/* -----[ optimizers ]----- */
|
|
@@ -27079,6 +27412,7 @@ var domprops = [
|
|
|
27079
27412
|
"c",
|
|
27080
27413
|
"cache",
|
|
27081
27414
|
"caches",
|
|
27415
|
+
"calendar",
|
|
27082
27416
|
"call",
|
|
27083
27417
|
"caller",
|
|
27084
27418
|
"camera",
|
|
@@ -27678,7 +28012,11 @@ var domprops = [
|
|
|
27678
28012
|
"databases",
|
|
27679
28013
|
"datagrams",
|
|
27680
28014
|
"dataset",
|
|
28015
|
+
"dateStyle",
|
|
27681
28016
|
"dateTime",
|
|
28017
|
+
"day",
|
|
28018
|
+
"dayPeriod",
|
|
28019
|
+
"days",
|
|
27682
28020
|
"db",
|
|
27683
28021
|
"debug",
|
|
27684
28022
|
"debuggerEnabled",
|
|
@@ -28031,6 +28369,7 @@ var domprops = [
|
|
|
28031
28369
|
"enumerateEditable",
|
|
28032
28370
|
"environmentBlendMode",
|
|
28033
28371
|
"equals",
|
|
28372
|
+
"era",
|
|
28034
28373
|
"error",
|
|
28035
28374
|
"errorCode",
|
|
28036
28375
|
"errorDetail",
|
|
@@ -28276,6 +28615,7 @@ var domprops = [
|
|
|
28276
28615
|
"forwardZ",
|
|
28277
28616
|
"foundation",
|
|
28278
28617
|
"fr",
|
|
28618
|
+
"fractionalSecondDigits",
|
|
28279
28619
|
"fragment",
|
|
28280
28620
|
"fragmentDirective",
|
|
28281
28621
|
"frame",
|
|
@@ -28806,6 +29146,10 @@ var domprops = [
|
|
|
28806
29146
|
"host",
|
|
28807
29147
|
"hostCandidate",
|
|
28808
29148
|
"hostname",
|
|
29149
|
+
"hour",
|
|
29150
|
+
"hour12",
|
|
29151
|
+
"hourCycle",
|
|
29152
|
+
"hours",
|
|
28809
29153
|
"href",
|
|
28810
29154
|
"hrefTranslate",
|
|
28811
29155
|
"hreflang",
|
|
@@ -29493,7 +29837,9 @@ var domprops = [
|
|
|
29493
29837
|
"method",
|
|
29494
29838
|
"methodDetails",
|
|
29495
29839
|
"methodName",
|
|
29840
|
+
"microseconds",
|
|
29496
29841
|
"mid",
|
|
29842
|
+
"milliseconds",
|
|
29497
29843
|
"mimeType",
|
|
29498
29844
|
"mimeTypes",
|
|
29499
29845
|
"min",
|
|
@@ -29513,6 +29859,8 @@ var domprops = [
|
|
|
29513
29859
|
"minValue",
|
|
29514
29860
|
"minWidth",
|
|
29515
29861
|
"minimumLatency",
|
|
29862
|
+
"minute",
|
|
29863
|
+
"minutes",
|
|
29516
29864
|
"mipLevel",
|
|
29517
29865
|
"mipLevelCount",
|
|
29518
29866
|
"mipmapFilter",
|
|
@@ -29525,6 +29873,8 @@ var domprops = [
|
|
|
29525
29873
|
"model",
|
|
29526
29874
|
"modify",
|
|
29527
29875
|
"module",
|
|
29876
|
+
"month",
|
|
29877
|
+
"months",
|
|
29528
29878
|
"mount",
|
|
29529
29879
|
"move",
|
|
29530
29880
|
"moveBefore",
|
|
@@ -29791,6 +30141,7 @@ var domprops = [
|
|
|
29791
30141
|
"names",
|
|
29792
30142
|
"namespaceURI",
|
|
29793
30143
|
"namespaces",
|
|
30144
|
+
"nanoseconds",
|
|
29794
30145
|
"nativeApplication",
|
|
29795
30146
|
"nativeMap",
|
|
29796
30147
|
"nativeObjectCreate",
|
|
@@ -29861,6 +30212,8 @@ var domprops = [
|
|
|
29861
30212
|
"numberOfItems",
|
|
29862
30213
|
"numberOfOutputs",
|
|
29863
30214
|
"numberValue",
|
|
30215
|
+
"numberingSystem",
|
|
30216
|
+
"numeric",
|
|
29864
30217
|
"oMatchesSelector",
|
|
29865
30218
|
"object",
|
|
29866
30219
|
"object-fit",
|
|
@@ -31208,6 +31561,8 @@ var domprops = [
|
|
|
31208
31561
|
"searchBox",
|
|
31209
31562
|
"searchBoxJavaBridge_",
|
|
31210
31563
|
"searchParams",
|
|
31564
|
+
"second",
|
|
31565
|
+
"seconds",
|
|
31211
31566
|
"sectionRowIndex",
|
|
31212
31567
|
"secureConnectionStart",
|
|
31213
31568
|
"securePaymentConfirmationAvailability",
|
|
@@ -31856,6 +32211,9 @@ var domprops = [
|
|
|
31856
32211
|
"timeOrigin",
|
|
31857
32212
|
"timeRemaining",
|
|
31858
32213
|
"timeStamp",
|
|
32214
|
+
"timeStyle",
|
|
32215
|
+
"timeZone",
|
|
32216
|
+
"timeZoneName",
|
|
31859
32217
|
"timecode",
|
|
31860
32218
|
"timeline",
|
|
31861
32219
|
"timelineTime",
|
|
@@ -32445,6 +32803,8 @@ var domprops = [
|
|
|
32445
32803
|
"webkitdirectory",
|
|
32446
32804
|
"webkitdropzone",
|
|
32447
32805
|
"webstore",
|
|
32806
|
+
"weekday",
|
|
32807
|
+
"weeks",
|
|
32448
32808
|
"weight",
|
|
32449
32809
|
"wgslLanguageFeatures",
|
|
32450
32810
|
"whatToShow",
|
|
@@ -32521,6 +32881,8 @@ var domprops = [
|
|
|
32521
32881
|
"y2",
|
|
32522
32882
|
"yChannelSelector",
|
|
32523
32883
|
"yandex",
|
|
32884
|
+
"year",
|
|
32885
|
+
"years",
|
|
32524
32886
|
"yield",
|
|
32525
32887
|
"z",
|
|
32526
32888
|
"z-index",
|