diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index b2ad2151bb638..aebbb7b3ca533 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1414,6 +1414,7 @@ namespace ts { 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: @@ -1715,7 +1716,7 @@ namespace ts { declareModuleMember(node, symbolFlags, symbolExcludes); break; } - // fall through. + // falls through default: if (!blockScopeContainer.locals) { blockScopeContainer.locals = createMap<Symbol>(); @@ -2009,6 +2010,7 @@ 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; @@ -2184,7 +2186,7 @@ namespace ts { if (!isFunctionLike(node.parent)) { return; } - // Fall through + // falls through case SyntaxKind.ModuleBlock: return updateStrictModeStatementList((<Block | ModuleBlock>node).statements); } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4dd739c395818..6e036bfc62120 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -902,6 +902,7 @@ namespace ts { 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)) { @@ -1938,6 +1939,7 @@ namespace ts { if (!isExternalOrCommonJsModule(<SourceFile>location)) { break; } + // falls through case SyntaxKind.ModuleDeclaration: if (result = callback(getSymbolOfNode(location).exports)) { return result; @@ -3658,7 +3660,7 @@ namespace ts { // If the binding pattern is empty, this variable declaration is not visible return false; } - // Otherwise fall through + // falls through case SyntaxKind.ModuleDeclaration: case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: @@ -3689,7 +3691,8 @@ namespace ts { // Private/protected properties/methods are not visible return false; } - // Public properties/methods are visible if its parents are visible, so const it fall into next case statement + // Public properties/methods are visible if its parents are visible, so: + // falls through case SyntaxKind.Constructor: case SyntaxKind.ConstructSignature: @@ -21050,7 +21053,7 @@ namespace ts { } break; } - // fallthrough + // falls through case SyntaxKind.ClassDeclaration: case SyntaxKind.EnumDeclaration: case SyntaxKind.FunctionDeclaration: @@ -21685,6 +21688,7 @@ namespace ts { if (!isExternalOrCommonJsModule(<SourceFile>location)) { break; } + // falls through case SyntaxKind.ModuleDeclaration: copySymbols(getSymbolOfNode(location).exports, meaning & SymbolFlags.ModuleMember); break; @@ -21696,7 +21700,8 @@ namespace ts { if (className) { copySymbol(location.symbol, meaning); } - // fall through; this fall-through is necessary because we would like to handle + // 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: case SyntaxKind.InterfaceDeclaration: @@ -21985,7 +21990,7 @@ namespace ts { return sig.thisParameter; } } - // fallthrough + // falls through case SyntaxKind.SuperKeyword: const type = isPartOfExpression(node) ? getTypeOfExpression(<Expression>node) : getTypeFromTypeNode(<TypeNode>node); @@ -22013,7 +22018,7 @@ namespace ts { if (isInJavaScriptFile(node) && isRequireCall(node.parent, /*checkArgumentIsStringLiteral*/ false)) { return resolveExternalModuleName(node, <LiteralExpression>node); } - // Fall through + // falls through case SyntaxKind.NumericLiteral: // index access diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 08144e7929952..dbfcf55129aa1 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3573,6 +3573,7 @@ namespace ts { if (isAwaitExpression()) { return parseAwaitExpression(); } + // falls through default: return parseIncrementExpression(); } @@ -3606,8 +3607,8 @@ namespace ts { if (sourceFile.languageVariant !== LanguageVariant.JSX) { return false; } - // We are in JSX context and the token is part of JSXElement. - // Fall through + // We are in JSX context and the token is part of JSXElement. + // falls through default: return true; } @@ -6571,7 +6572,8 @@ namespace ts { indent += scanner.getTokenText().length; break; } - // FALLTHROUGH otherwise to record the * as a comment + // record the * as a comment + // falls through default: state = JSDocState.SavingComments; // leading identifiers start recording as well pushComment(scanner.getTokenText()); @@ -6797,6 +6799,7 @@ namespace ts { break; case SyntaxKind.Identifier: canParseTag = false; + break; case SyntaxKind.EndOfFileToken: break; } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 47671ca792f6d..d7d93f49ee753 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -967,8 +967,7 @@ namespace ts { diagnostics.push(createDiagnosticForNode(node, Diagnostics._0_can_only_be_used_in_a_ts_file, "?")); return; } - - // Pass through + // falls through case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: @@ -1048,7 +1047,7 @@ namespace ts { diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.type_parameter_declarations_can_only_be_used_in_a_ts_file)); return; } - // pass through + // falls through case SyntaxKind.VariableStatement: // Check modifiers if (nodes === (<ClassDeclaration | FunctionLikeDeclaration | VariableStatement>parent).modifiers) { @@ -1096,7 +1095,8 @@ namespace ts { if (isConstValid) { continue; } - // Fallthrough to report error + // to report error, + // falls through case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 41c48700a9a04..406405600f179 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -308,6 +308,7 @@ namespace ts { if (text.charCodeAt(pos) === CharacterCodes.lineFeed) { pos++; } + // falls through case CharacterCodes.lineFeed: result.push(lineStart); lineStart = pos; @@ -454,6 +455,7 @@ namespace ts { if (text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) { pos++; } + // falls through case CharacterCodes.lineFeed: pos++; if (stopAfterLineBreak) { @@ -625,6 +627,7 @@ namespace ts { if (text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) { pos++; } + // falls through case CharacterCodes.lineFeed: pos++; if (trailing) { @@ -1072,7 +1075,7 @@ namespace ts { if (pos < end && text.charCodeAt(pos) === CharacterCodes.lineFeed) { pos++; } - // fall through + // falls through case CharacterCodes.lineFeed: case CharacterCodes.lineSeparator: case CharacterCodes.paragraphSeparator: @@ -1459,6 +1462,7 @@ namespace ts { // This fall-through is a deviation from the EcmaScript grammar. The grammar says that a leading zero // can only be followed by an octal digit, a dot, or the end of the number literal. However, we are being // permissive and allowing decimal digits of the form 08* and 09* (which many browsers also do). + // falls through case CharacterCodes._1: case CharacterCodes._2: case CharacterCodes._3: diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index cde4fcad57e76..5711d9f111667 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -479,8 +479,8 @@ namespace ts { // module is imported only for side-effects, no emit required break; } + // falls through - // fall-through case SyntaxKind.ImportEqualsDeclaration: Debug.assert(importVariableName !== undefined); // save import into the local diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 374cdfa4744dc..f34c15ee3467f 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -674,6 +674,7 @@ namespace ts { // At this point, node is either a qualified name or an identifier Debug.assert(node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName || node.kind === SyntaxKind.PropertyAccessExpression, "'node' was expected to be a qualified name, identifier or property access in 'isPartOfTypeNode'."); + // falls through case SyntaxKind.QualifiedName: case SyntaxKind.PropertyAccessExpression: case SyntaxKind.ThisKeyword: @@ -783,6 +784,7 @@ namespace ts { if (operand) { traverse(operand); } + return; case SyntaxKind.EnumDeclaration: case SyntaxKind.InterfaceDeclaration: case SyntaxKind.ModuleDeclaration: @@ -1000,7 +1002,7 @@ namespace ts { if (!includeArrowFunctions) { continue; } - // Fall through + // falls through case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ModuleDeclaration: @@ -1059,6 +1061,7 @@ namespace ts { if (!stopOnFunctions) { continue; } + // falls through case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: case SyntaxKind.MethodDeclaration: @@ -1258,7 +1261,7 @@ namespace ts { if (node.parent.kind === SyntaxKind.TypeQuery || isJSXTagName(node)) { return true; } - // fall through + // falls through case SyntaxKind.NumericLiteral: case SyntaxKind.StringLiteral: case SyntaxKind.ThisKeyword: @@ -1940,7 +1943,7 @@ namespace ts { if (node.asteriskToken) { flags |= FunctionFlags.Generator; } - // fall through + // falls through case SyntaxKind.ArrowFunction: if (hasModifier(node, ModifierFlags.Async)) { flags |= FunctionFlags.Async; diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 297d2cc0dde3c..b4b46a52fee67 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -322,7 +322,7 @@ namespace ts { nodesVisitor((<UnionOrIntersectionTypeNode>node).types, visitor, isTypeNode)); case SyntaxKind.ParenthesizedType: - Debug.fail("not implemented."); + throw Debug.fail("not implemented."); case SyntaxKind.TypeOperator: return updateTypeOperatorNode(<TypeOperatorNode>node, visitNode((<TypeOperatorNode>node).type, visitor, isTypeNode)); @@ -1289,6 +1289,7 @@ namespace ts { case SyntaxKind.JsxAttributes: result = reduceNodes((<JsxAttributes>node).properties, cbNodes, result); + break; case SyntaxKind.JsxClosingElement: result = reduceNode((<JsxClosingElement>node).tagName, cbNode, result); @@ -1310,7 +1311,7 @@ namespace ts { // Clauses case SyntaxKind.CaseClause: result = reduceNode((<CaseClause>node).expression, cbNode, result); - // fall-through + // falls through case SyntaxKind.DefaultClause: result = reduceNodes((<CaseClause | DefaultClause>node).statements, cbNodes, result); @@ -1344,6 +1345,7 @@ namespace ts { case SyntaxKind.EnumMember: result = reduceNode((<EnumMember>node).name, cbNode, result); result = reduceNode((<EnumMember>node).initializer, cbNode, result); + break; // Top-level nodes case SyntaxKind.SourceFile: diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 1f0b3add897d0..e47f6d016c72d 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -97,7 +97,7 @@ namespace ts.BreakpointResolver { if (isFunctionBlock(node)) { return spanInFunctionBlock(<Block>node); } - // Fall through + // falls through case SyntaxKind.ModuleBlock: return spanInBlock(<Block>node); @@ -186,6 +186,7 @@ namespace ts.BreakpointResolver { if (getModuleInstanceState(node) !== ModuleInstanceState.Instantiated) { return undefined; } + // falls through case SyntaxKind.ClassDeclaration: case SyntaxKind.EnumDeclaration: @@ -473,6 +474,7 @@ namespace ts.BreakpointResolver { if (getModuleInstanceState(block.parent) !== ModuleInstanceState.Instantiated) { return undefined; } + // falls through // Set on parent if on same line otherwise on first statement case SyntaxKind.WhileStatement: @@ -582,6 +584,7 @@ namespace ts.BreakpointResolver { if (getModuleInstanceState(node.parent.parent) !== ModuleInstanceState.Instantiated) { return undefined; } + // falls through case SyntaxKind.EnumDeclaration: case SyntaxKind.ClassDeclaration: @@ -593,7 +596,7 @@ namespace ts.BreakpointResolver { // Span on close brace token return textSpan(node); } - // fall through + // falls through case SyntaxKind.CatchClause: return spanInNode(lastOrUndefined((<Block>node.parent).statements)); diff --git a/src/services/classifier.ts b/src/services/classifier.ts index c15b65b0c3900..0deff25321206 100644 --- a/src/services/classifier.ts +++ b/src/services/classifier.ts @@ -160,7 +160,7 @@ namespace ts { case EndOfLineState.InTemplateMiddleOrTail: text = "}\n" + text; offset = 2; - // fallthrough + // falls through case EndOfLineState.InTemplateSubstitutionPosition: templateStack.push(SyntaxKind.TemplateHead); break; diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index e10794997cafe..78c27a1276b31 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -42,12 +42,13 @@ namespace ts.codefix { switch (this.compareModuleSpecifiers(existingAction.moduleSpecifier, newAction.moduleSpecifier)) { case ModuleSpecifierComparison.Better: - // the new one is not worth considering if it is a new improt. + // the new one is not worth considering if it is a new import. // However if it is instead a insertion into existing import, the user might want to use // the module specifier even it is worse by our standards. So keep it. if (newAction.kind === "NewImport") { return; } + // falls through case ModuleSpecifierComparison.Equal: // the current one is safe. But it is still possible that the new one is worse // than another existing one. For example, you may have new imports from "./foo/bar" diff --git a/src/services/codefixes/unusedIdentifierFixes.ts b/src/services/codefixes/unusedIdentifierFixes.ts index be6336ca22d4c..e1debfa4ffb62 100644 --- a/src/services/codefixes/unusedIdentifierFixes.ts +++ b/src/services/codefixes/unusedIdentifierFixes.ts @@ -58,6 +58,8 @@ namespace ts.codefix { return deleteNodeInList(token.parent); } } + // TODO: #14885 + // falls through case SyntaxKind.TypeParameter: const typeParameters = (<DeclarationWithTypeParameters>token.parent.parent).typeParameters; diff --git a/src/services/completions.ts b/src/services/completions.ts index e463c852f026c..6ac3762b4c749 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -487,7 +487,7 @@ namespace ts.Completions { // It has a left-hand side, so we're not in an opening JSX tag. break; } - // fall through + // falls through case SyntaxKind.JsxSelfClosingElement: case SyntaxKind.JsxElement: diff --git a/src/services/documentHighlights.ts b/src/services/documentHighlights.ts index 047e665d7a535..a8afc46d73638 100644 --- a/src/services/documentHighlights.ts +++ b/src/services/documentHighlights.ts @@ -233,7 +233,7 @@ namespace ts.DocumentHighlights { if (statement.kind === SyntaxKind.ContinueStatement) { continue; } - // Fall through. + // falls through case SyntaxKind.ForStatement: case SyntaxKind.ForInStatement: case SyntaxKind.ForOfStatement: diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index acf95d227c3c5..fd717fc546ea0 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -1234,7 +1234,7 @@ namespace ts.FindAllReferences.Core { if (isObjectLiteralMethod(searchSpaceNode)) { break; } - // fall through + // falls through case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: case SyntaxKind.Constructor: @@ -1247,7 +1247,7 @@ namespace ts.FindAllReferences.Core { if (isExternalModule(<SourceFile>searchSpaceNode)) { return undefined; } - // Fall through + // falls through case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: break; diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 3a4547d4597b8..d7c32da5e8d13 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -483,9 +483,8 @@ namespace ts.formatting { case SyntaxKind.MethodDeclaration: if ((<MethodDeclaration>node).asteriskToken) { return SyntaxKind.AsteriskToken; - }/* - fall-through - */ + } + // falls through case SyntaxKind.PropertyDeclaration: case SyntaxKind.Parameter: return (<Declaration>node).name.kind; diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 510f78c3f3957..5080de2edccda 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -146,7 +146,7 @@ namespace ts.OutliningElementsCollector { }); break; } - // Fallthrough. + // falls through case SyntaxKind.ModuleBlock: { const openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile); diff --git a/src/services/services.ts b/src/services/services.ts index 5624c48a53529..8f2cbb22379fe 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -659,7 +659,7 @@ namespace ts { if (!hasModifier(node, ModifierFlags.ParameterPropertyModifier)) { break; } - // fall through + // falls through case SyntaxKind.VariableDeclaration: case SyntaxKind.BindingElement: { const decl = <VariableDeclaration>node; @@ -670,6 +670,7 @@ namespace ts { if (decl.initializer) visit(decl.initializer); } + // falls through case SyntaxKind.EnumMember: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: @@ -2079,7 +2080,7 @@ namespace ts { if (node.parent.kind === SyntaxKind.ComputedPropertyName) { return isObjectLiteralElement(node.parent.parent) ? node.parent.parent : undefined; } - // intentionally fall through + // falls through case SyntaxKind.Identifier: return isObjectLiteralElement(node.parent) && (node.parent.parent.kind === SyntaxKind.ObjectLiteralExpression || node.parent.parent.kind === SyntaxKind.JsxAttributes) && diff --git a/src/services/utilities.ts b/src/services/utilities.ts index bba60675ccb92..56832b90d1f02 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -441,7 +441,7 @@ namespace ts { if (!(<NewExpression>n).arguments) { return true; } - // fall through + // falls through case SyntaxKind.CallExpression: case SyntaxKind.ParenthesizedExpression: case SyntaxKind.ParenthesizedType: diff --git a/tslint.json b/tslint.json index d418a97edfc0b..9552d193a70b5 100644 --- a/tslint.json +++ b/tslint.json @@ -60,6 +60,7 @@ "object-literal-surrounding-space": true, "no-type-assertion-whitespace": true, "no-in-operator": true, + "no-switch-case-fall-through": true, "triple-equals": true, "jsdoc-format": true }