Browse Source

upgrade flow to 0.31 (close #3482)

Evan You 9 years ago
parent
commit
982913fb1e

+ 1 - 1
flow/compiler.js

@@ -53,7 +53,7 @@ declare type ASTElementHooks = { [key: string]: Array<string> }
 
 declare type ASTDirective = {
   name: string;
-  value: ?string;
+  value: string;
   arg: ?string;
   modifiers: ?{ [key: string]: true };
 }

+ 1 - 1
package.json

@@ -58,7 +58,7 @@
     "eslint-config-vue": "^1.0.3",
     "eslint-loader": "^1.3.0",
     "eslint-plugin-flow-vars": "^0.5.0",
-    "flow-bin": "^0.27.0",
+    "flow-bin": "^0.31.1",
     "flow-remove-types": "github:yyx990803/flow-remove-types",
     "http-server": "^0.9.0",
     "jasmine": "^2.4.1",

+ 3 - 3
src/compiler/codegen/index.js

@@ -71,7 +71,7 @@ function genElement (el: ASTElement): string {
   }
 }
 
-function genIf (el: ASTElement): string {
+function genIf (el: any): string {
   const exp = el.if
   el.ifProcessed = true // avoid recursion
   return `(${exp})?${genElement(el)}:${genElse(el)}`
@@ -83,7 +83,7 @@ function genElse (el: ASTElement): string {
     : '_e()'
 }
 
-function genFor (el: ASTElement): string {
+function genFor (el: any): string {
   const exp = el.for
   const alias = el.alias
   const iterator1 = el.iterator1 ? `,${el.iterator1}` : ''
@@ -228,7 +228,7 @@ function genSlot (el: ASTElement): string {
     : slot
 }
 
-function genComponent (el: ASTElement): string {
+function genComponent (el: any): string {
   const children = genChildren(el)
   return `_h(${el.component},${genData(el)}${
     children ? `,${children}` : ''

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

@@ -27,7 +27,7 @@ export function createComponent (
 
   if (typeof Ctor !== 'function') {
     if (process.env.NODE_ENV !== 'production') {
-      warn(`Invalid Component definition: ${Ctor}`, context)
+      warn(`Invalid Component definition: ${String(Ctor)}`, context)
     }
     return
   }
@@ -208,7 +208,7 @@ function resolveAsyncComponent (
       // reject
       reason => {
         process.env.NODE_ENV !== 'production' && warn(
-          `Failed to resolve async component: ${factory}` +
+          `Failed to resolve async component: ${String(factory)}` +
           (reason ? `\nReason: ${reason}` : '')
         )
       }

+ 9 - 11
src/platforms/web/compiler/directives/model.js

@@ -26,7 +26,7 @@ export default function model (
   }
 }
 
-function genCheckboxModel (el: ASTElement, value: ?string) {
+function genCheckboxModel (el: ASTElement, value: string) {
   if (process.env.NODE_ENV !== 'production' &&
     el.attrsMap.checked != null) {
     warn(
@@ -35,7 +35,7 @@ function genCheckboxModel (el: ASTElement, value: ?string) {
       'Declare initial values in the component\'s data option instead.'
     )
   }
-  const valueBinding = getBindingAttr(el, 'value')
+  const valueBinding = getBindingAttr(el, 'value') || 'null'
   const trueValueBinding = getBindingAttr(el, 'true-value') || 'true'
   const falseValueBinding = getBindingAttr(el, 'false-value') || 'false'
   addProp(el, 'checked',
@@ -57,7 +57,7 @@ function genCheckboxModel (el: ASTElement, value: ?string) {
   )
 }
 
-function genRadioModel (el: ASTElement, value: ?string) {
+function genRadioModel (el: ASTElement, value: string) {
   if (process.env.NODE_ENV !== 'production' &&
     el.attrsMap.checked != null) {
     warn(
@@ -66,14 +66,14 @@ function genRadioModel (el: ASTElement, value: ?string) {
       'Declare initial values in the component\'s data option instead.'
     )
   }
-  const valueBinding = getBindingAttr(el, 'value')
+  const valueBinding = getBindingAttr(el, 'value') || 'null'
   addProp(el, 'checked', `(${value})===(${valueBinding})`)
   addHandler(el, 'change', `${value}=${valueBinding}`, null, true)
 }
 
 function genDefaultModel (
   el: ASTElement,
-  value: ?string,
+  value: string,
   modifiers: ?Object
 ): ?boolean {
   if (process.env.NODE_ENV !== 'production') {
@@ -116,7 +116,7 @@ function genDefaultModel (
   }
 }
 
-function genSelect (el: ASTElement, value: ?string) {
+function genSelect (el: ASTElement, value: string) {
   if (process.env.NODE_ENV !== 'production') {
     el.children.some(checkOptionWarning)
   }
@@ -129,18 +129,16 @@ function genSelect (el: ASTElement, value: ?string) {
   return true
 }
 
-function checkOptionWarning (option: ASTNode) {
+function checkOptionWarning (option: any): boolean {
   if (option.type === 1 &&
     option.tag === 'option' &&
     option.attrsMap.selected != null) {
-    const parentModel = option.parent &&
-      option.parent.type === 1 &&
-      option.parent.attrsMap['v-model']
     warn(
-      `<select v-model="${parentModel}">:\n` +
+      `<select v-model="${option.parent.attrsMap['v-model']}">:\n` +
       'inline selected attributes on <option> will be ignored when using v-model. ' +
       'Declare initial values in the component\'s data option instead.'
     )
     return true
   }
+  return false
 }

+ 1 - 1
src/platforms/web/runtime/node-ops.js

@@ -46,7 +46,7 @@ export function setTextContent (node: Node, text: string) {
   node.textContent = text
 }
 
-export function childNodes (node: Node): NodeList {
+export function childNodes (node: Node): NodeList<Node> {
   return node.childNodes
 }
 

+ 2 - 2
src/server/render.js

@@ -74,13 +74,13 @@ export function createRenderFunction (
         const key = name + '::' + getKey(node.componentOptions.propsData)
         if (has) {
           has(key, hit => {
-            if (hit) {
+            if (hit && get) {
               get(key, res => write(res, next))
             } else {
               renderComponentWithCache(node, write, next, isRoot, cache, key)
             }
           })
-        } else {
+        } else if (get) {
           get(key, res => {
             if (res) {
               write(res, next)