Skip to content

Commit e66a493

Browse files
committed
refactor: remove deprecated defineEmit() support
1 parent 562bddb commit e66a493

File tree

3 files changed

+7
-65
lines changed

3 files changed

+7
-65
lines changed

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

+1-32
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,6 @@ return { x }
3333
export const n = 1"
3434
`;
3535
36-
exports[`SFC compile <script setup> defineEmit() (deprecated) 1`] = `
37-
"export default {
38-
emits: ['foo', 'bar'],
39-
setup(__props, { expose, emit: myEmit }) {
40-
expose()
41-
42-
43-
44-
return { myEmit }
45-
}
46-
47-
}"
48-
`;
49-
5036
exports[`SFC compile <script setup> defineEmits() 1`] = `
5137
"export default {
5238
emits: ['foo', 'bar'],
@@ -195,7 +181,7 @@ export default {
195181
setup(__props, { expose }) {
196182
expose()
197183
198-
const foo = _ref(1)
184+
let foo = _ref(1)
199185
200186
return { foo, ref }
201187
}
@@ -324,23 +310,6 @@ return (_ctx, _cache) => {
324310
}"
325311
`;
326312
327-
exports[`SFC compile <script setup> inlineTemplate mode should not wrap render fn with withId when having scoped styles 1`] = `
328-
"import { toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock, withScopeId as _withScopeId } from \\"vue\\"
329-
330-
331-
export default {
332-
setup(__props) {
333-
334-
const msg = 1
335-
336-
return (_ctx, _cache) => {
337-
return (_openBlock(), _createElementBlock(\\"h1\\", null, _toDisplayString(msg)))
338-
}
339-
}
340-
341-
}"
342-
`;
343-
344313
exports[`SFC compile <script setup> inlineTemplate mode should work 1`] = `
345314
"import { toDisplayString as _toDisplayString, createElementVNode as _createElementVNode, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock } from \\"vue\\"
346315

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

+2-21
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,6 @@ const bar = 1
5959
props: propsModel,`)
6060
})
6161

62-
test('defineEmit() (deprecated)', () => {
63-
const { content, bindings } = compile(`
64-
<script setup>
65-
const myEmit = defineEmit(['foo', 'bar'])
66-
</script>
67-
`)
68-
assertCode(content)
69-
expect(bindings).toStrictEqual({
70-
myEmit: BindingTypes.SETUP_CONST
71-
})
72-
// should remove defineOptions import and call
73-
expect(content).not.toMatch(/defineEmits?/)
74-
// should generate correct setup signature
75-
expect(content).toMatch(`setup(__props, { expose, emit: myEmit }) {`)
76-
// should include context options in default export
77-
expect(content).toMatch(`export default {
78-
emits: ['foo', 'bar'],`)
79-
})
80-
8162
test('defineEmits()', () => {
8263
const { content, bindings } = compile(`
8364
<script setup>
@@ -204,7 +185,7 @@ defineExpose({ foo: 123 })
204185
`
205186
<script setup>
206187
import { ref } from 'vue'
207-
ref: foo = 1
188+
let foo = $ref(1)
208189
</script>
209190
`,
210191
{ refSugar: true }
@@ -848,7 +829,7 @@ const emit = defineEmits(['a', 'b'])
848829

849830
test('ref', () => {
850831
assertAwaitDetection(
851-
`ref: a = 1 + (await foo)`,
832+
`let a = $ref(1 + (await foo))`,
852833
`1 + ((([__temp,__restore]=_withAsyncContext(()=>(foo))),__temp=await __temp,__restore(),__temp))`
853834
)
854835
})

packages/compiler-sfc/src/compileScript.ts

+4-12
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import { rewriteDefault } from './rewriteDefault'
4848

4949
// Special compiler macros
5050
const DEFINE_PROPS = 'defineProps'
51-
const DEFINE_EMIT = 'defineEmit'
51+
const DEFINE_EMITS = 'defineEmits'
5252
const DEFINE_EXPOSE = 'defineExpose'
5353
const WITH_DEFAULTS = 'withDefaults'
5454

@@ -57,9 +57,6 @@ const $COMPUTED = `$computed`
5757
const $FROM_REFS = `$fromRefs`
5858
const $RAW = `$raw`
5959

60-
// deprecated
61-
const DEFINE_EMITS = 'defineEmits'
62-
6360
export interface SFCScriptCompileOptions {
6461
/**
6562
* Scope ID for prefixing injected CSS varialbes.
@@ -387,7 +384,7 @@ export function compileScript(
387384
}
388385

389386
function processDefineEmits(node: Node): boolean {
390-
if (!isCallOf(node, c => c === DEFINE_EMIT || c === DEFINE_EMITS)) {
387+
if (!isCallOf(node, DEFINE_EMITS)) {
391388
return false
392389
}
393390
if (hasDefineEmitCall) {
@@ -398,7 +395,7 @@ export function compileScript(
398395
if (node.typeParameters) {
399396
if (emitsRuntimeDecl) {
400397
error(
401-
`${DEFINE_EMIT}() cannot accept both type and non-type arguments ` +
398+
`${DEFINE_EMITS}() cannot accept both type and non-type arguments ` +
402399
`at the same time. Use one or the other.`,
403400
node
404401
)
@@ -873,7 +870,6 @@ export function compileScript(
873870
if (
874871
source === 'vue' &&
875872
(imported === DEFINE_PROPS ||
876-
imported === DEFINE_EMIT ||
877873
imported === DEFINE_EMITS ||
878874
imported === DEFINE_EXPOSE)
879875
) {
@@ -1414,11 +1410,7 @@ function walkDeclaration(
14141410
isConst &&
14151411
isCallOf(
14161412
init,
1417-
c =>
1418-
c === DEFINE_PROPS ||
1419-
c === DEFINE_EMIT ||
1420-
c === DEFINE_EMITS ||
1421-
c === WITH_DEFAULTS
1413+
c => c === DEFINE_PROPS || c === DEFINE_EMITS || c === WITH_DEFAULTS
14221414
)
14231415
)
14241416
if (id.type === 'Identifier') {

0 commit comments

Comments
 (0)