@putout/printer 6.3.0 → 6.4.1

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.11.16, v6.4.1
2
+
3
+ fix:
4
+ - a96503f @putout/printer: duplicated comments (babel/babel#16106)
5
+
6
+ 2023.11.15, v6.4.0
7
+
8
+ feature:
9
+ - a5a01f0 @putout/printer: use @putout/operator-json instead of processors
10
+
1
11
  2023.11.12, v6.3.0
2
12
 
3
13
  feature:
package/lib/json.js CHANGED
@@ -5,11 +5,10 @@ const {
5
5
  isIdentifier,
6
6
  } = require('@putout/babel').types;
7
7
 
8
- const {isJSON} = require('@putout/processor-json/is-json');
9
- const {isFilesystem} = require('@putout/processor-filesystem/is-filesystem');
8
+ const {isJSON} = require('@putout/operator-json');
10
9
 
11
10
  module.exports.maybeJSON = (ast, overrides) => {
12
- if (isASTJSON(ast)) {
11
+ if (isASTJSON(ast))
13
12
  return {
14
13
  ...overrides,
15
14
  format: {
@@ -22,7 +21,6 @@ module.exports.maybeJSON = (ast, overrides) => {
22
21
  encodeSingleQuote: false,
23
22
  },
24
23
  };
25
- }
26
24
 
27
25
  return overrides;
28
26
  };
@@ -48,11 +46,5 @@ function isASTJSON(ast) {
48
46
  if (!isIdentifier(callee))
49
47
  return false;
50
48
 
51
- const {name} = callee;
52
-
53
- if (isJSON(name))
54
- return true;
55
-
56
- if (isFilesystem(name))
57
- return true;
49
+ return isJSON(callee.name);
58
50
  }
@@ -10,6 +10,8 @@ const {
10
10
  const {markBefore} = require('../mark');
11
11
  const {maybeInsideFn} = require('./maybe-inside-fn');
12
12
 
13
+ const deduplicate = (a) => Array.from(new Set(a));
14
+
13
15
  const {
14
16
  isObjectProperty,
15
17
  isVariableDeclarator,
@@ -43,7 +45,7 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
43
45
  const propIs = isProperty(path);
44
46
  const isIndent = !looksLikeSwitchCase && !path.isClassMethod() && !insideFn && !propIs;
45
47
 
46
- for (const {type, value} of leadingComments) {
48
+ for (const {type, value} of deduplicate(leadingComments)) {
47
49
  maybe.indent(isIndent);
48
50
 
49
51
  if (type === 'CommentLine') {
@@ -56,9 +56,8 @@ module.exports.createLog = ({newline = '\n', store = createStore()} = {}) => ({t
56
56
  store(value);
57
57
  }
58
58
 
59
- if (LOG_TERM) {
59
+ if (LOG_TERM)
60
60
  process.stdout.write(value);
61
- }
62
61
  };
63
62
 
64
63
  function createStore() {
@@ -65,9 +65,8 @@ module.exports.ArrayExpression = {
65
65
 
66
66
  const indented = !isTwoLongStrings(elements) || !isInsideArray(path) && isIndented(elements[0]);
67
67
 
68
- if (indented) {
68
+ if (indented)
69
69
  maybe.indent.inc(shouldIncreaseIndent);
70
- }
71
70
 
72
71
  const isNewLine = isNewlineBetweenElements(path, {
73
72
  elements,
@@ -47,7 +47,6 @@ module.exports.concatanate = (path, {print, indent}) => {
47
47
  print.breakline();
48
48
  print('__right');
49
49
 
50
- if (!path.parentPath.isBinaryExpression()) {
50
+ if (!path.parentPath.isBinaryExpression())
51
51
  indent.dec();
52
- }
53
52
  };
@@ -36,9 +36,8 @@ function CallExpression(path, {indent, print, maybe, traverse}) {
36
36
  for (const [i, arg] of args.entries()) {
37
37
  const isObject = arg.isObjectExpression();
38
38
 
39
- if (isParentCall && !isObject && n) {
39
+ if (isParentCall && !isObject && n)
40
40
  print.breakline();
41
- }
42
41
 
43
42
  print(arg);
44
43
 
@@ -53,9 +53,8 @@ const classVisitor = maybeDecorators((path, printer, semantics) => {
53
53
  traverse(item);
54
54
  }
55
55
 
56
- if (!body.length) {
56
+ if (!body.length)
57
57
  parseComments(classBody, printer, semantics);
58
- }
59
58
 
60
59
  indent.dec();
61
60
  maybe.indent(body.length);
@@ -64,12 +64,11 @@ function build(path) {
64
64
  type: path.type,
65
65
  };
66
66
 
67
- if (path.isCallExpression()) {
67
+ if (path.isCallExpression())
68
68
  assign(prop, {
69
69
  args: path.node.arguments.length,
70
70
  name: path.node.callee.property?.name || '',
71
71
  });
72
- }
73
72
 
74
73
  return prop;
75
74
  }
@@ -33,9 +33,8 @@ module.exports.MemberExpression = (path, {print, maybe, traverse}) => {
33
33
 
34
34
  maybe.indent.inc(isChain);
35
35
 
36
- if (isChain) {
36
+ if (isChain)
37
37
  print.breakline();
38
- }
39
38
 
40
39
  print('.');
41
40
  print('__property');
@@ -50,13 +50,11 @@ function objectPlugin(plugin, path, printer, options) {
50
50
  afterIf = condition,
51
51
  } = maybeSatisfy(plugin);
52
52
 
53
- if (beforeIf?.(path, printer)) {
53
+ if (beforeIf?.(path, printer))
54
54
  before(path, printer);
55
- }
56
55
 
57
56
  print(path, printer, options);
58
57
 
59
- if (afterIf?.(path, printer)) {
58
+ if (afterIf?.(path, printer))
60
59
  after(path, printer);
61
- }
62
60
  }
@@ -18,13 +18,12 @@ module.exports.maybeDecorators = (visitor) => (path, printer, semantics, options
18
18
 
19
19
  const {decorators} = path.node;
20
20
 
21
- if (decorators) {
21
+ if (decorators)
22
22
  for (const decorator of path.get('decorators')) {
23
23
  maybe.write.breakline(isPrevClassProperty(path));
24
24
  traverse(decorator);
25
25
  write.breakline();
26
26
  }
27
- }
28
27
 
29
28
  visitor(path, printer, semantics, options);
30
29
  };
@@ -65,9 +65,8 @@ module.exports.BlockStatement = {
65
65
  maybe.indent(body.length);
66
66
  write('}');
67
67
 
68
- if (path.parentPath.isObjectMethod()) {
68
+ if (path.parentPath.isObjectMethod())
69
69
  write(',');
70
- }
71
70
  },
72
71
  afterIf(path) {
73
72
  return shouldAddNewlineAfter(path);
@@ -75,9 +75,8 @@ module.exports.ExportNamedDeclaration = {
75
75
  maybe.write(isType, 'type ');
76
76
  traverse(spec);
77
77
 
78
- if (i < lastIndex && !isNewline) {
78
+ if (i < lastIndex && !isNewline)
79
79
  write(', ');
80
- }
81
80
 
82
81
  maybe.write(isNewline, ',');
83
82
  maybe.write.newline(isNewline);
@@ -61,13 +61,11 @@ module.exports.ExpressionStatement = {
61
61
  return isBeforeElse(path);
62
62
  },
63
63
  after(path, {print, maybe, store}) {
64
- if (hasTrailingComment(path) && isLast(path) && isCoupleLines(path)) {
64
+ if (hasTrailingComment(path) && isLast(path) && isCoupleLines(path))
65
65
  print.breakline();
66
- }
67
66
 
68
- if (hasTrailingComment(path) && !isCoupleLines(path)) {
67
+ if (hasTrailingComment(path) && !isCoupleLines(path))
69
68
  return;
70
- }
71
69
 
72
70
  print.newline();
73
71
  maybe.markAfter(store(), path);
@@ -38,9 +38,8 @@ module.exports.IfStatement = {
38
38
  print.space();
39
39
  print(consequent);
40
40
 
41
- if (isInsideIf(path) || isInsideNestedBody(path)) {
41
+ if (isInsideIf(path) || isInsideNestedBody(path))
42
42
  maybe.print.newline(isEmptyBody(consequent));
43
- }
44
43
  } else {
45
44
  const is = !isEmptyConsequent(path);
46
45
  maybe.print.newline(is);
@@ -268,9 +268,8 @@ const createPrint = (path, {traverse, write}) => (maybeLine) => {
268
268
  };
269
269
 
270
270
  const computePath = (path, maybeLine) => {
271
- if (isString(maybeLine) && maybeLine.startsWith(GET)) {
271
+ if (isString(maybeLine) && maybeLine.startsWith(GET))
272
272
  return get(path, maybeLine);
273
- }
274
273
 
275
274
  if (isObject(maybeLine))
276
275
  return maybeLine;
@@ -17,11 +17,10 @@ module.exports.TSTypeParameter = (path, {write, traverse}) => {
17
17
  if (!exists(constraint))
18
18
  return;
19
19
 
20
- if (constraint.isTSTypeOperator() || path.parentPath.isTSMappedType()) {
20
+ if (constraint.isTSTypeOperator() || path.parentPath.isTSMappedType())
21
21
  write(' in ');
22
- } else {
22
+ else
23
23
  write(' extends ');
24
- }
25
24
 
26
25
  traverse(constraint);
27
26
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "6.3.0",
3
+ "version": "6.4.1",
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",
@@ -30,8 +30,7 @@
30
30
  "@putout/babel": "^1.1.1",
31
31
  "@putout/compare": "^13.0.0",
32
32
  "@putout/operate": "^11.0.0",
33
- "@putout/processor-filesystem": "^1.1.0",
34
- "@putout/processor-json": "^7.0.0",
33
+ "@putout/operator-json": "^1.2.0",
35
34
  "fullstore": "^3.0.0",
36
35
  "just-snake-case": "^3.2.0",
37
36
  "parse-import-specifiers": "^1.0.1",