Skip to content
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

dart2js code should start passing a language version to dart_style #56686

Closed
Tracked by #56688
munificent opened this issue Sep 10, 2024 · 2 comments
Closed
Tracked by #56688

dart2js code should start passing a language version to dart_style #56686

munificent opened this issue Sep 10, 2024 · 2 comments
Assignees
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop.

Comments

@munificent
Copy link
Member

munificent commented Sep 10, 2024

Greetings dart2js team friends!

The formatter is moving to being language version aware. This means that when it's parsing some code, it needs to be told what language version to parse it as. The DartFormatter constructor now takes an optional parameter where you can pass in the language version. In a future version of dart_style, that parameter will become mandatory.

If you own code that uses dart_style as a library, you should update your code to pass in a language version. To migrate:

  1. If this code is inside a package (as opposed to, say, the Dart core libraries), then update your constraint on dart_style to ^2.3.7. That's the version where the new parameter was added.

  2. If you know the precise language version the code should be parsed as, then pass in that version (as an instance of the pub_semver package's Version class). This is what "real" tools should do.

    For simple one-off scripts and other utilities where precise behavior doesn't matter much, you can pass in DartFormatter.latestLanguageVersion to unconditionally parse the code as the latest language version that the formatter itself supports.

When the --tall-style experiment flag ships, the passed in language version will also be used to determine whether you get the current formatting style or the new "tall" style.

I did a search through the SDK, and the constructor calls that I think are relevant are:

~/dev/dart/sdk/pkg/compiler/test/tool/graph_isomorphizer/graph_isomorphizer_test.dart:
   45:       DartFormatter().format(contents.toString()), expectations[filename]!);

~/dev/dart/sdk/pkg/compiler/tool/graph_isomorphizer.dart:
  461:     sink.write(DartFormatter().format(contents.toString()));

~/dev/dart/sdk/sdk/lib/_internal/js_dev_runtime/private/debugger.dart:
   43: var _devtoolsFormatter = JsonMLFormatter(DartFormatter());
  466:   DartFormatter()

Thank you!

@munificent munificent added the area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. label Sep 10, 2024
@biggs0125 biggs0125 self-assigned this Sep 10, 2024
@biggs0125
Copy link

Hey Bob, thanks for the detailed description! The two graph_isomorphizer files aren't heavily used and we don't necessarily care about the format of the code being emitted so I've added a change to have those specify DartFormatter.latestLanguageVersion.

sdk/sdk/lib/_internal/js_dev_runtime/private/debugger.dart is actually referencing a local class named DartFormatter so that one doesn't need updating.

copybara-service bot pushed a commit that referenced this issue Sep 10, 2024
Bug: #56686
Change-Id: I3f578d29e125426c02eac564ca6baff9fb7d8919
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384402
Reviewed-by: Bob Nystrom <[email protected]>
Auto-Submit: Nate Biggs <[email protected]>
Commit-Queue: Bob Nystrom <[email protected]>
@munificent
Copy link
Member Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop.
Projects
None yet
Development

No branches or pull requests

2 participants