Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦里逆天
uni-app
提交
0c21bacb
U
uni-app
项目概览
梦里逆天
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
22
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0c21bacb
编写于
10月 31, 2019
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(v3): custom directives
上级
9be8526b
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
47 addition
and
18 deletion
+47
-18
packages/uni-app-plus/dist/service.runtime.esm.js
packages/uni-app-plus/dist/service.runtime.esm.js
+0
-4
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js
...e-compiler/__tests__/compiler-app-plus-extra.view.spec.js
+1
-1
packages/uni-template-compiler/__tests__/compiler-app-plus.service.spec.js
...late-compiler/__tests__/compiler-app-plus.service.spec.js
+3
-3
packages/uni-template-compiler/__tests__/compiler-app-plus.view.spec.js
...emplate-compiler/__tests__/compiler-app-plus.view.spec.js
+2
-2
packages/uni-template-compiler/__tests__/demo.js
packages/uni-template-compiler/__tests__/demo.js
+2
-2
packages/uni-template-compiler/lib/app/view.js
packages/uni-template-compiler/lib/app/view.js
+37
-3
packages/uni-template-compiler/lib/index.js
packages/uni-template-compiler/lib/index.js
+2
-3
未找到文件。
packages/uni-app-plus/dist/service.runtime.esm.js
浏览文件 @
0c21bacb
...
...
@@ -6801,10 +6801,6 @@ var plugin = {
Vue
.
prototype
.
_$queue
=
queue
;
Vue
.
prototype
.
_m
=
function
renderStatic
()
{
return
this
.
_e
()
};
Vue
.
prototype
.
__call_hook
=
callHook$2
;
// 运行时需要格式化 class,style
Vue
.
prototype
.
_$stringifyClass
=
stringifyClass
;
...
...
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js
浏览文件 @
0c21bacb
...
...
@@ -15,7 +15,7 @@ describe('codegen', () => {
it
(
'
generate directive
'
,
()
=>
{
assertCodegen
(
'
<p v-custom1:[arg1].modifier="value1" v-custom2></p>
'
,
`with(this){return _c('v-uni-view',{
directives:[{name:"custom1",rawName:"v-custom1:[arg1].modifier",value:(_$g(0,'v-custom1')),expression:"_$g(0,'v-custom1')",arg:_$g(0,'v-custom1-arg'),modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}],
attrs:{"_i":0}})}`
`with(this){return _c('v-uni-view',{attrs:{"_i":0}})}`
)
})
it
(
'
generate v-for directive
'
,
()
=>
{
...
...
packages/uni-template-compiler/__tests__/compiler-app-plus.service.spec.js
浏览文件 @
0c21bacb
...
...
@@ -589,7 +589,7 @@ describe('codegen', () => {
// have "inline-template'"
assertCodegen
(
'
<my-component inline-template><p><span>hello world</span></p></my-component>
'
,
`with(this){return _c('my-component',{attrs:{"_i":0},inlineTemplate:{render:function(){with(this){return _
m(0)}},staticRenderFns:[function(){with(this){return _c('p',[_c('span')])}}
]}})}`
`with(this){return _c('my-component',{attrs:{"_i":0},inlineTemplate:{render:function(){with(this){return _
c('p',[_c('span')])}},staticRenderFns:[
]}})}`
)
// "have inline-template attrs, but not having exactly one child element
assertCodegen
(
...
...
@@ -616,7 +616,7 @@ describe('codegen', () => {
it
(
'
generate static trees inside v-for
'
,
()
=>
{
assertCodegen
(
`<div><div v-for="i in 10"><p><span></span></p></div></div>`
,
`with(this){return _c('div',_l((10),function(i,$10,$20,$30){return _c('div',[_
m(0,true
)])}),0)}`
`with(this){return _c('div',_l((10),function(i,$10,$20,$30){return _c('div',[_
c('p',[_c('span')]
)])}),0)}`
// [`with(this){return _c('p',[_c('span')])}`]
)
})
...
...
@@ -660,7 +660,7 @@ describe('codegen', () => {
it
(
'
does not squash templates inside v-pre
'
,
()
=>
{
assertCodegen
(
'
<div v-pre><template><p>{{msg}}</p></template></div>
'
,
`with(this){return _
m(0
)}`
`with(this){return _
c('div',[[_c('p')]],2
)}`
)
// const template = '<div v-pre><template><p>{{msg}}</p></template></div>'
// const generatedCode = `with(this){return _m(0)}`
...
...
packages/uni-template-compiler/__tests__/compiler-app-plus.view.spec.js
浏览文件 @
0c21bacb
...
...
@@ -15,12 +15,12 @@ describe('codegen', () => {
it
(
'
generate directive
'
,
()
=>
{
assertCodegen
(
'
<p v-custom1:arg1.modifier="value1" v-custom2></p>
'
,
`with(this){return _c('v-uni-view',{
directives:[{name:"custom1",rawName:"v-custom1:arg1.modifier",value:(_$g(0,'v-custom1')),expression:"_$g(0,'v-custom1')",arg:"arg1",modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}],
attrs:{"_i":0}})}`
`with(this){return _c('v-uni-view',{attrs:{"_i":0}})}`
)
// extra
assertCodegen
(
'
<p v-custom1:[arg1].modifier="value1" v-custom2></p>
'
,
`with(this){return _c('v-uni-view',{
directives:[{name:"custom1",rawName:"v-custom1:[arg1].modifier",value:(_$g(0,'v-custom1')),expression:"_$g(0,'v-custom1')",arg:_$g(0,'v-custom1-arg'),modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}],
attrs:{"_i":0}})}`
`with(this){return _c('v-uni-view',{attrs:{"_i":0}})}`
)
})
...
...
packages/uni-template-compiler/__tests__/demo.js
浏览文件 @
0c21bacb
const
compiler
=
require
(
'
../lib
'
)
const
res
=
compiler
.
compile
(
`
<
keep-alive exclude="componentWithStatus1"><component is="componentWithStatus"/></keep-alive
>
<
p v-text="test"></p
>
`
,
{
resourcePath
:
'
/User/fxy/Documents/test.wxml
'
,
isReservedTag
:
function
(
tag
)
{
...
...
@@ -13,7 +13,7 @@ const res = compiler.compile(
mp
:
{
platform
:
'
app-plus
'
},
service
:
true
,
//
service: true,
view
:
true
})
console
.
log
(
require
(
'
util
'
).
inspect
(
res
,
{
...
...
packages/uni-template-compiler/lib/app/view.js
浏览文件 @
0c21bacb
...
...
@@ -13,7 +13,6 @@ const {
parseIf
,
parseFor
,
parseText
,
parseDirs
,
parseAttrs
,
parseProps
,
parseBinding
...
...
@@ -54,6 +53,41 @@ function parseKey (el) {
}
}
function
parseDirs
(
el
,
genVar
,
ignoreDirs
,
includeDirs
=
[])
{
if
(
!
el
.
directives
)
{
return
}
el
.
directives
=
el
.
directives
.
filter
(
dir
=>
{
if
(
includeDirs
.
indexOf
(
dir
.
name
)
!==
-
1
)
{
if
(
ignoreDirs
.
indexOf
(
dir
.
name
)
===
-
1
)
{
dir
.
value
&&
(
dir
.
value
=
genVar
(
'
v-
'
+
dir
.
name
,
dir
.
value
))
dir
.
isDynamicArg
&&
(
dir
.
arg
=
genVar
(
'
v-
'
+
dir
.
name
+
'
-arg
'
,
dir
.
arg
))
}
return
true
}
})
}
const
includeDirs
=
[
'
text
'
,
'
html
'
,
'
bind
'
,
'
model
'
,
'
show
'
,
'
if
'
,
'
else
'
,
'
else-if
'
,
'
for
'
,
'
on
'
,
'
bind
'
,
'
slot
'
,
'
pre
'
,
'
cloak
'
,
'
once
'
]
const
ignoreDirs
=
[
'
model
'
]
function
transformNode
(
el
,
parent
,
state
)
{
if
(
el
.
type
===
3
)
{
return
...
...
@@ -86,7 +120,7 @@ function transformNode (el, parent, state) {
parseIf
(
el
,
createGenVar
)
parseBinding
(
el
,
genVar
)
parseDirs
(
el
,
genVar
,
[
'
model
'
]
)
parseDirs
(
el
,
genVar
,
ignoreDirs
,
includeDirs
)
parseAttrs
(
el
,
genVar
)
parseProps
(
el
,
genVar
)
}
...
...
packages/uni-template-compiler/lib/index.js
浏览文件 @
0c21bacb
...
...
@@ -30,7 +30,7 @@ module.exports = {
compile
(
source
,
options
=
{})
{
if
(
options
.
service
)
{
(
options
.
modules
||
(
options
.
modules
=
[])).
push
(
require
(
'
./app/service
'
))
options
.
optimize
=
tru
e
// 启用 staticRenderFns
options
.
optimize
=
fals
e
// 启用 staticRenderFns
// domProps => attrs
options
.
mustUseProp
=
()
=>
false
options
.
isReservedTag
=
(
tagName
)
=>
!
isComponent
(
tagName
)
// 非组件均为内置
...
...
@@ -38,7 +38,6 @@ module.exports = {
// clear staticRenderFns
const
compiled
=
compile
(
source
,
options
)
compiled
.
staticRenderFns
.
length
=
0
return
compiled
}
else
if
(
options
.
view
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录