Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yiicenne
uni-app
提交
f46520cf
U
uni-app
项目概览
yiicenne
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
f46520cf
编写于
3月 14, 2023
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mp-baidu, mp-alipay): scoped slot root element use block
上级
344e1ccd
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
20 addition
and
20 deletion
+20
-20
packages/uni-mp-alipay/lib/uni.compiler.js
packages/uni-mp-alipay/lib/uni.compiler.js
+1
-1
packages/uni-mp-baidu/lib/uni.compiler.js
packages/uni-mp-baidu/lib/uni.compiler.js
+1
-1
packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js
...ni-template-compiler/__tests__/compiler-mp-alipay.spec.js
+6
-6
packages/uni-template-compiler/__tests__/compiler-mp-baidu.spec.js
...uni-template-compiler/__tests__/compiler-mp-baidu.spec.js
+10
-10
packages/uni-template-compiler/lib/template/generate.js
packages/uni-template-compiler/lib/template/generate.js
+2
-2
未找到文件。
packages/uni-mp-alipay/lib/uni.compiler.js
浏览文件 @
f46520cf
...
...
@@ -92,7 +92,7 @@ module.exports = {
normalizeChildren
},
state
)
{
const
node
=
{
type
:
'
view
'
,
type
:
'
block
'
,
attr
:
{
slot
:
slotName
}
...
...
packages/uni-mp-baidu/lib/uni.compiler.js
浏览文件 @
f46520cf
...
...
@@ -24,7 +24,7 @@ module.exports = {
normalizeChildren
},
state
)
{
const
node
=
{
type
:
'
view
'
,
type
:
'
block
'
,
attr
:
{
slot
:
slotName
},
...
...
packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js
浏览文件 @
f46520cf
...
...
@@ -90,18 +90,18 @@ describe('mp:compiler-mp-alipay', () => {
)
assertCodegen
(
'
<component1>text<block slot="right"></block></component1>
'
,
'
<component1 vue-id="551070e6-1" onVueInit="__l" vue-slots="{{[
\'
default
\'
,
\'
right
\'
]}}">text<
view slot="right"></view
></component1>
'
'
<component1 vue-id="551070e6-1" onVueInit="__l" vue-slots="{{[
\'
default
\'
,
\'
right
\'
]}}">text<
block slot="right"></block
></component1>
'
)
})
it
(
'
generate scoped slot
'
,
()
=>
{
assertCodegen
(
'
<component1 :text="
\'
text
\'
"><template v-slot="props"><view :class="{text:props.text}">{{props.text}}</view></template></component1>
'
,
'
<component1 vue-id="551070e6-1" text="text" onVueInit="__l" vue-slots="{{[
\'
default
\'
]}}"><
view slot-scope="props"><view class="{{((props.text)?
\'
text
\'
:
\'\'
)}}">{{props.text}}</view></view
></component1>
'
'
<component1 vue-id="551070e6-1" text="text" onVueInit="__l" vue-slots="{{[
\'
default
\'
]}}"><
block slot-scope="props"><view class="{{((props.text)?
\'
text
\'
:
\'\'
)}}">{{props.text}}</view></block
></component1>
'
)
assertCodegen
(
'
<component1 :text="
\'
text
\'
"><template v-slot="{text}"><view :class="{text:text}">{{text}}</view></template></component1>
'
,
'
<component1 vue-id="551070e6-1" text="text" onVueInit="__l" vue-slots="{{[
\'
default
\'
]}}"><
view slot-scope="__SCOPED__"><view class="{{((__SCOPED__.text)?
\'
text
\'
:
\'\'
)}}">{{__SCOPED__.text}}</view></view
></component1>
'
'
<component1 vue-id="551070e6-1" text="text" onVueInit="__l" vue-slots="{{[
\'
default
\'
]}}"><
block slot-scope="__SCOPED__"><view class="{{((__SCOPED__.text)?
\'
text
\'
:
\'\'
)}}">{{__SCOPED__.text}}</view></block
></component1>
'
)
})
...
...
@@ -119,7 +119,7 @@ describe('mp:compiler-mp-alipay', () => {
it
(
'
generate scoped slot with scopedSlotsCompiler: auto
'
,
()
=>
{
assertCodegen
(
'
<my-component><template v-slot="{item}">{{item}}<template></my-component>
'
,
'
<my-component vue-id="551070e6-1" onVueInit="__l" vue-slots="{{[
\'
default
\'
]}}"><
view slot-scope="__SCOPED__">{{__SCOPED__.item}}</view
></my-component>
'
,
'
<my-component vue-id="551070e6-1" onVueInit="__l" vue-slots="{{[
\'
default
\'
]}}"><
block slot-scope="__SCOPED__">{{__SCOPED__.item}}</block
></my-component>
'
,
'
with(this){}
'
,
{
scopedSlotsCompiler
:
'
auto
'
...
...
@@ -135,7 +135,7 @@ describe('mp:compiler-mp-alipay', () => {
)
assertCodegen
(
'
<my-component><template v-slot="{item}">{{item}}{{title}}<template></my-component>
'
,
'
<my-component vue-id="551070e6-1" onVueInit="__l" vue-slots="{{[
\'
default
\'
]}}"><
view slot-scope="__SCOPED__">{{__SCOPED__.item+title}}</view
></my-component>
'
,
'
<my-component vue-id="551070e6-1" onVueInit="__l" vue-slots="{{[
\'
default
\'
]}}"><
block slot-scope="__SCOPED__">{{__SCOPED__.item+title}}</block
></my-component>
'
,
'
with(this){}
'
,
{
scopedSlotsCompiler
:
'
auto
'
...
...
@@ -143,7 +143,7 @@ describe('mp:compiler-mp-alipay', () => {
)
assertCodegen
(
'
<my-component><template v-slot="{item}">{{item}}{{getValue(title)}}<template></my-component>
'
,
'
<my-component vue-id="551070e6-1" onVueInit="__l" vue-slots="{{[
\'
default
\'
]}}"><
view slot-scope="__SCOPED__">{{__SCOPED__.item+$root.m0}}</view
></my-component>
'
,
'
<my-component vue-id="551070e6-1" onVueInit="__l" vue-slots="{{[
\'
default
\'
]}}"><
block slot-scope="__SCOPED__">{{__SCOPED__.item+$root.m0}}</block
></my-component>
'
,
'
with(this){var m0=getValue(title);$mp.data=Object.assign({},{$root:{m0:m0}})}
'
,
{
scopedSlotsCompiler
:
'
auto
'
...
...
packages/uni-template-compiler/__tests__/compiler-mp-baidu.spec.js
浏览文件 @
f46520cf
...
...
@@ -36,33 +36,33 @@ describe('mp:compiler-mp-baidu', () => {
it
(
'
generate scoped slot
'
,
()
=>
{
assertCodegen
(
'
<foo><template slot-scope="bar">{{ bar.foo }}</template></foo>
'
,
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
default
\'
]}}"><
view>{{foo}}</view
></foo>
'
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
default
\'
]}}"><
block>{{foo}}</block
></foo>
'
)
assertCodegen
(
'
<foo><view slot-scope="bar">{{ bar.foo }}</view></foo>
'
,
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
default
\'
]}}"><
view><view>{{foo}}</view></view
></foo>
'
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
default
\'
]}}"><
block><view>{{foo}}</view></block
></foo>
'
)
})
it
(
'
generate named scoped slot
'
,
()
=>
{
assertCodegen
(
'
<foo><template slot="foo" slot-scope="bar">{{ bar.foo }}</template></foo>
'
,
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
foo
\'
]}}"><
view slot="foo">{{foo}}</view
></foo>
'
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
foo
\'
]}}"><
block slot="foo">{{foo}}</block
></foo>
'
)
assertCodegen
(
'
<foo><view slot="foo" slot-scope="bar">{{ bar.foo }}</view></foo>
'
,
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
foo
\'
]}}"><
view slot="foo"><view>{{foo}}</view></view
></foo>
'
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
foo
\'
]}}"><
block slot="foo"><view>{{foo}}</view></block
></foo>
'
)
})
it
(
'
generate scoped slot with multiline v-if
'
,
()
=>
{
assertCodegen
(
'
<foo><template v-if="
\n
show
\n
" slot-scope="bar">{{ bar.foo }}</template></foo>
'
,
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
default
\'
]}}"><
view><block s-if="{{show}}">{{foo}}</block><block s-else><block></block></block></view
></foo>
'
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
default
\'
]}}"><
block><block s-if="{{show}}">{{foo}}</block><block s-else><block></block></block></block
></foo>
'
)
assertCodegen
(
'
<foo><view v-if="
\n
show
\n
" slot="foo" slot-scope="bar">{{ bar.foo }}</view></foo>
'
,
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
foo
\'
]}}"><
view slot="foo"><block s-if="{{show}}"><view>{{foo}}</view></block></view
></foo>
'
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
foo
\'
]}}"><
block slot="foo"><block s-if="{{show}}"><view>{{foo}}</view></block></block
></foo>
'
)
})
...
...
@@ -88,14 +88,14 @@ describe('mp:compiler-mp-baidu', () => {
)
assertCodegen
(
'
<foo><template v-slot:[test]="{user}"><view>{{user}}</view></template></foo>
'
,
'
<foo vue-id="551070e6-1" vue-slots="{{[test]}}"><
view slot="{{test}}"><view>{{user}}</view></view
></foo>
'
'
<foo vue-id="551070e6-1" vue-slots="{{[test]}}"><
block slot="{{test}}"><view>{{user}}</view></block
></foo>
'
)
})
it
(
'
generate scoped slot with scopedSlotsCompiler: auto
'
,
()
=>
{
assertCodegen
(
'
<my-component><template v-slot="{item}">{{item}}<template></my-component>
'
,
'
<my-component vue-id="551070e6-1" vue-slots="{{[
\'
default
\'
]}}"><
view>{{item}}</view
></my-component>
'
,
'
<my-component vue-id="551070e6-1" vue-slots="{{[
\'
default
\'
]}}"><
block>{{item}}</block
></my-component>
'
,
'
with(this){}
'
,
{
scopedSlotsCompiler
:
'
auto
'
...
...
@@ -111,7 +111,7 @@ describe('mp:compiler-mp-baidu', () => {
)
assertCodegen
(
'
<my-component><template v-slot="{item}">{{item}}{{title}}<template></my-component>
'
,
'
<my-component vue-id="551070e6-1" vue-slots="{{[
\'
default
\'
]}}"><
view>{{item+title}}</view
></my-component>
'
,
'
<my-component vue-id="551070e6-1" vue-slots="{{[
\'
default
\'
]}}"><
block>{{item+title}}</block
></my-component>
'
,
'
with(this){}
'
,
{
scopedSlotsCompiler
:
'
auto
'
...
...
@@ -119,7 +119,7 @@ describe('mp:compiler-mp-baidu', () => {
)
assertCodegen
(
'
<my-component><template v-slot="{item}">{{item}}{{getValue(title)}}<template></my-component>
'
,
'
<my-component vue-id="551070e6-1" vue-slots="{{[
\'
default
\'
]}}"><
view>{{item+$root.m0}}</view
></my-component>
'
,
'
<my-component vue-id="551070e6-1" vue-slots="{{[
\'
default
\'
]}}"><
block>{{item+$root.m0}}</block
></my-component>
'
,
'
with(this){var m0=getValue(title);$mp.data=Object.assign({},{$root:{m0:m0}})}
'
,
{
scopedSlotsCompiler
:
'
auto
'
...
...
packages/uni-template-compiler/lib/template/generate.js
浏览文件 @
f46520cf
...
...
@@ -73,14 +73,14 @@ function processElement (ast, state, isRoot) {
for
(
let
i
=
children
.
length
-
1
;
i
>=
0
;
i
--
)
{
const
childElement
=
children
[
i
]
/**
*
仅百度、字节支持使用 block 作为命名插槽根节点
*
百度、字节、支付宝小程序支持使用 block 作为命名插槽根节点,支付宝不支持在 block 使用动态插槽名
* <block slot="left"></block> => <view slot="left"></view>
*/
const
attr
=
typeof
childElement
!==
'
string
'
&&
childElement
.
attr
const
slot
=
attr
&&
(
attr
[
ATTR_SLOT_ORIGIN
]
||
attr
.
slot
)
if
(
slot
)
{
delete
attr
[
ATTR_SLOT_ORIGIN
]
if
(
!
[
'
mp-baidu
'
,
'
mp-toutiao
'
].
includes
(
platformName
)
&&
attr
.
slot
&&
attr
.
slot
!==
'
default
'
&&
childElement
.
type
===
'
block
'
)
{
if
(
!
[
'
mp-baidu
'
,
'
mp-toutiao
'
].
includes
(
platformName
)
&&
!
(
platformName
===
'
mp-alipay
'
&&
!
/
\{\{
.+
?\}\}
/
.
test
(
attr
.
slot
))
&&
attr
.
slot
&&
attr
.
slot
!==
'
default
'
&&
childElement
.
type
===
'
block
'
)
{
childElement
.
type
=
'
view
'
}
if
(
!
slots
.
includes
(
slot
))
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录