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

fix(mp): id as props (#3722)

上级 78738bb2
......@@ -101,10 +101,10 @@ describe('compiler: transform component', () => {
})
test(`component with props`, () => {
assert(
`<uni-collapse id="id" ref="a" :ref="b" slot="c" :slot="d" class="e" :class="f" style="g:g;" :style="h" @click="i" v-model:first="j" v-model:last="k" prop-a="l" :prop-b="m" data-a="n" :data-b="o" key="p" :key="r" is="s" :is="t"/>`,
`<uni-collapse id="id" ref="a" ref="{{a}}" slot="c" slot="{{b}}" class="{{['e', c]}}" style="{{'g:g' + ';' + d}}" bindclick="{{e}}" data-a="n" data-b="{{f}}" key="p" key="{{g}}" is="s" is="{{h}}" u-i="2a9ec0b0-0" bindupdateFirst="{{i}}" bindupdateLast="{{j}}" u-p="{{k}}"/>`,
`<uni-collapse id="id" :id="id" ref="a" :ref="b" slot="c" :slot="d" class="e" :class="f" style="g:g;" :style="h" @click="i" v-model:first="j" v-model:last="k" prop-a="l" :prop-b="m" data-a="n" :data-b="o" key="p" :key="r" is="s" :is="t"/>`,
`<uni-collapse id="id" id="{{a}}" ref="a" ref="{{b}}" slot="c" slot="{{c}}" class="{{['e', d]}}" style="{{'g:g' + ';' + e}}" bindclick="{{f}}" data-a="n" data-b="{{g}}" key="p" key="{{h}}" is="s" is="{{i}}" u-i="2a9ec0b0-0" bindupdateFirst="{{j}}" bindupdateLast="{{k}}" u-p="{{l}}"/>`,
`(_ctx, _cache) => {
return { a: _ctx.b, b: _ctx.d, c: _n(_ctx.f), d: _s(_ctx.h), e: _o(_ctx.i), f: _ctx.o, g: _ctx.r, h: _ctx.t, i: _o($event => _ctx.j = $event), j: _o($event => _ctx.k = $event), k: _p({ ['prop-a']: 'l', ['prop-b']: _ctx.m, first: _ctx.j, last: _ctx.k }) }
return { a: _ctx.id, b: _ctx.b, c: _ctx.d, d: _n(_ctx.f), e: _s(_ctx.h), f: _o(_ctx.i), g: _ctx.o, h: _ctx.r, i: _ctx.t, j: _o($event => _ctx.j = $event), k: _o($event => _ctx.k = $event), l: _p({ id: 'id', id: _ctx.id, ['prop-a']: 'l', ['prop-b']: _ctx.m, first: _ctx.j, last: _ctx.k }) }
}`
)
assert(
......
......@@ -116,7 +116,7 @@ function processBooleanAttr({ props }: ComponentNode) {
}
const builtInProps = [
'id',
// 'id',
'class',
'style',
ATTR_VUE_ID,
......@@ -172,8 +172,10 @@ export function rewriteBinding(
const properties: (ObjectProperty | SpreadElement)[] = []
for (let i = 0; i < props.length; i++) {
const prop = props[i]
let isIdProp = false
if (isAttributeNode(prop)) {
const { name } = prop
isIdProp = name === 'id'
if (!isComponentProp(name)) {
continue
}
......@@ -194,6 +196,7 @@ export function rewriteBinding(
properties.push(spreadElement)
}
} else if (isStaticExp(arg)) {
isIdProp = arg.content === 'id'
if (!isComponentProp(arg.content)) {
continue
}
......@@ -222,8 +225,11 @@ export function rewriteBinding(
)
}
}
props.splice(i, 1)
i--
// 即保留 id 属性,又补充到 props 中
if (!isIdProp) {
props.splice(i, 1)
i--
}
}
if (properties.length) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册