Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@microsoft/tsdoc",
"comment": "Fix an issue where tsdoc-param-tag-with-invalid-name was sometimes incorrectly reported certain identifiers (issue #148)",
"type": "patch"
}
],
"packageName": "@microsoft/tsdoc",
"email": "4673363+octogonz@users.noreply.github.com"
}
12 changes: 8 additions & 4 deletions tsdoc/src/nodes/DocMemberIdentifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ export class DocMemberIdentifier extends DocNode {
private readonly _rightQuoteExcerpt: DocExcerpt | undefined;

/**
* Returns true if the specified string is a valid TypeScript
* identifier. If not, {@link DocMemberIdentifier.hasQuotes} will be
* required.
* Tests whether the input string can be used without quotes as a member identifier in a declaration reference.
* If not, {@link DocMemberIdentifier.hasQuotes} will be required.
*
* @remarks
* In order to be used without quotes, the string must follow the identifier syntax for ECMAScript / TypeScript,
* and it must not be one of the reserved words used for system selectors (such as `instance`, `static`,
* `constructor`, etc).
*/
public static isValidIdentifier(identifier: string): boolean {
return !StringChecks.explainIfInvalidUnquotedIdentifier(identifier);
return !StringChecks.explainIfInvalidUnquotedMemberIdentifier(identifier);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tsdoc/src/parser/NodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ export class NodeParser {
const identifierExcerpt: TokenSequence = tokenReader.extractAccumulatedSequence();
const identifier: string = identifierExcerpt.toString();

const explanation: string | undefined = StringChecks.explainIfInvalidUnquotedIdentifier(identifier);
const explanation: string | undefined = StringChecks.explainIfInvalidUnquotedMemberIdentifier(identifier);
if (explanation) {
this._parserContext.log.addMessageForTokenSequence(
TSDocMessageId.ReferenceUnquotedIdentifier,
Expand Down
13 changes: 13 additions & 0 deletions tsdoc/src/parser/StringChecks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,19 @@ export class StringChecks {
return 'The identifier must not start with a number';
}

return undefined;
}

/**
* Tests whether the input string can be used without quotes as a member identifier in a declaration reference.
* If not, it should be enclosed in quotes.
*/
public static explainIfInvalidUnquotedMemberIdentifier(identifier: string): string | undefined {
const explanation: string | undefined = StringChecks.explainIfInvalidUnquotedIdentifier(identifier);
if (explanation !== undefined) {
return explanation;
}

if (StringChecks.isSystemSelector(identifier)) {
// We do this to avoid confusion about the declaration reference syntax rules.
// For example if someone were to see "MyClass.(static:instance)" it would be unclear which
Expand Down