Skip to content

Add syntactic sugar for package imports #3929

Open
@MichaelFenwick

Description

@MichaelFenwick

In Dart, it's extremely common to see imports that look like this

import 'package:epubx/epubx.dart';
import 'package:path/path.dart' as path;
import 'package:quiver/collection.dart';
import 'package:web/web.dart';
import 'package:xml/xml.dart';

The repetition in there should be plain to see. As it is the case that it's standard for libraries to put the primarily intended import in a file with the same name as the package, I suggest adding syntactic sugar where import 'package:foo' would be treated the same as import 'package:foo/foo.dart'. Under this proposed change, the current syntax would remain valid.

With this feature, the example above would instead look like

import 'package:epubx';
import 'package:path' as path;
import 'package:quiver/collection.dart';
import 'package:web';
import 'package:xml';

Beyond being less typing and less reading, and generally looking cleaner, I believe this sugar would also make it easier to see at a glance which packages are being imported partially. It would also allow these "standard" package imports to better mirror the format of Dart SDK imports (import 'dart:async;').

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureProposed language feature that solves one or more problems

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions