diff --git a/packages/compiler-core/src/transforms/vFor.ts b/packages/compiler-core/src/transforms/vFor.ts index a44532c0d58..56144dcd284 100644 --- a/packages/compiler-core/src/transforms/vFor.ts +++ b/packages/compiler-core/src/transforms/vFor.ts @@ -37,7 +37,8 @@ import { isTemplateNode, isSlotOutlet, injectProp, - findDir + findDir, + forAliasRE } from '../utils' import { RENDER_LIST, @@ -308,7 +309,6 @@ export function processFor( } } -const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/ // This regex doesn't cover the case if key or index aliases have destructuring, // but those do not make sense in the first place, so this works in practice. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/ diff --git a/packages/compiler-core/src/utils.ts b/packages/compiler-core/src/utils.ts index bd2882b09e2..baffe5086f6 100644 --- a/packages/compiler-core/src/utils.ts +++ b/packages/compiler-core/src/utils.ts @@ -519,3 +519,5 @@ export function getMemoedVNodeCall(node: BlockCodegenNode | MemoExpression) { return node } } + +export const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/ diff --git a/packages/compiler-sfc/src/script/importUsageCheck.ts b/packages/compiler-sfc/src/script/importUsageCheck.ts index a7e2e6f3565..34e95f1918b 100644 --- a/packages/compiler-sfc/src/script/importUsageCheck.ts +++ b/packages/compiler-sfc/src/script/importUsageCheck.ts @@ -4,6 +4,7 @@ import { NodeTypes, SimpleExpressionNode, createRoot, + forAliasRE, parserOptions, transform, walkIdentifiers @@ -87,8 +88,6 @@ function resolveTemplateUsageCheckString(sfc: SFCDescriptor) { return code } -const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/ - function processExp(exp: string, dir?: string): string { if (/ as\s+\w|<.*>|:/.test(exp)) { if (dir === 'slot') {