| | |
| | | |
| | | 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) { |
| | |
| | | }); |
| | | |
| | | 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) { |
| | |
| | | } |
| | | |
| | | const mangled_names = this.mangled_names = new Set(); |
| | | unmangleable_names = new Set(); |
| | | |
| | | if (options.cache) { |
| | | this.globals.forEach(collect); |
| | | if (options.cache.props) { |
| | |
| | | descend(); |
| | | 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); |
| | |
| | | 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 => { |
| | |
| | | |
| | | 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); |
| | | } |
| | | } |