Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wychl
uni-app
提交
4772e7d5
U
uni-app
项目概览
wychl
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
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,发现更多精彩内容 >>
提交
4772e7d5
编写于
6月 21, 2021
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mp): 修复 修改class编译导致部分小程序(如:百度)无法使用externalClasses
上级
e4ec80ac
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
81 addition
and
48 deletion
+81
-48
packages/uni-template-compiler/__tests__/compiler-extra.spec.js
...es/uni-template-compiler/__tests__/compiler-extra.spec.js
+9
-9
packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js
...ni-template-compiler/__tests__/compiler-mp-alipay.spec.js
+12
-8
packages/uni-template-compiler/__tests__/compiler-mp-baidu.spec.js
...uni-template-compiler/__tests__/compiler-mp-baidu.spec.js
+6
-0
packages/uni-template-compiler/__tests__/compiler-mp-kuaishou.spec.js
...-template-compiler/__tests__/compiler-mp-kuaishou.spec.js
+6
-0
packages/uni-template-compiler/__tests__/compiler-mp-qq.spec.js
...es/uni-template-compiler/__tests__/compiler-mp-qq.spec.js
+22
-16
packages/uni-template-compiler/__tests__/compiler-mp-toutiao.spec.js
...i-template-compiler/__tests__/compiler-mp-toutiao.spec.js
+12
-8
packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js
...ni-template-compiler/__tests__/compiler-mp-weixin.spec.js
+6
-0
packages/uni-template-compiler/lib/script/traverse/data/class.js
...s/uni-template-compiler/lib/script/traverse/data/class.js
+8
-7
未找到文件。
packages/uni-template-compiler/__tests__/compiler-extra.spec.js
浏览文件 @
4772e7d5
...
...
@@ -64,14 +64,14 @@ describe('mp:compiler-extra', () => {
)
assertCodegen
(
'
<view class="static" :class="[{ active: isActive }, errorClass]"></view>
'
,
'
<view class="{{[
\'
static
data-v-4
\'
,[(isActive)?
\'
active
\'
:
\'\'
],errorClass]}}"></view>
'
,
'
<view class="{{[
\'
static
\'
,
\'
data-v-4
\'
,[(isActive)?
\'
active
\'
:
\'\'
],errorClass]}}"></view>
'
,
undefined
,
{
scopeId
:
'
data-v-4
'
}
)
assertCodegen
(
'
<view ref="ref" :class="[{ active: isActive }, errorClass]"></view>
'
,
'
<view data-ref="ref" class="{{[
\'
data-v-5
vue-ref
\'
,[(isActive)?
\'
active
\'
:
\'\'
],errorClass]}}"></view>
'
,
'
<view data-ref="ref" class="{{[
\'
data-v-5
\'
,
\'
vue-ref
\'
,[(isActive)?
\'
active
\'
:
\'\'
],errorClass]}}"></view>
'
,
undefined
,
{
scopeId
:
'
data-v-5
'
}
...
...
@@ -92,7 +92,7 @@ describe('mp:compiler-extra', () => {
// )
assertCodegen
(
'
<view :class="view" class="view"></view>
'
,
'
<view class="{{[
\'
view
data-v-7
\'
,view]}}"></view>
'
,
'
<view class="{{[
\'
view
\'
,
\'
data-v-7
\'
,view]}}"></view>
'
,
undefined
,
{
scopeId
:
'
data-v-7
'
}
...
...
@@ -378,23 +378,23 @@ describe('mp:compiler-extra', () => {
)
assertCodegen
(
'
<p class="static" :class="{ active: isActive,
\'
text-danger
\'
: hasError }">2</p>
'
,
'
<view class="{{[
\'
static
_p
\'
,(isActive)?
\'
active
\'
:
\'\'
,(hasError)?
\'
text-danger
\'
:
\'\'
]}}">2</view>
'
'
<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>
'
'
<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>
'
'
<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>
'
'
<view class="{{[
\'
static
\'
,
\'
_p
\'
,[(isActive)?
\'
active
\'
:
\'\'
],errorClass]}}">5</view>
'
)
assertCodegen
(
'
<div class="container" :class="computedClassObject">6</div>
'
,
'
<view class="{{[
\'
container
_div
\'
,computedClassObject]}}">6</view>
'
'
<view class="{{[
\'
container
\'
,
\'
_div
\'
,computedClassObject]}}">6</view>
'
)
// assertCodegen(
// `<div class="container" :class="computedClassObject">6</div>`,
...
...
@@ -411,7 +411,7 @@ describe('mp:compiler-extra', () => {
)
assertCodegen
(
'
<p :class="classStr1 || classStr2" class="bg">9</p>
'
,
'
<view class="{{[
\'
bg
_p
\'
,classStr1||classStr2]}}">9</view>
'
'
<view class="{{[
\'
bg
\'
,
\'
_p
\'
,classStr1||classStr2]}}">9</view>
'
)
})
...
...
packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js
浏览文件 @
4772e7d5
...
...
@@ -137,27 +137,27 @@ describe('mp:compiler-mp-alipay', () => {
)
assertCodegen
(
'
<p class="static" :class="{ active: isActive,
\'
text-danger
\'
: hasError }">2</p>
'
,
'
<view class="{{(((
\'
static
_p
\'
)+
\'
\'
+((isActive)?
\'
active
\'
:
\'\'
))+
\'
\'
+((hasError)?
\'
text-danger
\'
:
\'\'
))}}">2</view>
'
'
<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>
'
'
<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>
'
'
<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>
'
'
<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>
'
'
<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>
'
'
<view class="{{((
(
\'
container
\'
)+
\'
\'
+
\'
_div
\'
)+
\'
\'
+computedClassObject)}}">6</view>
'
)
// assertCodegen(
// `<div class="container" :class="computedClassObject">6</div>`,
...
...
@@ -174,11 +174,15 @@ describe('mp:compiler-mp-alipay', () => {
)
assertCodegen
(
'
<p :class="classStr1 || classStr2" class="bg">9</p>
'
,
'
<view class="{{((
\'
bg
_p
\'
)+
\'
\'
+(classStr1||classStr2))}}">9</view>
'
'
<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>
'
'
<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>
'
)
})
...
...
packages/uni-template-compiler/__tests__/compiler-mp-baidu.spec.js
浏览文件 @
4772e7d5
...
...
@@ -15,6 +15,12 @@ function assertCodegen (template, templateCode, renderCode = 'with(this){}', opt
}
describe
(
'
mp:compiler-mp-baidu
'
,
()
=>
{
it
(
'
generate class
'
,
()
=>
{
assertCodegen
(
'
<view class="a external-class c" :class="class1">hello world</view>
'
,
'
<view class="{{[
\'
a
\'
,
\'
external-class
\'
,
\'
c
\'
,class1]}}">hello world</view>
'
)
})
it
(
'
generate v-for directive
'
,
()
=>
{
assertCodegen
(
'
<view><view v-for="(item,index) in items" :key="index"></view></view>
'
,
...
...
packages/uni-template-compiler/__tests__/compiler-mp-kuaishou.spec.js
浏览文件 @
4772e7d5
...
...
@@ -20,6 +20,12 @@ function assertCodegen (template, templateCode, renderCode = 'with(this){}', opt
}
describe
(
'
mp:compiler-mp-kuaishou
'
,
()
=>
{
it
(
'
generate class
'
,
()
=>
{
assertCodegen
(
'
<view class="a external-class c" :class="class1">hello world</view>
'
,
'
<view class="{{[
\'
a
\'
,
\'
external-class
\'
,
\'
c
\'
,class1]}}">hello world</view>
'
)
})
it
(
'
generate scoped slot
'
,
()
=>
{
assertCodegen
(
'
<foo><template slot-scope="{bar}">{{ bar.foo }}</template></foo>
'
,
...
...
packages/uni-template-compiler/__tests__/compiler-mp-qq.spec.js
浏览文件 @
4772e7d5
const
compiler
=
require
(
'
../lib
'
)
function
assertCodegen
(
template
,
templateCode
,
renderCode
=
'
with(this){}
'
,
options
=
{})
{
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-qq
'
},
options
)
})
expect
(
res
.
template
).
toBe
(
templateCode
)
expect
(
res
.
render
).
toBe
(
renderCode
)
}
resourcePath
:
'
test.wxml
'
,
mp
:
Object
.
assign
({
minified
:
true
,
isTest
:
true
,
platform
:
'
mp-qq
'
},
options
)
})
expect
(
res
.
template
).
toBe
(
templateCode
)
expect
(
res
.
render
).
toBe
(
renderCode
)
}
describe
(
'
mp:compiler-mp-qq
'
,
()
=>
{
it
(
'
generate class
'
,
()
=>
{
assertCodegen
(
'
<view class="a external-class c" :class="class1">hello world</view>
'
,
'
<view class="{{[
\'
a
\'
,
\'
external-class
\'
,
\'
c
\'
,class1]}}">hello world</view>
'
)
})
it
(
'
generate text trim
'
,
()
=>
{
assertCodegen
(
'
<text>
\n
N: {{title}}
\n
′</text>
'
,
...
...
@@ -33,5 +39,5 @@ describe('mp:compiler-mp-qq', () => {
我的第二行2{{title}}</text>`
,
'
<text>{{"我是第一行3
\\\\
n 我的第二行2"+title}}</text>
'
)
})
})
})
packages/uni-template-compiler/__tests__/compiler-mp-toutiao.spec.js
浏览文件 @
4772e7d5
...
...
@@ -36,27 +36,27 @@ describe('mp:compiler-mp-toutiao', () => {
)
assertCodegen
(
'
<p class="static" :class="{ active: isActive,
\'
text-danger
\'
: hasError }">2</p>
'
,
'
<view class="{{(((
\'
static
_p
\'
)+
\'
\'
+((isActive)?
\'
active
\'
:
\'\'
))+
\'
\'
+((hasError)?
\'
text-danger
\'
:
\'\'
))}}">2</view>
'
'
<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>
'
'
<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>
'
'
<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>
'
'
<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>
'
'
<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>
'
'
<view class="{{((
(
\'
container
\'
)+
\'
\'
+
\'
_div
\'
)+
\'
\'
+computedClassObject)}}">6</view>
'
)
// assertCodegen(
// `<div class="container" :class="computedClassObject">6</div>`,
...
...
@@ -73,11 +73,15 @@ describe('mp:compiler-mp-toutiao', () => {
)
assertCodegen
(
'
<p :class="classStr1 || classStr2" class="bg">9</p>
'
,
'
<view class="{{((
\'
bg
_p
\'
)+
\'
\'
+(classStr1||classStr2))}}">9</view>
'
'
<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>
'
'
<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>
'
)
})
...
...
packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js
浏览文件 @
4772e7d5
...
...
@@ -20,6 +20,12 @@ function assertCodegen (template, templateCode, renderCode = 'with(this){}', opt
}
describe
(
'
mp:compiler-mp-weixin
'
,
()
=>
{
it
(
'
generate class
'
,
()
=>
{
assertCodegen
(
'
<view class="a external-class c" :class="class1">hello world</view>
'
,
'
<view class="{{[
\'
a
\'
,
\'
external-class
\'
,
\'
c
\'
,class1]}}">hello world</view>
'
)
})
it
(
'
generate scoped slot
'
,
()
=>
{
assertCodegen
(
'
<foo><template slot-scope="{bar}">{{ bar.foo }}</template></foo>
'
,
...
...
packages/uni-template-compiler/lib/script/traverse/data/class.js
浏览文件 @
4772e7d5
...
...
@@ -8,9 +8,9 @@ function processClassArrayExpressionElements (classArrayExpression) {
let
binaryExpression
classArrayExpression
.
elements
.
forEach
(
expr
=>
{
if
(
t
.
isArrayExpression
(
expr
))
{
expr
=
processClassArrayExpressionElements
(
expr
)
}
if
(
t
.
isArrayExpression
(
expr
))
{
expr
=
processClassArrayExpressionElements
(
expr
)
}
if
(
!
binaryExpression
)
{
binaryExpression
=
t
.
parenthesizedExpression
(
expr
)
}
else
{
...
...
@@ -31,9 +31,10 @@ function processClassArrayExpressionElements (classArrayExpression) {
function
processStaticClass
(
classArrayExpression
,
staticClassPath
,
state
)
{
if
(
staticClassPath
)
{
classArrayExpression
.
elements
.
unshift
(
t
.
stringLiteral
(
staticClassPath
.
node
.
value
.
value
)
)
const
staticClassPathArr
=
staticClassPath
.
node
.
value
.
value
.
split
(
'
'
)
for
(
let
len
=
staticClassPathArr
.
length
,
index
=
len
-
1
;
index
>=
0
;
index
--
)
{
classArrayExpression
.
elements
.
unshift
(
t
.
stringLiteral
(
staticClassPathArr
[
index
]))
}
staticClassPath
.
remove
()
}
if
(
...
...
@@ -135,4 +136,4 @@ module.exports = function processClass (paths, path, state) {
}
}
return
[]
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录