Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
良好的行为成为习惯
uni-app
提交
a445c140
U
uni-app
项目概览
良好的行为成为习惯
/
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,发现更多精彩内容 >>
提交
a445c140
编写于
2月 08, 2020
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(v3): allow root elements with v-if, v-else-if and v-else
上级
30118f5b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
35 addition
and
12 deletion
+35
-12
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js
...ompiler/__tests__/compiler-app-plus-extra.service.spec.js
+6
-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__/demo.js
packages/uni-template-compiler/__tests__/demo.js
+4
-9
packages/uni-template-compiler/lib/app/parser/base-parser.js
packages/uni-template-compiler/lib/app/parser/base-parser.js
+8
-2
packages/uni-template-compiler/lib/app/service.js
packages/uni-template-compiler/lib/app/service.js
+5
-0
packages/uni-template-compiler/lib/app/view.js
packages/uni-template-compiler/lib/app/view.js
+6
-1
未找到文件。
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js
浏览文件 @
a445c140
...
...
@@ -136,6 +136,12 @@ describe('codegen', () => {
'
<view data-a="1" :data-b="b"></view>
'
,
`with(this){return _c('view',{attrs:{"data-b":_$s(0,'a-data-b',b),"_i":0}})}`
)
})
it
(
'
generate v-if directive
'
,
()
=>
{
assertCodegen
(
'
<text v-if="a">1</text><text v-else-if="b">2</text><text v-else-if="c">3</text><text v-else>d</text>
'
,
`with(this){return (_$s(0,'i',a))?_c('text'):(_$s(1,'e',b))?_c('text'):(_$s(2,'e',c))?_c('text'):_c('text')}`
)
})
})
/* eslint-enable quotes */
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js
浏览文件 @
a445c140
...
...
@@ -75,6 +75,12 @@ describe('codegen', () => {
'
<view data-a="1" :data-b="b"></view>
'
,
`with(this){return _c('v-uni-view',{attrs:{"data-a":"1","data-b":_$g(0,'a-data-b'),"_i":0}})}`
)
})
it
(
'
generate v-if directive
'
,
()
=>
{
assertCodegen
(
'
<text v-if="a">1</text><text v-else-if="b">2</text><text v-else-if="c">3</text><text v-else>d</text>
'
,
`with(this){return (_$g(0,'i'))?_c('v-uni-text',{attrs:{"_i":0}},[_v("1")]):(_$g(1,'e'))?_c('v-uni-text',{attrs:{"_i":1}},[_v("2")]):(_$g(2,'e'))?_c('v-uni-text',{attrs:{"_i":2}},[_v("3")]):_c('v-uni-text',{attrs:{"_i":3}},[_v("d")])}`
)
})
})
/* eslint-enable quotes */
packages/uni-template-compiler/__tests__/demo.js
浏览文件 @
a445c140
...
...
@@ -18,13 +18,8 @@ const scopedPath = path.resolve(__dirname, '../../')
const
compiler
=
require
(
'
../lib
'
)
const
res
=
compiler
.
compile
(
`
<view class="h-page">
<slot></slot>
<h-dialog></h-dialog>
<h-navbar></h-navbar>
<h-toast></h-toast>
</view>
`
<text v-if="a">1</text><text v-else-if="b">2</text><text v-else-if="c">3</text><text v-else>d</text>
`
,
{
miniprogram
:
true
,
resourcePath
:
'
/User/fxy/Documents/test.wxml
'
,
...
...
@@ -37,9 +32,9 @@ const res = compiler.compile(
mp
:
{
platform
:
'
mp-weixin
'
},
filterModules
:
[
'
swipe
'
]
filterModules
:
[
'
swipe
'
]
,
// service: true,
//
view: true
view
:
true
})
console
.
log
(
require
(
'
util
'
).
inspect
(
res
,
{
...
...
packages/uni-template-compiler/lib/app/parser/base-parser.js
浏览文件 @
a445c140
...
...
@@ -18,6 +18,10 @@ function parseIs (el, genVar) {
}
}
function
isProcessed
(
exp
)
{
return
String
(
exp
).
indexOf
(
'
_$
'
)
===
0
}
// 当根节点是由if,elseif,else组成,会调用多次parseIf来解析root
function
parseIf
(
el
,
createGenVar
,
isScopedSlot
)
{
if
(
!
el
.
if
)
{
return
...
...
@@ -26,11 +30,13 @@ function parseIf (el, createGenVar, isScopedSlot) {
isScopedSlot
=
false
}
el
.
ifConditions
.
forEach
(
con
=>
{
if
(
isVar
(
con
.
exp
))
{
if
(
!
isProcessed
(
con
.
exp
)
&&
isVar
(
con
.
exp
))
{
con
.
exp
=
createGenVar
(
con
.
block
.
attrsMap
[
ID
],
isScopedSlot
)(
con
.
block
.
elseif
?
V_ELSE_IF
:
V_IF
,
con
.
exp
)
}
})
el
.
if
=
createGenVar
(
el
.
attrsMap
[
ID
],
isScopedSlot
)(
V_IF
,
el
.
if
)
if
(
!
isProcessed
(
el
.
if
))
{
el
.
if
=
createGenVar
(
el
.
attrsMap
[
ID
],
isScopedSlot
)(
V_IF
,
el
.
if
)
}
}
function
parseFor
(
el
,
createGenVar
,
isScopedSlot
,
fill
=
false
)
{
...
...
packages/uni-template-compiler/lib/app/service.js
浏览文件 @
a445c140
...
...
@@ -156,6 +156,11 @@ function transformNode (el, parent, state, isScopedSlot) {
function
postTransformNode
(
el
,
options
)
{
if
(
!
el
.
parent
)
{
// 从根节点开始递归处理
if
(
options
.
root
)
{
// 当根节点是由if,elseif,else组成
parseIf
(
options
.
root
,
createGenVar
)
}
else
{
options
.
root
=
el
}
traverseNode
(
el
,
false
,
{
forIteratorId
:
0
,
transformNode
,
...
...
packages/uni-template-compiler/lib/app/view.js
浏览文件 @
a445c140
...
...
@@ -155,6 +155,11 @@ function transformNode (el, parent, state, isScopedSlot) {
function
postTransformNode
(
el
,
options
)
{
if
(
!
el
.
parent
)
{
// 从根节点开始递归处理
if
(
options
.
root
)
{
// 当根节点是由if,elseif,else组成
parseIf
(
options
.
root
,
createGenVar
)
}
else
{
options
.
root
=
el
}
traverseNode
(
el
,
false
,
{
forIteratorId
:
0
,
transformNode
,
...
...
@@ -235,4 +240,4 @@ module.exports = {
},
postTransformNode
,
genData
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录