Backtestsvuerun-20261013-093701#15465
[compiler-sfc] Typo 'exit' instead of 'leave' in estree-walker causes missing ASI guard and runtime error with consecutive awaits
Our patch was judged better than the merged fix.
In this judgment, Patch B = our agent, Patch A = the merged fix.
Both patches make the same source change: `exit` becomes `leave` in the estree-walker options in compileScript.ts. That fixes the root cause, since `scope.pop()` now runs when the walker leaves a BlockStatement and the `needsSemi` calculation for later awaits works again. Correctness is therefore equal, and the decision rests on the tests. Patch A adds one runtime test. It compiles an SFC with a nested empty `if` block followed by two awaits, strips the import, evaluates the code with `new Function` and a mocked `_withAsyncContext`, and checks that setup resolves. This would fail before the fix, because the missing `;` turns the second await into a call on the first one's result. It exercises the reported symptom directly, but it is more fragile: it depends on regex-stripping the import, on the `genDefaultAs` output shape, and on mocked runtime behavior. It also departs from the file's existing pattern for await-detection tests. Patch B adds two tests built on the existing `assertAwaitDetection` helper, which also checks syntax validity. They include explicit regex assertions that both awaits are prefixed with `;(`, plus snapshots. They cover two scenarios: a nested `if` block, and a nested `for` loop inside a `while`. Both would fail before the fix because the semicolon would be missing. Patch B's tests follow the conventions of the surrounding test suite, cover more than one nested-block shape, and give a clear snapshot of the corrected output. With identical fixes, Patch B's broader, convention-consistent tests make it slightly stronger.
The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.
Solve
5m 3s
Wall-clock time in the container
Full test suite
No new failures
626 passed · 1 skipped · 627 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
86vs 21 merged
Changed lines, ours vs merged
The issue
View on GitHubVue version
3.5.40
Link to minimal reproduction
Steps to reproduce
- Open the SFC Playground link.
- Click on the "JS" tab in the right panel to view the compiled output.
- Observe the compiled code for the two
awaitstatements. - Notice that there is no semicolon (
;) inserted between the two_withAsyncContextblocks.
What is expected?
- Open the SFC Playground link.
- Click on the "JS" tab in the right panel to view the compiled output.
- Observe the compiled code for the two
awaitstatements. - Notice that there is no semicolon (
;) inserted between the two_withAsyncContextblocks.
What is actually happening?
What is actually happening? *
The ASI guard (`;`) is missing.
Because of this, the JavaScript engine interprets the second statement as a function call invoked on the result of the first statement, causing a runtime error: `TypeError: (...) is not a function`.
([temp,restore] = _withAsyncContext(() => Promise.resolve(1))),
await __temp,
__restore()
)( // <--- RUNTIME ERROR
([temp,restore] = _withAsyncContext(() => Promise.resolve(2))),
await __temp,
__restore()
)
### System Info
System:
OS: Linux 5.10 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
CPU: (4) x64 AMD EPYC 9575F 64-Core Processor
Memory: 6.69 GB / 11.65 GB
Container: Yes
Shell: 5.1.4 - /bin/bash
Binaries:
Node: 24.14.1 - /root/.nvm/versions/node/v24.14.1/bin/node
Yarn: 1.22.22 - /root/.yarn/bin/yarn
npm: 11.11.0 - /root/.nvm/versions/node/v24.14.1/bin/npm
pnpm: 10.33.0 - /root/.nvm/versions/node/v24.14.1/bin/pnpm
Browsers:
Chrome: 150.0.7871.181
npmPackages:
vue: ^3.5.40 => 3.5.40
### Any additional comments?
**Root Cause:**
The bug is caused by a typo in the AST walker configuration inside `compiler-sfc`. The compiler uses `estree-walker` which expects the hooks `{ enter, leave }`. However, the code currently passes `{ enter, exit }`.
Since `exit` is not a valid hook in `estree-walker`, it is never called. Consequently, `scope.pop()` is never executed when leaving a `BlockStatement` (like the `if` block in the reproduction). This corrupts the `scope` stack, causing the `needsSemi` calculation to fail for all subsequent `AwaitExpression` nodes.
**Proposed Fix:**
Simply change `exit` to `leave` in the walker options:
- exit(node2) {
- leave(node2) { if (node2.type === "BlockStatement") scope.pop(); }
The two patches
packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snapindex 795f0ae88..2f6f8e614 100644@@ -518,6 +518,60 @@ return { } }" `; +exports[`SFC compile <script setup> > async/await detection > prepend semicolon for awaits after a nested block 1`] = `+"import { withAsyncContext as _withAsyncContext } from 'vue'++export default {+ async setup(__props, { expose: __expose }) {+ __expose();++let __temp, __restore+if (ok) {+ if (a) { foo() }+ ;(+ ([__temp,__restore] = _withAsyncContext(() => 1)),+ await __temp,+ __restore()+)+ ;(+ ([__temp,__restore] = _withAsyncContext(() => 2)),+ await __temp,+ __restore()+)+ }+return { }+}++}"+`;++exports[`SFC compile <script setup> > async/await detection > prepend semicolon for awaits after a nested loop block 1`] = `+"import { withAsyncContext as _withAsyncContext } from 'vue'++export default {+ async setup(__props, { expose: __expose }) {+ __expose();++let __temp, __restore+while (ok) {+ for (const i of list) { foo(i) }+ ;(+ ([__temp,__restore] = _withAsyncContext(() => 1)),+ await __temp,+ __restore()+)+ ;(+ ([__temp,__restore] = _withAsyncContext(() => 2)),+ await __temp,+ __restore()+)+ }+return { }+}++}"+`;+ exports[`SFC compile <script setup> > async/await detection > ref 1`] = ` "import { withAsyncContext as _withAsyncContext } from 'vue' packages/compiler-sfc/__tests__/compileScript.spec.tsindex d54541019..e56a4f153 100644@@ -960,6 +960,36 @@ describe('SFC compile <script setup>', () => { assertAwaitDetection(`if (ok) { await foo } else { await bar }`) }) + // scope must be popped when leaving a nested block, otherwise subsequent+ // awaits in the outer block lose their ASI guard+ test('prepend semicolon for awaits after a nested block', () => {+ const code = assertAwaitDetection(`if (ok) {+ if (a) { foo() }+ await 1+ await 2+ }`)+ expect(code).toMatch(+ /}\s*;\(\s*\(\[__temp,__restore\] = _withAsyncContext\(\(\) => 1\)\)/,+ )+ expect(code).toMatch(+ /\)\s*;\(\s*\(\[__temp,__restore\] = _withAsyncContext\(\(\) => 2\)\)/,+ )+ })++ test('prepend semicolon for awaits after a nested loop block', () => {+ const code = assertAwaitDetection(`while (ok) {+ for (const i of list) { foo(i) }+ await 1+ await 2+ }`)+ expect(code).toMatch(+ /}\s*;\(\s*\(\[__temp,__restore\] = _withAsyncContext\(\(\) => 1\)\)/,+ )+ expect(code).toMatch(+ /\)\s*;\(\s*\(\[__temp,__restore\] = _withAsyncContext\(\(\) => 2\)\)/,+ )+ })+ test('multiple `if` nested statements', () => { assertAwaitDetection(`if (ok) { let a = 'foo'packages/compiler-sfc/src/compileScript.tsindex d2047c5b2..901196235 100644@@ -669,7 +669,7 @@ export function compileScript( ) } },- exit(node: Node) {+ leave(node: Node) { if (node.type === 'BlockStatement') scope.pop() }, })
packages/compiler-sfc/__tests__/compileScript.spec.tsindex d54541019..a1cc885cd 100644@@ -1026,6 +1026,25 @@ describe('SFC compile <script setup>', () => { false, ) })++ // #15465+ test('await statements after a nested block should be separated', async () => {+ const { content } = compile(+ `<script setup>+ if (true) {+ if (false) {}+ await Promise.resolve(1)+ await Promise.resolve(2)+ }+ </script>`,+ { genDefaultAs: '_sfc_' },+ )+ const component = new Function(+ '_withAsyncContext',+ `${content.replace(/^import .*\n/, '')};return _sfc_`,+ )((getAwaitable: () => unknown) => [getAwaitable(), () => {}])+ await expect(component.setup({}, { expose() {} })).resolves.toEqual({})+ }) }) describe('errors', () => {packages/compiler-sfc/src/compileScript.tsindex d2047c5b2..901196235 100644@@ -669,7 +669,7 @@ export function compileScript( ) } },- exit(node: Node) {+ leave(node: Node) { if (node.type === 'BlockStatement') scope.pop() }, })