Skip to content
This repository was archived by the owner on Feb 12, 2023. It is now read-only.

Commit a825520

Browse files
committed
Fix fragments and components in arguments
1 parent 45ebce6 commit a825520

File tree

5 files changed

+34
-11
lines changed

5 files changed

+34
-11
lines changed

examples/Assets/Resources/components/component-preview.jsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import React from 'react';
22

3+
const ComponentWithHeader = ({ header, component }) => <>
4+
{header}
5+
{component}
6+
</>
7+
38
export default function ComponentPreview() {
49
return (
510
<scrollview style={{ backgroundColor: '#173e54' }}>
6-
Box:
7-
<box style={{ color: '#000000' }}>
8-
Some content in the box
9-
</box>
11+
<ComponentWithHeader header="Box" component={
12+
<box style={{ color: '#000000' }}>
13+
Some content in the box
14+
</box>
15+
}/>
1016

1117
Button:
1218
<button text="Some button text" />

packages/babel-transform/src/TransformJSXToReactBabelPlugin.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ You can turn on the 'throwIfNamespace' flag to bypass this warning.`,
7171
'Fragment tags are only supported in React 16 and up.',
7272
);
7373
}
74-
let callExpr;
75-
if (file.opts.useCreateElement) {
76-
callExpr = buildCreateElementFragmentCall(path, file);
77-
} else {
78-
callExpr = buildJSXFragmentCall(path, file);
79-
}
74+
let callExpr = buildCreateElementFragmentCall(path, file);
75+
// if (file.opts.useCreateElement) {
76+
// callExpr = buildCreateElementFragmentCall(path, file);
77+
// } else {
78+
// callExpr = buildJSXFragmentCall(path, file);
79+
// }
8080

8181
if (callExpr) {
8282
path.replaceWith(t.inherits(callExpr, path.node));

packages/babel-transform/src/babel.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ const types = {
8585
},
8686
isJSXEmptyExpression(node) {
8787
return node && node.type === 'JSXEmptyExpression';
88+
},
89+
nullLiteral() {
90+
return {
91+
type: 'Literal',
92+
value: null,
93+
raw: 'null'
94+
};
8895
}
8996
}
9097

packages/babel-transform/src/jsx-visitor.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ function sanitizeVisitor(visitor, findAncestor) {
5252
} else {
5353
ancestor.right = replacement;
5454
}
55+
} else if (ancestor.type === 'JSXExpressionContainer') {
56+
ancestor.expression = replacement;
57+
} else if (ancestor.type === 'JSXFragment') {
58+
const index = ancestor.children.indexOf(node);
59+
60+
if (index < 0) {
61+
throw new Error(`No argument found to replace in JSXFragment`)
62+
}
63+
64+
ancestor.children[index] = replacement;
5565
} else {
5666
console.log(JSON.stringify(ancestor));
5767
throw new Error(`Unknown ${ancestor.type} element in replaceWith`)

packages/com.mkmarek.uielements.react/Runtime/JsRuntime/JSLibraries.cs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)