@@ -249,13 +249,13 @@ type AddChangeOptions = {
249249 * formatting, update a changelog, or build one from scratch.
250250 */
251251export default class Changelog {
252- private _releases : ReleaseMetadata [ ] ;
252+ readonly #releases : ReleaseMetadata [ ] ;
253253
254- private _changes : ChangelogChanges ;
254+ #changes : ChangelogChanges ;
255255
256- private _repoUrl : string ;
256+ readonly #repoUrl : string ;
257257
258- private _tagPrefix : string ;
258+ readonly #tagPrefix : string ;
259259
260260 /**
261261 * Construct an empty changelog.
@@ -271,10 +271,10 @@ export default class Changelog {
271271 repoUrl : string ;
272272 tagPrefix ?: string ;
273273 } ) {
274- this . _releases = [ ] ;
275- this . _changes = { [ unreleased ] : { } } ;
276- this . _repoUrl = repoUrl ;
277- this . _tagPrefix = tagPrefix ;
274+ this . #releases = [ ] ;
275+ this . #changes = { [ unreleased ] : { } } ;
276+ this . #repoUrl = repoUrl ;
277+ this . #tagPrefix = tagPrefix ;
278278 }
279279
280280 /**
@@ -297,16 +297,16 @@ export default class Changelog {
297297 throw new Error ( 'Version required' ) ;
298298 } else if ( semver . valid ( version ) === null ) {
299299 throw new Error ( `Not a valid semver version: '${ version } '` ) ;
300- } else if ( this . _changes [ version ] ) {
300+ } else if ( this . #changes [ version ] ) {
301301 throw new Error ( `Release already exists: '${ version } '` ) ;
302302 }
303303
304- this . _changes [ version ] = { } ;
304+ this . #changes [ version ] = { } ;
305305 const newRelease = { version, date, status } ;
306306 if ( addToStart ) {
307- this . _releases . unshift ( newRelease ) ;
307+ this . #releases . unshift ( newRelease ) ;
308308 } else {
309- this . _releases . push ( newRelease ) ;
309+ this . #releases . push ( newRelease ) ;
310310 }
311311 }
312312
@@ -335,13 +335,13 @@ export default class Changelog {
335335 throw new Error ( `Unrecognized category: '${ category } '` ) ;
336336 } else if ( ! description ) {
337337 throw new Error ( 'Description required' ) ;
338- } else if ( version !== undefined && ! this . _changes [ version ] ) {
338+ } else if ( version !== undefined && ! this . #changes [ version ] ) {
339339 throw new Error ( `Specified release version does not exist: '${ version } '` ) ;
340340 }
341341
342342 const release = version
343- ? this . _changes [ version ]
344- : this . _changes [ unreleased ] ;
343+ ? this . #changes [ version ]
344+ : this . #changes [ unreleased ] ;
345345
346346 if ( ! release [ category ] ) {
347347 release [ category ] = [ ] ;
@@ -365,12 +365,12 @@ export default class Changelog {
365365 * @param version - The release version to migrate unreleased changes to.
366366 */
367367 migrateUnreleasedChangesToRelease ( version : Version ) {
368- const releaseChanges = this . _changes [ version ] ;
368+ const releaseChanges = this . #changes [ version ] ;
369369 if ( ! releaseChanges ) {
370370 throw new Error ( `Specified release version does not exist: '${ version } '` ) ;
371371 }
372372
373- const unreleasedChanges = this . _changes [ unreleased ] ;
373+ const unreleasedChanges = this . #changes [ unreleased ] ;
374374
375375 for ( const category of Object . keys ( unreleasedChanges ) as ChangeCategory [ ] ) {
376376 if ( releaseChanges [ category ] ) {
@@ -382,7 +382,7 @@ export default class Changelog {
382382 releaseChanges [ category ] = unreleasedChanges [ category ] ;
383383 }
384384 }
385- this . _changes [ unreleased ] = { } ;
385+ this . #changes [ unreleased ] = { } ;
386386 }
387387
388388 /**
@@ -391,7 +391,7 @@ export default class Changelog {
391391 * @returns The metadata for each release.
392392 */
393393 getReleases ( ) {
394- return this . _releases ;
394+ return this . #releases ;
395395 }
396396
397397 /**
@@ -429,7 +429,7 @@ export default class Changelog {
429429 * @returns The changes included in the given released.
430430 */
431431 getReleaseChanges ( version : Version ) {
432- return this . _changes [ version ] ;
432+ return this . #changes [ version ] ;
433433 }
434434
435435 /**
@@ -438,7 +438,7 @@ export default class Changelog {
438438 * @returns The changes that have not yet been released.
439439 */
440440 getUnreleasedChanges ( ) {
441- return this . _changes [ unreleased ] ;
441+ return this . #changes [ unreleased ] ;
442442 }
443443
444444 /**
@@ -450,12 +450,12 @@ export default class Changelog {
450450 return `${ changelogTitle }
451451${ changelogDescription }
452452
453- ${ stringifyReleases ( this . _releases , this . _changes ) }
453+ ${ stringifyReleases ( this . #releases , this . #changes ) }
454454
455455${ stringifyLinkReferenceDefinitions (
456- this . _repoUrl ,
457- this . _tagPrefix ,
458- this . _releases ,
456+ this . #repoUrl ,
457+ this . #tagPrefix ,
458+ this . #releases ,
459459) } `;
460460 }
461461}
0 commit comments