Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
modulovalue opened this issue Feb 15, 2023 · 0 comments
Open

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

modulovalue opened this issue Feb 15, 2023 · 0 comments
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-assist Issues with analysis server assists devexp-server Issues related to some aspect of the analysis server P4 type-enhancement A request for a change that isn't a bug

Comments

@modulovalue
Copy link
Contributor

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.

@mraleph mraleph added the legacy-area-analyzer Use area-devexp instead. label Feb 16, 2023
@scheglov scheglov added devexp-server Issues related to some aspect of the analysis server P4 devexp-assist Issues with analysis server assists labels Feb 17, 2023
@srawlins srawlins added the type-enhancement A request for a change that isn't a bug label Mar 15, 2024
@bwilkerson bwilkerson added area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. and removed legacy-area-analyzer Use area-devexp instead. labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-assist Issues with analysis server assists devexp-server Issues related to some aspect of the analysis server P4 type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants