function cached (fn) { const cache = Object.create(null) return function cachedFn (str) { const hit = cache[str] return hit || (cache[str] = fn(str)) } } const capitalize = cached(str => { return str.charAt(0).toUpperCase() + str.slice(1) }) const EVENTS = { click: 'tap', touchstart: 'touchStart', touchmove: 'touchMove', touchend: 'touchEnd', touchcancel: 'touchCancel', longtap: 'longTap', longpress: 'longTap', transitionend: 'transitionEnd', animationstart: 'animationStart', animationiteration: 'animationIteration', animationend: 'animationEnd', firstappear: 'firstAppear', // map markertap: 'markerTap', callouttap: 'calloutTap', controltap: 'controlTap', regionchange: 'regionChange', // scroll-view scrolltoupper: 'scrollToUpper', scrolltolower: 'scrollToLower', // movable-view changeend: 'changeEnd' } module.exports = { directive: 'a:', specialEvents: { form: { reset: 'onReset' }, map: { markertap: 'onMarkerTap', controltap: 'onControlTap', callouttap: 'onCalloutTap', regionchange: 'onRegionChange' } }, createFilterTag (filterTag, { attrs }) { return `` }, getEventType (eventType) { return EVENTS[eventType] || eventType }, formatEventType: function (eventName, isCatch) { return `${isCatch ? 'catch' : 'on'}${capitalize(eventName)}` }, createScopedSlots (slotName, props, state) { const node = { type: 'slot', attr: { name: slotName }, children: [] } Object.keys(props).forEach(name => { node.attr[name] = props[name] }) return node }, resolveScopedSlots (slotName, { paramExprNode, returnExprNodes, traverseExpr, normalizeChildren }, state) { const node = { type: 'view', attr: { slot: slotName }, children: normalizeChildren(traverseExpr(returnExprNodes, state)) } if (paramExprNode && paramExprNode.type === 'Identifier') { node.scoped = paramExprNode.name } return node } }