Skip to content

Plain say templates need placeholder naming, and an argument named id breaks the descriptor #67

Description

@k0d13

Two related gaps in @saykit/transform-js, both about the flat descriptor say.call receives.

An argument named id clobbers the message id

generateSayCallExpression (packages/transform-js/src/generator.ts:14-17) builds { id, ...values } as one object literal, so an argument that happens to be called id emits a duplicate key and wins:

say`Hi ${id} and ${name}`       // → say.call({ id: "sF5gu7", id: id, name: name })
say({ id: "greet" })`Hi ${id}`  // → say.call({ id: "greet", id: id })

descriptor.id is then the runtime value of the variable, so the lookup in Say#call (packages/integration/src/runtime.ts:243) misses and throws Message for <value> is not a string. It fails at runtime, in whatever locale happens to be active, with no build-time signal.

@saykit/transform-jsx no longer has this: as of #66 it compiles every value behind an underscore (_id={id}, _0={<u/>}) and the runtime strips one underscore back off, so Say's own props and the message's values live in separate namespaces and no name is reserved. say.call has no equivalent separation — the fix is a decision about its contract, either the same underscore convention with the runtime unprefixing, or splitting the id out of the values object (call(id, values)).

No way to name a placeholder in a plain say template

#66 added say-tag for JSX:

<Say>Signed in as <strong say-tag="bold">{user}</strong></Say>
// → Signed in as <bold>{user}</bold>

Plain templates have no equivalent, so their placeholders stay numbered and a translator gets <0> with nothing to go on. A placeholderLabel()-style macro was discussed in #61 and deliberately left out of #66's scope.

Worth doing together: whatever names a placeholder in a template has to agree with whatever fixes the descriptor namespace above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions