Skip to content

🎥 Make videos programmatically with React

@remotion/studio-codemods: Preserve inline split spacing

Jonny Burger5c1795411677
diff --git a/packages/studio-codemods/src/split-video-from-audio.ts b/packages/studio-codemods/src/split-video-from-audio.ts
index fb2d887e9a..7c09fe43ed 100644
--- a/packages/studio-codemods/src/split-video-from-audio.ts
+++ b/packages/studio-codemods/src/split-video-from-audio.ts
@@ -289,9 +289,6 @@ const getAudioSiblingSourceEdit = ({
lineEnd === -1 ? input.length : lineEnd,
);
const isStandalone = sourceAfterElement.trim() === '';
- const lineStart = input.lastIndexOf('\n', start - 1) + 1;
- const whitespaceBeforeElement =
- input.slice(lineStart, start).match(/[\t ]*$/)?.[0] ?? '';
return {
start: end,
@@ -301,7 +298,7 @@ const getAudioSiblingSourceEdit = ({
indent,
insertion: audioSource,
})}`
- : `${whitespaceBeforeElement}${indentContinuationLines({
+ : ` ${indentContinuationLines({
indent,
input,
printed: audioSource,
diff --git a/packages/studio-server/src/test/split-video-from-audio.test.ts b/packages/studio-server/src/test/split-video-from-audio.test.ts
index 96650210db..d32635efdb 100644
--- a/packages/studio-server/src/test/split-video-from-audio.test.ts
+++ b/packages/studio-server/src/test/split-video-from-audio.test.ts
@@ -140,6 +140,28 @@ export const Comp = () => <>
`);
});
+test('splitVideoFromAudio separates siblings with one space on a shared line', async () => {
+ const input = `import {Video} from '@remotion/media';
+
+export const Comp = () => (
+ <div>
+ <Video src="video.mp4" /></div>
+);
+`;
+ const {output} = await splitVideoFromAudio({
+ input,
+ nodePath: lineContainingToNodePath(input, '<Video'),
+ });
+
+ expect(output).toBe(`import {Video, Audio} from '@remotion/media';
+
+export const Comp = () => (
+ <div>
+ <Video src="video.mp4" muted /> <Audio src="video.mp4" /></div>
+);
+`);
+});
+
test('splitVideoFromAudio preserves CRLF and tab indentation', async () => {
const input = [
`import {Video} from '@remotion/media';`,