FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

add support for readonly modifier by Kingwl · Pull Request #23954 · microsoft/TypeScript · GitHub

add support for readonly modifier - #23954

Merged
Mohamed Hegazy (mhegazy) merged 4 commits into
microsoft:masterfrom
Kingwl:readonly-getter-support
May 10, 2018
Merged

add support for readonly modifier#23954
Mohamed Hegazy (mhegazy) merged 4 commits into
microsoft:masterfrom
Kingwl:readonly-getter-support

Conversation

Wenlu Wang (Kingwl) commented May 8, 2018
edited
Loading

Copy link
Copy Markdown
Contributor

Fixes #22143

  • allow readonly modifier
  • do not add set accessor if has readonly modifier
  • update all top level statement what is Initializer for readonly


function updateReadonlyPropertyInitializerStatementConstructor(changeTracker: textChanges.ChangeTracker, file: SourceFile, constructor: ConstructorDeclaration, accessorName: AcceptedNameType, fieldName: AcceptedNameType) {
if (constructor.body) {
const initializerStatement = find(constructor.body.statements, (stmt =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 => (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 => (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

the position should be the position of the property reference you are looking for. i am surprised this even works..

Mohamed Hegazy (mhegazy) merged commit 1b796ed into microsoft:master May 10, 2018
Wenlu Wang (Kingwl) deleted the readonly-getter-support branch May 10, 2018 23:23
Microsoft (microsoft) locked and limited conversation to collaborators Jul 31, 2018
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.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL