From ed8bc73b859d03cff563c1e9840f57165344cb8d Mon Sep 17 00:00:00 2001 From: ykforerlang <1527997464@qq.com> Date: Mon, 20 Apr 2020 10:32:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(alita-core):=20=E4=BF=AE=E5=A4=8D=20?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=A4=96=E5=B1=82view=20=E9=80=80=E5=8C=96?= =?UTF-8?q?=E4=B8=BAblock=EF=BC=8C=E5=BC=95=E8=B5=B7=E7=9A=84onLayout?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E4=B8=8D=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit affects: @areslabs/alita-core --- .../src/tran/compOutElementToBlock.js | 3 ++- packages/alita-core/src/util/uast.ts | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/alita-core/src/tran/compOutElementToBlock.js b/packages/alita-core/src/tran/compOutElementToBlock.js index 288e25b..69a3885 100644 --- a/packages/alita-core/src/tran/compOutElementToBlock.js +++ b/packages/alita-core/src/tran/compOutElementToBlock.js @@ -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' /** @@ -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' diff --git a/packages/alita-core/src/util/uast.ts b/packages/alita-core/src/util/uast.ts index 877403d..41121a5 100644 --- a/packages/alita-core/src/util/uast.ts +++ b/packages/alita-core/src/util/uast.ts @@ -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 '' } /**