Use dart.tool.dart2wasm in json.dart so DDC uses json_web.dart (#1108)
diff --git a/protobuf/CHANGELOG.md b/protobuf/CHANGELOG.md index 235bf31..421bb44 100644 --- a/protobuf/CHANGELOG.md +++ b/protobuf/CHANGELOG.md
@@ -1,3 +1,7 @@ +## 6.1.1-wip + +* Use `json_web.dart` on DDC (`dartdevc`) in addition to `dart2js`. + ## 6.1.0 * Make `BuilderInfo` methods accept `GeneratedMessage Function()` typed
diff --git a/protobuf/lib/src/protobuf/internal.dart b/protobuf/lib/src/protobuf/internal.dart index 6667afb..2f993e1 100644 --- a/protobuf/lib/src/protobuf/internal.dart +++ b/protobuf/lib/src/protobuf/internal.dart
@@ -26,7 +26,7 @@ import 'type_registry.dart'; import 'utils.dart'; -export 'annotations.dart' show TagNumber, GrpcServiceName; +export 'annotations.dart' show GrpcServiceName, TagNumber; export 'exceptions.dart' show InvalidProtocolBufferException; export 'pb_list.dart' show PbList; export 'pb_map.dart' show PbMap;
diff --git a/protobuf/lib/src/protobuf/json/json.dart b/protobuf/lib/src/protobuf/json/json.dart index 3b52bbc..d335e6d 100644 --- a/protobuf/lib/src/protobuf/json/json.dart +++ b/protobuf/lib/src/protobuf/json/json.dart
@@ -14,11 +14,15 @@ import 'json_vm.dart' as vm; import 'json_vm.dart' if (dart.library.js_interop) 'json_web.dart' as web; -// Use json_vm.dart with VM and dart2wasm, json_web.dart with dart2js. +// Use json_vm.dart with VM and dart2wasm, json_web.dart with dart2js and ddc. // json_web.dart uses JS interop for parsing, and JS interop is too slow on // Wasm. VM's patch performs better in Wasm. +const _useWebJson = + bool.fromEnvironment('dart.library.js_interop') && + !bool.fromEnvironment('dart.tool.dart2wasm'); + String writeToJsonString(FieldSet fs) { - if (const bool.fromEnvironment('dart.tool.dart2js')) { + if (_useWebJson) { return web.writeToJsonString(fs); } else { return vm.writeToJsonString(fs); @@ -31,7 +35,7 @@ String json, ExtensionRegistry? registry, ) { - if (const bool.fromEnvironment('dart.tool.dart2js')) { + if (_useWebJson) { web.mergeFromJsonString(fs, json, registry); } else { vm.mergeFromJsonString(fs, json, registry);
diff --git a/protobuf/pubspec.yaml b/protobuf/pubspec.yaml index e614c04..a142fdf 100644 --- a/protobuf/pubspec.yaml +++ b/protobuf/pubspec.yaml
@@ -1,5 +1,5 @@ name: protobuf -version: 6.1.0 +version: 6.1.1-wip description: >- Runtime library for protocol buffers support. Use with package:protoc_plugin to generate Dart code for your '.proto' files.