|
|
@@ -560,15 +560,18 @@ describe('compiler: v-for', () => {
|
|
|
function assertSharedCodegen(
|
|
|
node: ForCodegenNode,
|
|
|
keyed: boolean = false,
|
|
|
- customReturn: boolean = false
|
|
|
+ customReturn: boolean = false,
|
|
|
+ disableTracking: boolean = true
|
|
|
) {
|
|
|
expect(node).toMatchObject({
|
|
|
type: NodeTypes.VNODE_CALL,
|
|
|
tag: FRAGMENT,
|
|
|
- isForBlock: true,
|
|
|
- patchFlag: keyed
|
|
|
- ? genFlagText(PatchFlags.KEYED_FRAGMENT)
|
|
|
- : genFlagText(PatchFlags.UNKEYED_FRAGMENT),
|
|
|
+ disableTracking,
|
|
|
+ patchFlag: !disableTracking
|
|
|
+ ? genFlagText(PatchFlags.STABLE_FRAGMENT)
|
|
|
+ : keyed
|
|
|
+ ? genFlagText(PatchFlags.KEYED_FRAGMENT)
|
|
|
+ : genFlagText(PatchFlags.UNKEYED_FRAGMENT),
|
|
|
children: {
|
|
|
type: NodeTypes.JS_CALL_EXPRESSION,
|
|
|
callee: RENDER_LIST,
|
|
|
@@ -580,7 +583,7 @@ describe('compiler: v-for', () => {
|
|
|
? {}
|
|
|
: {
|
|
|
type: NodeTypes.VNODE_CALL,
|
|
|
- isBlock: true
|
|
|
+ isBlock: disableTracking
|
|
|
}
|
|
|
}
|
|
|
]
|
|
|
@@ -658,6 +661,43 @@ describe('compiler: v-for', () => {
|
|
|
expect(generate(root).code).toMatchSnapshot()
|
|
|
})
|
|
|
|
|
|
+ test('v-for with constant expression', () => {
|
|
|
+ const {
|
|
|
+ root,
|
|
|
+ node: { codegenNode }
|
|
|
+ } = parseWithForTransform('<p v-for="item in 10">{{item}}</p>', {
|
|
|
+ prefixIdentifiers: true
|
|
|
+ })
|
|
|
+
|
|
|
+ expect(
|
|
|
+ assertSharedCodegen(
|
|
|
+ codegenNode,
|
|
|
+ false /* keyed */,
|
|
|
+ false /* customReturn */,
|
|
|
+ false /* disableTracking */
|
|
|
+ )
|
|
|
+ ).toMatchObject({
|
|
|
+ source: { content: `10`, isConstant: true },
|
|
|
+ params: [{ content: `item` }],
|
|
|
+ innerVNodeCall: {
|
|
|
+ tag: `"p"`,
|
|
|
+ props: undefined,
|
|
|
+ isBlock: false,
|
|
|
+ children: {
|
|
|
+ type: NodeTypes.INTERPOLATION,
|
|
|
+ content: {
|
|
|
+ type: NodeTypes.SIMPLE_EXPRESSION,
|
|
|
+ content: 'item',
|
|
|
+ isStatic: false,
|
|
|
+ isConstant: false
|
|
|
+ }
|
|
|
+ },
|
|
|
+ patchFlag: genFlagText(PatchFlags.TEXT)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ expect(generate(root).code).toMatchSnapshot()
|
|
|
+ })
|
|
|
+
|
|
|
test('template v-for', () => {
|
|
|
const {
|
|
|
root,
|
|
|
@@ -777,7 +817,7 @@ describe('compiler: v-for', () => {
|
|
|
key: `[0]`
|
|
|
}),
|
|
|
isBlock: true,
|
|
|
- isForBlock: true,
|
|
|
+ disableTracking: true,
|
|
|
patchFlag: genFlagText(PatchFlags.UNKEYED_FRAGMENT),
|
|
|
children: {
|
|
|
type: NodeTypes.JS_CALL_EXPRESSION,
|