fix(compiler): reserve api as a runtime binding to avoid client-scope collision
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -61,6 +61,7 @@ const RUNTIME_BINDINGS = new Set([
|
|||||||
"server",
|
"server",
|
||||||
"props",
|
"props",
|
||||||
"refs",
|
"refs",
|
||||||
|
"api",
|
||||||
"event",
|
"event",
|
||||||
"payload",
|
"payload",
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -80,3 +80,31 @@ test("a block without an error section still emits its response body", () => {
|
|||||||
expect(generated).toContain("plainUsers");
|
expect(generated).toContain("plainUsers");
|
||||||
expect(generated).toContain("data.users");
|
expect(generated).toContain("data.users");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("a state field named api does not collide with the emitted api object", () => {
|
||||||
|
const generated = generateTargets(
|
||||||
|
parse(`page Repro {
|
||||||
|
state {
|
||||||
|
api = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
client {
|
||||||
|
${BLOCK}
|
||||||
|
}
|
||||||
|
|
||||||
|
functions {
|
||||||
|
client async function run(): Promise<void> {
|
||||||
|
const users = await api.searchUsers({ name: "Ajay" })
|
||||||
|
console.log(users)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
view { <main><button @click="run()">go</button></main> }
|
||||||
|
}
|
||||||
|
`),
|
||||||
|
).browser;
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
new Function(generated.replace(/^\s*import[^\n]*$/gm, "").replace(/\bexport\s+/g, ""));
|
||||||
|
}).not.toThrow();
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user