@putout/printer 5.8.0 → 5.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 CHANGED
@@ -1,3 +1,9 @@
1
+ 2023.09.23, v5.9.0
2
+
3
+ feature:
4
+ - f163f9e @putout/printer: drop maybeMarkBefore
5
+ - 06e2b19 @putout/printer: maybeDecorators
6
+
1
7
  2023.09.23, v5.8.0
2
8
 
3
9
  fix:
@@ -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,22 @@
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
+ const {decorators} = path.node;
12
+
13
+ if (decorators) {
14
+ for (const decorator of path.get('decorators')) {
15
+ maybe.write.breakline(isPrev(path));
16
+ traverse(decorator);
17
+ write.breakline();
18
+ }
19
+ }
20
+
21
+ visitor(path, printer, semantics, options);
22
+ };
@@ -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,7 @@ module.exports.tokenize = (ast, overrides) => {
175
171
  dec: maybeIndentDec,
176
172
  });
177
173
 
178
- const printer = {
174
+ const mainPrinter = freeze({
179
175
  indent,
180
176
  write,
181
177
  debug,
@@ -183,7 +179,7 @@ module.exports.tokenize = (ast, overrides) => {
183
179
  maybe,
184
180
  quote,
185
181
  store: fullstore(),
186
- };
182
+ });
187
183
 
188
184
  const currentTraversers = {
189
185
  ...traversers,
@@ -219,9 +215,10 @@ module.exports.tokenize = (ast, overrides) => {
219
215
  roundBraceClose,
220
216
  });
221
217
 
222
- assign(printer, {
218
+ const printer = {
219
+ ...mainPrinter,
223
220
  print,
224
- });
221
+ };
225
222
 
226
223
  const maybePrint = (a, b) => a && print(b);
227
224
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "5.8.0",
3
+ "version": "5.9.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
- };