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: Avoid internally generating negative source maps columns #15719

Merged
merged 3 commits into from Jul 5, 2023

Conversation

liuxingbaoyu
Copy link
Member

@liuxingbaoyu liuxingbaoyu commented Jun 23, 2023

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

@liuxingbaoyu liuxingbaoyu added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Jun 23, 2023
it("should not throw when loc.column === 0 with inputSourceMap", () => {
const ast = parseExpression("a(\n)");

ast.loc.end.column = 0;
Copy link
Contributor

@JLHwung JLHwung Jun 23, 2023

Choose a reason for hiding this comment

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

Can we construct a test without AST location mutations? If not it may point to a downstream issue and we can provide a better error message.

The current _normalizePosition implementation will also throw if any external tool sets ast.loc.end.line to -1. If we decide to mute such errors, we should also handle the .line info.

Copy link
Member Author

Choose a reason for hiding this comment

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

This happened in a complex Angular project, and I thought it was a downstream bug, but since it's a regression, I took this approach.

The current _normalizePosition implementation will also throw if any external tool sets ast.loc.end.line to -1. If we decide to mute such errors, we should also handle the .line info.

You are right, but the reason for this regression is that we internally added columnOffset resulting in a possible -1, and lineOffset is not currently actually used, I'm not sure about doing the same.
Maybe we can remove lineOffset?

Choose a reason for hiding this comment

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

Anything new here ? It would be awesome to have this fix :)

target.line = pos.line + lineOffset;
target.column = pos.column + columnOffset;
target.line = pos.line;
target.column = Math.max(pos.column + columnOffset, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a note here to #15712? So that we can investigate this issue in the future.

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

The changes look good, but I would like to learn more about the underlying cause of this problem (not a blocker for this PR)

@nicolo-ribaudo nicolo-ribaudo changed the title fix: Crashes in some special source map cases fix: Avoid internally generating negative source maps columns Jul 5, 2023
@nicolo-ribaudo nicolo-ribaudo merged commit 4986833 into babel:main Jul 5, 2023
52 of 54 checks passed
@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 Oct 5, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 5, 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
Development

Successfully merging this pull request may close these issues.

[Bug]: not working after upgrade to 7.22.5
4 participants