UNPKG

2.41 kBSource Map (JSON)View Raw
1{"version":3,"names":["_helperPluginUtils","require","_core","_default","declare","api","assertVersion","name","visitor","BinaryExpression","path","node","operator","helper","addHelper","isUnderHelper","findParent","isVariableDeclarator","id","isFunctionDeclaration","replaceWith","t","callExpression","left","right","exports","default"],"sources":["../src/index.ts"],"sourcesContent":["import { declare } from \"@babel/helper-plugin-utils\";\nimport { types as t } from \"@babel/core\";\n\nexport default declare(api => {\n api.assertVersion(7);\n\n return {\n name: \"transform-instanceof\",\n\n visitor: {\n BinaryExpression(path) {\n const { node } = path;\n if (node.operator === \"instanceof\") {\n const helper = this.addHelper(\"instanceof\");\n const isUnderHelper = path.findParent(path => {\n return (\n (path.isVariableDeclarator() && path.node.id === helper) ||\n (path.isFunctionDeclaration() &&\n path.node.id &&\n path.node.id.name === helper.name)\n );\n });\n\n if (isUnderHelper) {\n return;\n } else {\n path.replaceWith(\n t.callExpression(helper, [\n // @ts-expect-error node.left can be PrivateName only when node.operator is \"in\"\n node.left,\n node.right,\n ]),\n );\n }\n }\n },\n },\n };\n});\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAAyC,IAAAE,QAAA,GAE1B,IAAAC,0BAAO,EAACC,GAAG,IAAI;EAC5BA,GAAG,CAACC,aAAa,CAAC,CAAC,CAAC;EAEpB,OAAO;IACLC,IAAI,EAAE,sBAAsB;IAE5BC,OAAO,EAAE;MACPC,gBAAgBA,CAACC,IAAI,EAAE;QACrB,MAAM;UAAEC;QAAK,CAAC,GAAGD,IAAI;QACrB,IAAIC,IAAI,CAACC,QAAQ,KAAK,YAAY,EAAE;UAClC,MAAMC,MAAM,GAAG,IAAI,CAACC,SAAS,CAAC,YAAY,CAAC;UAC3C,MAAMC,aAAa,GAAGL,IAAI,CAACM,UAAU,CAACN,IAAI,IAAI;YAC5C,OACGA,IAAI,CAACO,oBAAoB,CAAC,CAAC,IAAIP,IAAI,CAACC,IAAI,CAACO,EAAE,KAAKL,MAAM,IACtDH,IAAI,CAACS,qBAAqB,CAAC,CAAC,IAC3BT,IAAI,CAACC,IAAI,CAACO,EAAE,IACZR,IAAI,CAACC,IAAI,CAACO,EAAE,CAACX,IAAI,KAAKM,MAAM,CAACN,IAAK;UAExC,CAAC,CAAC;UAEF,IAAIQ,aAAa,EAAE;YACjB;UACF,CAAC,MAAM;YACLL,IAAI,CAACU,WAAW,CACdC,WAAC,CAACC,cAAc,CAACT,MAAM,EAAE,CAEvBF,IAAI,CAACY,IAAI,EACTZ,IAAI,CAACa,KAAK,CACX,CACH,CAAC;UACH;QACF;MACF;IACF;EACF,CAAC;AACH,CAAC,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAAvB,QAAA"}
\No newline at end of file