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

Fix anonymous union variant in tree viewer #4353

Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: fix
packages:
- "@typespec/html-program-viewer"
---

Fix crash when using anonymous union variant
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: internal
packages:
- "@typespec/playground"
---
1 change: 1 addition & 0 deletions packages/html-program-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"default": "./dist/emitter/index.js"
},
"./react": {
"development": "./src/react/index.ts",
"types": "./dist/react/index.d.ts",
"default": "./dist/react/index.js"
},
Expand Down
18 changes: 18 additions & 0 deletions packages/html-program-viewer/src/react/type-graph.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { render } from "@testing-library/react";
import { it } from "vitest";
import { createViewerTestRunner } from "../../test/test-host.js";
import { TypeGraph } from "./index.js";

async function renderTypeGraphFor(code: string) {
const runner = await createViewerTestRunner();
await runner.compile(code);
render(<TypeGraph program={runner.program} />);
}

it("operation", async () => {
await renderTypeGraphFor(`op foo(): string;`);
});

it("compile unnamed union variant without error", async () => {
await renderTypeGraphFor(`union Foo { "a", "b" }`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,14 @@ function computeTypeNodeProps(path: string, type: NamedType, name?: string): Typ
}

function computeItemList(path: string, name: string, items: Map<string, NamedType>): TypeGraphNode {
let index = 0;
return {
kind: "list",
id: path,
name,
children: Array.from(items.entries()).map(([key, value]) => {
return computeTypeNode(path, value, key);
const name = typeof key === "symbol" ? `sym(${index++})` : key;
return computeTypeNode(path, value, name);
}),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ beforeEach(async () => {
runner = await createViewerTestRunner();
});

it("create html view", async () => {
await runner.compile(`op foo(): string;`);
});

it("compile unnamed union variant without error", async () => {
await runner.compile(`union Foo { "a", "b" }`);
it("runs emitter", async () => {
await runner.compile(`op foo(): string;`, {
emitters: { "@typespec/html-program-viewer": {} },
});
});
2 changes: 1 addition & 1 deletion packages/html-program-viewer/test/test-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function createViewerTestRunner() {
return createTestWrapper(host, {
autoImports: [],
compilerOptions: {
emitters: { "@typespec/html-program-viewer": {} },
// emitters: { "@typespec/html-program-viewer": {} },
},
});
}
6 changes: 6 additions & 0 deletions packages/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,32 @@
"main": "dist/src/index.js",
"exports": {
".": {
"development": "./src/index.ts",
"types": "./dist/src/index.d.ts",
"default": "./dist/index.js"
},
"./vite": {
"development": "./src/vite/index.ts",
"types": "./dist/src/vite/index.d.ts",
"default": "./dist/vite/index.js"
},
"./tooling": {
"development": "./src/tooling/index.ts",
"types": "./dist/src/tooling/index.d.ts",
"default": "./dist/tooling/index.js"
},
"./manifest": {
"development": "./src/manifest.ts",
"types": "./dist/src/manifest.d.ts",
"default": "./dist/manifest.js"
},
"./react": {
"development": "./src/react/index.ts",
"types": "./dist/src/react/index.d.ts",
"default": "./dist/react/index.js"
},
"./react/viewers": {
"development": "./src/react/viewers/index.tsx",
"types": "./dist/src/react/viewers/index.d.ts",
"default": "./dist/react/viewers/index.js"
},
Expand Down
1 change: 1 addition & 0 deletions packages/react-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"main": "dist/index.js",
"exports": {
".": {
"development": "./src/index.ts",
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
Expand Down
Loading