@@ -6,21 +6,21 @@ import { highlight, showErrorTooltip } from "./syntax";
66import example from "../assets/example.rn?raw" ;
77
88async function compile ( ) {
9- const inputElement = document . getElementById ( "compiler-input" ) ! ;
10- const outputElement = document . getElementById ( "compiler-output " ) ! ;
9+ const input = document . getElementById ( "compiler-input" ) ! ;
10+ const output = document . getElementById ( "compiler-console " ) ! ;
1111
1212 function clearOutput ( ) {
13- outputElement . innerText = "" ;
13+ output . innerText = "" ;
1414 }
1515
1616 function writeToOutput ( text : string ) {
17- outputElement . innerText += text ;
18- outputElement . innerText += "\n" ;
17+ output . innerText += text ;
18+ output . innerText += "\n" ;
1919 }
2020
2121 clearOutput ( ) ;
2222
23- const code = inputElement . innerText ! ;
23+ const code = input . innerText ;
2424
2525 try {
2626 const tokens = tokenize ( code ) ;
@@ -69,38 +69,35 @@ async function compile() {
6969 err instanceof WebAssembly . CompileError ||
7070 err instanceof WebAssembly . RuntimeError
7171 ) {
72- showErrorTooltip ( inputElement , err . message , code . length - 1 ) ;
72+ showErrorTooltip ( input , err . message , code . length - 1 ) ;
7373 }
7474
7575 if ( err instanceof LanguageError ) {
76- showErrorTooltip ( inputElement , err . message , err . offset ) ;
76+ showErrorTooltip ( input , err . message , err . offset ) ;
7777 }
7878 }
7979}
8080
8181document . addEventListener ( "DOMContentLoaded" , ( ) => {
82- document . getElementById ( "compile-button" ) ! . addEventListener ( "click" , compile ) ;
82+ document . getElementById ( "compile-button" ) ? .addEventListener ( "click" , compile ) ;
8383
84- const inputElement = document . getElementById ( "compiler-input" ) ! ;
85- inputElement . innerText = example ;
84+ const input = document . getElementById ( "compiler-input" ) ;
8685
87- highlight ( inputElement ) ;
86+ if ( ! input ) return ;
8887
89- inputElement . addEventListener ( " input" , ( ) => highlight ( inputElement ) ) ;
88+ input . innerText = example ;
9089
91- let isCollapsed = false ;
92- const toggle = document . getElementById ( "toggle-output" ) ! ;
93- toggle . addEventListener ( "click" , ( ) => {
94- const output = document . getElementById ( "output-section" ) ! ;
90+ highlight ( input ) ;
9591
96- isCollapsed = ! isCollapsed ;
92+ input . addEventListener ( "input" , ( ) => highlight ( input ) ) ;
9793
98- if ( isCollapsed ) {
99- output . classList . add ( "collapsed" ) ;
100- toggle . innerHTML = '<i class="fas fa-chevron-up"></i>' ;
101- } else {
102- output . classList . remove ( "collapsed" ) ;
103- toggle . innerHTML = '<i class="fas fa-chevron-down"></i>' ;
104- }
94+ const toggle = document . getElementById ( "toggle-output" ) ! ;
95+ const container = document . getElementById ( "compiler-output" ) ! ;
96+
97+ toggle . addEventListener ( "click" , ( ) => {
98+ const collapsed = container . classList . toggle ( "compiler__output--collapsed" ) ;
99+ toggle . innerHTML = collapsed
100+ ? '<i class="bi bi-chevron-up"></i>'
101+ : '<i class="bi bi-chevron-down"></i>' ;
105102 } ) ;
106103} ) ;
0 commit comments