Ver código fonte

remove unnecessary :any castings due to improved flow checks

Evan You 9 anos atrás
pai
commit
228f0f8f3b

+ 1 - 1
package.json

@@ -77,7 +77,7 @@
     "eslint-plugin-jasmine": "^2.1.0",
     "eslint-plugin-vue": "^2.0.0",
     "file-loader": "^0.10.1",
-    "flow-bin": "^0.39.0",
+    "flow-bin": "^0.45.0",
     "hash-sum": "^1.0.2",
     "he": "^1.1.0",
     "http-server": "^0.9.0",

+ 2 - 2
src/core/instance/render.js

@@ -4,7 +4,7 @@ import {
   warn,
   nextTick,
   toNumber,
-  _toString,
+  toString,
   looseEqual,
   emptyObject,
   handleError,
@@ -109,7 +109,7 @@ export function renderMixin (Vue: Class<Component>) {
   // code size.
   Vue.prototype._o = markOnce
   Vue.prototype._n = toNumber
-  Vue.prototype._s = _toString
+  Vue.prototype._s = toString
   Vue.prototype._l = renderList
   Vue.prototype._t = renderSlot
   Vue.prototype._q = looseEqual

+ 1 - 1
src/core/vdom/create-component.js

@@ -96,7 +96,7 @@ const componentVNodeHooks = {
 const hooksToMerge = Object.keys(componentVNodeHooks)
 
 export function createComponent (
-  Ctor: any,
+  Ctor: Class<Component> | Function | Object | void,
   data?: VNodeData,
   context: Component,
   children: ?Array<VNode>,

+ 1 - 1
src/core/vdom/create-element.js

@@ -113,7 +113,7 @@ function applyNS (vnode, ns) {
     // use default namespace inside foreignObject
     return
   }
-  if (Array.isArray(vnode.children)) {
+  if (isDef(vnode.children)) {
     for (let i = 0, l = vnode.children.length; i < l; i++) {
       const child = vnode.children[i]
       if (isDef(child.tag) && isUndef(child.ns)) {

+ 1 - 2
src/core/vdom/create-functional-component.js

@@ -21,9 +21,8 @@ export function createFunctionalComponent (
   const props = {}
   const propOptions = Ctor.options.props
   if (isDef(propOptions)) {
-    propsData = propsData || {}
     for (const key in propOptions) {
-      props[key] = validateProp(key, propOptions, propsData)
+      props[key] = validateProp(key, propOptions, propsData || {})
     }
   } else {
     if (isDef(data.attrs)) mergeProps(props, data.attrs)

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

@@ -51,7 +51,7 @@ export function extractPropsFromVNodeData (
 
 function checkProp (
   res: Object,
-  hash: any,
+  hash: ?Object,
   key: string,
   altKey: string,
   preserve: boolean

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

@@ -48,7 +48,7 @@ function normalizeArrayChildren (children: any, nestedIndex?: string): Array<VNo
       res.push.apply(res, normalizeArrayChildren(c, `${nestedIndex || ''}_${i}`))
     } else if (isPrimitive(c)) {
       if (isDef(last) && isDef(last.text)) {
-        (last: any).text += String(c)
+        last.text += String(c)
       } else if (c !== '') {
         // convert primitive to vnode
         res.push(createTextVNode(c))
@@ -59,7 +59,7 @@ function normalizeArrayChildren (children: any, nestedIndex?: string): Array<VNo
       } else {
         // default key for nested array children (likely generated by v-for)
         if (isDef(c.tag) && isUndef(c.key) && isDef(nestedIndex)) {
-          c.key = `__vlist${(nestedIndex: any)}_${i}__`
+          c.key = `__vlist${nestedIndex}_${i}__`
         }
         res.push(c)
       }

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

@@ -35,7 +35,7 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
       // non-string values will be stringified
       elm._value = cur
       // avoid resetting cursor position when value is the same
-      const strCur = cur == null ? '' : String(cur)
+      const strCur = isUndef(cur) ? '' : String(cur)
       if (shouldUpdateValue(elm, vnode, strCur)) {
         elm.value = strCur
       }

+ 4 - 4
src/platforms/web/runtime/modules/transition.js

@@ -57,7 +57,7 @@ export function enter (vnode: VNodeWithData, toggleDisplay: ?() => void) {
     afterAppear,
     appearCancelled,
     duration
-  } = (data: any)
+  } = data
 
   // activeInstance will always be the <transition> component managing this
   // transition. One edge case to check is when the <transition> is placed
@@ -201,7 +201,7 @@ export function leave (vnode: VNodeWithData, rm: Function) {
     leaveCancelled,
     delayLeave,
     duration
-  } = (data: any)
+  } = data
 
   const expectsCSS = css !== false && !isIE9
   const userWantsControl = getHookArgumentsLength(leave)
@@ -212,7 +212,7 @@ export function leave (vnode: VNodeWithData, rm: Function) {
       : duration
   )
 
-  if (process.env.NODE_ENV !== 'production' && explicitLeaveDuration != null) {
+  if (process.env.NODE_ENV !== 'production' && isDef(explicitLeaveDuration)) {
     checkDuration(explicitLeaveDuration, 'leave', vnode)
   }
 
@@ -249,7 +249,7 @@ export function leave (vnode: VNodeWithData, rm: Function) {
     }
     // record leaving element
     if (!vnode.data.show) {
-      (el.parentNode._pending || (el.parentNode._pending = {}))[vnode.key] = vnode
+      (el.parentNode._pending || (el.parentNode._pending = {}))[(vnode.key: any)] = vnode
     }
     beforeLeave && beforeLeave(el)
     if (expectsCSS) {

+ 1 - 1
src/platforms/web/server/modules/attrs.js

@@ -17,7 +17,7 @@ export default function renderAttrs (node: VNodeWithData): string {
   let attrs = node.data.attrs
   let res = ''
 
-  let parent: any = node.parent
+  let parent = node.parent
   while (isDef(parent)) {
     if (isDef(parent.data) && isDef(parent.data.attrs)) {
       attrs = Object.assign({}, attrs, parent.data.attrs)

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

@@ -9,7 +9,7 @@ export default function renderDOMProps (node: VNodeWithData): string {
   let props = node.data.domProps
   let res = ''
 
-  let parent: any = node.parent
+  let parent = node.parent
   while (isDef(parent)) {
     if (parent.data && parent.data.domProps) {
       props = Object.assign({}, props, parent.data.domProps)
@@ -21,7 +21,7 @@ export default function renderDOMProps (node: VNodeWithData): string {
     return res
   }
 
-  const attrs: any = node.data.attrs
+  const attrs = node.data.attrs
   for (const key in props) {
     if (key === 'innerHTML') {
       setText(node, props[key], true)

+ 3 - 3
src/server/render.js

@@ -77,9 +77,9 @@ function renderComponent (node, isRoot, context) {
     const key = name + '::' + getKey(node.componentOptions.propsData)
     const { has, get } = context
     if (isDef(has)) {
-      (has: any)(key, hit => {
+      has(key, hit => {
         if (hit === true && isDef(get)) {
-          (get: any)(key, res => {
+          get(key, res => {
             if (isDef(registerComponent)) {
               registerComponent(userContext)
             }
@@ -91,7 +91,7 @@ function renderComponent (node, isRoot, context) {
         }
       })
     } else if (isDef(get)) {
-      (get: any)(key, res => {
+      get(key, res => {
         if (isDef(res)) {
           if (isDef(registerComponent)) {
             registerComponent(userContext)

+ 9 - 9
src/shared/util.js

@@ -2,22 +2,22 @@
 
 // these helpers produces better vm code in JS engines due to their
 // explicitness and function inlining
-export function isUndef (v: any): boolean {
+export function isUndef (v: any): boolean %checks {
   return v === undefined || v === null
 }
 
-export function isDef (v: any) /* : %checks */ {
+export function isDef (v: any): boolean %checks {
   return v !== undefined && v !== null
 }
 
-export function isTrue (v: any): boolean {
+export function isTrue (v: any): boolean %checks {
   return v === true
 }
 
 /**
  * Check if value is primitive
  */
-export function isPrimitive (value: any): boolean {
+export function isPrimitive (value: any): boolean %checks {
   return typeof value === 'string' || typeof value === 'number'
 }
 
@@ -26,28 +26,28 @@ export function isPrimitive (value: any): boolean {
  * Objects from primitive values when we know the value
  * is a JSON-compliant type.
  */
-export function isObject (obj: mixed): boolean {
+export function isObject (obj: mixed): boolean %checks {
   return obj !== null && typeof obj === 'object'
 }
 
-const toString = Object.prototype.toString
+const _toString = Object.prototype.toString
 
 /**
  * Strict object type check. Only returns true
  * for plain JavaScript objects.
  */
 export function isPlainObject (obj: any): boolean {
-  return toString.call(obj) === '[object Object]'
+  return _toString.call(obj) === '[object Object]'
 }
 
 export function isRegExp (v: any): boolean {
-  return toString.call(v) === '[object RegExp]'
+  return _toString.call(v) === '[object RegExp]'
 }
 
 /**
  * Convert a value to a string that is actually rendered.
  */
-export function _toString (val: any): string {
+export function toString (val: any): string {
   return val == null
     ? ''
     : typeof val === 'object'

+ 7 - 3
yarn.lock

@@ -2138,9 +2138,9 @@ flat-cache@^1.2.1:
     graceful-fs "^4.1.2"
     write "^0.2.1"
 
-flow-bin@^0.39.0:
-  version "0.39.0"
-  resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.39.0.tgz#b1012a14460df1aa79d3a728e10f93c6944226d0"
+flow-bin@^0.45.0:
+  version "0.45.0"
+  resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.45.0.tgz#009dd0f577a3f665c74ca8be827ae8c2dd8fd6b5"
 
 flow-remove-types-no-whitespace@^1.0.3:
   version "1.0.5"
@@ -3270,6 +3270,10 @@ lodash.templatesettings@^4.0.0:
   dependencies:
     lodash._reinterpolate "~3.0.0"
 
+lodash.uniq@^4.5.0:
+  version "4.5.0"
+  resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
+
 lodash@3.10.1, lodash@^3.8.0:
   version "3.10.1"
   resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"