add support for readonly modifier#23954
Merged
mhegazy merged 4 commits intomicrosoft:masterfrom May 10, 2018
Merged
Conversation
mhegazy
reviewed
May 8, 2018
|
|
||
| function updateReadonlyPropertyInitializerStatementConstructor(changeTracker: textChanges.ChangeTracker, file: SourceFile, constructor: ConstructorDeclaration, accessorName: AcceptedNameType, fieldName: AcceptedNameType) { | ||
| if (constructor.body) { | ||
| const initializerStatement = find(constructor.body.statements, (stmt => |
Contributor
There was a problem hiding this comment.
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
mhegazy
reviewed
May 9, 2018
| if (!constructor.body) return; | ||
| const { file, program, cancellationToken } = context; | ||
|
|
||
| const referenceEntries = mapDefined(FindAllReferences.getReferenceEntriesForNode(-1, originalName, program, [file], cancellationToken), entry => ( |
Contributor
There was a problem hiding this comment.
use the position of the node in the file and not -1.
mhegazy
reviewed
May 10, 2018
| if (!constructor.body) return; | ||
| const { file, program, cancellationToken } = context; | ||
|
|
||
| const referenceEntries = mapDefined(FindAllReferences.getReferenceEntriesForNode(constructor.pos, originalName, program, [file], cancellationToken), entry => ( |
Contributor
There was a problem hiding this comment.
the position should be the position of the property reference you are looking for. i am surprised this even works..
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #22143