diff --git a/src/services/codefixes/superFixes.ts b/src/services/codefixes/superFixes.ts index d06ba9df955..622ded06d31 100644 --- a/src/services/codefixes/superFixes.ts +++ b/src/services/codefixes/superFixes.ts @@ -10,7 +10,10 @@ namespace ts.codefix { getCodeActions: (context: CodeFixContext) => { const sourceFile = context.sourceFile; const token = getTokenAtPosition(sourceFile, context.span.start); - Debug.assert(token.kind === SyntaxKind.ConstructorKeyword, "Failed to find the constructor."); + + if (token.kind !== SyntaxKind.ConstructorKeyword) { + return undefined; + } const newPosition = getOpenBraceEnd(token.parent, sourceFile); return [{ @@ -26,14 +29,18 @@ namespace ts.codefix { const sourceFile = context.sourceFile; const token = getTokenAtPosition(sourceFile, context.span.start); - const constructor = getContainingFunction(token); - Debug.assert(constructor.kind === SyntaxKind.Constructor, "Failed to find the constructor."); + if (token.kind !== SyntaxKind.ConstructorKeyword) { + return undefined; + } + const constructor = getContainingFunction(token); const superCall = findSuperCall((constructor).body); - Debug.assert(!!superCall, "Failed to find super call."); + if (!superCall) { + return undefined; + } const newPosition = getOpenBraceEnd(constructor, sourceFile); - const changes = [{ + const changes = [{ fileName: sourceFile.fileName, textChanges: [{ newText: superCall.getText(sourceFile), span: { start: newPosition, length: 0 }