From 8e29ef6019d1b9d9c8f67b4ebba0223b8e0f914c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E6=9D=89?= Date: Thu, 14 Apr 2022 10:10:26 +0800 Subject: [PATCH] fix(compiler-sfc): handle type modifier in import specifiers (#5498) --- .../__snapshots__/compileScript.spec.ts.snap | 16 ++++++++++++++++ .../compiler-sfc/__tests__/compileScript.spec.ts | 11 +++++++++++ packages/compiler-sfc/src/compileScript.ts | 8 ++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap index 52bda6f4..de223bf9 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap @@ -1351,6 +1351,22 @@ return { } })" `; +exports[`SFC compile ` + ) + expect(content).toMatch(`return { Baz }`) + assertCode(content) + }) }) describe('async/await detection', () => { diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 05623326..f70faeaf 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -802,7 +802,9 @@ export function compileScript( node.source.value, specifier.local.name, imported, - node.importKind === 'type', + node.importKind === 'type' || + (specifier.type === 'ImportSpecifier' && + specifier.importKind === 'type'), false ) } @@ -979,7 +981,9 @@ export function compileScript( source, local, imported, - node.importKind === 'type', + node.importKind === 'type' || + (specifier.type === 'ImportSpecifier' && + specifier.importKind === 'type'), true ) }