Skip to content

Commit

Permalink
add some tests and use indexOf
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshshanmugam committed Feb 16, 2017
1 parent 3686b0d commit 173bfcf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Expand Up @@ -67,10 +67,12 @@ function a() {
}
`;

exports[`minify-builtins should not evaluate if its has side effecty arguments 1`] = `
exports[`minify-builtins should not evaluate if its side effecty 1`] = `
Object {
"_source": "Math.max(foo(), 1);",
"expected": "Math.max(foo(), 1);",
"_source": "Math.max(foo(), 1);
Math.random();",
"expected": "Math.max(foo(), 1);
Math.random();",
}
`;

Expand Down
Expand Up @@ -68,9 +68,10 @@ describe("minify-builtins", () => {
expect({_source: source, expected: transform(source)}).toMatchSnapshot();
});

it("should not evaluate if its has side effecty arguments", () => {
it("should not evaluate if its side effecty", () => {
const source = unpad(`
Math.max(foo(), 1);
Math.random();
`);
expect({_source: source, expected: transform(source)}).toMatchSnapshot();
});
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-plugin-minify-builtins/src/index.js
Expand Up @@ -112,8 +112,8 @@ module.exports = function({ types: t }) {
const { object, property } = memberExpr.node;

if (t.isIdentifier(object) && t.isIdentifier(property)
&& VALID_CALLEES.includes(object.name)
&& !INVALID_METHODS.includes(property.name)) {
&& VALID_CALLEES.indexOf(object.name) >= 0
&& INVALID_METHODS.indexOf(property.name) < 0) {
return true;
}
return false;
Expand Down

0 comments on commit 173bfcf

Please sign in to comment.