Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小浣熊撸代码
uni-app
提交
4084674e
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,发现更多精彩内容 >>
提交
4084674e
编写于
10月 20, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(mp): ref
上级
92682ab7
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
45 addition
and
4 deletion
+45
-4
packages/uni-mp-compiler/__tests__/ref.spec.ts
packages/uni-mp-compiler/__tests__/ref.spec.ts
+25
-0
packages/uni-mp-compiler/__tests__/test.spec.ts
packages/uni-mp-compiler/__tests__/test.spec.ts
+2
-2
packages/uni-mp-compiler/src/transforms/transformElement.ts
packages/uni-mp-compiler/src/transforms/transformElement.ts
+17
-2
packages/uni-mp-compiler/src/transforms/vFor.ts
packages/uni-mp-compiler/src/transforms/vFor.ts
+1
-0
未找到文件。
packages/uni-mp-compiler/__tests__/ref.spec.ts
浏览文件 @
4084674e
...
...
@@ -7,6 +7,13 @@ describe('compiler: transform ref', () => {
`<custom class="vue-ref"/>`
,
`(_ctx, _cache) => {
return {}
}`
)
assert
(
`<custom/><custom/>`
,
`<custom class="vue-ref"/><custom class="vue-ref"/>`
,
`(_ctx, _cache) => {
return {}
}`
)
})
...
...
@@ -16,6 +23,24 @@ describe('compiler: transform ref', () => {
`<custom wx:for="{{a}}" wx:for-item="item" class="vue-ref-in-for"/>`
,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, item => { return {}; }) }
}`
)
})
test
(
'
static ref
'
,
()
=>
{
assert
(
`<custom ref="custom"/>`
,
`<custom class="vue-ref" data-ref="custom"/>`
,
`(_ctx, _cache) => {
return {}
}`
)
})
test
(
'
dynamic ref
'
,
()
=>
{
assert
(
`<custom :ref="custom"/>`
,
`<custom class="vue-ref" data-ref="{{a}}"/>`
,
`(_ctx, _cache) => {
return { a: _ctx.custom }
}`
)
})
...
...
packages/uni-mp-compiler/__tests__/test.spec.ts
浏览文件 @
4084674e
...
...
@@ -37,10 +37,10 @@ function assert(
describe
(
'
compiler
'
,
()
=>
{
test
(
'
scope
'
,
()
=>
{
assert
(
`<
template v-if="ok"><view/>hello<view/></template
>`
,
`<
view :style="{ color:
\`\$
{green}px
\`
}"/
>`
,
`<view style="{{'color:' + a}}"/>`
,
`(_ctx, _cache) => {
return { a:
_ctx.ok, ...(_ctx.ok ? {} : {})
}
return { a:
\`\$
{_ctx.green}px
\`
}
}`
)
})
...
...
packages/uni-mp-compiler/src/transforms/transformElement.ts
浏览文件 @
4084674e
...
...
@@ -95,7 +95,7 @@ function addVueRef(node: ElementNode, context: TransformContext) {
function
processComponent
(
node
:
ElementNode
,
context
:
TransformContext
)
{
const
{
tag
}
=
node
if
(
context
.
bindingComponents
[
tag
])
{
return
return
addVueRef
(
node
,
context
)
}
// 1. dynamic component
...
...
@@ -217,7 +217,12 @@ function processProps(node: ElementNode, context: TransformContext) {
for
(
let
i
=
0
;
i
<
props
.
length
;
i
++
)
{
const
prop
=
props
[
i
]
if
(
prop
.
type
===
NodeTypes
.
DIRECTIVE
)
{
if
(
prop
.
type
===
NodeTypes
.
ATTRIBUTE
)
{
// <custom ref="c"/> => <custom data-ref="c"/>
if
(
prop
.
name
===
'
ref
'
)
{
prop
.
name
=
'
data-ref
'
}
}
else
{
// directives
const
{
name
,
arg
,
loc
}
=
prop
const
isVBind
=
name
===
'
bind
'
...
...
@@ -276,6 +281,16 @@ function processProps(node: ElementNode, context: TransformContext) {
}
}
if
(
isVBind
)
{
// <custom :ref="c"/> => <custom :data-ref="c" />
if
(
arg
?.
type
===
NodeTypes
.
SIMPLE_EXPRESSION
&&
arg
.
content
===
'
ref
'
)
{
arg
.
content
=
'
data-ref
'
}
}
const
directiveTransform
=
context
.
directiveTransforms
[
name
]
if
(
directiveTransform
)
{
prop
.
exp
=
directiveTransform
(
prop
,
node
,
context
).
props
[
0
]
...
...
packages/uni-mp-compiler/src/transforms/vFor.ts
浏览文件 @
4084674e
...
...
@@ -131,6 +131,7 @@ export const transformFor = createStructuralDirectiveTransform(
scopes
.
vFor
++
return
()
=>
{
scopes
.
vFor
--
if
(
isTemplateNode
(
node
))
{
node
.
children
.
some
((
c
)
=>
{
if
(
c
.
type
===
NodeTypes
.
ELEMENT
&&
!
isForElementNode
(
c
))
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录