@putout/printer 1.59.0 → 1.61.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,13 @@
1
+ 2023.04.20, v1.61.0
2
+
3
+ feature:
4
+ - ff23a6b @putout/printer: add support of ClassProperty
5
+
6
+ 2023.04.20, v1.60.0
7
+
8
+ feature:
9
+ - 4ed5ce4 @putout/printer: improve support of clases
10
+
1
11
  2023.04.20, v1.59.0
2
12
 
3
13
  feature:
@@ -8,6 +8,7 @@ const {
8
8
  LOG,
9
9
  LOG_ALL,
10
10
  LOG_TOKENS,
11
+ LOG_TERM,
11
12
  DEBUG,
12
13
  } = process.env;
13
14
 
@@ -54,6 +55,10 @@ module.exports.createLog = ({newline = '\n', store = createStore()} = {}) => ({t
54
55
 
55
56
  store(value);
56
57
  }
58
+
59
+ if (LOG_TERM) {
60
+ process.stdout.write(value);
61
+ }
57
62
  };
58
63
 
59
64
  function createStore() {
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ module.exports.ClassProperty = (path, {print}) => {
4
+ print('__key');
5
+ print.space();
6
+ print('=');
7
+ print.space();
8
+ print('__value');
9
+ print(';');
10
+ print.newline();
11
+ };
@@ -1,32 +1,42 @@
1
1
  'use strict';
2
2
 
3
- module.exports.ClassMethod = (path, {print, maybe}) => {
4
- const {kind} = path.node;
5
- const isConstructor = kind === 'constructor';
6
- const isMethod = kind === 'method';
7
- const isGetter = /get|set/.test(kind);
8
-
9
- maybe.print(isConstructor, kind);
10
- maybe.print(isMethod, '__key');
11
-
12
- if (isGetter) {
13
- print(kind);
14
- print(' ');
15
- print('__key');
16
- }
17
-
18
- print('(');
19
-
20
- const params = path.get('params');
21
- const n = params.length;
22
-
23
- for (let i = 0; i < n; i++) {
24
- print(params[i]);
3
+ const {isNext} = require('../../is');
4
+
5
+ module.exports.ClassMethod = {
6
+ print(path, {print, maybe}) {
7
+ const {kind} = path.node;
8
+ const isConstructor = kind === 'constructor';
9
+ const isMethod = kind === 'method';
10
+ const isGetter = /get|set/.test(kind);
11
+
12
+ maybe.print(isConstructor, kind);
13
+ maybe.print(isMethod, '__key');
14
+
15
+ if (isGetter) {
16
+ print(kind);
17
+ print(' ');
18
+ print('__key');
19
+ }
20
+
21
+ print('(');
22
+
23
+ const params = path.get('params');
24
+ const n = params.length;
25
+
26
+ for (let i = 0; i < n; i++) {
27
+ print(params[i]);
28
+
29
+ if (i < n - 1)
30
+ print(', ');
31
+ }
25
32
 
26
- if (i < n - 1)
27
- print(', ');
28
- }
29
-
30
- print(') ');
31
- print('__body');
33
+ print(') ');
34
+ print('__body');
35
+ },
36
+ afterSatisfy: () => [
37
+ isNext,
38
+ ],
39
+ after(path, {print}) {
40
+ print.linebreak();
41
+ },
32
42
  };
@@ -22,6 +22,7 @@ const {
22
22
  } = require('./object-expression');
23
23
 
24
24
  const {ObjectPattern} = require('./object-pattern');
25
+ const {ClassProperty} = require('./class-property');
25
26
  const {AssignmentExpression} = require('./assignment-expression');
26
27
  const {ArrayExpression} = require('./array-expression');
27
28
  const {ArrayPattern} = require('./array-pattern');
@@ -49,6 +50,7 @@ module.exports = {
49
50
  BinaryExpression,
50
51
  CallExpression,
51
52
  ClassExpression,
53
+ ClassProperty,
52
54
  ClassDeclaration,
53
55
  ConditionalExpression,
54
56
  NewExpression,
@@ -20,7 +20,8 @@ module.exports = {
20
20
  write(path.node.name);
21
21
  },
22
22
  JSXText(path, {write}) {
23
- write(path.node.value);
23
+ const {value} = path.node;
24
+ write(value);
24
25
  },
25
26
  JSXMemberExpression(path, {print}) {
26
27
  print('__object');
@@ -46,4 +46,3 @@ module.exports = {
46
46
  write('super');
47
47
  },
48
48
  };
49
-
@@ -100,10 +100,8 @@ module.exports.tokenize = (ast, overrides = {}) => {
100
100
  });
101
101
 
102
102
  const linebreak = () => {
103
- addToken({
104
- type: TYPES.NEWLINE,
105
- value: `${printIndent(i, format.indent)}\n`,
106
- });
103
+ indent();
104
+ newline();
107
105
  };
108
106
 
109
107
  const space = () => {
@@ -114,15 +112,8 @@ module.exports.tokenize = (ast, overrides = {}) => {
114
112
  };
115
113
 
116
114
  const breakline = () => {
117
- addToken({
118
- type: TYPES.NEWLINE,
119
- value: '\n',
120
- });
121
-
122
- addToken({
123
- type: TYPES.SPACE,
124
- value: printIndent(i, format.indent),
125
- });
115
+ newline();
116
+ indent();
126
117
  };
127
118
 
128
119
  const newline = () => {
@@ -219,7 +210,10 @@ module.exports.tokenize = (ast, overrides = {}) => {
219
210
 
220
211
  const currentIndent = i;
221
212
  parseLeadingComments(path, printer);
213
+
214
+ // this is main thing
222
215
  maybePlugin(currentTraverse, path, printer);
216
+
223
217
  parseTrailingComments(path, printer);
224
218
  maybeThrow(i !== currentIndent, path, `☝️Looks like indent level changed after token visitor: '{{ type }}', for code: '{{ path }}'`);
225
219
  debug(path.type);
package/lib/types.js CHANGED
@@ -6,4 +6,5 @@ module.exports.TYPES = {
6
6
  LINEBREAK: 'Linebreak',
7
7
  INDENT: 'Indent',
8
8
  DEBUG: 'Debug',
9
+ SPACE: 'Space',
9
10
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.59.0",
3
+ "version": "1.61.0",
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",
@@ -45,6 +45,7 @@
45
45
  "generate"
46
46
  ],
47
47
  "devDependencies": {
48
+ "@putout/plugin-react-hooks": "^5.0.0",
48
49
  "@putout/test": "^6.0.1",
49
50
  "acorn": "^8.8.2",
50
51
  "c8": "^7.5.0",