From ff41743984bfb164485f9d0bebf86fcbbf48bdef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20M=C3=BCller?= Date: Mon, 23 Nov 2020 00:15:49 +0100 Subject: [PATCH] fix: user supplied prop function detection --- src/components/calendar/calendar.js | 14 +++----------- src/components/form-file/form-file.js | 17 ++++------------- .../form-spinbutton/form-spinbutton.js | 8 ++------ src/components/form-tags/form-tags.js | 8 ++------ src/components/table/helpers/mixin-filtering.js | 8 ++------ src/mixins/form-text.js | 7 +------ 6 files changed, 14 insertions(+), 48 deletions(-) diff --git a/src/components/calendar/calendar.js b/src/components/calendar/calendar.js index 19df7143e74..f531a332bfb 100644 --- a/src/components/calendar/calendar.js +++ b/src/components/calendar/calendar.js @@ -43,7 +43,7 @@ import { } from '../../utils/date' import { attemptBlur, attemptFocus, requestAF } from '../../utils/dom' import { stopEvent } from '../../utils/events' -import { isArray, isPlainObject, isString, isUndefined } from '../../utils/inspect' +import { isArray, isPlainObject, isString } from '../../utils/inspect' import { isLocaleRTL } from '../../utils/locale' import { mathMax } from '../../utils/math' import { toInteger } from '../../utils/number' @@ -342,20 +342,12 @@ export const BCalendar = Vue.extend({ }, computedDateDisabledFn() { const { dateDisabledFn } = this - let result = null - try { - result = dateDisabledFn() - } catch {} - return isUndefined(result) ? () => false : dateDisabledFn + return dateDisabledFn.name !== 'default' ? dateDisabledFn : () => false }, // TODO: Change `dateInfoFn` to handle events and notes as well as classes computedDateInfoFn() { const { dateInfoFn } = this - let result = null - try { - result = dateInfoFn() - } catch {} - return isUndefined(result) ? () => ({}) : dateInfoFn + return dateInfoFn.name !== 'default' ? dateInfoFn : () => ({}) }, calendarLocale() { // This locale enforces the gregorian calendar (for use in formatter functions) diff --git a/src/components/form-file/form-file.js b/src/components/form-file/form-file.js index bfbfee33b6b..fd57827d677 100644 --- a/src/components/form-file/form-file.js +++ b/src/components/form-file/form-file.js @@ -10,14 +10,7 @@ import { makePropsConfigurable } from '../../utils/config' import { closest } from '../../utils/dom' import { hasPromiseSupport } from '../../utils/env' import { eventOn, eventOff, stopEvent } from '../../utils/events' -import { - isArray, - isFile, - isFunction, - isNull, - isUndefined, - isUndefinedOrNull -} from '../../utils/inspect' +import { isArray, isFile, isFunction, isNull, isUndefinedOrNull } from '../../utils/inspect' import { File } from '../../utils/safe-types' import { escapeRegExp } from '../../utils/string' import { warn } from '../../utils/warn' @@ -276,11 +269,9 @@ export const BFormFile = /*#__PURE__*/ Vue.extend({ }, computedFileNameFormatter() { const { fileNameFormatter } = this - let result = null - try { - result = fileNameFormatter() - } catch {} - return isUndefined(result) ? this.defaultFileNameFormatter : fileNameFormatter + return fileNameFormatter.name !== 'default' + ? fileNameFormatter + : this.defaultFileNameFormatter }, clonedFiles() { return cloneDeep(this.files) diff --git a/src/components/form-spinbutton/form-spinbutton.js b/src/components/form-spinbutton/form-spinbutton.js index bdb0ae25c03..39b36ec3296 100644 --- a/src/components/form-spinbutton/form-spinbutton.js +++ b/src/components/form-spinbutton/form-spinbutton.js @@ -13,7 +13,7 @@ import { arrayIncludes, concat } from '../../utils/array' import { makePropsConfigurable } from '../../utils/config' import { attemptBlur, attemptFocus } from '../../utils/dom' import { eventOnOff, stopEvent } from '../../utils/events' -import { isNull, isUndefined } from '../../utils/inspect' +import { isNull } from '../../utils/inspect' import { isLocaleRTL } from '../../utils/locale' import { mathFloor, mathMax, mathPow, mathRound } from '../../utils/math' import { toFloat, toInteger } from '../../utils/number' @@ -223,11 +223,7 @@ export const BFormSpinbutton = /*#__PURE__*/ Vue.extend({ }, computedFormatter() { const { formatterFn } = this - let result = null - try { - result = formatterFn() - } catch {} - return isUndefined(result) ? this.defaultFormatter : formatterFn + return formatterFn.name !== 'default' ? formatterFn : this.defaultFormatter }, computedAttrs() { return { diff --git a/src/components/form-tags/form-tags.js b/src/components/form-tags/form-tags.js index 0000b13e82b..7d5bf3e379f 100644 --- a/src/components/form-tags/form-tags.js +++ b/src/components/form-tags/form-tags.js @@ -21,7 +21,7 @@ import { } from '../../utils/dom' import { stopEvent } from '../../utils/events' import { pick } from '../../utils/object' -import { isEvent, isNumber, isString, isUndefined } from '../../utils/inspect' +import { isEvent, isNumber, isString } from '../../utils/inspect' import { escapeRegExp, toString, trim, trimLeft } from '../../utils/string' import formControlMixin, { props as formControlProps } from '../../mixins/form-control' import formSizeMixin, { props as formSizeProps } from '../../mixins/form-size' @@ -508,11 +508,7 @@ export const BFormTags = /*#__PURE__*/ Vue.extend({ }, validateTag(tag) { const { tagValidator } = this - let result = null - try { - result = tagValidator() - } catch {} - return isUndefined(result) ? true : tagValidator(tag) + return tagValidator.name !== 'default' ? tagValidator(tag) : true }, getInput() { // Returns the input element reference (or null if not found) diff --git a/src/components/table/helpers/mixin-filtering.js b/src/components/table/helpers/mixin-filtering.js index 69a75e98554..a3c53cf33ca 100644 --- a/src/components/table/helpers/mixin-filtering.js +++ b/src/components/table/helpers/mixin-filtering.js @@ -5,7 +5,7 @@ import identity from '../../../utils/identity' import looseEqual from '../../../utils/loose-equal' import { concat } from '../../../utils/array' import { makePropsConfigurable } from '../../../utils/config' -import { isFunction, isString, isRegExp, isUndefined } from '../../../utils/inspect' +import { isFunction, isString, isRegExp } from '../../../utils/inspect' import { toInteger } from '../../../utils/number' import { escapeRegExp } from '../../../utils/string' import { warn } from '../../../utils/warn' @@ -83,11 +83,7 @@ export default { localFilterFn() { // Return `null` to signal to use internal filter function const { filterFunction } = this - let result = null - try { - result = filterFunction() - } catch {} - return isUndefined(result) ? null : filterFunction + return filterFunction.name !== 'default' ? filterFunction : null }, // Returns the records in `localItems` that match the filter criteria // Returns the original `localItems` array if not sorting diff --git a/src/mixins/form-text.js b/src/mixins/form-text.js index 49f6050fa9c..7efe584a521 100644 --- a/src/mixins/form-text.js +++ b/src/mixins/form-text.js @@ -1,7 +1,6 @@ import { makePropsConfigurable } from '../utils/config' import { attemptBlur, attemptFocus } from '../utils/dom' import { stopEvent } from '../utils/events' -import { isUndefined } from '../utils/inspect' import { mathMax } from '../utils/math' import { toInteger, toFloat } from '../utils/number' import { toString } from '../utils/string' @@ -112,11 +111,7 @@ export default { return mathMax(toInteger(this.debounce, 0), 0) }, hasFormatter() { - let result = null - try { - result = this.formatter() - } catch {} - return !isUndefined(result) + return this.formatter.name !== 'default' } }, watch: {