提交 f63216a6 编写于 作者: fxy060608's avatar fxy060608

wip(mp): reduce bundle size

上级 f0cfbbc4
......@@ -29,14 +29,14 @@ describe('compiler: transform class', () => {
`<view :class="foo"/>`,
`<view class="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: _normalizeClass(_ctx.foo) }
return { a: _n(_ctx.foo) }
}`
)
assert(
`<view :class="foo | bar"/>`,
`<view class="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: _normalizeClass(_ctx.foo | _ctx.bar) }
return { a: _n(_ctx.foo | _ctx.bar) }
}`
)
})
......@@ -45,14 +45,14 @@ describe('compiler: transform class', () => {
`<view :class="foo" class="bar"/>`,
`<view class="{{[a, 'bar']}}"/>`,
`(_ctx, _cache) => {
return { a: _normalizeClass(_ctx.foo) }
return { a: _n(_ctx.foo) }
}`
)
assert(
`<view class="bar" :class="foo"/>`,
`<view class="{{['bar', a]}}"/>`,
`(_ctx, _cache) => {
return { a: _normalizeClass(_ctx.foo) }
return { a: _n(_ctx.foo) }
}`
)
})
......@@ -68,7 +68,7 @@ describe('compiler: transform class', () => {
`<view :class="{ a: 1, b: 0, c: true, d: false, e: null, f: undefined, g: ok, h: handle(ok), i: ok>1, j, [k]:1, [l]:m, ...n, ...{a:true}, ...{b:o} }"/>`,
`<view class="{{['a', 'c', a && 'g', b && 'h', c && 'i', d && 'j', e, g && f, h, i, j]}}"/>`,
`(_ctx, _cache) => {
return { a: _ctx.ok ? 1 : 0, b: _ctx.handle(_ctx.ok) ? 1 : 0, c: _ctx.ok > 1 ? 1 : 0, d: _ctx.j ? 1 : 0, e: _ctx.k, f: _ctx.l, g: _ctx.m ? 1 : 0, h: _normalizeClass(_ctx.n), i: _normalizeClass({ a: true }), j: _normalizeClass({ b: _ctx.o }) }
return { a: _ctx.ok ? 1 : 0, b: _ctx.handle(_ctx.ok) ? 1 : 0, c: _ctx.ok > 1 ? 1 : 0, d: _ctx.j ? 1 : 0, e: _ctx.k, f: _ctx.l, g: _ctx.m ? 1 : 0, h: _n(_ctx.n), i: _n({ a: true }), j: _n({ b: _ctx.o }) }
}`
)
})
......@@ -91,14 +91,14 @@ describe('compiler: transform class', () => {
`<view :class="{ a: 1, b: 0, c: true, d: false, e: null, f: undefined, g: ok, h: handle(ok), i: ok>1, j, [k]:1, [l]:m, ...n, ...{a:true}, ...{b:o} }" class="foo bar"/>`,
`<view class="{{['a', 'c', a && 'g', b && 'h', c && 'i', d && 'j', e, g && f, h, i, j, 'foo bar']}}"/>`,
`(_ctx, _cache) => {
return { a: _ctx.ok ? 1 : 0, b: _ctx.handle(_ctx.ok) ? 1 : 0, c: _ctx.ok > 1 ? 1 : 0, d: _ctx.j ? 1 : 0, e: _ctx.k, f: _ctx.l, g: _ctx.m ? 1 : 0, h: _normalizeClass(_ctx.n), i: _normalizeClass({ a: true }), j: _normalizeClass({ b: _ctx.o }) }
return { a: _ctx.ok ? 1 : 0, b: _ctx.handle(_ctx.ok) ? 1 : 0, c: _ctx.ok > 1 ? 1 : 0, d: _ctx.j ? 1 : 0, e: _ctx.k, f: _ctx.l, g: _ctx.m ? 1 : 0, h: _n(_ctx.n), i: _n({ a: true }), j: _n({ b: _ctx.o }) }
}`
)
assert(
`<view class="foo bar" :class="{ a: 1, b: 0, c: true, d: false, e: null, f: undefined, g: ok, h: handle(ok), i: ok>1, j, [k]:1, [l]:m, ...n, ...{a:true}, ...{b:o} }"/>`,
`<view class="{{['foo bar', 'a', 'c', a && 'g', b && 'h', c && 'i', d && 'j', e, g && f, h, i, j]}}"/>`,
`(_ctx, _cache) => {
return { a: _ctx.ok ? 1 : 0, b: _ctx.handle(_ctx.ok) ? 1 : 0, c: _ctx.ok > 1 ? 1 : 0, d: _ctx.j ? 1 : 0, e: _ctx.k, f: _ctx.l, g: _ctx.m ? 1 : 0, h: _normalizeClass(_ctx.n), i: _normalizeClass({ a: true }), j: _normalizeClass({ b: _ctx.o }) }
return { a: _ctx.ok ? 1 : 0, b: _ctx.handle(_ctx.ok) ? 1 : 0, c: _ctx.ok > 1 ? 1 : 0, d: _ctx.j ? 1 : 0, e: _ctx.k, f: _ctx.l, g: _ctx.m ? 1 : 0, h: _n(_ctx.n), i: _n({ a: true }), j: _n({ b: _ctx.o }) }
}`
)
})
......@@ -107,21 +107,21 @@ describe('compiler: transform class', () => {
`<view :class="[classA, \`\${classB}\`]"/>`,
`<view class="{{[a, b]}}"/>`,
`(_ctx, _cache) => {
return { a: _normalizeClass(_ctx.classA), b: _normalizeClass(\`\${_ctx.classB}\`) }
return { a: _n(_ctx.classA), b: _n(\`\${_ctx.classB}\`) }
}`
)
assert(
`<view :class="[classA, classB]"/>`,
`<view class="{{[a, b]}}"/>`,
`(_ctx, _cache) => {
return { a: _normalizeClass(_ctx.classA), b: _normalizeClass(_ctx.classB) }
return { a: _n(_ctx.classA), b: _n(_ctx.classB) }
}`
)
assert(
`<view :class="[classA, classB, { classC: isC, classD: isD }, 'classE', isF ? 'classF' : '', isG && 'classG', ...classH, ...[classI,classJ], handle(classK) ]"/>`,
`<view class="{{[a, b, c, 'classE', d, e, f, g, h]}}"/>`,
`(_ctx, _cache) => {
return { a: _normalizeClass(_ctx.classA), b: _normalizeClass(_ctx.classB), c: _normalizeClass({ classC: _ctx.isC, classD: _ctx.isD }), d: _normalizeClass(_ctx.isF ? 'classF' : ''), e: _normalizeClass(_ctx.isG && 'classG'), f: _normalizeClass(_ctx.classH), g: _normalizeClass([_ctx.classI, _ctx.classJ]), h: _normalizeClass(_ctx.handle(_ctx.classK)) }
return { a: _n(_ctx.classA), b: _n(_ctx.classB), c: _n({ classC: _ctx.isC, classD: _ctx.isD }), d: _n(_ctx.isF ? 'classF' : ''), e: _n(_ctx.isG && 'classG'), f: _n(_ctx.classH), g: _n([_ctx.classI, _ctx.classJ]), h: _n(_ctx.handle(_ctx.classK)) }
}`
)
})
......@@ -130,28 +130,28 @@ describe('compiler: transform class', () => {
`<view :class="[classA, classB]" class="foo bar"/>`,
`<view class="{{[a, b, 'foo bar']}}"/>`,
`(_ctx, _cache) => {
return { a: _normalizeClass(_ctx.classA), b: _normalizeClass(_ctx.classB) }
return { a: _n(_ctx.classA), b: _n(_ctx.classB) }
}`
)
assert(
`<view class="foo bar" :class="[classA, classB]"/>`,
`<view class="{{['foo bar', a, b]}}"/>`,
`(_ctx, _cache) => {
return { a: _normalizeClass(_ctx.classA), b: _normalizeClass(_ctx.classB) }
return { a: _n(_ctx.classA), b: _n(_ctx.classB) }
}`
)
assert(
`<view :class="[classA, classB, { classC: isC, classD: isD }, 'classE', isF ? 'classF' : '', isG && 'classG', ...classH, ...[classI,classJ], handle(classK) ]" class="foo bar"/>`,
`<view class="{{[a, b, c, 'classE', d, e, f, g, h, 'foo bar']}}"/>`,
`(_ctx, _cache) => {
return { a: _normalizeClass(_ctx.classA), b: _normalizeClass(_ctx.classB), c: _normalizeClass({ classC: _ctx.isC, classD: _ctx.isD }), d: _normalizeClass(_ctx.isF ? 'classF' : ''), e: _normalizeClass(_ctx.isG && 'classG'), f: _normalizeClass(_ctx.classH), g: _normalizeClass([_ctx.classI, _ctx.classJ]), h: _normalizeClass(_ctx.handle(_ctx.classK)) }
return { a: _n(_ctx.classA), b: _n(_ctx.classB), c: _n({ classC: _ctx.isC, classD: _ctx.isD }), d: _n(_ctx.isF ? 'classF' : ''), e: _n(_ctx.isG && 'classG'), f: _n(_ctx.classH), g: _n([_ctx.classI, _ctx.classJ]), h: _n(_ctx.handle(_ctx.classK)) }
}`
)
assert(
`<view class="foo bar" :class="[classA, classB, { classC: isC, classD: isD }, 'classE', isF ? 'classF' : '', isG && 'classG', ...classH, ...[classI,classJ], handle(classK) ]"/>`,
`<view class="{{['foo bar', a, b, c, 'classE', d, e, f, g, h]}}"/>`,
`(_ctx, _cache) => {
return { a: _normalizeClass(_ctx.classA), b: _normalizeClass(_ctx.classB), c: _normalizeClass({ classC: _ctx.isC, classD: _ctx.isD }), d: _normalizeClass(_ctx.isF ? 'classF' : ''), e: _normalizeClass(_ctx.isG && 'classG'), f: _normalizeClass(_ctx.classH), g: _normalizeClass([_ctx.classI, _ctx.classJ]), h: _normalizeClass(_ctx.handle(_ctx.classK)) }
return { a: _n(_ctx.classA), b: _n(_ctx.classB), c: _n({ classC: _ctx.isC, classD: _ctx.isD }), d: _n(_ctx.isF ? 'classF' : ''), e: _n(_ctx.isG && 'classG'), f: _n(_ctx.classH), g: _n([_ctx.classI, _ctx.classJ]), h: _n(_ctx.handle(_ctx.classK)) }
}`
)
})
......
......@@ -5,10 +5,10 @@ describe('compiler: codegen', () => {
assert(
`<view v-for="item in items" @click="onClick"></view>`,
`<view wx:for="{{a}}" wx:for-item="item" bindtap="{{b}}"></view>`,
`import { vOn as _vOn, vFor as _vFor } from "vue"
`import { o as _o, f as _f } from "vue"
export function render(_ctx, _cache) {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }), b: _vOn(_ctx.onClick) }
return { a: _f(_ctx.items, (item, k0, i0) => { return {}; }), b: _o(_ctx.onClick) }
}`,
{ inline: false, mode: 'module', prefixIdentifiers: false }
)
......@@ -18,10 +18,10 @@ export function render(_ctx, _cache) {
assert(
`<view v-for="item in items" @click="onClick"></view>`,
`<view wx:for="{{a}}" wx:for-item="item" bindtap="{{b}}"></view>`,
`import { vOn as _vOn, vFor as _vFor } from "vue"
`import { o as _o, f as _f } from "vue"
export function render(_ctx, _cache) {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }), b: _vOn(_ctx.onClick) }
return { a: _f(_ctx.items, (item, k0, i0) => { return {}; }), b: _o(_ctx.onClick) }
}`,
{ inline: false, mode: 'module' }
)
......@@ -35,9 +35,9 @@ export function render(_ctx, _cache) {
return function render(_ctx, _cache) {
with (_ctx) {
const { vOn: _vOn, vFor: _vFor } = _Vue
const { o: _o, f: _f } = _Vue
return { a: _vFor(items, (item, k0, i0) => { return {}; }), b: _vOn(onClick) }
return { a: _f(items, (item, k0, i0) => { return {}; }), b: _o(onClick) }
}
}`,
{ inline: false, mode: 'function', prefixIdentifiers: false }
......@@ -47,10 +47,10 @@ return function render(_ctx, _cache) {
assert(
`<view v-for="item in items" @click="onClick"></view>`,
`<view wx:for="{{a}}" wx:for-item="item" bindtap="{{b}}"></view>`,
`const { vOn: _vOn, vFor: _vFor } = Vue
`const { o: _o, f: _f } = Vue
return function render(_ctx, _cache) {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }), b: _vOn(_ctx.onClick) }
return { a: _f(_ctx.items, (item, k0, i0) => { return {}; }), b: _o(_ctx.onClick) }
}`,
{ inline: false, mode: 'function' }
)
......@@ -69,7 +69,7 @@ return function render(_ctx, _cache) {
`{{hello}}`,
`{{a}}`,
`(_ctx, _cache) => {
return { a: _toDisplayString(_ctx.hello) }
return { a: _t(_ctx.hello) }
}`
)
})
......@@ -87,7 +87,7 @@ return function render(_ctx, _cache) {
`{{foo}}{{bar}}nested`,
`{{a}}{{b}}nested`,
`(_ctx, _cache) => {
return { a: _toDisplayString(_ctx.foo), b: _toDisplayString(_ctx.bar) }
return { a: _t(_ctx.foo), b: _t(_ctx.bar) }
}`
)
})
......
......@@ -43,7 +43,7 @@ describe('compiler: transform component', () => {
`<custom v-for="item in items"/>`,
`<custom wx:for="{{a}}" wx:for-item="item" class="v-r-i-f" v-i="{{item.a}}" bind:__l="__l"/>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0 }; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0 }; }) }
}`,
{
nodeTransforms: [addComponentBindLink as any],
......@@ -53,7 +53,7 @@ describe('compiler: transform component', () => {
`<custom v-for="(item,key,index) in items"/>`,
`<custom wx:for="{{a}}" wx:for-item="item" class="v-r-i-f" v-i="{{item.a}}" bind:__l="__l"/>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, key, index) => { return { a: '2a9ec0b0-0' + '-' + index }; }) }
return { a: _f(_ctx.items, (item, key, index) => { return { a: '2a9ec0b0-0' + '-' + index }; }) }
}`,
{
nodeTransforms: [addComponentBindLink as any],
......@@ -65,7 +65,7 @@ describe('compiler: transform component', () => {
`<custom><custom1 v-for="item in items"/></custom>`,
`<custom vue-slots="{{['default']}}" class="v-r" v-i="2a9ec0b0-0" bind:__l="__l"><custom1 wx:for="{{a}}" wx:for-item="item" class="v-r-i-f" v-i="{{item.a}}" bind:__l="__l"/></custom>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0' }; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0' }; }) }
}`,
{
nodeTransforms: [addComponentBindLink as any],
......@@ -77,7 +77,7 @@ describe('compiler: transform component', () => {
`<custom v-for="item in items"><custom1/></custom>`,
`<custom wx:for="{{a}}" wx:for-item="item" vue-slots="{{['default']}}" class="v-r-i-f" v-i="{{item.b}}" bind:__l="__l"><custom1 class="v-r-i-f" v-i="{{item.a}}" bind:__l="__l"/></custom>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-1' + '-' + i0 + ',' + ('2a9ec0b0-0' + '-' + i0), b: '2a9ec0b0-0' + '-' + i0 }; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-1' + '-' + i0 + ',' + ('2a9ec0b0-0' + '-' + i0), b: '2a9ec0b0-0' + '-' + i0 }; }) }
}`,
{
nodeTransforms: [addComponentBindLink as any],
......@@ -89,7 +89,7 @@ describe('compiler: transform component', () => {
`<custom v-for="item in items"><custom1 v-for="item1 in item.items"/></custom>`,
`<custom wx:for="{{a}}" wx:for-item="item" vue-slots="{{['default']}}" class="v-r-i-f" v-i="{{item.b}}" bind:__l="__l"><custom1 wx:for="{{item.a}}" wx:for-item="item1" class="v-r-i-f" v-i="{{item1.a}}" bind:__l="__l"/></custom>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: _vFor(item.items, (item1, k1, i1) => { return { a: '2a9ec0b0-1' + '-' + i0 + '-' + i1 + ',' + ('2a9ec0b0-0' + '-' + i0) }; }), b: '2a9ec0b0-0' + '-' + i0 }; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _f(item.items, (item1, k1, i1) => { return { a: '2a9ec0b0-1' + '-' + i0 + '-' + i1 + ',' + ('2a9ec0b0-0' + '-' + i0) }; }), b: '2a9ec0b0-0' + '-' + i0 }; }) }
}`,
{
nodeTransforms: [addComponentBindLink as any],
......
......@@ -22,7 +22,7 @@ describe('compiler: transform ref', () => {
`<custom v-for="item in items"/>`,
`<custom wx:for="{{a}}" wx:for-item="item" class="v-r-i-f" v-i="{{item.a}}"/>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0 }; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0 }; }) }
}`
)
})
......
......@@ -6,7 +6,7 @@ describe('compiler: scope', () => {
`<view v-for="item in items" :key="item.id" :class="{red: item.isRed}" @longpress="longpress" @click="onClick(item)">{{item.title}}</view>`,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="b" class="{{[item.c && 'red']}}" bindlongpress="{{b}}" bindtap="{{item.d}}">{{item.a}}</view>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: _toDisplayString(item.title), b: item.id, c: item.isRed ? 1 : 0, d: _vOn($event => _ctx.onClick(item)) }; }), b: _vOn(_ctx.longpress) }
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _t(item.title), b: item.id, c: item.isRed ? 1 : 0, d: _o($event => _ctx.onClick(item)) }; }), b: _o(_ctx.longpress) }
}`
)
})
......@@ -15,21 +15,21 @@ describe('compiler: scope', () => {
`<view v-for="item in items" :key="item.id">{{item.title}}{{handle(foo)}}<view v-for="item1 in item.list" :key="item1.id" @click="onClick(item)" @longpress="longpress(item1)">{{item.id}}{{item1.title}}</view></view>`,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="e">{{item.a}}{{b}}<view wx:for="{{item.b}}" wx:for-item="item1" wx:key="b" bindtap="{{item.d}}" bindlongpress="{{item1.c}}">{{item.c}}{{item1.a}}</view></view>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: _toDisplayString(item.title), b: _vFor(item.list, (item1, k1, i1) => { return { a: _toDisplayString(item1.title), b: item1.id, c: _vOn($event => _ctx.longpress(item1)) }; }), c: _toDisplayString(item.id), d: _vOn($event => _ctx.onClick(item)), e: item.id }; }), b: _toDisplayString(_ctx.handle(_ctx.foo)) }
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _t(item.title), b: _f(item.list, (item1, k1, i1) => { return { a: _t(item1.title), b: item1.id, c: _o($event => _ctx.longpress(item1)) }; }), c: _t(item.id), d: _o($event => _ctx.onClick(item)), e: item.id }; }), b: _t(_ctx.handle(_ctx.foo)) }
}`
)
assert(
`<view v-for="item in items"><view v-for="item1 in item1" :data-id="item.id" :data-title="item1.title"/></view>`,
`<view wx:for="{{a}}" wx:for-item="item"><view wx:for="{{b}}" wx:for-item="item1" data-id="{{item.a}}" data-title="{{item1.a}}"/></view>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: item.id }; }), b: _vFor(_ctx.item1, (item1, k1, i1) => { return { a: item1.title }; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: item.id }; }), b: _f(_ctx.item1, (item1, k1, i1) => { return { a: item1.title }; }) }
}`
)
assert(
`<view v-for="(item,weekIndex) in weeks" :key="weekIndex" :data-id="item.id"><view v-for="(weeks,weeksIndex) in item" :key="weeksIndex" :data-id="weeks.id"/></view>`,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="b" data-id="{{item.c}}"><view wx:for="{{item.a}}" wx:for-item="weeks" wx:key="a" data-id="{{weeks.b}}"/></view>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.weeks, (item, weekIndex, i0) => { return { a: _vFor(item, (weeks, weeksIndex, i1) => { return { a: weeksIndex, b: weeks.id }; }), b: weekIndex, c: item.id }; }) }
return { a: _f(_ctx.weeks, (item, weekIndex, i0) => { return { a: _f(item, (weeks, weeksIndex, i1) => { return { a: weeksIndex, b: weeks.id }; }), b: weekIndex, c: item.id }; }) }
}`
)
})
......@@ -38,7 +38,7 @@ describe('compiler: scope', () => {
`<view v-for="item in items"><view v-if="true" :data-id="id"></view></view>`,
`<view wx:for="{{a}}" wx:for-item="item"><view wx:if="{{true}}" data-id="{{item.a}}"></view></view>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return true ? { a: _ctx.id } : {}; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return true ? { a: _ctx.id } : {}; }) }
}`
)
})
......@@ -47,7 +47,7 @@ describe('compiler: scope', () => {
`<view v-if="ok">{{ok}}</view><view v-else-if="ok1">{{ok1}}</view><view v-else-if="ok2">{{ok2}}</view><view v-else>{{ok3}}</view>`,
`<view wx:if="{{a}}">{{b}}</view><view wx:elif="{{c}}">{{d}}</view><view wx:elif="{{e}}">{{f}}</view><view wx:else>{{g}}</view>`,
`(_ctx, _cache) => {
return _extend({ a: _ctx.ok }, _ctx.ok ? { b: _toDisplayString(_ctx.ok) } : _ctx.ok1 ? { d: _toDisplayString(_ctx.ok1) } : _ctx.ok2 ? { f: _toDisplayString(_ctx.ok2) } : { g: _toDisplayString(_ctx.ok3) }, { c: _ctx.ok1, e: _ctx.ok2 })
return _e({ a: _ctx.ok }, _ctx.ok ? { b: _t(_ctx.ok) } : _ctx.ok1 ? { d: _t(_ctx.ok1) } : _ctx.ok2 ? { f: _t(_ctx.ok2) } : { g: _t(_ctx.ok3) }, { c: _ctx.ok1, e: _ctx.ok2 })
}`
)
})
......@@ -56,7 +56,7 @@ describe('compiler: scope', () => {
`<view v-if="ok"><view v-for="item in items" :key="item.id" :data-title="item.title" :data-foo="foo" @click="onClick"/></view><view v-else-if="ok1"><view v-for="item in items" :key="item.id" :data-title="item.title" :data-foo="foo" @click="onClick"/></view><view v-else><view v-for="item in items" :key="item.id" :data-title="item.title" :data-foo="foo" @click="onClick"/></view>`,
`<view wx:if="{{a}}"><view wx:for="{{b}}" wx:for-item="item" wx:key="a" data-title="{{item.b}}" data-foo="{{c}}" bindtap="{{d}}"/></view><view wx:elif="{{e}}"><view wx:for="{{f}}" wx:for-item="item" wx:key="a" data-title="{{item.b}}" data-foo="{{g}}" bindtap="{{h}}"/></view><view wx:else><view wx:for="{{i}}" wx:for-item="item" wx:key="a" data-title="{{item.b}}" data-foo="{{j}}" bindtap="{{k}}"/></view>`,
`(_ctx, _cache) => {
return _extend({ a: _ctx.ok }, _ctx.ok ? { b: _vFor(_ctx.items, (item, k0, i0) => { return { a: item.id, b: item.title }; }), c: _ctx.foo, d: _vOn(_ctx.onClick) } : _ctx.ok1 ? { f: _vFor(_ctx.items, (item, k0, i0) => { return { a: item.id, b: item.title }; }), g: _ctx.foo, h: _vOn(_ctx.onClick) } : { i: _vFor(_ctx.items, (item, k0, i0) => { return { a: item.id, b: item.title }; }), j: _ctx.foo, k: _vOn(_ctx.onClick) }, { e: _ctx.ok1 })
return _e({ a: _ctx.ok }, _ctx.ok ? { b: _f(_ctx.items, (item, k0, i0) => { return { a: item.id, b: item.title }; }), c: _ctx.foo, d: _o(_ctx.onClick) } : _ctx.ok1 ? { f: _f(_ctx.items, (item, k0, i0) => { return { a: item.id, b: item.title }; }), g: _ctx.foo, h: _o(_ctx.onClick) } : { i: _f(_ctx.items, (item, k0, i0) => { return { a: item.id, b: item.title }; }), j: _ctx.foo, k: _o(_ctx.onClick) }, { e: _ctx.ok1 })
}`
)
})
......
......@@ -17,7 +17,7 @@ describe('compiler: transform scopeId', () => {
`<view :class="foo"/>`,
`<view class="{{['data-v-5584ec96', a]}}"/>`,
`(_ctx, _cache) => {
return { a: _normalizeClass(_ctx.foo) }
return { a: _n(_ctx.foo) }
}`,
options
)
......@@ -35,7 +35,7 @@ describe('compiler: transform scopeId', () => {
`<view class="bar" :class="foo"/>`,
`<view class="{{['bar data-v-5584ec96', a]}}"/>`,
`(_ctx, _cache) => {
return { a: _normalizeClass(_ctx.foo) }
return { a: _n(_ctx.foo) }
}`,
options
)
......@@ -43,7 +43,7 @@ describe('compiler: transform scopeId', () => {
`<view :class="foo" class="bar"/>`,
`<view class="{{[a, 'bar data-v-5584ec96']}}"/>`,
`(_ctx, _cache) => {
return { a: _normalizeClass(_ctx.foo) }
return { a: _n(_ctx.foo) }
}`,
options
)
......
......@@ -22,14 +22,14 @@ describe('compiler: transform style', () => {
`<view :style="foo"/>`,
`<view style="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: _stringifyStyle(_ctx.foo) }
return { a: _s(_ctx.foo) }
}`
)
assert(
`<view :style="foo | bar"/>`,
`<view style="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: _stringifyStyle(_ctx.foo | _ctx.bar) }
return { a: _s(_ctx.foo | _ctx.bar) }
}`
)
})
......@@ -38,14 +38,14 @@ describe('compiler: transform style', () => {
`<view :style="foo" style="color:green;"/>`,
`<view style="{{a + ';' + 'color:green;'}}"/>`,
`(_ctx, _cache) => {
return { a: _stringifyStyle(_ctx.foo) }
return { a: _s(_ctx.foo) }
}`
)
assert(
`<view style="color:green;" :style="foo"/>`,
`<view style="{{'color:green;' + ';' + a}}"/>`,
`(_ctx, _cache) => {
return { a: _stringifyStyle(_ctx.foo) }
return { a: _s(_ctx.foo) }
}`
)
})
......@@ -70,7 +70,7 @@ describe('compiler: transform style', () => {
`<view :style="{color:'green',fontSize:'15px',backgroundColor: handle(bg),fontWeight,[padding]:box.padding,...style,...{margin:'0px'}}"/>`,
`<view style="{{'color:' + 'green' + ';' + ('font-size:' + '15px') + ';' + ('background-color:' + a) + ';' + ('font-weight:' + b) + ';' + (c + ':' + d) + ';' + e + ';' + f}}"/>`,
`(_ctx, _cache) => {
return { a: _ctx.handle(_ctx.bg), b: _ctx.fontWeight, c: _hyphenate(_ctx.padding), d: _ctx.box.padding, e: _stringifyStyle(_ctx.style), f: _stringifyStyle({ margin: '0px' }) }
return { a: _ctx.handle(_ctx.bg), b: _ctx.fontWeight, c: _h(_ctx.padding), d: _ctx.box.padding, e: _s(_ctx.style), f: _s({ margin: '0px' }) }
}`
)
})
......@@ -93,14 +93,14 @@ describe('compiler: transform style', () => {
`<view :style="{color:'green',fontSize:'15px',backgroundColor: handle(bg),fontWeight,[padding]:box.padding,...style,...{margin:'0px'}}" style="font-size:15px"/>`,
`<view style="{{'color:' + 'green' + ';' + ('font-size:' + '15px') + ';' + ('background-color:' + a) + ';' + ('font-weight:' + b) + ';' + (c + ':' + d) + ';' + e + ';' + f + ';' + 'font-size:15px'}}"/>`,
`(_ctx, _cache) => {
return { a: _ctx.handle(_ctx.bg), b: _ctx.fontWeight, c: _hyphenate(_ctx.padding), d: _ctx.box.padding, e: _stringifyStyle(_ctx.style), f: _stringifyStyle({ margin: '0px' }) }
return { a: _ctx.handle(_ctx.bg), b: _ctx.fontWeight, c: _h(_ctx.padding), d: _ctx.box.padding, e: _s(_ctx.style), f: _s({ margin: '0px' }) }
}`
)
assert(
`<view style="font-size:15px" :style="{color:'green',fontSize:'15px',backgroundColor: handle(bg),fontWeight,[padding]:box.padding,...style,...{margin:'0px'}}"/>`,
`<view style="{{'font-size:15px' + ';' + ('color:' + 'green' + ';' + ('font-size:' + '15px') + ';' + ('background-color:' + a) + ';' + ('font-weight:' + b) + ';' + (c + ':' + d) + ';' + e + ';' + f)}}"/>`,
`(_ctx, _cache) => {
return { a: _ctx.handle(_ctx.bg), b: _ctx.fontWeight, c: _hyphenate(_ctx.padding), d: _ctx.box.padding, e: _stringifyStyle(_ctx.style), f: _stringifyStyle({ margin: '0px' }) }
return { a: _ctx.handle(_ctx.bg), b: _ctx.fontWeight, c: _h(_ctx.padding), d: _ctx.box.padding, e: _s(_ctx.style), f: _s({ margin: '0px' }) }
}`
)
})
......@@ -109,21 +109,21 @@ describe('compiler: transform style', () => {
`<view :style="[styleA, \`\${styleB}\`]"/>`,
`<view style="{{a + ';' + b}}"/>`,
`(_ctx, _cache) => {
return { a: _stringifyStyle(_ctx.styleA), b: _stringifyStyle(\`\${_ctx.styleB}\`) }
return { a: _s(_ctx.styleA), b: _s(\`\${_ctx.styleB}\`) }
}`
)
assert(
`<view :style="[styleA, styleB]"/>`,
`<view style="{{a + ';' + b}}"/>`,
`(_ctx, _cache) => {
return { a: _stringifyStyle(_ctx.styleA), b: _stringifyStyle(_ctx.styleB) }
return { a: _s(_ctx.styleA), b: _s(_ctx.styleB) }
}`
)
assert(
`<view :style="[styleA, styleB, { color:'red',fontSize }, 'font-weight:bold', ...styleC, ...[styleD,styleE], handle(styleF) ]"/>`,
`<view style="{{a + ';' + b + ';' + c + ';' + 'font-weight:bold' + ';' + d + ';' + e + ';' + f}}"/>`,
`(_ctx, _cache) => {
return { a: _stringifyStyle(_ctx.styleA), b: _stringifyStyle(_ctx.styleB), c: _stringifyStyle({ color: 'red', fontSize: _ctx.fontSize }), d: _stringifyStyle(_ctx.styleC), e: _stringifyStyle([_ctx.styleD, _ctx.styleE]), f: _stringifyStyle(_ctx.handle(_ctx.styleF)) }
return { a: _s(_ctx.styleA), b: _s(_ctx.styleB), c: _s({ color: 'red', fontSize: _ctx.fontSize }), d: _s(_ctx.styleC), e: _s([_ctx.styleD, _ctx.styleE]), f: _s(_ctx.handle(_ctx.styleF)) }
}`
)
})
......@@ -132,28 +132,28 @@ describe('compiler: transform style', () => {
`<view :style="[styleA, styleB]" style="font-size:15px"/>`,
`<view style="{{a + ';' + b + ';' + 'font-size:15px'}}"/>`,
`(_ctx, _cache) => {
return { a: _stringifyStyle(_ctx.styleA), b: _stringifyStyle(_ctx.styleB) }
return { a: _s(_ctx.styleA), b: _s(_ctx.styleB) }
}`
)
assert(
`<view style="font-size:15px" :style="[styleA, styleB]"/>`,
`<view style="{{'font-size:15px' + ';' + (a + ';' + b)}}"/>`,
`(_ctx, _cache) => {
return { a: _stringifyStyle(_ctx.styleA), b: _stringifyStyle(_ctx.styleB) }
return { a: _s(_ctx.styleA), b: _s(_ctx.styleB) }
}`
)
assert(
`<view :style="[styleA, styleB, { color:'red',fontSize }, 'font-weight:bold', ...styleC, ...[styleD,styleE], handle(styleF) ]" style="font-size:15px"/>`,
`<view style="{{a + ';' + b + ';' + c + ';' + 'font-weight:bold' + ';' + d + ';' + e + ';' + f + ';' + 'font-size:15px'}}"/>`,
`(_ctx, _cache) => {
return { a: _stringifyStyle(_ctx.styleA), b: _stringifyStyle(_ctx.styleB), c: _stringifyStyle({ color: 'red', fontSize: _ctx.fontSize }), d: _stringifyStyle(_ctx.styleC), e: _stringifyStyle([_ctx.styleD, _ctx.styleE]), f: _stringifyStyle(_ctx.handle(_ctx.styleF)) }
return { a: _s(_ctx.styleA), b: _s(_ctx.styleB), c: _s({ color: 'red', fontSize: _ctx.fontSize }), d: _s(_ctx.styleC), e: _s([_ctx.styleD, _ctx.styleE]), f: _s(_ctx.handle(_ctx.styleF)) }
}`
)
assert(
`<view style="font-size:15px" :style="[styleA, styleB, { color:'red',fontSize }, 'font-weight:bold', ...styleC, ...[styleD,styleE], handle(styleF) ]"/>`,
`<view style="{{'font-size:15px' + ';' + (a + ';' + b + ';' + c + ';' + 'font-weight:bold' + ';' + d + ';' + e + ';' + f)}}"/>`,
`(_ctx, _cache) => {
return { a: _stringifyStyle(_ctx.styleA), b: _stringifyStyle(_ctx.styleB), c: _stringifyStyle({ color: 'red', fontSize: _ctx.fontSize }), d: _stringifyStyle(_ctx.styleC), e: _stringifyStyle([_ctx.styleD, _ctx.styleE]), f: _stringifyStyle(_ctx.handle(_ctx.styleF)) }
return { a: _s(_ctx.styleA), b: _s(_ctx.styleB), c: _s({ color: 'red', fontSize: _ctx.fontSize }), d: _s(_ctx.styleC), e: _s([_ctx.styleD, _ctx.styleE]), f: _s(_ctx.handle(_ctx.styleF)) }
}`
)
})
......
......@@ -40,7 +40,7 @@ describe('compiler', () => {
`<view v-for="item in items"><view v-if="ok"></view></view>`,
`<view wx:if="{{a}}">{{b}}</view>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return _ctx.ok ? {} : {}; }), b: _ctx.ok }
return { a: _f(_ctx.items, (item, k0, i0) => { return _ctx.ok ? {} : {}; }), b: _ctx.ok }
}`,
{
renderDataSpread: false,
......
......@@ -29,7 +29,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="index in 5" />`,
`<view wx:for="{{a}}" wx:for-item="index"/>`,
`(_ctx, _cache) => {
return { a: _vFor(5, (index, k0, i0) => { return {}; }) }
return { a: _f(5, (index, k0, i0) => { return {}; }) }
}`
)
})
......@@ -38,7 +38,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="(item) in items" />`,
`<view wx:for="{{a}}" wx:for-item="item"/>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return {}; }) }
}`
)
})
......@@ -47,7 +47,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="({ id, value }) in items" />`,
`<view wx:for="{{a}}" wx:for-item="v0"/>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, ({ id, value }, k0, i0) => { return {}; }) }
return { a: _f(_ctx.items, ({ id, value }, k0, i0) => { return {}; }) }
}`
)
})
......@@ -56,7 +56,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="([ id, value ]) in items" />`,
`<view wx:for="{{a}}" wx:for-item="v0"/>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, ([id, value], k0, i0) => { return {}; }) }
return { a: _f(_ctx.items, ([id, value], k0, i0) => { return {}; }) }
}`
)
})
......@@ -65,7 +65,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="(item, key) in items" />`,
`<view wx:for="{{a}}" wx:for-item="item"/>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, key, i0) => { return {}; }) }
return { a: _f(_ctx.items, (item, key, i0) => { return {}; }) }
}`
)
})
......@@ -74,7 +74,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="(item, key, index) in items" />`,
`<view wx:for="{{a}}" wx:for-item="item"/>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, key, index) => { return {}; }) }
return { a: _f(_ctx.items, (item, key, index) => { return {}; }) }
}`
)
})
......@@ -83,7 +83,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="(value,,index) in items" />`,
`<view wx:for="{{a}}" wx:for-item="value"/>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (value, k0, index) => { return {}; }) }
return { a: _f(_ctx.items, (value, k0, index) => { return {}; }) }
}`
)
})
......@@ -92,7 +92,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="(,,index) in items" />`,
`<view wx:for="{{a}}" wx:for-item="v0"/>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (v0, k0, index) => { return {}; }) }
return { a: _f(_ctx.items, (v0, k0, index) => { return {}; }) }
}`
)
})
......@@ -101,7 +101,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="item in items" />`,
`<view wx:for="{{a}}" wx:for-item="item"/>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return {}; }) }
}`
)
})
......@@ -110,7 +110,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="item, key in items" />`,
`<view wx:for="{{a}}" wx:for-item="item"/>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, key, i0) => { return {}; }) }
return { a: _f(_ctx.items, (item, key, i0) => { return {}; }) }
}`
)
})
......@@ -119,7 +119,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="value, key, index in items" />`,
`<view wx:for="{{a}}" wx:for-item="value"/>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (value, key, index) => { return {}; }) }
return { a: _f(_ctx.items, (value, key, index) => { return {}; }) }
}`
)
})
......@@ -128,7 +128,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="value, , index in items" />`,
`<view wx:for="{{a}}" wx:for-item="value"/>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (value, k0, index) => { return {}; }) }
return { a: _f(_ctx.items, (value, k0, index) => { return {}; }) }
}`
)
})
......@@ -137,7 +137,7 @@ describe(`compiler: v-for`, () => {
`<view v-for=", , index in items" />`,
`<view wx:for="{{a}}" wx:for-item="v0"/>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (v0, k0, index) => { return {}; }) }
return { a: _f(_ctx.items, (v0, k0, index) => { return {}; }) }
}`
)
})
......@@ -146,7 +146,7 @@ describe(`compiler: v-for`, () => {
`<template v-for="item in items">hello<view/></template>`,
`<block wx:for="{{a}}" wx:for-item="item">hello<view/></block>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return {}; }) }
}`
)
})
......@@ -155,7 +155,7 @@ describe(`compiler: v-for`, () => {
`<template v-for="item in items"><slot/></template>`,
`<block wx:for="{{a}}" wx:for-item="item"><slot/></block>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return {}; }) }
}`
)
})
......@@ -165,7 +165,7 @@ describe(`compiler: v-for`, () => {
`<template v-for="item in items" :key="item.id"><view :id="item.id" /></template>`,
`<block wx:for="{{a}}" wx:for-item="item" wx:key="b"><view id="{{item.a}}"/></block>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: item.id, b: item.id }; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: item.id, b: item.id }; }) }
}`
)
})
......@@ -174,7 +174,7 @@ describe(`compiler: v-for`, () => {
`<slot v-for="item in items"></slot>`,
`<slot wx:for="{{a}}" wx:for-item="item"></slot>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return {}; }) }
}`
)
})
......@@ -183,7 +183,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="(item) in items" :key="item" />`,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="*this"/>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return {}; }) }
}`
)
})
......@@ -192,7 +192,7 @@ describe(`compiler: v-for`, () => {
`<template v-for="item in items" :key="item">hello<view/></template>`,
`<block wx:for="{{a}}" wx:for-item="item" wx:key="*this">hello<view/></block>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return {}; }) }
}`
)
})
......@@ -201,7 +201,7 @@ describe(`compiler: v-for`, () => {
`<view v-if="ok" v-for="i in list"/>`,
`<view wx:if="{{a}}" wx:for="{{b}}" wx:for-item="i"/>`,
`(_ctx, _cache) => {
return _extend({ a: _ctx.ok }, _ctx.ok ? { b: _vFor(_ctx.list, (i, k0, i0) => { return {}; }) } : {})
return _e({ a: _ctx.ok }, _ctx.ok ? { b: _f(_ctx.list, (i, k0, i0) => { return {}; }) } : {})
}`
)
})
......@@ -211,7 +211,7 @@ describe(`compiler: v-for`, () => {
`<template v-if="ok" v-for="i in list"/>`,
`<block wx:if="{{a}}" wx:for="{{b}}" wx:for-item="i"/>`,
`(_ctx, _cache) => {
return _extend({ a: _ctx.ok }, _ctx.ok ? { b: _vFor(_ctx.list, (i, k0, i0) => { return {}; }) } : {})
return _e({ a: _ctx.ok }, _ctx.ok ? { b: _f(_ctx.list, (i, k0, i0) => { return {}; }) } : {})
}`
)
})
......@@ -615,7 +615,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="item in items" :key="itemKey(item)">test</view>`,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="a">test</view>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: _ctx.itemKey(item) }; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _ctx.itemKey(item) }; }) }
}`
)
})
......@@ -626,7 +626,7 @@ describe(`compiler: v-for`, () => {
`<template v-for="item in items" :key="itemKey(item)">test</template>`,
`<block wx:for="{{a}}" wx:for-item="item" wx:key="a">test</block>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: _ctx.itemKey(item) }; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _ctx.itemKey(item) }; }) }
}`
)
})
......@@ -636,7 +636,7 @@ describe(`compiler: v-for`, () => {
`<template v-for="item in items" key="key">test</template>`,
`<block wx:for="{{a}}" wx:for-item="item" key="key">test</block>`,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return {}; }) }
}`
)
})
......
......@@ -29,7 +29,7 @@ describe(`compiler: v-if`, () => {
`<view v-if="ok"/>`,
`<view wx:if="{{a}}"/>`,
`(_ctx, _cache) => {
return _extend({ a: _ctx.ok }, _ctx.ok ? {} : {})
return _e({ a: _ctx.ok }, _ctx.ok ? {} : {})
}`
)
})
......@@ -38,7 +38,7 @@ describe(`compiler: v-if`, () => {
`<template v-if="ok"><view/>hello<view/></template>`,
`<block wx:if="{{a}}"><view/>hello<view/></block>`,
`(_ctx, _cache) => {
return _extend({ a: _ctx.ok }, _ctx.ok ? {} : {})
return _e({ a: _ctx.ok }, _ctx.ok ? {} : {})
}`
)
})
......@@ -47,7 +47,7 @@ describe(`compiler: v-if`, () => {
`<template v-if="ok"><slot/></template>`,
`<block wx:if="{{a}}"><slot/></block>`,
`(_ctx, _cache) => {
return _extend({ a: _ctx.ok }, _ctx.ok ? {} : {})
return _e({ a: _ctx.ok }, _ctx.ok ? {} : {})
}`
)
})
......@@ -56,7 +56,7 @@ describe(`compiler: v-if`, () => {
`<slot v-if="ok"/>`,
`<slot wx:if="{{a}}"/>`,
`(_ctx, _cache) => {
return _extend({ a: _ctx.ok }, _ctx.ok ? {} : {})
return _e({ a: _ctx.ok }, _ctx.ok ? {} : {})
}`
)
})
......@@ -65,7 +65,7 @@ describe(`compiler: v-if`, () => {
// `<Component v-if="ok"></Component>`,
// `<Component wx:if="{{a}}"></Component>`,
// `(_ctx, _cache) => {
// return _extend({ a: _ctx.ok }, _ctx.ok ? {} : {})
// return _e({ a: _ctx.ok }, _ctx.ok ? {} : {})
// }`
// )
})
......@@ -74,7 +74,7 @@ describe(`compiler: v-if`, () => {
`<view v-if="ok"/><view v-else/>`,
`<view wx:if="{{a}}"/><view wx:else/>`,
`(_ctx, _cache) => {
return _extend({ a: _ctx.ok }, _ctx.ok ? {} : {})
return _e({ a: _ctx.ok }, _ctx.ok ? {} : {})
}`
)
})
......@@ -83,7 +83,7 @@ describe(`compiler: v-if`, () => {
`<view v-if="ok"/><view v-else-if="orNot"/>`,
`<view wx:if="{{a}}"/><view wx:elif="{{b}}"/>`,
`(_ctx, _cache) => {
return _extend({ a: _ctx.ok }, _ctx.ok ? {} : _ctx.orNot ? {} : {}, { b: _ctx.orNot })
return _e({ a: _ctx.ok }, _ctx.ok ? {} : _ctx.orNot ? {} : {}, { b: _ctx.orNot })
}`
)
})
......@@ -92,7 +92,7 @@ describe(`compiler: v-if`, () => {
`<view v-if="ok"/><view v-else-if="orNot"/><template v-else>fine</template>`,
`<view wx:if="{{a}}"/><view wx:elif="{{b}}"/><block wx:else>fine</block>`,
`(_ctx, _cache) => {
return _extend({ a: _ctx.ok }, _ctx.ok ? {} : _ctx.orNot ? {} : {}, { b: _ctx.orNot })
return _e({ a: _ctx.ok }, _ctx.ok ? {} : _ctx.orNot ? {} : {}, { b: _ctx.orNot })
}`
)
})
......@@ -119,7 +119,7 @@ describe(`compiler: v-if`, () => {
`<view v-if="ok"/><view v-else-if="orNot"/><view v-else-if="3"/><template v-else>fine</template>`,
`<view wx:if="{{a}}"/><view wx:elif="{{b}}"/><view wx:elif="{{3}}"/><block wx:else>fine</block>`,
`(_ctx, _cache) => {
return _extend({ a: _ctx.ok }, _ctx.ok ? {} : _ctx.orNot ? {} : 3 ? {} : {}, { b: _ctx.orNot })
return _e({ a: _ctx.ok }, _ctx.ok ? {} : _ctx.orNot ? {} : 3 ? {} : {}, { b: _ctx.orNot })
}`
)
})
......@@ -134,7 +134,7 @@ describe(`compiler: v-if`, () => {
`,
`<view wx:if="{{a}}"/><view wx:elif="{{b}}"/><block wx:else>fine</block>`,
`(_ctx, _cache) => {
return _extend({ a: _ctx.ok }, _ctx.ok ? {} : _ctx.orNot ? {} : {}, { b: _ctx.orNot })
return _e({ a: _ctx.ok }, _ctx.ok ? {} : _ctx.orNot ? {} : {}, { b: _ctx.orNot })
}`
)
})
......@@ -143,7 +143,7 @@ describe(`compiler: v-if`, () => {
`<view v-if="ok"/> <view v-else-if="no"/> <view v-else/>`,
`<view wx:if="{{a}}"/><view wx:elif="{{b}}"/><view wx:else/>`,
`(_ctx, _cache) => {
return _extend({ a: _ctx.ok }, _ctx.ok ? {} : _ctx.no ? {} : {}, { b: _ctx.no })
return _e({ a: _ctx.ok }, _ctx.ok ? {} : _ctx.no ? {} : {}, { b: _ctx.no })
}`
)
})
......@@ -163,7 +163,7 @@ describe(`compiler: v-if`, () => {
`,
`<block wx:if="{{a}}"><view wx:if="{{b}}"></view><view wx:else/><view/></block>`,
`(_ctx, _cache) => {
return _extend({ a: _ctx.ok }, _ctx.ok ? _extend({ b: _ctx.ok2 }, _ctx.ok2 ? {} : {}) : {})
return _e({ a: _ctx.ok }, _ctx.ok ? _e({ b: _ctx.ok2 }, _ctx.ok2 ? {} : {}) : {})
}`
)
})
......
......@@ -6,7 +6,7 @@ describe('compiler: transform v-model', () => {
`<Comp v-model="model" />`,
`<comp class="v-r" v-i="2a9ec0b0-0" modelValue="{{a}}" bindupdateModelValue="{{b}}"/>`,
`(_ctx, _cache) => {
return { a: _ctx.model, b: _vOn($event => _ctx.model = $event) }
return { a: _ctx.model, b: _o($event => _ctx.model = $event) }
}`
)
})
......@@ -15,7 +15,7 @@ describe('compiler: transform v-model', () => {
`<Comp v-model="model" />`,
`<comp class="v-r" v-i="2a9ec0b0-0" modelValue="{{a}}" bindupdateModelValue="{{b}}"/>`,
`(_ctx, _cache) => {
return { a: _ctx.model, b: _vOn($event => _ctx.model = $event) }
return { a: _ctx.model, b: _o($event => _ctx.model = $event) }
}`,
{
cacheHandlers: true,
......@@ -27,14 +27,14 @@ describe('compiler: transform v-model', () => {
`<input v-model="model" />`,
`<input value="{{a}}" bindinput="{{b}}"/>`,
`(_ctx, _cache) => {
return { a: _ctx.model, b: _vOn($event => _ctx.model = $event.detail.value) }
return { a: _ctx.model, b: _o($event => _ctx.model = $event.detail.value) }
}`
)
assert(
`<textarea v-model="model" />`,
`<textarea value="{{a}}" bindinput="{{b}}"/>`,
`(_ctx, _cache) => {
return { a: _ctx.model, b: _vOn($event => _ctx.model = $event.detail.value) }
return { a: _ctx.model, b: _o($event => _ctx.model = $event.detail.value) }
}`
)
})
......@@ -43,7 +43,7 @@ describe('compiler: transform v-model', () => {
`<input @input="input" v-model="model" />`,
`<input bindinput="{{a}}" value="{{b}}"/>`,
`(_ctx, _cache) => {
return { a: _vOn([$event => _ctx.model = $event.detail.value, _ctx.input]), b: _ctx.model }
return { a: _o([$event => _ctx.model = $event.detail.value, _ctx.input]), b: _ctx.model }
}`
)
})
......
......@@ -25,7 +25,7 @@ describe('compiler(mp): transform v-on', () => {
`<editor @ready="ready"/>`,
`<block wx:if="{{r0}}"><editor bindready="{{a}}"/></block>`,
`(_ctx, _cache) => {
return { a: _vOn(_ctx.ready) }
return { a: _o(_ctx.ready) }
}`
)
})
......
......@@ -17,7 +17,7 @@ describe('compiler: transform v-on', () => {
`<view v-on:click="onClick"/>`,
`<view bindtap="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: _vOn(_ctx.onClick) }
return { a: _o(_ctx.onClick) }
}`
)
})
......@@ -35,7 +35,7 @@ describe('compiler: transform v-on', () => {
`<view @click="i++"/>`,
`<view bindtap="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: _vOn($event => _ctx.i++) }
return { a: _o($event => _ctx.i++) }
}`
)
})
......@@ -44,7 +44,7 @@ describe('compiler: transform v-on', () => {
`<view @click="foo();bar()"/>`,
`<view bindtap="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: _vOn($event => { _ctx.foo(); _ctx.bar(); }) }
return { a: _o($event => { _ctx.foo(); _ctx.bar(); }) }
}`
)
})
......@@ -54,9 +54,9 @@ describe('compiler: transform v-on', () => {
`<view bindtap="{{a}}"/>`,
`(_ctx, _cache) => {
with (_ctx) {
const { vOn: _vOn } = _Vue
const { o: _o } = _Vue
return { a: _vOn($event => { foo(); bar(); }) }
return { a: _o($event => { foo(); bar(); }) }
}
}`,
{ prefixIdentifiers: false, mode: 'function' }
......@@ -67,7 +67,7 @@ describe('compiler: transform v-on', () => {
`<view @click="foo($event)"/>`,
`<view bindtap="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: _vOn($event => _ctx.foo($event)) }
return { a: _o($event => _ctx.foo($event)) }
}`
)
})
......@@ -76,7 +76,7 @@ describe('compiler: transform v-on', () => {
`<view @click="foo($event);bar()"/>`,
`<view bindtap="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: _vOn($event => { _ctx.foo($event); _ctx.bar(); }) }
return { a: _o($event => { _ctx.foo($event); _ctx.bar(); }) }
}`
)
})
......@@ -85,7 +85,7 @@ describe('compiler: transform v-on', () => {
`<view @click="$event => foo($event)"/>`,
`<view bindtap="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: _vOn($event => _ctx.foo($event)) }
return { a: _o($event => _ctx.foo($event)) }
}`
)
})
......@@ -98,7 +98,7 @@ describe('compiler: transform v-on', () => {
"/>`,
`<view bindtap="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: _vOn($event => { _ctx.foo($event); }) }
return { a: _o($event => { _ctx.foo($event); }) }
}`
)
})
......@@ -111,7 +111,7 @@ describe('compiler: transform v-on', () => {
"/>`,
`<view bindtap="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: _vOn(function ($event) { _ctx.foo($event); }) }
return { a: _o(function ($event) { _ctx.foo($event); }) }
}`
)
})
......@@ -121,9 +121,9 @@ describe('compiler: transform v-on', () => {
`<view bindtap="{{a}}"/>`,
`(_ctx, _cache) => {
with (_ctx) {
const { vOn: _vOn } = _Vue
const { o: _o } = _Vue
return { a: _vOn(a['b' + c]) }
return { a: _o(a['b' + c]) }
}
}`,
{
......@@ -137,7 +137,7 @@ describe('compiler: transform v-on', () => {
`<view @click="a['b' + c]"/>`,
`<view bindtap="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: _vOn(_ctx.a['b' + _ctx.c]) }
return { a: _o(_ctx.a['b' + _ctx.c]) }
}`
)
})
......@@ -146,7 +146,7 @@ describe('compiler: transform v-on', () => {
`<view @click="e => foo(e)"/>`,
`<view bindtap="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: _vOn(e => _ctx.foo(e)) }
return { a: _o(e => _ctx.foo(e)) }
}`
)
})
......@@ -178,7 +178,7 @@ describe('compiler: transform v-on', () => {
`<view v-on:foo-bar="onMount"/>`,
`<view bind:foo-bar="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: _vOn(_ctx.onMount) }
return { a: _o(_ctx.onMount) }
}`
)
})
......@@ -188,7 +188,7 @@ describe('compiler: transform v-on', () => {
`<view v-on:vnode-mounted="onMount"/>`,
`<view bind:vnode-mounted="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: _vOn(_ctx.onMount) }
return { a: _o(_ctx.onMount) }
}`
)
})
......@@ -199,7 +199,7 @@ describe('compiler: transform v-on', () => {
`<view v-on:click.prevent />`,
`<view catchtap="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: _vOn(() => {}) }
return { a: _o(() => {}) }
}`
)
})
......
......@@ -32,7 +32,7 @@ describe('compiler: transform v-slot', () => {
`<custom><template v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom>`,
`<custom vue-slots="{{['default']}}" class="v-r" v-i="2a9ec0b0-0"><view slot="default"><view>{{a}}</view></view></custom>`,
`(_ctx, _cache) => {
return { a: _toDisplayString(_ctx.slotProps.item), b: slotProps }
return { a: _t(_ctx.slotProps.item), b: slotProps }
}`
)
})
......
......@@ -3,12 +3,18 @@ import { registerRuntimeHelpers } from '@vue/compiler-core'
export const V_ON = Symbol(`vOn`)
export const V_FOR = Symbol(`vFor`)
export const EXTEND = Symbol(`extend`)
export const CAMELIZE = Symbol(`camelize`)
export const HYPHENATE = Symbol(`hyphenate`)
export const STRINGIFY_STYLE = Symbol(`stringifyStyle`)
export const NORMALIZE_CLASS = Symbol(`normalizeClass`)
export const TO_DISPLAY_STRING = Symbol(`toDisplayString`)
registerRuntimeHelpers({
[V_ON]: 'vOn',
[V_FOR]: 'vFor',
[EXTEND]: 'extend',
[HYPHENATE]: 'hyphenate',
[STRINGIFY_STYLE]: 'stringifyStyle',
[V_ON]: 'o',
[V_FOR]: 'f',
[EXTEND]: 'e',
[CAMELIZE]: 'c',
[HYPHENATE]: 'h',
[STRINGIFY_STYLE]: 's',
[NORMALIZE_CLASS]: 'n',
[TO_DISPLAY_STRING]: `t`,
})
......@@ -528,9 +528,9 @@ function parseReturnObjExpr(prop: ObjectProperty) {
isObjectProperty(prop) &&
isCallExpression(prop.value) &&
isIdentifier(prop.value.callee) &&
prop.value.callee.name === '_vFor'
// 目前硬编码识别 _f,应该读取 context.helperString
prop.value.callee.name === '_f'
) {
// 目前硬编码
return (
(
(prop.value.arguments[1] as ArrowFunctionExpression)
......
......@@ -27,11 +27,11 @@ import {
createSimpleExpression,
ExpressionNode,
createCompoundExpression,
NORMALIZE_CLASS,
SourceLocation,
} from '@vue/compiler-core'
import { parseExpr, isTrueExpr, isUndefined, parseStringLiteral } from '../ast'
import { genBabelExpr } from '../codegen'
import { NORMALIZE_CLASS } from '../runtimeHelpers'
import { TransformContext } from '../transform'
import {
parseExprWithRewrite,
......
......@@ -2,7 +2,6 @@ import {
createCompoundExpression,
DirectiveNode,
NodeTypes,
TO_DISPLAY_STRING,
} from '@vue/compiler-core'
import { NodeTransform } from '../transform'
......@@ -19,6 +18,7 @@ import {
isStyleBinding,
rewriteStyle,
} from './transformStyle'
import { TO_DISPLAY_STRING } from '../runtimeHelpers'
export const transformIdentifier: NodeTransform = (node, context) => {
return () => {
......
import { camelize } from '@vue/shared'
import {
NodeTypes,
CAMELIZE,
createCompilerError,
ErrorCodes,
createObjectProperty,
......@@ -27,7 +26,7 @@ export const transformBind: DirectiveTransform = (dir, _node, context) => {
if (arg.isStatic) {
arg.content = camelize(arg.content)
} else {
arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`
// arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`
}
} else {
// arg.children.unshift(`${context.helperString(CAMELIZE)}(`)
......
import { extend, isSymbol, isObject, toRawType, def, hasChanged, isArray, isFunction, NOOP, remove, toHandlerKey, camelize, capitalize, isString, normalizeClass, normalizeStyle, isOn, isPromise, EMPTY_OBJ, isSet, isMap, isPlainObject, invokeArrayFns, hasOwn, NO, isIntegerKey, toNumber, hyphenate, isReservedProp, EMPTY_ARR, makeMap, toTypeString, stringifyStyle as stringifyStyle$1 } from '@vue/shared';
export { camelize, extend, hyphenate, normalizeClass, normalizeProps, normalizeStyle, toDisplayString, toHandlerKey } from '@vue/shared';
export { camelize as c, camelize, extend as e, hyphenate as h, normalizeClass as n, normalizeClass, normalizeProps, normalizeStyle, toDisplayString as t, toDisplayString, toHandlerKey } from '@vue/shared';
// lifecycle
// App and Page
......@@ -5068,4 +5068,4 @@ function createApp(rootComponent, rootProps = null) {
}
const createSSRApp = createApp;
export { EffectScope, ReactiveEffect, callWithAsyncErrorHandling, callWithErrorHandling, computed, createApp, createSSRApp, createVNode$1 as createVNode, createVueApp, customRef, defineComponent, defineEmits, defineExpose, defineProps, effect, effectScope, getCurrentInstance, getCurrentScope, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, mergeDefaults, mergeProps, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onUnmounted, onUpdated, provide, proxyRefs, queuePostFlushCb, reactive, readonly, ref, resolveComponent, resolveDirective, resolveFilter, setupDevtoolsPlugin, shallowReactive, shallowReadonly, shallowRef, stop, stringifyStyle, toHandlers, toRaw, toRef, toRefs, triggerRef, unref, useAttrs, useSSRContext, useSlots, vFor, vOn, version, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withModifiers, withScopeId };
export { EffectScope, ReactiveEffect, callWithAsyncErrorHandling, callWithErrorHandling, computed, createApp, createSSRApp, createVNode$1 as createVNode, createVueApp, customRef, defineComponent, defineEmits, defineExpose, defineProps, effect, effectScope, vFor as f, getCurrentInstance, getCurrentScope, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, mergeDefaults, mergeProps, nextTick, vOn as o, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onUnmounted, onUpdated, provide, proxyRefs, queuePostFlushCb, reactive, readonly, ref, resolveComponent, resolveDirective, resolveFilter, stringifyStyle as s, setupDevtoolsPlugin, shallowReactive, shallowReadonly, shallowRef, stop, toHandlers, toRaw, toRef, toRefs, triggerRef, unref, useAttrs, useSSRContext, useSlots, version, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withModifiers, withScopeId };
......@@ -6,7 +6,18 @@ export function createApp(rootComponent: unknown, rootProps = null) {
return createVueApp(rootComponent, rootProps).use(plugin)
}
export const createSSRApp = createApp
export * from './helpers'
export { extend, hyphenate } from '@vue/shared'
export {
vOn as o,
vFor as f,
stringifyStyle as s,
setupDevtoolsPlugin,
} from './helpers'
export {
camelize as c,
extend as e,
hyphenate as h,
normalizeClass as n,
toDisplayString as t,
} from '@vue/shared'
// @ts-ignore
export * from '../lib/vue.runtime.esm.js'
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册