forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler] Support enableRefAsProp in jsx transform
- Loading branch information
Jack Pope
committed
Nov 15, 2024
1 parent
0480cdb
commit b76ecd1
Showing
2 changed files
with
33 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
// 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 GitHub Actions / Lint babel-plugin-react-compiler
|
||
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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters