@@ -127,6 +127,13 @@ export const InjectHydrationPlugin = createUnplugin(() => {
127127
128128/**
129129 * Finds an import specifier for a given imported name from specified package names.
130+ * Searches through all matching import declarations since there can be multiple imports from the same package.
131+ *
132+ * Like
133+ * ```ts
134+ * import { ref } from 'vue'
135+ * import { defineComponent } from 'vue'
136+ * ```
130137 */
131138function findImportSpecifier (
132139 importDecl : ImportDeclaration [ ] ,
@@ -135,16 +142,18 @@ function findImportSpecifier(
135142 callback ?: ( specifier : ImportSpecifier , nextSpecifier ?: ImportDeclarationSpecifier ) => void ,
136143) {
137144 const names = Array . isArray ( pkgNames ) ? pkgNames : [ pkgNames ]
138- const decl = importDecl . find ( imp => names . includes ( imp . source . value ) )
139- if ( ! decl ) {
140- return
141- }
142- for ( let i = 0 ; i < decl . specifiers . length ; i ++ ) {
143- const specifier = decl . specifiers [ i ] !
144- if ( specifier . type === 'ImportSpecifier' && specifier . imported . type === 'Identifier' && specifier . imported . name === importedName ) {
145- callback ?.( specifier , decl . specifiers [ i + 1 ] )
146- return specifier
147- }
145+
146+ const allSpecifiers = importDecl
147+ . filter ( imp => names . includes ( imp . source . value ) )
148+ . flatMap ( decl => decl . specifiers . map ( ( spec , i ) => ( { spec, next : decl . specifiers [ i + 1 ] } ) ) )
149+
150+ const match = allSpecifiers . find ( ( { spec } ) =>
151+ spec . type === 'ImportSpecifier' && spec . imported . type === 'Identifier' && spec . imported . name === importedName ,
152+ )
153+
154+ if ( match ) {
155+ callback ?.( match . spec as ImportSpecifier , match . next )
156+ return match . spec as ImportSpecifier
148157 }
149158}
150159
0 commit comments