Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
genary
uni-app
提交
e000e9d8
U
uni-app
项目概览
genary
/
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,发现更多精彩内容 >>
提交
e000e9d8
编写于
12月 18, 2019
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(cli): isUnaryTag
上级
d0d1bbb4
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
41 addition
and
44 deletion
+41
-44
packages/uni-template-compiler/lib/auto-components.js
packages/uni-template-compiler/lib/auto-components.js
+2
-2
packages/uni-template-compiler/lib/index.js
packages/uni-template-compiler/lib/index.js
+9
-5
packages/uni-template-compiler/lib/util.js
packages/uni-template-compiler/lib/util.js
+23
-23
packages/vue-cli-plugin-uni/lib/h5/compiler-options.js
packages/vue-cli-plugin-uni/lib/h5/compiler-options.js
+0
-6
packages/vue-cli-plugin-uni/lib/h5/index.js
packages/vue-cli-plugin-uni/lib/h5/index.js
+5
-0
packages/vue-cli-plugin-uni/lib/mp-compiler-options.js
packages/vue-cli-plugin-uni/lib/mp-compiler-options.js
+2
-8
未找到文件。
packages/uni-template-compiler/lib/auto-components.js
浏览文件 @
e000e9d8
...
...
@@ -5,8 +5,8 @@ const {
module
.
exports
=
{
preTransformNode
(
el
,
options
)
{
if
(
isComponent
(
el
.
tag
))
{
// 挂在 is
Reserved
Tag 上边,可以保证外部访问到
(
options
.
is
ReservedTag
.
autoComponents
||
(
options
.
isReserved
Tag
.
autoComponents
=
new
Set
())).
add
(
el
.
tag
)
// 挂在 is
Unary
Tag 上边,可以保证外部访问到
(
options
.
is
UnaryTag
.
autoComponents
||
(
options
.
isUnary
Tag
.
autoComponents
=
new
Set
())).
add
(
el
.
tag
)
}
}
}
packages/uni-template-compiler/lib/index.js
浏览文件 @
e000e9d8
...
...
@@ -23,7 +23,8 @@ const compilerAlipayModule = require('./module-alipay')
const
generateCodeFrame
=
require
(
'
./codeframe
'
)
const
{
isComponent
isComponent
,
isUnaryTag
}
=
require
(
'
./util
'
)
function
compileTemplate
(
source
,
options
)
{
...
...
@@ -31,7 +32,7 @@ function compileTemplate (source, options) {
console
.
log
(
options
)
const
{
autoComponents
}
=
options
.
is
Reserved
Tag
}
=
options
.
is
Unary
Tag
if
(
autoComponents
)
{
console
.
log
(
'
检测到的自定义组件:
'
+
[...
autoComponents
])
}
...
...
@@ -44,10 +45,12 @@ function compileTemplate (source, options) {
module
.
exports
=
{
compile
(
source
,
options
=
{})
{
(
options
.
modules
||
(
options
.
modules
=
[])).
push
(
require
(
'
./auto-components
'
))
(
options
.
modules
||
(
options
.
modules
=
[])).
push
(
require
(
'
./auto-components
'
))
options
.
isUnaryTag
=
isUnaryTag
options
.
preserveWhitespace
=
false
if
(
options
.
service
)
{
(
options
.
modules
||
(
options
.
modules
=
[])).
push
(
require
(
'
./app/service
'
))
options
.
optimize
=
false
// 启用 staticRenderFns
options
.
optimize
=
false
// 启用 staticRenderFns
// domProps => attrs
options
.
mustUseProp
=
()
=>
false
options
.
isReservedTag
=
(
tagName
)
=>
!
isComponent
(
tagName
)
// 非组件均为内置
...
...
@@ -61,7 +64,8 @@ module.exports = {
}
}
else
if
(
options
.
view
)
{
(
options
.
modules
||
(
options
.
modules
=
[])).
push
(
require
(
'
./app/view
'
))
options
.
optimize
=
false
// 暂不启用 staticRenderFns
options
.
optimize
=
false
// 暂不启用 staticRenderFns
options
.
isUnaryTag
=
isUnaryTag
options
.
isReservedTag
=
(
tagName
)
=>
false
// 均为组件
try
{
return
compileTemplate
(
source
,
options
)
...
...
packages/uni-template-compiler/lib/util.js
浏览文件 @
e000e9d8
...
...
@@ -6,9 +6,9 @@ const {
METHOD_RENDER_LIST
}
=
require
(
'
./constants
'
)
function
cached
(
fn
)
{
function
cached
(
fn
)
{
const
cache
=
Object
.
create
(
null
)
return
function
cachedFn
(
str
)
{
return
function
cachedFn
(
str
)
{
const
hit
=
cache
[
str
]
return
hit
||
(
cache
[
str
]
=
fn
(
str
))
}
...
...
@@ -21,7 +21,7 @@ const camelize = cached((str) => {
return
str
.
replace
(
camelizeRE
,
(
_
,
c
)
=>
c
?
c
.
toUpperCase
()
:
''
)
})
function
getCode
(
node
)
{
function
getCode
(
node
)
{
return
babelGenerate
(
t
.
cloneDeep
(
node
),
{
compact
:
true
,
jsescOption
:
{
...
...
@@ -31,11 +31,11 @@ function getCode(node) {
}).
code
}
function
traverseKey
(
ast
,
state
)
{
function
traverseKey
(
ast
,
state
)
{
let
forKey
=
false
babelTraverse
(
ast
,
{
noScope
:
true
,
ObjectProperty
(
path
)
{
ObjectProperty
(
path
)
{
if
(
forKey
)
{
return
}
...
...
@@ -44,7 +44,7 @@ function traverseKey(ast, state) {
path
.
stop
()
}
},
CallExpression
(
path
)
{
CallExpression
(
path
)
{
if
(
path
.
node
.
callee
.
name
===
METHOD_RENDER_LIST
)
{
path
.
stop
()
}
...
...
@@ -53,7 +53,7 @@ function traverseKey(ast, state) {
return
forKey
}
function
traverseFilter
(
ast
,
state
)
{
function
traverseFilter
(
ast
,
state
)
{
const
filterModules
=
state
.
options
.
filterModules
if
(
!
filterModules
.
length
)
{
return
false
...
...
@@ -61,7 +61,7 @@ function traverseFilter(ast, state) {
let
isFilter
=
false
babelTraverse
(
ast
,
{
noScope
:
true
,
Identifier
(
path
)
{
Identifier
(
path
)
{
if
(
filterModules
.
includes
(
path
.
node
.
name
))
{
const
parentNode
=
path
.
parent
if
(
// t.msg || t['msg']
...
...
@@ -81,11 +81,11 @@ function traverseFilter(ast, state) {
return
isFilter
}
function
wrapper
(
code
,
reverse
=
false
)
{
function
wrapper
(
code
,
reverse
=
false
)
{
return
reverse
?
`{{!(
${
code
}
)}}`
:
`{{
${
code
}
}}`
}
function
genCode
(
node
,
noWrapper
=
false
,
reverse
=
false
,
quotes
=
true
)
{
function
genCode
(
node
,
noWrapper
=
false
,
reverse
=
false
,
quotes
=
true
)
{
if
(
t
.
isStringLiteral
(
node
))
{
return
reverse
?
`!(
${
node
.
value
}
)`
:
node
.
value
}
else
if
(
t
.
isIdentifier
(
node
))
{
...
...
@@ -98,11 +98,11 @@ function genCode(node, noWrapper = false, reverse = false, quotes = true) {
return
noWrapper
?
code
:
wrapper
(
code
,
reverse
)
}
function
getForIndexIdentifier
(
id
)
{
function
getForIndexIdentifier
(
id
)
{
return
`__i
${
id
}
__`
}
function
getForKey
(
forKey
,
forIndex
,
state
)
{
function
getForKey
(
forKey
,
forIndex
,
state
)
{
if
(
forKey
)
{
if
(
t
.
isIdentifier
(
forKey
))
{
if
(
forIndex
!==
forKey
.
name
)
{
// 非 forIndex
...
...
@@ -121,7 +121,7 @@ function getForKey(forKey, forIndex, state) {
return
''
}
function
processMemberProperty
(
node
,
state
)
{
function
processMemberProperty
(
node
,
state
)
{
if
(
node
.
computed
)
{
const
property
=
node
.
property
if
(
t
.
isNumericLiteral
(
property
))
{
...
...
@@ -139,7 +139,7 @@ function processMemberProperty(node, state) {
}
}
function
processMemberExpression
(
element
,
state
)
{
function
processMemberExpression
(
element
,
state
)
{
// item['order']=>item.order
if
(
t
.
isMemberExpression
(
element
))
{
element
=
t
.
cloneDeep
(
element
)
...
...
@@ -152,19 +152,19 @@ function processMemberExpression(element, state) {
babelTraverse
(
element
,
{
noScope
:
true
,
MemberExpression
(
path
)
{
MemberExpression
(
path
)
{
processMemberProperty
(
path
.
node
,
state
)
}
})
babelTraverse
(
element
,
{
noScope
:
true
,
MemberExpression
(
path
)
{
MemberExpression
(
path
)
{
if
(
t
.
isStringLiteral
(
path
.
node
.
property
))
{
path
.
node
.
computed
=
false
}
},
StringLiteral
(
path
)
{
StringLiteral
(
path
)
{
path
.
replaceWith
(
t
.
identifier
(
path
.
node
.
value
))
}
})
...
...
@@ -172,7 +172,7 @@ function processMemberExpression(element, state) {
return
element
}
function
hasOwn
(
obj
,
key
)
{
function
hasOwn
(
obj
,
key
)
{
return
hasOwnProperty
.
call
(
obj
,
key
)
}
...
...
@@ -182,7 +182,7 @@ const {
getTagName
}
=
require
(
'
./h5
'
)
function
isComponent
(
tagName
)
{
function
isComponent
(
tagName
)
{
if
(
tagName
===
'
block
'
||
tagName
===
'
component
'
||
...
...
@@ -194,15 +194,15 @@ function isComponent(tagName) {
return
!
hasOwn
(
tags
,
getTagName
(
tagName
.
replace
(
'
v-uni-
'
,
''
)))
}
function
makeMap
(
str
,
expectsLowerCase
)
{
function
makeMap
(
str
,
expectsLowerCase
)
{
const
map
=
Object
.
create
(
null
)
const
list
=
str
.
split
(
'
,
'
)
for
(
let
i
=
0
;
i
<
list
.
length
;
i
++
)
{
map
[
list
[
i
]]
=
true
}
return
expectsLowerCase
?
val
=>
map
[
val
.
toLowerCase
()]
:
val
=>
map
[
val
]
return
expectsLowerCase
?
val
=>
map
[
val
.
toLowerCase
()]
:
val
=>
map
[
val
]
}
module
.
exports
=
{
isUnaryTag
:
makeMap
(
...
...
packages/vue-cli-plugin-uni/lib/h5/compiler-options.js
浏览文件 @
e000e9d8
...
...
@@ -2,10 +2,6 @@ const {
tags
}
=
require
(
'
@dcloudio/uni-cli-shared
'
)
const
{
isUnaryTag
}
=
require
(
'
@dcloudio/uni-template-compiler/lib/util
'
)
const
simplePathRE
=
/^
[
A-Za-z_$
][\w
$
]
*
(?:\.[
A-Za-z_$
][\w
$
]
*|
\[
'
[^
'
]
*
?
']|
\[
"
[^
"
]
*
?
"]|
\[\d
+]|
\[[
A-Za-z_$
][\w
$
]
*]
)
*$/
function
processEvent
(
expr
,
filterModules
)
{
...
...
@@ -66,8 +62,6 @@ function fixBooleanAttribute (el) {
}
module
.
exports
=
{
isUnaryTag
,
preserveWhitespace
:
false
,
modules
:
[
require
(
'
../format-text
'
),
{
preTransformNode
(
el
,
options
)
{
fixBooleanAttribute
(
el
)
...
...
packages/vue-cli-plugin-uni/lib/h5/index.js
浏览文件 @
e000e9d8
...
...
@@ -144,6 +144,11 @@ module.exports = {
loader
:
resolve
(
'
packages/webpack-uni-filter-loader
'
)
}]
}]
},
resolveLoader
:
{
alias
:
{
'
vue-style-loader
'
:
resolve
(
'
packages/h5-vue-style-loader
'
)
}
},
plugins
}
...
...
packages/vue-cli-plugin-uni/lib/mp-compiler-options.js
浏览文件 @
e000e9d8
...
...
@@ -3,15 +3,9 @@ const {
convertStaticStyle
}
=
require
(
'
@dcloudio/uni-cli-shared
'
)
const
{
isUnaryTag
}
=
require
(
'
@dcloudio/uni-template-compiler/lib/util
'
)
module
.
exports
=
{
isUnaryTag
,
preserveWhitespace
:
false
,
modules
:
[
require
(
'
./format-text
'
),
{
preTransformNode
(
el
,
{
preTransformNode
(
el
,
{
warn
})
{
if
(
el
.
attrsMap
)
{
...
...
@@ -40,7 +34,7 @@ module.exports = {
})
}
},
postTransformNode
(
el
)
{
postTransformNode
(
el
)
{
if
(
process
.
env
.
UNI_PLATFORM
===
'
mp-alipay
'
)
{
if
(
el
.
tag
===
'
slot
'
)
{
if
(
!
el
.
children
.
length
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录