mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Fix importing empty toml file at runtime (#13252)
This commit is contained in:
@@ -1789,6 +1789,17 @@ pub const ModuleLoader = struct {
|
||||
}
|
||||
|
||||
if (loader == .json or loader == .toml) {
|
||||
if (parse_result.empty) {
|
||||
return ResolvedSource{
|
||||
.allocator = null,
|
||||
.specifier = input_specifier,
|
||||
.source_url = input_specifier.createIfDifferent(path.text),
|
||||
.hash = 0,
|
||||
.jsvalue_for_export = JSC.JSValue.createEmptyObject(jsc_vm.global, 0),
|
||||
.tag = .exports_object,
|
||||
};
|
||||
}
|
||||
|
||||
return ResolvedSource{
|
||||
.allocator = null,
|
||||
.specifier = input_specifier,
|
||||
|
||||
24
test/js/bun/resolve/jsonc.test.ts
Normal file
24
test/js/bun/resolve/jsonc.test.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { test, expect } from "bun:test";
|
||||
import { join } from "path";
|
||||
import { tempDirWithFiles } from "harness";
|
||||
test("empty jsonc - package.json", async () => {
|
||||
const dir = tempDirWithFiles("jsonc", {
|
||||
"package.json": ``,
|
||||
"index.ts": `
|
||||
import pkg from './package.json';
|
||||
if (JSON.stringify(pkg) !== '{}') throw new Error('package.json should be empty');
|
||||
`,
|
||||
});
|
||||
expect([join(dir, "index.ts")]).toRun();
|
||||
});
|
||||
|
||||
test("empty jsonc - tsconfig.json", async () => {
|
||||
const dir = tempDirWithFiles("jsonc", {
|
||||
"tsconfig.json": ``,
|
||||
"index.ts": `
|
||||
import tsconfig from './tsconfig.json';
|
||||
if (JSON.stringify(tsconfig) !== '{}') throw new Error('tsconfig.json should be empty');
|
||||
`,
|
||||
});
|
||||
expect([join(dir, "index.ts")]).toRun();
|
||||
});
|
||||
0
test/js/bun/resolve/toml/toml-empty.toml
Normal file
0
test/js/bun/resolve/toml/toml-empty.toml
Normal file
@@ -1,5 +1,6 @@
|
||||
import { expect, it } from "bun:test";
|
||||
import tomlFromCustomTypeAttribute from "./toml-fixture.toml.txt" with { type: "toml" };
|
||||
import emptyToml from "./toml-empty.toml";
|
||||
|
||||
function checkToml(toml) {
|
||||
expect(toml.framework).toBe("next");
|
||||
@@ -35,3 +36,7 @@ it("via dynamic import with type attribute", async () => {
|
||||
const toml = (await import("./toml-fixture.toml.txt", { with: { type: "toml" } })).default;
|
||||
checkToml(toml);
|
||||
});
|
||||
|
||||
it("empty via import statement", () => {
|
||||
expect(emptyToml).toEqual({});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user