Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/vite/src/plugins/composable-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ export const composableKeysPlugin = createUnplugin((options: ComposableKeysOptio
break
}

// 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(',')
Copy link
Member

@pi0 pi0 Nov 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perf: this is a heavy operation to run on each code block, copying the whole string, trimming (that also copies) to only check the last character is ,. We could replace it with a look-behind loop.

Suggested change
const endsWithComma = code.slice(codeIndex + (node as any).start, codeIndex + (node as any).end - 1).trim().endsWith(',')
// 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(',')


s.appendLeft(
codeIndex + (node as any).end - 1,
(node.arguments.length ? ', ' : '') + "'$" + hash(`${relativeID}-${++count}`) + "'"
(node.arguments.length && !endsWithComma ? ', ' : '') + "'$" + hash(`${relativeID}-${++count}`) + "'"
)
}
})
Expand Down