diff --git a/src/android/__tests__/expo-templates.test.ts b/src/android/__tests__/expo-templates.test.ts index 5c4cf0e..68be284 100644 --- a/src/android/__tests__/expo-templates.test.ts +++ b/src/android/__tests__/expo-templates.test.ts @@ -48,6 +48,18 @@ describe("app/build.gradle", () => { }); describe("MainApplication", () => { + it("accepts a trailing comma after the SDK 57 package list", () => { + const template = sdk57MainApplication.replace( + " }\n )", + " },\n )", + ); + const result = applyMainApplication(template, "kt"); + expect(result).toContain( + " },\n jsBundleFilePath = CodePush.getJSBundleFile()", + ); + expect(result).not.toContain(",,"); + expect(applyMainApplication(result, "kt")).toBe(result); + }); it("passes the CodePush bundle to the SDK 57 ReactHost factory", () => { const result = applyMainApplication(sdk57MainApplication, "kt"); diff --git a/src/utils/__tests__/insert-last-argument.test.ts b/src/utils/__tests__/insert-last-argument.test.ts index 605f2a4..2aefad8 100644 --- a/src/utils/__tests__/insert-last-argument.test.ts +++ b/src/utils/__tests__/insert-last-argument.test.ts @@ -7,6 +7,18 @@ describe("insertLastArgument", () => { ); }); + it.each(["", " // keep the comment", " /* keep the comment */"])( + "preserves an existing trailing comma%s", + (comment) => { + const result = insertLastArgument( + `foo(\n a = 1,${comment}\n)`, + "foo", + "b = 2", + ); + expect(result).toBe(`foo(\n a = 1,\n b = 2${comment}\n)`); + }, + ); + it("fills an empty argument list", () => { expect(insertLastArgument(`foo()`, "foo", "c = 1")).toBe(`foo(c = 1)`); }); diff --git a/src/utils/insert-last-argument.ts b/src/utils/insert-last-argument.ts index c1ab20a..98bf2fa 100644 --- a/src/utils/insert-last-argument.ts +++ b/src/utils/insert-last-argument.ts @@ -137,5 +137,6 @@ export function insertLastArgument( const closeIndent = /^[\t ]*/.exec(source.slice(lineStart, closeIndex))?.[0]; const indent = `${closeIndent ?? ""} `; - return `${source.slice(0, endOfArguments)},\n${indent}${argument}${source.slice(endOfArguments)}`; + const separator = source[endOfArguments - 1] === "," ? "" : ","; + return `${source.slice(0, endOfArguments)}${separator}\n${indent}${argument}${source.slice(endOfArguments)}`; }