@halospv3/hce.shared-config
Version:
Automate commit message quality, changelogs, and CI/CD releases. Exports a semantic-release shareable configuration deserialized from this package's '.releaserc.yml'. Shared resources for .NET projects are also distributed with this package.
56 lines (52 loc) • 2.29 kB
JavaScript
import { getPrototypeOf } from './getPrototypeOf.mjs';
import { baseClassProto } from './inheritance.mjs';
import { isConstructor } from './isConstructor.mjs';
/* eslint-disable jsdoc/no-defaults */
/**
* Iterate through the class and its base/super classes until an anonymous function is reached. This is the default superclass all classes extend.
* @template Class Any {@link ClassLike} type.
* @template ClassesOrInstances 'classes' or 'classInstances'
* @param classDefinition Any class type satisfying {@link Class}. This class (or its instance type) is included in the return value.
* @param [returnType='classes'] Determines return type. If 'classInstances', the return type is an array of the classes' `.prototype`. Else, the classes themselves are returned.
* @since 3.0.0
* @returns
* `returnType extends 'classInstances' ? ClassLike<T>[] : ClassLike<T>[].map(c => c.prototype)`
* Excludes default superclasses e.g. anonymous functions, native code.
*/
function getPrototypesChainOf(classDefinition, returnType) {
// class definitions or their respective .prototype; exclude default superclasses.
let current = classDefinition;
let parent;
const returnValue = [];
let index = 0;
while (baseClassProto !== current) {
parent = getPrototypeOf(current);
// current is a Class symbol/constructor. Object.getOwnPropertyDescriptors on current will include static properties.
if (!isConstructor(current)) break;
if (returnType === 'classInstances') {
const instanceOfCurrent = current.prototype;
returnValue[index] = instanceOfCurrent;
} else {
returnValue[index] = current;
}
/**
* Assign the super class to current.
* If the argument is a class, Reflect.getPrototypeOf method returns the
* superclass.
*/
if (isConstructor(parent) && 'name' in parent && typeof parent.name === 'string' && '' !== parent.name // it's possible for a Function/Constructor to be anonymous...
) {
current = parent;
} else {
break;
}
index++;
}
return returnValue;
/*
assuming current is NugetProjectProperties...
Reflect.getPrototypeOf(current).name is 'MSBuildProjectProperties'
*/
}
export { getPrototypesChainOf };
//# sourceMappingURL=getPrototypeChainOf.mjs.map