terser 5.46.2 → 5.47.1
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 +9 -0
- package/README.md +4 -0
- package/dist/bundle.min.js +417 -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/scope.js +1 -0
- 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;
|
|
@@ -12795,6 +12795,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
|
|
12795
12795
|
if (
|
|
12796
12796
|
function_defs
|
|
12797
12797
|
&& node instanceof AST_VarDef
|
|
12798
|
+
&& node.name instanceof AST_Symbol
|
|
12798
12799
|
&& node.value instanceof AST_Lambda
|
|
12799
12800
|
&& !node.value.name
|
|
12800
12801
|
&& keep_name(options.keep_fnames, node.name.name)
|
|
@@ -13851,10 +13852,14 @@ function retain_top_func(fn, compressor) {
|
|
|
13851
13852
|
// Note: Lots of methods and functions are missing here, in case they aren't pure
|
|
13852
13853
|
// or not available in all JS environments.
|
|
13853
13854
|
|
|
13854
|
-
|
|
13855
|
+
const make_nested_lookup = (feature_callback) => (compressor) => {
|
|
13856
|
+
const obj = feature_callback(feature_variables(compressor));
|
|
13857
|
+
|
|
13855
13858
|
const out = new Map();
|
|
13856
13859
|
for (var key of Object.keys(obj)) {
|
|
13857
|
-
|
|
13860
|
+
if (obj[key]) {
|
|
13861
|
+
out.set(key, makePredicate(remove_false(obj[key])));
|
|
13862
|
+
}
|
|
13858
13863
|
}
|
|
13859
13864
|
|
|
13860
13865
|
const does_have = (global_name, fname) => {
|
|
@@ -13862,8 +13867,74 @@ function make_nested_lookup(obj) {
|
|
|
13862
13867
|
return inner_map != null && inner_map.has(fname);
|
|
13863
13868
|
};
|
|
13864
13869
|
return does_have;
|
|
13870
|
+
};
|
|
13871
|
+
|
|
13872
|
+
const make_lookup = (feature_callback) => (compressor) => {
|
|
13873
|
+
const obj = feature_callback(feature_variables(compressor));
|
|
13874
|
+
|
|
13875
|
+
const predicate = makePredicate(remove_false(obj));
|
|
13876
|
+
const does_have = (global_name) => {
|
|
13877
|
+
return predicate.has(global_name);
|
|
13878
|
+
};
|
|
13879
|
+
return does_have;
|
|
13880
|
+
};
|
|
13881
|
+
|
|
13882
|
+
function remove_false(arr) {
|
|
13883
|
+
for (let i = 0; i < arr.length; i++) {
|
|
13884
|
+
if (arr[i] === false) {
|
|
13885
|
+
arr.splice(i, 1);
|
|
13886
|
+
i--;
|
|
13887
|
+
}
|
|
13888
|
+
}
|
|
13889
|
+
return arr;
|
|
13890
|
+
}
|
|
13891
|
+
|
|
13892
|
+
/** Generate the object with arguments seen below */
|
|
13893
|
+
function feature_variables(compressor) {
|
|
13894
|
+
return {
|
|
13895
|
+
sloppy: compressor.option("unsafe"),
|
|
13896
|
+
es: compressor.option("builtins_ecma"),
|
|
13897
|
+
};
|
|
13865
13898
|
}
|
|
13866
13899
|
|
|
13900
|
+
// eslint-disable-next-line no-unused-vars
|
|
13901
|
+
const pure_access_globals = make_lookup(({ sloppy, es }) => [
|
|
13902
|
+
"Array",
|
|
13903
|
+
"Boolean",
|
|
13904
|
+
"clearInterval",
|
|
13905
|
+
"clearTimeout",
|
|
13906
|
+
"console",
|
|
13907
|
+
"Date",
|
|
13908
|
+
"decodeURI",
|
|
13909
|
+
"decodeURIComponent",
|
|
13910
|
+
"encodeURI",
|
|
13911
|
+
"encodeURIComponent",
|
|
13912
|
+
"Error",
|
|
13913
|
+
"escape",
|
|
13914
|
+
"eval",
|
|
13915
|
+
"EvalError",
|
|
13916
|
+
"Function",
|
|
13917
|
+
es >= 2020 && "globalThis",
|
|
13918
|
+
"isFinite",
|
|
13919
|
+
"isNaN",
|
|
13920
|
+
"JSON",
|
|
13921
|
+
"Math",
|
|
13922
|
+
"Number",
|
|
13923
|
+
"parseFloat",
|
|
13924
|
+
"parseInt",
|
|
13925
|
+
"RangeError",
|
|
13926
|
+
"ReferenceError",
|
|
13927
|
+
"RegExp",
|
|
13928
|
+
"Object",
|
|
13929
|
+
"setInterval",
|
|
13930
|
+
"setTimeout",
|
|
13931
|
+
"String",
|
|
13932
|
+
"SyntaxError",
|
|
13933
|
+
"TypeError",
|
|
13934
|
+
"unescape",
|
|
13935
|
+
"URIError",
|
|
13936
|
+
]);
|
|
13937
|
+
|
|
13867
13938
|
// Objects which are safe to access without throwing or causing a side effect.
|
|
13868
13939
|
// Usually we'd check the `unsafe` option first but these are way too common for that
|
|
13869
13940
|
const pure_prop_access_globals = new Set([
|
|
@@ -13875,17 +13946,90 @@ const pure_prop_access_globals = new Set([
|
|
|
13875
13946
|
"Promise",
|
|
13876
13947
|
]);
|
|
13877
13948
|
|
|
13949
|
+
// eslint-disable-next-line no-unused-vars
|
|
13950
|
+
const is_pure_native_fn = make_lookup(({ sloppy, es }) => [
|
|
13951
|
+
sloppy && es >= 2021 && "AggregateError",
|
|
13952
|
+
"Array",
|
|
13953
|
+
"ArrayBuffer",
|
|
13954
|
+
es >= 2020 && "BigInt",
|
|
13955
|
+
es >= 2020 && "BigInt64Array",
|
|
13956
|
+
es >= 2020 && "BigUint64Array",
|
|
13957
|
+
"Boolean",
|
|
13958
|
+
"Date",
|
|
13959
|
+
sloppy && "decodeURI",
|
|
13960
|
+
sloppy && "decodeURIComponent",
|
|
13961
|
+
sloppy && "encodeURI",
|
|
13962
|
+
sloppy && "encodeURIComponent",
|
|
13963
|
+
"Error",
|
|
13964
|
+
"escape",
|
|
13965
|
+
"EvalError",
|
|
13966
|
+
es >= 2021 && "FinalizationRegistry",
|
|
13967
|
+
es >= 2026 && "Float16Array",
|
|
13968
|
+
"Float32Array",
|
|
13969
|
+
"Float64Array",
|
|
13970
|
+
"Int16Array",
|
|
13971
|
+
"Int32Array",
|
|
13972
|
+
"Int8Array",
|
|
13973
|
+
"isFinite",
|
|
13974
|
+
"isNaN",
|
|
13975
|
+
es >= 2026 && "Iterator",
|
|
13976
|
+
es >= 2015 && "Map",
|
|
13977
|
+
"Number",
|
|
13978
|
+
"parseFloat",
|
|
13979
|
+
"parseInt",
|
|
13980
|
+
es >= 2015 && "Promise",
|
|
13981
|
+
es >= 2015 && "Proxy",
|
|
13982
|
+
"RangeError",
|
|
13983
|
+
"ReferenceError",
|
|
13984
|
+
sloppy && "RegExp",
|
|
13985
|
+
es >= 2015 && "Set",
|
|
13986
|
+
"String",
|
|
13987
|
+
es >= 2015 && "Symbol",
|
|
13988
|
+
"SyntaxError",
|
|
13989
|
+
"TypeError",
|
|
13990
|
+
"Uint16Array",
|
|
13991
|
+
"Uint32Array",
|
|
13992
|
+
"Uint8Array",
|
|
13993
|
+
"Uint8ClampedArray",
|
|
13994
|
+
sloppy && "unescape",
|
|
13995
|
+
"URIError",
|
|
13996
|
+
sloppy && es >= 2015 && "WeakMap",
|
|
13997
|
+
sloppy && es >= 2021 && "WeakRef",
|
|
13998
|
+
sloppy && es >= 2015 && "WeakSet",
|
|
13999
|
+
]);
|
|
14000
|
+
|
|
14001
|
+
const arg1_is_iterable = new Set([
|
|
14002
|
+
"Map",
|
|
14003
|
+
"Set",
|
|
14004
|
+
"WeakMap",
|
|
14005
|
+
"WeakSet",
|
|
14006
|
+
]);
|
|
14007
|
+
const arg1_is_range_or_iterable = new Set([
|
|
14008
|
+
"ArrayBuffer",
|
|
14009
|
+
"Float32Array",
|
|
14010
|
+
"Float64Array",
|
|
14011
|
+
"Int16Array",
|
|
14012
|
+
"Int32Array",
|
|
14013
|
+
"Int8Array",
|
|
14014
|
+
"Uint16Array",
|
|
14015
|
+
"Uint32Array",
|
|
14016
|
+
"Uint8Array",
|
|
14017
|
+
"Uint8ClampedArray",
|
|
14018
|
+
]);
|
|
14019
|
+
const lone_arg_is_range = new Set(["Array"]);
|
|
14020
|
+
|
|
13878
14021
|
const object_methods = [
|
|
13879
14022
|
"constructor",
|
|
13880
14023
|
"toString",
|
|
13881
14024
|
"valueOf",
|
|
13882
14025
|
];
|
|
13883
14026
|
|
|
13884
|
-
|
|
14027
|
+
// eslint-disable-next-line no-unused-vars
|
|
14028
|
+
const is_pure_native_method = make_nested_lookup(({ sloppy, es }) => ({
|
|
13885
14029
|
Array: [
|
|
13886
|
-
"at",
|
|
13887
|
-
"flat",
|
|
13888
|
-
"includes",
|
|
14030
|
+
es >= 2022 && "at",
|
|
14031
|
+
es >= 2019 && "flat",
|
|
14032
|
+
es >= 2016 && "includes",
|
|
13889
14033
|
"indexOf",
|
|
13890
14034
|
"join",
|
|
13891
14035
|
"lastIndexOf",
|
|
@@ -13906,90 +14050,160 @@ const is_pure_native_method = make_nested_lookup({
|
|
|
13906
14050
|
...object_methods,
|
|
13907
14051
|
],
|
|
13908
14052
|
String: [
|
|
13909
|
-
"at",
|
|
14053
|
+
es >= 2022 && "at",
|
|
13910
14054
|
"charAt",
|
|
13911
14055
|
"charCodeAt",
|
|
13912
|
-
"
|
|
14056
|
+
es >= 2015 && "codePointAt",
|
|
13913
14057
|
"concat",
|
|
13914
|
-
"endsWith",
|
|
13915
|
-
"
|
|
13916
|
-
"fromCodePoint",
|
|
13917
|
-
"includes",
|
|
14058
|
+
es >= 2025 && "endsWith",
|
|
14059
|
+
es >= 2015 && "includes",
|
|
13918
14060
|
"indexOf",
|
|
13919
14061
|
"italics",
|
|
13920
14062
|
"lastIndexOf",
|
|
13921
|
-
"localeCompare",
|
|
14063
|
+
es >= 2020 && "localeCompare",
|
|
13922
14064
|
"match",
|
|
13923
|
-
"matchAll",
|
|
13924
|
-
"normalize",
|
|
13925
|
-
"padStart",
|
|
13926
|
-
"padEnd",
|
|
13927
|
-
"repeat",
|
|
14065
|
+
es >= 2020 && "matchAll",
|
|
14066
|
+
es >= 2015 && "normalize",
|
|
14067
|
+
es >= 2017 && "padStart",
|
|
14068
|
+
es >= 2017 && "padEnd",
|
|
14069
|
+
es >= 2015 && sloppy && "repeat",
|
|
13928
14070
|
"replace",
|
|
13929
|
-
"replaceAll",
|
|
14071
|
+
es >= 2021 && "replaceAll",
|
|
13930
14072
|
"search",
|
|
13931
14073
|
"slice",
|
|
13932
14074
|
"split",
|
|
13933
|
-
"startsWith",
|
|
14075
|
+
es >= 2015 && "startsWith",
|
|
13934
14076
|
"substr",
|
|
13935
14077
|
"substring",
|
|
13936
|
-
"repeat",
|
|
14078
|
+
es >= 2015 && "repeat",
|
|
13937
14079
|
"toLocaleLowerCase",
|
|
13938
14080
|
"toLocaleUpperCase",
|
|
13939
14081
|
"toLowerCase",
|
|
13940
14082
|
"toUpperCase",
|
|
13941
14083
|
"trim",
|
|
13942
|
-
"trimEnd",
|
|
13943
|
-
"trimStart",
|
|
14084
|
+
es >= 2019 && "trimEnd",
|
|
14085
|
+
es >= 2019 && "trimStart",
|
|
14086
|
+
es >= 2019 && "trimLeft",
|
|
14087
|
+
es >= 2019 && "trimRight",
|
|
13944
14088
|
...object_methods,
|
|
13945
14089
|
],
|
|
13946
|
-
});
|
|
14090
|
+
}));
|
|
13947
14091
|
|
|
13948
|
-
|
|
14092
|
+
// eslint-disable-next-line no-unused-vars
|
|
14093
|
+
const is_pure_native_static_fn = make_nested_lookup(({ sloppy, es }) => ({
|
|
13949
14094
|
Array: [
|
|
13950
14095
|
"isArray",
|
|
14096
|
+
es >= 2015 && "of",
|
|
14097
|
+
],
|
|
14098
|
+
ArrayBuffer: [
|
|
14099
|
+
"isView",
|
|
14100
|
+
],
|
|
14101
|
+
BigInt: es >= 2020 && [
|
|
14102
|
+
sloppy && "asIntN",
|
|
14103
|
+
sloppy && "asUintN",
|
|
14104
|
+
],
|
|
14105
|
+
BigInt64Array: sloppy && es >= 2020 && ["of"],
|
|
14106
|
+
BigUint64Array: sloppy && es >= 2020 && ["of"],
|
|
14107
|
+
Date: [
|
|
14108
|
+
"now",
|
|
14109
|
+
"parse",
|
|
14110
|
+
"UTC",
|
|
13951
14111
|
],
|
|
14112
|
+
Error: [
|
|
14113
|
+
es >= 2026 && "isError",
|
|
14114
|
+
],
|
|
14115
|
+
Float16Array: sloppy && es >= 2026 && ["of"],
|
|
14116
|
+
Float32Array: sloppy && ["of"],
|
|
14117
|
+
Float64Array: sloppy && ["of"],
|
|
14118
|
+
Int16Array: sloppy && ["of"],
|
|
14119
|
+
Int32Array: sloppy && ["of"],
|
|
14120
|
+
Int8Array: sloppy && ["of"],
|
|
13952
14121
|
Math: [
|
|
13953
14122
|
"abs",
|
|
13954
14123
|
"acos",
|
|
14124
|
+
es >= 2015 && "acosh",
|
|
13955
14125
|
"asin",
|
|
14126
|
+
es >= 2015 && "asinh",
|
|
13956
14127
|
"atan",
|
|
14128
|
+
"atan2",
|
|
14129
|
+
es >= 2015 && "atanh",
|
|
14130
|
+
es >= 2015 && "cbrt",
|
|
13957
14131
|
"ceil",
|
|
14132
|
+
es >= 2015 && "clz32",
|
|
13958
14133
|
"cos",
|
|
14134
|
+
es >= 2015 && "cosh",
|
|
13959
14135
|
"exp",
|
|
14136
|
+
es >= 2015 && "expm1",
|
|
13960
14137
|
"floor",
|
|
14138
|
+
es >= 2026 && "f16round",
|
|
14139
|
+
es >= 2015 && "fround",
|
|
14140
|
+
es >= 2015 && "hypot",
|
|
14141
|
+
es >= 2015 && "imul",
|
|
13961
14142
|
"log",
|
|
14143
|
+
es >= 2015 && "log10",
|
|
14144
|
+
es >= 2015 && "log1p",
|
|
14145
|
+
es >= 2015 && "log2",
|
|
14146
|
+
"max",
|
|
14147
|
+
"min",
|
|
14148
|
+
"pow",
|
|
13962
14149
|
"round",
|
|
14150
|
+
es >= 2015 && "sign",
|
|
13963
14151
|
"sin",
|
|
14152
|
+
es >= 2015 && "sinh",
|
|
13964
14153
|
"sqrt",
|
|
13965
14154
|
"tan",
|
|
13966
|
-
"
|
|
13967
|
-
"
|
|
13968
|
-
"max",
|
|
13969
|
-
"min",
|
|
14155
|
+
es >= 2015 && "tanh",
|
|
14156
|
+
es >= 2015 && "trunc",
|
|
13970
14157
|
],
|
|
13971
14158
|
Number: [
|
|
13972
|
-
"isFinite",
|
|
13973
|
-
"
|
|
14159
|
+
es >= 2015 && "isFinite",
|
|
14160
|
+
es >= 2015 && "isInteger",
|
|
14161
|
+
es >= 2015 && "isSafeInteger",
|
|
14162
|
+
es >= 2015 && "isNaN",
|
|
14163
|
+
es >= 2015 && "parseFloat",
|
|
14164
|
+
es >= 2015 && "parseInt",
|
|
13974
14165
|
],
|
|
13975
14166
|
Object: [
|
|
13976
|
-
"create",
|
|
13977
|
-
"getOwnPropertyDescriptor",
|
|
13978
|
-
"
|
|
13979
|
-
"
|
|
14167
|
+
sloppy && "create",
|
|
14168
|
+
sloppy && "getOwnPropertyDescriptor",
|
|
14169
|
+
es >= 2017 && sloppy && "getOwnPropertyDescriptors",
|
|
14170
|
+
sloppy && "getOwnPropertyNames",
|
|
14171
|
+
es >= 2015 && sloppy && "getOwnPropertySymbols",
|
|
14172
|
+
sloppy && "getPrototypeOf",
|
|
14173
|
+
es >= 2022 && sloppy && "hasOwn",
|
|
14174
|
+
es >= 2015 && "is",
|
|
13980
14175
|
"isExtensible",
|
|
13981
14176
|
"isFrozen",
|
|
13982
14177
|
"isSealed",
|
|
13983
|
-
"
|
|
13984
|
-
|
|
14178
|
+
es >= 2015 && sloppy && "keys",
|
|
14179
|
+
],
|
|
14180
|
+
Promise: es >= 2015 && [
|
|
14181
|
+
es >= 2024 && "withResolvers",
|
|
14182
|
+
],
|
|
14183
|
+
Proxy: es >= 2015 && [
|
|
14184
|
+
sloppy && "revocable",
|
|
14185
|
+
],
|
|
14186
|
+
Reflect: es >= 2015 && [
|
|
14187
|
+
sloppy && "has",
|
|
14188
|
+
sloppy && "isExtensible",
|
|
14189
|
+
sloppy && "ownKeys",
|
|
14190
|
+
],
|
|
14191
|
+
RegExp: [
|
|
14192
|
+
es >= 2026 && sloppy && "escape",
|
|
13985
14193
|
],
|
|
13986
14194
|
String: [
|
|
13987
14195
|
"fromCharCode",
|
|
14196
|
+
sloppy && es >= 2025 && "fromCodePoint",
|
|
13988
14197
|
],
|
|
13989
|
-
|
|
14198
|
+
Uint16Array: ["of"],
|
|
14199
|
+
Uint32Array: ["of"],
|
|
14200
|
+
Uint8Array: ["of"],
|
|
14201
|
+
Uint8ClampedArray: ["of"],
|
|
14202
|
+
}));
|
|
13990
14203
|
|
|
13991
14204
|
// Known numeric values which come with JS environments
|
|
13992
|
-
|
|
14205
|
+
// eslint-disable-next-line no-unused-vars
|
|
14206
|
+
const is_pure_native_static_property = make_nested_lookup(({ sloppy, es }) => ({
|
|
13993
14207
|
Math: [
|
|
13994
14208
|
"E",
|
|
13995
14209
|
"LN10",
|
|
@@ -14001,13 +14215,130 @@ const is_pure_native_value = make_nested_lookup({
|
|
|
14001
14215
|
"SQRT2",
|
|
14002
14216
|
],
|
|
14003
14217
|
Number: [
|
|
14218
|
+
es >= 2015 && "EPSILON",
|
|
14219
|
+
es >= 2015 && "MAX_SAFE_VALUE",
|
|
14004
14220
|
"MAX_VALUE",
|
|
14221
|
+
es >= 2015 && "MIN_SAFE_VALUE",
|
|
14005
14222
|
"MIN_VALUE",
|
|
14006
14223
|
"NaN",
|
|
14007
14224
|
"NEGATIVE_INFINITY",
|
|
14008
14225
|
"POSITIVE_INFINITY",
|
|
14009
14226
|
],
|
|
14010
|
-
|
|
14227
|
+
RegExp: [
|
|
14228
|
+
"$_",
|
|
14229
|
+
"$0",
|
|
14230
|
+
"$1",
|
|
14231
|
+
"$2",
|
|
14232
|
+
"$3",
|
|
14233
|
+
"$4",
|
|
14234
|
+
"$5",
|
|
14235
|
+
"$6",
|
|
14236
|
+
"$7",
|
|
14237
|
+
"$8",
|
|
14238
|
+
"$9",
|
|
14239
|
+
"input",
|
|
14240
|
+
"lastMatch",
|
|
14241
|
+
"lastParen",
|
|
14242
|
+
"leftContext",
|
|
14243
|
+
"rightContext",
|
|
14244
|
+
],
|
|
14245
|
+
}));
|
|
14246
|
+
|
|
14247
|
+
const re_uppercase_first_letter = /^[A-Z]/;
|
|
14248
|
+
function is_pure_builtin_call(compressor, call) {
|
|
14249
|
+
let builtin = "";
|
|
14250
|
+
let method = "";
|
|
14251
|
+
|
|
14252
|
+
let exp = call.expression;
|
|
14253
|
+
if (is_undeclared_ref(exp)) {
|
|
14254
|
+
builtin = exp.name;
|
|
14255
|
+
} else if (exp instanceof AST_Dot) {
|
|
14256
|
+
method = exp.property;
|
|
14257
|
+
|
|
14258
|
+
exp = exp.expression;
|
|
14259
|
+
if (is_undeclared_ref(exp)) {
|
|
14260
|
+
if (
|
|
14261
|
+
// globalThis.pureFunc()
|
|
14262
|
+
exp.name === "globalThis"
|
|
14263
|
+
&& compressor.option("builtins_ecma") >= 2020
|
|
14264
|
+
) {
|
|
14265
|
+
builtin = method;
|
|
14266
|
+
method = "";
|
|
14267
|
+
} else {
|
|
14268
|
+
// SomeBuiltin.pureFunc()
|
|
14269
|
+
builtin = exp.name;
|
|
14270
|
+
}
|
|
14271
|
+
} else if (exp instanceof AST_Dot) {
|
|
14272
|
+
if (
|
|
14273
|
+
is_undeclared_ref(exp.expression)
|
|
14274
|
+
&& exp.expression.name === "globalThis"
|
|
14275
|
+
&& compressor.option("builtins_ecma") >= 2020
|
|
14276
|
+
) {
|
|
14277
|
+
// globalThis.SomeBuiltin.pureFunc()
|
|
14278
|
+
builtin = exp.property;
|
|
14279
|
+
} else {
|
|
14280
|
+
return false;
|
|
14281
|
+
}
|
|
14282
|
+
} else {
|
|
14283
|
+
return false;
|
|
14284
|
+
}
|
|
14285
|
+
} else {
|
|
14286
|
+
return false;
|
|
14287
|
+
}
|
|
14288
|
+
|
|
14289
|
+
if (!method) {
|
|
14290
|
+
if (compressor.is_pure_native_fn(builtin)) {
|
|
14291
|
+
// some require `new`, others throw if you use it
|
|
14292
|
+
const is_new = call instanceof AST_New;
|
|
14293
|
+
const should_be_new = re_uppercase_first_letter.test(builtin); // true of all `is_pure_native_fn`
|
|
14294
|
+
if (is_new !== should_be_new) return false;
|
|
14295
|
+
|
|
14296
|
+
if (!is_builtin_pure_with_these_args(builtin, call.args)) {
|
|
14297
|
+
return false;
|
|
14298
|
+
}
|
|
14299
|
+
|
|
14300
|
+
return true;
|
|
14301
|
+
}
|
|
14302
|
+
|
|
14303
|
+
return false;
|
|
14304
|
+
} else {
|
|
14305
|
+
return compressor.is_pure_native_static_fn(builtin, method);
|
|
14306
|
+
}
|
|
14307
|
+
}
|
|
14308
|
+
|
|
14309
|
+
/** Some builtins are listed above but their purity is subject to some conditions */
|
|
14310
|
+
function is_builtin_pure_with_these_args(builtin, args) {
|
|
14311
|
+
// all the builtins we deal with here are ok with getting 0 args
|
|
14312
|
+
if (args.length === 0) return true;
|
|
14313
|
+
|
|
14314
|
+
let arg1 = args[0];
|
|
14315
|
+
if (arg1 instanceof AST_SymbolRef) {
|
|
14316
|
+
arg1 = arg1.fixed_value();
|
|
14317
|
+
}
|
|
14318
|
+
|
|
14319
|
+
if (lone_arg_is_range.has(builtin)) { // new Array(number)
|
|
14320
|
+
const arg_valid = args.length > 1
|
|
14321
|
+
|| arg1 instanceof AST_Number
|
|
14322
|
+
&& arg1.value >= 0 && arg1.value <= 0xffffffff;
|
|
14323
|
+
// TODO: or, we are asked to ignore TypeError
|
|
14324
|
+
if (!arg_valid) return false;
|
|
14325
|
+
}
|
|
14326
|
+
|
|
14327
|
+
if (arg1_is_range_or_iterable.has(builtin)) { // new Float32Array(number | Array)
|
|
14328
|
+
const arg_valid = args.length === 0
|
|
14329
|
+
|| arg1 instanceof AST_Array
|
|
14330
|
+
|| arg1 instanceof AST_Number
|
|
14331
|
+
&& arg1.value >= 0 && arg1.value <= 0xffffffff;
|
|
14332
|
+
if (!arg_valid) return false;
|
|
14333
|
+
}
|
|
14334
|
+
|
|
14335
|
+
if (arg1_is_iterable.has(builtin)) { // new Set(iterable)
|
|
14336
|
+
const arg_valid = args.length === 0 || arg1 instanceof AST_Array;
|
|
14337
|
+
if (!arg_valid) return false;
|
|
14338
|
+
}
|
|
14339
|
+
|
|
14340
|
+
return true;
|
|
14341
|
+
}
|
|
14011
14342
|
|
|
14012
14343
|
/***********************************************************************
|
|
14013
14344
|
|
|
@@ -14891,13 +15222,9 @@ AST_Call.DEFMETHOD("is_callee_pure", function(compressor) {
|
|
|
14891
15222
|
return false;
|
|
14892
15223
|
}
|
|
14893
15224
|
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
|
-
}
|
|
15225
|
+
if (is_pure_builtin_call(compressor, this)) return true;
|
|
15226
|
+
} else if (compressor.option("builtins_pure")) {
|
|
15227
|
+
if (is_pure_builtin_call(compressor, this)) return true;
|
|
14901
15228
|
}
|
|
14902
15229
|
if ((this instanceof AST_New) && compressor.option("pure_new")) {
|
|
14903
15230
|
return true;
|
|
@@ -14928,7 +15255,7 @@ AST_Dot.DEFMETHOD("is_call_pure", function(compressor) {
|
|
|
14928
15255
|
} else if (!this.may_throw_on_access(compressor)) {
|
|
14929
15256
|
native_obj = "Object";
|
|
14930
15257
|
}
|
|
14931
|
-
return native_obj != null && is_pure_native_method(native_obj, this.property);
|
|
15258
|
+
return native_obj != null && compressor.is_pure_native_method(native_obj, this.property);
|
|
14932
15259
|
});
|
|
14933
15260
|
|
|
14934
15261
|
// tell me if a statement aborts
|
|
@@ -15457,7 +15784,7 @@ def_eval(AST_PropAccess, function (compressor, depth, ast_chain) {
|
|
|
15457
15784
|
if (first_arg == null || first_arg.thedef && first_arg.thedef.undeclared) {
|
|
15458
15785
|
return this.clone();
|
|
15459
15786
|
}
|
|
15460
|
-
if (!
|
|
15787
|
+
if (!compressor.is_pure_native_static_property(exp.name, key))
|
|
15461
15788
|
return this;
|
|
15462
15789
|
obj = global_objs[exp.name];
|
|
15463
15790
|
} else {
|
|
@@ -15513,14 +15840,14 @@ def_eval(AST_Call, function (compressor, depth, ast_chain) {
|
|
|
15513
15840
|
if ((first_arg == null || first_arg.thedef && first_arg.thedef.undeclared)) {
|
|
15514
15841
|
return this.clone();
|
|
15515
15842
|
}
|
|
15516
|
-
if (!
|
|
15843
|
+
if (!compressor.is_pure_native_static_fn(e.name, key)) return this;
|
|
15517
15844
|
val = global_objs[e.name];
|
|
15518
15845
|
} else {
|
|
15519
15846
|
val = e._eval(compressor, depth + 1, /* don't pass ast_chain (exponential work) */);
|
|
15520
15847
|
|
|
15521
15848
|
if (val === e || !val)
|
|
15522
15849
|
return this;
|
|
15523
|
-
if (!is_pure_native_method(val.constructor.name, key))
|
|
15850
|
+
if (!compressor.is_pure_native_method(val.constructor.name, key))
|
|
15524
15851
|
return this;
|
|
15525
15852
|
}
|
|
15526
15853
|
var args = [];
|
|
@@ -19306,6 +19633,8 @@ class Compressor extends TreeWalker {
|
|
|
19306
19633
|
drop_console : false,
|
|
19307
19634
|
drop_debugger : !false_by_default,
|
|
19308
19635
|
ecma : 5,
|
|
19636
|
+
builtins_ecma : 5,
|
|
19637
|
+
builtins_pure : false,
|
|
19309
19638
|
evaluate : !false_by_default,
|
|
19310
19639
|
expression : false,
|
|
19311
19640
|
global_defs : false,
|
|
@@ -19401,6 +19730,12 @@ class Compressor extends TreeWalker {
|
|
|
19401
19730
|
this._mangle_options = mangle_options
|
|
19402
19731
|
? format_mangler_options(mangle_options)
|
|
19403
19732
|
: mangle_options;
|
|
19733
|
+
|
|
19734
|
+
this.pure_access_globals = pure_access_globals(this);
|
|
19735
|
+
this.is_pure_native_fn = is_pure_native_fn(this);
|
|
19736
|
+
this.is_pure_native_method = is_pure_native_method(this);
|
|
19737
|
+
this.is_pure_native_static_fn = is_pure_native_static_fn(this);
|
|
19738
|
+
this.is_pure_native_static_property = is_pure_native_static_property(this);
|
|
19404
19739
|
}
|
|
19405
19740
|
|
|
19406
19741
|
mangle_options() {
|
|
@@ -19735,10 +20070,9 @@ function find_variable(compressor, name) {
|
|
|
19735
20070
|
return scope.find_variable(name);
|
|
19736
20071
|
}
|
|
19737
20072
|
|
|
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
20073
|
AST_SymbolRef.DEFMETHOD("is_declared", function(compressor) {
|
|
19740
20074
|
return !this.definition().undeclared
|
|
19741
|
-
|| compressor.option("unsafe") &&
|
|
20075
|
+
|| (compressor.option("unsafe") || compressor.option("builtins_pure")) && compressor.pure_access_globals(this.name);
|
|
19742
20076
|
});
|
|
19743
20077
|
|
|
19744
20078
|
/* -----[ optimizers ]----- */
|
|
@@ -27079,6 +27413,7 @@ var domprops = [
|
|
|
27079
27413
|
"c",
|
|
27080
27414
|
"cache",
|
|
27081
27415
|
"caches",
|
|
27416
|
+
"calendar",
|
|
27082
27417
|
"call",
|
|
27083
27418
|
"caller",
|
|
27084
27419
|
"camera",
|
|
@@ -27678,7 +28013,11 @@ var domprops = [
|
|
|
27678
28013
|
"databases",
|
|
27679
28014
|
"datagrams",
|
|
27680
28015
|
"dataset",
|
|
28016
|
+
"dateStyle",
|
|
27681
28017
|
"dateTime",
|
|
28018
|
+
"day",
|
|
28019
|
+
"dayPeriod",
|
|
28020
|
+
"days",
|
|
27682
28021
|
"db",
|
|
27683
28022
|
"debug",
|
|
27684
28023
|
"debuggerEnabled",
|
|
@@ -28031,6 +28370,7 @@ var domprops = [
|
|
|
28031
28370
|
"enumerateEditable",
|
|
28032
28371
|
"environmentBlendMode",
|
|
28033
28372
|
"equals",
|
|
28373
|
+
"era",
|
|
28034
28374
|
"error",
|
|
28035
28375
|
"errorCode",
|
|
28036
28376
|
"errorDetail",
|
|
@@ -28276,6 +28616,7 @@ var domprops = [
|
|
|
28276
28616
|
"forwardZ",
|
|
28277
28617
|
"foundation",
|
|
28278
28618
|
"fr",
|
|
28619
|
+
"fractionalSecondDigits",
|
|
28279
28620
|
"fragment",
|
|
28280
28621
|
"fragmentDirective",
|
|
28281
28622
|
"frame",
|
|
@@ -28806,6 +29147,10 @@ var domprops = [
|
|
|
28806
29147
|
"host",
|
|
28807
29148
|
"hostCandidate",
|
|
28808
29149
|
"hostname",
|
|
29150
|
+
"hour",
|
|
29151
|
+
"hour12",
|
|
29152
|
+
"hourCycle",
|
|
29153
|
+
"hours",
|
|
28809
29154
|
"href",
|
|
28810
29155
|
"hrefTranslate",
|
|
28811
29156
|
"hreflang",
|
|
@@ -29493,7 +29838,9 @@ var domprops = [
|
|
|
29493
29838
|
"method",
|
|
29494
29839
|
"methodDetails",
|
|
29495
29840
|
"methodName",
|
|
29841
|
+
"microseconds",
|
|
29496
29842
|
"mid",
|
|
29843
|
+
"milliseconds",
|
|
29497
29844
|
"mimeType",
|
|
29498
29845
|
"mimeTypes",
|
|
29499
29846
|
"min",
|
|
@@ -29513,6 +29860,8 @@ var domprops = [
|
|
|
29513
29860
|
"minValue",
|
|
29514
29861
|
"minWidth",
|
|
29515
29862
|
"minimumLatency",
|
|
29863
|
+
"minute",
|
|
29864
|
+
"minutes",
|
|
29516
29865
|
"mipLevel",
|
|
29517
29866
|
"mipLevelCount",
|
|
29518
29867
|
"mipmapFilter",
|
|
@@ -29525,6 +29874,8 @@ var domprops = [
|
|
|
29525
29874
|
"model",
|
|
29526
29875
|
"modify",
|
|
29527
29876
|
"module",
|
|
29877
|
+
"month",
|
|
29878
|
+
"months",
|
|
29528
29879
|
"mount",
|
|
29529
29880
|
"move",
|
|
29530
29881
|
"moveBefore",
|
|
@@ -29791,6 +30142,7 @@ var domprops = [
|
|
|
29791
30142
|
"names",
|
|
29792
30143
|
"namespaceURI",
|
|
29793
30144
|
"namespaces",
|
|
30145
|
+
"nanoseconds",
|
|
29794
30146
|
"nativeApplication",
|
|
29795
30147
|
"nativeMap",
|
|
29796
30148
|
"nativeObjectCreate",
|
|
@@ -29861,6 +30213,8 @@ var domprops = [
|
|
|
29861
30213
|
"numberOfItems",
|
|
29862
30214
|
"numberOfOutputs",
|
|
29863
30215
|
"numberValue",
|
|
30216
|
+
"numberingSystem",
|
|
30217
|
+
"numeric",
|
|
29864
30218
|
"oMatchesSelector",
|
|
29865
30219
|
"object",
|
|
29866
30220
|
"object-fit",
|
|
@@ -31208,6 +31562,8 @@ var domprops = [
|
|
|
31208
31562
|
"searchBox",
|
|
31209
31563
|
"searchBoxJavaBridge_",
|
|
31210
31564
|
"searchParams",
|
|
31565
|
+
"second",
|
|
31566
|
+
"seconds",
|
|
31211
31567
|
"sectionRowIndex",
|
|
31212
31568
|
"secureConnectionStart",
|
|
31213
31569
|
"securePaymentConfirmationAvailability",
|
|
@@ -31856,6 +32212,9 @@ var domprops = [
|
|
|
31856
32212
|
"timeOrigin",
|
|
31857
32213
|
"timeRemaining",
|
|
31858
32214
|
"timeStamp",
|
|
32215
|
+
"timeStyle",
|
|
32216
|
+
"timeZone",
|
|
32217
|
+
"timeZoneName",
|
|
31859
32218
|
"timecode",
|
|
31860
32219
|
"timeline",
|
|
31861
32220
|
"timelineTime",
|
|
@@ -32445,6 +32804,8 @@ var domprops = [
|
|
|
32445
32804
|
"webkitdirectory",
|
|
32446
32805
|
"webkitdropzone",
|
|
32447
32806
|
"webstore",
|
|
32807
|
+
"weekday",
|
|
32808
|
+
"weeks",
|
|
32448
32809
|
"weight",
|
|
32449
32810
|
"wgslLanguageFeatures",
|
|
32450
32811
|
"whatToShow",
|
|
@@ -32521,6 +32882,8 @@ var domprops = [
|
|
|
32521
32882
|
"y2",
|
|
32522
32883
|
"yChannelSelector",
|
|
32523
32884
|
"yandex",
|
|
32885
|
+
"year",
|
|
32886
|
+
"years",
|
|
32524
32887
|
"yield",
|
|
32525
32888
|
"z",
|
|
32526
32889
|
"z-index",
|