Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ChenYFan_OHHH
uni-app
提交
d9f72436
U
uni-app
项目概览
ChenYFan_OHHH
/
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,发现更多精彩内容 >>
提交
d9f72436
编写于
9月 06, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(app-nvue): auto add render-whole
上级
eb5eef87
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
78 addition
and
17 deletion
+78
-17
packages/uni-app-vite/__tests__/nvue/__snapshots__/compiler.spec.ts.snap
...p-vite/__tests__/nvue/__snapshots__/compiler.spec.ts.snap
+18
-14
packages/uni-app-vite/src/nvue/plugin/transforms/transformRenderWhole.ts
...p-vite/src/nvue/plugin/transforms/transformRenderWhole.ts
+51
-2
packages/uni-app-vite/src/nvue/plugin/transforms/transformRootNode.ts
...-app-vite/src/nvue/plugin/transforms/transformRootNode.ts
+9
-1
未找到文件。
packages/uni-app-vite/__tests__/nvue/__snapshots__/compiler.spec.ts.snap
浏览文件 @
d9f72436
...
...
@@ -19,7 +19,8 @@ exports[`app-nvue: compiler <scroll-view data-id="id" scroll-x="true" :show-scro
const _hoisted_1 = {
\\"data-id\\": \\"id\\",
scrollX: \\"true\\",
showScrollbar: true
showScrollbar: true,
renderWhole: true
}
export function render(_ctx, _cache) {
...
...
@@ -76,41 +77,44 @@ export function render(_ctx, _cache) {
exports[`app-nvue: compiler <view><text>hello</text></view> 1`] = `
"import { createElementVNode as _createElementVNode, openBlock as _openBlock, createElementBlock as _createElementBlock } from \\"vue\\"
const _hoisted_1 = /*#__PURE__*/_createElementVNode(\\"u-text\\", null, \\"hello\\", -1 /* HOISTED */)
const _hoisted_2 = [
_hoisted_1
const _hoisted_1 = { renderWhole: true }
const _hoisted_2 = /*#__PURE__*/_createElementVNode(\\"u-text\\", null, \\"hello\\", -1 /* HOISTED */)
const _hoisted_3 = [
_hoisted_2
]
export function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock(\\"view\\",
null, _hoisted_2
))
return (_openBlock(), _createElementBlock(\\"view\\",
_hoisted_1, _hoisted_3
))
}"
`;
exports[`app-nvue: compiler <view>hello</view> 1`] = `
"import { createElementVNode as _createElementVNode, openBlock as _openBlock, createElementBlock as _createElementBlock } from \\"vue\\"
const _hoisted_1 = /*#__PURE__*/_createElementVNode(\\"u-text\\", null, \\"hello\\", -1 /* HOISTED */)
const _hoisted_2 = [
_hoisted_1
const _hoisted_1 = { renderWhole: true }
const _hoisted_2 = /*#__PURE__*/_createElementVNode(\\"u-text\\", null, \\"hello\\", -1 /* HOISTED */)
const _hoisted_3 = [
_hoisted_2
]
export function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock(\\"view\\",
null, _hoisted_2
))
return (_openBlock(), _createElementBlock(\\"view\\",
_hoisted_1, _hoisted_3
))
}"
`;
exports[`app-nvue: compiler <view>hello{{a}}<view>aaa{{a}}</view>{{b}}</view> 1`] = `
"import { createElementVNode as _createElementVNode, toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock } from \\"vue\\"
const _hoisted_1 = /*#__PURE__*/_createElementVNode(\\"u-text\\", null, \\"hello\\", -1 /* HOISTED */)
const _hoisted_2 = /*#__PURE__*/_createElementVNode(\\"u-text\\", null, \\"aaa\\", -1 /* HOISTED */)
const _hoisted_1 = { renderWhole: true }
const _hoisted_2 = /*#__PURE__*/_createElementVNode(\\"u-text\\", null, \\"hello\\", -1 /* HOISTED */)
const _hoisted_3 = /*#__PURE__*/_createElementVNode(\\"u-text\\", null, \\"aaa\\", -1 /* HOISTED */)
export function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock(\\"view\\",
null
, [
_hoisted_
1
,
return (_openBlock(), _createElementBlock(\\"view\\",
_hoisted_1
, [
_hoisted_
2
,
_createElementVNode(\\"u-text\\", null, _toDisplayString(_ctx.a), 1 /* TEXT */),
_createElementVNode(\\"view\\", null, [
_hoisted_
2
,
_hoisted_
3
,
_createElementVNode(\\"u-text\\", null, _toDisplayString(_ctx.a), 1 /* TEXT */)
]),
_createElementVNode(\\"u-text\\", null, _toDisplayString(_ctx.b), 1 /* TEXT */)
...
...
packages/uni-app-vite/src/nvue/plugin/transforms/transformRenderWhole.ts
浏览文件 @
d9f72436
import
{
renameProp
,
isElementNode
}
from
'
@dcloudio/uni-cli-shared
'
import
{
findProp
,
NodeTransform
}
from
'
@vue/compiler-core
'
import
{
renameProp
,
isElementNode
,
createBindDirectiveNode
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
createSimpleExpression
,
findProp
,
NodeTransform
,
RootNode
,
}
from
'
@vue/compiler-core
'
export
const
transformRenderWhole
:
NodeTransform
=
(
node
,
_
)
=>
{
if
(
!
isElementNode
(
node
))
{
...
...
@@ -12,3 +21,43 @@ export const transformRenderWhole: NodeTransform = (node, _) => {
// render-whole => append
renameProp
(
'
append
'
,
prop
)
}
//
const
RENDER_WHOLE_TAGS
=
[
'
view
'
,
'
scroll-view
'
,
'
swiper
'
,
'
match-media
'
,
'
movable-area
'
,
'
movable-view
'
,
'
cover-view
'
,
'
cover-image
'
,
'
form
'
,
'
picker
'
,
'
picker-view
'
,
'
navigator
'
,
'
map
'
,
]
/**
* 仅当根节点只有一个,标签在白名单,且开发者未主动配置的情况下,才补充
* @param node
*/
export
function
addRenderWhole
(
node
:
RootNode
)
{
if
(
node
.
children
.
length
===
1
)
{
const
element
=
node
.
children
[
0
]
if
(
isElementNode
(
element
)
&&
RENDER_WHOLE_TAGS
.
includes
(
element
.
tag
))
{
if
(
!
findProp
(
element
,
'
render-whole
'
)
&&
!
findProp
(
element
,
'
append
'
)
&&
!
findProp
(
element
,
'
appendAsTree
'
)
)
{
element
.
props
.
push
(
createBindDirectiveNode
(
'
render-whole
'
,
createSimpleExpression
(
'
true
'
)
)
)
}
}
}
}
packages/uni-app-vite/src/nvue/plugin/transforms/transformRootNode.ts
浏览文件 @
d9f72436
...
...
@@ -14,6 +14,7 @@ import {
RootNode
,
TemplateChildNode
,
}
from
'
@vue/compiler-core
'
import
{
addRenderWhole
}
from
'
./transformRenderWhole
'
const
SCROLLER_COMPONENTS
=
[
'
list
'
,
'
scroller
'
,
...
...
@@ -21,10 +22,17 @@ const SCROLLER_COMPONENTS = [
'
waterfall
'
,
'
recycle-list
'
,
]
export
const
transformRootNode
:
NodeTransform
=
(
node
,
context
)
=>
{
if
(
node
.
type
!==
NodeTypes
.
ROOT
||
!
context
.
bindingMetadata
.
__pageOptions
)
{
if
(
node
.
type
!==
NodeTypes
.
ROOT
)
{
return
}
const
isPage
=
!!
context
.
bindingMetadata
.
__pageOptions
if
(
!
isPage
)
{
// 非页面组件,自动为根节点补充 render-whole
return
addRenderWhole
(
node
)
}
const
{
disableScroll
,
scrollIndicator
}
=
context
.
bindingMetadata
.
__pageOptions
as
{
disableScroll
?:
boolean
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录