Skip to content

Commit 2794a3b

Browse files
authored
Merge pull request #383 from childrentime/fix/early-wrapReturn
Fix: mv wrapReturn behind transform
2 parents 43d32b0 + 7a66f5f commit 2794a3b

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { generateElement } from "../../transpile";
2+
import { shallow } from "../renderer";
3+
4+
describe("transpile", () => {
5+
it("should support optional chain", () => {
6+
const code = `function Demo() {
7+
return <h3 style={{
8+
background: 'darkslateblue',
9+
color: 'white',
10+
padding: 8,
11+
borderRadius: 4
12+
}}>
13+
{'1'?.toString()}
14+
</h3>
15+
}`;
16+
const Component = generateElement({ code });
17+
const wrapper = shallow(<Component />);
18+
19+
expect(wrapper.html()).toMatchInlineSnapshot(
20+
`"<h3 style=\\"background:darkslateblue;color:white;padding:8px;border-radius:4px\\">1</h3>"`
21+
);
22+
});
23+
});

packages/react-live/src/utils/transpile/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ export const generateElement = (
3535
const transformed = compose<string>(
3636
addJsxConst,
3737
transform({ transforms: ["imports"] }),
38-
wrapReturn,
3938
spliceJsxConst,
4039
trimCode,
4140
transform({ transforms: firstPassTransforms }),
41+
wrapReturn,
4242
trimCode
4343
)(code);
4444

0 commit comments

Comments
 (0)