diff --git a/src/compiler/codegen/events.js b/src/compiler/codegen/events.js index 2a4930c6a09..c329c110ebb 100644 --- a/src/compiler/codegen/events.js +++ b/src/compiler/codegen/events.js @@ -4,7 +4,7 @@ const fnExpRE = /^\s*([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/ const simplePathRE = /^\s*[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['.*?']|\[".*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*\s*$/ // keyCode aliases -const keyCodes = { +const keyCodes: { [k: any]: number | [number, number] } = { esc: 27, tab: 9, enter: 13, @@ -16,7 +16,7 @@ const keyCodes = { 'delete': [8, 46] } -const modifierCode = { +const modifierCode: { [k: string]: string } = { stop: '$event.stopPropagation();', prevent: '$event.preventDefault();', self: 'if($event.target !== $event.currentTarget)return;', diff --git a/src/compiler/codegen/index.js b/src/compiler/codegen/index.js index 1f23178a795..5cfb1863aa3 100644 --- a/src/compiler/codegen/index.js +++ b/src/compiler/codegen/index.js @@ -5,10 +5,14 @@ import { baseWarn, pluckModuleFunction } from '../helpers' import baseDirectives from '../directives/index' import { camelize, no } from 'shared/util' +type TransformFunction = (el: ASTElement, code: string) => string +type DataGenFunction = (el: ASTElement) => string +type DirctiveFunction = (el: ASTElement, dir: ASTDirective, warn: Function) => boolean + // configurable state let warn -let transforms -let dataGenFns +let transforms: Array +let dataGenFns: Array let platformDirectives let isPlatformReservedTag let staticRenderFns @@ -225,7 +229,7 @@ function genDirectives (el: ASTElement): string | void { for (i = 0, l = dirs.length; i < l; i++) { dir = dirs[i] needRuntime = true - const gen = platformDirectives[dir.name] || baseDirectives[dir.name] + const gen: DirctiveFunction = platformDirectives[dir.name] || baseDirectives[dir.name] if (gen) { // compile-time directive that manipulates AST. // returns true if it also needs a runtime counterpart. @@ -317,11 +321,11 @@ function getNormalizationType (children): number { return 0 } -function needsNormalization (el) { +function needsNormalization (el: ASTElement) { return el.for || el.tag === 'template' || el.tag === 'slot' } -function maybeComponent (el) { +function maybeComponent (el: ASTElement) { return el.type === 1 && !isPlatformReservedTag(el.tag) } diff --git a/src/compiler/directives/index.js b/src/compiler/directives/index.js index f6a8902ab17..df295f3dea0 100644 --- a/src/compiler/directives/index.js +++ b/src/compiler/directives/index.js @@ -1,3 +1,5 @@ +/* @flow */ + import bind from './bind' import { noop } from 'shared/util' diff --git a/src/compiler/helpers.js b/src/compiler/helpers.js index b36ba69f91f..29469333003 100644 --- a/src/compiler/helpers.js +++ b/src/compiler/helpers.js @@ -6,10 +6,10 @@ export function baseWarn (msg: string) { console.error(`[Vue parser]: ${msg}`) } -export function pluckModuleFunction ( +export function pluckModuleFunction ( modules: ?Array, key: string -): Array { +): Array { return modules ? modules.map(m => m[key]).filter(_ => _) : [] diff --git a/src/core/util/props.js b/src/core/util/props.js index 0f8da5367e9..ca7e3afe59f 100644 --- a/src/core/util/props.js +++ b/src/core/util/props.js @@ -104,7 +104,7 @@ function assertProp ( } for (let i = 0; i < type.length && !valid; i++) { const assertedType = assertType(value, type[i]) - expectedTypes.push(assertedType.expectedType) + expectedTypes.push(assertedType.expectedType || '') valid = assertedType.valid } } diff --git a/src/shared/util.js b/src/shared/util.js index eda49380989..4ca5f1f2479 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -73,12 +73,12 @@ export function isPrimitive (value: any): boolean { /** * Create a cached version of a pure function. */ -export function cached (fn: Function): Function { +export function cached (fn: F): F { const cache = Object.create(null) - return function cachedFn (str: string): any { + return (function cachedFn (str: string) { const hit = cache[str] return hit || (cache[str] = fn(str)) - } + }: any) } /**