Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wzj-java
uni-app
提交
4d285abb
U
uni-app
项目概览
wzj-java
/
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,体验更适合开发者的 AI 搜索 >>
提交
4d285abb
编写于
4月 23, 2020
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(v3): text trim
上级
ef933b99
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
143 addition
and
8 deletion
+143
-8
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js
...ompiler/__tests__/compiler-app-plus-extra.service.spec.js
+68
-0
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js
...e-compiler/__tests__/compiler-app-plus-extra.view.spec.js
+68
-0
packages/uni-template-compiler/__tests__/demo.js
packages/uni-template-compiler/__tests__/demo.js
+1
-6
packages/uni-template-compiler/lib/app/service.js
packages/uni-template-compiler/lib/app/service.js
+3
-1
packages/uni-template-compiler/lib/app/view.js
packages/uni-template-compiler/lib/app/view.js
+3
-1
未找到文件。
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js
浏览文件 @
4d285abb
...
...
@@ -182,6 +182,74 @@ describe('codegen', () => {
'
<image src="~@/static/logo.png"/>
'
,
`with(this){return _c('image',{attrs:{"_i":0}})}`
)
})
it
(
'
generate text trim
'
,
()
=>
{
assertCodegen
(
'
<view>text</view>
'
,
`with(this){return _c('view')}`
)
assertCodegen
(
'
<view> text </view>
'
,
`with(this){return _c('view')}`
)
assertCodegen
(
'
<text>{{line_one_cn+
\'
\'
}}</text>
'
,
`with(this){return _c('text',[_v((_$s(0,'t0-0',_s(line_one_cn+' '))))])}`
)
assertCodegen
(
'
<text>{{" "+line_one_cn}}</text>
'
,
`with(this){return _c('text',[_v((_$s(0,'t0-0',_s(" "+line_one_cn))))])}`
)
assertCodegen
(
'
<text>
\n
N: {{title}}
\n
′</text>
'
,
`with(this){return _c('text',[_v((_$s(0,'t0-0',_s(title))))])}`
)
assertCodegen
(
'
<text>我是第一行
\n
我的第二行</text>
'
,
`with(this){return _c('text')}`
)
assertCodegen
(
'
<text>我是第一行
\n
我的第二行1{{title}}</text>
'
,
`with(this){return _c('text',[_v((_$s(0,'t0-0',_s(title))))])}`
)
assertCodegen
(
`<text>我是第一行
我的第二行2{{title}}</text>`
,
`with(this){return _c('text',[_v((_$s(0,'t0-0',_s(title))))])}`
)
assertCodegen
(
'
<view> text text </view>
'
,
`with(this){return _c('view')}`
)
assertCodegen
(
'
<view>text {{text}} text</view>
'
,
`with(this){return _c('view',[_v((_$s(0,'t0-0',_s(text))))])}`
)
assertCodegen
(
'
<view> text {{text}} 文本 </view>
'
,
`with(this){return _c('view',[_v((_$s(0,'t0-0',_s(text))))])}`
)
assertCodegen
(
'
<view>{{text}} text text </view>
'
,
`with(this){return _c('view',[_v((_$s(0,'t0-0',_s(text))))])}`
)
assertCodegen
(
'
<view> {{text}} text text </view>
'
,
`with(this){return _c('view',[_v((_$s(0,'t0-0',_s(text))))])}`
)
assertCodegen
(
'
<view>{{text}} text text {{text}}</view>
'
,
`with(this){return _c('view',[_v((_$s(0,'t0-0',_s(text)))+(_$s(0,'t0-1',_s(text))))])}`
)
assertCodegen
(
'
<view> {{text}} text text {{text}} </view>
'
,
`with(this){return _c('view',[_v((_$s(0,'t0-0',_s(text)))+(_$s(0,'t0-1',_s(text))))])}`
)
})
})
/* eslint-enable quotes */
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js
浏览文件 @
4d285abb
...
...
@@ -122,5 +122,73 @@ describe('codegen', () => {
`with(this){return _c('v-uni-image',{attrs:{"src":"/static/logo.png","_i":0}})}`
)
})
it
(
'
generate text trim
'
,
()
=>
{
assertCodegen
(
'
<view>text</view>
'
,
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v("text")])}`
)
assertCodegen
(
'
<view> text </view>
'
,
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v("text")])}`
)
assertCodegen
(
'
<text>{{line_one_cn+
\'
\'
}}</text>
'
,
`with(this){return _c('v-uni-text',{attrs:{"_i":0}},[_v((_$g(0,'t0-0')))])}`
)
assertCodegen
(
'
<text>{{" "+line_one_cn}}</text>
'
,
`with(this){return _c('v-uni-text',{attrs:{"_i":0}},[_v((_$g(0,'t0-0')))])}`
)
assertCodegen
(
'
<text>
\n
N: {{title}}
\n
′</text>
'
,
`with(this){return _c('v-uni-text',{attrs:{"_i":0}},[_v("N: "+(_$g(0,'t0-0'))+"\\n′")])}`
)
assertCodegen
(
'
<text>我是第一行
\n
我的第二行</text>
'
,
`with(this){return _c('v-uni-text',{attrs:{"_i":0}},[_v("我是第一行\\n我的第二行")])}`
)
assertCodegen
(
'
<text>我是第一行
\n
我的第二行1{{title}}</text>
'
,
`with(this){return _c('v-uni-text',{attrs:{"_i":0}},[_v("我是第一行\\n我的第二行1"+(_$g(0,'t0-0')))])}`
)
assertCodegen
(
`<text>我是第一行
我的第二行2{{title}}</text>`
,
`with(this){return _c('v-uni-text',{attrs:{"_i":0}},[_v("我是第一行\\n 我的第二行2"+(_$g(0,'t0-0')))])}`
)
assertCodegen
(
'
<view> text text </view>
'
,
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v("text text")])}`
)
assertCodegen
(
'
<view>text {{text}} text</view>
'
,
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v("text "+(_$g(0,'t0-0'))+" text")])}`
)
assertCodegen
(
'
<view> text {{text}} 文本 </view>
'
,
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v("text "+(_$g(0,'t0-0'))+" 文本")])}`
)
assertCodegen
(
'
<view>{{text}} text text </view>
'
,
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v((_$g(0,'t0-0'))+" text text")])}`
)
assertCodegen
(
'
<view> {{text}} text text </view>
'
,
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v((_$g(0,'t0-0'))+" text text")])}`
)
assertCodegen
(
'
<view>{{text}} text text {{text}}</view>
'
,
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v((_$g(0,'t0-0'))+" text text "+(_$g(0,'t0-1')))])}`
)
assertCodegen
(
'
<view> {{text}} text text {{text}} </view>
'
,
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v((_$g(0,'t0-0'))+" text text "+(_$g(0,'t0-1')))])}`
)
})
})
/* eslint-enable quotes */
packages/uni-template-compiler/__tests__/demo.js
浏览文件 @
4d285abb
...
...
@@ -19,12 +19,7 @@ const scopedPath = path.resolve(__dirname, '../../')
const
compiler
=
require
(
'
../lib
'
)
const
res
=
compiler
.
compile
(
`
<text>
123
456
</text>
<view> {{text}} text text {{text}} </view>
`
,
{
miniprogram
:
true
,
resourcePath
:
'
/User/fxy/Documents/test.wxml
'
,
...
...
packages/uni-template-compiler/lib/app/service.js
浏览文件 @
4d285abb
...
...
@@ -105,7 +105,9 @@ function checkAutoFill (el) {
}
function
transformNode
(
el
,
parent
,
state
,
isScopedSlot
)
{
if
(
el
.
type
===
3
)
{
if
(
el
.
type
===
3
)
{
// fixed by xxxxxx 注意:保持平台一致性,trim 一下,理论上service不需要,保险起见也处理一遍
el
.
text
=
el
.
text
.
trim
()
return
}
parseBlock
(
el
,
parent
)
...
...
packages/uni-template-compiler/lib/app/view.js
浏览文件 @
4d285abb
...
...
@@ -100,7 +100,9 @@ const includeDirs = [
const
ignoreDirs
=
[
'
model
'
]
function
transformNode
(
el
,
parent
,
state
,
isScopedSlot
)
{
if
(
el
.
type
===
3
)
{
if
(
el
.
type
===
3
)
{
// fixed by xxxxxx 注意:保持平台一致性,trim 一下
el
.
text
=
el
.
text
.
trim
()
return
}
parseBlock
(
el
,
parent
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录