{"version":3,"names":["requireNoInterop","source","template","expression","ast","requireInterop","file","t","callExpression","addHelper","transformDynamicImport","path","noInterop","buildRequire","getDynamicImportSource","node","replacement","isStringLiteral","isTemplateLiteral","quasis","length","identifier","replaceWith"],"sources":["../src/dynamic-import.ts"],"sourcesContent":["// Heavily inspired by\n// https://github.com/airbnb/babel-plugin-dynamic-import-node/blob/master/src/utils.js\n\nimport type { NodePath } from \"@babel/traverse\";\nimport { types as t, template, type File } from \"@babel/core\";\nimport { getDynamicImportSource } from \"@babel/helper-module-transforms\";\n\nconst requireNoInterop = (source: t.Expression) =>\n template.expression.ast`require(${source})`;\n\nconst requireInterop = (source: t.Expression, file: File) =>\n t.callExpression(file.addHelper(\"interopRequireWildcard\"), [\n requireNoInterop(source),\n ]);\n\nexport function transformDynamicImport(\n path: NodePath,\n noInterop: boolean,\n file: File,\n) {\n const buildRequire = noInterop ? requireNoInterop : requireInterop;\n\n const source = getDynamicImportSource(path.node);\n\n const replacement =\n t.isStringLiteral(source) ||\n (t.isTemplateLiteral(source) && source.quasis.length === 0)\n ? template.expression.ast`\n Promise.resolve().then(() => ${buildRequire(source, file)})\n `\n : template.expression.ast`\n Promise.resolve(${source}).then(\n s => ${buildRequire(t.identifier(\"s\"), file)}\n )\n `;\n\n path.replaceWith(replacement);\n}\n"],"mappings":";;;;;;;AAIA;;AACA;;AAEA,MAAMA,gBAAgB,GAAIC,MAAD,IACvBC,cAAA,CAASC,UAAT,CAAoBC,GAAI,WAAUH,MAAO,GAD3C;;AAGA,MAAMI,cAAc,GAAG,CAACJ,MAAD,EAAuBK,IAAvB,KACrBC,WAAA,CAAEC,cAAF,CAAiBF,IAAI,CAACG,SAAL,CAAe,wBAAf,CAAjB,EAA2D,CACzDT,gBAAgB,CAACC,MAAD,CADyC,CAA3D,CADF;;AAKO,SAASS,sBAAT,CACLC,IADK,EAELC,SAFK,EAGLN,IAHK,EAIL;EACA,MAAMO,YAAY,GAAGD,SAAS,GAAGZ,gBAAH,GAAsBK,cAApD;EAEA,MAAMJ,MAAM,GAAG,IAAAa,8CAAA,EAAuBH,IAAI,CAACI,IAA5B,CAAf;EAEA,MAAMC,WAAW,GACfT,WAAA,CAAEU,eAAF,CAAkBhB,MAAlB,KACCM,WAAA,CAAEW,iBAAF,CAAoBjB,MAApB,KAA+BA,MAAM,CAACkB,MAAP,CAAcC,MAAd,KAAyB,CADzD,GAEIlB,cAAA,CAASC,UAAT,CAAoBC,GAAI;AAChC,uCAAuCS,YAAY,CAACZ,MAAD,EAASK,IAAT,CAAe;AAClE,OAJI,GAKIJ,cAAA,CAASC,UAAT,CAAoBC,GAAI;AAChC,0BAA0BH,MAAO;AACjC,iBAAiBY,YAAY,CAACN,WAAA,CAAEc,UAAF,CAAa,GAAb,CAAD,EAAoBf,IAApB,CAA0B;AACvD;AACA,OAVE;EAYAK,IAAI,CAACW,WAAL,CAAiBN,WAAjB;AACD"}