wip(ssr): v-bind basic usage

This commit is contained in:
Evan You
2020-02-04 12:20:51 -05:00
parent 7f38c1e0ff
commit 6a5ed49ea9
25 changed files with 173 additions and 75 deletions

View File

@@ -1,30 +0,0 @@
import {
baseParse as parse,
transform,
ElementNode,
CallExpression
} from '@vue/compiler-core'
import { transformCloak } from '../../src/transforms/vCloak'
import { transformElement } from '../../../compiler-core/src/transforms/transformElement'
function transformWithCloak(template: string) {
const ast = parse(template)
transform(ast, {
nodeTransforms: [transformElement],
directiveTransforms: {
cloak: transformCloak
}
})
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)
})
})

View File

@@ -28,7 +28,8 @@ export const enum DOMErrorCodes {
X_V_MODEL_ON_INVALID_ELEMENT,
X_V_MODEL_ARG_ON_ELEMENT,
X_V_MODEL_ON_FILE_INPUT_ELEMENT,
X_V_SHOW_NO_EXPRESSION
X_V_SHOW_NO_EXPRESSION,
__EXTEND_POINT__
}
export const DOMErrorMessages: { [code: number]: string } = {

View File

@@ -5,12 +5,12 @@ import {
CodegenResult,
isBuiltInType,
ParserOptions,
RootNode
RootNode,
noopDirectiveTransform
} 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'
import { transformVText } from './transforms/vText'
import { transformModel } from './transforms/vModel'
@@ -31,7 +31,7 @@ export function compile(
...options,
nodeTransforms: [transformStyle, ...(options.nodeTransforms || [])],
directiveTransforms: {
cloak: transformCloak,
cloak: noopDirectiveTransform,
html: transformVHtml,
text: transformVText,
model: transformModel, // override compiler-core
@@ -56,4 +56,5 @@ export function parse(template: string, options: ParserOptions = {}): RootNode {
})
}
export { DOMErrorCodes } from './errors'
export * from '@vue/compiler-core'

View File

@@ -1,5 +0,0 @@
import { DirectiveTransform } from '@vue/compiler-core'
export const transformCloak: DirectiveTransform = () => {
return { props: [], needRuntime: false }
}

View File

@@ -24,7 +24,6 @@ export const transformVHtml: DirectiveTransform = (dir, node, context) => {
createSimpleExpression(`innerHTML`, true, loc),
exp || createSimpleExpression('', true)
)
],
needRuntime: false
]
}
}

View File

@@ -102,8 +102,7 @@ export const transformOn: DirectiveTransform = (dir, node, context) => {
}
return {
props: [createObjectProperty(key, handlerExp)],
needRuntime: false
props: [createObjectProperty(key, handlerExp)]
}
})
}

View File

@@ -24,7 +24,6 @@ export const transformVText: DirectiveTransform = (dir, node, context) => {
createSimpleExpression(`textContent`, true, loc),
exp || createSimpleExpression('', true)
)
],
needRuntime: false
]
}
}