Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move injected styled component to end of file #334

Merged
merged 1 commit into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/visitors/transpileCssProp.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ export default t => (path, state) => {
if (!injector) {
let parent = elem

while (!t.isProgram(parent.parentPath)) {
while (!t.isProgram(parent)) {
parent = parent.parentPath
}

injector = nodeToInsert => parent.insertBefore(nodeToInsert)
injector = nodeToInsert => parent.pushContainer('body', nodeToInsert)
}

injector(
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/css-declared-after-component/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"plugins": [
[
"../../../src"
]
]
}
10 changes: 10 additions & 0 deletions test/fixtures/css-declared-after-component/code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from "react"
import { css } from "styled-components"

export default function Example() {
return <div css={someCss}>oops</div>
}

const someCss = css`
color: red;
`
12 changes: 12 additions & 0 deletions test/fixtures/css-declared-after-component/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import _styled from "styled-components";
import React from "react";
import { css } from "styled-components";
export default function Example() {
return <_StyledDiv>oops</_StyledDiv>;
}
const someCss = css(["color:red;"]);

var _StyledDiv = _styled("div").withConfig({
displayName: "code___StyledDiv",
componentId: "sc-7mydya-0"
})(["", ""], someCss);
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&

const someCss = (0, _styledComponents.css)([" background:purple;"]);

const App1 = () => {
return <_StyledIcons />;
};

const App2 = () => {
return <_StyledIconsFoo />;
};

const App3 = () => {
return <_StyledIconsFooBar />;
};

var _StyledIcons = (0, _styledComponents.default)(_icons.default).withConfig({
displayName: "code___StyledIcons",
componentId: "sc-1wxehft-0"
})(["", ""], someCss);

const App1 = () => {
return <_StyledIcons />;
};

var _StyledIconsFoo = (0, _styledComponents.default)(_icons.default.Foo).withConfig({
displayName: "code___StyledIconsFoo",
componentId: "sc-1wxehft-1"
})(["", ""], someCss);

const App2 = () => {
return <_StyledIconsFoo />;
};

var _StyledIconsFooBar = (0, _styledComponents.default)(_icons.default.Foo.Bar).withConfig({
displayName: "code___StyledIconsFooBar",
componentId: "sc-1wxehft-2"
})(["", ""], someCss);

const App3 = () => {
return <_StyledIconsFooBar />;
};
4 changes: 2 additions & 2 deletions test/fixtures/transpile-css-prop-add-import/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d

function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }

var _StyledDiv = (0, _styledComponents["default"])("div")(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n width: 35em;\n "])));

var _default = function _default() {
return <_StyledDiv>
<_Card.default>
Expand All @@ -35,3 +33,5 @@ var _default = function _default() {
};

exports["default"] = _default;

var _StyledDiv = (0, _styledComponents["default"])("div")(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n width: 35em;\n "])));
4 changes: 2 additions & 2 deletions test/fixtures/transpile-css-prop-add-require/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d

function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }

var _StyledDiv = (0, _styledComponents["default"])("div")(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n width: 35em;\n "])));

var _default = function _default() {
return <_StyledDiv />;
};

exports["default"] = _default;

var _StyledDiv = (0, _styledComponents["default"])("div")(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n width: 35em;\n "])));
Loading