Skip to content

Commit 228f0f8

Browse files
committed
remove unnecessary :any castings due to improved flow checks
1 parent 3b426ef commit 228f0f8

File tree

14 files changed

+36
-33
lines changed

14 files changed

+36
-33
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"eslint-plugin-jasmine": "^2.1.0",
7878
"eslint-plugin-vue": "^2.0.0",
7979
"file-loader": "^0.10.1",
80-
"flow-bin": "^0.39.0",
80+
"flow-bin": "^0.45.0",
8181
"hash-sum": "^1.0.2",
8282
"he": "^1.1.0",
8383
"http-server": "^0.9.0",

src/core/instance/render.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
warn,
55
nextTick,
66
toNumber,
7-
_toString,
7+
toString,
88
looseEqual,
99
emptyObject,
1010
handleError,
@@ -109,7 +109,7 @@ export function renderMixin (Vue: Class<Component>) {
109109
// code size.
110110
Vue.prototype._o = markOnce
111111
Vue.prototype._n = toNumber
112-
Vue.prototype._s = _toString
112+
Vue.prototype._s = toString
113113
Vue.prototype._l = renderList
114114
Vue.prototype._t = renderSlot
115115
Vue.prototype._q = looseEqual

src/core/vdom/create-component.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const componentVNodeHooks = {
9696
const hooksToMerge = Object.keys(componentVNodeHooks)
9797

9898
export function createComponent (
99-
Ctor: any,
99+
Ctor: Class<Component> | Function | Object | void,
100100
data?: VNodeData,
101101
context: Component,
102102
children: ?Array<VNode>,

src/core/vdom/create-element.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function applyNS (vnode, ns) {
113113
// use default namespace inside foreignObject
114114
return
115115
}
116-
if (Array.isArray(vnode.children)) {
116+
if (isDef(vnode.children)) {
117117
for (let i = 0, l = vnode.children.length; i < l; i++) {
118118
const child = vnode.children[i]
119119
if (isDef(child.tag) && isUndef(child.ns)) {

src/core/vdom/create-functional-component.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ export function createFunctionalComponent (
2121
const props = {}
2222
const propOptions = Ctor.options.props
2323
if (isDef(propOptions)) {
24-
propsData = propsData || {}
2524
for (const key in propOptions) {
26-
props[key] = validateProp(key, propOptions, propsData)
25+
props[key] = validateProp(key, propOptions, propsData || {})
2726
}
2827
} else {
2928
if (isDef(data.attrs)) mergeProps(props, data.attrs)

src/core/vdom/helpers/extract-props.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function extractPropsFromVNodeData (
5151

5252
function checkProp (
5353
res: Object,
54-
hash: any,
54+
hash: ?Object,
5555
key: string,
5656
altKey: string,
5757
preserve: boolean

src/core/vdom/helpers/normalize-children.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function normalizeArrayChildren (children: any, nestedIndex?: string): Array<VNo
4848
res.push.apply(res, normalizeArrayChildren(c, `${nestedIndex || ''}_${i}`))
4949
} else if (isPrimitive(c)) {
5050
if (isDef(last) && isDef(last.text)) {
51-
(last: any).text += String(c)
51+
last.text += String(c)
5252
} else if (c !== '') {
5353
// convert primitive to vnode
5454
res.push(createTextVNode(c))
@@ -59,7 +59,7 @@ function normalizeArrayChildren (children: any, nestedIndex?: string): Array<VNo
5959
} else {
6060
// default key for nested array children (likely generated by v-for)
6161
if (isDef(c.tag) && isUndef(c.key) && isDef(nestedIndex)) {
62-
c.key = `__vlist${(nestedIndex: any)}_${i}__`
62+
c.key = `__vlist${nestedIndex}_${i}__`
6363
}
6464
res.push(c)
6565
}

src/platforms/web/runtime/modules/dom-props.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
3535
// non-string values will be stringified
3636
elm._value = cur
3737
// avoid resetting cursor position when value is the same
38-
const strCur = cur == null ? '' : String(cur)
38+
const strCur = isUndef(cur) ? '' : String(cur)
3939
if (shouldUpdateValue(elm, vnode, strCur)) {
4040
elm.value = strCur
4141
}

src/platforms/web/runtime/modules/transition.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function enter (vnode: VNodeWithData, toggleDisplay: ?() => void) {
5757
afterAppear,
5858
appearCancelled,
5959
duration
60-
} = (data: any)
60+
} = data
6161

6262
// activeInstance will always be the <transition> component managing this
6363
// transition. One edge case to check is when the <transition> is placed
@@ -201,7 +201,7 @@ export function leave (vnode: VNodeWithData, rm: Function) {
201201
leaveCancelled,
202202
delayLeave,
203203
duration
204-
} = (data: any)
204+
} = data
205205

206206
const expectsCSS = css !== false && !isIE9
207207
const userWantsControl = getHookArgumentsLength(leave)
@@ -212,7 +212,7 @@ export function leave (vnode: VNodeWithData, rm: Function) {
212212
: duration
213213
)
214214

215-
if (process.env.NODE_ENV !== 'production' && explicitLeaveDuration != null) {
215+
if (process.env.NODE_ENV !== 'production' && isDef(explicitLeaveDuration)) {
216216
checkDuration(explicitLeaveDuration, 'leave', vnode)
217217
}
218218

@@ -249,7 +249,7 @@ export function leave (vnode: VNodeWithData, rm: Function) {
249249
}
250250
// record leaving element
251251
if (!vnode.data.show) {
252-
(el.parentNode._pending || (el.parentNode._pending = {}))[vnode.key] = vnode
252+
(el.parentNode._pending || (el.parentNode._pending = {}))[(vnode.key: any)] = vnode
253253
}
254254
beforeLeave && beforeLeave(el)
255255
if (expectsCSS) {

src/platforms/web/server/modules/attrs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default function renderAttrs (node: VNodeWithData): string {
1717
let attrs = node.data.attrs
1818
let res = ''
1919

20-
let parent: any = node.parent
20+
let parent = node.parent
2121
while (isDef(parent)) {
2222
if (isDef(parent.data) && isDef(parent.data.attrs)) {
2323
attrs = Object.assign({}, attrs, parent.data.attrs)

src/platforms/web/server/modules/dom-props.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default function renderDOMProps (node: VNodeWithData): string {
99
let props = node.data.domProps
1010
let res = ''
1111

12-
let parent: any = node.parent
12+
let parent = node.parent
1313
while (isDef(parent)) {
1414
if (parent.data && parent.data.domProps) {
1515
props = Object.assign({}, props, parent.data.domProps)
@@ -21,7 +21,7 @@ export default function renderDOMProps (node: VNodeWithData): string {
2121
return res
2222
}
2323

24-
const attrs: any = node.data.attrs
24+
const attrs = node.data.attrs
2525
for (const key in props) {
2626
if (key === 'innerHTML') {
2727
setText(node, props[key], true)

src/server/render.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ function renderComponent (node, isRoot, context) {
7777
const key = name + '::' + getKey(node.componentOptions.propsData)
7878
const { has, get } = context
7979
if (isDef(has)) {
80-
(has: any)(key, hit => {
80+
has(key, hit => {
8181
if (hit === true && isDef(get)) {
82-
(get: any)(key, res => {
82+
get(key, res => {
8383
if (isDef(registerComponent)) {
8484
registerComponent(userContext)
8585
}
@@ -91,7 +91,7 @@ function renderComponent (node, isRoot, context) {
9191
}
9292
})
9393
} else if (isDef(get)) {
94-
(get: any)(key, res => {
94+
get(key, res => {
9595
if (isDef(res)) {
9696
if (isDef(registerComponent)) {
9797
registerComponent(userContext)

src/shared/util.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22

33
// these helpers produces better vm code in JS engines due to their
44
// explicitness and function inlining
5-
export function isUndef (v: any): boolean {
5+
export function isUndef (v: any): boolean %checks {
66
return v === undefined || v === null
77
}
88

9-
export function isDef (v: any) /* : %checks */ {
9+
export function isDef (v: any): boolean %checks {
1010
return v !== undefined && v !== null
1111
}
1212

13-
export function isTrue (v: any): boolean {
13+
export function isTrue (v: any): boolean %checks {
1414
return v === true
1515
}
1616

1717
/**
1818
* Check if value is primitive
1919
*/
20-
export function isPrimitive (value: any): boolean {
20+
export function isPrimitive (value: any): boolean %checks {
2121
return typeof value === 'string' || typeof value === 'number'
2222
}
2323

@@ -26,28 +26,28 @@ export function isPrimitive (value: any): boolean {
2626
* Objects from primitive values when we know the value
2727
* is a JSON-compliant type.
2828
*/
29-
export function isObject (obj: mixed): boolean {
29+
export function isObject (obj: mixed): boolean %checks {
3030
return obj !== null && typeof obj === 'object'
3131
}
3232

33-
const toString = Object.prototype.toString
33+
const _toString = Object.prototype.toString
3434

3535
/**
3636
* Strict object type check. Only returns true
3737
* for plain JavaScript objects.
3838
*/
3939
export function isPlainObject (obj: any): boolean {
40-
return toString.call(obj) === '[object Object]'
40+
return _toString.call(obj) === '[object Object]'
4141
}
4242

4343
export function isRegExp (v: any): boolean {
44-
return toString.call(v) === '[object RegExp]'
44+
return _toString.call(v) === '[object RegExp]'
4545
}
4646

4747
/**
4848
* Convert a value to a string that is actually rendered.
4949
*/
50-
export function _toString (val: any): string {
50+
export function toString (val: any): string {
5151
return val == null
5252
? ''
5353
: typeof val === 'object'

yarn.lock

+7-3
Original file line numberDiff line numberDiff line change
@@ -2138,9 +2138,9 @@ flat-cache@^1.2.1:
21382138
graceful-fs "^4.1.2"
21392139
write "^0.2.1"
21402140

2141-
flow-bin@^0.39.0:
2142-
version "0.39.0"
2143-
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.39.0.tgz#b1012a14460df1aa79d3a728e10f93c6944226d0"
2141+
flow-bin@^0.45.0:
2142+
version "0.45.0"
2143+
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.45.0.tgz#009dd0f577a3f665c74ca8be827ae8c2dd8fd6b5"
21442144

21452145
flow-remove-types-no-whitespace@^1.0.3:
21462146
version "1.0.5"
@@ -3270,6 +3270,10 @@ lodash.templatesettings@^4.0.0:
32703270
dependencies:
32713271
lodash._reinterpolate "~3.0.0"
32723272

3273+
lodash.uniq@^4.5.0:
3274+
version "4.5.0"
3275+
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
3276+
32733277
[email protected], lodash@^3.8.0:
32743278
version "3.10.1"
32753279
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"

0 commit comments

Comments
 (0)