Skip to content

Commit

Permalink
Merge pull request #89 from SimplrJS/dev
Browse files Browse the repository at this point in the history
v4.0.0-beta.5
  • Loading branch information
Martynas Žilinskas authored Jan 16, 2018
2 parents 4a92793 + fbc7b3e commit 4b6f1ee
Show file tree
Hide file tree
Showing 109 changed files with 896 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-extractor",
"version": "4.0.0-beta.4",
"version": "4.0.0-beta.5",
"description": "TypeScript AST extractor to useful JSON structure.",
"keywords": [
"typescript",
Expand Down
3 changes: 3 additions & 0 deletions src/abstractions/api-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export abstract class ApiItem<TDeclaration extends ts.Declaration = ts.Declarati
return this.ItemStatus;
}

/**
* It gives precise TypeScript information about item after extracting.
*/
protected GetTsDebugInfo(): TypeScriptTypeDeclarationDebug | undefined {
if (this.Options.ExtractorOptions.IncludeTsDebugInfo) {
return {
Expand Down
17 changes: 17 additions & 0 deletions src/api-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,21 @@ export namespace ApiHelpers {
IsExternalPackage: isExternalPackage
};
}

/**
* Get parent reference id from declaration.
*/
export function GetParentIdFromDeclaration(declaration: ts.Declaration, options: ApiItemOptions): string | undefined {
const parentDeclaration = declaration.parent as ts.Declaration;
if (parentDeclaration == null) {
return undefined;
}

const parentSymbol = TSHelpers.GetSymbolFromDeclaration(parentDeclaration, options.Program.getTypeChecker());
if (parentSymbol == null) {
return undefined;
}

return ApiHelpers.GetItemId(parentDeclaration, parentSymbol, options);
}
}
7 changes: 7 additions & 0 deletions src/contracts/api-base-item-dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,12 @@ export interface ApiBaseItemDto {
ApiKind: ApiItemKinds;
Metadata: ApiMetadataDto;
Location: ApiItemLocationDto;
/**
* Parent reference id.
*/
ParentId: string | undefined;
/**
* TypeScript debug info.
*/
_ts?: TypeScriptTypeDeclarationDebug;
}
2 changes: 2 additions & 0 deletions src/definitions/api-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { ApiItemLocationDto } from "../contracts/api-item-location-dto";

export class ApiCall extends ApiCallableBase<ts.CallSignatureDeclaration, ApiCallDto> {
public OnExtract(): ApiCallDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.Call,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
IsOverloadBase: this.IsOverloadBase,
Expand Down
2 changes: 2 additions & 0 deletions src/definitions/api-class-constructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ export class ApiClassConstructor extends ApiItem<ts.ConstructorDeclaration, ApiC
}

public OnExtract(): ApiClassConstructorDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.ClassConstructor,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
IsOverloadBase: this.isOverloadBase,
Expand Down
2 changes: 2 additions & 0 deletions src/definitions/api-class-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ export class ApiClassMethod extends ApiCallableBase<ts.MethodDeclaration, ApiCla
}

public OnExtract(): ApiClassMethodDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.ClassMethod,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
IsOverloadBase: this.IsOverloadBase,
Expand Down
2 changes: 2 additions & 0 deletions src/definitions/api-class-property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ export class ApiClassProperty extends ApiItem<ts.PropertyDeclaration, ApiClassPr
}

public OnExtract(): ApiClassPropertyDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.ClassProperty,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
AccessModifier: this.accessModifier,
Expand Down
2 changes: 2 additions & 0 deletions src/definitions/api-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ export class ApiClass extends ApiItem<ts.ClassDeclaration, ApiClassDto> {
}

public OnExtract(): ApiClassDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.Class,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
IsAbstract: this.isAbstract,
Expand Down
2 changes: 2 additions & 0 deletions src/definitions/api-construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import { ApiItemLocationDto } from "../contracts/api-item-location-dto";

export class ApiConstruct extends ApiCallableBase<ts.ConstructSignatureDeclaration | ts.ConstructorTypeNode, ApiConstructDto> {
public OnExtract(): ApiConstructDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.Construct,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
IsOverloadBase: this.IsOverloadBase,
Expand Down
2 changes: 2 additions & 0 deletions src/definitions/api-enum-member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ export class ApiEnumMember extends ApiItem<ts.EnumMember, ApiEnumMemberDto> {
}

public OnExtract(): ApiEnumMemberDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);
const value: string = this.GetValue();

return {
ApiKind: ApiItemKinds.EnumMember,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
Value: value,
Expand Down
2 changes: 2 additions & 0 deletions src/definitions/api-enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ export class ApiEnum extends ApiItem<ts.EnumDeclaration, ApiEnumDto> {
}

public OnExtract(): ApiEnumDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.Enum,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
IsConst: this.isConst,
Expand Down
2 changes: 2 additions & 0 deletions src/definitions/api-export-specifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ export class ApiExportSpecifier extends ApiItem<ts.ExportSpecifier, ApiExportSpe
}

public OnExtract(): ApiExportSpecifierDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.ExportSpecifier,
Name: this.Declaration.name.getText(),
ParentId: parentId,
Metadata: metadata,
Location: location,
ApiItems: this.apiItems,
Expand Down
2 changes: 2 additions & 0 deletions src/definitions/api-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ export class ApiExport extends ApiItem<ts.ExportDeclaration, ApiExportDto> {
}

public OnExtract(): ApiExportDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const exportPath: string | undefined = this.getExportPath();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.Export,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
SourceFileId: this.sourceFileId,
Expand Down
2 changes: 2 additions & 0 deletions src/definitions/api-function-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { ApiItemLocationDto } from "../contracts/api-item-location-dto";

export class ApiFunctionType extends ApiCallableBase<ts.FunctionTypeNode, ApiFunctionTypeDto> {
public OnExtract(): ApiFunctionTypeDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.FunctionType,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
IsOverloadBase: this.IsOverloadBase,
Expand Down
2 changes: 2 additions & 0 deletions src/definitions/api-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ export class ApiFunction extends ApiCallableBase<ts.FunctionDeclaration, ApiFunc
}

public OnExtract(): ApiFunctionDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.Function,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
IsOverloadBase: this.IsOverloadBase,
Expand Down
2 changes: 2 additions & 0 deletions src/definitions/api-get-accessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ export class ApiGetAccessor extends ApiItem<ts.GetAccessorDeclaration, ApiGetAcc
}

public OnExtract(): ApiGetAccessorDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.GetAccessor,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
AccessModifier: this.accessModifier,
Expand Down
2 changes: 2 additions & 0 deletions src/definitions/api-import-specifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ export class ApiImportSpecifier extends ApiItem<ts.ImportSpecifier, ApiImportSpe
}

public OnExtract(): ApiImportSpecifierDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.ImportSpecifier,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
ApiItems: this.apiItems,
Expand Down
2 changes: 2 additions & 0 deletions src/definitions/api-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ export class ApiIndex extends ApiItem<ts.IndexSignatureDeclaration, ApiIndexDto>
}

public OnExtract(): ApiIndexDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.Index,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
Parameter: this.parameter,
Expand Down
2 changes: 2 additions & 0 deletions src/definitions/api-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ export class ApiInterface extends ApiItem<ts.InterfaceDeclaration, ApiInterfaceD
}

public OnExtract(): ApiInterfaceDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.Interface,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
Members: this.members,
Expand Down
2 changes: 2 additions & 0 deletions src/definitions/api-mapped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ export class ApiMapped extends ApiItem<ts.MappedTypeNode, ApiMappedDto> {
}

public OnExtract(): ApiMappedDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.Mapped,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
TypeParameter: this.typeParameter,
Expand Down
2 changes: 2 additions & 0 deletions src/definitions/api-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ export class ApiMethod extends ApiCallableBase<ts.MethodSignature, ApiMethodDto>
}

public OnExtract(): ApiMethodDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.Method,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
IsOverloadBase: this.IsOverloadBase,
Expand Down
2 changes: 2 additions & 0 deletions src/definitions/api-namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ export class ApiNamespace extends ApiItem<ts.ModuleDeclaration | ts.NamespaceImp
}

public OnExtract(): ApiNamespaceDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.Namespace,
Name: this.Declaration.name.getText(),
ParentId: parentId,
Metadata: metadata,
Location: location,
Members: this.members,
Expand Down
2 changes: 2 additions & 0 deletions src/definitions/api-parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ export class ApiParameter extends ApiItem<ts.ParameterDeclaration, ApiParameterD
}

public OnExtract(): ApiParameterDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.Parameter,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
IsOptional: this.isOptional,
Expand Down
2 changes: 2 additions & 0 deletions src/definitions/api-property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ export class ApiProperty extends ApiItem<ts.PropertySignature, ApiPropertyDto> {
}

public OnExtract(): ApiPropertyDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.Property,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
IsOptional: this.isOptional,
Expand Down
2 changes: 2 additions & 0 deletions src/definitions/api-set-accessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ export class ApiSetAccessor extends ApiItem<ts.SetAccessorDeclaration, ApiSetAcc
}

public OnExtract(): ApiSetAccessorDto {
const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options);
const metadata: ApiMetadataDto = this.GetItemMetadata();
const location: ApiItemLocationDto = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);

return {
ApiKind: ApiItemKinds.SetAccessor,
Name: this.Symbol.name,
ParentId: parentId,
Metadata: metadata,
Location: location,
AccessModifier: this.accessModifier,
Expand Down
Loading

0 comments on commit 4b6f1ee

Please sign in to comment.