Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the sourcemap comment removal logic by replacing a custom state-machine parser with oxc-parser for non-trailing or multiple sourcemap comments, while maintaining a fast path for single trailing comments. It also introduces a decodeUtf8 helper in the Vite memory plugin to avoid copying memory during UTF-8 decoding, and adds extensive unit tests to cover various edge cases. A review comment identifies a high-severity issue where using __filename with createRequire will throw a ReferenceError in ESM environments, suggesting the use of import.meta.url instead.
alan-agius4
reviewed
Nov 2, 2026
alan-agius4
approved these changes
Nov 2, 2026
…p comments Previously, `removeSourceMappingURL` relied on a custom character-by-character state machine to strip top-level `//# sourceMappingURL=` comments from JavaScript strings. Because that scanner did not track regular expression literals, quote characters or backticks inside a regex literal (such as `/"/`) inverted string boundaries for the remainder of the file. When a subsequent string literal contained `//# sourceMappingURL=`, the scanner misidentified it as a top-level comment and truncated valid JavaScript, or failed to strip the actual trailing comment at the end of the chunk. Extend the single-trailing-comment fast path to string inputs and pass raw byte buffers directly from the Vite memory plugin so standard chunks slice trailing source-map comments without invoking a parser. When a file contains multiple or non-trailing `//# sourceMappingURL=` occurrences, lazily load `oxc-parser` and read only the `comments` of the parse result, avoiding JS-side AST deserialization while delegating full ECMAScript lexical handling (including regex literals, templates, and escapes) to Oxc. This keeps main-thread startup free of eager native or WASM parser loading. The fallback removes whitespace consistently with the fast path, removing comment-only lines entirely while preserving line terminators for comments that follow code. Also harden trailing URL and base64 validation so block comments or template literals closing on the same line are never misclassified by the fast path. Closes angular#34590
…urce-map comments
…ASI shim
Replace side-effect imports of `oxc-wasi-shim` with a centralized
`loadOxcParser()` helper across `@angular/build` consumers.
Because `oxc-parser` evaluates its WASI bindings synchronously during
`require('oxc-parser')`, `loadOxcParser()` restores `Module._resolveFilename`
in a `finally` block immediately after loading. This avoids leaving
`@emnapi/core` and `@emnapi/runtime` resolution permanently overridden on the
main thread where `rolldown` and `vite` resolve their own `@emnapi/*` versions.
clydin
force-pushed
the
fix/source-map-oxc-comment-stripping
branch
from
November 3, 2026 13:33
a2e3e69 to
69e3051
Compare
Collaborator
alan-agius4
pushed a commit
that referenced
this pull request
Nov 3, 2026
…p comments (#34632) Previously, `removeSourceMappingURL` relied on a custom character-by-character state machine to strip top-level `//# sourceMappingURL=` comments from JavaScript strings. Because that scanner did not track regular expression literals, quote characters or backticks inside a regex literal (such as `/"/`) inverted string boundaries for the remainder of the file. When a subsequent string literal contained `//# sourceMappingURL=`, the scanner misidentified it as a top-level comment and truncated valid JavaScript, or failed to strip the actual trailing comment at the end of the chunk. Extend the single-trailing-comment fast path to string inputs and pass raw byte buffers directly from the Vite memory plugin so standard chunks slice trailing source-map comments without invoking a parser. When a file contains multiple or non-trailing `//# sourceMappingURL=` occurrences, lazily load `oxc-parser` and read only the `comments` of the parse result, avoiding JS-side AST deserialization while delegating full ECMAScript lexical handling (including regex literals, templates, and escapes) to Oxc. This keeps main-thread startup free of eager native or WASM parser loading. The fallback removes whitespace consistently with the fast path, removing comment-only lines entirely while preserving line terminators for comments that follow code. Also harden trailing URL and base64 validation so block comments or template literals closing on the same line are never misclassified by the fast path. Closes #34590 PR Close #34632
alan-agius4
pushed a commit
that referenced
this pull request
Nov 3, 2026
…ASI shim (#34632) Replace side-effect imports of `oxc-wasi-shim` with a centralized `loadOxcParser()` helper across `@angular/build` consumers. Because `oxc-parser` evaluates its WASI bindings synchronously during `require('oxc-parser')`, `loadOxcParser()` restores `Module._resolveFilename` in a `finally` block immediately after loading. This avoids leaving `@emnapi/core` and `@emnapi/runtime` resolution permanently overridden on the main thread where `rolldown` and `vite` resolve their own `@emnapi/*` versions. PR Close #34632
alan-agius4
pushed a commit
to alan-agius4/angular-cli
that referenced
this pull request
Nov 3, 2026
…ASI shim (angular#34632) Replace side-effect imports of `oxc-wasi-shim` with a centralized `loadOxcParser()` helper across `@angular/build` consumers. Because `oxc-parser` evaluates its WASI bindings synchronously during `require('oxc-parser')`, `loadOxcParser()` restores `Module._resolveFilename` in a `finally` block immediately after loading. This avoids leaving `@emnapi/core` and `@emnapi/runtime` resolution permanently overridden on the main thread where `rolldown` and `vite` resolve their own `@emnapi/*` versions. PR Close angular#34632
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously,
removeSourceMappingURLrelied on a custom character-by-character state machine to strip top-level//# sourceMappingURL=comments from JavaScript strings. Because that scanner did not track regular expression literals, quote characters or backticks inside a regex literal (such as/"/) inverted string boundaries for the remainder of the file. When a subsequent string literal contained//# sourceMappingURL=, the scanner misidentified it as a top-level comment and truncated valid JavaScript, or failed to strip the actual trailing comment at the end of the chunk.Extend the single-trailing-comment fast path to string inputs and pass raw byte buffers directly from the Vite memory plugin so standard chunks slice trailing source-map comments without invoking a parser. When a file contains multiple or non-trailing
//# sourceMappingURL=occurrences, lazily loadoxc-parserand read only thecommentsof the parse result, avoiding JS-side AST deserialization while delegating full ECMAScript lexical handling (including regex literals, templates, and escapes) to Oxc. This keeps main-thread startup free of eager native or WASM parser loading. The fallback removes whitespace consistently with the fast path, removing comment-only lines entirely while preserving line terminators for comments that follow code. Also harden trailing URL and base64 validation so block comments or template literals closing on the same line are never misclassified by the fast path.Closes #34590