@putout/printer 11.14.0 → 12.1.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,15 @@
1
+ 2025.01.12, v12.1.0
2
+
3
+ feature:
4
+ - 93a6b0b @putout/printer: JSX: indent
5
+
6
+ 2025.01.11, v12.0.0
7
+
8
+ feature:
9
+ - 610ea6e @putout/printer: babel alpha v15
10
+ - 8093095 @putout/printer: CallExpression: typeParameters -> typeArguments
11
+ - d628037 @putout/printer: @putout/babel v3.0.0
12
+
1
13
  2025.01.05, v11.14.0
2
14
 
3
15
  feature:
@@ -26,9 +26,7 @@ const isFnParam = (path) => {
26
26
  if (!parentPath.isFunction())
27
27
  return false;
28
28
 
29
- return parentPath
30
- .get('params')
31
- .includes(path);
29
+ return parentPath.get('params').includes(path);
32
30
  };
33
31
 
34
32
  function isSameLine(path, loc) {
@@ -57,9 +57,7 @@ const isSpreadBeforeObject = (a) => {
57
57
  if (prev.getPrevSibling().isObjectExpression())
58
58
  return false;
59
59
 
60
- return prev
61
- .get('argument')
62
- .isCallExpression();
60
+ return prev.get('argument').isCallExpression();
63
61
  };
64
62
 
65
63
  const isNextSimple = (a) => {
@@ -245,13 +245,9 @@ function isNumbers(elements) {
245
245
  return false;
246
246
  }
247
247
 
248
- function isLastArg({parentPath}) {
249
- return !parentPath.isCallExpression();
250
- }
248
+ const isLastArg = ({parentPath}) => !parentPath.isCallExpression();
251
249
 
252
- function isParentProperty(path) {
253
- return path.find(isObjectProperty);
254
- }
250
+ const isParentProperty = (path) => path.find(isObjectProperty);
255
251
 
256
252
  module.exports.isIncreaseIndent = isIncreaseIndent;
257
253
  function isIncreaseIndent(path) {
@@ -18,7 +18,7 @@ const CallExpression = maybeParens((path, {indent, print, maybe, traverse}) => {
18
18
  const isParentCall = tooLong(args) && path.parentPath.isCallExpression();
19
19
 
20
20
  const callee = path.get('callee');
21
- const typeParameters = path.get('typeParameters');
21
+ const typeParameters = path.get('typeArguments');
22
22
 
23
23
  traverse(callee);
24
24
 
@@ -44,9 +44,7 @@ const classVisitor = maybeDecorators((path, printer, semantics) => {
44
44
 
45
45
  if (node.implements) {
46
46
  print(' implements ');
47
- path
48
- .get('implements')
49
- .forEach(print);
47
+ path.get('implements').forEach(print);
50
48
  }
51
49
 
52
50
  print.space();
@@ -2,9 +2,7 @@
2
2
 
3
3
  const {parseComments} = require('../../comment/comment');
4
4
 
5
- function parseParams(path) {
6
- return path.get('params');
7
- }
5
+ const parseParams = (path) => path.get('params');
8
6
 
9
7
  module.exports.printParams = (path, printer, semantics, customization = {}) => {
10
8
  const {extra, typeParameters} = path.node;
@@ -83,16 +83,14 @@ const isIfUp = (path) => {
83
83
  if (!ifPath)
84
84
  return is;
85
85
 
86
- ifPath
87
- .get('test')
88
- .traverse({
89
- MemberExpression(currentPath) {
90
- if (path === currentPath) {
91
- is = true;
92
- path.stop();
93
- }
94
- },
95
- });
86
+ ifPath.get('test').traverse({
87
+ MemberExpression(currentPath) {
88
+ if (path === currentPath) {
89
+ is = true;
90
+ path.stop();
91
+ }
92
+ },
93
+ });
96
94
 
97
95
  return is;
98
96
  };
@@ -39,7 +39,7 @@ module.exports.NewExpression = {
39
39
  const {print, maybe} = printer;
40
40
  print('new ');
41
41
  print('__callee');
42
- print('__typeParameters');
42
+ print('__typeArguments');
43
43
 
44
44
  const args = path.get('arguments');
45
45
  maybePrintOpenBrace(path, printer, semantics);
@@ -142,9 +142,7 @@ const notLastArgInsideCall = (path) => {
142
142
  if (isCoupleLines(path))
143
143
  return false;
144
144
 
145
- return path !== parentPath
146
- .get('arguments')
147
- .at(-1);
145
+ return path !== parentPath.get('arguments').at(-1);
148
146
  };
149
147
 
150
148
  const ONE_LINE = true;
@@ -20,7 +20,7 @@ module.exports.UnaryExpression = unaryExpression;
20
20
  module.exports.UpdateExpression = unaryExpression;
21
21
 
22
22
  module.exports.AwaitExpression = maybeParens((path, {print}) => {
23
- printUnary(path, 'await', {
23
+ printUnary('await', {
24
24
  print,
25
25
  });
26
26
  });
@@ -37,7 +37,7 @@ module.exports.YieldExpression = maybeParens((path, {print, maybe}) => {
37
37
  module.exports.ThrowStatement = (path, {print, indent, maybe}) => {
38
38
  indent();
39
39
 
40
- printUnary(path, 'throw', {
40
+ printUnary('throw', {
41
41
  print,
42
42
  });
43
43
 
@@ -46,7 +46,7 @@ module.exports.ThrowStatement = (path, {print, indent, maybe}) => {
46
46
  maybe.print.breakline(isNext(path));
47
47
  };
48
48
 
49
- function printUnary(path, name, {print}) {
49
+ function printUnary(name, {print}) {
50
50
  print(`${name} `);
51
51
  print('__argument');
52
52
  }
@@ -35,11 +35,17 @@ const isPrev = (path) => {
35
35
  const isNextParent = (path) => isNext(path.parentPath);
36
36
  const isLast = (path) => isParentProgram(path) && !isNext(path);
37
37
 
38
- module.exports.isNextObject = (a) => a.getNextSibling().isObjectExpression();
39
- module.exports.isPrevObject = (a) => a.getPrevSibling().isObjectExpression();
38
+ module.exports.isNextObject = (a) => a
39
+ .getNextSibling()
40
+ .isObjectExpression();
41
+ module.exports.isPrevObject = (a) => a
42
+ .getPrevSibling()
43
+ .isObjectExpression();
40
44
 
41
45
  module.exports.isFirst = (path) => path.node === path.parentPath.node.body?.[0];
42
- module.exports.isPrevBody = (path) => path.getPrevSibling().isBlockStatement();
46
+ module.exports.isPrevBody = (path) => path
47
+ .getPrevSibling()
48
+ .isBlockStatement();
43
49
  module.exports.isNext = isNext;
44
50
  module.exports.isPrev = isPrev;
45
51
  module.exports.isNextParent = isNextParent;
@@ -17,22 +17,16 @@ module.exports.JSXElement = {
17
17
  write.newline();
18
18
  }
19
19
  },
20
- print(path, {print, traverse, indent}) {
21
- const insideFn = path.parentPath.isArrowFunctionExpression();
22
- const insideCall = path.parentPath.parentPath.isCallExpression();
23
-
24
- if (insideFn && insideCall)
25
- indent.inc();
20
+ print(path, {print, traverse, maybe}) {
21
+ const needIndent = isNeedIndent(path);
22
+ maybe.indent.inc(needIndent);
26
23
 
27
24
  print('__openingElement');
28
- path
29
- .get('children')
30
- .map(traverse);
25
+ path.get('children').map(traverse);
31
26
 
32
27
  print('__closingElement');
33
28
 
34
- if (insideFn && insideCall)
35
- indent.dec();
29
+ maybe.indent.dec(needIndent);
36
30
  },
37
31
  after(path, {write, indent, maybe}) {
38
32
  const {leadingComments} = path.node;
@@ -62,3 +56,16 @@ function condition(path) {
62
56
 
63
57
  return path.parentPath.isVariableDeclarator();
64
58
  }
59
+
60
+ function isNeedIndent(path) {
61
+ const attributesCount = path.node.openingElement.attributes.length;
62
+
63
+ if (attributesCount > 3)
64
+ return false;
65
+
66
+ const insideFn = path.parentPath.isArrowFunctionExpression();
67
+ const insideJSX = path.parentPath.isJSXElement();
68
+ const insideCall = path.parentPath.parentPath.isCallExpression();
69
+
70
+ return insideJSX || insideFn && insideCall;
71
+ }
@@ -9,9 +9,7 @@ module.exports.JSXFragment = {
9
9
  },
10
10
  print(path, {print, traverse}) {
11
11
  print('__openingFragment');
12
- path
13
- .get('children')
14
- .map(traverse);
12
+ path.get('children').map(traverse);
15
13
  print('__closingFragment');
16
14
  },
17
15
  after(path, {write, indent}) {
@@ -16,32 +16,28 @@ module.exports.parseOverrides = (overrides = {}) => {
16
16
  };
17
17
  };
18
18
 
19
- function initFormat(format) {
20
- return {
21
- indent: ' ',
22
- newline: '\n',
23
- space: ' ',
24
- splitter: '\n',
25
- quote: `'`,
26
- endOfFile: '\n',
27
- ...format,
28
- };
29
- }
19
+ const initFormat = (format) => ({
20
+ indent: ' ',
21
+ newline: '\n',
22
+ space: ' ',
23
+ splitter: '\n',
24
+ quote: `'`,
25
+ endOfFile: '\n',
26
+ ...format,
27
+ });
30
28
 
31
- function initSemantics(semantics = {}) {
32
- return {
33
- comments: true,
34
- maxPropertiesInOneLine: 2,
35
- maxPropertiesLengthInOneLine: 15,
36
- maxSpecifiersInOneLine: 2,
37
- maxElementsInOneLine: 5,
38
- maxLogicalsInOneLine: 3,
39
- maxVariablesInOneLine: 4,
40
- maxTypesInOneLine: 3,
41
- trailingComma: true,
42
- encodeSingleQuote: true,
43
- encodeDoubleQuote: false,
44
- ...semantics,
45
- roundBraces: parseRoundBraces(semantics),
46
- };
47
- }
29
+ const initSemantics = (semantics = {}) => ({
30
+ comments: true,
31
+ maxPropertiesInOneLine: 2,
32
+ maxPropertiesLengthInOneLine: 15,
33
+ maxSpecifiersInOneLine: 2,
34
+ maxElementsInOneLine: 5,
35
+ maxLogicalsInOneLine: 3,
36
+ maxVariablesInOneLine: 4,
37
+ maxTypesInOneLine: 3,
38
+ trailingComma: true,
39
+ encodeSingleQuote: true,
40
+ encodeDoubleQuote: false,
41
+ ...semantics,
42
+ roundBraces: parseRoundBraces(semantics),
43
+ });
@@ -22,9 +22,7 @@ module.exports.Program = (path, printer, semantics) => {
22
22
  maybe.write.newline(body.length);
23
23
  }
24
24
 
25
- path
26
- .get('body')
27
- .forEach(traverse);
25
+ path.get('body').forEach(traverse);
28
26
 
29
27
  if (directives.length && !body.length)
30
28
  return;
@@ -204,7 +204,5 @@ const isNextAssign = (path) => {
204
204
  if (parentPath.isBlockStatement() && parentPath.node.body.length < 3)
205
205
  return false;
206
206
 
207
- return nextPath
208
- .get('expression')
209
- .isAssignmentExpression();
207
+ return nextPath.get('expression').isAssignmentExpression();
210
208
  };
@@ -24,7 +24,7 @@ module.exports.TSEnumDeclaration = {
24
24
  indent.inc();
25
25
  print.newline();
26
26
 
27
- for (const member of path.get('members')) {
27
+ for (const member of path.get('body.members')) {
28
28
  traverse(member);
29
29
  print(',');
30
30
  print.newline();
@@ -136,7 +136,7 @@ module.exports = {
136
136
  },
137
137
  TSInstantiationExpression(path, {print}) {
138
138
  print('__expression');
139
- print('__typeParameters');
139
+ print('__typeArguments');
140
140
  },
141
141
  TSAnyKeyword(path, {write}) {
142
142
  write('any');
@@ -165,7 +165,7 @@ module.exports = {
165
165
  },
166
166
  TSClassImplements(path, {print}) {
167
167
  print('__expression');
168
- print('__typeParameters');
168
+ print('__typeArguments');
169
169
  },
170
170
  TSInterfaceHeritage(path, {print}) {
171
171
  print('__expression');
@@ -24,9 +24,7 @@ module.exports.TSInterfaceDeclaration = {
24
24
 
25
25
  if (node.extends) {
26
26
  print(' extends ');
27
- path
28
- .get('extends')
29
- .map(print);
27
+ path.get('extends').map(print);
30
28
  }
31
29
 
32
30
  print('__typeParameters');
@@ -8,8 +8,14 @@ const {
8
8
 
9
9
  const {markAfter} = require('../../mark');
10
10
  const {maybeDeclare} = require('../../maybe/maybe-declare');
11
- const isNextType = (a) => a.getNextSibling().isTSTypeAliasDeclaration();
12
- const isNextExport = (a) => a.getNextSibling().isExportDeclaration();
11
+
12
+ const isNextType = (a) => a
13
+ .getNextSibling()
14
+ .isTSTypeAliasDeclaration();
15
+
16
+ const isNextExport = (a) => a
17
+ .getNextSibling()
18
+ .isExportDeclaration();
13
19
 
14
20
  module.exports.TSTypeAliasDeclaration = {
15
21
  beforeIf: (path) => !path.parentPath.isExportDeclaration(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "11.14.0",
3
+ "version": "12.1.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",
@@ -32,7 +32,7 @@
32
32
  "report": "madrun report"
33
33
  },
34
34
  "dependencies": {
35
- "@putout/babel": "^2.0.0",
35
+ "@putout/babel": "^3.0.0",
36
36
  "@putout/compare": "^15.0.2",
37
37
  "@putout/operate": "^12.0.0",
38
38
  "@putout/operator-json": "^2.0.0",