fix: harden generated identifiers and types
This commit is contained in:
@@ -181,6 +181,7 @@ export function generateApplicationTypes(
|
|||||||
.map((name) => join(root, name))
|
.map((name) => join(root, name))
|
||||||
.find(existsSync);
|
.find(existsSync);
|
||||||
const code = `// AUTO-GENERATED by \`wrnexus generate types\` - do not edit.
|
const code = `// AUTO-GENERATED by \`wrnexus generate types\` - do not edit.
|
||||||
|
/* eslint-disable @typescript-eslint/no-empty-object-type */
|
||||||
declare namespace WRNexusGenerated {
|
declare namespace WRNexusGenerated {
|
||||||
type ApiContract<T> = T extends import("@wrnexus/core").DefinedEndpoint<infer I, infer O>
|
type ApiContract<T> = T extends import("@wrnexus/core").DefinedEndpoint<infer I, infer O>
|
||||||
? { input: I; output: O }
|
? { input: I; output: O }
|
||||||
|
|||||||
@@ -1566,6 +1566,13 @@ const JS_RESERVED = new Set([
|
|||||||
"enum",
|
"enum",
|
||||||
"with",
|
"with",
|
||||||
"debugger",
|
"debugger",
|
||||||
|
"implements",
|
||||||
|
"interface",
|
||||||
|
"package",
|
||||||
|
"private",
|
||||||
|
"protected",
|
||||||
|
"public",
|
||||||
|
"static",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/** A JS reference for a prop/state name (reserved words get a `__p_` prefix). */
|
/** A JS reference for a prop/state name (reserved words get a `__p_` prefix). */
|
||||||
|
|||||||
@@ -1387,3 +1387,14 @@ test("style blocks compile with stable page/component/layout metadata", () => {
|
|||||||
expect(layout).toContain("export const __wrnexusStyles");
|
expect(layout).toContain("export const __wrnexusStyles");
|
||||||
expect(page).toMatch(/data-wrnexus-style-id="wrn-page-[a-z0-9]+"/);
|
expect(page).toMatch(/data-wrnexus-style-id="wrn-page-[a-z0-9]+"/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("strict-mode reserved prop names compile through safe local references", () => {
|
||||||
|
const output = compileWireFile(`component Visibility {
|
||||||
|
props { private: boolean = false }
|
||||||
|
view { {#if private}<span>Private</span>{/if} }
|
||||||
|
}`);
|
||||||
|
|
||||||
|
expect(output).toContain("const __p_private: boolean");
|
||||||
|
expect(output).toContain("(__p_private) ?");
|
||||||
|
expect(output).not.toContain("const private:");
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user