Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Velpro187
uni-app
提交
52b9e8c2
U
uni-app
项目概览
Velpro187
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
52b9e8c2
编写于
10月 19, 2021
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(mp-lark): complier tests
上级
231df55e
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
94 addition
and
0 deletion
+94
-0
packages/uni-template-compiler/__tests__/compiler-mp-lark.spec.js
.../uni-template-compiler/__tests__/compiler-mp-lark.spec.js
+94
-0
未找到文件。
packages/uni-template-compiler/__tests__/compiler-mp-lark.spec.js
0 → 100644
浏览文件 @
52b9e8c2
const
compiler
=
require
(
'
../lib
'
)
function
assertCodegen
(
template
,
templateCode
,
renderCode
=
'
with(this){}
'
,
options
=
{})
{
const
res
=
compiler
.
compile
(
template
,
{
resourcePath
:
'
test.wxml
'
,
mp
:
Object
.
assign
({
minified
:
true
,
isTest
:
true
,
platform
:
'
mp-lark
'
},
options
)
})
expect
(
res
.
template
).
toBe
(
templateCode
)
expect
(
res
.
render
).
toBe
(
renderCode
)
}
describe
(
'
mp:compiler-mp-lark
'
,
()
=>
{
it
(
'
generate v-for directive
'
,
()
=>
{
assertCodegen
(
'
<view><view v-for="(item,index) in items" :key="index"></view></view>
'
,
'
<view><block tt:for="{{items}}" tt:for-item="item" tt:for-index="index" tt:key="index"><view></view></block></view>
'
)
})
it
(
'
generate ref
'
,
()
=>
{
assertCodegen
(
'
<my-component ref="ref"></my-component>
'
,
'
<my-component class="vue-ref" vue-id="551070e6-1" data-ref="ref" bind:__l="__l"></my-component>
'
)
})
it
(
'
generate class binding
'
,
()
=>
{
assertCodegen
(
'
<div :class="{ active: isActive }">1</div>
'
,
'
<view class="{{((
\'
_div
\'
)+
\'
\'
+((isActive)?
\'
active
\'
:
\'\'
))}}">1</view>
'
)
assertCodegen
(
'
<p class="static" :class="{ active: isActive,
\'
text-danger
\'
: hasError }">2</p>
'
,
'
<view class="{{((((
\'
static
\'
)+
\'
\'
+
\'
_p
\'
)+
\'
\'
+((isActive)?
\'
active
\'
:
\'\'
))+
\'
\'
+((hasError)?
\'
text-danger
\'
:
\'\'
))}}">2</view>
'
)
assertCodegen
(
'
<p class="static" :class="[activeClass, errorClass]">3</p>
'
,
'
<view class="{{((((
\'
static
\'
)+
\'
\'
+
\'
_p
\'
)+
\'
\'
+activeClass)+
\'
\'
+errorClass)}}">3</view>
'
)
assertCodegen
(
'
<p class="static" :class="[isActive ? activeClass :
\'\'
, errorClass]">4</p>
'
,
'
<view class="{{((((
\'
static
\'
)+
\'
\'
+
\'
_p
\'
)+
\'
\'
+(isActive?activeClass:
\'\'
))+
\'
\'
+errorClass)}}">4</view>
'
)
assertCodegen
(
'
<p class="static" :class="[{ active: isActive }, errorClass]">5</p>
'
,
'
<view class="{{((((
\'
static
\'
)+
\'
\'
+
\'
_p
\'
)+
\'
\'
+((isActive)?
\'
active
\'
:
\'\'
))+
\'
\'
+errorClass)}}">5</view>
'
)
assertCodegen
(
'
<p class="static" :class="[{ active: isActive, disabled: isDisabled }, errorClass]">52</p>
'
,
'
<view class="{{((((
\'
static
\'
)+
\'
\'
+
\'
_p
\'
)+
\'
\'
+(((isActive)?
\'
active
\'
:
\'\'
)+
\'
\'
+((isDisabled)?
\'
disabled
\'
:
\'\'
)))+
\'
\'
+errorClass)}}">52</view>
'
)
assertCodegen
(
'
<div class="container" :class="computedClassObject">6</div>
'
,
'
<view class="{{(((
\'
container
\'
)+
\'
\'
+
\'
_div
\'
)+
\'
\'
+computedClassObject)}}">6</view>
'
)
// assertCodegen(
// `<div class="container" :class="computedClassObject">6</div>`,
// `<view class="{{$root.c0}}">6</view>`,
// `with(this){var c0=__get_class(computedClassObject,"container");$mp.data=Object.assign({},{$root:{c0:c0}})}`
// )
assertCodegen
(
'
<p :class="index === currentIndex ? activeClass : itemClass">7</p>
'
,
'
<view class="{{((
\'
_p
\'
)+
\'
\'
+(index===currentIndex?activeClass:itemClass))}}">7</view>
'
)
assertCodegen
(
'
<p :class="
\'
m-content-head-
\'
+message.user">8</p>
'
,
'
<view class="{{((
\'
_p
\'
)+
\'
\'
+(
\'
m-content-head-
\'
+message.user))}}">8</view>
'
)
assertCodegen
(
'
<p :class="classStr1 || classStr2" class="bg">9</p>
'
,
'
<view class="{{(((
\'
bg
\'
)+
\'
\'
+
\'
_p
\'
)+
\'
\'
+(classStr1||classStr2))}}">9</view>
'
)
assertCodegen
(
'
<p class="static" :class="[{ active: isActive }, errorClass, [flex,
\'
flex-row
\'
]]">10</p>
'
,
'
<view class="{{(((((
\'
static
\'
)+
\'
\'
+
\'
_p
\'
)+
\'
\'
+((isActive)?
\'
active
\'
:
\'\'
))+
\'
\'
+errorClass)+
\'
\'
+((flex)+
\'
\'
+
\'
flex-row
\'
))}}">10</view>
'
)
assertCodegen
(
'
<p class="a external-class c" :class="class1">hello world</p>
'
,
'
<view class="{{(((((
\'
a
\'
)+
\'
\'
+
\'
external-class
\'
)+
\'
\'
+
\'
c
\'
)+
\'
\'
+
\'
_p
\'
)+
\'
\'
+class1)}}">hello world</view>
'
)
})
it
(
'
generate v-show directive
'
,
()
=>
{
assertCodegen
(
'
<test v-show="shown">hello world</test>
'
,
'
<test bind:-data-custom-hidden="{{!(shown)}}" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[
\'
default
\'
]}}">hello world</test>
'
)
})
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录