/
githubmirror
/
babel
Обзор
Документация
Войти
/
githubmirror
/
babel
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/babel-plugin-transform-modules-commonjs/test/esmodule-flag.js
35 строк
898 B
Huáng Jùnliàng
Enforce node protocol import (#17207)
31 мар 2025, 17:49
Не верифицирован
31 мар 2025, 17:49
317e332
Код
Авторство
О чём код?
import * as babel from "@babel/core"; import vm from "node:vm"; import { fileURLToPath } from "node:url"; import path from "node:path"; import transformCommonJS from "../lib/index.js"; test("Re-export doesn't overwrite __esModule flag", function () { let code = 'export * from "./dep";'; const depStub = { __esModule: false, }; const context = { module: { exports: {}, }, require: function (id) { if (id === "./dep") return depStub; throw new Error("Unexpected dependency: " + id); }, }; context.exports = context.module.exports; code = babel.transformSync(code, { cwd: path.dirname(fileURLToPath(import.meta.url)), plugins: [[transformCommonJS, { loose: true }]], ast: false, }).code; vm.runInNewContext(code, context); // exports.__esModule shouldn't be overwritten. expect(context.exports.__esModule).toBe(true); });