@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 +11 -0
- package/README.md +9 -2
- package/lib/{is-json.js → json.js} +17 -4
- package/lib/printer.js +2 -10
- package/lib/tokenize/comment/parse-leading-comments.js +1 -1
- package/lib/tokenize/debug.js +2 -2
- package/lib/tokenize/expressions/array-expression/array-expression.js +2 -1
- package/lib/tokenize/expressions/array-expression/new-line.js +1 -1
- package/lib/tokenize/expressions/assignment-expression.js +1 -1
- package/lib/tokenize/expressions/binary-expression/concatanate.js +1 -1
- package/lib/tokenize/expressions/member-expression/member-expressions.js +1 -1
- package/lib/tokenize/expressions/object-pattern/object-pattern.js +1 -1
- package/lib/tokenize/is.js +1 -1
- package/lib/tokenize/maybe/index.js +1 -1
- package/lib/tokenize/statements/block-statement/block-statement.js +1 -1
- package/lib/tokenize/statements/export-declaration/export-declaration.js +1 -1
- package/lib/tokenize/statements/variable-declaration/variable-declaration.js +1 -1
- package/lib/tokenize/tokenize.js +1 -1
- package/lib/tokenize/typescript/interface/ts-interface-declaration.js +1 -1
- package/lib/tokenize/typescript/ts-mapped-type.js +1 -1
- package/lib/tokenize/typescript/type/ts-type-literal.js +1 -1
- package/package.json +2 -5
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
|
|
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
|
-
|
|
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 {
|
|
6
|
-
const {assign} = Object;
|
|
5
|
+
const {maybeJSON} = require('./json');
|
|
7
6
|
|
|
8
7
|
module.exports.print = (ast, overrides = {}) => {
|
|
9
|
-
|
|
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
|
|
4
|
+
const {isVariableDeclarator} = require('@putout/babel').types;
|
|
5
5
|
|
|
6
6
|
const {markBefore} = require('../mark');
|
|
7
7
|
const {maybeInsideFn} = require('./maybe-inside-fn');
|
package/lib/tokenize/debug.js
CHANGED
|
@@ -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
|
|
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
|
|
package/lib/tokenize/is.js
CHANGED
|
@@ -9,7 +9,7 @@ const {
|
|
|
9
9
|
isVariableDeclaration,
|
|
10
10
|
isMemberExpression,
|
|
11
11
|
isArrayExpression,
|
|
12
|
-
} = require('@babel
|
|
12
|
+
} = require('@putout/babel').types;
|
|
13
13
|
|
|
14
14
|
const isParentProgram = (path) => path.parentPath?.isProgram();
|
|
15
15
|
const isParentBlock = (path) => path.parentPath.isBlockStatement();
|
|
@@ -8,7 +8,7 @@ const {
|
|
|
8
8
|
} = require('../../is');
|
|
9
9
|
|
|
10
10
|
const {markAfter, isMarkedAfter} = require('../../mark');
|
|
11
|
-
const {isExportNamespaceSpecifier} = require('@babel
|
|
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
|
|
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');
|
package/lib/tokenize/tokenize.js
CHANGED
|
@@ -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
|
|
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');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "4.
|
|
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
|
|
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",
|