mirror of
https://github.com/hanzoai/babel.git
synced 2026-09-24 16:56:45 +00:00
* enable prefer-node-protocol rule * prefer node protocol import * fix broken scripts * fix e2e-old-babel error * strip node: protocol for old node versions * update Makefile.mjs
36 lines
898 B
JavaScript
36 lines
898 B
JavaScript
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);
|
|
});
|