Skip to content

Allow library declarations with no name. #1073

Closed
@lrhn

Description

@lrhn

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:

  • Adding annotations/metadata to the library.
  • Writing documentation for the library.

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

Metadata

Metadata

Assignees

Labels

requestRequests to resolve a particular developer problemsmall-featureA small feature which is relatively cheap to implement.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions