Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wychl
uni-app
提交
bcecd71b
U
uni-app
项目概览
wychl
/
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,发现更多精彩内容 >>
提交
bcecd71b
编写于
7月 17, 2020
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: 解决小程序上具名插槽default和默认插槽不等同的问题
上级
6f321a1a
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
70 addition
and
58 deletion
+70
-58
packages/uni-template-compiler/__tests__/compiler-extra.spec.js
...es/uni-template-compiler/__tests__/compiler-extra.spec.js
+3
-3
packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js
...ni-template-compiler/__tests__/compiler-mp-alipay.spec.js
+2
-2
packages/uni-template-compiler/__tests__/compiler-mp-baidu.spec.js
...uni-template-compiler/__tests__/compiler-mp-baidu.spec.js
+49
-49
packages/uni-template-compiler/__tests__/compiler.spec.js
packages/uni-template-compiler/__tests__/compiler.spec.js
+8
-3
packages/uni-template-compiler/lib/template/generate.js
packages/uni-template-compiler/lib/template/generate.js
+8
-1
未找到文件。
packages/uni-template-compiler/__tests__/compiler-extra.spec.js
浏览文件 @
bcecd71b
...
...
@@ -226,12 +226,12 @@ describe('mp:compiler-extra', () => {
assertCodegen
(
'
<component1 v-slot>text</component1>
'
,
'
<component1 vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[
\'
default
\'
]}}"><view
slot="default"
>text</view></component1>
'
'
<component1 vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[
\'
default
\'
]}}"><view>text</view></component1>
'
)
assertCodegen
(
'
<component1 v-slot:default>text<text>123213</text></component1>
'
,
'
<component1 vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[
\'
default
\'
]}}"><view
slot="default"
>text<text>123213</text></view></component1>
'
'
<component1 vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[
\'
default
\'
]}}"><view>text<text>123213</text></view></component1>
'
)
assertCodegen
(
'
<component1><template v-slot:left><text></text></template><template v-slot:right><text></text></template></component1>
'
,
...
...
packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js
浏览文件 @
bcecd71b
...
...
@@ -64,11 +64,11 @@ describe('mp:compiler-mp-alipay', () => {
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"><view slot
="default" slot
-scope="props"><view class="{{((props.text)?
\'
text
\'
:
\'\'
)}}">{{props.text}}</view></view></component1>
'
'
<component1 vue-id="551070e6-1" text="text" onVueInit="__l"><view slot-scope="props"><view class="{{((props.text)?
\'
text
\'
:
\'\'
)}}">{{props.text}}</view></view></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"><view slot
="default" slot
-scope="__SCOPED__"><view class="{{((__SCOPED__.text)?
\'
text
\'
:
\'\'
)}}">{{__SCOPED__.text}}</view></view></component1>
'
'
<component1 vue-id="551070e6-1" text="text" onVueInit="__l"><view slot-scope="__SCOPED__"><view class="{{((__SCOPED__.text)?
\'
text
\'
:
\'\'
)}}">{{__SCOPED__.text}}</view></view></component1>
'
)
})
...
...
packages/uni-template-compiler/__tests__/compiler-mp-baidu.spec.js
浏览文件 @
bcecd71b
...
...
@@ -24,11 +24,11 @@ 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
slot="default"
>{{foo}}</view></foo>
'
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
default
\'
]}}"><view>{{foo}}</view></foo>
'
)
assertCodegen
(
'
<foo><view slot-scope="bar">{{ bar.foo }}</view></foo>
'
,
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
default
\'
]}}"><view
slot="default"
><view>{{foo}}</view></view></foo>
'
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
default
\'
]}}"><view><view>{{foo}}</view></view></foo>
'
)
})
...
...
@@ -46,7 +46,7 @@ describe('mp:compiler-mp-baidu', () => {
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
slot="default"
><block s-if="{{show}}">{{foo}}</block><block s-else><block></block></block></view></foo>
'
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
default
\'
]}}"><view><block s-if="{{show}}">{{foo}}</block><block s-else><block></block></block></view></foo>
'
)
assertCodegen
(
'
<foo><view v-if="
\n
show
\n
" slot="foo" slot-scope="bar">{{ bar.foo }}</view></foo>
'
,
...
...
@@ -57,7 +57,7 @@ describe('mp:compiler-mp-baidu', () => {
it
(
'
generate scoped slot
'
,
()
=>
{
assertCodegen
(
'
<span><slot v-bind:user="user">{{ user.lastName }}</slot></span>
'
,
'
<label class="_span"><block s-if="{{$slots.default}}"><slot
name="default"
var-user="user"></slot></block><block s-else>{{user.lastName}}</block></label>
'
'
<label class="_span"><block s-if="{{$slots.default}}"><slot var-user="user"></slot></block><block s-else>{{user.lastName}}</block></label>
'
)
assertCodegen
(
'
<span><slot name="header" v-bind:user="user">{{ user.lastName }}</slot></span>
'
,
...
...
packages/uni-template-compiler/__tests__/compiler.spec.js
浏览文件 @
bcecd71b
...
...
@@ -172,6 +172,7 @@ describe('mp:compiler', () => {
it
(
'
generate single slot
'
,
()
=>
{
assertCodegen
(
'
<view><slot></slot></view>
'
,
'
<view><slot></slot></view>
'
)
assertCodegen
(
'
<view><slot name="default"></slot></view>
'
,
'
<view><slot></slot></view>
'
)
})
it
(
'
generate named slot
'
,
()
=>
{
...
...
@@ -193,6 +194,10 @@ describe('mp:compiler', () => {
'
<view slot="one">hello world</view>
'
,
'
<view slot="one">hello world</view>
'
)
assertCodegen
(
'
<view slot="default">hello world</view>
'
,
'
<view>hello world</view>
'
)
})
// it('generate scoped slot', () => {
...
...
packages/uni-template-compiler/lib/template/generate.js
浏览文件 @
bcecd71b
...
...
@@ -14,6 +14,13 @@ function processElement (ast, state, isRoot) {
ast
.
type
=
'
view
'
}
// 由于小程序端 default 不等同于默认插槽,统一移除 default 命名
if
(
ast
.
type
===
'
slot
'
&&
hasOwn
(
ast
.
attr
,
'
name
'
)
&&
ast
.
attr
.
name
===
'
default
'
)
{
delete
ast
.
attr
.
name
}
else
if
(
hasOwn
(
ast
.
attr
,
'
slot
'
)
&&
ast
.
attr
.
slot
===
'
default
'
)
{
delete
ast
.
attr
.
slot
}
if
(
hasOwn
(
ast
.
attr
,
'
textContent
'
))
{
ast
.
children
=
[
ast
.
attr
.
textContent
]
delete
ast
.
attr
.
textContent
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录