-
Notifications
You must be signed in to change notification settings - Fork 597
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] add basic support for import * as module from './local-module'
#1796
Merged
Merged
Changes from 5 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
efdde26
added support for 'import * as module from ./local-module'
mckn 1a94da5
added change description.
mckn 79b397e
fixed so we return a proper error messae.
mckn 6e8b0e2
fixed build errors.
mckn 9c3d85a
added missing annotation.
mckn ec5757a
fixed feedback on pr.
mckn a4ea1c1
added tests.
mckn 90032e9
merged master into branch.
mckn 64e2c66
fixed version missmatch.
mckn c88df79
Convert "api-extractor-test-no-report" to be a scenario test
octogonz dc9bb83
Convert test functions to be stereotypical functions instead of lambd…
octogonz 24ddf89
Merge remote-tracking branch 'remotes/origin/master' into octogonz/ex…
octogonz 0b81dfb
Adjust changelog
octogonz 3651886
Improve test to show how top-level name conflicts are handled
octogonz de80229
Show how aliases are handled
octogonz dd449f4
Refactor AstEntity into a proper base class
octogonz 04a5563
Merge remote-tracking branch 'remotes/origin/release/master-before-pr…
octogonz 11db642
Reapply Prettier following the steps in this comment:
octogonz 872bccb
Merge remote-tracking branch 'remotes/origin/master' into export-star…
octogonz 9481016
Fix lint warnings from merge
octogonz 828baad
Some minor cleanups (no semantic changes)
octogonz 4fbadd8
Add class documentation, rename "exportName" to "namespaceName"
octogonz cfc693c
Rename AstImportAsModule --> AstNamespaceImport because that's what t…
octogonz 2e75e83
Rename AstImportAsModule --> AstNamespaceImport because that's what t…
octogonz b2fa123
Tune up the code for generating the .d.ts rollup and add a location f…
octogonz 857a27a
Start work on generating an API report for namespace imports
octogonz cdc1678
Merge branch 'master' into export-star-as-support
mckn 88ce9ca
fixed issue in change log.
mckn 7ff319d
Merge remote-tracking branch 'remotes/origin/master' into export-star…
octogonz 615a387
rush build
octogonz 2e100e6
Update lockfile
octogonz 8cac97b
Include /// directives in API report, since they are relevant to API …
octogonz 66636f4
Introduce CollectorEntity.consumable distinction to ensure that AstNa…
octogonz ec267b3
Fix an issue where DocCommentEnhancer was skipping AstNamespaceImport…
octogonz 0ba9748
Eliminate trailing comma
octogonz 51acb54
Add a second test case
octogonz 12799aa
Implement the missing ae-forgotten-export analysis for AstNamespaceIm…
octogonz fcc005a
Update change log
octogonz 73a3498
Improve the error message for not yet supported "export * as ___ from…
octogonz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
// See LICENSE in the project root for license information. | ||
|
||
import { AstModule } from './AstModule'; | ||
|
||
export interface IAstImportAsModuleOptions { | ||
readonly astModule: AstModule; | ||
readonly exportName: string; | ||
} | ||
|
||
// TODO [MA]: add documentation | ||
export class AstImportAsModule { | ||
// TODO [MA]: add documentation | ||
public analyzed: boolean = false; | ||
|
||
// TODO [MA]: add documentation | ||
public readonly astModule: AstModule; | ||
|
||
/** | ||
* The name of the symbol being imported. | ||
* | ||
* @remarks | ||
* | ||
* The name depends on the type of import: | ||
* | ||
* ```ts | ||
* // For AstImportKind.DefaultImport style, exportName would be "X" in this example: | ||
* import X from "y"; | ||
* | ||
* // For AstImportKind.NamedImport style, exportName would be "X" in this example: | ||
* import { X } from "y"; | ||
* | ||
* // For AstImportKind.StarImport style, exportName would be "x" in this example: | ||
* import * as x from "y"; | ||
* | ||
* // For AstImportKind.EqualsImport style, exportName would be "x" in this example: | ||
* import x = require("y"); | ||
* ``` | ||
*/ | ||
public readonly exportName: string; | ||
|
||
public constructor(options: IAstImportAsModuleOptions) { | ||
this.astModule = options.astModule; | ||
this.exportName = options.exportName; | ||
} | ||
|
||
public get localName(): string { | ||
return this.exportName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,12 @@ import { AstModule, AstModuleExportInfo } from './AstModule'; | |
import { PackageMetadataManager } from './PackageMetadataManager'; | ||
import { ExportAnalyzer } from './ExportAnalyzer'; | ||
import { AstImport } from './AstImport'; | ||
import { AstImportAsModule } from './AstImportAsModule'; | ||
import { MessageRouter } from '../collector/MessageRouter'; | ||
import { TypeScriptInternals } from './TypeScriptInternals'; | ||
import { StringChecks } from './StringChecks'; | ||
|
||
export type AstEntity = AstSymbol | AstImport; | ||
export type AstEntity = AstSymbol | AstImport | AstImportAsModule; | ||
|
||
/** | ||
* Options for `AstSymbolTable._fetchAstSymbol()` | ||
|
@@ -137,43 +138,13 @@ export class AstSymbolTable { | |
* or members. (We do always construct its parents however, since AstDefinition.parent | ||
* is immutable, and needed e.g. to calculate release tag inheritance.) | ||
*/ | ||
public analyze(astSymbol: AstSymbol): void { | ||
if (astSymbol.analyzed) { | ||
return; | ||
public analyze(astEntity: AstEntity): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You've opened |
||
if (astEntity instanceof AstSymbol) { | ||
return this._analyzeAstSymbol(astEntity); | ||
} | ||
|
||
if (astSymbol.nominalAnalysis) { | ||
// We don't analyze nominal symbols | ||
astSymbol._notifyAnalyzed(); | ||
return; | ||
} | ||
|
||
// Start at the root of the tree | ||
const rootAstSymbol: AstSymbol = astSymbol.rootAstSymbol; | ||
|
||
// Calculate the full child tree for each definition | ||
for (const astDeclaration of rootAstSymbol.astDeclarations) { | ||
this._analyzeChildTree(astDeclaration.declaration, astDeclaration); | ||
} | ||
|
||
rootAstSymbol._notifyAnalyzed(); | ||
|
||
if (!astSymbol.isExternal) { | ||
// If this symbol is non-external (i.e. it belongs to the working package), then we also analyze any | ||
// referencedAstSymbols that are non-external. For example, this ensures that forgotten exports | ||
// get analyzed. | ||
rootAstSymbol.forEachDeclarationRecursive((astDeclaration: AstDeclaration) => { | ||
for (const referencedAstEntity of astDeclaration.referencedAstEntities) { | ||
|
||
// Walk up to the root of the tree, looking for any imports along the way | ||
if (referencedAstEntity instanceof AstSymbol) { | ||
if (!referencedAstEntity.isExternal) { | ||
this.analyze(referencedAstEntity); | ||
} | ||
} | ||
|
||
} | ||
}); | ||
if (astEntity instanceof AstImportAsModule) { | ||
return this._analyzeAstImportAsModule(astEntity); | ||
} | ||
} | ||
|
||
|
@@ -292,6 +263,71 @@ export class AstSymbolTable { | |
return unquotedName; | ||
} | ||
|
||
|
||
private _analyzeAstImportAsModule(astImportAsModule: AstImportAsModule): void { | ||
if (astImportAsModule.analyzed) { | ||
return; | ||
} | ||
|
||
// mark before actual analyzing, to handle module cyclic reexport | ||
astImportAsModule.analyzed = true; | ||
|
||
this.fetchAstModuleExportInfo(astImportAsModule.astModule).exportedLocalEntities.forEach(exportedEntity => { | ||
if (exportedEntity instanceof AstImportAsModule) { | ||
this._analyzeAstImportAsModule(exportedEntity); | ||
} | ||
|
||
if (exportedEntity instanceof AstSymbol) { | ||
this._analyzeAstSymbol(exportedEntity); | ||
} | ||
}); | ||
} | ||
|
||
private _analyzeAstSymbol(astSymbol: AstSymbol): void { | ||
if (astSymbol.analyzed) { | ||
return; | ||
} | ||
|
||
if (astSymbol.nominalAnalysis) { | ||
// We don't analyze nominal symbols | ||
astSymbol._notifyAnalyzed(); | ||
return; | ||
} | ||
|
||
// Start at the root of the tree | ||
const rootAstSymbol: AstSymbol = astSymbol.rootAstSymbol; | ||
|
||
// Calculate the full child tree for each definition | ||
for (const astDeclaration of rootAstSymbol.astDeclarations) { | ||
this._analyzeChildTree(astDeclaration.declaration, astDeclaration); | ||
} | ||
|
||
rootAstSymbol._notifyAnalyzed(); | ||
|
||
if (!astSymbol.isExternal) { | ||
// If this symbol is non-external (i.e. it belongs to the working package), then we also analyze any | ||
// referencedAstSymbols that are non-external. For example, this ensures that forgotten exports | ||
// get analyzed. | ||
rootAstSymbol.forEachDeclarationRecursive((astDeclaration: AstDeclaration) => { | ||
for (const referencedAstEntity of astDeclaration.referencedAstEntities) { | ||
|
||
// Walk up to the root of the tree, looking for any imports along the way | ||
if (referencedAstEntity instanceof AstSymbol) { | ||
if (!referencedAstEntity.isExternal) { | ||
this._analyzeAstSymbol(referencedAstEntity); | ||
} | ||
} | ||
|
||
if (referencedAstEntity instanceof AstImportAsModule) { | ||
if (!referencedAstEntity.astModule.isExternal) { | ||
this._analyzeAstImportAsModule(referencedAstEntity) | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Used by analyze to recursively analyze the entire child tree. | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was there a reason to introduce a new class here rather than integrate this capability into
AstSymbol
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or the existing
AstImport
, which hasAstImportKind.StarImport
?