mirror of https://github.com/vuejs/core.git
refactor(compiler-sfc): remove unnecessary emits type codegen
This is no longer necessary as we no longer recommend type checking generated code
This commit is contained in:
parent
ef73ea53ea
commit
f5971468e5
|
@ -1388,7 +1388,7 @@ export interface Emits { (e: 'foo' | 'bar'): void }
|
||||||
|
|
||||||
export default /*#__PURE__*/_defineComponent({
|
export default /*#__PURE__*/_defineComponent({
|
||||||
emits: [\\"foo\\", \\"bar\\"],
|
emits: [\\"foo\\", \\"bar\\"],
|
||||||
setup(__props, { expose: __expose, emit }: { emit: ({ (e: 'foo' | 'bar'): void }), expose: any, slots: any, attrs: any }) {
|
setup(__props, { expose: __expose, emit }) {
|
||||||
__expose();
|
__expose();
|
||||||
|
|
||||||
|
|
||||||
|
@ -1405,7 +1405,7 @@ export type Emits = { (e: 'foo' | 'bar'): void }
|
||||||
|
|
||||||
export default /*#__PURE__*/_defineComponent({
|
export default /*#__PURE__*/_defineComponent({
|
||||||
emits: [\\"foo\\", \\"bar\\"],
|
emits: [\\"foo\\", \\"bar\\"],
|
||||||
setup(__props, { expose: __expose, emit }: { emit: ({ (e: 'foo' | 'bar'): void }), expose: any, slots: any, attrs: any }) {
|
setup(__props, { expose: __expose, emit }) {
|
||||||
__expose();
|
__expose();
|
||||||
|
|
||||||
|
|
||||||
|
@ -1439,7 +1439,23 @@ interface Emits { (e: 'foo' | 'bar'): void }
|
||||||
|
|
||||||
export default /*#__PURE__*/_defineComponent({
|
export default /*#__PURE__*/_defineComponent({
|
||||||
emits: [\\"foo\\", \\"bar\\"],
|
emits: [\\"foo\\", \\"bar\\"],
|
||||||
setup(__props, { expose: __expose, emit }: { emit: ({ (e: 'foo' | 'bar'): void }), expose: any, slots: any, attrs: any }) {
|
setup(__props, { expose: __expose, emit }) {
|
||||||
|
__expose();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return { emit }
|
||||||
|
}
|
||||||
|
|
||||||
|
})"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`SFC compile <script setup> > with TypeScript > defineEmits w/ type (property syntax) 1`] = `
|
||||||
|
"import { defineComponent as _defineComponent } from 'vue'
|
||||||
|
|
||||||
|
export default /*#__PURE__*/_defineComponent({
|
||||||
|
emits: [\\"foo\\", \\"bar\\"],
|
||||||
|
setup(__props, { expose: __expose, emit }) {
|
||||||
__expose();
|
__expose();
|
||||||
|
|
||||||
|
|
||||||
|
@ -1456,7 +1472,7 @@ export type Emits = (e: 'foo' | 'bar') => void
|
||||||
|
|
||||||
export default /*#__PURE__*/_defineComponent({
|
export default /*#__PURE__*/_defineComponent({
|
||||||
emits: [\\"foo\\", \\"bar\\"],
|
emits: [\\"foo\\", \\"bar\\"],
|
||||||
setup(__props, { expose: __expose, emit }: { emit: ((e: 'foo' | 'bar') => void), expose: any, slots: any, attrs: any }) {
|
setup(__props, { expose: __expose, emit }) {
|
||||||
__expose();
|
__expose();
|
||||||
|
|
||||||
|
|
||||||
|
@ -1473,23 +1489,7 @@ type Emits = (e: 'foo' | 'bar') => void
|
||||||
|
|
||||||
export default /*#__PURE__*/_defineComponent({
|
export default /*#__PURE__*/_defineComponent({
|
||||||
emits: [\\"foo\\", \\"bar\\"],
|
emits: [\\"foo\\", \\"bar\\"],
|
||||||
setup(__props, { expose: __expose, emit }: { emit: ((e: 'foo' | 'bar') => void), expose: any, slots: any, attrs: any }) {
|
setup(__props, { expose: __expose, emit }) {
|
||||||
__expose();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return { emit }
|
|
||||||
}
|
|
||||||
|
|
||||||
})"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`SFC compile <script setup> > with TypeScript > defineEmits w/ type (tuple syntax) 1`] = `
|
|
||||||
"import { defineComponent as _defineComponent } from 'vue'
|
|
||||||
|
|
||||||
export default /*#__PURE__*/_defineComponent({
|
|
||||||
emits: [\\"foo\\", \\"bar\\"],
|
|
||||||
setup(__props, { expose: __expose, emit }: { emit: ({ foo: [], bar: [] }), expose: any, slots: any, attrs: any }) {
|
|
||||||
__expose();
|
__expose();
|
||||||
|
|
||||||
|
|
||||||
|
@ -1506,7 +1506,7 @@ type Emits = { (e: 'foo' | 'bar'): void }
|
||||||
|
|
||||||
export default /*#__PURE__*/_defineComponent({
|
export default /*#__PURE__*/_defineComponent({
|
||||||
emits: [\\"foo\\", \\"bar\\"],
|
emits: [\\"foo\\", \\"bar\\"],
|
||||||
setup(__props, { expose: __expose, emit }: { emit: ({ (e: 'foo' | 'bar'): void }), expose: any, slots: any, attrs: any }) {
|
setup(__props, { expose: __expose, emit }) {
|
||||||
__expose();
|
__expose();
|
||||||
|
|
||||||
|
|
||||||
|
@ -1522,7 +1522,7 @@ exports[`SFC compile <script setup> > with TypeScript > defineEmits w/ type (typ
|
||||||
|
|
||||||
export default /*#__PURE__*/_defineComponent({
|
export default /*#__PURE__*/_defineComponent({
|
||||||
emits: [\\"foo\\", \\"bar\\", \\"baz\\"],
|
emits: [\\"foo\\", \\"bar\\", \\"baz\\"],
|
||||||
setup(__props, { expose: __expose, emit }: { emit: ({(e: 'foo' | 'bar'): void; (e: 'baz', id: number): void;}), expose: any, slots: any, attrs: any }) {
|
setup(__props, { expose: __expose, emit }) {
|
||||||
__expose();
|
__expose();
|
||||||
|
|
||||||
|
|
||||||
|
@ -1538,7 +1538,7 @@ exports[`SFC compile <script setup> > with TypeScript > defineEmits w/ type 1`]
|
||||||
|
|
||||||
export default /*#__PURE__*/_defineComponent({
|
export default /*#__PURE__*/_defineComponent({
|
||||||
emits: [\\"foo\\", \\"bar\\"],
|
emits: [\\"foo\\", \\"bar\\"],
|
||||||
setup(__props, { expose: __expose, emit }: { emit: ((e: 'foo' | 'bar') => void), expose: any, slots: any, attrs: any }) {
|
setup(__props, { expose: __expose, emit }) {
|
||||||
__expose();
|
__expose();
|
||||||
|
|
||||||
|
|
||||||
|
@ -1556,7 +1556,7 @@ exports[`SFC compile <script setup> > with TypeScript > defineEmits w/ type from
|
||||||
|
|
||||||
export default /*#__PURE__*/_defineComponent({
|
export default /*#__PURE__*/_defineComponent({
|
||||||
emits: [\\"foo\\", \\"bar\\"],
|
emits: [\\"foo\\", \\"bar\\"],
|
||||||
setup(__props, { expose: __expose, emit }: { emit: ({ (e: 'foo' | 'bar'): void }), expose: any, slots: any, attrs: any }) {
|
setup(__props, { expose: __expose, emit }) {
|
||||||
__expose();
|
__expose();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1414,7 +1414,6 @@ const emit = defineEmits(['a', 'b'])
|
||||||
</script>
|
</script>
|
||||||
`)
|
`)
|
||||||
assertCode(content)
|
assertCode(content)
|
||||||
expect(content).toMatch(`emit: ((e: 'foo' | 'bar') => void),`)
|
|
||||||
expect(content).toMatch(`emits: ["foo", "bar"]`)
|
expect(content).toMatch(`emits: ["foo", "bar"]`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1437,7 +1436,6 @@ const emit = defineEmits(['a', 'b'])
|
||||||
</script>
|
</script>
|
||||||
`)
|
`)
|
||||||
assertCode(content)
|
assertCode(content)
|
||||||
expect(content).toMatch(`emit: (${type}),`)
|
|
||||||
expect(content).toMatch(`emits: ["foo", "bar", "baz"]`)
|
expect(content).toMatch(`emits: ["foo", "bar", "baz"]`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1449,7 +1447,6 @@ const emit = defineEmits(['a', 'b'])
|
||||||
</script>
|
</script>
|
||||||
`)
|
`)
|
||||||
assertCode(content)
|
assertCode(content)
|
||||||
expect(content).toMatch(`emit: ({ (e: 'foo' | 'bar'): void }),`)
|
|
||||||
expect(content).toMatch(`emits: ["foo", "bar"]`)
|
expect(content).toMatch(`emits: ["foo", "bar"]`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1461,7 +1458,6 @@ const emit = defineEmits(['a', 'b'])
|
||||||
</script>
|
</script>
|
||||||
`)
|
`)
|
||||||
assertCode(content)
|
assertCode(content)
|
||||||
expect(content).toMatch(`emit: ({ (e: 'foo' | 'bar'): void }),`)
|
|
||||||
expect(content).toMatch(`emits: ["foo", "bar"]`)
|
expect(content).toMatch(`emits: ["foo", "bar"]`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1475,7 +1471,6 @@ const emit = defineEmits(['a', 'b'])
|
||||||
</script>
|
</script>
|
||||||
`)
|
`)
|
||||||
assertCode(content)
|
assertCode(content)
|
||||||
expect(content).toMatch(`emit: ({ (e: 'foo' | 'bar'): void }),`)
|
|
||||||
expect(content).toMatch(`emits: ["foo", "bar"]`)
|
expect(content).toMatch(`emits: ["foo", "bar"]`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1487,7 +1482,6 @@ const emit = defineEmits(['a', 'b'])
|
||||||
</script>
|
</script>
|
||||||
`)
|
`)
|
||||||
assertCode(content)
|
assertCode(content)
|
||||||
expect(content).toMatch(`emit: ({ (e: 'foo' | 'bar'): void }),`)
|
|
||||||
expect(content).toMatch(`emits: ["foo", "bar"]`)
|
expect(content).toMatch(`emits: ["foo", "bar"]`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1499,7 +1493,6 @@ const emit = defineEmits(['a', 'b'])
|
||||||
</script>
|
</script>
|
||||||
`)
|
`)
|
||||||
assertCode(content)
|
assertCode(content)
|
||||||
expect(content).toMatch(`emit: ({ (e: 'foo' | 'bar'): void }),`)
|
|
||||||
expect(content).toMatch(`emits: ["foo", "bar"]`)
|
expect(content).toMatch(`emits: ["foo", "bar"]`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1511,7 +1504,6 @@ const emit = defineEmits(['a', 'b'])
|
||||||
</script>
|
</script>
|
||||||
`)
|
`)
|
||||||
assertCode(content)
|
assertCode(content)
|
||||||
expect(content).toMatch(`emit: ((e: 'foo' | 'bar') => void),`)
|
|
||||||
expect(content).toMatch(`emits: ["foo", "bar"]`)
|
expect(content).toMatch(`emits: ["foo", "bar"]`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1523,7 +1515,6 @@ const emit = defineEmits(['a', 'b'])
|
||||||
</script>
|
</script>
|
||||||
`)
|
`)
|
||||||
assertCode(content)
|
assertCode(content)
|
||||||
expect(content).toMatch(`emit: ((e: 'foo' | 'bar') => void),`)
|
|
||||||
expect(content).toMatch(`emits: ["foo", "bar"]`)
|
expect(content).toMatch(`emits: ["foo", "bar"]`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1536,11 +1527,10 @@ const emit = defineEmits(['a', 'b'])
|
||||||
</script>
|
</script>
|
||||||
`)
|
`)
|
||||||
assertCode(content)
|
assertCode(content)
|
||||||
expect(content).toMatch(`setup(__props, { expose: __expose, emit }) {`)
|
|
||||||
expect(content).toMatch(`emits: ['foo']`)
|
expect(content).toMatch(`emits: ['foo']`)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('defineEmits w/ type (tuple syntax)', () => {
|
test('defineEmits w/ type (property syntax)', () => {
|
||||||
const { content } = compile(`
|
const { content } = compile(`
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const emit = defineEmits<{ foo: [], bar: [] }>()
|
const emit = defineEmits<{ foo: [], bar: [] }>()
|
||||||
|
@ -1882,7 +1872,7 @@ const emit = defineEmits(['a', 'b'])
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('mixed usage of tuple / call signature in defineEmits', () => {
|
test('mixed usage of property / call signature in defineEmits', () => {
|
||||||
expect(() =>
|
expect(() =>
|
||||||
compile(`<script setup lang="ts">
|
compile(`<script setup lang="ts">
|
||||||
defineEmits<{
|
defineEmits<{
|
||||||
|
|
|
@ -322,7 +322,6 @@ export function compileScript(
|
||||||
let propsIdentifier: string | undefined
|
let propsIdentifier: string | undefined
|
||||||
let emitsRuntimeDecl: Node | undefined
|
let emitsRuntimeDecl: Node | undefined
|
||||||
let emitsTypeDecl: EmitsDeclType | undefined
|
let emitsTypeDecl: EmitsDeclType | undefined
|
||||||
let emitsTypeDeclRaw: Node | undefined
|
|
||||||
let emitIdentifier: string | undefined
|
let emitIdentifier: string | undefined
|
||||||
let optionsRuntimeDecl: Node | undefined
|
let optionsRuntimeDecl: Node | undefined
|
||||||
let hasAwait = false
|
let hasAwait = false
|
||||||
|
@ -582,7 +581,7 @@ export function compileScript(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
emitsTypeDeclRaw = node.typeParameters.params[0]
|
const emitsTypeDeclRaw = node.typeParameters.params[0]
|
||||||
emitsTypeDecl = resolveQualifiedType(
|
emitsTypeDecl = resolveQualifiedType(
|
||||||
emitsTypeDeclRaw,
|
emitsTypeDeclRaw,
|
||||||
node => node.type === 'TSFunctionType' || node.type === 'TSTypeLiteral'
|
node => node.type === 'TSFunctionType' || node.type === 'TSTypeLiteral'
|
||||||
|
@ -1623,15 +1622,6 @@ export function compileScript(
|
||||||
}
|
}
|
||||||
if (destructureElements.length) {
|
if (destructureElements.length) {
|
||||||
args += `, { ${destructureElements.join(', ')} }`
|
args += `, { ${destructureElements.join(', ')} }`
|
||||||
if (emitsTypeDecl) {
|
|
||||||
const content = emitsTypeDecl.__fromNormalScript
|
|
||||||
? script!.content
|
|
||||||
: scriptSetup.content
|
|
||||||
args += `: { emit: (${content.slice(
|
|
||||||
emitsTypeDecl.start!,
|
|
||||||
emitsTypeDecl.end!
|
|
||||||
)}), expose: any, slots: any, attrs: any }`
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 10. generate return statement
|
// 10. generate return statement
|
||||||
|
|
Loading…
Reference in New Issue