Skip to content

Commit f93964d

Browse files
committed
Convert to ES6 import/export syntax
1 parent f50ca6e commit f93964d

File tree

13 files changed

+41
-47
lines changed

13 files changed

+41
-47
lines changed

src/TokenStream.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const SYMBOL_MATCH = 'SYMBOL_MATCH'
22

3-
module.exports = class TokenStream {
3+
export default class TokenStream {
44
constructor(nodes, parent) {
55
this.index = 0
66
this.nodes = nodes

src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-disable no-param-reassign */
2-
const parse = require('postcss-value-parser')
3-
const camelizeStyleName = require('fbjs/lib/camelizeStyleName')
4-
const transforms = require('./transforms')
5-
const TokenStream = require('./TokenStream')
2+
import parse from 'postcss-value-parser'
3+
import camelizeStyleName from 'fbjs/lib/camelizeStyleName'
4+
import transforms from './transforms'
5+
import TokenStream from './TokenStream'
66

77
// Note if this is wrong, you'll need to change tokenTypes.js too
88
const numberOrLengthRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)(?:px)?$/i

src/tokenTypes.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const { stringify } = require('postcss-value-parser')
2-
const cssColorKeywords = require('css-color-keywords')
1+
import { stringify } from 'postcss-value-parser'
2+
import cssColorKeywords from 'css-color-keywords'
33

44
const matchString = node => {
55
if (node.type !== 'string') return null
@@ -40,7 +40,7 @@ const noopToken = predicate => node => (predicate(node) ? '<token>' : null)
4040
const valueForTypeToken = type => node =>
4141
node.type === type ? node.value : null
4242

43-
const regExpToken = (regExp, transform = String) => node => {
43+
export const regExpToken = (regExp, transform = String) => node => {
4444
if (node.type !== 'word') return null
4545

4646
const match = node.value.match(regExp)
@@ -51,9 +51,7 @@ const regExpToken = (regExp, transform = String) => node => {
5151
return value
5252
}
5353

54-
module.exports.regExpToken = regExpToken
55-
56-
module.exports.tokens = {
54+
export const tokens = {
5755
SPACE: noopToken(node => node.type === 'space'),
5856
SLASH: noopToken(node => node.type === 'div' && node.value === '/'),
5957
COMMA: noopToken(node => node.type === 'div' && node.value === ','),

src/transforms/boxShadow.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const { parseShadow } = require('./util')
1+
import { parseShadow } from './util'
22

3-
module.exports = tokenStream => {
3+
export default tokenStream => {
44
const { offset, radius, color } = parseShadow(tokenStream)
55
return {
66
$merge: {

src/transforms/flex.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { tokens } = require('../tokenTypes')
1+
import { tokens } from '../tokenTypes'
22

33
const { NONE, AUTO, NUMBER, LENGTH, SPACE } = tokens
44

@@ -8,7 +8,7 @@ const defaultFlexBasis = 0
88

99
const FLEX_BASIS_AUTO = {} // Used for reference equality
1010

11-
module.exports = tokenStream => {
11+
export default tokenStream => {
1212
let flexGrow
1313
let flexShrink
1414
let flexBasis

src/transforms/font.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const parseFontFamily = require('./fontFamily')
2-
const { regExpToken, tokens } = require('../tokenTypes')
1+
import parseFontFamily from './fontFamily'
2+
import { regExpToken, tokens } from '../tokenTypes'
33

44
const { SPACE, LENGTH, NUMBER, SLASH } = tokens
55
const NORMAL = regExpToken(/^(normal)$/)
@@ -11,7 +11,7 @@ const defaultFontStyle = 'normal'
1111
const defaultFontWeight = 'normal'
1212
const defaultFontVariant = []
1313

14-
module.exports = tokenStream => {
14+
export default tokenStream => {
1515
let fontStyle
1616
let fontWeight
1717
let fontVariant

src/transforms/fontFamily.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const { tokens } = require('../tokenTypes')
1+
import { tokens } from '../tokenTypes'
22

33
const { SPACE, IDENT, STRING } = tokens
44

5-
module.exports = tokenStream => {
5+
export default tokenStream => {
66
let fontFamily
77

88
if (tokenStream.matches(STRING)) {

src/transforms/index.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
const { regExpToken, tokens } = require('../tokenTypes')
2-
const boxShadow = require('./boxShadow')
3-
const flex = require('./flex')
4-
const font = require('./font')
5-
const fontFamily = require('./fontFamily')
6-
const textShadow = require('./textShadow')
7-
const textDecoration = require('./textDecoration')
8-
const textDecorationLine = require('./textDecorationLine')
9-
const transform = require('./transform')
10-
const {
11-
directionFactory,
12-
anyOrderFactory,
13-
shadowOffsetFactory,
14-
} = require('./util')
1+
import { regExpToken, tokens } from '../tokenTypes'
2+
import boxShadow from './boxShadow'
3+
import flex from './flex'
4+
import font from './font'
5+
import fontFamily from './fontFamily'
6+
import textShadow from './textShadow'
7+
import textDecoration from './textDecoration'
8+
import textDecorationLine from './textDecorationLine'
9+
import transform from './transform'
10+
import { directionFactory, anyOrderFactory, shadowOffsetFactory } from './util'
1511

1612
const { IDENT, WORD, COLOR } = tokens
1713

@@ -60,7 +56,7 @@ const fontWeight = tokenStream => tokenStream.expect(WORD) // Also match numbers
6056
const shadowOffset = shadowOffsetFactory()
6157
const textShadowOffset = shadowOffsetFactory()
6258

63-
module.exports = {
59+
export default {
6460
background,
6561
border,
6662
borderColor,

src/transforms/textDecoration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const defaultTextDecorationLine = 'none'
88
const defaultTextDecorationStyle = 'solid'
99
const defaultTextDecorationColor = 'black'
1010

11-
module.exports = tokenStream => {
11+
export default tokenStream => {
1212
let line
1313
let style
1414
let color

src/transforms/textDecorationLine.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const { tokens } = require('../tokenTypes')
1+
import { tokens } from '../tokenTypes'
22

33
const { SPACE, LINE } = tokens
44

5-
module.exports = tokenStream => {
5+
export default tokenStream => {
66
const lines = []
77

88
let didParseFirst = false

src/transforms/textShadow.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const { parseShadow } = require('./util')
1+
import { parseShadow } from './util'
22

3-
module.exports = tokenStream => {
3+
export default tokenStream => {
44
const { offset, radius, color } = parseShadow(tokenStream)
55
return {
66
$merge: {

src/transforms/transform.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { tokens } = require('../tokenTypes')
1+
import { tokens } from '../tokenTypes'
22

33
const { SPACE, COMMA, LENGTH, NUMBER, ANGLE } = tokens
44

@@ -54,7 +54,7 @@ const partTransforms = {
5454
skew: xyAngle('skew', '0deg'),
5555
}
5656

57-
module.exports = tokenStream => {
57+
export default tokenStream => {
5858
let transforms = []
5959

6060
let didParseFirst = false

src/transforms/util.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const { tokens } = require('../tokenTypes')
1+
import { tokens } from '../tokenTypes'
22

33
const { LENGTH, PERCENT, COLOR, SPACE, NONE } = tokens
44

5-
module.exports.directionFactory = ({
5+
export const directionFactory = ({
66
types = [LENGTH, PERCENT],
77
directions = ['Top', 'Right', 'Bottom', 'Left'],
88
prefix = '',
@@ -34,7 +34,7 @@ module.exports.directionFactory = ({
3434
return { $merge: output }
3535
}
3636

37-
module.exports.anyOrderFactory = (properties, delim = SPACE) => tokenStream => {
37+
export const anyOrderFactory = (properties, delim = SPACE) => tokenStream => {
3838
const propertyNames = Object.keys(properties)
3939
const values = propertyNames.reduce((accum, propertyName) => {
4040
accum[propertyName] === undefined // eslint-disable-line
@@ -70,14 +70,14 @@ module.exports.anyOrderFactory = (properties, delim = SPACE) => tokenStream => {
7070
return { $merge: values }
7171
}
7272

73-
module.exports.shadowOffsetFactory = () => tokenStream => {
73+
export const shadowOffsetFactory = () => tokenStream => {
7474
const width = tokenStream.expect(LENGTH)
7575
const height = tokenStream.matches(SPACE) ? tokenStream.expect(LENGTH) : width
7676
tokenStream.expectEmpty()
7777
return { width, height }
7878
}
7979

80-
module.exports.parseShadow = tokenStream => {
80+
export const parseShadow = tokenStream => {
8181
let offsetX
8282
let offsetY
8383
let radius

0 commit comments

Comments
 (0)