utils/node_modules/@microsoft/api-extractor-model/lib/mixins/ApiInitializerMixin.js.map
2024-02-07 01:33:07 -05:00

1 line
6.2 KiB
Plaintext

{"version":3,"file":"ApiInitializerMixin.js","sourceRoot":"","sources":["../../src/mixins/ApiInitializerMixin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAM3D,8DAA2D;AAC3D,oEAA6D;AAe7D,MAAM,mBAAmB,GAAkB,MAAM,CAAC,yCAAyC,CAAC,CAAC;AA4B7F;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CACjC,SAAqB;AACrB,8DAA8D;;IAE9D,MAAM,UAAW,SAAQ,SAAS;QAGhC,8DAA8D;QAC9D,YAAmB,GAAG,IAAW;YAC/B,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YAEf,MAAM,OAAO,GAAgC,IAAI,CAAC,CAAC,CAAC,CAAC;YAErD,IAAI,IAAI,YAAY,iCAAe,EAAE;gBACnC,IAAI,OAAO,CAAC,qBAAqB,EAAE;oBACjC,IAAI,CAAC,mBAAmB,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;iBAC9E;aACF;iBAAM;gBACL,MAAM,IAAI,iCAAa,CACrB,6EAA6E,CAC9E,CAAC;aACH;QACH,CAAC;QAED,gBAAgB;QACT,MAAM,CAAC,iBAAiB,CAC7B,OAA6C,EAC7C,OAA4B,EAC5B,UAAoC;YAEpC,SAAS,CAAC,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;YAE1D,OAAO,CAAC,qBAAqB,GAAG,UAAU,CAAC,qBAAqB,CAAC;QACnE,CAAC;QAED,IAAW,kBAAkB;YAC3B,OAAO,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACnC,CAAC;QAED,gBAAgB;QACT,aAAa,CAAC,UAA6C;YAChE,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YAEhC,iHAAiH;YACjH,IAAI,IAAI,CAAC,kBAAkB,EAAE;gBAC3B,UAAU,CAAC,qBAAqB,GAAG,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC;aACvE;QACH,CAAC;KACF;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAnDD,kDAmDC;AAED;;;GAGG;AACH,WAAiB,mBAAmB;IAClC;;;;;;;;OAQG;IACH,SAAgB,aAAa,CAAC,OAAgB;QAC5C,OAAO,OAAO,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC;IACrD,CAAC;IAFe,iCAAa,gBAE5B,CAAA;AACH,CAAC,EAbgB,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAanC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n/* eslint-disable @typescript-eslint/no-redeclare */\n\nimport type { ApiItem, IApiItemJson, IApiItemConstructor, IApiItemOptions } from '../items/ApiItem';\nimport type { IExcerptTokenRange, Excerpt } from './Excerpt';\nimport { ApiDeclaredItem } from '../items/ApiDeclaredItem';\nimport { InternalError } from '@rushstack/node-core-library';\nimport type { DeserializerContext } from '../model/DeserializerContext';\n\n/**\n * Constructor options for {@link (IApiInitializerMixinOptions:interface)}.\n * @public\n */\nexport interface IApiInitializerMixinOptions extends IApiItemOptions {\n initializerTokenRange?: IExcerptTokenRange;\n}\n\nexport interface IApiInitializerMixinJson extends IApiItemJson {\n initializerTokenRange?: IExcerptTokenRange;\n}\n\nconst _initializerExcerpt: unique symbol = Symbol('ApiInitializerMixin._initializerExcerpt');\n\n/**\n * The mixin base class for API items that can have an initializer.\n *\n * @remarks\n *\n * This is part of the {@link ApiModel} hierarchy of classes, which are serializable representations of\n * API declarations. The non-abstract classes (e.g. `ApiClass`, `ApiEnum`, `ApiInterface`, etc.) use\n * TypeScript \"mixin\" functions (e.g. `ApiDeclaredItem`, `ApiItemContainerMixin`, etc.) to add various\n * features that cannot be represented as a normal inheritance chain (since TypeScript does not allow a child class\n * to extend more than one base class). The \"mixin\" is a TypeScript merged declaration with three components:\n * the function that generates a subclass, an interface that describes the members of the subclass, and\n * a namespace containing static members of the class.\n *\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface ApiInitializerMixin extends ApiItem {\n /**\n * An {@link Excerpt} that describes the item's initializer.\n */\n readonly initializerExcerpt?: Excerpt;\n\n /** @override */\n serializeInto(jsonObject: Partial<IApiInitializerMixinJson>): void;\n}\n\n/**\n * Mixin function for {@link (ApiInitializerMixin:interface)}.\n *\n * @param baseClass - The base class to be extended\n * @returns A child class that extends baseClass, adding the {@link (ApiInitializerMixin:interface)} functionality.\n *\n * @public\n */\nexport function ApiInitializerMixin<TBaseClass extends IApiItemConstructor>(\n baseClass: TBaseClass\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): TBaseClass & (new (...args: any[]) => ApiInitializerMixin) {\n class MixedClass extends baseClass implements ApiInitializerMixin {\n public [_initializerExcerpt]?: Excerpt;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public constructor(...args: any[]) {\n super(...args);\n\n const options: IApiInitializerMixinOptions = args[0];\n\n if (this instanceof ApiDeclaredItem) {\n if (options.initializerTokenRange) {\n this[_initializerExcerpt] = this.buildExcerpt(options.initializerTokenRange);\n }\n } else {\n throw new InternalError(\n 'ApiInitializerMixin expects a base class that inherits from ApiDeclaredItem'\n );\n }\n }\n\n /** @override */\n public static onDeserializeInto(\n options: Partial<IApiInitializerMixinOptions>,\n context: DeserializerContext,\n jsonObject: IApiInitializerMixinJson\n ): void {\n baseClass.onDeserializeInto(options, context, jsonObject);\n\n options.initializerTokenRange = jsonObject.initializerTokenRange;\n }\n\n public get initializerExcerpt(): Excerpt | undefined {\n return this[_initializerExcerpt];\n }\n\n /** @override */\n public serializeInto(jsonObject: Partial<IApiInitializerMixinJson>): void {\n super.serializeInto(jsonObject);\n\n // Note that JSON does not support the \"undefined\" value, so we simply omit the field entirely if it is undefined\n if (this.initializerExcerpt) {\n jsonObject.initializerTokenRange = this.initializerExcerpt.tokenRange;\n }\n }\n }\n\n return MixedClass;\n}\n\n/**\n * Static members for {@link (ApiInitializerMixin:interface)}.\n * @public\n */\nexport namespace ApiInitializerMixin {\n /**\n * A type guard that tests whether the specified `ApiItem` subclass extends the `ApiInitializerMixin` mixin.\n *\n * @remarks\n *\n * The JavaScript `instanceof` operator cannot be used to test for mixin inheritance, because each invocation of\n * the mixin function produces a different subclass. (This could be mitigated by `Symbol.hasInstance`, however\n * the TypeScript type system cannot invoke a runtime test.)\n */\n export function isBaseClassOf(apiItem: ApiItem): apiItem is ApiInitializerMixin {\n return apiItem.hasOwnProperty(_initializerExcerpt);\n }\n}\n"]}