Skip to content

Fixes to @augments handling #18775

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

Merged
4 commits merged into from
Sep 28, 2017
Merged

Fixes to @augments handling #18775

4 commits merged into from
Sep 28, 2017

Conversation

ghost
Copy link

@ghost ghost commented Sep 26, 2017

Fixes #18740

We will now get a superclass from @augments even if there is no extends.

Allows us to parse /** @augments A */ without the curly braces, because that seems to be the style.

We will no longer parse arbitrary types, only a class (qualified) name followed by type arguments. So you can't declare to inherit from () => void without parse errors.

Adds errors for:

  • @augments tag not on a class
  • @augments A but extends B

@ghost ghost requested a review from sandersn September 26, 2017 20:42
@ghost ghost force-pushed the jsdoc_augments branch from f0bedf7 to e056e83 Compare September 26, 2017 20:43
return;
}

const name: Identifier = node.class.expression.kind === SyntaxKind.PropertyAccessExpression ? (node.class.expression as PropertyAccessExpression).name : (node.class.expression as Identifier);
Copy link
Author

Choose a reason for hiding this comment

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

Waiting on #18774 to get rid of these casts

}
}

function getClassName(node: Expression): Identifier | undefined {
Copy link
Member

Choose a reason for hiding this comment

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

This feels like it already exists. Either way, getClassName is too vague+specific a name for something that treats an Expression like a QualifiedName and then gets the identifier at the bottom. getIdentifierFromExpressionAsQualifiedName? That's horrible in a different way. I'm not sure what the best name is.

@@ -1591,6 +1590,11 @@ namespace ts {
return parameter && parameter.symbol;
}

export function getNodeCommentedByJSDocTag(node: JSDocTag): Node {
Copy link
Member

Choose a reason for hiding this comment

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

we should really make up a name for "the node that this jsdoc is attached to". Commentee? Given that the parameter name and type could be tag: JSDocTag, I think getCommentee would be a fine name, given a good word for "Commentee".

Copy link
Member

Choose a reason for hiding this comment

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

I've been calling it the "host" node in my internal monologue.

"category": "Error",
"code": 8022
},
"JSDoc '@augments' tag declares to extend '{0}', but actual class augments '{1}'.": {
Copy link
Member

Choose a reason for hiding this comment

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

JSDoc '@Augments {0}' does not match the 'extends {1}' clause.

@@ -3511,6 +3511,14 @@
"category": "Error",
"code": 8021
},
"JSDoc '@augments' tag will be ignored if not attached to a class declaration.": {
Copy link
Member

Choose a reason for hiding this comment

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

JSDoc '@Augments' tag is not attached to a class declaration.

return;
}

const name = node.class.expression.kind === SyntaxKind.PropertyAccessExpression ? node.class.expression.name : node.class.expression;
Copy link
Member

Choose a reason for hiding this comment

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

why isn't this a call to getClassName too?

@@ -1856,6 +1856,12 @@ namespace ts {
case CharacterCodes.closeBracket:
pos++;
return token = SyntaxKind.CloseBracketToken;
case CharacterCodes.lessThan:
Copy link
Member

Choose a reason for hiding this comment

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

can you make sure that we have some tests that use < and > inside jsdoc comments in various places? it should be allowed everywhere in comment text, especially in misaligned cases like

  /**
   * @param x hi
< > still part of the previous comment
   */

And of course it should cause error in places like the tag name, etc.

Copy link
Author

Choose a reason for hiding this comment

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

Added a test.

@@ -2161,7 +2161,7 @@ namespace ts {

export interface JSDocAugmentsTag extends JSDocTag {
kind: SyntaxKind.JSDocAugmentsTag;
typeExpression: JSDocTypeExpression;
class: ExpressionWithTypeArguments & { expression: Identifier | PropertyAccessEntityNameExpression };
Copy link
Member

Choose a reason for hiding this comment

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

don't you want a subclass of ExpressionWithTypeArguments that has the override expression: Identifier | PropertyAccessEntityNameExpression ? Seems like intersection would be too permissive.

Copy link
Author

Choose a reason for hiding this comment

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

How is intersection permissive where extends isn't? Could you give an example?

Copy link
Member

Choose a reason for hiding this comment

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

I forgot that Identifier is assignable to Expression & Identifier but (for example) BinaryExpression isn't. Never mind.

return finishNode(result);
}

function parseValidExpressionWithTypeArguments(): ExpressionWithTypeArguments & { expression: Identifier | PropertyAccessEntityNameExpression } {
Copy link
Member

Choose a reason for hiding this comment

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

this doesn't parse all valid expressions, only PropertyAccessEntityNameExpressions, right? This name is confusing.

@ghost ghost force-pushed the jsdoc_augments branch from ca1bfda to 171c054 Compare September 28, 2017 18:25
@@ -1591,6 +1590,11 @@ namespace ts {
return parameter && parameter.symbol;
}

export function getJSDocHost(node: JSDocTag): Node {
Copy link
Member

Choose a reason for hiding this comment

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

This can have a return type of HasJSDoc instead of Node. 😉

@ghost ghost merged commit 1a2de72 into master Sep 28, 2017
@ghost ghost deleted the jsdoc_augments branch September 28, 2017 19:34
@minestarks
Copy link
Member

@Andy-MS <> aren't legal characters on Windows file systems. I can't git pull after this commit:

E:\src\TypeScript>git pull upstream master
From https://github.com/Microsoft/TypeScript
 * branch                  master     -> FETCH_HEAD
error: unable to create file tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.<> characters.json: Invalid argument

function checkJSDocAugmentsTag(node: JSDocAugmentsTag): void {
const cls = getJSDocHost(node);
if (!isClassDeclaration(cls) && !isClassExpression(cls)) {
error(cls, Diagnostics.JSDoc_augments_is_not_attached_to_a_class_declaration);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this message mention class expressions?

@ghost ghost mentioned this pull request Oct 7, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
This pull request was closed.
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.

4 participants