Skip to content

Commit 0f4a88f

Browse files
HerringtonDarkholmeyyx990803
authored andcommitted
try to improve flowtype (vuejs#4567)
1 parent 13e3a5d commit 0f4a88f

File tree

6 files changed

+19
-13
lines changed

6 files changed

+19
-13
lines changed

src/compiler/codegen/events.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const fnExpRE = /^\s*([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/
44
const simplePathRE = /^\s*[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['.*?']|\[".*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*\s*$/
55

66
// keyCode aliases
7-
const keyCodes = {
7+
const keyCodes: { [k: any]: number | [number, number] } = {
88
esc: 27,
99
tab: 9,
1010
enter: 13,
@@ -16,7 +16,7 @@ const keyCodes = {
1616
'delete': [8, 46]
1717
}
1818

19-
const modifierCode = {
19+
const modifierCode: { [k: string]: string } = {
2020
stop: '$event.stopPropagation();',
2121
prevent: '$event.preventDefault();',
2222
self: 'if($event.target !== $event.currentTarget)return;',

src/compiler/codegen/index.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ import { baseWarn, pluckModuleFunction } from '../helpers'
55
import baseDirectives from '../directives/index'
66
import { camelize, no } from 'shared/util'
77

8+
type TransformFunction = (el: ASTElement, code: string) => string
9+
type DataGenFunction = (el: ASTElement) => string
10+
type DirctiveFunction = (el: ASTElement, dir: ASTDirective, warn: Function) => boolean
11+
812
// configurable state
913
let warn
10-
let transforms
11-
let dataGenFns
14+
let transforms: Array<TransformFunction>
15+
let dataGenFns: Array<DataGenFunction>
1216
let platformDirectives
1317
let isPlatformReservedTag
1418
let staticRenderFns
@@ -225,7 +229,7 @@ function genDirectives (el: ASTElement): string | void {
225229
for (i = 0, l = dirs.length; i < l; i++) {
226230
dir = dirs[i]
227231
needRuntime = true
228-
const gen = platformDirectives[dir.name] || baseDirectives[dir.name]
232+
const gen: DirctiveFunction = platformDirectives[dir.name] || baseDirectives[dir.name]
229233
if (gen) {
230234
// compile-time directive that manipulates AST.
231235
// returns true if it also needs a runtime counterpart.
@@ -317,11 +321,11 @@ function getNormalizationType (children): number {
317321
return 0
318322
}
319323

320-
function needsNormalization (el) {
324+
function needsNormalization (el: ASTElement) {
321325
return el.for || el.tag === 'template' || el.tag === 'slot'
322326
}
323327

324-
function maybeComponent (el) {
328+
function maybeComponent (el: ASTElement) {
325329
return el.type === 1 && !isPlatformReservedTag(el.tag)
326330
}
327331

src/compiler/directives/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* @flow */
2+
13
import bind from './bind'
24
import { noop } from 'shared/util'
35

src/compiler/helpers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ export function baseWarn (msg: string) {
66
console.error(`[Vue parser]: ${msg}`)
77
}
88

9-
export function pluckModuleFunction (
9+
export function pluckModuleFunction<F: Function> (
1010
modules: ?Array<Object>,
1111
key: string
12-
): Array<Function> {
12+
): Array<F> {
1313
return modules
1414
? modules.map(m => m[key]).filter(_ => _)
1515
: []

src/core/util/props.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function assertProp (
104104
}
105105
for (let i = 0; i < type.length && !valid; i++) {
106106
const assertedType = assertType(value, type[i])
107-
expectedTypes.push(assertedType.expectedType)
107+
expectedTypes.push(assertedType.expectedType || '')
108108
valid = assertedType.valid
109109
}
110110
}

src/shared/util.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ export function isPrimitive (value: any): boolean {
7373
/**
7474
* Create a cached version of a pure function.
7575
*/
76-
export function cached (fn: Function): Function {
76+
export function cached<F: Function> (fn: F): F {
7777
const cache = Object.create(null)
78-
return function cachedFn (str: string): any {
78+
return (function cachedFn (str: string) {
7979
const hit = cache[str]
8080
return hit || (cache[str] = fn(str))
81-
}
81+
}: any)
8282
}
8383

8484
/**

0 commit comments

Comments
 (0)