/
githubmirror
/
babel
Обзор
Документация
Войти
/
githubmirror
/
babel
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/babel-plugin-transform-modules-commonjs/src/dynamic-import.ts
28 строк
896 B
liuxingbaoyu
Enable `strictNullChecks` for all packages (#17844)
08 мар 2026, 01:39
Не верифицирован
08 мар 2026, 01:39
10e8a1b
Код
Авторство
О чём код?
// Heavily inspired by // https://github.com/airbnb/babel-plugin-dynamic-import-node/blob/master/src/utils.js import type { File, NodePath } from "@babel/core"; import { types as t, template } from "@babel/core"; import { buildDynamicImport } from "@babel/helper-module-transforms"; const requireNoInterop = (source: t.Expression) => template.expression.ast`require(${source})`; const requireInterop = (source: t.Expression, file: File) => t.callExpression(file.addHelper("interopRequireWildcard"), [ requireNoInterop(source), ]); export function transformDynamicImport( path: NodePath<t.CallExpression | t.ImportExpression>, noInterop: boolean | undefined, file: File, ) { const buildRequire = noInterop ? requireNoInterop : requireInterop; path.replaceWith( buildDynamicImport(path.node, true, false, specifier => buildRequire(specifier, file), ), ); }