@putout/printer 6.2.0 → 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,9 @@
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
+
1
7
  2023.11.09, v6.2.0
2
8
 
3
9
  feature:
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
@@ -19,6 +19,7 @@ module.exports.maybeJSON = (ast, overrides) => {
19
19
  semantics: {
20
20
  ...overrides?.semantics,
21
21
  trailingComma: false,
22
+ encodeSingleQuote: false,
22
23
  },
23
24
  };
24
25
  }
@@ -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.2.0",
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",
@@ -66,7 +66,7 @@
66
66
  "mock-require": "^3.0.3",
67
67
  "montag": "^1.0.0",
68
68
  "nodemon": "^3.0.1",
69
- "putout": "^32.0.4",
69
+ "putout": "^33.1.1",
70
70
  "supertape": "^8.0.0",
71
71
  "try-catch": "^3.0.0"
72
72
  },