Skip to content

🎥 Make videos programmatically with React

that works!

Jonny Burger34d2be2c8f89
diff --git a/packages/studio-server/src/codemods/duplicate-composition.ts b/packages/studio-server/src/codemods/duplicate-composition.ts
index a5425716dd..f093d9d3c3 100644
--- a/packages/studio-server/src/codemods/duplicate-composition.ts
+++ b/packages/studio-server/src/codemods/duplicate-composition.ts
@@ -1,7 +1,7 @@
import type {File} from '@babel/types';
import type {RecastCodemod} from '@remotion/studio-shared';
import * as recast from 'recast';
-import tsParser from 'recast/parsers/babel-ts';
+import * as tsParser from 'recast/parsers/babel-ts';
import {applyCodemod} from './recast-mods';
const getPrettier = async () => {
diff --git a/packages/studio-server/src/codemods/recast-mods.ts b/packages/studio-server/src/codemods/recast-mods.ts
index 629d6ffc5d..b1f910f0b5 100644
--- a/packages/studio-server/src/codemods/recast-mods.ts
+++ b/packages/studio-server/src/codemods/recast-mods.ts
@@ -140,42 +140,57 @@ const mapJsxFragment = (
return {
...jsxFragment,
children: jsxFragment.children
- .map((c) => {
- const compId = getCompositionIdFromJSXElement(c);
- if (
- transformation.type === 'duplicate-composition' &&
- compId === transformation.idToDuplicate
- ) {
- return [
- mapJsxChild(c),
- changeCompositionIdInJSXElement(c, transformation.newId),
- ];
- }
-
- if (
- transformation.type === 'rename-composition' &&
- compId === transformation.idToRename
- ) {
- return [changeCompositionIdInJSXElement(c, transformation.newId)];
- }
-
- if (
- transformation.type === 'delete-composition' &&
- compId === transformation.idToDelete
- ) {
- return [];
- }
-
- return [mapJsxChild(c)];
- })
+ .map((c) => mapJsxChild(c, transformation))
.flat(1),
};
};
const mapJsxChild = (
- jsxChild: JSXFragment['children'][number],
-): JSXFragment['children'][number] => {
- return jsxChild;
+ c: JSXFragment['children'][number],
+ transformation: RecastCodemod | null,
+): JSXFragment['children'][number][] => {
+ const compId = getCompositionIdFromJSXElement(c);
+
+ if (transformation === null) {
+ return [c];
+ }
+
+ if (
+ transformation.type === 'duplicate-composition' &&
+ compId === transformation.idToDuplicate
+ ) {
+ return [
+ ...mapJsxChild(c, null),
+ changeCompositionIdInJSXElement(c, transformation.newId),
+ ];
+ }
+
+ if (
+ transformation.type === 'rename-composition' &&
+ compId === transformation.idToRename
+ ) {
+ return [changeCompositionIdInJSXElement(c, transformation.newId)];
+ }
+
+ if (
+ transformation.type === 'delete-composition' &&
+ compId === transformation.idToDelete
+ ) {
+ return [];
+ }
+
+ if (c.type === 'JSXElement') {
+ return [
+ {
+ ...c,
+ children: c.children
+ .map((childOfChild) => mapJsxChild(childOfChild, transformation))
+ .flat(1),
+ },
+ ];
+ }
+
+ return [c];
};
const getCompositionIdFromJSXElement = (