From ecbd42a1444e3c599e464dec002e43d548d99669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E9=9B=BE=E4=B8=89=E8=AF=AD?= <32354856+baiwusanyu-c@users.noreply.github.com> Date: Thu, 18 May 2023 13:07:08 +0800 Subject: [PATCH] fix(compiler-sfc): parses correctly when inline mode is off (#8337) close #6088 --- .../__tests__/compileScript.spec.ts | 19 +++++++++++++++++++ .../src/script/importUsageCheck.ts | 4 +++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/compiler-sfc/__tests__/compileScript.spec.ts b/packages/compiler-sfc/__tests__/compileScript.spec.ts index afe656b4a2c..6da274dd8a5 100644 --- a/packages/compiler-sfc/__tests__/compileScript.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScript.spec.ts @@ -804,6 +804,25 @@ describe('SFC compile + + `, + { + inlineTemplate: false + } + ) + ).not.toThrowError() + }) }) describe('with TypeScript', () => { diff --git a/packages/compiler-sfc/src/script/importUsageCheck.ts b/packages/compiler-sfc/src/script/importUsageCheck.ts index 59473a9dda3..b42397d573b 100644 --- a/packages/compiler-sfc/src/script/importUsageCheck.ts +++ b/packages/compiler-sfc/src/script/importUsageCheck.ts @@ -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) } }