Revert "fix passing nested object to macro" (#20495)

This commit is contained in:
Meghan Denny
2025-06-19 12:14:46 -08:00
committed by GitHub
parent 43777cffee
commit d4ccba67f2
5 changed files with 4 additions and 69 deletions

View File

@@ -397,12 +397,6 @@ pub const JSValue = enum(i64) {
JSC__JSValue__putMayBeIndex(this, globalObject, key, value);
}
extern fn JSC__JSValue__putToPropertyKey(target: JSValue, globalObject: *JSGlobalObject, key: JSC.JSValue, value: JSC.JSValue) void;
pub fn putToPropertyKey(target: JSValue, globalObject: *JSGlobalObject, key: JSC.JSValue, value: JSC.JSValue) error{JSError}!void {
JSC__JSValue__putToPropertyKey(target, globalObject, key, value);
if (globalObject.hasException()) return error.JSError;
}
extern fn JSC__JSValue__putIndex(value: JSValue, globalObject: *JSGlobalObject, i: u32, out: JSValue) void;
pub fn putIndex(value: JSValue, globalObject: *JSGlobalObject, i: u32, out: JSValue) void {
JSC__JSValue__putIndex(value, globalObject, i, out);

View File

@@ -3664,19 +3664,6 @@ void JSC__JSValue__put(JSC::EncodedJSValue JSValue0, JSC::JSGlobalObject* arg1,
object->putDirect(arg1->vm(), Zig::toIdentifier(*arg2, arg1), JSC::JSValue::decode(JSValue3));
}
void JSC__JSValue__putToPropertyKey(JSC::EncodedJSValue JSValue0, JSC::JSGlobalObject* arg1, JSC::EncodedJSValue arg2, JSC::EncodedJSValue arg3)
{
auto& vm = JSC::getVM(arg1);
auto scope = DECLARE_THROW_SCOPE(vm);
auto obj = JSValue::decode(JSValue0);
auto key = JSValue::decode(arg2);
auto value = JSValue::decode(arg3);
auto object = obj.asCell()->getObject();
auto pkey = key.toPropertyKey(arg1);
RETURN_IF_EXCEPTION(scope, );
object->putDirectMayBeIndex(arg1, pkey, value);
}
extern "C" void JSC__JSValue__putMayBeIndex(JSC::EncodedJSValue target, JSC::JSGlobalObject* globalObject, const BunString* key, JSC::EncodedJSValue value)
{
auto& vm = JSC::getVM(globalObject);

View File

@@ -1967,12 +1967,11 @@ pub const E = struct {
defer obj.unprotect();
const props: []const G.Property = this.properties.slice();
for (props) |prop| {
if (prop.kind != .normal or prop.class_static_block != null or prop.key == null or prop.value == null) {
if (prop.kind != .normal or prop.class_static_block != null or prop.key == null or prop.key.?.data != .e_string or prop.value == null) {
return error.@"Cannot convert argument type to JS";
}
const key = try prop.key.?.data.toJS(allocator, globalObject);
const value = try prop.value.?.toJS(allocator, globalObject);
try obj.putToPropertyKey(globalObject, key, value);
var key = prop.key.?.data.e_string.toZigString(allocator);
obj.put(globalObject, &key, try prop.value.?.toJS(allocator, globalObject));
}
return obj;

View File

@@ -1,9 +1,8 @@
import assert from "assert";
import { describe, expect, test } from "bun:test";
import { readFileSync, writeFileSync } from "fs";
import { bunEnv, bunExe, tempDirWithFiles, tempDirWithFilesAnon } from "harness";
import { bunEnv, bunExe, tempDirWithFiles } from "harness";
import path, { join } from "path";
import { cwd } from "process";
import { buildNoThrow } from "./buildNoThrow";
describe("Bun.build", () => {
@@ -633,41 +632,3 @@ test("onEnd Plugin does not crash", async () => {
})(),
).rejects.toThrow("On-end callbacks is not implemented yet. See https://github.com/oven-sh/bun/issues/2771");
});
test("macro with nested object", async () => {
const dir = tempDirWithFilesAnon({
"index.ts": `
import { testMacro } from "./macro" assert { type: "macro" };
export const testConfig = testMacro({
borderRadius: {
1: "4px",
2: "8px",
},
});
`,
"macro.ts": `
export function testMacro(val: any) {
return val;
}
`,
});
const build = await Bun.build({
entrypoints: [join(dir, "index.ts")],
});
expect(build.outputs).toHaveLength(1);
expect(build.outputs[0].kind).toBe("entry-point");
expect(await build.outputs[0].text()).toEqualIgnoringWhitespace(`// ${path.relative(cwd(), dir)}/index.ts
var testConfig = {
borderRadius: {
"1": "4px",
"2": "8px"
}
};
export {
testConfig
};
`);
});

View File

@@ -262,12 +262,6 @@ export function tempDirWithFiles(
return base;
}
export function tempDirWithFilesAnon(filesOrAbsolutePathToCopyFolderFrom: DirectoryTree | string): string {
const base = tmpdirSync();
makeTreeSync(base, filesOrAbsolutePathToCopyFolderFrom);
return base;
}
export function bunRun(file: string, env?: Record<string, string> | NodeJS.ProcessEnv) {
var path = require("path");
const result = Bun.spawnSync([bunExe(), file], {