Skip to content

Commit

Permalink
fix(alita-core): 修复 组件外层view 退化为block,引起的onLayout事件不调用
Browse files Browse the repository at this point in the history
affects: @areslabs/alita-core
  • Loading branch information
ykforerlang committed Apr 20, 2020
1 parent 3c32d90 commit ed8bc73
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/alita-core/src/tran/compOutElementToBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
*/
import {isRenderReturn, getOriginal} from '../util/uast'
import {isRenderReturn, getOriginal, getAttri} from '../util/uast'
import errorLogTraverse from '../util/ErrorLogTraverse'

/**
Expand All @@ -23,6 +23,7 @@ export default function compOutElementToBlock (ast, info) {
&& path.node.name.name === 'view'
&& getOriginal(path) // 没有origial属性的view,可能是直接使用的小程序内置组件,这个时候view可能有其他属性,故无法转化为block
&& isRenderReturn(path)
&& !getAttri(path, 'onLayout') // 有onLayout属性的,无法转化为block
) {
path.node.name.name = 'block'

Expand Down
19 changes: 16 additions & 3 deletions packages/alita-core/src/util/uast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,27 @@ export function isRenderReturn(path) {
* @returns {any}
*/
export function getOriginal(path) {
const attr = getAttri(path, 'original')
if (attr) {
return attr.value.value
}
return ''
}

/**
* 获取JSXElement的属性
* @param path
* @param name
* @returns {any}
*/
export function getAttri(path, name) {
const attris = path.node.attributes
for (let i = 0; i< attris.length; i ++) {
const item = attris[i]
if (item.type === 'JSXAttribute' && item.name.name === 'original') {
return item.value.value
if (item.type === 'JSXAttribute' && item.name.name === name) {
return item
}
}
return ''
}

/**
Expand Down

0 comments on commit ed8bc73

Please sign in to comment.