2019-10-09 22:41:31 +08:00
|
|
|
import {
|
|
|
|
parse,
|
|
|
|
transform,
|
2019-10-10 05:32:58 +08:00
|
|
|
ElementNode,
|
|
|
|
CallExpression
|
2019-10-09 22:41:31 +08:00
|
|
|
} from '@vue/compiler-core'
|
|
|
|
import { transformCloak } from '../../src/transforms/vCloak'
|
|
|
|
import { transformElement } from '../../../compiler-core/src/transforms/transformElement'
|
|
|
|
|
2019-10-10 05:32:58 +08:00
|
|
|
function transformWithCloak(template: string) {
|
2019-10-09 22:41:31 +08:00
|
|
|
const ast = parse(template)
|
|
|
|
transform(ast, {
|
|
|
|
nodeTransforms: [transformElement],
|
|
|
|
directiveTransforms: {
|
|
|
|
cloak: transformCloak
|
2019-10-10 05:32:58 +08:00
|
|
|
}
|
2019-10-09 22:41:31 +08:00
|
|
|
})
|
|
|
|
return ast.children[0] as ElementNode
|
|
|
|
}
|
|
|
|
|
2019-10-10 05:32:58 +08:00
|
|
|
describe('compiler: v-cloak transform', () => {
|
2019-10-09 22:41:31 +08:00
|
|
|
test('should add no props to DOM', () => {
|
|
|
|
const node = transformWithCloak(`<div v-cloak/>`)
|
|
|
|
const codegenArgs = (node.codegenNode as CallExpression).arguments
|
|
|
|
|
|
|
|
// As v-cloak adds no properties the codegen should be identical to
|
|
|
|
// rendering a div with no props or reactive data (so just the tag as the arg)
|
|
|
|
expect(codegenArgs.length).toBe(1)
|
|
|
|
})
|
|
|
|
})
|