Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
20岁爱吃必胜客
uni-app
提交
af4a2304
U
uni-app
项目概览
20岁爱吃必胜客
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
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,发现更多精彩内容 >>
提交
af4a2304
编写于
5月 07, 2020
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: boolean attribute
上级
fd2cbbf1
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
67 addition
and
56 deletion
+67
-56
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js
...ompiler/__tests__/compiler-app-plus-extra.service.spec.js
+10
-0
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js
...e-compiler/__tests__/compiler-app-plus-extra.view.spec.js
+10
-0
packages/uni-template-compiler/__tests__/compiler-extra.spec.js
...es/uni-template-compiler/__tests__/compiler-extra.spec.js
+10
-0
packages/uni-template-compiler/__tests__/demo.js
packages/uni-template-compiler/__tests__/demo.js
+3
-3
packages/uni-template-compiler/lib/app/pre-transform-node.js
packages/uni-template-compiler/lib/app/pre-transform-node.js
+0
-22
packages/uni-template-compiler/lib/bool-attr.js
packages/uni-template-compiler/lib/bool-attr.js
+19
-0
packages/uni-template-compiler/lib/index.js
packages/uni-template-compiler/lib/index.js
+10
-7
packages/vue-cli-plugin-hbuilderx/build/vue-loader.conf.js
packages/vue-cli-plugin-hbuilderx/build/vue-loader.conf.js
+2
-1
packages/vue-cli-plugin-hbuilderx/packages/weex-template-compiler/build.js
...plugin-hbuilderx/packages/weex-template-compiler/build.js
+3
-1
packages/vue-cli-plugin-uni/lib/h5/compiler-options.js
packages/vue-cli-plugin-uni/lib/h5/compiler-options.js
+0
-22
未找到文件。
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js
浏览文件 @
af4a2304
...
...
@@ -250,6 +250,16 @@ describe('codegen', () => {
'
<view> {{text}} text text {{text}} </view>
'
,
`with(this){return _c('view',[_v((_$s(0,'t0-0',_s(text)))+(_$s(0,'t0-1',_s(text))))])}`
)
})
it
(
'
generate bool attr
'
,
()
=>
{
assertCodegen
(
'
<video controls/>
'
,
`with(this){return _c('video',{attrs:{"_i":0}})}`
)
assertCodegen
(
'
<video controls=""/>
'
,
`with(this){return _c('video',{})}`
)
})
})
/* eslint-enable quotes */
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js
浏览文件 @
af4a2304
...
...
@@ -189,6 +189,16 @@ describe('codegen', () => {
'
<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')))])}`
)
})
it
(
'
generate bool attr
'
,
()
=>
{
assertCodegen
(
'
<video controls/>
'
,
`with(this){return _c('v-uni-video',{attrs:{"controls":true,"_i":0}})}`
)
assertCodegen
(
'
<video controls=""/>
'
,
`with(this){return _c('v-uni-video',{attrs:{"controls":"","_i":0}})}`
)
})
})
/* eslint-enable quotes */
packages/uni-template-compiler/__tests__/compiler-extra.spec.js
浏览文件 @
af4a2304
...
...
@@ -646,5 +646,15 @@ describe('mp:compiler-extra', () => {
'
<view v-for="item in list" @click="test(item)">{{ item }}</view>
'
,
'
<block wx:for="{{list}}" wx:for-item="item" wx:for-index="__i0__"><view data-event-opts="{{[[
\'
tap
\'
,[[
\'
test
\'
,[
\'
$0
\'
],[[[
\'
list
\'
,
\'\'
,__i0__]]]]]]]}}" bindtap="__e">{{item}}</view></block>
'
)
})
it
(
'
generate bool attr
'
,
()
=>
{
assertCodegen
(
'
<video controls/>
'
,
'
<video controls="{{true}}"></video>
'
)
assertCodegen
(
'
<video controls=""/>
'
,
'
<video controls></video>
'
)
})
})
packages/uni-template-compiler/__tests__/demo.js
浏览文件 @
af4a2304
...
...
@@ -19,7 +19,7 @@ const scopedPath = path.resolve(__dirname, '../../')
const
compiler
=
require
(
'
../lib
'
)
const
res
=
compiler
.
compile
(
`
<vi
ew> {{text}} text text {{text}} </view
>
<vi
deo controls=""/
>
`
,
{
miniprogram
:
true
,
resourcePath
:
'
/User/fxy/Documents/test.wxml
'
,
...
...
@@ -32,9 +32,9 @@ const res = compiler.compile(
mp
:
{
platform
:
'
mp-weixin
'
},
filterModules
:
[
'
swipe
'
]
,
filterModules
:
[
'
swipe
'
]
// service: true,
view
:
true
//
view: true
})
console
.
log
(
require
(
'
util
'
).
inspect
(
res
,
{
...
...
packages/uni-template-compiler/lib/app/pre-transform-node.js
浏览文件 @
af4a2304
...
...
@@ -4,32 +4,10 @@ const {
addRawAttr
}
=
require
(
'
./util
'
)
const
dirRE
=
/^v-|^@|^:|^#/
/**
* 兼容小程序Boolean属性的怪异行为(<custom loading/>为true,<custom loading=""/>为false)
* @param {Object} el
*/
function
fixBooleanAttribute
(
el
)
{
if
(
!
el
.
attrsList
)
{
return
}
el
.
attrsList
.
forEach
(
attr
=>
{
if
(
attr
.
bool
)
{
// <custom loading/> => <custom :loading="true"/>
if
(
!
dirRE
.
test
(
attr
.
name
)
&&
attr
.
name
!==
'
inline-template
'
)
{
delete
el
.
attrsMap
[
attr
.
name
]
attr
.
name
=
'
:
'
+
attr
.
name
attr
.
value
=
'
true
'
el
.
attrsMap
[
attr
.
name
]
=
attr
.
value
}
}
})
}
module
.
exports
=
function
preTransformNode
(
el
,
options
)
{
if
(
!
hasOwn
(
options
,
'
nid
'
))
{
options
.
nid
=
0
}
fixBooleanAttribute
(
el
)
addRawAttr
(
el
,
ID
,
options
.
nid
++
)
if
(
el
.
attrsMap
[
'
v-for
'
])
{
el
.
forId
=
el
.
attrsMap
[
ID
]
...
...
packages/uni-template-compiler/lib/bool-attr.js
0 → 100644
浏览文件 @
af4a2304
const
dirRE
=
/^v-|^@|^:|^#/
module
.
exports
=
{
preTransformNode
(
el
)
{
if
(
!
el
.
attrsList
)
{
return
}
el
.
attrsList
.
forEach
(
attr
=>
{
if
(
attr
.
bool
)
{
if
(
!
dirRE
.
test
(
attr
.
name
)
&&
attr
.
name
!==
'
inline-template
'
)
{
delete
el
.
attrsMap
[
attr
.
name
]
attr
.
name
=
'
:
'
+
attr
.
name
attr
.
value
=
'
true
'
el
.
attrsMap
[
attr
.
name
]
=
attr
.
value
}
}
})
}
}
packages/uni-template-compiler/lib/index.js
浏览文件 @
af4a2304
...
...
@@ -44,9 +44,12 @@ module.exports = {
)
{
(
options
.
modules
||
(
options
.
modules
=
[])).
push
(
autoComponentsModule
)
}
if
(
!
options
.
modules
)
{
options
.
modules
=
[]
}
// transformAssetUrls
(
options
.
modules
||
(
options
.
modules
=
[])).
push
(
require
(
'
./asset-url
'
))
options
.
modules
.
push
(
require
(
'
./asset-url
'
))
options
.
modules
.
push
(
require
(
'
./bool-attr
'
))
options
.
isUnaryTag
=
isUnaryTag
// 将 autoComponents 挂在 isUnaryTag 上边
...
...
@@ -54,7 +57,7 @@ module.exports = {
options
.
preserveWhitespace
=
false
if
(
options
.
service
)
{
(
options
.
modules
||
(
options
.
modules
=
[]))
.
push
(
require
(
'
./app/service
'
))
options
.
modules
.
push
(
require
(
'
./app/service
'
))
options
.
optimize
=
false
// 启用 staticRenderFns
// domProps => attrs
options
.
mustUseProp
=
()
=>
false
...
...
@@ -68,7 +71,7 @@ module.exports = {
throw
e
}
}
else
if
(
options
.
view
)
{
(
options
.
modules
||
(
options
.
modules
=
[]))
.
push
(
require
(
'
./app/view
'
))
options
.
modules
.
push
(
require
(
'
./app/view
'
))
options
.
optimize
=
false
// 暂不启用 staticRenderFns
options
.
isUnaryTag
=
isUnaryTag
options
.
isReservedTag
=
(
tagName
)
=>
false
// 均为组件
...
...
@@ -80,14 +83,14 @@ module.exports = {
}
}
else
if
(
options
[
'
quickapp-native
'
])
{
// 后续改版,应统一由具体包实现
(
options
.
modules
||
(
options
.
modules
=
[]))
.
push
(
require
(
'
@dcloudio/uni-quickapp-native/lib/compiler-module
'
))
options
.
modules
.
push
(
require
(
'
@dcloudio/uni-quickapp-native/lib/compiler-module
'
))
}
if
(
!
options
.
mp
)
{
// h5,quickapp-native
return
compileTemplate
(
source
,
options
,
compile
)
}
(
options
.
modules
||
(
options
.
modules
=
[]))
.
push
(
compilerModule
)
options
.
modules
.
push
(
compilerModule
)
if
(
options
.
mp
.
platform
===
'
mp-alipay
'
)
{
options
.
modules
.
push
(
compilerAlipayModule
)
...
...
@@ -147,7 +150,7 @@ module.exports = {
delete
state
.
files
// resolve scoped slots
res
.
generic
=
state
.
generic
||
[]
res
.
generic
=
state
.
generic
||
[]
delete
state
.
generic
// define scoped slots
...
...
packages/vue-cli-plugin-hbuilderx/build/vue-loader.conf.js
浏览文件 @
af4a2304
...
...
@@ -105,7 +105,8 @@ const oldCompile = compiler.compile
compiler
.
compile
=
function
(
source
,
options
=
{})
{
(
options
.
modules
||
(
options
.
modules
=
[])).
push
(
autoComponentsModule
)
options
.
modules
.
push
(
require
(
'
@dcloudio/uni-template-compiler/lib/asset-url
'
))
options
.
modules
.
push
(
require
(
'
@dcloudio/uni-template-compiler/lib/asset-url
'
))
options
.
modules
.
push
(
require
(
'
@dcloudio/uni-template-compiler/lib/bool-attr
'
))
options
.
isUnaryTag
=
isUnaryTag
// 将 autoComponents 挂在 isUnaryTag 上边
...
...
packages/vue-cli-plugin-hbuilderx/packages/weex-template-compiler/build.js
浏览文件 @
af4a2304
...
...
@@ -479,7 +479,9 @@ function parseHTML (html, options) {
:
options
.
shouldDecodeNewlines
;
attrs
[
i
]
=
{
name
:
args
[
1
],
value
:
decodeAttr
(
value
,
shouldDecodeNewlines
)
value
:
decodeAttr
(
value
,
shouldDecodeNewlines
),
// fixed by xxxxxx 标记 Boolean Attribute
bool
:
args
[
3
]
===
undefined
&&
args
[
4
]
===
undefined
&&
args
[
5
]
===
undefined
};
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
&&
options
.
outputSourceRange
)
{
attrs
[
i
].
start
=
args
.
start
+
args
[
0
].
match
(
/^
\s
*/
).
length
;
...
...
packages/vue-cli-plugin-uni/lib/h5/compiler-options.js
浏览文件 @
af4a2304
...
...
@@ -40,32 +40,10 @@ function addTag (tag) {
process
.
UNI_TAGS
.
add
(
tag
)
}
const
dirRE
=
/^v-|^@|^:/
/**
* 兼容小程序Boolean属性的怪异行为(<custom loading/>为true,<custom loading=""/>为false)
* @param {Object} el
*/
function
fixBooleanAttribute
(
el
)
{
if
(
!
el
.
attrsList
)
{
return
}
el
.
attrsList
.
forEach
(
attr
=>
{
if
(
attr
.
bool
)
{
// <custom loading/> => <custom :loading="true"/>
if
(
!
dirRE
.
test
(
attr
.
name
)
&&
attr
.
name
!==
'
inline-template
'
)
{
delete
el
.
attrsMap
[
attr
.
name
]
attr
.
name
=
'
:
'
+
attr
.
name
attr
.
value
=
'
true
'
el
.
attrsMap
[
attr
.
name
]
=
attr
.
value
}
}
})
}
module
.
exports
=
{
h5
:
true
,
modules
:
[
require
(
'
../format-text
'
),
{
preTransformNode
(
el
,
options
)
{
fixBooleanAttribute
(
el
)
if
(
el
.
tag
.
indexOf
(
'
v-uni-
'
)
===
0
)
{
addTag
(
el
.
tag
.
replace
(
'
v-uni-
'
,
''
))
}
else
if
(
hasOwn
(
tags
,
el
.
tag
))
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录