Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.
/frameworkPublic archive
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 numberDiff line numberDiff 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(',')

@pi0pi0Nov 2, 2022

Copy link
Copy Markdown
Member

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
constendsWithComma=code.slice(codeIndex+(nodeasany).start,codeIndex+(nodeasany).end-1).trim().endsWith(',')
// TODO: Optimize me (https://github.com/nuxt/framework/pull/8529)
constendsWithComma=code.slice(codeIndex+(nodeasany).start,codeIndex+(nodeasany).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