Skip to content

Commit 2cc481b

Browse files
committed
refactor: small tweaks
1 parent 9663793 commit 2cc481b

File tree

6 files changed

+14
-21
lines changed

6 files changed

+14
-21
lines changed

packages/create-instance/add-mocks.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import $$Vue from 'vue'
33
import { warn } from 'shared/util'
44

55
export default function addMocks (
6-
Vue: Component,
6+
_Vue: Component,
77
mockedProperties: Object | false = {}
88
): void {
99
if (mockedProperties === false) {
@@ -12,7 +12,7 @@ export default function addMocks (
1212
Object.keys(mockedProperties).forEach(key => {
1313
try {
1414
// $FlowIgnore
15-
Vue.prototype[key] = mockedProperties[key]
15+
_Vue.prototype[key] = mockedProperties[key]
1616
} catch (e) {
1717
warn(
1818
`could not overwrite property ${key}, this is ` +
@@ -21,6 +21,6 @@ export default function addMocks (
2121
)
2222
}
2323
// $FlowIgnore
24-
$$Vue.util.defineReactive(Vue, key, mockedProperties[key])
24+
$$Vue.util.defineReactive(_Vue, key, mockedProperties[key])
2525
})
2626
}

packages/create-instance/create-functional-component.js

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export default function createFunctionalComponent (
2121
data.scopedSlots = createScopedSlots(mountingOptions.scopedSlots)
2222

2323
return {
24-
$_doNotStubChildren: true,
2524
render (h: Function) {
2625
return h(
2726
component,

packages/create-instance/create-instance.js

-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ export default function createInstance (
136136
Constructor,
137137
{
138138
ref: 'vm',
139-
name: 'root',
140139
on: options.listeners,
141140
attrs: {
142141
...options.attrs,

packages/create-instance/patch-render.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ export function patchRender (_Vue, stubs, stubAllComponents) {
4949
// before they are rendered in shallow mode. We also need to ensure that
5050
// component constructors were created from the _Vue constructor. If not,
5151
// we must replace them with components created from the _Vue constructor
52-
// before calling the original $createElement. This ensures that the component
53-
// will have the correct instance properties and stubs when it renders.
52+
// before calling the original $createElement. This ensures that components
53+
// have the correct instance properties and stubs when they are rendered.
5454
function patchRenderMixin () {
5555
const vm = this
5656

@@ -69,18 +69,18 @@ export function patchRender (_Vue, stubs, stubAllComponents) {
6969

7070
if (isConstructor(el)) {
7171
if (stubAllComponents) {
72-
const elem = createStubFromComponent(
72+
const stub = createStubFromComponent(
7373
el,
7474
el.name || 'anonymous'
7575
)
76-
return originalCreateElement(elem, ...args)
76+
return originalCreateElement(stub, ...args)
7777
}
7878

79-
if (shouldExtend(el, _Vue)) {
80-
return originalCreateElement(extend(el, _Vue), ...args)
81-
}
79+
const Constructor = shouldExtend(el, _Vue)
80+
? extend(el, _Vue)
81+
: el
8282

83-
return originalCreateElement(el, ...args)
83+
return originalCreateElement(Constructor, ...args)
8484
}
8585

8686
if (typeof el === 'string') {

packages/shared/util.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,9 @@ function hasOwnProperty (obj, prop) {
3939
}
4040

4141
export function resolveComponent (id: string, components: Object) {
42-
/* istanbul ignore if */
4342
if (typeof id !== 'string') {
4443
return
4544
}
46-
// var components = options['components'];
47-
4845
// check local registration variations first
4946
if (hasOwnProperty(components, id)) {
5047
return components[id]
@@ -58,7 +55,5 @@ export function resolveComponent (id: string, components: Object) {
5855
return components[PascalCaseId]
5956
}
6057
// fallback to prototype chain
61-
var res =
62-
components[id] || components[camelizedId] || components[PascalCaseId]
63-
return res
58+
return components[id] || components[camelizedId] || components[PascalCaseId]
6459
}

test/resources/utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ export const functionalSFCsSupported = vueVersion > 2.4
2929
export const scopedSlotsSupported = vueVersion > 2
3030

3131
const shallowAndMount =
32-
process.env.TEST_ENV === 'node' ? [] : [shallowMount, mount]
32+
process.env.TEST_ENV === 'node' ? [] : [mount, shallowMount]
3333
const shallowMountAndRender =
34-
process.env.TEST_ENV === 'node' ? [renderToString] : [shallowMount, mount]
34+
process.env.TEST_ENV === 'node' ? [renderToString] : [mount, shallowMount]
3535

3636
export function describeWithShallowAndMount (spec, cb) {
3737
if (shallowAndMount.length > 0) {

0 commit comments

Comments
 (0)