@putout/printer 9.15.2 → 9.16.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,9 @@
1
+ 2024.09.27, v9.16.0
2
+
3
+ feature:
4
+ - 3cf8ea6 @putout/printer: strict mode: newline
5
+ - 41c63a8 @putout/printer: FunctionExpression: IIFE: improve support
6
+
1
7
  2024.09.11, v9.15.2
2
8
 
3
9
  fix:
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- const {isArray} = Array;
4
3
  const {exists} = require('../is');
4
+ const {isArray} = Array;
5
5
 
6
6
  const parseArgs = (path) => {
7
7
  const argsPath = path.get('arguments');
@@ -6,13 +6,19 @@ const {printParams} = require('./params');
6
6
 
7
7
  module.exports.FunctionDeclaration = {
8
8
  print(path, printer, semantics) {
9
- const {print, maybe} = printer;
9
+ const {
10
+ print,
11
+ maybe,
12
+ indent,
13
+ } = printer;
14
+
10
15
  const {
11
16
  async,
12
17
  generator,
13
18
  returnType,
14
19
  } = path.node;
15
20
 
21
+ indent();
16
22
  maybe.print(async, 'async ');
17
23
 
18
24
  print('function');
@@ -4,16 +4,7 @@ const {TemplateLiteral} = require('./template-literal');
4
4
  const {Identifier} = require('./identifier');
5
5
 
6
6
  const {Decorator} = require('../expressions/decorator');
7
-
8
- const maybeEncode = (value, {encodeDoubleQuote, encodeSingleQuote}) => {
9
- if (encodeSingleQuote && !value.includes('\\'))
10
- return value.replaceAll(`'`, `\\'`);
11
-
12
- if (encodeDoubleQuote && !value.includes('\\"'))
13
- return value.replaceAll(`"`, '\\"');
14
-
15
- return value;
16
- };
7
+ const {StringLiteral} = require('./string-literal');
17
8
 
18
9
  module.exports = {
19
10
  Identifier,
@@ -44,27 +35,7 @@ module.exports = {
44
35
  BooleanLiteral(path, {write}) {
45
36
  write(path.node.value);
46
37
  },
47
- StringLiteral(path, {write}, semantics) {
48
- const {raw, value} = path.node;
49
-
50
- if (raw && path.parentPath.isJSXAttribute()) {
51
- write(raw);
52
- return;
53
- }
54
-
55
- if (raw) {
56
- const value = raw.slice(1, -1);
57
- write.quote();
58
- write(maybeEncode(value, semantics));
59
- write.quote();
60
-
61
- return;
62
- }
63
-
64
- write.quote();
65
- write(value);
66
- write.quote();
67
- },
38
+ StringLiteral,
68
39
  RegExpLiteral(path, {print}) {
69
40
  const {raw, pattern} = path.node;
70
41
  print(raw || `/${pattern}/`);
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ const maybeEncode = (value, {encodeDoubleQuote, encodeSingleQuote}) => {
4
+ if (encodeSingleQuote && !value.includes('\\'))
5
+ return value.replaceAll(`'`, `\\'`);
6
+
7
+ if (encodeDoubleQuote && !value.includes('\\"'))
8
+ return value.replaceAll(`"`, '\\"');
9
+
10
+ return value;
11
+ };
12
+
13
+ module.exports.StringLiteral = (path, {write}, semantics) => {
14
+ const {raw, value} = path.node;
15
+
16
+ if (raw && path.parentPath.isJSXAttribute()) {
17
+ write(raw);
18
+ return;
19
+ }
20
+
21
+ if (raw) {
22
+ const value = raw.slice(1, -1);
23
+ write.quote();
24
+ write(maybeEncode(value, semantics));
25
+ write.quote();
26
+
27
+ return;
28
+ }
29
+
30
+ write.quote();
31
+ write(value);
32
+ write.quote();
33
+ };
@@ -58,6 +58,8 @@ module.exports.BlockStatement = {
58
58
  traverse(directive);
59
59
  }
60
60
 
61
+ maybe.write.linebreak(directives.length && body.length);
62
+
61
63
  for (const element of body) {
62
64
  traverse(element);
63
65
  }
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
- module.exports.ForInStatement = (path, {print}) => {
3
+ module.exports.ForInStatement = (path, {print, indent}) => {
4
+ indent();
4
5
  print('for');
5
6
  print.space();
6
7
  print('(');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "9.15.2",
3
+ "version": "9.16.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",
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
15
- "url": "git://github.com/putoutjs/printer.git"
15
+ "url": "git+https://github.com/putoutjs/printer.git"
16
16
  },
17
17
  "scripts": {
18
18
  "wisdom": "madrun wisdom",