Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
e2f57caa
U
uni-app
项目概览
DCloud
/
uni-app
14 天 前同步成功
通知
751
Star
38709
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
8
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
8
Issue
8
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
e2f57caa
编写于
3月 11, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(mp): component support v-bind="props" (#3330)
上级
bccb592c
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
84 addition
and
31 deletion
+84
-31
packages/uni-app-plus/dist/uni-app-view.umd.js
packages/uni-app-plus/dist/uni-app-view.umd.js
+1
-1
packages/uni-cli-shared/src/json/mp/jsonFile.ts
packages/uni-cli-shared/src/json/mp/jsonFile.ts
+3
-3
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+5
-2
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-app-plus/dist/uni-app-view.umd.js
浏览文件 @
e2f57caa
此差异已折叠。
点击以展开。
packages/uni-cli-shared/src/json/mp/jsonFile.ts
浏览文件 @
e2f57caa
...
...
@@ -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-h5/dist/uni-h5.es.js
浏览文件 @
e2f57caa
...
...
@@ -9071,6 +9071,7 @@ function useTouchtrack(element, method, useCancel) {
let y1 = 0;
const fn = function($event, state2, x, y) {
if (method({
cancelable: $event.cancelable,
target: $event.target,
currentTarget: $event.currentTarget,
preventDefault: $event.preventDefault.bind($event),
...
...
@@ -10947,13 +10948,15 @@ function useScroller(element, options) {
if (scroller.onTouchStart) {
scroller.onTouchStart();
}
event.preventDefault();
if (typeof event.cancelable !== "boolean" || event.cancelable)
event.preventDefault();
}
function handleTouchMove(event) {
const touchtrackEvent = event;
const mouseEvent = event;
if (touchInfo.trackingID !== -1) {
event.preventDefault();
if (typeof event.cancelable !== "boolean" || event.cancelable)
event.preventDefault();
const delta = findDelta(event);
if (delta) {
for (touchInfo.maxDy = Math.max(touchInfo.maxDy, Math.abs(delta.y)), touchInfo.maxDx = Math.max(touchInfo.maxDx, Math.abs(delta.x)), touchInfo.historyX.push(delta.x), touchInfo.historyY.push(delta.y), touchInfo.historyTime.push(touchtrackEvent.detail.timeStamp || mouseEvent.timeStamp); touchInfo.historyTime.length > 10; ) {
...
...
packages/uni-mp-compiler/__tests__/component.spec.ts
浏览文件 @
e2f57caa
...
...
@@ -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
浏览文件 @
e2f57caa
...
...
@@ -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
浏览文件 @
e2f57caa
...
...
@@ -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
浏览文件 @
e2f57caa
...
...
@@ -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
浏览文件 @
e2f57caa
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录