From a883c3ed0a95cba111993c9db218d0e138e4ce47 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Fri, 18 Oct 2019 16:37:10 +0800 Subject: [PATCH] fix(v3): __tests__ --- package.json | 3 +- .../compiler-app-plus-extra.service.spec.js | 14 ++-- .../compiler-app-plus-extra.view.spec.js | 8 +- .../compiler-app-plus.service.spec.js | 6 +- .../__tests__/compiler-app-plus.view.spec.js | 82 +++++++++---------- .../uni-template-compiler/__tests__/demo.js | 9 +- .../uni-template-compiler/lib/app/util.js | 2 +- 7 files changed, 59 insertions(+), 65 deletions(-) diff --git a/package.json b/package.json index 37e338ce3..006486051 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,8 @@ "test:unit": "cross-env NODE_ENV=test UNI_PLATFORM=h5 mocha-webpack --require tests/unit/setup.js --webpack-config build/webpack.config.test.js tests/unit/**/*.spec.js", "release": "npm run lint:cli && lerna publish --force-publish=*", "release:alpha": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=alpha", - "release:next": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=next" + "release:next": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=next", + "release:v3": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=v3" }, "dependencies": { "base64-arraybuffer": "^0.2.0", diff --git a/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js b/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js index 025748c19..2b1366a1a 100644 --- a/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js @@ -19,7 +19,7 @@ describe('codegen', () => { ) assertCodegen( '
', - `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('div',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0-'+$30}),attrs:{"_i":("2-"+$30)}}),_c('div',{key:_$f(1,{forIndex:$20,keyIndex:1,key:1+'-1-'+$30}),attrs:{"_i":("3-"+$30)}})]})],2)}` + `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('div',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0'+$30}),attrs:{"_i":("2-"+$30)}}),_c('div',{key:_$f(1,{forIndex:$20,keyIndex:1,key:1+'-1'+$30}),attrs:{"_i":("3-"+$30)}})]})],2)}` ) assertCodegen( '
', @@ -35,27 +35,27 @@ describe('codegen', () => { it('generate v-for directive', () => { assertCodegen( '
', - `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('div',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0-'+$30}),attrs:{"_i":("2-"+$30)}}),_c('div',{key:_$f(1,{forIndex:$20,keyIndex:1,key:1+'-1-'+$30}),attrs:{"_i":("3-"+$30)}})]})],2)}` + `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('div',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0'+$30}),attrs:{"_i":("2-"+$30)}}),_c('div',{key:_$f(1,{forIndex:$20,keyIndex:1,key:1+'-1'+$30}),attrs:{"_i":("3-"+$30)}})]})],2)}` ) assertCodegen( '
', - `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('text',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0-'+$30}),attrs:{"_i":("1-"+$30)}})]})],2)}` + `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('text',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0'+$30}),attrs:{"_i":("1-"+$30)}})]})],2)}` ) assertCodegen( '
', - `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$i){return [_c('text',{key:_$f(1,{forIndex:$i,keyIndex:0,key:'1-0-'+$i}),extras:{t0:_s(text)},attrs:{"_i":("1-"+$i)}})]})],2)}` + `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('text',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0'+$30}),extras:{t0:_s(text)},attrs:{"_i":("1-"+$30)}})]})],2)}` ) assertCodegen( '
', - `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$i){return [_c('span',{key:_$f(1,{forIndex:$i,keyIndex:0,key:'1-0-'+$i}),attrs:{"_i":("2-"+$i)}}),_c('text',{extras:{t0:_s(text)},attrs:{"_i":("1-"+$i)}})]})],2)}` + `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('span',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0'+$30}),attrs:{"_i":("2-"+$30)}}),_c('text',{extras:{t0:_s(text)},attrs:{"_i":("1-"+$30)}})]})],2)}` ) assertCodegen( '
', - `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$i){return [_c('text',{key:_$f(1,{forIndex:$i,keyIndex:0,key:'1-0-'+$i}),extras:{t0:_s(text1),t1:_s(text2)},attrs:{"_i":("1-"+$i)}})]})],2)}` + `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [_c('text',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0'+$30}),extras:{t0:_s(text1),t1:_s(text2)},attrs:{"_i":("1-"+$30)}})]})],2)}` ) assertCodegen( '
', - `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$i){return [(_$i(("2-"+$i),item.sub))?_c('span',{key:_$f(1,{forIndex:$i,keyIndex:0,key:'1-0-'+$i}),attrs:{"_i":("2-"+$i)}}):_e()]})],2)}` + `with(this){return _c('div',{attrs:{"_i":0}},[_l((_$f(1,{forItems:items})),function(item,$10,$20,$30){return [(_$i(("2-"+$30),item.sub))?_c('span',{key:_$f(1,{forIndex:$20,keyIndex:0,key:1+'-0'+$30}),attrs:{"_i":("2-"+$30)}}):_e()]})],2)}` ) }) it('generate text with multiple statements', () => { diff --git a/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js b/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js index 886501156..62278524d 100644 --- a/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js @@ -15,23 +15,23 @@ describe('codegen', () => { it('generate directive', () => { assertCodegen( '

', - `with(this){return _c('v-uni-view',{directives:[{name:"custom1",rawName:"v-custom1:[arg1].modifier",value:($r['0']['v-custom1']),expression:"$r['0']['v-custom1']",arg:$r['0']['v-custom1-arg'],modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}],attrs:{"_i":0}})}` + `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}})}` ) }) it('generate v-for directive', () => { assertCodegen( '
', - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_l(($r['1']['v-for']),function(item,$i){return [_c('v-uni-view',{key:item['k0'],attrs:{"_i":("2-"+$i)}}),_c('v-uni-view',{key:item['k1'],attrs:{"_i":("3-"+$i)}})]})],2)}` + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_l((_$g(1,'v-for')),function(item,$10,$20,$30){return [_c('v-uni-view',{key:item['k0'],attrs:{"_i":("2-"+$30)}}),_c('v-uni-view',{key:item['k1'],attrs:{"_i":("3-"+$30)}})]})],2)}` ) assertCodegen( '
', - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_l(($r['1']['v-for']),function(item,$i){return [($r[("2-"+$i)]['v-if'])?_c('v-uni-label',{key:item['k0'],attrs:{"_i":("2-"+$i)}}):_e()]})],2)}` + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_l((_$g(1,'v-for')),function(item,$10,$20,$30){return [(_$g(("2-"+$30),'v-if'))?_c('v-uni-label',{key:item['k0'],attrs:{"_i":("2-"+$30)}}):_e()]})],2)}` ) }) it('generate events with multiple statements', () => { assertCodegen( '
A{{ d | e | f }}B{{text}}C
', - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v("A"+($r['0']['t0'])+"B"+($r['0']['t1'])+"C")])}` + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v("A"+(_$g(0,'t0'))+"B"+(_$g(0,'t1'))+"C")])}` ) }) }) diff --git a/packages/uni-template-compiler/__tests__/compiler-app-plus.service.spec.js b/packages/uni-template-compiler/__tests__/compiler-app-plus.service.spec.js index c5c10c53e..8b8e5af98 100644 --- a/packages/uni-template-compiler/__tests__/compiler-app-plus.service.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-app-plus.service.spec.js @@ -616,7 +616,7 @@ describe('codegen', () => { it('generate static trees inside v-for', () => { assertCodegen( `

`, - `with(this){return _c('div',{attrs:{"_i":0}},_l((10),function(i,$i){return _c('div',{attrs:{"_i":("1-"+$i)}},[_m(0,true)])}),0)}` + `with(this){return _c('div',{attrs:{"_i":0}},_l((10),function(i,$10,$20,$30){return _c('div',{attrs:{"_i":("1-"+$30)}},[_m(0,true)])}),0)}` // [`with(this){return _c('p',[_c('span')])}`] ) }) @@ -625,7 +625,7 @@ describe('codegen', () => { // normalize type: 2 assertCodegen( '
', - `with(this){return _c('div',{attrs:{"_i":0}},[_c('child',{attrs:{"_i":1}}),_l((_$f(2,{forItems:list})),function(item,$i){return [_c('text',{key:_$f(2,{forIndex:$i,keyIndex:0,key:'2-0-'+$i}),extras:{t0:_s(item)},attrs:{"_i":("2-"+$i)}})]})],2)}` + `with(this){return _c('div',{attrs:{"_i":0}},[_c('child',{attrs:{"_i":1}}),_l((_$f(2,{forItems:list})),function(item,$10,$20,$30){return [_c('text',{key:_$f(2,{forIndex:$20,keyIndex:0,key:2+'-0'+$30}),extras:{t0:_s(item)},attrs:{"_i":("2-"+$30)}})]})],2)}` ) }) @@ -695,7 +695,7 @@ describe('codegen', () => { it('should compile single v-for component inside template', () => { assertCodegen( `
`, - `with(this){return _c('div',{attrs:{"_i":0}},[(_$i(1,ok))?_l((1),function(i,$i){return _c('foo',{key:i,attrs:{"_i":("2-"+$i)}})}):_e()],2)}` + `with(this){return _c('div',{attrs:{"_i":0}},[(_$i(1,ok))?_l((1),function(i,$10,$20,$30){return _c('foo',{key:i,attrs:{"_i":("2-"+$30)}})}):_e()],2)}` ) }) }) diff --git a/packages/uni-template-compiler/__tests__/compiler-app-plus.view.spec.js b/packages/uni-template-compiler/__tests__/compiler-app-plus.view.spec.js index dde7fd142..2ae04bf1c 100644 --- a/packages/uni-template-compiler/__tests__/compiler-app-plus.view.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-app-plus.view.spec.js @@ -15,91 +15,91 @@ describe('codegen', () => { it('generate directive', () => { assertCodegen( '

', - `with(this){return _c('v-uni-view',{directives:[{name:"custom1",rawName:"v-custom1:arg1.modifier",value:($r['0']['v-custom1']),expression:"$r['0']['v-custom1']",arg:"arg1",modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}],attrs:{"_i":0}})}` + `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}})}` ) // extra assertCodegen( '

', - `with(this){return _c('v-uni-view',{directives:[{name:"custom1",rawName:"v-custom1:[arg1].modifier",value:($r['0']['v-custom1']),expression:"$r['0']['v-custom1']",arg:$r['0']['v-custom1-arg'],modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}],attrs:{"_i":0}})}` + `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}})}` ) }) it('generate filters', () => { assertCodegen( '
{{ d | e | f }}
', - `with(this){return _c('v-uni-view',{attrs:{"id":$r['0']['a-id'],"_i":0}},[_v(($r['0']['t0']))])}` + `with(this){return _c('v-uni-view',{attrs:{"id":_$g(0,'a-id'),"_i":0}},[_v((_$g(0,'t0')))])}` ) }) it('generate filters with no arguments', () => { assertCodegen( '
{{ d | e() }}
', - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v(($r['0']['t0']))])}` + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v((_$g(0,'t0')))])}` ) }) it('generate v-for directive', () => { assertCodegen( '
  • ', - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},_l(($r['1']['v-for']),function(item,$10,$20,$30){return _c('v-uni-view',{key:item,attrs:{"_i":("1-"+$30)}})}),0)}` + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},_l((_$g(1,'v-for')),function(item,$10,$20,$30){return _c('v-uni-view',{key:item,attrs:{"_i":("1-"+$30)}})}),1)}` ) // iterator syntax assertCodegen( '
  • ', - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},_l(($r['1']['v-for']),function(item,i){return _c('v-uni-view',{key:item,attrs:{"_i":("1-"+i)}})}),1)}` + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},_l((_$g(1,'v-for')),function(item,i,$20,$30){return _c('v-uni-view',{key:item,attrs:{"_i":("1-"+$30)}})}),1)}` ) assertCodegen( '
  • ', - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},_l(($r['1']['v-for']),function(item,index){return _c('v-uni-view',{key:item,attrs:{"_i":("1-"+index)}})}),1)}` + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},_l((_$g(1,'v-for')),function(item,key,index,$30){return _c('v-uni-view',{key:item,attrs:{"_i":("1-"+$30)}})}),1)}` ) // destructuring assertCodegen( '
  • ', - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},_l(($r['1']['v-for']),function($item,$i){return _c('v-uni-view',{key:$item,attrs:{"_i":("1-"+$i)}})}),1)}` + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},_l((_$g(1,'v-for')),function($item,$10,$20,$30){return _c('v-uni-view',{key:$item,attrs:{"_i":("1-"+$30)}})}),1)}` ) assertCodegen( '
  • ', - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},_l(($r['1']['v-for']),function($item,index){return _c('v-uni-view',{key:$item,attrs:{"_i":("1-"+index)}})}),1)}` + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},_l((_$g(1,'v-for')),function($item,key,index,$30){return _c('v-uni-view',{key:$item,attrs:{"_i":("1-"+$30)}})}),1)}` ) // v-for with extra element assertCodegen( '

  • ', - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_c('v-uni-view',{attrs:{"_i":1}}),_l(($r['2']['v-for']),function(item,$i){return _c('v-uni-view',{key:item,attrs:{"_i":("2-"+$i)}})})],2)}` + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_c('v-uni-view',{attrs:{"_i":1}}),_l((_$g(2,'v-for')),function(item,$10,$20,$30){return _c('v-uni-view',{key:item,attrs:{"_i":("2-"+$30)}})})],2)}` ) }) it('generate v-if directive', () => { assertCodegen( '

    hello

    ', - `with(this){return ($r['0']['v-if'])?_c('v-uni-view',{attrs:{"_i":0}},[_v("hello")]):_e()}` + `with(this){return (_$g(0,'v-if'))?_c('v-uni-view',{attrs:{"_i":0}},[_v("hello")]):_e()}` ) }) it('generate v-else directive', () => { assertCodegen( '

    hello

    world

    ', - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[($r['1']['v-if'])?_c('v-uni-view',{attrs:{"_i":1}},[_v("hello")]):_c('v-uni-view',{attrs:{"_i":2}},[_v("world")])],1)}` + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[(_$g(1,'v-if'))?_c('v-uni-view',{attrs:{"_i":1}},[_v("hello")]):_c('v-uni-view',{attrs:{"_i":2}},[_v("world")])],1)}` ) }) it('generate v-else-if directive', () => { assertCodegen( '

    hello

    world

    ', - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[($r['1']['v-if'])?_c('v-uni-view',{attrs:{"_i":1}},[_v("hello")]):($r['2']['v-else-if'])?_c('v-uni-view',{attrs:{"_i":2}},[_v("world")]):_e()],1)}` + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[(_$g(1,'v-if'))?_c('v-uni-view',{attrs:{"_i":1}},[_v("hello")]):(_$g(2,'v-else-if'))?_c('v-uni-view',{attrs:{"_i":2}},[_v("world")]):_e()],1)}` ) }) it('generate v-else-if with v-else directive', () => { assertCodegen( '

    hello

    world

    bye

    ', - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[($r['1']['v-if'])?_c('v-uni-view',{attrs:{"_i":1}},[_v("hello")]):($r['2']['v-else-if'])?_c('v-uni-view',{attrs:{"_i":2}},[_v("world")]):_c('v-uni-view',{attrs:{"_i":3}},[_v("bye")])],1)}` + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[(_$g(1,'v-if'))?_c('v-uni-view',{attrs:{"_i":1}},[_v("hello")]):(_$g(2,'v-else-if'))?_c('v-uni-view',{attrs:{"_i":2}},[_v("world")]):_c('v-uni-view',{attrs:{"_i":3}},[_v("bye")])],1)}` ) }) it('generate multi v-else-if with v-else directive', () => { assertCodegen( '

    hello

    world

    elseif

    bye

    ', - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[($r['1']['v-if'])?_c('v-uni-view',{attrs:{"_i":1}},[_v("hello")]):($r['2']['v-else-if'])?_c('v-uni-view',{attrs:{"_i":2}},[_v("world")]):(3)?_c('v-uni-view',{attrs:{"_i":3}},[_v("elseif")]):_c('v-uni-view',{attrs:{"_i":4}},[_v("bye")])],1)}` + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[(_$g(1,'v-if'))?_c('v-uni-view',{attrs:{"_i":1}},[_v("hello")]):(_$g(2,'v-else-if'))?_c('v-uni-view',{attrs:{"_i":2}},[_v("world")]):(3)?_c('v-uni-view',{attrs:{"_i":3}},[_v("elseif")]):_c('v-uni-view',{attrs:{"_i":4}},[_v("bye")])],1)}` ) }) @@ -113,56 +113,56 @@ describe('codegen', () => { it('generate ref on v-for', () => { assertCodegen( '', - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},_l(($r['1']['v-for']),function(item,$i){return _c('v-uni-view',{key:item,ref:"component1",refInFor:true,attrs:{"_i":("1-"+$i)}})}),1)}` + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},_l((_$g(1,'v-for')),function(item,$10,$20,$30){return _c('v-uni-view',{key:item,ref:"component1",refInFor:true,attrs:{"_i":("1-"+$30)}})}),1)}` ) }) it('generate v-bind directive', () => { assertCodegen( '

    ', - `with(this){return _c('v-uni-view',_b({attrs:{"_i":0}},'v-uni-view',$r['0']['v-bind'],false))}` + `with(this){return _c('v-uni-view',_b({attrs:{"_i":0}},'v-uni-view',_$g(0,'v-bind'),false))}` ) }) it('generate v-bind with prop directive', () => { assertCodegen( '

    ', - `with(this){return _c('v-uni-view',_b({attrs:{"_i":0}},'v-uni-view',$r['0']['v-bind'],true))}` + `with(this){return _c('v-uni-view',_b({attrs:{"_i":0}},'v-uni-view',_$g(0,'v-bind'),true))}` ) }) it('generate v-bind directive with sync modifier', () => { assertCodegen( '

    ', - `with(this){return _c('v-uni-view',_b({attrs:{"_i":0}},'v-uni-view',$r['0']['v-bind'],false,true))}` + `with(this){return _c('v-uni-view',_b({attrs:{"_i":0}},'v-uni-view',_$g(0,'v-bind'),false,true))}` ) }) it('generate v-model directive', () => { assertCodegen( '', - `with(this){return _c('v-uni-input',{attrs:{"_i":0},model:{value:($r['0']['v-model']),callback:function ($$v) {},expression:"$r['0']['v-model']"}})}` + `with(this){return _c('v-uni-input',{attrs:{"_i":0},model:{value:(_$g(0,'v-model')),callback:function ($$v) {},expression:"_$g(0,'v-model')"}})}` ) }) it('generate multiline v-model directive', () => { assertCodegen( '', - `with(this){return _c('v-uni-input',{attrs:{"_i":0},model:{value:($r['0']['v-model']),callback:function ($$v) {},expression:"$r['0']['v-model']"}})}` + `with(this){return _c('v-uni-input',{attrs:{"_i":0},model:{value:(_$g(0,'v-model')),callback:function ($$v) {},expression:"_$g(0,'v-model')"}})}` ) }) it('generate multiline v-model directive on custom component', () => { assertCodegen( '', - `with(this){return _c('my-component',{attrs:{"_i":0},model:{value:($r['0']['v-model']),callback:function ($$v) {},expression:"$r['0']['v-model']"}})}` + `with(this){return _c('my-component',{attrs:{"_i":0},model:{value:(_$g(0,'v-model')),callback:function ($$v) {},expression:"_$g(0,'v-model')"}})}` ) }) it('generate template tag', () => { assertCodegen( '
    ', - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[[_c('v-uni-view',{attrs:{"_i":2}},[_v(($r['2']['t0']))])]],2)}` + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[[_c('v-uni-view',{attrs:{"_i":2}},[_v((_$g(2,'t0')))])]],2)}` ) }) @@ -197,47 +197,47 @@ describe('codegen', () => { it('generate scoped slot', () => { assertCodegen( '', - `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar){return [_v(($r['1']['t0']))]}}])})}` + `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar){return [_v((_$g(1,'t0')))]}}])})}` ) assertCodegen( '
    {{ bar }}
    ', - `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar){return _c('v-uni-view',{attrs:{"_i":1}},[_v(($r['1']['t0']))])}}])})}` + `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar){return _c('v-uni-view',{attrs:{"_i":1}},[_v((_$g(1,'t0')))])}}])})}` ) }) it('generate named scoped slot', () => { assertCodegen( '', - `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar){return [_v(($r['1']['t0']))]}}])})}` + `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar){return [_v((_$g(1,'t0')))]}}])})}` ) assertCodegen( '
    {{ bar }}
    ', - `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar){return _c('v-uni-view',{attrs:{"_i":1}},[_v(($r['1']['t0']))])}}])})}` + `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar){return _c('v-uni-view',{attrs:{"_i":1}},[_v((_$g(1,'t0')))])}}])})}` ) }) it('generate dynamic scoped slot', () => { assertCodegen( '', - `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:foo,fn:function(bar){return [_v(($r['1']['t0']))]}}],null,true)})}` + `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:foo,fn:function(bar){return [_v((_$g(1,'t0')))]}}],null,true)})}` ) }) it('generate scoped slot with multiline v-if', () => { assertCodegen( '', - `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar){return ($r['1']['v-if'])?[_v(($r['1']['t0']))]:undefined}}],null,true)})}` + `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar){return (_$g(1,'v-if'))?[_v((_$g(1,'t0')))]:undefined}}],null,true)})}` ) assertCodegen( '
    {{ bar }}
    ', - `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar){return ($r['1']['v-if'])?_c('v-uni-view',{attrs:{"_i":1}},[_v(($r['1']['t0']))]):_e()}}],null,true)})}` + `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar){return (_$g(1,'v-if'))?_c('v-uni-view',{attrs:{"_i":1}},[_v((_$g(1,'t0')))]):_e()}}],null,true)})}` ) }) it('generate scoped slot with new slot syntax', () => { assertCodegen( '', - `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([($r['1']['v-if'])?{key:"default",fn:function(bar){return [_v(($r['1']['t0']))]}}:null],null,true)})}` + `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([(_$g(1,'v-if'))?{key:"default",fn:function(bar){return [_v((_$g(1,'t0')))]}}:null],null,true)})}` ) }) @@ -250,21 +250,21 @@ describe('codegen', () => { // dynamic assertCodegen( '

    hello world

    ', - `with(this){return _c('v-uni-view',{class:$r['0']['c'],attrs:{"_i":0}},[_v("hello world")])}` + `with(this){return _c('v-uni-view',{class:_$g(0,'c'),attrs:{"_i":0}},[_v("hello world")])}` ) }) it('generate style binding', () => { assertCodegen( '

    hello world

    ', - `with(this){return _c('v-uni-view',{style:($r['0']['s']),attrs:{"_i":0}},[_v("hello world")])}` + `with(this){return _c('v-uni-view',{style:(_$g(0,'s')),attrs:{"_i":0}},[_v("hello world")])}` ) }) it('generate v-show directive', () => { assertCodegen( '

    hello world

    ', - `with(this){return _c('v-uni-view',{directives:[{name:"show",rawName:"v-show",value:($r['0']['v-show']),expression:"$r['0']['v-show']"}],attrs:{"_i":0}},[_v("hello world")])}` + `with(this){return _c('v-uni-view',{directives:[{name:"show",rawName:"v-show",value:(_$g(0,'v-show')),expression:"_$g(0,'v-show')"}],attrs:{"_i":0}},[_v("hello world")])}` ) }) @@ -272,19 +272,19 @@ describe('codegen', () => { // input + value assertCodegen( '', - `with(this){return _c('v-uni-input',{attrs:{"value":$r['0']['a-value'],"_i":0}})}` + `with(this){return _c('v-uni-input',{attrs:{"value":_$g(0,'a-value'),"_i":0}})}` ) // non input assertCodegen( '

    ', - `with(this){return _c('v-uni-view',{attrs:{"value":$r['0']['a-value'],"_i":0}})}` + `with(this){return _c('v-uni-view',{attrs:{"value":_$g(0,'a-value'),"_i":0}})}` ) }) it('generate attrs with v-bind directive', () => { assertCodegen( '', - `with(this){return _c('v-uni-input',{attrs:{"name":$r['0']['a-name'],"_i":0}})}` + `with(this){return _c('v-uni-input',{attrs:{"name":_$g(0,'a-name'),"_i":0}})}` ) }) @@ -616,7 +616,7 @@ describe('codegen', () => { it('generate static trees inside v-for', () => { assertCodegen( `

    `, - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},_l((10),function(i,$i){return _c('v-uni-view',{attrs:{"_i":("1-"+$i)}},[_c('v-uni-view',{attrs:{"_i":("2-"+$i)}},[_c('v-uni-label',{attrs:{"_i":("3-"+$i)}})],1)],1)}),1)}` + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},_l((10),function(i,$10,$20,$30){return _c('v-uni-view',{attrs:{"_i":("1-"+$30)}},[_c('v-uni-view',{attrs:{"_i":("2-"+$30)}},[_c('v-uni-label',{attrs:{"_i":("3-"+$30)}})],1)],1)}),1)}` // [`with(this){return _c('v-uni-view',{attrs:{"_i":("2-"+$i)}},[_c('v-uni-view',{attrs:{"_i":("3-"+$i)}})])}`] ) }) @@ -625,7 +625,7 @@ describe('codegen', () => { // normalize type: 2 assertCodegen( '
    ', - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_c('child',{attrs:{"_i":1}}),_l(($r['2']['v-for']),function(item,$i){return [_v(($r[("2-"+$i)]['t0']))]})],2)}` + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_c('child',{attrs:{"_i":1}}),_l((_$g(2,'v-for')),function(item,$10,$20,$30){return [_v((_$g(("2-"+$30),'t0')))]})],2)}` ) }) @@ -685,7 +685,7 @@ describe('codegen', () => { it('not specified directives option', () => { assertCodegen( '

    hello world

    ', - `with(this){return ($r['0']['v-if'])?_c('v-uni-view',{attrs:{"_i":0}},[_v("hello world")]):_e()}`, { + `with(this){return (_$g(0,'v-if'))?_c('v-uni-view',{attrs:{"_i":0}},[_v("hello world")]):_e()}`, { // isReservedTag } ) @@ -695,7 +695,7 @@ describe('codegen', () => { it('should compile single v-for component inside template', () => { assertCodegen( `
    `, - `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[($r['1']['v-if'])?_l((1),function(i,$i){return _c('foo',{key:i,attrs:{"_i":("2-"+$i)}})}):_e()],2)}` + `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[(_$g(1,'v-if'))?_l((1),function(i,$10,$20,$30){return _c('foo',{key:i,attrs:{"_i":("2-"+$30)}})}):_e()],2)}` ) }) }) diff --git a/packages/uni-template-compiler/__tests__/demo.js b/packages/uni-template-compiler/__tests__/demo.js index 402a7af1c..e4bea3e85 100644 --- a/packages/uni-template-compiler/__tests__/demo.js +++ b/packages/uni-template-compiler/__tests__/demo.js @@ -1,14 +1,7 @@ const compiler = require('../lib') const res = compiler.compile( ` -
    - - - - - - -
    +
    `, { resourcePath: '/User/fxy/Documents/test.wxml', isReservedTag: function (tag) { diff --git a/packages/uni-template-compiler/lib/app/util.js b/packages/uni-template-compiler/lib/app/util.js index ccb8a00ea..7e64091eb 100644 --- a/packages/uni-template-compiler/lib/app/util.js +++ b/packages/uni-template-compiler/lib/app/util.js @@ -122,7 +122,7 @@ function processForKey (el) { } } } else { - el.key = `${forEl.forId}+${it}` + el.key = `${forEl.forId}+'-'+${it}` } } } -- GitLab