Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yangkaifeng
uni-app
提交
02dc0d9a
U
uni-app
项目概览
yangkaifeng
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
3
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,发现更多精彩内容 >>
提交
02dc0d9a
编写于
10月 22, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(mp): serialize render data
上级
e29ab96f
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
47 addition
and
11 deletion
+47
-11
packages/uni-mp-compiler/__tests__/class.spec.ts
packages/uni-mp-compiler/__tests__/class.spec.ts
+6
-6
packages/uni-mp-compiler/__tests__/scope.spec.ts
packages/uni-mp-compiler/__tests__/scope.spec.ts
+1
-1
packages/uni-mp-compiler/__tests__/test.spec.ts
packages/uni-mp-compiler/__tests__/test.spec.ts
+3
-3
packages/uni-mp-compiler/src/transforms/transformClass.ts
packages/uni-mp-compiler/src/transforms/transformClass.ts
+2
-1
packages/uni-mp-compiler/src/transforms/utils.ts
packages/uni-mp-compiler/src/transforms/utils.ts
+21
-0
packages/uni-mp-vue/dist/vue.runtime.esm.js
packages/uni-mp-vue/dist/vue.runtime.esm.js
+7
-0
packages/uni-mp-vue/lib/vue.runtime.esm.js
packages/uni-mp-vue/lib/vue.runtime.esm.js
+7
-0
未找到文件。
packages/uni-mp-compiler/__tests__/class.spec.ts
浏览文件 @
02dc0d9a
...
...
@@ -61,14 +61,14 @@ describe('compiler: transform class', () => {
`<view :class="{ red:
\`\$
{isRed}
\`
}"/>`
,
`<view class="{{[a && 'red']}}"/>`
,
`(_ctx, _cache) => {
return { a:
\`\$
{_ctx.isRed}
\`
}
return { a:
\`\$
{_ctx.isRed}
\`
? 1 : 0
}
}`
)
assert
(
`<view :class="{ a: 1, b: 0, c: true, d: false, e: null, f: undefined, g: ok, h: handle(ok), i: ok>1, j, [k]:1, [l]:m, ...n, ...{a:true}, ...{b:o} }"/>`
,
`<view class="{{['a', 'c', a && 'g', b && 'h', c && 'i', d && 'j', e, g && f, h, i, j]}}"/>`
,
`(_ctx, _cache) => {
return { a: _ctx.ok
, b: _ctx.handle(_ctx.ok), c: _ctx.ok > 1, d: _ctx.j, e: _ctx.k, f: _ctx.l, g: _ctx.m
, h: _normalizeClass(_ctx.n), i: _normalizeClass({ a: true }), j: _normalizeClass({ b: _ctx.o }) }
return { a: _ctx.ok
? 1 : 0, b: _ctx.handle(_ctx.ok) ? 1 : 0, c: _ctx.ok > 1 ? 1 : 0, d: _ctx.j ? 1 : 0, e: _ctx.k, f: _ctx.l, g: _ctx.m ? 1 : 0
, h: _normalizeClass(_ctx.n), i: _normalizeClass({ a: true }), j: _normalizeClass({ b: _ctx.o }) }
}`
)
})
...
...
@@ -77,28 +77,28 @@ describe('compiler: transform class', () => {
`<view :class="{ red: isRed }" class="foo bar"/>`
,
`<view class="{{[a && 'red', 'foo bar']}}"/>`
,
`(_ctx, _cache) => {
return { a: _ctx.isRed }
return { a: _ctx.isRed
? 1 : 0
}
}`
)
assert
(
`<view class="foo bar" :class="{ red: isRed }"/>`
,
`<view class="{{['foo bar', a && 'red']}}"/>`
,
`(_ctx, _cache) => {
return { a: _ctx.isRed }
return { a: _ctx.isRed
? 1 : 0
}
}`
)
assert
(
`<view :class="{ a: 1, b: 0, c: true, d: false, e: null, f: undefined, g: ok, h: handle(ok), i: ok>1, j, [k]:1, [l]:m, ...n, ...{a:true}, ...{b:o} }" class="foo bar"/>`
,
`<view class="{{['a', 'c', a && 'g', b && 'h', c && 'i', d && 'j', e, g && f, h, i, j, 'foo bar']}}"/>`
,
`(_ctx, _cache) => {
return { a: _ctx.ok
, b: _ctx.handle(_ctx.ok), c: _ctx.ok > 1, d: _ctx.j, e: _ctx.k, f: _ctx.l, g: _ctx.m
, h: _normalizeClass(_ctx.n), i: _normalizeClass({ a: true }), j: _normalizeClass({ b: _ctx.o }) }
return { a: _ctx.ok
? 1 : 0, b: _ctx.handle(_ctx.ok) ? 1 : 0, c: _ctx.ok > 1 ? 1 : 0, d: _ctx.j ? 1 : 0, e: _ctx.k, f: _ctx.l, g: _ctx.m ? 1 : 0
, h: _normalizeClass(_ctx.n), i: _normalizeClass({ a: true }), j: _normalizeClass({ b: _ctx.o }) }
}`
)
assert
(
`<view class="foo bar" :class="{ a: 1, b: 0, c: true, d: false, e: null, f: undefined, g: ok, h: handle(ok), i: ok>1, j, [k]:1, [l]:m, ...n, ...{a:true}, ...{b:o} }"/>`
,
`<view class="{{['foo bar', 'a', 'c', a && 'g', b && 'h', c && 'i', d && 'j', e, g && f, h, i, j]}}"/>`
,
`(_ctx, _cache) => {
return { a: _ctx.ok
, b: _ctx.handle(_ctx.ok), c: _ctx.ok > 1, d: _ctx.j, e: _ctx.k, f: _ctx.l, g: _ctx.m
, h: _normalizeClass(_ctx.n), i: _normalizeClass({ a: true }), j: _normalizeClass({ b: _ctx.o }) }
return { a: _ctx.ok
? 1 : 0, b: _ctx.handle(_ctx.ok) ? 1 : 0, c: _ctx.ok > 1 ? 1 : 0, d: _ctx.j ? 1 : 0, e: _ctx.k, f: _ctx.l, g: _ctx.m ? 1 : 0
, h: _normalizeClass(_ctx.n), i: _normalizeClass({ a: true }), j: _normalizeClass({ b: _ctx.o }) }
}`
)
})
...
...
packages/uni-mp-compiler/__tests__/scope.spec.ts
浏览文件 @
02dc0d9a
...
...
@@ -6,7 +6,7 @@ describe('compiler: scope', () => {
`<view v-for="item in items" :key="item.id" :class="{red: item.isRed}" @longpress="longpress" @click="onClick(item)">{{item.title}}</view>`
,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="b" class="{{[item.c && 'red']}}" bindlongpress="{{b}}" bindtap="{{item.d}}">{{item.a}}</view>`
,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: _toDisplayString(item.title), b: item.id, c: item.isRed, d: _vOn($event => _ctx.onClick(item)) }; }), b: _vOn(_ctx.longpress) }
return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: _toDisplayString(item.title), b: item.id, c: item.isRed
? 1 : 0
, d: _vOn($event => _ctx.onClick(item)) }; }), b: _vOn(_ctx.longpress) }
}`
)
})
...
...
packages/uni-mp-compiler/__tests__/test.spec.ts
浏览文件 @
02dc0d9a
...
...
@@ -37,10 +37,10 @@ function assert(
describe
(
'
compiler
'
,
()
=>
{
test
(
'
scope
'
,
()
=>
{
assert
(
`<view :
style="{ color:
\`\$
{green}px
\`
}"/>`
,
`<view
style="{{'color:' + a
}}"/>`
,
`<view :
class="{ red: isRed
}"/>`
,
`<view
class="{{[a && 'red']
}}"/>`
,
`(_ctx, _cache) => {
return { a:
\`\$
{_ctx.green}px
\`
}
return { a:
_ctx.isRed ? 1 : 0
}
}`
)
})
...
...
packages/uni-mp-compiler/src/transforms/transformClass.ts
浏览文件 @
02dc0d9a
...
...
@@ -35,6 +35,7 @@ import { genBabelExpr } from '../codegen'
import
{
TransformContext
}
from
'
../transform
'
import
{
parseExprWithRewrite
,
parseExprWithRewriteClass
,
rewriteExpression
,
rewriteSpreadElement
,
}
from
'
./utils
'
...
...
@@ -160,7 +161,7 @@ function rewriteClassObjectExpression(
if
(
isLiteral
(
value
)
&&
!
isTemplateLiteral
(
value
))
{
return
}
else
{
const
newExpr
=
parseExprWithRewrite
(
const
newExpr
=
parseExprWithRewrite
Class
(
genBabelExpr
(
value
as
Expression
),
loc
,
context
,
...
...
packages/uni-mp-compiler/src/transforms/utils.ts
浏览文件 @
02dc0d9a
import
{
conditionalExpression
,
Expression
,
Identifier
,
identifier
,
isIdentifier
,
isReferenced
,
MemberExpression
,
numericLiteral
,
objectProperty
,
SpreadElement
,
}
from
'
@babel/types
'
...
...
@@ -54,6 +56,25 @@ export function parseExprWithRewrite(
)
as
Identifier
|
MemberExpression
|
undefined
}
export
function
parseExprWithRewriteClass
(
code
:
string
,
loc
:
SourceLocation
,
context
:
TransformContext
,
node
:
Expression
)
{
// a?1:0
return
parseExpr
(
rewriteExpression
(
createSimpleExpression
(
code
,
false
,
loc
),
context
,
!
isUndefined
(
node
)
?
conditionalExpression
(
node
,
numericLiteral
(
1
),
numericLiteral
(
0
))
:
node
),
context
)
as
Identifier
|
MemberExpression
|
undefined
}
export
function
rewriteExpression
(
node
:
ExpressionNode
,
context
:
TransformContext
,
...
...
packages/uni-mp-vue/dist/vue.runtime.esm.js
浏览文件 @
02dc0d9a
...
...
@@ -4548,6 +4548,13 @@ function getMPInstanceData(instance, keys) {
return
ret
;
}
function
patch
(
instance
,
data
)
{
if
(
!
data
)
{
return
;
}
// 序列化
pauseTracking
();
data
=
JSON
.
parse
(
JSON
.
stringify
(
data
));
resetTracking
();
const
ctx
=
instance
.
ctx
;
const
mpType
=
ctx
.
mpType
;
if
(
mpType
===
'
page
'
||
mpType
===
'
component
'
)
{
...
...
packages/uni-mp-vue/lib/vue.runtime.esm.js
浏览文件 @
02dc0d9a
...
...
@@ -4480,6 +4480,13 @@ function getMPInstanceData(instance, keys) {
return
ret
;
}
function
patch
(
instance
,
data
)
{
if
(
!
data
)
{
return
;
}
// 序列化
pauseTracking
();
data
=
JSON
.
parse
(
JSON
.
stringify
(
data
));
resetTracking
();
const
ctx
=
instance
.
ctx
;
const
mpType
=
ctx
.
mpType
;
if
(
mpType
===
'
page
'
||
mpType
===
'
component
'
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录