Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
b0229d7f
U
uni-app
项目概览
DCloud
/
uni-app
4 个月 前同步成功
通知
731
Star
38707
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
b0229d7f
编写于
10月 23, 2019
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(v3): v-slot
上级
51f5cc39
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
40 addition
and
15 deletion
+40
-15
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js
...ompiler/__tests__/compiler-app-plus-extra.service.spec.js
+7
-0
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js
...e-compiler/__tests__/compiler-app-plus-extra.view.spec.js
+6
-0
packages/uni-template-compiler/__tests__/compiler-app-plus.view.spec.js
...emplate-compiler/__tests__/compiler-app-plus.view.spec.js
+1
-1
packages/uni-template-compiler/__tests__/demo.js
packages/uni-template-compiler/__tests__/demo.js
+3
-5
packages/uni-template-compiler/lib/app/parser/block-parser.js
...ages/uni-template-compiler/lib/app/parser/block-parser.js
+16
-3
packages/uni-template-compiler/lib/app/parser/component-parser.js
.../uni-template-compiler/lib/app/parser/component-parser.js
+1
-1
packages/uni-template-compiler/lib/app/service.js
packages/uni-template-compiler/lib/app/service.js
+2
-2
packages/uni-template-compiler/lib/app/view.js
packages/uni-template-compiler/lib/app/view.js
+1
-1
packages/uni-template-compiler/lib/index.js
packages/uni-template-compiler/lib/index.js
+2
-1
packages/uni-template-compiler/lib/util.js
packages/uni-template-compiler/lib/util.js
+1
-1
未找到文件。
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js
浏览文件 @
b0229d7f
...
@@ -63,6 +63,13 @@ describe('codegen', () => {
...
@@ -63,6 +63,13 @@ describe('codegen', () => {
'
<div>A{{ d | e | f }}B{{text}}C</div>
'
,
'
<div>A{{ d | e | f }}B{{text}}C</div>
'
,
`with(this){return _c('div',[_v((_$s(0,'t0',_s(_f("f")(_f("e")(d)))))+(_$s(0,'t1',_s(text))))])}`
`with(this){return _c('div',[_v((_$s(0,'t0',_s(_f("f")(_f("e")(d)))))+(_$s(0,'t1',_s(text))))])}`
)
)
})
it
(
'
generate v-slot
'
,
()
=>
{
assertCodegen
(
'
<current-user v-slot="{ user }">{{ user.firstName }}</current-user>
'
,
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({ user }){return [_v((_$s(0,'t0',_s(user.firstName))))]}}])})}`
)
})
})
})
})
/* eslint-enable quotes */
/* eslint-enable quotes */
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js
浏览文件 @
b0229d7f
...
@@ -39,6 +39,12 @@ describe('codegen', () => {
...
@@ -39,6 +39,12 @@ describe('codegen', () => {
'
<div><slot><div>{{hi}}</div></slot></div>
'
,
'
<div><slot><div>{{hi}}</div></slot></div>
'
,
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_t("default",[_c('v-uni-view',{attrs:{"_i":2}},[_v((_$g(2,'t0')))])],{"_i":1})],2)}`
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_t("default",[_c('v-uni-view',{attrs:{"_i":2}},[_v((_$g(2,'t0')))])],{"_i":1})],2)}`
)
)
})
it
(
'
generate v-slot
'
,
()
=>
{
assertCodegen
(
'
<current-user v-slot="{ user }">{{ user.firstName }}</current-user>
'
,
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({ user }){return [_v((_$g(0,'t0')))]}}])})}`
)
})
})
})
})
/* eslint-enable quotes */
/* eslint-enable quotes */
packages/uni-template-compiler/__tests__/compiler-app-plus.view.spec.js
浏览文件 @
b0229d7f
...
@@ -565,7 +565,7 @@ describe('codegen', () => {
...
@@ -565,7 +565,7 @@ describe('codegen', () => {
it
(
'
generate svg component with children
'
,
()
=>
{
it
(
'
generate svg component with children
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
'
<svg><my-comp><circle :r="10"></circle></my-comp></svg>
'
,
'
<svg><my-comp><circle :r="10"></circle></my-comp></svg>
'
,
`with(this){return _c('svg',{attrs:{"_i":0}},[_c('my-comp',{attrs:{"_i":1}},[_c('circle',{attrs:{"_i":2}})])],1)}`
`with(this){return _c('svg',{attrs:{"_i":0}},[_c('my-comp',{attrs:{"_i":1}},[_c('circle',{attrs:{"_i":2}})]
,1
)],1)}`
)
)
})
})
...
...
packages/uni-template-compiler/__tests__/demo.js
浏览文件 @
b0229d7f
const
compiler
=
require
(
'
../lib
'
)
const
compiler
=
require
(
'
../lib
'
)
const
res
=
compiler
.
compile
(
const
res
=
compiler
.
compile
(
`
`
<input v-model="\n test \n">
<div><block v-for="item in items"><div></div><div></div></block></div>
`
,
{
`
,
{
resourcePath
:
'
/User/fxy/Documents/test.wxml
'
,
resourcePath
:
'
/User/fxy/Documents/test.wxml
'
,
isReservedTag
:
function
(
tag
)
{
isReservedTag
:
function
(
tag
)
{
return
true
return
true
...
@@ -15,7 +13,7 @@ const res = compiler.compile(
...
@@ -15,7 +13,7 @@ const res = compiler.compile(
mp
:
{
mp
:
{
platform
:
'
app-plus
'
platform
:
'
app-plus
'
},
},
//
service: true,
service
:
true
,
view
:
true
view
:
true
})
})
console
.
log
(
require
(
'
util
'
).
inspect
(
res
,
{
console
.
log
(
require
(
'
util
'
).
inspect
(
res
,
{
...
...
packages/uni-template-compiler/lib/app/parser/block-parser.js
浏览文件 @
b0229d7f
module
.
exports
=
function
parseBlock
(
el
)
{
const
{
if
(
el
.
tag
===
'
block
'
)
{
ID
,
hasOwn
,
addRawAttr
}
=
require
(
'
../util
'
)
module
.
exports
=
function
parseBlock
(
el
,
parent
)
{
if
(
el
.
tag
===
'
template
'
&&
!
hasOwn
(
el
.
attrsMap
,
ID
))
{
/**
* <current-user v-slot="{ user }">
* {{ user.firstName }}
* </current-user>
*/
addRawAttr
(
el
,
ID
,
parent
.
attrsMap
[
ID
])
}
else
if
(
el
.
tag
===
'
block
'
)
{
el
.
tag
=
'
template
'
el
.
tag
=
'
template
'
const
vForKey
=
el
.
key
const
vForKey
=
el
.
key
if
(
vForKey
)
{
if
(
vForKey
)
{
delete
el
.
key
delete
el
.
key
el
.
children
.
forEach
((
childEl
,
index
)
=>
{
el
.
children
.
forEach
((
childEl
,
index
)
=>
{
...
...
packages/uni-template-compiler/lib/app/parser/component-parser.js
浏览文件 @
b0229d7f
...
@@ -10,6 +10,6 @@ module.exports = function parseComponent (el) {
...
@@ -10,6 +10,6 @@ module.exports = function parseComponent (el) {
// 需要把自定义组件的 attrs, props 全干掉
// 需要把自定义组件的 attrs, props 全干掉
if
(
el
.
tag
&&
!
hasOwn
(
tags
,
el
.
tag
.
replace
(
'
v-uni-
'
,
''
)))
{
if
(
el
.
tag
&&
!
hasOwn
(
tags
,
el
.
tag
.
replace
(
'
v-uni-
'
,
''
)))
{
// 仅保留 ID
// 仅保留 ID
el
.
attrs
=
el
.
attrs
.
filter
(
attr
=>
attr
.
name
===
ID
)
el
.
attrs
&&
(
el
.
attrs
=
el
.
attrs
.
filter
(
attr
=>
attr
.
name
===
ID
)
)
}
}
}
}
packages/uni-template-compiler/lib/app/service.js
浏览文件 @
b0229d7f
...
@@ -66,7 +66,7 @@ function transformNode (el, parent, state) {
...
@@ -66,7 +66,7 @@ function transformNode (el, parent, state) {
if
(
el
.
type
===
3
)
{
if
(
el
.
type
===
3
)
{
return
return
}
}
parseBlock
(
el
)
parseBlock
(
el
,
parent
)
parseEvent
(
el
)
parseEvent
(
el
)
updateForEleId
(
el
,
state
)
updateForEleId
(
el
,
state
)
...
@@ -115,7 +115,7 @@ function genVModel (el) {
...
@@ -115,7 +115,7 @@ function genVModel (el) {
const
prop
=
el
.
props
.
find
(
prop
=>
prop
.
name
===
'
value
'
)
const
prop
=
el
.
props
.
find
(
prop
=>
prop
.
name
===
'
value
'
)
prop
.
value
=
createGenVar
(
el
.
attrsMap
[
ID
])(
'
v-model
'
,
prop
.
value
)
prop
.
value
=
createGenVar
(
el
.
attrsMap
[
ID
])(
'
v-model
'
,
prop
.
value
)
}
}
if
(
el
.
model
)
{
if
(
el
.
model
)
{
el
.
model
.
value
=
createGenVar
(
el
.
attrsMap
[
ID
])(
'
v-model
'
,
el
.
model
.
value
)
el
.
model
.
value
=
createGenVar
(
el
.
attrsMap
[
ID
])(
'
v-model
'
,
el
.
model
.
value
)
}
}
}
}
...
...
packages/uni-template-compiler/lib/app/view.js
浏览文件 @
b0229d7f
...
@@ -57,7 +57,7 @@ function transformNode (el, parent, state) {
...
@@ -57,7 +57,7 @@ function transformNode (el, parent, state) {
if
(
el
.
type
===
3
)
{
if
(
el
.
type
===
3
)
{
return
return
}
}
parseBlock
(
el
)
parseBlock
(
el
,
parent
)
parseComponent
(
el
)
parseComponent
(
el
)
parseEvent
(
el
)
parseEvent
(
el
)
// 更新 id
// 更新 id
...
...
packages/uni-template-compiler/lib/index.js
浏览文件 @
b0229d7f
...
@@ -43,7 +43,8 @@ module.exports = {
...
@@ -43,7 +43,8 @@ module.exports = {
return
compiled
return
compiled
}
else
if
(
options
.
view
)
{
}
else
if
(
options
.
view
)
{
(
options
.
modules
||
(
options
.
modules
=
[])).
push
(
require
(
'
./app/view
'
))
(
options
.
modules
||
(
options
.
modules
=
[])).
push
(
require
(
'
./app/view
'
))
options
.
optimize
=
false
// 暂不启用 staticRenderFns
options
.
optimize
=
false
// 暂不启用 staticRenderFns
options
.
isReservedTag
=
(
tagName
)
=>
false
// 均为组件
return
compile
(
source
,
options
)
return
compile
(
source
,
options
)
}
}
...
...
packages/uni-template-compiler/lib/util.js
浏览文件 @
b0229d7f
...
@@ -185,7 +185,7 @@ const {
...
@@ -185,7 +185,7 @@ const {
function
isComponent
(
tagName
)
{
function
isComponent
(
tagName
)
{
if
(
tagName
===
'
block
'
||
tagName
===
'
template
'
)
{
if
(
tagName
===
'
block
'
||
tagName
===
'
template
'
)
{
return
false
return
false
}
}
return
!
hasOwn
(
tags
,
getTagName
(
tagName
.
replace
(
'
v-uni-
'
,
''
)))
return
!
hasOwn
(
tags
,
getTagName
(
tagName
.
replace
(
'
v-uni-
'
,
''
)))
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录