UNPKG

@babel/plugin-transform-instanceof

Version:

This plugin transforms all the ES2015 'instanceof' methods

31 lines (28 loc) 888 B
import { declare } from '@babel/helper-plugin-utils'; import { types } from '@babel/core'; const index = declare(api => { api.assertVersion("^7.0.0-0 || ^8.0.0"); return { name: "transform-instanceof", 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?.name === helper.name; }); if (isUnderHelper) { return; } else { path.replaceWith(types.callExpression(helper, [node.left, node.right])); } } } } }; }); export { index as default }; //# sourceMappingURL=index.js.map