Skip to content

Commit 2000382

Browse files
authored
Replace duplicated visualization code in playground with @ethdebug/bugc-react (#180)
* Replace duplicated visualization code with @ethdebug/bugc-react The playground had local copies of all bugc-react visualization components (AstView, BytecodeView, CfgView, IrView, EthdebugTooltip) plus utilities (debugUtils, irDebugUtils, formatBytecode, bugLanguage). These were pre-extraction originals that diverged from the extracted package. Replace them with imports from @ethdebug/bugc-react and delete the duplicated files. Also removes unused vis-network dependency. * Add @types/dagre to bugc-react devDependencies CfgView.tsx imports dagre, so the type declarations need to be available during bugc-react's build. Previously this worked by accident via hoisting from playground.
1 parent aaed7fb commit 2000382

21 files changed

+38
-2895
lines changed

packages/bugc-react/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"devDependencies": {
3737
"@testing-library/dom": "^10.0.0",
3838
"@testing-library/react": "^16.0.0",
39+
"@types/dagre": "^0.7.52",
3940
"@types/react": "^18.2.43",
4041
"@types/react-dom": "^18.2.17",
4142
"jsdom": "^26.0.0",

packages/playground/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
},
1616
"dependencies": {
1717
"@ethdebug/bugc": "^0.1.0-0",
18+
"@ethdebug/bugc-react": "^0.1.0-0",
1819
"@monaco-editor/react": "^4.6.0",
19-
"@types/dagre": "^0.7.52",
2020
"dagre": "^0.8.5",
2121
"monaco-editor": "^0.52.2",
2222
"react": "^18.2.0",
2323
"react-dom": "^18.2.0",
24-
"react-flow-renderer": "^10.3.17",
25-
"vis-network": "^9.1.9"
24+
"react-flow-renderer": "^10.3.17"
2625
},
2726
"devDependencies": {
2827
"@types/react": "^18.2.43",

packages/playground/src/compiler/CompilerOutput.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
import { useState } from "react";
22
import type { CompileResult } from "./types";
3-
import { AstView } from "../visualization/AstView";
4-
import { IrView } from "../visualization/IrView";
5-
import { CfgView } from "../visualization/CfgView";
6-
import { BytecodeView } from "../visualization/BytecodeView";
3+
import {
4+
AstView,
5+
IrView,
6+
CfgView,
7+
BytecodeView,
8+
type SourceRange,
9+
} from "@ethdebug/bugc-react";
710
import { ErrorView } from "./ErrorView";
8-
import type { SourceRange } from "../visualization/debugUtils";
911
import "./CompilerOutput.css";
1012

13+
// CSS for bugc-react components
14+
import "@ethdebug/bugc-react/src/components/variables.css";
15+
import "@ethdebug/bugc-react/src/components/AstView.css";
16+
import "@ethdebug/bugc-react/src/components/BytecodeView.css";
17+
import "@ethdebug/bugc-react/src/components/CfgView.css";
18+
import "@ethdebug/bugc-react/src/components/EthdebugTooltip.css";
19+
import "@ethdebug/bugc-react/src/components/IrView.css";
20+
1121
interface CompilerOutputProps {
1222
result: CompileResult;
1323
onOpcodeHover?: (ranges: SourceRange[]) => void;
Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
1-
import type { Ast, Ir, Evm } from "@ethdebug/bugc";
2-
3-
export interface BytecodeOutput {
4-
runtime: Uint8Array;
5-
create?: Uint8Array;
6-
runtimeInstructions: Evm.Instruction[];
7-
createInstructions?: Evm.Instruction[];
8-
}
9-
10-
export interface SuccessfulCompileResult {
11-
success: true;
12-
ast: Ast.Program;
13-
ir: Ir.Module;
14-
bytecode: BytecodeOutput;
15-
warnings: string[];
16-
}
17-
18-
export interface FailedCompileResult {
19-
success: false;
20-
error: string;
21-
ast?: Ast.Program;
22-
warnings?: string[];
23-
}
24-
25-
export type CompileResult = SuccessfulCompileResult | FailedCompileResult;
1+
export type {
2+
BytecodeOutput,
3+
SuccessfulCompileResult,
4+
FailedCompileResult,
5+
CompileResult,
6+
} from "@ethdebug/bugc-react";

packages/playground/src/editor/Editor.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import MonacoEditor, { type OnMount } from "@monaco-editor/react";
22
import { useEffect, useRef } from "react";
3-
import { registerBugLanguage } from "./bugLanguage";
4-
import type { editor as MonacoEditor_Type } from "monaco-editor";
3+
import * as monaco from "monaco-editor";
4+
import { registerBugLanguage } from "@ethdebug/bugc-react";
5+
import type { SourceRange } from "@ethdebug/bugc-react";
56

6-
export interface SourceRange {
7-
offset: number;
8-
length: number;
9-
}
7+
export type { SourceRange } from "@ethdebug/bugc-react";
108

119
interface EditorProps {
1210
value: string;
@@ -21,13 +19,11 @@ export function Editor({
2119
language = "bug",
2220
highlightedRanges = [],
2321
}: EditorProps) {
24-
const editorRef = useRef<MonacoEditor_Type.IStandaloneCodeEditor | null>(
25-
null,
26-
);
22+
const editorRef = useRef<monaco.editor.IStandaloneCodeEditor | null>(null);
2723
const decorationsRef = useRef<string[]>([]);
2824

2925
useEffect(() => {
30-
registerBugLanguage();
26+
registerBugLanguage(monaco);
3127
}, []);
3228

3329
useEffect(() => {

packages/playground/src/editor/bugLanguage.ts

Lines changed: 0 additions & 192 deletions
This file was deleted.

packages/playground/src/visualization/AstView.css

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/playground/src/visualization/AstView.tsx

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)