You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use util::{attached_trivia, detached_trivia, has_detached_leading_comment, leading_newlines};
23
26
24
-
pubmod import_key;
25
-
pubmod specifiers_attributes;
26
-
mod util;
27
-
28
27
declare_source_rule!{
29
28
/// Provides a code action to sort the imports and exports in the file using a built-in or custom order.
30
29
///
31
30
/// Imports and exports are first separated into chunks, before being sorted.
32
31
/// Imports or exports of a chunk are then grouped according to the user-defined groups.
33
-
/// Within a group, imports are sorted using a built-in order that depends on the import/export kind, whether the import/export has attributes and the source being imported from.
32
+
/// Within a group, imports are sorted using a built-in order that depends on the import/export kind,
33
+
/// whether the import/export has attributes and the source being imported from.
34
34
/// **source** is also often called **specifier** in the JavaScript ecosystem.
35
35
///
36
36
/// ```js,ignore
@@ -62,8 +62,9 @@ declare_source_rule! {
62
62
/// export { F } from "f";
63
63
/// ```
64
64
///
65
-
/// Chunks also end as soon as a statement or a **side-effect import** (also called _bare import_) is encountered.
66
-
/// Every side-effect import forms an independent chunk.
65
+
/// Chunks also end as soon as a statement or a **bare import** (also called _side-effect import_) is encountered.
66
+
/// Bare imports can be sorted with other imports by setting the `ignoreBareImports` option to `false`.
67
+
/// Every bare import forms an independent chunk.
67
68
/// The following example contains six chunks:
68
69
///
69
70
/// ```js,ignore
@@ -84,9 +85,9 @@ declare_source_rule! {
84
85
/// export { F } from "f";
85
86
/// ```
86
87
///
87
-
/// 1. The first chunk contains the two first `import` and ends with the appearance of the first side-effect import `import "x"`.
88
-
/// 2. The second chunk contains only the side-effect import `import "x"`.
89
-
/// 3. The third chunk contains only the side-effect import `import "y"`.
88
+
/// 1. The first chunk contains the two first `import` and ends with the appearance of the first bare import `import "x"`.
89
+
/// 2. The second chunk contains only the bare import `import "x"`.
90
+
/// 3. The third chunk contains only the bare import `import "y"`.
90
91
/// 4. The fourth chunk contains a single `import`; The first `export` ends it.
91
92
/// 5. The fifth chunk contains the first `export`; The function declaration ends it.
92
93
/// 6. The sixth chunk contains the last two `export`.
@@ -111,8 +112,10 @@ declare_source_rule! {
111
112
/// The line `import { C } from "c"` forms the second chunk.
112
113
/// The blank line between the first two imports is ignored so they form a single chunk.
113
114
///
114
-
/// The sorter ensures that chunks are separated from each other with blank lines.
115
-
/// Only side-effect imports adjacent to a chunk of imports are not separated by a blank line.
115
+
/// The sorter ensures that a chunk of imports and a chunk of exports
116
+
/// are separated from each other with blank lines.
117
+
/// Also, it ensures that a chunk that starts with a detached comment
118
+
/// is separated from the previous chunk with a blank line.
116
119
/// The following code...
117
120
///
118
121
/// ```js,ignore
@@ -198,16 +201,18 @@ declare_source_rule! {
198
201
/// import sibling from "./file.js";
199
202
/// ```
200
203
///
201
-
/// If two imports or exports share the same source and are in the same chunk, then they are ordered according to their kind as follows:
204
+
/// If two imports or exports share the same source and are in the same chunk,
205
+
/// then they are ordered according to their kind as follows:
202
206
///
203
-
/// 1. Namespace type import / Namespace type export
204
-
/// 2. Default type import
205
-
/// 3. Named type import / Named type export
206
-
/// 4. Namespace import / Namespace export
207
-
/// 5. Combined default and namespace import
208
-
/// 6. Default import
209
-
/// 7. Combined default and named import
210
-
/// 8. Named import / Named export
207
+
/// 1. Bare imports
208
+
/// 2. Namespace type import / Namespace type export
209
+
/// 3. Default type import
210
+
/// 4. Named type import / Named type export
211
+
/// 5. Namespace import / Namespace export
212
+
/// 6. Combined default and namespace import
213
+
/// 7. Default import
214
+
/// 8. Combined default and named import
215
+
/// 9. Named import / Named export
211
216
///
212
217
/// Imports and exports with attributes are always placed first.
213
218
/// For example, the following code...
@@ -570,6 +575,8 @@ declare_source_rule! {
570
575
/// import D2, { A, B } from "package";
571
576
/// ```
572
577
///
578
+
/// Also, note that bare imports are never merged with other imports
579
+
/// even if you set `ignoreBareImports` to `false`.
573
580
///
574
581
/// ## Named imports, named exports and attributes sorting
575
582
///
@@ -661,8 +668,11 @@ declare_source_rule! {
661
668
/// }
662
669
/// ```
663
670
///
664
-
/// ## Change the sorting of import identifiers to lexicographic sorting
665
-
/// This only applies to the named import/exports and not the source itself.
671
+
/// ## Change the sorting of import and export identifiers
672
+
///
673
+
/// By default, attributes, imported and exported names are sorted with a `natural` sort.
674
+
/// Yo ucan opt for a `lexicographic` sort (sometimes referred as _binary_ sort) by
0 commit comments