fix: should check isCustomElement (#431)

* fix: respect isCustomElement

* chore: yarn lint
This commit is contained in:
fxy060608 2021-05-14 20:18:27 +08:00 committed by GitHub
parent 77ed541aa3
commit 117b25a56a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -46,7 +46,7 @@ const getJSXAttributeValue = (
const buildProps = (path: NodePath<t.JSXElement>, state: State) => { const buildProps = (path: NodePath<t.JSXElement>, state: State) => {
const tag = getTag(path, state); const tag = getTag(path, state);
const isComponent = checkIsComponent(path.get('openingElement')); const isComponent = checkIsComponent(path.get('openingElement'), state);
const props = path.get('openingElement').get('attributes'); const props = path.get('openingElement').get('attributes');
const directives: t.ArrayExpression[] = []; const directives: t.ArrayExpression[] = [];
const dynamicPropNames = new Set<string>(); const dynamicPropNames = new Set<string>();

View File

@ -41,7 +41,7 @@ export const shouldTransformedToSlots = (tag: string) => !(tag.endsWith(FRAGMENT
* @param path JSXOpeningElement * @param path JSXOpeningElement
* @returns boolean * @returns boolean
*/ */
export const checkIsComponent = (path: NodePath<t.JSXOpeningElement>): boolean => { export const checkIsComponent = (path: NodePath<t.JSXOpeningElement>, state: State): boolean => {
const namePath = path.get('name'); const namePath = path.get('name');
if (namePath.isJSXMemberExpression()) { if (namePath.isJSXMemberExpression()) {
@ -50,6 +50,10 @@ export const checkIsComponent = (path: NodePath<t.JSXOpeningElement>): boolean =
const tag = (namePath as NodePath<t.JSXIdentifier>).node.name; const tag = (namePath as NodePath<t.JSXIdentifier>).node.name;
if (state.opts.isCustomElement && state.opts.isCustomElement(tag)) {
return false;
}
return shouldTransformedToSlots(tag) && !htmlTags.includes(tag) && !svgTags.includes(tag); return shouldTransformedToSlots(tag) && !htmlTags.includes(tag) && !svgTags.includes(tag);
}; };