ifStatement function

Expression ifStatement(
  1. Expression expression, {
  2. ({Expression cse, Expression? when})? pattern,
  3. Code? body,
})

Implementation

Expression ifStatement(
  Expression expression, {
  ({Expression cse, Expression? when})? pattern,
  Code? body,
}) {
  return CodeExpression(
    Block.of([
      const Code('if ('),
      expression.code,
      if (pattern != null)
        Block.of([
          const Code(' case '),
          pattern.cse.code,
          if (pattern.when case final whn?) ...[
            const Code(' when '),
            whn.code,
          ],
        ]),
      const Code(') {'),
      if (body case final body?) body,
      const Code('}'),
    ]),
  );
}