From f63216a6ae8c3c73df0a14c6288cb797bf5369a7 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Sat, 23 Oct 2021 00:15:05 +0800 Subject: [PATCH] wip(mp): reduce bundle size --- .../uni-mp-compiler/__tests__/class.spec.ts | 28 +++++------ .../uni-mp-compiler/__tests__/codegen.spec.ts | 20 ++++---- .../__tests__/component.spec.ts | 10 ++-- .../uni-mp-compiler/__tests__/ref.spec.ts | 2 +- .../uni-mp-compiler/__tests__/scope.spec.ts | 14 +++--- .../uni-mp-compiler/__tests__/scopeId.spec.ts | 6 +-- .../uni-mp-compiler/__tests__/style.spec.ts | 28 +++++------ .../uni-mp-compiler/__tests__/test.spec.ts | 2 +- .../uni-mp-compiler/__tests__/vFor.spec.ts | 48 +++++++++---------- .../uni-mp-compiler/__tests__/vIf.spec.ts | 24 +++++----- .../uni-mp-compiler/__tests__/vModel.spec.ts | 10 ++-- .../uni-mp-compiler/__tests__/vOn.mp.spec.ts | 2 +- .../uni-mp-compiler/__tests__/vOn.spec.ts | 34 ++++++------- .../uni-mp-compiler/__tests__/vSlot.spec.ts | 2 +- .../uni-mp-compiler/src/runtimeHelpers.ts | 16 +++++-- packages/uni-mp-compiler/src/transform.ts | 4 +- .../src/transforms/transformClass.ts | 2 +- .../src/transforms/transformIdentifier.ts | 2 +- .../uni-mp-compiler/src/transforms/vBind.ts | 3 +- packages/uni-mp-vue/dist/vue.runtime.esm.js | 4 +- packages/uni-mp-vue/src/index.ts | 15 +++++- 21 files changed, 146 insertions(+), 130 deletions(-) diff --git a/packages/uni-mp-compiler/__tests__/class.spec.ts b/packages/uni-mp-compiler/__tests__/class.spec.ts index 28b03a36d..ecf394ba3 100644 --- a/packages/uni-mp-compiler/__tests__/class.spec.ts +++ b/packages/uni-mp-compiler/__tests__/class.spec.ts @@ -29,14 +29,14 @@ describe('compiler: transform class', () => { ``, ``, `(_ctx, _cache) => { - return { a: _normalizeClass(_ctx.foo) } + return { a: _n(_ctx.foo) } }` ) assert( ``, ``, `(_ctx, _cache) => { - return { a: _normalizeClass(_ctx.foo | _ctx.bar) } + return { a: _n(_ctx.foo | _ctx.bar) } }` ) }) @@ -45,14 +45,14 @@ describe('compiler: transform class', () => { ``, ``, `(_ctx, _cache) => { - return { a: _normalizeClass(_ctx.foo) } + return { a: _n(_ctx.foo) } }` ) assert( ``, ``, `(_ctx, _cache) => { - return { a: _normalizeClass(_ctx.foo) } + return { a: _n(_ctx.foo) } }` ) }) @@ -68,7 +68,7 @@ describe('compiler: transform class', () => { ``, ``, `(_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', () => { ``, ``, `(_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( ``, ``, `(_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', () => { ``, ``, `(_ctx, _cache) => { - return { a: _normalizeClass(_ctx.classA), b: _normalizeClass(\`\${_ctx.classB}\`) } + return { a: _n(_ctx.classA), b: _n(\`\${_ctx.classB}\`) } }` ) assert( ``, ``, `(_ctx, _cache) => { - return { a: _normalizeClass(_ctx.classA), b: _normalizeClass(_ctx.classB) } + return { a: _n(_ctx.classA), b: _n(_ctx.classB) } }` ) assert( ``, ``, `(_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', () => { ``, ``, `(_ctx, _cache) => { - return { a: _normalizeClass(_ctx.classA), b: _normalizeClass(_ctx.classB) } + return { a: _n(_ctx.classA), b: _n(_ctx.classB) } }` ) assert( ``, ``, `(_ctx, _cache) => { - return { a: _normalizeClass(_ctx.classA), b: _normalizeClass(_ctx.classB) } + return { a: _n(_ctx.classA), b: _n(_ctx.classB) } }` ) assert( ``, ``, `(_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( ``, ``, `(_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)) } }` ) }) diff --git a/packages/uni-mp-compiler/__tests__/codegen.spec.ts b/packages/uni-mp-compiler/__tests__/codegen.spec.ts index b8c221595..fb6513c81 100644 --- a/packages/uni-mp-compiler/__tests__/codegen.spec.ts +++ b/packages/uni-mp-compiler/__tests__/codegen.spec.ts @@ -5,10 +5,10 @@ describe('compiler: codegen', () => { assert( ``, ``, - `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( ``, ``, - `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( ``, ``, - `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) } }` ) }) diff --git a/packages/uni-mp-compiler/__tests__/component.spec.ts b/packages/uni-mp-compiler/__tests__/component.spec.ts index a16459803..ddbce41ae 100644 --- a/packages/uni-mp-compiler/__tests__/component.spec.ts +++ b/packages/uni-mp-compiler/__tests__/component.spec.ts @@ -43,7 +43,7 @@ describe('compiler: transform component', () => { ``, ``, `(_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', () => { ``, ``, `(_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', () => { ``, ``, `(_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', () => { ``, ``, `(_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', () => { ``, ``, `(_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], diff --git a/packages/uni-mp-compiler/__tests__/ref.spec.ts b/packages/uni-mp-compiler/__tests__/ref.spec.ts index 782a455ef..e6a1511ec 100644 --- a/packages/uni-mp-compiler/__tests__/ref.spec.ts +++ b/packages/uni-mp-compiler/__tests__/ref.spec.ts @@ -22,7 +22,7 @@ describe('compiler: transform ref', () => { ``, ``, `(_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 }; }) } }` ) }) diff --git a/packages/uni-mp-compiler/__tests__/scope.spec.ts b/packages/uni-mp-compiler/__tests__/scope.spec.ts index 8cf56b7fe..d6e9f413f 100644 --- a/packages/uni-mp-compiler/__tests__/scope.spec.ts +++ b/packages/uni-mp-compiler/__tests__/scope.spec.ts @@ -6,7 +6,7 @@ describe('compiler: scope', () => { `{{item.title}}`, `{{item.a}}`, `(_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', () => { `{{item.title}}{{handle(foo)}}{{item.id}}{{item1.title}}`, `{{item.a}}{{b}}{{item.c}}{{item1.a}}`, `(_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( ``, ``, `(_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( ``, ``, `(_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', () => { ``, ``, `(_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', () => { `{{ok}}{{ok1}}{{ok2}}{{ok3}}`, `{{b}}{{d}}{{f}}{{g}}`, `(_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', () => { ``, ``, `(_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 }) }` ) }) diff --git a/packages/uni-mp-compiler/__tests__/scopeId.spec.ts b/packages/uni-mp-compiler/__tests__/scopeId.spec.ts index 43a6201ec..04b3b4815 100644 --- a/packages/uni-mp-compiler/__tests__/scopeId.spec.ts +++ b/packages/uni-mp-compiler/__tests__/scopeId.spec.ts @@ -17,7 +17,7 @@ describe('compiler: transform scopeId', () => { ``, ``, `(_ctx, _cache) => { - return { a: _normalizeClass(_ctx.foo) } + return { a: _n(_ctx.foo) } }`, options ) @@ -35,7 +35,7 @@ describe('compiler: transform scopeId', () => { ``, ``, `(_ctx, _cache) => { - return { a: _normalizeClass(_ctx.foo) } + return { a: _n(_ctx.foo) } }`, options ) @@ -43,7 +43,7 @@ describe('compiler: transform scopeId', () => { ``, ``, `(_ctx, _cache) => { - return { a: _normalizeClass(_ctx.foo) } + return { a: _n(_ctx.foo) } }`, options ) diff --git a/packages/uni-mp-compiler/__tests__/style.spec.ts b/packages/uni-mp-compiler/__tests__/style.spec.ts index a9d723517..b6e68af69 100644 --- a/packages/uni-mp-compiler/__tests__/style.spec.ts +++ b/packages/uni-mp-compiler/__tests__/style.spec.ts @@ -22,14 +22,14 @@ describe('compiler: transform style', () => { ``, ``, `(_ctx, _cache) => { - return { a: _stringifyStyle(_ctx.foo) } + return { a: _s(_ctx.foo) } }` ) assert( ``, ``, `(_ctx, _cache) => { - return { a: _stringifyStyle(_ctx.foo | _ctx.bar) } + return { a: _s(_ctx.foo | _ctx.bar) } }` ) }) @@ -38,14 +38,14 @@ describe('compiler: transform style', () => { ``, ``, `(_ctx, _cache) => { - return { a: _stringifyStyle(_ctx.foo) } + return { a: _s(_ctx.foo) } }` ) assert( ``, ``, `(_ctx, _cache) => { - return { a: _stringifyStyle(_ctx.foo) } + return { a: _s(_ctx.foo) } }` ) }) @@ -70,7 +70,7 @@ describe('compiler: transform style', () => { ``, ``, `(_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', () => { ``, ``, `(_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( ``, ``, `(_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', () => { ``, ``, `(_ctx, _cache) => { - return { a: _stringifyStyle(_ctx.styleA), b: _stringifyStyle(\`\${_ctx.styleB}\`) } + return { a: _s(_ctx.styleA), b: _s(\`\${_ctx.styleB}\`) } }` ) assert( ``, ``, `(_ctx, _cache) => { - return { a: _stringifyStyle(_ctx.styleA), b: _stringifyStyle(_ctx.styleB) } + return { a: _s(_ctx.styleA), b: _s(_ctx.styleB) } }` ) assert( ``, ``, `(_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', () => { ``, ``, `(_ctx, _cache) => { - return { a: _stringifyStyle(_ctx.styleA), b: _stringifyStyle(_ctx.styleB) } + return { a: _s(_ctx.styleA), b: _s(_ctx.styleB) } }` ) assert( ``, ``, `(_ctx, _cache) => { - return { a: _stringifyStyle(_ctx.styleA), b: _stringifyStyle(_ctx.styleB) } + return { a: _s(_ctx.styleA), b: _s(_ctx.styleB) } }` ) assert( ``, ``, `(_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( ``, ``, `(_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)) } }` ) }) diff --git a/packages/uni-mp-compiler/__tests__/test.spec.ts b/packages/uni-mp-compiler/__tests__/test.spec.ts index 05752244c..e82880559 100644 --- a/packages/uni-mp-compiler/__tests__/test.spec.ts +++ b/packages/uni-mp-compiler/__tests__/test.spec.ts @@ -40,7 +40,7 @@ describe('compiler', () => { ``, `{{b}}`, `(_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, diff --git a/packages/uni-mp-compiler/__tests__/vFor.spec.ts b/packages/uni-mp-compiler/__tests__/vFor.spec.ts index e52be1b6d..1a4f5b2c4 100644 --- a/packages/uni-mp-compiler/__tests__/vFor.spec.ts +++ b/packages/uni-mp-compiler/__tests__/vFor.spec.ts @@ -29,7 +29,7 @@ describe(`compiler: v-for`, () => { ``, ``, `(_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`, () => { ``, ``, `(_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`, () => { ``, ``, `(_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`, () => { ``, ``, `(_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`, () => { ``, ``, `(_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`, () => { ``, ``, `(_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`, () => { ``, ``, `(_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`, () => { ``, ``, `(_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`, () => { ``, ``, `(_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`, () => { ``, ``, `(_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`, () => { ``, ``, `(_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`, () => { ``, ``, `(_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`, () => { ``, ``, `(_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`, () => { ``, `hello`, `(_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`, () => { ``, ``, `(_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`, () => { ``, ``, `(_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`, () => { ``, ``, `(_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`, () => { ``, ``, `(_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`, () => { ``, `hello`, `(_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`, () => { ``, ``, `(_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`, () => { `