Skip to content

ref(nextjs): Refactor findInjectionIndexAfterDirectives for better readability#20310

Merged
s1gr1d merged 1 commit intodevelopfrom
sig/ref-turbopack-directive
Apr 15, 2026
Merged

ref(nextjs): Refactor findInjectionIndexAfterDirectives for better readability#20310
s1gr1d merged 1 commit intodevelopfrom
sig/ref-turbopack-directive

Conversation

@s1gr1d
Copy link
Copy Markdown
Member

@s1gr1d s1gr1d commented Apr 15, 2026

Builds on top of this PR: #20103

Adds some explaining comments and refactors the directive-scanning logic in the value injection loader from 4 functions down to 3 by inlining whitespace and comment skipping into the main loop.

The previous implementation split the scanning into a separate skipWhitespaceAndComments function. The new version handles whitespace, line comments, and block comments as continue branches directly in the main while loop, which:

  • Eliminates one level of function calls
  • Unterminated block comments are handled inline with an early return
  • Makes the control flow easier to follow. Each iteration of the loop either skips something inert (whitespace/comments), successfully parses a directive and advances, or exits

@s1gr1d s1gr1d requested a review from chargome April 15, 2026 07:44
Copy link
Copy Markdown
Member

@chargome chargome left a comment

Choose a reason for hiding this comment

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

thanks!

@s1gr1d s1gr1d merged commit 7ded034 into develop Apr 15, 2026
73 checks passed
@s1gr1d s1gr1d deleted the sig/ref-turbopack-directive branch April 15, 2026 08:04
mydea pushed a commit that referenced this pull request Apr 15, 2026
…readability (#20310)

Builds on top of this PR:
#20103

Adds some explaining comments and refactors the directive-scanning logic
in the value injection loader from 4 functions down to 3 by inlining
whitespace and comment skipping into the main loop.

The previous implementation split the scanning into a separate
`skipWhitespaceAndComments` function. The new version handles
whitespace, line comments, and block comments as continue branches
directly in the main while loop, which:
- Eliminates one level of function calls
- Unterminated block comments are handled inline with an early return
- Makes the control flow easier to follow. Each iteration of the loop
either skips something inert (whitespace/comments), successfully parses
a directive and advances, or exits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants