|
|
@@ -283,6 +283,45 @@ describe('parser', () => {
|
|
|
expect(liAst.key).toBe('item.uid')
|
|
|
})
|
|
|
|
|
|
+ it('v-for directive destructuring', () => {
|
|
|
+ let ast = parse('<ul><li v-for="{ foo } in items"></li></ul>', baseOptions)
|
|
|
+ let liAst = ast.children[0]
|
|
|
+ expect(liAst.for).toBe('items')
|
|
|
+ expect(liAst.alias).toBe('{ foo }')
|
|
|
+
|
|
|
+ // with paren
|
|
|
+ ast = parse('<ul><li v-for="({ foo }) in items"></li></ul>', baseOptions)
|
|
|
+ liAst = ast.children[0]
|
|
|
+ expect(liAst.for).toBe('items')
|
|
|
+ expect(liAst.alias).toBe('{ foo }')
|
|
|
+
|
|
|
+ // multi-var destructuring
|
|
|
+ ast = parse('<ul><li v-for="{ foo, bar, baz } in items"></li></ul>', baseOptions)
|
|
|
+ liAst = ast.children[0]
|
|
|
+ expect(liAst.for).toBe('items')
|
|
|
+ expect(liAst.alias).toBe('{ foo, bar, baz }')
|
|
|
+
|
|
|
+ // multi-var destructuring with paren
|
|
|
+ ast = parse('<ul><li v-for="({ foo, bar, baz }) in items"></li></ul>', baseOptions)
|
|
|
+ liAst = ast.children[0]
|
|
|
+ expect(liAst.for).toBe('items')
|
|
|
+ expect(liAst.alias).toBe('{ foo, bar, baz }')
|
|
|
+
|
|
|
+ // with index
|
|
|
+ ast = parse('<ul><li v-for="({ foo }, i) in items"></li></ul>', baseOptions)
|
|
|
+ liAst = ast.children[0]
|
|
|
+ expect(liAst.for).toBe('items')
|
|
|
+ expect(liAst.alias).toBe('{ foo }')
|
|
|
+ expect(liAst.iterator1).toBe('i')
|
|
|
+
|
|
|
+ // multi-var destructuring with index
|
|
|
+ ast = parse('<ul><li v-for="({ foo, bar, baz }, i) in items"></li></ul>', baseOptions)
|
|
|
+ liAst = ast.children[0]
|
|
|
+ expect(liAst.for).toBe('items')
|
|
|
+ expect(liAst.alias).toBe('{ foo, bar, baz }')
|
|
|
+ expect(liAst.iterator1).toBe('i')
|
|
|
+ })
|
|
|
+
|
|
|
it('v-for directive invalid syntax', () => {
|
|
|
parse('<ul><li v-for="item into items"></li></ul>', baseOptions)
|
|
|
expect('Invalid v-for expression').toHaveBeenWarned()
|