Skip to content

Commit

Permalink
Fix minify-builtins memberExpression name
Browse files Browse the repository at this point in the history
  • Loading branch information
boopathi committed Feb 17, 2017
1 parent 7f66b97 commit 31abdc2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/babel-plugin-minify-builtins/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ module.exports = function({ types: t }) {
return;
}

const expName = memberToString(path);
if (!isComputed(path) && isBuiltin(path)) {
const expName = memberToString(path.node);

if (!context.pathsToUpdate.has(expName)) {
context.pathsToUpdate.set(expName, []);
}
Expand All @@ -44,7 +45,6 @@ module.exports = function({ types: t }) {
return;
}

const expName = memberToString(callee);
// computed property should be not optimized
// Math[max]() -> Math.max()
if (!isComputed(callee) && isBuiltin(callee)) {
Expand All @@ -55,6 +55,8 @@ module.exports = function({ types: t }) {
if (result.confident && hasPureArgs(path)) {
path.replaceWith(t.valueToNode(result.value));
} else {
const expName = memberToString(callee.node);

if (!context.pathsToUpdate.has(expName)) {
context.pathsToUpdate.set(expName, []);
}
Expand Down Expand Up @@ -98,7 +100,7 @@ module.exports = function({ types: t }) {
};

function memberToString(memberExpr) {
const { object, property } = memberExpr.node;
const { object, property } = memberExpr;
let result = "";

if (t.isIdentifier(object)) result += object.name;
Expand Down

0 comments on commit 31abdc2

Please sign in to comment.