fix(nuxt): check before appending comma in composable keys (#8529)

This commit is contained in:
Daniel Roe 2022-11-02 06:15:33 -04:00 committed by GitHub
parent bdacfa6ffe
commit f485c143f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -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(',')
s.appendLeft(
codeIndex + (node as any).end - 1,
(node.arguments.length ? ', ' : '') + "'$" + hash(`${relativeID}-${++count}`) + "'"
(node.arguments.length && !endsWithComma ? ', ' : '') + "'$" + hash(`${relativeID}-${++count}`) + "'"
)
}
})