Skip to content

Commit 9b6d7a1

Browse files
Schleuseludofischer
authored andcommitted
feat: add support for lh & rlh units
1 parent 1ccc2ef commit 9b6d7a1

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

Diff for: parser.jison

+5-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)cqb\b return 'CQBS';
5252
(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)cqmin\b return 'CQMINS';
5353
(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)cqmax\b return 'CQMAXS';
54+
(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)lh\b return 'LHS';
55+
(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)rlh\b return 'RLHS';
5456
(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)cm\b return 'LENGTH';
5557
(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)mm\b return 'LENGTH';
5658
(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)Q\b return 'LENGTH';
@@ -150,7 +152,9 @@ expression
150152
| CQIS { $$ = { type: 'CqiValue', value: parseFloat($1), unit: 'cqi' }; }
151153
| CQBS { $$ = { type: 'CqbValue', value: parseFloat($1), unit: 'cqb' }; }
152154
| CQMINS { $$ = { type: 'CqminValue', value: parseFloat($1), unit: 'cqmin' }; }
153-
| CQMAXS { $$ = { type: 'CqmaxValue', value: parseFloat($1), unit: 'cqmax' }; }
155+
| CQMAXS { $$ = { type: 'CqmaxValue', value: parseFloat($1), unit: 'cqmax' }; }
156+
| LHS { $$ = { type: 'LhValue', value: parseFloat($1), unit: 'lh' }; }
157+
| RLHS { $$ = { type: 'RlhValue', value: parseFloat($1), unit: 'rlh' }; }
154158
| PERCENTAGE { $$ = { type: 'PercentageValue', value: parseFloat($1), unit: '%' }; }
155159
| ADD dimension { var prev = $2; $$ = prev; }
156160
| SUB dimension { var prev = $2; prev.value *= -1; $$ = prev; }

Diff for: src/lib/reducer.js

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ function isValueType(node) {
4747
case 'CqminValue':
4848
case 'CqmaxValue':
4949
case 'PercentageValue':
50+
case 'LhValue':
51+
case 'RlhValue':
5052
case 'Number':
5153
return true;
5254
}

Diff for: src/parser.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ export interface DimensionExpression {
5151
| 'CqbValue'
5252
| 'CqiValue'
5353
| 'CqminValue'
54-
| 'CqmaxValue';
54+
| 'CqmaxValue'
55+
| 'LhValue'
56+
| 'RlhValue';
5557
value: number;
5658
unit: string;
5759
}

Diff for: test/index.js

+20
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,26 @@ test(
305305
testValue('calc(100svmax - 44.5svh)', 'calc(100svmax - 44.5svh)')
306306
);
307307

308+
test(
309+
'should add numbers with lh units',
310+
testValue('calc(1lh + 4lh)', '5lh')
311+
);
312+
313+
test(
314+
'should add numbers with rlh units',
315+
testValue('calc(1rlh + 4rlh)', '5rlh')
316+
);
317+
318+
test(
319+
'should not combine different lh units',
320+
testValue('calc(1lh + 4rlh)', 'calc(1lh + 4rlh)')
321+
);
322+
323+
test(
324+
'should not combine different lh units',
325+
testValue('calc(1lh + 20px)', 'calc(1lh + 20px)')
326+
);
327+
308328
test(
309329
'should parse fractions without leading zero',
310330
testValue('calc(2rem - .14285em)', 'calc(2rem - 0.14285em)')

0 commit comments

Comments
 (0)