Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compiler): extract docs for accessors, rest params, and types (#…
…51733) Based on top of #51697 Adds extraction for accessors (getters/setters), rest params, and resolved type info for everything so far. This also refactors function extraction into a new class and splits tests for common class info and directive info into separate files. PR Close #51733
- Loading branch information
1 parent
c7daf7e
commit b9c7015
Showing
8 changed files
with
362 additions
and
187 deletions.
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
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
33 changes: 0 additions & 33 deletions
33
packages/compiler-cli/src/ngtsc/docs/src/function-extractor.ts
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
packages/compiler-cli/src/ngtsc/docs/src/function_extractor.ts
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,47 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {EntryType, FunctionEntry, ParameterEntry} from '@angular/compiler-cli/src/ngtsc/docs/src/entities'; | ||
import ts from 'typescript'; | ||
|
||
import {extractResolvedTypeString} from './type_extractor'; | ||
|
||
export class FunctionExtractor { | ||
constructor( | ||
private declaration: ts.FunctionDeclaration|ts.MethodDeclaration, | ||
private typeChecker: ts.TypeChecker, | ||
) {} | ||
|
||
extract(): FunctionEntry { | ||
// TODO: is there any real situation in which the signature would not be available here? | ||
// Is void a better type? | ||
const signature = this.typeChecker.getSignatureFromDeclaration(this.declaration); | ||
const returnType = signature ? | ||
this.typeChecker.typeToString(this.typeChecker.getReturnTypeOfSignature(signature)) : | ||
'unknown'; | ||
|
||
return { | ||
params: this.extractAllParams(this.declaration.parameters), | ||
// We know that the function has a name here because we would have skipped it | ||
// already before getting to this point if it was anonymous. | ||
name: this.declaration.name!.getText(), | ||
returnType, | ||
entryType: EntryType.function, | ||
}; | ||
} | ||
|
||
private extractAllParams(params: ts.NodeArray<ts.ParameterDeclaration>): ParameterEntry[] { | ||
return params.map(param => ({ | ||
name: param.name.getText(), | ||
description: 'TODO', | ||
type: extractResolvedTypeString(param, this.typeChecker), | ||
isOptional: !!(param.questionToken || param.initializer), | ||
isRestParam: !!param.dotDotDotToken, | ||
})); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/compiler-cli/src/ngtsc/docs/src/type_extractor.ts
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,14 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import ts from 'typescript'; | ||
|
||
/** Gets the string representation of a node's resolved type. */ | ||
export function extractResolvedTypeString(node: ts.Node, checker: ts.TypeChecker): string { | ||
return checker.typeToString(checker.getTypeAtLocation(node)); | ||
} |
Oops, something went wrong.