mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 15:45:27 -05:00
improve stripInternal with inline comments (#23611)
* improve stripInternal with inline comments * fix lint * stash * simptify StripInternal * fix internal type declaration * fix internal type declaration again * accept baseline * refactor inline * simply prev check * remove getTrailingCommentRangesOfNode * Merge implementation with new isInternalDeclaration method, accept lkg-based baseline
This commit is contained in:
committed by
Wesley Wigham
parent
b15e64feba
commit
bd27296ba6
@@ -9,12 +9,31 @@ namespace ts {
|
||||
return result.diagnostics;
|
||||
}
|
||||
|
||||
function hasInternalAnnotation(range: CommentRange, currentSourceFile: SourceFile) {
|
||||
const comment = currentSourceFile.text.substring(range.pos, range.end);
|
||||
return stringContains(comment, "@internal");
|
||||
}
|
||||
|
||||
export function isInternalDeclaration(node: Node, currentSourceFile: SourceFile) {
|
||||
const parseTreeNode = getParseTreeNode(node);
|
||||
if (parseTreeNode && parseTreeNode.kind === SyntaxKind.Parameter) {
|
||||
const paramIdx = (parseTreeNode.parent as FunctionLike).parameters.indexOf(parseTreeNode as ParameterDeclaration);
|
||||
const previousSibling = paramIdx > 0 ? (parseTreeNode.parent as FunctionLike).parameters[paramIdx - 1] : undefined;
|
||||
const text = currentSourceFile.text;
|
||||
const commentRanges = previousSibling
|
||||
? concatenate(
|
||||
// to handle
|
||||
// ... parameters, /* @internal */
|
||||
// public param: string
|
||||
getTrailingCommentRanges(text, skipTrivia(text, previousSibling.end + 1, /* stopAfterLineBreak */ false, /* stopAtComments */ true)),
|
||||
getLeadingCommentRanges(text, node.pos)
|
||||
)
|
||||
: getTrailingCommentRanges(text, skipTrivia(text, node.pos, /* stopAfterLineBreak */ false, /* stopAtComments */ true));
|
||||
return commentRanges && commentRanges.length && hasInternalAnnotation(last(commentRanges), currentSourceFile);
|
||||
}
|
||||
const leadingCommentRanges = parseTreeNode && getLeadingCommentRangesOfNode(parseTreeNode, currentSourceFile);
|
||||
return !!forEach(leadingCommentRanges, range => {
|
||||
const comment = currentSourceFile.text.substring(range.pos, range.end);
|
||||
return stringContains(comment, "@internal");
|
||||
return hasInternalAnnotation(range, currentSourceFile);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1075,8 +1094,8 @@ namespace ts {
|
||||
let parameterProperties: ReadonlyArray<PropertyDeclaration> | undefined;
|
||||
if (ctor) {
|
||||
const oldDiag = getSymbolAccessibilityDiagnostic;
|
||||
parameterProperties = compact(flatMap(ctor.parameters, param => {
|
||||
if (!hasModifier(param, ModifierFlags.ParameterPropertyModifier)) return;
|
||||
parameterProperties = compact(flatMap(ctor.parameters, (param) => {
|
||||
if (!hasModifier(param, ModifierFlags.ParameterPropertyModifier) || shouldStripInternal(param)) return;
|
||||
getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(param);
|
||||
if (param.name.kind === SyntaxKind.Identifier) {
|
||||
return preserveJsDoc(createProperty(
|
||||
|
||||
@@ -221,7 +221,7 @@ namespace ts.server {
|
||||
|
||||
/*@internal*/
|
||||
constructor(
|
||||
readonly projectName: string,
|
||||
/*@internal*/ readonly projectName: string,
|
||||
readonly projectKind: ProjectKind,
|
||||
readonly projectService: ProjectService,
|
||||
private documentRegistry: DocumentRegistry,
|
||||
|
||||
Reference in New Issue
Block a user