Repository navigation
fix(cli): preserve inline script diagnostic positions - #1454
Conversation
Lorenzobattistela
left a comment
There was a problem hiding this comment.
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.
|
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 Locally, |
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
mainand passes with this change; it checks the actual script line and column.bend2/main.ts tests/io/bundle_inline.bend:0.0.PASS: 54 / 54.bend2/main.tspassed.The full mini-cluster test gate was not available locally.