Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
genary
uni-app
提交
fefb7bbd
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,发现更多精彩内容 >>
提交
fefb7bbd
编写于
3月 11, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
差异文件
chore: merge
上级
e4a5786a
96deecbd
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
78 addition
and
28 deletion
+78
-28
packages/uni-cli-shared/src/json/mp/jsonFile.ts
packages/uni-cli-shared/src/json/mp/jsonFile.ts
+3
-3
packages/uni-mp-compiler/__tests__/component.spec.ts
packages/uni-mp-compiler/__tests__/component.spec.ts
+18
-2
packages/uni-mp-compiler/__tests__/test.ts
packages/uni-mp-compiler/__tests__/test.ts
+1
-1
packages/uni-mp-compiler/src/template/codegen.ts
packages/uni-mp-compiler/src/template/codegen.ts
+3
-1
packages/uni-mp-compiler/src/transforms/transformComponent.ts
...ages/uni-mp-compiler/src/transforms/transformComponent.ts
+33
-6
packages/uni-mp-compiler/src/transforms/transformElement.ts
packages/uni-mp-compiler/src/transforms/transformElement.ts
+20
-15
未找到文件。
packages/uni-cli-shared/src/json/mp/jsonFile.ts
浏览文件 @
fefb7bbd
...
...
@@ -171,10 +171,10 @@ function findMiniProgramUsingComponent(
return
Object
.
keys
(
usingComponents
).
reduce
<
MiniProgramComponents
>
(
(
res
,
name
)
=>
{
const
path
=
usingComponents
[
name
]
if
(
componentsDir
&&
path
.
includes
(
componentsDir
+
'
/
'
))
{
res
[
name
]
=
'
component
'
}
else
if
(
path
.
includes
(
'
plugin://
'
))
{
if
(
path
.
includes
(
'
plugin://
'
))
{
res
[
name
]
=
'
plugin
'
}
else
if
(
componentsDir
&&
path
.
includes
(
componentsDir
+
'
/
'
))
{
res
[
name
]
=
'
component
'
}
return
res
},
...
...
packages/uni-mp-compiler/__tests__/component.spec.ts
浏览文件 @
fefb7bbd
...
...
@@ -3,6 +3,7 @@ import {
COMPONENT_BIND_LINK
,
createTransformComponentLink
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
MPErrorCodes
}
from
'
../src/errors
'
import
{
assert
}
from
'
./testUtils
'
const
nodeTransforms
=
[
createTransformComponentLink
(
COMPONENT_BIND_LINK
)]
...
...
@@ -116,6 +117,7 @@ describe('compiler: transform component', () => {
})
test
(
`mini program component`
,
()
=>
{
const
onError
=
jest
.
fn
()
const
filename
=
'
pages/vant/vant
'
addMiniProgramPageJson
(
filename
,
{
usingComponents
:
{
...
...
@@ -124,15 +126,29 @@ describe('compiler: transform component', () => {
},
})
assert
(
`<wxparser :rich-text="richText"
/><van-button custom-style="background-color: unset;" :close-on-click-overlay="true
"><template #default><view/></template><template #head><view/></template></van-button>`
,
`<wxparser :rich-text="richText"
v-bind="props"/><van-button custom-style="background-color: unset;" :close-on-click-overlay="true" v-bind="props
"><template #default><view/></template><template #head><view/></template></van-button>`
,
`<wxparser rich-text="{{a}}" u-t="m" u-i="dc555fe4-0" bind:__l="__l"/><van-button u-t="m" u-i="dc555fe4-1" bind:__l="__l" u-p="{{b}}"><view/><view slot="head"/></van-button>`
,
`(_ctx, _cache) => {
return { a: _ctx.richText, b: _p({ customStyle: 'background-color: unset;', closeOnClickOverlay: true }) }
return { a: _ctx.richText, b: _p({ customStyle: 'background-color: unset;', closeOnClickOverlay: true
, ..._ctx.props
}) }
}`
,
{
onError
,
filename
,
nodeTransforms
,
}
)
expect
(
onError
.
mock
.
calls
[
0
][
0
]).
toMatchObject
({
code
:
MPErrorCodes
.
X_V_BIND_NO_ARGUMENT
,
loc
:
{
start
:
{
line
:
1
,
column
:
33
,
},
end
:
{
line
:
1
,
column
:
47
,
},
},
})
})
})
packages/uni-mp-compiler/__tests__/test.ts
浏览文件 @
fefb7bbd
...
...
@@ -60,7 +60,7 @@ addMiniProgramPageJson(filename, {
},
})
assert
(
`<van-button><template #default><view/></template></van-button>`
,
`<van-button
v-bind="a"
><template #default><view/></template></van-button>`
,
`<van-button u-i="dc555fe4-0"/>`
,
`(_ctx, _cache) => {
return {}
...
...
packages/uni-mp-compiler/src/template/codegen.ts
浏览文件 @
fefb7bbd
...
...
@@ -448,6 +448,8 @@ function genDirectiveNode(
const
exp
=
(
prop
.
exp
as
SimpleExpressionNode
).
content
push
(
`
${
arg
}
="{{
${
exp
}
}}"`
)
}
else
{
throw
new
Error
(
`unknown directive`
+
JSON
.
stringify
(
prop
))
if
(
prop
.
name
!==
'
bind
'
)
{
throw
new
Error
(
`unknown directive `
+
JSON
.
stringify
(
prop
))
}
}
}
packages/uni-mp-compiler/src/transforms/transformComponent.ts
浏览文件 @
fefb7bbd
...
...
@@ -11,6 +11,8 @@ import {
import
{
createAttributeNode
,
createBindDirectiveNode
,
isAttributeNode
,
isDirectiveNode
,
isUserComponent
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
isVForScope
,
NodeTransform
,
TransformContext
}
from
'
../transform
'
...
...
@@ -31,6 +33,8 @@ import {
objectExpression
,
objectProperty
,
ObjectProperty
,
spreadElement
,
SpreadElement
,
stringLiteral
,
}
from
'
@babel/types
'
import
{
RENDER_PROPS
}
from
'
../runtimeHelpers
'
...
...
@@ -165,11 +169,10 @@ export function rewriteBinding(
computed
)
}
const
properties
:
ObjectProperty
[]
=
[]
const
properties
:
(
ObjectProperty
|
SpreadElement
)[]
=
[]
for
(
let
i
=
0
;
i
<
props
.
length
;
i
++
)
{
const
prop
=
props
[
i
]
if
(
prop
.
type
===
NodeTypes
.
ATTRIBUTE
)
{
if
(
isAttributeNode
(
prop
)
)
{
const
{
name
}
=
prop
if
(
!
isComponentProp
(
name
))
{
continue
...
...
@@ -177,15 +180,20 @@ export function rewriteBinding(
properties
.
push
(
createObjectProperty
(
name
,
stringLiteral
(
prop
.
value
?.
content
||
''
))
)
}
else
if
(
prop
.
type
===
NodeTypes
.
DIRECTIVE
)
{
}
else
if
(
isDirectiveNode
(
prop
)
)
{
if
(
prop
.
name
!==
'
bind
'
)
{
continue
}
const
{
arg
,
exp
}
=
prop
if
(
!
arg
||
!
exp
)
{
if
(
!
exp
)
{
continue
}
if
(
isStaticExp
(
arg
))
{
if
(
!
arg
)
{
const
spreadElement
=
createVBindSpreadElement
(
prop
,
context
)
if
(
spreadElement
)
{
properties
.
push
(
spreadElement
)
}
}
else
if
(
isStaticExp
(
arg
))
{
if
(
!
isComponentProp
(
arg
.
content
))
{
continue
}
...
...
@@ -217,6 +225,7 @@ export function rewriteBinding(
props
.
splice
(
i
,
1
)
i
--
}
if
(
properties
.
length
)
{
props
.
push
(
createBindDirectiveNode
(
...
...
@@ -226,6 +235,24 @@ export function rewriteBinding(
)
}
}
function
createVBindSpreadElement
(
prop
:
DirectiveNode
,
context
:
TransformContext
)
{
const
{
arg
,
exp
}
=
prop
if
(
!
exp
)
{
return
}
if
(
!
arg
)
{
const
argument
=
parseExpr
(
genExpr
(
exp
),
context
,
exp
)
if
(
!
argument
)
{
return
}
return
spreadElement
(
argument
)
}
}
export
function
isPropsBinding
({
arg
}:
DirectiveNode
)
{
return
(
arg
&&
...
...
packages/uni-mp-compiler/src/transforms/transformElement.ts
浏览文件 @
fefb7bbd
...
...
@@ -176,7 +176,8 @@ export function processProps(
)
{
const
{
tag
}
=
node
const
isComponent
=
node
.
tagType
===
ElementTypes
.
COMPONENT
const
isPluginComponent
=
isComponent
&&
context
.
isMiniProgramComponent
(
node
.
tag
)
===
'
plugin
'
for
(
let
i
=
0
;
i
<
props
.
length
;
i
++
)
{
const
prop
=
props
[
i
]
if
(
prop
.
type
===
NodeTypes
.
DIRECTIVE
)
{
...
...
@@ -209,14 +210,16 @@ export function processProps(
// v-on=""
// v-bind=""
if
(
!
arg
)
{
context
.
onError
(
createMPCompilerError
(
isVBind
?
MPErrorCodes
.
X_V_BIND_NO_ARGUMENT
:
MPErrorCodes
.
X_V_ON_NO_ARGUMENT
,
loc
if
(
isVOn
)
{
context
.
onError
(
createMPCompilerError
(
MPErrorCodes
.
X_V_ON_NO_ARGUMENT
,
loc
)
)
)
}
if
(
isVBind
&&
(
!
isComponent
||
isPluginComponent
))
{
context
.
onError
(
createMPCompilerError
(
MPErrorCodes
.
X_V_BIND_NO_ARGUMENT
,
loc
)
)
}
continue
}
// v-on:[a]=""
...
...
@@ -224,14 +227,16 @@ export function processProps(
// v-bind:[a]=""
// v-bind:[a.b]=""
if
(
!
(
arg
.
type
===
NodeTypes
.
SIMPLE_EXPRESSION
&&
arg
.
isStatic
))
{
context
.
onError
(
createMPCompilerError
(
isVBind
?
MPErrorCodes
.
X_V_BIND_DYNAMIC_ARGUMENT
:
MPErrorCodes
.
X_V_ON_DYNAMIC_EVENT
,
loc
if
(
isVOn
)
{
context
.
onError
(
createMPCompilerError
(
MPErrorCodes
.
X_V_ON_DYNAMIC_EVENT
,
loc
)
)
)
}
if
(
isVBind
&&
(
!
isComponent
||
isPluginComponent
))
{
context
.
onError
(
createMPCompilerError
(
MPErrorCodes
.
X_V_BIND_DYNAMIC_ARGUMENT
,
loc
)
)
}
continue
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录