Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/codegen/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;',
Expand Down
14 changes: 9 additions & 5 deletions src/compiler/codegen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<TransformFunction>
let dataGenFns: Array<DataGenFunction>
let platformDirectives
let isPlatformReservedTag
let staticRenderFns
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 2 additions & 0 deletions src/compiler/directives/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* @flow */

import bind from './bind'
import { noop } from 'shared/util'

Expand Down
4 changes: 2 additions & 2 deletions src/compiler/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export function baseWarn (msg: string) {
console.error(`[Vue parser]: ${msg}`)
}

export function pluckModuleFunction (
export function pluckModuleFunction<F: Function> (
modules: ?Array<Object>,
key: string
): Array<Function> {
): Array<F> {
return modules
? modules.map(m => m[key]).filter(_ => _)
: []
Expand Down
2 changes: 1 addition & 1 deletion src/core/util/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<F: Function> (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)
}

/**
Expand Down