From a046f15f39128cb31aea53ebc591d3fd34fe039d Mon Sep 17 00:00:00 2001 From: Jose Manuel Heredia Hidalgo Date: Tue, 25 Apr 2023 17:24:25 -0700 Subject: [PATCH] [TypeScript Parser] support release tags (#6047) * support release tags * remove un needed formatitng * remove extra line --------- Co-authored-by: Jose Mauel Heredia Hidalgo <> --- tools/apiview/parsers/js-api-parser/export.ts | 25 +++++++++++++++++-- .../parsers/js-api-parser/tokensBuilder.ts | 11 ++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/tools/apiview/parsers/js-api-parser/export.ts b/tools/apiview/parsers/js-api-parser/export.ts index fc41f9c290e..5607e4b152d 100644 --- a/tools/apiview/parsers/js-api-parser/export.ts +++ b/tools/apiview/parsers/js-api-parser/export.ts @@ -3,7 +3,8 @@ import { ApiItem, ApiItemKind, ApiDeclaredItem, - ExcerptTokenKind + ExcerptTokenKind, + ReleaseTag } from '@microsoft/api-extractor-model'; import { writeFile } from 'fs'; @@ -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); @@ -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 = ""; @@ -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" } diff --git a/tools/apiview/parsers/js-api-parser/tokensBuilder.ts b/tools/apiview/parsers/js-api-parser/tokensBuilder.ts index 16de467e4a7..61c6882f8b4 100644 --- a/tools/apiview/parsers/js-api-parser/tokensBuilder.ts +++ b/tools/apiview/parsers/js-api-parser/tokensBuilder.ts @@ -2,6 +2,7 @@ import {ApiViewTokenKind, IApiViewToken} from './models'; const jsTokens = require("js-tokens"); +const ANNOTATION_TOKEN = "@"; export class TokensBuilder { @@ -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({