All files / packages/fds-uif/generator-lwc/src/blocks createPropertyGetter.ts

0% Statements 0/2
100% Branches 0/0
100% Functions 0/0
0% Lines 0/2

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                                                           
import ts from 'typescript';
 
export function createGetterProperty(
    propertyName: string,
    returnType: ts.TypeNode,
    body: ts.Block
): ts.PropertyDeclaration {
    // Create the getter method signature (name, parameters, return type)
    const getterSignature = ts.factory.createGetAccessorDeclaration(
        undefined, // modifiers (e.g., public, private)
        propertyName,
        [], // parameters (empty for getter)
        returnType,
        body // method body
    );
 
    // Create the property declaration for the getter
    // Although we use get accessor, we create it as a property for consistency
    // in some API usages, though the getter itself defines the accessor.
    // A more direct way to get the accessor is `createGetAccessorDeclaration`.
    // Let's use the accessor directly within the class members.
    return ts.factory.createPropertyDeclaration(
        [ts.factory.createModifier(ts.SyntaxKind.PublicKeyword)], // Modifiers
        propertyName, // Property name (will be the getter name)
        undefined, // Question token (not optional)
        returnType, // Type of the returned value
        undefined // Initial value (not needed for getter)
    );
}