Skip to content

Commit

Permalink
[compiler] Support enableRefAsProp in jsx transform
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Pope committed Nov 15, 2024
1 parent 0480cdb commit b76ecd1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -559,28 +559,37 @@ function createPropsProperties(
propAttributes.forEach(prop => {
switch (prop.kind) {
case 'JsxAttribute': {
if (prop.name === 'ref') {
refProperty = {
kind: 'ObjectProperty',
key: {name: 'ref', kind: 'string'},
type: 'property',
place: {...prop.place},
};
} else if (prop.name === 'key') {
keyProperty = {
kind: 'ObjectProperty',
key: {name: 'key', kind: 'string'},
type: 'property',
place: {...prop.place},
};
} else {
const attributeProperty: ObjectProperty = {
kind: 'ObjectProperty',
key: {name: prop.name, kind: 'string'},
type: 'property',
place: {...prop.place},
};
props.push(attributeProperty);
switch (prop.name) {
case 'key': {
keyProperty = {
kind: 'ObjectProperty',
key: {name: 'key', kind: 'string'},
type: 'property',
place: {...prop.place},
};
break;
}
// In the current JSX implementation, ref is both

Check failure on line 572 in compiler/packages/babel-plugin-react-compiler/src/Optimization/InlineJsxTransform.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Expected a block comment instead of consecutive line comments
// a property on the element and a property on props.
// Intentional fallthrough to push into props.
// @ts-expect-error

Check failure on line 575 in compiler/packages/babel-plugin-react-compiler/src/Optimization/InlineJsxTransform.ts

View workflow job for this annotation

GitHub Actions / Lint babel-plugin-react-compiler

Include a description after the "@ts-expect-error" directive to explain why the @ts-expect-error is necessary. The description must be 3 characters or longer
case 'ref': {
refProperty = {
kind: 'ObjectProperty',
key: {name: 'ref', kind: 'string'},
type: 'property',
place: {...prop.place},
};
}
default: {
const attributeProperty: ObjectProperty = {
kind: 'ObjectProperty',
key: {name: prop.name, kind: 'string'},
type: 'property',
place: {...prop.place},
};
props.push(attributeProperty);
}
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function Parent(t0) {
type: "div",
ref: ref,
key: null,
props: { children: children },
props: { ref: ref, children: children },
};
}
$[0] = children;
Expand Down Expand Up @@ -180,7 +180,7 @@ function ParentAndRefAndKey(props) {
type: Parent,
ref: testRef,
key: "testKey",
props: { a: "a", b: { b: "b" }, c: C },
props: { a: "a", b: { b: "b" }, c: C, ref: testRef },
};
}
$[0] = t0;
Expand Down

0 comments on commit b76ecd1

Please sign in to comment.