SIGN IN SIGN UP
oven-sh / bun UNCLAIMED

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one

0 0 150 Rust

Fix `await using` expression printing `using` as `await` (#31324)

### Problem

Found by the transpiler fuzzer (printed output does not reparse):

```js
new Bun.Transpiler({ loader: "jsx", target: "bun", minifyWhitespace: true })
  .transformSync("async function f(){await using instanceof o}")
// => "async function f(){await await instanceof o}"   (does not reparse: "Unexpected instanceof")
```

`await using` only starts an `await using` declaration when it is
followed by an identifier on the same line. Otherwise it is an `await`
expression whose operand is the identifier `using` — e.g. `await using
instanceof o`, `await using.foo()`, `await using` followed by a newline.
In that fallback path the parser printed the operand as `await`,
producing invalid output like `await await instanceof o`.

### Cause

In `parse_expr_or_let_stmt` (`src/js_parser/parse/mod.rs`), the fallback
that builds the `E::Identifier` for `using` called
`store_name_in_ref(raw)`, where `raw` is the raw text of the *first*
token (`"await"`). The identifier therefore got the name `await`. The
correct name is `raw2`, the raw text of the `using` token.

### Fix

Pass `raw2` (`"using"`) to `store_name_in_ref`, matching what the normal
identifier-expression path would have stored.

### Verification

- `bun bd test test/bundler/transpiler/transpiler.test.js` — 147 pass, 0
fail.
- New test `await of the identifier 'using' is not an await using
declaration` covers `instanceof`, bare `await using`, ASI via newline,
member access, for-loop init, and top-level await; it fails without the
src change and passes with it.
- `await using x = y`, `using x = y`, and `for (await using a of b)`
declarations still parse and lower through `__using`/`__callDispose` as
before.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
R
robobun committed
9d5356a686f8b66a9b8fc9b4d300add36b7f90bc
Parent: 80df5b1
Committed by GitHub <noreply@github.com> on 5/24/2026, 8:50:39 PM