]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): support extends template for runtime compiler (#6250)
authoredison <daiwei521@126.com>
Wed, 31 Aug 2022 05:44:21 +0000 (13:44 +0800)
committerGitHub <noreply@github.com>
Wed, 31 Aug 2022 05:44:21 +0000 (01:44 -0400)
fix #6249

packages/runtime-core/__tests__/apiOptions.spec.ts
packages/runtime-core/src/component.ts

index 18207f61dc37a75b668acad0adaac5e3aa3f460e..da5fe346c32a3acc196325cf6893908922d551eb 100644 (file)
@@ -12,6 +12,7 @@ import {
   createApp,
   computed
 } from '@vue/runtime-test'
+import { render as domRender } from 'vue'
 
 describe('api: options', () => {
   test('data', async () => {
@@ -1035,6 +1036,19 @@ describe('api: options', () => {
     expect(renderToString(h(Comp))).toBe('base,base')
   })
 
+  test('extends template', () => {
+    const Comp = {
+      extends: {
+        template: `<h1>Foo</h1>`
+      }
+    }
+
+    const root = document.createElement('div') as any
+    domRender(h(Comp), root)
+    expect(root.innerHTML).toBe(`<h1>Foo</h1>`)
+  })
+
+
   test('options defined in component have higher priority', async () => {
     const Mixin = {
       msg1: 'base'
index eb933bb70fe3863bdeb9baa8aaf0d2f0e3ce1a2f..c70a6f87411e350fdb81cdd39550abf526a563fb 100644 (file)
@@ -35,7 +35,8 @@ import {
   applyOptions,
   ComponentOptions,
   ComputedOptions,
-  MethodOptions
+  MethodOptions,
+  resolveMergedOptions
 } from './componentOptions'
 import {
   EmitsOptions,
@@ -792,7 +793,8 @@ export function finishComponentSetup(
         (__COMPAT__ &&
           instance.vnode.props &&
           instance.vnode.props['inline-template']) ||
-        Component.template
+        Component.template ||
+        resolveMergedOptions(instance).template
       if (template) {
         if (__DEV__) {
           startMeasure(instance, `compile`)