Skip to content

Commit

Permalink
feat(transformer): 处理支付宝小程序事件差异
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche committed Oct 10, 2018
1 parent 50eac86 commit ef1cb30
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/taro-transformer-wx/src/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions packages/taro-transformer-wx/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit ef1cb30

Please sign in to comment.