@@ -98,24 +98,18 @@ const patchScriptlet = (content, arglist) => {
9898 ) ;
9999} ;
100100
101+ const requote = s => {
102+ if ( / ^ ( [ " ' ` ] ) .+ \1$ | , / . test ( s ) === false ) { return s ; }
103+ if ( s . includes ( "'" ) === false ) { return `'${ s } '` ; }
104+ if ( s . includes ( '"' ) === false ) { return `"${ s } "` ; }
105+ if ( s . includes ( '`' ) === false ) { return `\`${ s } \`` ; }
106+ return `'${ s . replace ( / ' / g, "\\'" ) } '` ;
107+ } ;
108+
101109const decompile = json => {
102- const args = JSON . parse ( json ) . map ( s => {
103- if ( / ^ ( [ " ' ` ] ) .+ \1$ / . test ( s ) ) {
104- const c0 = s . charAt ( 0 ) ;
105- const inner = s . slice ( 1 , - 1 ) ;
106- if ( c0 === '"' || c0 === '`' ) {
107- return inner . includes ( "'" )
108- ? '`' + s . replace ( / ` / g, '\\`' ) + '`'
109- : `'${ s } '` ;
110- }
111- return inner . includes ( '"' )
112- ? '`' + s . replace ( / ` / g, '\\`' ) + '`'
113- : `"${ s } "` ;
114- }
115- return s . replace ( / , / g, '\\,' ) ;
116- } ) ;
110+ const args = JSON . parse ( json ) ;
117111 if ( args . length === 0 ) { return '+js()' ; }
118- return `+js(${ args . join ( ', ' ) } )` ;
112+ return `+js(${ args . map ( s => requote ( s ) ) . join ( ', ' ) } )` ;
119113} ;
120114
121115/******************************************************************************/
0 commit comments