Open rocketnik opened 2 years ago
Here is another crash in line 21 in typeName.
:
{% macro customTypes %}
class Timestamp {
}
class Category {
}
class ClosedRange<Range> {
}
{% endmacro %}
{% macro qualifiedName name %}{% typed name as String %}{{ name | split:"."| join:"" }}{% endmacro %}
{% macro convertPrimitiveTypeName typeName %}{% typed typeName as TypeName %}{% if typeName.name == "Bool" %}bool{% elif typeName.name == "Int"%}int{% elif typeName.name == "Float"%}double{% else %}{% call qualifiedName typeName.name %}{% endif %}{% endmacro %}
{% macro convertTypeName typeName %}{% typed typeName as TypeName %}{% if typeName.isOptional %}Option<{% call convertTypeName typeName. %}>{% elif typeName.isDictionary %}IMap<{% call convertTypeName typeName.dictionary.keyTypeName %}, {% call convertTypeName typeName.dictionary.valueTypeName %}>{% elif typeName.isArray %}List<{% call convertTypeName typeName.array.elementTypeName %}>{% else %}{% call convertPrimitiveTypeName typeName %}{% endif %}{% endmacro %}
{% macro convertType type %}{% typed type as Enum %}{# Enum seems to by subclass of Type and we don't seem to need functionality of Class/Struct subclass #}
{% if type.kind == "struct" %}
class {% call qualifiedName type.name %} {
{% for ivar in type.variables | !computed %}
final {% call convertTypeName ivar.typeName %} _{{ ivar.name }};
{% endfor %}
{% call qualifiedName type.name %}({% for ivar in type.variables | !computed %}this._{{ ivar.name }}{% if not forloop.last %}, {% endif %}{% endfor %});
{% call qualifiedName type.name %} copy({ {% for ivar in type.variables | !computed %}{% call convertTypeName ivar.typeName %}? {{ ivar.name }}{% if not forloop.last %}, {% endif %}{% endfor %}}) => {% call qualifiedName type.name %}({% for ivar in type.variables | !computed %}{{ ivar.name }} ?? _{{ ivar.name }}{% if not forloop.last %}, {% endif %}{% endfor %});
@override String toString() => "{% call qualifiedName type.name %}({% for ivar in type.variables | !computed %}{{ ivar.name }} = $_{{ ivar.name }}{% if not forloop.last %}, {% endif %}{% endfor %})";
}
{% elif type.kind == "enum" %}
{% if type.cases.count != 0 %}{# don't generate empty enums #}
enum {% call qualifiedName type.name %} {
{% for case in type.cases %}
{{ case.name }}{% if not forloop.last %},{% endif %}
{% endfor %}
}
{% endif %}
{% elif type.kind == "extension" %}
// extension {% call qualifiedName type.name %} {
{% for var in type.variables %}
// var {{ var.name }}: {{ var.typeName }}
{% endfor %}
// }
{% else %}
// todo: unknown type {% call qualifiedName type.name %}: {{ type.kind }} with content {{ type }}
{% endif %}
{% endmacro %}
// Generated {% now %}
import 'package:dartz/dartz.dart';
{% call customTypes %}
{% for type in types.all where type.name != "Category" %}
{% call convertType type %}
{% endfor %}
// static final title = lensS<Article, String>((article) => article._title, (article, title) => article.copy(title: title));
// static final sections = lensS<Article, IMap<String, Section>>((article) => article._sections, (article, sections) => article.copy(sections: sections));
// static final section = (String id) => sections.andThenE<Section, String>(imapLensE(id, () => "No section '$id'"));
{% newline %}
The following code crashes when typing
ivar
in{% call convertType ivar %}
- of course I was not finished typing. I wanted to type{% call convertType ivar.typeName %}
, but code generation crashed as soon as ivar was entered - it is of the wrong type of course.