{"version":3,"sources":["../../../../src/build/babel/plugins/jsx-pragma.ts"],"sourcesContent":["import type {\n NodePath,\n types as BabelTypes,\n} from 'next/dist/compiled/babel/core'\nimport type { PluginObj } from 'next/dist/compiled/babel/core'\nimport jsx from 'next/dist/compiled/babel/plugin-syntax-jsx'\n\nexport default function ({\n types: t,\n}: {\n types: typeof BabelTypes\n}): PluginObj {\n return {\n inherits: jsx,\n visitor: {\n JSXElement(_path, state) {\n state.set('jsx', true)\n },\n\n // Fragment syntax is still JSX since it compiles to createElement(),\n // but JSXFragment is not a JSXElement\n JSXFragment(_path, state) {\n state.set('jsx', true)\n },\n\n Program: {\n exit(path: NodePath, state) {\n if (state.get('jsx')) {\n const pragma = t.identifier(state.opts.pragma)\n let importAs = pragma\n\n // if there's already a React in scope, use that instead of adding an import\n const existingBinding =\n state.opts.reuseImport !== false &&\n state.opts.importAs &&\n path.scope.getBinding(state.opts.importAs)\n\n // var _jsx = _pragma.createElement;\n if (state.opts.property) {\n if (state.opts.importAs) {\n importAs = t.identifier(state.opts.importAs)\n } else {\n importAs = path.scope.generateUidIdentifier('pragma')\n }\n\n const mapping = t.variableDeclaration('var', [\n t.variableDeclarator(\n pragma,\n t.memberExpression(\n importAs,\n t.identifier(state.opts.property)\n )\n ),\n ])\n\n // if the React binding came from a require('react'),\n // make sure that our usage comes after it.\n let newPath: NodePath\n\n if (\n existingBinding &&\n t.isVariableDeclarator(existingBinding.path.node) &&\n t.isCallExpression(existingBinding.path.node.init) &&\n t.isIdentifier(existingBinding.path.node.init.callee) &&\n existingBinding.path.node.init.callee.name === 'require'\n ) {\n ;[newPath] =\n existingBinding.path.parentPath.insertAfter(mapping)\n } else {\n ;[newPath] = path.unshiftContainer('body', mapping)\n }\n\n path.scope.registerDeclaration(newPath)\n }\n\n if (!existingBinding) {\n const importSpecifier = t.importDeclaration(\n [\n state.opts.import\n ? // import { $import as _pragma } from '$module'\n t.importSpecifier(\n importAs,\n t.identifier(state.opts.import)\n )\n : state.opts.importNamespace\n ? t.importNamespaceSpecifier(importAs)\n : // import _pragma from '$module'\n t.importDefaultSpecifier(importAs),\n ],\n t.stringLiteral(state.opts.module || 'react')\n )\n\n const [newPath] = path.unshiftContainer('body', importSpecifier)\n for (const specifier of newPath.get('specifiers')) {\n path.scope.registerBinding(\n 'module',\n specifier as NodePath\n )\n }\n }\n }\n },\n },\n },\n }\n}\n"],"names":["jsx","types","t","inherits","visitor","JSXElement","_path","state","set","JSXFragment","Program","exit","path","get","pragma","identifier","opts","importAs","existingBinding","reuseImport","scope","getBinding","property","generateUidIdentifier","mapping","variableDeclaration","variableDeclarator","memberExpression","newPath","isVariableDeclarator","node","isCallExpression","init","isIdentifier","callee","name","parentPath","insertAfter","unshiftContainer","registerDeclaration","importSpecifier","importDeclaration","import","importNamespace","importNamespaceSpecifier","importDefaultSpecifier","stringLiteral","module","specifier","registerBinding"],"mappings":"AAKA,OAAOA,SAAS,6CAA4C;AAE5D,eAAe,SAAU,EACvBC,OAAOC,CAAC,EAGT;IACC,OAAO;QACLC,UAAUH;QACVI,SAAS;YACPC,YAAWC,KAAK,EAAEC,KAAK;gBACrBA,MAAMC,GAAG,CAAC,OAAO;YACnB;YAEA,qEAAqE;YACrE,sCAAsC;YACtCC,aAAYH,KAAK,EAAEC,KAAK;gBACtBA,MAAMC,GAAG,CAAC,OAAO;YACnB;YAEAE,SAAS;gBACPC,MAAKC,IAAkC,EAAEL,KAAK;oBAC5C,IAAIA,MAAMM,GAAG,CAAC,QAAQ;wBACpB,MAAMC,SAASZ,EAAEa,UAAU,CAACR,MAAMS,IAAI,CAACF,MAAM;wBAC7C,IAAIG,WAAWH;wBAEf,4EAA4E;wBAC5E,MAAMI,kBACJX,MAAMS,IAAI,CAACG,WAAW,KAAK,SAC3BZ,MAAMS,IAAI,CAACC,QAAQ,IACnBL,KAAKQ,KAAK,CAACC,UAAU,CAACd,MAAMS,IAAI,CAACC,QAAQ;wBAE3C,oCAAoC;wBACpC,IAAIV,MAAMS,IAAI,CAAC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