Skip to content

perf(transform): skip parsing files without await#135

Open
TheAlexLichter wants to merge 1 commit into
unjs:mainfrom
TheAlexLichter:fix/skip-transform-without-await
Open

perf(transform): skip parsing files without await#135
TheAlexLichter wants to merge 1 commit into
unjs:mainfrom
TheAlexLichter:fix/skip-transform-without-await

Conversation

@TheAlexLichter

@TheAlexLichter TheAlexLichter commented Jun 27, 2026

Copy link
Copy Markdown
Member

Thightens shouldTransform given that await is needed as keyword.

Summary by CodeRabbit

  • Bug Fixes
    • Tightened transformation eligibility so code is only processed when it includes both a supported target function call and a real await keyword.
    • Avoids triggering on lookalike or unrelated patterns that merely contain “await” text.
  • Tests
    • Expanded shouldTransform test coverage with additional negative and edge-case inputs (e.g., target call without await, await without the target call, and non-keyword “await” usage).

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d9e10adc-f9d9-476a-b130-2baf3b29c249

📥 Commits

Reviewing files that changed from the base of the PR and between fe2bf77 and 901160d.

📒 Files selected for processing (2)
  • src/transform.ts
  • test/transform.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/transform.test.ts
  • src/transform.ts

📝 Walkthrough

Walkthrough

Adds an AWAIT_RE regex to src/transform.ts and updates shouldTransform to return true only when both the configured function-call pattern and the await keyword are present in the source. New tests verify all four conditions.

shouldTransform await guard

Layer / File(s) Summary
AWAIT_RE regex and shouldTransform guard
src/transform.ts, test/transform.test.ts
AWAIT_RE detects the await keyword; shouldTransform now ANDs it with the existing matchRE check. Tests assert true only when both are present and false for missing function, missing await, or non-keyword await.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐇 A hop through the code, a quick little check,
No await? No transform — keep logic in spec!
The regex stands guard like a sentinel keen,
Only matched calls with await shall convene.
Carrots for correctness, the rabbit agrees! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: skipping transform work when no await keyword is present.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/transform.ts`:
- Line 38: The `AWAIT_RE` fast path in `shouldTransform()` is too broad because
it matches member accesses like `obj.await()` and `$await()` even when no
`AwaitExpression` exists. Tighten the regex or guard logic in `shouldTransform`
to only detect real async/await syntax, and add test coverage for member-access
and `$`-prefixed identifiers to ensure those cases do not trigger parsing.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0c0818a1-3201-42e7-a1bf-9761959b36f3

📥 Commits

Reviewing files that changed from the base of the PR and between 7005e81 and fe2bf77.

📒 Files selected for processing (2)
  • src/transform.ts
  • test/transform.test.ts

Comment thread src/transform.ts Outdated
@TheAlexLichter TheAlexLichter force-pushed the fix/skip-transform-without-await branch from fe2bf77 to 901160d Compare June 27, 2026 17:52
Comment thread src/transform.ts
function shouldTransform(code: string): boolean {
return typeof code === "string" && matchRE.test(code);
return (
typeof code === "string" && matchRE.test(code) && AWAIT_RE.test(code)

@pi0 pi0 Jun 28, 2026

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.

I think we can reorder await check before matchRe as it is more predictable/restrictive.

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.

I don't think that'll be more efficient.

At the moment, we check less files for both the functions + await
If we put the await regex first we have more files in the first selection (more files have await than one of the functions checked matchRE), and then reject a lot of files after.

@TheAlexLichter TheAlexLichter requested a review from pi0 June 28, 2026 12:34
@TheAlexLichter

Copy link
Copy Markdown
Member Author

CI is failing due to setup issues that I resolved via #134 already

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