mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
* fix #2370 and import-meta test * edit test to not allow transpiler optimization
This commit is contained in:
@@ -84,9 +84,11 @@ static EncodedJSValue functionRequireResolve(JSC::JSGlobalObject* globalObject,
|
||||
// require.resolve also supports a paths array
|
||||
// we only support a single path
|
||||
if (!fromValue.isUndefinedOrNull() && fromValue.isObject()) {
|
||||
if (JSC::JSArray* array = JSC::jsDynamicCast<JSC::JSArray*>(fromValue.getObject()->getIfPropertyExists(globalObject, JSC::Identifier::fromString(vm, "paths"_s)))) {
|
||||
if (array->length() > 0) {
|
||||
fromValue = array->getIndex(globalObject, 0);
|
||||
if (JSValue pathsValue = fromValue.getObject()->getIfPropertyExists(globalObject, JSC::Identifier::fromString(vm, "paths"_s))) {
|
||||
if (JSC::JSArray* array = JSC::jsDynamicCast<JSC::JSArray*>(pathsValue)) {
|
||||
if (array->length() > 0) {
|
||||
fromValue = array->getIndex(globalObject, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { it, expect } from "bun:test";
|
||||
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
||||
import * as Module from "node:module";
|
||||
import sync from "./require-json.json.js";
|
||||
import sync from "./require-json.json";
|
||||
|
||||
const { path, dir } = import.meta;
|
||||
|
||||
@@ -50,7 +50,7 @@ it("require with a query string works on dynamically created content", () => {
|
||||
it("import.meta.require (json)", () => {
|
||||
expect(import.meta.require("./require-json.json").hello).toBe(sync.hello);
|
||||
const require = Module.createRequire(import.meta.path);
|
||||
expect(require("./require-json.json.js").hello).toBe(sync.hello);
|
||||
expect(require("./require-json").hello).toBe(sync.hello);
|
||||
});
|
||||
|
||||
it("const f = require;require(json)", () => {
|
||||
@@ -162,3 +162,7 @@ it('require("bun") works', () => {
|
||||
it('import("bun") works', async () => {
|
||||
expect(await import("bun")).toBe(Bun);
|
||||
});
|
||||
|
||||
it("require.resolve with empty options object", () => {
|
||||
expect(require.resolve(import.meta.path + String(""), {})).toBe(import.meta.path);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user