Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[labs/analyzer] More analysis coverage for gen-manifest (#3529)
* Print diagnostic errors more gracefully to CLI. * Add support for --exclude options (e.g. exclude tests) * Add support for TS enum type variables. * Parse & emit description, summary, and deprecated for all models. * Add support for module-level descriptions. * Add class member analysis. * Fix jsdoc tests. * Add tests * Update goldens * Add changeset * Revert error logging change * Normalize JSDoc parsing for events, fixes Windows issue * Print diagnostic errors more gracefully to CLI * Line ending fixes for Windows * Add tests for module-level JSDoc, and improve logic & comments * Remove heuristic for parsing @summary * Fix @slot to require dash before comment Also fixes accidentally skipped tests re: summary and removes more unused code. * Fix typo in regex * Be more lenient to casing on jsDoc tags. * Update test project JSDoc to match updates to analyzer rules * Address review feedback * Apply suggestions from code review Co-authored-by: Justin Fagnani <justinfagnani@google.com> * Refactor to take advantage of undefined not JSON.serialize'd * Improve naming of model heritage Co-authored-by: Justin Fagnani <justinfagnani@google.com>
- Loading branch information
1 parent
88a4017
commit 389d0c5
Showing
28 changed files
with
1,985 additions
and
654 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
'@lit-labs/analyzer': minor | ||
'@lit-labs/cli': minor | ||
'@lit-labs/gen-manifest': minor | ||
--- | ||
|
||
Added CLI improvements: | ||
|
||
- Add support for --exclude options (important for excluding test files from e.g. manifest or wrapper generation) | ||
|
||
Added more analysis support and manifest emit: | ||
|
||
- TS enum type variables | ||
- description, summary, and deprecated for all models | ||
- module-level description & summary | ||
- ClassField and ClassMethod |
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
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* @license | ||
* Copyright 2022 Google LLC | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
/** | ||
* @fileoverview | ||
* | ||
* Utilities for analyzing function declarations | ||
*/ | ||
|
||
import ts from 'typescript'; | ||
import {DiagnosticsError} from '../errors.js'; | ||
import {AnalyzerInterface, Parameter, Return} from '../model.js'; | ||
import {getTypeForNode, getTypeForType} from '../types.js'; | ||
import {parseJSDocDescription} from './jsdoc.js'; | ||
|
||
/** | ||
* Returns information on FunctionLike nodes | ||
*/ | ||
export const getFunctionLikeInfo = ( | ||
node: ts.FunctionLikeDeclaration, | ||
analyzer: AnalyzerInterface | ||
) => { | ||
return { | ||
parameters: node.parameters.map((p) => getParameter(p, analyzer)), | ||
return: getReturn(node, analyzer), | ||
}; | ||
}; | ||
|
||
const getParameter = ( | ||
param: ts.ParameterDeclaration, | ||
analyzer: AnalyzerInterface | ||
): Parameter => { | ||
const paramTag = ts.getAllJSDocTagsOfKind( | ||
param, | ||
ts.SyntaxKind.JSDocParameterTag | ||
)[0]; | ||
const p: Parameter = { | ||
name: param.name.getText(), | ||
type: getTypeForNode(param, analyzer), | ||
...(paramTag ? parseJSDocDescription(paramTag) : {}), | ||
optional: false, | ||
rest: false, | ||
}; | ||
if (param.initializer !== undefined) { | ||
p.optional = true; | ||
p.default = param.initializer.getText(); | ||
} | ||
if (param.questionToken !== undefined) { | ||
p.optional = true; | ||
} | ||
if (param.dotDotDotToken !== undefined) { | ||
p.rest = true; | ||
} | ||
return p; | ||
}; | ||
|
||
const getReturn = ( | ||
node: ts.FunctionLikeDeclaration, | ||
analyzer: AnalyzerInterface | ||
): Return => { | ||
const returnTag = ts.getAllJSDocTagsOfKind( | ||
node, | ||
ts.SyntaxKind.JSDocReturnTag | ||
)[0]; | ||
const signature = analyzer.program | ||
.getTypeChecker() | ||
.getSignatureFromDeclaration(node); | ||
if (signature === undefined) { | ||
throw new DiagnosticsError( | ||
node, | ||
`Could not get signature to determine return type` | ||
); | ||
} | ||
return { | ||
type: getTypeForType(signature.getReturnType(), node, analyzer), | ||
...(returnTag ? parseJSDocDescription(returnTag) : {}), | ||
}; | ||
}; |
Oops, something went wrong.