diff --git a/packages/uni-cli-shared/src/mp/template.ts b/packages/uni-cli-shared/src/mp/template.ts index 20f4cc3f7a5a5a18429c83cd16e8fd865e50b769..a3542f471c85e94ac8732430796f7f76bfa05f63 100644 --- a/packages/uni-cli-shared/src/mp/template.ts +++ b/packages/uni-cli-shared/src/mp/template.ts @@ -4,6 +4,12 @@ import { LINEFEED } from '@dcloudio/uni-shared' import { normalizeMiniProgramFilename } from '../utils' export interface MiniProgramCompilerOptions { + event?: { + format( + name: string, + opts: { isCatch?: boolean; isCapture?: boolean; isComponent?: boolean } + ): string + } class: { /** * 是否支持绑定 array 类型 diff --git a/packages/uni-mp-alipay/__tests__/component.spec.ts b/packages/uni-mp-alipay/__tests__/component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..0d741df864346cb5ee703db5f61f000cd86acec5 --- /dev/null +++ b/packages/uni-mp-alipay/__tests__/component.spec.ts @@ -0,0 +1,15 @@ +import { tags } from '../src/compiler/options' +import { assert } from './testUtils' + +describe('mp-alipay: transform component', () => { + test(`built-in component`, () => { + const code = tags.map((tag) => `<${tag}/>`).join('') + assert( + code, + code, + `(_ctx, _cache) => { + return {} +}` + ) + }) +}) diff --git a/packages/uni-mp-alipay/__tests__/ref.spec.ts b/packages/uni-mp-alipay/__tests__/ref.spec.ts index bfa37724a6569b19e5ebf603531da439936a6388..f767db708e9616c47044f4f7e3f3843c4621b99d 100644 --- a/packages/uni-mp-alipay/__tests__/ref.spec.ts +++ b/packages/uni-mp-alipay/__tests__/ref.spec.ts @@ -1,6 +1,6 @@ import { assert } from './testUtils' -describe('compiler: transform ref', () => { +describe('mp-alipay: transform ref', () => { test('without ref', () => { assert( ``, diff --git a/packages/uni-mp-alipay/__tests__/testUtils.ts b/packages/uni-mp-alipay/__tests__/testUtils.ts index f546e2a9a34290896d4c89d61d87e40ed5633193..d06e2918a6e59bcfbe5ed5a0bf72ec459991fdfb 100644 --- a/packages/uni-mp-alipay/__tests__/testUtils.ts +++ b/packages/uni-mp-alipay/__tests__/testUtils.ts @@ -1,7 +1,11 @@ -import { isCustomElement, isNativeTag } from '@dcloudio/uni-shared' +import { isNativeTag } from '@dcloudio/uni-shared' import { compile, CompilerOptions } from '@dcloudio/uni-mp-compiler' -import { miniProgram, nodeTransforms } from '../src/compiler/options' +import { + isCustomElement, + miniProgram, + nodeTransforms, +} from '../src/compiler/options' export function assert( template: string, diff --git a/packages/uni-mp-alipay/__tests__/vOn.spec.ts b/packages/uni-mp-alipay/__tests__/vOn.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..cc2b50427d901865224616c305bbe53938e95f52 --- /dev/null +++ b/packages/uni-mp-alipay/__tests__/vOn.spec.ts @@ -0,0 +1,213 @@ +import { assert } from './testUtils' + +describe('mp-alipay: transform v-on', () => { + test('basic', () => { + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _o(_ctx.onClick) } +}` + ) + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _o(_ctx.onClick) } +}` + ) + }) + test('dynamic arg', () => { + // + }) + test('dynamic arg with prefixing', () => { + // + }) + test('dynamic arg with complex exp prefixing', () => { + // + }) + test('should wrap as function if expression is inline statement', () => { + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _o($event => _ctx.i++) } +}` + ) + }) + test('should handle multiple inline statement', () => { + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _o($event => { _ctx.foo(); _ctx.bar(); }) } +}` + ) + }) + test('should handle multi-line statement', () => { + assert( + ``, + ``, + `(_ctx, _cache) => { + with (_ctx) { + const { o: _o } = _Vue + + return { a: _o($event => { foo(); bar(); }) } + } +}`, + { prefixIdentifiers: false, mode: 'function' } + ) + }) + test('inline statement w/ prefixIdentifiers: true', () => { + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _o($event => _ctx.foo($event)) } +}` + ) + }) + test('multiple inline statements w/ prefixIdentifiers: true', () => { + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _o($event => { _ctx.foo($event); _ctx.bar(); }) } +}` + ) + }) + test('should NOT wrap as function if expression is already function expression', () => { + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _o($event => _ctx.foo($event)) } +}` + ) + }) + test('should NOT wrap as function if expression is already function expression (with newlines)', () => { + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _o($event => { _ctx.foo($event); }) } +}` + ) + }) + test('should NOT wrap as function if expression is already function expression (with newlines + function keyword)', () => { + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _o(function ($event) { _ctx.foo($event); }) } +}` + ) + }) + test('should NOT wrap as function if expression is complex member expression', () => { + assert( + ``, + ``, + `(_ctx, _cache) => { + with (_ctx) { + const { o: _o } = _Vue + + return { a: _o(a['b' + c]) } + } +}`, + { + prefixIdentifiers: false, + mode: 'function', + } + ) + }) + test('complex member expression w/ prefixIdentifiers: true', () => { + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _o(_ctx.a['b' + _ctx.c]) } +}` + ) + }) + test('function expression w/ prefixIdentifiers: true', () => { + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _o(e => _ctx.foo(e)) } +}` + ) + }) + + test('case conversion for kebab-case events', () => { + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _o(_ctx.onMount) } +}` + ) + }) + + test('case conversion for vnode hooks', () => { + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _o(_ctx.onMount) } +}` + ) + }) + + describe('cacheHandler', () => { + test('empty handler', () => { + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _o(() => {}) } +}` + ) + }) + + test('member expression handler', () => { + //
+ }) + + test('compound member expression handler', () => { + //
+ }) + + test('bail on component member expression handler', () => { + // + }) + + test('should not be cached inside v-once', () => { + //
+ }) + + test('inline function expression handler', () => { + //
+ }) + + test('inline async arrow function expression handler', () => { + //
+ }) + + test('inline async function expression handler', () => { + //
+ }) + + test('inline statement handler', () => { + //
+ }) + }) +}) diff --git a/packages/uni-mp-alipay/__tests__/vSlot.spec.ts b/packages/uni-mp-alipay/__tests__/vSlot.spec.ts index 5cccaab071d3fc163c76b3878615f9b7f7a6ff28..47c20fe8e74062a556a112e6b251805f809c0de2 100644 --- a/packages/uni-mp-alipay/__tests__/vSlot.spec.ts +++ b/packages/uni-mp-alipay/__tests__/vSlot.spec.ts @@ -1,6 +1,6 @@ import { assert } from './testUtils' -describe('compiler: transform v-slot', () => { +describe('mp-alipay: transform v-slot', () => { test('default slot', () => { assert( `