@putout/printer 11.10.1 → 11.11.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.12.22, v11.11.0
2
+
3
+ feature:
4
+ - a9800ca @putout/printer: AssignmentExpression: inside BinaryExpression: parens
5
+
6
+ 2024.12.20, v11.10.2
7
+
8
+ feature:
9
+ - c9ced91 group imports
10
+ - be513ff @putout/printer: nodejs/declare-after-require: apply
11
+
1
12
  2024.12.19, v11.10.1
2
13
 
3
14
  feature:
package/lib/json.js CHANGED
@@ -1,11 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  const {types} = require('@putout/babel');
4
+ const {isJSON} = require('@putout/operator-json');
5
+
4
6
  const {
5
7
  isCallExpression,
6
8
  isIdentifier,
7
9
  } = types;
8
- const {isJSON} = require('@putout/operator-json');
9
10
 
10
11
  module.exports.maybeJSON = (ast, overrides) => {
11
12
  if (isASTJSON(ast))
@@ -1,16 +1,18 @@
1
1
  'use strict';
2
2
 
3
3
  const {types} = require('@putout/babel');
4
- const {
5
- isDecorator,
6
- isMemberExpression,
7
- } = types;
4
+
8
5
  const {
9
6
  isLast,
10
7
  isCoupleLines,
11
8
  isNext,
12
9
  } = require('../is');
13
10
 
11
+ const {
12
+ isDecorator,
13
+ isMemberExpression,
14
+ } = types;
15
+
14
16
  const hasBody = (path) => {
15
17
  if (path.isTSModuleDeclaration())
16
18
  return true;
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- const {stringify} = JSON;
4
- const {TYPES} = require('../types');
3
+ const process = require('node:process');
5
4
  const toSnakeCase = require('just-snake-case');
6
-
7
5
  const {codeFrameColumns} = require('@putout/babel');
6
+ const {TYPES} = require('../types');
8
7
 
8
+ const {stringify} = JSON;
9
9
  const {
10
10
  LOG,
11
11
  LOG_ALL,
@@ -2,6 +2,17 @@
2
2
 
3
3
  const {isSimple} = require('@putout/operate');
4
4
  const {types} = require('@putout/babel');
5
+
6
+ const {
7
+ isStringAndMember,
8
+ isStringAndIdentifier,
9
+ isIdentifierAndString,
10
+ isCoupleLines,
11
+ isStringAndArray,
12
+ isIdentifierAndIdentifier,
13
+ isSimpleAndNotEmptyObject,
14
+ } = require('../../is');
15
+
5
16
  const {
6
17
  isObjectExpression,
7
18
  isArrayExpression,
@@ -14,16 +25,6 @@ const {
14
25
  isSpreadElement,
15
26
  } = types;
16
27
 
17
- const {
18
- isStringAndMember,
19
- isStringAndIdentifier,
20
- isIdentifierAndString,
21
- isCoupleLines,
22
- isStringAndArray,
23
- isIdentifierAndIdentifier,
24
- isSimpleAndNotEmptyObject,
25
- } = require('../../is');
26
-
27
28
  const {round} = Math;
28
29
 
29
30
  const isOneSpread = (elements) => {
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
+ const {types} = require('@putout/babel');
3
4
  const {
4
5
  maybePrintLeftBrace,
5
6
  maybePrintRightBrace,
6
7
  } = require('./maybe-write-brace');
7
8
 
8
- const {types} = require('@putout/babel');
9
9
  const {
10
10
  isExpressionStatement,
11
11
  isAssignmentExpression,
@@ -30,6 +30,11 @@ function maybeWriteBrace(path, printer, semantics, {brace}) {
30
30
  return;
31
31
  }
32
32
 
33
+ if (type === 'BinaryExpression') {
34
+ write(brace);
35
+ return;
36
+ }
37
+
33
38
  if (type === 'UnaryExpression') {
34
39
  write(brace);
35
40
  return;
@@ -6,6 +6,7 @@ const {
6
6
  isTemplateLiteral,
7
7
  isBinaryExpression,
8
8
  } = types;
9
+
9
10
  const isStringLike = (a) => {
10
11
  if (isStringLiteral(a))
11
12
  return true;
@@ -1,14 +1,14 @@
1
1
  'use strict';
2
2
 
3
3
  const {types} = require('@putout/babel');
4
- const {isFunction} = types;
4
+
5
5
  const {isNext} = require('../../is');
6
6
  const {markAfter} = require('../../mark');
7
7
 
8
8
  const {maybeDeclare} = require('../../maybe/maybe-declare');
9
9
  const {parseComments} = require('../../comment/comment');
10
10
  const {maybeDecorators} = require('../../maybe/maybe-decorators');
11
-
11
+ const {isFunction} = types;
12
12
  const isInsideExport = ({parentPath}) => parentPath.isExportDeclaration();
13
13
  const isFunctionLike = (path) => isFunction(path.parentPath.parentPath);
14
14
  const hasBody = ({node}) => node.body.body.length;
@@ -1,14 +1,16 @@
1
1
  'use strict';
2
2
 
3
3
  const {types} = require('@putout/babel');
4
+
5
+ const {markAfter} = require('../../mark');
6
+ const {isNext, isNextParent} = require('../../is');
7
+ const {printParams} = require('./params');
8
+
4
9
  const {
5
10
  isTSModuleBlock,
6
11
  isBlockStatement,
7
12
  isExportNamedDeclaration,
8
13
  } = types;
9
- const {markAfter} = require('../../mark');
10
- const {isNext, isNextParent} = require('../../is');
11
- const {printParams} = require('./params');
12
14
 
13
15
  const isInsideNamedExport = ({parentPath}) => isExportNamedDeclaration(parentPath);
14
16
 
@@ -1,17 +1,19 @@
1
1
  'use strict';
2
2
 
3
3
  const {types} = require('@putout/babel');
4
- const {
5
- isUnaryExpression,
6
- isArrowFunctionExpression,
7
- isIfStatement,
8
- } = types;
4
+
9
5
  const {chain} = require('./chain');
10
6
  const {satisfy} = require('../../is');
11
7
 
12
8
  const {maybePrintComputed} = require('../object-expression/maybe-print-computed');
13
9
  const {maybeParens} = require('../../maybe/maybe-parens');
14
10
 
11
+ const {
12
+ isUnaryExpression,
13
+ isArrowFunctionExpression,
14
+ isIfStatement,
15
+ } = types;
16
+
15
17
  const isArgOfCall = (path) => path.parentPath.isCallExpression() && path.parentPath.get('arguments.0') === path;
16
18
 
17
19
  module.exports.MemberExpression = (path, printer) => {
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const {types} = require('@putout/babel');
3
4
  const {
4
5
  isCoupleLines,
5
6
  isForOf,
@@ -13,7 +14,7 @@ const {
13
14
 
14
15
  const {parseComments} = require('../../comment/comment');
15
16
  const {likeChain} = require('../member-expression/member-expressions');
16
- const {types} = require('@putout/babel');
17
+
17
18
  const {isStringLiteral} = types;
18
19
 
19
20
  const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
@@ -1,12 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {types} = require('@putout/babel');
4
- const {
5
- isIdentifier,
6
- isObjectPattern,
7
- isAssignmentPattern,
8
- isVariableDeclarator,
9
- } = types;
4
+
10
5
  const {wrongShorthand} = require('./wrong-shortand');
11
6
 
12
7
  const {
@@ -16,11 +11,18 @@ const {
16
11
  } = require('../../is');
17
12
 
18
13
  const {moreThenMaxPropertiesInOneLine} = require('./more-then-max-properties-in-one-line');
19
- const isInsideFn = (path) => path.parentPath.isFunction();
20
14
 
21
15
  const {maybeTypeAnnotation} = require('../../maybe/maybe-type-annotation');
22
16
  const {moreThenMaxPropertiesLengthInOneLine} = require('./more-then-max-properties-length-in-one-line');
23
17
  const {printKey} = require('../object-expression/print-key');
18
+ const isInsideFn = (path) => path.parentPath.isFunction();
19
+
20
+ const {
21
+ isIdentifier,
22
+ isObjectPattern,
23
+ isAssignmentPattern,
24
+ isVariableDeclarator,
25
+ } = types;
24
26
 
25
27
  function isIndent(path) {
26
28
  return !path.parentPath.isArrayPattern();
@@ -1,8 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  const rendy = require('rendy');
4
- const maybeSatisfy = require('./satisfy');
4
+
5
5
  const {types} = require('@putout/babel');
6
+ const maybeSatisfy = require('./satisfy');
7
+
6
8
  const {
7
9
  isProgram,
8
10
  isFile,
@@ -11,6 +13,7 @@ const {
11
13
  Program,
12
14
  isStatement,
13
15
  } = types;
16
+
14
17
  const isFn = (a) => typeof a === 'function';
15
18
 
16
19
  module.exports.maybeThrow = (a, path, b) => {
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const {types} = require('@putout/babel');
3
4
  const {
4
5
  isNext,
5
6
  isParentProgram,
@@ -8,7 +9,11 @@ const {
8
9
  satisfy,
9
10
  } = require('../../is');
10
11
 
11
- const {types} = require('@putout/babel');
12
+ const {markAfter} = require('../../mark');
13
+ const {parseComments} = require('../../comment/comment');
14
+ const {insideIfWithNoBody} = require('./inside-if-with-no-body');
15
+ const {getDirectives} = require('./get-directives');
16
+
12
17
  const {
13
18
  isArrowFunctionExpression,
14
19
  isObjectMethod,
@@ -17,10 +22,6 @@ const {
17
22
  isDoWhileStatement,
18
23
  isBlockStatement,
19
24
  } = types;
20
- const {markAfter} = require('../../mark');
21
- const {parseComments} = require('../../comment/comment');
22
- const {insideIfWithNoBody} = require('./inside-if-with-no-body');
23
- const {getDirectives} = require('./get-directives');
24
25
 
25
26
  const isFirstStatement = (path) => path.node.body[0];
26
27
  const isFirstDirective = (path) => path.node.directives?.[0];
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {types} = require('@putout/babel');
4
- const {isExportNamespaceSpecifier} = types;
4
+
5
5
  const {markAfter, isMarkedAfter} = require('../../mark');
6
6
 
7
7
  const {
@@ -11,6 +11,7 @@ const {
11
11
  isLast,
12
12
  } = require('../../is');
13
13
 
14
+ const {isExportNamespaceSpecifier} = types;
14
15
  const isDeclarationNewline = (path) => isMarkedAfter(path.get('declaration'));
15
16
  const isInsideNamespace = (path) => path.parentPath.isTSModuleBlock();
16
17
 
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {types} = require('@putout/babel');
4
- const {isJSXElement} = types;
4
+
5
5
  const {
6
6
  isPrevBody,
7
7
  noTrailingComment,
@@ -10,7 +10,7 @@ const {
10
10
 
11
11
  const {hasPrevNewline} = require('../../mark');
12
12
  const {maybeSpaceAfterKeyword} = require('./maybe-space-after-keyword');
13
-
13
+ const {isJSXElement} = types;
14
14
  const isBodyLength = ({parentPath}) => parentPath.node?.body?.length > 2;
15
15
 
16
16
  const isInsideIfWithElse = ({parentPath}) => parentPath.isIfStatement() && parentPath.node.alternate;
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const {types} = require('@putout/babel');
3
4
  const {
4
5
  isNext,
5
6
  isCoupleLines,
@@ -9,14 +10,13 @@ const {
9
10
  } = require('../../is');
10
11
 
11
12
  const {hasPrevNewline} = require('../../mark');
12
- const {types} = require('@putout/babel');
13
- const {isExportDeclaration} = types;
13
+
14
14
  const {maybeSpaceAfterKeyword} = require('./maybe-space-after-keyword');
15
15
 
16
16
  const {isConcatenation} = require('../../expressions/binary-expression/concatenate');
17
17
  const {parseLeadingComments} = require('../../comment/comment');
18
18
  const {maybeDeclare} = require('../../maybe/maybe-declare');
19
-
19
+ const {isExportDeclaration} = types;
20
20
  const isParentTSModuleBlock = (path) => path.parentPath.isTSModuleBlock();
21
21
  const isParentBlock = (path) => /Program|BlockStatement|Export|LabeledStatement/.test(path.parentPath.type);
22
22
  const isInsideBlock = (path) => /^(Program|BlockStatement|TSModuleBlock|SwitchCase)$/.test(path.parentPath.type);
@@ -1,8 +1,7 @@
1
1
  'use strict';
2
2
 
3
- const {round} = Math;
4
3
  const fullstore = require('fullstore');
5
- const isObject = (a) => a && typeof a === 'object';
4
+
6
5
  const babelTraverse = require('@putout/babel').traverse;
7
6
  const {TYPES} = require('../types');
8
7
  const baseVisitors = require('./visitors');
@@ -22,7 +21,8 @@ const {
22
21
  } = require('./comment/comment');
23
22
 
24
23
  const {parseOverrides} = require('./overrides/overrides');
25
-
24
+ const isObject = (a) => a && typeof a === 'object';
25
+ const {round} = Math;
26
26
  const isString = (a) => typeof a === 'string';
27
27
  const {assign, freeze} = Object;
28
28
 
@@ -1,15 +1,17 @@
1
1
  'use strict';
2
2
 
3
3
  const {types} = require('@putout/babel');
4
+
5
+ const {isNext, isNextParent} = require('../../is');
6
+ const {maybeDeclare} = require('../../maybe/maybe-declare');
7
+ const {markAfter} = require('../../mark');
8
+
4
9
  const {
5
10
  isTSTypeAliasDeclaration,
6
11
  isExportNamedDeclaration,
7
12
  isTSModuleBlock,
8
13
  } = types;
9
14
 
10
- const {isNext, isNextParent} = require('../../is');
11
- const {maybeDeclare} = require('../../maybe/maybe-declare');
12
- const {markAfter} = require('../../mark');
13
15
  const isInsideNamespace = (path) => isTSModuleBlock(path.parentPath.parentPath);
14
16
 
15
17
  module.exports.TSInterfaceDeclaration = {
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
- const {maybeParens} = require('../../maybe/maybe-parens');
4
3
  const {types} = require('@putout/babel');
4
+ const {maybeParens} = require('../../maybe/maybe-parens');
5
+
5
6
  const {
6
7
  isVariableDeclarator,
7
8
  isObjectExpression,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "11.10.1",
3
+ "version": "11.11.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",