@@ -426,14 +426,24 @@ export class FileIndexer {
426426 }
427427
428428 private prototypeAssignmentOwner ( node : ts . Node ) : ts . Declaration | undefined {
429- if ( ! ts . isObjectLiteralExpression ( node ) ) {
430- return
431- }
432- const assignment = node . parent
429+ const assignment = ts . isBinaryExpression ( node )
430+ ? node
431+ : ts . isObjectLiteralExpression ( node )
432+ ? node . parent
433+ : ts . isPropertyAccessExpression ( node )
434+ ? node . parent
435+ : ts . isIdentifier ( node ) && ts . isPropertyAccessExpression ( node . parent )
436+ ? node . parent . parent
437+ : ( ts . isPropertyAssignment ( node ) ||
438+ ts . isShorthandPropertyAssignment ( node ) ) &&
439+ ts . isObjectLiteralExpression ( node . parent )
440+ ? node . parent . parent
441+ : undefined
433442 if (
443+ ! assignment ||
434444 ! ts . isBinaryExpression ( assignment ) ||
435445 assignment . operatorToken . kind !== ts . SyntaxKind . EqualsToken ||
436- assignment . right !== node ||
446+ ! ts . isObjectLiteralExpression ( assignment . right ) ||
437447 ! ts . isPropertyAccessExpression ( assignment . left ) ||
438448 assignment . left . name . text !== 'prototype'
439449 ) {
@@ -462,6 +472,20 @@ export class FileIndexer {
462472 }
463473 return this . cached ( node , package_ )
464474 }
475+
476+ const prototypeOwner = this . prototypeAssignmentOwner ( node )
477+ if ( prototypeOwner ) {
478+ // Declarations attached to the assignment and its object literal belong
479+ // to the constructor. Property assignments need their own stable member
480+ // descriptor instead of the counter-based object-property fallback.
481+ const owner = this . scipSymbol ( prototypeOwner )
482+ const symbol =
483+ ts . isPropertyAssignment ( node ) || ts . isShorthandPropertyAssignment ( node )
484+ ? ScipSymbol . global ( owner , termDescriptor ( node . name . getText ( ) ) )
485+ : owner
486+ return this . cached ( node , symbol )
487+ }
488+
465489 if (
466490 ts . isPropertyAssignment ( node ) ||
467491 ts . isShorthandPropertyAssignment ( node )
@@ -512,14 +536,6 @@ export class FileIndexer {
512536 }
513537 }
514538
515- const prototypeOwner = this . prototypeAssignmentOwner ( node )
516- if ( prototypeOwner ) {
517- // Methods in `Constructor.prototype = { ... }` belong to the constructor,
518- // not to an anonymous object local to this file. Giving that object the
519- // constructor's identity makes its members stable across files.
520- return this . cached ( node , this . scipSymbol ( prototypeOwner ) )
521- }
522-
523539 const owner = this . scipSymbol ( node . parent )
524540 if ( owner . isEmpty ( ) || owner . isLocal ( ) ) {
525541 return this . newLocalSymbol ( node )
0 commit comments