@putout/printer 4.0.0 → 4.2.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
+ 2023.09.13, v4.2.0
2
+
3
+ feature:
4
+ - d5b4479 @putout/printer: babel 7 -> babel 8
5
+ - dd1b24e @putout/printer: typescript: newline -> breakline
6
+
7
+ 2023.09.04, v4.1.0
8
+
9
+ feature:
10
+ - 317718e @putout/printer: imporove JSON support
11
+
1
12
  2023.09.03, v4.0.0
2
13
 
3
14
  feature:
package/README.md CHANGED
@@ -1,7 +1,13 @@
1
- # Printer [![NPM version][NPMIMGURL]][NPMURL]
1
+ # Printer [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage Status][CoverageIMGURL]][CoverageURL]
2
2
 
3
- [NPMIMGURL]: https://img.shields.io/npm/v/@putout/printer.svg?style=flat&longCache=true
4
3
  [NPMURL]: https://npmjs.org/package/@putout/printer "npm"
4
+ [NPMIMGURL]: https://img.shields.io/npm/v/@putout/printer.svg?style=flat&longCache=true
5
+ [BuildStatusURL]: https://github.com/putoutjs/printer/actions/workflows/nodejs.yml "Build Status"
6
+ [BuildStatusIMGURL]: https://github.com/putoutjs/printer/actions/workflows/nodejs.yml/badge.svg
7
+ [LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"
8
+ [LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
9
+ [CoverageURL]: https://coveralls.io/github/putoutjs/printer?branch=master
10
+ [CoverageIMGURL]: https://coveralls.io/repos/putoutjs/printer/badge.svg?branch=master&service=github
5
11
 
6
12
  Prints [**Babel AST**](https://github.com/coderaiser/estree-to-babel) to readable **JavaScript**. For Babel 7 use `@putout/printer` v2.
7
13
 
@@ -15,6 +21,7 @@ Supports:
15
21
  - ✅ **ES2023**;
16
22
  - ✅ **JSX**;
17
23
  - ✅ **TypeScript**;
24
+ - ✅ [**JSON**](https://github.com/coderaiser/putout/tree/master/packages/processor-json#readme);
18
25
 
19
26
  ## Install
20
27
 
@@ -3,10 +3,24 @@
3
3
  const {
4
4
  isCallExpression,
5
5
  isIdentifier,
6
- } = require('@babel/types');
6
+ } = require('@putout/babel').types;
7
+
7
8
  const {isJSON} = require('@putout/processor-json/is-json');
9
+ const {assign} = Object;
10
+
11
+ module.exports.maybeJSON = (ast, overrides) => {
12
+ if (isASTJSON(ast))
13
+ assign(overrides, {
14
+ format: {
15
+ quote: `"`,
16
+ },
17
+ semantics: {
18
+ trailingComma: false,
19
+ },
20
+ });
21
+ };
8
22
 
9
- module.exports.isASTJSON = (ast) => {
23
+ function isASTJSON(ast) {
10
24
  const {program} = ast;
11
25
 
12
26
  if (!program)
@@ -28,5 +42,4 @@ module.exports.isASTJSON = (ast) => {
28
42
  return false;
29
43
 
30
44
  return isJSON(callee.name);
31
- };
32
-
45
+ }
package/lib/printer.js CHANGED
@@ -2,19 +2,11 @@
2
2
 
3
3
  const {tokenize} = require('./tokenize/tokenize');
4
4
  const {printTokens} = require('./print-tokens');
5
- const {isASTJSON} = require('./is-json');
6
- const {assign} = Object;
5
+ const {maybeJSON} = require('./json');
7
6
 
8
7
  module.exports.print = (ast, overrides = {}) => {
9
- if (isASTJSON(ast))
10
- assign(overrides, {
11
- format: {
12
- quote: `"`,
13
- },
14
- });
15
-
8
+ maybeJSON(ast, overrides);
16
9
  const tokens = tokenize(ast, overrides);
17
10
 
18
11
  return printTokens(tokens);
19
12
  };
20
-
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {hasTrailingComment} = require('../is');
4
- const {isVariableDeclarator} = require('@babel/types');
4
+ const {isVariableDeclarator} = require('@putout/babel').types;
5
5
 
6
6
  const {markBefore} = require('../mark');
7
7
  const {maybeInsideFn} = require('./maybe-inside-fn');
@@ -4,6 +4,8 @@ const {stringify} = JSON;
4
4
  const {TYPES} = require('../types');
5
5
  const toSnakeCase = require('just-snake-case');
6
6
 
7
+ const {codeFrameColumns} = require('@putout/babel');
8
+
7
9
  const {
8
10
  LOG,
9
11
  LOG_ALL,
@@ -12,8 +14,6 @@ const {
12
14
  DEBUG,
13
15
  } = process.env;
14
16
 
15
- const {codeFrameColumns} = require('@babel/code-frame');
16
-
17
17
  module.exports.createDebug = (tokens) => (a) => {
18
18
  if (!DEBUG)
19
19
  return;
@@ -17,7 +17,7 @@ const {
17
17
  const {
18
18
  isObjectExpression,
19
19
  isStringLiteral,
20
- } = require('@babel/types');
20
+ } = require('@putout/babel').types;
21
21
 
22
22
  const isNextObject = (a) => a.getNextSibling().isObjectExpression();
23
23
 
@@ -57,6 +57,7 @@ module.exports.ArrayExpression = {
57
57
  maxElementsInOneLine,
58
58
  trailingComma,
59
59
  } = semantics;
60
+
60
61
  const elements = path.get('elements');
61
62
  const shouldIncreaseIndent = !isIncreaseIndent(path);
62
63
 
@@ -12,7 +12,7 @@ const {
12
12
  isNullLiteral,
13
13
  isStringLiteral,
14
14
  isSpreadElement,
15
- } = require('@babel/types');
15
+ } = require('@putout/babel').types;
16
16
 
17
17
  const {
18
18
  isStringAndMember,
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {isObjectPattern} = require('@babel/types');
3
+ const {isObjectPattern} = require('@putout/babel').types;
4
4
  const {isParens} = require('./unary-expression/parens');
5
5
 
6
6
  module.exports.AssignmentExpression = {
@@ -4,7 +4,7 @@ const {
4
4
  isStringLiteral,
5
5
  isTemplateLiteral,
6
6
  isBinaryExpression,
7
- } = require('@babel/types');
7
+ } = require('@putout/babel').types;
8
8
 
9
9
  const isStringLike = (a) => {
10
10
  if (isStringLiteral(a))
@@ -5,7 +5,7 @@ const {
5
5
  isArrowFunctionExpression,
6
6
  isLogicalExpression,
7
7
  isIfStatement,
8
- } = require('@babel/types');
8
+ } = require('@putout/babel').types;
9
9
 
10
10
  const {chain} = require('./chain');
11
11
  const {satisfy} = require('../../is');
@@ -4,7 +4,7 @@ const {
4
4
  isIdentifier,
5
5
  isObjectPattern,
6
6
  isAssignmentPattern,
7
- } = require('@babel/types');
7
+ } = require('@putout/babel').types;
8
8
 
9
9
  const {wrongShorthand} = require('./wrong-shortand');
10
10
 
@@ -9,7 +9,7 @@ const {
9
9
  isVariableDeclaration,
10
10
  isMemberExpression,
11
11
  isArrayExpression,
12
- } = require('@babel/types');
12
+ } = require('@putout/babel').types;
13
13
 
14
14
  const isParentProgram = (path) => path.parentPath?.isProgram();
15
15
  const isParentBlock = (path) => path.parentPath.isBlockStatement();
@@ -10,7 +10,7 @@ const {
10
10
  ExpressionStatement,
11
11
  Program,
12
12
  isStatement,
13
- } = require('@babel/types');
13
+ } = require('@putout/babel').types;
14
14
 
15
15
  const isFn = (a) => typeof a === 'function';
16
16
 
@@ -10,7 +10,7 @@ const {
10
10
  const {
11
11
  isArrowFunctionExpression,
12
12
  isObjectMethod,
13
- } = require('@babel/types');
13
+ } = require('@putout/babel').types;
14
14
 
15
15
  const {markAfter} = require('../../mark');
16
16
  const {parseComments} = require('../../comment/comment');
@@ -8,7 +8,7 @@ const {
8
8
  } = require('../../is');
9
9
 
10
10
  const {markAfter, isMarkedAfter} = require('../../mark');
11
- const {isExportNamespaceSpecifier} = require('@babel/types');
11
+ const {isExportNamespaceSpecifier} = require('@putout/babel').types;
12
12
  const isDeclarationNewline = (path) => isMarkedAfter(path.get('declaration'));
13
13
  const isInsideNamespace = (path) => path.parentPath.isTSModuleBlock();
14
14
 
@@ -9,7 +9,7 @@ const {
9
9
  } = require('../../is');
10
10
 
11
11
  const {hasPrevNewline} = require('../../mark');
12
- const {isExportDeclaration} = require('@babel/types');
12
+ const {isExportDeclaration} = require('@putout/babel').types;
13
13
  const {maybeSpaceAfterKeyword} = require('./maybe-space-after-keyword');
14
14
 
15
15
  const {isConcatenation} = require('../../expressions/binary-expression/concatanate');
@@ -3,7 +3,7 @@
3
3
  const {round} = Math;
4
4
  const fullstore = require('fullstore');
5
5
  const isObject = (a) => a && typeof a === 'object';
6
- const babelTraverse = require('@babel/traverse').default;
6
+ const babelTraverse = require('@putout/babel').traverse;
7
7
  const expressions = require('./expressions');
8
8
  const statements = require('./statements');
9
9
  const literals = require('./literals');
@@ -4,7 +4,7 @@ const {isNext, isNextParent} = require('../../is');
4
4
  const {
5
5
  isTSTypeAliasDeclaration,
6
6
  isExportDeclaration,
7
- } = require('@babel/types');
7
+ } = require('@putout/babel').types;
8
8
 
9
9
  module.exports.TSInterfaceDeclaration = {
10
10
  print(path, {print}) {
@@ -28,6 +28,6 @@ module.exports.TSMappedType = (path, {print, write, indent, maybe}) => {
28
28
  print('__typeAnnotation');
29
29
  write(';');
30
30
  indent.dec();
31
- write.newline();
31
+ write.breakline();
32
32
  write('}');
33
33
  };
@@ -23,8 +23,8 @@ module.exports.TSTypeLiteral = (path, {indent, traverse, write, maybe}) => {
23
23
  }
24
24
 
25
25
  if (is) {
26
- write.newline();
27
26
  indent.dec();
27
+ write.breakline();
28
28
  }
29
29
 
30
30
  write('}');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "4.0.0",
3
+ "version": "4.2.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",
@@ -26,10 +26,7 @@
26
26
  "report": "madrun report"
27
27
  },
28
28
  "dependencies": {
29
- "@babel/code-frame": "^7.18.6",
30
- "@babel/parser": "^7.19.0",
31
- "@babel/traverse": "^7.21.2",
32
- "@babel/types": "^7.21.3",
29
+ "@putout/babel": "^1.1.1",
33
30
  "@putout/compare": "^12.0.4",
34
31
  "@putout/operate": "^10.0.2",
35
32
  "@putout/processor-json": "^7.0.0",