Skip to content

Commit 4674ae6

Browse files
hchlqyyx990803
authored andcommitted
fix(compiler-core): missing source and have with multiple spaces should emit error during compiler
1 parent a3e8aaf commit 4674ae6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/compiler-core/__tests__/transforms/vFor.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,18 @@ describe('compiler: v-for', () => {
253253
)
254254
})
255255

256+
test('missing source and have multiple spaces with', () => {
257+
const onError = vi.fn()
258+
parseWithForTransform('<span v-for="item in " />', { onError })
259+
260+
expect(onError).toHaveBeenCalledTimes(1)
261+
expect(onError).toHaveBeenCalledWith(
262+
expect.objectContaining({
263+
code: ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION
264+
})
265+
)
266+
})
267+
256268
test('missing value', () => {
257269
const onError = vi.fn()
258270
parseWithForTransform('<span v-for="in items" />', { onError })

packages/compiler-core/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,4 +499,4 @@ export function getMemoedVNodeCall(node: BlockCodegenNode | MemoExpression) {
499499
}
500500
}
501501

502-
export const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/
502+
export const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/

0 commit comments

Comments
 (0)