Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | 16x 16x 16x 16x 16x 67x 56x 56x 56x 67x 16x 16x 5x 16x 13x 16x 16x 20x 16x 16x 16x 16x 16x 16x | import { factory, SyntaxKind, printNodes, type ClassElement } from './utils/ts7.js';
import { PropMetadata, type ComponentMetadata } from '@fds-uif/generator-base';
import { createPropertyApi } from './blocks/createPropertyApi.js';
import { createLwcImportStatement } from './blocks/createLwcImportStatement.js';
import { createClassGetter } from './blocks/createClassGetter.js';
import { createRenderWhenGetter } from './blocks/createRenderWhenGetter.js';
import { buildClassGetterPlan } from './utils/classGetterPlan.js';
import { buildRenderWhenPlan } from './utils/renderWhenPlan.js';
function createComponentClass(metadata: ComponentMetadata) {
const className = metadata.name;
const baseClass = factory.createIdentifier('LightningElement');
const heritageClause = factory.createHeritageClause(SyntaxKind.ExtendsKeyword, [
factory.createExpressionWithTypeArguments(baseClass, []),
]);
const classBody = [] as ClassElement[];
metadata.props.forEach((prop: PropMetadata) => {
if (prop.source !== 'slot') {
const api = createPropertyApi(prop.name, prop.type, prop.default);
Eif (api) {
classBody.push(api);
}
}
});
const propNames = new Set(metadata.props.filter((p) => p.source !== 'slot').map((p) => p.name));
const classPlan = buildClassGetterPlan(metadata);
if (classPlan.rootGetterName) {
classBody.push(createClassGetter(classPlan.rootGetterName, classPlan.rootRules, propNames));
}
for (const { name, rules } of classPlan.nodes.values()) {
classBody.push(createClassGetter(name, rules, propNames));
}
const rwPlan = buildRenderWhenPlan(metadata);
for (const g of rwPlan.getters) {
classBody.push(createRenderWhenGetter(g.name, g.match));
}
const classDeclaration = factory.createClassDeclaration(
[factory.createModifier(SyntaxKind.ExportKeyword), factory.createModifier(SyntaxKind.DefaultKeyword)],
factory.createIdentifier(className),
undefined,
[heritageClause],
classBody,
);
return classDeclaration;
}
export function generateClass(metadata: ComponentMetadata): string {
const lwcImportStatement = createLwcImportStatement(metadata);
const lwcComponentClass = createComponentClass(metadata);
try {
return printNodes([lwcImportStatement, lwcComponentClass]);
} catch (error) {
console.log(error);
throw error;
}
}
|