Skip to content

Commit

Permalink
[TypeScript Parser] support release tags (#6047)
Browse files Browse the repository at this point in the history
* support release tags

* remove un needed formatitng

* remove extra line

---------

Co-authored-by: Jose Mauel Heredia Hidalgo <>
  • Loading branch information
joheredi authored Apr 26, 2023
1 parent 1229529 commit a046f15
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
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

0 comments on commit a046f15

Please sign in to comment.