added instanceOf plugin to preset es2015 (#6257)
* added instanceOf plugin to preset es2015 * fixed test cases
This commit is contained in:
committed by
Justin Ridgewell
parent
f5ad86c5c6
commit
3cdb7d7f0f
@@ -4,12 +4,20 @@ export default function({ types: t }) {
|
||||
BinaryExpression(path) {
|
||||
const { node } = path;
|
||||
if (node.operator === "instanceof") {
|
||||
path.replaceWith(
|
||||
t.callExpression(this.addHelper("instanceof"), [
|
||||
node.left,
|
||||
node.right,
|
||||
]),
|
||||
);
|
||||
const helper = this.addHelper("instanceof");
|
||||
const isUnderHelper = path.findParent(path => {
|
||||
return (
|
||||
(path.isVariableDeclarator() && path.node.id === helper) ||
|
||||
(path.isFunctionDeclaration() &&
|
||||
path.node.id.name === helper.name)
|
||||
);
|
||||
});
|
||||
|
||||
if (isUnderHelper) {
|
||||
return;
|
||||
} else {
|
||||
path.replaceWith(t.callExpression(helper, [node.left, node.right]));
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user