Skip to content

Commit

Permalink
Should not throw an exception when unknow function exist in calc
Browse files Browse the repository at this point in the history
Fix #34
  • Loading branch information
Semigradsky committed Nov 9, 2017
1 parent 704fe47 commit 23d5fd9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions parser.jison
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

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

"(" return 'LPAREN';
Expand Down Expand Up @@ -72,6 +73,7 @@ expression
| css_variable { $$ = $1; }
| css_value { $$ = $1; }
| value { $$ = $1; }
| UNKNOW_FUNCTION { $$ = { type: 'Unknow', value: $1 }; }
;

value
Expand Down
7 changes: 7 additions & 0 deletions src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,10 @@ test(
'calc( (1em - calc( 10px + 1em)) / 2)',
'-5px'
)

test(
'should not throw an exception when unknow function exist in calc',
testFixture,
'calc(constant(safe-area-inset-left) + 100px - 50px)',
'calc(constant(safe-area-inset-left) + 50px)'
)
1 change: 1 addition & 0 deletions src/lib/stringifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function stringify(node, prec) {
case "Value":
return round(node.value, prec)
case 'CssVariable':
case 'Unknow':
return node.value
default:
return round(node.value, prec) + node.unit
Expand Down

0 comments on commit 23d5fd9

Please sign in to comment.