Skip to content

Commit a940fc1

Browse files
authored
Merge pull request #185 from satya164/patch-1
Fix transpiling inserted tagged template literals. Fixes #184
2 parents 3b3df72 + 5e66e45 commit a940fc1

File tree

3 files changed

+184
-41
lines changed

3 files changed

+184
-41
lines changed

src/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ export default function({ types: t }) {
1717
state.items = []
1818
},
1919
exit(path, state) {
20+
const oldLength = path.node.body.length
21+
2022
path.node.body.push(...state.items)
23+
24+
const newLength = path.node.body.length
25+
26+
for (let i = 0; i < newLength - oldLength; i++) {
27+
// Queue all inserted items for revisiting so that tagged templates are transpiled
28+
path.requeue(path.get('body')[oldLength + i]);
29+
}
2130
},
2231
},
2332
JSXAttribute(path, state) {

test/__snapshots__/index.test.js.snap

Lines changed: 175 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,146 @@ const WrappedComponent = s(Inner).withConfig({
368368
exports[`fixtures should transpile css prop 1`] = `
369369
"\\"use strict\\";
370370
371+
function _templateObject17() {
372+
var data = _taggedTemplateLiteral([void 0], [\\"flex: 1\\"]);
373+
374+
_templateObject17 = function _templateObject17() {
375+
return data;
376+
};
377+
378+
return data;
379+
}
380+
381+
function _templateObject16() {
382+
var data = _taggedTemplateLiteral([void 0], [\\"flex: 1\\"]);
383+
384+
_templateObject16 = function _templateObject16() {
385+
return data;
386+
};
387+
388+
return data;
389+
}
390+
391+
function _templateObject15() {
392+
var data = _taggedTemplateLiteral([\\"\\\\n color: \\", \\";\\\\n \\"]);
393+
394+
_templateObject15 = function _templateObject15() {
395+
return data;
396+
};
397+
398+
return data;
399+
}
400+
401+
function _templateObject14() {
402+
var data = _taggedTemplateLiteral([\\"\\\\n color: \\", \\";\\\\n \\"]);
403+
404+
_templateObject14 = function _templateObject14() {
405+
return data;
406+
};
407+
408+
return data;
409+
}
410+
411+
function _templateObject13() {
412+
var data = _taggedTemplateLiteral([\\"\\\\n border-radius: \\", \\"px;\\\\n \\"]);
413+
414+
_templateObject13 = function _templateObject13() {
415+
return data;
416+
};
417+
418+
return data;
419+
}
420+
421+
function _templateObject12() {
422+
var data = _taggedTemplateLiteral([\\"\\\\n color: \\", \\";\\\\n \\"]);
423+
424+
_templateObject12 = function _templateObject12() {
425+
return data;
426+
};
427+
428+
return data;
429+
}
430+
431+
function _templateObject11() {
432+
var data = _taggedTemplateLiteral([\\"\\\\n background: \\", \\";\\\\n \\"]);
433+
434+
_templateObject11 = function _templateObject11() {
435+
return data;
436+
};
437+
438+
return data;
439+
}
440+
441+
function _templateObject10() {
442+
var data = _taggedTemplateLiteral([void 0, void 0], [\\"\\", \\"\\"]);
443+
444+
_templateObject10 = function _templateObject10() {
445+
return data;
446+
};
447+
448+
return data;
449+
}
450+
451+
function _templateObject9() {
452+
var data = _taggedTemplateLiteral([void 0], [\\"flex: 1\\"]);
453+
454+
_templateObject9 = function _templateObject9() {
455+
return data;
456+
};
457+
458+
return data;
459+
}
460+
461+
function _templateObject8() {
462+
var data = _taggedTemplateLiteral([\\"\\\\n color: blue;\\\\n \\"]);
463+
464+
_templateObject8 = function _templateObject8() {
465+
return data;
466+
};
467+
468+
return data;
469+
}
470+
471+
function _templateObject7() {
472+
var data = _taggedTemplateLiteral([void 0], [\\"flex: 1;\\"]);
473+
474+
_templateObject7 = function _templateObject7() {
475+
return data;
476+
};
477+
478+
return data;
479+
}
480+
481+
function _templateObject6() {
482+
var data = _taggedTemplateLiteral([void 0, void 0], [\\"\\", \\"\\"]);
483+
484+
_templateObject6 = function _templateObject6() {
485+
return data;
486+
};
487+
488+
return data;
489+
}
490+
491+
function _templateObject5() {
492+
var data = _taggedTemplateLiteral([\\"\\\\n flex: 1;\\\\n \\"]);
493+
494+
_templateObject5 = function _templateObject5() {
495+
return data;
496+
};
497+
498+
return data;
499+
}
500+
501+
function _templateObject4() {
502+
var data = _taggedTemplateLiteral([void 0], [\\"flex: 1;\\"]);
503+
504+
_templateObject4 = function _templateObject4() {
505+
return data;
506+
};
507+
508+
return data;
509+
}
510+
371511
var _styledComponents = _interopRequireDefault(require(\\"styled-components\\"));
372512
373513
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -485,60 +625,62 @@ var NestedCompWithDot = function NestedCompWithDot(p) {
485625
return <_StyledButtonGhostNew>H</_StyledButtonGhostNew>;
486626
};
487627
488-
var _StyledP = (0, _styledComponents.default)(\\"p\\")\`flex: 1;\`;
628+
var _StyledP = (0, _styledComponents.default)(\\"p\\")(_templateObject4());
489629
490-
var _StyledP2 = (0, _styledComponents.default)(\\"p\\")\`
491-
flex: 1;
492-
\`;
630+
var _StyledP2 = (0, _styledComponents.default)(\\"p\\")(_templateObject5());
493631
494-
var _StyledP3 = (0, _styledComponents.default)(\\"p\\")\`\${p => p._$p_}\`;
632+
var _StyledP3 = (0, _styledComponents.default)(\\"p\\")(_templateObject6(), function (p) {
633+
return p._$p_;
634+
});
495635
496-
var _StyledP4 = (0, _styledComponents.default)(\\"p\\")\`flex: 1;\`;
636+
var _StyledP4 = (0, _styledComponents.default)(\\"p\\")(_templateObject7());
497637
498-
var _StyledP5 = (0, _styledComponents.default)(\\"p\\")\`
499-
color: blue;
500-
\`;
638+
var _StyledP5 = (0, _styledComponents.default)(\\"p\\")(_templateObject8());
501639
502-
var _StyledParagraph = (0, _styledComponents.default)(Paragraph)\`flex: 1\`;
640+
var _StyledParagraph = (0, _styledComponents.default)(Paragraph)(_templateObject9());
503641
504-
var _StyledP6 = (0, _styledComponents.default)(\\"p\\")\`\${p => p._$p_2}\`;
642+
var _StyledP6 = (0, _styledComponents.default)(\\"p\\")(_templateObject10(), function (p) {
643+
return p._$p_2;
644+
});
505645
506-
var _StyledP7 = (0, _styledComponents.default)(\\"p\\")\`
507-
background: \${function (p) {
646+
var _StyledP7 = (0, _styledComponents.default)(\\"p\\")(_templateObject11(), function (p) {
508647
return p._$p_3;
509-
}};
510-
\`;
648+
});
511649
512-
var _StyledP8 = (0, _styledComponents.default)(\\"p\\")\`
513-
color: \${function (props) {
650+
var _StyledP8 = (0, _styledComponents.default)(\\"p\\")(_templateObject12(), function (props) {
514651
return props.theme.a;
515-
}};
516-
\`;
652+
});
517653
518-
var _StyledP9 = (0, _styledComponents.default)(\\"p\\")\`
519-
border-radius: \${radius}px;
520-
\`;
654+
var _StyledP9 = (0, _styledComponents.default)(\\"p\\")(_templateObject13(), radius);
521655
522-
var _StyledP10 = (0, _styledComponents.default)(\\"p\\")\`
523-
color: \${function (p) {
656+
var _StyledP10 = (0, _styledComponents.default)(\\"p\\")(_templateObject14(), function (p) {
524657
return p._$p_4;
525-
}};
526-
\`;
658+
});
527659
528-
var _StyledP11 = (0, _styledComponents.default)(\\"p\\")\`
529-
color: \${function (props) {
660+
var _StyledP11 = (0, _styledComponents.default)(\\"p\\")(_templateObject15(), function (props) {
530661
return props.theme.color;
531-
}};
532-
\`;
662+
});
533663
534-
var _StyledButtonGhost = (0, _styledComponents.default)(Button.Ghost)\`flex: 1\`;
664+
var _StyledButtonGhost = (0, _styledComponents.default)(Button.Ghost)(_templateObject16());
535665
536-
var _StyledButtonGhostNew = (0, _styledComponents.default)(Button.Ghost.New)\`flex: 1\`;"
666+
var _StyledButtonGhostNew = (0, _styledComponents.default)(Button.Ghost.New)(_templateObject17());"
537667
`;
538668
539669
exports[`fixtures should transpile css prop add import 1`] = `
540670
"\\"use strict\\";
541671
672+
function _templateObject() {
673+
var data = _taggedTemplateLiteral([\\"\\\\n width: 35em;\\\\n \\"]);
674+
675+
_templateObject = function _templateObject() {
676+
return data;
677+
};
678+
679+
return data;
680+
}
681+
682+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
683+
542684
Object.defineProperty(exports, \\"__esModule\\", {
543685
value: true
544686
});
@@ -570,9 +712,7 @@ var _default = function _default() {
570712
571713
exports.default = _default;
572714
573-
var _StyledDiv = (0, _styledComponents.default)(\\"div\\")\`
574-
width: 35em;
575-
\`;"
715+
var _StyledDiv = (0, _styledComponents.default)(\\"div\\")(_templateObject());"
576716
`;
577717
578718
exports[`fixtures should transpile require default 1`] = `

yarn.lock

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,6 @@
323323
dependencies:
324324
"@babel/helper-plugin-utils" "^7.0.0"
325325

326-
"@babel/plugin-syntax-jsx@^7.0.0":
327-
version "7.0.0"
328-
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.0.0.tgz#034d5e2b4e14ccaea2e4c137af7e4afb39375ffd"
329-
dependencies:
330-
"@babel/helper-plugin-utils" "^7.0.0"
331-
332326
"@babel/plugin-syntax-object-rest-spread@^7.0.0":
333327
version "7.0.0"
334328
resolved "https://registry.npmjs.org/@babel/plugin-syntax-object-rest-spread/-/plugin-syntax-object-rest-spread-7.0.0.tgz#37d8fbcaf216bd658ea1aebbeb8b75e88ebc549b"

0 commit comments

Comments
 (0)