feat(compiler): annotate patchFlags in generated code

This commit is contained in:
Evan You
2019-10-01 17:53:57 -04:00
parent 4021307f4c
commit 4fc963bc5a
7 changed files with 70 additions and 30 deletions

View File

@@ -16,7 +16,7 @@ import {
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,
@@ -99,7 +99,15 @@ export const transformElement: NodeTransform = (node, context) => {
}
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(`, `)}]`