Skip to content

Commit bc5fafd

Browse files
committed
remove desugaring and import rewriting functionality
It was a good idea but ultimately doesn't work in certain cases. Also, since react-dom ships these strings anyway, the gains from no-tags backflips end up getting gzipped away.
1 parent 50237e2 commit bc5fafd

File tree

8 files changed

+62
-209
lines changed

8 files changed

+62
-209
lines changed

src/index.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
import minify from './visitors/minify'
2-
import desugarStyled from './visitors/desugarStyled'
32
import displayNameAndId from './visitors/displayNameAndId'
43
import templateLiterals from './visitors/templateLiterals'
54
import assignStyledRequired from './visitors/assignStyledRequired'
6-
import rewriteStyledImport from './visitors/rewriteStyledImport'
75

86
export default function({ types: t }) {
97
return {
108
visitor: {
11-
ImportDeclaration(path, state) {
12-
rewriteStyledImport(t)(path, state)
13-
},
14-
MemberExpression(path, state) {
15-
desugarStyled(t)(path, state)
16-
},
179
TaggedTemplateExpression(path, state) {
1810
minify(t)(path, state)
1911
displayNameAndId(t)(path, state)

src/visitors/desugarStyled.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/visitors/rewriteStyledImport.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/__snapshots__/index.test.js.snap

Lines changed: 62 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`fixtures should add display names 1`] = `
4-
"const Test = styled(\\"div\\").withConfig({
4+
"const Test = styled.div.withConfig({
55
displayName: \\"Test\\"
66
})\`width:100%;\`;
77
const Test2 = styled('div').withConfig({
88
displayName: \\"Test2\\"
99
})\`\`;
10-
const Test3 = true ? styled(\\"div\\").withConfig({
10+
const Test3 = true ? styled.div.withConfig({
1111
displayName: \\"Test3\\"
12-
})\`\` : styled(\\"div\\").withConfig({
12+
})\`\` : styled.div.withConfig({
1313
displayName: \\"Test3\\"
1414
})\`\`;
1515
const styles = {
16-
One: styled(\\"div\\").withConfig({
16+
One: styled.div.withConfig({
1717
displayName: \\"One\\"
1818
})\`\`
1919
};
2020
let Component;
21-
Component = styled(\\"div\\").withConfig({
21+
Component = styled.div.withConfig({
2222
displayName: \\"Component\\"
2323
})\`\`;
2424
const WrappedComponent = styled(Inner).withConfig({
@@ -27,27 +27,27 @@ const WrappedComponent = styled(Inner).withConfig({
2727
2828
class ClassComponent {}
2929
30-
ClassComponent.Child = styled(\\"div\\").withConfig({
30+
ClassComponent.Child = styled.div.withConfig({
3131
displayName: \\"Child\\"
3232
})\`\`;"
3333
`;
3434
3535
exports[`fixtures should add identifier 1`] = `
36-
"const Test = styled(\\"div\\").withConfig({
36+
"const Test = styled.div.withConfig({
3737
componentId: \\"wkc8iz-0\\"
3838
})\`width:100%;\`;
39-
const Test2 = true ? styled(\\"div\\").withConfig({
39+
const Test2 = true ? styled.div.withConfig({
4040
componentId: \\"wkc8iz-1\\"
41-
})\`\` : styled(\\"div\\").withConfig({
41+
})\`\` : styled.div.withConfig({
4242
componentId: \\"wkc8iz-2\\"
4343
})\`\`;
4444
const styles = {
45-
One: styled(\\"div\\").withConfig({
45+
One: styled.div.withConfig({
4646
componentId: \\"wkc8iz-3\\"
4747
})\`\`
4848
};
4949
let Component;
50-
Component = styled(\\"div\\").withConfig({
50+
Component = styled.div.withConfig({
5151
componentId: \\"wkc8iz-4\\"
5252
})\`\`;
5353
const WrappedComponent = styled(Inner).withConfig({
@@ -56,25 +56,25 @@ const WrappedComponent = styled(Inner).withConfig({
5656
`;
5757
5858
exports[`fixtures should add identifier and display name 1`] = `
59-
"const Test = styled(\\"div\\").withConfig({
59+
"const Test = styled.div.withConfig({
6060
displayName: \\"Test\\",
6161
componentId: \\"sc-1n5umup-0\\"
6262
})\`width:100%;\`;
63-
const Test2 = true ? styled(\\"div\\").withConfig({
63+
const Test2 = true ? styled.div.withConfig({
6464
displayName: \\"Test2\\",
6565
componentId: \\"sc-1n5umup-1\\"
66-
})\`\` : styled(\\"div\\").withConfig({
66+
})\`\` : styled.div.withConfig({
6767
displayName: \\"Test2\\",
6868
componentId: \\"sc-1n5umup-2\\"
6969
})\`\`;
7070
const styles = {
71-
One: styled(\\"div\\").withConfig({
71+
One: styled.div.withConfig({
7272
displayName: \\"One\\",
7373
componentId: \\"sc-1n5umup-3\\"
7474
})\`\`
7575
};
7676
let Component;
77-
Component = styled(\\"div\\").withConfig({
77+
Component = styled.div.withConfig({
7878
displayName: \\"Component\\",
7979
componentId: \\"sc-1n5umup-4\\"
8080
})\`\`;
@@ -85,7 +85,7 @@ const WrappedComponent = styled(Inner).withConfig({
8585
`;
8686
8787
exports[`fixtures should allow chains of member calls 1`] = `
88-
"const WithAttrs = styled(\\"div\\").attrs({
88+
"const WithAttrs = styled.div.attrs({
8989
some: 'value'
9090
}).withConfig({
9191
displayName: \\"WithAttrs\\"
@@ -110,11 +110,11 @@ domElements.forEach(domElement => {
110110
exports[`fixtures should does not replace native with no tags 1`] = `
111111
"const styled_default = require('styled-components/native');
112112
113-
const TestNormal = styled(\\"div\\").withConfig({
113+
const TestNormal = styled.div.withConfig({
114114
displayName: \\"does-not-replace-native-with-no-tags__TestNormal\\",
115115
componentId: \\"sc-1vnscvm-0\\"
116116
})([\\"width:100%;\\"]);
117-
const Test = styled_default.default(\\"div\\").withConfig({
117+
const Test = styled_default.default.div.withConfig({
118118
displayName: \\"does-not-replace-native-with-no-tags__Test\\",
119119
componentId: \\"sc-1vnscvm-1\\"
120120
})([\\"width:100%;\\"]);
@@ -189,85 +189,89 @@ function _templateObject() {
189189
190190
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
191191
192-
var Simple = (0, _styledComponents.default)(\\"div\\")(_templateObject());
193-
var Interpolation = (0, _styledComponents.default)(\\"div\\")(_templateObject2(), function (props) {
192+
var Simple = _styledComponents.default.div(_templateObject());
193+
194+
var Interpolation = _styledComponents.default.div(_templateObject2(), function (props) {
194195
return props.text;
195196
});
196-
var SpecialCharacters = (0, _styledComponents.default)(\\"div\\")(_templateObject3(), function (props) {
197+
198+
var SpecialCharacters = _styledComponents.default.div(_templateObject3(), function (props) {
197199
return props.text;
198200
});
199-
var Comment = (0, _styledComponents.default)(\\"div\\")(_templateObject4());
200-
var Parens = (0, _styledComponents.default)(\\"div\\")(_templateObject5());"
201+
202+
var Comment = _styledComponents.default.div(_templateObject4());
203+
204+
var Parens = _styledComponents.default.div(_templateObject5());"
201205
`;
202206
203207
exports[`fixtures should minify css to use without transpilation 1`] = `
204208
"import styled from 'styled-components';
205-
const Simple = styled(\\"div\\")\`width:100%;\`;
206-
const Interpolation = styled(\\"div\\")\`content:\\"https://test.com/\${props => props.endpoint}\\";\`;
207-
const SpecialCharacters = styled(\\"div\\")\`content:\\" \${props => props.text} \\";color:red;\`;
208-
const Comment = styled(\\"div\\")\`width:100%;color:red;\`;
209-
const Parens = styled(\\"div\\")\`&:hover{color:blue;}color:red;\`;
210-
const UrlComments = styled(\\"div\\")\`color:red;background:red;border:1px solid green;\`;"
209+
const Simple = styled.div\`width:100%;\`;
210+
const Interpolation = styled.div\`content:\\"https://test.com/\${props => props.endpoint}\\";\`;
211+
const SpecialCharacters = styled.div\`content:\\" \${props => props.text} \\";color:red;\`;
212+
const Comment = styled.div\`width:100%;color:red;\`;
213+
const Parens = styled.div\`&:hover{color:blue;}color:red;\`;
214+
const UrlComments = styled.div\`color:red;background:red;border:1px solid green;\`;"
211215
`;
212216
213217
exports[`fixtures should minify single line comments with interpolations 1`] = `
214218
"import styled from 'styled-components';
215-
const Test1 = styled(\\"div\\").withConfig({
219+
const Test1 = styled.div.withConfig({
216220
displayName: \\"minify-single-line-comments-with-interpolations__Test1\\",
217221
componentId: \\"sc-1p41dy5-0\\"
218222
})([\\"width:100%;\\"]);
219-
const Test2 = styled(\\"div\\").withConfig({
223+
const Test2 = styled.div.withConfig({
220224
displayName: \\"minify-single-line-comments-with-interpolations__Test2\\",
221225
componentId: \\"sc-1p41dy5-1\\"
222226
})([\\"width:100%;\\"]);
223-
const Test3 = styled(\\"div\\").withConfig({
227+
const Test3 = styled.div.withConfig({
224228
displayName: \\"minify-single-line-comments-with-interpolations__Test3\\",
225229
componentId: \\"sc-1p41dy5-2\\"
226230
})([\\"width:100%;\\", \\";\\"], 'red');
227-
const Test4 = styled(\\"div\\").withConfig({
231+
const Test4 = styled.div.withConfig({
228232
displayName: \\"minify-single-line-comments-with-interpolations__Test4\\",
229233
componentId: \\"sc-1p41dy5-3\\"
230234
})([\\"width:100%;\\"]);
231-
const Test5 = styled(\\"div\\").withConfig({
235+
const Test5 = styled.div.withConfig({
232236
displayName: \\"minify-single-line-comments-with-interpolations__Test5\\",
233237
componentId: \\"sc-1p41dy5-4\\"
234238
})([\\"width:100%;\\"]);
235-
const Test6 = styled(\\"div\\").withConfig({
239+
const Test6 = styled.div.withConfig({
236240
displayName: \\"minify-single-line-comments-with-interpolations__Test6\\",
237241
componentId: \\"sc-1p41dy5-5\\"
238242
})([\\"background:url(\\\\\\"https://google.com\\\\\\");width:100%;\\", \\" \\"], 'green');
239-
const Test7 = styled(\\"div\\").withConfig({
243+
const Test7 = styled.div.withConfig({
240244
displayName: \\"minify-single-line-comments-with-interpolations__Test7\\",
241245
componentId: \\"sc-1p41dy5-6\\"
242246
})([\\"background:url(\\\\\\"https://google.com\\\\\\");width:\\", \\";\\", \\" height:\\", \\";\\"], p => p.props.width, 'green', p => p.props.height);"
243247
`;
244248
245249
exports[`fixtures should not use private api if not required 1`] = `
246250
"import styled from 'styled-components';
247-
const Test = styled(\\"div\\")\`width:100%;\`;"
251+
const Test = styled.div\`width:100%;\`;"
248252
`;
249253
250254
exports[`fixtures should track the imported variable 1`] = `
251255
"import s from \\"styled-components\\";
252-
const Test = s(\\"div\\").withConfig({
256+
const Test = s.div.withConfig({
253257
displayName: \\"Test\\",
254258
componentId: \\"g2kfnj-0\\"
255259
})\`width:100%;\`;
256-
const Test2 = true ? s(\\"div\\").withConfig({
260+
const Test2 = true ? s.div.withConfig({
257261
displayName: \\"Test2\\",
258262
componentId: \\"g2kfnj-1\\"
259-
})\`\` : s(\\"div\\").withConfig({
263+
})\`\` : s.div.withConfig({
260264
displayName: \\"Test2\\",
261265
componentId: \\"g2kfnj-2\\"
262266
})\`\`;
263267
const styles = {
264-
One: s(\\"div\\").withConfig({
268+
One: s.div.withConfig({
265269
displayName: \\"One\\",
266270
componentId: \\"g2kfnj-3\\"
267271
})\`\`
268272
};
269273
let Component;
270-
Component = s(\\"div\\").withConfig({
274+
Component = s.div.withConfig({
271275
displayName: \\"Component\\",
272276
componentId: \\"g2kfnj-4\\"
273277
})\`\`;
@@ -280,11 +284,11 @@ const WrappedComponent = s(Inner).withConfig({
280284
exports[`fixtures should transpile require default 1`] = `
281285
"const styled_default = require(\\"styled-components\\");
282286
283-
const TestNormal = styled(\\"div\\").withConfig({
287+
const TestNormal = styled.div.withConfig({
284288
displayName: \\"transpile-require-default__TestNormal\\",
285289
componentId: \\"stn6f-0\\"
286290
})([\\"width:100%;\\"]);
287-
const Test = styled_default.default(\\"div\\").withConfig({
291+
const Test = styled_default.default.div.withConfig({
288292
displayName: \\"transpile-require-default__Test\\",
289293
componentId: \\"stn6f-1\\"
290294
})([\\"width:100%;\\"]);
@@ -301,14 +305,16 @@ var _styledComponents = _interopRequireDefault(require(\\"styled-components\\"))
301305
302306
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
303307
304-
var Named = (0, _styledComponents.default)(\\"div\\").withConfig({
308+
var Named = _styledComponents.default.div.withConfig({
305309
displayName: \\"transpile-template-literals-with-config__Named\\"
306310
})([\\"\\\\n width: 100%;\\\\n\\"]);
307-
var NamedWithInterpolation = (0, _styledComponents.default)(\\"div\\").withConfig({
311+
312+
var NamedWithInterpolation = _styledComponents.default.div.withConfig({
308313
displayName: \\"transpile-template-literals-with-config__NamedWithInterpolation\\"
309314
})([\\"\\\\n color: \\", \\";\\\\n\\"], function (color) {
310315
return props.color;
311316
});
317+
312318
var Wrapped = (0, _styledComponents.default)(Inner).withConfig({
313319
displayName: \\"transpile-template-literals-with-config__Wrapped\\"
314320
})([\\"\\\\n color: red;\\\\n\\"]);"
@@ -321,35 +327,37 @@ var _styledComponents = _interopRequireDefault(require(\\"styled-components\\"))
321327
322328
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
323329
324-
var Named = (0, _styledComponents.default)(\\"div\\")([\\"\\\\n width: 100%;\\\\n\\"]);
325-
var NamedWithInterpolation = (0, _styledComponents.default)(\\"div\\")([\\"\\\\n color: \\", \\";\\\\n\\"], function (color) {
330+
var Named = _styledComponents.default.div([\\"\\\\n width: 100%;\\\\n\\"]);
331+
332+
var NamedWithInterpolation = _styledComponents.default.div([\\"\\\\n color: \\", \\";\\\\n\\"], function (color) {
326333
return props.color;
327334
});
335+
328336
var Wrapped = (0, _styledComponents.default)(Inner)([\\"color: red;\\"]);"
329337
`;
330338
331339
exports[`fixtures should use file name 1`] = `
332340
"import styled from \\"styled-components\\";
333-
const Test = styled(\\"div\\").withConfig({
341+
const Test = styled.div.withConfig({
334342
displayName: \\"use-file-name__Test\\",
335343
componentId: \\"sc-15riiwx-0\\"
336344
})\`color:red;\`;
337-
const before = styled(\\"div\\").withConfig({
345+
const before = styled.div.withConfig({
338346
displayName: \\"use-file-name__before\\",
339347
componentId: \\"sc-15riiwx-1\\"
340348
})\`color:blue;\`;
341-
styled(\\"div\\").withConfig({
349+
styled.div.withConfig({
342350
displayName: \\"use-file-name\\",
343351
componentId: \\"sc-15riiwx-2\\"
344352
})\`\`;
345-
export default styled(\\"button\\").withConfig({
353+
export default styled.button.withConfig({
346354
displayName: \\"use-file-name\\",
347355
componentId: \\"sc-15riiwx-3\\"
348356
})\`\`;"
349357
`;
350358
351359
exports[`fixtures should work with hoisted default as import 1`] = `
352-
"const Test = s(\\"div\\").withConfig({
360+
"const Test = s.div.withConfig({
353361
displayName: \\"work-with-hoisted-default-as-import__Test\\",
354362
componentId: \\"sc-1te5tgi-0\\"
355363
})\`width:100%;\`;

0 commit comments

Comments
 (0)