Skip to content

Commit 7eb58ec

Browse files
mahirshahMahir Shah
authored andcommitted
(bug)[Generic Lexer]: Make Generic Lexer Case Insensitive
- add token transformation to make generic lexer case insensitive Fixes #7
1 parent f94685d commit 7eb58ec

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/constants/genericLexer.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
const moo = require('moo');
22

33
module.exports = moo.compile({
4-
color: /(?:#(?:[0-9a-fA-F]{2}){2,4}|#[0-9a-fA-F]{3}|(?:rgba?|hsla?)\(\s*(?:\d+%?(?:deg|rad|grad|turn)?(?:,|\s)+){2,3}[\s/]*[\d.]+%?\s*\))/,
4+
color: {
5+
match: /(?:#(?:[0-9a-fA-F]{2}){2,4}|#[0-9a-fA-F]{3}|(?:rgba?|hsla?)\(\s*(?:\d+%?(?:deg|rad|grad|turn)?(?:,|\s)+){2,3}[\s/]*[\d.]+%?\s*\))/,
6+
value: match => match.toLowerCase(),
7+
},
58
number: /(?:[+-])?(?:(?:\d+\.\d*)|(?:\d*\.\d+))/,
69
integer: /(?:[+-])?[0-9]+/,
710
string: /(?:"[^"]")|(?:'[^']')/,
811
functionStart: /[a-zA-Z]+\(/,
9-
customIdent: /[^0-9\s](?:[a-zA-Z0-9_-]|(?:\\.))*/,
10-
ident: /[a-zA-Z-]+/,
11-
char: /./,
12+
customIdent: {
13+
match: /[^0-9\s](?:[a-zA-Z0-9_-]|(?:\\.))*/,
14+
value: match => match.toLowerCase(),
15+
},
16+
ident: {
17+
match: /[a-zA-Z-]+/,
18+
value: match => match.toLowerCase(),
19+
},
20+
char: {
21+
match: /./,
22+
value: match => match.toLowerCase(),
23+
},
1224
});

test/isValidDeclarationTest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('isValidDeclaration', function () {
1919
});
2020

2121
describe('border', function () {
22-
['1px', 'solid', 'black', '1px solid', 'solid 1px', '1px solid black', 'medium dashed green', 'green medium dashed']
22+
['1px', 'solid', 'black', 'Black', 'bLaCk', '1px solid', 'solid 1px', '1px solid black', 'medium dashed green', 'gReeN mEdiuM DasHed', 'green medium dashed']
2323
.forEach((value) => {
2424
it(`should return true for ${value}`, function () {
2525
assert(isValidDeclaration('border', value));
@@ -28,7 +28,7 @@ describe('isValidDeclaration', function () {
2828
});
2929

3030
describe('margin', function () {
31-
['0', 'auto', '1px', '1em', '0 auto', '1px 1px', '1px 1em', '20% auto 1px', '20% 1px 20em -2%', 'var(--hello09-a)']
31+
['0', 'auto', '1px', '1em', '0 auto', '1px 1px', '1px 1em', '20% auto 1px', '20% 1px 20em -2%', 'var(--hello09-a)', '1Px', '2PX', '0 aUto']
3232
.forEach((value) => {
3333
it(`should return true for ${value}`, function () {
3434
assert(isValidDeclaration('margin', value));

0 commit comments

Comments
 (0)