Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minify-mangle-names fail when default parameters are assigned to a variable #1023

Open
binary-person opened this issue Mar 15, 2022 · 0 comments · May be fixed by #1024
Open

minify-mangle-names fail when default parameters are assigned to a variable #1023

binary-person opened this issue Mar 15, 2022 · 0 comments · May be fixed by #1024

Comments

@binary-person
Copy link

Describe the bug

mangling names don't work when there is a default parameter with a value referencing another variable like this:

var abc = 123;
function lmno(abcdefg = abc) {}

This causes issues when trying to minify with mangling as described in this still open issue opened two years ago: #974

To Reproduce

Minimal code to reproduce the bug

const babel = require('@babel/core');

console.log(babel.transformSync(`
var uhoh = 'oops';
function test(first, second = '123', third = uhoh) {}

(function() {
    var uhoh1 = 'oops1';
    function test1(first1, second1 = '123', third1 = uhoh1) {}
})()
`, {
    plugins: ['minify-mangle-names'],
}).code);

Expected Output

var uhoh = 'oops';

function test(a, b = '123', c = uhoh) {}

(function () {
  var d = 'oops1';

  function b(a, b = '123', c = d) {}
})();

Stack Trace

/home/coder/project/fix-babel/node_modules/@babel/core/lib/transformation/index.js:45
    throw e;
    ^

TypeError: unknown: Cannot read properties of undefined (reading 'add')
    at ScopeTracker.addReference (/home/coder/project/fix-babel/node_modules/babel-plugin-minify-mangle-names/lib/scope-tracker.js:47:34)
    at ReferencedIdentifier (/home/coder/project/fix-babel/node_modules/babel-plugin-minify-mangle-names/lib/index.js:196:26)
    at newFn (/home/coder/project/fix-babel/node_modules/@babel/traverse/lib/visitors.js:218:17)
    at bfsTraverse (/home/coder/project/fix-babel/node_modules/babel-plugin-minify-mangle-names/lib/bfs-traverse.js:32:43)
    at Mangler.collect (/home/coder/project/fix-babel/node_modules/babel-plugin-minify-mangle-names/lib/index.js:229:7)
    at Mangler.run (/home/coder/project/fix-babel/node_modules/babel-plugin-minify-mangle-names/lib/index.js:54:12)
    at PluginPass.exit (/home/coder/project/fix-babel/node_modules/babel-plugin-minify-mangle-names/lib/index.js:558:19)
    at newFn (/home/coder/project/fix-babel/node_modules/@babel/traverse/lib/visitors.js:177:21)
    at NodePath._call (/home/coder/project/fix-babel/node_modules/@babel/traverse/lib/path/context.js:53:20)
    at NodePath.call (/home/coder/project/fix-babel/node_modules/@babel/traverse/lib/path/context.js:40:17) {
  code: 'BABEL_TRANSFORM_ERROR'
}

Configuration

package.json:

    "@babel/core": "^7.17.7",
    "babel-plugin-minify-mangle-names": "^0.5.0"

babel-minify-config: There is none

babelrc: There is none

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant