Skip to content

Commit

Permalink
Revert "refactor(compiler-cli): extract function overload separatly (a…
Browse files Browse the repository at this point in the history
…ngular#56489)"

This reverts commit 37b88a5.
  • Loading branch information
AndrewKushnir committed Aug 29, 2024
1 parent 1d79cbd commit c864a53
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 41 deletions.
2 changes: 1 addition & 1 deletion packages/compiler-cli/src/ngtsc/docs/src/extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class DocsExtractor {
private getExportedDeclarations(sourceFile: ts.SourceFile): DeclarationWithExportName[] {
// Use the reflection host to get all the exported declarations from this
// source file entry point.
const reflector = new TypeScriptReflectionHost(this.typeChecker, false, true);
const reflector = new TypeScriptReflectionHost(this.typeChecker);
const exportedDeclarationMap = reflector.getExportsOfModule(sourceFile);

// Augment each declaration with the exported name in the public API.
Expand Down
16 changes: 3 additions & 13 deletions packages/compiler-cli/src/ngtsc/reflection/src/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,9 @@ import {isNamedClassDeclaration} from './util';
*/

export class TypeScriptReflectionHost implements ReflectionHost {
/**
* @param skipPrivateValueDeclarationTypes Avoids using a value declaration that is considered private (using a ɵ-prefix),
* instead using the first available declaration. This is needed for the {@link FormControl} API of
* which the type declaration documents the type and the value declaration corresponds with an implementation detail.
*/
constructor(
protected checker: ts.TypeChecker,
private readonly isLocalCompilation = false,
private readonly skipPrivateValueDeclarationTypes: boolean = false,
) {}

getDecoratorsOfDeclaration(declaration: DeclarationNode): Decorator[] | null {
Expand Down Expand Up @@ -404,13 +398,9 @@ export class TypeScriptReflectionHost implements ReflectionHost {
symbol = this.checker.getAliasedSymbol(symbol);
}

const symbolType = this.checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration!);
// Look at the resolved Symbol's declarations and pick one of them to return.
// Value declarations are given precedence over type declarations if not specified otherwise
if (
symbol.valueDeclaration !== undefined &&
(!this.skipPrivateValueDeclarationTypes || symbolType?.symbol?.name.startsWith('ɵ') !== true)
) {
// Look at the resolved Symbol's declarations and pick one of them to return. Value declarations
// are given precedence over type declarations.
if (symbol.valueDeclaration !== undefined) {
return {
node: symbol.valueDeclaration,
viaModule: this._viaModule(symbol.valueDeclaration, originalId, importInfo),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,5 @@ runInEachFileSystem(() => {
const docs: DocEntry[] = env.driveDocsExtraction('index.ts');
expect(docs.length).toBe(0);
});

it('should extract the type declaration if the value declaration is private', () => {
env.write(
'index.ts',
`
/**
* Documented
*/
export interface FormControl<T> {
name: string;
}
export interface ɵFormControlCtor {
new (): FormControl<any>;
}
export const FormControl: ɵFormControlCtor = class FormControl<TValue = any> {
}
`,
);

const docs: DocEntry[] = env.driveDocsExtraction('index.ts');
expect(docs.length).toBe(1);
expect(docs[0].name).toBe('FormControl');
expect(docs[0].rawComment).toMatch(/Documented/);
});
});
});

0 comments on commit c864a53

Please sign in to comment.