提交 06b48591 编写于 作者: Q qiang

Merge branch 'dev' of github.com:dcloudio/uni-app into dev

...@@ -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})),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',_s(item))))])]]})],2)}`
) )
}) })
it('generate directive', () => { it('generate directive', () => {
......
...@@ -194,15 +194,15 @@ describe('mp:compiler-extra', () => { ...@@ -194,15 +194,15 @@ describe('mp:compiler-extra', () => {
it('generate default slot', () => { it('generate default slot', () => {
assertCodegen( assertCodegen(
'<component1>text</component1>', '<component1>text</component1>',
`<component1 vue-id="1" bind:__l="__l" vue-slots="{{['default']}}">text</component1>` `<component1 vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default']}}">text</component1>`
) )
assertCodegen( assertCodegen(
'<component1>text<text>123213</text></component1>', '<component1>text<text>123213</text></component1>',
`<component1 vue-id="1" bind:__l="__l" vue-slots="{{['default']}}">text<text>123213</text></component1>` `<component1 vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default']}}">text<text>123213</text></component1>`
) )
assertCodegen( assertCodegen(
'<component1>text<block slot="right"></block></component1>', '<component1>text<block slot="right"></block></component1>',
`<component1 vue-id="1" bind:__l="__l" vue-slots="{{['default','right']}}">text<view slot="right"></view></component1>` `<component1 vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default','right']}}">text<view slot="right"></view></component1>`
) )
}) })
...@@ -221,21 +221,21 @@ describe('mp:compiler-extra', () => { ...@@ -221,21 +221,21 @@ describe('mp:compiler-extra', () => {
assertCodegen( assertCodegen(
'<component1><template slot="f">f</template><template slot="c">c</template>默认</component1>', '<component1><template slot="f">f</template><template slot="c">c</template>默认</component1>',
`<component1 vue-id="1" bind:__l="__l" vue-slots="{{['default','f','c']}}"><view slot="f">f</view><view slot="c">c</view>默认</component1>` `<component1 vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default','f','c']}}"><view slot="f">f</view><view slot="c">c</view>默认</component1>`
) )
assertCodegen( assertCodegen(
'<component1 v-slot>text</component1>', '<component1 v-slot>text</component1>',
`<component1 vue-id="1" bind:__l="__l" vue-slots="{{['default']}}"><view slot="default">text</view></component1>` `<component1 vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default']}}"><view slot="default">text</view></component1>`
) )
assertCodegen( assertCodegen(
'<component1 v-slot:default>text<text>123213</text></component1>', '<component1 v-slot:default>text<text>123213</text></component1>',
`<component1 vue-id="1" bind:__l="__l" vue-slots="{{['default']}}"><view slot="default">text<text>123213</text></view></component1>` `<component1 vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default']}}"><view slot="default">text<text>123213</text></view></component1>`
) )
assertCodegen( assertCodegen(
'<component1><template v-slot:left><text></text></template><template v-slot:right><text></text></template></component1>', '<component1><template v-slot:left><text></text></template><template v-slot:right><text></text></template></component1>',
`<component1 vue-id="1" bind:__l="__l" vue-slots="{{['left','right']}}"><view slot="left"><text></text></view><view slot="right"><text></text></view></component1>` `<component1 vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['left','right']}}"><view slot="left"><text></text></view><view slot="right"><text></text></view></component1>`
) )
assertCodegen( assertCodegen(
`<my-component> `<my-component>
...@@ -247,7 +247,7 @@ describe('mp:compiler-extra', () => { ...@@ -247,7 +247,7 @@ describe('mp:compiler-extra', () => {
<p>Here's some contact info</p> <p>Here's some contact info</p>
</template> </template>
</my-component>`, </my-component>`,
`<my-component vue-id="1" bind:__l="__l" vue-slots="{{['default','header','footer']}}"><view slot="header"><view class="_h1">Here might be a page title</view></view><view slot="footer"><view class="_p">Here's some contact info</view></view><view class="_p">A paragraph for the main content.</view></my-component>` `<my-component vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default','header','footer']}}"><view slot="header"><view class="_h1">Here might be a page title</view></view><view slot="footer"><view class="_p">Here's some contact info</view></view><view class="_p">A paragraph for the main content.</view></my-component>`
) )
}) })
...@@ -429,41 +429,41 @@ describe('mp:compiler-extra', () => { ...@@ -429,41 +429,41 @@ describe('mp:compiler-extra', () => {
it('generate events with v-on directive on custom component', () => { it('generate events with v-on directive on custom component', () => {
assertCodegen( assertCodegen(
'<my-component @click="handleClick"/>', '<my-component @click="handleClick"/>',
`<my-component bind:click="__e" vue-id="1" data-event-opts="{{[['^click',[['handleClick']]]]}}" bind:__l="__l"></my-component>` `<my-component bind:click="__e" vue-id="551070e6-1" data-event-opts="{{[['^click',[['handleClick']]]]}}" bind:__l="__l"></my-component>`
) )
assertCodegen( assertCodegen(
'<my-component @click-left="handleClick"/>', '<my-component @click-left="handleClick"/>',
`<my-component bind:clickLeft="__e" vue-id="1" data-event-opts="{{[['^clickLeft',[['handleClick']]]]}}" bind:__l="__l"></my-component>` `<my-component bind:clickLeft="__e" vue-id="551070e6-1" data-event-opts="{{[['^clickLeft',[['handleClick']]]]}}" bind:__l="__l"></my-component>`
) )
}) })
it('generate v-model directive on custom component', () => { it('generate v-model directive on custom component', () => {
assertCodegen( assertCodegen(
'<my-component v-model="test" @input="handle">1</my-component>', '<my-component v-model="test" @input="handle">1</my-component>',
`<my-component bind:input="__e" vue-id="1" value="{{test}}" data-event-opts="{{[['^input',[['__set_model',['','test','$event',[]]],['handle']]]]}}" bind:__l="__l" vue-slots="{{['default']}}">1</my-component>` `<my-component bind:input="__e" vue-id="551070e6-1" value="{{test}}" data-event-opts="{{[['^input',[['__set_model',['','test','$event',[]]],['handle']]]]}}" bind:__l="__l" vue-slots="{{['default']}}">1</my-component>`
) )
assertCodegen( assertCodegen(
'<my-component v-model="test" @click="handle">2</my-component>', '<my-component v-model="test" @click="handle">2</my-component>',
`<my-component bind:click="__e" bind:input="__e" vue-id="1" value="{{test}}" data-event-opts="{{[['^click',[['handle']]],['^input',[['__set_model',['','test','$event',[]]]]]]}}" bind:__l="__l" vue-slots="{{['default']}}">2</my-component>` `<my-component bind:click="__e" bind:input="__e" vue-id="551070e6-1" value="{{test}}" data-event-opts="{{[['^click',[['handle']]],['^input',[['__set_model',['','test','$event',[]]]]]]}}" bind:__l="__l" vue-slots="{{['default']}}">2</my-component>`
) )
assertCodegen( assertCodegen(
'<my-component v-model="test.a">3</my-component>', '<my-component v-model="test.a">3</my-component>',
`<my-component bind:input="__e" vue-id="1" value="{{test.a}}" data-event-opts="{{[['^input',[['__set_model',['$0','a','$event',[]],['test']]]]]}}" bind:__l="__l" vue-slots="{{['default']}}">3</my-component>` `<my-component bind:input="__e" vue-id="551070e6-1" value="{{test.a}}" data-event-opts="{{[['^input',[['__set_model',['$0','a','$event',[]],['test']]]]]}}" bind:__l="__l" vue-slots="{{['default']}}">3</my-component>`
) )
assertCodegen( assertCodegen(
'<my-component v-model="test.a.b">4</my-component>', '<my-component v-model="test.a.b">4</my-component>',
`<my-component bind:input="__e" vue-id="1" value="{{test.a.b}}" data-event-opts="{{[['^input',[['__set_model',['$0','b','$event',[]],['test.a']]]]]}}" bind:__l="__l" vue-slots="{{['default']}}">4</my-component>` `<my-component bind:input="__e" vue-id="551070e6-1" value="{{test.a.b}}" data-event-opts="{{[['^input',[['__set_model',['$0','b','$event',[]],['test.a']]]]]}}" bind:__l="__l" vue-slots="{{['default']}}">4</my-component>`
) )
assertCodegen( assertCodegen(
'<my-component v-model="test[a.b][a.b]">4</my-component>', '<my-component v-model="test[a.b][a.b]">4</my-component>',
`<my-component bind:input="__e" vue-id="1" value="{{test[a.b][a.b]}}" data-event-opts="{{[['^input',[['__set_model',['$0','$1','$event',[]],['test.'+a.b+'','a.b']]]]]}}" bind:__l="__l" vue-slots="{{['default']}}">4</my-component>` `<my-component bind:input="__e" vue-id="551070e6-1" value="{{test[a.b][a.b]}}" data-event-opts="{{[['^input',[['__set_model',['$0','$1','$event',[]],['test.'+a.b+'','a.b']]]]]}}" bind:__l="__l" vue-slots="{{['default']}}">4</my-component>`
) )
}) })
it('generate object property on custom component', () => { it('generate object property on custom component', () => {
assertCodegen( assertCodegen(
'<my-component v-model="test" @input="handle" />', '<my-component v-model="test" @input="handle" />',
`<my-component bind:input="__e" vue-id="1" value="{{test}}" data-event-opts="{{[['^input',[['__set_model',['','test','$event',[]]],['handle']]]]}}" bind:__l="__l"></my-component>` `<my-component bind:input="__e" vue-id="551070e6-1" value="{{test}}" data-event-opts="{{[['^input',[['__set_model',['','test','$event',[]]],['handle']]]]}}" bind:__l="__l"></my-component>`
) )
}) })
it('generate v-text directive', () => { it('generate v-text directive', () => {
...@@ -490,23 +490,23 @@ describe('mp:compiler-extra', () => { ...@@ -490,23 +490,23 @@ describe('mp:compiler-extra', () => {
it('generate v-bind directive with sync modifier', () => { it('generate v-bind directive with sync modifier', () => {
assertCodegen( assertCodegen(
'<text-document :title.sync="aaa"></text-document>', '<text-document :title.sync="aaa"></text-document>',
`<text-document vue-id="1" title="{{aaa}}" data-event-opts="{{[['^updateTitle',[['__set_sync',['$0','aaa','$event'],['']]]]]}}" bind:updateTitle="__e" bind:__l="__l"></text-document>` `<text-document vue-id="551070e6-1" title="{{aaa}}" data-event-opts="{{[['^updateTitle',[['__set_sync',['$0','aaa','$event'],['']]]]]}}" bind:updateTitle="__e" bind:__l="__l"></text-document>`
) )
assertCodegen( assertCodegen(
'<text-document :title.sync="doc.title"></text-document>', '<text-document :title.sync="doc.title"></text-document>',
`<text-document vue-id="1" title="{{doc.title}}" data-event-opts="{{[['^updateTitle',[['__set_sync',['$0','title','$event'],['doc']]]]]}}" bind:updateTitle="__e" bind:__l="__l"></text-document>` `<text-document vue-id="551070e6-1" title="{{doc.title}}" data-event-opts="{{[['^updateTitle',[['__set_sync',['$0','title','$event'],['doc']]]]]}}" bind:updateTitle="__e" bind:__l="__l"></text-document>`
) )
assertCodegen( assertCodegen(
'<text-document :title.sync="doc.a.title"></text-document>', '<text-document :title.sync="doc.a.title"></text-document>',
`<text-document vue-id="1" title="{{doc.a.title}}" data-event-opts="{{[['^updateTitle',[['__set_sync',['$0','title','$event'],['doc.a']]]]]}}" bind:updateTitle="__e" bind:__l="__l"></text-document>` `<text-document vue-id="551070e6-1" title="{{doc.a.title}}" data-event-opts="{{[['^updateTitle',[['__set_sync',['$0','title','$event'],['doc.a']]]]]}}" bind:updateTitle="__e" bind:__l="__l"></text-document>`
) )
assertCodegen( assertCodegen(
'<text-document v-for="item in items" :title.sync="item.title"></text-document>', '<text-document v-for="item in items" :title.sync="item.title"></text-document>',
`<block wx:for="{{items}}" wx:for-item="item" wx:for-index="__i0__"><text-document vue-id="{{'1-'+__i0__}}" title="{{item.title}}" data-event-opts="{{[['^updateTitle',[['__set_sync',['$0','title','$event'],[[['items','',__i0__,'']]]]]]]}}" bind:updateTitle="__e" bind:__l="__l"></text-document></block>` `<block wx:for="{{items}}" wx:for-item="item" wx:for-index="__i0__"><text-document vue-id="{{'551070e6-1-'+__i0__}}" title="{{item.title}}" data-event-opts="{{[['^updateTitle',[['__set_sync',['$0','title','$event'],[[['items','',__i0__,'']]]]]]]}}" bind:updateTitle="__e" bind:__l="__l"></text-document></block>`
) )
assertCodegen( assertCodegen(
'<text-document v-for="item in items" :title.sync="item.meta.title"></text-document>', '<text-document v-for="item in items" :title.sync="item.meta.title"></text-document>',
`<block wx:for="{{items}}" wx:for-item="item" wx:for-index="__i0__"><text-document vue-id="{{'1-'+__i0__}}" title="{{item.meta.title}}" data-event-opts="{{[['^updateTitle',[['__set_sync',['$0','title','$event'],[[['items','',__i0__,'meta']]]]]]]}}" bind:updateTitle="__e" bind:__l="__l"></text-document></block>` `<block wx:for="{{items}}" wx:for-item="item" wx:for-index="__i0__"><text-document vue-id="{{'551070e6-1-'+__i0__}}" title="{{item.meta.title}}" data-event-opts="{{[['^updateTitle',[['__set_sync',['$0','title','$event'],[[['items','',__i0__,'meta']]]]]]]}}" bind:updateTitle="__e" bind:__l="__l"></text-document></block>`
) )
}) })
......
...@@ -31,33 +31,33 @@ describe('mp:compiler-mp-alipay', () => { ...@@ -31,33 +31,33 @@ describe('mp:compiler-mp-alipay', () => {
it('generate ref', () => { it('generate ref', () => {
assertCodegen( assertCodegen(
'<component1 ref="c1">text</component1>', '<component1 ref="c1">text</component1>',
`<component1 vue-id="1" ref="__r" data-ref="c1" onVueInit="__l">text</component1>` `<component1 vue-id="551070e6-1" ref="__r" data-ref="c1" onVueInit="__l">text</component1>`
) )
assertCodegen( assertCodegen(
'<component1 :ref="c2">text<text>123213</text></component1>', '<component1 :ref="c2">text<text>123213</text></component1>',
`<component1 vue-id="1" ref="__r" data-ref="{{c2}}" onVueInit="__l">text<text>123213</text></component1>` `<component1 vue-id="551070e6-1" ref="__r" data-ref="{{c2}}" onVueInit="__l">text<text>123213</text></component1>`
) )
assertCodegen( assertCodegen(
'<component1 v-for="item in items" ref="c3"></component1>', '<component1 v-for="item in items" ref="c3"></component1>',
`<block a:for="{{items}}" a:for-item="item" a:for-index="__i0__"><component1 vue-id="{{'1-'+__i0__}}" ref="__r" data-ref-in-for="c3" onVueInit="__l"></component1></block>` `<block a:for="{{items}}" a:for-item="item" a:for-index="__i0__"><component1 vue-id="{{'551070e6-1-'+__i0__}}" ref="__r" data-ref-in-for="c3" onVueInit="__l"></component1></block>`
) )
assertCodegen( assertCodegen(
'<component1 v-for="item in items" :ref="c4"></component1>', '<component1 v-for="item in items" :ref="c4"></component1>',
`<block a:for="{{items}}" a:for-item="item" a:for-index="__i0__"><component1 vue-id="{{'1-'+__i0__}}" ref="__r" data-ref-in-for="{{c4}}" onVueInit="__l"></component1></block>` `<block a:for="{{items}}" a:for-item="item" a:for-index="__i0__"><component1 vue-id="{{'551070e6-1-'+__i0__}}" ref="__r" data-ref-in-for="{{c4}}" onVueInit="__l"></component1></block>`
) )
}) })
it('generate default slot', () => { it('generate default slot', () => {
assertCodegen( assertCodegen(
'<component1>text</component1>', '<component1>text</component1>',
`<component1 vue-id="1" onVueInit="__l">text</component1>` `<component1 vue-id="551070e6-1" onVueInit="__l">text</component1>`
) )
assertCodegen( assertCodegen(
'<component1>text<text>123213</text></component1>', '<component1>text<text>123213</text></component1>',
`<component1 vue-id="1" onVueInit="__l">text<text>123213</text></component1>` `<component1 vue-id="551070e6-1" onVueInit="__l">text<text>123213</text></component1>`
) )
assertCodegen( assertCodegen(
'<component1>text<block slot="right"></block></component1>', '<component1>text<block slot="right"></block></component1>',
`<component1 vue-id="1" onVueInit="__l">text<view slot="right"></view></component1>` `<component1 vue-id="551070e6-1" onVueInit="__l">text<view slot="right"></view></component1>`
) )
}) })
it('generate class binding', () => { it('generate class binding', () => {
...@@ -114,7 +114,7 @@ describe('mp:compiler-mp-alipay', () => { ...@@ -114,7 +114,7 @@ describe('mp:compiler-mp-alipay', () => {
it('generate events with v-on directive', () => { it('generate events with v-on directive', () => {
assertCodegen( assertCodegen(
`<uni-list-item title="标题文字" note="描述信息" show-extra-icon="true" :extra-icon="{color: '#4cd964',size: '22',type: 'spinner'}"></uni-list-item>`, `<uni-list-item title="标题文字" note="描述信息" show-extra-icon="true" :extra-icon="{color: '#4cd964',size: '22',type: 'spinner'}"></uni-list-item>`,
`<uni-list-item vue-id="1" title="标题文字" note="描述信息" show-extra-icon="true" extra-icon="{{$root.a0}}" onVueInit="__l"></uni-list-item>`, `<uni-list-item vue-id="551070e6-1" title="标题文字" note="描述信息" show-extra-icon="true" extra-icon="{{$root.a0}}" onVueInit="__l"></uni-list-item>`,
`with(this){var a0={color:"#4cd964",size:"22",type:"spinner"};$mp.data=Object.assign({},{$root:{a0:a0}})}` `with(this){var a0={color:"#4cd964",size:"22",type:"spinner"};$mp.data=Object.assign({},{$root:{a0:a0}})}`
) )
......
...@@ -24,33 +24,33 @@ describe('mp:compiler-mp-baidu', () => { ...@@ -24,33 +24,33 @@ describe('mp:compiler-mp-baidu', () => {
it('generate scoped slot', () => { it('generate scoped slot', () => {
assertCodegen( assertCodegen(
'<foo><template slot-scope="bar">{{ bar.foo }}</template></foo>', '<foo><template slot-scope="bar">{{ bar.foo }}</template></foo>',
`<foo vue-id="1" vue-slots="{{['default']}}"><view slot="default">{{foo}}</view></foo>` `<foo vue-id="551070e6-1" vue-slots="{{['default']}}"><view slot="default">{{foo}}</view></foo>`
) )
assertCodegen( assertCodegen(
'<foo><view slot-scope="bar">{{ bar.foo }}</view></foo>', '<foo><view slot-scope="bar">{{ bar.foo }}</view></foo>',
`<foo vue-id="1" vue-slots="{{['default']}}"><view slot="default"><view>{{foo}}</view></view></foo>` `<foo vue-id="551070e6-1" vue-slots="{{['default']}}"><view slot="default"><view>{{foo}}</view></view></foo>`
) )
}) })
it('generate named scoped slot', () => { it('generate named scoped slot', () => {
assertCodegen( assertCodegen(
'<foo><template slot="foo" slot-scope="bar">{{ bar.foo }}</template></foo>', '<foo><template slot="foo" slot-scope="bar">{{ bar.foo }}</template></foo>',
`<foo vue-id="1" vue-slots="{{['foo']}}"><view slot="foo">{{foo}}</view></foo>` `<foo vue-id="551070e6-1" vue-slots="{{['foo']}}"><view slot="foo">{{foo}}</view></foo>`
) )
assertCodegen( assertCodegen(
'<foo><view slot="foo" slot-scope="bar">{{ bar.foo }}</view></foo>', '<foo><view slot="foo" slot-scope="bar">{{ bar.foo }}</view></foo>',
`<foo vue-id="1" vue-slots="{{['foo']}}"><view slot="foo"><view>{{foo}}</view></view></foo>` `<foo vue-id="551070e6-1" vue-slots="{{['foo']}}"><view slot="foo"><view>{{foo}}</view></view></foo>`
) )
}) })
it('generate scoped slot with multiline v-if', () => { it('generate scoped slot with multiline v-if', () => {
assertCodegen( assertCodegen(
'<foo><template v-if="\nshow\n" slot-scope="bar">{{ bar.foo }}</template></foo>', '<foo><template v-if="\nshow\n" slot-scope="bar">{{ bar.foo }}</template></foo>',
`<foo vue-id="1" vue-slots="{{['default']}}"><view slot="default"><block s-if="{{show}}">{{foo}}</block><block s-else><block></block></block></view></foo>` `<foo vue-id="551070e6-1" vue-slots="{{['default']}}"><view slot="default"><block s-if="{{show}}">{{foo}}</block><block s-else><block></block></block></view></foo>`
) )
assertCodegen( assertCodegen(
'<foo><view v-if="\nshow\n" slot="foo" slot-scope="bar">{{ bar.foo }}</view></foo>', '<foo><view v-if="\nshow\n" slot="foo" slot-scope="bar">{{ bar.foo }}</view></foo>',
`<foo vue-id="1" vue-slots="{{['foo']}}"><view slot="foo"><block s-if="{{show}}"><view>{{foo}}</view></block></view></foo>` `<foo vue-id="551070e6-1" vue-slots="{{['foo']}}"><view slot="foo"><block s-if="{{show}}"><view>{{foo}}</view></block></view></foo>`
) )
}) })
...@@ -68,23 +68,23 @@ describe('mp:compiler-mp-baidu', () => { ...@@ -68,23 +68,23 @@ describe('mp:compiler-mp-baidu', () => {
it('generate vue id', () => { it('generate vue id', () => {
assertCodegen( assertCodegen(
'<Test/>', '<Test/>',
`<test vue-id="1"></test>` `<test vue-id="551070e6-1"></test>`
) )
assertCodegen( assertCodegen(
'<Test a="a">', '<Test a="a">',
`<test vue-id="1" a="a"></test>` `<test vue-id="551070e6-1" a="a"></test>`
) )
assertCodegen( assertCodegen(
'<view><Test v-for="item in items" :key="item"/></view>', '<view><Test v-for="item in items" :key="item"/></view>',
`<view><block s-for="{{items}}" s-for-item="item" s-for-index="__i0__" s-key="*this"><test vue-id="{{'1-'+__i0__}}"></test></block></view>` `<view><block s-for="{{items}}" s-for-item="item" s-for-index="__i0__" s-key="*this"><test vue-id="{{'551070e6-1-'+__i0__}}"></test></block></view>`
) )
assertCodegen( assertCodegen(
'<view><Test v-for="item in items" :key="item"><Test v-for="item in item.items" :key="item"></Test></Test></view>', '<view><Test v-for="item in items" :key="item"><Test v-for="item in item.items" :key="item"></Test></Test></view>',
`<view><block s-for="{{items}}" s-for-item="item" s-for-index="__i0__" s-key="*this"><test vue-id="{{'1-'+__i0__}}" vue-slots="{{['default']}}"><block s-for="{{item.items}}" s-for-item="item" s-for-index="__i1__" s-key="*this"><test vue-id="{{('2-'+__i0__+'-'+__i1__)+','+('1-'+__i0__)}}"></test></block></test></block></view>` `<view><block s-for="{{items}}" s-for-item="item" s-for-index="__i0__" s-key="*this"><test vue-id="{{'551070e6-1-'+__i0__}}" vue-slots="{{['default']}}"><block s-for="{{item.items}}" s-for-item="item" s-for-index="__i1__" s-key="*this"><test vue-id="{{('551070e6-2-'+__i0__+'-'+__i1__)+','+('551070e6-1-'+__i0__)}}"></test></block></test></block></view>`
) )
assertCodegen( assertCodegen(
'<view><Test v-for="(item,index) in items" :key="item"><Test v-for="(item,index1) in item.items" :key="item"></Test></Test></view>', '<view><Test v-for="(item,index) in items" :key="item"><Test v-for="(item,index1) in item.items" :key="item"></Test></Test></view>',
`<view><block s-for="{{items}}" s-for-item="item" s-for-index="index" s-key="*this"><test vue-id="{{'1-'+index}}" vue-slots="{{['default']}}"><block s-for="{{item.items}}" s-for-item="item" s-for-index="index1" s-key="*this"><test vue-id="{{('2-'+index+'-'+index1)+','+('1-'+index)}}"></test></block></test></block></view>` `<view><block s-for="{{items}}" s-for-item="item" s-for-index="index" s-key="*this"><test vue-id="{{'551070e6-1-'+index}}" vue-slots="{{['default']}}"><block s-for="{{item.items}}" s-for-item="item" s-for-index="index1" s-key="*this"><test vue-id="{{('551070e6-2-'+index+'-'+index1)+','+('551070e6-1-'+index)}}"></test></block></test></block></view>`
) )
}) })
......
...@@ -25,7 +25,7 @@ describe('mp:compiler-mp-toutiao', () => { ...@@ -25,7 +25,7 @@ describe('mp:compiler-mp-toutiao', () => {
it('generate ref', () => { it('generate ref', () => {
assertCodegen( assertCodegen(
'<my-component ref="ref"></my-component>', '<my-component ref="ref"></my-component>',
`<my-component class="vue-ref" vue-id="1" data-ref="ref" bind:__l="__l"></my-component>` `<my-component class="vue-ref" vue-id="551070e6-1" data-ref="ref" bind:__l="__l"></my-component>`
) )
}) })
......
...@@ -23,14 +23,14 @@ describe('mp:compiler-mp-weixin', () => { ...@@ -23,14 +23,14 @@ describe('mp:compiler-mp-weixin', () => {
it('generate scoped slot', () => { it('generate scoped slot', () => {
assertCodegen( assertCodegen(
'<foo><template slot-scope="{bar}">{{ bar.foo }}</template></foo>', '<foo><template slot-scope="{bar}">{{ bar.foo }}</template></foo>',
`<foo generic:scoped-slots-default="test-foo-default" vue-id="1" bind:__l="__l" vue-slots="{{['default']}}"></foo>`, `<foo generic:scoped-slots-default="test-foo-default" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default']}}"></foo>`,
function (res) { function (res) {
expect(res.generic[0]).toBe('test-foo-default') expect(res.generic[0]).toBe('test-foo-default')
} }
) )
assertCodegen( assertCodegen(
'<foo><view slot-scope="{bar}">{{ bar.foo }}</view></foo>', '<foo><view slot-scope="{bar}">{{ bar.foo }}</view></foo>',
`<foo generic:scoped-slots-default="test-foo-default" vue-id="1" bind:__l="__l" vue-slots="{{['default']}}"></foo>`, `<foo generic:scoped-slots-default="test-foo-default" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default']}}"></foo>`,
function (res) { function (res) {
expect(res.generic[0]).toBe('test-foo-default') expect(res.generic[0]).toBe('test-foo-default')
} }
...@@ -40,14 +40,14 @@ describe('mp:compiler-mp-weixin', () => { ...@@ -40,14 +40,14 @@ describe('mp:compiler-mp-weixin', () => {
it('generate named scoped slot', () => { it('generate named scoped slot', () => {
assertCodegen( assertCodegen(
'<foo><template slot="foo" slot-scope="{bar}">{{ bar.foo }}</template></foo>', '<foo><template slot="foo" slot-scope="{bar}">{{ bar.foo }}</template></foo>',
`<foo generic:scoped-slots-foo="test-foo-foo" vue-id="1" bind:__l="__l" vue-slots="{{['foo']}}"></foo>`, `<foo generic:scoped-slots-foo="test-foo-foo" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['foo']}}"></foo>`,
function (res) { function (res) {
expect(res.generic[0]).toBe('test-foo-foo') expect(res.generic[0]).toBe('test-foo-foo')
} }
) )
assertCodegen( assertCodegen(
'<foo><view slot="foo" slot-scope="{bar}">{{ bar.foo }}</view></foo>', '<foo><view slot="foo" slot-scope="{bar}">{{ bar.foo }}</view></foo>',
`<foo generic:scoped-slots-foo="test-foo-foo" vue-id="1" bind:__l="__l" vue-slots="{{['foo']}}"></foo>`, `<foo generic:scoped-slots-foo="test-foo-foo" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['foo']}}"></foo>`,
function (res) { function (res) {
expect(res.generic[0]).toBe('test-foo-foo') expect(res.generic[0]).toBe('test-foo-foo')
} }
...@@ -57,14 +57,14 @@ describe('mp:compiler-mp-weixin', () => { ...@@ -57,14 +57,14 @@ describe('mp:compiler-mp-weixin', () => {
it('generate scoped slot with multiline v-if', () => { it('generate scoped slot with multiline v-if', () => {
assertCodegen( assertCodegen(
'<foo><template v-if="\nshow\n" slot-scope="{bar}">{{ bar.foo }}</template></foo>', '<foo><template v-if="\nshow\n" slot-scope="{bar}">{{ bar.foo }}</template></foo>',
`<foo generic:scoped-slots-default="test-foo-default" vue-id="1" bind:__l="__l" vue-slots="{{['default']}}"></foo>`, `<foo generic:scoped-slots-default="test-foo-default" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['default']}}"></foo>`,
function (res) { function (res) {
expect(res.generic[0]).toBe('test-foo-default') expect(res.generic[0]).toBe('test-foo-default')
} }
) )
assertCodegen( assertCodegen(
'<foo><view v-if="\nshow\n" slot="foo" slot-scope="{bar}">{{ bar.foo }}</view></foo>', '<foo><view v-if="\nshow\n" slot="foo" slot-scope="{bar}">{{ bar.foo }}</view></foo>',
`<foo generic:scoped-slots-foo="test-foo-foo" vue-id="1" bind:__l="__l" vue-slots="{{['foo']}}"></foo>`, `<foo generic:scoped-slots-foo="test-foo-foo" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{['foo']}}"></foo>`,
function (res) { function (res) {
expect(res.generic[0]).toBe('test-foo-foo') expect(res.generic[0]).toBe('test-foo-foo')
} }
...@@ -90,7 +90,7 @@ describe('mp:compiler-mp-weixin', () => { ...@@ -90,7 +90,7 @@ describe('mp:compiler-mp-weixin', () => {
it('generate page-meta', () => { it('generate page-meta', () => {
assertCodegen(// TODO vue-id assertCodegen(// TODO vue-id
'<view><page-meta/><view><button></button></view></view>', '<view><page-meta/><view><button></button></view></view>',
`<page-meta vue-id="1" bind:__l="__l"></page-meta><view><button></button></view>` `<page-meta vue-id="551070e6-1" bind:__l="__l"></page-meta><view><button></button></view>`
) )
}) })
}) })
...@@ -159,7 +159,7 @@ describe('mp:compiler', () => { ...@@ -159,7 +159,7 @@ describe('mp:compiler', () => {
it('generate multiline v-model directive on custom component', () => { it('generate multiline v-model directive on custom component', () => {
assertCodegen( assertCodegen(
'<my-component v-model="\n test \n" />', '<my-component v-model="\n test \n" />',
`<my-component bind:input="__e" vue-id="1" value="{{test}}" data-event-opts="{{[['^input',[['__set_model',['','test','$event',[]]]]]]}}" bind:__l="__l"></my-component>` `<my-component bind:input="__e" vue-id="551070e6-1" value="{{test}}" data-event-opts="{{[['^input',[['__set_model',['','test','$event',[]]]]]]}}" bind:__l="__l"></my-component>`
) )
}) })
...@@ -558,7 +558,7 @@ describe('mp:compiler', () => { ...@@ -558,7 +558,7 @@ describe('mp:compiler', () => {
it('generate component', () => { it('generate component', () => {
assertCodegen( assertCodegen(
'<my-component name="mycomponent1" :msg="msg" @notify="onNotify"><div>hi</div></my-component>', '<my-component name="mycomponent1" :msg="msg" @notify="onNotify"><div>hi</div></my-component>',
`<my-component vue-id="1" name="mycomponent1" msg="{{msg}}" data-event-opts="{{[['^notify',[['onNotify']]]]}}" bind:notify="__e" bind:__l="__l" vue-slots="{{['default']}}"><view class="_div">hi</view></my-component>` `<my-component vue-id="551070e6-1" name="mycomponent1" msg="{{msg}}" data-event-opts="{{[['^notify',[['onNotify']]]]}}" bind:notify="__e" bind:__l="__l" vue-slots="{{['default']}}"><view class="_div">hi</view></my-component>`
// `with(this){if(!$mp.events){$mp.events=__get_event({"e0":{on:{"notify":onNotify},component:true}})}}` // `with(this){if(!$mp.events){$mp.events=__get_event({"e0":{on:{"notify":onNotify},component:true}})}}`
) )
}) })
...@@ -573,7 +573,7 @@ describe('mp:compiler', () => { ...@@ -573,7 +573,7 @@ describe('mp:compiler', () => {
it('generate is attribute', () => { it('generate is attribute', () => {
assertCodegen( assertCodegen(
'<div is="component1"></div>', '<div is="component1"></div>',
'<component1 vue-id="1" bind:__l="__l"></component1>' '<component1 vue-id="551070e6-1" bind:__l="__l"></component1>'
) )
// assertCodegen( // assertCodegen(
// '<div :is="component1"></div>', // '<div :is="component1"></div>',
...@@ -582,7 +582,7 @@ describe('mp:compiler', () => { ...@@ -582,7 +582,7 @@ describe('mp:compiler', () => {
// maybe a component and normalize type should be 1 // maybe a component and normalize type should be 1
assertCodegen( assertCodegen(
'<div><div is="component1"></div></div>', '<div><div is="component1"></div></div>',
'<view class="_div"><component1 vue-id="1" bind:__l="__l"></component1></view>' '<view class="_div"><component1 vue-id="551070e6-1" bind:__l="__l"></component1></view>'
) )
}) })
...@@ -619,7 +619,7 @@ describe('mp:compiler', () => { ...@@ -619,7 +619,7 @@ describe('mp:compiler', () => {
// 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>',
`<view class="_div"><child vue-id="1" bind:__l="__l"></child><block wx:for="{{list}}" wx:for-item="item" wx:for-index="__i0__">{{item}}</block></view>` `<view class="_div"><child vue-id="551070e6-1" bind:__l="__l"></child><block wx:for="{{list}}" wx:for-item="item" wx:for-index="__i0__">{{item}}</block></view>`
) )
}) })
...@@ -662,7 +662,7 @@ describe('mp:compiler', () => { ...@@ -662,7 +662,7 @@ describe('mp:compiler', () => {
it('should compile single v-for component inside template', () => { it('should compile single v-for component inside template', () => {
assertCodegen( assertCodegen(
`<div><template v-if="ok"><foo v-for="i in 1" :key="i"></foo></template></div>`, `<div><template v-if="ok"><foo v-for="i in 1" :key="i"></foo></template></div>`,
`<view class="_div"><block wx:if="{{ok}}"><block wx:for="{{1}}" wx:for-item="i" wx:for-index="__i0__" wx:key="*this"><foo vue-id="{{'1-'+__i0__}}" bind:__l="__l"></foo></block></block></view>` `<view class="_div"><block wx:if="{{ok}}"><block wx:for="{{1}}" wx:for-item="i" wx:for-index="__i0__" wx:key="*this"><foo vue-id="{{'551070e6-1-'+__i0__}}" bind:__l="__l"></foo></block></block></view>`
) )
}) })
}) })
...@@ -19,7 +19,12 @@ const scopedPath = path.resolve(__dirname, '../../') ...@@ -19,7 +19,12 @@ const scopedPath = path.resolve(__dirname, '../../')
const compiler = require('../lib') const compiler = require('../lib')
const res = compiler.compile( const res = compiler.compile(
` `
<view><block v-for="(item,index) in arr" v-bind:key="index"><block v-if="item==3">{{item}}</block></block></view> <view class="h-page">
<slot></slot>
<h-dialog></h-dialog>
<h-navbar></h-navbar>
<h-toast></h-toast>
</view>
`, { `, {
miniprogram: true, miniprogram: true,
resourcePath: '/User/fxy/Documents/test.wxml', resourcePath: '/User/fxy/Documents/test.wxml',
...@@ -32,9 +37,9 @@ const res = compiler.compile( ...@@ -32,9 +37,9 @@ const res = compiler.compile(
mp: { mp: {
platform: 'mp-weixin' platform: 'mp-weixin'
}, },
filterModules: ['swipe'], filterModules: ['swipe']
service: true, // service: true,
view: true // view: true
}) })
console.log(require('util').inspect(res, { console.log(require('util').inspect(res, {
......
const path = require('path') const path = require('path')
const hash = require('hash-sum')
const parser = require('@babel/parser') const parser = require('@babel/parser')
const { const {
...@@ -95,6 +95,11 @@ module.exports = { ...@@ -95,6 +95,11 @@ module.exports = {
options.mp.scopeId = options.scopeId options.mp.scopeId = options.scopeId
options.mp.resourcePath = options.resourcePath options.mp.resourcePath = options.resourcePath
if (options.resourcePath) {
options.mp.hashId = hash(options.resourcePath)
} else {
options.mp.hashId = ''
}
options.mp.globalUsingComponents = options.globalUsingComponents || Object.create(null) options.mp.globalUsingComponents = options.globalUsingComponents || Object.create(null)
......
...@@ -58,7 +58,8 @@ function addVueId (path, state) { ...@@ -58,7 +58,8 @@ function addVueId (path, state) {
if (!state.options.hasOwnProperty('$vueId')) { if (!state.options.hasOwnProperty('$vueId')) {
state.options.$vueId = 1 state.options.$vueId = 1
} }
const vueId = String(state.options.$vueId++) const hashId = state.options.hashId
const vueId = String((hashId ? (hashId + '-') : '') + (state.options.$vueId++))
let value let value
......
...@@ -74,7 +74,7 @@ const plugins = [ ...@@ -74,7 +74,7 @@ const plugins = [
'NODE_ENV': JSON.stringify(process.env.NODE_ENV), 'NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'VUE_APP_PLATFORM': JSON.stringify(process.env.UNI_PLATFORM), 'VUE_APP_PLATFORM': JSON.stringify(process.env.UNI_PLATFORM),
'UNI_CLOUD_PROVIDER': process.env.UNI_CLOUD_PROVIDER, 'UNI_CLOUD_PROVIDER': process.env.UNI_CLOUD_PROVIDER,
'HBX_USER_TOKEN': process.env.HBX_USER_TOKEN || '' 'HBX_USER_TOKEN': JSON.stringify(process.env.HBX_USER_TOKEN || '')
} }
}), }),
new webpack.BannerPlugin({ new webpack.BannerPlugin({
......
...@@ -96,7 +96,7 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) { ...@@ -96,7 +96,7 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) {
.use(require.resolve('webpack/lib/DefinePlugin'), [{ .use(require.resolve('webpack/lib/DefinePlugin'), [{
'process.env.UNI_ENV': JSON.stringify(process.env.UNI_PLATFORM), 'process.env.UNI_ENV': JSON.stringify(process.env.UNI_PLATFORM),
'process.env.UNI_CLOUD_PROVIDER': process.env.UNI_CLOUD_PROVIDER, 'process.env.UNI_CLOUD_PROVIDER': process.env.UNI_CLOUD_PROVIDER,
'process.env.HBX_USER_TOKEN': process.env.HBX_USER_TOKEN || '' 'process.env.HBX_USER_TOKEN': JSON.stringify(process.env.HBX_USER_TOKEN || '')
}]) }])
if (runByHBuilderX) { // 由 HBuilderX 运行时,移除进度,错误 if (runByHBuilderX) { // 由 HBuilderX 运行时,移除进度,错误
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册