import type { CompilerMessage } from './compiler-message' ; returns export function formatCompilerLog ( shaderLog , source , options ? ) { const lines = source . split ( /\r?\n/ ) ; let formattedLog = '' ; for ( const message of shaderLog ) { formattedLog += formatCompilerMessage ( message , lines , message . lineNum , options ) ; } return formattedLog ; } /** Format one message */ function formatCompilerMessage ( message , lines , lineNum , options ? ) { if ( options ?. showSourceCode ) { const positionIndicator = message . linePos > 0 ? `${ ' ' . repeat ( message . linePos + 5 ) }^^^\n` : '' ; const numberedLines = getNumberedLines ( lines , lineNum ) ; return `\
${ numberedLines }${ positionIndicator }${ message . type . toUpperCase ( ) }: ${ message . message }

` ; } return `${ message . type . toUpperCase ( ) }: ${ message . message }\n` ; } function getNumberedLines ( lines , lineNum ) { let numberedLines = '' ; for ( let line = lineNum - 2 ; line <= lineNum ; line ++ ) { const sourceLine = lines [ line ] ; if ( sourceLine !== undefined ) { numberedLines += `${ padLeft ( String ( line ) , 4 ) }: ${ sourceLine }\n` ; } } return numberedLines ; } param { String } string param { Number } digits return { String } function padLeft ( string , paddedLength ) { let result = '' ; for ( let i = string . length ; i < paddedLength ; ++ i ) { result += ' ' ; } return result + string ; }