Skip to content

fix #5539: improve isDef type definition #5549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 29, 2017
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
2 changes: 1 addition & 1 deletion flow/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ declare interface Component {
$once: (event: string, fn: Function) => Component;
$off: (event?: string | Array<string>, fn?: Function) => Component;
$emit: (event: string, ...args: Array<mixed>) => Component;
$nextTick: (fn: Function) => void;
$nextTick: (fn: Function) => void | Promise<*>;
$createElement: (tag?: string | Component, data?: Object, children?: VNodeChildren) => VNode;

// private properties
Expand Down
2 changes: 1 addition & 1 deletion flow/global-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ declare interface GlobalAPI {
extend: (options: Object) => Function;
set: <T>(target: Object | Array<T>, key: string | number, value: T) => T;
delete: <T>(target: Object| Array<T>, key: string | number) => void;
nextTick: (fn: Function, context?: Object) => void;
nextTick: (fn: Function, context?: Object) => void | Promise<*>;
use: (plugin: Function | Object) => void;
mixin: (mixin: Object) => void;
compile: (template: string) => { render: Function, staticRenderFns: Array<Function> };
Expand Down
8 changes: 5 additions & 3 deletions src/core/observer/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
handleError
} from '../util/index'

import type { ISet } from '../util/index'

let uid = 0

/**
Expand All @@ -32,8 +34,8 @@ export default class Watcher {
active: boolean;
deps: Array<Dep>;
newDeps: Array<Dep>;
depIds: Set;
newDepIds: Set;
depIds: ISet;
newDepIds: ISet;
getter: Function;
value: any;

Expand Down Expand Up @@ -242,7 +244,7 @@ function traverse (val: any) {
_traverse(val, seenObjects)
}

function _traverse (val: any, seen: Set) {
function _traverse (val: any, seen: ISet) {
let i, keys
const isA = Array.isArray(val)
if ((!isA && !isObject(val)) || !Object.isExtensible(val)) {
Expand Down
4 changes: 3 additions & 1 deletion src/core/util/debug.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* @flow */

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

export let warn = noop
export let tip = noop
export let formatComponentName
export let formatComponentName: Function = (null: any) // work around flow check
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cast is necessary because we cannot persuade flow that formatComponentName is initialized before other code.


if (process.env.NODE_ENV !== 'production') {
const hasConsole = typeof console !== 'undefined'
Expand Down
9 changes: 8 additions & 1 deletion src/core/util/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ if (typeof Set !== 'undefined' && isNative(Set)) {
_Set = Set
} else {
// a non-standard Set polyfill that only works with primitive keys.
_Set = class Set {
_Set = class Set implements ISet {
set: Object;
constructor () {
this.set = Object.create(null)
Expand All @@ -170,4 +170,11 @@ if (typeof Set !== 'undefined' && isNative(Set)) {
}
}

interface ISet {
has(key: string| number): boolean;
add(key: string| number): mixed;
clear(): void;
}

export { _Set }
export type { ISet }
4 changes: 3 additions & 1 deletion src/core/util/error.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* @flow */

import config from '../config'
import { warn } from './debug'
import { inBrowser } from './env'

export function handleError (err, vm, info) {
export function handleError (err: Error, vm: any, info: string) {
if (config.errorHandler) {
config.errorHandler.call(null, err, vm, info)
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/core/util/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* @flow */

export * from 'shared/util'
export * from './lang'
export * from './env'
Expand Down
1 change: 1 addition & 0 deletions src/core/vdom/create-functional-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function createFunctionalComponent (
const props = {}
const propOptions = Ctor.options.props
if (isDef(propOptions)) {
propsData = propsData || {}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed because propsData is possibly null.

for (const key in propOptions) {
props[key] = validateProp(key, propOptions, propsData)
}
Expand Down
4 changes: 2 additions & 2 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function isUndef (v: any): boolean {
return v === undefined || v === null
}

export function isDef (v: any): boolean {
export function isDef (v: any) /* : %checks */ {
return v !== undefined && v !== null
}

Expand Down Expand Up @@ -103,7 +103,7 @@ export function remove (arr: Array<any>, item: any): Array<any> | void {
* Check whether the object has the property.
*/
const hasOwnProperty = Object.prototype.hasOwnProperty
export function hasOwn (obj: Object, key: string): boolean {
export function hasOwn (obj: Object | Array<*>, key: string): boolean {
return hasOwnProperty.call(obj, key)
}

Expand Down