const userImports: Record<
string,
{
+ isType: boolean
imported: string | null
source: string
}
try {
return _parse(input, options).program.body
} catch (e) {
- e.message = `[@vue/compiler-sfc] ${e.message}\n\n${generateCodeFrame(
- source,
- e.pos + offset,
- e.pos + offset + 1
- )}`
+ e.message = `[@vue/compiler-sfc] ${e.message}\n\n${
+ sfc.filename
+ }\n${generateCodeFrame(source, e.pos + offset, e.pos + offset + 1)}`
throw e
}
}
end: number = node.end! + startOffset
) {
throw new Error(
- `[@vue/compiler-sfc] ${msg}\n\n` +
- generateCodeFrame(source, node.start! + startOffset, end)
+ `[@vue/compiler-sfc] ${msg}\n\n${sfc.filename}\n${generateCodeFrame(
+ source,
+ node.start! + startOffset,
+ end
+ )}`
)
}
function registerUserImport(
source: string,
local: string,
- imported: string | false
+ imported: string | false,
+ isType: boolean
) {
if (source === 'vue' && imported) {
userImportAlias[imported] = local
}
userImports[local] = {
+ isType,
imported: imported || null,
source
}
specifier.type === 'ImportSpecifier' &&
specifier.imported.type === 'Identifier' &&
specifier.imported.name
- registerUserImport(node.source.value, specifier.local.name, imported)
+ registerUserImport(
+ node.source.value,
+ specifier.local.name,
+ imported,
+ node.importKind === 'type'
+ )
}
} else if (node.type === 'ExportDefaultDeclaration') {
// export default
error(`different imports aliased to same local name.`, specifier)
}
} else {
- registerUserImport(source, local, imported)
+ registerUserImport(
+ source,
+ local,
+ imported,
+ node.importKind === 'type'
+ )
}
}
if (removed === node.specifiers.length) {
if (optionsArg) {
Object.assign(bindingMetadata, analyzeBindingsFromOptions(optionsArg))
}
- for (const [key, { source }] of Object.entries(userImports)) {
+ for (const [key, { isType, source }] of Object.entries(userImports)) {
+ if (isType) continue
bindingMetadata[key] =
source.endsWith('.vue') || source === 'vue'
? BindingTypes.SETUP_CONST
} else if (err) {
if (err.loc) {
err.message +=
- `\n` +
+ `\n\n` +
+ sfc.filename +
+ '\n' +
generateCodeFrame(
source,
err.loc.start.offset,
// return bindings from setup
const allBindings: Record<string, any> = { ...setupBindings }
for (const key in userImports) {
- allBindings[key] = true
+ if (!userImports[key].isType) {
+ allBindings[key] = true
+ }
}
returned = `{ ${Object.keys(allBindings).join(', ')} }`
}