Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api-extractor] Improve symbol analyzer to support "export * from" constructs #1002

Merged
merged 27 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bced506
Initial prototype of improving the symbol analyzer to support "export…
pgonzal Dec 20, 2018
adddd30
Ensure isExternalModuleNameRelative() is called consistently
pgonzal Dec 20, 2018
75d2a90
Fix up ApiModelGenerator and ReviewFileGenerator to handle reexported…
pgonzal Dec 23, 2018
d0f872e
Update tests after rebase
pgonzal Jan 13, 2019
432d977
Generalize CollectorEntity to support a given declaration being expor…
pgonzal Jan 14, 2019
95a7ae1
Improve exportStar3 test cases
pgonzal Jan 14, 2019
eb7a2cc
Redesign the fundamental symbol following algorithm to solve exportStar3
pgonzal Jan 15, 2019
0a472c3
Move the symbol following code into a separate class ExportAnalyzer.ts
pgonzal Jan 15, 2019
e04e434
Generate all config files even if some of the tests failed
pgonzal Jan 15, 2019
29be5e0
Reintroduce analysis of ImportSpecifier and ImportClause and fix some…
pgonzal Jan 16, 2019
ff512cb
Eliminate the old SymbolAnalyzer class
pgonzal Jan 16, 2019
e8842dd
Emit "export * from" in .d.ts rollup and .api.ts
pgonzal Jan 16, 2019
b76720a
Reintroduce the declarationName logic
pgonzal Jan 16, 2019
2a00e8e
Implement AstSymboltable.fetchReferencedAstSymbol
pgonzal Jan 16, 2019
3f36ff9
Reintroduce limited support for ts.SyntaxKind.ExportSpecifier
pgonzal Jan 16, 2019
19f0204
Clean up logic
pgonzal Jan 16, 2019
1118a37
Rename "nominal" to "nominalAnalysis" to avoid confusion with nominal…
pgonzal Jan 16, 2019
9c39f61
Rename emitWithExportKeyword to shouldInlineExport
pgonzal Jan 16, 2019
1afcdbd
Split compiler internals into a separate file
pgonzal Jan 16, 2019
2757b66
Improve documentation for new code
pgonzal Jan 17, 2019
5cbb407
Fix typo
pgonzal Jan 17, 2019
5bb4088
rush change
pgonzal Jan 17, 2019
9365de2
rush change
pgonzal Jan 17, 2019
0904681
Normalize newlines in .api.ts files
pgonzal Jan 17, 2019
f2e0fd8
rush change
pgonzal Jan 17, 2019
7af89ee
Merge branch 'master' into pgonzal/ae-export-star
pgonzal Jan 17, 2019
70d4f0b
Normalize newlines in .api.ts files
pgonzal Jan 17, 2019
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
34 changes: 18 additions & 16 deletions apps/api-extractor/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"program": "${workspaceFolder}/lib/start.js",
"cwd": "${workspaceFolder}/../../build-tests/api-extractor-test-01",
"args": [
"-d",
"--debug",
"run",
"-l"
"--local"
],
"sourceMaps": true
},
Expand All @@ -24,9 +24,9 @@
"program": "${workspaceFolder}/lib/start.js",
"cwd": "${workspaceFolder}/../../build-tests/api-extractor-test-02",
"args": [
"-d",
"--debug",
"run",
"-l"
"--local"
],
"sourceMaps": true
},
Expand All @@ -37,9 +37,9 @@
"program": "${workspaceFolder}/lib/start.js",
"cwd": "${workspaceFolder}/../../build-tests/api-extractor-test-03",
"args": [
"-d",
"--debug",
"run",
"-l"
"--local"
],
"sourceMaps": true
},
Expand All @@ -50,9 +50,9 @@
"program": "${workspaceFolder}/lib/start.js",
"cwd": "${workspaceFolder}/../../build-tests/api-extractor-test-04",
"args": [
"-d",
"--debug",
"run",
"-l"
"--local"
],
"sourceMaps": true
},
Expand All @@ -63,22 +63,24 @@
"program": "${workspaceFolder}/lib/start.js",
"cwd": "${workspaceFolder}/../../build-tests/api-extractor-test-05",
"args": [
"-d",
"--debug",
"run",
"-l"
"--local"
],
"sourceMaps": true
},
{
"type": "node",
"request": "launch",
"name": "test-06",
"name": "scenario",
"program": "${workspaceFolder}/lib/start.js",
"cwd": "${workspaceFolder}/../../build-tests/api-extractor-test-06",
"cwd": "${workspaceFolder}/../../build-tests/api-extractor-scenarios",
"args": [
"-d",
"--debug",
"run",
"-l"
"--local",
"--config",
"./temp/configs/api-extractor-defaultExportOfEntryPoint1.json"
],
"sourceMaps": true
},
Expand All @@ -89,9 +91,9 @@
"program": "${workspaceFolder}/lib/start.js",
"cwd": "(your project path)",
"args": [
"-d",
"--debug",
"run",
"-l"
"--local"
],
"sourceMaps": true
}
Expand Down
38 changes: 37 additions & 1 deletion apps/api-extractor/src/analyzer/AstDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface IAstDeclarationOptions {
* of analyzing AEDoc and emitting *.d.ts files.
*
* The AstDeclarations correspond to items from the compiler's ts.Node hierarchy, but
* omitting/skipping any nodes that don't match the SymbolAnalyzer.isAstDeclaration()
* omitting/skipping any nodes that don't match the AstDeclaration.isSupportedSyntaxKind()
* criteria. This simplification makes the other API Extractor stages easier to implement.
*/
export class AstDeclaration {
Expand Down Expand Up @@ -180,4 +180,40 @@ export class AstDeclaration {
child.forEachDeclarationRecursive(action);
}
}

/**
* This function determines which ts.Node kinds will generate an AstDeclaration.
* These correspond to the definitions that we can add AEDoc to.
*/
public static isSupportedSyntaxKind(kind: ts.SyntaxKind): boolean {
// (alphabetical order)
switch (kind) {
case ts.SyntaxKind.CallSignature:
case ts.SyntaxKind.ClassDeclaration:
case ts.SyntaxKind.ConstructSignature: // Example: "new(x: number): IMyClass"
case ts.SyntaxKind.Constructor: // Example: "constructor(x: number)"
case ts.SyntaxKind.EnumDeclaration:
case ts.SyntaxKind.EnumMember:
case ts.SyntaxKind.FunctionDeclaration: // Example: "(x: number): number"
case ts.SyntaxKind.IndexSignature: // Example: "[key: string]: string"
case ts.SyntaxKind.InterfaceDeclaration:
case ts.SyntaxKind.MethodDeclaration:
case ts.SyntaxKind.MethodSignature:
case ts.SyntaxKind.ModuleDeclaration: // Used for both "module" and "namespace" declarations
case ts.SyntaxKind.PropertyDeclaration:
case ts.SyntaxKind.PropertySignature:
case ts.SyntaxKind.TypeAliasDeclaration: // Example: "type Shape = Circle | Square"
case ts.SyntaxKind.VariableDeclaration:
return true;

// NOTE: In contexts where a source file is treated as a module, we do create "nominal"
// AstSymbol objects corresponding to a ts.SyntaxKind.SourceFile node. However, a source file
// is NOT considered a nesting structure, and it does NOT act as a root for the declarations
// appearing in the file. This is because the *.d.ts generator is in the business of rolling up
// source files, and thus wants to ignore them in general.
}

return false;
}

}
29 changes: 0 additions & 29 deletions apps/api-extractor/src/analyzer/AstEntryPoint.ts

This file was deleted.

12 changes: 5 additions & 7 deletions apps/api-extractor/src/analyzer/AstImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,24 @@ export interface IAstImportOptions {
export class AstImport {
/**
* The name of the external package (and possibly module path) that this definition
* was imported from. If it was defined in the referencing source file, or if it was
* imported from a local file, or if it is an ambient definition, then externalPackageName
* will be undefined.
* was imported from.
*
* Example: "@microsoft/gulp-core-build/lib/IBuildConfig"
* Example: "@microsoft/node-core-library/lib/FileSystem"
*/
public readonly modulePath: string;

/**
* If importPackagePath is defined, then this specifies the export name for the definition.
* If modulePath is defined, then this specifies the export name for the definition.
*
* Example: "IBuildConfig"
*/
public readonly exportName: string;

/**
* If importPackagePath and importPackageExportName are defined, then this is a dictionary key
* If modulePath and exportName are defined, then this is a dictionary key
* that combines them with a colon (":").
*
* Example: "@microsoft/gulp-core-build/lib/IBuildConfig:IBuildConfig"
* Example: "@microsoft/node-core-library/lib/FileSystem:FileSystem"
*/
public readonly key: string;

Expand Down
33 changes: 33 additions & 0 deletions apps/api-extractor/src/analyzer/AstModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.

import * as ts from 'typescript';

import { AstSymbol } from './AstSymbol';

/**
*/
export class AstModule {
public readonly sourceFile: ts.SourceFile;

public readonly exportedSymbols: Map<string, AstSymbol>;
public readonly starExportedExternalModules: Set<AstModule>;

/**
* Example: "@microsoft/node-core-library/lib/FileSystem"
* but never: "./FileSystem"
*/
public externalModulePath: string | undefined;

public constructor(sourceFile: ts.SourceFile) {
this.sourceFile = sourceFile;
this.exportedSymbols = new Map<string, AstSymbol>();
this.starExportedExternalModules = new Set<AstModule>();
this.externalModulePath = undefined;
}

public get isExternal(): boolean {
return this.externalModulePath !== undefined;
}

}
4 changes: 3 additions & 1 deletion apps/api-extractor/src/analyzer/AstSymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export class AstSymbol {

/**
* If this symbol was imported from another package, that information is tracked here.
* Otherwise, the value is undefined.
* Otherwise, the value is undefined. For example, if this symbol was defined in the referencing source file,
* or if it was imported from a local file in the current project, or if it is an ambient definition,
* then astImport will be undefined.
*/
public readonly astImport: AstImport | undefined;

Expand Down
Loading