Skip to content

fix(@angular/build): prevent stripping nested sourceMappingURL comments#33545

Open
clydin wants to merge 1 commit into
angular:mainfrom
clydin:fix-sourcemap-stripping
Open

fix(@angular/build): prevent stripping nested sourceMappingURL comments#33545
clydin wants to merge 1 commit into
angular:mainfrom
clydin:fix-sourcemap-stripping

Conversation

@clydin

@clydin clydin commented Jul 10, 2026

Copy link
Copy Markdown
Member

When compiling files, the dev server and transformers strip original //# sourceMappingURL= comments. However, using a naive RegExp like /^\/\/# sourceMappingURL=[^\r\n]*/gm matches the comment even when it is embedded inside multiline template literals or string literals (such as inline web worker code), which causes template literals to become unterminated and fail compilation.

This introduces a robust, lexer-style utility removeSourceMappingURL that ignores occurrences of the comment when they appear inside single/double quotes, template literals, or block comments, preventing syntax errors in compiled chunks.

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

Copy link
Copy Markdown

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 introduces a new utility function, removeSourceMappingURL, to safely strip top-level //# sourceMappingURL= comments from JavaScript code without affecting occurrences inside string literals, template literals, or block comments. This utility replaces several inline regex replacements across the codebase. The review feedback highlights a critical edge case where the proposed regular expression fails to handle nested template literals when a sourcemap comment is placed directly inside them without inner quotes. To address this, the reviewer suggests implementing a lightweight state-machine parser instead of a regular expression and provides corresponding unit tests to verify this behavior.

Comment thread packages/angular/build/src/utils/source-map.ts Outdated
Comment thread packages/angular/build/src/utils/source-map_spec.ts
When compiling files, the dev server and transformers strip original `//# sourceMappingURL=` comments. However, using a naive RegExp like `/^\/\/# sourceMappingURL=[^\r\n]*/gm` matches the comment even when it is embedded inside multiline template literals or string literals (such as inline web worker code), which causes template literals to become unterminated and fail compilation.

This introduces a robust, lexer-style utility `removeSourceMappingURL` that ignores occurrences of the comment when they appear inside single/double quotes, template literals, or block comments, preventing syntax errors in compiled chunks.
@clydin clydin force-pushed the fix-sourcemap-stripping branch from 5194b41 to a6c7b73 Compare July 10, 2026 14:49
@clydin clydin added target: patch This PR is targeted for the next patch release action: review The PR is still awaiting reviews from at least one requested reviewer labels Jul 10, 2026
@clydin clydin added target: minor This PR is targeted for the next minor release and removed target: patch This PR is targeted for the next patch release labels Jul 10, 2026
@clydin clydin requested a review from alan-agius4 July 10, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer area: @angular/build target: minor This PR is targeted for the next minor release

Projects

None yet

1 participant