@putout/plugin-remove-useless-escape 3.2.0 → 4.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;
@@ -105,6 +104,12 @@ function isEscaped(raw) {
105
104
  if (/\\\//g.test(raw))
106
105
  return true;
107
106
 
107
+ if (raw.includes('\\$'))
108
+ return true;
109
+
110
+ if (raw.includes('\\{'))
111
+ return true;
112
+
108
113
  if (raw.includes('\\+') && !raw.includes('\\\\+'))
109
114
  return true;
110
115
 
@@ -117,21 +122,20 @@ function isEscaped(raw) {
117
122
  if (hasA(raw))
118
123
  return true;
119
124
 
120
- if (hasComa(raw))
121
- return true;
122
-
123
- return false;
125
+ return hasComa(raw);
124
126
  }
125
127
 
126
128
  const createEncodedRegExp = (a) => RegExp(`\\\\${a}`, 'g');
127
129
 
128
130
  function unEscape(raw) {
129
131
  raw = raw
130
- .replaceAll('\\\'', `'`)
132
+ .replaceAll(`\\'`, `'`)
131
133
  .replaceAll('\\/', '/')
132
134
  .replaceAll('\\+', '+')
133
135
  .replace(createEncodedRegExp(`"`), '"')
134
136
  .replaceAll('\\^', '^')
137
+ .replaceAll('\\$', '$')
138
+ .replaceAll('\\{', '{')
135
139
  .replace(/(\\),/, ',');
136
140
 
137
141
  for (const emoji of match(raw)) {
@@ -159,4 +163,3 @@ function isEscapedRegExp(raw) {
159
163
 
160
164
  return isRegExpColon(raw) || isRegExpSlash(raw) || isComa(raw);
161
165
  }
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": "4.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,15 +37,16 @@
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": "^7.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",
44
+ "eslint-plugin-n": "^16.0.0",
45
+ "eslint-plugin-putout": "^21.0.0",
46
46
  "madrun": "^9.0.0"
47
47
  },
48
48
  "peerDependencies": {
49
- "putout": ">=25"
49
+ "putout": ">=33"
50
50
  },
51
51
  "license": "MIT",
52
52
  "engines": {