@putout/printer 1.6.8 → 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 CHANGED
@@ -1,3 +1,13 @@
1
+ 2023.03.22, v1.6.10
2
+
3
+ feature:
4
+ - 2c82f51 @putout/printer: add support of WhileStatement, NullLiteral
5
+
6
+ 2023.03.21, v1.6.9
7
+
8
+ feature:
9
+ - 39386c6 @putout/printer: add support of RegExpLiteral, OptionalCallExpression
10
+
1
11
  2023.03.21, v1.6.8
2
12
 
3
13
  feature:
@@ -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
  }
@@ -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
-
@@ -5,9 +5,19 @@ const {
5
5
  isMarkedPrevAfter,
6
6
  } = require('../mark');
7
7
 
8
+ module.exports.OptionalCallExpression = (path, {indent, print, maybe}) => {
9
+ return CallExpression(path, {
10
+ indent,
11
+ print,
12
+ maybe,
13
+ });
14
+ };
15
+
8
16
  const {entries} = Object;
9
17
 
10
- module.exports.CallExpression = (path, {indent, print, maybe}) => {
18
+ module.exports.CallExpression = CallExpression;
19
+
20
+ function CallExpression(path, {indent, print, maybe}) {
11
21
  const isParentCall = toLong(path) && path.parentPath.isCallExpression();
12
22
 
13
23
  if (shouldAddNewLine(path) && !isMarkedParentBefore(path) && !isMarkedPrevAfter(path.parentPath))
@@ -44,7 +54,7 @@ module.exports.CallExpression = (path, {indent, print, maybe}) => {
44
54
  }
45
55
 
46
56
  print(')');
47
- };
57
+ }
48
58
 
49
59
  function shouldAddNewLine({parentPath}) {
50
60
  if (!parentPath.isExpressionStatement())
@@ -77,4 +87,3 @@ function toLong(path) {
77
87
 
78
88
  return false;
79
89
  }
80
-
@@ -3,9 +3,12 @@
3
3
  const functions = require('./functions');
4
4
  const unaryExpressions = require('./unary-expressions');
5
5
  const memberExpressions = require('./member-expressions');
6
-
7
6
  const {ClassDeclaration} = require('./class-declaration');
8
- const {CallExpression} = require('./call-expression');
7
+ const {
8
+ CallExpression,
9
+ OptionalCallExpression,
10
+ } = require('./call-expression');
11
+
9
12
  const {NewExpression} = require('./new-expression');
10
13
  const {ObjectExpression} = require('./object-expression');
11
14
  const {ObjectPattern} = require('./object-pattern');
@@ -26,6 +29,7 @@ module.exports = {
26
29
  AssignmentExpression,
27
30
  AssignmentPattern,
28
31
  CallExpression,
32
+ OptionalCallExpression,
29
33
  ClassDeclaration,
30
34
  NewExpression,
31
35
  ObjectExpression,
@@ -44,4 +48,3 @@ module.exports = {
44
48
  traverse(path.get('right'));
45
49
  },
46
50
  };
47
-
@@ -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.line;
8
- const end = path.node?.loc?.end.line;
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
  };
@@ -26,5 +26,10 @@ module.exports = {
26
26
  Identifier(path, {write}) {
27
27
  write(path.node.name);
28
28
  },
29
+ RegExpLiteral(path, {print}) {
30
+ print(path.node.raw);
31
+ },
32
+ NullLiteral(path, {print}) {
33
+ print('null');
34
+ },
29
35
  };
30
-
@@ -19,7 +19,6 @@ module.exports.BlockStatement = (path, {indent, maybe, print}) => {
19
19
  }
20
20
 
21
21
  indent.dec();
22
-
23
22
  maybe.indent(body.length);
24
23
  print('}');
25
24
 
@@ -53,4 +52,3 @@ function isTry({parentPath}) {
53
52
 
54
53
  return false;
55
54
  }
56
-
@@ -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
+ };
@@ -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(path, maybeLine));
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.8",
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",