Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
8ed1ce87
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看板
提交
8ed1ce87
编写于
8月 01, 2020
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev' into alpha
上级
e26d9483
7c234e52
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
89 addition
and
16 deletion
+89
-16
packages/uni-template-compiler/__tests__/compiler-extra.spec.js
...es/uni-template-compiler/__tests__/compiler-extra.spec.js
+24
-7
packages/uni-template-compiler/lib/script/traverse/member-expr.js
.../uni-template-compiler/lib/script/traverse/member-expr.js
+34
-1
packages/uni-template-compiler/lib/script/traverse/statements.js
...s/uni-template-compiler/lib/script/traverse/statements.js
+9
-5
src/platforms/h5/view/components/ad/index.vue
src/platforms/h5/view/components/ad/index.vue
+22
-3
未找到文件。
packages/uni-template-compiler/__tests__/compiler-extra.spec.js
浏览文件 @
8ed1ce87
...
...
@@ -553,22 +553,22 @@ describe('mp:compiler-extra', () => {
assertCodegen
(
'
<view><view v-for="(item, index) in list"><view>{{handle(item)}}</view></view></view>
'
,
'
<view><block wx:for="{{$root.l0}}" wx:for-item="item" wx:for-index="index"><view><view>{{item.m0}}</view></view></block></view>
'
,
'
with(this){var l0=__map(list,function(item,index){var
m0=handle(item);return{$orig:__get_orig(item)
,m0:m0}});$mp.data=Object.assign({},{$root:{l0:l0}})}
'
'
with(this){var l0=__map(list,function(item,index){var
$orig=__get_orig(item);var m0=handle(item);return{$orig:$orig
,m0:m0}});$mp.data=Object.assign({},{$root:{l0:l0}})}
'
)
assertCodegen
(
'
<view><view v-for="(item, index) in list"><view>{{handle(item)}}{{item.title}}</view></view></view>
'
,
'
<view><block wx:for="{{$root.l0}}" wx:for-item="item" wx:for-index="index"><view><view>{{item.m0+item.$orig.title}}</view></view></block></view>
'
,
'
with(this){var l0=__map(list,function(item,index){var
m0=handle(item);return{$orig:__get_orig(item)
,m0:m0}});$mp.data=Object.assign({},{$root:{l0:l0}})}
'
'
with(this){var l0=__map(list,function(item,index){var
$orig=__get_orig(item);var m0=handle(item);return{$orig:$orig
,m0:m0}});$mp.data=Object.assign({},{$root:{l0:l0}})}
'
)
assertCodegen
(
'
<view><view v-for="(item, index) in list"><view v-for="(item1,index1) in list1">{{handle(item1)}}{{item1.title}}</view></view></view>
'
,
'
<view><block wx:for="{{$root.l1}}" wx:for-item="item" wx:for-index="index"><view><block wx:for="{{item.l0}}" wx:for-item="item1" wx:for-index="index1"><view>{{item1.m0+item1.$orig.title}}</view></block></view></block></view>
'
,
'
with(this){var l1=__map(list,function(item,index){var
l0=__map(list1,function(item1,index1){var m0=handle(item1);return{$orig:__get_orig(item1),m0:m0}});return{$orig:__get_orig(item)
,l0:l0}});$mp.data=Object.assign({},{$root:{l1:l1}})}
'
'
with(this){var l1=__map(list,function(item,index){var
$orig=__get_orig(item);var l0=__map(list1,function(item1,index1){var $orig=__get_orig(item1);var m0=handle(item1);return{$orig:$orig,m0:m0}});return{$orig:$orig
,l0:l0}});$mp.data=Object.assign({},{$root:{l1:l1}})}
'
)
assertCodegen
(
'
<view v-for="(section, index) in sections" :key="index">title: {{ section.title|prefix }}<view v-for="(sub_titles, _index) in section.sub_titles" :key="_index">{{ sub_titles|prefix }}</view></view>
'
,
'
<block wx:for="{{$root.l1}}" wx:for-item="section" wx:for-index="index" wx:key="index"><view>{{"title: "+section.f0}}<block wx:for="{{section.l0}}" wx:for-item="sub_titles" wx:for-index="_index" wx:key="_index"><view>{{sub_titles.f1}}</view></block></view></block>
'
,
'
with(this){var l1=__map(sections,function(section,index){var
f0=_f("prefix")(section.title);var l0=__map(section.sub_titles,function(sub_titles,_index){var f1=_f("prefix")(sub_titles);return{$orig:__get_orig(sub_titles),f1:f1}});return{$orig:__get_orig(section)
,f0:f0,l0:l0}});$mp.data=Object.assign({},{$root:{l1:l1}})}
'
'
with(this){var l1=__map(sections,function(section,index){var
$orig=__get_orig(section);var f0=_f("prefix")(section.title);var l0=__map(section.sub_titles,function(sub_titles,_index){var $orig=__get_orig(sub_titles);var f1=_f("prefix")(sub_titles);return{$orig:$orig,f1:f1}});return{$orig:$orig
,f0:f0,l0:l0}});$mp.data=Object.assign({},{$root:{l1:l1}})}
'
)
assertCodegen
(
...
...
@@ -579,12 +579,12 @@ describe('mp:compiler-extra', () => {
assertCodegen
(
'
<view v-for="(item, index) in list" :key="item">{{item.item.id | test | test1}}</view>
'
,
'
<block wx:for="{{$root.l0}}" wx:for-item="item" wx:for-index="index" wx:key="$orig"><view>{{item.f0}}</view></block>
'
,
'
with(this){var l0=__map(list,function(item,index){var
f0=_f("test1")(_f("test")(item.item.id));return{$orig:__get_orig(item)
,f0:f0}});$mp.data=Object.assign({},{$root:{l0:l0}})}
'
'
with(this){var l0=__map(list,function(item,index){var
$orig=__get_orig(item);var f0=_f("test1")(_f("test")(item.item.id));return{$orig:$orig
,f0:f0}});$mp.data=Object.assign({},{$root:{l0:l0}})}
'
)
assertCodegen
(
'
<text v-for="(item, i) in list" v-bind:key="i" >{{ item.split(
\'\'
).join(
\'
\'
) }}</text>
'
,
'
<block wx:for="{{$root.l0}}" wx:for-item="item" wx:for-index="i" wx:key="i"><text>{{item.g0}}</text></block>
'
,
'
with(this){var l0=__map(list,function(item,i){var
g0=item.split("").join(" ");return{$orig:__get_orig(item)
,g0:g0}});$mp.data=Object.assign({},{$root:{l0:l0}})}
'
'
with(this){var l0=__map(list,function(item,i){var
$orig=__get_orig(item);var g0=item.split("").join(" ");return{$orig:$orig
,g0:g0}});$mp.data=Object.assign({},{$root:{l0:l0}})}
'
)
assertCodegen
(
`<view class="content">
...
...
@@ -595,7 +595,7 @@ describe('mp:compiler-extra', () => {
</view>
</view>`
,
'
<view class="content"><block wx:for="{{$root.l1}}" wx:for-item="item" wx:for-index="index" wx:key="index"><view><block wx:for="{{item.l0}}" wx:for-item="item2" wx:for-index="index2" wx:key="index2"><view data-event-opts="{{[[
\'
tap
\'
,[[
\'
show
\'
,[
\'
$0
\'
,
\'
$1
\'
],[[[
\'
list.
\'
+item.$orig.key+
\'\'
,
\'\'
,index2,
\'
id
\'
]],[[
\'
list.
\'
+item.$orig.key+
\'\'
,
\'\'
,index2,
\'
id
\'
]]]]]]]}}" bindtap="__e">{{
\'\'
+item2.m0+
\'\'
}}</view></block></view></block></view>
'
,
'
with(this){var l1=__map(tabList,function(item,index){var
l0=__map(list[item.key],function(item2,index2){var m0=formatIt(item2.id);return{$orig:__get_orig(item2),m0:m0}});return{$orig:__get_orig(item)
,l0:l0}});$mp.data=Object.assign({},{$root:{l1:l1}})}
'
'
with(this){var l1=__map(tabList,function(item,index){var
$orig=__get_orig(item);var l0=__map(list[item.key],function(item2,index2){var $orig=__get_orig(item2);var m0=formatIt(item2.id);return{$orig:$orig,m0:m0}});return{$orig:$orig
,l0:l0}});$mp.data=Object.assign({},{$root:{l1:l1}})}
'
)
})
...
...
@@ -676,4 +676,21 @@ describe('mp:compiler-extra', () => {
'
<video controls></video>
'
)
})
it
(
'
generate v-if
'
,
()
=>
{
assertCodegen
(
'
<view v-if="show">{{getValue(key)}}</view>
'
,
'
<block wx:if="{{show}}"><view>{{$root.m0}}</view></block>
'
,
'
with(this){var m0=show?getValue(key):null;$mp.data=Object.assign({},{$root:{m0:m0}})}
'
)
assertCodegen
(
'
<view v-if="getValue(key)">{{getValue(key)}}</view>
'
,
'
<block wx:if="{{$root.m0}}"><view>{{$root.m1}}</view></block>
'
,
'
with(this){var m0=getValue(key);var m1=m0?getValue(key):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}
'
)
assertCodegen
(
'
<view v-for="(item,index) in list" :key="index"><view v-if="item">{{getValue(item)}}</view></view>
'
,
'
<block wx:for="{{$root.l0}}" wx:for-item="item" wx:for-index="index" wx:key="index"><view><block wx:if="{{item.$orig}}"><view>{{item.m0}}</view></block></view></block>
'
,
'
with(this){var l0=__map(list,function(item,index){var $orig=__get_orig(item);var m0=item?getValue(item):null;return{$orig:$orig,m0:m0}});$mp.data=Object.assign({},{$root:{l0:l0}})}
'
)
})
})
packages/uni-template-compiler/lib/script/traverse/member-expr.js
浏览文件 @
8ed1ce87
const
t
=
require
(
'
@babel/types
'
)
const
traverse
=
require
(
'
@babel/traverse
'
).
default
const
{
VAR_ROOT
}
=
require
(
'
../../constants
'
)
function
isMatch
(
name
,
forItem
,
forIndex
)
{
return
name
===
forItem
||
name
===
forIndex
...
...
@@ -33,8 +38,36 @@ function findScoped (path, state) {
return
scoped
||
state
}
function
findTest
(
path
,
state
)
{
let
tests
while
(
path
.
parentPath
&&
path
.
key
!==
'
body
'
)
{
if
(
path
.
key
===
'
consequent
'
||
path
.
key
===
'
alternate
'
)
{
let
test
=
t
.
arrayExpression
([
t
.
clone
(
path
.
container
.
test
)])
traverse
(
test
,
{
noScope
:
true
,
MemberExpression
(
path
)
{
const
names
=
state
.
scoped
.
map
(
scoped
=>
scoped
.
forItem
)
const
node
=
path
.
node
const
objectName
=
node
.
object
.
name
if
(
objectName
===
VAR_ROOT
||
names
.
includes
(
objectName
))
{
path
.
replaceWith
(
node
.
property
)
}
}
})
test
=
test
.
elements
[
0
]
if
(
path
.
key
===
'
alternate
'
)
{
test
=
t
.
unaryExpression
(
'
!
'
,
test
)
}
tests
=
tests
?
t
.
logicalExpression
(
'
&&
'
,
test
,
tests
)
:
test
}
path
=
path
.
parentPath
}
return
tests
}
module
.
exports
=
function
getMemberExpr
(
path
,
name
,
init
,
state
,
variableDeclaration
=
true
)
{
const
scoped
=
findScoped
(
path
,
state
)
const
test
=
findTest
(
path
,
state
)
if
(
!
variableDeclaration
)
{
scoped
.
declarationArray
.
push
(
t
.
expressionStatement
(
init
))
...
...
@@ -45,7 +78,7 @@ module.exports = function getMemberExpr (path, name, init, state, variableDeclar
scoped
.
propertyArray
.
push
(
t
.
objectProperty
(
identifier
,
identifier
))
scoped
.
declarationArray
.
push
(
t
.
variableDeclaration
(
'
var
'
,
[
t
.
variableDeclarator
(
identifier
,
init
)])
t
.
variableDeclaration
(
'
var
'
,
[
t
.
variableDeclarator
(
identifier
,
test
?
t
.
conditionalExpression
(
test
,
init
,
t
.
nullLiteral
())
:
init
)])
)
state
.
identifierArray
.
push
(
identifier
)
...
...
packages/uni-template-compiler/lib/script/traverse/statements.js
浏览文件 @
8ed1ce87
...
...
@@ -43,20 +43,24 @@ function getMapCallExpression (
forIndex
)
{
const
blockStatement
=
[]
// var $orgi = __get_orig(forItem)
blockStatement
.
push
(
t
.
variableDeclaration
(
'
var
'
,
[
t
.
variableDeclarator
(
t
.
identifier
(
VAR_ORIGINAL
),
t
.
callExpression
(
t
.
identifier
(
INTERNAL_GET_ORIG
),
[
t
.
identifier
(
forItem
)
]))
]))
if
(
declarationArray
.
length
)
{
declarationArray
.
forEach
(
declaration
=>
{
blockStatement
.
push
(
declaration
)
})
blockStatement
.
push
(
t
.
returnStatement
(
// return {$orgi:
__get_orig(forItem)
}
// return {$orgi:
$orgi
}
t
.
objectExpression
(
[
t
.
objectProperty
(
t
.
identifier
(
VAR_ORIGINAL
),
t
.
callExpression
(
t
.
identifier
(
INTERNAL_GET_ORIG
),
[
t
.
identifier
(
forItem
)
])
t
.
identifier
(
VAR_ORIGINAL
)
)
].
concat
(
objectPropertyArray
)
)
...
...
@@ -116,4 +120,4 @@ module.exports = {
getMapCallExpression
,
getDataExpressionStatement
,
getEventExpressionStatement
}
}
src/platforms/h5/view/components/ad/index.vue
浏览文件 @
8ed1ce87
...
...
@@ -24,6 +24,9 @@ class AdConfig {
return
this
.
_instance
}
static
IC
=
0
static
IS
=
0
constructor
()
{
this
.
_instance
=
null
this
.
_adConfig
=
null
...
...
@@ -55,6 +58,7 @@ class AdConfig {
}
get
(
adpid
,
success
,
fail
)
{
AdConfig
.
IC
++
if
(
this
.
_adConfig
!=
null
)
{
this
.
_doCallback
(
adpid
,
success
,
fail
)
if
(
this
.
isExpired
)
{
...
...
@@ -73,6 +77,7 @@ class AdConfig {
}
_doCallback
(
adpid
,
success
,
fail
)
{
AdConfig
.
IS
++
var
data
=
this
.
_adConfig
if
(
data
[
adpid
])
{
success
(
data
[
adpid
])
...
...
@@ -267,7 +272,9 @@ export default {
AdReport
.
instance
.
get
({
h
:
__uniConfig
.
compilerVersion
,
a
:
this
.
adpid
,
at
:
30
at
:
30
,
ic
:
AdConfig
.
IC
,
is
:
AdConfig
.
IS
})
},
beforeDestroy
()
{
...
...
@@ -338,11 +345,16 @@ export default {
this
.
_startCheckTimer
()
},
_renderKY
(
data
)
{
var
randomId
=
this
.
_randomId
()
var
ad
=
document
.
createElement
(
'
script
'
)
ad
.
src
=
data
.
src
||
data
.
url
ad
.
src
=
(
data
.
src
||
data
.
url
)
+
'
&_ct=
'
+
randomId
var
adView
=
document
.
createElement
(
'
div
'
)
adView
.
setAttribute
(
'
id
'
,
randomId
)
adView
.
appendChild
(
ad
)
this
.
$refs
.
container
.
innerHTML
=
''
this
.
$refs
.
container
.
append
(
ad
)
this
.
$refs
.
container
.
append
(
ad
View
)
this
.
_startCheckTimer
()
},
...
...
@@ -390,6 +402,13 @@ export default {
t
:
taskId
,
at
:
type
})
},
_randomId
()
{
var
result
=
''
for
(
let
i
=
0
;
i
<
2
;
i
++
)
{
result
+=
(
65536
*
(
1
+
Math
.
random
())
|
0
).
toString
(
16
).
substring
(
1
)
}
return
result
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录