Skip to content

fix: Avoid internally generating negative source maps columns - #15719

Merged
nicolo-ribaudo merged 3 commits into
babel:mainfrom
liuxingbaoyu:fix-column
Jul 5, 2023
Merged

nicolo-ribaudo merged 3 commits into
babel:mainfrom
liuxingbaoyu:fix-column

Conversation

@liuxingbaoyu

@liuxingbaoyu liuxingbaoyu commented Jun 23, 2023 •

Copy link
Copy Markdown
Member
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;

@JLHwung JLHwung Jun 23, 2023 •

Copy link
Copy Markdown
Contributor

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.

@liuxingbaoyu liuxingbaoyu Jun 23, 2023 •

Copy link
Copy Markdown
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?

Copy link
Copy Markdown

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
Copy Markdown
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.

@nicolo-ribaudo nicolo-ribaudo left a comment

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.

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
@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