-
Notifications
You must be signed in to change notification settings - Fork 208
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
Allow library declarations with no name. #1073
Comments
FYI: there is special handling in |
AFAIK this is not the case, see dart-lang/dartdoc#1082. |
It does indeed seem like that feature never made it into DartDoc. All the more reason to introduce the |
library name is useful for mirror, such as: but testaa's library name is aa and testbb's library name is aa, the code will throw exception: |
@Silentdoer Not sure what point you are making. You can add names to libraries if you want to, and you can choose not to if you want to. The one thing you can't currently do is not have a library name and have metadata or documentation on the library. People choose not to give libraries names for a reason. Letting libraries define their own name means that you risk conflicts. Dart disallows such conflicts, but there is no way to resolve them other than to not include one of the libraries in the program. Generally in Dart, a declaration with a name is included in a scope which limits that name's reach (and risk of conflict). You can't have two top-level declarations in the same library, but a library is also a unit of editing, so the person adding the conflict is also able to resolve it again. The scope of library names is the program. That means that any library name you declare can potentially conflict with any other library. The solution to that is to use structured library names based on the package name and library name, like The solution to that is to not give libraries names. That's what people are already doing. Whether library names are useful for mirrors or not isn't really important, because you can still choose to give libraries a name if you want to, and most people choose not to do that. This request is to allow those people to still attach metadata (including documentation) to the library. |
We actually removed that error in 14fcda2, July 2020. Of course, this means that library names are only useful for code using mirrors, which makes it even more natural to use a bare |
This would be very useful to me right now. |
Just do it! (My biggest obstacle to having already done this was that it required changes to the analyzer AST model. Parsing is trivial. Libraries having empty names is already possible. Some code will not expect a library with a |
Yes please!!! |
@bwilkerson @srawlins Is there something in the analyzer blocking this? |
No, there shouldn't be. We'd be game to implement. |
I believe I've more-or-less implemented this in https://dart-review.googlesource.com/c/sdk/+/257490. @leafpetersen should I still spell out the feature real quick in a language repo spec? |
It's nice to have something around as a record, so if you don't mind, maybe a 1 paragraph spec would be great? You could land it directly in accepted/future_releases I think? |
Specification mailed in: #2490 |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
@srawlins – leave it open until we have a plan to ship it in a specific release? (CC @mit-mit @leafpetersen ) |
Yeah I think leaving it open for now is good. |
Bug: dart-lang/language#1073 Change-Id: I9d57c86c35b5712029c610197e6ad823d34c492e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262580 Commit-Queue: Samuel Rawlins <srawlins@google.com> Reviewed-by: Erik Ernst <eernst@google.com>
TEST=tests/language/library/unnamed_library_test.dart Bug: dart-lang/language#1073 Change-Id: I1c7fa7b4ee4450e344a7613525765e4ab590cc8c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/265381 Reviewed-by: Alexander Aprelev <aam@google.com> Reviewed-by: Samuel Rawlins <srawlins@google.com> Reviewed-by: Michael Thomsen <mit@google.com> Reviewed-by: Leaf Petersen <leafp@google.com> Commit-Queue: Samuel Rawlins <srawlins@google.com>
@srawlins – can we close this as "done"? 😺 |
I want to check off the last box there for vm_service support. I hoped to work on it today, but... tomorrow! |
Debugging a library without a name seems to work perfectly :D. Checked off vm_service. |
Dart has library declarations of the form
library some.name;
which are no longer commonly used.The name used to be required for having
part
files, but is now not necessary.Giving a library a name is only really useful for avoiding duplicate imports with different paths, so most libraries do not use the declaration.
However, it's still useful to have a library declaration for a number of reasons:
The latter is "fixed" by the dartdoc tool assuming that a dartdoc occurring before the first import is really documenting the library, and not the import. (Edit: No, it actually doesn't. The culprit is the
@TestOn
annotation.)The former is not fixed, so when you want to annotate your library with metadata, you need to give it an otherwise completely useless name.
The obvious solution would be to allow a declaration of the form
library;
, which gives the library the empty name (same as no library declaration). It's just a hook to hang your annotations from.Feature specification
https://github.com/dart-lang/language/blob/master/accepted/future-releases/unnamed-libraries/feature-specification.md
Experiment flag
--unnamed-libraries
Implementation Tasks
core library updates.(https://dart-review.googlesource.com/c/sdk/+/257490).
(https://dart-review.googlesource.com/c/sdk/+/257490).
implementation in DDC.implementation in the VM.implementation in syntax highlightersGithub syntax highlighting.highlight.js support (api.dart.dev, api.pub.dev, Dartdoc):CodeMirror support (DartPad).implementation in IntelliJ.implementation in Cider.web debugging support.implementation in dart2js.The text was updated successfully, but these errors were encountered: