@putout/printer 9.6.0 → 9.8.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,7 +1,19 @@
1
+ 2024.07.14, v9.8.0
2
+
3
+ feature:
4
+ - 8fc9139 @putout/printer: maybe-print-computed: add
5
+ - 8800d25 @putout/printer: printKey: add
6
+
7
+ 2024.07.13, v9.7.0
8
+
9
+ feature:
10
+ - 192a828 @putout/printer: TryStatement: spaces: align with eslint-plugin-putout
11
+ - 5fb3b67 @putout/printer: MemberExpression: object used as AssignProperty (coderaiser/minify#124)
12
+
1
13
  2024.07.11, v9.6.0
2
14
 
3
15
  feature:
4
- - 0d1f296 @putout/printer: MemberExpression: object used as AssignProperty
16
+ - 0d1f296 @putout/printer: MemberExpression: object used as AssignProperty (coderaiser/minify#124)
5
17
 
6
18
  2024.06.16, v9.5.0
7
19
 
@@ -3,6 +3,8 @@
3
3
  const {exists} = require('../../is');
4
4
  const {maybePrintTypeAnnotation} = require('../../maybe/maybe-type-annotation');
5
5
  const {maybeDecorators} = require('../../maybe/maybe-decorators');
6
+ const {printKey} = require('../object-expression/print-key');
7
+ const {printKind} = require('../function/kind');
6
8
 
7
9
  const processClassProperty = maybeDecorators((path, printer, semantics, {accessor} = {}) => {
8
10
  const {node} = path;
@@ -23,7 +25,9 @@ const processClassProperty = maybeDecorators((path, printer, semantics, {accesso
23
25
  maybe.print(node.readonly, 'readonly ');
24
26
  maybe.print(declare, 'declare ');
25
27
 
26
- print('__key');
28
+ printKind(path, printer);
29
+ printKey(path, printer);
30
+
27
31
  maybe.print(optional, '?');
28
32
 
29
33
  maybePrintTypeAnnotation(path, printer);
@@ -3,7 +3,8 @@
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
+ const {printKey} = require('../object-expression/print-key');
7
+ const {printKind} = require('./kind');
7
8
 
8
9
  const ClassMethod = {
9
10
  print: maybeDecorators((path, printer, semantics) => {
@@ -26,6 +27,7 @@ const ClassMethod = {
26
27
  print(' ');
27
28
  }
28
29
 
30
+ printKind(path, printer);
29
31
  printKey(path, printer);
30
32
  printParams(path, printer, semantics);
31
33
 
@@ -1,12 +1,7 @@
1
1
  'use strict';
2
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;
3
+ module.exports.printKind = (path, {write}) => {
4
+ const {kind, generator} = path.node;
10
5
 
11
6
  const isGetter = kind === 'get' || kind === 'set';
12
7
 
@@ -14,8 +9,4 @@ module.exports.printKey = (path, {write, traverse, maybe}) => {
14
9
  write(`${kind} `);
15
10
  else if (generator)
16
11
  write('*');
17
-
18
- maybe.write(computed, '[');
19
- traverse(key);
20
- maybe.write(computed, ']');
21
12
  };
@@ -2,7 +2,8 @@
2
2
 
3
3
  const {isNewlineBetweenSiblings} = require('../../is');
4
4
  const {printParams} = require('./params');
5
- const {printKey} = require('./kind');
5
+ const {printKey} = require('../object-expression/print-key');
6
+ const {printKind} = require('./kind');
6
7
 
7
8
  module.exports.ObjectMethod = {
8
9
  beforeIf(path) {
@@ -14,6 +15,7 @@ module.exports.ObjectMethod = {
14
15
  print(path, printer, semantics) {
15
16
  const {print} = printer;
16
17
 
18
+ printKind(path, printer);
17
19
  printKey(path, printer);
18
20
  printParams(path, printer, semantics);
19
21
 
@@ -9,10 +9,19 @@ const {
9
9
  const {chain} = require('./chain');
10
10
  const {satisfy} = require('../../is');
11
11
 
12
+ const {maybePrintComputed} = require('../object-expression/maybe-print-computed');
13
+
12
14
  const isArgOfCall = (path) => path.parentPath.isCallExpression() && path.parentPath.get('arguments.0') === path;
13
15
 
14
- module.exports.MemberExpression = (path, {print, maybe, traverse}) => {
16
+ module.exports.MemberExpression = (path, printer) => {
17
+ const {
18
+ print,
19
+ maybe,
20
+ traverse,
21
+ } = printer;
22
+
15
23
  const object = path.get('object');
24
+ const property = path.get('property');
16
25
  const isParens = object.isAwaitExpression() || object.isAssignmentExpression();
17
26
  const {computed} = path.node;
18
27
 
@@ -20,13 +29,8 @@ module.exports.MemberExpression = (path, {print, maybe, traverse}) => {
20
29
  traverse(object);
21
30
  maybe.print(isParens, ')');
22
31
 
23
- if (computed) {
24
- print('[');
25
- print('__property');
26
- print(']');
27
-
28
- return;
29
- }
32
+ if (computed)
33
+ return maybePrintComputed(path, property, printer);
30
34
 
31
35
  const isChain = likeChain(path);
32
36
 
@@ -109,4 +113,3 @@ function likeChain(path) {
109
113
 
110
114
  return calls.length > 1;
111
115
  }
112
-
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ module.exports.maybePrintComputed = (path, key, {maybe, traverse}) => {
4
+ const {computed} = path.node;
5
+
6
+ maybe.write(computed, '[');
7
+ traverse(key);
8
+ maybe.write(computed, ']');
9
+ };
@@ -2,21 +2,24 @@
2
2
 
3
3
  const {isConcatenation} = require('../binary-expression/concatanate');
4
4
  const {isOneLine} = require('./object-expression');
5
+ const {printKey} = require('./print-key');
5
6
 
6
- module.exports.ObjectProperty = (path, {maybe, traverse, write}, semantics) => {
7
+ module.exports.ObjectProperty = (path, printer, semantics) => {
7
8
  const {trailingComma} = semantics;
8
- const {shorthand, computed} = path.node;
9
+ const {shorthand} = path.node;
10
+ const {
11
+ maybe,
12
+ traverse,
13
+ write,
14
+ } = printer;
9
15
 
10
- const key = path.get('key');
11
16
  const value = path.get('value');
12
17
 
13
18
  const properties = path.parentPath.get('properties');
14
19
  const isLast = path === properties.at(-1);
15
20
  const manyLines = !isOneLine(path.parentPath);
16
21
 
17
- maybe.write(computed, '[');
18
- traverse(key);
19
- maybe.write(computed, ']');
22
+ printKey(path, printer);
20
23
 
21
24
  if (!shorthand) {
22
25
  write(':');
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ const {maybePrintComputed} = require('./maybe-print-computed');
4
+
5
+ module.exports.printKey = (path, printer) => {
6
+ const key = path.get('key');
7
+
8
+ maybePrintComputed(path, key, printer);
9
+ };
@@ -18,6 +18,7 @@ const {moreThenMaxPropertiesInOneLine} = require('./more-then-max-properties-in-
18
18
 
19
19
  const {maybeTypeAnnotation} = require('../../maybe/maybe-type-annotation');
20
20
  const {moreThenMaxPropertiesLengthInOneLine} = require('./more-then-max-properties-length-in-one-line');
21
+ const {printKey} = require('../object-expression/print-key');
21
22
 
22
23
  const isTwoLevelsDeep = ({parentPath}) => parentPath.parentPath.parentPath.isObjectProperty();
23
24
  const isOneParentProperty = ({parentPath}) => parentPath.parentPath.node.properties?.length === 1;
@@ -37,13 +38,19 @@ const isCoupleProperties = ({path, valuePath, property}) => {
37
38
  };
38
39
 
39
40
  module.exports.ObjectPattern = {
40
- print: maybeTypeAnnotation((path, {print, maybe, indent}, semantics) => {
41
+ print: maybeTypeAnnotation((path, printer, semantics) => {
41
42
  const shouldIndent = isIndent(path);
42
43
  const {
43
44
  maxPropertiesInOneLine,
44
45
  maxPropertiesLengthInOneLine,
45
46
  } = semantics;
46
47
 
48
+ const {
49
+ print,
50
+ maybe,
51
+ indent,
52
+ } = printer;
53
+
47
54
  maybe.indent.inc(shouldIndent);
48
55
  print('{');
49
56
 
@@ -83,9 +90,7 @@ module.exports.ObjectPattern = {
83
90
  maybe.indent(is);
84
91
  maybe.print.breakline(couple);
85
92
 
86
- maybe.print(computed, '[');
87
- print(keyPath);
88
- maybe.print(computed, ']');
93
+ printKey(property, printer);
89
94
 
90
95
  if (!shorthand || wrongShorthand({computed, isAssign, keyPath, valuePath})) {
91
96
  print(':');
@@ -32,9 +32,10 @@ module.exports.CatchClause = (path, {print, maybe}) => {
32
32
 
33
33
  print.space();
34
34
  print('catch');
35
- print.space();
36
35
 
37
- if (param.node) {
36
+ if (!param.node) {
37
+ print.space();
38
+ } else {
38
39
  print('(');
39
40
  print(param);
40
41
  print(')');
@@ -1,15 +1,18 @@
1
1
  'use strict';
2
2
 
3
3
  const {printParams} = require('../../expressions/function/params');
4
- const {printKey} = require('../../expressions/function/kind');
4
+ const {printKind} = require('../../expressions/function/kind');
5
5
  const {
6
6
  hasReturnType,
7
7
  printReturnType,
8
8
  } = require('./print-return-type');
9
9
 
10
+ const {printKey} = require('../../expressions/object-expression/print-key');
11
+
10
12
  module.exports.TSMethodSignature = (path, printer, semantics) => {
11
13
  const {write} = printer;
12
14
 
15
+ printKind(path, printer);
13
16
  printKey(path, printer);
14
17
  printParams(path, printer, semantics);
15
18
 
@@ -7,23 +7,15 @@ const {
7
7
  isNext,
8
8
  } = require('../../is');
9
9
 
10
+ const {printKey} = require('../../expressions/object-expression/print-key');
11
+
10
12
  module.exports.TSPropertySignature = (path, printer) => {
11
- const {
12
- print,
13
- maybe,
14
- write,
15
- } = printer;
13
+ const {maybe, write} = printer;
16
14
 
17
- const {
18
- computed,
19
- optional,
20
- readonly,
21
- } = path.node;
15
+ const {optional, readonly} = path.node;
22
16
 
23
17
  maybe.print(readonly, 'readonly ');
24
- maybe.print(computed, '[');
25
- print('__key');
26
- maybe.print(computed, ']');
18
+ printKey(path, printer);
27
19
  maybe.print(optional, '?');
28
20
 
29
21
  maybePrintTypeAnnotation(path, printer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "9.6.0",
3
+ "version": "9.8.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",
@@ -45,6 +45,7 @@
45
45
  "generate"
46
46
  ],
47
47
  "devDependencies": {
48
+ "@putout/eslint": "^3.5.0",
48
49
  "@putout/plugin-minify": "^8.0.0",
49
50
  "@putout/plugin-printer": "^3.0.0",
50
51
  "@putout/plugin-promises": "^15.0.0",