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