Skip to content

Dart experiment to remove (or hide) dart:html and friends from included libraries #54347

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

Closed
parlough opened this issue Dec 14, 2023 · 6 comments
Labels
legacy-area-analyzer Use area-devexp instead. P4

Comments

@parlough
Copy link
Member

parlough commented Dec 14, 2023

It would be super cool to have an experiment (that can be used with --enable-experiment) or some other mode/common flag that removes (or hides) dart:html, dart:svg, dart:js, dart:js_util, etc. from the supported/surfaced SDK libraries. So I suppose it would load a different SDK overview file?

This would allow the analyzer and compilers to catch usages of the old libraries in your package and dependencies (sure, can be partially done by compiling with dart2wasm).

Perhaps more importantly though, the analyzer could avoid surfacing those libraries in completion suggestions, greatly improving the developer experience of those using modern interop functionality.

It would be a useful step towards migration that could be enabled relatively soon due to the lack of guarantees around experiments.

@parlough parlough changed the title Dart experiment to remove dart:html and friends from included libraries Dart experiment to remove (or hide) dart:html and friends from included libraries Dec 14, 2023
@lrhn lrhn added the area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. label Dec 14, 2023
@sigmundch sigmundch added the legacy-area-analyzer Use area-devexp instead. label Dec 14, 2023
@sigmundch
Copy link
Member

For what it's worth, we have a dart2js flag --server-mode that does this for dart2js.

I'll start the triage here first by asking a few questions:

For the @dart-lang/language-team: is it possible to use experiment flags and language versioning to hide a library?

For the analyzer team: if not, are there mechanisms to enable/disable an SDK library from being available in the analysis server?

@parlough
Copy link
Member Author

parlough commented Dec 14, 2023

I didn't think about --server-mode, thanks for calling that out as another option! I do think standard support for this from the web compilers is nice to have, but I feel that's less important since it can be surfaced with dart2wasm and the server mode. I believe that also won't work for identifying usages of the old interop libraries: dart:js, dart:js_util, etc.

The big win I see for developers is mostly in analysis errors and especially less noisy completion suggestions :)

@sigmundch sigmundch removed the area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. label Dec 14, 2023
@jakemac53
Copy link
Contributor

You can also use the import_path package to check for imports to any library (such as dart:html):

pub global activate import_path
import_path web/main.dart dart:html

@keertip
Copy link
Contributor

keertip commented Dec 14, 2023

/cc @bwilkerson , @scheglov

@keertip keertip added the P4 label Dec 14, 2023
@DanTup
Copy link
Collaborator

DanTup commented Dec 14, 2023

that removes (or hides) dart:html and its friends from the supported/surfaced SDK libraries.

It might be nice to make it more general than this - why can't I pick which specific dart: libraries I do/don't want (like I can with other dependencies)? There are quite a few libraries you get "for free" from the SDK and even some non-web ones you might just never want to use.

Screenshot 2023-12-14 184345

I've previously also wondered whether the Dart SDK could include package: libraries rather than them having to be dart: so that they are opt-in, similar to how you can reference packages from the Flutter SDK:

dependencyes:
  flutter:
    sdk: flutter
  mirrors:
    sdk: dart // package:mirrors but comes from the SDK

That could allow things to be shipped in the Dart SDK without being automatically available to projects (for example allowing other packages to use the same names without completion lists being full of duplicates). For example IIRC in flutter_tools it's forbidden to use dart:io instead of going through an abstraction - but it's very easy to accidentally get all the types from dart:io with fixes/completion.

@parlough
Copy link
Member Author

parlough commented Feb 7, 2024

Closing in favor of #54610 which implemented not surfacing dart:html and friends when not already used.

For determining outdated usages during compile, you can use dart compile wasm.

Thanks all.

@parlough parlough closed this as completed Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-analyzer Use area-devexp instead. P4
Projects
None yet
Development

No branches or pull requests

6 participants