提交 b1689b6c 编写于 作者: fxy060608's avatar fxy060608

wip(mp): boolean attribute

上级 4233d676
......@@ -88,4 +88,13 @@ describe('compiler: transform component', () => {
}
)
})
test(`component with boolean attribute`, () => {
assert(
`<uni-collapse accordion/>`,
`<uni-collapse accordion="{{true}}" v-i="2a9ec0b0-0"/>`,
`(_ctx, _cache) => {
return {}
}`
)
})
})
import { ComponentNode } from '@vue/compiler-core'
import { ComponentNode, NodeTypes } from '@vue/compiler-core'
import {
createAttributeNode,
createBindDirectiveNode,
......@@ -12,6 +12,7 @@ export const transformComponent: NodeTransform = (node, context) => {
return
}
addVueId(node, context)
processBooleanAttr(node)
return function postTransformComponent() {
context.vueIds.pop()
}
......@@ -54,3 +55,18 @@ function addVueId(node: ComponentNode, context: TransformContext) {
}
return node.props.push(createAttributeNode(ATTR_VUE_ID, value))
}
/**
* <uni-collapse accordion/> => <uni-collapse :accordion="true"/>
* 否则部分平台(快手)可能获取到的 accordion 是空字符串
* @param param0
*/
function processBooleanAttr({ props }: ComponentNode) {
props.forEach((prop, index) => {
if (
prop.type === NodeTypes.ATTRIBUTE &&
typeof prop.value === 'undefined'
) {
props.splice(index, 1, createBindDirectiveNode(prop.name, 'true'))
}
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册