@@ -17,6 +17,8 @@ import type { NuxtComponentMeta } from './types'
17
17
18
18
export * from './options'
19
19
20
+ const slotReplacer = ( _ : unknown , _before : string , slotName : string , _rest : unknown ) => `<slot ${ _before || '' } ${ slotName === 'default' ? '' : `name="${ slotName } "` } `
21
+
20
22
export default defineNuxtModule < ModuleOptions > ( {
21
23
meta : {
22
24
name : 'nuxt-component-meta' ,
@@ -40,19 +42,18 @@ export default defineNuxtModule<ModuleOptions>({
40
42
transformers : [
41
43
// @nuxt /content support
42
44
( component , code ) => {
43
- code = code . replace (
44
- / < C o n t e n t S l o t \s * ( [ ^ > ] * ) ? : u s e = " \$ s l o t s \. ( [ a - z A - Z 0 - 9 _ ] + ) " / gm,
45
- ( _ , _before , slotName , _rest ) => {
46
- return `<slot ${ _before || '' } ${ slotName === 'default' ? '' : `name="${ slotName } "` } `
47
- }
48
- )
49
- code = code . replace (
50
- / < C o n t e n t S l o t \s * ( [ ^ > ] * ) ? n a m e = " ( [ a - z A - Z 0 - 9 _ ] + ) " / gm,
51
- ( _ , _before , slotName , _rest ) => {
52
- return `<slot ${ _before || '' } ${ slotName === 'default' ? '' : `name="${ slotName } "` } `
53
- }
54
- )
55
- code = code . replace ( / < \/ C o n t e n t S l o t > / gm, '</slot>' )
45
+ // MDCSlot
46
+ if ( code . includes ( 'MDCSlot' ) ) {
47
+ code = code . replace ( / < M D C S l o t \s * ( [ ^ > ] * ) ? : u s e = " \$ s l o t s \. ( [ a - z A - Z 0 - 9 _ ] + ) " / gm, slotReplacer )
48
+ code = code . replace ( / < M D C S l o t \s * ( [ ^ > ] * ) ? n a m e = " ( [ a - z A - Z 0 - 9 _ ] + ) " / gm, slotReplacer )
49
+ code = code . replace ( / < \/ M D C S l o t > / gm, '</slot>' )
50
+ }
51
+ // ContentSlot
52
+ if ( code . includes ( 'ContentSlot' ) ) {
53
+ code = code . replace ( / < C o n t e n t S l o t \s * ( [ ^ > ] * ) ? : u s e = " \$ s l o t s \. ( [ a - z A - Z 0 - 9 _ ] + ) " / gm, slotReplacer )
54
+ code = code . replace ( / < C o n t e n t S l o t \s * ( [ ^ > ] * ) ? n a m e = " ( [ a - z A - Z 0 - 9 _ ] + ) " / gm, slotReplacer )
55
+ code = code . replace ( / < \/ C o n t e n t S l o t > / gm, '</slot>' )
56
+ }
56
57
57
58
// Handle `(const|let|var) slots = useSlots()`
58
59
const name = code . match ( / ( c o n s t | l e t | v a r ) ( [ a - z A - Z ] [ a - z A - Z - _ 0 - 9 ] * ) = u s e S l o t s \( \) / ) ?. [ 2 ] || '$slots'
@@ -97,8 +98,8 @@ export default defineNuxtModule<ModuleOptions>({
97
98
98
99
99
100
// Retrieve transformers
100
- const transformers = options ?. transformers || [ ]
101
- await nuxt . callHook ( 'component-meta:transformers' as any , transformers )
101
+ let transformers = options ?. transformers || [ ]
102
+ transformers = await nuxt . callHook ( 'component-meta:transformers' as any , transformers ) || transformers
102
103
103
104
let parser : ComponentMetaParser
104
105
const parserOptions : ComponentMetaParserOptions = {
0 commit comments