From bf6357ac83685f6883ee9351ebf9d20d5924fd79 Mon Sep 17 00:00:00 2001 From: Benny Powers Date: Sun, 16 Jun 2024 11:47:38 +0300 Subject: [PATCH] fix(tools): don't export react wrapper for non-exported class --- .changeset/healthy-clocks-laugh.md | 5 +++++ tools/pfe-tools/react/generate-wrappers.ts | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .changeset/healthy-clocks-laugh.md diff --git a/.changeset/healthy-clocks-laugh.md b/.changeset/healthy-clocks-laugh.md new file mode 100644 index 0000000000..0ae0d4d2df --- /dev/null +++ b/.changeset/healthy-clocks-laugh.md @@ -0,0 +1,5 @@ +--- +"@patternfly/pfe-tools": patch +--- + +**React**: ensure that only classes which are exported get wrapped diff --git a/tools/pfe-tools/react/generate-wrappers.ts b/tools/pfe-tools/react/generate-wrappers.ts index 29f69a66ad..86ac859847 100644 --- a/tools/pfe-tools/react/generate-wrappers.ts +++ b/tools/pfe-tools/react/generate-wrappers.ts @@ -22,6 +22,12 @@ function isCustomElementDeclaration( return !!(declaration as CEM.CustomElementDeclaration).customElement; } +function isExported(exports: CEM.Export[] | undefined) { + return function(declaration: CEM.Declaration): boolean { + return !!exports?.some(exp => exp.kind === 'js' && exp.declaration.name === declaration.name); + }; +} + /** Remove a prefix from a class name */ function getDeprefixedClassName(className: string, prefix: string) { const [fst, ...tail] = className.replace(prefix, ''); @@ -80,10 +86,10 @@ function genJavascriptModule(module: CEM.Module, pkgName: string, data: ReactWra return javascript`// ${module.path} import { createComponent } from '@lit/react'; import react from 'react';${data.map(x => javascript` -import { ${x.Class} as elementClass } from '${pkgName}/${module.path}';`).join('')}${data.map(x => javascript` +import { ${x.Class} } from '${pkgName}/${module.path}';`).join('')}${data.map(x => javascript` export const ${x.reactComponentName} = createComponent({ tagName: '${x.tagName}', - elementClass, + elementClass: ${x.Class}, react, events: ${x.eventsMap}, });`).join('\n')} @@ -106,6 +112,7 @@ function genWrapperModules( ) { const data: ReactWrapperData[] = (module.declarations ?? []) .filter(isCustomElementDeclaration) + .filter(isExported(module.exports)) .map(getReactWrapperData(module, classPrefix, elPrefix)); const js = genJavascriptModule(module, pkgName, data); const ts = genTypescriptModule(module, pkgName, data);