Skip to content

Commit 23abe0f

Browse files
committed
feature: @putout/plugin-regexp: apply-character-class: with optimize
1 parent dd20c05 commit 23abe0f

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const reg = /^[~/]/;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const reg = /^(~|\/)/;

packages/plugin-regexp/lib/apply-character-class/index.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {createTest} from '@putout/test';
22
import * as plugin from './index.js';
3+
import * as optimize from '../optimize/index.js';
34

45
const test = createTest(import.meta.url, {
56
plugins: [
@@ -27,6 +28,13 @@ test('regexp: apply-character-class: transform: couple', (t) => {
2728
t.end();
2829
});
2930

31+
test('regexp: apply-character-class: transform: optimize', (t) => {
32+
t.transform('optimize', {
33+
optimize,
34+
});
35+
t.end();
36+
});
37+
3038
test('regexp: apply-character-class: report: not-escaped', (t) => {
3139
t.report('not-escaped', `Use character class instead of single character alternation: '/\\.(c|m)?ts(x)?$/' -> '/\\.[cm]?ts(x)?$/'`);
3240
t.end();

packages/plugin-regexp/lib/create-regexp.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ const createReport = (regexp) => ({from, to}) => {
1414
};
1515

1616
const fix = ({path, to}) => {
17-
const [, pattern] = to.split('/');
18-
19-
path.node.pattern = pattern;
17+
path.node.pattern = to.slice(1, -1);
2018
path.node.raw = to;
2119
path.node.extra.raw = to;
2220
};

0 commit comments

Comments
 (0)