Skip to content

Commit b41f4f4

Browse files
authored
Merge pull request styled-components#74 from styled-components/import-statements
Convert to ES6 import/export syntax
2 parents f50ca6e + cb673a9 commit b41f4f4

16 files changed

+51
-52
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
/node_modules
2-
/dist
2+
/index.js

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"name": "css-to-react-native",
33
"version": "2.1.1",
44
"description": "Convert CSS text to a React Native stylesheet object",
5-
"main": "dist/index.js",
5+
"main": "index.js",
66
"scripts": {
7-
"build": "babel src --ignore test.js --out-dir dist",
7+
"build": "rollup ./src/index.js -o index.js --f cjs && babel index.js -o index.js",
88
"test": "jest",
99
"test:watch": "jest --watch",
1010
"lint": "eslint src",
@@ -13,7 +13,7 @@
1313
"lint-staged": "lint-staged"
1414
},
1515
"files": [
16-
"dist",
16+
"index.js",
1717
"src"
1818
],
1919
"repository": {
@@ -43,7 +43,8 @@
4343
"eslint-plugin-prettier": "^2.6.0",
4444
"jest": "^22.2.2",
4545
"lint-staged": "^6.1.0",
46-
"prettier": "^1.10.2"
46+
"prettier": "^1.10.2",
47+
"rollup": "^0.55.5"
4748
},
4849
"dependencies": {
4950
"css-color-keywords": "^1.0.0",

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/index'
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

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3809,6 +3809,10 @@ rimraf@^2.5.1, rimraf@^2.5.4, rimraf@^2.6.1:
38093809
dependencies:
38103810
glob "^7.0.5"
38113811

3812+
rollup@^0.55.5:
3813+
version "0.55.5"
3814+
resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.55.5.tgz#2f88c300f7cf24b5ec2dca8a6aba73b04e087e93"
3815+
38123816
run-async@^2.2.0:
38133817
version "2.3.0"
38143818
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.3.0.tgz#0371ab4ae0bdd720d4166d7dfda64ff7a445a6c0"

0 commit comments

Comments
 (0)