Skip to content

Commit

Permalink
Comment out old mangler
Browse files Browse the repository at this point in the history
+ Remove unused renamer
+ #106
  • Loading branch information
boopathi committed Aug 27, 2016
1 parent 31f4360 commit 833b8c2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 45 deletions.
95 changes: 50 additions & 45 deletions packages/babel-plugin-minify-mangle-names/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Renamer = require("./renamer");
// const Renamer = require("./renamer");

module.exports = ({ types: t }) => {
const hop = Object.prototype.hasOwnProperty;
Expand Down Expand Up @@ -123,7 +123,7 @@ module.exports = ({ types: t }) => {
// TODO:
// re-enable this
// resetNext();
mangler.renameNew(scope, b, next);
mangler.rename(scope, b, next);
});
}
});
Expand All @@ -134,7 +134,7 @@ module.exports = ({ types: t }) => {
// this.updateReferences();
}

renameNew(scope, oldName, newName) {
rename(scope, oldName, newName) {
const binding = scope.getBinding(oldName);

// rename at the declaration level
Expand Down Expand Up @@ -176,48 +176,53 @@ module.exports = ({ types: t }) => {
// TODO
}

rename(scope, oldName, newName) {
const binding = scope.getBinding(oldName);
if (!binding) {
throw new Error("Binding not found - " + oldName);
}
new Renamer(binding, oldName, newName).rename();

this.referencesToUpdate.set(oldName, {
scope,
referenced: false
});
}

updateReferences() {
const mangler = this;

this.program.traverse({
Identifier(path) {
const { node } = path;
if (
path.parentPath.isMemberExpression({ property: node }) ||
path.parentPath.isObjectProperty({key: node})
) return;

mangler.referencesToUpdate.forEach((ref, oldName) => {
if (node.name === oldName) {
mangler.referencesToUpdate.get(oldName).referenced = true;
}
});
}
});

this.referencesToUpdate.forEach((ref, oldName) => {
if (ref.referenced) return;

let current = ref.scope;
do {
current.references[oldName] = false;
}
while (current = current.parent);
});
}
// Old rename
// Suspect some bugs in new rename
//
// Will be removed once it is tested well
//
// renameOld(scope, oldName, newName) {
// const binding = scope.getBinding(oldName);
// if (!binding) {
// throw new Error("Binding not found - " + oldName);
// }
// new Renamer(binding, oldName, newName).rename();

// this.referencesToUpdate.set(oldName, {
// scope,
// referenced: false
// });
// }

// updateReferences() {
// const mangler = this;

// this.program.traverse({
// Identifier(path) {
// const { node } = path;
// if (
// path.parentPath.isMemberExpression({ property: node }) ||
// path.parentPath.isObjectProperty({key: node})
// ) return;

// mangler.referencesToUpdate.forEach((ref, oldName) => {
// if (node.name === oldName) {
// mangler.referencesToUpdate.get(oldName).referenced = true;
// }
// });
// }
// });

// this.referencesToUpdate.forEach((ref, oldName) => {
// if (ref.referenced) return;

// let current = ref.scope;
// do {
// current.references[oldName] = false;
// }
// while (current = current.parent);
// });
// }
}

return {
Expand Down
5 changes: 5 additions & 0 deletions packages/babel-plugin-minify-mangle-names/src/renamer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
* This one modifies it for one scenario -
* check the parent of a ReferencedIdentifier and don't rename Labels
*
* This file is no longer used
* Will be removed once the new renamer is tested in the wild
*
*/

// TODO: Babel-types should be installed
const t = require("babel-types");

let renameVisitor = {
Expand Down

0 comments on commit 833b8c2

Please sign in to comment.