Skip to content

Commit

Permalink
fix empty constructor contains {} bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ebwood committed Mar 11, 2024
1 parent 3b4e842 commit d8e69c3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
9 changes: 8 additions & 1 deletion packages/rfw2txt/lib/rfw2txt.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import 'dart:typed_data';

import 'package:collection/collection.dart';
import 'package:rfw/formats.dart';
import 'package:rfw2txt/rwl2json.dart';
import 'package:rfw2txt/rwl2txt.dart';

// Parse .rfw to .rfwtxt
String rfw2txt(Uint8List bytes) {
RemoteWidgetLibrary rwl = decodeLibraryBlob(bytes);
return rwl2txt(rwl);
String output = rwl2txt(rwl);
if (ListEquality()
.equals(bytes, encodeLibraryBlob(parseLibraryFile(output))) ==
false) {
throw Exception('rfw2txt failed');
}
return output;
}

// Parse .rfw to json
Expand Down
13 changes: 9 additions & 4 deletions packages/rfw2txt/lib/rwl2txt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class TxtVisitor {
buffer.writeln();
// write widget declarations
for (var element in library.widgets) {
buffer.writeln(_visitWidgetDeclaration(element));
buffer.write(_visitWidgetDeclaration(element));
buffer.write('\n\n');
}
return buffer.toString();
}
Expand Down Expand Up @@ -87,9 +88,13 @@ class TxtVisitor {
StringBuffer buffer = StringBuffer();
if (node is ConstructorCall) {
// ConstructorCall ignore arguments' curly braces
buffer.write('${node.name}(\n');
buffer.write(_visitDynamicMap(node.arguments, withoutCurlyBraces: true));
buffer.write(_leadingIndent);
buffer.write('${node.name}(');
if (node.arguments.isNotEmpty) {
buffer.write('\n');
buffer
.write(_visitDynamicMap(node.arguments, withoutCurlyBraces: true));
buffer.write(_leadingIndent);
}
buffer.write(')');
} else if (node is Switch) {
buffer.write('switch ');
Expand Down
2 changes: 2 additions & 0 deletions packages/rfw2txt/test/match.rfwtxt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import core.widgets;
import core.material;

widget Empty = Container();

widget Counter = Container(
color: 0xFF66AACC,
child: Center(
Expand Down
4 changes: 2 additions & 2 deletions packages/rfw2txt/test/rfw2txt_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ void main() {

test('rfw2txt with output path', () async {
Process process = await Process.start('dart',
['run', 'bin/rfw2txt.dart', "test/test.rfw", "-o", "test.rfwtxt"]);
['run', 'bin/rfw2txt.dart', "test/test.rfw", "-o", "output.rfwtxt"]);
await process.stdout.transform(utf8.decoder).forEach(print);
await process.stderr.transform(utf8.decoder).forEach(print);
File matchFile = File('test/test.rfw');
File outputTxtFile = File('test.rfwtxt');
File outputTxtFile = File('output.rfwtxt');
File outputFile = File('output.rfw');
outputFile.writeAsBytesSync(
encodeLibraryBlob(parseLibraryFile(outputTxtFile.readAsStringSync())));
Expand Down
Binary file modified packages/rfw2txt/test/test.rfw
Binary file not shown.

0 comments on commit d8e69c3

Please sign in to comment.