@@ -76,7 +76,7 @@ class Widget {
7676 // Parse files
7777 const files = getElemsByClass ( this . container , 'file' ) ;
7878 // Check to make sure we have files in the widget
79- if ( files . length == 0 ) {
79+ if ( files . length === 0 ) {
8080 throw Error ( 'Malformed widget: No files present.' ) ;
8181 }
8282 for ( const file of files ) {
@@ -148,7 +148,7 @@ class Widget {
148148
149149 // Get tabbed view status from cookie
150150 const cookieTabbedView = cookies . get ( 'tabbed_view' ) as string ;
151- const tabbedView = ( cookieTabbedView != 'false' ) ;
151+ const tabbedView = ( cookieTabbedView !== 'false' ) ;
152152
153153 // attach handlers to the settings bar items
154154 const tabSetting =
@@ -184,7 +184,7 @@ class Widget {
184184 const themeSetting =
185185 this . getElem ( 'settings-bar' , 'theme-setting' ) as HTMLInputElement ;
186186 // Set checkbox according to value from cookie
187- themeSetting . checked = ( cookieTheme == 'dark' ) ;
187+ themeSetting . checked = ( cookieTheme === 'dark' ) ;
188188 this . setTheme ( cookieTheme ) ;
189189
190190 themeSetting . addEventListener ( 'change' , ( ) => {
@@ -220,7 +220,13 @@ class Widget {
220220 dlButton . addEventListener ( 'click' , async ( ) => {
221221 this . outputArea . reset ( ) ;
222222 const files = this . collectResources ( ) ;
223- const switches = JSON . parse ( this . container . dataset . switches as string ) ;
223+ let switches ;
224+ try {
225+ switches = JSON . parse ( this . container . dataset . switches as string ) ;
226+ } catch {
227+ this . outputArea . addError ( Strings . INTERNAL_ERROR_MESSAGE ) ;
228+ return ;
229+ }
224230 const activeSwitches : UnparsedSwitches = {
225231 Builder : switches [ 'Builder' ] ,
226232 Compiler : this . getActiveCompilerSwitches ( ) } ;
@@ -380,18 +386,22 @@ class Widget {
380386 'compiler-switch-help-info' ) [ 0 ] ;
381387 d . addEventListener ( 'click' , ( ) => {
382388 if ( ! d . classList . contains ( 'disabled' ) ) {
383- d . innerHTML = '' ;
389+ d . textContent = '' ;
384390 d . classList . add ( 'disabled' ) ;
385391 }
386392 } ) ;
387393
388394 b . addEventListener ( 'click' , ( ) => {
389- d . innerHTML = '<b>' + switchName + '</b>: ' +
390- b . title + '<br/>' +
391- '<div class="compiler-switch-help-info-click-remove">(' +
392- Strings . COMPILER_SWITCH_REMOVE_HELP_MESSAGE +
393- ')</div>' ;
394-
395+ d . textContent = '' ;
396+ const bold = document . createElement ( 'b' ) ;
397+ bold . textContent = switchName ;
398+ d . appendChild ( bold ) ;
399+ d . appendChild ( document . createTextNode ( ': ' + b . title ) ) ;
400+ d . appendChild ( document . createElement ( 'br' ) ) ;
401+ const helpDiv = document . createElement ( 'div' ) ;
402+ helpDiv . classList . add ( 'compiler-switch-help-info-click-remove' ) ;
403+ helpDiv . textContent = '(' + Strings . COMPILER_SWITCH_REMOVE_HELP_MESSAGE + ')' ;
404+ d . appendChild ( helpDiv ) ;
395405 d . classList . remove ( 'disabled' ) ;
396406 } ) ;
397407 }
@@ -403,7 +413,7 @@ class Widget {
403413 */
404414 private setTheme ( themeStr : string ) : void {
405415 let theme = EditorTheme . Light ;
406- if ( themeStr == 'dark' ) {
416+ if ( themeStr === 'dark' ) {
407417 theme = EditorTheme . Dark ;
408418 }
409419
@@ -474,7 +484,14 @@ class Widget {
474484
475485 const files = this . collectResources ( ) ;
476486
477- const switches = JSON . parse ( this . container . dataset . switches as string ) ;
487+ let switches ;
488+ try {
489+ switches = JSON . parse ( this . container . dataset . switches as string ) ;
490+ } catch {
491+ this . outputArea . addError ( Strings . INTERNAL_ERROR_MESSAGE ) ;
492+ this . outputArea . showSpinner ( false ) ;
493+ return ;
494+ }
478495 switches [ 'Compiler' ] = this . getActiveCompilerSwitches ( ) ;
479496
480497 const serverData : RunProgram . TSData = {
@@ -555,7 +572,7 @@ class Widget {
555572
556573 // Lines that contain a sloc are clickable:
557574 const cb = ( ) : void => {
558- if ( window . getSelection ( ) ?. toString ( ) == '' ) {
575+ if ( window . getSelection ( ) ?. toString ( ) === '' ) {
559576 view . header . scrollIntoView ( true ) ;
560577 view . header . click ( ) ;
561578 // Jump to corresponding line
@@ -567,7 +584,7 @@ class Widget {
567584
568585 // If the message if of type info, addInfo
569586 // Otherwise, addMsg
570- if ( msgType == 'info' ) {
587+ if ( msgType === 'info' ) {
571588 homeArea . addInfo ( outMsg , cb ) ;
572589 } else {
573590 homeArea . addMsg ( outMsg , cb ) ;
@@ -594,7 +611,7 @@ class Widget {
594611 }
595612
596613 if ( data . completed ) {
597- if ( data . status != 0 ) {
614+ if ( data . status !== 0 ) {
598615 this . outputArea . addError ( Strings . EXIT_STATUS_LABEL +
599616 ': ' + data . status ) ;
600617 }
@@ -716,13 +733,14 @@ export function widgetFactory(widgets: Array<HTMLDivElement>): void {
716733 console . error ( 'Error:' , error ) ;
717734
718735 // clear the offending element to remove any processing that was done
719- element . innerHTML = '' ;
736+ element . textContent = '' ;
720737
721738 // add an error message to the page in its place
722739 const errorDiv = document . createElement ( 'div' ) ;
723- errorDiv . innerHTML = '<p>An error has occured processing this widget.' +
724- Strings . INTERNAL_ERROR_MESSAGE + '</p>' ;
725-
740+ const errorP = document . createElement ( 'p' ) ;
741+ errorP . textContent = 'An error has occured processing this widget.' +
742+ Strings . INTERNAL_ERROR_MESSAGE ;
743+ errorDiv . appendChild ( errorP ) ;
726744 element . appendChild ( errorDiv ) ;
727745 }
728746 }
0 commit comments