diff --git a/src/js_parser/parse/mod.rs b/src/js_parser/parse/mod.rs index 5719a2acba2..91c5e576d55 100644 --- a/src/js_parser/parse/mod.rs +++ b/src/js_parser/parse/mod.rs @@ -919,7 +919,7 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O decls: decls_slice, }); } - let r = p.store_name_in_ref(raw)?; + let r = p.store_name_in_ref(raw2)?; break 'value p.new_expr( E::Identifier { ref_: r, diff --git a/test/bundler/transpiler/transpiler.test.js b/test/bundler/transpiler/transpiler.test.js index 1faa1b04f2b..b662dc5a9ab 100644 --- a/test/bundler/transpiler/transpiler.test.js +++ b/test/bundler/transpiler/transpiler.test.js @@ -3824,6 +3824,23 @@ console.log("boop"); expectCapturePrintedSnapshot(`for await (await using a of b) { c(a); a(c) }`); }); + it("await of the identifier 'using' is not an await using declaration", () => { + // "await using" only starts a declaration when followed by an identifier on + // the same line. Otherwise it's an "await" expression of the identifier "using". + expectPrinted_( + "async function f() { await using instanceof o }", + "async function f() {\n await using instanceof o;\n}", + ); + expectPrinted_("async function f() { await using }", "async function f() {\n await using;\n}"); + expectPrinted_("async function f() { await using\n x = 1 }", "async function f() {\n await using;\n x = 1;\n}"); + expectPrinted_("async function f() { await using.foo() }", "async function f() {\n await using.foo();\n}"); + expectPrinted_( + "async function f() { for (await using instanceof o;;); }", + "async function f() {\n for (await using instanceof o;; )\n ;\n}", + ); + expectBunPrinted_("await using instanceof o", "await using instanceof o"); + }); + it("using top level", () => { expectPrintedSnapshot(` using a = b;