Skip to content

feat: add await expression support#157

Merged
antfu merged 1 commit into
unjs:mainfrom
Jack-sh1:feat/await-expression
May 13, 2026
Merged

feat: add await expression support#157
antfu merged 1 commit into
unjs:mainfrom
Jack-sh1:feat/await-expression

Conversation

@Jack-sh1
Copy link
Copy Markdown
Contributor

@Jack-sh1 Jack-sh1 commented May 12, 2026

Add builders.awaitExpression() and corresponding proxy/type definitions to allow programmatic creation and parsing of await expressions.

Resolves #114

Changes

  • New src/proxy/await-expression.ts — proxifier for AwaitExpression AST nodes
  • New builders.awaitExpression(argument) in src/builders.ts
  • Add ProxifiedAwaitExpression type and include it in ProxifiedValue union
  • Add AwaitExpression case in proxify() router
  • Add tests covering builder usage, raw expression wrapping, and parsing existing await code

Summary by CodeRabbit

Release Notes

  • New Features

    • Users can now create and manipulate await expressions programmatically through an enhanced builder API, enabling more flexible and intuitive handling of complex asynchronous code patterns in both generated code and existing modules.
  • Tests

    • Added comprehensive test coverage for the new await expression functionality across multiple async scenarios, patterns, and common real-world use cases.

Review Change Stack

Add `builders.awaitExpression()` and corresponding proxy/type definitions
to allow programmatic creation and parsing of `await` expressions.

Closes unjs#114
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 25746bdb-f0a1-4627-9073-8f8221887ab6

📥 Commits

Reviewing files that changed from the base of the PR and between 12917c0 and 11f8be4.

📒 Files selected for processing (5)
  • src/builders.ts
  • src/proxy/await-expression.ts
  • src/proxy/proxify.ts
  • src/proxy/types.ts
  • test/builders/await-expression.test.ts

📝 Walkthrough

Walkthrough

This PR adds complete support for JavaScript await expressions to the Magicast library. It defines a new proxified AST node type, implements proxification and deserialization handlers, adds a builder factory method, and includes comprehensive test coverage for building and parsing await-expression code.

Changes

Await Expression Feature

Layer / File(s) Summary
Proxification infrastructure and type definitions
src/proxy/types.ts, src/proxy/await-expression.ts, src/proxy/proxify.ts
Defines ProxifiedAwaitExpression type with $type: "await-expression" and proxified $argument. Implements proxifyAwaitExpression with Babel type validation and proxy construction. Integrates AwaitExpression routing into the proxify switch statement to support runtime deserialization.
Builder API and test coverage
src/builders.ts, test/builders/await-expression.test.ts
Introduces builders.awaitExpression() factory that converts arguments to AST form and proxifies the result. Tests validate building await-expressions around function calls and imports, parsing existing await-expression code, and verifying the resulting proxified structure.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

A rabbit hops through promises with care,
With await expressions now floating in air,
New proxies bloom where suspense takes its place,
Building and parsing at a furry fast pace! 🐰✨

🚥 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 'feat: add await expression support' is clear and specific, accurately summarizing the main feature addition of comprehensive await expression support with builders and proxified AST nodes.
Linked Issues check ✅ Passed The PR successfully implements full await expression support as requested in #114, providing a new proxified AST node approach instead of modifying function-call builder, meeting the primary feature requirement.
Out of Scope Changes check ✅ Passed All changes are directly related to await expression support: new proxy handler, builder method, type definitions, router integration, and comprehensive tests—no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@userquin
Copy link
Copy Markdown
Contributor

LGTM

@antfu antfu merged commit b112424 into unjs:main May 13, 2026
1 check passed
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.

[Feature Request] Add await expressions or modify the functionCall builder to be able to be set to await'ed

3 participants