@putout/printer 1.29.0 → 1.31.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,13 @@
1
+ 2023.04.10, v1.31.0
2
+
3
+ feature:
4
+ - f80319e @putout/printer: add support of JSXAttribute
5
+
6
+ 2023.04.10, v1.30.0
7
+
8
+ feature:
9
+ - 27b22b3 @putout/printer: add support of JSXElement
10
+
1
11
  2023.04.07, v1.29.0
2
12
 
3
13
  feature:
@@ -1,13 +1,15 @@
1
1
  'use strict';
2
2
 
3
3
  const {hasPrevNewline} = require('../mark');
4
- const isFirst = (path) => !path
5
- .getPrevSibling().node;
4
+ const isFirst = (path) => !path.getPrevSibling().node;
6
5
 
7
6
  module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
8
7
  const {node} = path;
9
8
 
10
- const {generator, async} = node;
9
+ const {
10
+ generator,
11
+ async,
12
+ } = node;
11
13
 
12
14
  maybe.print(async, 'async ');
13
15
  print('function');
@@ -3,13 +3,8 @@
3
3
  const {isCoupleLines} = require('../is');
4
4
  const {isFunction} = require('@babel/types');
5
5
  const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
6
-
7
- const isLogical = (path) => path
8
- .get('argument').isLogicalExpression();
9
-
10
- const isValue = (path) => path
11
- .get('properties.0.value').node;
12
-
6
+ const isLogical = (path) => path.get('argument').isLogicalExpression();
7
+ const isValue = (path) => path.get('properties.0.value').node;
13
8
  const isIf = (path) => path.parentPath.parentPath.isIfStatement();
14
9
  const isParentExpression = (path) => path.parentPath.isExpressionStatement();
15
10
 
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ const {JSXElement} = require('./jsx-element');
4
+
5
+ module.exports = {
6
+ JSXElement,
7
+ JSXOpeningElement(path, {print}) {
8
+ print('<');
9
+ print('__name');
10
+
11
+ for (const attr of path.get('attributes')) {
12
+ print.space();
13
+ print(attr);
14
+ }
15
+
16
+ print('>');
17
+ },
18
+ JSXAttribute(path, {print}) {
19
+ print('__name');
20
+ print('=');
21
+ print('__value');
22
+ },
23
+ JSXIdentifier(path, {write}) {
24
+ write(path.node.name);
25
+ },
26
+ JSXText(path, {write}) {
27
+ write(path.node.value);
28
+ },
29
+ JSXClosingElement(path, {print}) {
30
+ print('</');
31
+ print('__name');
32
+ print('>');
33
+ },
34
+ };
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ module.exports.JSXElement = {
4
+ condition,
5
+ before(path, {write, indent}) {
6
+ write('(');
7
+ write.breakline();
8
+ indent();
9
+ indent.inc();
10
+ },
11
+ print(path, {print, traverse}) {
12
+ print('__openingElement');
13
+ path.get('children').map(traverse);
14
+ print('__closingElement');
15
+ },
16
+ after(path, {write, indent}) {
17
+ indent.dec();
18
+ write.breakline();
19
+ write(')');
20
+ },
21
+ };
22
+
23
+ function condition(path) {
24
+ return path.parentPath.isReturnStatement();
25
+ }
@@ -27,10 +27,11 @@ function objectPlugin(plugin, path, printer) {
27
27
  const {
28
28
  print,
29
29
  split,
30
+ condition,
30
31
  before = split,
31
- beforeIf,
32
+ beforeIf = condition,
32
33
  after = split,
33
- afterIf,
34
+ afterIf = condition,
34
35
  } = plugin;
35
36
 
36
37
  if (beforeIf?.(path, printer)) {
@@ -6,9 +6,7 @@ const {
6
6
  } = require('../mark');
7
7
 
8
8
  const {isFirst} = require('../is');
9
-
10
- const isEmptyConsequent = (path) => path
11
- .get('consequent').isEmptyStatement();
9
+ const isEmptyConsequent = (path) => path.get('consequent').isEmptyStatement();
12
10
 
13
11
  module.exports.IfStatement = {
14
12
  before: (path, {print}) => {
@@ -8,6 +8,7 @@ const expressions = require('./expressions');
8
8
  const statements = require('./statements');
9
9
  const literals = require('./literals');
10
10
  const typescript = require('./typescript');
11
+ const jsx = require('./jsx');
11
12
  const {TYPES} = require('../types');
12
13
 
13
14
  const {
@@ -38,6 +39,7 @@ const traversers = {
38
39
  ...statements,
39
40
  ...literals,
40
41
  ...typescript,
42
+ ...jsx,
41
43
  };
42
44
 
43
45
  const GET = '__';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.29.0",
3
+ "version": "1.31.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Easiest possible opinionated Babel AST printer made with ❤️ to use in 🐊Putout",