Skip to content

Commit 409c9ba

Browse files
dleeMoOx
authored andcommitted
Don't process constant() and env() (#48)
Workaround for #34 Closes #34
1 parent 00eb6f3 commit 409c9ba

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/__tests__/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,17 @@ test(
338338
'calc( (1em - calc( 10px + 1em)) / 2)',
339339
'-5px'
340340
)
341+
342+
test(
343+
'should skip constant()',
344+
testFixture,
345+
'calc(constant(safe-area-inset-left))',
346+
'calc(constant(safe-area-inset-left))'
347+
)
348+
349+
test(
350+
'should skip env()',
351+
testFixture,
352+
'calc(env(safe-area-inset-left))',
353+
'calc(env(safe-area-inset-left))'
354+
)

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ export default (value, precision = 5) => {
1414

1515
// stringify calc expression and produce an AST
1616
const contents = valueParser.stringify(node.nodes)
17+
18+
// skip constant() and env()
19+
if (contents.indexOf('constant') >= 0 || contents.indexOf('env') >= 0) return;
20+
1721
const ast = parser.parse(contents)
1822

1923
// reduce AST to its simplest form, that is, either to a single value

0 commit comments

Comments
 (0)