]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core/inject): handle optional `from` option in inject object config ...
authorStanislav Lashmanov <stasvarenkin@gmail.com>
Mon, 14 Sep 2020 16:52:19 +0000 (19:52 +0300)
committerGitHub <noreply@github.com>
Mon, 14 Sep 2020 16:52:19 +0000 (12:52 -0400)
packages/runtime-core/__tests__/apiOptions.spec.ts
packages/runtime-core/src/componentOptions.ts

index 4dd1910bfa15faaf89f9afa59cd817f442e67e6f..00ecb6e4c4c7ae38dbb52003550f5350d0fb1134 100644 (file)
@@ -253,7 +253,16 @@ describe('api: options', () => {
         }
       },
       render() {
-        return [h(ChildA), h(ChildB), h(ChildC), h(ChildD), h(ChildE)]
+        return [
+          h(ChildA),
+          h(ChildB),
+          h(ChildC),
+          h(ChildD),
+          h(ChildE),
+          h(ChildF),
+          h(ChildG),
+          h(ChildH)
+        ]
       }
     })
 
@@ -272,19 +281,37 @@ describe('api: options', () => {
         from: 'a'
       }
     })
-    const ChildD = defineChild({
+    const ChildD = defineChild(
+      {
+        a: {
+          default: () => 0
+        }
+      },
+      'a'
+    )
+    const ChildE = defineChild({
       b: {
         from: 'c',
         default: 2
       }
     })
-    const ChildE = defineChild({
+    const ChildF = defineChild({
       b: {
         from: 'c',
         default: () => 3
       }
     })
-    expect(renderToString(h(Root))).toBe(`11123`)
+    const ChildG = defineChild({
+      b: {
+        default: 4
+      }
+    })
+    const ChildH = defineChild({
+      b: {
+        default: () => 5
+      }
+    })
+    expect(renderToString(h(Root))).toBe(`11112345`)
   })
 
   test('lifecycle', async () => {
index d02a1bb0bdc6ffb3e3c559cbc15e10781b617410..672cb8af92a85d90097c1faad98b28b1040ee33e 100644 (file)
@@ -275,7 +275,7 @@ type ComponentInjectOptions =
   | string[]
   | Record<
       string | symbol,
-      string | symbol | { from: string | symbol; default?: unknown }
+      string | symbol | { from?: string | symbol; default?: unknown }
     >
 
 interface LegacyOptions<
@@ -460,7 +460,7 @@ export function applyOptions(
         const opt = injectOptions[key]
         if (isObject(opt)) {
           ctx[key] = inject(
-            opt.from,
+            opt.from || key,
             opt.default,
             true /* treat default function as factory */
           )