@putout/printer 8.37.0 → 8.39.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
+ 2024.05.26, v8.39.0
2
+
3
+ feature:
4
+ - cb3474b @putout/printer: TSMethodDeclaration: getter/setter
5
+
6
+ 2024.05.24, v8.38.0
7
+
8
+ feature:
9
+ - f1f3d74 @putout/printer: check-dts v0.8.0
10
+ - 2e9ff2d @putout/printer: AssignmentExpression: newline after FunctionDeclaration
11
+
1
12
  2024.05.21, v8.37.0
2
13
 
3
14
  feature:
@@ -3,6 +3,7 @@
3
3
  const {isObjectPattern} = require('@putout/babel').types;
4
4
  const {isParens} = require('../unary-expression/parens');
5
5
  const {isCoupleLines} = require('../../is');
6
+ const {isMarkedAfter} = require('../../mark');
6
7
 
7
8
  module.exports.AssignmentExpression = {
8
9
  condition: (path) => {
@@ -34,18 +35,14 @@ module.exports.AssignmentExpression = {
34
35
  },
35
36
  };
36
37
 
37
- const isPrevCoupleLines = (path) => {
38
- const {parentPath} = path;
38
+ const isPrevCoupleLines = ({parentPath}) => {
39
39
  const prev = parentPath.getPrevSibling();
40
40
 
41
- if (!prev.node)
41
+ if (isMarkedAfter(prev))
42
42
  return false;
43
43
 
44
- const currentStart = path.node?.loc?.start.line;
45
- const prevEnd = prev.node?.loc?.end.line;
46
-
47
- if (!isCoupleLines(prev))
44
+ if (!prev.node)
48
45
  return false;
49
46
 
50
- return currentStart - prevEnd < 2;
47
+ return isCoupleLines(prev);
51
48
  };
@@ -3,22 +3,13 @@
3
3
  const {isNext} = require('../../is');
4
4
  const {printParams} = require('./params');
5
5
  const {maybeDecorators} = require('../../maybe/maybe-decorators');
6
+ const {printKey} = require('./kind');
6
7
 
7
8
  const ClassMethod = {
8
9
  print: maybeDecorators((path, printer, semantics) => {
9
- const {print, maybe} = printer;
10
+ const {print} = printer;
10
11
  const {node} = path;
11
- const {
12
- kind,
13
- computed,
14
- generator,
15
- accessibility,
16
- returnType,
17
- } = node;
18
-
19
- const isConstructor = kind === 'constructor';
20
- const isMethod = kind === 'method';
21
- const isGetter = /get|set/.test(kind);
12
+ const {accessibility, returnType} = node;
22
13
 
23
14
  if (accessibility) {
24
15
  print(accessibility);
@@ -35,21 +26,7 @@ const ClassMethod = {
35
26
  print(' ');
36
27
  }
37
28
 
38
- maybe.print(generator, '*');
39
- maybe.print(isConstructor, kind);
40
-
41
- if (isMethod) {
42
- maybe.print(computed, '[');
43
- print('__key');
44
- maybe.print(computed, ']');
45
- }
46
-
47
- if (isGetter) {
48
- print(kind);
49
- print(' ');
50
- print('__key');
51
- }
52
-
29
+ printKey(path, printer);
53
30
  printParams(path, printer, semantics);
54
31
 
55
32
  if (returnType) {
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ module.exports.printKey = (path, {write, traverse, maybe}) => {
4
+ const key = path.get('key');
5
+ const {
6
+ kind,
7
+ computed,
8
+ generator,
9
+ } = path.node;
10
+
11
+ const isGetter = kind === 'get' || kind === 'set';
12
+
13
+ if (isGetter)
14
+ write(`${kind} `);
15
+ else if (generator)
16
+ write('*');
17
+
18
+ maybe.write(computed, '[');
19
+ traverse(key);
20
+ maybe.write(computed, ']');
21
+ };
@@ -2,6 +2,7 @@
2
2
 
3
3
  const {isNewlineBetweenSiblings} = require('../../is');
4
4
  const {printParams} = require('./params');
5
+ const {printKey} = require('./kind');
5
6
 
6
7
  module.exports.ObjectMethod = {
7
8
  beforeIf(path) {
@@ -11,23 +12,9 @@ module.exports.ObjectMethod = {
11
12
  write('async ');
12
13
  },
13
14
  print(path, printer, semantics) {
14
- const {print, maybe} = printer;
15
-
16
- const {
17
- kind,
18
- generator,
19
- computed,
20
- } = path.node;
21
-
22
- const notMethod = kind !== 'method';
23
-
24
- maybe.print(notMethod, `${kind} `);
25
- maybe.print(generator, '*');
26
-
27
- maybe.print(computed, '[');
28
- print('__key');
29
- maybe.print(computed, ']');
15
+ const {print} = printer;
30
16
 
17
+ printKey(path, printer);
31
18
  printParams(path, printer, semantics);
32
19
 
33
20
  print.space();
@@ -1,16 +1,16 @@
1
1
  'use strict';
2
2
 
3
3
  const {printParams} = require('../../expressions/function/params');
4
-
4
+ const {printKey} = require('../../expressions/function/kind');
5
5
  const {
6
6
  hasReturnType,
7
7
  printReturnType,
8
8
  } = require('./print-return-type');
9
9
 
10
10
  module.exports.TSMethodSignature = (path, printer, semantics) => {
11
- const {traverse, write} = printer;
11
+ const {write} = printer;
12
12
 
13
- traverse(path.get('key'));
13
+ printKey(path, printer);
14
14
  printParams(path, printer, semantics);
15
15
 
16
16
  if (hasReturnType(path)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "8.37.0",
3
+ "version": "8.39.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",
@@ -53,7 +53,7 @@
53
53
  "@putout/plugin-react-hooks": "^6.0.0",
54
54
  "acorn": "^8.8.2",
55
55
  "c8": "^9.1.0",
56
- "check-dts": "^0.7.2",
56
+ "check-dts": "^0.8.0",
57
57
  "escover": "^4.0.1",
58
58
  "eslint": "^9.0.0",
59
59
  "eslint-plugin-putout": "^22.0.0",