From 1c1dec715bc8238217ecfba81faedc510dc2661c Mon Sep 17 00:00:00 2001 From: dy-xiaodong2022 Date: Fri, 26 Jan 2024 02:03:16 +0800 Subject: [PATCH] perf: update error function --- src/base/index.ts | 19 +++++++++---------- src/date/main.ts | 12 ++---------- src/dom/dom.ts | 29 ++++++++++++----------------- src/request/base.ts | 6 +----- 4 files changed, 24 insertions(+), 42 deletions(-) diff --git a/src/base/index.ts b/src/base/index.ts index 82388aab9..c84065bb6 100644 --- a/src/base/index.ts +++ b/src/base/index.ts @@ -52,16 +52,15 @@ class FastjsBaseModule> { then(func: (e: T) => void, time: number = 0): T { if (__DEV__) { if (typeof func !== "function") { - _dev.warn("fastjs/base/FastjsBaseModule", "Invalid function, **a function is required**.", [ - `***func: ${func}`, - `time: ${time}`, - "then(**func: (e: T) => void**, time: number = 0): T", - "FastjsBaseModule.then" - ], ["fastjs.wrong"]); - throw _dev.error("fastjs/base/FastjsBaseModule", "Invalid function, a function is required.", [ - "then(func: (e: T) => void, time: number = 0): T", - "FastjsBaseModule.then" - ]); + if (__DEV__) { + throw _dev.error("fastjs/base/FastjsBaseModule", "Invalid function, **a function is required**.", [ + `***func: ${func}`, + `time: ${time}`, + "then(**func: (e: T) => void**, time: number = 0): T", + "FastjsBaseModule.then" + ], ["fastjs.wrong"]); + } + throw "t33q"; } if (typeof time !== "number") { _dev.warn("fastjs/base/FastjsBaseModule", "Invalid time, **a number is required**.", [ diff --git a/src/date/main.ts b/src/date/main.ts index 2ebcba35b..270c10063 100644 --- a/src/date/main.ts +++ b/src/date/main.ts @@ -141,16 +141,12 @@ class FastjsDate extends FastjsBaseModule { if (allTokens.includes(char)) { if (isToken) { if (__DEV__) { - _dev.warn("fastjs/date/FastjsDate", "Invalid format string, token cannot be adjacent", [ + throw _dev.error("fastjs/date/FastjsDate", "Invalid format string, token cannot be adjacent", [ "***formatString: " + formatString, "***dateString: " + dateString, "private parseFormatString(formatString: string, dateString: string): number", "super: ", this ], ["fastjs.wrong"]); - throw _dev.error("fastjs/date/FastjsDate", "Invalid format string, token cannot be adjacent", [ - "private parseFormatString(formatString: string, dateString: string): number", - "FastjsDate.parseFormatString", - ]); } throw "fg3j" } @@ -205,16 +201,12 @@ class FastjsDate extends FastjsBaseModule { if (is12Hour) { if (isAm === null) { if (__DEV__) { - _dev.warn("fastjs/date/FastjsDate", "Invalid format string, using 12 hours format but missing AM/PM token", [ + throw _dev.error("fastjs/date/FastjsDate", "Invalid format string, using 12 hours format but missing AM/PM token", [ "***formatString: " + formatString, "***dateString: " + dateString, "private parseFormatString(formatString: string, dateString: string): number", "super: ", this ], ["fastjs.wrong"]); - throw _dev.error("fastjs/date/FastjsDate", "Invalid format string, using 12 hours format but missing AM/PM token", [ - "private parseFormatString(formatString: string, dateString: string): number", - "FastjsDate.parseFormatString", - ]); } throw "2b5s" } diff --git a/src/dom/dom.ts b/src/dom/dom.ts index 6f76d2826..789180468 100644 --- a/src/dom/dom.ts +++ b/src/dom/dom.ts @@ -71,18 +71,17 @@ class FastjsDom extends FastjsBaseModule{ } } else if (el instanceof HTMLElement) { this._el = el - } else if (__DEV__) { - _dev.warn("fastjs/dom/Dom", `el is not **HTMLElement or string**, instead of **${typeof el}**`, [ - "*el: ", el, - "properties: ", p, - "constructor(**el: Dom | HTMLElement | Element | string**, properties?: FastjsDomProps)", - "super: ", this - ], ["fastjs.right", "fastjs.wrong"]); - throw _dev.error("fastjs/dom/Dom", "el is not HTMLElement or string, instead of " + typeof el, [ - "constructor(el: Dom | HTMLElement | Element | string, properties?: FastjsDomProps)", - "Dom.constructor", - ]); - } else throw "6e2s" + } else { + if (__DEV__) { + throw _dev.error("fastjs/dom/Dom", `el is not **HTMLElement or string**, instead of **${typeof el}**`, [ + "*el: ", el, + "properties: ", p, + "constructor(**el: Dom | HTMLElement | Element | string**, properties?: FastjsDomProps)", + "super: ", this + ], ["fastjs.right", "fastjs.wrong"]); + } + throw "6e2s" + } return this; } @@ -270,17 +269,13 @@ class FastjsDom extends FastjsBaseModule{ if (el.parentElement === null) { if (__DEV__) { let callback = typeof callbackOrTarget === "function" ? callbackOrTarget : undefined; - _dev.warn("fastjs/dom/push", "el.parentElement is null, did you pass the **document object** or is this element **exist in document**?", [ + throw _dev.error("fastjs/dom/push", "el.parentElement is null, did you pass the **document object** or is this element **exist in document**?", [ "*el: ", el, "target: Fastjs.PushTarget." + target, "clone: " + clone, "callback: " + callback, "push(**el?: HTMLElement | FastjsDomList | Dom**, target?: T, clone?: boolean): PushReturn", ], ["fastjs.warn", "fastjs.warn", "fastjs.wrong"]); - throw _dev.error("fastjs/dom/push", "el.parentElement can't be null", [ - "push(el?: HTMLElement | FastjsDomList | Dom, target?: T, clone?: boolean): PushReturn", - "Dom.push", - ]) } throw "hg42" } diff --git a/src/request/base.ts b/src/request/base.ts index 965050ba3..94fdfc0fb 100644 --- a/src/request/base.ts +++ b/src/request/base.ts @@ -20,16 +20,12 @@ class FastjsRequest extends FastjsBaseModule { super(); if (__DEV__ && !url) { - _dev.warn("fastjs/request", "A correct url is **required**.", [ + throw _dev.error("fastjs/request", "A correct url is **required**.", [ `***url: ${url}`, "data: ", data, "config: ", config, "super: ", this ], ["fastjs.wrong"]) - throw _dev.error("fastjs/request", "A correct url is required.", [ - "constructor(public url: string, public data: data = {}, config: Partial = {})", - "FastjsRequest.constructor" - ]); } this.config = {