1
0
mirror of https://github.com/S2-/minifyfromhtml.git synced 2025-08-04 12:40:05 +02:00

update packages to latest version

This commit is contained in:
s2
2022-08-20 18:51:33 +02:00
parent 09663a35a5
commit 806ebf9a57
4513 changed files with 366205 additions and 92512 deletions

104
node_modules/terser/lib/scope.js generated vendored
View File

@@ -107,7 +107,7 @@ import {
walk
} from "./ast.js";
import {
RESERVED_WORDS,
ALL_RESERVED_WORDS,
js_error,
} from "./parse.js";
@@ -116,6 +116,11 @@ const MASK_EXPORT_WANT_MANGLE = 1 << 1;
let function_defs = null;
let unmangleable_names = null;
/**
* When defined, there is a function declaration somewhere that's inside of a block.
* See https://tc39.es/ecma262/multipage/additional-ecmascript-features-for-web-browsers.html#sec-block-level-function-declarations-web-legacy-compatibility-semantics
*/
let scopes_with_block_defuns = null;
class SymbolDef {
constructor(scope, orig, init) {
@@ -299,7 +304,14 @@ AST_Scope.DEFMETHOD("figure_out_scope", function(options, { parent_scope = null,
// scope when we encounter the AST_Defun node (which is
// instanceof AST_Scope) but we get to the symbol a bit
// later.
mark_export((node.scope = defun.parent_scope.get_defun_scope()).def_function(node, defun), 1);
const closest_scope = defun.parent_scope;
// In strict mode, function definitions are block-scoped
node.scope = tw.directives["use strict"]
? closest_scope
: closest_scope.get_defun_scope();
mark_export(node.scope.def_function(node, defun), 1);
} else if (node instanceof AST_SymbolClass) {
mark_export(defun.def_variable(node, defun), 1);
} else if (node instanceof AST_SymbolImport) {
@@ -478,7 +490,6 @@ AST_Toplevel.DEFMETHOD("def_global", function(node) {
AST_Scope.DEFMETHOD("init_scope_vars", function(parent_scope) {
this.variables = new Map(); // map name to AST_SymbolVar (variables defined in this scope; includes functions)
this.functions = new Map(); // map name to AST_SymbolDefun (functions defined in this scope)
this.uses_with = false; // will be set to true if this or some nested scope uses the `with` statement
this.uses_eval = false; // will be set to true if this or nested scope uses the global `eval`
this.parent_scope = parent_scope; // the parent scope
@@ -641,7 +652,6 @@ AST_Scope.DEFMETHOD("find_variable", function(name) {
AST_Scope.DEFMETHOD("def_function", function(symbol, init) {
var def = this.def_variable(symbol, init);
if (!def.init || def.init instanceof AST_Defun) def.init = init;
this.functions.set(symbol.name, def);
return def;
});
@@ -661,10 +671,20 @@ AST_Scope.DEFMETHOD("def_variable", function(symbol, init) {
});
function next_mangled(scope, options) {
let defun_scope;
if (
scopes_with_block_defuns
&& (defun_scope = scope.get_defun_scope())
&& scopes_with_block_defuns.has(defun_scope)
) {
scope = defun_scope;
}
var ext = scope.enclosed;
var nth_identifier = options.nth_identifier;
out: while (true) {
var m = base54(++scope.cname);
if (RESERVED_WORDS.has(m)) continue; // skip over "do"
var m = nth_identifier.get(++scope.cname);
if (ALL_RESERVED_WORDS.has(m)) continue; // skip over "do"
// https://github.com/mishoo/UglifyJS2/issues/242 -- do not
// shadow a name reserved from mangling.
@@ -739,6 +759,7 @@ AST_Symbol.DEFMETHOD("global", function() {
AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options) {
options = defaults(options, {
eval : false,
nth_identifier : base54,
ie8 : false,
keep_classnames: false,
keep_fnames : false,
@@ -760,6 +781,7 @@ AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options) {
AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
options = this._default_mangler_options(options);
var nth_identifier = options.nth_identifier;
// We only need to mangle declaration nodes. Special logic wired
// into the code generator will display the mangled name if it's
@@ -773,6 +795,8 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
}
const mangled_names = this.mangled_names = new Set();
unmangleable_names = new Set();
if (options.cache) {
this.globals.forEach(collect);
if (options.cache.props) {
@@ -790,6 +814,13 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
lname = save_nesting;
return true; // don't descend again in TreeWalker
}
if (
node instanceof AST_Defun
&& !(tw.parent() instanceof AST_Scope)
) {
scopes_with_block_defuns = scopes_with_block_defuns || new Set();
scopes_with_block_defuns.add(node.parent_scope.get_defun_scope());
}
if (node instanceof AST_Scope) {
node.variables.forEach(collect);
return;
@@ -811,8 +842,8 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
if (node instanceof AST_Label) {
let name;
do {
name = base54(++lname);
} while (RESERVED_WORDS.has(name));
name = nth_identifier.get(++lname);
} while (ALL_RESERVED_WORDS.has(name));
node.mangled_name = name;
return true;
}
@@ -825,7 +856,6 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
this.walk(tw);
if (options.keep_fnames || options.keep_classnames) {
unmangleable_names = new Set();
// Collect a set of short names which are unmangleable,
// for use in avoiding collisions in next_mangled.
to_mangle.forEach(def => {
@@ -839,11 +869,12 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
function_defs = null;
unmangleable_names = null;
scopes_with_block_defuns = null;
function collect(symbol) {
const should_mangle = !options.reserved.has(symbol.name)
&& !(symbol.export & MASK_EXPORT_DONT_MANGLE);
if (should_mangle) {
if (symbol.export & MASK_EXPORT_DONT_MANGLE) {
unmangleable_names.add(symbol.name);
} else if (!options.reserved.has(symbol.name)) {
to_mangle.push(symbol);
}
}
@@ -873,9 +904,12 @@ AST_Toplevel.DEFMETHOD("find_colliding_names", function(options) {
});
AST_Toplevel.DEFMETHOD("expand_names", function(options) {
base54.reset();
base54.sort();
options = this._default_mangler_options(options);
var nth_identifier = options.nth_identifier;
if (nth_identifier.reset && nth_identifier.sort) {
nth_identifier.reset();
nth_identifier.sort();
}
var avoid = this.find_colliding_names(options);
var cname = 0;
this.globals.forEach(rename);
@@ -887,8 +921,8 @@ AST_Toplevel.DEFMETHOD("expand_names", function(options) {
function next_name() {
var name;
do {
name = base54(cname++);
} while (avoid.has(name) || RESERVED_WORDS.has(name));
name = nth_identifier.get(cname++);
} while (avoid.has(name) || ALL_RESERVED_WORDS.has(name));
return name;
}
@@ -914,30 +948,37 @@ AST_Sequence.DEFMETHOD("tail_node", function() {
AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options) {
options = this._default_mangler_options(options);
var nth_identifier = options.nth_identifier;
if (!nth_identifier.reset || !nth_identifier.consider || !nth_identifier.sort) {
// If the identifier mangler is invariant, skip computing character frequency.
return;
}
nth_identifier.reset();
try {
AST_Node.prototype.print = function(stream, force_parens) {
this._print(stream, force_parens);
if (this instanceof AST_Symbol && !this.unmangleable(options)) {
base54.consider(this.name, -1);
nth_identifier.consider(this.name, -1);
} else if (options.properties) {
if (this instanceof AST_DotHash) {
base54.consider("#" + this.property, -1);
nth_identifier.consider("#" + this.property, -1);
} else if (this instanceof AST_Dot) {
base54.consider(this.property, -1);
nth_identifier.consider(this.property, -1);
} else if (this instanceof AST_Sub) {
skip_string(this.property);
}
}
};
base54.consider(this.print_to_string(), 1);
nth_identifier.consider(this.print_to_string(), 1);
} finally {
AST_Node.prototype.print = AST_Node.prototype._print;
}
base54.sort();
nth_identifier.sort();
function skip_string(node) {
if (node instanceof AST_String) {
base54.consider(node.value, -1);
nth_identifier.consider(node.value, -1);
} else if (node instanceof AST_Conditional) {
skip_string(node.consequent);
skip_string(node.alternative);
@@ -961,19 +1002,20 @@ const base54 = (() => {
frequency.set(ch, 0);
});
}
base54.consider = function(str, delta) {
function consider(str, delta) {
for (var i = str.length; --i >= 0;) {
frequency.set(str[i], frequency.get(str[i]) + delta);
}
};
}
function compare(a, b) {
return frequency.get(b) - frequency.get(a);
}
base54.sort = function() {
function sort() {
chars = mergeSort(leading, compare).concat(mergeSort(digits, compare));
};
base54.reset = reset;
}
// Ensure this is in a usable initial state.
reset();
sort();
function base54(num) {
var ret = "", base = 54;
num++;
@@ -985,7 +1027,13 @@ const base54 = (() => {
} while (num > 0);
return ret;
}
return base54;
return {
get: base54,
consider,
reset,
sort
};
})();
export {