File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11declare module 'node:worker_threads' {
22 const parentPort : {
33 on ( kind : string , listener : ( event : Event ) => void ) : void ;
4- once ( kind : string , listener : ( event : Event ) => void ) : void ;
54 postMessage ( msg : any ) : void ;
65 } ;
76 const workerData : any ;
Original file line number Diff line number Diff line change @@ -625,7 +625,6 @@ export class HTMLAdaptor<
625625 ) {
626626 const { path, maps, worker } = options ;
627627 const file = `${ path } /${ worker } ` ;
628- const quoted = ( text : string ) => text . replace ( / ( \\ * ) ( [ \\ ' ] ) / g, '$1$1\\$2' ) ;
629628 const content = `
630629 self.maps = '${ quoted ( maps ) } ';
631630 import('${ quoted ( file ) } ');
@@ -639,3 +638,24 @@ export class HTMLAdaptor<
639638 return webworker ;
640639 }
641640}
641+
642+ /**
643+ * Quote any backslashes or single quotes, and turn non-ASCII
644+ * characters into \u{...} so that the result can be inserted into
645+ * single quotes and return the original string when evaluated.
646+ *
647+ * @param {string } text The text to be quoted
648+ * @returns {string } The quoted text
649+ */
650+ function quoted ( text : string ) : string {
651+ return [ ...text ]
652+ . map ( ( c ) => {
653+ if ( c === '\\' || c === "'" ) {
654+ c = '\\' + c ;
655+ } else if ( c < ' ' || c > '\u007e' ) {
656+ c = `\\u{${ c . codePointAt ( 0 ) . toString ( 16 ) } }` ;
657+ }
658+ return c ;
659+ } )
660+ . join ( '' ) ;
661+ }
You can’t perform that action at this time.
0 commit comments