Skip to content

fix(scanners): measure template text ranges on the source text - #166

Open
0froq wants to merge 1 commit into
mainfrom
fix/vue-template-text-range
Open

0froq wants to merge 1 commit into
mainfrom
fix/vue-template-text-range

Conversation

@0froq

@0froq 0froq commented Nov 17, 2026

Copy link
Copy Markdown
Member

Fixes #165

Description

The range for Vue template text came from node.content, which condenses whitespace and decodes entities, so it no longer lines up with the source. The range is now measured on node.loc.source, and the message stays the decoded text.

Svelte had the same bug for entities: it measured on the decoded data instead of the Text node's raw. Same fix there.

Test

packages/builtins/test/extract.test.ts has two new cases. One extracts indented, multi-line and entity text from a .vue file, and one extracts an entity from a .svelte file. Both fail on main, where the call replaces a short range and leaves a tail of the original text, and pass on this branch.

Vue condenses whitespace and decodes entities in node.content, and Svelte
does the same in a Text node's data, so offsets taken from them miss the
source. Measure the range on the raw source text and keep the decoded text
as the message.
@vercel

vercel Bot commented Nov 17, 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 17, 2026 3:38am UTC

@0froq

0froq commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

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

raw result

💭 analyzed by openai-compatible/opencode-go/deepseek-v4.1-flash
🕰️ 2026-11-17 04:26 UTC
🔗 head ad23c50
🤖 automated by pulls.review

{
  "headSha": "ad23c500715a9e9e03b38e2893fe19b0cf1de15c",
  "result": {
    "overallSummary": "The Vue and Svelte text scanners produced ranges from decoded/condensed text (`node.content`, `data`) instead of the raw source, so extraction replaced the wrong span and left a tail of original text behind. This PR measures the ranges on `node.loc.source` / `node.raw` while keeping the decoded text as the extracted message, and adds regression tests for indented, multi-line and entity text.",
    "groups": [
      {
        "key": "scanner-source-ranges",
        "label": "Source-based text ranges",
        "summary": "Fix the range computation in both template scanners so offsets are taken from the untouched source text. The extracted message still uses the decoded text, so `text` and `range` intentionally no longer have the same length; the end offset is derived from the source's trimmed tail rather than from `text.length`.",
        "category": "core",
        "filePaths": [
          "packages/builtins/src/scanners/vue/index.ts",
          "packages/builtins/src/scanners/svelte/index.ts"
        ],
        "critical": true,
        "lineNotes": [
          {
            "path": "packages/builtins/src/scanners/vue/index.ts",
            "side": "additions",
            "line": 143,
            "text": "`end` is now computed independently of `text`, so the range may be longer than the decoded `text` (entities like `&` expand). That is the point of the fix: the replacement span must cover the whole source token."
          },
          {
            "path": "packages/builtins/src/scanners/svelte/index.ts",
            "side": "additions",
            "line": 45,
            "text": "Leading whitespace offset comes from `raw`, while `text` is the decoded `data`; the two are deliberately mixed here. Inside the text, condensed whitespace is fine because only the outer trim offsets are used."
          },
          {
            "path": "packages/builtins/src/scanners/svelte/index.ts",
            "side": "additions",
            "line": 105,
            "text": "New `'raw' in node` guard: a Text node without a string `raw` is now skipped entirely instead of falling back to `data`-based offsets. Intended, but worth confirming no supported Svelte AST version omits `raw`."
          }
        ]
      },
      {
        "key": "tests",
        "label": "Extraction regression tests",
        "summary": "Two cases reproducing the bug: indented multi-line plus entity text in a `.vue` file, and an entity in a `.svelte` file. Both assert the rewritten source and the decoded message, so a range regression shows up as a leftover text tail.",
        "category": "tests",
        "filePaths": [
          "packages/builtins/test/extract.test.ts"
        ]
      }
    ],
    "schemaVersion": 1,
    "source": "llm",
    "generatedAt": "2026-11-17T04:26:49.647Z",
    "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.

Vue: extracting indented or multi-line template text replaces the wrong range

1 participant