Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
一把秋刀鱼
uni-app
提交
86f512f1
U
uni-app
项目概览
一把秋刀鱼
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
4
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,发现更多精彩内容 >>
提交
86f512f1
编写于
2月 25, 2020
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(v3): generate text with multiple statements(
https://ask.dcloud.net.cn/question/89423)
上级
c9bebaa9
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
64 addition
and
45 deletion
+64
-45
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js
...ompiler/__tests__/compiler-app-plus-extra.service.spec.js
+14
-10
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js
...e-compiler/__tests__/compiler-app-plus-extra.view.spec.js
+9
-3
packages/uni-template-compiler/__tests__/compiler-app-plus.service.spec.js
...late-compiler/__tests__/compiler-app-plus.service.spec.js
+12
-12
packages/uni-template-compiler/__tests__/compiler-app-plus.view.spec.js
...emplate-compiler/__tests__/compiler-app-plus.view.spec.js
+12
-12
packages/uni-template-compiler/__tests__/demo.js
packages/uni-template-compiler/__tests__/demo.js
+2
-2
packages/uni-template-compiler/lib/app/parser/text-parser.js
packages/uni-template-compiler/lib/app/parser/text-parser.js
+1
-1
packages/uni-template-compiler/lib/app/service.js
packages/uni-template-compiler/lib/app/service.js
+1
-0
packages/uni-template-compiler/lib/app/util.js
packages/uni-template-compiler/lib/app/util.js
+11
-4
packages/uni-template-compiler/lib/app/view.js
packages/uni-template-compiler/lib/app/view.js
+2
-1
未找到文件。
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js
浏览文件 @
86f512f1
...
@@ -28,7 +28,7 @@ describe('codegen', () => {
...
@@ -28,7 +28,7 @@ describe('codegen', () => {
)
)
assertCodegen
(
assertCodegen
(
'
<div><block v-for="(item,index) in list" :key="index"><block><text>{{item}}</text></block></block></div>
'
,
'
<div><block v-for="(item,index) in list" :key="index"><block><text>{{item}}</text></block></block></div>
'
,
`with(this){return _c('div',[_l((_$s(1,'f',{forItems:list,fill:true})),function(item,index,$20,$30){return [[_c('text',{key:_$s(("3-"+$30),'a-key',index+'_0'+'_0')},[_v((_$s(("3-"+$30),'t0',_s(item))))])]]})],2)}`
`with(this){return _c('div',[_l((_$s(1,'f',{forItems:list,fill:true})),function(item,index,$20,$30){return [[_c('text',{key:_$s(("3-"+$30),'a-key',index+'_0'+'_0')},[_v((_$s(("3-"+$30),'t0
-0
',_s(item))))])]]})],2)}`
)
)
})
})
it
(
'
generate directive
'
,
()
=>
{
it
(
'
generate directive
'
,
()
=>
{
...
@@ -48,15 +48,15 @@ describe('codegen', () => {
...
@@ -48,15 +48,15 @@ describe('codegen', () => {
)
)
assertCodegen
(
assertCodegen
(
'
<div><template v-for="item in items">{{text}}</template></div>
'
,
'
<div><template v-for="item in items">{{text}}</template></div>
'
,
`with(this){return _c('div',[_l((_$s(1,'f',{forItems:items,fill:true})),function(item,$10,$20,$30){return [_v((_$s(("1-"+$30),'t0',_s(text))))]})],2)}`
`with(this){return _c('div',[_l((_$s(1,'f',{forItems:items,fill:true})),function(item,$10,$20,$30){return [_v((_$s(("1-"+$30),'t0
-0
',_s(text))))]})],2)}`
)
)
assertCodegen
(
assertCodegen
(
'
<div><template v-for="item in items"><span></span>{{text}}</template></div>
'
,
'
<div><template v-for="item in items"><span></span>{{text}}</template></div>
'
,
`with(this){return _c('div',[_l((_$s(1,'f',{forItems:items})),function(item,$10,$20,$30){return [_c('span',{key:_$s(1,'f',{forIndex:$20,keyIndex:0,key:1+'-0'+$30})}),_v((_$s(("1-"+$30),'t0',_s(text))))]})],2)}`
`with(this){return _c('div',[_l((_$s(1,'f',{forItems:items})),function(item,$10,$20,$30){return [_c('span',{key:_$s(1,'f',{forIndex:$20,keyIndex:0,key:1+'-0'+$30})}),_v((_$s(("1-"+$30),'t
1-
0',_s(text))))]})],2)}`
)
)
assertCodegen
(
assertCodegen
(
'
<div><template v-for="item in items">a {{text1}} b {{text2}}</template></div>
'
,
'
<div><template v-for="item in items">a {{text1}} b {{text2}}</template></div>
'
,
`with(this){return _c('div',[_l((_$s(1,'f',{forItems:items,fill:true})),function(item,$10,$20,$30){return [_v((_$s(("1-"+$30),'t0
',_s(text1)))+(_$s(("1-"+$30),'t
1',_s(text2))))]})],2)}`
`with(this){return _c('div',[_l((_$s(1,'f',{forItems:items,fill:true})),function(item,$10,$20,$30){return [_v((_$s(("1-"+$30),'t0
-0',_s(text1)))+(_$s(("1-"+$30),'t0-
1',_s(text2))))]})],2)}`
)
)
assertCodegen
(
assertCodegen
(
'
<div><template v-for="item in items"><span v-if="item.sub"></span></template></div>
'
,
'
<div><template v-for="item in items"><span v-if="item.sub"></span></template></div>
'
,
...
@@ -64,28 +64,32 @@ describe('codegen', () => {
...
@@ -64,28 +64,32 @@ describe('codegen', () => {
)
)
assertCodegen
(
assertCodegen
(
'
<view><template v-for="(item, index) in arr">{{item}}</template></view>
'
,
'
<view><template v-for="(item, index) in arr">{{item}}</template></view>
'
,
`with(this){return _c('view',[_l((_$s(1,'f',{forItems:arr,fill:true})),function(item,index,$20,$30){return [_v((_$s(("1-"+$30),'t0',_s(item))))]})],2)}`
`with(this){return _c('view',[_l((_$s(1,'f',{forItems:arr,fill:true})),function(item,index,$20,$30){return [_v((_$s(("1-"+$30),'t0
-0
',_s(item))))]})],2)}`
)
)
assertCodegen
(
assertCodegen
(
'
<view><block v-for="(item, index) in arr" v-bind:key="index">{{item}}</block></view>
'
,
'
<view><block v-for="(item, index) in arr" v-bind:key="index">{{item}}</block></view>
'
,
`with(this){return _c('view',[_l((_$s(1,'f',{forItems:arr,fill:true})),function(item,index,$20,$30){return [_v((_$s(("1-"+$30),'t0',_s(item))))]})],2)}`
`with(this){return _c('view',[_l((_$s(1,'f',{forItems:arr,fill:true})),function(item,index,$20,$30){return [_v((_$s(("1-"+$30),'t0
-0
',_s(item))))]})],2)}`
)
)
assertCodegen
(
assertCodegen
(
'
<view><block v-for="(item,index) in arr" v-bind:key="index"><block v-if="item==3">{{item}}</block></block></view>
'
,
'
<view><block v-for="(item,index) in arr" v-bind:key="index"><block v-if="item==3">{{item}}</block></block></view>
'
,
`with(this){return _c('view',[_l((_$s(1,'f',{forItems:arr,fill:true})),function(item,index,$20,$30){return [(_$s(("2-"+$30),'i',item==3))?[_v((_$s(("2-"+$30),'t0',_s(item))))]:_e()]})],2)}`
`with(this){return _c('view',[_l((_$s(1,'f',{forItems:arr,fill:true})),function(item,index,$20,$30){return [(_$s(("2-"+$30),'i',item==3))?[_v((_$s(("2-"+$30),'t0
-0
',_s(item))))]:_e()]})],2)}`
)
)
})
})
it
(
'
generate text with multiple statements
'
,
()
=>
{
it
(
'
generate text with multiple statements
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
`<div :id="'a'+b">A{{ d | e | f }}B{{text}}C</div>`
,
`<div :id="'a'+b">A{{ d | e | f }}B{{text}}C</div>`
,
`with(this){return _c('div',{attrs:{"id":_$s(0,'a-id','a'+b),"_i":0}},[_v((_$s(0,'t0',_s(_f("f")(_f("e")(d)))))+(_$s(0,'t1',_s(text))))])}`
`with(this){return _c('div',{attrs:{"id":_$s(0,'a-id','a'+b),"_i":0}},[_v((_$s(0,'t0-0',_s(_f("f")(_f("e")(d)))))+(_$s(0,'t0-1',_s(text))))])}`
)
assertCodegen
(
`<view>{{obj.param1}}123123{{obj.param1}}123123{{obj.param1}}<text> -{{obj.param3}}---{{obj.param3}} </text>{{obj.param2}}aaaa{{obj.param2}}aaaa{{obj.param2}}</view>`
,
`with(this){return _c('view',[_v((_$s(0,'t0-0',_s(obj.param1)))+(_$s(0,'t0-1',_s(obj.param1)))+(_$s(0,'t0-2',_s(obj.param1)))),_c('text',[_v((_$s(1,'t0-0',_s(obj.param3)))+(_$s(1,'t0-1',_s(obj.param3))))]),_v((_$s(0,'t2-0',_s(obj.param2)))+(_$s(0,'t2-1',_s(obj.param2)))+(_$s(0,'t2-2',_s(obj.param2))))])}`
)
)
})
})
it
(
'
generate v-slot
'
,
()
=>
{
it
(
'
generate v-slot
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
'
<current-user v-slot="{ user }">{{ user.firstName }}</current-user>
'
,
'
<current-user v-slot="{ user }">{{ user.firstName }}</current-user>
'
,
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({ user }, _svm, _si){return [_v((_svm._$s(("0-"+_si),'t0',_s(user.firstName))))]}}])})}`
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({ user }, _svm, _si){return [_v((_svm._$s(("0-"+_si),'t0
-0
',_s(user.firstName))))]}}])})}`
)
)
assertCodegen
(
assertCodegen
(
'
<current-user>ABCD</current-user>
'
,
'
<current-user>ABCD</current-user>
'
,
...
@@ -97,7 +101,7 @@ describe('codegen', () => {
...
@@ -97,7 +101,7 @@ describe('codegen', () => {
<view v-for="(item,index) in result.list">{{item.name}}</view>
<view v-for="(item,index) in result.list">{{item.name}}</view>
</template>
</template>
</current-user>`
,
</current-user>`
,
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({result}, _svm, _si){return _l((_svm._$s(("2-"+_si),'f',{forItems:result.list})),function(item,index,$20,$30){return _c('view',{key:_svm._$s(("2-"+_si),'f',{forIndex:$20,key:("2-"+_si)+'-'+$30}),attrs:{"_i":(("2-"+_si)+$30)}},[_v((_svm._$s((("2-"+_si)+$30),'t0',_s(item.name))))])})}}])})}`
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({result}, _svm, _si){return _l((_svm._$s(("2-"+_si),'f',{forItems:result.list})),function(item,index,$20,$30){return _c('view',{key:_svm._$s(("2-"+_si),'f',{forIndex:$20,key:("2-"+_si)+'-'+$30}),attrs:{"_i":(("2-"+_si)+$30)}},[_v((_svm._$s((("2-"+_si)+$30),'t0
-0
',_s(item.name))))])})}}])})}`
)
)
})
})
...
...
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js
浏览文件 @
86f512f1
...
@@ -32,19 +32,25 @@ describe('codegen', () => {
...
@@ -32,19 +32,25 @@ describe('codegen', () => {
it
(
'
generate events with multiple statements
'
,
()
=>
{
it
(
'
generate events with multiple statements
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
'
<div>A{{ d | e | f }}B{{text}}C</div>
'
,
'
<div>A{{ d | e | f }}B{{text}}C</div>
'
,
`with(this){return _c('div',{attrs:{"_i":0}},[_v("A"+(_$g(0,'t0
'))+"B"+(_$g(0,'t
1'))+"C")])}`
`with(this){return _c('div',{attrs:{"_i":0}},[_v("A"+(_$g(0,'t0
-0'))+"B"+(_$g(0,'t0-
1'))+"C")])}`
)
)
})
})
it
(
'
generate slot fallback content
'
,
()
=>
{
it
(
'
generate slot fallback content
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
'
<div><slot><div>{{hi}}</div></slot></div>
'
,
'
<div><slot><div>{{hi}}</div></slot></div>
'
,
`with(this){return _c('div',{attrs:{"_i":0}},[_t("default",[_c('div',{attrs:{"_i":2}},[_v((_$g(2,'t0')))])],{"_i":1})],2)}`
`with(this){return _c('div',{attrs:{"_i":0}},[_t("default",[_c('div',{attrs:{"_i":2}},[_v((_$g(2,'t0
-0
')))])],{"_i":1})],2)}`
)
)
})
it
(
'
generate text with multiple statements
'
,
()
=>
{
assertCodegen
(
`<view>{{obj.param1}}123123{{obj.param1}}123123{{obj.param1}}<text> -{{obj.param3}}---{{obj.param3}} </text>{{obj.param2}}aaaa{{obj.param2}}aaaa{{obj.param2}}</view>`
,
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v((_$g(0,'t0-0'))+"123123"+(_$g(0,'t0-1'))+"123123"+(_$g(0,'t0-2'))),_c('v-uni-text',{attrs:{"_i":1}},[_v("-"+(_$g(1,'t0-0'))+"---"+(_$g(1,'t0-1')))]),_v((_$g(0,'t2-0'))+"aaaa"+(_$g(0,'t2-1'))+"aaaa"+(_$g(0,'t2-2')))],1)}`
)
})
})
it
(
'
generate v-slot
'
,
()
=>
{
it
(
'
generate v-slot
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
'
<current-user v-slot="{ user }">{{ user.firstName }}</current-user>
'
,
'
<current-user v-slot="{ user }">{{ user.firstName }}</current-user>
'
,
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({ user }, _svm, _si){return [_v((_svm._$g(("0-"+_si),'t0')))]}}])})}`
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({ user }, _svm, _si){return [_v((_svm._$g(("0-"+_si),'t0
-0
')))]}}])})}`
)
)
})
})
it
(
'
generate keep-alive
'
,
()
=>
{
it
(
'
generate keep-alive
'
,
()
=>
{
...
...
packages/uni-template-compiler/__tests__/compiler-app-plus.service.spec.js
浏览文件 @
86f512f1
...
@@ -27,14 +27,14 @@ describe('codegen', () => {
...
@@ -27,14 +27,14 @@ describe('codegen', () => {
it
(
'
generate filters
'
,
()
=>
{
it
(
'
generate filters
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
'
<div :id="a | b | c">{{ d | e | f }}</div>
'
,
'
<div :id="a | b | c">{{ d | e | f }}</div>
'
,
`with(this){return _c('div',{attrs:{"id":_$s(0,'a-id',_f("c")(_f("b")(a))),"_i":0}},[_v((_$s(0,'t0',_s(_f("f")(_f("e")(d))))))])}`
`with(this){return _c('div',{attrs:{"id":_$s(0,'a-id',_f("c")(_f("b")(a))),"_i":0}},[_v((_$s(0,'t0
-0
',_s(_f("f")(_f("e")(d))))))])}`
)
)
})
})
it
(
'
generate filters with no arguments
'
,
()
=>
{
it
(
'
generate filters with no arguments
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
'
<div>{{ d | e() }}</div>
'
,
'
<div>{{ d | e() }}</div>
'
,
`with(this){return _c('div',[_v((_$s(0,'t0',_s(_f("e")(d)))))])}`
`with(this){return _c('div',[_v((_$s(0,'t0
-0
',_s(_f("e")(d)))))])}`
)
)
})
})
...
@@ -162,7 +162,7 @@ describe('codegen', () => {
...
@@ -162,7 +162,7 @@ describe('codegen', () => {
it
(
'
generate template tag
'
,
()
=>
{
it
(
'
generate template tag
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
'
<div><template><p>{{hello}}</p></template></div>
'
,
'
<div><template><p>{{hello}}</p></template></div>
'
,
`with(this){return _c('div',[[_c('p',[_v((_$s(2,'t0',_s(hello))))])]],2)}`
`with(this){return _c('div',[[_c('p',[_v((_$s(2,'t0
-0
',_s(hello))))])]],2)}`
)
)
})
})
...
@@ -197,47 +197,47 @@ describe('codegen', () => {
...
@@ -197,47 +197,47 @@ describe('codegen', () => {
it
(
'
generate scoped slot
'
,
()
=>
{
it
(
'
generate scoped slot
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
'
<foo><template slot-scope="bar">{{ bar }}</template></foo>
'
,
'
<foo><template slot-scope="bar">{{ bar }}</template></foo>
'
,
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar, _svm, _si){return [_v((_svm._$s(("1-"+_si),'t0',_s(bar))))]}}])})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar, _svm, _si){return [_v((_svm._$s(("1-"+_si),'t0
-0
',_s(bar))))]}}])})}`
)
)
assertCodegen
(
assertCodegen
(
'
<foo><div slot-scope="bar">{{ bar }}</div></foo>
'
,
'
<foo><div slot-scope="bar">{{ bar }}</div></foo>
'
,
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar, _svm, _si){return _c('div',{attrs:{"_i":("1-"+_si)}},[_v((_svm._$s(("1-"+_si),'t0',_s(bar))))])}}])})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar, _svm, _si){return _c('div',{attrs:{"_i":("1-"+_si)}},[_v((_svm._$s(("1-"+_si),'t0
-0
',_s(bar))))])}}])})}`
)
)
})
})
it
(
'
generate named scoped slot
'
,
()
=>
{
it
(
'
generate named scoped slot
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
'
<foo><template slot="foo" slot-scope="bar">{{ bar }}</template></foo>
'
,
'
<foo><template slot="foo" slot-scope="bar">{{ bar }}</template></foo>
'
,
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar, _svm, _si){return [_v((_svm._$s(("1-"+_si),'t0',_s(bar))))]}}])})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar, _svm, _si){return [_v((_svm._$s(("1-"+_si),'t0
-0
',_s(bar))))]}}])})}`
)
)
assertCodegen
(
assertCodegen
(
'
<foo><div slot="foo" slot-scope="bar">{{ bar }}</div></foo>
'
,
'
<foo><div slot="foo" slot-scope="bar">{{ bar }}</div></foo>
'
,
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar, _svm, _si){return _c('div',{attrs:{"_i":("1-"+_si)}},[_v((_svm._$s(("1-"+_si),'t0',_s(bar))))])}}])})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar, _svm, _si){return _c('div',{attrs:{"_i":("1-"+_si)}},[_v((_svm._$s(("1-"+_si),'t0
-0
',_s(bar))))])}}])})}`
)
)
})
})
it
(
'
generate dynamic scoped slot
'
,
()
=>
{
it
(
'
generate dynamic scoped slot
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
'
<foo><template :slot="foo" slot-scope="bar">{{ bar }}</template></foo>
'
,
'
<foo><template :slot="foo" slot-scope="bar">{{ bar }}</template></foo>
'
,
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:foo,fn:function(bar, _svm, _si){return [_v((_svm._$s(("1-"+_si),'t0',_s(bar))))]}}],null,true)})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:foo,fn:function(bar, _svm, _si){return [_v((_svm._$s(("1-"+_si),'t0
-0
',_s(bar))))]}}],null,true)})}`
)
)
})
})
it
(
'
generate scoped slot with multiline v-if
'
,
()
=>
{
it
(
'
generate scoped slot with multiline v-if
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
'
<foo><template v-if="
\n
show
\n
" slot-scope="bar">{{ bar }}</template></foo>
'
,
'
<foo><template v-if="
\n
show
\n
" slot-scope="bar">{{ bar }}</template></foo>
'
,
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar, _svm, _si){return (_svm._$s(("1-"+_si),'i',\nshow\n))?[_v((_svm._$s(("1-"+_si),'t0',_s(bar))))]:undefined}}],null,true)})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar, _svm, _si){return (_svm._$s(("1-"+_si),'i',\nshow\n))?[_v((_svm._$s(("1-"+_si),'t0
-0
',_s(bar))))]:undefined}}],null,true)})}`
)
)
assertCodegen
(
assertCodegen
(
'
<foo><div v-if="
\n
show
\n
" slot="foo" slot-scope="bar">{{ bar }}</div></foo>
'
,
'
<foo><div v-if="
\n
show
\n
" slot="foo" slot-scope="bar">{{ bar }}</div></foo>
'
,
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar, _svm, _si){return (_svm._$s(("1-"+_si),'i',\nshow\n))?_c('div',{attrs:{"_i":("1-"+_si)}},[_v((_svm._$s(("1-"+_si),'t0',_s(bar))))]):_e()}}],null,true)})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar, _svm, _si){return (_svm._$s(("1-"+_si),'i',\nshow\n))?_c('div',{attrs:{"_i":("1-"+_si)}},[_v((_svm._$s(("1-"+_si),'t0
-0
',_s(bar))))]):_e()}}],null,true)})}`
)
)
})
})
it
(
'
generate scoped slot with new slot syntax
'
,
()
=>
{
it
(
'
generate scoped slot with new slot syntax
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
'
<foo><template v-if="show" #default="bar">{{ bar }}</template></foo>
'
,
'
<foo><template v-if="show" #default="bar">{{ bar }}</template></foo>
'
,
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([(_$s(1,'i',show))?{key:"default",fn:function(bar, _svm, _si){return [_v((_svm._$s(("1-"+_si),'t0',_s(bar))))]}}:null],null,true)})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([(_$s(1,'i',show))?{key:"default",fn:function(bar, _svm, _si){return [_v((_svm._$s(("1-"+_si),'t0
-0
',_s(bar))))]}}:null],null,true)})}`
)
)
})
})
...
@@ -625,7 +625,7 @@ describe('codegen', () => {
...
@@ -625,7 +625,7 @@ describe('codegen', () => {
// normalize type: 2
// normalize type: 2
assertCodegen
(
assertCodegen
(
'
<div><child></child><template v-for="item in list">{{ item }}</template></div>
'
,
'
<div><child></child><template v-for="item in list">{{ item }}</template></div>
'
,
`with(this){return _c('div',[_c('child',{attrs:{"_i":1}}),_l((_$s(2,'f',{forItems:list,fill:true})),function(item,$10,$20,$30){return [_v((_$s(("2-"+$30),'t0',_s(item))))]})],2)}`
`with(this){return _c('div',[_c('child',{attrs:{"_i":1}}),_l((_$s(2,'f',{forItems:list,fill:true})),function(item,$10,$20,$30){return [_v((_$s(("2-"+$30),'t0
-0
',_s(item))))]})],2)}`
)
)
})
})
...
...
packages/uni-template-compiler/__tests__/compiler-app-plus.view.spec.js
浏览文件 @
86f512f1
...
@@ -27,14 +27,14 @@ describe('codegen', () => {
...
@@ -27,14 +27,14 @@ describe('codegen', () => {
it
(
'
generate filters
'
,
()
=>
{
it
(
'
generate filters
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
'
<div :id="a | b | c">{{ d | e | f }}</div>
'
,
'
<div :id="a | b | c">{{ d | e | f }}</div>
'
,
`with(this){return _c('div',{attrs:{"id":_$g(0,'a-id'),"_i":0}},[_v((_$g(0,'t0')))])}`
`with(this){return _c('div',{attrs:{"id":_$g(0,'a-id'),"_i":0}},[_v((_$g(0,'t0
-0
')))])}`
)
)
})
})
it
(
'
generate filters with no arguments
'
,
()
=>
{
it
(
'
generate filters with no arguments
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
'
<div>{{ d | e() }}</div>
'
,
'
<div>{{ d | e() }}</div>
'
,
`with(this){return _c('div',{attrs:{"_i":0}},[_v((_$g(0,'t0')))])}`
`with(this){return _c('div',{attrs:{"_i":0}},[_v((_$g(0,'t0
-0
')))])}`
)
)
})
})
...
@@ -162,7 +162,7 @@ describe('codegen', () => {
...
@@ -162,7 +162,7 @@ describe('codegen', () => {
it
(
'
generate template tag
'
,
()
=>
{
it
(
'
generate template tag
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
'
<div><template><p>{{hello}}</p></template></div>
'
,
'
<div><template><p>{{hello}}</p></template></div>
'
,
`with(this){return _c('div',{attrs:{"_i":0}},[[_c('p',{attrs:{"_i":2}},[_v((_$g(2,'t0')))])]],2)}`
`with(this){return _c('div',{attrs:{"_i":0}},[[_c('p',{attrs:{"_i":2}},[_v((_$g(2,'t0
-0
')))])]],2)}`
)
)
})
})
...
@@ -197,47 +197,47 @@ describe('codegen', () => {
...
@@ -197,47 +197,47 @@ describe('codegen', () => {
it
(
'
generate scoped slot
'
,
()
=>
{
it
(
'
generate scoped slot
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
'
<foo><template slot-scope="bar">{{ bar }}</template></foo>
'
,
'
<foo><template slot-scope="bar">{{ bar }}</template></foo>
'
,
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar, _svm, _si){return [_v((_svm._$g(("1-"+_si),'t0')))]}}])})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar, _svm, _si){return [_v((_svm._$g(("1-"+_si),'t0
-0
')))]}}])})}`
)
)
assertCodegen
(
assertCodegen
(
'
<foo><div slot-scope="bar">{{ bar }}</div></foo>
'
,
'
<foo><div slot-scope="bar">{{ bar }}</div></foo>
'
,
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar, _svm, _si){return _c('div',{attrs:{"_i":("1-"+_si)}},[_v((_svm._$g(("1-"+_si),'t0')))])}}])})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar, _svm, _si){return _c('div',{attrs:{"_i":("1-"+_si)}},[_v((_svm._$g(("1-"+_si),'t0
-0
')))])}}])})}`
)
)
})
})
it
(
'
generate named scoped slot
'
,
()
=>
{
it
(
'
generate named scoped slot
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
'
<foo><template slot="foo" slot-scope="bar">{{ bar }}</template></foo>
'
,
'
<foo><template slot="foo" slot-scope="bar">{{ bar }}</template></foo>
'
,
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar, _svm, _si){return [_v((_svm._$g(("1-"+_si),'t0')))]}}])})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar, _svm, _si){return [_v((_svm._$g(("1-"+_si),'t0
-0
')))]}}])})}`
)
)
assertCodegen
(
assertCodegen
(
'
<foo><div slot="foo" slot-scope="bar">{{ bar }}</div></foo>
'
,
'
<foo><div slot="foo" slot-scope="bar">{{ bar }}</div></foo>
'
,
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar, _svm, _si){return _c('div',{attrs:{"_i":("1-"+_si)}},[_v((_svm._$g(("1-"+_si),'t0')))])}}])})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar, _svm, _si){return _c('div',{attrs:{"_i":("1-"+_si)}},[_v((_svm._$g(("1-"+_si),'t0
-0
')))])}}])})}`
)
)
})
})
it
(
'
generate dynamic scoped slot
'
,
()
=>
{
it
(
'
generate dynamic scoped slot
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
'
<foo><template :slot="foo" slot-scope="bar">{{ bar }}</template></foo>
'
,
'
<foo><template :slot="foo" slot-scope="bar">{{ bar }}</template></foo>
'
,
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:foo,fn:function(bar, _svm, _si){return [_v((_svm._$g(("1-"+_si),'t0')))]}}],null,true)})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:foo,fn:function(bar, _svm, _si){return [_v((_svm._$g(("1-"+_si),'t0
-0
')))]}}],null,true)})}`
)
)
})
})
it
(
'
generate scoped slot with multiline v-if
'
,
()
=>
{
it
(
'
generate scoped slot with multiline v-if
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
'
<foo><template v-if="
\n
show
\n
" slot-scope="bar">{{ bar }}</template></foo>
'
,
'
<foo><template v-if="
\n
show
\n
" slot-scope="bar">{{ bar }}</template></foo>
'
,
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar, _svm, _si){return (_svm._$g(("1-"+_si),'i'))?[_v((_svm._$g(("1-"+_si),'t0')))]:undefined}}],null,true)})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar, _svm, _si){return (_svm._$g(("1-"+_si),'i'))?[_v((_svm._$g(("1-"+_si),'t0
-0
')))]:undefined}}],null,true)})}`
)
)
assertCodegen
(
assertCodegen
(
'
<foo><div v-if="
\n
show
\n
" slot="foo" slot-scope="bar">{{ bar }}</div></foo>
'
,
'
<foo><div v-if="
\n
show
\n
" slot="foo" slot-scope="bar">{{ bar }}</div></foo>
'
,
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar, _svm, _si){return (_svm._$g(("1-"+_si),'i'))?_c('div',{attrs:{"_i":("1-"+_si)}},[_v((_svm._$g(("1-"+_si),'t0')))]):_e()}}],null,true)})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar, _svm, _si){return (_svm._$g(("1-"+_si),'i'))?_c('div',{attrs:{"_i":("1-"+_si)}},[_v((_svm._$g(("1-"+_si),'t0
-0
')))]):_e()}}],null,true)})}`
)
)
})
})
it
(
'
generate scoped slot with new slot syntax
'
,
()
=>
{
it
(
'
generate scoped slot with new slot syntax
'
,
()
=>
{
assertCodegen
(
assertCodegen
(
'
<foo><template v-if="show" #default="bar">{{ bar }}</template></foo>
'
,
'
<foo><template v-if="show" #default="bar">{{ bar }}</template></foo>
'
,
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([(_$g(1,'i'))?{key:"default",fn:function(bar, _svm, _si){return [_v((_svm._$g(("1-"+_si),'t0')))]}}:null],null,true)})}`
`with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([(_$g(1,'i'))?{key:"default",fn:function(bar, _svm, _si){return [_v((_svm._$g(("1-"+_si),'t0
-0
')))]}}:null],null,true)})}`
)
)
})
})
...
@@ -625,7 +625,7 @@ describe('codegen', () => {
...
@@ -625,7 +625,7 @@ describe('codegen', () => {
// normalize type: 2
// normalize type: 2
assertCodegen
(
assertCodegen
(
'
<div><child></child><template v-for="item in list">{{ item }}</template></div>
'
,
'
<div><child></child><template v-for="item in list">{{ item }}</template></div>
'
,
`with(this){return _c('div',{attrs:{"_i":0}},[_c('child',{attrs:{"_i":1}}),_l((_$g(2,'f')),function(item,$10,$20,$30){return [_v((_$g(("2-"+$30),'t0')))]})],2)}`
`with(this){return _c('div',{attrs:{"_i":0}},[_c('child',{attrs:{"_i":1}}),_l((_$g(2,'f')),function(item,$10,$20,$30){return [_v((_$g(("2-"+$30),'t0
-0
')))]})],2)}`
)
)
})
})
...
...
packages/uni-template-compiler/__tests__/demo.js
浏览文件 @
86f512f1
...
@@ -18,8 +18,8 @@ const scopedPath = path.resolve(__dirname, '../../')
...
@@ -18,8 +18,8 @@ const scopedPath = path.resolve(__dirname, '../../')
const
compiler
=
require
(
'
../lib
'
)
const
compiler
=
require
(
'
../lib
'
)
const
res
=
compiler
.
compile
(
const
res
=
compiler
.
compile
(
`
`
<
text v-if="a">1</text><text v-else-if="b">2</text><text v-else-if="c">3</text><text v-else>d</text>
<
view>{{obj.param1}}123123{{obj.param1}}123123{{obj.param1}}<text> -{{obj.param3}}---{{obj.param3}} </text>{{obj.param2}}aaaa{{obj.param2}}aaaa{{obj.param2}}</view>
`
,
{
`
,
{
miniprogram
:
true
,
miniprogram
:
true
,
resourcePath
:
'
/User/fxy/Documents/test.wxml
'
,
resourcePath
:
'
/User/fxy/Documents/test.wxml
'
,
...
...
packages/uni-template-compiler/lib/app/parser/text-parser.js
浏览文件 @
86f512f1
...
@@ -43,7 +43,7 @@ module.exports = function parseText (
...
@@ -43,7 +43,7 @@ module.exports = function parseText (
}
}
// tag token
// tag token
const
exp
=
parseFilters
(
match
[
1
].
trim
())
const
exp
=
parseFilters
(
match
[
1
].
trim
())
tokens
.
push
(
`(
${
state
.
genVar
(
'
t
'
+
(
state
.
index
++
),
'
_s(
'
+
exp
+
'
)
'
)}
)`
)
tokens
.
push
(
`(
${
state
.
genVar
(
'
t
'
+
(
state
.
childIndex
)
+
'
-
'
+
(
state
.
index
++
),
'
_s(
'
+
exp
+
'
)
'
)}
)`
)
rawTokens
.
push
({
rawTokens
.
push
({
'
@binding
'
:
exp
'
@binding
'
:
exp
})
})
...
...
packages/uni-template-compiler/lib/app/service.js
浏览文件 @
86f512f1
...
@@ -119,6 +119,7 @@ function transformNode (el, parent, state, isScopedSlot) {
...
@@ -119,6 +119,7 @@ function transformNode (el, parent, state, isScopedSlot) {
pid
=
getNewId
(
pid
,
'
_si
'
)
pid
=
getNewId
(
pid
,
'
_si
'
)
}
}
return
parseText
(
el
,
parent
,
{
return
parseText
(
el
,
parent
,
{
childIndex
:
state
.
childIndex
||
0
,
index
:
0
,
index
:
0
,
service
:
true
,
service
:
true
,
// <uni-popup>{{content}}</uni-popup>
// <uni-popup>{{content}}</uni-popup>
...
...
packages/uni-template-compiler/lib/app/util.js
浏览文件 @
86f512f1
...
@@ -104,7 +104,7 @@ function updateForIterator (el, state) {
...
@@ -104,7 +104,7 @@ function updateForIterator (el, state) {
function
updateForEleId
(
el
,
state
)
{
function
updateForEleId
(
el
,
state
)
{
updateForIterator
(
el
,
state
)
updateForIterator
(
el
,
state
)
if
(
el
.
for
)
{
if
(
el
.
for
)
{
const
it
=
el
.
$parentIterator3
?
(
el
.
$parentIterator3
+
'
+
'
+
"
'-'
"
+
'
+
'
+
el
.
iterator3
)
:
el
.
iterator3
const
it
=
el
.
$parentIterator3
?
(
el
.
$parentIterator3
+
'
+
'
+
"
'-'
"
+
'
+
'
+
el
.
iterator3
)
:
el
.
iterator3
updateEleId
(
el
,
it
,
state
)
updateEleId
(
el
,
it
,
state
)
}
}
...
@@ -194,11 +194,18 @@ function hasOwn (obj, key) {
...
@@ -194,11 +194,18 @@ function hasOwn (obj, key) {
function
traverseNode
(
el
,
parent
,
state
,
isScopedSlot
)
{
function
traverseNode
(
el
,
parent
,
state
,
isScopedSlot
)
{
state
.
transformNode
(
el
,
parent
,
state
,
isScopedSlot
)
state
.
transformNode
(
el
,
parent
,
state
,
isScopedSlot
)
el
.
children
&&
el
.
children
.
forEach
(
child
=>
traverseNode
(
child
,
el
,
state
,
isScopedSlot
))
el
.
children
&&
el
.
children
.
forEach
((
child
,
index
)
=>
{
state
.
childIndex
=
index
traverseNode
(
child
,
el
,
state
,
isScopedSlot
)
})
el
.
ifConditions
&&
el
.
ifConditions
.
forEach
((
con
,
index
)
=>
{
el
.
ifConditions
&&
el
.
ifConditions
.
forEach
((
con
,
index
)
=>
{
index
!==
0
&&
traverseNode
(
con
.
block
,
el
,
state
,
isScopedSlot
)
if
(
index
!==
0
)
{
state
.
childIndex
=
index
traverseNode
(
con
.
block
,
el
,
state
,
isScopedSlot
)
}
})
})
el
.
scopedSlots
&&
Object
.
values
(
el
.
scopedSlots
).
forEach
(
slot
=>
{
el
.
scopedSlots
&&
Object
.
values
(
el
.
scopedSlots
).
forEach
((
slot
,
index
)
=>
{
state
.
childIndex
=
index
slot
.
slotScope
=
`
${
slot
.
slotScope
}
, _svm, _si`
slot
.
slotScope
=
`
${
slot
.
slotScope
}
, _svm, _si`
traverseNode
(
slot
,
el
,
state
,
true
)
traverseNode
(
slot
,
el
,
state
,
true
)
})
})
...
...
packages/uni-template-compiler/lib/app/view.js
浏览文件 @
86f512f1
...
@@ -114,7 +114,8 @@ function transformNode (el, parent, state, isScopedSlot) {
...
@@ -114,7 +114,8 @@ function transformNode (el, parent, state, isScopedSlot) {
if
(
isScopedSlot
&&
String
(
pid
).
indexOf
(
'
_si
'
)
===
-
1
)
{
if
(
isScopedSlot
&&
String
(
pid
).
indexOf
(
'
_si
'
)
===
-
1
)
{
pid
=
getNewId
(
pid
,
'
_si
'
)
pid
=
getNewId
(
pid
,
'
_si
'
)
}
}
return
parseText
(
el
,
parent
,
{
return
parseText
(
el
,
parent
,
{
childIndex
:
state
.
childIndex
||
0
,
index
:
0
,
index
:
0
,
view
:
true
,
view
:
true
,
// <uni-popup>{{content}}</uni-popup>
// <uni-popup>{{content}}</uni-popup>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录