Skip to content

Commit

Permalink
feat(taro): 匿名函数转换后标记统一改为 funPrivate,close #956
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Oct 29, 2018
1 parent d7aa7a2 commit 86e01b9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/taro-alipay/src/create-component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isEmptyObject, noop } from './util'
import { updateComponent } from './lifecycle'
const anonymousFnNamePreffix = 'func__'
const anonymousFnNamePreffix = 'funPrivate'
const componentFnReg = /^__fn_/
const pageExtraFns = ['onTitleClick', 'onOptionMenuClick', 'onPageScroll', 'onPullDownRefresh', 'onReachBottom', 'onShareAppMessage']

Expand Down
2 changes: 1 addition & 1 deletion packages/taro-swan/src/create-component.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isEmptyObject, noop } from './util'
import { updateComponent } from './lifecycle'
const privatePropValName = 'privateTriggerObserer'
const anonymousFnNamePreffix = 'func__'
const anonymousFnNamePreffix = 'funPrivate'
const componentFnReg = /^__fn_/
const pageExtraFns = ['onPullDownRefresh', 'onReachBottom', 'onShareAppMessage', 'onPageScroll', 'onTabItemTap']

Expand Down
10 changes: 5 additions & 5 deletions packages/taro-transformer-wx/__tests__/event.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ describe('event', () => {

const instance = evalClass(ast)

expect(template).toMatch(`<view bindtap="func__1"></view>`)
expect(instance.$$events).toEqual(['func__1'])
expect(template).toMatch(`<view bindtap="funPrivate1"></view>`)
expect(instance.$$events).toEqual(['funPrivate1'])
})

test('相同的事件', () => {
Expand All @@ -164,13 +164,13 @@ describe('event', () => {
prettyPrint(`
<block>
<view>
<text bindtap=\"func__2\"></text>
<text bindtap=\"func__2\"></text>
<text bindtap=\"funPrivate2\"></text>
<text bindtap=\"funPrivate2\"></text>
</view>
</block>
`)
)
expect(instance.$$events).toEqual(['func__2'])
expect(instance.$$events).toEqual(['funPrivate2'])
})
})

Expand Down
16 changes: 8 additions & 8 deletions packages/taro-transformer-wx/__tests__/loop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ describe('loop', () => {
<view>
<cover-view wx:for=\"{{array}}\" wx:for-item=\"arr\">
<block wx:if=\"{{b1}}\" wx:for=\"{{arr.list}}\" wx:for-item=\"item\">
<scroll-view bindtap=\"func__1\">
<scroll-view bindtap=\"funPrivate1\">
<block wx:if=\"{{b2}}\">
<map></map>
</block>
Expand Down Expand Up @@ -1030,7 +1030,7 @@ describe('loop', () => {
<view>
<cover-view wx:for=\"{{array}}\" wx:for-item=\"arr\">
<block wx:if=\"{{b1}}\" wx:for=\"{{arr.list}}\" wx:for-item=\"item\">
<scroll-view bindtap=\"func__2\" data-e-func__2-so=\"this\" data-e-func__2-a-a=\"{{null}}\">
<scroll-view bindtap=\"funPrivate2\" data-e-funPrivate2-so=\"this\" data-e-funPrivate2-a-a=\"{{null}}\">
<block wx:if=\"{{b2}}\">
<map></map>
</block>
Expand Down Expand Up @@ -1720,7 +1720,7 @@ describe('loop', () => {
<block>
<view>
<block wx:if=\"{{b1}}\" wx:for=\"{{array}}\" wx:for-item=\"arr\">
<cover-view bindtap=\"func__3\">
<cover-view bindtap=\"funPrivate3\">
<block wx:if=\"{{b2}}\">
<map bindtap=\"handleClick\" data-e-handleClick-so=\"this\" data-e-handleClick-a-a=\"{{b2}}\"></map>
</block>
Expand Down Expand Up @@ -1782,9 +1782,9 @@ describe('loop', () => {
<block>
<view>
<block wx:if=\"{{b1}}\" wx:for=\"{{array}}\" wx:for-item=\"arr\">
<cover-view bindtap=\"func__4\" data-e-func__4-so=\"this\" data-e-func__4-a-a=\"{{b1}}\">
<cover-view bindtap=\"funPrivate4\" data-e-funPrivate4-so=\"this\" data-e-funPrivate4-a-a=\"{{b1}}\">
<block wx:if=\"{{b2}}\">
<map bindtap=\"func__5\" data-e-func__5-so=\"this\" data-e-func__5-a-a=\"{{b2}}\"></map>
<map bindtap=\"funPrivate5\" data-e-funPrivate5-so=\"this\" data-e-funPrivate5-a-a=\"{{b2}}\"></map>
</block>
<text></text>
<cover-view>
Expand Down Expand Up @@ -1844,9 +1844,9 @@ describe('loop', () => {
<block>
<view>
<block wx:if=\"{{b1}}\" wx:for=\"{{array}}\" wx:for-item=\"arr\">
<cover-view bindtap=\"func__6\" data-e-func__6-so=\"this\" data-e-func__6-a-a=\"{{b1}}\">
<cover-view bindtap=\"funPrivate6\" data-e-funPrivate6-so=\"this\" data-e-funPrivate6-a-a=\"{{b1}}\">
<block wx:if=\"{{b2}}\">
<map bindtap=\"func__7\" data-e-func__7-so=\"this\" data-e-func__7-a-a=\"{{b2}}\"></map>
<map bindtap=\"funPrivate7\" data-e-funPrivate7-so=\"this\" data-e-funPrivate7-a-a=\"{{b2}}\"></map>
</block>
<text></text>
<cover-view>
Expand All @@ -1856,7 +1856,7 @@ describe('loop', () => {
</block>
</cover-view>
<block wx:if=\"{{b3}}\">
<progress bindtap=\"func__8\" data-e-func__8-so=\"this\" data-e-func__8-a-a=\"{{b2}}\"></progress>
<progress bindtap=\"funPrivate8\" data-e-funPrivate8-so=\"this\" data-e-funPrivate8-a-a=\"{{b2}}\"></progress>
</block>
</cover-view>
</block>
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-transformer-wx/src/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ class Transformer {
const funcName = hasMethodName
? this.anonymousMethod.get(methodName)!
// 测试时使用1个稳定的 uniqueID 便于测试,实际使用5个英文字母,否则小程序不支持
: process.env.NODE_ENV === 'test' ? uniqueId('func__') : `func__${createRandomLetters(5)}`
: process.env.NODE_ENV === 'test' ? uniqueId('funPrivate') : `funPrivate${createRandomLetters(5)}`
this.anonymousMethod.set(methodName, funcName)
const newVal = isBind
? t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier(funcName)), t.identifier('bind')), expr.arguments || [])
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-weapp/src/create-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isEmptyObject, noop } from './util'
import { updateComponent } from './lifecycle'
import { cacheDataSet, cacheDataGet, cacheDataHas } from './data-cache'
const privatePropValName = '__triggerObserer'
const anonymousFnNamePreffix = 'func__'
const anonymousFnNamePreffix = 'funPrivate'
const componentFnReg = /^__fn_/
const routerParamsPrivateKey = '__key_'
const preloadPrivateKey = '__preload_'
Expand Down

0 comments on commit 86e01b9

Please sign in to comment.