Skip to content

Commit 92c3b23

Browse files
committed
Bail at the correct point when containingFunction is undefined
1 parent fa988ea commit 92c3b23

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/services/codefixes/inferFromUsage.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ namespace ts.codefix {
7070
return undefined;
7171
}
7272

73-
const containingFunction = getContainingFunction(token);
74-
if (containingFunction === undefined) {
75-
// Possible in certain syntax error cases
76-
return undefined;
77-
}
7873
switch (errorCode) {
7974
// Variable and Property declarations
8075
case Diagnostics.Member_0_implicitly_has_an_1_type.code:
@@ -85,6 +80,13 @@ namespace ts.codefix {
8580
const symbol = program.getTypeChecker().getSymbolAtLocation(token);
8681
return symbol && symbol.valueDeclaration && getCodeActionForVariableDeclaration(<VariableDeclaration>symbol.valueDeclaration, sourceFile, program, cancellationToken);
8782
}
83+
}
84+
85+
const containingFunction = getContainingFunction(token);
86+
if (containingFunction === undefined) {
87+
return undefined;
88+
}
89+
switch (errorCode) {
8890

8991
// Parameter declarations
9092
case Diagnostics.Parameter_0_implicitly_has_an_1_type.code:
@@ -156,7 +158,7 @@ namespace ts.codefix {
156158
if (containingFunction.parameters.length !== types.length) {
157159
return undefined;
158160
}
159-
161+
160162
const textChanges = arrayFrom(mapDefinedIterator(zipToIterator(containingFunction.parameters, types), ([parameter, type]) =>
161163
type && !parameter.type && !parameter.initializer ? makeChange(containingFunction, parameter.end, type, program) : undefined));
162164
return textChanges.length ? { declaration: parameterDeclaration, textChanges } : undefined;

0 commit comments

Comments
 (0)