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.
…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.
a2e3e69 to
69e3051
Compare
…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
…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
…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 pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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