Skip to content

[code_builder] external and static in wrong order for fields #2118

Closed
@nikeokoronkwo

Description

@nikeokoronkwo

Description

I was trying to create a field on an extension type making use of external and static (representing static properties on JS objects, for this particular use case):

return Field((f) => f
  ..external = true
  ..static = true
  // more
);

Expected Behavior

I expected that the rendered code would produce something similar to the following

external static JSEnum Blue = /* value */;

This is similar to expected behaviour described in the example here

Actual Behaviour

The code produced was instead the following

static external JSEnum Blue = /* value */;

This code does not work, as passing this through the DartFormatter in dart_style produced the following error (separate example):

line 41, column 8 of .: The modifier 'external' should be before the modifier 'static'.
   ╷
41 │ static external final MathConstants Random;
   │        ^^^^^^^^
   ╵
line 43, column 8 of .: The modifier 'external' should be before the modifier 'static'.
   ╷
43 │ static external final MathConstants Length;
   │        ^^^^^^^^

Reason

After some digging, I found that this was coming from the following:

if (spec.static) {
output.write('static ');
}
if (spec.late && _useNullSafetySyntax) {
output.write('late ');
}
if (spec.external) {
output.write('external ');
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions