Skip to content

Commit

Permalink
Merge pull request #67 from narumincho/list-spread
Browse files Browse the repository at this point in the history
add List spread
  • Loading branch information
narumincho authored Jan 20, 2024
2 parents b1d1c86 + e3675b3 commit f43d875
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions packages/simple_dart_code_gen/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.0

- add List spread

## 0.5.4

- add PatternObject
Expand Down
14 changes: 9 additions & 5 deletions packages/simple_dart_code_gen/lib/simple_dart_code_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ final class ClassDeclaration implements Declaration {
positionalArguments: useHashAll
? IList([
ExprListLiteral(IList(fields.map(
(field) => ExprVariable(field.name),
(field) =>
(ExprVariable(field.name), spread: false),
)))
])
: IList(fields.map(
Expand Down Expand Up @@ -1113,17 +1114,20 @@ final class ExprLambda implements Expr {
@immutable
final class ExprListLiteral implements Expr {
const ExprListLiteral(this.items);
final IList<Expr> items;
final IList<(Expr expr, {bool spread})> items;

@override
CodeAndConstType toCodeAndConstType() {
final codeAndConstTypeIter = items.map((item) => item.toCodeAndConstType());
final isAllConst = codeAndConstTypeIter.every((item) => item.isConst());
final codeAndConstTypeIter = items
.map((item) => (item.$1.toCodeAndConstType(), spread: item.spread));
final isAllConst = codeAndConstTypeIter.every((item) => item.$1.isConst());
return CodeAndConstType(
'[' +
stringListJoinWithComma(
IList(codeAndConstTypeIter.map(
(item) => item.toCodeString(!isAllConst),
(item) =>
(item.spread ? '...' : '') +
item.$1.toCodeString(!isAllConst),
)),
) +
']',
Expand Down
2 changes: 1 addition & 1 deletion packages/simple_dart_code_gen/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: simple_dart_code_gen
description: simple_dart_code_gen
repository: https://github.com/narumincho/dart-packages/tree/main/packages/simple_dart_code_gen
version: "0.5.4"
version: "0.6.0"
environment:
sdk: ">=3.2.0 <4.0.0"
dependencies:
Expand Down

0 comments on commit f43d875

Please sign in to comment.