-
Notifications
You must be signed in to change notification settings - Fork 13k
Add jsdoc support for @public/@private/@protected #35731
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
Changes from 9 commits
87666a9
9c1a370
88dcb39
871a643
455b7b3
bd5781a
14d3c38
b80847b
62a568d
f30f399
37a586a
8182bfd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -840,13 +840,11 @@ namespace ts { | |
ensureType(input, input.type) | ||
)); | ||
case SyntaxKind.Constructor: { | ||
const isPrivate = hasModifier(input, ModifierFlags.Private); | ||
// A constructor declaration may not have a type annotation | ||
const ctor = createSignatureDeclaration( | ||
SyntaxKind.Constructor, | ||
isPrivate ? undefined : ensureTypeParams(input, input.typeParameters), | ||
// TODO: GH#18217 | ||
isPrivate ? undefined! : updateParamsList(input, input.parameters, ModifierFlags.None), | ||
ensureTypeParams(input, input.typeParameters), | ||
updateParamsList(input, input.parameters, ModifierFlags.None), | ||
/*type*/ undefined | ||
); | ||
ctor.modifiers = createNodeArray(ensureModifiers(input)); | ||
|
@@ -865,15 +863,14 @@ namespace ts { | |
return cleanup(sig); | ||
} | ||
case SyntaxKind.GetAccessor: { | ||
const isPrivate = hasModifier(input, ModifierFlags.Private); | ||
const accessorType = getTypeAnnotationFromAllAccessorDeclarations(input, resolver.getAllAccessorDeclarations(input)); | ||
return cleanup(updateGetAccessor( | ||
input, | ||
/*decorators*/ undefined, | ||
ensureModifiers(input), | ||
input.name, | ||
updateAccessorParamsList(input, isPrivate), | ||
!isPrivate ? ensureType(input, accessorType) : undefined, | ||
updateAccessorParamsList(input, hasModifier(input, ModifierFlags.Private)), | ||
ensureType(input, accessorType), | ||
/*body*/ undefined)); | ||
} | ||
case SyntaxKind.SetAccessor: { | ||
|
@@ -892,7 +889,7 @@ namespace ts { | |
ensureModifiers(input), | ||
input.name, | ||
input.questionToken, | ||
!hasModifier(input, ModifierFlags.Private) ? ensureType(input, input.type) : undefined, | ||
ensureType(input, input.type), | ||
ensureNoInitializer(input) | ||
)); | ||
case SyntaxKind.PropertySignature: | ||
|
@@ -901,7 +898,7 @@ namespace ts { | |
ensureModifiers(input), | ||
input.name, | ||
input.questionToken, | ||
!hasModifier(input, ModifierFlags.Private) ? ensureType(input, input.type) : undefined, | ||
ensureType(input, input.type), | ||
ensureNoInitializer(input) | ||
)); | ||
case SyntaxKind.MethodSignature: { | ||
|
@@ -1476,7 +1473,7 @@ namespace ts { | |
} | ||
|
||
function maskModifierFlags(node: Node, modifierMask: ModifierFlags = ModifierFlags.All ^ ModifierFlags.Public, modifierAdditions: ModifierFlags = ModifierFlags.None): ModifierFlags { | ||
let flags = (getModifierFlags(node) & modifierMask) | modifierAdditions; | ||
let flags = (getEffectiveModifierFlags(node) & modifierMask) | modifierAdditions; | ||
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. this is the only substantive change in this file; all the others just eliminate checks that are already performed in |
||
if (flags & ModifierFlags.Default && !(flags & ModifierFlags.Export)) { | ||
// A non-exported default is a nonsequitor - we usually try to remove all export modifiers | ||
// from statements in ambient declarations; but a default export must retain its export modifier to be syntactically valid | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4100,7 +4100,7 @@ namespace ts { | |
} | ||
|
||
export function getSelectedModifierFlags(node: Node, flags: ModifierFlags): ModifierFlags { | ||
return getModifierFlags(node) & flags; | ||
return getEffectiveModifierFlags(node) & flags; | ||
} | ||
|
||
export function getModifierFlags(node: Node): ModifierFlags { | ||
|
@@ -4128,6 +4128,19 @@ namespace ts { | |
return flags; | ||
} | ||
|
||
export function getEffectiveModifierFlags(node: Node) { | ||
const flags = getModifierFlags(node); | ||
if (!!node.parent && isInJSFile(node)) { | ||
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. Shouldn't you just integrate this into |
||
// Do not try to look for tags during parsing, because parent pointers aren't set and | ||
// non-local tags will incorrectly be missed; this wrong answer will be cached. | ||
const tags = (getJSDocPublicTag(node) ? ModifierFlags.Public : ModifierFlags.None) | ||
| (getJSDocPrivateTag(node) ? ModifierFlags.Private : ModifierFlags.None) | ||
| (getJSDocProtectedTag(node) ? ModifierFlags.Protected : ModifierFlags.None); | ||
return flags | tags; | ||
} | ||
return flags; | ||
} | ||
|
||
export function modifierToFlag(token: SyntaxKind): ModifierFlags { | ||
switch (token) { | ||
case SyntaxKind.StaticKeyword: return ModifierFlags.Static; | ||
|
Uh oh!
There was an error while loading. Please reload this page.