@putout/printer 1.104.0 → 1.106.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.05.22, v1.106.0
2
+
3
+ feature:
4
+ - f859c20 @putout/printer: AssignmentExpression inside LogicalExpression (coderaiser/minify#100)
5
+
6
+ 2023.05.22, v1.105.0
7
+
8
+ feature:
9
+ - 44fa04d @putout/printer: ClassPrivateMethod: add support (putoutjs/minify#3)
10
+
1
11
  2023.05.22, v1.104.0
2
12
 
3
13
  feature:
package/README.md CHANGED
@@ -95,6 +95,57 @@ print(ast, {
95
95
  'const {a/* [hello world] */= 5} = b;\n';
96
96
  ```
97
97
 
98
+ ### `format`
99
+
100
+ With help of `format` you can override next options:
101
+
102
+ ```js
103
+ const overrides = {
104
+ format: {
105
+ indent: ' ',
106
+ newline: '\n',
107
+ space: ' ',
108
+ comments: true,
109
+ splitter: '\n',
110
+ },
111
+ };
112
+ ```
113
+
114
+ - `indent` - use two spaces, tabs, or anything you want;
115
+ - `newline` - symbol for used for line separation;
116
+ - `space` - default symbol used for space character;
117
+ - `comments` - produce comments in output or skip them;
118
+ - `splitter` - mandatory symbol that used inside of statements like this:
119
+
120
+ Default options produce:
121
+
122
+ ```js
123
+ if (a > 3)
124
+ console.log('ok');else
125
+ console.log('not ok');
126
+ ```
127
+
128
+ But you can override them with:
129
+
130
+ ```js
131
+ const overrides = {
132
+ format: {
133
+ indent: '',
134
+ newline: '',
135
+ space: '',
136
+ splitter: ' ',
137
+ },
138
+ };
139
+ ```
140
+
141
+ And have minified code:
142
+
143
+ ```js
144
+ if (a > 3)
145
+ console.log('ok');else
146
+ console.log('not ok');
147
+ ```
148
+
98
149
  ### `print`
99
150
 
100
151
  Used in previous example `print` can be used for a couple purposes:
@@ -3,12 +3,26 @@
3
3
  const {isObjectPattern} = require('@babel/types');
4
4
 
5
5
  module.exports.AssignmentExpression = {
6
- condition: (path) => isObjectPattern(path.node.left),
6
+ condition: (path) => {
7
+ const {
8
+ left,
9
+ extra,
10
+ } = path.node;
11
+
12
+ if (isObjectPattern(left))
13
+ return true;
14
+
15
+ if (extra?.parenthesized)
16
+ return true;
17
+
18
+ return path.parentPath.isLogicalExpression();
19
+ },
7
20
  before(path, {write}) {
8
21
  write('(');
9
22
  },
10
23
  print(path, {print}) {
11
24
  const {operator} = path.node;
25
+
12
26
  print('__left');
13
27
  print.space();
14
28
  print(operator);
@@ -2,7 +2,7 @@
2
2
 
3
3
  const {isNext} = require('../../is');
4
4
 
5
- module.exports.ClassMethod = {
5
+ const ClassMethod = {
6
6
  print(path, {print, maybe}) {
7
7
  const {kind} = path.node;
8
8
  const isConstructor = kind === 'constructor';
@@ -40,3 +40,6 @@ module.exports.ClassMethod = {
40
40
  print.linebreak();
41
41
  },
42
42
  };
43
+
44
+ module.exports.ClassPrivateMethod = ClassMethod;
45
+ module.exports.ClassMethod = ClassMethod;
@@ -2,7 +2,12 @@
2
2
 
3
3
  const {ArrowFunctionExpression} = require('./arrow-function-expression');
4
4
  const {FunctionDeclaration} = require('./function-declaration');
5
- const {ClassMethod} = require('./class-method');
5
+
6
+ const {
7
+ ClassMethod,
8
+ ClassPrivateMethod,
9
+ } = require('./class-method');
10
+
6
11
  const {ObjectMethod} = require('./object-method');
7
12
  const {FunctionExpression} = require('./function-expression');
8
13
 
@@ -10,4 +15,5 @@ module.exports.FunctionDeclaration = FunctionDeclaration;
10
15
  module.exports.FunctionExpression = FunctionExpression;
11
16
  module.exports.ArrowFunctionExpression = ArrowFunctionExpression;
12
17
  module.exports.ClassMethod = ClassMethod;
18
+ module.exports.ClassPrivateMethod = ClassPrivateMethod;
13
19
  module.exports.ObjectMethod = ObjectMethod;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.104.0",
3
+ "version": "1.106.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",
@@ -46,6 +46,7 @@
46
46
  "generate"
47
47
  ],
48
48
  "devDependencies": {
49
+ "@putout/plugin-minify": "^1.8.0",
49
50
  "@putout/plugin-printer": "^1.0.0",
50
51
  "@putout/plugin-react-hooks": "^5.0.0",
51
52
  "@putout/test": "^6.0.1",