@@ -3,18 +3,19 @@ import { getState, updateState } from './state.mjs';
33const features = document . querySelector ( '#features' ) ;
44const output = document . querySelector ( '#output' ) ;
55
6+ /** @type {Worker } */
67let worker ;
78function respawn ( first = false ) {
89 if ( worker ) {
910 worker . terminate ( ) ;
1011 }
11- worker = new Worker ( new URL ( './worker.js ' , import . meta. url ) ) ;
12+ worker = new Worker ( new URL ( './worker.mjs ' , import . meta. url ) , { type : 'module' } ) ;
1213 worker . addEventListener ( 'message' , ( { data } ) => {
1314 console . log ( '@MAIN' , data ) ; // eslint-disable-line no-console
1415
1516 if ( first && data . type === 'initialize' ) {
1617 const { FEATURES } = data . value ;
17- FEATURES . forEach ( ( { name, flag } ) => {
18+ FEATURES . forEach ( ( /** @type { any } */ { name, flag } ) => {
1819 // <li>
1920 // <label>
2021 // <input type="checkbox">
@@ -26,7 +27,7 @@ function respawn(first = false) {
2627 input . type = 'checkbox' ;
2728 input . addEventListener ( 'change' , ( ) => {
2829 getState ( 'features' )
29- . then ( ( f ) => {
30+ . then ( ( /** @type { any } */ f ) => {
3031 if ( input . checked ) {
3132 f . add ( flag ) ;
3233 } else {
@@ -37,7 +38,7 @@ function respawn(first = false) {
3738 } ) ;
3839 } ) ;
3940 getState ( 'features' )
40- . then ( ( requestedFeatures ) => {
41+ . then ( ( /** @type { any } */ requestedFeatures ) => {
4142 input . checked = requestedFeatures . has ( flag ) ;
4243 } ) ;
4344
@@ -48,38 +49,38 @@ function respawn(first = false) {
4849 const li = document . createElement ( 'li' ) ;
4950 li . appendChild ( label ) ;
5051
51- features . appendChild ( li ) ;
52+ features ? .appendChild ( li ) ;
5253 } ) ;
5354 } else if ( data . type === 'console' ) {
5455 if ( data . value . method === 'clear' ) {
5556 const range = document . createRange ( ) ;
56- range . selectNodeContents ( output ) ;
57+ output && range . selectNodeContents ( output ) ;
5758 range . deleteContents ( ) ;
5859 } else {
5960 const line = document . createElement ( 'span' ) ;
60- data . value . values . forEach ( ( v ) => {
61+ data . value . values . forEach ( ( /** @type { any } */ v ) => {
6162 line . textContent += v ;
6263 line . textContent += ' ' ;
6364 } ) ;
6465 const container = document . createElement ( 'div' ) ;
6566 container . className = `log-${ data . value . method } ` ;
6667 container . appendChild ( line ) ;
67- output . appendChild ( container ) ;
68+ output ? .appendChild ( container ) ;
6869 }
6970 } else if ( data . type === 'unhandledRejection' ) {
7071 const line = document . createElement ( 'span' ) ;
7172 line . textContent = `Unhandled Rejection:\n${ data . value } ` ;
7273 const container = document . createElement ( 'div' ) ;
7374 container . className = 'log-error' ;
7475 container . appendChild ( line ) ;
75- output . appendChild ( container ) ;
76+ output ? .appendChild ( container ) ;
7677 }
7778 } ) ;
7879}
7980
80- export function evaluate ( code ) {
81+ export function evaluate ( /** @type { string } */ code ) {
8182 getState ( )
82- . then ( ( state ) => {
83+ . then ( ( /** @type { any } */ state ) => {
8384 state . set ( 'code' , code ) ;
8485 worker . postMessage ( { type : 'evaluate' , value : { code, state } } ) ;
8586 return updateState ( ) ;
0 commit comments