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

fix: mangling variables in default parameters #1024

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions packages/babel-plugin-minify-mangle-names/src/scope-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = class ScopeTracker {
addReference(scope, binding, name) {
let parent = scope;
do {
this.references.get(parent).add(name);
(this.references.get(parent) || this.references.get(parent.parent)).add(name);
if (!binding) {
throw new Error(
`Binding Not Found for ${name} during scopeTracker.addRefernce. ` +
Expand All @@ -60,7 +60,7 @@ module.exports = class ScopeTracker {
* @param {String} name
*/
hasReference(scope, name) {
return this.references.get(scope).has(name);
return (this.references.get(scope) || this.references.get(scope.parent)).has(name);
}

/**
Expand All @@ -75,7 +75,7 @@ module.exports = class ScopeTracker {
updateReference(scope, binding, oldName, newName) {
let parent = scope;
do {
const ref = this.references.get(parent);
const ref = this.references.get(parent) || this.references.get(parent.parent);

ref.delete(oldName);
ref.add(newName);
Expand Down Expand Up @@ -193,7 +193,7 @@ module.exports = class ScopeTracker {
return;
}

const bindings = this.bindings.get(binding.scope);
const bindings = this.bindings.get(binding.scope) || this.bindings.get(binding.scope.parent);
const existingBinding = bindings.get(binding.identifier.name);

if (existingBinding && existingBinding !== binding) {
Expand All @@ -216,8 +216,8 @@ module.exports = class ScopeTracker {
* @param {Scope} toScope
*/
moveBinding(binding, toScope) {
this.bindings.get(binding.scope).delete(binding.identifier.name);
this.bindings.get(toScope).set(binding.identifier.name, binding);
(this.bindings.get(binding.scope) || this.bindings.get(binding.scope.parent)).delete(binding.identifier.name);
(this.bindings.get(toScope) || this.bindings.get(toScope.parent)).set(binding.identifier.name, binding);
}

/**
Expand All @@ -226,7 +226,7 @@ module.exports = class ScopeTracker {
* @param {String} name
*/
hasBinding(scope, name) {
return this.bindings.get(scope).has(name);
return (this.bindings.get(scope) || this.bindings.get(scope.parent)).has(name);
}

/**
Expand All @@ -236,7 +236,7 @@ module.exports = class ScopeTracker {
* @param {String} newName
*/
renameBinding(scope, oldName, newName) {
const bindings = this.bindings.get(scope);
const bindings = this.bindings.get(scope) || this.bindings.get(scope.parent);
bindings.set(newName, bindings.get(oldName));
bindings.delete(oldName);
}
Expand Down