@@ -57,16 +57,23 @@ function setOption(name: string, value: string, opts: CompilerOptions, optMap: M
5757 break
5858
5959 case "list" :
60- opts [ opt . name ] = value . split ( "," ) . map ( v => parsePrimitive ( v , opt . element ! . type as string ) )
60+ const elementType = opt . element ! . type
61+ const strings = value . split ( "," )
62+ if ( typeof elementType === "string" ) {
63+ opts [ opt . name ] = strings . map ( v => parsePrimitive ( v , elementType ) )
64+ } else {
65+ opts [ opt . name ] = strings . map ( v => getOptionValueFromMap ( opt . name , v , elementType as Map < string , string > ) ! ) . filter ( Boolean )
66+ }
6167 break
6268
63- default :
64- opts [ opt . name ] = opt . type . get ( value . toLowerCase ( ) )
69+ default : // It's a map!
70+ const optMap = opt . type as Map < string , string >
71+ opts [ opt . name ] = getOptionValueFromMap ( opt . name , value , optMap )
72+ }
6573
66- if ( opts [ opt . name ] === undefined ) {
67- const keys = Array . from ( opt . type . keys ( ) as any )
68- console . log ( `Invalid value ${ value } for ${ opt . name } . Allowed values: ${ keys . join ( "," ) } ` )
69- }
74+ if ( opts [ opt . name ] === undefined ) {
75+ const keys = Array . from ( opt . type . keys ( ) as any )
76+ console . log ( `Invalid value ${ value } for ${ opt . name } . Allowed values: ${ keys . join ( "," ) } ` )
7077 }
7178}
7279
@@ -82,6 +89,21 @@ export function parsePrimitive(value: string, type: string): any {
8289 console . log ( `Unknown primitive type ${ type } with - ${ value } ` )
8390}
8491
92+
93+ function getOptionValueFromMap ( name : string , key : string , optMap : Map < string , string > ) {
94+ const result = optMap . get ( key . toLowerCase ( ) )
95+ if ( result === undefined ) {
96+ const keys = Array . from ( optMap . keys ( ) as any )
97+
98+ console . error (
99+ `Invalid inline compiler value` ,
100+ `Got ${ key } for ${ name } but it is not a supported value by the TS compiler.` ,
101+ `Allowed values: ${ keys . join ( "," ) } `
102+ )
103+ }
104+ return result
105+ }
106+
85107// Function to generate autocompletion results
86108export const twoslashCompletions = ( ts : TS , monaco : typeof import ( "monaco-editor" ) ) => (
87109 model : import ( "monaco-editor" ) . editor . ITextModel ,
0 commit comments