@@ -8110,9 +8110,10 @@ export function setObjectAllocator(alloc: ObjectAllocator) {
81108110 forEach ( objectAllocatorPatchers , fn => fn ( objectAllocator ) ) ;
81118111}
81128112
8113+ // TODO(jakebailey): replace args type with DiagnosticArguments
81138114/** @internal */
8114- export function formatStringFromArgs ( text : string , args : ArrayLike < string | number > , baseIndex = 0 ) : string {
8115- return text . replace ( / { ( \d + ) } / g, ( _match , index : string ) => "" + Debug . checkDefined ( args [ + index + baseIndex ] ) ) ;
8115+ export function formatStringFromArgs ( text : string , args : ArrayLike < string | number > ) : string {
8116+ return text . replace ( / { ( \d + ) } / g, ( _match , index : string ) => "" + Debug . checkDefined ( args [ + index ] ) ) ;
81168117}
81178118
81188119let localizedDiagnosticMessages : MapLike < string > | undefined ;
@@ -8137,14 +8138,13 @@ export function getLocaleSpecificMessage(message: DiagnosticMessage) {
81378138}
81388139
81398140/** @internal */
8140- export function createDetachedDiagnostic ( fileName : string , start : number , length : number , message : DiagnosticMessage , ...args : DiagnosticArguments ) : DiagnosticWithDetachedLocation ;
8141- /** @internal */
8142- export function createDetachedDiagnostic ( fileName : string , start : number , length : number , message : DiagnosticMessage ) : DiagnosticWithDetachedLocation {
8141+ export function createDetachedDiagnostic ( fileName : string , start : number , length : number , message : DiagnosticMessage , ...args : DiagnosticArguments ) : DiagnosticWithDetachedLocation {
81438142 assertDiagnosticLocation ( /*file*/ undefined , start , length ) ;
81448143 let text = getLocaleSpecificMessage ( message ) ;
81458144
8146- if ( arguments . length > 4 ) {
8147- text = formatStringFromArgs ( text , arguments , 4 ) ;
8145+ // TODO(jakebailey): would love to use length here; maybe use some instead?
8146+ if ( args . length > 0 ) {
8147+ text = formatStringFromArgs ( text , args ) ;
81488148 }
81498149
81508150 return {
@@ -8208,15 +8208,14 @@ export function attachFileToDiagnostics(diagnostics: DiagnosticWithDetachedLocat
82088208}
82098209
82108210/** @internal */
8211- export function createFileDiagnostic ( file : SourceFile , start : number , length : number , message : DiagnosticMessage , ...args : DiagnosticArguments ) : DiagnosticWithLocation ;
8212- /** @internal */
8213- export function createFileDiagnostic ( file : SourceFile , start : number , length : number , message : DiagnosticMessage ) : DiagnosticWithLocation {
8211+ export function createFileDiagnostic ( file : SourceFile , start : number , length : number , message : DiagnosticMessage , ...args : DiagnosticArguments ) : DiagnosticWithLocation {
82148212 assertDiagnosticLocation ( file , start , length ) ;
82158213
82168214 let text = getLocaleSpecificMessage ( message ) ;
82178215
8218- if ( arguments . length > 4 ) {
8219- text = formatStringFromArgs ( text , arguments , 4 ) ;
8216+ // TODO(jakebailey): would love to use length here; maybe use some instead?
8217+ if ( args . length > 0 ) {
8218+ text = formatStringFromArgs ( text , args ) ;
82208219 }
82218220
82228221 return {
@@ -8233,26 +8232,22 @@ export function createFileDiagnostic(file: SourceFile, start: number, length: nu
82338232}
82348233
82358234/** @internal */
8236- export function formatMessage ( _dummy : any , message : DiagnosticMessage , ...args : DiagnosticArguments ) : string ;
8237- /** @internal */
8238- export function formatMessage ( _dummy : any , message : DiagnosticMessage ) : string {
8235+ export function formatMessage ( message : DiagnosticMessage , ...args : DiagnosticArguments ) : string {
82398236 let text = getLocaleSpecificMessage ( message ) ;
82408237
8241- if ( arguments . length > 2 ) {
8242- text = formatStringFromArgs ( text , arguments , 2 ) ;
8238+ if ( length ( args ) ) {
8239+ text = formatStringFromArgs ( text , args ) ;
82438240 }
82448241
82458242 return text ;
82468243}
82478244
82488245/** @internal */
8249- export function createCompilerDiagnostic ( message : DiagnosticMessage , ...args : DiagnosticArguments ) : Diagnostic ;
8250- /** @internal */
8251- export function createCompilerDiagnostic ( message : DiagnosticMessage ) : Diagnostic {
8246+ export function createCompilerDiagnostic ( message : DiagnosticMessage , ...args : DiagnosticArguments ) : Diagnostic {
82528247 let text = getLocaleSpecificMessage ( message ) ;
82538248
8254- if ( arguments . length > 1 ) {
8255- text = formatStringFromArgs ( text , arguments , 1 ) ;
8249+ if ( length ( args ) ) {
8250+ text = formatStringFromArgs ( text , args ) ;
82568251 }
82578252
82588253 return {
@@ -8283,13 +8278,11 @@ export function createCompilerDiagnosticFromMessageChain(chain: DiagnosticMessag
82838278}
82848279
82858280/** @internal */
8286- export function chainDiagnosticMessages ( details : DiagnosticMessageChain | DiagnosticMessageChain [ ] | undefined , message : DiagnosticMessage , ...args : DiagnosticArguments ) : DiagnosticMessageChain ;
8287- /** @internal */
8288- export function chainDiagnosticMessages ( details : DiagnosticMessageChain | DiagnosticMessageChain [ ] | undefined , message : DiagnosticMessage ) : DiagnosticMessageChain {
8281+ export function chainDiagnosticMessages ( details : DiagnosticMessageChain | DiagnosticMessageChain [ ] | undefined , message : DiagnosticMessage , ...args : DiagnosticArguments ) : DiagnosticMessageChain {
82898282 let text = getLocaleSpecificMessage ( message ) ;
82908283
8291- if ( arguments . length > 2 ) {
8292- text = formatStringFromArgs ( text , arguments , 2 ) ;
8284+ if ( length ( args ) ) {
8285+ text = formatStringFromArgs ( text , args ) ;
82938286 }
82948287 return {
82958288 messageText : text ,
0 commit comments