diff --git a/packages/alita-core/src/tran/addTempName.js b/packages/alita-core/src/tran/addTempName.js index bb33758..396492b 100644 --- a/packages/alita-core/src/tran/addTempName.js +++ b/packages/alita-core/src/tran/addTempName.js @@ -11,12 +11,12 @@ import * as t from "@babel/types" import {InnerTemplateNamePrefix} from "../constants"; import {isJSXChild, isChildCompChild} from "../util/uast"; import {geneOrder} from '../util/util' -export default function addTempName (ast) { +export default function addTempName (ast, info) { const go = geneOrder() errorLogTraverse(ast, { exit: path => { if (path.type === 'JSXElement' - && (!isJSXChild(path) || isChildCompChild(path)) + && (!isJSXChild(path) || isChildCompChild(path, info.filepath)) ) { const jsxOp = path.node.openingElement diff --git a/packages/alita-core/src/tran/childrenToTemplate.js b/packages/alita-core/src/tran/childrenToTemplate.js index eda02cb..463bb33 100644 --- a/packages/alita-core/src/tran/childrenToTemplate.js +++ b/packages/alita-core/src/tran/childrenToTemplate.js @@ -98,7 +98,7 @@ export default function childrenToTemplate(ast, info) { exit: path => { if (path.type === 'JSXElement' - && !isChildComp(path.node.openingElement.name.name) + && !isChildComp(path.node.openingElement.name.name, info.filepath) ) { const children = path.node.children let tempName = null//`${ChildTemplateNamePrefix}${goForCTNP.next}` diff --git a/packages/alita-core/src/tran/cptCompHandler.js b/packages/alita-core/src/tran/cptCompHandler.js index 589662a..21d7c9e 100644 --- a/packages/alita-core/src/tran/cptCompHandler.js +++ b/packages/alita-core/src/tran/cptCompHandler.js @@ -257,7 +257,7 @@ export default function cptCompHandler (ast, info) { } if (path.type === 'JSXElement' - && isChildComp(path.node.openingElement.name.name) + && isChildComp(path.node.openingElement.name.name, info.filepath) && path.node.children.length > 0 ) { const pe = path.node.openingElement diff --git a/packages/alita-core/src/tran/geneAllTemplate.js b/packages/alita-core/src/tran/geneAllTemplate.js index a74019b..e5e431b 100644 --- a/packages/alita-core/src/tran/geneAllTemplate.js +++ b/packages/alita-core/src/tran/geneAllTemplate.js @@ -140,7 +140,7 @@ export default function(ast, info) { if (path.type === 'JSXElement' - && isChildComp(path.node.openingElement.name.name) + && isChildComp(path.node.openingElement.name.name, info.filepath) ) { path.node.children = [] } @@ -156,7 +156,7 @@ export default function(ast, info) { * 若A是自定义组件,需要将其children转化为 generic:抽象节点的形式,传递出去,也需要提取为 tempName */ if (path.type === 'JSXElement' - && (!isJSXChild(path) || isChildCompChild(path)) + && (!isJSXChild(path) || isChildCompChild(path, info.filepath)) ) { const jsxOp = path.node.openingElement let tempName = '' diff --git a/packages/alita-core/src/util/uast.ts b/packages/alita-core/src/util/uast.ts index d809dc5..3fda311 100644 --- a/packages/alita-core/src/util/uast.ts +++ b/packages/alita-core/src/util/uast.ts @@ -12,6 +12,8 @@ import * as t from "@babel/types" import {allBaseComp, extChildComp} from './getAndStorecompInfos' import {wxBaseComp} from '../constants' +import {getModuleInfo} from './cacheModuleInfos' +import {judgeLibPath} from './util' import configure from '../configure' @@ -154,7 +156,7 @@ export function isJSXChild(path) { * @param name * @returns {boolean} */ -export function isChildComp(name) { +export function isChildComp(name, filepath) { if (wxBaseComp.has(name) || configure.configObj.miniprogramComponents[name]) return false // 基本组件children 需要转化为childrencpt的组件 @@ -162,8 +164,10 @@ export function isChildComp(name) { return true } + const {im} = getModuleInfo(filepath) // 基本组件children 不需要转化为childrencpt的组件 - if (allBaseComp.has(name)) { + // 通过组件名称判断还不够,还需要判断来源是否是组件库里 + if (allBaseComp.has(name) && judgeLibPath(im[name].source)) { return false } @@ -176,7 +180,7 @@ export function isChildComp(name) { * @param path * @returns {any} */ -export function isChildCompChild(path) { +export function isChildCompChild(path, filepath) { const jc = isJSXChild(path) if (!jc) return false @@ -184,7 +188,7 @@ export function isChildCompChild(path) { const name = parentElement.node.openingElement.name.name - return isChildComp(name) + return isChildComp(name, filepath) } /**