]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): add test for #5808
authorliulinboyi <814921718@qq.com>
Wed, 27 Apr 2022 01:33:21 +0000 (09:33 +0800)
committerEvan You <yyx990803@gmail.com>
Fri, 13 May 2022 07:41:49 +0000 (15:41 +0800)
packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap
packages/compiler-sfc/__tests__/compileScript.spec.ts

index 7cfb593cb0b5bba4d9ff1f05e5b3c8541af4bf47..358f79dec4d9bbf4cfc95b378ec858aeebd13db5 100644 (file)
@@ -194,6 +194,173 @@ return {  }
 }"
 `;
 
+exports[`SFC compile <script setup> async/await detection multiple \`if for\` nested statements 1`] = `
+"import { withAsyncContext as _withAsyncContext } from 'vue'
+
+export default {
+  async setup(__props, { expose }) {
+  expose();
+
+let __temp, __restore
+if (ok) { 
+        for (let a of [1,2,3]) {
+          (
+  ([__temp,__restore] = _withAsyncContext(() => a)),
+  await __temp,
+  __restore()
+)
+        }
+        for (let a of [1,2,3]) {
+          (
+  ([__temp,__restore] = _withAsyncContext(() => a)),
+  await __temp,
+  __restore()
+)
+          ;(
+  ([__temp,__restore] = _withAsyncContext(() => a)),
+  await __temp,
+  __restore()
+)
+        }
+      }
+return {  }
+}
+
+}"
+`;
+
+exports[`SFC compile <script setup> async/await detection multiple \`if while\` nested statements 1`] = `
+"import { withAsyncContext as _withAsyncContext } from 'vue'
+
+export default {
+  async setup(__props, { expose }) {
+  expose();
+
+let __temp, __restore
+if (ok) { 
+        while (d) {
+          (
+  ([__temp,__restore] = _withAsyncContext(() => 5)),
+  await __temp,
+  __restore()
+)
+        }
+        while (d) {
+          (
+  ([__temp,__restore] = _withAsyncContext(() => 5)),
+  await __temp,
+  __restore()
+)
+          ;(
+  ([__temp,__restore] = _withAsyncContext(() => 6)),
+  await __temp,
+  __restore()
+)
+          if (c) {
+            let f = 10
+            10 + (
+  ([__temp,__restore] = _withAsyncContext(() => 7)),
+  __temp = await __temp,
+  __restore(),
+  __temp
+)
+          } else {
+            (
+  ([__temp,__restore] = _withAsyncContext(() => 8)),
+  await __temp,
+  __restore()
+)
+            ;(
+  ([__temp,__restore] = _withAsyncContext(() => 9)),
+  await __temp,
+  __restore()
+)
+          }
+        }
+      }
+return {  }
+}
+
+}"
+`;
+
+exports[`SFC compile <script setup> async/await detection multiple \`if\` nested statements 1`] = `
+"import { withAsyncContext as _withAsyncContext } from 'vue'
+
+export default {
+  async setup(__props, { expose }) {
+  expose();
+
+let __temp, __restore
+if (ok) { 
+        let a = 'foo'
+        ;(
+  ([__temp,__restore] = _withAsyncContext(() => 0)),
+  __temp = await __temp,
+  __restore(),
+  __temp
+) + (
+  ([__temp,__restore] = _withAsyncContext(() => 1)),
+  __temp = await __temp,
+  __restore(),
+  __temp
+)
+        ;(
+  ([__temp,__restore] = _withAsyncContext(() => 2)),
+  await __temp,
+  __restore()
+)
+      } else if (a) {
+        (
+  ([__temp,__restore] = _withAsyncContext(() => 10)),
+  await __temp,
+  __restore()
+)
+        if (b) {
+          (
+  ([__temp,__restore] = _withAsyncContext(() => 0)),
+  __temp = await __temp,
+  __restore(),
+  __temp
+) + (
+  ([__temp,__restore] = _withAsyncContext(() => 1)),
+  __temp = await __temp,
+  __restore(),
+  __temp
+)
+        } else {
+          let a = 'foo'
+          ;(
+  ([__temp,__restore] = _withAsyncContext(() => 2)),
+  await __temp,
+  __restore()
+)
+        }
+        if (b) {
+          (
+  ([__temp,__restore] = _withAsyncContext(() => 3)),
+  await __temp,
+  __restore()
+)
+          ;(
+  ([__temp,__restore] = _withAsyncContext(() => 4)),
+  await __temp,
+  __restore()
+)
+        }
+      } else { 
+        (
+  ([__temp,__restore] = _withAsyncContext(() => 5)),
+  await __temp,
+  __restore()
+)
+      }
+return {  }
+}
+
+}"
+`;
+
 exports[`SFC compile <script setup> async/await detection nested await 1`] = `
 "import { withAsyncContext as _withAsyncContext } from 'vue'
 
index 85c851d6f8b0133212e70bae4b9fc3b105e007b0..3226be19e6487000a42013db6ee6a5f731d93b62 100644 (file)
@@ -1195,6 +1195,59 @@ const emit = defineEmits(['a', 'b'])
       assertAwaitDetection(`if (ok) { await foo } else { await bar }`)
     })
 
+    test('multiple `if` nested statements', () => {
+      assertAwaitDetection(`if (ok) { 
+        let a = 'foo'
+        await 0 + await 1
+        await 2
+      } else if (a) {
+        await 10
+        if (b) {
+          await 0 + await 1
+        } else {
+          let a = 'foo'
+          await 2
+        }
+        if (b) {
+          await 3
+          await 4
+        }
+      } else { 
+        await 5
+      }`)
+    })
+
+    test('multiple `if while` nested statements', () => {
+      assertAwaitDetection(`if (ok) { 
+        while (d) {
+          await 5
+        }
+        while (d) {
+          await 5
+          await 6
+          if (c) {
+            let f = 10
+            10 + await 7
+          } else {
+            await 8
+            await 9
+          }
+        }
+      }`)
+    })
+
+    test('multiple `if for` nested statements', () => {
+      assertAwaitDetection(`if (ok) { 
+        for (let a of [1,2,3]) {
+          await a
+        }
+        for (let a of [1,2,3]) {
+          await a
+          await a
+        }
+      }`)
+    })
+
     test('should ignore await inside functions', () => {
       // function declaration
       assertAwaitDetection(`async function foo() { await bar }`, false)