Skip to content

Commit ba8879d

Browse files
author
Andy
authored
Prefer 'return Debug.fail()' over 'throw Debug.fail()' (#22092)
1 parent b151573 commit ba8879d

File tree

8 files changed

+14
-14
lines changed

8 files changed

+14
-14
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15333,7 +15333,7 @@ namespace ts {
1533315333
const intrinsicElementsType = getJsxType(JsxNames.IntrinsicElements, node);
1533415334
if (intrinsicElementsType !== unknownType) {
1533515335
// Property case
15336-
if (!isIdentifier(node.tagName)) throw Debug.fail();
15336+
if (!isIdentifier(node.tagName)) return Debug.fail();
1533715337
const intrinsicProp = getPropertyOfType(intrinsicElementsType, node.tagName.escapedText);
1533815338
if (intrinsicProp) {
1533915339
links.jsxFlags |= JsxFlags.IntrinsicNamedElement;
@@ -18106,7 +18106,7 @@ namespace ts {
1810618106
}
1810718107

1810818108
// Make sure require is not a local function
18109-
if (!isIdentifier(node.expression)) throw Debug.fail();
18109+
if (!isIdentifier(node.expression)) return Debug.fail();
1811018110
const resolvedRequire = resolveName(node.expression, node.expression.escapedText, SymbolFlags.Value, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ true);
1811118111
if (!resolvedRequire) {
1811218112
// project does not contain symbol named 'require' - assume commonjs require
@@ -21841,7 +21841,7 @@ namespace ts {
2184121841

2184221842
const symbol = getSymbolOfNode(node);
2184321843
if (symbol.flags & SymbolFlags.FunctionScopedVariable) {
21844-
if (!isIdentifier(node.name)) throw Debug.fail();
21844+
if (!isIdentifier(node.name)) return Debug.fail();
2184521845
const localDeclarationSymbol = resolveName(node, node.name.escapedText, SymbolFlags.Variable, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false);
2184621846
if (localDeclarationSymbol &&
2184721847
localDeclarationSymbol !== symbol &&

src/compiler/visitor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,10 +1545,10 @@ namespace ts {
15451545
let isDebugInfoEnabled = false;
15461546

15471547
export const failBadSyntaxKind = shouldAssert(AssertionLevel.Normal)
1548-
? (node: Node, message?: string): void => fail(
1548+
? (node: Node, message?: string): never => fail(
15491549
`${message || "Unexpected node."}\r\nNode ${formatSyntaxKind(node.kind)} was unexpected.`,
15501550
failBadSyntaxKind)
1551-
: noop;
1551+
: noop as () => never; // TODO: GH#22091
15521552

15531553
export const assertEachNode = shouldAssert(AssertionLevel.Normal)
15541554
? (nodes: Node[], test: (node: Node) => boolean, message?: string): void => assert(

src/services/classifier.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ namespace ts {
224224
case SyntaxKind.NoSubstitutionTemplateLiteral:
225225
return EndOfLineState.InTemplateHeadOrNoSubstitutionTemplate;
226226
default:
227-
throw Debug.fail("Only 'NoSubstitutionTemplateLiteral's and 'TemplateTail's can be unterminated; got SyntaxKind #" + token);
227+
return Debug.fail("Only 'NoSubstitutionTemplateLiteral's and 'TemplateTail's can be unterminated; got SyntaxKind #" + token);
228228
}
229229
}
230230
return lastOnTemplateStack === SyntaxKind.TemplateHead ? EndOfLineState.InTemplateSubstitutionPosition : undefined;
@@ -343,7 +343,7 @@ namespace ts {
343343
case EndOfLineState.None:
344344
return { prefix: "" };
345345
default:
346-
throw Debug.assertNever(lexState);
346+
return Debug.assertNever(lexState);
347347
}
348348
}
349349

src/services/codefixes/importFixes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ namespace ts.codefix {
699699
// Fall back to the `import * as ns` style import.
700700
return ImportKind.Namespace;
701701
default:
702-
throw Debug.assertNever(moduleKind);
702+
return Debug.assertNever(moduleKind);
703703
}
704704
}
705705

src/services/codefixes/inferFromUsage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ namespace ts.codefix {
109109
return isSetAccessor(containingFunction) ? getCodeActionForSetAccessor(containingFunction, program, cancellationToken) : undefined;
110110

111111
default:
112-
throw Debug.fail(String(errorCode));
112+
return Debug.fail(String(errorCode));
113113
}
114114
}
115115

src/services/completions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ namespace ts.Completions {
6969
case CompletionDataKind.JsDocParameterName:
7070
return jsdocCompletionInfo(JsDoc.getJSDocParameterNameCompletions(completionData.tag));
7171
default:
72-
throw Debug.assertNever(completionData);
72+
return Debug.assertNever(completionData);
7373
}
7474
}
7575

@@ -1453,7 +1453,7 @@ namespace ts.Completions {
14531453
isNewIdentifierLocation = false;
14541454

14551455
const rootDeclaration = getRootDeclaration(objectLikeContainer.parent);
1456-
if (!isVariableLike(rootDeclaration)) throw Debug.fail("Root declaration is not variable-like.");
1456+
if (!isVariableLike(rootDeclaration)) return Debug.fail("Root declaration is not variable-like.");
14571457

14581458
// We don't want to complete using the type acquired by the shape
14591459
// of the binding pattern; we are only interested in types acquired

src/services/jsTyping.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ namespace ts.JsTyping {
318318
case PackageNameValidationResult.NameContainsNonURISafeCharacters:
319319
return `Package name '${typing}' contains non URI safe characters`;
320320
case PackageNameValidationResult.Ok:
321-
throw Debug.fail(); // Shouldn't have called this.
321+
return Debug.fail(); // Shouldn't have called this.
322322
default:
323323
Debug.assertNever(result);
324324
}

src/services/textChanges.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ namespace ts.textChanges {
346346
else if (isVariableDeclaration(before)) { // insert `x = 1, ` into `const x = 1, y = 2;
347347
return { suffix: ", " };
348348
}
349-
throw Debug.failBadSyntaxKind(before); // We haven't handled this kind of node yet -- add it
349+
return Debug.failBadSyntaxKind(before); // We haven't handled this kind of node yet -- add it
350350
}
351351

352352
public insertNodeAtConstructorStart(sourceFile: SourceFile, ctr: ConstructorDeclaration, newStatement: Statement): void {
@@ -430,7 +430,7 @@ namespace ts.textChanges {
430430
else if (isVariableDeclaration(node)) {
431431
return { prefix: ", " };
432432
}
433-
throw Debug.failBadSyntaxKind(node); // We haven't handled this kind of node yet -- add it
433+
return Debug.failBadSyntaxKind(node); // We haven't handled this kind of node yet -- add it
434434
}
435435

436436
/**

0 commit comments

Comments
 (0)