Skip to content

Commit 23d5fd9

Browse files
committed
Should not throw an exception when unknow function exist in calc
Fix #34
1 parent 704fe47 commit 23d5fd9

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

parser.jison

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
(calc) return 'NESTED_CALC';
4141
(var\([^\)]*\)) return 'CSS_VAR';
42+
([a-z]+\([a-z0-9-]+\)) return 'UNKNOW_FUNCTION'
4243
([a-z]+) return 'PREFIX';
4344

4445
"(" return 'LPAREN';
@@ -72,6 +73,7 @@ expression
7273
| css_variable { $$ = $1; }
7374
| css_value { $$ = $1; }
7475
| value { $$ = $1; }
76+
| UNKNOW_FUNCTION { $$ = { type: 'Unknow', value: $1 }; }
7577
;
7678

7779
value

src/__tests__/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,10 @@ test(
324324
'calc( (1em - calc( 10px + 1em)) / 2)',
325325
'-5px'
326326
)
327+
328+
test(
329+
'should not throw an exception when unknow function exist in calc',
330+
testFixture,
331+
'calc(constant(safe-area-inset-left) + 100px - 50px)',
332+
'calc(constant(safe-area-inset-left) + 50px)'
333+
)

src/lib/stringifier.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function stringify(node, prec) {
3636
case "Value":
3737
return round(node.value, prec)
3838
case 'CssVariable':
39+
case 'Unknow':
3940
return node.value
4041
default:
4142
return round(node.value, prec) + node.unit

0 commit comments

Comments
 (0)