mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-31 15:50:32 +00:00
fix(nuxt): don't return stub function from tree-shaken composables (#5786)
This commit is contained in:
parent
728a0a5ef4
commit
b045b7141b
@ -10,7 +10,7 @@ interface TreeShakePluginOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const TreeShakePlugin = createUnplugin((options: TreeShakePluginOptions) => {
|
export const TreeShakePlugin = createUnplugin((options: TreeShakePluginOptions) => {
|
||||||
const COMPOSABLE_RE = new RegExp(`($|\\s*)(${options.treeShake.join('|')})(?=\\()`, 'g')
|
const COMPOSABLE_RE = new RegExp(`($|\\s+)(${options.treeShake.join('|')})(?=\\()`, 'gm')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: 'nuxt:server-treeshake:transfrom',
|
name: 'nuxt:server-treeshake:transfrom',
|
||||||
@ -35,7 +35,7 @@ export const TreeShakePlugin = createUnplugin((options: TreeShakePluginOptions)
|
|||||||
const s = new MagicString(code)
|
const s = new MagicString(code)
|
||||||
const strippedCode = stripLiteral(code)
|
const strippedCode = stripLiteral(code)
|
||||||
for (const match of strippedCode.matchAll(COMPOSABLE_RE) || []) {
|
for (const match of strippedCode.matchAll(COMPOSABLE_RE) || []) {
|
||||||
s.overwrite(match.index, match.index + match[0].length, `(() => {}) || /*#__PURE__*/ false && ${match[0]}`)
|
s.overwrite(match.index, match.index + match[0].length, `${match[1]} /*#__PURE__*/ false && ${match[2]}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s.hasChanged()) {
|
if (s.hasChanged()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user