Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix for issue 4187 (recursive components) (Vue 1.x) #4739

Open
wants to merge 9 commits into
base: 1.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/global-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ export default function (Vue) {
}
}
var Sub = createClass(name || 'VueComponent')
// cache constructor
if (isFirstExtend) {
extendOptions._Ctor = Sub
}
Sub.prototype = Object.create(Super.prototype)
Sub.prototype.constructor = Sub
Sub.cid = cid++
Expand All @@ -124,10 +128,6 @@ export default function (Vue) {
if (name) {
Sub.options.components[name] = Sub
}
// cache constructor
if (isFirstExtend) {
extendOptions._Ctor = Sub
}
return Sub
}

Expand Down
27 changes: 27 additions & 0 deletions test/unit/specs/global_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,32 @@ describe('Global API', function () {
expect(typeof component).toBe('function')
expect(component.options.name).toBe('Component1')
})

// GitHub issue #4187
it('convert recursive components correctly', function () {
var components = {}
components['CompB'] = {
props: ['level'],
template: '<div>B{{level}}<div v-if="level<11111"><comp-a :level="level+1"></comp-a></div></div>',
components: components
}
components['CompA'] = {
props: ['level'],
template: '<div>A{{level}}<div v-if="level<11111"><comp-b :level="level+1"></comp-b></div></div>',
components: components
}
components['App'] = {
template: '<div>Start<comp-a level="1"></comp-a></div>',
components: components
}

var app = new Vue({
components: components
})

expect(app.$options.components.App.name).toBe('VueComponent')
expect(typeof app.$options.components.CompA).toBe('function')
expect(typeof app.$options.components.CompB).toBe('function')
})
})
})