@@ -277,6 +277,7 @@ export function buildClassDeclaration(node: ClassDeclaration, isExported: boolea
277277
278278/**
279279 * Helper to build member modifiers string efficiently
280+ * TypeScript modifier order: private/protected/public, static, abstract, readonly
280281 */
281282function buildMemberModifiers (
282283 isStatic : boolean ,
@@ -286,16 +287,20 @@ function buildMemberModifiers(
286287 isProtected : boolean ,
287288) : string {
288289 const parts : string [ ] = [ ' ' ]
290+ // Access modifiers come first
291+ if ( isPrivate )
292+ parts . push ( 'private ' )
293+ else if ( isProtected )
294+ parts . push ( 'protected ' )
295+ // Then static
289296 if ( isStatic )
290297 parts . push ( 'static ' )
298+ // Then abstract
291299 if ( isAbstract )
292300 parts . push ( 'abstract ' )
301+ // Then readonly
293302 if ( isReadonly )
294303 parts . push ( 'readonly ' )
295- if ( isPrivate )
296- parts . push ( 'private ' )
297- else if ( isProtected )
298- parts . push ( 'protected ' )
299304 return parts . join ( '' )
300305}
301306
@@ -346,6 +351,12 @@ export function buildClassBody(node: ClassDeclaration): string {
346351 // First, add property declarations for parameter properties
347352 for ( const param of member . parameters ) {
348353 if ( param . modifiers && param . modifiers . length > 0 ) {
354+ // Skip private parameter properties - they're not part of the public API
355+ const isPrivateParam = param . modifiers . some ( mod => mod . kind === SyntaxKind . PrivateKeyword )
356+ if ( isPrivateParam ) {
357+ continue
358+ }
359+
349360 // This is a parameter property, add it as a separate property declaration
350361 const name = getParameterName ( param )
351362 const type = param . type ?. getText ( ) || 'any'
@@ -372,14 +383,20 @@ export function buildClassBody(node: ClassDeclaration): string {
372383 continue
373384 }
374385
386+ // Skip private keyword methods - they're not part of the public API
387+ const isPrivateMethod = member . modifiers ?. some ( mod => mod . kind === SyntaxKind . PrivateKeyword )
388+ if ( isPrivateMethod ) {
389+ continue
390+ }
391+
375392 // Method signature without implementation
376393 const name = getMemberNameText ( member )
377394 const isGenerator = ! ! member . asteriskToken
378395 const mods = buildMemberModifiers (
379396 ! ! member . modifiers ?. some ( mod => mod . kind === SyntaxKind . StaticKeyword ) ,
380397 ! ! member . modifiers ?. some ( mod => mod . kind === SyntaxKind . AbstractKeyword ) ,
381398 false ,
382- ! ! member . modifiers ?. some ( mod => mod . kind === SyntaxKind . PrivateKeyword ) ,
399+ false , // Already filtered out private
383400 ! ! member . modifiers ?. some ( mod => mod . kind === SyntaxKind . ProtectedKeyword ) ,
384401 )
385402
@@ -434,13 +451,19 @@ export function buildClassBody(node: ClassDeclaration): string {
434451 continue
435452 }
436453
454+ // Skip private keyword properties - they're not part of the public API
455+ const isPrivateProperty = member . modifiers ?. some ( mod => mod . kind === SyntaxKind . PrivateKeyword )
456+ if ( isPrivateProperty ) {
457+ continue
458+ }
459+
437460 // Property declaration
438461 const name = getMemberNameText ( member )
439462 const mods = buildMemberModifiers (
440463 ! ! member . modifiers ?. some ( mod => mod . kind === SyntaxKind . StaticKeyword ) ,
441464 ! ! member . modifiers ?. some ( mod => mod . kind === SyntaxKind . AbstractKeyword ) ,
442465 ! ! member . modifiers ?. some ( mod => mod . kind === SyntaxKind . ReadonlyKeyword ) ,
443- ! ! member . modifiers ?. some ( mod => mod . kind === SyntaxKind . PrivateKeyword ) ,
466+ false , // Already filtered out private
444467 ! ! member . modifiers ?. some ( mod => mod . kind === SyntaxKind . ProtectedKeyword ) ,
445468 )
446469
@@ -455,13 +478,19 @@ export function buildClassBody(node: ClassDeclaration): string {
455478 continue
456479 }
457480
481+ // Skip private keyword accessors - they're not part of the public API
482+ const isPrivateAccessor = member . modifiers ?. some ( mod => mod . kind === SyntaxKind . PrivateKeyword )
483+ if ( isPrivateAccessor ) {
484+ continue
485+ }
486+
458487 // Get accessor declaration
459488 const name = getMemberNameText ( member )
460489 const mods = buildMemberModifiers (
461490 ! ! member . modifiers ?. some ( mod => mod . kind === SyntaxKind . StaticKeyword ) ,
462491 ! ! member . modifiers ?. some ( mod => mod . kind === SyntaxKind . AbstractKeyword ) ,
463492 false ,
464- ! ! member . modifiers ?. some ( mod => mod . kind === SyntaxKind . PrivateKeyword ) ,
493+ false , // Already filtered out private
465494 ! ! member . modifiers ?. some ( mod => mod . kind === SyntaxKind . ProtectedKeyword ) ,
466495 )
467496
@@ -474,13 +503,19 @@ export function buildClassBody(node: ClassDeclaration): string {
474503 continue
475504 }
476505
506+ // Skip private keyword accessors - they're not part of the public API
507+ const isPrivateAccessor = member . modifiers ?. some ( mod => mod . kind === SyntaxKind . PrivateKeyword )
508+ if ( isPrivateAccessor ) {
509+ continue
510+ }
511+
477512 // Set accessor declaration
478513 const name = getMemberNameText ( member )
479514 const mods = buildMemberModifiers (
480515 ! ! member . modifiers ?. some ( mod => mod . kind === SyntaxKind . StaticKeyword ) ,
481516 ! ! member . modifiers ?. some ( mod => mod . kind === SyntaxKind . AbstractKeyword ) ,
482517 false ,
483- ! ! member . modifiers ?. some ( mod => mod . kind === SyntaxKind . PrivateKeyword ) ,
518+ false , // Already filtered out private
484519 ! ! member . modifiers ?. some ( mod => mod . kind === SyntaxKind . ProtectedKeyword ) ,
485520 )
486521
0 commit comments