-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Omnibus fixes for telemetry-sourced crashes #20545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6e74f7e
2cf7295
b7b43fe
5c99c67
fa988ea
92c3b23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,6 @@ namespace ts.codefix { | |
return undefined; | ||
} | ||
|
||
const containingFunction = getContainingFunction(token); | ||
switch (errorCode) { | ||
// Variable and Property declarations | ||
case Diagnostics.Member_0_implicitly_has_an_1_type.code: | ||
|
@@ -81,6 +80,13 @@ namespace ts.codefix { | |
const symbol = program.getTypeChecker().getSymbolAtLocation(token); | ||
return symbol && symbol.valueDeclaration && getCodeActionForVariableDeclaration(<VariableDeclaration>symbol.valueDeclaration, sourceFile, program, cancellationToken); | ||
} | ||
} | ||
|
||
const containingFunction = getContainingFunction(token); | ||
if (containingFunction === undefined) { | ||
return undefined; | ||
} | ||
switch (errorCode) { | ||
|
||
// Parameter declarations | ||
case Diagnostics.Parameter_0_implicitly_has_an_1_type.code: | ||
|
@@ -148,6 +154,11 @@ namespace ts.codefix { | |
containingFunction.parameters.map(p => isIdentifier(p.name) ? inferTypeForVariableFromUsage(p.name, sourceFile, program, cancellationToken) : undefined); | ||
if (!types) return undefined; | ||
|
||
// We didn't actually find a set of type inference positions matching each parameter position | ||
if (containingFunction.parameters.length !== types.length) { | ||
return undefined; | ||
} | ||
|
||
const textChanges = arrayFrom(mapDefinedIterator(zipToIterator(containingFunction.parameters, types), ([parameter, type]) => | ||
type && !parameter.type && !parameter.initializer ? makeChange(containingFunction, parameter.end, type, program) : undefined)); | ||
return textChanges.length ? { declaration: parameterDeclaration, textChanges } : undefined; | ||
|
@@ -191,8 +202,9 @@ namespace ts.codefix { | |
sourceFile, | ||
token.getStart(sourceFile)); | ||
|
||
Debug.assert(!!references, "Found no references!"); | ||
Debug.assert(references.length === 1, "Found more references than expected"); | ||
if (!references || references.length !== 1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This variable is probably badly named. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it better to remove the asserts or leave them? There is minimal user impact either way (though throwing errors probably isn't good for perf), since we merely end up swallowing the error and writing it as part of the failure response. |
||
return []; | ||
} | ||
|
||
return references[0].references.map(r => <Identifier>getTokenAtPosition(program.getSourceFile(r.fileName), r.textSpan.start, /*includeJsDocComment*/ false)); | ||
} | ||
|
@@ -281,6 +293,10 @@ namespace ts.codefix { | |
} | ||
|
||
export function inferTypeForParametersFromReferences(references: Identifier[], declaration: FunctionLikeDeclaration, checker: TypeChecker, cancellationToken: CancellationToken): (Type | undefined)[] | undefined { | ||
if (references.length === 0) { | ||
return undefined; | ||
} | ||
|
||
if (declaration.parameters) { | ||
const usageContext: UsageContext = {}; | ||
for (const reference of references) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -496,7 +496,7 @@ namespace ts.SymbolDisplay { | |
addNewLineIfDisplayPartsExist(); | ||
if (symbolKind) { | ||
pushTypePart(symbolKind); | ||
if (!some(symbol.declarations, d => isArrowFunction(d) || (isFunctionExpression(d) || isClassExpression(d)) && !d.name)) { | ||
if (symbol && !some(symbol.declarations, d => isArrowFunction(d) || (isFunctionExpression(d) || isClassExpression(d)) && !d.name)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code path builds either anonymous or non-anonymous declarations (e.g. |
||
displayParts.push(spacePart()); | ||
addFullSymbolName(symbol); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @noImplicitAny: true | ||
//// function f(/*1*/x) { | ||
//// } | ||
//// f( | ||
|
||
verify.not.codeFixAvailable([]); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @noImplicitAny: true | ||
//// function f(new C(100, 3, undefined) | ||
|
||
verify.not.codeFixAvailable([]); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @noImplicitAny: true | ||
//// function ...q) {}} f(10); | ||
|
||
verify.not.codeFixAvailable([]); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
// @noImplicitAny: true | ||
//// function f(y, z = { p: y[ | ||
|
||
verify.getAndApplyCodeFix(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, I believe this will be deprecated by #18860. Good catch!