Skip to content

Commit 3793fec

Browse files
committed
Progress
1 parent b6f888c commit 3793fec

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

src/compiler/checker.ts

+10-22
Original file line numberDiff line numberDiff line change
@@ -5882,6 +5882,8 @@ namespace ts {
58825882
typeParameters = signature.typeParameters && signature.typeParameters.map(parameter => typeParameterToDeclaration(parameter, context));
58835883
}
58845884

5885+
const expandedParams = getExpandedParameters(signature, /*skipUnionExpanding*/ true)[0];
5886+
58855887
// For regular function/method declarations, the enclosing declaration will already be signature.declaration,
58865888
// so this is a no-op, but for arrow functions and function expressions, the enclosing declaration will be
58875889
// the declaration that the arrow function / function expression is assigned to.
@@ -5902,12 +5904,11 @@ namespace ts {
59025904
if (saveEnclosingDeclaration && originalDeclaration && originalDeclaration !== saveEnclosingDeclaration && !isInJSFile(originalDeclaration)) {
59035905
// Debug.assert(!isJSDocSignature(originalDeclaration));
59045906
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
59085910
}
59095911

5910-
const expandedParams = getExpandedParameters(signature, /*skipUnionExpanding*/ true)[0];
59115912
// If the expanded parameter list had a variadic in a non-trailing position, don't expand it
59125913
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));
59135914
const thisParameter = context.flags & NodeBuilderFlags.OmitThisParameter ? undefined : tryGetThisParameterDeclaration(signature, context);
@@ -6482,6 +6483,7 @@ namespace ts {
64826483
return factory.createIdentifier("(Missing type parameter)");
64836484
}
64846485
if (context.flags & NodeBuilderFlags.GenerateNamesForShadowedTypeParams) {
6486+
// TODO(jakebailey): these casts would be better flipped.
64856487
const rawtext = result.escapedText as string;
64866488
let i = context.typeParameterNamesByTextNextNameCount?.get(rawtext) || 0;
64876489
let text = rawtext;
@@ -6651,22 +6653,8 @@ namespace ts {
66516653
return initial;
66526654
}
66536655

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-
66686656
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));
66706658
}
66716659

66726660
function existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(existing: TypeNode, type: Type) {
@@ -6692,7 +6680,7 @@ namespace ts {
66926680
}
66936681
}
66946682
const oldFlags = context.flags;
6695-
if (type.flags & TypeFlags.UniqueESSymbol &&
6683+
if (type.flags & TypeFlags.UniqueESSymbol && // TODO(jakebailey): isChildOfEnclosingDeclaration?
66966684
type.symbol === symbol && (!context.enclosingDeclaration || some(symbol.declarations, d => getSourceFileOfNode(d) === getSourceFileOfNode(context.enclosingDeclaration!)))) {
66976685
context.flags |= NodeBuilderFlags.AllowUniqueESSymbolType;
66986686
}
@@ -6715,7 +6703,7 @@ namespace ts {
67156703
function serializeReturnTypeForSignature(context: NodeBuilderContext, type: Type, signature: Signature, includePrivateSymbol?: (s: Symbol) => void, bundled?: boolean) {
67166704
if (!isErrorType(type) && context.enclosingDeclaration) {
67176705
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)) {
67196707
const annotated = getTypeFromTypeNode(annotation);
67206708
const thisInstantiated = annotated.flags & TypeFlags.TypeParameter && (annotated as TypeParameter).isThisType ? instantiateType(annotated, signature.mapper) : annotated;
67216709
if (thisInstantiated === type && existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(annotation, type)) {
@@ -7179,7 +7167,7 @@ namespace ts {
71797167
visitedSymbols.add(getSymbolId(visitedSym));
71807168
// Only actually serialize symbols within the correct enclosing declaration, otherwise do nothing with the out-of-context symbol
71817169
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)))) {
71837171
const oldContext = context;
71847172
context = cloneNodeBuilderContext(context);
71857173
serializeSymbolWorker(symbol, isPrivate, propertyAsAlias);

0 commit comments

Comments
 (0)