From ef1cb306d1128416f3590d7fbb5c5bdf91157d76 Mon Sep 17 00:00:00 2001 From: yuche Date: Wed, 10 Oct 2018 15:20:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(transformer):=20=E5=A4=84=E7=90=86?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=AE=9D=E5=B0=8F=E7=A8=8B=E5=BA=8F=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/jsx.ts | 5 ++++- packages/taro-transformer-wx/src/render.ts | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/taro-transformer-wx/src/jsx.ts b/packages/taro-transformer-wx/src/jsx.ts index a1c9f488dc5a..2b7c17d82647 100644 --- a/packages/taro-transformer-wx/src/jsx.ts +++ b/packages/taro-transformer-wx/src/jsx.ts @@ -158,8 +158,11 @@ export function parseJSXElement (element: t.JSXElement): string { if (t.isStringLiteral(attrValue)) { value = attrValue.value } else if (t.isJSXExpressionContainer(attrValue)) { - const isBindEvent = + let isBindEvent = (name.startsWith('bind') && name !== 'bind') || (name.startsWith('catch') && name !== 'catch') + if (Adapter.type === Adapters.alipay && /(on[A-Z_])|(catch[A-Z_])/.test(name)) { + isBindEvent = true + } let { code } = generate(attrValue.expression, { quotes: 'single', concise: true diff --git a/packages/taro-transformer-wx/src/render.ts b/packages/taro-transformer-wx/src/render.ts index 11a4bab73da1..8c3d628850c0 100644 --- a/packages/taro-transformer-wx/src/render.ts +++ b/packages/taro-transformer-wx/src/render.ts @@ -28,7 +28,7 @@ import { parseJSXElement } from './jsx' import { DEFAULT_Component_SET, MAP_CALL_ITERATOR, LOOP_STATE, LOOP_CALLEE, THIRD_PARTY_COMPONENTS, LOOP_ORIGINAL, INTERNAL_GET_ORIGNAL } from './constant' -import { Adapter } from './adapter' +import { Adapter, Adapters } from './adapter' import generate from 'babel-generator' const template = require('babel-template') @@ -267,7 +267,7 @@ export class RenderParser { ) }) let classProp = t.classProperty( - t.identifier('properties'), + t.identifier(Adapter.type === Adapters.alipay ? 'props' : 'properties'), t.objectExpression(properties) ) as any classProp.static = true @@ -685,8 +685,13 @@ export class RenderParser { + name.name.slice(2).toLowerCase() if (name.name === 'onClick') { transformName = eventShouldBeCatched ? 'catchtap' : 'bindtap' + if (Adapter.type === Adapters.alipay) { + transformName = eventShouldBeCatched ? 'catchTap' : 'onTap' + } } path.node.name = t.jSXIdentifier(transformName) + } else if (Adapter.type === Adapters.alipay) { + // 其他支付宝情况不用更改事件名 } else if (THIRD_PARTY_COMPONENTS.has(componentName)) { path.node.name = t.jSXIdentifier('bind' + name.name.slice(2)) } else {