]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): parses correctly when inline mode is off (#8337)
author白雾三语 <32354856+baiwusanyu-c@users.noreply.github.com>
Thu, 18 May 2023 05:07:08 +0000 (13:07 +0800)
committerGitHub <noreply@github.com>
Thu, 18 May 2023 05:07:08 +0000 (13:07 +0800)
close #6088

packages/compiler-sfc/__tests__/compileScript.spec.ts
packages/compiler-sfc/src/script/importUsageCheck.ts

index afe656b4a2c7ceaa4ebae65fa506ea0e41375ab1..6da274dd8a5506f67f8aeeaccd98cf9625118421 100644 (file)
@@ -804,6 +804,25 @@ describe('SFC compile <script setup>', () => {
       expect(content).toMatch(`"--${mockId}-count": (count.value)`)
       assertCode(content)
     })
+
+    test('the v-for wrapped in parentheses can be correctly parsed & inline is false', () => {
+      expect(() =>
+        compile(
+          `
+        <script setup lang="ts">
+        import { ref } from 'vue'
+        const stacks = ref([])
+        </script>
+        <template>
+            <div v-for="({ file: efile }) of stacks"></div>
+        </template>
+        `,
+          {
+            inlineTemplate: false
+          }
+        )
+      ).not.toThrowError()
+    })
   })
 
   describe('with TypeScript', () => {
index 59473a9dda38adc3beadbb4e2548765dce1a6895..b42397d573b267d46476b107a190ede5ad6fcef3 100644 (file)
@@ -83,7 +83,9 @@ function processExp(exp: string, dir?: string): string {
     } else if (dir === 'for') {
       const inMatch = exp.match(forAliasRE)
       if (inMatch) {
-        const [, LHS, RHS] = inMatch
+        let [, LHS, RHS] = inMatch
+        // #6088
+        LHS = LHS.trim().replace(/^\(|\)$/g, '')
         return processExp(`(${LHS})=>{}`) + processExp(RHS)
       }
     }