@putout/printer 5.8.0 → 5.10.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 CHANGED
@@ -1,3 +1,14 @@
1
+ 2023.09.26, v5.10.0
2
+
3
+ feature:
4
+ - 04ff653 @putout/printer: improve check of unsupported node
5
+
6
+ 2023.09.23, v5.9.0
7
+
8
+ feature:
9
+ - f163f9e @putout/printer: drop maybeMarkBefore
10
+ - 06e2b19 @putout/printer: maybeDecorators
11
+
1
12
  2023.09.23, v5.8.0
2
13
 
3
14
  fix:
package/README.md CHANGED
@@ -14,7 +14,7 @@ Prints [**Babel AST**](https://github.com/coderaiser/estree-to-babel) to readabl
14
14
  - ☝️ Similar to **Recast**, but [twice faster](#speed-comparison), also simpler and easier in maintenance, since it supports only **Babel**.
15
15
  - ☝️ As opinionated as **Prettier**, but has more user-friendly output and works directly with **AST**.
16
16
  - ☝️ Like **ESLint** but works directly with **Babel AST**.
17
- - ☝️ Easily extendable with help of [Overrides](h#overrides).
17
+ - ☝️ Easily extendable with help of [Overrides](#overrides).
18
18
 
19
19
  Supports:
20
20
 
@@ -2,23 +2,9 @@
2
2
 
3
3
  const {exists} = require('../../is');
4
4
  const {maybePrintTypeAnnotation} = require('../../literals/maybe-type-annotation');
5
- const {maybePrintDecorators} = require('./maybe-print-decorators');
5
+ const {maybeDecorators} = require('./maybe-decorators');
6
6
 
7
- module.exports.ClassProperty = processClassProperty;
8
- module.exports.ClassPrivateProperty = processClassProperty;
9
-
10
- module.exports.PrivateName = (path, {print}) => {
11
- print('#');
12
- print('__id');
13
- };
14
-
15
- module.exports.ClassAccessorProperty = (path, printer, semantics) => {
16
- processClassProperty(path, printer, semantics, {
17
- accessor: true,
18
- });
19
- };
20
-
21
- function processClassProperty(path, printer, semantics, {accessor} = {}) {
7
+ const processClassProperty = maybeDecorators((path, printer, semantics, {accessor} = {}) => {
22
8
  const {print, maybe} = printer;
23
9
  const {node} = path;
24
10
  const {
@@ -27,7 +13,6 @@ function processClassProperty(path, printer, semantics, {accessor} = {}) {
27
13
  optional,
28
14
  } = node;
29
15
 
30
- maybePrintDecorators(path, printer);
31
16
  maybe.print(accessor, 'accessor ');
32
17
 
33
18
  const value = path.get('value');
@@ -50,4 +35,18 @@ function processClassProperty(path, printer, semantics, {accessor} = {}) {
50
35
 
51
36
  print(';');
52
37
  print.newline();
53
- }
38
+ });
39
+
40
+ module.exports.ClassProperty = processClassProperty;
41
+ module.exports.ClassPrivateProperty = processClassProperty;
42
+
43
+ module.exports.PrivateName = (path, {print}) => {
44
+ print('#');
45
+ print('__id');
46
+ };
47
+
48
+ module.exports.ClassAccessorProperty = (path, printer, semantics) => {
49
+ processClassProperty(path, printer, semantics, {
50
+ accessor: true,
51
+ });
52
+ };
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ const {isPrev} = require('../../is');
4
+
5
+ module.exports.maybeDecorators = (visitor) => (path, printer, semantics, options) => {
6
+ const {
7
+ write,
8
+ traverse,
9
+ maybe,
10
+ } = printer;
11
+
12
+ const {decorators} = path.node;
13
+
14
+ if (decorators) {
15
+ for (const decorator of path.get('decorators')) {
16
+ maybe.write.breakline(isPrev(path));
17
+ traverse(decorator);
18
+ write.breakline();
19
+ }
20
+ }
21
+
22
+ visitor(path, printer, semantics, options);
23
+ };
@@ -2,10 +2,10 @@
2
2
 
3
3
  const {isNext} = require('../../is');
4
4
  const {printParams} = require('./params');
5
- const {maybePrintDecorators} = require('../class/maybe-print-decorators');
5
+ const {maybeDecorators} = require('../class/maybe-decorators');
6
6
 
7
7
  const ClassMethod = {
8
- print(path, printer, semantics) {
8
+ print: maybeDecorators((path, printer, semantics) => {
9
9
  const {print, maybe} = printer;
10
10
  const {node} = path;
11
11
  const {
@@ -20,8 +20,6 @@ const ClassMethod = {
20
20
  const isMethod = kind === 'method';
21
21
  const isGetter = /get|set/.test(kind);
22
22
 
23
- maybePrintDecorators(path, printer);
24
-
25
23
  if (accessibility) {
26
24
  print(accessibility);
27
25
  print(' ');
@@ -62,7 +60,7 @@ const ClassMethod = {
62
60
 
63
61
  print.space();
64
62
  print('__body');
65
- },
63
+ }),
66
64
  afterSatisfy: () => [isNext],
67
65
  after(path, {print}) {
68
66
  print.linebreak();
@@ -19,10 +19,7 @@ const {
19
19
 
20
20
  const {createDebug, createLog} = require('./debug');
21
21
 
22
- const {
23
- maybeMarkAfter,
24
- maybeMarkBefore,
25
- } = require('./mark');
22
+ const {maybeMarkAfter} = require('./mark');
26
23
 
27
24
  const {
28
25
  parseLeadingComments,
@@ -32,7 +29,7 @@ const {
32
29
  const {parseOverrides} = require('./overrides');
33
30
 
34
31
  const isString = (a) => typeof a === 'string';
35
- const {assign} = Object;
32
+ const {assign, freeze} = Object;
36
33
  const callWith = (fn, a) => () => fn(a);
37
34
 
38
35
  const traversers = {
@@ -164,7 +161,6 @@ module.exports.tokenize = (ast, overrides) => {
164
161
 
165
162
  const maybe = {
166
163
  indent: maybeIndent,
167
- markBefore: maybeMarkBefore,
168
164
  markAfter: maybeMarkAfter,
169
165
  write: maybeWrite,
170
166
  space: maybeSpace,
@@ -175,7 +171,8 @@ module.exports.tokenize = (ast, overrides) => {
175
171
  dec: maybeIndentDec,
176
172
  });
177
173
 
178
- const printer = {
174
+ // should never change to avoid unexpected errors related to printing path, since it hard to debug
175
+ const mainPrinter = freeze({
179
176
  indent,
180
177
  write,
181
178
  debug,
@@ -183,7 +180,7 @@ module.exports.tokenize = (ast, overrides) => {
183
180
  maybe,
184
181
  quote,
185
182
  store: fullstore(),
186
- };
183
+ });
187
184
 
188
185
  const currentTraversers = {
189
186
  ...traversers,
@@ -219,9 +216,10 @@ module.exports.tokenize = (ast, overrides) => {
219
216
  roundBraceClose,
220
217
  });
221
218
 
222
- assign(printer, {
219
+ const printer = {
220
+ ...mainPrinter,
223
221
  print,
224
- });
222
+ };
225
223
 
226
224
  const maybePrint = (a, b) => a && print(b);
227
225
 
@@ -236,7 +234,7 @@ module.exports.tokenize = (ast, overrides) => {
236
234
  print: maybePrint,
237
235
  });
238
236
 
239
- maybeThrow(!currentTraverse, path, `Node type '{{ type }}' is not supported yet: '{{ path }}'`);
237
+ maybeThrow(!currentTraverse, path, `☝️Node type '{{ type }}' is not supported yet by @putout/printer: '{{ path }}'`);
240
238
 
241
239
  const currentIndent = i;
242
240
  parseLeadingComments(path, printer, semantics);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "5.8.0",
3
+ "version": "5.10.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Simplest possible opinionated Babel AST printer for 🐊Putout",
@@ -1,16 +0,0 @@
1
- 'use strict';
2
-
3
- const {isPrev} = require('../../is');
4
-
5
- module.exports.maybePrintDecorators = (path, printer) => {
6
- const {print, maybe} = printer;
7
- const {decorators} = path.node;
8
-
9
- if (decorators) {
10
- for (const decorator of path.get('decorators')) {
11
- maybe.print.breakline(isPrev(path));
12
- print(decorator);
13
- print.breakline();
14
- }
15
- }
16
- };