Skip to content

fix(es/parser): Don't call bump_bytes in the continue_if of byte_search!#11328

Merged
kdy1 merged 4 commits intoswc-project:mainfrom
CPunisher:11-25-fix/skip-block-comment
Nov 25, 2025
Merged

fix(es/parser): Don't call bump_bytes in the continue_if of byte_search!#11328
kdy1 merged 4 commits intoswc-project:mainfrom
CPunisher:11-25-fix/skip-block-comment

Conversation

@CPunisher
Copy link
Member

Description:

In #11323, we only records the pos as an offset related the current remaining string and bumps the lexer at the end of byte_search! to reduce the calls to bump_bytes. However, if bump_bytes is manually called in the continue_if, the invariant is broken.

Copilot AI review requested due to automatic review settings November 25, 2025 06:18
@CPunisher CPunisher requested a review from a team as a code owner November 25, 2025 06:18
@changeset-bot
Copy link

changeset-bot bot commented Nov 25, 2025

🦋 Changeset detected

Latest commit: ea61d97

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes an issue in the byte_search! macro usage where bump_bytes was being called within the continue_if block, breaking the invariant that the lexer position should only be bumped at the end of the macro. The fix refactors the block comment parsing to use offset-based position tracking and defer the final bump until after the search completes.

Key Changes

  • Added documentation to the byte_search! macro explaining the pointer-based search approach and warning about not changing lexer position in continue_if
  • Removed local had_line_break variable and replaced with direct calls to mark_had_line_break()
  • Replaced manual bump_bytes calls in continue_if with offset increments, deferring position updates to the macro's end

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
crates/swc_ecma_parser/src/lexer/search.rs Added documentation for the byte_search! macro explaining its behavior and usage constraints
crates/swc_ecma_parser/src/lexer/mod.rs Refactored skip_block_comment to use offset-based tracking instead of calling bump_bytes in continue_if, eliminating the local had_line_break variable

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 25, 2025

CodSpeed Performance Report

Merging #11328 will not alter performance

Comparing CPunisher:11-25-fix/skip-block-comment (ea61d97) with main (93bbe7f)

Summary

✅ 138 untouched

@github-actions
Copy link
Contributor

github-actions bot commented Nov 25, 2025

Binary Sizes

File Size
swc.linux-x64-gnu.node 31M (31956552 bytes)

Commit: 1411811

@CPunisher CPunisher marked this pull request as draft November 25, 2025 06:30
@CPunisher CPunisher marked this pull request as ready for review November 25, 2025 06:49
Copilot AI review requested due to automatic review settings November 25, 2025 06:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@kdy1 kdy1 added this to the Planned milestone Nov 25, 2025
@kdy1 kdy1 requested a review from a team as a code owner November 25, 2025 10:47
Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

Thank you, as always!

@kdy1 kdy1 merged commit 583619d into swc-project:main Nov 25, 2025
23 checks passed
@CPunisher CPunisher deleted the 11-25-fix/skip-block-comment branch November 25, 2025 11:30
@kdy1 kdy1 modified the milestones: Planned, 1.15.4 Dec 14, 2025
@swc-project swc-project locked as resolved and limited conversation to collaborators Jan 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

3 participants