Skip to content

Prefer 'return Debug.fail()' over 'throw Debug.fail()' #22092

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

Merged
2 commits merged into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15325,7 +15325,7 @@ namespace ts {
const intrinsicElementsType = getJsxType(JsxNames.IntrinsicElements, node);
if (intrinsicElementsType !== unknownType) {
// Property case
if (!isIdentifier(node.tagName)) throw Debug.fail();
if (!isIdentifier(node.tagName)) return Debug.fail();
const intrinsicProp = getPropertyOfType(intrinsicElementsType, node.tagName.escapedText);
if (intrinsicProp) {
links.jsxFlags |= JsxFlags.IntrinsicNamedElement;
Expand Down Expand Up @@ -18093,7 +18093,7 @@ namespace ts {
}

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

const symbol = getSymbolOfNode(node);
if (symbol.flags & SymbolFlags.FunctionScopedVariable) {
if (!isIdentifier(node.name)) throw Debug.fail();
if (!isIdentifier(node.name)) return Debug.fail();
const localDeclarationSymbol = resolveName(node, node.name.escapedText, SymbolFlags.Variable, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false);
if (localDeclarationSymbol &&
localDeclarationSymbol !== symbol &&
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1545,10 +1545,10 @@ namespace ts {
let isDebugInfoEnabled = false;

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

export const assertEachNode = shouldAssert(AssertionLevel.Normal)
? (nodes: Node[], test: (node: Node) => boolean, message?: string): void => assert(
Expand Down
4 changes: 2 additions & 2 deletions src/services/classifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ namespace ts {
case SyntaxKind.NoSubstitutionTemplateLiteral:
return EndOfLineState.InTemplateHeadOrNoSubstitutionTemplate;
default:
throw Debug.fail("Only 'NoSubstitutionTemplateLiteral's and 'TemplateTail's can be unterminated; got SyntaxKind #" + token);
return Debug.fail("Only 'NoSubstitutionTemplateLiteral's and 'TemplateTail's can be unterminated; got SyntaxKind #" + token);
}
}
return lastOnTemplateStack === SyntaxKind.TemplateHead ? EndOfLineState.InTemplateSubstitutionPosition : undefined;
Expand Down Expand Up @@ -343,7 +343,7 @@ namespace ts {
case EndOfLineState.None:
return { prefix: "" };
default:
throw Debug.assertNever(lexState);
return Debug.assertNever(lexState);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/codefixes/importFixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ namespace ts.codefix {
// Fall back to the `import * as ns` style import.
return ImportKind.Namespace;
default:
throw Debug.assertNever(moduleKind);
return Debug.assertNever(moduleKind);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/codefixes/inferFromUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace ts.codefix {
return isSetAccessor(containingFunction) ? getCodeActionForSetAccessor(containingFunction, program, cancellationToken) : undefined;

default:
throw Debug.fail(String(errorCode));
return Debug.fail(String(errorCode));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace ts.Completions {
case CompletionDataKind.JsDocParameterName:
return jsdocCompletionInfo(JsDoc.getJSDocParameterNameCompletions(completionData.tag));
default:
throw Debug.assertNever(completionData);
return Debug.assertNever(completionData);
}
}

Expand Down Expand Up @@ -1453,7 +1453,7 @@ namespace ts.Completions {
isNewIdentifierLocation = false;

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

// We don't want to complete using the type acquired by the shape
// of the binding pattern; we are only interested in types acquired
Expand Down
2 changes: 1 addition & 1 deletion src/services/jsTyping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ namespace ts.JsTyping {
case PackageNameValidationResult.NameContainsNonURISafeCharacters:
return `Package name '${typing}' contains non URI safe characters`;
case PackageNameValidationResult.Ok:
throw Debug.fail(); // Shouldn't have called this.
return Debug.fail(); // Shouldn't have called this.
default:
Debug.assertNever(result);
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/textChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ namespace ts.textChanges {
else if (isVariableDeclaration(before)) { // insert `x = 1, ` into `const x = 1, y = 2;
return { suffix: ", " };
}
throw Debug.failBadSyntaxKind(before); // We haven't handled this kind of node yet -- add it
return Debug.failBadSyntaxKind(before); // We haven't handled this kind of node yet -- add it
}

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

/**
Expand Down