diff --git a/src/domain/javascript/javascriptAstValues.ts b/src/domain/javascript/javascriptAstValues.ts index fe7ba5b8a7..b9a1830476 100644 --- a/src/domain/javascript/javascriptAstValues.ts +++ b/src/domain/javascript/javascriptAstValues.ts @@ -629,7 +629,11 @@ export const semanticFinalObjectStringProperty = ( key: string, ): string | undefined => { const value = semanticFinalObjectProperty(node, key); - return t.isStringLiteral(value) ? value.value : undefined; + if (value === undefined) return undefined; + const literal = readExactJavaScriptLiteral(value); + return literal.found && typeof literal.value === "string" + ? literal.value + : undefined; }; /** Read exact consumed object-pattern keys, leaving dynamic keys unknown. */ diff --git a/src/domain/javascript/javascriptRpcEndpoints.test.ts b/src/domain/javascript/javascriptRpcEndpoints.test.ts index 69fe580d50..61573f84f4 100644 --- a/src/domain/javascript/javascriptRpcEndpoints.test.ts +++ b/src/domain/javascript/javascriptRpcEndpoints.test.ts @@ -35,6 +35,9 @@ describe("RPC object property ownership", () => { ['url: "/trpc/live", [0x1n]: {}', "/trpc/live"], ['url: "/trpc/live", [0b1n]: {}', "/trpc/live"], ['url: "/trpc/live", [-1n]: {}', "/trpc/live"], + ["url: `/trpc/\\u006cive`", "/trpc/live"], + ['url: "/trpc/old", url: `/trpc/live`', "/trpc/live"], + ['url: "/trpc/old", url: `/trpc/${runtimeUrl}`', null], ] as const)( "reads only the final known link URL from {%s}", (options, value) => { @@ -48,6 +51,11 @@ describe("RPC object property ownership", () => { it.each([ ['operation: "mutation"', "Old", "graphql:mutation"], + [ + "kind: `OperationDefinition`, operation: `mutation`, name: { kind: `Name`, value: `Current` }", + "Current", + "graphql:mutation", + ], ['name: { kind: "Name", value: "Current" }', "Current", "graphql:query"], ['kind: "FragmentDefinition"', null, null], ["name: runtimeName", null, null], @@ -317,7 +325,7 @@ describe("tRPC binding identity and bundled syntax", () => { c.users.query(); const p = (t.createTRPCProxyClient as any)({}); p.posts.query(); - (0, t.httpLink)({ url: "/api/other" }); + (0, t.httpLink)({ url: \`/api/other\` }); `), ).toEqual([ { diff --git a/tests/acceptance/applications/javascriptRpcPropertyOwnershipCli.test.ts b/tests/acceptance/applications/javascriptRpcPropertyOwnershipCli.test.ts index 205a05a28c..ebc4d6e9f6 100644 --- a/tests/acceptance/applications/javascriptRpcPropertyOwnershipCli.test.ts +++ b/tests/acceptance/applications/javascriptRpcPropertyOwnershipCli.test.ts @@ -120,6 +120,7 @@ cliTest.for(["CLI", "stdio MCP"] as const)( httpBatchLink({ url: "/trpc/spread-old", ...options }), httpBatchLink({ url: "/trpc/computed-old", [key]: options.url }), httpBatchLink({ ...options, url: "/trpc/final", headers: {} }), + httpBatchLink({ url: \`/trpc/template\` }), ]; const doc = { kind: "OperationDefinition", operation: "query", operation: "mutation", @@ -131,7 +132,13 @@ cliTest.for(["CLI", "stdio MCP"] as const)( }); // This control checks JavaScript object semantics, not a live tRPC client. expect(await runNodeJsonControl(root, "entry.mjs")).toEqual([ - ["/trpc/live", "/trpc/runtime", "/trpc/runtime", "/trpc/final"], + [ + "/trpc/live", + "/trpc/runtime", + "/trpc/runtime", + "/trpc/final", + "/trpc/template", + ], "mutation", "Current", ]); @@ -147,9 +154,10 @@ cliTest.for(["CLI", "stdio MCP"] as const)( expect.arrayContaining([ ["/trpc/live", "trpc:link:httpBatchLink"], ["/trpc/final", "trpc:link:httpBatchLink"], + ["/trpc/template", "trpc:link:httpBatchLink"], ["Current", "graphql:mutation"], ]), ); - expect(endpoints).toHaveLength(3); + expect(endpoints).toHaveLength(4); }, );