Skip to content

Commit 5dd8076

Browse files
committed
1 parent c217bc1 commit 5dd8076

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/optimizer/__tests__/optimizer-integration-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,14 @@ describe('optimizer-integration-test', () => {
145145
.toString()
146146
).toBe(optimized.toString());
147147
});
148+
149+
[
150+
/(?:.|\s)*/,
151+
/^import ((?:.|\s)*?) from "(.*)";/gm,
152+
/(.|[\n\r])/, // from https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1231#issue-870010385
153+
].map(regexp =>
154+
it(`can recognise dot as "any single character" token in ${regexp}`, () => {
155+
expect(optimizer.optimize(regexp).toString()).toBe(regexp.toString());
156+
})
157+
);
148158
});

src/optimizer/transforms/__tests__/group-single-chars-to-char-class-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ describe('(a|b|c) -> ([abc])', () => {
4444
expect(re.toString()).toBe('/(a|b|no)/');
4545
});
4646

47+
it('have no effect on "any single character" token', () => {
48+
const re = transform(/(\r|\n|.)/, [singleCharsGroupToCharClass]);
49+
expect(re.toString()).toBe(/(\r|\n|.)/.toString());
50+
});
51+
4752
it('has no effet on empty values', () => {
4853
const re = transform(/(a|b|)/, [singleCharsGroupToCharClass]);
4954
expect(re.toString()).toBe('/(a|b|)/');

src/optimizer/transforms/group-single-chars-to-char-class.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ function shouldProcess(expression, charset) {
6969

7070
return shouldProcess(left, charset) && shouldProcess(right, charset);
7171
} else if (type === 'Char') {
72+
if (expression.kind === 'meta' && expression.symbol === '.') {
73+
return false;
74+
}
75+
7276
const {value} = expression;
7377

7478
charset.set(value, expression);

0 commit comments

Comments
 (0)