From 63e5da17c7b05f0b7b23bb47c1cc004ba0a1c648 Mon Sep 17 00:00:00 2001 From: David Lee Date: Sun, 16 Sep 2018 22:52:51 -0700 Subject: [PATCH] Don't process constant() and env(); fixes #34 --- src/__tests__/index.js | 14 ++++++++++++++ src/index.js | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/src/__tests__/index.js b/src/__tests__/index.js index 4741658..b6435a6 100644 --- a/src/__tests__/index.js +++ b/src/__tests__/index.js @@ -338,3 +338,17 @@ test( 'calc( (1em - calc( 10px + 1em)) / 2)', '-5px' ) + +test( + 'should skip constant()', + testFixture, + 'calc(constant(safe-area-inset-left))', + 'calc(constant(safe-area-inset-left))' +) + +test( + 'should skip env()', + testFixture, + 'calc(env(safe-area-inset-left))', + 'calc(env(safe-area-inset-left))' +) diff --git a/src/index.js b/src/index.js index d2de067..a67efa2 100644 --- a/src/index.js +++ b/src/index.js @@ -14,6 +14,10 @@ export default (value, precision = 5) => { // stringify calc expression and produce an AST const contents = valueParser.stringify(node.nodes) + + // skip constant() and env() + if (contents.indexOf('constant') >= 0 || contents.indexOf('env') >= 0) return; + const ast = parser.parse(contents) // reduce AST to its simplest form, that is, either to a single value