fix(compiler-sfc): fix template usage check false positives on types

fix #5414
This commit is contained in:
Evan You
2022-05-12 18:23:10 +08:00
parent ba17792b72
commit ccf92564d3
3 changed files with 71 additions and 8 deletions

View File

@@ -535,6 +535,23 @@ return { props, a, emit }
}"
`;
exports[`SFC compile <script setup> dev mode import usage check TS annotations 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
import { Foo, Bar, Baz } from './x'
export default /*#__PURE__*/_defineComponent({
setup(__props, { expose }) {
expose();
const a = 1
function b() {}
return { a, b, Baz }
}
})"
`;
exports[`SFC compile <script setup> dev mode import usage check attribute expressions 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
import { bar, baz } from './x'

View File

@@ -432,6 +432,23 @@ defineExpose({ foo: 123 })
expect(content).toMatch(`return { FooBaz, Last }`)
assertCode(content)
})
test('TS annotations', () => {
const { content } = compile(`
<script setup lang="ts">
import { Foo, Bar, Baz } from './x'
const a = 1
function b() {}
</script>
<template>
{{ a as Foo }}
{{ b<Bar>() }}
{{ Baz }}
</template>
`)
expect(content).toMatch(`return { a, b, Baz }`)
assertCode(content)
})
})
describe('inlineTemplate mode', () => {