ソースを参照

types: upgrade flow

Evan You 8 年 前
コミット
531371b818

+ 2 - 10
flow/compiler.js

@@ -173,21 +173,13 @@ declare type SFCDescriptor = {
   template: ?SFCBlock;
   script: ?SFCBlock;
   styles: Array<SFCBlock>;
-  customBlocks: Array<SFCCustomBlock>;
-}
-
-declare type SFCCustomBlock = {
-  type: string;
-  content: string;
-  start?: number;
-  end?: number;
-  src?: string;
-  attrs: {[attribute:string]: string};
+  customBlocks: Array<SFCBlock>;
 };
 
 declare type SFCBlock = {
   type: string;
   content: string;
+  attrs: {[attribute:string]: string};
   start?: number;
   end?: number;
   lang?: string;

+ 3 - 3
package-lock.json

@@ -3814,9 +3814,9 @@
       }
     },
     "flow-bin": {
-      "version": "0.54.1",
-      "resolved": "https://registry.npmjs.org/flow-bin/-/flow-bin-0.54.1.tgz",
-      "integrity": "sha1-cQG8zPAG3AZScUqK7wxyB4p2BRA=",
+      "version": "0.61.0",
+      "resolved": "https://registry.npmjs.org/flow-bin/-/flow-bin-0.61.0.tgz",
+      "integrity": "sha512-w6SGi5CDfKLNGzYssRhW6N37qKclDXijsxDQ5M8c3WbivRYta0Horv22bwakegfKBVDnyeS0lRW3OqBC74eq2g==",
       "dev": true
     },
     "flow-remove-types-no-whitespace": {

+ 1 - 1
package.json

@@ -85,7 +85,7 @@
     "eslint-plugin-jasmine": "^2.8.4",
     "eslint-plugin-vue-libs": "^2.0.1",
     "file-loader": "^1.1.5",
-    "flow-bin": "^0.54.0",
+    "flow-bin": "^0.61.0",
     "hash-sum": "^1.0.2",
     "he": "^1.1.1",
     "http-server": "^0.10.0",

+ 1 - 1
src/compiler/create-compiler.js

@@ -26,7 +26,7 @@ export function createCompilerCreator (baseCompile: Function): Function {
         // merge custom directives
         if (options.directives) {
           finalOptions.directives = extend(
-            Object.create(baseOptions.directives),
+            Object.create(baseOptions.directives || null),
             options.directives
           )
         }

+ 1 - 3
src/compiler/to-function.js

@@ -18,9 +18,7 @@ function createFunction (code, errors) {
 }
 
 export function createCompileToFunctionFn (compile: Function): Function {
-  const cache: {
-    [key: string]: CompiledFunctionResult;
-  } = Object.create(null)
+  const cache = Object.create(null)
 
   return function compileToFunctions (
     template: string,

+ 2 - 0
src/core/config.js

@@ -36,6 +36,7 @@ export default ({
   /**
    * Option merge strategies (used in core/util/options)
    */
+  // $flow-disable-line
   optionMergeStrategies: Object.create(null),
 
   /**
@@ -76,6 +77,7 @@ export default ({
   /**
    * Custom user key aliases for v-on
    */
+  // $flow-disable-line
   keyCodes: Object.create(null),
 
   /**

+ 1 - 1
src/core/instance/lifecycle.js

@@ -212,7 +212,7 @@ export function updateChildComponent (
   vm: Component,
   propsData: ?Object,
   listeners: ?Object,
-  parentVnode: VNode,
+  parentVnode: MountedComponentVNode,
   renderChildren: ?Array<VNode>
 ) {
   if (process.env.NODE_ENV !== 'production') {

+ 4 - 2
src/core/instance/render-helpers/resolve-slots.js

@@ -1,5 +1,7 @@
 /* @flow */
 
+import type VNode from 'core/vdom/vnode'
+
 /**
  * Runtime helper for resolving raw children VNodes into a slot object.
  */
@@ -23,10 +25,10 @@ export function resolveSlots (
     if ((child.context === context || child.fnContext === context) &&
       data && data.slot != null
     ) {
-      const name = child.data.slot
+      const name = data.slot
       const slot = (slots[name] || (slots[name] = []))
       if (child.tag === 'template') {
-        slot.push.apply(slot, child.children)
+        slot.push.apply(slot, child.children || [])
       } else {
         slot.push(child)
       }

+ 1 - 0
src/core/instance/state.js

@@ -161,6 +161,7 @@ function getData (data: Function, vm: Component): any {
 const computedWatcherOptions = { lazy: true }
 
 function initComputed (vm: Component, computed: Object) {
+  // $flow-disable-line
   const watchers = vm._computedWatchers = Object.create(null)
   // computed properties are just getters during SSR
   const isSSR = isServerRendering()

+ 3 - 0
src/core/vdom/modules/directives.js

@@ -86,17 +86,20 @@ function normalizeDirectives (
 ): { [key: string]: VNodeDirective } {
   const res = Object.create(null)
   if (!dirs) {
+    // $flow-disable-line
     return res
   }
   let i, dir
   for (i = 0; i < dirs.length; i++) {
     dir = dirs[i]
     if (!dir.modifiers) {
+      // $flow-disable-line
       dir.modifiers = emptyModifiers
     }
     res[getRawDirName(dir)] = dir
     dir.def = resolveAsset(vm.$options, 'directives', dir.name, true)
   }
+  // $flow-disable-line
   return res
 }
 

+ 3 - 3
src/platforms/web/util/class.js

@@ -2,18 +2,18 @@
 
 import { isDef, isObject } from 'shared/util'
 
-export function genClassForVnode (vnode: VNode): string {
+export function genClassForVnode (vnode: VNodeWithData): string {
   let data = vnode.data
   let parentNode = vnode
   let childNode = vnode
   while (isDef(childNode.componentInstance)) {
     childNode = childNode.componentInstance._vnode
-    if (childNode.data) {
+    if (childNode && childNode.data) {
       data = mergeClassData(childNode.data, data)
     }
   }
   while (isDef(parentNode = parentNode.parent)) {
-    if (parentNode.data) {
+    if (parentNode && parentNode.data) {
       data = mergeClassData(data, parentNode.data)
     }
   }

+ 5 - 2
src/platforms/web/util/style.js

@@ -40,7 +40,7 @@ export function normalizeStyleBinding (bindingStyle: any): ?Object {
  * parent component style should be after child's
  * so that parent component's style could override it
  */
-export function getStyle (vnode: VNode, checkChild: boolean): Object {
+export function getStyle (vnode: VNodeWithData, checkChild: boolean): Object {
   const res = {}
   let styleData
 
@@ -48,7 +48,10 @@ export function getStyle (vnode: VNode, checkChild: boolean): Object {
     let childNode = vnode
     while (childNode.componentInstance) {
       childNode = childNode.componentInstance._vnode
-      if (childNode.data && (styleData = normalizeStyleData(childNode.data))) {
+      if (
+        childNode && childNode.data &&
+        (styleData = normalizeStyleData(childNode.data))
+      ) {
         extend(res, styleData)
       }
     }

+ 3 - 3
src/sfc/parser.js

@@ -27,7 +27,7 @@ export function parseComponent (
     customBlocks: []
   }
   let depth = 0
-  let currentBlock: ?(SFCBlock | SFCCustomBlock) = null
+  let currentBlock: ?SFCBlock = null
 
   function start (
     tag: string,
@@ -44,7 +44,7 @@ export function parseComponent (
         attrs: attrs.reduce((cumulated, { name, value }) => {
           cumulated[name] = value || true
           return cumulated
-        }, Object.create(null))
+        }, {})
       }
       if (isSpecialTag(tag)) {
         checkAttrs(currentBlock, attrs)
@@ -95,7 +95,7 @@ export function parseComponent (
     depth--
   }
 
-  function padContent (block: SFCBlock | SFCCustomBlock, pad: true | "line" | "space") {
+  function padContent (block: SFCBlock, pad: true | "line" | "space") {
     if (pad === 'space') {
       return content.slice(0, block.start).replace(replaceRE, ' ')
     } else {