Export internal functions needed by dtsBundler.mjs (#52941)

This commit is contained in:
Jake Bailey
2024-01-11 11:15:58 -08:00
committed by GitHub
parent 1717826b6e
commit 67b644e543
11 changed files with 64 additions and 63 deletions
+4 -5
View File
@@ -875,7 +875,6 @@ import {
NonNullExpression,
not,
noTruncationMaximumTruncationLength,
nullTransformationContext,
NumberLiteralType,
NumericLiteral,
objectAllocator,
@@ -2365,7 +2364,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function markAsSynthetic<T extends Node>(node: T): VisitResult<T> {
setTextRangePosEnd(node, -1, -1);
return visitEachChild(node, markAsSynthetic, nullTransformationContext);
return visitEachChild(node, markAsSynthetic, /*context*/ undefined);
}
function getEmitResolver(sourceFile: SourceFile, cancellationToken: CancellationToken) {
@@ -7032,7 +7031,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (!nodeIsSynthesized(node) && getParseTreeNode(node) === node) {
return node;
}
return setTextRange(factory.cloneNode(visitEachChild(node, deepCloneOrReuseNode, nullTransformationContext, deepCloneOrReuseNodes)), node);
return setTextRange(factory.cloneNode(visitEachChild(node, deepCloneOrReuseNode, /*context*/ undefined, deepCloneOrReuseNodes)), node);
}
function deepCloneOrReuseNodes(
@@ -7826,7 +7825,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (context.tracker.canTrackSymbol && isComputedPropertyName(node) && isLateBindableName(node)) {
trackComputedName(node.expression, context.enclosingDeclaration, context);
}
let visited = visitEachChild(node, elideInitializerAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags)!;
let visited = visitEachChild(node, elideInitializerAndSetEmitFlags, /*context*/ undefined, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags)!;
if (isBindingElement(visited)) {
visited = factory.updateBindingElement(
visited,
@@ -8663,7 +8662,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
setEmitFlags(node, EmitFlags.SingleLine);
}
return visitEachChild(node, visitExistingNodeTreeSymbols, nullTransformationContext);
return visitEachChild(node, visitExistingNodeTreeSymbols, /*context*/ undefined);
function getEffectiveDotDotDotForParameter(p: ParameterDeclaration) {
return p.dotDotDotToken || (p.type && isJSDocVariadicType(p.type) ? factory.createToken(SyntaxKind.DotDotDotToken) : undefined);
+1 -35
View File
@@ -14,7 +14,6 @@ import {
canHaveModifiers,
canProduceDiagnostics,
ClassDeclaration,
CommentRange,
compact,
concatenate,
ConditionalTypeNode,
@@ -63,8 +62,6 @@ import {
getExternalModuleImportEqualsDeclarationExpression,
getExternalModuleNameFromDeclaration,
getFirstConstructorWithBody,
getLeadingCommentRanges,
getLeadingCommentRangesOfNode,
getLineAndCharacterOfPosition,
getNameOfDeclaration,
getNormalizedAbsolutePath,
@@ -80,7 +77,6 @@ import {
GetSymbolAccessibilityDiagnostic,
getTextOfNode,
getThisParameter,
getTrailingCommentRanges,
hasDynamicName,
hasEffectiveModifier,
hasExtension,
@@ -126,6 +122,7 @@ import {
isImportEqualsDeclaration,
isIndexSignatureDeclaration,
isInterfaceDeclaration,
isInternalDeclaration,
isJsonSourceFile,
isLateVisibilityPaintedStatement,
isLiteralImportTypeNode,
@@ -158,7 +155,6 @@ import {
isVariableDeclaration,
isVarUsing,
JSDocFunctionType,
last,
LateBoundDeclaration,
LateVisibilityPaintedStatement,
length,
@@ -202,7 +198,6 @@ import {
setParent,
setTextRange,
SignatureDeclaration,
skipTrivia,
some,
SourceFile,
startsWith,
@@ -243,35 +238,6 @@ export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver
return result.diagnostics;
}
function hasInternalAnnotation(range: CommentRange, currentSourceFile: SourceFile) {
const comment = currentSourceFile.text.substring(range.pos, range.end);
return comment.includes("@internal");
}
/** @internal */
export function isInternalDeclaration(node: Node, currentSourceFile: SourceFile) {
const parseTreeNode = getParseTreeNode(node);
if (parseTreeNode && parseTreeNode.kind === SyntaxKind.Parameter) {
const paramIdx = (parseTreeNode.parent as SignatureDeclaration).parameters.indexOf(parseTreeNode as ParameterDeclaration);
const previousSibling = paramIdx > 0 ? (parseTreeNode.parent as SignatureDeclaration).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 => {
return hasInternalAnnotation(range, currentSourceFile);
});
}
const declarationEmitNodeBuilderFlags = NodeBuilderFlags.MultilineObjectLiterals |
NodeBuilderFlags.WriteClassExpressionAsTypeLiteral |
NodeBuilderFlags.UseTypeOfFunction |
+4 -5
View File
@@ -156,7 +156,6 @@ import {
NodeCheckFlags,
NodeFlags,
nodeIsSynthesized,
nullTransformationContext,
NumericLiteral,
ObjectLiteralElementLike,
ObjectLiteralExpression,
@@ -1642,12 +1641,12 @@ export function transformES2015(context: TransformationContext): (x: SourceFile
case SyntaxKind.PropertyDeclaration: {
const named = node as AccessorDeclaration | MethodDeclaration | PropertyDeclaration;
if (isComputedPropertyName(named.name)) {
return factory.replacePropertyName(named, visitEachChild(named.name, elideUnusedThisCaptureWorker, nullTransformationContext));
return factory.replacePropertyName(named, visitEachChild(named.name, elideUnusedThisCaptureWorker, /*context*/ undefined));
}
return node;
}
}
return visitEachChild(node, elideUnusedThisCaptureWorker, nullTransformationContext);
return visitEachChild(node, elideUnusedThisCaptureWorker, /*context*/ undefined);
}
/**
@@ -1728,12 +1727,12 @@ export function transformES2015(context: TransformationContext): (x: SourceFile
case SyntaxKind.PropertyDeclaration: {
const named = node as AccessorDeclaration | MethodDeclaration | PropertyDeclaration;
if (isComputedPropertyName(named.name)) {
return factory.replacePropertyName(named, visitEachChild(named.name, injectSuperPresenceCheckWorker, nullTransformationContext));
return factory.replacePropertyName(named, visitEachChild(named.name, injectSuperPresenceCheckWorker, /*context*/ undefined));
}
return node;
}
}
return visitEachChild(node, injectSuperPresenceCheckWorker, nullTransformationContext);
return visitEachChild(node, injectSuperPresenceCheckWorker, /*context*/ undefined);
}
/**
-1
View File
@@ -2432,7 +2432,6 @@ export const fullTripleSlashAMDReferencePathRegEx = /^(\/\/\/\s*<amd-dependency\
const fullTripleSlashAMDModuleRegEx = /^\/\/\/\s*<amd-module\s+.*?\/>/;
const defaultLibReferenceRegEx = /^(\/\/\/\s*<reference\s+no-default-lib\s*=\s*)(('[^']*')|("[^"]*"))\s*\/>/;
/** @internal */
export function isPartOfTypeNode(node: Node): boolean {
if (SyntaxKind.FirstTypeNode <= node.kind && node.kind <= SyntaxKind.LastTypeNode) {
return true;
+39 -1
View File
@@ -32,8 +32,10 @@ import {
ClassLikeDeclaration,
ClassStaticBlockDeclaration,
combinePaths,
CommentRange,
compareDiagnostics,
CompilerOptions,
concatenate,
ConciseBody,
ConstructorDeclaration,
ConstructorTypeNode,
@@ -62,6 +64,7 @@ import {
filter,
find,
flatMap,
forEach,
ForInitializer,
ForInOrOfStatement,
FunctionBody,
@@ -81,6 +84,10 @@ import {
getJSDocCommentsAndTags,
getJSDocRoot,
getJSDocTypeParameterDeclarations,
getLeadingCommentRanges,
getLeadingCommentRangesOfNode,
getSourceFileOfNode,
getTrailingCommentRanges,
hasAccessorModifier,
HasDecorators,
hasDecorators,
@@ -204,6 +211,7 @@ import {
JsxTagNameExpression,
KeywordSyntaxKind,
LabeledStatement,
last,
lastOrUndefined,
LeftHandSideExpression,
length,
@@ -258,9 +266,11 @@ import {
setUILocale,
SignatureDeclaration,
skipOuterExpressions,
skipTrivia,
some,
sortAndDeduplicate,
SortedReadonlyArray,
SourceFile,
Statement,
StringLiteral,
StringLiteralLike,
@@ -2376,7 +2386,6 @@ export function isDeclaration(node: Node): node is NamedDeclaration {
return isDeclarationKind(node.kind);
}
/** @internal */
export function isDeclarationStatement(node: Node): node is DeclarationStatement {
return isDeclarationStatementKind(node.kind);
}
@@ -2606,3 +2615,32 @@ export function isRestParameter(node: ParameterDeclaration | JSDocParameterTag):
const type = isJSDocParameterTag(node) ? (node.typeExpression && node.typeExpression.type) : node.type;
return (node as ParameterDeclaration).dotDotDotToken !== undefined || !!type && type.kind === SyntaxKind.JSDocVariadicType;
}
function hasInternalAnnotation(range: CommentRange, sourceFile: SourceFile) {
const comment = sourceFile.text.substring(range.pos, range.end);
return comment.includes("@internal");
}
export function isInternalDeclaration(node: Node, sourceFile?: SourceFile) {
sourceFile ??= getSourceFileOfNode(node);
const parseTreeNode = getParseTreeNode(node);
if (parseTreeNode && parseTreeNode.kind === SyntaxKind.Parameter) {
const paramIdx = (parseTreeNode.parent as SignatureDeclaration).parameters.indexOf(parseTreeNode as ParameterDeclaration);
const previousSibling = paramIdx > 0 ? (parseTreeNode.parent as SignatureDeclaration).parameters[paramIdx - 1] : undefined;
const text = sourceFile.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 some(commentRanges) && hasInternalAnnotation(last(commentRanges), sourceFile);
}
const leadingCommentRanges = parseTreeNode && getLeadingCommentRangesOfNode(parseTreeNode, sourceFile);
return !!forEach(leadingCommentRanges, range => {
return hasInternalAnnotation(range, sourceFile!);
});
}
+6 -5
View File
@@ -90,6 +90,7 @@ import {
NodeArray,
NodesVisitor,
NodeVisitor,
nullTransformationContext,
ParameterDeclaration,
ScriptTarget,
setEmitFlags,
@@ -580,9 +581,9 @@ export function visitCommaListElements(elements: NodeArray<Expression>, visitor:
* @param visitor The callback used to visit each child.
* @param context A lexical environment context for the visitor.
*/
export function visitEachChild<T extends Node>(node: T, visitor: Visitor, context: TransformationContext): T;
export function visitEachChild<T extends Node>(node: T, visitor: Visitor, context: TransformationContext | undefined): T;
/** @internal */
export function visitEachChild<T extends Node>(node: T, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor, tokenVisitor?: Visitor, nodeVisitor?: NodeVisitor): T; // eslint-disable-line @typescript-eslint/unified-signatures
export function visitEachChild<T extends Node>(node: T, visitor: Visitor, context: TransformationContext | undefined, nodesVisitor?: NodesVisitor, tokenVisitor?: Visitor, nodeVisitor?: NodeVisitor): T; // eslint-disable-line @typescript-eslint/unified-signatures
/**
* Visits each child of a Node using the supplied visitor, possibly returning a new Node of the same kind in its place.
*
@@ -590,10 +591,10 @@ export function visitEachChild<T extends Node>(node: T, visitor: Visitor, contex
* @param visitor The callback used to visit each child.
* @param context A lexical environment context for the visitor.
*/
export function visitEachChild<T extends Node>(node: T | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: typeof visitNodes, tokenVisitor?: Visitor): T | undefined;
export function visitEachChild<T extends Node>(node: T | undefined, visitor: Visitor, context: TransformationContext | undefined, nodesVisitor?: typeof visitNodes, tokenVisitor?: Visitor): T | undefined;
/** @internal */
export function visitEachChild<T extends Node>(node: T | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: NodesVisitor, tokenVisitor?: Visitor, nodeVisitor?: NodeVisitor): T | undefined;
export function visitEachChild<T extends Node>(node: T | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor = visitNodes, tokenVisitor?: Visitor, nodeVisitor: NodeVisitor = visitNode): T | undefined {
export function visitEachChild<T extends Node>(node: T | undefined, visitor: Visitor, context: TransformationContext | undefined, nodesVisitor?: NodesVisitor, tokenVisitor?: Visitor, nodeVisitor?: NodeVisitor): T | undefined;
export function visitEachChild<T extends Node>(node: T | undefined, visitor: Visitor, context = nullTransformationContext, nodesVisitor = visitNodes, tokenVisitor?: Visitor, nodeVisitor: NodeVisitor = visitNode): T | undefined {
if (node === undefined) {
return undefined;
}
@@ -27,7 +27,6 @@ import {
last,
map,
Node,
nullTransformationContext,
ParameterDeclaration,
PropertyDeclaration,
PropertySignature,
@@ -144,7 +143,7 @@ function transformJSDocType(node: Node): Node {
case SyntaxKind.JSDocTypeLiteral:
return transformJSDocTypeLiteral(node as JSDocTypeLiteral);
default:
const visited = visitEachChild(node, transformJSDocType, nullTransformationContext);
const visited = visitEachChild(node, transformJSDocType, /*context*/ undefined);
setEmitFlags(visited, EmitFlags.SingleLine);
return visited;
}
+1 -2
View File
@@ -70,7 +70,6 @@ import {
NodeArray,
NodeBuilderFlags,
NodeFlags,
nullTransformationContext,
ObjectFlags,
ObjectLiteralExpression,
ObjectType,
@@ -913,7 +912,7 @@ export function tryGetAutoImportableReferenceFromTypeNode(importTypeNode: TypeNo
const typeArguments = visitNodes(node.typeArguments, visit, isTypeNode);
return factory.createTypeReferenceNode(qualifier, typeArguments);
}
return visitEachChild(node, visit, nullTransformationContext);
return visitEachChild(node, visit, /*context*/ undefined);
}
}
+2 -3
View File
@@ -120,7 +120,6 @@ import {
Node,
NodeBuilderFlags,
NodeFlags,
nullTransformationContext,
ObjectLiteralElementLike,
ParameterDeclaration,
positionIsSynthesized,
@@ -1648,7 +1647,7 @@ function transformFunctionBody(body: Node, exposedVariableDeclarations: readonly
const oldIgnoreReturns = ignoreReturns;
ignoreReturns = ignoreReturns || isFunctionLikeDeclaration(node) || isClassLike(node);
const substitution = substitutions.get(getNodeId(node).toString());
const result = substitution ? getSynthesizedDeepClone(substitution) : visitEachChild(node, visitor, nullTransformationContext);
const result = substitution ? getSynthesizedDeepClone(substitution) : visitEachChild(node, visitor, /*context*/ undefined);
ignoreReturns = oldIgnoreReturns;
return result;
}
@@ -1662,7 +1661,7 @@ function transformConstantInitializer(initializer: Expression, substitutions: Re
function visitor(node: Node): VisitResult<Node> {
const substitution = substitutions.get(getNodeId(node).toString());
return substitution ? getSynthesizedDeepClone(substitution) : visitEachChild(node, visitor, nullTransformationContext);
return substitution ? getSynthesizedDeepClone(substitution) : visitEachChild(node, visitor, /*context*/ undefined);
}
}
+1 -2
View File
@@ -294,7 +294,6 @@ import {
normalizePath,
NoSubstitutionTemplateLiteral,
notImplemented,
nullTransformationContext,
NumericLiteral,
or,
OrganizeImports,
@@ -3175,7 +3174,7 @@ function getSynthesizedDeepCloneWorker<T extends Node>(node: T, replaceNode?: (n
const nodesClone: <T extends Node>(ns: NodeArray<T> | undefined) => NodeArray<T> | undefined = replaceNode
? ns => ns && getSynthesizedDeepClonesWithReplacements(ns, /*includeTrivia*/ true, replaceNode)
: ns => ns && getSynthesizedDeepClones(ns);
const visited = visitEachChild(node, nodeClone, nullTransformationContext, nodesClone, nodeClone);
const visited = visitEachChild(node, nodeClone, /*context*/ undefined, nodesClone, nodeClone);
if (visited === node) {
// This only happens for leaf nodes - internal nodes always see their children change.
+5 -2
View File
@@ -9198,6 +9198,7 @@ declare namespace ts {
function isForInitializer(node: Node): node is ForInitializer;
function isModuleBody(node: Node): node is ModuleBody;
function isNamedImportBindings(node: Node): node is NamedImportBindings;
function isDeclarationStatement(node: Node): node is DeclarationStatement;
function isStatement(node: Node): node is Statement;
function isModuleReference(node: Node): node is ModuleReference;
function isJsxTagNameExpression(node: Node): node is JsxTagNameExpression;
@@ -9217,11 +9218,13 @@ declare namespace ts {
function isJSDocLinkLike(node: Node): node is JSDocLink | JSDocLinkCode | JSDocLinkPlain;
function hasRestParameter(s: SignatureDeclaration | JSDocSignature): boolean;
function isRestParameter(node: ParameterDeclaration | JSDocParameterTag): boolean;
function isInternalDeclaration(node: Node, sourceFile?: SourceFile): boolean;
const unchangedTextChangeRange: TextChangeRange;
type ParameterPropertyDeclaration = ParameterDeclaration & {
parent: ConstructorDeclaration;
name: Identifier;
};
function isPartOfTypeNode(node: Node): boolean;
/**
* This function checks multiple locations for JSDoc comments that apply to a host node.
* At each location, the whole comment may apply to the node, or only a specific tag in
@@ -9860,7 +9863,7 @@ declare namespace ts {
* @param visitor The callback used to visit each child.
* @param context A lexical environment context for the visitor.
*/
function visitEachChild<T extends Node>(node: T, visitor: Visitor, context: TransformationContext): T;
function visitEachChild<T extends Node>(node: T, visitor: Visitor, context: TransformationContext | undefined): T;
/**
* Visits each child of a Node using the supplied visitor, possibly returning a new Node of the same kind in its place.
*
@@ -9868,7 +9871,7 @@ declare namespace ts {
* @param visitor The callback used to visit each child.
* @param context A lexical environment context for the visitor.
*/
function visitEachChild<T extends Node>(node: T | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: typeof visitNodes, tokenVisitor?: Visitor): T | undefined;
function visitEachChild<T extends Node>(node: T | undefined, visitor: Visitor, context: TransformationContext | undefined, nodesVisitor?: typeof visitNodes, tokenVisitor?: Visitor): T | undefined;
function getTsBuildInfoEmitOutputFilePath(options: CompilerOptions): string | undefined;
function getOutputFileNames(commandLine: ParsedCommandLine, inputFileName: string, ignoreCase: boolean): readonly string[];
function createPrinter(printerOptions?: PrinterOptions, handlers?: PrintHandlers): Printer;