Skip to content

fix(cli): preserve inline script diagnostic positions - #1454

Merged
Lorenzobattistela merged 3 commits into
bendlang:mainfrom
Osraka:fix/inline-bundle-source-location
Oct 11, 2026
Merged

Lorenzobattistela merged 3 commits into
bendlang:mainfrom
Osraka:fix/inline-bundle-source-location

Conversation

@Osraka

@Osraka Osraka commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The inline-module bundler introduced in #1412 uses src.indexOf(m.text, end) to pad virtual module sources for diagnostics. If an earlier HTML comment contains the same JavaScript text, a syntax error points into that comment rather than the actual <script type=module> body.

Change

Use a non-mutating HTMLRewriter pass to mark each inline module script body and derive its position from the parser-selected script, not from a text search for the body. The existing HTML rewrite and emitted module contents are unchanged. The regression fixture covers a commented-out script with identical source, multiple modules, and marker-like text already present in the page.

Validation

  • The new fixture fails on main and passes with this change; it checks the actual script line and column.
  • bend2/main.ts tests/io/bundle_inline.bend: 0.
  • Emitted JavaScript version of the same fixture: 0.
  • Repository shape/token gate: PASS: 54 / 54.
  • Bun build of bend2/main.ts passed.

The full mini-cluster test gate was not available locally.

@Lorenzobattistela Lorenzobattistela left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Osraka, the marker approach looks right: it fixes the repeated-text case (and a copy inside a <textarea>), and bundles for normal pages come out byte-identical to main.

One regression: a page with an empty self-closing script in SVG, e.g.

<svg><script type="module"/></svg>
<script type="module">
console.log(1);
</script>

now fails to build with String.prototype.repeat argument must be greater than or equal to 0, even with no error in the page (main builds it). prepend does nothing on an element that can't have content, so that script's mark never shows up in marked. Could you handle it and add the case to the multi.html fixture?

Two small style points: the module-script check is now duplicated in both passes (one shared helper keeps marks and mods aligned), and the while needs braces like the rest of main.ts.

@Osraka

Osraka commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the concrete SVG repro. I updated the branch so both HTMLRewriter passes use the same inline-module check, which skips elements that cannot have content. That keeps the marker and module indexes aligned for a self-closing SVG <script/>. The fixture now covers this case in both a successful page and multi.html; the latter failed before the fix and passes afterward with the expected diagnostic position. I also added braces to the while loop.

Locally, bun bend2/main.ts tests/io/bundle_inline.bend returns 0, the Bun build passes, and the PR check is green.

@Lorenzobattistela
Lorenzobattistela merged commit 4ba5c3a into bendlang:main Oct 11, 2026
1 check passed
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.

2 participants