Skip to content

fix(builtins): read svelte-i18n params from options.values - #161

Open
0froq wants to merge 1 commit into
mainfrom
fix/svelte-i18n-params-values
Open

0froq wants to merge 1 commit into
mainfrom
fix/svelte-i18n-params-values

Conversation

@0froq

@0froq 0froq commented Nov 13, 2026

Copy link
Copy Markdown
Member

Fixes #156

Description

$_('welcome', { values: { name } }) keeps its message params inside values, and the call spec had no way to name that. The preset recorded no params, so param-mismatch said nothing about the call.

ParamsSource gained property, the dot-separated path to the object that holds the params, and the svelte-i18n preset points it at options.values. The preset's callee list split in two, because only the translators read message params: $_, $t, _ and t point at options.values, while $format, $json, format and json keep their second argument as Intl options.

A call that passes options without values, or no options at all, records an empty params list instead of an unreadable object, so a missing placeholder still gets reported. When values itself cannot be read, as in { values }, { values: opts } or { values: { ...opts } }, the params stay unknown and the check skips the call.

Test

The component from the issue, with $_('greeting') and $_('welcome', { values: { who: 'Alice', unused: 'Bob' } }), checked through the CLI built from the repo on main and then on this branch.

On main:

$ x18n check --only param-mismatch --no-cache
Found no errors.

On this branch:

$ x18n check --only param-mismatch --no-cache
src/App.svelte:6:9
 WARNING  The params of "welcome" differ from its placeholders in en: missing name; unused who, unused.  param-mismatch
6 │ <p>{$_('welcome', { values: { who: 'Alice', unused: 'Bob' } })}</p>
  │         ~~~~~~~

$_('greeting') stays quiet in both runs, since a call without options has no params to compare.

A call such as `$_('welcome', { values: { name } })` kept its params inside
`values`, which `ParamsSource` had no way to name, so `param-mismatch` saw no
params at all and reported neither the missing nor the unused ones.

`ParamsSource` gains `property`, the property of the argument that holds the
params object, and the svelte-i18n preset points it at `options.values`.
A call that passes options without `values`, or none, now records `[]` rather
than an unreadable params object, so the missing placeholders still show up.
@vercel

vercel Bot commented Nov 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
x18n Ready Ready Preview Nov 13, 2026 9:57pm UTC

@0froq
0froq marked this pull request as ready for review November 13, 2026 21:57
@0froq

0froq commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

👁️‍🗨️ Review this pull request with grouped, summarized diffs at:
👉 https://pulls.review/gh/x18n-dev/x18n/161?from=0froq

raw result

💭 analyzed by openai-compatible/opencode-go/deepseek-v4.1-flash
🕰️ 2026-11-13 21:58 UTC
🔗 head 9a03455
🤖 automated by pulls.review

{
  "headSha": "9a034557d4771a63c3f54f123c61bd858188cbd3",
  "result": {
    "overallSummary": "Fixes #156: svelte-i18n puts a message's params inside `options.values`, which `ParamsSource` could not express, so `param-mismatch` never saw those params. The PR adds an optional `property` path to `ParamsSource` and teaches the JS scanner to read the params object from it, then points the svelte-i18n preset's translators at `options.values` (and stops treating formatter calls' Intl options as params).",
    "groups": [
      {
        "key": "params-property",
        "label": "Params source property",
        "summary": "Adds the generic capability: `ParamsSource.property`, a dot-separated path to the object holding the params, exposed in the public type and the config schema, and consumed by the scanner. The scanner now resolves the params object through that property and distinguishes \"call passes no options\" (`[]`, still comparable) from \"params cannot be read\" (`undefined`, check skipped).",
        "category": "core",
        "filePaths": [
          "packages/core/src/types/config.ts",
          "packages/core/src/schema.ts",
          "packages/builtins/src/scanners/shared/js.ts"
        ],
        "critical": true,
        "fileNotes": [
          {
            "path": "packages/builtins/src/scanners/shared/js.ts",
            "text": "The shared `paramObject` helper is the crux: `null` means the call has no params (so a missing placeholder is still reported) while `undefined` means unreadable (`opts`, `{ ...opts }`), which skips the check. Keep that distinction intact when refactoring — `paramNames` and `paramValues` both depend on it."
          },
          {
            "path": "packages/core/src/types/config.ts",
            "text": "`property` is optional, so existing presets keep their second-argument behaviour unchanged."
          }
        ]
      },
      {
        "key": "svelte-i18n-preset",
        "label": "svelte-i18n preset",
        "summary": "Splits the preset's callee list so only the translators (`$_`, `$t`, `_`, `t`) read message params, now from `arg: 1` + `property: 'values'`. The formatters (`$format`, `$json`, `format`, `json`) no longer pretend their second argument holds params, which also stops false `param-mismatch` reports on Intl options objects.",
        "category": "api",
        "filePaths": [
          "packages/builtins/src/presets/svelte-i18n/index.ts"
        ],
        "fileNotes": [
          {
            "path": "packages/builtins/src/presets/svelte-i18n/index.ts",
            "text": "Behaviour change beyond the issue: formatter calls previously inherited the params spec, so an Intl options object like `{ number: { style: 'currency' } }` was compared against placeholders. Worth confirming no user relied on that."
          }
        ]
      },
      {
        "key": "tests",
        "label": "Tests",
        "summary": "Covers the new behaviour from both sides: a scanner-level test for the `property` lookup across all arg positions and unreadable forms, and an end-to-end svelte-i18n test reproducing the issue's component so the resulting `param-mismatch` message is pinned.",
        "category": "tests",
        "filePaths": [
          "packages/builtins/test/presets.test.ts",
          "packages/builtins/test/scanners.test.ts"
        ]
      },
      {
        "key": "docs",
        "label": "Config reference",
        "summary": "Documents `ParamsSource.property` in the config reference next to `arg` and `options`, with the `t(key, { values: { n } })` example.",
        "category": "docs",
        "filePaths": [
          "docs/content/6.references/1.config.md"
        ]
      },
      {
        "key": "snapshots",
        "label": "Schema/type snapshots",
        "summary": "Generated snapshots updated mechanically for the new optional `property` field in both the published schema and the `.d.ts` API surface.",
        "category": "other",
        "filePaths": [
          "packages/core/test/__snapshots__/config.test.ts.snap",
          "test/__snapshots__/tsnapi/@x18n/core/index.snapshot.d.ts"
        ]
      }
    ],
    "schemaVersion": 1,
    "source": "llm",
    "generatedAt": "2026-11-13T21:58:11.303Z",
    "model": "openai-compatible/opencode-go/deepseek-v4.1-flash",
    "locale": "en"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[svelte-i18n] Interpolation parameters aren't checked inside values

1 participant