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

[apiview-js-parser] more bug fixes #9184

Merged
merged 13 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
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
14 changes: 13 additions & 1 deletion tools/apiview/parsers/js-api-parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# 2.0.3

- add `SkipDiff: true` for dependency header line
- set related line id for pre-release tags
- add `export const` before constants
- fix leading whitespace issue around punctuation and keyword
- fix type reference issue in multi-line code
- fix contextual keyword in property/method signature
- add "class" renderClass to type parameters
- hide enum members from navigation list
- replace `export declare enum` with `export enum`

# 2.0.2

- fix issue where `type` is not treated as keyword.
Expand All @@ -10,4 +22,4 @@

- Migrate to tree token.

# 1.0.8
# 1.0.8
4 changes: 2 additions & 2 deletions tools/apiview/parsers/js-api-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure-tools/ts-genapi",
"version": "2.0.2",
"version": "2.0.3",
"description": "",
"main": "index.js",
"publishConfig": {
Expand All @@ -25,7 +25,7 @@
"rimraf": "^6.0.1",
"ts-node": "^10.0.0",
"typescript": "~5.6.2",
"typescript-eslint": "^8.6.0"
"typescript-eslint": "^8.11.0"
},
"scripts": {
"build": "npm run clean && tsc -p .",
Expand Down
47 changes: 14 additions & 33 deletions tools/apiview/parsers/js-api-parser/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function buildDependencies(reviewLines: ReviewLine[], dependencies: Record<strin
Value: "Dependencies:",
NavigationDisplayName: "Dependencies",
RenderClasses: ["dependencies"],
SkipDiff: true,
}),
],
};
Expand Down Expand Up @@ -177,13 +178,14 @@ const ANNOTATION_TOKEN = "@";
* Builds review line for a release tag
* @param reviewLines The result array to push {@link ReviewLine}s to
* @param tag release tag
* @param relatedLineId the id of the review line with which the release tag is associated
*/
function buildReleaseTag(reviewLines: ReviewLine[], tag: string): void {
function buildReleaseTag(reviewLines: ReviewLine[], tag: string, relatedLineId: string): void {
const tagToken = buildToken({
Kind: TokenKind.StringLiteral,
Value: `${ANNOTATION_TOKEN}${tag}`,
});
reviewLines.push({ Tokens: [tagToken] });
reviewLines.push({ Tokens: [tagToken], RelatedToLine: relatedLineId });
}

/**
Expand All @@ -200,43 +202,22 @@ function mayHaveChildren(item: ApiItem): boolean {
);
}

/**
* Returns normalized item kind string of an {@link ApiDeclaredItem}
* @param item {@link ApiDeclaredItem} instance
* @returns
*/
function getItemKindString(item: ApiDeclaredItem) {
let itemKind: string = "";
if (mayHaveChildren(item)) {
itemKind = item.kind.toLowerCase();
} else if (item.kind === ApiItemKind.Function) {
itemKind = "method";
} else if (item.kind === ApiItemKind.TypeAlias) {
itemKind = "struct";
}
return itemKind;
}

/**
* Builds the token list for an Api and pushes to the review line that is passed in
* @param line The {@link ReviewLine} to push {@link ReviewToken}s to
* @param item {@link ApiItem} instance
*/
function buildMemberLineTokens(line: ReviewLine, item: ApiItem) {
const itemId = item.canonicalReference.toString();
if (item instanceof ApiDeclaredItem) {
const itemKind: string = getItemKindString(item);

if (item.kind === ApiItemKind.Namespace) {
line.Tokens.push(
...splitAndBuild(
`declare namespace ${item.displayName} `,
itemId,
item.displayName,
itemKind,
),
);
splitAndBuild(line.Tokens, `declare namespace ${item.displayName} `, item);
} else {
if (item.kind === ApiItemKind.Variable) {
line.Tokens.push(
buildToken({ Kind: TokenKind.Keyword, Value: "export", HasSuffixSpace: true }),
buildToken({ Kind: TokenKind.Keyword, Value: "const", HasSuffixSpace: true }),
);
}
if (!item.excerptTokens.some((except) => except.text.includes("\n"))) {
for (const excerpt of item.excerptTokens) {
if (excerpt.kind === ExcerptTokenKind.Reference && excerpt.canonicalReference) {
Expand All @@ -247,11 +228,11 @@ function buildMemberLineTokens(line: ReviewLine, item: ApiItem) {
});
line.Tokens.push(token);
} else {
line.Tokens.push(...splitAndBuild(excerpt.text, itemId, item.displayName, itemKind));
splitAndBuild(line.Tokens, excerpt.text, item);
}
}
} else {
splitAndBuildMultipleLine(line, item.excerptTokens, itemId, item.displayName, itemKind);
splitAndBuildMultipleLine(line, item.excerptTokens, item);
}
}
}
Expand All @@ -275,7 +256,7 @@ function buildMember(reviewLines: ReviewLine[], item: ApiItem) {
const releaseTag = getReleaseTag(item);
const parentReleaseTag = getReleaseTag(item.parent);
if (releaseTag && releaseTag !== parentReleaseTag) {
buildReleaseTag(reviewLines, releaseTag);
buildReleaseTag(reviewLines, releaseTag, line.LineId);
}

buildMemberLineTokens(line, item);
Expand Down
Loading