Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
b345ec9a
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看板
提交
b345ec9a
编写于
7月 11, 2024
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(x-android): tsc
上级
d0cb2ad8
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
34 addition
and
18 deletion
+34
-18
packages/uni-app-uts/src/plugins/android/uvue/code/script.ts
packages/uni-app-uts/src/plugins/android/uvue/code/script.ts
+12
-4
packages/uni-app-uts/src/plugins/android/uvue/code/template.ts
...ges/uni-app-uts/src/plugins/android/uvue/code/template.ts
+1
-1
packages/uni-app-uts/src/plugins/android/uvue/compiler/codegen.ts
.../uni-app-uts/src/plugins/android/uvue/compiler/codegen.ts
+1
-1
packages/uni-app-uts/src/plugins/android/uvue/compiler/utils.ts
...es/uni-app-uts/src/plugins/android/uvue/compiler/utils.ts
+6
-2
packages/uni-app-uts/src/plugins/android/uvue/descriptorCache.ts
...s/uni-app-uts/src/plugins/android/uvue/descriptorCache.ts
+3
-0
packages/uni-app-uts/src/plugins/android/uvue/sfc/index.ts
packages/uni-app-uts/src/plugins/android/uvue/sfc/index.ts
+1
-0
packages/uni-app-uts/src/plugins/android/uvue/sfc/main.ts
packages/uni-app-uts/src/plugins/android/uvue/sfc/main.ts
+4
-6
packages/uni-app-uts/src/plugins/android/uvue/sfc/template.ts
...ages/uni-app-uts/src/plugins/android/uvue/sfc/template.ts
+4
-2
packages/uni-uts-v1/src/tsc/kotlin/index.ts
packages/uni-uts-v1/src/tsc/kotlin/index.ts
+2
-2
未找到文件。
packages/uni-app-uts/src/plugins/android/uvue/code/script.ts
浏览文件 @
b345ec9a
...
...
@@ -2,12 +2,10 @@ import type { SFCDescriptor } from '@vue/compiler-sfc'
export
function
genScript
(
{
script
}:
SFCDescriptor
,
_options
:
{
filename
:
string
}
{
genDefaultAs
}:
{
genDefaultAs
?
:
string
}
)
{
if
(
!
script
)
{
return
`
export default {}
`
return
genDefaultScriptCode
(
genDefaultAs
)
}
return
(
'
\n
'
.
repeat
(
script
.
loc
.
start
.
line
-
1
)
+
...
...
@@ -15,3 +13,13 @@ export default {}
`
)
}
export
function
genDefaultScriptCode
(
genDefaultAs
?:
string
)
{
if
(
genDefaultAs
)
{
return
`const
${
genDefaultAs
}
= defineComponent({})
export default
${
genDefaultAs
}
`
}
return
`
export default {}
`
}
packages/uni-app-uts/src/plugins/android/uvue/code/template.ts
浏览文件 @
b345ec9a
...
...
@@ -9,7 +9,7 @@ import { getDescriptor, getResolvedOptions } from '../descriptorCache'
export
function
genTemplate
(
{
template
}:
SFCDescriptor
,
options
:
TemplateCompilerOptions
options
:
TemplateCompilerOptions
&
{
genDefaultAs
?:
string
}
)
{
if
(
!
template
||
!
template
.
content
)
{
return
{
...
...
packages/uni-app-uts/src/plugins/android/uvue/compiler/codegen.ts
浏览文件 @
b345ec9a
...
...
@@ -209,7 +209,7 @@ const UTS_COMPONENT_ELEMENT_IMPORTS = `/*UTS-COMPONENTS-IMPORTS*/`
export
function
generate
(
ast
:
RootNode
,
options
:
CodegenOptions
=
{}
options
:
CodegenOptions
&
{
genDefaultAs
?:
string
}
=
{}
):
CodegenResult
{
const
context
=
createCodegenContext
(
ast
,
options
)
const
{
mode
,
deindent
,
indent
,
push
,
newline
}
=
context
...
...
packages/uni-app-uts/src/plugins/android/uvue/compiler/utils.ts
浏览文件 @
b345ec9a
...
...
@@ -21,13 +21,17 @@ export const __COMPAT__ = false
export
function
genRenderFunctionDecl
({
className
=
''
,
genDefaultAs
,
}:
// inline = false,
TemplateCompilerOptions
):
string
{
TemplateCompilerOptions
&
{
genDefaultAs
?:
string
}
):
string
{
// if(inline){
// return `(): VNode | null =>`
// }
// 调整返回值类型为 any | null, 支持 <template>some text</template>
return
`function
${
className
}
Render(): any | null`
const
thisCode
=
genDefaultAs
?
`this: InstanceType<typeof
${
genDefaultAs
}
>`
:
''
return
`function
${
className
}
Render(
${
thisCode
}
): any | null`
}
export
function
rewriteObjectExpression
(
...
...
packages/uni-app-uts/src/plugins/android/uvue/descriptorCache.ts
浏览文件 @
b345ec9a
...
...
@@ -4,6 +4,7 @@ import { preUVueHtml, preUVueJs } from '@dcloudio/uni-cli-shared'
import
type
*
as
_compiler
from
'
@vue/compiler-sfc
'
import
type
{
CompilerError
,
SFCDescriptor
}
from
'
@vue/compiler-sfc
'
import
{
parseUTSRelativeFilename
}
from
'
../utils
'
import
{
scriptIdentifier
}
from
'
./sfc/script
'
export
interface
ResolvedOptions
{
compiler
:
typeof
_compiler
...
...
@@ -11,6 +12,7 @@ export interface ResolvedOptions {
sourceMap
:
boolean
targetLanguage
?:
'
kotlin
'
classNamePrefix
?:
string
genDefaultAs
?:
string
}
export
function
getResolvedOptions
():
ResolvedOptions
{
...
...
@@ -23,6 +25,7 @@ export function getResolvedOptions(): ResolvedOptions {
// eslint-disable-next-line no-restricted-globals
compiler
:
require
(
'
@vue/compiler-sfc
'
),
targetLanguage
:
process
.
env
.
UNI_UTS_TARGET_LANGUAGE
as
'
kotlin
'
,
genDefaultAs
:
scriptIdentifier
,
}
}
...
...
packages/uni-app-uts/src/plugins/android/uvue/sfc/index.ts
浏览文件 @
b345ec9a
...
...
@@ -65,4 +65,5 @@ export interface ResolvedOptions extends Options {
className
?:
string
classNamePrefix
?:
string
componentType
:
'
app
'
|
'
page
'
|
'
component
'
genDefaultAs
?:
string
}
packages/uni-app-uts/src/plugins/android/uvue/sfc/main.ts
浏览文件 @
b345ec9a
...
...
@@ -30,6 +30,7 @@ import { createResolveError, parseImports, wrapResolve } from '../../utils'
import
{
genTemplateCode
}
from
'
../code/template
'
import
{
resolveGenTemplateCodeOptions
}
from
'
./template
'
import
{
addExtApiComponents
}
from
'
../../../utils
'
import
{
genDefaultScriptCode
}
from
'
../code/script
'
export
async
function
transformMain
(
code
:
string
,
...
...
@@ -129,10 +130,7 @@ export async function transformMain(
const
stylesCode
=
await
genStyleCode
(
descriptor
,
pluginContext
)
const
utsOutput
:
string
[]
=
[
scriptCode
||
`
export default {}
`
,
scriptCode
||
genDefaultScriptCode
(
options
.
genDefaultAs
),
templateCode
,
`/*
${
className
}
Styles*/\n`
,
]
...
...
@@ -251,13 +249,13 @@ export const ${genUTSComponentPublicInstanceImported(
async
function
genScriptCode
(
descriptor
:
SFCDescriptor
,
options
:
ResolvedOptions
options
:
ResolvedOptions
&
{
genDefaultAs
?:
string
}
):
Promise
<
{
code
:
string
map
:
RawSourceMap
|
undefined
bindingMetadata
?:
BindingMetadata
}
>
{
let
scriptCode
=
`export default {}`
let
scriptCode
=
genDefaultScriptCode
(
options
.
genDefaultAs
)
let
map
:
RawSourceMap
|
undefined
const
script
=
resolveScript
(
descriptor
,
options
)
...
...
packages/uni-app-uts/src/plugins/android/uvue/sfc/template.ts
浏览文件 @
b345ec9a
...
...
@@ -12,7 +12,7 @@ import {
parseUTSComponent
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
getResolvedScript
}
from
'
./script
'
import
{
getResolvedScript
,
scriptIdentifier
}
from
'
./script
'
import
type
{
ResolvedOptions
}
from
'
.
'
import
type
{
TemplateCompilerOptions
}
from
'
../compiler/options
'
import
{
parseUTSImportFilename
}
from
'
../../utils
'
...
...
@@ -32,10 +32,11 @@ export function resolveGenTemplateCodeOptions(
preprocessLang
?:
string
preprocessOptions
?:
any
}
):
TemplateCompilerOptions
{
):
TemplateCompilerOptions
&
{
genDefaultAs
?:
string
}
{
const
block
=
descriptor
.
template
if
(
!
block
)
{
return
{
genDefaultAs
:
scriptIdentifier
,
...
options
,
filename
:
relativeFileName
,
}
...
...
@@ -50,6 +51,7 @@ export function resolveGenTemplateCodeOptions(
}
}
return
{
genDefaultAs
:
scriptIdentifier
,
...
options
,
filename
:
relativeFileName
,
inMap
:
descriptor
.
template
?.
map
,
...
...
packages/uni-uts-v1/src/tsc/kotlin/index.ts
浏览文件 @
b345ec9a
...
...
@@ -65,8 +65,8 @@ export function runUTS2Kotlin(
const
vueRuntimeDts
=
[
path
.
resolve
(
hbxLanguageService
Path
,
'
uniapp
x/node_modules/@vue/runtime-core/index
.d.ts
'
plugin
Path
,
'
uniapp
-cli-vite/node_modules/@vue/runtime-core/dist/runtime-core
.d.ts
'
),
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录