/
css-requires-options.js
159 lines (146 loc) Β· 5.23 KB
/
css-requires-options.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// @flow
import babelTester from 'babel-tester'
import plugin from 'babel-plugin-emotion'
const last = arr => arr[arr.length - 1]
const cases = {
'label format with only local': {
code: `
import { css } from 'emotion'
let cls = css({color:'hotpink'})
`,
plugins: [
[
plugin,
{
labelFormat: 'my-css-[local]',
autoLabel: true
}
]
],
babelFileName: __filename
},
'label format with filename that is index and local': {
code: `
import { css } from 'emotion'
let cls = css({color:'hotpink'})
`,
plugins: [
[
plugin,
{
labelFormat: 'my-css-[filename]-[local]',
autoLabel: true
}
]
],
babelFileName: 'some-directory/index.js'
},
'label format with filename and local': {
code: `
import { css } from 'emotion'
let cls = css({color:'hotpink'})
`,
plugins: [
[
plugin,
{
labelFormat: 'my-css-[filename]-[local]',
autoLabel: true
}
]
],
babelFileName: __filename
},
'label format with dirname, filename, and local': {
code: `
import { css } from 'emotion'
let cls = css({color:'hotpink'})
`,
plugins: [
[
plugin,
{
labelFormat: 'my-css-[dirname]-[filename]-[local]',
autoLabel: true
}
]
],
babelFileName: __filename
},
'label format function': {
code: `
import { css } from 'emotion'
let cls = css({color:'hotpink'})
`,
plugins: [
[
plugin,
{
labelFormat: ({ name, path }) =>
`${name.toUpperCase()}_${last(
path.replace(/\..+$/, '').split('/')
).toUpperCase()}`,
autoLabel: true
}
]
],
babelFileName: __filename
},
// this test has better readability for label alone than other ones which include source maps
'label on code transpiled by TS': {
code: `
import { __makeTemplateObject } from 'tslib'
import { css } from '@emotion/core'
var templateObject_1
const someVar = css(
templateObject_1 ||
(templateObject_1 = __makeTemplateObject(
['\\n color: hotpink;\\n'],
['\\n color: hotpink;\\n']
))
)
`,
plugins: [
[
plugin,
{
autoLabel: true,
sourceMap: false
}
]
],
babelFileName: __filename
},
'code already transpiled by emotion plugin (avoid double transpilation)': {
code: `
import { keyframes as _keyframes } from "emotion";
import { css as _css } from "emotion";
function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from \`css\` function. It isn't supposed to be used directly (e.g. as value of the \`className\` prop), but rather handed to emotion so it can handle it (e.g. as value of \`css\` prop)."; }
let someCls =
/*#__PURE__*/
_css(process.env.NODE_ENV === "production" ? {
name: "1jwq1yt-someCls",
styles: "color:hotpink;;label:someCls;"
} : {
name: "1jwq1yt-someCls",
styles: "color:hotpink;;label:someCls;",
map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImRvZXMtbm90LWRvdWJsZS1sYWJlbC1hbHJlYWR5LXRyYW5zcGlsZWQtY29kZS5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFHaUIiLCJmaWxlIjoiZG9lcy1ub3QtZG91YmxlLWxhYmVsLWFscmVhZHktdHJhbnNwaWxlZC1jb2RlLmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8gVE9ETzogdGhlb3JldGljYWxsdCBgZW1vdGlvbmAgc2hvdWxkIGJlIG1lbnRpb25lZCBpbiB0aGlzIHRlc3QgLSBzbyBwcm9iYWJseSB3ZSdkIGxpa2UgdG8gbW92ZSB0aGlzIHRlc3QgYXJvdW5kXG5pbXBvcnQgeyBjc3MsIGtleWZyYW1lcyB9IGZyb20gJ2Vtb3Rpb24nXG5cbmxldCBzb21lQ2xzID0gY3NzYFxuICBjb2xvcjogaG90cGluaztcbmBcblxubGV0IHJvdGF0ZTM2MCA9IGtleWZyYW1lc2BcbiAgZnJvbSB7XG4gICAgdHJhbnNmb3JtOiByb3RhdGUoMGRlZyk7XG4gIH1cbiAgdG8ge1xuICAgIHRyYW5zZm9ybTogcm90YXRlKDM2MGRlZyk7XG4gIH1cbmBcbiJdfQ== */",
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
});
let rotate360 =
/*#__PURE__*/
_keyframes(process.env.NODE_ENV === "production" ? {
name: "1k98dea-rotate360",
styles: "from{transform:rotate(0deg);}to{transform:rotate(360deg);};label:rotate360;"
} : {
name: "1k98dea-rotate360",
styles: "from{transform:rotate(0deg);}to{transform:rotate(360deg);};label:rotate360;",
map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImRvZXMtbm90LWRvdWJsZS1sYWJlbC1hbHJlYWR5LXRyYW5zcGlsZWQtY29kZS5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFPeUIiLCJmaWxlIjoiZG9lcy1ub3QtZG91YmxlLWxhYmVsLWFscmVhZHktdHJhbnNwaWxlZC1jb2RlLmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8gVE9ETzogdGhlb3JldGljYWxsdCBgZW1vdGlvbmAgc2hvdWxkIGJlIG1lbnRpb25lZCBpbiB0aGlzIHRlc3QgLSBzbyBwcm9iYWJseSB3ZSdkIGxpa2UgdG8gbW92ZSB0aGlzIHRlc3QgYXJvdW5kXG5pbXBvcnQgeyBjc3MsIGtleWZyYW1lcyB9IGZyb20gJ2Vtb3Rpb24nXG5cbmxldCBzb21lQ2xzID0gY3NzYFxuICBjb2xvcjogaG90cGluaztcbmBcblxubGV0IHJvdGF0ZTM2MCA9IGtleWZyYW1lc2BcbiAgZnJvbSB7XG4gICAgdHJhbnNmb3JtOiByb3RhdGUoMGRlZyk7XG4gIH1cbiAgdG8ge1xuICAgIHRyYW5zZm9ybTogcm90YXRlKDM2MGRlZyk7XG4gIH1cbmBcbiJdfQ== */",
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
});
`,
plugins: [plugin],
babelFileName: __filename
}
}
babelTester('babel css inline', cases)