import * as Configuration from "./Configuration" ; const SUPPORTED_PER_FILE_OPTS = { main : true , out : true , outExt : true , sourceMap : true , sourceMapFileInline : true , compress : true , relativeUrls : true , ieCompat : true , autoprefixer : true , javascriptEnabled : true , math : true , } ; const ARRAY_OPTS = { main : true , } ; export function parse ( line , defaults ) { const commentMatch = /^\s*\/\/\s*(.+)/ . exec ( line ) ; if ( ! commentMatch ) { return defaults ; } const options = { ... defaults } ; const optionLine = commentMatch [ 1 ] ; const seenKeys = { } ; for ( const item of optionLine . split ( "," ) ) { const i = item . indexOf ( ":" ) ; if ( i < 0 ) { continue ; } const key = item . substr ( 0 , i ) . trim ( ) ; if ( ! SUPPORTED_PER_FILE_OPTS . hasOwnProperty ( key ) ) { continue ; } let value = item . substr ( i + 1 ) . trim ( ) ; if ( value . match ( /^(true|false|undefined|null|[0-9]+)$/ ) ) { value = eval ( value ) ; } if ( seenKeys [ key ] === true && ARRAY_OPTS [ key ] ) { let existingValue = options [ key ] ; if ( ! Array . isArray ( existingValue ) ) { existingValue = options [ key ] = [ existingValue ] ; } existingValue . push ( value ) ; } else { options [ key ] = value ; seenKeys [ key ] = true ; } } return options as Configuration . EasyLessOptions ; }