Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
f37eb25a
U
uni-app
项目概览
DCloud
/
uni-app
通知
699
Star
38703
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,体验更适合开发者的 AI 搜索 >>
提交
f37eb25a
编写于
1月 16, 2024
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(uvue): 调整 defineProps 类型为 PropType 的生成
上级
eb667df3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
50 addition
and
9 deletion
+50
-9
packages/uni-app-uts/__tests__/android/sfc/compileScript/__snapshots__/defineProps.spec.ts.snap
.../sfc/compileScript/__snapshots__/defineProps.spec.ts.snap
+2
-1
packages/uni-app-uts/__tests__/android/sfc/compileScript/defineProps.spec.ts
...s/__tests__/android/sfc/compileScript/defineProps.spec.ts
+7
-0
packages/uni-app-uts/src/plugins/android/uvue/sfc/compiler/script/defineProps.ts
...c/plugins/android/uvue/sfc/compiler/script/defineProps.ts
+41
-8
未找到文件。
packages/uni-app-uts/__tests__/android/sfc/compileScript/__snapshots__/defineProps.spec.ts.snap
浏览文件 @
f37eb25a
...
...
@@ -328,7 +328,8 @@ export default {
unknownUnion: { type: null, required: true },
unknownIntersection: { type: Object, required: true },
unknownUnionWithBoolean: { type: Boolean, required: true, skipCheck: true },
unknownUnionWithFunction: { type: Function, required: true, skipCheck: true }
unknownUnionWithFunction: { type: Function, required: true, skipCheck: true },
propType: { type: Object as PropType<()=>string>, required: true, skipCheck: true }
},
setup(__props: GenAnonymous) {
const __ins = getCurrentInstance()!;
...
...
packages/uni-app-uts/__tests__/android/sfc/compileScript/defineProps.spec.ts
浏览文件 @
f37eb25a
...
...
@@ -130,6 +130,9 @@ const props = defineProps({ foo: String })
unknownIntersection: UnknownType & Object
unknownUnionWithBoolean: UnknownType | boolean
unknownUnionWithFunction: UnknownType | (() => any)
propType: PropType<()=>string>
}>()
</script>`
)
assertCode
(
content
)
...
...
@@ -188,6 +191,9 @@ const props = defineProps({ foo: String })
expect
(
content
).
toMatch
(
`unknownUnionWithFunction: { type: Function, required: true, skipCheck: true }`
)
expect
(
content
).
toMatch
(
`propType: { type: Object as PropType<()=>string>, required: true, skipCheck: true }`
)
expect
(
bindings
).
toStrictEqual
({
string
:
BindingTypes
.
PROPS
,
number
:
BindingTypes
.
PROPS
,
...
...
@@ -228,6 +234,7 @@ const props = defineProps({ foo: String })
unknownIntersection
:
BindingTypes
.
PROPS
,
unknownUnionWithBoolean
:
BindingTypes
.
PROPS
,
unknownUnionWithFunction
:
BindingTypes
.
PROPS
,
propType
:
BindingTypes
.
PROPS
,
})
})
...
...
packages/uni-app-uts/src/plugins/android/uvue/sfc/compiler/script/defineProps.ts
浏览文件 @
f37eb25a
...
...
@@ -5,6 +5,8 @@ import {
ObjectMethod
,
ObjectExpression
,
Expression
,
TSPropertySignature
,
TSMethodSignature
,
}
from
'
@babel/types
'
import
{
BindingTypes
,
isFunctionType
}
from
'
@vue/compiler-dom
'
import
{
ScriptCompileContext
}
from
'
./context
'
...
...
@@ -225,6 +227,32 @@ function genRuntimePropsFromTypes(ctx: ScriptCompileContext) {
return
propsDecls
}
function
parsePropType
(
ctx
:
ScriptCompileContext
,
node
:
TSMethodSignature
|
TSPropertySignature
)
{
if
(
node
.
type
===
'
TSPropertySignature
'
)
{
const
typeAnn
=
node
.
typeAnnotation
if
(
typeAnn
)
{
const
tsType
=
typeAnn
?.
typeAnnotation
if
(
tsType
?.
type
===
'
TSTypeReference
'
)
{
if
(
tsType
.
typeName
.
type
===
'
Identifier
'
&&
tsType
.
typeName
.
name
===
'
PropType
'
)
{
return
[
`Object as
${
ctx
.
source
.
slice
(
tsType
.
start
!
+
ctx
.
startOffset
!
,
tsType
.
end
!
+
ctx
.
startOffset
!
)}
`
,
]
}
}
}
}
return
[]
}
function
resolveRuntimePropsFromType
(
ctx
:
ScriptCompileContext
,
node
:
Node
...
...
@@ -233,15 +261,20 @@ function resolveRuntimePropsFromType(
const
elements
=
resolveTypeElements
(
ctx
,
node
)
for
(
const
key
in
elements
.
props
)
{
const
e
=
elements
.
props
[
key
]
let
type
=
inferRuntime
Type
(
ctx
,
e
)
let
type
=
parseProp
Type
(
ctx
,
e
)
let
skipCheck
=
false
// skip check for result containing unknown types
if
(
type
.
includes
(
UNKNOWN_TYPE
))
{
if
(
type
.
includes
(
'
Boolean
'
)
||
type
.
includes
(
'
Function
'
))
{
type
=
type
.
filter
((
t
)
=>
t
!==
UNKNOWN_TYPE
)
skipCheck
=
true
}
else
{
type
=
[
'
null
'
]
if
(
type
.
length
)
{
skipCheck
=
true
}
else
{
type
=
inferRuntimeType
(
ctx
,
e
)
// skip check for result containing unknown types
if
(
type
.
includes
(
UNKNOWN_TYPE
))
{
if
(
type
.
includes
(
'
Boolean
'
)
||
type
.
includes
(
'
Function
'
))
{
type
=
type
.
filter
((
t
)
=>
t
!==
UNKNOWN_TYPE
)
skipCheck
=
true
}
else
{
type
=
[
'
null
'
]
}
}
}
props
.
push
({
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录