@putout/printer 6.1.1 → 6.3.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.11.12, v6.3.0
2
+
3
+ feature:
4
+ - d4795dc @putout/printer: putout v33.1.1
5
+ - 68439dd @putout/printer: StringLiteral: encode single quote (coderaiser/putout#192)
6
+
7
+ 2023.11.09, v6.2.0
8
+
9
+ feature:
10
+ - 6892d1c @putout/printer: json: add support of @putout/processor-filesystem
11
+
1
12
  2023.11.03, v6.1.1
2
13
 
3
14
  fix:
package/README.md CHANGED
@@ -98,6 +98,7 @@ print(ast, {
98
98
  maxVariablesInOneLine: 4,
99
99
  maxPropertiesInOneLine: 2,
100
100
  trailingComma: true,
101
+ encodeSingleQuote: true,
101
102
  },
102
103
  visitors: {
103
104
  AssignmentPattern(path, {print}) {
package/lib/json.js CHANGED
@@ -6,6 +6,7 @@ const {
6
6
  } = require('@putout/babel').types;
7
7
 
8
8
  const {isJSON} = require('@putout/processor-json/is-json');
9
+ const {isFilesystem} = require('@putout/processor-filesystem/is-filesystem');
9
10
 
10
11
  module.exports.maybeJSON = (ast, overrides) => {
11
12
  if (isASTJSON(ast)) {
@@ -18,6 +19,7 @@ module.exports.maybeJSON = (ast, overrides) => {
18
19
  semantics: {
19
20
  ...overrides?.semantics,
20
21
  trailingComma: false,
22
+ encodeSingleQuote: false,
21
23
  },
22
24
  };
23
25
  }
@@ -46,5 +48,11 @@ function isASTJSON(ast) {
46
48
  if (!isIdentifier(callee))
47
49
  return false;
48
50
 
49
- return isJSON(callee.name);
51
+ const {name} = callee;
52
+
53
+ if (isJSON(name))
54
+ return true;
55
+
56
+ if (isFilesystem(name))
57
+ return true;
50
58
  }
@@ -1,9 +1,15 @@
1
1
  'use strict';
2
2
 
3
3
  const {TemplateLiteral} = require('./template-literal');
4
-
5
4
  const {Identifier} = require('./identifier');
6
5
 
6
+ const maybeEncode = (value, {encodeSingleQuote}) => {
7
+ if (encodeSingleQuote && !value.includes('\\'))
8
+ return value.replaceAll(`'`, `\\'`);
9
+
10
+ return value;
11
+ };
12
+
7
13
  module.exports = {
8
14
  Identifier,
9
15
  TemplateLiteral,
@@ -36,7 +42,7 @@ module.exports = {
36
42
  BooleanLiteral(path, {write}) {
37
43
  write(path.node.value);
38
44
  },
39
- StringLiteral(path, {write}) {
45
+ StringLiteral(path, {write}, semantics) {
40
46
  const {raw, value} = path.node;
41
47
 
42
48
  if (raw && path.parentPath.isJSXAttribute()) {
@@ -47,7 +53,7 @@ module.exports = {
47
53
  if (raw) {
48
54
  const value = raw.slice(1, -1);
49
55
  write.quote();
50
- write(value);
56
+ write(maybeEncode(value, semantics));
51
57
  write.quote();
52
58
 
53
59
  return;
@@ -36,6 +36,7 @@ function initSemantics(semantics = {}) {
36
36
  maxElementsInOneLine: 5,
37
37
  maxVariablesInOneLine: 4,
38
38
  trailingComma: true,
39
+ encodeSingleQuote: true,
39
40
  ...semantics,
40
41
  };
41
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "6.1.1",
3
+ "version": "6.3.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",
@@ -30,6 +30,7 @@
30
30
  "@putout/babel": "^1.1.1",
31
31
  "@putout/compare": "^13.0.0",
32
32
  "@putout/operate": "^11.0.0",
33
+ "@putout/processor-filesystem": "^1.1.0",
33
34
  "@putout/processor-json": "^7.0.0",
34
35
  "fullstore": "^3.0.0",
35
36
  "just-snake-case": "^3.2.0",
@@ -65,7 +66,7 @@
65
66
  "mock-require": "^3.0.3",
66
67
  "montag": "^1.0.0",
67
68
  "nodemon": "^3.0.1",
68
- "putout": "^32.0.4",
69
+ "putout": "^33.1.1",
69
70
  "supertape": "^8.0.0",
70
71
  "try-catch": "^3.0.0"
71
72
  },