@@ -49,9 +49,7 @@ export default {
4949 if ( isComponentDefinition ( objectNode ) ) {
5050 componentNode = objectNode ;
5151 emitsNode = objectNode . properties . find (
52- ( property ) =>
53- property . key ?. name === "emits" &&
54- property . value . type === "ArrayExpression" ,
52+ ( property ) => property . key ?. name === "emits" && property . value . type === "ArrayExpression" ,
5553 ) ?. value ;
5654 }
5755 }
@@ -70,15 +68,10 @@ export default {
7068 function getEmitCallsFromTemplate ( importNode ) {
7169 if ( importNode . name === "template" ) {
7270 const templateFileName = importNode . parent . parent . source . value ;
73- const directoryPath = dirname ( context . getFilename ( ) ) ;
74- const templateSource = readFileSync (
75- resolve ( directoryPath , templateFileName ) ,
76- "utf8" ,
77- ) ;
78-
79- const templateEventsNames = Array . from (
80- templateSource . matchAll ( EVENT_NAME_REGEXP ) ,
81- )
71+ const directoryPath = dirname ( context . filename ) ;
72+ const templateSource = readFileSync ( resolve ( directoryPath , templateFileName ) , "utf8" ) ;
73+
74+ const templateEventsNames = Array . from ( templateSource . matchAll ( EVENT_NAME_REGEXP ) )
8275 . map ( ( [ , capturedGroup ] ) => capturedGroup )
8376 . filter ( Boolean ) ;
8477
@@ -145,8 +138,7 @@ export default {
145138 }
146139
147140 function fixMissingEmitDefinitions ( programNode ) {
148- const emitsDefinition =
149- emitsNode ?. elements . map ( ( element ) => element . value ) ?? [ ] ;
141+ const emitsDefinition = emitsNode ?. elements . map ( ( element ) => element . value ) ?? [ ] ;
150142 const pendingEmitDefinitions = Array . from ( emittedEvents ) . filter (
151143 ( e ) => e && ! emitsDefinition . includes ( e ) ,
152144 ) ;
@@ -170,10 +162,7 @@ export default {
170162 // emits with already some event in the component
171163 const lastElement = emitsNode . elements . at ( - 1 ) ;
172164 if ( lastElement ) {
173- return fixer . insertTextAfter (
174- lastElement ,
175- `, ${ stringEmitEvents } ` ,
176- ) ;
165+ return fixer . insertTextAfter ( lastElement , `, ${ stringEmitEvents } ` ) ;
177166 }
178167
179168 // emits without any event in
@@ -201,15 +190,12 @@ export default {
201190 "provide" ,
202191 ] ;
203192
204- const nodeAfterWhichToInsert = componentNode . properties . findLast (
205- ( property ) => fieldsBeforeEmits . includes ( property . key . name ) ,
193+ const nodeAfterWhichToInsert = componentNode . properties . findLast ( ( property ) =>
194+ fieldsBeforeEmits . includes ( property . key . name ) ,
206195 ) ;
207196
208197 if ( nodeAfterWhichToInsert ) {
209- return fixer . insertTextAfter (
210- nodeAfterWhichToInsert ,
211- `,\n\nemits: [${ stringEmitEvents } ]` ,
212- ) ;
198+ return fixer . insertTextAfter ( nodeAfterWhichToInsert , `,\n\nemits: [${ stringEmitEvents } ]` ) ;
213199 }
214200
215201 // in the case there is no fields that should be before emits, then we insert at the beginning of the component
0 commit comments