@@ -42,7 +42,10 @@ import {
42
42
ObjectMethod ,
43
43
LVal ,
44
44
Expression ,
45
- VariableDeclaration
45
+ VariableDeclaration ,
46
+ ImportSpecifier ,
47
+ ImportDefaultSpecifier ,
48
+ ImportNamespaceSpecifier
46
49
} from '@babel/types'
47
50
import { walk } from 'estree-walker'
48
51
import { RawSourceMap } from 'source-map'
@@ -375,10 +378,24 @@ export function compileScript(
375
378
s . move ( start , end , 0 )
376
379
}
377
380
381
+ function getImported (
382
+ specifier :
383
+ | ImportSpecifier
384
+ | ImportDefaultSpecifier
385
+ | ImportNamespaceSpecifier
386
+ ) {
387
+ if ( specifier . type === 'ImportSpecifier' )
388
+ return specifier . imported . type === 'Identifier'
389
+ ? specifier . imported . name
390
+ : specifier . imported . value
391
+ else if ( specifier . type === 'ImportNamespaceSpecifier' ) return '*'
392
+ return 'default'
393
+ }
394
+
378
395
function registerUserImport (
379
396
source : string ,
380
397
local : string ,
381
- imported : string | false ,
398
+ imported : string ,
382
399
isType : boolean ,
383
400
isFromSetup : boolean ,
384
401
needTemplateUsageCheck : boolean
@@ -398,7 +415,7 @@ export function compileScript(
398
415
399
416
userImports [ local ] = {
400
417
isType,
401
- imported : imported || 'default' ,
418
+ imported,
402
419
local,
403
420
source,
404
421
isFromSetup,
@@ -951,10 +968,7 @@ export function compileScript(
951
968
if ( node . type === 'ImportDeclaration' ) {
952
969
// record imports for dedupe
953
970
for ( const specifier of node . specifiers ) {
954
- const imported =
955
- specifier . type === 'ImportSpecifier' &&
956
- specifier . imported . type === 'Identifier' &&
957
- specifier . imported . name
971
+ const imported = getImported ( specifier )
958
972
registerUserImport (
959
973
node . source . value ,
960
974
specifier . local . name ,
@@ -996,13 +1010,7 @@ export function compileScript(
996
1010
for ( let i = 0 ; i < node . specifiers . length ; i ++ ) {
997
1011
const specifier = node . specifiers [ i ]
998
1012
const local = specifier . local . name
999
- let imported =
1000
- specifier . type === 'ImportSpecifier' &&
1001
- specifier . imported . type === 'Identifier' &&
1002
- specifier . imported . name
1003
- if ( specifier . type === 'ImportNamespaceSpecifier' ) {
1004
- imported = '*'
1005
- }
1013
+ const imported = getImported ( specifier )
1006
1014
const source = node . source . value
1007
1015
const existing = userImports [ local ]
1008
1016
if (
0 commit comments