Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小浣熊撸代码
uni-app
提交
bc7b9fbd
U
uni-app
项目概览
小浣熊撸代码
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
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,发现更多精彩内容 >>
提交
bc7b9fbd
编写于
1月 18, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(app): nvue
上级
b1207592
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
132 addition
and
13 deletion
+132
-13
packages/uni-app-vite/__tests__/nvue/__snapshots__/compiler.spec.ts.snap
...p-vite/__tests__/nvue/__snapshots__/compiler.spec.ts.snap
+36
-0
packages/uni-app-vite/__tests__/nvue/compiler.spec.ts
packages/uni-app-vite/__tests__/nvue/compiler.spec.ts
+27
-12
packages/uni-app-vite/src/nvue/plugin/index.ts
packages/uni-app-vite/src/nvue/plugin/index.ts
+2
-0
packages/uni-app-vite/src/nvue/plugin/transforms/transformRenderWhole.ts
...p-vite/src/nvue/plugin/transforms/transformRenderWhole.ts
+0
-1
packages/uni-app-vite/src/nvue/plugin/transforms/transformText.ts
.../uni-app-vite/src/nvue/plugin/transforms/transformText.ts
+67
-0
未找到文件。
packages/uni-app-vite/__tests__/nvue/__snapshots__/compiler.spec.ts.snap
0 → 100644
浏览文件 @
bc7b9fbd
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`app-nvue: compiler <video></video> 1`] = `
"import { openBlock as _openBlock, createElementBlock as _createElementBlock } from \\"vue\\"
export function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock(\\"u-video\\"))
}"
`;
exports[`app-nvue: compiler <video><view></view></video> 1`] = `
"import { createElementVNode as _createElementVNode, openBlock as _openBlock, createElementBlock as _createElementBlock } from \\"vue\\"
const _hoisted_1 = /*#__PURE__*/_createElementVNode(\\"u-scalable\\", { style: {position:\\"absolute\\",left:\\"0\\",right:\\"0\\",top:\\"0\\",bottom:\\"0\\"} }, [
/*#__PURE__*/_createElementVNode(\\"view\\")
], -1 /* HOISTED */)
const _hoisted_2 = [
_hoisted_1
]
export function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock(\\"u-video\\", null, _hoisted_2))
}"
`;
exports[`app-nvue: compiler <view>hello</view> 1`] = `
"import { createElementVNode as _createElementVNode, openBlock as _openBlock, createElementBlock as _createElementBlock } from \\"vue\\"
const _hoisted_1 = [\\"appendAsTree\\"]
export function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock(\\"view\\", null, [
_createElementVNode(\\"u-text\\", { appendAsTree: true }, \\"hello\\", 8 /* PROPS */, _hoisted_1)
]))
}"
`;
packages/uni-app-vite/__tests__/nvue/compiler.spec.ts
浏览文件 @
bc7b9fbd
...
...
@@ -19,9 +19,29 @@ function compile(source: string) {
compilerOptions
:
{
...
compilerOptions
,
},
}).
ast
!
.
children
[
0
]
as
ElementNode
})
}
function
genAst
(
source
:
string
)
{
return
compile
(
source
).
ast
!
.
children
[
0
]
as
ElementNode
}
function
genCode
(
source
:
string
)
{
return
compile
(
source
).
code
}
const
codes
=
[
`<view>hello</view>`
,
`<video></video>`
,
`<video><view></view></video>`
,
]
describe
(
'
app-nvue: compiler
'
,
()
=>
{
codes
.
forEach
((
code
)
=>
{
test
(
code
,
()
=>
{
expect
(
genCode
(
code
)).
toMatchSnapshot
()
})
})
test
(
'
u-tags
'
,
()
=>
{
;[
'
text
'
,
...
...
@@ -32,24 +52,19 @@ describe('app-nvue: compiler', () => {
'
web-view
'
,
'
slider
'
,
].
forEach
((
tag
)
=>
{
expect
(
compile
(
`<
${
tag
}
></
${
tag
}
>`
).
tag
).
toBe
(
`u-
${
tag
}
`
)
expect
(
genAst
(
`<
${
tag
}
></
${
tag
}
>`
).
tag
).
toBe
(
`u-
${
tag
}
`
)
})
})
test
(
'
video
'
,
()
=>
{
expect
(
compile
(
`<video></video>`
).
children
.
length
).
toBe
(
0
)
expect
(
(
compile
(
`<video><view></view></video>`
).
children
[
0
]
as
ElementNode
).
tag
).
toBe
(
'
u-scalable
'
)
})
test
(
'
scroll-view
'
,
()
=>
{
compile
(
`<view></view>`
)
genAst
(
`<view></view>`
)
})
test
(
'
render-whole
'
,
()
=>
{
expect
(
(
(
findProp
(
compile
(
`<view :render-whole="true">hello</view>`
),
genAst
(
`<view :render-whole="true">hello</view>`
),
'
appendAsTree
'
,
true
,
false
...
...
@@ -60,13 +75,13 @@ describe('app-nvue: compiler', () => {
})
test
(
'
unitary tag
'
,
()
=>
{
expect
(
findProp
(
compile
(
`<text>hello</text>`
),
'
appendAsTree
'
,
true
,
false
)
findProp
(
genAst
(
`<text>hello</text>`
),
'
appendAsTree
'
,
true
,
false
)
).
toBeTruthy
()
})
test
(
'
tap=>click
'
,
()
=>
{
expect
(
(
findDir
(
compile
(
`<view @tap="click"></view>`
),
'
on
'
)
!
findDir
(
genAst
(
`<view @tap="click"></view>`
),
'
on
'
)
!
.
arg
as
SimpleExpressionNode
).
content
).
toBe
(
'
click
'
)
...
...
packages/uni-app-vite/src/nvue/plugin/index.ts
浏览文件 @
bc7b9fbd
...
...
@@ -13,6 +13,7 @@ import { nvueOutDir } from '../../utils'
import
{
transformRenderWhole
}
from
'
./transforms/transformRenderWhole
'
import
{
transformAppendAsTree
}
from
'
./transforms/transformAppendAsTree
'
import
{
transformVideo
}
from
'
./transforms/transformVideo
'
import
{
transformText
}
from
'
./transforms/transformText
'
const
uTags
=
{
text
:
'
u-text
'
,
image
:
'
u-image
'
,
...
...
@@ -27,6 +28,7 @@ export function initNVueNodeTransforms() {
// 优先级必须确保 renderWhole > appendAsTree
return
[
createTransformTag
(
uTags
),
transformText
,
transformVideo
,
transformRenderWhole
,
transformAppendAsTree
,
...
...
packages/uni-app-vite/src/nvue/plugin/transforms/transformRenderWhole.ts
浏览文件 @
bc7b9fbd
...
...
@@ -5,7 +5,6 @@ export const transformRenderWhole: NodeTransform = (node, _) => {
if
(
!
isElementNode
(
node
))
{
return
}
debugger
const
prop
=
findProp
(
node
,
'
render-whole
'
)
if
(
!
prop
)
{
return
...
...
packages/uni-app-vite/src/nvue/plugin/transforms/transformText.ts
0 → 100644
浏览文件 @
bc7b9fbd
import
{
isElementNode
}
from
'
@dcloudio/uni-cli-shared
'
import
{
CompoundExpressionNode
,
ElementNode
,
ElementTypes
,
InterpolationNode
,
NodeTransform
,
NodeTypes
,
TemplateChildNode
,
TextCallNode
,
TextNode
,
}
from
'
@vue/compiler-core
'
function
isTextNode
({
tag
}:
ElementNode
)
{
return
tag
===
'
text
'
||
tag
===
'
u-text
'
||
tag
===
'
button
'
}
function
isText
(
node
:
TemplateChildNode
):
node
is
|
TextNode
|
TextCallNode
|
InterpolationNode
|
CompoundExpressionNode
{
const
{
type
}
=
node
return
(
type
===
NodeTypes
.
TEXT
||
type
===
NodeTypes
.
TEXT_CALL
||
type
===
NodeTypes
.
INTERPOLATION
||
type
===
NodeTypes
.
COMPOUND_EXPRESSION
)
}
export
const
transformText
:
NodeTransform
=
(
node
,
_
)
=>
{
if
(
!
isElementNode
(
node
))
{
return
}
if
(
isTextNode
(
node
))
{
return
}
const
{
children
}
=
node
if
(
!
children
.
length
)
{
return
}
children
.
forEach
((
child
,
index
)
=>
{
if
(
isText
(
child
))
{
children
.
splice
(
index
,
1
,
createText
(
node
,
child
))
}
})
}
function
createText
(
parent
:
ElementNode
,
node
:
TextNode
|
TextCallNode
|
InterpolationNode
|
CompoundExpressionNode
):
ElementNode
{
return
{
tag
:
'
u-text
'
,
type
:
NodeTypes
.
ELEMENT
,
tagType
:
ElementTypes
.
ELEMENT
,
props
:
[],
isSelfClosing
:
false
,
children
:
[
node
],
codegenNode
:
undefined
,
ns
:
parent
.
ns
,
loc
:
node
.
loc
,
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录