Skip to content

Commit

Permalink
feat: support isCustomElement
Browse files Browse the repository at this point in the history
  • Loading branch information
Amour1688 committed Jul 25, 2020
1 parent aa8dd8c commit a8710f8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/babel-plugin-jsx/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ module.exports = {
],
plugins: [
/* eslint-disable-next-line global-require */
[require('./dist/index.js'), { optimize: true }],
[require('./dist/index.js'), { optimize: true, isCustomElement: (tag) => /^x-/.test(tag) }],
],
};
1 change: 1 addition & 0 deletions packages/babel-plugin-jsx/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface Opts {
transformOn?: boolean;
compatibleProps?: boolean;
optimize?: boolean;
isCustomElement?: (tag: string) => boolean;
}

export type ExcludesBoolean = <T>(x: T | false | true) => x is T;
Expand Down
6 changes: 5 additions & 1 deletion packages/babel-plugin-jsx/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ const getTag = (
if (!htmlTags.includes(name) && !svgTags.includes(name)) {
return path.scope.hasBinding(name)
? t.identifier(name)
: t.callExpression(createIdentifier(state, 'resolveComponent'), [t.stringLiteral(name)]);
: (
state.opts.isCustomElement?.(name)
? t.stringLiteral(name)
: t.callExpression(createIdentifier(state, 'resolveComponent'), [t.stringLiteral(name)])
);
}

return t.stringLiteral(name);
Expand Down

0 comments on commit a8710f8

Please sign in to comment.