From 860cfe16b3e2bda4e4e3e02a66d37921cbca406d Mon Sep 17 00:00:00 2001 From: Michael Brevard Date: Mon, 29 Jan 2024 13:11:06 +0200 Subject: [PATCH] perf(vite): avoid `endsWith` when checking for whitespace (#24746) --- packages/vite/src/plugins/composable-keys.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/plugins/composable-keys.ts b/packages/vite/src/plugins/composable-keys.ts index a160545b59..4998ef17ee 100644 --- a/packages/vite/src/plugins/composable-keys.ts +++ b/packages/vite/src/plugins/composable-keys.ts @@ -119,7 +119,8 @@ export const composableKeysPlugin = createUnplugin((options: ComposableKeysOptio } // TODO: Optimize me (https://github.com/nuxt/framework/pull/8529) - const endsWithComma = code.slice(codeIndex + (node as any).start, codeIndex + (node as any).end - 1).trim().endsWith(',') + const newCode = code.slice(codeIndex + (node as any).start, codeIndex + (node as any).end - 1).trim() + const endsWithComma = newCode[newCode.length - 1] === ',' s.appendLeft( codeIndex + (node as any).end - 1,