Skip to content
Permalink
Browse files
fix(compiler-sfc): handle type modifier in import specifiers (#5498)
  • Loading branch information
zhmushan committed Apr 14, 2022
1 parent cc238cd commit 8e29ef6019d1b9d9c8f67b4ebba0223b8e0f914c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
@@ -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`] = `
"import { defineComponent as _defineComponent } from 'vue'
enum Foo { A = 123 }
@@ -1103,6 +1103,17 @@ const emit = defineEmits(['a', 'b'])
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', () => {
@@ -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
)
}

0 comments on commit 8e29ef6

Please sign in to comment.