Skip to content

Enable noFallthroughCasesInSwitch #19109

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts
else {
options += " --lib es5"
}
options += " --noUnusedLocals --noUnusedParameters";
options += " --noUnusedLocals --noUnusedParameters --noFallthroughCasesInSwitch";

var cmd = host + " " + compilerPath + " " + options + " ";
cmd = cmd + sources.join(" ");
Expand Down
10 changes: 5 additions & 5 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1401,11 +1401,11 @@ namespace ts {
case SyntaxKind.SourceFile:
return ContainerFlags.IsContainer | ContainerFlags.IsControlFlowContainer | ContainerFlags.HasLocals;

// @ts-ignore falls through
case SyntaxKind.MethodDeclaration:
if (isObjectLiteralOrClassExpressionMethod(node)) {
return ContainerFlags.IsContainer | ContainerFlags.IsControlFlowContainer | ContainerFlags.HasLocals | ContainerFlags.IsFunctionLike | ContainerFlags.IsObjectLiteralOrClassExpressionMethod;
}
// falls through
case SyntaxKind.Constructor:
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.MethodSignature:
Expand Down Expand Up @@ -1700,12 +1700,12 @@ namespace ts {
case SyntaxKind.ModuleDeclaration:
declareModuleMember(node, symbolFlags, symbolExcludes);
break;
// @ts-ignore falls through
case SyntaxKind.SourceFile:
if (isExternalModule(<SourceFile>container)) {
declareModuleMember(node, symbolFlags, symbolExcludes);
break;
}
// falls through
default:
if (!blockScopeContainer.locals) {
blockScopeContainer.locals = createSymbolTable();
Expand Down Expand Up @@ -1980,6 +1980,7 @@ namespace ts {
function bindWorker(node: Node) {
switch (node.kind) {
/* Strict mode checks */
// @ts-ignore falls through
case SyntaxKind.Identifier:
// for typedef type names with namespaces, bind the new jsdoc type symbol here
// because it requires all containing namespaces to be in effect, namely the
Expand All @@ -1992,7 +1993,6 @@ namespace ts {
bindBlockScopedDeclaration(<Declaration>parentNode, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes);
break;
}
// falls through
case SyntaxKind.ThisKeyword:
if (currentFlow && (isExpression(node) || parent.kind === SyntaxKind.ShorthandPropertyAssignment)) {
node.flowNode = currentFlow;
Expand Down Expand Up @@ -2140,19 +2140,19 @@ namespace ts {
case SyntaxKind.SourceFile:
updateStrictModeStatementList((<SourceFile>node).statements);
return bindSourceFileIfExternalModule();
// @ts-ignore falls through
case SyntaxKind.Block:
if (!isFunctionLike(node.parent)) {
return;
}
// falls through
case SyntaxKind.ModuleBlock:
return updateStrictModeStatementList((<Block | ModuleBlock>node).statements);

// @ts-ignore falls through
case SyntaxKind.JSDocParameterTag:
if (node.parent.kind !== SyntaxKind.JSDocTypeLiteral) {
break;
}
// falls through
case SyntaxKind.JSDocPropertyTag:
const propTag = node as JSDocPropertyLikeTag;
const flags = propTag.isBracketed || propTag.typeExpression && propTag.typeExpression.type.kind === SyntaxKind.JSDocOptionalType ?
Expand Down
24 changes: 12 additions & 12 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -959,10 +959,10 @@ namespace ts {
}
}
switch (location.kind) {
// @ts-ignore falls through
case SyntaxKind.SourceFile:
if (!isExternalOrCommonJsModule(<SourceFile>location)) break;
isInExternalModule = true;
// falls through
case SyntaxKind.ModuleDeclaration:
const moduleExports = getSymbolOfNode(location).exports;
if (location.kind === SyntaxKind.SourceFile || isAmbientModule(location)) {
Expand Down Expand Up @@ -1288,11 +1288,11 @@ namespace ts {
case SyntaxKind.Identifier:
case SyntaxKind.PropertyAccessExpression:
return node.parent ? getEntityNameForExtendingInterface(node.parent) : undefined;
// @ts-ignore falls through
case SyntaxKind.ExpressionWithTypeArguments:
if (isEntityNameExpression((<ExpressionWithTypeArguments>node).expression)) {
return <EntityNameExpression>(<ExpressionWithTypeArguments>node).expression;
}
// falls through
default:
return undefined;
}
Expand Down Expand Up @@ -2075,11 +2075,11 @@ namespace ts {
}
}
switch (location.kind) {
// @ts-ignore falls through
case SyntaxKind.SourceFile:
if (!isExternalOrCommonJsModule(<SourceFile>location)) {
break;
}
// falls through
case SyntaxKind.ModuleDeclaration:
if (result = callback(getSymbolOfNode(location).exports)) {
return result;
Expand Down Expand Up @@ -3899,13 +3899,13 @@ namespace ts {
switch (node.kind) {
case SyntaxKind.BindingElement:
return isDeclarationVisible(<Declaration>node.parent.parent);
// @ts-ignore falls through
case SyntaxKind.VariableDeclaration:
if (isBindingPattern((node as VariableDeclaration).name) &&
!((node as VariableDeclaration).name as BindingPattern).elements.length) {
// If the binding pattern is empty, this variable declaration is not visible
return false;
}
// falls through
case SyntaxKind.ModuleDeclaration:
case SyntaxKind.ClassDeclaration:
case SyntaxKind.InterfaceDeclaration:
Expand All @@ -3931,13 +3931,13 @@ namespace ts {
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
case SyntaxKind.MethodDeclaration:
// @ts-ignore falls through
case SyntaxKind.MethodSignature:
if (hasModifier(node, ModifierFlags.Private | ModifierFlags.Protected)) {
// Private/protected properties/methods are not visible
return false;
}
// Public properties/methods are visible if its parents are visible, so:
// falls through

case SyntaxKind.Constructor:
case SyntaxKind.ConstructSignature:
Expand Down Expand Up @@ -13319,13 +13319,13 @@ namespace ts {
switch (getSpecialPropertyAssignmentKind(binaryExpression)) {
case SpecialPropertyAssignmentKind.None:
break;
// @ts-ignore falls through
case SpecialPropertyAssignmentKind.Property:
// If `binaryExpression.left` was assigned a symbol, then this is a new declaration; otherwise it is an assignment to an existing declaration.
// See `bindStaticPropertyAssignment` in `binder.ts`.
if (!binaryExpression.left.symbol) {
break;
}
// falls through
case SpecialPropertyAssignmentKind.ExportsProperty:
case SpecialPropertyAssignmentKind.ModuleExports:
case SpecialPropertyAssignmentKind.PrototypeProperty:
Expand Down Expand Up @@ -18430,11 +18430,11 @@ namespace ts {
return checkPropertyAccessExpression(<PropertyAccessExpression>node);
case SyntaxKind.ElementAccessExpression:
return checkIndexedAccess(<ElementAccessExpression>node);
// @ts-ignore falls through
case SyntaxKind.CallExpression:
if ((<CallExpression>node).expression.kind === SyntaxKind.ImportKeyword) {
return checkImportCallExpression(<ImportCall>node);
}
/* falls through */
case SyntaxKind.NewExpression:
return checkCallExpression(<CallExpression>node);
case SyntaxKind.TaggedTemplateExpression:
Expand Down Expand Up @@ -22383,6 +22383,7 @@ namespace ts {
grammarErrorOnFirstToken(node, Diagnostics.Imports_are_not_permitted_in_module_augmentations_Consider_moving_them_to_the_enclosing_external_module);
break;
case SyntaxKind.BindingElement:
// @ts-ignore falls through
case SyntaxKind.VariableDeclaration:
const name = (<VariableDeclaration | BindingElement>node).name;
if (isBindingPattern(name)) {
Expand All @@ -22392,7 +22393,6 @@ namespace ts {
}
break;
}
// falls through
case SyntaxKind.ClassDeclaration:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.FunctionDeclaration:
Expand Down Expand Up @@ -22795,9 +22795,9 @@ namespace ts {
return checkJSDocTypedefTag(node as JSDocTypedefTag);
case SyntaxKind.JSDocParameterTag:
return checkJSDocParameterTag(node as JSDocParameterTag);
// @ts-ignore falls through
case SyntaxKind.JSDocFunctionType:
checkSignatureDeclaration(node as JSDocFunctionType);
// falls through
case SyntaxKind.JSDocVariadicType:
case SyntaxKind.JSDocNonNullableType:
case SyntaxKind.JSDocNullableType:
Expand Down Expand Up @@ -23077,12 +23077,12 @@ namespace ts {
case SyntaxKind.EnumDeclaration:
copySymbols(getSymbolOfNode(location).exports, meaning & SymbolFlags.EnumMember);
break;
// @ts-ignore falls through
case SyntaxKind.ClassExpression:
const className = (<ClassExpression>location).name;
if (className) {
copySymbol(location.symbol, meaning);
}
// falls through
// this fall-through is necessary because we would like to handle
// type parameter inside class expression similar to how we handle it in classDeclaration and interface Declaration
case SyntaxKind.ClassDeclaration:
Expand Down Expand Up @@ -23387,6 +23387,7 @@ namespace ts {
case SyntaxKind.QualifiedName:
return getSymbolOfEntityNameOrPropertyAccessExpression(<EntityName | PropertyAccessExpression>node);

// @ts-ignore falls through
case SyntaxKind.ThisKeyword:
const container = getThisContainer(node, /*includeArrowFunctions*/ false);
if (isFunctionLike(container)) {
Expand All @@ -23398,7 +23399,6 @@ namespace ts {
if (isInExpressionContext(node)) {
return checkExpression(node as Expression).symbol;
}
// falls through

case SyntaxKind.ThisType:
return getTypeFromThisTypeNode(node as ThisExpression | ThisTypeNode).symbol;
Expand All @@ -23414,6 +23414,7 @@ namespace ts {
}
return undefined;

// @ts-ignore falls through
case SyntaxKind.StringLiteral:
// 1). import x = require("./mo/*gotToDefinitionHere*/d")
// 2). External module name in an import declaration
Expand All @@ -23423,7 +23424,6 @@ namespace ts {
((isInJavaScriptFile(node) && isRequireCall(node.parent, /*checkArgumentIsStringLiteral*/ false)) || isImportCall(node.parent))) {
return resolveExternalModuleName(node, <LiteralExpression>node);
}
// falls through

case SyntaxKind.NumericLiteral:
// index access
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4027,11 +4027,11 @@ namespace ts {
node = (<ConditionalExpression>node).condition;
continue;

// @ts-ignore falls through
case SyntaxKind.CallExpression:
if (stopAtCallExpressions) {
return node;
}
// falls through
case SyntaxKind.ElementAccessExpression:
case SyntaxKind.PropertyAccessExpression:
node = (<CallExpression | PropertyAccessExpression | ElementAccessExpression>node).expression;
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3738,11 +3738,11 @@ namespace ts {
// UnaryExpression (modified):
// < type > UnaryExpression
return parseTypeAssertion();
// @ts-ignore falls through
case SyntaxKind.AwaitKeyword:
if (isAwaitExpression()) {
return parseAwaitExpression();
}
// falls through
default:
return parseUpdateExpression();
}
Expand Down Expand Up @@ -3771,13 +3771,13 @@ namespace ts {
case SyntaxKind.VoidKeyword:
case SyntaxKind.AwaitKeyword:
return false;
// @ts-ignore falls through
case SyntaxKind.LessThanToken:
// If we are not in JSX context, we are parsing TypeAssertion which is an UnaryExpression
if (sourceFile.languageVariant !== LanguageVariant.JSX) {
return false;
}
// We are in JSX context and the token is part of JSXElement.
// falls through
default:
return true;
}
Expand Down Expand Up @@ -6450,6 +6450,7 @@ namespace ts {
indent += whitespace.length;
}
break;
// @ts-ignore falls through
case SyntaxKind.AsteriskToken:
if (state === JSDocState.BeginningOfLine) {
// leading asterisks start recording on the *next* (non-whitespace) token
Expand All @@ -6458,7 +6459,6 @@ namespace ts {
break;
}
// record the * as a comment
// falls through
default:
state = JSDocState.SavingComments; // leading identifiers start recording as well
pushComment(scanner.getTokenText());
Expand Down
7 changes: 3 additions & 4 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1329,12 +1329,12 @@ namespace ts {

switch (parent.kind) {
case SyntaxKind.Parameter:
// @ts-ignore falls through
case SyntaxKind.PropertyDeclaration:
if ((<ParameterDeclaration | PropertyDeclaration>parent).questionToken === node) {
diagnostics.push(createDiagnosticForNode(node, Diagnostics._0_can_only_be_used_in_a_ts_file, "?"));
return;
}
// falls through
case SyntaxKind.MethodDeclaration:
case SyntaxKind.MethodSignature:
case SyntaxKind.Constructor:
Expand Down Expand Up @@ -1410,13 +1410,13 @@ namespace ts {
case SyntaxKind.SetAccessor:
case SyntaxKind.FunctionExpression:
case SyntaxKind.FunctionDeclaration:
// @ts-ignore falls through
case SyntaxKind.ArrowFunction:
// Check type parameters
if (nodes === (<ClassDeclaration | FunctionLikeDeclaration>parent).typeParameters) {
diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.type_parameter_declarations_can_only_be_used_in_a_ts_file));
return;
}
// falls through
case SyntaxKind.VariableStatement:
// Check modifiers
if (nodes === (<ClassDeclaration | FunctionLikeDeclaration | VariableStatement>parent).modifiers) {
Expand Down Expand Up @@ -1460,12 +1460,11 @@ namespace ts {
function checkModifiers(modifiers: NodeArray<Modifier>, isConstValid: boolean) {
for (const modifier of modifiers) {
switch (modifier.kind) {
// @ts-ignore falls through
case SyntaxKind.ConstKeyword:
if (isConstValid) {
continue;
}
// to report error,
// falls through
case SyntaxKind.PublicKeyword:
case SyntaxKind.PrivateKeyword:
case SyntaxKind.ProtectedKeyword:
Expand Down
Loading