fix(compiler-sfc): handle type modifier in import specifiers (#5498)

This commit is contained in:
木杉 2022-04-14 10:10:26 +08:00 committed by GitHub
parent cc238cdb8e
commit 8e29ef6019
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 2 deletions

View File

@ -1351,6 +1351,22 @@ return { }
})" })"
`; `;
exports[`SFC compile <script setup> with TypeScript import type 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
import type { Foo } from './main.ts'
import { type Bar, Baz } from './main.ts'
export default /*#__PURE__*/_defineComponent({
setup(__props, { expose }) {
expose();
return { Baz }
}
})"
`;
exports[`SFC compile <script setup> with TypeScript runtime Enum 1`] = ` exports[`SFC compile <script setup> with TypeScript runtime Enum 1`] = `
"import { defineComponent as _defineComponent } from 'vue' "import { defineComponent as _defineComponent } from 'vue'
enum Foo { A = 123 } enum Foo { A = 123 }

View File

@ -1103,6 +1103,17 @@ const emit = defineEmits(['a', 'b'])
Foo: BindingTypes.SETUP_CONST Foo: BindingTypes.SETUP_CONST
}) })
}) })
test('import type', () => {
const { content } = compile(
`<script setup lang="ts">
import type { Foo } from './main.ts'
import { type Bar, Baz } from './main.ts'
</script>`
)
expect(content).toMatch(`return { Baz }`)
assertCode(content)
})
}) })
describe('async/await detection', () => { describe('async/await detection', () => {

View File

@ -802,7 +802,9 @@ export function compileScript(
node.source.value, node.source.value,
specifier.local.name, specifier.local.name,
imported, imported,
node.importKind === 'type', node.importKind === 'type' ||
(specifier.type === 'ImportSpecifier' &&
specifier.importKind === 'type'),
false false
) )
} }
@ -979,7 +981,9 @@ export function compileScript(
source, source,
local, local,
imported, imported,
node.importKind === 'type', node.importKind === 'type' ||
(specifier.type === 'ImportSpecifier' &&
specifier.importKind === 'type'),
true true
) )
} }