-
Notifications
You must be signed in to change notification settings - Fork 12.8k
add support for readonly modifier #23954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
||
function updateReadonlyPropertyInitializerStatementConstructor(changeTracker: textChanges.ChangeTracker, file: SourceFile, constructor: ConstructorDeclaration, accessorName: AcceptedNameType, fieldName: AcceptedNameType) { | ||
if (constructor.body) { | ||
const initializerStatement = find(constructor.body.statements, (stmt => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An assignment to the private name can happen anywhere really and not just in expressionStatemetns, it can be in a comma expression nested in a call... you want to use FindAllReferences.getReferenceEntriesForNode
here instead of searching the body yourself. a few notes:
- this could return you nodes outside the body of the constructor, these you want to ignore, so filter out ones that fall outside the pos/end of the constructor
- you only want to look at places where you are writing to the property, use
isWriteAccess(node)
to filter read only operations
if (!constructor.body) return; | ||
const { file, program, cancellationToken } = context; | ||
|
||
const referenceEntries = mapDefined(FindAllReferences.getReferenceEntriesForNode(-1, originalName, program, [file], cancellationToken), entry => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the position of the node in the file and not -1
.
if (!constructor.body) return; | ||
const { file, program, cancellationToken } = context; | ||
|
||
const referenceEntries = mapDefined(FindAllReferences.getReferenceEntriesForNode(constructor.pos, originalName, program, [file], cancellationToken), entry => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the position should be the position of the property reference you are looking for. i am surprised this even works..
Fixes #22143