forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAstModule.ts
More file actions
54 lines (46 loc) · 2.16 KB
/
AstModule.ts
File metadata and controls
54 lines (46 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
/* tslint:disable:no-bitwise */
import * as ts from 'typescript';
import { IAstItemOptions } from './AstItem';
import { AstItemContainer } from './AstItemContainer';
import { TypeScriptHelpers } from '../utils/TypeScriptHelpers';
import { AstStructuredType } from './AstStructuredType';
import { AstEnum } from './AstEnum';
import { AstFunction } from './AstFunction';
/**
* This is an abstract base class for AstPackage and AstNamespace.
*/
export abstract class AstModule extends AstItemContainer {
protected processModuleExport(exportSymbol: ts.Symbol): void {
const followedSymbol: ts.Symbol = TypeScriptHelpers.followAliases(exportSymbol, this.typeChecker);
if (!followedSymbol.declarations) {
// This is an API Extractor bug, but it could happen e.g. if we upgrade to a new
// version of the TypeScript compiler that introduces new AST variations that we
// haven't tested before.
this.reportWarning(`Definition with no declarations: ${exportSymbol.name}`);
return;
}
for (const declaration of followedSymbol.declarations) {
const options: IAstItemOptions = {
context: this.context,
declaration,
declarationSymbol: followedSymbol,
exportSymbol
};
if (followedSymbol.flags & (ts.SymbolFlags.Class | ts.SymbolFlags.Interface)) {
this.addMemberItem(new AstStructuredType(options));
} else if (followedSymbol.flags & (ts.SymbolFlags.ValueModule | ts.SymbolFlags.NamespaceModule)) {
this.addMemberItem(new AstNamespace(options)); // tslint:disable-line:no-use-before-declare
} else if (followedSymbol.flags & ts.SymbolFlags.Function) {
this.addMemberItem(new AstFunction(options));
} else if (followedSymbol.flags & ts.SymbolFlags.Enum) {
this.addMemberItem(new AstEnum(options));
} else {
this.reportWarning(`Unsupported export: ${exportSymbol.name}`);
}
}
}
}
// This is defer imported to break the circular dependency
import { AstNamespace } from './AstNamespace';