Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should not throw an exception when unknow function exist in calc #40

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions parser.jison
Expand Up @@ -39,6 +39,7 @@

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex doesn't seem very resilient to me. Furthermore it might be worth normalising this and the CSS variable stuff to a single thing. \cc @MoOx what do you think?

([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 }; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the name is to be kept, it should be "unknown function". But I'm leaning towards normalisation, so maybe just "function".

;

value
Expand Down
7 changes: 7 additions & 0 deletions src/__tests__/index.js
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
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