Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api-extractor/src/definitions/ApiEnum.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as ts from 'typescript';
import { ApiItemKind } from './ApiItem';
import ApiItemContainer from './ApiItemContainer';
import { IApiItemOptions } from './ApiItem';
import ApiEnumValue from './ApiEnumValue';
Expand All @@ -11,6 +12,8 @@ import TypeScriptHelpers from '../TypeScriptHelpers';
export default class ApiEnum extends ApiItemContainer {
constructor(options: IApiItemOptions) {
super(options);
this.kind = ApiItemKind.Enum;

for (const memberDeclaration of (options.declaration as ts.EnumDeclaration).members) {
const memberSymbol: ts.Symbol = TypeScriptHelpers.getSymbolForDeclaration(memberDeclaration);

Expand Down
3 changes: 2 additions & 1 deletion api-extractor/src/definitions/ApiEnumValue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ApiItem, { IApiItemOptions } from './ApiItem';
import ApiItem, { ApiItemKind, IApiItemOptions } from './ApiItem';
import PrettyPrinter from '../PrettyPrinter';

/**
Expand All @@ -8,6 +8,7 @@ import PrettyPrinter from '../PrettyPrinter';
export default class ApiEnumValue extends ApiItem {
constructor(options: IApiItemOptions) {
super(options);
this.kind = ApiItemKind.EnumValue;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion api-extractor/src/definitions/ApiFunction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ts from 'typescript';
import ApiItem, { IApiItemOptions } from './ApiItem';
import ApiItem, { ApiItemKind, IApiItemOptions } from './ApiItem';
import ApiParameter from './ApiParameter';
import TypeScriptHelpers from '../TypeScriptHelpers';
import PrettyPrinter from '../PrettyPrinter';
Expand All @@ -16,6 +16,7 @@ class ApiFunction extends ApiItem {

constructor(options: IApiItemOptions) {
super(options);
this.kind = ApiItemKind.Function;

const methodDeclaration: ts.FunctionDeclaration = options.declaration as ts.FunctionDeclaration;

Expand Down
51 changes: 51 additions & 0 deletions api-extractor/src/definitions/ApiItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,52 @@ import * as ts from 'typescript';
import Extractor from '../Extractor';
import ApiDocumentation from './ApiDocumentation';

/**
* Indicates the type of definition represented by a ApiItem object.
*/
export enum ApiItemKind {
/**
* A TypeScript class.
*/
Class = 0,
/**
* A TypeScript enum.
*/
Enum = 1,
/**
* A TypeScript value on an enum.
*/
EnumValue = 2,
/**
* A TypeScript function.
*/
Function = 3,
/**
* A TypeScript interface.
*/
Interface = 4,
/**
* A TypeScript method.
*/
Method = 5,
/**
* A TypeScript package.
*/
Package = 6,
/**
* A TypeScript parameter.
*/
Parameter = 7,
/**
* A TypeScript property.
*/
Property = 8,
/**
* A TypeScript type literal expression, i.e. which defines an anonymous interface.
*/
TypeLiteral = 9
}

/**
* This interface is used to pass options between constructors for ApiItem child classes.
*/
Expand Down Expand Up @@ -52,6 +98,11 @@ abstract class ApiItem {
*/
public name: string;

/**
* Indicates the type of definition represented by this ApiItem instance.
*/
public kind: ApiItemKind;

/**
* A list of extractor warnings that were reported using ApiItem.reportWarning().
* Whereas an "error" will break the build, a "warning" will merely be tracked in
Expand Down
3 changes: 2 additions & 1 deletion api-extractor/src/definitions/ApiMethod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ts from 'typescript';
import { IApiItemOptions } from './ApiItem';
import { ApiItemKind, IApiItemOptions } from './ApiItem';
import ApiMember from './ApiMember';
import ApiParameter from './ApiParameter';
import TypeScriptHelpers from '../TypeScriptHelpers';
Expand All @@ -17,6 +17,7 @@ export default class ApiMethod extends ApiMember {

constructor(options: IApiItemOptions) {
super(options);
this.kind = ApiItemKind.Method;

const methodDeclaration: ts.MethodDeclaration = options.declaration as ts.MethodDeclaration;

Expand Down
3 changes: 2 additions & 1 deletion api-extractor/src/definitions/ApiPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Extractor from '../Extractor';
import ApiStructuredType from './ApiStructuredType';
import ApiEnum from './ApiEnum';
import ApiFunction from './ApiFunction';
import { IApiItemOptions } from './ApiItem';
import { ApiItemKind, IApiItemOptions } from './ApiItem';
import ApiItemContainer from './ApiItemContainer';
import TypeScriptHelpers from '../TypeScriptHelpers';

Expand Down Expand Up @@ -39,6 +39,7 @@ export default class ApiPackage extends ApiItemContainer {
}
constructor(extractor: Extractor, rootFile: ts.SourceFile) {
super(ApiPackage._getOptions(extractor, rootFile));
this.kind = ApiItemKind.Package;

const exportSymbols: ts.Symbol[] = this.typeChecker.getExportsOfModule(this.declarationSymbol);
if (exportSymbols) {
Expand Down
3 changes: 2 additions & 1 deletion api-extractor/src/definitions/ApiParameter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ts from 'typescript';
import ApiItem, { IApiItemOptions } from './ApiItem';
import ApiItem, { ApiItemKind, IApiItemOptions } from './ApiItem';

/**
* This class is part of the ApiItem abstract syntax tree. It represents parameters of a function declaration
Expand All @@ -16,6 +16,7 @@ class ApiParameter extends ApiItem {

constructor(options: IApiItemOptions, docComment?: string) {
super(options);
this.kind = ApiItemKind.Parameter;

this.documentation.docComment = docComment;

Expand Down
3 changes: 2 additions & 1 deletion api-extractor/src/definitions/ApiProperty.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IApiItemOptions } from './ApiItem';
import { ApiItemKind, IApiItemOptions } from './ApiItem';
import ApiMember from './ApiMember';

/**
Expand All @@ -12,6 +12,7 @@ class ApiProperty extends ApiMember {

constructor(options: IApiItemOptions) {
super(options);
this.kind = ApiItemKind.Property;

this.isReadOnly = this.documentation.readonly ? this.documentation.readonly : false;

Expand Down
29 changes: 5 additions & 24 deletions api-extractor/src/definitions/ApiStructuredType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,16 @@
import * as ts from 'typescript';
import ApiMethod from './ApiMethod';
import ApiProperty from './ApiProperty';
import ApiItem, { IApiItemOptions } from './ApiItem';
import ApiItem, { ApiItemKind, IApiItemOptions } from './ApiItem';
import ApiItemContainer from './ApiItemContainer';
import TypeScriptHelpers from '../TypeScriptHelpers';
import PrettyPrinter from '../PrettyPrinter';

/**
* Indicates the type of definition represented by a ApiStructuredType object.
*/
export enum ApiStructuredTypeKind {
/**
* A TypeScript class.
*/
Class,
/**
* A TypeScript interface.
*/
Interface,
/**
* A TypeScript type literal expression, i.e. which defines an anonymous interface.
*/
TypeLiteral
}

/**
* This class is part of the ApiItem abstract syntax tree. It represents a class,
* interface, or type literal expression.
*/
export default class ApiStructuredType extends ApiItemContainer {
public kind: ApiStructuredTypeKind;
public implements?: string;
public extends?: string;

Expand All @@ -58,11 +39,11 @@ export default class ApiStructuredType extends ApiItemContainer {
this.type = this.typeChecker.getDeclaredTypeOfSymbol(this.declarationSymbol);

if (this.declarationSymbol.flags & ts.SymbolFlags.Interface) {
this.kind = ApiStructuredTypeKind.Interface;
this.kind = ApiItemKind.Interface;
} else if (this.declarationSymbol.flags & ts.SymbolFlags.TypeLiteral) {
this.kind = ApiStructuredTypeKind.TypeLiteral;
this.kind = ApiItemKind.TypeLiteral;
} else {
this.kind = ApiStructuredTypeKind.Class;
this.kind = ApiItemKind.Class;
}

for (const memberDeclaration of this._classLikeDeclaration.members) {
Expand Down Expand Up @@ -130,7 +111,7 @@ export default class ApiStructuredType extends ApiItemContainer {
public getDeclarationLine(): string {
let result: string = '';

if (this.kind !== ApiStructuredTypeKind.TypeLiteral) {
if (this.kind !== ApiItemKind.TypeLiteral) {
result += (this.declarationSymbol.flags & ts.SymbolFlags.Interface)
? 'interface ' : 'class ';

Expand Down
6 changes: 3 additions & 3 deletions api-extractor/src/generators/ApiFileGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as fs from 'fs';
import Extractor from '../Extractor';
import ApiStructuredType, { ApiStructuredTypeKind } from '../definitions/ApiStructuredType';
import ApiStructuredType from '../definitions/ApiStructuredType';
import ApiEnum from '../definitions/ApiEnum';
import ApiEnumValue from '../definitions/ApiEnumValue';
import ApiFunction from '../definitions/ApiFunction';
import ApiItem from '../definitions/ApiItem';
import ApiItem, { ApiItemKind } from '../definitions/ApiItem';
import ApiItemVisitor from '../ApiItemVisitor';
import ApiPackage from '../definitions/ApiPackage';
import ApiParameter from '../definitions/ApiParameter';
Expand Down Expand Up @@ -66,7 +66,7 @@ export default class ApiFileGenerator extends ApiItemVisitor {
return;
}

if (apiStructuredType.kind !== ApiStructuredTypeKind.TypeLiteral) {
if (apiStructuredType.kind !== ApiItemKind.TypeLiteral) {
this._writeJsdocSynopsis(apiStructuredType);
}

Expand Down
8 changes: 4 additions & 4 deletions api-extractor/src/generators/ApiJsonGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import * as path from 'path';
import * as ts from 'typescript';

import Extractor from '../Extractor';
import ApiStructuredType, { ApiStructuredTypeKind } from '../definitions/ApiStructuredType';
import ApiStructuredType from '../definitions/ApiStructuredType';
import ApiEnum from '../definitions/ApiEnum';
import ApiEnumValue from '../definitions/ApiEnumValue';
import ApiFunction from '../definitions/ApiFunction';
import ApiItem from '../definitions/ApiItem';
import ApiItem, { ApiItemKind } from '../definitions/ApiItem';
import ApiItemVisitor from '../ApiItemVisitor';
import ApiPackage from '../definitions/ApiPackage';
import ApiParameter from '../definitions/ApiParameter';
Expand Down Expand Up @@ -73,8 +73,8 @@ export default class ApiJsonGenerator extends ApiItemVisitor {

protected visitApiStructuredType(apiStructuredType: ApiStructuredType, refObject?: Object): void {
const kind: string =
apiStructuredType.kind === ApiStructuredTypeKind.Class ? ApiJsonGenerator._KIND_CLASS :
apiStructuredType.kind === ApiStructuredTypeKind.Interface ? ApiJsonGenerator._KIND_INTERFACE :
apiStructuredType.kind === ApiItemKind.Class ? ApiJsonGenerator._KIND_CLASS :
apiStructuredType.kind === ApiItemKind.Interface ? ApiJsonGenerator._KIND_INTERFACE :
'';

const structureNode: Object = {
Expand Down
10 changes: 10 additions & 0 deletions common/changes/dagaeta-ApiItemKind_2017-02-01-01-12.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/api-extractor",
"comment": "Added ApiItemKind enum and refactored child classes.",
"type": "patch"
}
],
"email": "dagaeta@users.noreply.github.com"
}
2 changes: 1 addition & 1 deletion common/reviews/api/gulp-core-build-webpack.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class WebpackTask extends GulpTask<IWebpackTaskConfig> {
// (undocumented)
public isEnabled(buildConfig: IBuildConfig): boolean;
// (undocumented)
protected loadSchema(): Object;
public loadSchema(): Object;
// (undocumented)
public name: string;
// (undocumented)
Expand Down
2 changes: 1 addition & 1 deletion common/reviews/api/node-library-build.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class TypeScriptTask extends GulpTask<ITypeScriptTaskConfig> {
// (undocumented)
getCleanMatch(buildConfig: IBuildConfig, taskConfig?: ITypeScriptTaskConfig): string[];
// (undocumented)
protected loadSchema(): Object;
loadSchema(): Object;
mergeConfig(config: ITypeScriptTaskConfig): void;
// (undocumented)
name: string;
Expand Down
4 changes: 2 additions & 2 deletions common/reviews/api/web-library-build.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class TypeScriptTask extends GulpTask<ITypeScriptTaskConfig> {
// (undocumented)
getCleanMatch(buildConfig: IBuildConfig, taskConfig?: ITypeScriptTaskConfig): string[];
// (undocumented)
protected loadSchema(): Object;
loadSchema(): Object;
mergeConfig(config: ITypeScriptTaskConfig): void;
// (undocumented)
name: string;
Expand All @@ -224,7 +224,7 @@ class WebpackTask extends GulpTask<IWebpackTaskConfig> {
// (undocumented)
isEnabled(buildConfig: IBuildConfig): boolean;
// (undocumented)
protected loadSchema(): Object;
loadSchema(): Object;
// (undocumented)
name: string;
// (undocumented)
Expand Down