Skip to content

Make it possible to augment constructor initializer in FieldDefinitionMacro #56337

Open
@AlexanderFarkas

Description

To clarify, I refer specifically to FieldDefinitionMacros. I believe it's already possible to augment constructor initializers in ClassDefinitionMacro.

Now we can augment field initializer (though not implemented yet)

builder.augment(
  initializer: ExpressionCode.fromParts([
    observableListClazz,
    "(augmented)",
  ]),
);

I think it's reasonable to allow augmenting constructor initializer for this field:

builder.augment(
  constructorInitializer: ExpressionCode.fromParts([
    observableListClazz,
    "(augmented)",
  ]),
);

Or may be just duplicate initializer's ExpressionCode to constructor if field doesn't have initializer.

Before:

class MyClass {
  @observable
  final List<String> names;
  MyClass(this.name);
}

After:

augment class MyClass {
  augment MyClass(List<String> names): this.names = generatedCodeByMacro(augmented)
}

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).feature-macrosImplementation of the macros featurepkg-macrosThe experimental package:_macros librarytype-enhancementA request for a change that isn't a bug

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions