Skip to content

Commit 03b2bff

Browse files
committed
wip: do not return type imports
1 parent 09c861d commit 03b2bff

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

packages/compiler-sfc/src/compileScript.ts

+32-13
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export function compileScript(
156156
const userImports: Record<
157157
string,
158158
{
159+
isType: boolean
159160
imported: string | null
160161
source: string
161162
}
@@ -202,11 +203,9 @@ export function compileScript(
202203
try {
203204
return _parse(input, options).program.body
204205
} 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)}`
210209
throw e
211210
}
212211
}
@@ -217,20 +216,25 @@ export function compileScript(
217216
end: number = node.end! + startOffset
218217
) {
219218
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+
)}`
222224
)
223225
}
224226

225227
function registerUserImport(
226228
source: string,
227229
local: string,
228-
imported: string | false
230+
imported: string | false,
231+
isType: boolean
229232
) {
230233
if (source === 'vue' && imported) {
231234
userImportAlias[imported] = local
232235
}
233236
userImports[local] = {
237+
isType,
234238
imported: imported || null,
235239
source
236240
}
@@ -425,7 +429,12 @@ export function compileScript(
425429
specifier.type === 'ImportSpecifier' &&
426430
specifier.imported.type === 'Identifier' &&
427431
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+
)
429438
}
430439
} else if (node.type === 'ExportDefaultDeclaration') {
431440
// export default
@@ -575,7 +584,12 @@ export function compileScript(
575584
error(`different imports aliased to same local name.`, specifier)
576585
}
577586
} else {
578-
registerUserImport(source, local, imported)
587+
registerUserImport(
588+
source,
589+
local,
590+
imported,
591+
node.importKind === 'type'
592+
)
579593
}
580594
}
581595
if (removed === node.specifiers.length) {
@@ -790,7 +804,8 @@ export function compileScript(
790804
if (optionsArg) {
791805
Object.assign(bindingMetadata, analyzeBindingsFromOptions(optionsArg))
792806
}
793-
for (const [key, { source }] of Object.entries(userImports)) {
807+
for (const [key, { isType, source }] of Object.entries(userImports)) {
808+
if (isType) continue
794809
bindingMetadata[key] =
795810
source.endsWith('.vue') || source === 'vue'
796811
? BindingTypes.SETUP_CONST
@@ -841,7 +856,9 @@ export function compileScript(
841856
} else if (err) {
842857
if (err.loc) {
843858
err.message +=
844-
`\n` +
859+
`\n\n` +
860+
sfc.filename +
861+
'\n' +
845862
generateCodeFrame(
846863
source,
847864
err.loc.start.offset,
@@ -868,7 +885,9 @@ export function compileScript(
868885
// return bindings from setup
869886
const allBindings: Record<string, any> = { ...setupBindings }
870887
for (const key in userImports) {
871-
allBindings[key] = true
888+
if (!userImports[key].isType) {
889+
allBindings[key] = true
890+
}
872891
}
873892
returned = `{ ${Object.keys(allBindings).join(', ')} }`
874893
}

0 commit comments

Comments
 (0)