Skip to content

Commit 8e29ef6

Browse files
authored
fix(compiler-sfc): handle type modifier in import specifiers (#5498)
1 parent cc238cd commit 8e29ef6

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap

+16
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,22 @@ return { }
13511351
})"
13521352
`;
13531353

1354+
exports[`SFC compile <script setup> with TypeScript import type 1`] = `
1355+
"import { defineComponent as _defineComponent } from 'vue'
1356+
import type { Foo } from './main.ts'
1357+
import { type Bar, Baz } from './main.ts'
1358+
1359+
export default /*#__PURE__*/_defineComponent({
1360+
setup(__props, { expose }) {
1361+
expose();
1362+
1363+
1364+
return { Baz }
1365+
}
1366+
1367+
})"
1368+
`;
1369+
13541370
exports[`SFC compile <script setup> with TypeScript runtime Enum 1`] = `
13551371
"import { defineComponent as _defineComponent } from 'vue'
13561372
enum Foo { A = 123 }

packages/compiler-sfc/__tests__/compileScript.spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,17 @@ const emit = defineEmits(['a', 'b'])
11031103
Foo: BindingTypes.SETUP_CONST
11041104
})
11051105
})
1106+
1107+
test('import type', () => {
1108+
const { content } = compile(
1109+
`<script setup lang="ts">
1110+
import type { Foo } from './main.ts'
1111+
import { type Bar, Baz } from './main.ts'
1112+
</script>`
1113+
)
1114+
expect(content).toMatch(`return { Baz }`)
1115+
assertCode(content)
1116+
})
11061117
})
11071118

11081119
describe('async/await detection', () => {

packages/compiler-sfc/src/compileScript.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,9 @@ export function compileScript(
802802
node.source.value,
803803
specifier.local.name,
804804
imported,
805-
node.importKind === 'type',
805+
node.importKind === 'type' ||
806+
(specifier.type === 'ImportSpecifier' &&
807+
specifier.importKind === 'type'),
806808
false
807809
)
808810
}
@@ -979,7 +981,9 @@ export function compileScript(
979981
source,
980982
local,
981983
imported,
982-
node.importKind === 'type',
984+
node.importKind === 'type' ||
985+
(specifier.type === 'ImportSpecifier' &&
986+
specifier.importKind === 'type'),
983987
true
984988
)
985989
}

0 commit comments

Comments
 (0)