Skip to content

Commit b95d9a4

Browse files
committed
Fix mistakes in examples and handle dotted names in short imports.
1 parent 4d31dbb commit b95d9a4

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

working/unquoted-imports/feature-specification.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Author: Bob Nystrom
44

55
Status: In-progress
66

7-
Version 0.1 (see [CHANGELOG](#CHANGELOG) at end)
7+
Version 0.2 (see [CHANGELOG](#CHANGELOG) at end)
88

99
Experiment flag: unquoted-imports
1010

@@ -101,7 +101,7 @@ import dart/isolate;
101101
import flutter_test;
102102
import path;
103103
import flutter/material;
104-
import analyzer/dart/ast/visitor;
104+
import analyzer/dart/ast/visitor/visitor;
105105
import widget.tla.server;
106106
import widget.tla.proto/client/component;
107107
```
@@ -110,8 +110,9 @@ You can probably infer what's going on from the before and after, but the basic
110110
idea is that the library is a slash-separated series of dotted identifier
111111
segments. The first segment is the name of the package. The rest is the path to
112112
the library within that package. A `.dart` extension is implicitly added to the
113-
end. If there is only a single segment, it is treated as both package name and
114-
path. If the package name is `dart`, it's a "dart:" library import.
113+
end. If there is only a single segment, it is treated as the package name and
114+
its last dotted component is the path. If the package name is `dart`, it's a
115+
"dart:" library import.
115116

116117
The way I think about the proposed syntax is that relative imports are
117118
*physical* in that they specify the actual relative path on the file system from
@@ -189,7 +190,7 @@ import 'package:flutter/material.dart';
189190
import flutter/material ;
190191
191192
import 'package:analyzer/dart/ast/visitor/visitor.dart';
192-
import analyzer/dart/ast/visitor ;
193+
import analyzer/dart/ast/visitor/visitor ;
193194
194195
import 'package:widget.tla.proto/client/component.dart';
195196
import widget.tla.proto/client/component ;
@@ -340,8 +341,14 @@ a string literal containing that string. The process is:
340341

341342
1. Let *name* be the segment.
342343

343-
2. The URI is "package:*name*/*name*.dart". *So `import test;` desugars to
344-
`import "package:test/test.dart";`.
344+
2. Let *path* be the last identifier in the segment. *If the segment is
345+
only a single identifier, this is the entire segment. Otherwise, it's
346+
the last identifier after the last `.`. So in `foo`, *path* is `foo`.
347+
In `foo.bar.baz`, it's `baz`.*
348+
349+
3. The URI is "package:*name*/*path*.dart". *So `import test;` desugars to
350+
`import "package:test/test.dart";`, and `import server.api;` desugars
351+
to `import "package:server.api/api.dart";`.*
345352

346353
5. Else:
347354

@@ -410,6 +417,11 @@ new unquoted style whenever an existing directive could use it.
410417

411418
## Changelog
412419

420+
### 0.2
421+
422+
- Handle dotted identifiers in single-segment imports specially. *This makes
423+
them work better for common cases in Google's monorepo.*
424+
413425
### 0.1
414426

415427
- Initial draft.

0 commit comments

Comments
 (0)