]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: remove deprecated defineEmit() support
authorEvan You <yyx990803@gmail.com>
Wed, 14 Jul 2021 19:40:09 +0000 (15:40 -0400)
committerEvan You <yyx990803@gmail.com>
Fri, 16 Jul 2021 18:30:49 +0000 (14:30 -0400)
packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap
packages/compiler-sfc/__tests__/compileScript.spec.ts
packages/compiler-sfc/src/compileScript.ts

index 785ca1d47bf3560ccdc9e87103512a9e38e7e8a1..a9a6f236778a041303a954308950c27f0507f9dc 100644 (file)
@@ -33,20 +33,6 @@ return { x }
       export const n = 1"
 `;
 
-exports[`SFC compile <script setup> defineEmit() (deprecated) 1`] = `
-"export default {
-  emits: ['foo', 'bar'],
-  setup(__props, { expose, emit: myEmit }) {
-  expose()
-
-
-
-return { myEmit }
-}
-
-}"
-`;
-
 exports[`SFC compile <script setup> defineEmits() 1`] = `
 "export default {
   emits: ['foo', 'bar'],
@@ -195,7 +181,7 @@ export default {
   setup(__props, { expose }) {
   expose()
 
-      const foo = _ref(1)
+      let foo = _ref(1)
       
 return { foo, ref }
 }
@@ -324,23 +310,6 @@ return (_ctx, _cache) => {
 }"
 `;
 
-exports[`SFC compile <script setup> inlineTemplate mode should not wrap render fn with withId when having scoped styles 1`] = `
-"import { toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock, withScopeId as _withScopeId } from \\"vue\\"
-
-
-export default {
-  setup(__props) {
-
-        const msg = 1
-        
-return (_ctx, _cache) => {
-  return (_openBlock(), _createElementBlock(\\"h1\\", null, _toDisplayString(msg)))
-}
-}
-
-}"
-`;
-
 exports[`SFC compile <script setup> inlineTemplate mode should work 1`] = `
 "import { toDisplayString as _toDisplayString, createElementVNode as _createElementVNode, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock } from \\"vue\\"
 
index 1e99fe51a25fc699be3823c4d88356373d934caf..42cb84f97fb2b6338fd47e1c4c715612c8c84791 100644 (file)
@@ -59,25 +59,6 @@ const bar = 1
   props: propsModel,`)
   })
 
-  test('defineEmit() (deprecated)', () => {
-    const { content, bindings } = compile(`
-<script setup>
-const myEmit = defineEmit(['foo', 'bar'])
-</script>
-  `)
-    assertCode(content)
-    expect(bindings).toStrictEqual({
-      myEmit: BindingTypes.SETUP_CONST
-    })
-    // should remove defineOptions import and call
-    expect(content).not.toMatch(/defineEmits?/)
-    // should generate correct setup signature
-    expect(content).toMatch(`setup(__props, { expose, emit: myEmit }) {`)
-    // should include context options in default export
-    expect(content).toMatch(`export default {
-  emits: ['foo', 'bar'],`)
-  })
-
   test('defineEmits()', () => {
     const { content, bindings } = compile(`
 <script setup>
@@ -204,7 +185,7 @@ defineExpose({ foo: 123 })
         `
       <script setup>
       import { ref } from 'vue'
-      ref: foo = 1
+      let foo = $ref(1)
       </script>
       `,
         { refSugar: true }
@@ -848,7 +829,7 @@ const emit = defineEmits(['a', 'b'])
 
     test('ref', () => {
       assertAwaitDetection(
-        `ref: a = 1 + (await foo)`,
+        `let a = $ref(1 + (await foo))`,
         `1 + ((([__temp,__restore]=_withAsyncContext(()=>(foo))),__temp=await __temp,__restore(),__temp))`
       )
     })
index 7da9334ebb374162538613a693c1728c0061f78e..05b8c8a50b07d438c6f1d77ef5f30ba191681d1a 100644 (file)
@@ -48,7 +48,7 @@ import { rewriteDefault } from './rewriteDefault'
 
 // Special compiler macros
 const DEFINE_PROPS = 'defineProps'
-const DEFINE_EMIT = 'defineEmit'
+const DEFINE_EMITS = 'defineEmits'
 const DEFINE_EXPOSE = 'defineExpose'
 const WITH_DEFAULTS = 'withDefaults'
 
@@ -57,9 +57,6 @@ const $COMPUTED = `$computed`
 const $FROM_REFS = `$fromRefs`
 const $RAW = `$raw`
 
-// deprecated
-const DEFINE_EMITS = 'defineEmits'
-
 export interface SFCScriptCompileOptions {
   /**
    * Scope ID for prefixing injected CSS varialbes.
@@ -387,7 +384,7 @@ export function compileScript(
   }
 
   function processDefineEmits(node: Node): boolean {
-    if (!isCallOf(node, c => c === DEFINE_EMIT || c === DEFINE_EMITS)) {
+    if (!isCallOf(node, DEFINE_EMITS)) {
       return false
     }
     if (hasDefineEmitCall) {
@@ -398,7 +395,7 @@ export function compileScript(
     if (node.typeParameters) {
       if (emitsRuntimeDecl) {
         error(
-          `${DEFINE_EMIT}() cannot accept both type and non-type arguments ` +
+          `${DEFINE_EMITS}() cannot accept both type and non-type arguments ` +
             `at the same time. Use one or the other.`,
           node
         )
@@ -873,7 +870,6 @@ export function compileScript(
         if (
           source === 'vue' &&
           (imported === DEFINE_PROPS ||
-            imported === DEFINE_EMIT ||
             imported === DEFINE_EMITS ||
             imported === DEFINE_EXPOSE)
         ) {
@@ -1414,11 +1410,7 @@ function walkDeclaration(
         isConst &&
         isCallOf(
           init,
-          c =>
-            c === DEFINE_PROPS ||
-            c === DEFINE_EMIT ||
-            c === DEFINE_EMITS ||
-            c === WITH_DEFAULTS
+          c => c === DEFINE_PROPS || c === DEFINE_EMITS || c === WITH_DEFAULTS
         )
       )
       if (id.type === 'Identifier') {