Skip to content

Commit d5fd343

Browse files
authored
refactor(compiler-sfc): reuse forAliasRE regex from compiler-core (#9568)
1 parent ae6f164 commit d5fd343

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

packages/compiler-core/src/transforms/vFor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ import {
3737
isTemplateNode,
3838
isSlotOutlet,
3939
injectProp,
40-
findDir
40+
findDir,
41+
forAliasRE
4142
} from '../utils'
4243
import {
4344
RENDER_LIST,
@@ -308,7 +309,6 @@ export function processFor(
308309
}
309310
}
310311

311-
const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/
312312
// This regex doesn't cover the case if key or index aliases have destructuring,
313313
// but those do not make sense in the first place, so this works in practice.
314314
const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/

packages/compiler-core/src/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,3 +519,5 @@ export function getMemoedVNodeCall(node: BlockCodegenNode | MemoExpression) {
519519
return node
520520
}
521521
}
522+
523+
export const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/

packages/compiler-sfc/src/script/importUsageCheck.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
NodeTypes,
55
SimpleExpressionNode,
66
createRoot,
7+
forAliasRE,
78
parserOptions,
89
transform,
910
walkIdentifiers
@@ -87,8 +88,6 @@ function resolveTemplateUsageCheckString(sfc: SFCDescriptor) {
8788
return code
8889
}
8990

90-
const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/
91-
9291
function processExp(exp: string, dir?: string): string {
9392
if (/ as\s+\w|<.*>|:/.test(exp)) {
9493
if (dir === 'slot') {

0 commit comments

Comments
 (0)