Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
luomor
uni-app
提交
0b74a921
uni-app
项目概览
luomor
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
0b74a921
编写于
8月 14, 2020
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: 解决组件属性使用复杂的对象表达式在小程序编译报错的问题 question/103944
上级
a7dee553
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
49 addition
and
44 deletion
+49
-44
packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js
...ni-template-compiler/__tests__/compiler-mp-weixin.spec.js
+1
-0
packages/uni-template-compiler/lib/script/traverse/data/attrs.js
...s/uni-template-compiler/lib/script/traverse/data/attrs.js
+16
-14
packages/uni-template-compiler/lib/script/traverse/member-expr.js
.../uni-template-compiler/lib/script/traverse/member-expr.js
+32
-30
未找到文件。
packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js
浏览文件 @
0b74a921
...
@@ -131,6 +131,7 @@ describe('mp:compiler-mp-weixin', () => {
...
@@ -131,6 +131,7 @@ describe('mp:compiler-mp-weixin', () => {
'
<block wx:for="{{({list1,list2})}}" wx:for-item="item" wx:for-index="key"></block>
'
'
<block wx:for="{{({list1,list2})}}" wx:for-item="item" wx:for-index="key"></block>
'
)
)
assertCodegen
(
'
<test :obj="{x:0}"></test>
'
,
'
<test vue-id="551070e6-1" obj="{{({x:0})}}" bind:__l="__l"></test>
'
)
assertCodegen
(
'
<test :obj="{x:0}"></test>
'
,
'
<test vue-id="551070e6-1" obj="{{({x:0})}}" bind:__l="__l"></test>
'
)
assertCodegen
(
'
<test :obj="{
\'
x
\'
:0}"></test>
'
,
'
<test vue-id="551070e6-1" obj="{{$root.a0}}" bind:__l="__l"></test>
'
,
'
with(this){var a0={"x":0};$mp.data=Object.assign({},{$root:{a0:a0}})}
'
)
})
})
it
(
'
generate v-show directive
'
,
()
=>
{
it
(
'
generate v-show directive
'
,
()
=>
{
...
...
packages/uni-template-compiler/lib/script/traverse/data/attrs.js
浏览文件 @
0b74a921
// const {
const
t
=
require
(
'
@babel/types
'
)
// IDENTIFIER_ATTR
// } = require('../../../constants')
// const getMemberExpr = require('../member-expr')
const
{
IDENTIFIER_ATTR
}
=
require
(
'
../../../constants
'
)
const
getMemberExpr
=
require
(
'
../member-expr
'
)
module
.
exports
=
function
processAttrs
(
paths
,
path
,
state
,
isComponent
,
tagName
)
{
module
.
exports
=
function
processAttrs
(
paths
,
path
,
state
,
isComponent
,
tagName
)
{
// 不再单独处理ObjectExpression,改为在转换temlplte时用()包裹(微信、QQ)
const
attrsPath
=
paths
.
attrs
// const attrsPath = paths.attrs
if
(
attrsPath
)
{
// if (attrsPath)
{
attrsPath
.
get
(
'
value.properties
'
).
forEach
(
propertyPath
=>
{
// attrsPath.get('value.properties').forEach(propertyPath => {
const
valuePath
=
propertyPath
.
get
(
'
value
'
)
// const valuePath = propertyPath.get('value')
// 对于普通的ObjectExpression不再单独处理,改为在转换temlplte时用()包裹(微信、QQ)
// if (valuePath.isObjectExpression(
)) {
if
(
valuePath
.
isObjectExpression
()
&&
valuePath
.
node
.
properties
.
find
(({
key
})
=>
!
t
.
isIdentifier
(
key
)
))
{
// valuePath.replaceWith(getMemberExpr(null
, IDENTIFIER_ATTR, valuePath.node, state))
valuePath
.
replaceWith
(
getMemberExpr
(
path
,
IDENTIFIER_ATTR
,
valuePath
.
node
,
state
))
//
}
}
//
})
})
//
}
}
return
[]
return
[]
}
}
packages/uni-template-compiler/lib/script/traverse/member-expr.js
浏览文件 @
0b74a921
...
@@ -42,41 +42,43 @@ function findScoped (path, state) {
...
@@ -42,41 +42,43 @@ function findScoped (path, state) {
function
findTest
(
path
,
state
)
{
function
findTest
(
path
,
state
)
{
let
tests
let
tests
while
(
path
.
parentPath
&&
path
.
key
!==
'
body
'
)
{
if
(
path
)
{
if
(
path
.
key
===
'
consequent
'
||
path
.
key
===
'
alternate
'
)
{
while
(
path
.
parentPath
&&
path
.
key
!==
'
body
'
)
{
const
testOrig
=
path
.
container
.
test
if
(
path
.
key
===
'
consequent
'
||
path
.
key
===
'
alternate
'
)
{
let
test
=
t
.
arrayExpression
([
t
.
cloneDeep
(
testOrig
)])
const
testOrig
=
path
.
container
.
test
traverse
(
test
,
{
let
test
=
t
.
arrayExpression
([
t
.
cloneDeep
(
testOrig
)])
noScope
:
true
,
traverse
(
test
,
{
MemberExpression
(
memberExpressionPath
)
{
noScope
:
true
,
const
names
=
state
.
scoped
.
map
(
scoped
=>
scoped
.
forItem
)
MemberExpression
(
memberExpressionPath
)
{
const
node
=
memberExpressionPath
.
node
const
names
=
state
.
scoped
.
map
(
scoped
=>
scoped
.
forItem
)
const
objectName
=
node
.
object
.
name
const
node
=
memberExpressionPath
.
node
const
property
=
node
.
property
const
objectName
=
node
.
object
.
name
const
propertyName
=
property
.
name
const
property
=
node
.
property
if
(
objectName
===
VAR_ROOT
||
(
names
.
includes
(
objectName
)
&&
(
propertyName
===
IDENTIFIER_METHOD
||
propertyName
===
IDENTIFIER_FILTER
)))
{
const
propertyName
=
property
.
name
let
property
if
(
objectName
===
VAR_ROOT
||
(
names
.
includes
(
objectName
)
&&
(
propertyName
===
IDENTIFIER_METHOD
||
propertyName
===
IDENTIFIER_FILTER
)))
{
traverse
(
testOrig
,
{
let
property
noScope
:
true
,
traverse
(
testOrig
,
{
Identifier
(
identifierPath
)
{
noScope
:
true
,
const
node
=
identifierPath
.
node
Identifier
(
identifierPath
)
{
if
(
node
.
name
===
propertyName
)
{
const
node
=
identifierPath
.
node
property
=
node
if
(
node
.
name
===
propertyName
)
{
identifierPath
.
stop
()
property
=
node
identifierPath
.
stop
()
}
}
}
}
}
)
}
)
memberExpressionPath
.
replaceWith
(
property
)
memberExpressionPath
.
replaceWith
(
property
)
}
}
}
})
test
=
test
.
elements
[
0
]
if
(
path
.
key
===
'
alternate
'
)
{
test
=
t
.
unaryExpression
(
'
!
'
,
test
)
}
}
})
tests
=
tests
?
t
.
logicalExpression
(
'
&&
'
,
test
,
tests
)
:
test
test
=
test
.
elements
[
0
]
if
(
path
.
key
===
'
alternate
'
)
{
test
=
t
.
unaryExpression
(
'
!
'
,
test
)
}
}
tests
=
tests
?
t
.
logicalExpression
(
'
&&
'
,
test
,
tests
)
:
test
path
=
path
.
parentPath
}
}
path
=
path
.
parentPath
}
}
return
tests
return
tests
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录