@putout/printer 9.12.0 → 9.14.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.09.02, v9.14.0
2
+
3
+ feature:
4
+ - c75c1c5 @putout/printer: TSAsExpression: parens
5
+
6
+ 2024.09.01, v9.13.0
7
+
8
+ feature:
9
+ - 627dda0 @putout/printer: add AST validation
10
+ - 88ab70b @putout/printer: eslint-plugin-putout v23.0.0
11
+
1
12
  2024.08.24, v9.12.0
2
13
 
3
14
  feature:
package/lib/printer.js CHANGED
@@ -8,6 +8,8 @@ const {maybeVisitor} = require('./tokenize/maybe/index');
8
8
  const visitors = require('./tokenize/visitors');
9
9
 
10
10
  module.exports.print = (ast, overrides = {}) => {
11
+ check(ast);
12
+
11
13
  const options = maybeJSON(ast, overrides);
12
14
  const tokens = tokenize(ast, options);
13
15
 
@@ -16,3 +18,8 @@ module.exports.print = (ast, overrides = {}) => {
16
18
 
17
19
  module.exports.visitors = visitors;
18
20
  module.exports.maybeVisitor = maybeVisitor;
21
+
22
+ function check(ast) {
23
+ if (typeof ast !== 'object')
24
+ throw Error('☝️Looks like ast not an object');
25
+ }
@@ -121,4 +121,3 @@ module.exports.parseTrailingComments = (path, {write, maybe}, semantics) => {
121
121
  }
122
122
  }
123
123
  };
124
-
@@ -4,6 +4,7 @@ const {
4
4
  isNext,
5
5
  hasTrailingComment,
6
6
  } = require('../../is');
7
+
7
8
  const {printParams} = require('./params');
8
9
  const {maybeDecorators} = require('../../maybe/maybe-decorators');
9
10
  const {printKey} = require('../object-expression/print-key');
@@ -13,7 +13,8 @@ const {
13
13
 
14
14
  const {parseComments} = require('../../comment/comment');
15
15
  const {likeChain} = require('../member-expression/member-expressions');
16
- const {isStringLiteral} = require('@putout/babel').types;
16
+ const {types} = require('@putout/babel');
17
+ const {isStringLiteral} = types;
17
18
 
18
19
  const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
19
20
  const isLogical = (path) => path.get('argument').isLogicalExpression();
@@ -1,11 +1,13 @@
1
1
  'use strict';
2
2
 
3
3
  const {maybeParens} = require('../../expressions/function/parens');
4
- const {isObjectExpression} = require('@putout/babel').types;
4
+ const {
5
+ isVariableDeclarator,
6
+ isObjectExpression,
7
+ } = require('@putout/babel').types;
5
8
 
6
9
  module.exports.TSAsExpression = maybeParens((path, {print, maybe}) => {
7
- const {expression} = path.node;
8
- const is = isObjectExpression(expression);
10
+ const is = isParens(path);
9
11
 
10
12
  maybe.print(is, '(');
11
13
  print('__expression');
@@ -14,3 +16,12 @@ module.exports.TSAsExpression = maybeParens((path, {print, maybe}) => {
14
16
  print(' as ');
15
17
  print('__typeAnnotation');
16
18
  });
19
+
20
+ function isParens(path) {
21
+ const {expression} = path.node;
22
+
23
+ if (isVariableDeclarator(path.parentPath))
24
+ return false;
25
+
26
+ return isObjectExpression(expression);
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "9.12.0",
3
+ "version": "9.14.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",
@@ -56,7 +56,7 @@
56
56
  "check-dts": "^0.8.0",
57
57
  "escover": "^4.0.1",
58
58
  "eslint": "^9.0.0",
59
- "eslint-plugin-putout": "^22.0.0",
59
+ "eslint-plugin-putout": "^23.0.0",
60
60
  "estree-to-babel": "^9.0.0",
61
61
  "goldstein": "^5.14.0",
62
62
  "just-kebab-case": "^4.2.0",