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 mapping of tokens with generated nodes in between #16948

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix mapping of tokens with generated nodes in between
  • Loading branch information
nicolo-ribaudo committed Oct 30, 2024
commit 9fab039ba5efbdbefc218ba3ef595297a1529717
3 changes: 2 additions & 1 deletion packages/babel-generator/src/token-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ export class TokenMap {
const indexes = [];

for (const child of children) {
if (!child) continue;
if (child == null) continue;
if (child.start == null || child.end == null) continue;
Comment on lines +161 to +162

Choose a reason for hiding this comment

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

Suggested change
if (child == null) continue;
if (child.start == null || child.end == null) continue;
if (child == null || child.start == null || child.end == null) continue;

Copy link
Member Author

Choose a reason for hiding this comment

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

Heheh unfortunately typescript-eslint complains that child == null || child.start == null should be rewritten to child?.start == null, but I find child?.start == null || child.end == null to be terrible so this two-lines solution was the compromise I reached with the linter :P


const childTok = this._findTokensOfNode(child, low, last);

Expand Down
4 changes: 2 additions & 2 deletions packages/babel-generator/test/preserve-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ describe("experimental_preserveFormat", () => {
const expected = `
const foo
= 3;hello;
const bar=
3
const bar =
3;
bax
`;

Expand Down
Loading