Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
d1cd5f20
U
uni-app
项目概览
DCloud
/
uni-app
5 天 前同步成功
通知
815
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看板
提交
d1cd5f20
编写于
9月 06, 2023
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(uts): compiler
上级
973abfc7
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
114 addition
and
40 deletion
+114
-40
packages/uni-app-uts/__tests__/testUtils.ts
packages/uni-app-uts/__tests__/testUtils.ts
+2
-1
packages/uni-app-uts/package.json
packages/uni-app-uts/package.json
+2
-0
packages/uni-app-uts/src/plugins/uvue/compiler/codegen.ts
packages/uni-app-uts/src/plugins/uvue/compiler/codegen.ts
+4
-3
packages/uni-app-uts/src/plugins/uvue/compiler/options.ts
packages/uni-app-uts/src/plugins/uvue/compiler/options.ts
+4
-4
packages/uni-app-uts/src/plugins/uvue/compiler/transform.ts
packages/uni-app-uts/src/plugins/uvue/compiler/transform.ts
+1
-1
packages/uni-app-uts/src/plugins/uvue/compiler/utils.ts
packages/uni-app-uts/src/plugins/uvue/compiler/utils.ts
+2
-2
packages/uni-app-uts/src/plugins/uvue/index.ts
packages/uni-app-uts/src/plugins/uvue/index.ts
+71
-14
packages/uni-uts-v1/src/uvue/index.ts
packages/uni-uts-v1/src/uvue/index.ts
+7
-0
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/uts-win32-ia32-msvc/uts.win32-ia32-msvc.node
packages/uts-win32-ia32-msvc/uts.win32-ia32-msvc.node
+0
-0
packages/uts-win32-x64-msvc/uts.win32-x64-msvc.node
packages/uts-win32-x64-msvc/uts.win32-x64-msvc.node
+0
-0
packages/uts/src/types.ts
packages/uts/src/types.ts
+3
-0
pnpm-lock.yaml
pnpm-lock.yaml
+18
-15
未找到文件。
packages/uni-app-uts/__tests__/testUtils.ts
浏览文件 @
d1cd5f20
...
...
@@ -15,7 +15,8 @@ export function assert(
options
:
CompilerOptions
=
{
targetLanguage
:
'
kotlin
'
}
)
{
const
compilerOptions
:
CompilerOptions
=
{
filename
:
'
PagesIndexIndex
'
,
filename
:
'
pages/index/index.uvue
'
,
className
:
'
PagesIndexIndex
'
,
prefixIdentifiers
:
true
,
...
options
,
}
...
...
packages/uni-app-uts/package.json
浏览文件 @
d1cd5f20
...
...
@@ -24,6 +24,8 @@
"@dcloudio/uni-i18n"
:
"3.0.0-alpha-3090020230826001"
,
"@dcloudio/uni-nvue-styler"
:
"3.0.0-alpha-3090020230826001"
,
"@dcloudio/uni-shared"
:
"3.0.0-alpha-3090020230826001"
,
"@jridgewell/gen-mapping"
:
"^0.3.3"
,
"@jridgewell/trace-mapping"
:
"^0.3.19"
,
"@rollup/pluginutils"
:
"^4.2.0"
,
"@vue/compiler-core"
:
"3.2.47"
,
"@vue/compiler-sfc"
:
"3.2.47"
,
...
...
packages/uni-app-uts/src/plugins/uvue/compiler/codegen.ts
浏览文件 @
d1cd5f20
...
...
@@ -54,7 +54,9 @@ import { isBinaryExpression } from '@babel/types'
type
CodegenNode
=
TemplateChildNode
|
JSChildNode
|
SSRCodegenNode
export
interface
CodegenContext
extends
Required
<
Omit
<
CodegenOptions
,
'
sourceMapGeneratedLine
'
>>
{
extends
Required
<
Omit
<
CodegenOptions
,
'
sourceMapGeneratedLine
'
|
'
className
'
>
>
{
source
:
string
code
:
string
importEasyComponents
:
string
[]
...
...
@@ -80,7 +82,6 @@ function createCodegenContext(
prefixIdentifiers
=
false
,
bindingMetadata
=
{},
sourceMap
=
false
,
sourceMapGeneratedLine
=
1
,
filename
=
''
,
matchEasyCom
=
NOOP
,
parseUTSComponent
=
NOOP
,
...
...
@@ -98,7 +99,7 @@ function createCodegenContext(
importEasyComponents
:
[],
importUTSComponents
:
[],
column
:
1
,
line
:
sourceMapGeneratedLine
??
1
,
line
:
1
,
offset
:
0
,
indentLevel
:
0
,
map
:
undefined
,
...
...
packages/uni-app-uts/src/plugins/uvue/compiler/options.ts
浏览文件 @
d1cd5f20
...
...
@@ -20,6 +20,10 @@ interface SharedTransformCodegenOptions {
* @default ''
*/
filename
?:
string
/**
* 编译的模板类名
*/
className
?:
string
}
export
interface
CodegenOptions
extends
SharedTransformCodegenOptions
{
/**
...
...
@@ -32,10 +36,6 @@ export interface CodegenOptions extends SharedTransformCodegenOptions {
* @default false
*/
sourceMap
?:
boolean
/**
*
*/
sourceMapGeneratedLine
?:
number
/**
* 匹配 easycom 组件
* @param tag
...
...
packages/uni-app-uts/src/plugins/uvue/compiler/transform.ts
浏览文件 @
d1cd5f20
...
...
@@ -78,7 +78,7 @@ export interface ImportItem {
}
export
interface
TransformContext
extends
Required
<
Omit
<
TransformOptions
,
'
filename
'
>>
{
extends
Required
<
Omit
<
TransformOptions
,
'
filename
'
|
'
className
'
>>
{
selfName
:
string
|
null
root
:
RootNode
helpers
:
Map
<
symbol
,
number
>
...
...
packages/uni-app-uts/src/plugins/uvue/compiler/utils.ts
浏览文件 @
d1cd5f20
...
...
@@ -11,11 +11,11 @@ import { CompilerError } from './errors'
export
function
genRenderFunctionDecl
({
targetLanguage
,
filen
ame
,
classN
ame
,
}:
CompilerOptions
):
string
{
return
`
${
targetLanguage
===
'
kotlin
'
?
'
@Suppress("UNUSED_PARAMETER")
'
:
''
}
function
${
filen
ame
}
Render(): VNode | null`
}
function
${
classN
ame
}
Render(): VNode | null`
}
export
function
rewriteObjectExpression
(
...
...
packages/uni-app-uts/src/plugins/uvue/index.ts
浏览文件 @
d1cd5f20
...
...
@@ -2,7 +2,12 @@ import path from 'path'
import
fs
from
'
fs-extra
'
import
type
{
Plugin
}
from
'
vite
'
import
type
{
SFCBlock
,
SFCDescriptor
,
SFCParseResult
}
from
'
@vue/compiler-sfc
'
import
{
MagicString
,
type
SFCBlock
,
type
SFCDescriptor
,
type
SFCParseResult
,
}
from
'
@vue/compiler-sfc
'
import
type
{
TransformPluginContext
}
from
'
rollup
'
import
{
isString
}
from
'
@vue/shared
'
...
...
@@ -16,6 +21,13 @@ import {
import
type
{
RawSourceMap
}
from
'
source-map-js
'
import
{
addMapping
,
fromMap
,
toEncodedMap
}
from
'
@jridgewell/gen-mapping
'
import
{
TraceMap
,
eachMapping
,
EncodedSourceMap
,
}
from
'
@jridgewell/trace-mapping
'
import
{
ResolvedOptions
,
createDescriptor
,
...
...
@@ -98,7 +110,7 @@ export function uniAppUVuePlugin(): Plugin {
}
if
(
!
query
.
vue
)
{
// main request
const
{
errors
,
uts
,
js
,
templateS
ourceMap
}
=
await
transformVue
(
const
{
errors
,
uts
,
js
,
s
ourceMap
}
=
await
transformVue
(
code
,
filename
,
options
,
...
...
@@ -118,11 +130,11 @@ export function uniAppUVuePlugin(): Plugin {
fileName
,
source
:
uts
,
})
if
(
templateS
ourceMap
)
{
if
(
s
ourceMap
)
{
this
.
emitFile
({
type
:
'
asset
'
,
fileName
:
removeExt
(
fileName
)
+
'
.template.map
'
,
source
:
JSON
.
stringify
(
templateS
ourceMap
),
source
:
JSON
.
stringify
(
s
ourceMap
),
})
}
return
{
...
...
@@ -187,7 +199,7 @@ interface TransformVueResult {
uts
?:
string
js
?:
string
descriptor
:
SFCDescriptor
templateS
ourceMap
?:
RawSourceMap
s
ourceMap
?:
RawSourceMap
}
export
async
function
transformVue
(
...
...
@@ -208,23 +220,25 @@ export async function transformVue(
return
{
errors
,
descriptor
}
}
const
isApp
=
isAppVue
(
filename
)
const
fileName
=
path
.
relative
(
options
.
root
,
filename
)
const
fileName
=
normalizePath
(
path
.
relative
(
options
.
root
,
filename
)
)
const
className
=
genClassName
(
fileName
,
options
.
classNamePrefix
)
let
templateCode
=
''
let
templateImportEasyComponentsCode
=
''
let
templateImportUTSComponentsCode
=
''
let
templateSourceMap
const
needSourceMap
=
process
.
env
.
UNI_APP_X_TEMPLATE_SOURCEMAP
?
true
:
process
.
env
.
NODE_ENV
!==
'
production
'
let
templateSourceMap
:
RawSourceMap
|
undefined
if
(
!
isApp
)
{
const
templateResult
=
genTemplate
(
descriptor
,
{
targetLanguage
:
options
.
targetLanguage
as
any
,
mode
:
'
function
'
,
filename
:
className
,
filename
:
fileName
,
className
:
className
,
prefixIdentifiers
:
true
,
sourceMap
:
process
.
env
.
NODE_ENV
!==
'
production
'
,
// TODO 将sourceMap的行数调整为script的最后一行,后续需要考虑setup
sourceMapGeneratedLine
:
descriptor
.
script
?
descriptor
.
script
.
loc
.
end
.
line
+
1
:
1
,
// 方便测试,build模式也提供sourceMap
// sourceMap: false,
sourceMap
:
needSourceMap
,
matchEasyCom
:
(
tag
,
uts
)
=>
{
const
source
=
matchEasycom
(
tag
)
if
(
uts
&&
source
)
{
...
...
@@ -265,6 +279,49 @@ export async function transformVue(
uts
:
utsCode
,
js
:
jsCode
,
descriptor
,
templateSourceMap
,
sourceMap
:
needSourceMap
?
createSourceMap
(
descriptor
.
script
?
descriptor
.
script
.
loc
.
end
.
line
+
1
:
1
,
new
MagicString
(
code
).
generateMap
({
hires
:
true
,
source
:
fileName
,
includeContent
:
true
,
})
as
unknown
as
RawSourceMap
,
templateSourceMap
)
:
undefined
,
}
}
function
createSourceMap
(
scriptCodeOffset
:
number
,
scriptMap
:
RawSourceMap
,
templateMap
?:
RawSourceMap
)
{
if
(
!
templateMap
)
{
return
scriptMap
}
const
gen
=
fromMap
(
// version property of result.map is declared as string
// but actually it is `3`
scriptMap
as
Omit
<
RawSourceMap
,
'
version
'
>
as
EncodedSourceMap
)
const
tracer
=
new
TraceMap
(
// same above
templateMap
as
Omit
<
RawSourceMap
,
'
version
'
>
as
EncodedSourceMap
)
// const offset = (scriptCode.match(/\r?\n/g)?.length ?? 0) + 1
eachMapping
(
tracer
,
(
m
)
=>
{
if
(
m
.
source
==
null
)
return
addMapping
(
gen
,
{
source
:
m
.
source
,
original
:
{
line
:
m
.
originalLine
,
column
:
m
.
originalColumn
-
1
},
generated
:
{
line
:
m
.
generatedLine
+
scriptCodeOffset
-
1
,
column
:
m
.
generatedColumn
,
},
})
})
return
toEncodedMap
(
gen
)
as
unknown
as
RawSourceMap
}
packages/uni-uts-v1/src/uvue/index.ts
浏览文件 @
d1cd5f20
...
...
@@ -114,6 +114,9 @@ export async function compileApp(entry: string, options: CompileAppOptions) {
noColor
:
true
,
split
,
disableSplitManifest
:
options
.
disableSplitManifest
,
uniAppX
:
{
uvueOutDir
:
uvueOutDir
(),
},
transform
:
{
uniExtApiDefaultNamespace
:
'
io.dcloud.uniapp.extapi
'
,
uniExtApiNamespaces
:
extApis
,
...
...
@@ -150,6 +153,10 @@ export async function compileApp(entry: string, options: CompileAppOptions) {
return
runKotlinDev
(
options
,
result
as
RunKotlinDevResult
,
hasCache
)
}
export
function
uvueOutDir
()
{
return
path
.
join
(
process
.
env
.
UNI_OUTPUT_DIR
,
'
../.uvue
'
)
}
function
kotlinDir
(
outputDir
:
string
)
{
return
(
process
.
env
.
UNI_APP_X_CACHE_DIR
||
path
.
resolve
(
outputDir
,
'
../.kotlin
'
)
...
...
packages/uts-darwin-arm64/uts.darwin-arm64.node
浏览文件 @
d1cd5f20
无法预览此类型文件
packages/uts-darwin-x64/uts.darwin-x64.node
浏览文件 @
d1cd5f20
无法预览此类型文件
packages/uts-linux-x64-gnu/uts.linux-x64-gnu.node
浏览文件 @
d1cd5f20
无法预览此类型文件
packages/uts-linux-x64-musl/uts.linux-x64-musl.node
浏览文件 @
d1cd5f20
无法预览此类型文件
packages/uts-win32-ia32-msvc/uts.win32-ia32-msvc.node
LFS
浏览文件 @
d1cd5f20
无法预览此类型文件
packages/uts-win32-x64-msvc/uts.win32-x64-msvc.node
LFS
浏览文件 @
d1cd5f20
无法预览此类型文件
packages/uts/src/types.ts
浏览文件 @
d1cd5f20
...
...
@@ -46,6 +46,9 @@ export type UTSOutputOptions = {
isPlugin
?:
boolean
split
?:
boolean
disableSplitManifest
?:
boolean
uniAppX
?:
{
uvueOutDir
:
string
}
transform
?:
{
paramDefaultValue
?:
boolean
constructorInvocation
?:
boolean
...
...
pnpm-lock.yaml
浏览文件 @
d1cd5f20
...
...
@@ -379,6 +379,12 @@ importers:
'
@dcloudio/uni-shared'
:
specifier
:
3.0.0-alpha-3090020230826001
version
:
link:../uni-shared
'
@jridgewell/gen-mapping'
:
specifier
:
^0.3.3
version
:
0.3.3
'
@jridgewell/trace-mapping'
:
specifier
:
^0.3.19
version
:
0.3.19
'
@rollup/pluginutils'
:
specifier
:
^4.2.0
version
:
4.2.0
...
...
@@ -1529,7 +1535,7 @@ packages:
resolution
:
{
integrity
:
sha512-hoyByceqwKirw7w3Z7gnIIZC3Wx3J484Y3L/cMpXFbr7d9ZQj2mODrirNzcJa+SM3UlpWXYvKV4RlRpFXlWgXg==
}
engines
:
{
node
:
'
>=6.0.0'
}
dependencies
:
'
@jridgewell/trace-mapping'
:
0.3.1
8
'
@jridgewell/trace-mapping'
:
0.3.1
9
dev
:
false
/@ampproject/remapping@2.2.1
:
...
...
@@ -1537,7 +1543,7 @@ packages:
engines
:
{
node
:
'
>=6.0.0'
}
dependencies
:
'
@jridgewell/gen-mapping'
:
0.3.3
'
@jridgewell/trace-mapping'
:
0.3.1
8
'
@jridgewell/trace-mapping'
:
0.3.1
9
/@babel/code-frame@7.21.4
:
resolution
:
{
integrity
:
sha512-LYvhNKfwWSPpocw8GI7gpK2nq3HSDuEPC/uSYaALSJu9xjsalaaYFOq0Pwt5KmVqwEbZlDu81aLXwBOmD/Fv9g==
}
...
...
@@ -1585,7 +1591,7 @@ packages:
dependencies
:
'
@babel/types'
:
7.21.5
'
@jridgewell/gen-mapping'
:
0.3.3
'
@jridgewell/trace-mapping'
:
0.3.1
8
'
@jridgewell/trace-mapping'
:
0.3.1
9
jsesc
:
2.5.2
/@babel/helper-annotate-as-pure@7.18.6
:
...
...
@@ -3424,7 +3430,7 @@ packages:
'
@jest/test-result'
:
29.5.0
'
@jest/transform'
:
29.5.0
'
@jest/types'
:
29.5.0
'
@jridgewell/trace-mapping'
:
0.3.1
8
'
@jridgewell/trace-mapping'
:
0.3.1
9
'
@types/node'
:
18.16.2
chalk
:
4.1.2
collect-v8-coverage
:
1.0.1
...
...
@@ -3467,7 +3473,7 @@ packages:
resolution
:
{
integrity
:
sha512-qyt/mb6rLyd9j1jUts4EQncvS6Yy3PM9HghnNv86QBlV+zdL2inCdK1tuVlL+J+lpiw2BI67qXOrX3UurBqQ1w==
}
engines
:
{
node
:
^14.15.0 || ^16.10.0 || >=18.0.0
}
dependencies
:
'
@jridgewell/trace-mapping'
:
0.3.1
8
'
@jridgewell/trace-mapping'
:
0.3.1
9
callsites
:
3.1.0
graceful-fs
:
4.2.11
dev
:
true
...
...
@@ -3543,7 +3549,7 @@ packages:
dependencies
:
'
@babel/core'
:
7.21.3
'
@jest/types'
:
29.5.0
'
@jridgewell/trace-mapping'
:
0.3.1
8
'
@jridgewell/trace-mapping'
:
0.3.1
9
babel-plugin-istanbul
:
6.1.1
chalk
:
4.1.2
convert-source-map
:
2.0.0
...
...
@@ -4006,7 +4012,7 @@ packages:
dependencies
:
'
@jridgewell/set-array'
:
1.1.2
'
@jridgewell/sourcemap-codec'
:
1.4.15
'
@jridgewell/trace-mapping'
:
0.3.1
8
'
@jridgewell/trace-mapping'
:
0.3.1
9
/@jridgewell/resolve-uri@3.1.0
:
resolution
:
{
integrity
:
sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==
}
...
...
@@ -4020,20 +4026,17 @@ packages:
resolution
:
{
integrity
:
sha512-b+fsZXeLYi9fEULmfBrhxn4IrPlINf8fiNarzTof004v3lFdntdwa9PF7vFJqm3mg7s+ScJMxXaE3Acp1irZcg==
}
dependencies
:
'
@jridgewell/gen-mapping'
:
0.3.3
'
@jridgewell/trace-mapping'
:
0.3.1
8
'
@jridgewell/trace-mapping'
:
0.3.1
9
dev
:
true
/@jridgewell/sourcemap-codec@1.4.14
:
resolution
:
{
integrity
:
sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==
}
/@jridgewell/sourcemap-codec@1.4.15
:
resolution
:
{
integrity
:
sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==
}
/@jridgewell/trace-mapping@0.3.1
8
:
resolution
:
{
integrity
:
sha512-
w+niJYzMHdd7USdiH2U6869nqhD2nbfZXND5Yp93qIbEmnDNk7PD48o+YchRVpzMU7M6jVCbenTR7PA1FLQ9pA
==
}
/@jridgewell/trace-mapping@0.3.1
9
:
resolution
:
{
integrity
:
sha512-
kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw
==
}
dependencies
:
'
@jridgewell/resolve-uri'
:
3.1.0
'
@jridgewell/sourcemap-codec'
:
1.4.1
4
'
@jridgewell/sourcemap-codec'
:
1.4.1
5
/@jsbits/escape-regex-str@1.0.3
:
resolution
:
{
integrity
:
sha512-0800vYI2fg1nuUq/T9Tqv8DMOLLNiRAltxFbKIbR7szrvW6qTuI2+zGK51hV7NAAmUr4G83Kvpj2R6Yyg07iIw==
}
...
...
@@ -10481,7 +10484,7 @@ packages:
resolution
:
{
integrity
:
sha512-6z3GW9x8G1gd+JIIgQQQxXuiJtCXeAjp6RaPEPLv62mH3iPHPxV6W3robxtCzNErRo6ZwTmzWhsbNvjyEBKzKA==
}
engines
:
{
node
:
'
>=10.12.0'
}
dependencies
:
'
@jridgewell/trace-mapping'
:
0.3.1
8
'
@jridgewell/trace-mapping'
:
0.3.1
9
'
@types/istanbul-lib-coverage'
:
2.0.4
convert-source-map
:
1.9.0
dev
:
true
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录