]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(compiler-sfc): remove useless type generation
authorEvan You <yyx990803@gmail.com>
Tue, 11 Apr 2023 05:06:33 +0000 (13:06 +0800)
committerEvan You <yyx990803@gmail.com>
Tue, 11 Apr 2023 08:05:00 +0000 (16:05 +0800)
we are no longer type-checking generated code

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

index f6136eb1bac66f008d9c4dfb9a105ce219b4a77c..9280aee88dd9a007847cd6b4e2bacb15b1a082a7 100644 (file)
@@ -2084,11 +2084,7 @@ export default /*#__PURE__*/_defineComponent({
   setup(__props: any, { expose: __expose }) {
   __expose();
 
-const props = __props as {
-        foo?: string
-        bar?: number
-        baz: boolean
-      };
+const props = __props;
 
       
       
@@ -2112,12 +2108,7 @@ export default /*#__PURE__*/_defineComponent({
   setup(__props: any, { expose: __expose }) {
   __expose();
 
-const props = __props as {
-        foo: () => void
-        bar: boolean
-        baz: boolean | (() => void)
-        qux: string | number
-      };
+const props = __props;
 
       
       
@@ -2140,11 +2131,7 @@ export default /*#__PURE__*/_defineComponent({
   setup(__props: any, { expose: __expose }) {
   __expose();
 
-const props = __props as {
-        foo?: string
-        bar?: number
-        baz: boolean
-      };
+const props = __props;
 
       
       
@@ -2168,7 +2155,7 @@ export default /*#__PURE__*/_defineComponent({
   setup(__props: any, { expose: __expose }) {
   __expose();
 
-const props = __props as { a: string };
+const props = __props;
 
         
       
@@ -2194,7 +2181,7 @@ export default /*#__PURE__*/_defineComponent({
   setup(__props: any, { expose: __expose }) {
   __expose();
 
-const props = __props as { foo: string, bar?: number, baz: boolean, qux(): number, quux(): void, quuxx: Promise<string>, fred: string };
+const props = __props;
 
       
       
@@ -2217,7 +2204,7 @@ export default /*#__PURE__*/_defineComponent({
   setup(__props: any, { expose: __expose }) {
   __expose();
 
-const props = __props as { foo: () => void, bar: boolean, baz: boolean | (() => void), qux: string | number };
+const props = __props;
 
       
       
@@ -2239,9 +2226,7 @@ export default /*#__PURE__*/_defineComponent({
   setup(__props: any, { expose: __expose }) {
   __expose();
 
-const props = __props as {
-        foo?: () => 'string'
-      };
+const props = __props;
 
       
       
index 32c1367eb57db64fa0382604cdc0645d69498b34..3daf46a51dd801a69d91dd135cde3467c65368c9 100644 (file)
@@ -1482,9 +1482,6 @@ const emit = defineEmits(['a', 'b'])
       expect(content).toMatch(
         `fred: { type: String, required: false, get default() { return 'fred' } }`
       )
-      expect(content).toMatch(
-        `{ foo: string, bar?: number, baz: boolean, qux(): number, quux(): void, quuxx: Promise<string>, fred: string }`
-      )
       expect(content).toMatch(`const props = __props`)
       expect(bindings).toStrictEqual({
         foo: BindingTypes.PROPS,
index 5dacc84d55209c6609c2bc0e54371db2616277bc..ae2843613db9aa0b7a0cc48ca71ff5fdb67e89c1 100644 (file)
@@ -59,8 +59,7 @@ import { ScriptCompileContext } from './script/context'
 import {
   processDefineProps,
   DEFINE_PROPS,
-  WITH_DEFAULTS,
-  PropsDeclType
+  WITH_DEFAULTS
 } from './script/defineProps'
 
 // Special compiler macros
@@ -1002,52 +1001,6 @@ export function compileScript(
     }
   }
 
-  function genSetupPropsType(node: PropsDeclType) {
-    const scriptSource = node.__fromNormalScript
-      ? script!.content
-      : scriptSetup!.content
-    if (hasStaticWithDefaults()) {
-      // if withDefaults() is used, we need to remove the optional flags
-      // on props that have default values
-      let res = `{ `
-      const members = node.type === 'TSTypeLiteral' ? node.members : node.body
-      for (const m of members) {
-        if (
-          (m.type === 'TSPropertySignature' ||
-            m.type === 'TSMethodSignature') &&
-          m.typeAnnotation &&
-          m.key.type === 'Identifier'
-        ) {
-          if (
-            (ctx.propsRuntimeDefaults as ObjectExpression).properties.some(
-              p => {
-                if (p.type === 'SpreadElement') return false
-                return (
-                  resolveObjectKey(p.key, p.computed) ===
-                  (m.key as Identifier).name
-                )
-              }
-            )
-          ) {
-            res +=
-              m.key.name +
-              (m.type === 'TSMethodSignature' ? '()' : '') +
-              scriptSource.slice(
-                m.typeAnnotation.start!,
-                m.typeAnnotation.end!
-              ) +
-              ', '
-          } else {
-            res += scriptSource.slice(m.start!, m.typeAnnotation.end!) + `, `
-          }
-        }
-      }
-      return (res.length ? res.slice(0, -2) : res) + ` }`
-    } else {
-      return scriptSource.slice(node.start!, node.end!)
-    }
-  }
-
   function genRuntimeEmits() {
     function genEmitsFromTS() {
       return typeDeclaredEmits.size
@@ -1659,12 +1612,7 @@ export function compileScript(
   // we use a default __props so that template expressions referencing props
   // can use it directly
   if (ctx.propsIdentifier) {
-    s.prependLeft(
-      startOffset,
-      `\nconst ${ctx.propsIdentifier} = __props${
-        ctx.propsTypeDecl ? ` as ${genSetupPropsType(ctx.propsTypeDecl)}` : ``
-      };\n`
-    )
+    s.prependLeft(startOffset, `\nconst ${ctx.propsIdentifier} = __props;\n`)
   }
   if (ctx.propsDestructureRestId) {
     s.prependLeft(