@putout/printer 1.8.10 → 1.9.0
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 +11 -0
- package/lib/tokenize/debug.js +17 -7
- package/lib/tokenize/is.js +1 -0
- package/lib/tokenize/statements/export-default-declaration.js +19 -0
- package/lib/tokenize/statements/import-declarations.js +1 -1
- package/lib/tokenize/statements/index.js +2 -0
- package/lib/tokenize/statements/variable-declaration.js +5 -0
- package/package.json +1 -1
- package/rules/putout-plugin-apply-computed-print/fixture/apply-computed-print-fix.js +0 -2
- package/rules/putout-plugin-apply-computed-print/fixture/apply-computed-print.js +0 -2
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2023.03.27, v1.9.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- cdcea37 @putout/printer: add support of ExportDefaultDeclaration
|
|
5
|
+
- e891b21 @putout/printer: add support of ExportDefaultDeclaration
|
|
6
|
+
|
|
7
|
+
2023.03.27, v1.8.11
|
|
8
|
+
|
|
9
|
+
fix:
|
|
10
|
+
- f7a06ec @putout/printer: drop redundant newline after VariableDeclaration
|
|
11
|
+
|
|
1
12
|
2023.03.27, v1.8.10
|
|
2
13
|
|
|
3
14
|
feature:
|
package/lib/tokenize/debug.js
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const {TYPES} = require('../types');
|
|
4
4
|
const toSnakeCase = require('just-snake-case');
|
|
5
|
-
const {
|
|
5
|
+
const {
|
|
6
|
+
LOG,
|
|
7
|
+
LOG_ALL,
|
|
8
|
+
DEBUG,
|
|
9
|
+
} = process.env;
|
|
6
10
|
const {codeFrameColumns} = require('@babel/code-frame');
|
|
7
11
|
|
|
8
12
|
module.exports.createDebug = (tokens) => (a) => {
|
|
@@ -16,17 +20,23 @@ module.exports.createDebug = (tokens) => (a) => {
|
|
|
16
20
|
};
|
|
17
21
|
|
|
18
22
|
module.exports.createLog = ({newline = '\n', store = createStore()} = {}) => (chunk) => {
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (chunk === newline) {
|
|
23
|
-
console.log(codeFrameColumns(store(), {}, {
|
|
23
|
+
if (LOG_ALL) {
|
|
24
|
+
console.log(codeFrameColumns(chunk, {}, {
|
|
24
25
|
highlightCode: true,
|
|
25
26
|
}));
|
|
26
27
|
return;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
if (LOG) {
|
|
31
|
+
if (chunk === newline) {
|
|
32
|
+
console.log(codeFrameColumns(store(), {}, {
|
|
33
|
+
highlightCode: true,
|
|
34
|
+
}));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
store(chunk);
|
|
39
|
+
}
|
|
30
40
|
};
|
|
31
41
|
|
|
32
42
|
function createStore() {
|
package/lib/tokenize/is.js
CHANGED
|
@@ -5,6 +5,7 @@ module.exports.isPrevBody = (path) => path.getPrevSibling().isBlockStatement();
|
|
|
5
5
|
module.exports.isNext = (path) => path.getNextSibling().node;
|
|
6
6
|
module.exports.isProgramParent = (path) => path.parentPath?.isProgram();
|
|
7
7
|
module.exports.isNextParent = (path) => path.parentPath.getNextSibling().node;
|
|
8
|
+
module.exports.isNextBlock = (path) => path.getNextSibling().isBlockStatement();
|
|
8
9
|
|
|
9
10
|
module.exports.isCoupleLines = (path) => {
|
|
10
11
|
const start = path.node?.loc?.start?.line;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {isFirst} = require('../is');
|
|
4
|
+
|
|
5
|
+
module.exports.ExportDefaultDeclaration = (path, {print}) => {
|
|
6
|
+
if (shouldAddNewlineBefore(path))
|
|
7
|
+
print.newline();
|
|
8
|
+
|
|
9
|
+
print('export default ');
|
|
10
|
+
print('__declaration');
|
|
11
|
+
print(';');
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
function shouldAddNewlineBefore(path) {
|
|
15
|
+
if (isFirst(path))
|
|
16
|
+
return false;
|
|
17
|
+
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
@@ -14,12 +14,14 @@ const exportDeclarations = require('./export-declarations');
|
|
|
14
14
|
const {WhileStatement} = require('./while-statement');
|
|
15
15
|
const {SwitchStatement} = require('./switch-statement');
|
|
16
16
|
const {ForInStatement} = require('./for-in-statement');
|
|
17
|
+
const {ExportDefaultDeclaration} = require('./export-default-declaration');
|
|
17
18
|
|
|
18
19
|
module.exports = {
|
|
19
20
|
...importDeclarations,
|
|
20
21
|
...exportDeclarations,
|
|
21
22
|
BlockStatement,
|
|
22
23
|
ExpressionStatement,
|
|
24
|
+
ExportDefaultDeclaration,
|
|
23
25
|
VariableDeclaration,
|
|
24
26
|
IfStatement,
|
|
25
27
|
ForStatement,
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
const {
|
|
4
4
|
isNext,
|
|
5
5
|
isCoupleLines,
|
|
6
|
+
isNextBlock,
|
|
7
|
+
|
|
6
8
|
} = require('../is');
|
|
7
9
|
const {
|
|
8
10
|
hasPrevNewline,
|
|
@@ -42,6 +44,9 @@ function shouldAddNewlineAfter(path) {
|
|
|
42
44
|
if (!isNext(path) && path.parentPath.isBlockStatement())
|
|
43
45
|
return true;
|
|
44
46
|
|
|
47
|
+
if (isNextBlock(path))
|
|
48
|
+
return false;
|
|
49
|
+
|
|
45
50
|
if (isLast(path))
|
|
46
51
|
return false;
|
|
47
52
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Easiest possible opinionated Babel AST printer made with ❤️ to use in 🐊Putout",
|