Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
genary
uni-app
提交
bcecd71b
U
uni-app
项目概览
genary
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
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>
'
,
...
...
@@ -676,4 +676,4 @@ describe('mp:compiler-extra', () => {
'
<video controls></video>
'
)
})
})
})
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
const
compiler
=
require
(
'
../lib
'
)
function
assertCodegen
(
template
,
templateCode
,
renderCode
=
'
with(this){}
'
,
options
=
{})
{
const
res
=
compiler
.
compile
(
template
,
{
const
res
=
compiler
.
compile
(
template
,
{
resourcePath
:
'
test.wxml
'
,
mp
:
Object
.
assign
({
minified
:
true
,
...
...
@@ -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,54 +57,54 @@ 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>
'
,
'
<label class="_span"><block s-if="{{$slots.header}}"><slot name="header" var-user="user"></slot></block><block s-else>{{user.lastName}}</block></label>
'
)
})
it
(
'
generate vue id
'
,
()
=>
{
assertCodegen
(
'
<Test/>
'
,
'
<test vue-id="551070e6-1"></test>
'
)
assertCodegen
(
'
<Test a="a">
'
,
'
<test vue-id="551070e6-1" a="a"></test>
'
)
assertCodegen
(
'
<view><Test v-for="item in items" :key="item"/></view>
'
,
'
<view><block s-for="{{items}}" s-for-item="item" s-for-index="__i0__" s-key="*this"><test vue-id="{{
\'
551070e6-1-
\'
+__i0__}}"></test></block></view>
'
)
assertCodegen
(
'
<view><Test v-for="item in items" :key="item"><Test v-for="item in item.items" :key="item"></Test></Test></view>
'
,
'
<view><block s-for="{{items}}" s-for-item="item" s-for-index="__i0__" s-key="*this"><test vue-id="{{
\'
551070e6-1-
\'
+__i0__}}" vue-slots="{{[
\'
default
\'
]}}"><block s-for="{{item.items}}" s-for-item="item" s-for-index="__i1__" s-key="*this"><test vue-id="{{(
\'
551070e6-2-
\'
+__i0__+
\'
-
\'
+__i1__)+
\'
,
\'
+(
\'
551070e6-1-
\'
+__i0__)}}"></test></block></test></block></view>
'
)
assertCodegen
(
'
<view><Test v-for="(item,index) in items" :key="item"><Test v-for="(item,index1) in item.items" :key="item"></Test></Test></view>
'
,
'
<view><block s-for="{{items}}" s-for-item="item" s-for-index="index" s-key="*this"><test vue-id="{{
\'
551070e6-1-
\'
+index}}" vue-slots="{{[
\'
default
\'
]}}"><block s-for="{{item.items}}" s-for-item="item" s-for-index="index1" s-key="*this"><test vue-id="{{(
\'
551070e6-2-
\'
+index+
\'
-
\'
+index1)+
\'
,
\'
+(
\'
551070e6-1-
\'
+index)}}"></test></block></test></block></view>
'
)
})
it
(
'
generate text trim
'
,
()
=>
{
assertCodegen
(
'
<text>
\n
N: {{title}}
\n
′</text>
'
,
'
<text>{{
\'
N:
\'
+title+"
\\\\
n′"}}</text>
'
)
assertCodegen
(
'
<text>我是第一行1
\n
我的第二行</text>
'
,
'
<text>我是第一行1
\n
我的第二行</text>
'
)
assertCodegen
(
'
<text>我是第一行2
\n
我的第二行1{{title}}</text>
'
,
'
<text>{{"我是第一行2
\\\\
n我的第二行1"+title}}</text>
'
)
assertCodegen
(
`<text>我是第一行3
我的第二行2{{title}}</text>`
,
'
<text>{{"我是第一行3
\\\\
n 我的第二行2"+title}}</text>
'
)
})
})
it
(
'
generate vue id
'
,
()
=>
{
assertCodegen
(
'
<Test/>
'
,
'
<test vue-id="551070e6-1"></test>
'
)
assertCodegen
(
'
<Test a="a">
'
,
'
<test vue-id="551070e6-1" a="a"></test>
'
)
assertCodegen
(
'
<view><Test v-for="item in items" :key="item"/></view>
'
,
'
<view><block s-for="{{items}}" s-for-item="item" s-for-index="__i0__" s-key="*this"><test vue-id="{{
\'
551070e6-1-
\'
+__i0__}}"></test></block></view>
'
)
assertCodegen
(
'
<view><Test v-for="item in items" :key="item"><Test v-for="item in item.items" :key="item"></Test></Test></view>
'
,
'
<view><block s-for="{{items}}" s-for-item="item" s-for-index="__i0__" s-key="*this"><test vue-id="{{
\'
551070e6-1-
\'
+__i0__}}" vue-slots="{{[
\'
default
\'
]}}"><block s-for="{{item.items}}" s-for-item="item" s-for-index="__i1__" s-key="*this"><test vue-id="{{(
\'
551070e6-2-
\'
+__i0__+
\'
-
\'
+__i1__)+
\'
,
\'
+(
\'
551070e6-1-
\'
+__i0__)}}"></test></block></test></block></view>
'
)
assertCodegen
(
'
<view><Test v-for="(item,index) in items" :key="item"><Test v-for="(item,index1) in item.items" :key="item"></Test></Test></view>
'
,
'
<view><block s-for="{{items}}" s-for-item="item" s-for-index="index" s-key="*this"><test vue-id="{{
\'
551070e6-1-
\'
+index}}" vue-slots="{{[
\'
default
\'
]}}"><block s-for="{{item.items}}" s-for-item="item" s-for-index="index1" s-key="*this"><test vue-id="{{(
\'
551070e6-2-
\'
+index+
\'
-
\'
+index1)+
\'
,
\'
+(
\'
551070e6-1-
\'
+index)}}"></test></block></test></block></view>
'
)
})
it
(
'
generate text trim
'
,
()
=>
{
assertCodegen
(
'
<text>
\n
N: {{title}}
\n
′</text>
'
,
'
<text>{{
\'
N:
\'
+title+"
\\\\
n′"}}</text>
'
)
assertCodegen
(
'
<text>我是第一行1
\n
我的第二行</text>
'
,
'
<text>我是第一行1
\n
我的第二行</text>
'
)
assertCodegen
(
'
<text>我是第一行2
\n
我的第二行1{{title}}</text>
'
,
'
<text>{{"我是第一行2
\\\\
n我的第二行1"+title}}</text>
'
)
assertCodegen
(
`<text>我是第一行3
我的第二行2{{title}}</text>`
,
'
<text>{{"我是第一行3
\\\\
n 我的第二行2"+title}}</text>
'
)
})
})
packages/uni-template-compiler/__tests__/compiler.spec.js
浏览文件 @
bcecd71b
const
compiler
=
require
(
'
../lib
'
)
function
assertCodegen
(
template
,
templateCode
,
renderCode
=
'
with(this){}
'
)
{
const
res
=
compiler
.
compile
(
template
,
{
const
res
=
compiler
.
compile
(
template
,
{
resourcePath
:
'
test.wxml
'
,
mp
:
{
minified
:
true
,
...
...
@@ -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', () => {
...
...
@@ -486,7 +491,7 @@ describe('mp:compiler', () => {
)
// normal named function
assertCodegen
(
'
<input @input="function fn () { current++ }">
'
,
'
<input @input="function fn () { current++ }">
'
,
'
<input data-event-opts="{{[[
\'
input
\'
,[[
\'
e0
\'
,[
\'
$event
\'
]]]]]}}" bindinput="__e"/>
'
,
'
with(this){if(!_isMounted){e0=function fn(){current++}}}
'
)
...
...
@@ -665,4 +670,4 @@ describe('mp:compiler', () => {
'
<view class="_div"><block wx:if="{{ok}}"><block wx:for="{{1}}" wx:for-item="i" wx:for-index="__i0__" wx:key="*this"><foo vue-id="{{
\'
551070e6-1-
\'
+__i0__}}" bind:__l="__l"></foo></block></block></view>
'
)
})
})
})
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
...
...
@@ -145,4 +152,4 @@ module.exports = function generate (ast, state) {
}
return
code
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录