]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): fix error when passed plugin is undefined (#502)
authorGabriel Loiácono <32134586+loiacon@users.noreply.github.com>
Wed, 27 Nov 2019 14:18:03 +0000 (11:18 -0300)
committerEvan You <yyx990803@gmail.com>
Wed, 27 Nov 2019 14:18:03 +0000 (09:18 -0500)
packages/runtime-core/__tests__/apiApp.spec.ts
packages/runtime-core/src/apiApp.ts

index 417cb772450facd872a043cdb361ce5f961be119..be76223dc35575596c22c7ccdd557d88edac5543 100644 (file)
@@ -244,6 +244,7 @@ describe('api: createApp', () => {
     const PluginB: Plugin = {
       install: app => app.provide('bar', 2)
     }
+    const PluginC: any = undefined
 
     const app = createApp()
     app.use(PluginA)
@@ -264,6 +265,12 @@ describe('api: createApp', () => {
     expect(
       `Plugin has already been applied to target app`
     ).toHaveBeenWarnedTimes(1)
+
+    app.use(PluginC)
+    expect(
+      `A plugin must either be a function or an object with an "install" ` +
+        `function.`
+    ).toHaveBeenWarnedTimes(1)
   })
 
   test('config.errorHandler', () => {
index 7b757240ea2e2b3ac7167b8c272925047b7a9af6..c526e84f580dfe60e707f13a015efee93ff268c4 100644 (file)
@@ -102,7 +102,7 @@ export function createAppAPI<HostNode, HostElement>(
         } else if (isFunction(plugin)) {
           installedPlugins.add(plugin)
           plugin(app)
-        } else if (isFunction(plugin.install)) {
+        } else if (plugin && isFunction(plugin.install)) {
           installedPlugins.add(plugin)
           plugin.install(app)
         } else if (__DEV__) {
@@ -137,15 +137,12 @@ export function createAppAPI<HostNode, HostElement>(
         }
         if (!component) {
           return context.components[name]
-        } else {
-          if (__DEV__ && context.components[name]) {
-            warn(
-              `Component "${name}" has already been registered in target app.`
-            )
-          }
-          context.components[name] = component
-          return app
         }
+        if (__DEV__ && context.components[name]) {
+          warn(`Component "${name}" has already been registered in target app.`)
+        }
+        context.components[name] = component
+        return app
       },
 
       directive(name: string, directive?: Directive) {
@@ -155,15 +152,12 @@ export function createAppAPI<HostNode, HostElement>(
 
         if (!directive) {
           return context.directives[name] as any
-        } else {
-          if (__DEV__ && context.directives[name]) {
-            warn(
-              `Directive "${name}" has already been registered in target app.`
-            )
-          }
-          context.directives[name] = directive
-          return app
         }
+        if (__DEV__ && context.directives[name]) {
+          warn(`Directive "${name}" has already been registered in target app.`)
+        }
+        context.directives[name] = directive
+        return app
       },
 
       mount(