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

Minor optimization for handling blacklisted names #446

Merged
merged 1 commit into from Mar 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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