Skip to content

Readonly support for jsdoc - #35790

Merged
Nathan Shively-Sanders (sandersn) merged 4 commits into
masterfrom
readonly-jsdoc
Dec 20, 2019
Merged

Readonly support for jsdoc#35790
Nathan Shively-Sanders (sandersn) merged 4 commits into
masterfrom
readonly-jsdoc

Conversation

@sandersn

Copy link
Copy Markdown
Member

Add @readonly to jsdoc; works the same way readonly does in TS.

Fixes #17233

The rule for @readonly on this-assignments in the constructor is wrong.
See failing tests.
Add ctor function test
Add some notes and rename variable
Comment thread src/compiler/checker.ts
error(right, Diagnostics.Cannot_assign_to_0_because_it_is_a_read_only_property, idText(right));
return errorType;
}
if (isAssignmentToReadonlyEntity(node as Expression, prop, assignmentKind)) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I collapsed these three checks into one function because they are always called together.

Comment thread src/compiler/checker.ts
const isLocalPropertyDeclaration = ctor.parent === symbol.valueDeclaration.parent;
const isLocalParameterProperty = ctor === symbol.valueDeclaration.parent;
const isLocalThisPropertyAssignment = isAssignmentDeclaration && symbol.parent?.valueDeclaration === ctor.parent;
const isLocalThisPropertyAssignmentConstructorFunction = isAssignmentDeclaration && symbol.parent?.valueDeclaration === ctor;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This one is this.x = whatever inside a JS constructor function?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep. Any suggestions for making the variable name clearer?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

- isLocalThisPropertyAssignmentConstructorFunction
+ isLocalThisPropertyAssignmentInConstructorFunction

?

Comment thread src/compiler/checker.ts
const isAssignmentDeclaration = isBinaryExpression(symbol.valueDeclaration);
const isLocalPropertyDeclaration = ctor.parent === symbol.valueDeclaration.parent;
const isLocalParameterProperty = ctor === symbol.valueDeclaration.parent;
const isLocalThisPropertyAssignment = isAssignmentDeclaration && symbol.parent?.valueDeclaration === ctor.parent;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This would be true inside any method, but we’ve already ensured we’re in a constructor 👍

@weswigham Wesley Wigham (weswigham) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How's the user suite look?

TypeScript Bot (@typescript-bot) user test this

@sandersn

Copy link
Copy Markdown
Member Author

TypeScript Bot (@typescript-bot) user test this

@typescript-bot

TypeScript Bot (typescript-bot) commented Dec 20, 2019

Copy link
Copy Markdown
Contributor

Heya Nathan Shively-Sanders (@sandersn), I've started to run the parallelized community code test suite on this PR at a1d3a3e. You can monitor the build here. It should now contribute to this PR's status checks.

@sandersn

Copy link
Copy Markdown
Member Author

Wesley Wigham (@weswigham) Looks like the bot doesn't pay attention to sign off comments.

@typescript-bot

Copy link
Copy Markdown
Contributor

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

@sandersn

Copy link
Copy Markdown
Member Author

Results are the same as yesterday's @private results.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Update Docs on Next Release Indicates that this PR affects docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSDoc: Support @readonly tag

5 participants