@eslint-react/shared
Advanced tools
Comparing version
import * as z from '@zod/mini'; | ||
import * as micro_memoize from 'micro-memoize'; | ||
import { _ } from '@eslint-react/eff'; | ||
@@ -565,106 +566,2 @@ | ||
interface Dictionary<Type> { | ||
[key: string]: Type; | ||
[index: number]: Type; | ||
} | ||
type AnyFn = (...args: any[]) => any; | ||
type Key = any[]; | ||
type RawKey = Key | IArguments; | ||
type Value = any; | ||
interface CacheSnapshot { | ||
keys: Key[]; | ||
size: number; | ||
values: Value[]; | ||
} | ||
declare class Cache<Fn extends AnyFn> { | ||
readonly canTransformKey: boolean; | ||
readonly getKeyIndex: KeyIndexGetter; | ||
readonly options: NormalizedOptions<Fn>; | ||
readonly shouldCloneArguments: boolean; | ||
readonly shouldUpdateOnAdd: boolean; | ||
readonly shouldUpdateOnChange: boolean; | ||
readonly shouldUpdateOnHit: boolean; | ||
/** | ||
* The prevents call arguments which have cached results. | ||
*/ | ||
keys: Key[]; | ||
/** | ||
* The results of previous cached calls. | ||
*/ | ||
values: Value[]; | ||
constructor(options: NormalizedOptions<Fn>); | ||
/** | ||
* The number of cached [key,value] results. | ||
*/ | ||
get size(): number; | ||
/** | ||
* A copy of the cache at a moment in time. This is useful | ||
* to compare changes over time, since the cache mutates | ||
* internally for performance reasons. | ||
*/ | ||
get snapshot(): CacheSnapshot; | ||
/** | ||
* Order the array based on a Least-Recently-Used basis. | ||
*/ | ||
orderByLru(key: Key, value: Value, startingIndex: number): void; | ||
/** | ||
* Update the promise method to auto-remove from cache if rejected, and | ||
* if resolved then fire cache hit / changed. | ||
*/ | ||
updateAsyncCache(memoized: Memoized<Fn>): void; | ||
} | ||
type EqualityComparator = (object1: any, object2: any) => boolean; | ||
type MatchingKeyComparator = (key1: Key, key2: RawKey) => boolean; | ||
type CacheModifiedHandler<Fn extends AnyFn> = ( | ||
cache: Cache<Fn>, | ||
options: NormalizedOptions<Fn>, | ||
memoized: Memoized<Fn>, | ||
) => void; | ||
type KeyTransformer = (args: Key) => Key; | ||
type KeyIndexGetter = (keyToMatch: RawKey) => number; | ||
interface StandardOptions<Fn extends AnyFn> { | ||
isEqual?: EqualityComparator; | ||
isMatchingKey?: MatchingKeyComparator; | ||
isPromise?: boolean; | ||
maxSize?: number; | ||
onCacheAdd?: CacheModifiedHandler<Fn>; | ||
onCacheChange?: CacheModifiedHandler<Fn>; | ||
onCacheHit?: CacheModifiedHandler<Fn>; | ||
transformKey?: KeyTransformer; | ||
} | ||
interface Options<Fn extends AnyFn> | ||
extends StandardOptions<Fn>, | ||
Dictionary<any> {} | ||
interface NormalizedOptions<Fn extends AnyFn> extends Options<Fn> { | ||
isEqual: EqualityComparator; | ||
isPromise: boolean; | ||
maxSize: number; | ||
} | ||
type Memoized<Fn extends AnyFn> = Fn & | ||
Dictionary<any> & { | ||
cache: Cache<Fn>; | ||
fn: Fn; | ||
isMemoized: true; | ||
options: NormalizedOptions<Fn>; | ||
}; | ||
/** | ||
@@ -1357,3 +1254,5 @@ Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive). | ||
attributes: CustomComponentPropNormalized[]; | ||
re: RegExp; | ||
re: { | ||
test(s: string): boolean; | ||
}; | ||
} | ||
@@ -1390,3 +1289,3 @@ interface CustomComponentPropNormalized { | ||
*/ | ||
declare const decodeSettings: Memoized<(data: unknown) => ESLintReactSettings>; | ||
declare const decodeSettings: micro_memoize.Memoized<(data: unknown) => ESLintReactSettings>; | ||
/** | ||
@@ -1398,3 +1297,3 @@ * The memoized version of `ESLintReactSettings`. | ||
*/ | ||
declare const toNormalizedSettings: Memoized<({ additionalComponents, additionalHooks, importSource, polymorphicPropName, skipImportCheck, version, ...rest }: ESLintReactSettings) => ESLintReactSettingsNormalized>; | ||
declare const toNormalizedSettings: micro_memoize.Memoized<({ additionalComponents, additionalHooks, importSource, polymorphicPropName, skipImportCheck, version, ...rest }: ESLintReactSettings) => ESLintReactSettingsNormalized>; | ||
declare function getSettingsFromContext(context: { | ||
@@ -1401,0 +1300,0 @@ settings: unknown; |
@@ -7,3 +7,5 @@ 'use strict'; | ||
var z = require('@zod/mini'); | ||
var pm = require('picomatch'); | ||
var kit = require('@eslint-react/kit'); | ||
var fastEquals = require('fast-equals'); | ||
var memoize = require('micro-memoize'); | ||
@@ -33,3 +35,3 @@ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null; | ||
var z__namespace = /*#__PURE__*/_interopNamespace(z); | ||
var pm__default = /*#__PURE__*/_interopDefault(pm); | ||
var memoize__default = /*#__PURE__*/_interopDefault(memoize); | ||
@@ -212,700 +214,6 @@ // src/constants.ts | ||
}; | ||
// ../../node_modules/.pnpm/fast-equals@5.2.2/node_modules/fast-equals/dist/esm/index.mjs | ||
var getOwnPropertyNames = Object.getOwnPropertyNames; | ||
var getOwnPropertySymbols = Object.getOwnPropertySymbols; | ||
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
function combineComparators(comparatorA, comparatorB) { | ||
return function isEqual(a, b, state) { | ||
return comparatorA(a, b, state) && comparatorB(a, b, state); | ||
}; | ||
} | ||
function createIsCircular(areItemsEqual) { | ||
return function isCircular(a, b, state) { | ||
if (!a || !b || typeof a !== "object" || typeof b !== "object") { | ||
return areItemsEqual(a, b, state); | ||
} | ||
var cache = state.cache; | ||
var cachedA = cache.get(a); | ||
var cachedB = cache.get(b); | ||
if (cachedA && cachedB) { | ||
return cachedA === b && cachedB === a; | ||
} | ||
cache.set(a, b); | ||
cache.set(b, a); | ||
var result = areItemsEqual(a, b, state); | ||
cache.delete(a); | ||
cache.delete(b); | ||
return result; | ||
}; | ||
} | ||
function getStrictProperties(object2) { | ||
return getOwnPropertyNames(object2).concat(getOwnPropertySymbols(object2)); | ||
} | ||
var hasOwn = Object.hasOwn || function(object2, property) { | ||
return hasOwnProperty.call(object2, property); | ||
}; | ||
function sameValueZeroEqual(a, b) { | ||
return a === b || !a && !b && a !== a && b !== b; | ||
} | ||
var PREACT_VNODE = "__v"; | ||
var PREACT_OWNER = "__o"; | ||
var REACT_OWNER = "_owner"; | ||
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; | ||
var keys = Object.keys; | ||
function areArraysEqual(a, b, state) { | ||
var index = a.length; | ||
if (b.length !== index) { | ||
return false; | ||
} | ||
while (index-- > 0) { | ||
if (!state.equals(a[index], b[index], index, index, a, b, state)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
function areDatesEqual(a, b) { | ||
return sameValueZeroEqual(a.getTime(), b.getTime()); | ||
} | ||
function areErrorsEqual(a, b) { | ||
return a.name === b.name && a.message === b.message && a.cause === b.cause && a.stack === b.stack; | ||
} | ||
function areFunctionsEqual(a, b) { | ||
return a === b; | ||
} | ||
function areMapsEqual(a, b, state) { | ||
var size = a.size; | ||
if (size !== b.size) { | ||
return false; | ||
} | ||
if (!size) { | ||
return true; | ||
} | ||
var matchedIndices = new Array(size); | ||
var aIterable = a.entries(); | ||
var aResult; | ||
var bResult; | ||
var index = 0; | ||
while (aResult = aIterable.next()) { | ||
if (aResult.done) { | ||
break; | ||
} | ||
var bIterable = b.entries(); | ||
var hasMatch = false; | ||
var matchIndex = 0; | ||
while (bResult = bIterable.next()) { | ||
if (bResult.done) { | ||
break; | ||
} | ||
if (matchedIndices[matchIndex]) { | ||
matchIndex++; | ||
continue; | ||
} | ||
var aEntry = aResult.value; | ||
var bEntry = bResult.value; | ||
if (state.equals(aEntry[0], bEntry[0], index, matchIndex, a, b, state) && state.equals(aEntry[1], bEntry[1], aEntry[0], bEntry[0], a, b, state)) { | ||
hasMatch = matchedIndices[matchIndex] = true; | ||
break; | ||
} | ||
matchIndex++; | ||
} | ||
if (!hasMatch) { | ||
return false; | ||
} | ||
index++; | ||
} | ||
return true; | ||
} | ||
var areNumbersEqual = sameValueZeroEqual; | ||
function areObjectsEqual(a, b, state) { | ||
var properties = keys(a); | ||
var index = properties.length; | ||
if (keys(b).length !== index) { | ||
return false; | ||
} | ||
while (index-- > 0) { | ||
if (!isPropertyEqual(a, b, state, properties[index])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
function areObjectsEqualStrict(a, b, state) { | ||
var properties = getStrictProperties(a); | ||
var index = properties.length; | ||
if (getStrictProperties(b).length !== index) { | ||
return false; | ||
} | ||
var property; | ||
var descriptorA; | ||
var descriptorB; | ||
while (index-- > 0) { | ||
property = properties[index]; | ||
if (!isPropertyEqual(a, b, state, property)) { | ||
return false; | ||
} | ||
descriptorA = getOwnPropertyDescriptor(a, property); | ||
descriptorB = getOwnPropertyDescriptor(b, property); | ||
if ((descriptorA || descriptorB) && (!descriptorA || !descriptorB || descriptorA.configurable !== descriptorB.configurable || descriptorA.enumerable !== descriptorB.enumerable || descriptorA.writable !== descriptorB.writable)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
function arePrimitiveWrappersEqual(a, b) { | ||
return sameValueZeroEqual(a.valueOf(), b.valueOf()); | ||
} | ||
function areRegExpsEqual(a, b) { | ||
return a.source === b.source && a.flags === b.flags; | ||
} | ||
function areSetsEqual(a, b, state) { | ||
var size = a.size; | ||
if (size !== b.size) { | ||
return false; | ||
} | ||
if (!size) { | ||
return true; | ||
} | ||
var matchedIndices = new Array(size); | ||
var aIterable = a.values(); | ||
var aResult; | ||
var bResult; | ||
while (aResult = aIterable.next()) { | ||
if (aResult.done) { | ||
break; | ||
} | ||
var bIterable = b.values(); | ||
var hasMatch = false; | ||
var matchIndex = 0; | ||
while (bResult = bIterable.next()) { | ||
if (bResult.done) { | ||
break; | ||
} | ||
if (!matchedIndices[matchIndex] && state.equals(aResult.value, bResult.value, aResult.value, bResult.value, a, b, state)) { | ||
hasMatch = matchedIndices[matchIndex] = true; | ||
break; | ||
} | ||
matchIndex++; | ||
} | ||
if (!hasMatch) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
function areTypedArraysEqual(a, b) { | ||
var index = a.length; | ||
if (b.length !== index) { | ||
return false; | ||
} | ||
while (index-- > 0) { | ||
if (a[index] !== b[index]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
function areUrlsEqual(a, b) { | ||
return a.hostname === b.hostname && a.pathname === b.pathname && a.protocol === b.protocol && a.port === b.port && a.hash === b.hash && a.username === b.username && a.password === b.password; | ||
} | ||
function isPropertyEqual(a, b, state, property) { | ||
if ((property === REACT_OWNER || property === PREACT_OWNER || property === PREACT_VNODE) && (a.$$typeof || b.$$typeof)) { | ||
return true; | ||
} | ||
return hasOwn(b, property) && state.equals(a[property], b[property], property, property, a, b, state); | ||
} | ||
var ARGUMENTS_TAG = "[object Arguments]"; | ||
var BOOLEAN_TAG = "[object Boolean]"; | ||
var DATE_TAG = "[object Date]"; | ||
var ERROR_TAG = "[object Error]"; | ||
var MAP_TAG = "[object Map]"; | ||
var NUMBER_TAG = "[object Number]"; | ||
var OBJECT_TAG = "[object Object]"; | ||
var REG_EXP_TAG = "[object RegExp]"; | ||
var SET_TAG = "[object Set]"; | ||
var STRING_TAG = "[object String]"; | ||
var URL_TAG = "[object URL]"; | ||
var isArray = Array.isArray; | ||
var isTypedArray = typeof ArrayBuffer === "function" && ArrayBuffer.isView ? ArrayBuffer.isView : null; | ||
var assign = Object.assign; | ||
var getTag = Object.prototype.toString.call.bind(Object.prototype.toString); | ||
function createEqualityComparator(_a) { | ||
var areArraysEqual2 = _a.areArraysEqual, areDatesEqual2 = _a.areDatesEqual, areErrorsEqual2 = _a.areErrorsEqual, areFunctionsEqual2 = _a.areFunctionsEqual, areMapsEqual2 = _a.areMapsEqual, areNumbersEqual2 = _a.areNumbersEqual, areObjectsEqual2 = _a.areObjectsEqual, arePrimitiveWrappersEqual2 = _a.arePrimitiveWrappersEqual, areRegExpsEqual2 = _a.areRegExpsEqual, areSetsEqual2 = _a.areSetsEqual, areTypedArraysEqual2 = _a.areTypedArraysEqual, areUrlsEqual2 = _a.areUrlsEqual; | ||
return function comparator(a, b, state) { | ||
if (a === b) { | ||
return true; | ||
} | ||
if (a == null || b == null) { | ||
return false; | ||
} | ||
var type = typeof a; | ||
if (type !== typeof b) { | ||
return false; | ||
} | ||
if (type !== "object") { | ||
if (type === "number") { | ||
return areNumbersEqual2(a, b, state); | ||
} | ||
if (type === "function") { | ||
return areFunctionsEqual2(a, b, state); | ||
} | ||
return false; | ||
} | ||
var constructor = a.constructor; | ||
if (constructor !== b.constructor) { | ||
return false; | ||
} | ||
if (constructor === Object) { | ||
return areObjectsEqual2(a, b, state); | ||
} | ||
if (isArray(a)) { | ||
return areArraysEqual2(a, b, state); | ||
} | ||
if (isTypedArray != null && isTypedArray(a)) { | ||
return areTypedArraysEqual2(a, b, state); | ||
} | ||
if (constructor === Date) { | ||
return areDatesEqual2(a, b, state); | ||
} | ||
if (constructor === RegExp) { | ||
return areRegExpsEqual2(a, b, state); | ||
} | ||
if (constructor === Map) { | ||
return areMapsEqual2(a, b, state); | ||
} | ||
if (constructor === Set) { | ||
return areSetsEqual2(a, b, state); | ||
} | ||
var tag = getTag(a); | ||
if (tag === DATE_TAG) { | ||
return areDatesEqual2(a, b, state); | ||
} | ||
if (tag === REG_EXP_TAG) { | ||
return areRegExpsEqual2(a, b, state); | ||
} | ||
if (tag === MAP_TAG) { | ||
return areMapsEqual2(a, b, state); | ||
} | ||
if (tag === SET_TAG) { | ||
return areSetsEqual2(a, b, state); | ||
} | ||
if (tag === OBJECT_TAG) { | ||
return typeof a.then !== "function" && typeof b.then !== "function" && areObjectsEqual2(a, b, state); | ||
} | ||
if (tag === URL_TAG) { | ||
return areUrlsEqual2(a, b, state); | ||
} | ||
if (tag === ERROR_TAG) { | ||
return areErrorsEqual2(a, b, state); | ||
} | ||
if (tag === ARGUMENTS_TAG) { | ||
return areObjectsEqual2(a, b, state); | ||
} | ||
if (tag === BOOLEAN_TAG || tag === NUMBER_TAG || tag === STRING_TAG) { | ||
return arePrimitiveWrappersEqual2(a, b, state); | ||
} | ||
return false; | ||
}; | ||
} | ||
function createEqualityComparatorConfig(_a) { | ||
var circular = _a.circular, createCustomConfig = _a.createCustomConfig, strict = _a.strict; | ||
var config = { | ||
areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual, | ||
areDatesEqual, | ||
areErrorsEqual, | ||
areFunctionsEqual, | ||
areMapsEqual: strict ? combineComparators(areMapsEqual, areObjectsEqualStrict) : areMapsEqual, | ||
areNumbersEqual, | ||
areObjectsEqual: strict ? areObjectsEqualStrict : areObjectsEqual, | ||
arePrimitiveWrappersEqual, | ||
areRegExpsEqual, | ||
areSetsEqual: strict ? combineComparators(areSetsEqual, areObjectsEqualStrict) : areSetsEqual, | ||
areTypedArraysEqual: strict ? areObjectsEqualStrict : areTypedArraysEqual, | ||
areUrlsEqual | ||
}; | ||
if (createCustomConfig) { | ||
config = assign({}, config, createCustomConfig(config)); | ||
} | ||
if (circular) { | ||
var areArraysEqual$1 = createIsCircular(config.areArraysEqual); | ||
var areMapsEqual$1 = createIsCircular(config.areMapsEqual); | ||
var areObjectsEqual$1 = createIsCircular(config.areObjectsEqual); | ||
var areSetsEqual$1 = createIsCircular(config.areSetsEqual); | ||
config = assign({}, config, { | ||
areArraysEqual: areArraysEqual$1, | ||
areMapsEqual: areMapsEqual$1, | ||
areObjectsEqual: areObjectsEqual$1, | ||
areSetsEqual: areSetsEqual$1 | ||
}); | ||
} | ||
return config; | ||
} | ||
function createInternalEqualityComparator(compare) { | ||
return function(a, b, _indexOrKeyA, _indexOrKeyB, _parentA, _parentB, state) { | ||
return compare(a, b, state); | ||
}; | ||
} | ||
function createIsEqual(_a) { | ||
var circular = _a.circular, comparator = _a.comparator, createState = _a.createState, equals = _a.equals, strict = _a.strict; | ||
if (createState) { | ||
return function isEqual(a, b) { | ||
var _a2 = createState(), _b = _a2.cache, cache = _b === void 0 ? circular ? /* @__PURE__ */ new WeakMap() : void 0 : _b, meta = _a2.meta; | ||
return comparator(a, b, { | ||
cache, | ||
equals, | ||
meta, | ||
strict | ||
}); | ||
}; | ||
} | ||
if (circular) { | ||
return function isEqual(a, b) { | ||
return comparator(a, b, { | ||
cache: /* @__PURE__ */ new WeakMap(), | ||
equals, | ||
meta: void 0, | ||
strict | ||
}); | ||
}; | ||
} | ||
var state = { | ||
cache: void 0, | ||
equals, | ||
meta: void 0, | ||
strict | ||
}; | ||
return function isEqual(a, b) { | ||
return comparator(a, b, state); | ||
}; | ||
} | ||
createCustomEqual(); | ||
createCustomEqual({ strict: true }); | ||
createCustomEqual({ circular: true }); | ||
createCustomEqual({ | ||
circular: true, | ||
strict: true | ||
}); | ||
var shallowEqual = createCustomEqual({ | ||
createInternalComparator: function() { | ||
return sameValueZeroEqual; | ||
} | ||
}); | ||
createCustomEqual({ | ||
strict: true, | ||
createInternalComparator: function() { | ||
return sameValueZeroEqual; | ||
} | ||
}); | ||
createCustomEqual({ | ||
circular: true, | ||
createInternalComparator: function() { | ||
return sameValueZeroEqual; | ||
} | ||
}); | ||
createCustomEqual({ | ||
circular: true, | ||
createInternalComparator: function() { | ||
return sameValueZeroEqual; | ||
}, | ||
strict: true | ||
}); | ||
function createCustomEqual(options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
var _a = options.circular, circular = _a === void 0 ? false : _a, createCustomInternalComparator = options.createInternalComparator, createState = options.createState, _b = options.strict, strict = _b === void 0 ? false : _b; | ||
var config = createEqualityComparatorConfig(options); | ||
var comparator = createEqualityComparator(config); | ||
var equals = createCustomInternalComparator ? createCustomInternalComparator(comparator) : createInternalEqualityComparator(comparator); | ||
return createIsEqual({ circular, comparator, createState, equals, strict }); | ||
} | ||
// ../../node_modules/.pnpm/micro-memoize@4.1.3/node_modules/micro-memoize/dist/micro-memoize.esm.js | ||
var DEFAULT_OPTIONS_KEYS = { | ||
isEqual: true, | ||
isMatchingKey: true, | ||
isPromise: true, | ||
maxSize: true, | ||
onCacheAdd: true, | ||
onCacheChange: true, | ||
onCacheHit: true, | ||
transformKey: true | ||
}; | ||
var slice = Array.prototype.slice; | ||
function cloneArray(arrayLike) { | ||
var length = arrayLike.length; | ||
if (!length) { | ||
return []; | ||
} | ||
if (length === 1) { | ||
return [arrayLike[0]]; | ||
} | ||
if (length === 2) { | ||
return [arrayLike[0], arrayLike[1]]; | ||
} | ||
if (length === 3) { | ||
return [arrayLike[0], arrayLike[1], arrayLike[2]]; | ||
} | ||
return slice.call(arrayLike, 0); | ||
} | ||
function getCustomOptions(options) { | ||
var customOptions = {}; | ||
for (var key in options) { | ||
if (!DEFAULT_OPTIONS_KEYS[key]) { | ||
customOptions[key] = options[key]; | ||
} | ||
} | ||
return customOptions; | ||
} | ||
function isMemoized(fn) { | ||
return typeof fn === "function" && fn.isMemoized; | ||
} | ||
function isSameValueZero(object1, object2) { | ||
return object1 === object2 || object1 !== object1 && object2 !== object2; | ||
} | ||
function mergeOptions(existingOptions, newOptions) { | ||
var target = {}; | ||
for (var key in existingOptions) { | ||
target[key] = existingOptions[key]; | ||
} | ||
for (var key in newOptions) { | ||
target[key] = newOptions[key]; | ||
} | ||
return target; | ||
} | ||
var Cache = ( | ||
/** @class */ | ||
function() { | ||
function Cache2(options) { | ||
this.keys = []; | ||
this.values = []; | ||
this.options = options; | ||
var isMatchingKeyFunction = typeof options.isMatchingKey === "function"; | ||
if (isMatchingKeyFunction) { | ||
this.getKeyIndex = this._getKeyIndexFromMatchingKey; | ||
} else if (options.maxSize > 1) { | ||
this.getKeyIndex = this._getKeyIndexForMany; | ||
} else { | ||
this.getKeyIndex = this._getKeyIndexForSingle; | ||
} | ||
this.canTransformKey = typeof options.transformKey === "function"; | ||
this.shouldCloneArguments = this.canTransformKey || isMatchingKeyFunction; | ||
this.shouldUpdateOnAdd = typeof options.onCacheAdd === "function"; | ||
this.shouldUpdateOnChange = typeof options.onCacheChange === "function"; | ||
this.shouldUpdateOnHit = typeof options.onCacheHit === "function"; | ||
} | ||
Object.defineProperty(Cache2.prototype, "size", { | ||
/** | ||
* The number of cached [key,value] results. | ||
*/ | ||
get: function() { | ||
return this.keys.length; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Cache2.prototype, "snapshot", { | ||
/** | ||
* A copy of the cache at a moment in time. This is useful | ||
* to compare changes over time, since the cache mutates | ||
* internally for performance reasons. | ||
*/ | ||
get: function() { | ||
return { | ||
keys: cloneArray(this.keys), | ||
size: this.size, | ||
values: cloneArray(this.values) | ||
}; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Cache2.prototype._getKeyIndexFromMatchingKey = function(keyToMatch) { | ||
var _a = this.options, isMatchingKey = _a.isMatchingKey, maxSize = _a.maxSize; | ||
var keys2 = this.keys; | ||
var keysLength = keys2.length; | ||
if (!keysLength) { | ||
return -1; | ||
} | ||
if (isMatchingKey(keys2[0], keyToMatch)) { | ||
return 0; | ||
} | ||
if (maxSize > 1) { | ||
for (var index = 1; index < keysLength; index++) { | ||
if (isMatchingKey(keys2[index], keyToMatch)) { | ||
return index; | ||
} | ||
} | ||
} | ||
return -1; | ||
}; | ||
Cache2.prototype._getKeyIndexForMany = function(keyToMatch) { | ||
var isEqual = this.options.isEqual; | ||
var keys2 = this.keys; | ||
var keysLength = keys2.length; | ||
if (!keysLength) { | ||
return -1; | ||
} | ||
if (keysLength === 1) { | ||
return this._getKeyIndexForSingle(keyToMatch); | ||
} | ||
var keyLength = keyToMatch.length; | ||
var existingKey; | ||
var argIndex; | ||
if (keyLength > 1) { | ||
for (var index = 0; index < keysLength; index++) { | ||
existingKey = keys2[index]; | ||
if (existingKey.length === keyLength) { | ||
argIndex = 0; | ||
for (; argIndex < keyLength; argIndex++) { | ||
if (!isEqual(existingKey[argIndex], keyToMatch[argIndex])) { | ||
break; | ||
} | ||
} | ||
if (argIndex === keyLength) { | ||
return index; | ||
} | ||
} | ||
} | ||
} else { | ||
for (var index = 0; index < keysLength; index++) { | ||
existingKey = keys2[index]; | ||
if (existingKey.length === keyLength && isEqual(existingKey[0], keyToMatch[0])) { | ||
return index; | ||
} | ||
} | ||
} | ||
return -1; | ||
}; | ||
Cache2.prototype._getKeyIndexForSingle = function(keyToMatch) { | ||
var keys2 = this.keys; | ||
if (!keys2.length) { | ||
return -1; | ||
} | ||
var existingKey = keys2[0]; | ||
var length = existingKey.length; | ||
if (keyToMatch.length !== length) { | ||
return -1; | ||
} | ||
var isEqual = this.options.isEqual; | ||
if (length > 1) { | ||
for (var index = 0; index < length; index++) { | ||
if (!isEqual(existingKey[index], keyToMatch[index])) { | ||
return -1; | ||
} | ||
} | ||
return 0; | ||
} | ||
return isEqual(existingKey[0], keyToMatch[0]) ? 0 : -1; | ||
}; | ||
Cache2.prototype.orderByLru = function(key, value, startingIndex) { | ||
var keys2 = this.keys; | ||
var values = this.values; | ||
var currentLength = keys2.length; | ||
var index = startingIndex; | ||
while (index--) { | ||
keys2[index + 1] = keys2[index]; | ||
values[index + 1] = values[index]; | ||
} | ||
keys2[0] = key; | ||
values[0] = value; | ||
var maxSize = this.options.maxSize; | ||
if (currentLength === maxSize && startingIndex === currentLength) { | ||
keys2.pop(); | ||
values.pop(); | ||
} else if (startingIndex >= maxSize) { | ||
keys2.length = values.length = maxSize; | ||
} | ||
}; | ||
Cache2.prototype.updateAsyncCache = function(memoized) { | ||
var _this = this; | ||
var _a = this.options, onCacheChange = _a.onCacheChange, onCacheHit = _a.onCacheHit; | ||
var firstKey = this.keys[0]; | ||
var firstValue = this.values[0]; | ||
this.values[0] = firstValue.then(function(value) { | ||
if (_this.shouldUpdateOnHit) { | ||
onCacheHit(_this, _this.options, memoized); | ||
} | ||
if (_this.shouldUpdateOnChange) { | ||
onCacheChange(_this, _this.options, memoized); | ||
} | ||
return value; | ||
}, function(error) { | ||
var keyIndex = _this.getKeyIndex(firstKey); | ||
if (keyIndex !== -1) { | ||
_this.keys.splice(keyIndex, 1); | ||
_this.values.splice(keyIndex, 1); | ||
} | ||
throw error; | ||
}); | ||
}; | ||
return Cache2; | ||
}() | ||
); | ||
function createMemoizedFunction(fn, options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
if (isMemoized(fn)) { | ||
return createMemoizedFunction(fn.fn, mergeOptions(fn.options, options)); | ||
} | ||
if (typeof fn !== "function") { | ||
throw new TypeError("You must pass a function to `memoize`."); | ||
} | ||
var _a = options.isEqual, isEqual = _a === void 0 ? isSameValueZero : _a, isMatchingKey = options.isMatchingKey, _b = options.isPromise, isPromise = _b === void 0 ? false : _b, _c = options.maxSize, maxSize = _c === void 0 ? 1 : _c, onCacheAdd = options.onCacheAdd, onCacheChange = options.onCacheChange, onCacheHit = options.onCacheHit, transformKey = options.transformKey; | ||
var normalizedOptions = mergeOptions({ | ||
isEqual, | ||
isMatchingKey, | ||
isPromise, | ||
maxSize, | ||
onCacheAdd, | ||
onCacheChange, | ||
onCacheHit, | ||
transformKey | ||
}, getCustomOptions(options)); | ||
var cache = new Cache(normalizedOptions); | ||
var keys2 = cache.keys, values = cache.values, canTransformKey = cache.canTransformKey, shouldCloneArguments = cache.shouldCloneArguments, shouldUpdateOnAdd = cache.shouldUpdateOnAdd, shouldUpdateOnChange = cache.shouldUpdateOnChange, shouldUpdateOnHit = cache.shouldUpdateOnHit; | ||
var memoized = function() { | ||
var key = shouldCloneArguments ? cloneArray(arguments) : arguments; | ||
if (canTransformKey) { | ||
key = transformKey(key); | ||
} | ||
var keyIndex = keys2.length ? cache.getKeyIndex(key) : -1; | ||
if (keyIndex !== -1) { | ||
if (shouldUpdateOnHit) { | ||
onCacheHit(cache, normalizedOptions, memoized); | ||
} | ||
if (keyIndex) { | ||
cache.orderByLru(keys2[keyIndex], values[keyIndex], keyIndex); | ||
if (shouldUpdateOnChange) { | ||
onCacheChange(cache, normalizedOptions, memoized); | ||
} | ||
} | ||
} else { | ||
var newValue = fn.apply(this, arguments); | ||
var newKey = shouldCloneArguments ? key : cloneArray(arguments); | ||
cache.orderByLru(newKey, newValue, keys2.length); | ||
if (isPromise) { | ||
cache.updateAsyncCache(memoized); | ||
} | ||
if (shouldUpdateOnAdd) { | ||
onCacheAdd(cache, normalizedOptions, memoized); | ||
} | ||
if (shouldUpdateOnChange) { | ||
onCacheChange(cache, normalizedOptions, memoized); | ||
} | ||
} | ||
return values[0]; | ||
}; | ||
memoized.cache = cache; | ||
memoized.fn = fn; | ||
memoized.isMemoized = true; | ||
memoized.options = normalizedOptions; | ||
return memoized; | ||
} | ||
function unsafeDecodeSettings(data) { | ||
return data?.["react-x"] ?? {}; | ||
} | ||
var decodeSettings = createMemoizedFunction((data) => { | ||
var decodeSettings = memoize__default.default((data) => { | ||
return { | ||
@@ -916,3 +224,3 @@ ...DEFAULT_ESLINT_REACT_SETTINGS, | ||
}, { isEqual: (a, b) => a === b }); | ||
var toNormalizedSettings = createMemoizedFunction( | ||
var toNormalizedSettings = memoize__default.default( | ||
({ | ||
@@ -944,3 +252,3 @@ additionalComponents = [], | ||
})), | ||
re: pm__default.default.makeRe(name, { fastpaths: true }) | ||
re: kit.RE.toRegExp(name) | ||
})), | ||
@@ -954,3 +262,3 @@ additionalHooks, | ||
}, | ||
{ isEqual: shallowEqual } | ||
{ isEqual: fastEquals.shallowEqual } | ||
); | ||
@@ -957,0 +265,0 @@ function getSettingsFromContext(context) { |
{ | ||
"name": "@eslint-react/shared", | ||
"version": "1.45.2", | ||
"version": "1.45.3-next.0", | ||
"description": "ESLint React's Shared constants and functions.", | ||
@@ -40,6 +40,7 @@ "homepage": "https://github.com/Rel1cx/eslint-react", | ||
"@zod/mini": "^4.0.0-beta.0", | ||
"picomatch": "^4.0.2", | ||
"fast-equals": "^5.2.2", | ||
"micro-memoize": "^4.1.3", | ||
"ts-pattern": "^5.7.0", | ||
"@eslint-react/eff": "1.45.2", | ||
"@eslint-react/kit": "1.45.2" | ||
"@eslint-react/eff": "1.45.3-next.0", | ||
"@eslint-react/kit": "1.45.3-next.0" | ||
}, | ||
@@ -49,4 +50,2 @@ "devDependencies": { | ||
"@types/picomatch": "^4.0.0", | ||
"fast-equals": "^5.2.2", | ||
"micro-memoize": "^4.1.3", | ||
"tsup": "^8.4.0", | ||
@@ -53,0 +52,0 @@ "type-fest": "^4.39.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
5
-28.57%119356
-28.75%7
16.67%1669
-46.78%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed