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

fix(react): honour import_source in new jsx #7128

Merged
merged 2 commits into from Mar 23, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -7,14 +7,14 @@ Object.defineProperty(exports, "__esModule", {
var _objectSpread = require("@swc/helpers/lib/_object_spread.js").default;
var _objectSpreadProps = require("@swc/helpers/lib/_object_spread_props.js").default;
var _jsxRuntime = require("preact/jsx-runtime");
var _react = require("react");
var _preact = require("preact");
var props = {
answer: 42
};
var a = /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", _objectSpreadProps(_objectSpread({}, props), {
children: "text"
}), "foo");
var b = /*#__PURE__*/ (0, _react.createElement)("div", _objectSpreadProps(_objectSpread({}, props), {
var b = /*#__PURE__*/ (0, _preact.createElement)("div", _objectSpreadProps(_objectSpread({}, props), {
key: "bar"
}), "text");
//// [react.tsx]
Expand Down
Expand Up @@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
value: !0
});
var _objectSpread = require("@swc/helpers/lib/_object_spread.js").default, _objectSpreadProps = require("@swc/helpers/lib/_object_spread_props.js").default;
require("preact/jsx-runtime"), require("react");
require("preact/jsx-runtime"), require("preact");
var props = {
answer: 42
};
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_transforms_react/src/jsx/mod.rs
Expand Up @@ -993,7 +993,7 @@ where
src: Str {
span: DUMMY_SP,
raw: None,
value: "react".into(),
value: self.import_source.clone(),
}
.into(),
type_only: Default::default(),
Expand Down
@@ -0,0 +1,24 @@
import { isValidElement, Children } from "react";

import * as styles from "./CheckmarkList.styles";


const CheckmarkList = ({ children}) => {
const listItems = () =>
Children.map(children, (child, index) => {
if (!isValidElement(child)) {
return null;
}
const { children: liChildren, css: liCss, ...otherProps } = child.props;

return (
<li {...otherProps} key={`checkmark-list-item-${index}`} css={[styles.listItem, liCss]}>
{liChildren}
</li>
);
});

return <ul css={styles.list}>{listItems()}</ul>;
};

export { CheckmarkList };
@@ -0,0 +1,6 @@
{
"runtime": "automatic",
"importSource": "@emotion/react",
"pragma": "React.createElement",
"pragmaFrag": "React.Fragment"
}
@@ -0,0 +1,25 @@
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
import { createElement as _createElement } from "@emotion/react";
import { isValidElement, Children } from "react";
import * as styles from "./CheckmarkList.styles";
const CheckmarkList = ({ children })=>{
const listItems = ()=>Children.map(children, (child, index)=>{
if (!/*#__PURE__*/ isValidElement(child)) {
return null;
}
const { children: liChildren , css: liCss , ...otherProps } = child.props;
return /*#__PURE__*/ _createElement("li", {
...otherProps,
key: `checkmark-list-item-${index}`,
css: [
styles.listItem,
liCss
]
}, liChildren);
});
return /*#__PURE__*/ _jsx("ul", {
css: styles.list,
children: listItems()
});
};
export { CheckmarkList };