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

0% Statements 0/2
100% Branches 0/0
0% Functions 0/1
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 31                                                             
import { factory, SyntaxKind, type TypeNode, type Block } from '../utils/ts7.js';
import type { PropertyDeclaration } from '@typescript/native/unstable/ast';
 
export function createGetterProperty(
  propertyName: string,
  returnType: TypeNode,
  body: Block,
): PropertyDeclaration {
  // Create the getter method signature (name, parameters, return type)
  const getterSignature = factory.createGetAccessorDeclaration(
    undefined, // modifiers (e.g., public, private)
    factory.createIdentifier(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 factory.createPropertyDeclaration(
    [factory.createModifier(SyntaxKind.PublicKeyword)], // Modifiers
    factory.createIdentifier(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)
  );
}