Skip to content

Commit

Permalink
Minor optimization for handling blacklisted names (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
hzlmn authored and boopathi committed Mar 1, 2017
1 parent ca9c3fe commit 6d13e6b
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/babel-plugin-minify-mangle-names/src/index.js
Expand Up @@ -21,7 +21,7 @@ module.exports = ({ types: t, traverse }) => {
} = {}) {
this.charset = charset;
this.program = program;
this.blacklist = blacklist;
this.blacklist = toObject(blacklist);
this.keepFnName = keepFnName;
this.keepClassName = keepClassName;
this.eval = _eval;
Expand All @@ -46,9 +46,6 @@ module.exports = ({ types: t, traverse }) => {
}

isBlacklist(name) {
if (Array.isArray(this.blacklist)) {
return this.blacklist.indexOf(name) !== -1;
}
return hop.call(this.blacklist, name) && this.blacklist[name];
}

Expand Down Expand Up @@ -311,6 +308,19 @@ class Charset {
}
}

// convert value to object
function toObject(value) {
if (!Array.isArray(value)) {
return value;
}

const map = {};
for (let i = 0; i < value.length; i++) {
map[value[i]] = true;
}
return map;
}

// for keepFnName
function isFunction(path) {
return path.isFunctionExpression()
Expand Down

0 comments on commit 6d13e6b

Please sign in to comment.