Skip to content

Commit

Permalink
Don't process constant() and env(); fixes MoOx#34
Browse files Browse the repository at this point in the history
  • Loading branch information
dlee committed Sep 17, 2018
1 parent 00eb6f3 commit 63e5da1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))'
)
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

1 comment on commit 63e5da1

@sbaechler
Copy link

Choose a reason for hiding this comment

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

@dlee I think we could even get rid of 'constant'. It was only ever used in iOS 11.0.

Please sign in to comment.