@putout/printer 1.6.9 → 1.6.10
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 +5 -0
- package/lib/tokenize/comments.js +1 -1
- package/lib/tokenize/debug.js +0 -2
- package/lib/tokenize/is.js +3 -2
- package/lib/tokenize/literals/index.js +3 -0
- package/lib/tokenize/statements/index.js +2 -1
- package/lib/tokenize/statements/while-statement.js +19 -0
- package/lib/tokenize/tokenize.js +6 -6
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/lib/tokenize/comments.js
CHANGED
|
@@ -10,7 +10,7 @@ module.exports.parseComments = (path, {write}) => {
|
|
|
10
10
|
function parseLeadingComments(path, {write}) {
|
|
11
11
|
const {leadingComments} = path.node;
|
|
12
12
|
|
|
13
|
-
for (const {value}of leadingComments) {
|
|
13
|
+
for (const {value} of leadingComments) {
|
|
14
14
|
write(`//${value}`);
|
|
15
15
|
write.newline();
|
|
16
16
|
}
|
package/lib/tokenize/debug.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const {TYPES} = require('../types');
|
|
4
4
|
const toSnakeCase = require('just-snake-case');
|
|
5
|
-
|
|
6
5
|
const {DEBUG} = process.env;
|
|
7
6
|
|
|
8
7
|
module.exports.createDebug = (tokens) => (a) => {
|
|
@@ -14,4 +13,3 @@ module.exports.createDebug = (tokens) => (a) => {
|
|
|
14
13
|
value: `/*__${toSnakeCase(a)}*/`,
|
|
15
14
|
});
|
|
16
15
|
};
|
|
17
|
-
|
package/lib/tokenize/is.js
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
module.exports.isFirst = (path) => path.node === path.parentPath.node.body[0];
|
|
4
4
|
module.exports.isPrevBody = (path) => path.getPrevSibling().isBlockStatement();
|
|
5
5
|
module.exports.isNext = (path) => path.getNextSibling().node;
|
|
6
|
+
|
|
6
7
|
module.exports.isCoupleLines = (path) => {
|
|
7
|
-
const start = path.node?.loc?.start
|
|
8
|
-
const end = path.node?.loc?.end
|
|
8
|
+
const start = path.node?.loc?.start?.line;
|
|
9
|
+
const end = path.node?.loc?.end?.line;
|
|
9
10
|
|
|
10
11
|
return end > start;
|
|
11
12
|
};
|
|
@@ -11,6 +11,7 @@ const {DebuggerStatement} = require('./debugger-statement');
|
|
|
11
11
|
const {ForStatement} = require('./for-statement');
|
|
12
12
|
const importDeclarations = require('./import-declarations');
|
|
13
13
|
const exportDeclarations = require('./export-declarations');
|
|
14
|
+
const {WhileStatement} = require('./while-statement');
|
|
14
15
|
|
|
15
16
|
module.exports = {
|
|
16
17
|
...importDeclarations,
|
|
@@ -37,5 +38,5 @@ module.exports = {
|
|
|
37
38
|
print('continue;');
|
|
38
39
|
print.newline();
|
|
39
40
|
},
|
|
41
|
+
WhileStatement,
|
|
40
42
|
};
|
|
41
|
-
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.WhileStatement = (path, {print, indent}) => {
|
|
4
|
+
print('while (');
|
|
5
|
+
print('__test');
|
|
6
|
+
print(')');
|
|
7
|
+
|
|
8
|
+
if (path.node.body.body) {
|
|
9
|
+
print(' ');
|
|
10
|
+
print('__body');
|
|
11
|
+
} else {
|
|
12
|
+
indent.inc();
|
|
13
|
+
print.newline();
|
|
14
|
+
print('__body');
|
|
15
|
+
indent.dec();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
print.linebreak();
|
|
19
|
+
};
|
package/lib/tokenize/tokenize.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const isObject = (a) => a && typeof a === 'object';
|
|
4
|
-
|
|
5
4
|
const babelTraverse = require('@babel/traverse').default;
|
|
6
5
|
const expressions = require('./expressions');
|
|
7
6
|
const statements = require('./statements');
|
|
@@ -12,12 +11,10 @@ const {
|
|
|
12
11
|
maybeMarkAfter,
|
|
13
12
|
maybeMarkBefore,
|
|
14
13
|
} = require('./mark');
|
|
15
|
-
const {parseComments} = require('./comments');
|
|
16
14
|
|
|
15
|
+
const {parseComments} = require('./comments');
|
|
17
16
|
const isString = (a) => typeof a === 'string';
|
|
18
|
-
|
|
19
17
|
const {assign} = Object;
|
|
20
|
-
|
|
21
18
|
const traversers = {
|
|
22
19
|
...expressions,
|
|
23
20
|
...statements,
|
|
@@ -147,6 +144,7 @@ module.exports.tokenize = (ast, overrides = {}) => {
|
|
|
147
144
|
newline: maybeNewline,
|
|
148
145
|
breakline: maybeBreakline,
|
|
149
146
|
});
|
|
147
|
+
|
|
150
148
|
assign(printer.maybe, {
|
|
151
149
|
print: maybePrint,
|
|
152
150
|
});
|
|
@@ -172,13 +170,15 @@ function printIndent(i, indent) {
|
|
|
172
170
|
|
|
173
171
|
return result;
|
|
174
172
|
}
|
|
175
|
-
|
|
176
173
|
const createPrint = (path, {traverse, write}) => (maybeLine) => {
|
|
177
174
|
if (maybeLine === path)
|
|
178
175
|
return null;
|
|
179
176
|
|
|
180
177
|
if (isString(maybeLine) && maybeLine.startsWith(GET))
|
|
181
|
-
return traverse(get(
|
|
178
|
+
return traverse(get(
|
|
179
|
+
path,
|
|
180
|
+
maybeLine,
|
|
181
|
+
));
|
|
182
182
|
|
|
183
183
|
if (isObject(maybeLine))
|
|
184
184
|
return traverse(maybeLine);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.10",
|
|
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",
|