Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler-sfc): Check if the type modifier in the import statement #5498

Merged
merged 1 commit into from Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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 }
Expand Down
11 changes: 11 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript.spec.ts
Expand Up @@ -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', () => {
Expand Down
8 changes: 6 additions & 2 deletions packages/compiler-sfc/src/compileScript.ts
Expand Up @@ -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
)
}
Expand Down Expand Up @@ -979,7 +981,9 @@ export function compileScript(
source,
local,
imported,
node.importKind === 'type',
node.importKind === 'type' ||
zhmushan marked this conversation as resolved.
Show resolved Hide resolved
(specifier.type === 'ImportSpecifier' &&
specifier.importKind === 'type'),
true
)
}
Expand Down