@samitouri / QOS-React-2 / commits / b1eb22d941

[be] Don't show duplicate codegen tab

The JS tab and the codegen tab are the same.

Sathya Gunasekaran committed Jan 13, 2023 at 16:33 UTC b1eb22d94159e7e829fd0cb93e9c60e28f228ea0
1 file changed +18 -28
compiler/forget/packages/playground/components/Editor/Output.tsx
+18 -28
@@ -61,24 +61,12 @@ function compile(source: string): Map<string, React.ReactNode> | CompilerError {
61
62 // TODO: Handle multiple functions
63 const func = astFunctions[0];
64 -
64 const tabs = new Map<string, React.ReactNode>();
66 - const generator = run(func);
67 - let ast;
68 - while (true) {
69 - const next = generator.next();
70 - if (next.done) {
71 - ast = next.value;
72 - break;
73 - }
74 - const result = next.value;
65 + let ast: t.Function | null = null;
66 + for (const result of run(func)) {
67 switch (result.kind) {
68 case "ast": {
77 - const { code } = codegen(result.value, source);
78 - tabs.set(
79 - result.name,
80 - <TextTabContent output={code}></TextTabContent>
81 - );
69 + ast = result.value;
70 break;
71 }
72 case "hir": {
@@ -104,19 +92,21 @@ function compile(source: string): Map<string, React.ReactNode> | CompilerError {
92 }
93 // Ensure that JS and the JS source map come first
94 const reorderedTabs = new Map();
107 - const { code, sourceMapUrl } = codegen(ast, source);
108 - reorderedTabs.set("JS", <TextTabContent output={code}></TextTabContent>);
109 - if (sourceMapUrl) {
110 - reorderedTabs.set(
111 - "SourceMap",
112 - <>
113 - <iframe
114 - src={sourceMapUrl}
115 - className="w-full h-96"
116 - title="Generated Code"
117 - />
118 - </>
119 - );
95 + if (ast !== null) {
96 + const { code, sourceMapUrl } = codegen(ast, source);
97 + reorderedTabs.set("JS", <TextTabContent output={code}></TextTabContent>);
98 + if (sourceMapUrl) {
99 + reorderedTabs.set(
100 + "SourceMap",
101 + <>
102 + <iframe
103 + src={sourceMapUrl}
104 + className="w-full h-96"
105 + title="Generated Code"
106 + />
107 + </>
108 + );
109 + }
110 }
111 tabs.forEach((tab, name) => {
112 reorderedTabs.set(name, tab);