Skip to content

Commit

Permalink
[js-api-parser] don't add members as types (#7382)
Browse files Browse the repository at this point in the history
* [js-api-parser] Don't add members as types

This PR uses the id of the token to determine whether it should be added as a
member or a type.

* bump js-api-parser version to 1.0.8
  • Loading branch information
jeremymeng authored Jan 29, 2024
1 parent f23c1aa commit e6aec64
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class JavaScriptLanguageService : LanguageProcessor
public override string Name { get; } = "JavaScript";
public override string[] Extensions { get; } = { ".api.json" };
public override string ProcessName { get; } = "node";
public override string VersionString { get; } = "1.0.7";
public override string VersionString { get; } = "1.0.8";

public override string GetProcessorArguments(string originalName, string tempDirectory, string jsonFilePath)
{
Expand Down
10 changes: 5 additions & 5 deletions tools/apiview/parsers/js-api-parser/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function appendMembers(builder: TokensBuilder, navigation: IApiViewNavItem[], it
}
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 @@ -81,7 +81,7 @@ function appendMembers(builder: TokensBuilder, navigation: IApiViewNavItem[], it
.punct("{")
.newline()
.incIndent()

for (const member of item.members) {
appendMembers(builder,navigationItem.ChildItems, member);
}
Expand All @@ -102,7 +102,7 @@ function appendMembers(builder: TokensBuilder, navigation: IApiViewNavItem[], it
}
}
else
{
{
builder.newline();
}
}
Expand Down Expand Up @@ -130,7 +130,7 @@ apiModel.loadPackage(fileName);
var navigation: IApiViewNavItem[] = [];
var builder = new TokensBuilder();

for (const modelPackage of apiModel.packages) {
for (const modelPackage of apiModel.packages) {
for (const entryPoint of modelPackage.entryPoints) {
for (const member of entryPoint.members) {
appendMembers(builder, navigation, member);
Expand All @@ -148,7 +148,7 @@ var apiViewFile: IApiViewFile = {
Navigation: navigation,
Tokens: builder.tokens,
PackageName: apiModel.packages[0].name,
VersionString: "1.0.7",
VersionString: "1.0.8",
Language: "JavaScript",
PackageVersion: PackageversionString
}
Expand Down
2 changes: 1 addition & 1 deletion 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": "1.0.7",
"version": "1.0.8",
"description": "",
"main": "index.js",
"publishConfig": {
Expand Down
22 changes: 17 additions & 5 deletions tools/apiview/parsers/js-api-parser/tokensBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ export class TokensBuilder

incIndent(): TokensBuilder
{
this.indentString = ' '.repeat(this.indentString.length + 4);
this.indentString = ' '.repeat(this.indentString.length + 4);
return this;
}

decIndent(): TokensBuilder
{
this.indentString = ' '.repeat(this.indentString.length - 4);
this.indentString = ' '.repeat(this.indentString.length - 4);
return this;
}

Expand Down Expand Up @@ -185,15 +185,27 @@ export class TokensBuilder
}

var tokens: any[] = Array.from(jsTokens(line));
tokens.forEach(token =>
tokens.forEach(token =>
{
if (this.keywords.indexOf(token.value) > 0)
{
this.keyword(token.value);
}
else if (token.value === currentTypeName)
{
this.tokens.push({ Kind: ApiViewTokenKind.TypeName, DefinitionId: currentTypeId, Value: token.value });
if (currentTypeId.match(/.*:member(\(\d+\))*$/)) {
this.tokens.push({
Kind: ApiViewTokenKind.MemberName,
DefinitionId: currentTypeId,
Value: token.value,
});
} else {
this.tokens.push({
Kind: ApiViewTokenKind.TypeName,
DefinitionId: currentTypeId,
Value: token.value,
});
}
}
else if (token.type === "StringLiteral")
{
Expand All @@ -212,7 +224,7 @@ export class TokensBuilder
this.text(token.value);
}
});

if (index < array.length - 1)
{
this.newline();
Expand Down

0 comments on commit e6aec64

Please sign in to comment.