@@ -156,6 +156,7 @@ export function compileScript(
156
156
const userImports : Record <
157
157
string ,
158
158
{
159
+ isType : boolean
159
160
imported : string | null
160
161
source : string
161
162
}
@@ -202,11 +203,9 @@ export function compileScript(
202
203
try {
203
204
return _parse ( input , options ) . program . body
204
205
} catch ( e ) {
205
- e . message = `[@vue/compiler-sfc] ${ e . message } \n\n${ generateCodeFrame (
206
- source ,
207
- e . pos + offset ,
208
- e . pos + offset + 1
209
- ) } `
206
+ e . message = `[@vue/compiler-sfc] ${ e . message } \n\n${
207
+ sfc . filename
208
+ } \n${ generateCodeFrame ( source , e . pos + offset , e . pos + offset + 1 ) } `
210
209
throw e
211
210
}
212
211
}
@@ -217,20 +216,25 @@ export function compileScript(
217
216
end : number = node . end ! + startOffset
218
217
) {
219
218
throw new Error (
220
- `[@vue/compiler-sfc] ${ msg } \n\n` +
221
- generateCodeFrame ( source , node . start ! + startOffset , end )
219
+ `[@vue/compiler-sfc] ${ msg } \n\n${ sfc . filename } \n${ generateCodeFrame (
220
+ source ,
221
+ node . start ! + startOffset ,
222
+ end
223
+ ) } `
222
224
)
223
225
}
224
226
225
227
function registerUserImport (
226
228
source : string ,
227
229
local : string ,
228
- imported : string | false
230
+ imported : string | false ,
231
+ isType : boolean
229
232
) {
230
233
if ( source === 'vue' && imported ) {
231
234
userImportAlias [ imported ] = local
232
235
}
233
236
userImports [ local ] = {
237
+ isType,
234
238
imported : imported || null ,
235
239
source
236
240
}
@@ -425,7 +429,12 @@ export function compileScript(
425
429
specifier . type === 'ImportSpecifier' &&
426
430
specifier . imported . type === 'Identifier' &&
427
431
specifier . imported . name
428
- registerUserImport ( node . source . value , specifier . local . name , imported )
432
+ registerUserImport (
433
+ node . source . value ,
434
+ specifier . local . name ,
435
+ imported ,
436
+ node . importKind === 'type'
437
+ )
429
438
}
430
439
} else if ( node . type === 'ExportDefaultDeclaration' ) {
431
440
// export default
@@ -575,7 +584,12 @@ export function compileScript(
575
584
error ( `different imports aliased to same local name.` , specifier )
576
585
}
577
586
} else {
578
- registerUserImport ( source , local , imported )
587
+ registerUserImport (
588
+ source ,
589
+ local ,
590
+ imported ,
591
+ node . importKind === 'type'
592
+ )
579
593
}
580
594
}
581
595
if ( removed === node . specifiers . length ) {
@@ -790,7 +804,8 @@ export function compileScript(
790
804
if ( optionsArg ) {
791
805
Object . assign ( bindingMetadata , analyzeBindingsFromOptions ( optionsArg ) )
792
806
}
793
- for ( const [ key , { source } ] of Object . entries ( userImports ) ) {
807
+ for ( const [ key , { isType, source } ] of Object . entries ( userImports ) ) {
808
+ if ( isType ) continue
794
809
bindingMetadata [ key ] =
795
810
source . endsWith ( '.vue' ) || source === 'vue'
796
811
? BindingTypes . SETUP_CONST
@@ -841,7 +856,9 @@ export function compileScript(
841
856
} else if ( err ) {
842
857
if ( err . loc ) {
843
858
err . message +=
844
- `\n` +
859
+ `\n\n` +
860
+ sfc . filename +
861
+ '\n' +
845
862
generateCodeFrame (
846
863
source ,
847
864
err . loc . start . offset ,
@@ -868,7 +885,9 @@ export function compileScript(
868
885
// return bindings from setup
869
886
const allBindings : Record < string , any > = { ...setupBindings }
870
887
for ( const key in userImports ) {
871
- allBindings [ key ] = true
888
+ if ( ! userImports [ key ] . isType ) {
889
+ allBindings [ key ] = true
890
+ }
872
891
}
873
892
returned = `{ ${ Object . keys ( allBindings ) . join ( ', ' ) } }`
874
893
}
0 commit comments