Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
34efd782
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
720
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
34efd782
编写于
8月 10, 2023
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore: merge
上级
1263e73d
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
74 addition
and
68 deletion
+74
-68
packages/uni-app-uts/__tests__/transforms/vBind.spec.ts
packages/uni-app-uts/__tests__/transforms/vBind.spec.ts
+6
-0
packages/uni-app-uts/__tests__/transforms/vOn.spec.ts
packages/uni-app-uts/__tests__/transforms/vOn.spec.ts
+1
-1
packages/uni-app-uts/src/plugins/uvue/compiler/codegen.ts
packages/uni-app-uts/src/plugins/uvue/compiler/codegen.ts
+0
-20
packages/uni-app-uts/src/plugins/uvue/compiler/index.ts
packages/uni-app-uts/src/plugins/uvue/compiler/index.ts
+3
-2
packages/uni-app-uts/src/plugins/uvue/compiler/transforms/transformExpression.ts
...c/plugins/uvue/compiler/transforms/transformExpression.ts
+5
-3
packages/uni-app-uts/src/plugins/uvue/compiler/transforms/transformObjectExpression.ts
...ins/uvue/compiler/transforms/transformObjectExpression.ts
+25
-0
packages/uni-app-uts/src/plugins/uvue/compiler/transforms/vBind.ts
...uni-app-uts/src/plugins/uvue/compiler/transforms/vBind.ts
+0
-34
packages/uni-app-uts/src/plugins/uvue/compiler/utils.ts
packages/uni-app-uts/src/plugins/uvue/compiler/utils.ts
+34
-8
packages/uts-darwin-arm64/uts.darwin-arm64.node
packages/uts-darwin-arm64/uts.darwin-arm64.node
+0
-0
packages/uts-darwin-x64/uts.darwin-x64.node
packages/uts-darwin-x64/uts.darwin-x64.node
+0
-0
packages/uts-linux-x64-gnu/uts.linux-x64-gnu.node
packages/uts-linux-x64-gnu/uts.linux-x64-gnu.node
+0
-0
packages/uts-linux-x64-musl/uts.linux-x64-musl.node
packages/uts-linux-x64-musl/uts.linux-x64-musl.node
+0
-0
未找到文件。
packages/uni-app-uts/__tests__/transforms/vBind.spec.ts
浏览文件 @
34efd782
...
...
@@ -49,6 +49,12 @@ describe('compiler: v-bind', () => {
`createElementVNode("view", utsMapOf({ id: _ctx.id }), null, 8 /* PROPS */, ["id"])`
)
})
test
(
'
object expression
'
,
()
=>
{
assert
(
`<view v-bind="{id}"/>`
,
`createElementVNode("view", normalizeProps(guardReactiveProps(utsMapOf({id: _ctx.id}))), null, 16 /* FULL_PROPS */)`
)
})
test
(
'
dynamic arg
'
,
()
=>
{
assert
(
`<view v-bind:[id]="id"/>`
,
...
...
packages/uni-app-uts/__tests__/transforms/vOn.spec.ts
浏览文件 @
34efd782
...
...
@@ -175,7 +175,7 @@ _ctx.bar()
test
(
'
empty object syntax
'
,
()
=>
{
assert
(
`<text v-on="{ }"/>`
,
`createElementVNode("text", toHandlers(utsMapOf({ }), true), null, 16 /* FULL_PROPS */)`
`createElementVNode("text", toHandlers(utsMapOf
<string, any | null>
({ }), true), null, 16 /* FULL_PROPS */)`
)
})
test
(
'
simple object syntax
'
,
()
=>
{
...
...
packages/uni-app-uts/src/plugins/uvue/compiler/codegen.ts
浏览文件 @
34efd782
...
...
@@ -42,12 +42,7 @@ import {
RESOLVE_COMPONENT
,
RESOLVE_DIRECTIVE
,
RESOLVE_EASY_COMPONENT
,
TO_HANDLERS
,
}
from
'
./runtimeHelpers
'
import
{
isCompoundExpressionNode
,
isSimpleExpressionNode
,
}
from
'
@dcloudio/uni-cli-shared
'
type
CodegenNode
=
TemplateChildNode
|
JSChildNode
|
SSRCodegenNode
...
...
@@ -539,9 +534,6 @@ function genCallExpression(node: CallExpression, context: CodegenContext) {
if
(
callee
===
helper
(
RENDER_LIST
))
{
genRenderList
(
node
)
}
if
(
callee
===
helper
(
TO_HANDLERS
))
{
genToHandlers
(
node
,
context
)
}
genNodeList
(
node
.
arguments
,
context
)
push
(
`)`
)
...
...
@@ -555,18 +547,6 @@ function genRenderList(node: CallExpression) {
})
}
function
genToHandlers
(
node
:
CallExpression
,
context
:
CodegenContext
)
{
const
args
=
node
.
arguments
[
0
]
if
(
isString
(
args
)
||
isSymbol
(
args
)
||
isArray
(
args
))
{
// skip
}
else
if
(
isSimpleExpressionNode
(
args
))
{
args
.
content
=
`utsMapOf(
${
args
.
content
}
)`
}
else
if
(
isCompoundExpressionNode
(
args
))
{
args
.
children
.
unshift
(
`utsMapOf(`
)
args
.
children
.
push
(
'
)
'
)
}
}
function
genObjectExpression
(
node
:
ObjectExpression
,
context
:
CodegenContext
)
{
const
{
push
,
indent
,
deindent
,
newline
}
=
context
const
{
properties
}
=
node
...
...
packages/uni-app-uts/src/plugins/uvue/compiler/index.ts
浏览文件 @
34efd782
...
...
@@ -4,7 +4,6 @@ import {
trackSlotScopes
,
trackVForSlotScopes
,
transformElement
,
transformExpression
,
}
from
'
@vue/compiler-core
'
import
{
isAppUVueNativeTag
}
from
'
@dcloudio/uni-shared
'
...
...
@@ -24,7 +23,8 @@ import { transformText } from './transforms/transformText'
import
{
transformOn
}
from
'
./transforms/vOn
'
import
{
transformBind
}
from
'
./transforms/vBind
'
import
{
transformSlotOutlet
}
from
'
./transforms/transformSlotOutlet
'
// import { transformExpression } from './transforms/transformExpression'
import
{
transformObjectExpression
}
from
'
./transforms/transformObjectExpression
'
import
{
transformExpression
}
from
'
./transforms/transformExpression
'
export
type
TransformPreset
=
[
NodeTransform
[],
...
...
@@ -47,6 +47,7 @@ export function getBaseTransformPreset(
transformText
,
transformTapToClick
,
transformInterpolation
,
transformObjectExpression
,
]
as
any
,
{
on
:
transformOn
,
...
...
packages/uni-app-uts/src/plugins/uvue/compiler/transforms/transformExpression.ts
浏览文件 @
34efd782
...
...
@@ -31,9 +31,11 @@ import {
import
{
createCompilerError
,
ErrorCodes
}
from
'
../errors
'
const
GLOBALS_WHITE_LISTED
=
`Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,
decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,
Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console`
const
GLOBALS_WHITE_LISTED
=
`Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI`
+
`,decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array`
+
`,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt`
+
`,console`
const
isGloballyWhitelisted
=
/*#__PURE__*/
makeMap
(
GLOBALS_WHITE_LISTED
)
const
isLiteralWhitelisted
=
/*#__PURE__*/
makeMap
(
'
true,false,null,this
'
)
...
...
packages/uni-app-uts/src/plugins/uvue/compiler/transforms/transformObjectExpression.ts
0 → 100644
浏览文件 @
34efd782
import
{
isDirectiveNode
,
isElementNode
}
from
'
@dcloudio/uni-cli-shared
'
import
{
NodeTransform
}
from
'
../transform
'
import
{
rewriteObjectExpression
}
from
'
../utils
'
export
const
transformObjectExpression
:
NodeTransform
=
(
node
,
context
)
=>
{
// 因为 v-bind without arg 是被 transformElements.ts 直接处理的,没办法在 vBind 中解析处理objectExpression
// 所以 统一在这里拦截处理
return
function
postTransformObjectExpression
()
{
node
=
context
.
currentNode
!
if
(
!
isElementNode
(
node
))
{
return
}
node
.
props
.
forEach
((
p
)
=>
{
if
(
!
isDirectiveNode
(
p
)
||
!
p
.
exp
)
{
return
}
if
(
p
.
name
===
'
bind
'
||
p
.
name
===
'
on
'
)
{
const
newExp
=
rewriteObjectExpression
(
p
.
exp
,
context
)
if
(
newExp
)
{
p
.
exp
=
newExp
}
}
})
}
}
packages/uni-app-uts/src/plugins/uvue/compiler/transforms/vBind.ts
浏览文件 @
34efd782
import
{
camelize
}
from
'
@vue/shared
'
import
{
parseExpression
}
from
'
@babel/parser
'
import
type
{
Node
}
from
'
@babel/types
'
import
{
CAMELIZE
}
from
'
@vue/compiler-core
'
import
{
createObjectProperty
,
...
...
@@ -12,9 +10,6 @@ import {
import
type
{
DirectiveTransform
}
from
'
../transform
'
import
{
createCompilerError
,
ErrorCodes
}
from
'
../errors
'
import
{
stringifyExpression
}
from
'
./transformExpression
'
import
{
MagicString
,
walk
}
from
'
@vue/compiler-sfc
'
// v-bind without arg is handled directly in ./transformElements.ts due to it affecting
// codegen for the entire props object. This transform here is only for v-bind
// *with* args.
...
...
@@ -61,35 +56,6 @@ export const transformBind: DirectiveTransform = (dir, _node, context) => {
props
:
[
createObjectProperty
(
arg
,
createSimpleExpression
(
''
,
true
,
loc
))],
}
}
// 简易处理,理论上rust中也可以处理,但为了单元测试一致性,还是在该阶段中处理
const
source
=
stringifyExpression
(
exp
)
if
(
source
.
includes
(
'
{
'
))
{
const
s
=
new
MagicString
(
source
)
const
ast
=
parseExpression
(
source
,
{
plugins
:
context
.
expressionPlugins
,
})
walk
(
ast
,
{
enter
(
node
:
Node
)
{
if
(
node
.
type
===
'
ObjectExpression
'
)
{
const
type
=
s
.
original
.
substring
(
1
,
s
.
original
.
length
-
1
)
.
replaceAll
(
/
\s
+/g
,
''
)
?
''
:
'
<string, any | null>
'
s
.
prependLeft
(
node
.
start
!
,
`utsMapOf
${
type
}
(`
)
s
.
prependRight
(
node
.
end
!
,
'
)
'
)
}
},
})
return
{
props
:
[
createObjectProperty
(
arg
,
createSimpleExpression
(
s
.
toString
(),
false
,
exp
.
loc
)
),
],
}
}
return
{
props
:
[
createObjectProperty
(
arg
,
exp
)],
}
...
...
packages/uni-app-uts/src/plugins/uvue/compiler/utils.ts
浏览文件 @
34efd782
import
{
makeMap
}
from
'
@vue/shared
'
import
type
{
Node
}
from
'
@babel/types
'
import
{
ExpressionNode
,
createSimpleExpression
}
from
'
@vue/compiler-core
'
import
{
MagicString
,
walk
}
from
'
@vue/compiler-sfc
'
import
{
parseExpression
}
from
'
@babel/parser
'
import
{
CompilerOptions
}
from
'
./options
'
import
{
stringifyExpression
}
from
'
./transforms/transformExpression
'
import
{
TransformContext
}
from
'
./transform
'
export
function
genRenderFunctionDecl
({
targetLanguage
,
filename
,
...
...
@@ -10,10 +17,29 @@ export function genRenderFunctionDecl({
}
function
${
filename
}
Render(): VNode | null`
}
const
GLOBALS_WHITE_LISTED
=
'
Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,
'
+
'
decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,
'
+
'
Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt
'
+
'
console
'
export
const
isGloballyWhitelisted
=
/*#__PURE__*/
makeMap
(
GLOBALS_WHITE_LISTED
)
export
function
rewriteObjectExpression
(
exp
:
ExpressionNode
,
context
:
TransformContext
)
{
const
source
=
stringifyExpression
(
exp
)
if
(
source
.
includes
(
'
{
'
))
{
const
s
=
new
MagicString
(
source
)
const
ast
=
parseExpression
(
source
,
{
plugins
:
context
.
expressionPlugins
,
})
walk
(
ast
,
{
enter
(
node
:
Node
)
{
if
(
node
.
type
===
'
ObjectExpression
'
)
{
s
.
prependLeft
(
node
.
start
!
,
node
.
properties
.
length
>
0
?
'
utsMapOf(
'
:
'
utsMapOf<string, any | null>(
'
)
s
.
prependRight
(
node
.
end
!
,
'
)
'
)
}
},
})
return
createSimpleExpression
(
s
.
toString
(),
false
,
exp
.
loc
)
}
}
packages/uts-darwin-arm64/uts.darwin-arm64.node
浏览文件 @
34efd782
无法预览此类型文件
packages/uts-darwin-x64/uts.darwin-x64.node
浏览文件 @
34efd782
无法预览此类型文件
packages/uts-linux-x64-gnu/uts.linux-x64-gnu.node
浏览文件 @
34efd782
无法预览此类型文件
packages/uts-linux-x64-musl/uts.linux-x64-musl.node
浏览文件 @
34efd782
无法预览此类型文件
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录