Commit 9a0d8d1a authored by wincent's avatar wincent

wiki: Proofread "Import statement ordering"

parent 7b093433
......@@ -22,7 +22,7 @@ export type T = string;
export default function foo() {}
```
The rationale from moving from NPM packages, to the current directory, to the parent(s) is to start with the "closest" items first. NPM packages and Node built-ins are "closest" because they are globally accessible everywhere without a relative path. This is next followed by items in the current directory ("./"), then the parent ("../"), then the grandparent ("../../") and so on; the further away we move from the current directory, the longer the prefix.
The rationale for moving from NPM packages, to the current directory, to the parent(s) is to start with the "closest" items first. NPM packages and Node built-ins are "closest" because they are globally accessible everywhere without a relative path. This is next followed by items in the current directory ("./"), then the parent ("../"), then the grandparent ("../../") and so on; the further away we move from the current directory, the longer the prefix.
Note that when accessing items in subdirectories, we sort lexicographically and not by depth:
......@@ -31,7 +31,7 @@ import a from './a/something/very/very/deeply/nested';
import b from './b/something/shallow';
```
Uppercase sorts before lowercase. Note in this example how, even though we're importing `thing`, `z` and `a` here, the order is dictated by the string on the right:
Uppercase sorts before lowercase. Note in this example how, even though we're importing `thing`, `z` and `a` here, the order is dictated by the source string on the right:
```javascript
import thing from 'Somewhere';
......@@ -39,7 +39,7 @@ import {z} from 'bar';
import {a} from 'foo';
```
Part of the rationale is that we shouldn't have to move an import just because we add to or remove from the list on the left-hand-side; this keeps diffs small; eg:
Part of the rationale is that we shouldn't have to move an import just because we add to or remove from the list of specifiers on the left-hand-side; this keeps diffs small; eg:
```diff
import {something} from 'a';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment