Skip to content

Commit

Permalink
Merge pull request #383 from childrentime/fix/early-wrapReturn
Browse files Browse the repository at this point in the history
Fix: mv wrapReturn behind transform
  • Loading branch information
carbonrobot authored Feb 5, 2024
2 parents 43d32b0 + 7a66f5f commit 2794a3b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions packages/react-live/src/utils/test/fixtures/optional-chain.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { generateElement } from "../../transpile";
import { shallow } from "../renderer";

describe("transpile", () => {
it("should support optional chain", () => {
const code = `function Demo() {
return <h3 style={{
background: 'darkslateblue',
color: 'white',
padding: 8,
borderRadius: 4
}}>
{'1'?.toString()}
</h3>
}`;
const Component = generateElement({ code });
const wrapper = shallow(<Component />);

expect(wrapper.html()).toMatchInlineSnapshot(
`"<h3 style=\\"background:darkslateblue;color:white;padding:8px;border-radius:4px\\">1</h3>"`
);
});
});
2 changes: 1 addition & 1 deletion packages/react-live/src/utils/transpile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ export const generateElement = (
const transformed = compose<string>(
addJsxConst,
transform({ transforms: ["imports"] }),
wrapReturn,
spliceJsxConst,
trimCode,
transform({ transforms: firstPassTransforms }),
wrapReturn,
trimCode
)(code);

Expand Down

0 comments on commit 2794a3b

Please sign in to comment.