Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add PERCENT support to transforms
  • Loading branch information
aleskafka committed May 9, 2018
commit b4baa43b48bb23b79baa4a91c7559093e2967623
16 changes: 8 additions & 8 deletions src/transforms/transform.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { tokens } from '../tokenTypes'

const { SPACE, COMMA, LENGTH, NUMBER, ANGLE } = tokens
const { SPACE, COMMA, LENGTH, PERCENT, NUMBER, ANGLE } = tokens

const oneOfType = tokenType => functionStream => {
const value = functionStream.expect(tokenType)
const oneOfType = (...tokenTypes) => functionStream => {
const value = functionStream.expect(...tokenTypes)
functionStream.expectEmpty()
return value
}

const singleNumber = oneOfType(NUMBER)
const singleLength = oneOfType(LENGTH)
const singleLength = oneOfType(LENGTH, PERCENT)
const singleAngle = oneOfType(ANGLE)
const xyTransformFactory = tokenType => (
const xyTransformFactory = (...tokenTypes) => (
key,
valueIfOmitted
) => functionStream => {
const x = functionStream.expect(tokenType)
const x = functionStream.expect(...tokenTypes)

let y
if (functionStream.hasTokens()) {
functionStream.expect(COMMA)
y = functionStream.expect(tokenType)
y = functionStream.expect(...tokenTypes)
} else if (valueIfOmitted !== undefined) {
y = valueIfOmitted
} else {
Expand All @@ -34,7 +34,7 @@ const xyTransformFactory = tokenType => (
return [{ [`${key}Y`]: y }, { [`${key}X`]: x }]
}
const xyNumber = xyTransformFactory(NUMBER)
const xyLength = xyTransformFactory(LENGTH)
const xyLength = xyTransformFactory(LENGTH, PERCENT)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think RN doesn't support percents in transforms

const xyAngle = xyTransformFactory(ANGLE)

const partTransforms = {
Expand Down