@putout/plugin-remove-useless-escape 2.1.0 → 3.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.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-remove-useless-escape.svg?style=flat&longCache=true
4
4
  [NPMURL]: https://npmjs.org/package/@putout/plugin-remove-useless-escape"npm"
5
5
 
6
- 🐊[`Putout`](https://github.com/coderaiser/putout) plugin adds ability to find and remove useless escape.
6
+ 🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to find and remove useless escape.
7
7
 
8
8
  ## Install
9
9
 
@@ -21,7 +21,7 @@ npm i @putout/plugin-remove-useless-escape
21
21
  }
22
22
  ```
23
23
 
24
- ## ❌ Incorrect code example
24
+ ## ❌ Example of incorrect code
25
25
 
26
26
  ```js
27
27
  const t = 'hello \"world\"';
@@ -30,7 +30,7 @@ const s = `hello \'world\'`;
30
30
  const reg = /\w\:/g;
31
31
  ```
32
32
 
33
- ## ✅ Correct code Example
33
+ ## ✅ Example of correct code
34
34
 
35
35
  ```js
36
36
  const t = 'hello "world"';
@@ -47,8 +47,9 @@ module.exports.traverse = ({push}) => ({
47
47
  'RegExpLiteral'(path) {
48
48
  const {raw} = path.node;
49
49
 
50
- if (isEscapedRegExp(raw))
50
+ if (isEscapedRegExp(raw)) {
51
51
  push(path);
52
+ }
52
53
  },
53
54
  '"__"'(path) {
54
55
  const {raw} = path.node;
@@ -97,6 +98,9 @@ function isEscaped(raw) {
97
98
  if (!raw.includes('\\'))
98
99
  return false;
99
100
 
101
+ if (/\\\//g.test(raw) && !/\\\\\//g.test(raw))
102
+ return true;
103
+
100
104
  if (raw.includes('\\+') && !raw.includes('\\\\+'))
101
105
  return true;
102
106
 
@@ -120,6 +124,7 @@ const createEncodedRegExp = (a) => RegExp(`\\\\${a}`, 'g');
120
124
  function unEscape(raw) {
121
125
  raw = raw
122
126
  .replace(/\\'/g, `'`)
127
+ .replace(/\\\//g, '/')
123
128
  .replace(/\\\+/g, '+')
124
129
  .replace(createEncodedRegExp(`"`), '"')
125
130
  .replace(/\\\^/g, '^')
@@ -145,6 +150,9 @@ const isComa = is(',');
145
150
  const isRegExpSlash = (a) => a.includes('\\\\\\\\');
146
151
 
147
152
  function isEscapedRegExp(raw) {
153
+ if (raw.includes('\\/'))
154
+ return false;
155
+
148
156
  return isRegExpColon(raw) || isRegExpSlash(raw) || isComa(raw);
149
157
  }
150
158
 
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@putout/plugin-remove-useless-escape",
3
- "version": "2.1.0",
3
+ "version": "3.0.0",
4
+ "type": "commonjs",
4
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
5
6
  "description": "putout plugin adds ability to find and remove useless escape",
6
- "homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-escape",
7
+ "homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-escape#readme",
7
8
  "main": "lib/remove-useless-escape.js",
8
9
  "release": false,
9
10
  "tag": false,
@@ -36,19 +37,19 @@
36
37
  ],
37
38
  "devDependencies": {
38
39
  "@putout/plugin-madrun": "*",
39
- "@putout/test": "^4.0.0",
40
+ "@putout/test": "^5.0.0",
40
41
  "c8": "^7.5.0",
41
42
  "eslint": "^8.0.1",
42
43
  "eslint-plugin-node": "^11.0.0",
43
- "eslint-plugin-putout": "^12.0.0",
44
- "madrun": "^8.0.1"
44
+ "eslint-plugin-putout": "^14.0.0",
45
+ "madrun": "^9.0.0"
45
46
  },
46
47
  "peerDependencies": {
47
- "putout": ">=22"
48
+ "putout": ">=25"
48
49
  },
49
50
  "license": "MIT",
50
51
  "engines": {
51
- "node": ">=14"
52
+ "node": ">=16"
52
53
  },
53
54
  "publishConfig": {
54
55
  "access": "public"