UNPKG

1.16 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8function _helperPluginUtils() {
9 const data = require("@babel/helper-plugin-utils");
10
11 _helperPluginUtils = function () {
12 return data;
13 };
14
15 return data;
16}
17
18function _core() {
19 const data = require("@babel/core");
20
21 _core = function () {
22 return data;
23 };
24
25 return data;
26}
27
28var _default = (0, _helperPluginUtils().declare)(api => {
29 api.assertVersion(7);
30 return {
31 visitor: {
32 BinaryExpression(path) {
33 const {
34 node
35 } = path;
36
37 if (node.operator === "instanceof") {
38 const helper = this.addHelper("instanceof");
39 const isUnderHelper = path.findParent(path => {
40 return path.isVariableDeclarator() && path.node.id === helper || path.isFunctionDeclaration() && path.node.id && path.node.id.name === helper.name;
41 });
42
43 if (isUnderHelper) {
44 return;
45 } else {
46 path.replaceWith(_core().types.callExpression(helper, [node.left, node.right]));
47 }
48 }
49 }
50
51 }
52 };
53});
54
55exports.default = _default;
\No newline at end of file