提交 a1c85c4a 编写于 作者: Y yurj26

feat(uts): v-text

上级 43a38070
import { assert } from '../testUtils'
describe('compiler:v-text', () => {
test('template v-text', () => {
assert(
`<text v-text="a"/>`,
`createElementVNode("text", new Map<string,any>([
["value", toDisplayString(_ctx.a)]
]), null, 8 /* PROPS */, ["value"])`
)
})
})
......@@ -18,6 +18,7 @@ import { transformIf } from './transforms/vIf'
import { transformFor } from './transforms/vFor'
import { transformModel } from './transforms/vModel'
import { transformShow } from './transforms/vShow'
import { transformVText } from './transforms/vText'
import { transformText } from './transforms/transformText'
export type TransformPreset = [
......@@ -44,6 +45,7 @@ export function getBaseTransformPreset(
bind: transformBind,
model: transformModel,
show: transformShow,
text: transformVText,
} as any,
]
}
......
import {
DirectiveTransform,
createObjectProperty,
createSimpleExpression,
TO_DISPLAY_STRING,
createCallExpression,
getConstantType,
} from '@vue/compiler-core'
// import { createDOMCompilerError, DOMErrorCodes } from '../errors'
export const transformVText: DirectiveTransform = (dir, node, context) => {
const { exp, loc } = dir
// if (!exp) {
// context.onError(
// createDOMCompilerError(DOMErrorCodes.X_V_TEXT_NO_EXPRESSION, loc)
// )
// }
// if (node.children.length) {
// context.onError(
// createDOMCompilerError(DOMErrorCodes.X_V_TEXT_WITH_CHILDREN, loc)
// )
// node.children.length = 0
// }
return {
props: [
createObjectProperty(
createSimpleExpression(`value`, true),
exp
? getConstantType(exp, context) > 0
? exp
: createCallExpression(
context.helperString(TO_DISPLAY_STRING),
[exp],
loc
)
: createSimpleExpression('', true)
),
],
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册