Backtestsvuerun-20261001-022054#15465
[compiler-sfc] Typo 'exit' instead of 'leave' in estree-walker causes missing ASI guard and runtime error with consecutive awaits
The merged fix was judged better than our patch.
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. This fixes the root cause the issue identifies. `scope.pop()` now runs when leaving a BlockStatement, so the scope stack stays correct and the ASI guard is emitted for later awaits. Correctness is therefore identical, and the difference comes down to the tests. Patch A's test reproduces the issue's scenario: a nested block followed by two consecutive awaits. It then runs the compiled output via `new Function` with a stubbed `_withAsyncContext` and asserts that `setup` resolves. That checks the user-visible failure directly, the `TypeError: (...) is not a function` caused by the missing semicolon. It would fail before the fix and pass after it, and it does not depend on exact output formatting. Patch B's test builds a similar scenario but asserts on exact substrings of the generated code, including a hard-coded newline and 8-space indentation (`__restore()\n)\n ;(`). It does catch the regression, but it is tied to whitespace and codegen layout and only checks for the semicolon, not runtime behaviour. Patch B's placement next to the related await-detection tests is slightly more in keeping with the file, but that does not outweigh Patch A's more robust behavioural test. Scope is minimal and equal in both. Overall, A is moderately better on test quality.
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
1m 50s8 turns
Wall-clock time in the container
Full test suite
No new failures
3,720 passed · 6 skipped · 3,726 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
16vs 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__/compileScript.spec.tsindex d54541019..2338d5ee9 100644@@ -960,6 +960,20 @@ describe('SFC compile <script setup>', () => { assertAwaitDetection(`if (ok) { await foo } else { await bar }`) }) + // should prepend semicolon after leaving a nested block+ test('consecutive awaits after a nested block statement', () => {+ // not using assertAwaitDetection to avoid a snapshot+ const { content } = compile(`<script setup>if (ok) {+ if (a) { foo() }+ await 1+ await 2+ }</script>`)+ expect(content).toMatch(`let __temp, __restore`)+ expect(content).toMatch(`async setup(`)+ expect(content).toMatch(`__restore()\n)\n ;(`)+ expect(content).not.toMatch(`__restore()\n)\n (`)+ })+ 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() }, })
What the agent reported
I fixed the bug: in compileScript.ts the "leaving a block" hook was named exit, which the AST walker never calls. I renamed it to leave, added a regression test for it, and the tests pass.
What was wrong: The compiler keeps a stack of the blocks it is inside, and uses it to decide whether a compiled await needs a ; in front of it. The walker in node_modules/estree-walker only calls enter and leave, so the code that pops a block off the stack never ran. After the walker left a nested { } block, it kept checking against that inner block. As a result, a later await that needed the ; didn't get one. Two compiled awaits in a row then read as a function call, which causes the TypeError: (...) is not a function in the report.
What I changed:
packages/compiler-sfc/src/compileScript.ts:672:exit(node: Node)is nowleave(node: Node). This is the fix proposed in the report.packages/compiler-sfc/__tests__/compileScript.spec.ts: a new test, "consecutive awaits after a nested block statement". It compiles:if (ok) { if (a) { foo() } await 1 await 2 }It checks that the second compiled await starts with;(and that the bad form)\n(is gone. It callscompiledirectly rather than the usualassertAwaitDetectionhelper: that helper also compares against a snapshot, and the test runner won't save new snapshots, so the test would fail on the snapshot step instead of the real check.
Test evidence:
- On the original code the new test fails with an assertion error, and the compiled output shows
)\n(between the two awaits. Withleaveit passes. I checked it both ways. - All
compileScript.spec.tstests and everything under__tests__/compileScript/pass: 11 files, 326 passed, 1 skipped (that skip already existed). The existing saved outputs for nested-block awaits are unchanged.
The playground example: The block stack is reset for each top-level statement. In the report's example, the if block and the two awaits are separate top-level statements, and the source already ends each await with ;. So I'd expect that exact input to compile correctly even without the fix, though I didn't run it. The bug shows up when a nested block and the following awaits are inside the same top-level statement, which is what the new test covers.
Requirements:
- Rename
exittoleaveso the stack is popped when leaving a block: done, at line 672. - Put the
;back between consecutive awaits after a nested block: done. The new test fails before the fix and passes after. - No
TypeErrorfrom two compiled awaits being read as a call: covered, since the test asserts the)\n(form no longer appears. - Keep the change minimal: one line of production code plus one test. No existing tests or saved outputs changed, and no extra files were left behind.
I reviewed the final diff myself instead of sending it to the reviewer agent, since it is two lines of production code plus one test. All changes are uncommitted in the working tree.