remove es20xx prefixes from plugins and rename folders (#6575)
This commit is contained in:
26
packages/babel-plugin-transform-instanceof/src/index.js
Normal file
26
packages/babel-plugin-transform-instanceof/src/index.js
Normal file
@@ -0,0 +1,26 @@
|
||||
export default function({ types: t }) {
|
||||
return {
|
||||
visitor: {
|
||||
BinaryExpression(path) {
|
||||
const { node } = path;
|
||||
if (node.operator === "instanceof") {
|
||||
const helper = this.addHelper("instanceof");
|
||||
const isUnderHelper = path.findParent(path => {
|
||||
return (
|
||||
(path.isVariableDeclarator() && path.node.id === helper) ||
|
||||
(path.isFunctionDeclaration() &&
|
||||
path.node.id &&
|
||||
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