use `is_function` everywhere

pull/7703/head
Ivan Hofer 4 years ago
parent 0c472c00c7
commit fcaa238e7d

@ -1,3 +1,5 @@
import { is_function} from '../../runtime/internal/utils';
// adapted from klona v2.0.4 - https://github.com/lukeed/klona
// (c) Luke Edwards, under MIT License
@ -22,7 +24,7 @@ export function clone(val) {
enumerable: true,
writable: true
});
} else if (typeof val[k] !== 'function') { // MODIFICATION: skip functions
} else if (!is_function(val[k])) { // MODIFICATION: skip functions
out[k] = (tmp = val[k]) && typeof tmp === 'object' ? clone(tmp) : tmp;
}
}

@ -177,7 +177,7 @@ export function init(component, options, instance, create_fragment, not_equal, p
}
export let SvelteElement;
if (typeof HTMLElement === 'function') {
if (is_function(HTMLElement)) {
SvelteElement = class extends HTMLElement {
$$: T$$;
$$set?: ($$props: any) => void;

@ -1,6 +1,7 @@
import { custom_event, append, append_hydration, insert, insert_hydration, detach, listen, attr } from './dom';
import { SvelteComponent } from './Component';
import { is_void } from '../../shared/utils/names';
import { is_function } from './utils';
export function dispatch_dev<T=any>(type: string, detail?: T) {
document.dispatchEvent(custom_event(type, { version: '__VERSION__', ...detail }, { bubbles: true }));
@ -93,7 +94,7 @@ export function set_data_dev(text, data) {
export function validate_each_argument(arg) {
if (typeof arg !== 'string' && !(arg && typeof arg === 'object' && 'length' in arg)) {
let msg = '{#each} only iterates over array-like objects.';
if (typeof Symbol === 'function' && arg && Symbol.iterator in arg) {
if (is_function(Symbol) && arg && Symbol.iterator in arg) {
msg += ' You can use a spread to convert this iterable into an array.';
}
throw new Error(msg);

@ -11,7 +11,7 @@ export function assign<T, S>(tar: T, src: S): T & S {
}
export function is_promise<T = any>(value: any): value is PromiseLike<T> {
return value && typeof value === 'object' && typeof value.then === 'function';
return value && typeof value === 'object' && is_function(value.then);
}
export function add_location(element, file, line, column, char) {
@ -33,7 +33,7 @@ export function is_function(thing: any): thing is Function {
}
export function safe_not_equal(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || is_function(a));
}
let src_url_equal_anchor;
@ -55,7 +55,7 @@ export function is_empty(obj) {
}
export function validate_store(store, name) {
if (store != null && typeof store.subscribe !== 'function') {
if (store != null && !is_function(store.subscribe)) {
throw new Error(`'${name}' is not a store with a 'subscribe' method`);
}
}

@ -1,5 +1,5 @@
import { Readable, writable } from 'svelte/store';
import { assign, loop, now, Task } from 'svelte/internal';
import { assign, loop, now, Task, is_function } from 'svelte/internal';
import { linear } from 'svelte/easing';
import { is_date } from './utils';
import { resolved_promise } from 'svelte/internal/constants';
@ -112,7 +112,7 @@ export function tweened<T>(value?: T, defaults: Options<T> = {}): Tweened<T> {
if (!started) {
fn = interpolate(value, new_value);
if (typeof duration === 'function') duration = duration(value, new_value);
if (is_function(duration)) duration = duration(value, new_value);
started = true;
}

@ -190,7 +190,7 @@ export function draw(node: SVGElement & { getTotalLength(): number }, {
} else {
duration = len / speed;
}
} else if (typeof duration === 'function') {
} else if (is_function(duration)) {
duration = duration(len);
}

Loading…
Cancel
Save