@@ -15,7 +15,7 @@ import {
1515import type { Macros } from '..'
1616import { transformAwait } from './await'
1717import { transformReturn } from './return'
18- import type { Node , ObjectExpression } from '@babel/types'
18+ import type { Node } from '@babel/types'
1919
2020export function transformDefineComponent (
2121 root : FunctionalNode ,
@@ -118,31 +118,13 @@ export function transformDefineComponent(
118118 . map ( ( [ key , value ] ) => `'${ key } ': ${ value } ` )
119119 . join ( ', \n' )
120120 if ( propsString ) {
121- const argument = macros . defineComponent . arguments [ 1 ]
122- if ( ! argument ) {
123- s . appendRight (
124- root . end ! ,
125- `, {${ hasRestProp ? 'inheritAttrs: false,' : '' } props: {\n${ propsString } \n} }` ,
126- )
127- } else if ( argument . type === 'ObjectExpression' ) {
128- const resolvedPropsString = `{\n${ propsString } \n}`
129- const prop = prependObjectExpression (
130- argument ,
131- 'props' ,
132- resolvedPropsString ,
133- s ,
134- )
135- if (
136- prop &&
137- prop . type === 'ObjectProperty' &&
138- prop . value . type === 'ObjectExpression'
139- ) {
140- s . appendLeft ( prop . value . start ! , `{...${ resolvedPropsString } , ...` )
141- s . appendRight ( prop . value . end ! , '}' )
142- }
143- if ( hasRestProp ) {
144- prependObjectExpression ( argument , 'inheritAttrs' , 'false' , s )
145- }
121+ const resolvedPropsString = `${ hasRestProp ? 'inheritAttrs: false, ' : '' } props: {\n${ propsString } \n}`
122+ const compOptions = macros . defineComponent . arguments [ 1 ]
123+ if ( ! compOptions ) {
124+ s . appendRight ( root . end ! , `, { ${ resolvedPropsString } }` )
125+ } else if ( compOptions . type === 'ObjectExpression' ) {
126+ s . appendLeft ( compOptions . start ! , `{ ${ resolvedPropsString } , ...` )
127+ s . appendRight ( compOptions . end ! , ' }' )
146128 }
147129 }
148130
@@ -152,24 +134,6 @@ export function transformDefineComponent(
152134 }
153135}
154136
155- function prependObjectExpression (
156- argument : ObjectExpression ,
157- name : string ,
158- value : string ,
159- s : MagicStringAST ,
160- ) {
161- const prop = argument . properties ?. find (
162- ( prop ) =>
163- prop . type === 'ObjectProperty' &&
164- prop . key . type === 'Identifier' &&
165- prop . key . name === name ,
166- )
167- if ( ! prop ) {
168- s . appendRight ( argument . start ! + 1 , `${ name } : ${ value } ,` )
169- }
170- return prop
171- }
172-
173137function getWalkedIds ( root : FunctionalNode , propsName : string ) {
174138 const walkedIds = new Set < string > ( )
175139 walkIdentifiers ( root . body , ( id , parent ) => {
0 commit comments