Skip to content

fix(sourcemap): accept a sourceMappingURL that ends with a newline#45983

Merged
weswigham merged 2 commits into
microsoft:mainfrom
JoelEinbinder:sourcemap_newline
Oct 1, 2021
Merged

fix(sourcemap): accept a sourceMappingURL that ends with a newline#45983
weswigham merged 2 commits into
microsoft:mainfrom
JoelEinbinder:sourcemap_newline

Conversation

@JoelEinbinder

Copy link
Copy Markdown
Contributor

Fixes #45982

After I upgraded my TypeScript I noticed my sourcemaps broke. I bisected down to #44197, which
seem to subtly change the regex matching the sourceMappingURL so that it will not match
if the line ends with '\n'.

The old regex ended with \s* to match and trim all whitespace.
The new regex doesn't have that I guess for performance? But because . does not match \n, and
getLineText preserves the ending \n, this does not match any line that isn't the last one in the
file.

I am happy to add a test if someone points me to the correct place for it. I tried to add
a fourslash test but I couldn't seem to create a file where the last line was a newline.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Sep 21, 2021
Comment thread src/compiler/sourcemap.ts Outdated

// Sometimes tools can see the following line as a source mapping url comment, so we mangle it a bit (the [M])
const sourceMapCommentRegExp = /^\/\/[@#] source[M]appingURL=(.+)$/;
const sourceMapCommentRegExp = /^\/\/[@#] source[M]appingURL=(.+)\n?$/;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also include \r?, just in case~

Comment thread src/compiler/sourcemap.ts Outdated
@typescript-bot typescript-bot added For Milestone Bug PRs that fix a bug with a specific milestone and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Oct 1, 2021
@weswigham weswigham merged commit 46a12fd into microsoft:main Oct 1, 2021
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Milestone Bug PRs that fix a bug with a specific milestone

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Cannot detect sourceMappingURL if there is a trailing newline

4 participants