parseKeyValuePair method Null safety

KeyValuePair? parseKeyValuePair()

Implementation

KeyValuePair? parseKeyValuePair() {
  var key = parseExpression(0);
  if (key == null) return null;

  if (!next(TokenType.colon)) return KeyValuePair(key, null, null);

  var colon = _current, value = parseExpression(0) as Token?;

  if (value == null) {
    errors.add(JaelError(JaelErrorSeverity.error,
        'Missing expression in key-value pair.', colon.span));
    return null;
  }

  return KeyValuePair(key, colon, value as Expression);
}