Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement v-cloak transform #141

Merged
merged 8 commits into from
Oct 9, 2019
32 changes: 32 additions & 0 deletions packages/compiler-dom/__tests__/transforms/vCloak.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
parse,
transform,
CompilerOptions,
ElementNode
} from '@vue/compiler-core'
import { transformCloak } from '../../src/transforms/vCloak'
import { transformElement } from '../../../compiler-core/src/transforms/transformElement'
import { CallExpression } from '../../src'

function transformWithCloak(template: string, options: CompilerOptions = {}) {
const ast = parse(template)
transform(ast, {
nodeTransforms: [transformElement],
directiveTransforms: {
laquasicinque marked this conversation as resolved.
Show resolved Hide resolved
cloak: transformCloak
},
...options
})
return ast.children[0] as ElementNode
}

describe('compiler: `v-cloak` transform', () => {
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)
})
})
2 changes: 2 additions & 0 deletions packages/compiler-dom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { baseCompile, CompilerOptions, CodegenResult } from '@vue/compiler-core'
import { parserOptionsMinimal } from './parserOptionsMinimal'
import { parserOptionsStandard } from './parserOptionsStandard'
import { transformStyle } from './transforms/transformStyle'
import { transformCloak } from './transforms/vCloak'
import { transformVHtml } from './transforms/vHtml'

export function compile(
Expand All @@ -13,6 +14,7 @@ export function compile(
...(__BROWSER__ ? parserOptionsMinimal : parserOptionsStandard),
nodeTransforms: [transformStyle, ...(options.nodeTransforms || [])],
directiveTransforms: {
cloak: transformCloak,
html: transformVHtml,
...(options.directiveTransforms || {})
}
Expand Down
6 changes: 5 additions & 1 deletion packages/compiler-dom/src/transforms/vCloak.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
// TODO
import { DirectiveTransform } from 'packages/compiler-core/src/transform'

export const transformCloak: DirectiveTransform = (node, context) => {
return { props: [], needRuntime: false }
}