diff --git a/pkg/_macros/CHANGELOG.md b/pkg/_macros/CHANGELOG.md index e336684afc2e..0b802bc6fb3a 100644 --- a/pkg/_macros/CHANGELOG.md +++ b/pkg/_macros/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.3 + +- Validate parts in `Code.fromParts()`. + ## 0.1.2 - Add caching for `typeDeclarationOf` results. diff --git a/pkg/_macros/lib/src/api/code.dart b/pkg/_macros/lib/src/api/code.dart index 4b7ec6543816..8d2ca664a55f 100644 --- a/pkg/_macros/lib/src/api/code.dart +++ b/pkg/_macros/lib/src/api/code.dart @@ -17,9 +17,18 @@ sealed class Code { Code.fromString(String code) : parts = [code]; - Code.fromParts(this.parts) - : assert(parts.every((element) => - element is String || element is Code || element is Identifier)); + Code.fromParts(this.parts) { + for (final part in parts) { + switch (part) { + case Code(): + case Identifier(): + case String(): + break; // OK + default: + throw StateError('Unrecognized code part ${part.runtimeType}'); + } + } + } } /// An arbitrary chunk of code, which does not have to be syntactically valid diff --git a/pkg/_macros/pubspec.yaml b/pkg/_macros/pubspec.yaml index 2badb8ccaeef..661a4523ba8d 100644 --- a/pkg/_macros/pubspec.yaml +++ b/pkg/_macros/pubspec.yaml @@ -1,5 +1,5 @@ name: _macros -version: 0.1.2 +version: 0.1.3 description: >- This is a private SDK vendored package, which is re-exported by the public `macros` package, which is a pub package. Every change to this package is diff --git a/pkg/front_end/testcases/incremental/macro_change_entry_one.yaml.world.1.expect b/pkg/front_end/testcases/incremental/macro_change_entry_one.yaml.world.1.expect index 04dcec101301..b5952f23c7e4 100644 --- a/pkg/front_end/testcases/incremental/macro_change_entry_one.yaml.world.1.expect +++ b/pkg/front_end/testcases/incremental/macro_change_entry_one.yaml.world.1.expect @@ -49,7 +49,7 @@ holepunch:pkg/_macros/lib/src/api/builders.dart: - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart) holepunch:pkg/_macros/lib/src/api/code.dart: -- CodeKind. (from holepunch:pkg/_macros/lib/src/api/code.dart:460:6) +- CodeKind. (from holepunch:pkg/_macros/lib/src/api/code.dart:469:6) - _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart) - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart) diff --git a/pkg/front_end/testcases/incremental/macro_change_entry_one.yaml.world.2.expect b/pkg/front_end/testcases/incremental/macro_change_entry_one.yaml.world.2.expect index e05c18459e71..0c95abe7b48c 100644 --- a/pkg/front_end/testcases/incremental/macro_change_entry_one.yaml.world.2.expect +++ b/pkg/front_end/testcases/incremental/macro_change_entry_one.yaml.world.2.expect @@ -36,7 +36,7 @@ holepunch:pkg/_macros/lib/src/api/builders.dart: - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart) holepunch:pkg/_macros/lib/src/api/code.dart: -- CodeKind. (from holepunch:pkg/_macros/lib/src/api/code.dart:460:6) +- CodeKind. (from holepunch:pkg/_macros/lib/src/api/code.dart:469:6) - _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart) - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart) diff --git a/pkg/front_end/testcases/incremental/macro_change_entry_two.yaml.world.1.expect b/pkg/front_end/testcases/incremental/macro_change_entry_two.yaml.world.1.expect index 49a6727ddfe4..371c8d87a291 100644 --- a/pkg/front_end/testcases/incremental/macro_change_entry_two.yaml.world.1.expect +++ b/pkg/front_end/testcases/incremental/macro_change_entry_two.yaml.world.1.expect @@ -49,7 +49,7 @@ holepunch:pkg/_macros/lib/src/api/builders.dart: - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart) holepunch:pkg/_macros/lib/src/api/code.dart: -- CodeKind. (from holepunch:pkg/_macros/lib/src/api/code.dart:460:6) +- CodeKind. (from holepunch:pkg/_macros/lib/src/api/code.dart:469:6) - _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart) - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart) diff --git a/pkg/front_end/testcases/incremental/macro_change_entry_two.yaml.world.2.expect b/pkg/front_end/testcases/incremental/macro_change_entry_two.yaml.world.2.expect index e96d5466b829..0617fd38c4dc 100644 --- a/pkg/front_end/testcases/incremental/macro_change_entry_two.yaml.world.2.expect +++ b/pkg/front_end/testcases/incremental/macro_change_entry_two.yaml.world.2.expect @@ -45,7 +45,7 @@ holepunch:pkg/_macros/lib/src/api/builders.dart: - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart) holepunch:pkg/_macros/lib/src/api/code.dart: -- CodeKind. (from holepunch:pkg/_macros/lib/src/api/code.dart:460:6) +- CodeKind. (from holepunch:pkg/_macros/lib/src/api/code.dart:469:6) - _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart) - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart) diff --git a/pkg/front_end/testcases/incremental/macro_change_nestedness.yaml.world.1.expect b/pkg/front_end/testcases/incremental/macro_change_nestedness.yaml.world.1.expect index f737654d3f98..bd3d21dffef0 100644 --- a/pkg/front_end/testcases/incremental/macro_change_nestedness.yaml.world.1.expect +++ b/pkg/front_end/testcases/incremental/macro_change_nestedness.yaml.world.1.expect @@ -69,7 +69,7 @@ holepunch:pkg/_macros/lib/src/api/builders.dart: - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart) holepunch:pkg/_macros/lib/src/api/code.dart: -- CodeKind. (from holepunch:pkg/_macros/lib/src/api/code.dart:460:6) +- CodeKind. (from holepunch:pkg/_macros/lib/src/api/code.dart:469:6) - _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart) - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart) diff --git a/pkg/front_end/testcases/incremental/macro_change_nestedness.yaml.world.2.expect b/pkg/front_end/testcases/incremental/macro_change_nestedness.yaml.world.2.expect index 811e0c30fc18..c7b0d2e1bdcb 100644 --- a/pkg/front_end/testcases/incremental/macro_change_nestedness.yaml.world.2.expect +++ b/pkg/front_end/testcases/incremental/macro_change_nestedness.yaml.world.2.expect @@ -84,7 +84,7 @@ holepunch:pkg/_macros/lib/src/api/builders.dart: - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart) holepunch:pkg/_macros/lib/src/api/code.dart: -- CodeKind. (from holepunch:pkg/_macros/lib/src/api/code.dart:460:6) +- CodeKind. (from holepunch:pkg/_macros/lib/src/api/code.dart:469:6) - _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart) - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart) diff --git a/pkg/front_end/testcases/incremental/macro_recompile.yaml.world.1.expect b/pkg/front_end/testcases/incremental/macro_recompile.yaml.world.1.expect index f737654d3f98..bd3d21dffef0 100644 --- a/pkg/front_end/testcases/incremental/macro_recompile.yaml.world.1.expect +++ b/pkg/front_end/testcases/incremental/macro_recompile.yaml.world.1.expect @@ -69,7 +69,7 @@ holepunch:pkg/_macros/lib/src/api/builders.dart: - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart) holepunch:pkg/_macros/lib/src/api/code.dart: -- CodeKind. (from holepunch:pkg/_macros/lib/src/api/code.dart:460:6) +- CodeKind. (from holepunch:pkg/_macros/lib/src/api/code.dart:469:6) - _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart) - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart) diff --git a/pkg/front_end/testcases/incremental/macro_recompile.yaml.world.2.expect b/pkg/front_end/testcases/incremental/macro_recompile.yaml.world.2.expect index 7ab638d4a603..a666ddf5b355 100644 --- a/pkg/front_end/testcases/incremental/macro_recompile.yaml.world.2.expect +++ b/pkg/front_end/testcases/incremental/macro_recompile.yaml.world.2.expect @@ -66,7 +66,7 @@ holepunch:pkg/_macros/lib/src/api/builders.dart: - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart) holepunch:pkg/_macros/lib/src/api/code.dart: -- CodeKind. (from holepunch:pkg/_macros/lib/src/api/code.dart:460:6) +- CodeKind. (from holepunch:pkg/_macros/lib/src/api/code.dart:469:6) - _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart) - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart) diff --git a/pkg/front_end/testcases/incremental/macro_reuse_compiled_macro.yaml.world.1.expect b/pkg/front_end/testcases/incremental/macro_reuse_compiled_macro.yaml.world.1.expect index 809fc810edf3..5789a31c8bf0 100644 --- a/pkg/front_end/testcases/incremental/macro_reuse_compiled_macro.yaml.world.1.expect +++ b/pkg/front_end/testcases/incremental/macro_reuse_compiled_macro.yaml.world.1.expect @@ -68,7 +68,7 @@ holepunch:pkg/_macros/lib/src/api/builders.dart: - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart) holepunch:pkg/_macros/lib/src/api/code.dart: -- CodeKind. (from holepunch:pkg/_macros/lib/src/api/code.dart:460:6) +- CodeKind. (from holepunch:pkg/_macros/lib/src/api/code.dart:469:6) - _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart) - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart) diff --git a/pkg/front_end/testcases/incremental/macro_reuse_compiled_macro.yaml.world.2.expect b/pkg/front_end/testcases/incremental/macro_reuse_compiled_macro.yaml.world.2.expect index 70f6a16c976d..325a35a8011d 100644 --- a/pkg/front_end/testcases/incremental/macro_reuse_compiled_macro.yaml.world.2.expect +++ b/pkg/front_end/testcases/incremental/macro_reuse_compiled_macro.yaml.world.2.expect @@ -65,7 +65,7 @@ holepunch:pkg/_macros/lib/src/api/builders.dart: - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart) holepunch:pkg/_macros/lib/src/api/code.dart: -- CodeKind. (from holepunch:pkg/_macros/lib/src/api/code.dart:460:6) +- CodeKind. (from holepunch:pkg/_macros/lib/src/api/code.dart:469:6) - _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart) - Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart) diff --git a/pkg/macros/CHANGELOG.md b/pkg/macros/CHANGELOG.md index b73f94ec1291..dbc6a3cf08ac 100644 --- a/pkg/macros/CHANGELOG.md +++ b/pkg/macros/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.0-main.3 + +- Validate parts in `Code.fromParts()`. + ## 0.1.0-main.2 - Add caching for `typeDeclarationOf` results. diff --git a/pkg/macros/pubspec.yaml b/pkg/macros/pubspec.yaml index d804d852974c..a7f087aba713 100644 --- a/pkg/macros/pubspec.yaml +++ b/pkg/macros/pubspec.yaml @@ -1,5 +1,5 @@ name: macros -version: 0.1.0-main.2 +version: 0.1.0-main.3 description: >- This package is for macro authors, and exposes the APIs necessary to write a macro. It exports the APIs from the private `_macros` SDK vendored package. @@ -11,4 +11,4 @@ environment: dependencies: _macros: sdk: dart - version: 0.1.2 + version: 0.1.3