@putout/printer 1.70.0 → 1.70.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ChangeLog +10 -0
- package/lib/tokenize/statements/export-declarations.js +48 -28
- package/lib/tokenize/statements/{import-declarations.js → import-declaration.js} +5 -0
- package/lib/tokenize/statements/index.js +1 -1
- package/lib/tokenize/statements/variable-declaration.js +2 -5
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {isNewlineBetweenStatements} = require('../is');
|
|
4
|
+
const {
|
|
5
|
+
markAfter,
|
|
6
|
+
isMarkedAfter,
|
|
7
|
+
} = require('../mark');
|
|
8
|
+
|
|
9
|
+
const isDeclarationNewline = (path) => isMarkedAfter(path.get('declaration'));
|
|
10
|
+
|
|
3
11
|
module.exports.ExportSpecifier = (path, {print}) => {
|
|
4
12
|
const {
|
|
5
13
|
local,
|
|
@@ -19,37 +27,49 @@ module.exports.ExportNamespaceSpecifier = (path, {print}) => {
|
|
|
19
27
|
print('__exported');
|
|
20
28
|
};
|
|
21
29
|
|
|
22
|
-
module.exports.ExportNamedDeclaration =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
write('export ');
|
|
27
|
-
|
|
28
|
-
if (exportKind === 'type' && specifiers.length) {
|
|
29
|
-
print('type');
|
|
30
|
-
print(specifiers[0]);
|
|
31
|
-
print(' from ');
|
|
32
|
-
print('__source');
|
|
33
|
-
print(';');
|
|
30
|
+
module.exports.ExportNamedDeclaration = {
|
|
31
|
+
print(path, {print, traverse, write, indent}) {
|
|
32
|
+
const {exportKind} = path.node;
|
|
33
|
+
const specifiers = path.get('specifiers');
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (specifiers.length) {
|
|
39
|
-
write('{');
|
|
40
|
-
indent.inc();
|
|
41
|
-
write.newline();
|
|
35
|
+
write('export ');
|
|
42
36
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
if (exportKind === 'type' && specifiers.length) {
|
|
38
|
+
print('type');
|
|
39
|
+
print(specifiers[0]);
|
|
40
|
+
print(' from ');
|
|
41
|
+
print('__source');
|
|
42
|
+
print(';');
|
|
43
|
+
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (specifiers.length) {
|
|
48
|
+
write('{');
|
|
49
|
+
indent.inc();
|
|
47
50
|
write.newline();
|
|
51
|
+
|
|
52
|
+
for (const spec of specifiers) {
|
|
53
|
+
indent();
|
|
54
|
+
traverse(spec);
|
|
55
|
+
write(',');
|
|
56
|
+
write.newline();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
indent.dec();
|
|
60
|
+
write('}');
|
|
48
61
|
}
|
|
49
62
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
63
|
+
print('__declaration');
|
|
64
|
+
},
|
|
65
|
+
afterIf(path) {
|
|
66
|
+
if (isDeclarationNewline(path))
|
|
67
|
+
return false;
|
|
68
|
+
|
|
69
|
+
return isNewlineBetweenStatements(path);
|
|
70
|
+
},
|
|
71
|
+
after(path, {print}) {
|
|
72
|
+
print.newline();
|
|
73
|
+
markAfter(path);
|
|
74
|
+
},
|
|
55
75
|
};
|
|
@@ -17,6 +17,11 @@ module.exports.ImportDeclaration = {
|
|
|
17
17
|
continue;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
if (spec.isImportNamespaceSpecifier()) {
|
|
21
|
+
print('* as ');
|
|
22
|
+
print(spec.get('local'));
|
|
23
|
+
}
|
|
24
|
+
|
|
20
25
|
if (spec.isImportSpecifier()) {
|
|
21
26
|
maybe.print(index, ', ');
|
|
22
27
|
maybe.print(!wasSpecifier, '{');
|
|
@@ -9,7 +9,7 @@ const {ReturnStatement} = require('./return-statement');
|
|
|
9
9
|
const TryStatements = require('./try-statements');
|
|
10
10
|
const {DebuggerStatement} = require('./debugger-statement');
|
|
11
11
|
const {ForStatement} = require('./for-statement');
|
|
12
|
-
const importDeclarations = require('./import-
|
|
12
|
+
const importDeclarations = require('./import-declaration');
|
|
13
13
|
const exportDeclarations = require('./export-declarations');
|
|
14
14
|
const {WhileStatement} = require('./while-statement');
|
|
15
15
|
const {SwitchStatement} = require('./switch-statement');
|
|
@@ -6,10 +6,7 @@ const {
|
|
|
6
6
|
isNewlineBetweenStatements,
|
|
7
7
|
} = require('../is');
|
|
8
8
|
|
|
9
|
-
const {
|
|
10
|
-
hasPrevNewline,
|
|
11
|
-
markAfter,
|
|
12
|
-
} = require('../mark');
|
|
9
|
+
const {hasPrevNewline} = require('../mark');
|
|
13
10
|
|
|
14
11
|
const {isExportDeclaration} = require('@babel/types');
|
|
15
12
|
|
|
@@ -52,7 +49,7 @@ module.exports.VariableDeclaration = {
|
|
|
52
49
|
const wasNewline = store();
|
|
53
50
|
maybe.print.linebreak(wasNewline);
|
|
54
51
|
maybe.print.newline(!wasNewline);
|
|
55
|
-
markAfter(path);
|
|
52
|
+
maybe.markAfter(wasNewline, path);
|
|
56
53
|
},
|
|
57
54
|
};
|
|
58
55
|
|
package/package.json
CHANGED