Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit bc2670d

Browse files
author
Martynas Žilinskas
authored
Merge pull request #96 from SimplrJS/dev
v4.0.0-beta.8
2 parents 35626d0 + e2c8025 commit bc2670d

File tree

142 files changed

+3263
-845
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+3263
-845
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-extractor",
3-
"version": "4.0.0-beta.7",
3+
"version": "4.0.0-beta.8",
44
"description": "TypeScript AST extractor to useful JSON structure.",
55
"keywords": [
66
"typescript",

src/abstractions/api-callable-base.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,30 @@ import { ApiItem } from "../abstractions/api-item";
33

44
import { ApiHelpers } from "../api-helpers";
55
import { ApiItemReference } from "../contracts/api-item-reference";
6-
import { ApiType } from "../contracts/api-type";
7-
import { ApiCallableDto } from "../contracts/api-callable-dto";
6+
import { ApiType } from "../contracts/api-types";
7+
import { ApiCallableBaseDefinition } from "../contracts/api-definitions";
88
import { ApiTypeHelpers } from "../api-type-helpers";
9+
import { ApiItemLocationDto } from "../contracts";
910

1011
/**
1112
* A callable api item base.
1213
*/
1314
export abstract class ApiCallableBase<
1415
TDeclaration extends ts.SignatureDeclaration,
15-
TExtractDto extends ApiCallableDto
16+
TExtractDto extends ApiCallableBaseDefinition
1617
>
1718
extends ApiItem<TDeclaration, TExtractDto> {
1819

1920
protected IsOverloadBase: boolean;
2021
protected Parameters: ApiItemReference[] = [];
2122
protected TypeParameters: ApiItemReference[] = [];
2223
protected ReturnType: ApiType | undefined;
24+
protected Location: ApiItemLocationDto;
2325

2426
protected OnGatherData(): void {
27+
// ApiItemLocation
28+
this.Location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options);
29+
2530
// Overload
2631
this.IsOverloadBase = this.TypeChecker.isImplementationOfOverload(this.Declaration as ts.FunctionLike) || false;
2732

@@ -38,7 +43,7 @@ export abstract class ApiCallableBase<
3843
if (signature != null) {
3944
const type = this.TypeChecker.getReturnTypeOfSignature(signature);
4045

41-
this.ReturnType = ApiTypeHelpers.ResolveApiType(this.Options, type, this.Declaration.type);
46+
this.ReturnType = ApiTypeHelpers.ResolveApiType(this.Options, this.Location, type, this.Declaration.type);
4247
}
4348
}
4449
}

src/abstractions/api-item.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as ts from "typescript";
22

3-
import { ApiBaseItemDto, TypeScriptTypeDeclarationDebug } from "../contracts/api-base-item-dto";
3+
import { ApiBaseDefinition, TypeScriptTypeDeclarationDebug } from "../contracts/api-definitions";
44
import { ApiMetadataDto } from "../contracts/api-metadata-dto";
55
import { ExtractorOptions } from "../contracts/extractor-options";
66
import { ReadonlyRegistry } from "../contracts/registry";
@@ -20,7 +20,7 @@ export enum ApiItemStatus {
2020
GatheredAndExtracted = Gathered | Extracted
2121
}
2222

23-
export abstract class ApiItem<TDeclaration extends ts.Declaration = ts.Declaration, TExtractDto = ApiBaseItemDto> {
23+
export abstract class ApiItem<TDeclaration extends ts.Declaration = ts.Declaration, TExtractDto = ApiBaseDefinition> {
2424
constructor(private declaration: TDeclaration, private symbol: ts.Symbol, private options: ApiItemOptions) {
2525
this.TypeChecker = options.Program.getTypeChecker();
2626
}

src/api-helpers.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ApiItem, ApiItemOptions } from "./abstractions/api-item";
66

77
import { ApiItemReference } from "./contracts/api-item-reference";
88
import { AccessModifier } from "./contracts/access-modifier";
9-
import { TSHelpers } from "./ts-helpers";
9+
import { TsHelpers } from "./ts-helpers";
1010
import { Logger } from "./utils/logger";
1111
import { ApiItemLocationDto } from "./contracts/api-item-location-dto";
1212

@@ -35,7 +35,7 @@ import { ApiCall } from "./definitions/api-call";
3535
import { ApiConstruct } from "./definitions/api-construct";
3636
import { ApiTypeParameter } from "./definitions/api-type-parameter";
3737
import { ApiTypeLiteral } from "./definitions/api-type-literal";
38-
import { ApiFunctionType } from "./definitions/api-function-type";
38+
import { ApiFunctionExpression } from "./definitions/api-function-expression";
3939
import { ApiMapped } from "./definitions/api-mapped";
4040
import { PathIsInside } from "./utils/path-is-inside";
4141

@@ -97,7 +97,7 @@ export namespace ApiHelpers {
9797
} else if (ts.isTypeLiteralNode(declaration) || ts.isObjectLiteralExpression(declaration)) {
9898
apiItem = new ApiTypeLiteral(declaration, symbol, options);
9999
} else if (ts.isFunctionTypeNode(declaration) || ts.isArrowFunction(declaration) || ts.isFunctionExpression(declaration)) {
100-
apiItem = new ApiFunctionType(declaration, symbol, options);
100+
apiItem = new ApiFunctionExpression(declaration, symbol, options);
101101
} else if (ts.isMappedTypeNode(declaration)) {
102102
apiItem = new ApiMapped(declaration, symbol, options);
103103
}
@@ -147,7 +147,7 @@ export namespace ApiHelpers {
147147
return options.Registry.GetDeclarationId(declaration);
148148
}
149149

150-
const resolveRealSymbol = TSHelpers.FollowSymbolAliases(symbol, options.Program.getTypeChecker());
150+
const resolveRealSymbol = TsHelpers.FollowSymbolAliases(symbol, options.Program.getTypeChecker());
151151
const apiItem = VisitApiItem(declaration, resolveRealSymbol, options);
152152
if (apiItem == null) {
153153
return undefined;
@@ -212,7 +212,7 @@ export namespace ApiHelpers {
212212
const typeChecker = options.Program.getTypeChecker();
213213

214214
declarations.forEach(declaration => {
215-
const symbol = TSHelpers.GetSymbolFromDeclaration(declaration, typeChecker);
215+
const symbol = TsHelpers.GetSymbolFromDeclaration(declaration, typeChecker);
216216
if (symbol == null) {
217217
return;
218218
}
@@ -277,6 +277,11 @@ export namespace ApiHelpers {
277277
Logger.Log(logLevel, `${linePrefix}: ${message}`);
278278
}
279279

280+
export function LogWithLocation(logLevel: LogLevel, location: ApiItemLocationDto, message: string): void {
281+
const linePrefix = `${location.FileName}(${location.Line + 1},${location.Character + 1})`;
282+
Logger.Log(logLevel, `${linePrefix}: ${message}`);
283+
}
284+
280285
export function StandardizeRelativePath(location: string, options: ApiItemOptions): string {
281286
const workingSep = options.ExtractorOptions.OutputPathSeparator;
282287
const fixedLocation = location.split(path.sep).join(workingSep);
@@ -326,7 +331,7 @@ export namespace ApiHelpers {
326331
return undefined;
327332
}
328333

329-
const parentSymbol = TSHelpers.GetSymbolFromDeclaration(parentDeclaration, options.Program.getTypeChecker());
334+
const parentSymbol = TsHelpers.GetSymbolFromDeclaration(parentDeclaration, options.Program.getTypeChecker());
330335
if (parentSymbol == null) {
331336
return undefined;
332337
}

src/api-registry.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import * as ts from "typescript";
22
import { ApiItem } from "./abstractions/api-item";
33
import { Dictionary } from "./contracts/dictionary";
44
import { Registry } from "./contracts/registry";
5-
import { ApiItemDto } from "./contracts/api-item-dto";
5+
import { ApiDefinition } from "./contracts/api-definitions";
66

7-
export type ExtractedApiRegistry = Dictionary<ApiItemDto>;
7+
export type ExtractedApiRegistry = Dictionary<ApiDefinition>;
88

99
export class ApiRegistry implements Registry<ApiItem> {
1010
protected registry: Map<string, ApiItem> = new Map<string, ApiItem>();
@@ -20,7 +20,7 @@ export class ApiRegistry implements Registry<ApiItem> {
2020
for (const [key, apiItem] of this.Registry) {
2121
const extractedData = apiItem.Extract(forceExtract);
2222

23-
this.ExtractedData[key] = extractedData as ApiItemDto;
23+
this.ExtractedData[key] = extractedData as ApiDefinition;
2424
}
2525

2626
this.IsDataExtracted = true;

0 commit comments

Comments
 (0)