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

[TypeScript Parser] support release tags #6047

Merged
merged 3 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 23 additions & 2 deletions tools/apiview/parsers/js-api-parser/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
ApiItem,
ApiItemKind,
ApiDeclaredItem,
ExcerptTokenKind
ExcerptTokenKind,
ReleaseTag
} from '@microsoft/api-extractor-model';

import { writeFile } from 'fs';
Expand All @@ -15,6 +16,15 @@ function appendMembers(builder: TokensBuilder, navigation: IApiViewNavItem[], it
{
builder.lineId(item.canonicalReference.toString());
builder.indent();
const releaseTag = getReleaseTag(item);
const parentReleaseTag = getReleaseTag(item.parent);
if(releaseTag && releaseTag !== parentReleaseTag) {
if(item.parent.kind === ApiItemKind.EntryPoint) {
builder.newline();
}
builder.annotate(releaseTag);
}

if (item instanceof ApiDeclaredItem) {
if ( item.kind === ApiItemKind.Namespace) {
builder.splitAppend(`declare namespace ${item.displayName} `, item.canonicalReference.toString(), item.displayName);
Expand Down Expand Up @@ -95,6 +105,17 @@ function appendMembers(builder: TokensBuilder, navigation: IApiViewNavItem[], it
}
}

function getReleaseTag(item: ApiItem & {releaseTag?: ReleaseTag}): "alpha" | "beta" | undefined {
switch(item.releaseTag) {
case ReleaseTag.Beta:
return "beta";
case ReleaseTag.Alpha:
return "alpha";
default:
return undefined;
}
}

const apiModel = new ApiModel();
const fileName = process.argv[2];
var versionString = "";
Expand Down Expand Up @@ -125,7 +146,7 @@ var apiViewFile: IApiViewFile = {
Navigation: navigation,
Tokens: builder.tokens,
PackageName: apiModel.packages[0].name,
VersionString: "1.0.3",
VersionString: "1.0.4",
Language: "JavaScript"
}

Expand Down
11 changes: 11 additions & 0 deletions tools/apiview/parsers/js-api-parser/tokensBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import {ApiViewTokenKind, IApiViewToken} from './models';

const jsTokens = require("js-tokens");
const ANNOTATION_TOKEN = "@";

export class TokensBuilder
{
Expand Down Expand Up @@ -72,6 +73,16 @@ export class TokensBuilder
"keyof",
"readonly"];

annotate(value: string): TokensBuilder {
this.tokens.push({
Kind: ApiViewTokenKind.StringLiteral,
Value: `${ANNOTATION_TOKEN}${value}`,
});

this.newline().indent()
return this;
}

indent(): TokensBuilder
{
this.tokens.push({
Expand Down