diff --git a/package.json b/package.json
index 37e338ce30bd5b70f39717f5f47921f40d7bb698..006486051c696dbdf4cdc947b5acc7c16d7f769c 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 025748c19331602e367b2ea7b9744608b87d6f48..2b1366a1a6a77234a3906f03941fb06e00c9f85e 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(
'text
',
- `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(
'{{text}}
',
- `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(
'{{text}}
',
- `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(
'a {{text1}} b {{text2}}
',
- `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 886501156940c05fc5eb83d476aff2440ce08186..62278524de24b7b3fd0f1b5fbc23f4bc4118990b 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 c5c10c53eaf47c0c6e1ad6180e48bb243cf65035..8b8e5af9834601bac05ad395bc66547ea72840cb 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(
'{{ item }}
',
- `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 dde7fd142aca6c41304ca85fa77142ff3c22f32c..2ae04bf1c051124719e612e129acef23e062dee8 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(
'',
- `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(
'',
- `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(
'',
- `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(
'',
- `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(
'{{ bar }}',
- `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(
'{{ bar }}',
- `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(
'{{ bar }}',
- `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(
'{{ bar }}',
- `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(
'{{ bar }}',
- `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(
'{{ item }}
',
- `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 402a7af1c8c28be86b3f011bb0c25c1f895ed5dc..e4bea3e850ea0f23ab8db7c2719fb812a68cf512 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 ccb8a00ea9b55f7e34f2514f782b568d1c115f5c..7e64091eba53d70d871d16d678aaa1ca6ea2c5b3 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}`
}
}
}