mirror of
https://github.com/vuejs/vue.git
synced 2024-11-21 20:28:54 +00:00
fix(compiler-sfc): Optimize the value of emitIdentifier (#12851)
This commit is contained in:
parent
099401e227
commit
bb59751dd4
@ -414,7 +414,10 @@ export function compileScript(
|
||||
}
|
||||
|
||||
if (declId) {
|
||||
emitIdentifier = scriptSetup!.content.slice(declId.start!, declId.end!)
|
||||
emitIdentifier =
|
||||
declId.type === 'Identifier'
|
||||
? declId.name
|
||||
: scriptSetup!.content.slice(declId.start!, declId.end!)
|
||||
}
|
||||
|
||||
return true
|
||||
|
@ -558,6 +558,22 @@ export default /*#__PURE__*/_defineComponent({
|
||||
|
||||
|
||||
|
||||
return { emit }
|
||||
}
|
||||
|
||||
})"
|
||||
`;
|
||||
|
||||
exports[`SFC compile <script setup> > with TypeScript > defineEmits w/ type (interface ts type) 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
interface Emits { (e: 'foo'): void }
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
emits: ['foo'],
|
||||
setup(__props, { emit }) {
|
||||
|
||||
|
||||
|
||||
return { emit }
|
||||
}
|
||||
|
||||
|
@ -1081,6 +1081,19 @@ const emit = defineEmits(['a', 'b'])
|
||||
expect(content).toMatch(`emits: ["foo", "bar"]`)
|
||||
})
|
||||
|
||||
// https://github.com/vuejs/core/issues/5393
|
||||
test('defineEmits w/ type (interface ts type)', () => {
|
||||
const { content } = compile(`
|
||||
<script setup lang="ts">
|
||||
interface Emits { (e: 'foo'): void }
|
||||
const emit: Emits = defineEmits(['foo'])
|
||||
</script>
|
||||
`)
|
||||
assertCode(content)
|
||||
expect(content).toMatch(`setup(__props, { emit }) {`)
|
||||
expect(content).toMatch(`emits: ['foo']`)
|
||||
})
|
||||
|
||||
test('runtime Enum', () => {
|
||||
const { content, bindings } = compile(
|
||||
`<script setup lang="ts">
|
||||
|
Loading…
Reference in New Issue
Block a user