mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Prefer 'return Debug.fail()' over 'throw Debug.fail()' (#22092)
This commit is contained in:
@@ -15333,7 +15333,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;
|
||||
@@ -18106,7 +18106,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
|
||||
@@ -21841,7 +21841,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 &&
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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;
|
||||
@@ -343,7 +343,7 @@ namespace ts {
|
||||
case EndOfLineState.None:
|
||||
return { prefix: "" };
|
||||
default:
|
||||
throw Debug.assertNever(lexState);
|
||||
return Debug.assertNever(lexState);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
@@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user