fix(runtime-core): fix error when passed plugin is undefined (#502)
This commit is contained in:
parent
cfa7efe4e8
commit
fbcc47841b
@ -244,6 +244,7 @@ describe('api: createApp', () => {
|
|||||||
const PluginB: Plugin = {
|
const PluginB: Plugin = {
|
||||||
install: app => app.provide('bar', 2)
|
install: app => app.provide('bar', 2)
|
||||||
}
|
}
|
||||||
|
const PluginC: any = undefined
|
||||||
|
|
||||||
const app = createApp()
|
const app = createApp()
|
||||||
app.use(PluginA)
|
app.use(PluginA)
|
||||||
@ -264,6 +265,12 @@ describe('api: createApp', () => {
|
|||||||
expect(
|
expect(
|
||||||
`Plugin has already been applied to target app`
|
`Plugin has already been applied to target app`
|
||||||
).toHaveBeenWarnedTimes(1)
|
).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', () => {
|
test('config.errorHandler', () => {
|
||||||
|
@ -102,7 +102,7 @@ export function createAppAPI<HostNode, HostElement>(
|
|||||||
} else if (isFunction(plugin)) {
|
} else if (isFunction(plugin)) {
|
||||||
installedPlugins.add(plugin)
|
installedPlugins.add(plugin)
|
||||||
plugin(app)
|
plugin(app)
|
||||||
} else if (isFunction(plugin.install)) {
|
} else if (plugin && isFunction(plugin.install)) {
|
||||||
installedPlugins.add(plugin)
|
installedPlugins.add(plugin)
|
||||||
plugin.install(app)
|
plugin.install(app)
|
||||||
} else if (__DEV__) {
|
} else if (__DEV__) {
|
||||||
@ -137,15 +137,12 @@ export function createAppAPI<HostNode, HostElement>(
|
|||||||
}
|
}
|
||||||
if (!component) {
|
if (!component) {
|
||||||
return context.components[name]
|
return context.components[name]
|
||||||
} else {
|
}
|
||||||
if (__DEV__ && context.components[name]) {
|
if (__DEV__ && context.components[name]) {
|
||||||
warn(
|
warn(`Component "${name}" has already been registered in target app.`)
|
||||||
`Component "${name}" has already been registered in target app.`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
context.components[name] = component
|
context.components[name] = component
|
||||||
return app
|
return app
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
directive(name: string, directive?: Directive) {
|
directive(name: string, directive?: Directive) {
|
||||||
@ -155,15 +152,12 @@ export function createAppAPI<HostNode, HostElement>(
|
|||||||
|
|
||||||
if (!directive) {
|
if (!directive) {
|
||||||
return context.directives[name] as any
|
return context.directives[name] as any
|
||||||
} else {
|
}
|
||||||
if (__DEV__ && context.directives[name]) {
|
if (__DEV__ && context.directives[name]) {
|
||||||
warn(
|
warn(`Directive "${name}" has already been registered in target app.`)
|
||||||
`Directive "${name}" has already been registered in target app.`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
context.directives[name] = directive
|
context.directives[name] = directive
|
||||||
return app
|
return app
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
mount(
|
mount(
|
||||||
|
Loading…
Reference in New Issue
Block a user