_createVNode(\\"span\\", null, _toString(value + index))
])
})))
- ], 2)
+ ], 2 /* CLASS */)
}
}"
`;
createVNode(\\"span\\", null, toString(value + index))
])
})))
- ], 2)
+ ], 2 /* CLASS */)
}"
`;
createVNode(\\"span\\", null, _toString(value + index))
])
})))
- ], 2)
+ ], 2 /* CLASS */)
}"
`;
toString(_ctx.foo),
toString(bar)
]
- }, 256)
+ }, 256 /* DYNAMIC_SLOTS */)
}"
`;
]
},
`null`,
- String(PatchFlags.NEED_PATCH) // should generate appropriate flag
+ `${PatchFlags.NEED_PATCH} /* NEED_PATCH */` // should generate appropriate flag
]
},
{
test('CLASS', () => {
const { node } = parseWithBind(`<div :class="foo" />`)
expect(node.arguments.length).toBe(4)
- expect(node.arguments[3]).toBe(String(PatchFlags.CLASS))
+ expect(node.arguments[3]).toBe(`${PatchFlags.CLASS} /* CLASS */`)
})
test('STYLE', () => {
const { node } = parseWithBind(`<div :style="foo" />`)
expect(node.arguments.length).toBe(4)
- expect(node.arguments[3]).toBe(String(PatchFlags.STYLE))
+ expect(node.arguments[3]).toBe(`${PatchFlags.STYLE} /* STYLE */`)
})
test('PROPS', () => {
const { node } = parseWithBind(`<div id="foo" :foo="bar" :baz="qux" />`)
expect(node.arguments.length).toBe(5)
- expect(node.arguments[3]).toBe(String(PatchFlags.PROPS))
+ expect(node.arguments[3]).toBe(`${PatchFlags.PROPS} /* PROPS */`)
expect(node.arguments[4]).toBe(`["foo", "baz"]`)
})
)
expect(node.arguments.length).toBe(5)
expect(node.arguments[3]).toBe(
- String(PatchFlags.PROPS | PatchFlags.CLASS | PatchFlags.STYLE)
+ `${PatchFlags.PROPS |
+ PatchFlags.CLASS |
+ PatchFlags.STYLE} /* CLASS, STYLE, PROPS */`
)
expect(node.arguments[4]).toBe(`["foo", "baz"]`)
})
test('FULL_PROPS (v-bind)', () => {
const { node } = parseWithBind(`<div v-bind="foo" />`)
expect(node.arguments.length).toBe(4)
- expect(node.arguments[3]).toBe(String(PatchFlags.FULL_PROPS))
+ expect(node.arguments[3]).toBe(
+ `${PatchFlags.FULL_PROPS} /* FULL_PROPS */`
+ )
})
test('FULL_PROPS (dynamic key)', () => {
const { node } = parseWithBind(`<div :[foo]="bar" />`)
expect(node.arguments.length).toBe(4)
- expect(node.arguments[3]).toBe(String(PatchFlags.FULL_PROPS))
+ expect(node.arguments[3]).toBe(
+ `${PatchFlags.FULL_PROPS} /* FULL_PROPS */`
+ )
})
test('FULL_PROPS (w/ others)', () => {
`<div id="foo" v-bind="bar" :class="cls" />`
)
expect(node.arguments.length).toBe(4)
- expect(node.arguments[3]).toBe(String(PatchFlags.FULL_PROPS))
+ expect(node.arguments[3]).toBe(
+ `${PatchFlags.FULL_PROPS} /* FULL_PROPS */`
+ )
})
test('NEED_PATCH (static ref)', () => {
const { node } = parseWithBind(`<div ref="foo" />`)
expect(node.arguments.length).toBe(4)
- expect(node.arguments[3]).toBe(String(PatchFlags.NEED_PATCH))
+ expect(node.arguments[3]).toBe(
+ `${PatchFlags.NEED_PATCH} /* NEED_PATCH */`
+ )
})
test('NEED_PATCH (dynamic ref)', () => {
const { node } = parseWithBind(`<div :ref="foo" />`)
expect(node.arguments.length).toBe(4)
- expect(node.arguments[3]).toBe(String(PatchFlags.NEED_PATCH))
+ expect(node.arguments[3]).toBe(
+ `${PatchFlags.NEED_PATCH} /* NEED_PATCH */`
+ )
})
test('NEED_PATCH (custom directives)', () => {
const { node } = parseWithBind(`<div v-foo />`)
const vnodeCall = node.arguments[0] as CallExpression
expect(vnodeCall.arguments.length).toBe(4)
- expect(vnodeCall.arguments[3]).toBe(String(PatchFlags.NEED_PATCH))
+ expect(vnodeCall.arguments[3]).toBe(
+ `${PatchFlags.NEED_PATCH} /* NEED_PATCH */`
+ )
})
})
})
Property,
SourceLocation
} from '../ast'
-import { isArray, PatchFlags } from '@vue/shared'
+import { isArray, PatchFlags, PatchFlagNames } from '@vue/shared'
import { createCompilerError, ErrorCodes } from '../errors'
import {
CREATE_VNODE,
}
args.push(`null`)
}
- args.push(String(patchFlag))
+ if (__DEV__) {
+ const flagNames = Object.keys(PatchFlagNames)
+ .filter(n => patchFlag & Number(n))
+ .map(n => PatchFlagNames[n as any])
+ .join(`, `)
+ args.push(patchFlag + ` /* ${flagNames} */`)
+ } else {
+ args.push(patchFlag + '')
+ }
if (dynamicPropNames && dynamicPropNames.length) {
args.push(
`[${dynamicPropNames.map(n => JSON.stringify(n)).join(`, `)}]`
it('patch fragment children (compiler generated, unkeyed)', () => {
const root = nodeOps.createElement('div')
render(
- createVNode(Fragment, null, [h('div', 'one'), 'two'], PatchFlags.UNKEYED),
+ createVNode(
+ Fragment,
+ null,
+ [h('div', 'one'), 'two'],
+ PatchFlags.UNKEYED_V_FOR
+ ),
root
)
expect(serializeInner(root)).toBe(`<!----><div>one</div>two<!---->`)
Fragment,
null,
[h('div', 'foo'), 'bar', 'baz'],
- PatchFlags.UNKEYED
+ PatchFlags.UNKEYED_V_FOR
),
root
)
Fragment,
null,
[h('div', { key: 1 }, 'one'), h('div', { key: 2 }, 'two')],
- PatchFlags.KEYED
+ PatchFlags.KEYED_V_FOR
),
root
)
Fragment,
null,
[h('div', { key: 2 }, 'two'), h('div', { key: 1 }, 'one')],
- PatchFlags.KEYED
+ PatchFlags.KEYED_V_FOR
),
root
)
// fast path
const { patchFlag, shapeFlag } = n2
if (patchFlag) {
- if (patchFlag & PatchFlags.KEYED) {
+ if (patchFlag & PatchFlags.KEYED_V_FOR) {
// this could be either fully-keyed or mixed (some keyed some not)
// presence of patchFlag means children are guaranteed to be arrays
patchKeyedChildren(
optimized
)
return
- } else if (patchFlag & PatchFlags.UNKEYED) {
+ } else if (patchFlag & PatchFlags.UNKEYED_V_FOR) {
// unkeyed
patchUnkeyedChildren(
c1 as HostVNode[],
// value.
NEED_PATCH = 1 << 5,
- // Indicates a fragment or element with keyed or partially-keyed v-for
- // children
- KEYED = 1 << 6,
+ // Indicates a v-for fragment with keyed or partially keyed children
+ KEYED_V_FOR = 1 << 6,
- // Indicates a fragment or element that contains unkeyed v-for children
- UNKEYED = 1 << 7,
+ // Indicates a v-for fragment with unkeyed children.
+ UNKEYED_V_FOR = 1 << 7,
// Indicates a component with dynamic slots (e.g. slot that references a v-for
// iterated value, or dynamic slot names).
PROPS: PatchFlags.PROPS,
NEED_PATCH: PatchFlags.NEED_PATCH,
FULL_PROPS: PatchFlags.FULL_PROPS,
- KEYED: PatchFlags.KEYED,
- UNKEYED: PatchFlags.UNKEYED
+ KEYED_V_FOR: PatchFlags.KEYED_V_FOR,
+ UNKEYED_V_FOR: PatchFlags.UNKEYED_V_FOR,
+ DYNAMIC_SLOTS: PatchFlags.DYNAMIC_SLOTS
+}
+
+// dev only flag -> name mapping
+export const PatchFlagNames = {
+ [PatchFlags.TEXT]: `TEXT`,
+ [PatchFlags.CLASS]: `CLASS`,
+ [PatchFlags.STYLE]: `STYLE`,
+ [PatchFlags.PROPS]: `PROPS`,
+ [PatchFlags.NEED_PATCH]: `NEED_PATCH`,
+ [PatchFlags.FULL_PROPS]: `FULL_PROPS`,
+ [PatchFlags.KEYED_V_FOR]: `KEYED_V_FOR`,
+ [PatchFlags.UNKEYED_V_FOR]: `UNKEYED_V_FOR`,
+ [PatchFlags.DYNAMIC_SLOTS]: `DYNAMIC_SLOTS`
}