Skip to content

[analyzer] New refactoring: wrap expression in IIFE #51423

Open
@modulovalue

Description

@modulovalue

An immediately invoked function expression (IIFE) is a quick and common way to embed multiple statements, followed by a return statement, where only an expression is expected.

I think a refactoring for wrapping an expression in an IIFE would be very helpful.

Here is a simple concrete example:

Initial program:

void main() {
  final foo = MapEntry(
    0,
    1,
  );
}

Refactored program:

void main() {
  final foo = MapEntry(
    () {
      return 0;
    }(),
    1,
  );
}

The usefulness of such a refactoring becomes much more apparent when considered in a context where e.g. big Trees need to be constructed (as is common in Flutter). Having the statements close to the related expression is useful for improving code readability, but manually wrapping expressions in IIFEs is very tedious.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-assistIssues with analysis server assistsdevexp-serverIssues related to some aspect of the analysis servertype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions