🎥 Make videos programmatically with React
make id={"seven"} work
Jonny Burger28ad1f7aba2c
diff --git a/packages/example/src/CodemodTestbed.tsx b/packages/example/src/CodemodTestbed.tsxindex 9f07dad75b..0c13d5636b 100644--- a/packages/example/src/CodemodTestbed.tsx+++ b/packages/example/src/CodemodTestbed.tsx@@ -41,6 +41,17 @@ function AltCodemodRootFragment() {schema={dynamicDurationSchema}defaultProps={{duration: 50}}/>+ <Composition+ // eslint-disable-next-line react/jsx-curly-brace-presence+ id={'seven'}+ component={DynamicDuration}+ width={1080}+ height={1080}+ fps={30}+ durationInFrames={100}+ schema={dynamicDurationSchema}+ defaultProps={{duration: 50}}+ /></>);}diff --git a/packages/it-tests/src/codemods/codemods.test.ts b/packages/it-tests/src/codemods/codemods.test.tsindex 39ef221474..4f75756d6e 100644--- a/packages/it-tests/src/codemods/codemods.test.ts+++ b/packages/it-tests/src/codemods/codemods.test.ts@@ -136,3 +136,19 @@ test("in non-return statement", () => {expect(newContents).not.toContain('"six"');expect(newContents).toContain('"jkl"');});++test("curly braces id={'seven'}", () => {+ const { changesMade, newContents } =+ StudioServerInternals.parseAndApplyCodemod({+ input: contents,+ codeMod: {+ type: "rename-composition",+ idToRename: "seven",+ newId: "mno",+ },+ });+ expect(changesMade.length).toBe(1);+ expect(getCompositionCount(newContents)).toBe(compCount);+ expect(newContents).not.toContain('"seven"');+ expect(newContents).toContain('"mno"');+});diff --git a/packages/studio-server/src/codemods/recast-mods.ts b/packages/studio-server/src/codemods/recast-mods.tsindex cc63737eca..b65b04c0b8 100644--- a/packages/studio-server/src/codemods/recast-mods.ts+++ b/packages/studio-server/src/codemods/recast-mods.ts@@ -283,8 +283,6 @@ const getCompositionIdFromJSXElement = (const {openingElement} = jsxElement;const {name} = openingElement;- // TODO: There is also JSXMemberExpression | JSXNamespacedName,- // could these be in a composition as wellif (name.type !== 'JSXIdentifier') {return null;}@@ -311,11 +309,17 @@ const getCompositionIdFromJSXElement = (return null;}- // TODO: At least JSXif (attribute.value.type === 'StringLiteral') {return attribute.value.value;}+ if (+ attribute.value.type === 'JSXExpressionContainer' &&+ attribute.value.expression.type === 'StringLiteral'+ ) {+ return attribute.value.expression.value;+ }+return null;}).filter(Boolean);@@ -348,8 +352,6 @@ const changeComposition = ({const {openingElement} = jsxElement;const {name} = openingElement;- // TODO: There is also JSXMemberExpression | JSXNamespacedName,- // could these be in a composition as wellif (name.type !== 'JSXIdentifier') {return jsxElement;}@@ -381,7 +383,7 @@ const changeComposition = ({return null;}- // TODO: Support JSX+ // id="one"if (attribute.name.name === 'id' &&attribute.value &&@@ -397,6 +399,30 @@ const changeComposition = ({};}+ // id={"one"}++ if (+ attribute.name.name === 'id' &&+ attribute.value &&+ attribute.value.type === 'JSXExpressionContainer' &&+ attribute.value.expression.type === 'StringLiteral'+ ) {+ changesMade.push({+ description: 'Replaced composition id',+ });++ return {+ ...attribute,+ value: {+ ...attribute.value,+ expression: {+ ...attribute.value.expression,+ value: newCompositionId,+ },+ },+ };+ }+if (attribute.name.name === 'fps' &&attribute.value &&