Skip to content
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

[spec] Adding snippets for "declaration references" #64

Merged
merged 5 commits into from
Sep 21, 2018

Conversation

octogonz
Copy link
Collaborator

RFC issue #9 proposes a notation for "declaration references" that provide an unambiguous notation for referencing any API declaration such as classes, member functions, enum values, etc. This syntax will be used by standard tags such as {@link} and {@inheritDoc}, and can also be used by custom tags.

The proposed syntax supports edge cases such as:

  • imports from external packages, including NPM scopes and explicit import paths
  • disambiguating function overloads
  • disambiguating merged declarations
  • handling member names that are not well-formed identifiers (e.g. Mr. X or constructor as object property names)
  • handling operators that don't have a name (e.g. new (hour: number, minute: number);)

We also propose a new TSDoc inline tag {@label YOUR_NAME} that can label a declaration for use by a reference.

This PR is just a source file with a bunch of commented snippets, which will later be incorporated into the TSDoc spec document. My next PR will add a parser for this notation to the library.

// a TypeScript "import" definition, so we don't discuss them further here.
//
// TSDoc declaration references are always resolved relative to a specific entry point
// (NOT relative to the current source file or declaration scope). Thus, their syntax
Copy link
Member

@iclanton iclanton Sep 18, 2018

Choose a reason for hiding this comment

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

NOT relative to the current source file or declaration scope [](start = 4, length = 60)

This means that it's effectively impossible to refer to something that isn't exported from the package. #Resolved

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can work around that by supporting relative imports. For example:

/**
 * {@link ./lib/controls/Button:Button | referencing a local *.d.ts file}
 */

I updated the note to explain this.


In reply to: 218613174 [](ancestors = 218613174)

}

/**
* Shortest name: {@link Class00.member01[static]}
Copy link
Member

@iclanton iclanton Sep 18, 2018

Choose a reason for hiding this comment

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

static [](start = 45, length = 6)

It'd be useful to have an example where there isn't both a static and instance member with the same name. #Resolved

// Function overloads

/**
* Shortest name: {@link function06[1]}
Copy link
Member

@iclanton iclanton Sep 18, 2018

Choose a reason for hiding this comment

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

1 [](start = 37, length = 1)

It would be helpful to warn against using this if you're talking about your own package (perhaps in strict mode) #Resolved

/**
* Shortest name: {@link Class15."\uD842\uDFB7"}
* Full name: {@link Class15[class]."\uD842\uDFB7"[instance]}
*
Copy link
Member

@iclanton iclanton Sep 18, 2018

Choose a reason for hiding this comment

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

Include alternatively:

Alternative name:      {@link Class15[class].𠮷[instance]}
``` #Resolved

/**
* Shortest name: {@link Class15.\{\}}
* JSON approach: {@link Class15."\u007B\u007D"}
* Full name: {@link Class15[class].\{\}[instance]}
Copy link
Member

@iclanton iclanton Sep 18, 2018

Choose a reason for hiding this comment

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

There's a mistake with the escaping here. #Resolved

* NOTE: The string in double quotes is parsed using JSON.parse(), which converts
* this surrogate pair expression to the corresponding Unicode character.
*/
public '𠮷': string = 'instance member using JSON unicode escapes';
Copy link
Member

@iclanton iclanton Sep 18, 2018

Choose a reason for hiding this comment

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

string [](start = 15, length = 6)

It might be useful to include an example of a member containing an allowed non-ASCII character (ß) #Resolved

public '𠮷': string = 'instance member using JSON unicode escapes';

/**
* Shortest name: {@link Class15."\\\""}
Copy link
Member

@iclanton iclanton Sep 18, 2018

Choose a reason for hiding this comment

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

"\" [](start = 36, length = 5)

We should allow single- and double-quotes, and to escape a quotemark, double it. #WontFix

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm undecided on that one for now. We can add it later if needed.


In reply to: 218621886 [](ancestors = 218621886)


/**
* Shortest name: {@link Class15."\uD842\uDFB7"}
* Full name: {@link Class15[class]."\uD842\uDFB7"[instance]}
Copy link
Member

@iclanton iclanton Sep 18, 2018

Choose a reason for hiding this comment

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

uD842 [](start = 45, length = 5)

I don't think we should support unicode \u notation. #Resolved

/**
* Shortest name: {@link Type16}
* Full name: {@link Type16[type]}
*
Copy link
Member

@iclanton iclanton Sep 18, 2018

Choose a reason for hiding this comment

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

It might be interesting to have an example like this:

/**
 * @type T - {@inheritdoc Y[class].X[type]}
 */
export class X<T> extends Y<string, X> {
}
``` #WontFix

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we want to support this in the future, I think it can be incorporated without any significant changes to the notation. It seems like a fairly rare case, however, so in the interests of time I'm going to skip it for now.


In reply to: 218623575 [](ancestors = 218623575)

Copy link
Member

@iclanton iclanton left a comment

Choose a reason for hiding this comment

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

:shipit:

*/
export interface Interface17 {
/**
* Shortest name: {@link Interface17.operator[STRING_INDEXER]}
Copy link
Member

@iclanton iclanton Sep 18, 2018

Choose a reason for hiding this comment

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

operator [](start = 40, length = 8)

this won't work if you have a member called "operator"

What if you could say {@link Interface17.[STRING_INDEXER]} #Resolved

@octogonz octogonz merged commit 483b6eb into master Sep 21, 2018
@octogonz octogonz deleted the pgonzal/spec-dec-refs branch September 21, 2018 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants