wip(ssr): v-bind basic usage
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import {
|
||||
baseParse as parse,
|
||||
transform,
|
||||
ElementNode,
|
||||
CallExpression,
|
||||
noopDirectiveTransform
|
||||
} from '../../src'
|
||||
import { transformElement } from '../../src/transforms/transformElement'
|
||||
|
||||
describe('compiler: noop directive transform', () => {
|
||||
test('should add no props to DOM', () => {
|
||||
const ast = parse(`<div v-noop/>`)
|
||||
transform(ast, {
|
||||
nodeTransforms: [transformElement],
|
||||
directiveTransforms: {
|
||||
noop: noopDirectiveTransform
|
||||
}
|
||||
})
|
||||
const node = ast.children[0] as ElementNode
|
||||
const codegenArgs = (node.codegenNode as CallExpression).arguments
|
||||
|
||||
// As v-noop 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)
|
||||
})
|
||||
})
|
||||
@@ -405,8 +405,7 @@ describe('compiler: element transform', () => {
|
||||
foo(dir) {
|
||||
_dir = dir
|
||||
return {
|
||||
props: [createObjectProperty(dir.arg!, dir.exp!)],
|
||||
needRuntime: false
|
||||
props: [createObjectProperty(dir.arg!, dir.exp!)]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ export {
|
||||
export * from './ast'
|
||||
export * from './utils'
|
||||
export { registerRuntimeHelpers } from './runtimeHelpers'
|
||||
export { noopDirectiveTransform } from './transforms/noopDirectiveTransform'
|
||||
|
||||
// expose transforms so higher-order compilers can import and extend them
|
||||
export { transformModel } from './transforms/vModel'
|
||||
|
||||
@@ -28,7 +28,8 @@ export interface ParserOptions {
|
||||
|
||||
export interface TransformOptions {
|
||||
nodeTransforms?: NodeTransform[]
|
||||
directiveTransforms?: { [name: string]: DirectiveTransform | undefined }
|
||||
directiveTransforms?: Record<string, DirectiveTransform | undefined>
|
||||
ssrDirectiveTransforms?: Record<string, DirectiveTransform | undefined>
|
||||
isBuiltInComponent?: (tag: string) => symbol | void
|
||||
// Transform expressions like {{ foo }} to `_ctx.foo`.
|
||||
// If this option is false, the generated code will be wrapped in a
|
||||
|
||||
@@ -61,7 +61,7 @@ export type DirectiveTransform = (
|
||||
|
||||
export interface DirectiveTransformResult {
|
||||
props: Property[]
|
||||
needRuntime: boolean | symbol
|
||||
needRuntime?: boolean | symbol
|
||||
}
|
||||
|
||||
// A structural directive transform is a technically a NodeTransform;
|
||||
@@ -114,6 +114,7 @@ function createTransformContext(
|
||||
cacheHandlers = false,
|
||||
nodeTransforms = [],
|
||||
directiveTransforms = {},
|
||||
ssrDirectiveTransforms = {},
|
||||
isBuiltInComponent = NOOP,
|
||||
ssr = false,
|
||||
onError = defaultOnError
|
||||
@@ -126,6 +127,7 @@ function createTransformContext(
|
||||
cacheHandlers,
|
||||
nodeTransforms,
|
||||
directiveTransforms,
|
||||
ssrDirectiveTransforms,
|
||||
isBuiltInComponent,
|
||||
ssr,
|
||||
onError,
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
import { DirectiveTransform } from '../transform'
|
||||
|
||||
export const noopDirectiveTransform: DirectiveTransform = () => ({ props: [] })
|
||||
@@ -30,7 +30,6 @@ export const transformBind: DirectiveTransform = (dir, node, context) => {
|
||||
return {
|
||||
props: [
|
||||
createObjectProperty(arg!, exp || createSimpleExpression('', true, loc))
|
||||
],
|
||||
needRuntime: false
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,5 +101,5 @@ export const transformModel: DirectiveTransform = (dir, node, context) => {
|
||||
}
|
||||
|
||||
function createTransformProps(props: Property[] = []) {
|
||||
return { props, needRuntime: false }
|
||||
return { props }
|
||||
}
|
||||
|
||||
@@ -99,8 +99,7 @@ export const transformOn: DirectiveTransform = (
|
||||
eventName,
|
||||
exp || createSimpleExpression(`() => {}`, false, loc)
|
||||
)
|
||||
],
|
||||
needRuntime: false
|
||||
]
|
||||
}
|
||||
|
||||
// apply extended compiler augmentor
|
||||
|
||||
Reference in New Issue
Block a user