-
Notifications
You must be signed in to change notification settings - Fork 632
Add the 5 modifier jsdoc tags #927
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
base: main
Are you sure you want to change the base?
Conversation
`@public @Private @Protected @readonly @override` Three notes: - I did not add support for BinaryExpressions yet because they don't have a Modifiers list. I think the right thing is to add it (along with a Type node), but I want to bring it up at a design meeting first. - I dropped the error messages with tag-specific wording for `@override`. This seems unnecessary to me -- people who use JS as TS are aware that's what they're doing. - I added a setModifiers method on nodeData and exposed it via a public AsMutable method on Node. I don't know if that's exactly the right way to do it.
if declaration.AsVariableDeclaration().Type == nil { | ||
declaration.AsVariableDeclaration().Type = p.makeNewType(tag.AsJSDocTypeTag().TypeExpression, declaration) | ||
break | ||
switch parent.Kind { |
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.
this is a drive-by reformat. As usual, best reviewed ignoring whitespace.
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.
Pull Request Overview
Adds support for five new JSDoc tags by reparsing comments into actual TypeScript modifiers.
- Parses
@public
,@private
,@protected
,@readonly
, and@override
tags and injects corresponding modifiers into the AST. - Adjusts grammar checks to recognize modifiers inserted by the reparser and avoid spurious ordering errors.
- Extends the AST API to allow mutation of modifier lists on nodes.
Reviewed Changes
Copilot reviewed 31 out of 31 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
internal/parser/reparser.go | Add JSDoc‐tag cases to insert matching modifiers on declarations |
internal/checker/grammarchecks.go | Skip ordering errors for modifiers added via JSDoc reparse |
internal/ast/ast.go | Introduce AsMutable() + setModifiers() for AST nodes |
testdata/baselines/reference/submoduleAccepted/conformance/jsdocReadonly.errors.txt.diff | Remove obsolete readonly‐property error baseline |
testdata/baselines/reference/submoduleAccepted/conformance/jsdocOverrideTag1.errors.txt.diff | Update override‐tag1 error expectations |
testdata/baselines/reference/submoduleAccepted/conformance/jsdocAccessibilityTags.errors.txt.diff | Clean up accessibility‐tag error baselines |
testdata/baselines/reference/submodule/conformance/uniqueSymbolsDeclarationsInJsErrors.types | Expect unique symbol for readonly‐unique symbol props |
testdata/baselines/reference/submodule/conformance/uniqueSymbolsDeclarationsInJsErrors.errors.txt | Drop duplicate unique‐symbol error |
testdata/baselines/reference/submodule/conformance/uniqueSymbolsDeclarationsInJs.types | Reflect unique symbol type in all readonly symbol cases |
testdata/baselines/reference/submodule/conformance/uniqueSymbolsDeclarationsInJs.errors.txt | Remove outdated unique‐symbol error baseline |
testdata/baselines/reference/submodule/conformance/privateNamesIncompatibleModifiersJs.errors.txt | Add tests for private‐identifier modifier conflicts |
testdata/baselines/reference/submodule/conformance/override_js4.errors.txt | New test for typo suggestion in override error |
testdata/baselines/reference/submodule/conformance/override_js3.errors.txt | Remove obsolete JS3 override baseline |
testdata/baselines/reference/submodule/conformance/override_js2.errors.txt | Expand override tests in JS2 |
testdata/baselines/reference/submodule/conformance/override_js1.errors.txt | Expand override tests in JS1 |
testdata/baselines/reference/submodule/conformance/jsdocReadonlyDeclarations.types | Update declaration‐site readonly types to literal values |
testdata/baselines/reference/submodule/conformance/jsdocReadonly.types | Update readonly property types and instance assignment types |
testdata/baselines/reference/submodule/conformance/jsdocReadonly.errors.txt | Add readonly‐assignment error baseline |
testdata/baselines/reference/submodule/conformance/jsdocOverrideTag1.errors.txt | Update override‐tag1 error baselines |
testdata/baselines/reference/submodule/conformance/jsdocAccessibilityTags.errors.txt | Add accessibility‐tag error baseline |
case ast.KindJSDocReadonlyTag, ast.KindJSDocPrivateTag, ast.KindJSDocPublicTag, ast.KindJSDocProtectedTag, ast.KindJSDocOverrideTag: | ||
switch parent.Kind { | ||
case ast.KindPropertyDeclaration, ast.KindMethodDeclaration, ast.KindGetAccessor, ast.KindSetAccessor: | ||
// !!! BinaryExpression (this.p assignments) |
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.
[nitpick] Consider implementing handling for BinaryExpression parent nodes (e.g. this.property = ...
inside constructors) so that JSDoc modifiers on assignments are consistently applied, or remove the stray comment if unneeded.
// !!! BinaryExpression (this.p assignments) | |
// Handle JSDoc modifiers for declarations |
Copilot uses AI. Check for mistakes.
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.
I can't implement handling until I decide how to store modifiers for this.p=
. Waiting on a decision at a design meeting.
l.y = 12 | ||
>l.y = 12 : 12 | ||
>l.y : number | ||
>l.y : any | ||
>l : LOL | ||
>y : number | ||
>y : any | ||
>12 : 12 |
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 type of l.y
has been widened to any
after applying @readonly
. It should remain number
(or the literal type) to preserve type safety and avoid losing information.
Copilot uses AI. Check for mistakes.
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.
No, it's because y
is readonly now, so assignments to it are not allowed.
nodes = append(parent.Modifiers().Nodes, modifier) | ||
loc = parent.Modifiers().Loc | ||
} | ||
parent.AsMutable().SetModifiers(p.newModifierList(loc, nodes)) |
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.
Does this ever happen on any parent kind, or is there a specific subset of nodes that do this? I'm not entirely certain how I feel about the AsMutable
pattern, so curious if it's just shorthand for a couple of types.
@public @private @protected @readonly @override
Three notes:
@override
. This seems unnecessary to me -- people who use JS as TS are aware that's what they're doing.to do it.