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: Account for offsets when creating new Position instances #16937

Merged
merged 3 commits into from
Oct 30, 2024

Conversation

DylanPiercey
Copy link
Contributor

@DylanPiercey DylanPiercey commented Oct 26, 2024

Another followup to #16936 and #16849...

  • The column passed for new Position in the curPosition api is incorrectly subtracting a "source position" (index) from an "offset position" (this.lineStart). This causes the column to be incorrect. Since lineStart is a "source position" we can subtract it directly from the pos.
  • I searched through the codebase for all new Position calls to ensure that correctly offset line/column/index was passed and discovered the index for firstInvalidTemplateEscapePos was not correctly offset.

As I mentioned in the other PR I am attempting to use these new apis in Marko and with these two (hopefully final) tweaks the Marko test suite now passes. There's a fair amount of "source position" testing and snapshots in that suite so hopefully a good sign that we're not missing anything else.

Note I added another test that is a copy of all of the "start" position override tests just so that I could manually diff/compare all of the test suites from that output.json to see that all the offsetting looks correct. I think it's helpful to keep that test there to reference.

Again I thank all of you for working with me on this 🙏

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

@babel-bot
Copy link
Collaborator

babel-bot commented Oct 26, 2024

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

@DylanPiercey DylanPiercey changed the title fix(babel-parser): ensure offset positions passed when creating new p… fix(babel-parser): ensure offset positions passed when creating new Position instance Oct 26, 2024
@liuxingbaoyu
Copy link
Member

Well, the FUZZ test is not running completely correctly, I will investigate.

@nicolo-ribaudo
Copy link
Member

Would you like to open a PR adding Marko to out e2e test suite?

https://github.com/babel/babel/blob/main/.github/workflows/e2e-tests.yml

Well, the FUZZ test is not running completely correctly, I will investigate.

It's that we are ignoring locations in the fuzz test so we cannot catch this, right?

@liuxingbaoyu
Copy link
Member

It's that we are ignoring locations in the fuzz test so we cannot catch this, right?

Yes!

@nicolo-ribaudo nicolo-ribaudo added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Oct 26, 2024
@nicolo-ribaudo
Copy link
Member

Maybe the adjust function in those tests would adjust the locations in the AST so that we don't need to ignore them?

It's been very long since I looked at that code, I don't remember well how it works.

@liuxingbaoyu
Copy link
Member

Maybe the adjust function in those tests would adjust the locations in the AST so that we don't need to ignore them?

It's been very long since I looked at that code, I don't remember well how it works.

Amazingly correct! It's just a little more complicated to fix since we automatically adjust options in the parser.
Also, fuzz testing found a few bugs that I'll push as soon as possible.

@nicolo-ribaudo
Copy link
Member

Really happy with how the tests turned out :)

@@ -66,8 +73,6 @@ export default function toFuzzedOptions(options) {
[randomIndex, 1, 0],
[randomIndex, randomLine, randomColumn],
[false, randomLine, false],
[false, false, randomColumn],
[randomIndex, false, false],
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add [randomIndex, false, randomIndex] here? It seems that this option does not overlap with others.

Copy link
Member

Choose a reason for hiding this comment

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

Great idea!

Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

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

Well done!

@nicolo-ribaudo nicolo-ribaudo changed the title fix(babel-parser): ensure offset positions passed when creating new Position instance fix: Account for offsets when creating new Position instances Oct 30, 2024
@nicolo-ribaudo nicolo-ribaudo merged commit d8ed865 into babel:main Oct 30, 2024
53 of 54 checks passed
@nicolo-ribaudo
Copy link
Member

Released

@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 Feb 12, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser 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.

6 participants