Skip to content

Commit aca8409

Browse files
authored
fix(tools): don't export react wrapper for non-exported class (#2775)
1 parent 83a433b commit aca8409

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

.changeset/healthy-clocks-laugh.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@patternfly/pfe-tools": patch
3+
---
4+
5+
**React**: ensure that only classes which are exported get wrapped

tools/pfe-tools/react/generate-wrappers.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ function isCustomElementDeclaration(
2222
return !!(declaration as CEM.CustomElementDeclaration).customElement;
2323
}
2424

25+
function isExported(exports: CEM.Export[] | undefined) {
26+
return function(declaration: CEM.Declaration): boolean {
27+
return !!exports?.some(exp => exp.kind === 'js' && exp.declaration.name === declaration.name);
28+
};
29+
}
30+
2531
/** Remove a prefix from a class name */
2632
function getDeprefixedClassName(className: string, prefix: string) {
2733
const [fst, ...tail] = className.replace(prefix, '');
@@ -80,10 +86,10 @@ function genJavascriptModule(module: CEM.Module, pkgName: string, data: ReactWra
8086
return javascript`// ${module.path}
8187
import { createComponent } from '@lit/react';
8288
import react from 'react';${data.map(x => javascript`
83-
import { ${x.Class} as elementClass } from '${pkgName}/${module.path}';`).join('')}${data.map(x => javascript`
89+
import { ${x.Class} } from '${pkgName}/${module.path}';`).join('')}${data.map(x => javascript`
8490
export const ${x.reactComponentName} = createComponent({
8591
tagName: '${x.tagName}',
86-
elementClass,
92+
elementClass: ${x.Class},
8793
react,
8894
events: ${x.eventsMap},
8995
});`).join('\n')}
@@ -106,6 +112,7 @@ function genWrapperModules(
106112
) {
107113
const data: ReactWrapperData[] = (module.declarations ?? [])
108114
.filter(isCustomElementDeclaration)
115+
.filter(isExported(module.exports))
109116
.map(getReactWrapperData(module, classPrefix, elPrefix));
110117
const js = genJavascriptModule(module, pkgName, data);
111118
const ts = genTypescriptModule(module, pkgName, data);

0 commit comments

Comments
 (0)