Skip to content

Commit

Permalink
do inline function body parsing in config
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgrain committed Dec 16, 2024
1 parent 9e81af4 commit 65060f2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/aws-cdk/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,11 @@ export class DynamicValue {
}

public static fromInline(f: () => any): DynamicResult {
const ARROW = '=>';
const body = f.toString();
return {
dynamicType: 'function',
dynamicValue: f.toString(),
dynamicValue: body.substring(body.indexOf(ARROW) + ARROW.length).trim(),
};
}
}
4 changes: 1 addition & 3 deletions tools/@aws-cdk/yargs-gen/lib/yargs-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ function makeOptions(prefix: Expression, options: { [optionName: string]: CliOpt
optionArgs[optionProp] = code.expr.ident(optionValue.dynamicValue);
} else if (optionValue && optionValue.dynamicType === 'function') {
const inlineFunction: string = optionValue.dynamicValue;
const NUMBER_OF_SPACES_BETWEEN_ARROW_AND_CODE = 3;
// this only works with arrow functions, like () =>
optionArgs[optionProp] = code.expr.directCode(inlineFunction.substring(inlineFunction.indexOf('=>') + NUMBER_OF_SPACES_BETWEEN_ARROW_AND_CODE));
optionArgs[optionProp] = code.expr.directCode(inlineFunction);
} else {
optionArgs[optionProp] = lit(optionValue);
}
Expand Down

0 comments on commit 65060f2

Please sign in to comment.