@@ -5882,6 +5882,8 @@ namespace ts {
5882
5882
typeParameters = signature.typeParameters && signature.typeParameters.map(parameter => typeParameterToDeclaration(parameter, context));
5883
5883
}
5884
5884
5885
+ const expandedParams = getExpandedParameters(signature, /*skipUnionExpanding*/ true)[0];
5886
+
5885
5887
// For regular function/method declarations, the enclosing declaration will already be signature.declaration,
5886
5888
// so this is a no-op, but for arrow functions and function expressions, the enclosing declaration will be
5887
5889
// the declaration that the arrow function / function expression is assigned to.
@@ -5902,12 +5904,11 @@ namespace ts {
5902
5904
if (saveEnclosingDeclaration && originalDeclaration && originalDeclaration !== saveEnclosingDeclaration && !isInJSFile(originalDeclaration)) {
5903
5905
// Debug.assert(!isJSDocSignature(originalDeclaration));
5904
5906
const clone = parseNodeFactory.cloneNode(originalDeclaration);
5905
- // setTextRange( clone, originalDeclaration ); // TODO(jakebailey): Is this needed?
5906
- setParent(clone, saveEnclosingDeclaration); // TODO(jakebailey): we can chain these if we want.
5907
- context.enclosingDeclaration = clone;
5907
+ clone.locals = createSymbolTable(expandedParams ); // We only care about the parameters, not type parameters.
5908
+ setParent(clone, saveEnclosingDeclaration);
5909
+ context.enclosingDeclaration = clone; // TODO(jakebailey): HERE
5908
5910
}
5909
5911
5910
- const expandedParams = getExpandedParameters(signature, /*skipUnionExpanding*/ true)[0];
5911
5912
// If the expanded parameter list had a variadic in a non-trailing position, don't expand it
5912
5913
const parameters = (some(expandedParams, p => p !== expandedParams[expandedParams.length - 1] && !!(getCheckFlags(p) & CheckFlags.RestParameter)) ? signature.parameters : expandedParams).map(parameter => symbolToParameterDeclaration(parameter, context, kind === SyntaxKind.Constructor, options?.privateSymbolVisitor, options?.bundledImports));
5913
5914
const thisParameter = context.flags & NodeBuilderFlags.OmitThisParameter ? undefined : tryGetThisParameterDeclaration(signature, context);
@@ -6482,6 +6483,7 @@ namespace ts {
6482
6483
return factory.createIdentifier("(Missing type parameter)");
6483
6484
}
6484
6485
if (context.flags & NodeBuilderFlags.GenerateNamesForShadowedTypeParams) {
6486
+ // TODO(jakebailey): these casts would be better flipped.
6485
6487
const rawtext = result.escapedText as string;
6486
6488
let i = context.typeParameterNamesByTextNextNameCount?.get(rawtext) || 0;
6487
6489
let text = rawtext;
@@ -6651,22 +6653,8 @@ namespace ts {
6651
6653
return initial;
6652
6654
}
6653
6655
6654
- function isChildOfEnclosingDeclaration(enclosingDeclaration: Node | undefined, node: Node): boolean {
6655
- return !!findAncestor(node, n => isEnclosingDeclarationOrOriginal(n));
6656
- // If our enclosing declaration was created via cloning, then the enclosing declaration won't be
6657
- // an ancestor of say, a parameter declaration, but an original node may be.
6658
- function isEnclosingDeclarationOrOriginal(n: Node): boolean {
6659
- for (let e = enclosingDeclaration; e; e = e.original) {
6660
- if (e === n) {
6661
- return true;
6662
- }
6663
- }
6664
- return false;
6665
- }
6666
- }
6667
-
6668
6656
function getDeclarationWithTypeAnnotation(symbol: Symbol, enclosingDeclaration: Node | undefined) {
6669
- return symbol.declarations && find(symbol.declarations, s => !!getEffectiveTypeAnnotationNode(s) && (!enclosingDeclaration || isChildOfEnclosingDeclaration(enclosingDeclaration, s) ));
6657
+ return symbol.declarations && find(symbol.declarations, s => !!getEffectiveTypeAnnotationNode(s) && !!findAncestor(s, n => n === enclosingDeclaration ));
6670
6658
}
6671
6659
6672
6660
function existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(existing: TypeNode, type: Type) {
@@ -6692,7 +6680,7 @@ namespace ts {
6692
6680
}
6693
6681
}
6694
6682
const oldFlags = context.flags;
6695
- if (type.flags & TypeFlags.UniqueESSymbol &&
6683
+ if (type.flags & TypeFlags.UniqueESSymbol && // TODO(jakebailey): isChildOfEnclosingDeclaration?
6696
6684
type.symbol === symbol && (!context.enclosingDeclaration || some(symbol.declarations, d => getSourceFileOfNode(d) === getSourceFileOfNode(context.enclosingDeclaration!)))) {
6697
6685
context.flags |= NodeBuilderFlags.AllowUniqueESSymbolType;
6698
6686
}
@@ -6715,7 +6703,7 @@ namespace ts {
6715
6703
function serializeReturnTypeForSignature(context: NodeBuilderContext, type: Type, signature: Signature, includePrivateSymbol?: (s: Symbol) => void, bundled?: boolean) {
6716
6704
if (!isErrorType(type) && context.enclosingDeclaration) {
6717
6705
const annotation = signature.declaration && getEffectiveReturnTypeNode(signature.declaration);
6718
- if (annotation && isChildOfEnclosingDeclaration(context.enclosingDeclaration, annotation)) { // TODO(jakebailey): this also needs to check original; move to helper
6706
+ if (annotation && findAncestor(annotation, n => n === context.enclosingDeclaration)) {
6719
6707
const annotated = getTypeFromTypeNode(annotation);
6720
6708
const thisInstantiated = annotated.flags & TypeFlags.TypeParameter && (annotated as TypeParameter).isThisType ? instantiateType(annotated, signature.mapper) : annotated;
6721
6709
if (thisInstantiated === type && existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(annotation, type)) {
@@ -7179,7 +7167,7 @@ namespace ts {
7179
7167
visitedSymbols.add(getSymbolId(visitedSym));
7180
7168
// Only actually serialize symbols within the correct enclosing declaration, otherwise do nothing with the out-of-context symbol
7181
7169
const skipMembershipCheck = !isPrivate; // We only call this on exported symbols when we know they're in the correct scope
7182
- if (skipMembershipCheck || (!!length(symbol.declarations) && some(symbol.declarations, d => isChildOfEnclosingDeclaration(enclosingDeclaration, d )))) {
7170
+ if (skipMembershipCheck || (!!length(symbol.declarations) && some(symbol.declarations, d => !!findAncestor(d, n => n === enclosingDeclaration )))) {
7183
7171
const oldContext = context;
7184
7172
context = cloneNodeBuilderContext(context);
7185
7173
serializeSymbolWorker(symbol, isPrivate, propertyAsAlias);
0 commit comments