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 | 1x 1x | import ts from 'typescript';
import type { RenderWhenPropMatch } from '@fds-uif/generator-base';
/**
* Build a getter accessor for a `renderWhen: { prop, eq }` expression.
*
* Output shape:
* ```ts
* get isIconPositionRight() {
* return this.iconPosition === 'right';
* }
* ```
*/
export function createRenderWhenGetter(
getterName: string,
match: RenderWhenPropMatch,
): ts.GetAccessorDeclaration {
const cmp = ts.factory.createBinaryExpression(
ts.factory.createPropertyAccessExpression(
ts.factory.createThis(),
ts.factory.createIdentifier(match.prop),
),
ts.SyntaxKind.EqualsEqualsEqualsToken,
ts.factory.createStringLiteral(match.eq),
);
return ts.factory.createGetAccessorDeclaration(
undefined,
ts.factory.createIdentifier(getterName),
[],
undefined,
ts.factory.createBlock([ts.factory.createReturnStatement(cmp)], true),
);
}
|