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
Next Next commit
Add TIME and TIMING into tokenTypes
  • Loading branch information
aleskafka committed May 9, 2018
commit a1b8db2192aca0419f8cf500f6afbdce754cee16
16 changes: 15 additions & 1 deletion src/tokenTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,28 @@ const matchColor = node => {
return null
}


const matchTime = node => {
if (node.type !== 'word') return null

const match = node.value.match(timeRe)
if (match === null) return null

return Number(match[1]) * (match[2]==='s' ? 1000 : 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you run prettier on this file?

}

const noneRe = /^(none)$/i
const autoRe = /^(auto)$/i
const identRe = /(^-?[_a-z][_a-z0-9-]*$)/i
// Note if these are wrong, you'll need to change index.js too
const numberRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)$/
// Note lengthRe is sneaky: you can omit units for 0
const timeRe = /^((?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)(s|ms)$/
const lengthRe = /^(0$|(?:[+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)(?=px$))/
const unsupportedUnitRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(ch|em|ex|rem|vh|vw|vmin|vmax|cm|mm|in|pc|pt))$/
const angleRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(?:deg|rad))$/
const percentRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?%)$/
const timingRe = /^(linear|ease|ease-in|ease-out|ease-in-out|step-start|step-end)$/


const noopToken = predicate => node => (predicate(node) ? '<token>' : null)

Expand All @@ -60,6 +72,8 @@ export const tokens = {
NONE: regExpToken(noneRe),
AUTO: regExpToken(autoRe),
NUMBER: regExpToken(numberRe, Number),
TIME: matchTime,
TIMING: regExpToken(timingRe),
LENGTH: regExpToken(lengthRe, Number),
UNSUPPORTED_LENGTH_UNIT: regExpToken(unsupportedUnitRe),
ANGLE: regExpToken(angleRe),
Expand Down