-
Notifications
You must be signed in to change notification settings - Fork 12.8k
JSDoc support #6024
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
Merged
JSDoc support #6024
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e223b2e
Clean up unrelated changes
RyanCavanaugh 5eb1cc4
Merge remote-tracking branch 'upstream/master' into jsDoc2
RyanCavanaugh 68f11b4
Remove unrelated changes
RyanCavanaugh 8e3daa4
Merge remote-tracking branch 'upstream/master' into jsDoc2
RyanCavanaugh c006634
JSDoc identifiers must start with an identifier start
RyanCavanaugh b1711e3
scanJsIdentifier -> parseJSDocIdentifier
RyanCavanaugh a3126fd
Simplify JSDoc scanner loop
RyanCavanaugh 3c715dd
Merge remote-tracking branch 'upstream/master' into jsDoc2
RyanCavanaugh 4fe3373
Tidy up unused comments / code
RyanCavanaugh 120fa19
Remove duplicated functions
RyanCavanaugh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,6 +240,15 @@ namespace ts { | |
case SyntaxKind.FunctionDeclaration: | ||
case SyntaxKind.ClassDeclaration: | ||
return node.flags & NodeFlags.Default ? "default" : undefined; | ||
case SyntaxKind.JSDocFunctionType: | ||
return isJSDocConstructSignature(node) ? "__new" : "__call"; | ||
case SyntaxKind.Parameter: | ||
// Parameters with names are handled at the top of this function. Parameters | ||
// without names can only come from JSDocFunctionTypes. | ||
Debug.assert(node.parent.kind === SyntaxKind.JSDocFunctionType); | ||
let functionType = <JSDocFunctionType>node.parent; | ||
let index = indexOf(functionType.parameters, node); | ||
return "p" + index; | ||
} | ||
} | ||
|
||
|
@@ -405,7 +414,6 @@ namespace ts { | |
|
||
addToContainerChain(container); | ||
} | ||
|
||
else if (containerFlags & ContainerFlags.IsBlockScopedContainer) { | ||
blockScopeContainer = node; | ||
blockScopeContainer.locals = undefined; | ||
|
@@ -440,6 +448,10 @@ namespace ts { | |
labelStack = labelIndexMap = implicitLabels = undefined; | ||
} | ||
|
||
if (isInJavaScriptFile(node) && node.jsDocComment) { | ||
bind(node.jsDocComment); | ||
} | ||
|
||
bindReachableStatement(node); | ||
|
||
if (currentReachabilityState === Reachability.Reachable && isFunctionLikeKind(kind) && nodeIsPresent((<FunctionLikeDeclaration>node).body)) { | ||
|
@@ -688,8 +700,9 @@ namespace ts { | |
case SyntaxKind.ClassDeclaration: | ||
case SyntaxKind.InterfaceDeclaration: | ||
case SyntaxKind.EnumDeclaration: | ||
case SyntaxKind.TypeLiteral: | ||
case SyntaxKind.ObjectLiteralExpression: | ||
case SyntaxKind.TypeLiteral: | ||
case SyntaxKind.JSDocRecordType: | ||
return ContainerFlags.IsContainer; | ||
|
||
case SyntaxKind.CallSignature: | ||
|
@@ -775,6 +788,7 @@ namespace ts { | |
case SyntaxKind.TypeLiteral: | ||
case SyntaxKind.ObjectLiteralExpression: | ||
case SyntaxKind.InterfaceDeclaration: | ||
case SyntaxKind.JSDocRecordType: | ||
// Interface/Object-types always have their children added to the 'members' of | ||
// their container. They are only accessible through an instance of their | ||
// container, and are never in scope otherwise (even inside the body of the | ||
|
@@ -795,6 +809,7 @@ namespace ts { | |
case SyntaxKind.FunctionDeclaration: | ||
case SyntaxKind.FunctionExpression: | ||
case SyntaxKind.ArrowFunction: | ||
case SyntaxKind.JSDocFunctionType: | ||
case SyntaxKind.TypeAliasDeclaration: | ||
// All the children of these container types are never visible through another | ||
// symbol (i.e. through another symbol's 'exports' or 'members'). Instead, | ||
|
@@ -873,7 +888,7 @@ namespace ts { | |
} | ||
} | ||
|
||
function bindFunctionOrConstructorType(node: SignatureDeclaration) { | ||
function bindFunctionOrConstructorTypeOrJSDocFunctionType(node: SignatureDeclaration): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to just keep the existing name. |
||
// For a given function symbol "<...>(...) => T" we want to generate a symbol identical | ||
// to the one we would get for: { <...>(...): T } | ||
// | ||
|
@@ -948,7 +963,7 @@ namespace ts { | |
declareModuleMember(node, symbolFlags, symbolExcludes); | ||
break; | ||
} | ||
// fall through. | ||
// fall through. | ||
default: | ||
if (!blockScopeContainer.locals) { | ||
blockScopeContainer.locals = {}; | ||
|
@@ -1227,12 +1242,14 @@ namespace ts { | |
return bindVariableDeclarationOrBindingElement(<VariableDeclaration | BindingElement>node); | ||
case SyntaxKind.PropertyDeclaration: | ||
case SyntaxKind.PropertySignature: | ||
case SyntaxKind.JSDocRecordMember: | ||
return bindPropertyOrMethodOrAccessor(<Declaration>node, SymbolFlags.Property | ((<PropertyDeclaration>node).questionToken ? SymbolFlags.Optional : SymbolFlags.None), SymbolFlags.PropertyExcludes); | ||
case SyntaxKind.PropertyAssignment: | ||
case SyntaxKind.ShorthandPropertyAssignment: | ||
return bindPropertyOrMethodOrAccessor(<Declaration>node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); | ||
case SyntaxKind.EnumMember: | ||
return bindPropertyOrMethodOrAccessor(<Declaration>node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes); | ||
|
||
case SyntaxKind.CallSignature: | ||
case SyntaxKind.ConstructSignature: | ||
case SyntaxKind.IndexSignature: | ||
|
@@ -1256,8 +1273,10 @@ namespace ts { | |
return bindPropertyOrMethodOrAccessor(<Declaration>node, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes); | ||
case SyntaxKind.FunctionType: | ||
case SyntaxKind.ConstructorType: | ||
return bindFunctionOrConstructorType(<SignatureDeclaration>node); | ||
case SyntaxKind.JSDocFunctionType: | ||
return bindFunctionOrConstructorTypeOrJSDocFunctionType(<SignatureDeclaration>node); | ||
case SyntaxKind.TypeLiteral: | ||
case SyntaxKind.JSDocRecordType: | ||
return bindAnonymousDeclaration(<TypeLiteralNode>node, SymbolFlags.TypeLiteral, "__type"); | ||
case SyntaxKind.ObjectLiteralExpression: | ||
return bindObjectLiteralExpression(<ObjectLiteralExpression>node); | ||
|
@@ -1269,6 +1288,8 @@ namespace ts { | |
|
||
case SyntaxKind.CallExpression: | ||
if (isInJavaScriptFile(node)) { | ||
// We're only inspecting call expressions to detect CommonJS modules, so we can skip | ||
// this check if we've already seen the module indicator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not seeing where you skip this check. |
||
bindCallExpression(<CallExpression>node); | ||
} | ||
break; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Will we ever manifest this name to the user?
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.
Yes