@putout/plugin-remove-useless-escape 2.0.0 → 2.1.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.
|
@@ -22,11 +22,13 @@ module.exports.fix = (path) => {
|
|
|
22
22
|
if (path.isRegExpLiteral()) {
|
|
23
23
|
const {pattern, flags} = path.node;
|
|
24
24
|
const unescaped = unescapeRegExp(pattern);
|
|
25
|
+
const raw = `/${unescaped}/`;
|
|
25
26
|
|
|
26
27
|
const regExpNode = assign(RegExpLiteral(unescaped, flags), {
|
|
27
28
|
value: unescaped,
|
|
29
|
+
raw,
|
|
28
30
|
extra: {
|
|
29
|
-
raw
|
|
31
|
+
raw,
|
|
30
32
|
rawValue: unescaped,
|
|
31
33
|
},
|
|
32
34
|
});
|
|
@@ -121,7 +123,7 @@ function unEscape(raw) {
|
|
|
121
123
|
.replace(/\\\+/g, '+')
|
|
122
124
|
.replace(createEncodedRegExp(`"`), '"')
|
|
123
125
|
.replace(/\\\^/g, '^')
|
|
124
|
-
.replace(/(\\)
|
|
126
|
+
.replace(/(\\),/, ',');
|
|
125
127
|
|
|
126
128
|
for (const emoji of match(raw)) {
|
|
127
129
|
raw = raw.replace(createEncodedRegExp(emoji), emoji);
|
|
@@ -134,12 +136,13 @@ function unescapeRegExp(raw) {
|
|
|
134
136
|
return raw
|
|
135
137
|
.replace(/\\:/g, ':')
|
|
136
138
|
.replace(/\+\\\//g, '+/')
|
|
137
|
-
.replace(
|
|
139
|
+
.replace(/\\,/g, ',');
|
|
138
140
|
}
|
|
139
141
|
|
|
140
|
-
const
|
|
141
|
-
const
|
|
142
|
-
const isComa = (
|
|
142
|
+
const is = (a) => (b) => b.includes(`\\${a}`) && !b.includes(`\\\\${a}`);
|
|
143
|
+
const isRegExpColon = is(':');
|
|
144
|
+
const isComa = is(',');
|
|
145
|
+
const isRegExpSlash = (a) => a.includes('\\\\\\\\');
|
|
143
146
|
|
|
144
147
|
function isEscapedRegExp(raw) {
|
|
145
148
|
return isRegExpColon(raw) || isRegExpSlash(raw) || isComa(raw);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-remove-useless-escape",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
5
5
|
"description": "putout plugin adds ability to find and remove useless escape",
|
|
6
6
|
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-escape",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"escape"
|
|
36
36
|
],
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@putout/plugin-madrun": "
|
|
38
|
+
"@putout/plugin-madrun": "*",
|
|
39
39
|
"@putout/test": "^4.0.0",
|
|
40
40
|
"c8": "^7.5.0",
|
|
41
41
|
"eslint": "^8.0.1",
|