Backtestsvuerun-20261002-115633#15465

Issue #15465 Merged fix PR # Run 2 Oct 2026 · run-20261002-115633 vuejs/core

[compiler-sfc] Typo 'exit' instead of 'leave' in estree-walker causes missing ASI guard and runtime error with consecutive awaits

Better

Our patch was judged better than the merged fix.

In this judgment, Patch A = our agent, Patch B = the merged fix.

Both patches make the same core fix in compileScript.ts, renaming the never-invoked `exit` hook to `leave`. That lets `scope.pop()` run when leaving a BlockStatement and restores the `needsSemi` ASI guard. On correctness they are identical. The difference is in the supporting changes. Patch A also removes the bogus `exit?` option from the hand-written `estree-walker` declaration in global.d.ts. That declaration is what let the typo type-check in the first place. Removing it means the type checker will reject a future `exit` key, which addresses why the bug went unnoticed without adding any risk. On tests, Patch A adds two output-based cases. One has a nested `if` and the other has `for` and `try/catch` blocks before consecutive awaits. Both assert that each await gets its leading `;(` guard. Before the fix the stale scope stack hides the enclosing statement list, so the semicolon would be missing and these tests would fail. Patch B's single test actually runs the compiled setup via `new Function`, which tests the runtime symptom directly. That is a nice idea, but the test is more fragile. It relies on stripping one import line with a regex. It stubs `_withAsyncContext`. It also relies on `toEqual({})` against the dev-mode `__returned__` object, which carries a non-enumerable `__isScriptSetup` property. It covers only one nested-block shape. Both test sets would catch the regression, but A covers more block types and also hardens the typings. A is the better patch.

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

7m 20s

Wall-clock time in the container

Full test suite

No new failures

3,721 passed · 6 skipped · 3,727 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

48vs 21 merged

Changed lines, ours vs merged

Vue version

3.5.40

Link to minimal reproduction

https://play.vuejs.org/#eNp9kk9PAyEQxb/KhIttUln/xYNumqjxoAc12ngiMevuuEVZIDBsa0y/u8M21h60J8j8HsN7A1/iwnvZJxRnoox10J4gIiU/VbYo4FDChf0Ei5GwgVfj6g8Y+RTnGIEcxNp5nMBrIpb0GMA7H6FJmCHNkUk7Vla/wYhCwjF8KQtQOxudQWlcO9rbbr3H2pWyw81HEmYLN2ixTqT73NPvG77GQLWoNEVlhxUegut0RBmQ2/Y4Ohyf/4eOMiqLdVCOWBJ23lSE07LR/XTGZsoi78piQ8REEAe1b7qV79FZntQQQ4nadV4bDPeeNPtU4mwdMLPKGLe4HWo5+uSnXs+x/vij/h6XuabEA3vF0KMSG0ZVaJHW+PrpDpe838DONcmwegd8zOl5hs6uZZfJNmx7Sze4vem8C6RtO4vXS0Ibf0Jlo1m5GvRK8He52hH91+6xPBnO8bPyFF8oPmPIXXmEp/JAHovVNzTb1oo=

Steps to reproduce

  1. Open the SFC Playground link.
  2. Click on the "JS" tab in the right panel to view the compiled output.
  3. Observe the compiled code for the two await statements.
  4. Notice that there is no semicolon (;) inserted between the two _withAsyncContext blocks.

What is expected?

  1. Open the SFC Playground link.
  2. Click on the "JS" tab in the right panel to view the compiled output.
  3. Observe the compiled code for the two await statements.
  4. Notice that there is no semicolon (;) inserted between the two _withAsyncContext blocks.

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

Our patch+46 −2
packages/compiler-sfc/__tests__/compileScript.spec.tsindex d54541019..bc913e60c 100644@@ -1013,6 +1013,51 @@ describe('SFC compile <script setup>', () => {       }`)     }) +    // the walker must pop the block scope when leaving a nested block,+    // otherwise awaits following that block are checked against the wrong+    // scope and lose their ASI guard, making the second await be parsed as+    // a call on the result of the first one.+    function assertGuardedAwaits(code: string, values: number[]) {+      const { content } = compile(`<script setup>${code}</script>`)+      expect(content).toMatch(`async setup(`)+      for (const v of values) {+        expect(content).toMatch(+          new RegExp(+            `\\n\\s*;\\(\\n  \\(\\[__temp,__restore\\] = _withAsyncContext\\(\\(\\) => ${v}\\)\\)`,+          ),+        )+      }+    }++    test('consecutive awaits after a nested block statement', () => {+      assertGuardedAwaits(+        `if (ok) {+          if (a) {+            foo()+          }+          await 1+          await 2+        }`,+        [1, 2],+      )+    })++    test('consecutive awaits after nested loop and try blocks', () => {+      assertGuardedAwaits(+        `if (ok) {+          for (const i of list) {+            foo(i)+          }+          try {+            bar()+          } catch (e) {}+          await 1+          await 2+        }`,+        [1, 2],+      )+    })+     test('should ignore await inside functions', () => {       // function declaration       assertAwaitDetection(`async function foo() { await bar }`, false)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/global.d.tsindex 8b627d2e5..43a204763 100644@@ -24,7 +24,6 @@ declare module 'estree-walker' {     options: {       enter?: (node: T, parent: T | null) => any       leave?: (node: T, parent: T | null) => any-      exit?: (node: T) => any     } & ThisType<{ skip: () => void }>,   ) } 
Merged fix · PR #+20 −1
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()         },       })