GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(@angular/build): use oxc-parser fallback when stripping source-map comments by clydin · Pull Request #34632 · angular/angular-cli

Conversation

@clydin

@clydin clydin commented Nov 2, 2026

Copy link
Copy Markdown
Member

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gemini-code-assist[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction
@angular-robot angular-robot Bot added the area: @angular/build label Nov 2, 2026
gemini-code-assist[bot]
gemini-code-assist Bot reviewed Nov 2, 2026
View reviewed changes

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/angular/build/src/utils/source-map.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

alan-agius4
alan-agius4 reviewed Nov 2, 2026
View reviewed changes
Comment thread packages/angular/build/src/utils/source-map.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@alan-agius4 alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Nov 2, 2026
alan-agius4
alan-agius4 approved these changes Nov 2, 2026
View reviewed changes
clydin added 2 commits November 2, 2026 17:27
@clydin
fix(@angular/build): use oxc-parser fallback when stripping source-ma…
575c988
…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
@clydin
fixup! fix(@angular/build): use oxc-parser fallback when stripping so…
ce1b638
…urce-map comments
@alan-agius4 alan-agius4 removed the action: review The PR is still awaiting reviews from at least one requested reviewer label Nov 3, 2026
@clydin
refactor(@angular/build): centralize oxc-parser loading with scoped W…
69e3051
…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
clydin force-pushed the fix/source-map-oxc-comment-stripping branch from a2e3e69 to 69e3051 Compare November 3, 2026 13:33
@clydin clydin added the action: merge The PR is ready for merge by the caretaker label Nov 3, 2026
@alan-agius4

alan-agius4 commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

This PR was merged into the repository. The changes were merged into the following branches:

  • main: 12578ec
  • 22.2.x: ca32365
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

alan-agius4 pushed a commit that referenced this pull request Nov 3, 2026
@clydin @alan-agius4
fix(@angular/build): use oxc-parser fallback when stripping source-ma…
631ac8a
…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
@clydin @alan-agius4
refactor(@angular/build): centralize oxc-parser loading with scoped W…
ca32365
…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 alan-agius4 closed this in 8984b4a Nov 3, 2026
alan-agius4 pushed a commit to alan-agius4/angular-cli that referenced this pull request Nov 3, 2026
@clydin @alan-agius4
refactor(@angular/build): centralize oxc-parser loading with scoped W…
12578ec
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@alan-agius4 alan-agius4 alan-agius4 approved these changes
+1 more reviewer
@gemini-code-assist gemini-code-assist[bot] gemini-code-assist[bot] left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build target: patch This PR is targeted for the next patch release

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

@angular/build: source-map comment scanner corrupts valid JS containing a regex literal

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@clydin @alan-agius4
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.