Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Properly generate source maps for manually added multi-line content #15365

Merged
merged 2 commits into from
Jan 25, 2023

Conversation

liuxingbaoyu
Copy link
Member

@liuxingbaoyu liuxingbaoyu commented Jan 25, 2023

Q                       A
Fixed Issues? Fixes #15363
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass?
Documentation PR Link
Any Dependency Changes?
License MIT

This was technically a regression, about a year ago (7.17.0~7.18.0).
A lot of snapshot changes have nothing to do with this fix, it seems like I accidentally broke some tests in a past PR and now they are fixed.

@liuxingbaoyu liuxingbaoyu added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: generator area: sourcemaps i: regression labels Jan 25, 2023
@babel-bot
Copy link
Collaborator

babel-bot commented Jan 25, 2023

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/53787/

@@ -371,7 +371,7 @@ async function run(task: Test) {
}
}

if (opts.sourceMaps === true) {
if (opts.sourceMaps === true || opts.sourceMap === true) {
Copy link
Contributor

Choose a reason for hiding this comment

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

sourceMaps vs sourceMap is confusing. I would prefer we stick to one of them in the test runner.

Comment on lines 264 to 271
if (last < len) {
this._mark(++line, 0, identifierName, filename);
this._mark(
// When manually adding multi-line content (such as a comment), `line` will be `undefined`.
line != undefined ? ++line : line,
0,
identifierName,
filename,
);
Copy link
Member

Choose a reason for hiding this comment

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

If this is a source-less segment (it doesn't have an original line/column), then we only need to call mark 0/1 times (which is done above the loop). That's because any additional lines generated by the comment will also be source-less, and source-less segments at the beginning of a line are discarded by gen-mapping.

Suggested change
if (last < len) {
this._mark(++line, 0, identifierName, filename);
this._mark(
// When manually adding multi-line content (such as a comment), `line` will be `undefined`.
line != undefined ? ++line : line,
0,
identifierName,
filename,
);
if (last < len && line !== undefined) {
this._mark(++line, 0, identifierName, filename);

@nicolo-ribaudo nicolo-ribaudo merged commit 6de6d58 into babel:main Jan 25, 2023
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Apr 27, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: sourcemaps i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: generator PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
5 participants