diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-822/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-822/actual.js new file mode 100644 index 000000000..c50da617e --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-822/actual.js @@ -0,0 +1,32 @@ +function d3_svg_line(projection) { + var x = d3_geom_pointX, + y = d3_geom_pointY, + defined = d3_true, + interpolate = d3_svg_lineLinear, + interpolateKey = interpolate.key, + tension = 0.7; + + function line(data) { + var segments = [], + points = [], + i = -1, + n = data.length, + d, + fx = d3_functor(x); + function segment() { + segments.push("M", interpolate(projection(points), tension)); + } + while (++i < n) { + if (defined.call(this, (d = data[i]), i)) { + points.push([+fx.call(this, d, i)]); + } else if (points.length) { + segment(); + points = []; + } + } + if (points.length) segment(); + return segments.length ? segments.join("") : null; + } + + return line; +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-822/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-822/expected.js new file mode 100644 index 000000000..d47113d3a --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-822/expected.js @@ -0,0 +1,35 @@ +function d3_svg_line(a) { + var c = d3_geom_pointX, + d = d3_geom_pointY, + e = d3_true, + f = d3_svg_lineLinear, + g = f.key, + h = 0.7; + + function b(b) { + var j = [], + k = [], + l = -1, + m = b.length, + n, + o = d3_functor(c); + + function g() { + j.push("M", f(a(k), h)); + } + + while (++l < m) { + if (e.call(this, n = b[l], l)) { + k.push([+o.call(this, n, l)]); + } else if (k.length) { + g(); + k = []; + } + } + + if (k.length) g(); + return j.length ? j.join("") : null; + } + + return b; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/src/index.js b/packages/babel-plugin-minify-mangle-names/src/index.js index 49d908a3a..1b20fc8e5 100644 --- a/packages/babel-plugin-minify-mangle-names/src/index.js +++ b/packages/babel-plugin-minify-mangle-names/src/index.js @@ -131,6 +131,11 @@ module.exports = babel => { // Collect bindings defined in the scope Object.keys(scope.bindings).forEach(name => { scopeTracker.addBinding(scope.bindings[name]); + + // add all constant violations as references + scope.bindings[name].constantViolations.forEach(() => { + scopeTracker.addReference(scope, scope.bindings[name], name); + }); }); },