@putout/plugin-remove-useless-escape 3.2.0 → 5.0.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.
@@ -1,10 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  const emojiRegex = require('emoji-regex');
4
- const {
5
- types,
6
- operator,
7
- } = require('putout');
4
+
5
+ const {types, operator} = require('putout');
8
6
 
9
7
  const {replaceWith} = operator;
10
8
  const {RegExpLiteral} = types;
@@ -15,6 +13,7 @@ module.exports.report = () => 'Unnecessary escape character';
15
13
  module.exports.fix = (path) => {
16
14
  if (path.isStringLiteral()) {
17
15
  const {raw} = path.node;
16
+
18
17
  path.node.raw = unEscape(raw);
19
18
 
20
19
  return;
@@ -22,6 +21,7 @@ module.exports.fix = (path) => {
22
21
 
23
22
  if (path.isRegExpLiteral()) {
24
23
  const {pattern, flags} = path.node;
24
+
25
25
  const unescaped = unescapeRegExp(pattern);
26
26
  const raw = `/${unescaped}/`;
27
27
 
@@ -48,9 +48,8 @@ module.exports.traverse = ({push}) => ({
48
48
  'RegExpLiteral'(path) {
49
49
  const {raw} = path.node;
50
50
 
51
- if (isEscapedRegExp(raw)) {
51
+ if (isEscapedRegExp(raw))
52
52
  push(path);
53
- }
54
53
  },
55
54
  '"__"'(path) {
56
55
  const {raw} = path.node;
@@ -69,6 +68,9 @@ module.exports.traverse = ({push}) => ({
69
68
  if (hasQuote(raw))
70
69
  return push(path);
71
70
 
71
+ if (raw.includes('\\"'))
72
+ return push(path);
73
+
72
74
  if (raw.includes(`\\'`) && !raw.includes(`\\\\'`))
73
75
  return push(path);
74
76
  }
@@ -105,6 +107,12 @@ function isEscaped(raw) {
105
107
  if (/\\\//g.test(raw))
106
108
  return true;
107
109
 
110
+ if (raw.includes('\\$'))
111
+ return true;
112
+
113
+ if (raw.includes('\\{'))
114
+ return true;
115
+
108
116
  if (raw.includes('\\+') && !raw.includes('\\\\+'))
109
117
  return true;
110
118
 
@@ -117,21 +125,20 @@ function isEscaped(raw) {
117
125
  if (hasA(raw))
118
126
  return true;
119
127
 
120
- if (hasComa(raw))
121
- return true;
122
-
123
- return false;
128
+ return hasComa(raw);
124
129
  }
125
130
 
126
131
  const createEncodedRegExp = (a) => RegExp(`\\\\${a}`, 'g');
127
132
 
128
133
  function unEscape(raw) {
129
134
  raw = raw
130
- .replaceAll('\\\'', `'`)
135
+ .replaceAll(`\\'`, `'`)
131
136
  .replaceAll('\\/', '/')
132
137
  .replaceAll('\\+', '+')
133
138
  .replace(createEncodedRegExp(`"`), '"')
134
139
  .replaceAll('\\^', '^')
140
+ .replaceAll('\\$', '$')
141
+ .replaceAll('\\{', '{')
135
142
  .replace(/(\\),/, ',');
136
143
 
137
144
  for (const emoji of match(raw)) {
@@ -159,4 +166,3 @@ function isEscapedRegExp(raw) {
159
166
 
160
167
  return isRegExpColon(raw) || isRegExpSlash(raw) || isComa(raw);
161
168
  }
162
-
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@putout/plugin-remove-useless-escape",
3
- "version": "3.2.0",
3
+ "version": "5.0.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds ability to find and remove useless escape",
7
7
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-escape#readme",
8
8
  "main": "lib/remove-useless-escape.js",
9
- "commitType": "colon",
10
9
  "release": false,
11
10
  "tag": false,
12
11
  "changelog": false,
@@ -38,19 +37,20 @@
38
37
  ],
39
38
  "devDependencies": {
40
39
  "@putout/plugin-madrun": "*",
41
- "@putout/test": "^5.0.0",
42
- "c8": "^7.5.0",
40
+ "@putout/plugin-regexp": "*",
41
+ "@putout/test": "^8.0.0",
42
+ "c8": "^8.0.0",
43
43
  "eslint": "^8.0.1",
44
- "eslint-plugin-n": "^15.2.4",
45
- "eslint-plugin-putout": "^16.0.0",
46
- "madrun": "^9.0.0"
44
+ "eslint-plugin-n": "^16.0.0",
45
+ "eslint-plugin-putout": "^22.0.0",
46
+ "madrun": "^10.0.0"
47
47
  },
48
48
  "peerDependencies": {
49
- "putout": ">=25"
49
+ "putout": ">=34"
50
50
  },
51
51
  "license": "MIT",
52
52
  "engines": {
53
- "node": ">=16"
53
+ "node": ">=18"
54
54
  },
55
55
  "publishConfig": {
56
56
  "access": "public"