diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 2e17d8bf3a1..e325b2033e7 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -534,7 +534,7 @@ module ts { case SyntaxKind.ForStatement: case SyntaxKind.ForInStatement: case SyntaxKind.ForOfStatement: - case SyntaxKind.SwitchStatement: + case SyntaxKind.CaseBlock: bindChildren(node, 0, /*isBlockScopeContainer*/ true); break; default: diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8908501593c..94f3fc2244a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9031,7 +9031,7 @@ module ts { var hasDuplicateDefaultClause = false; var expressionType = checkExpression(node.expression); - forEach(node.clauses, clause => { + forEach(node.caseBlock.clauses, clause => { // Grammar check for duplicate default clauses, skip if we already report duplicate default clause if (clause.kind === SyntaxKind.DefaultClause && !hasDuplicateDefaultClause) { if (firstDefaultClause === undefined) { @@ -10147,6 +10147,7 @@ module ts { case SyntaxKind.BreakStatement: case SyntaxKind.ReturnStatement: case SyntaxKind.SwitchStatement: + case SyntaxKind.CaseBlock: case SyntaxKind.CaseClause: case SyntaxKind.DefaultClause: case SyntaxKind.LabeledStatement: diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 8947314a6f6..e9848af989c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3541,10 +3541,10 @@ module ts { write(" "); emitToken(SyntaxKind.OpenBraceToken, endPos); increaseIndent(); - emitLines(node.clauses); + emitLines(node.caseBlock.clauses); decreaseIndent(); writeLine(); - emitToken(SyntaxKind.CloseBraceToken, node.clauses.end); + emitToken(SyntaxKind.CloseBraceToken, node.caseBlock.clauses.end); } function nodeStartPositionsAreOnSameLine(node1: Node, node2: Node) { @@ -3938,7 +3938,7 @@ module ts { } switch (current.kind) { case SyntaxKind.SourceFile: - case SyntaxKind.SwitchKeyword: + case SyntaxKind.CaseBlock: case SyntaxKind.CatchClause: case SyntaxKind.ModuleDeclaration: case SyntaxKind.ForStatement: diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 0d6f002a3da..6e444eb23c7 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -209,7 +209,9 @@ module ts { visitNode(cbNode, (node).statement); case SyntaxKind.SwitchStatement: return visitNode(cbNode, (node).expression) || - visitNodes(cbNodes, (node).clauses); + visitNode(cbNode, (node).caseBlock); + case SyntaxKind.CaseBlock: + return visitNodes(cbNodes, (node).clauses); case SyntaxKind.CaseClause: return visitNode(cbNode, (node).expression) || visitNodes(cbNodes, (node).statements); @@ -3954,9 +3956,11 @@ module ts { parseExpected(SyntaxKind.OpenParenToken); node.expression = allowInAnd(parseExpression); parseExpected(SyntaxKind.CloseParenToken); + var caseBlock = createNode(SyntaxKind.CaseBlock, scanner.getStartPos()); parseExpected(SyntaxKind.OpenBraceToken); - node.clauses = parseList(ParsingContext.SwitchClauses, /*checkForStrictMode*/ false, parseCaseOrDefaultClause); + caseBlock.clauses = parseList(ParsingContext.SwitchClauses, /*checkForStrictMode*/ false, parseCaseOrDefaultClause); parseExpected(SyntaxKind.CloseBraceToken); + node.caseBlock = finishNode(caseBlock); return finishNode(node); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index abace7e224e..7301e087ae1 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -233,6 +233,7 @@ module ts { EnumDeclaration, ModuleDeclaration, ModuleBlock, + CaseBlock, ImportEqualsDeclaration, ImportDeclaration, ImportClause, @@ -790,6 +791,10 @@ module ts { export interface SwitchStatement extends Statement { expression: Expression; + caseBlock: CaseBlock; + } + + export interface CaseBlock extends Node { clauses: NodeArray; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 28e9b114ec3..0278af8671b 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -376,6 +376,7 @@ module ts { switch (node.kind) { case SyntaxKind.ReturnStatement: return visitor(node); + case SyntaxKind.CaseBlock: case SyntaxKind.Block: case SyntaxKind.IfStatement: case SyntaxKind.DoStatement: diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index d59718322c9..1f87ae40745 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -416,8 +416,8 @@ module ts.BreakpointResolver { var classDeclaration = node.parent; return spanInNodeIfStartsOnSameLine(findPrecedingToken(node.pos, sourceFile, node.parent), classDeclaration.members.length ? classDeclaration.members[0] : classDeclaration.getLastToken(sourceFile)); - case SyntaxKind.SwitchStatement: - return spanInNodeIfStartsOnSameLine(node.parent, (node.parent).clauses[0]); + case SyntaxKind.CaseBlock: + return spanInNodeIfStartsOnSameLine(node.parent.parent, (node.parent).clauses[0]); } // Default to parent node @@ -447,10 +447,10 @@ module ts.BreakpointResolver { case SyntaxKind.CatchClause: return spanInNode((node.parent).statements[(node.parent).statements.length - 1]);; - case SyntaxKind.SwitchStatement: + case SyntaxKind.CaseBlock: // breakpoint in last statement of the last clause - var switchStatement = node.parent; - var lastClause = switchStatement.clauses[switchStatement.clauses.length - 1]; + var caseBlock = node.parent; + var lastClause = caseBlock.clauses[caseBlock.clauses.length - 1]; if (lastClause) { return spanInNode(lastClause.statements[lastClause.statements.length - 1]); } diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index ecfc5012915..7eb5232af18 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -541,7 +541,7 @@ module ts.formatting { switch (node.kind) { case SyntaxKind.Block: - case SyntaxKind.SwitchStatement: + case SyntaxKind.CaseBlock: case SyntaxKind.ObjectLiteralExpression: case SyntaxKind.ModuleBlock: return true; diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 6974f160e10..96159d332fe 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -357,7 +357,7 @@ module ts.formatting { case SyntaxKind.ModuleBlock: case SyntaxKind.ObjectLiteralExpression: case SyntaxKind.TypeLiteral: - case SyntaxKind.SwitchStatement: + case SyntaxKind.CaseBlock: case SyntaxKind.DefaultClause: case SyntaxKind.CaseClause: case SyntaxKind.ParenthesizedExpression: @@ -431,7 +431,7 @@ module ts.formatting { case SyntaxKind.ObjectLiteralExpression: case SyntaxKind.Block: case SyntaxKind.ModuleBlock: - case SyntaxKind.SwitchStatement: + case SyntaxKind.CaseBlock: return nodeEndsWith(n, SyntaxKind.CloseBraceToken, sourceFile); case SyntaxKind.CatchClause: return isCompletedNode((n).block, sourceFile); diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 54b548336de..eee537bbebb 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -104,7 +104,7 @@ module ts { case SyntaxKind.InterfaceDeclaration: case SyntaxKind.EnumDeclaration: case SyntaxKind.ObjectLiteralExpression: - case SyntaxKind.SwitchStatement: + case SyntaxKind.CaseBlock: var openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile); var closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile); addOutliningSpan(n, openBrace, closeBrace, autoCollapse(n)); diff --git a/src/services/services.ts b/src/services/services.ts index 6ef044ad75a..61d7a0736b0 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3619,8 +3619,8 @@ module ts { break; case SyntaxKind.CaseKeyword: case SyntaxKind.DefaultKeyword: - if (hasKind(parent(parent(node)), SyntaxKind.SwitchStatement)) { - return getSwitchCaseDefaultOccurrences(node.parent.parent); + if (hasKind(parent(parent(parent(node))), SyntaxKind.SwitchStatement)) { + return getSwitchCaseDefaultOccurrences(node.parent.parent.parent); } break; case SyntaxKind.BreakKeyword: @@ -3887,7 +3887,7 @@ module ts { pushKeywordIf(keywords, switchStatement.getFirstToken(), SyntaxKind.SwitchKeyword); // Go through each clause in the switch statement, collecting the 'case'/'default' keywords. - forEach(switchStatement.clauses, clause => { + forEach(switchStatement.caseBlock.clauses, clause => { pushKeywordIf(keywords, clause.getFirstToken(), SyntaxKind.CaseKeyword, SyntaxKind.DefaultKeyword); var breaksAndContinues = aggregateAllBreakAndContinueStatements(clause); diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index a94858d9154..6e6adb2cd45 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -261,27 +261,28 @@ declare module "typescript" { EnumDeclaration = 199, ModuleDeclaration = 200, ModuleBlock = 201, - ImportEqualsDeclaration = 202, - ImportDeclaration = 203, - ImportClause = 204, - NamespaceImport = 205, - NamedImports = 206, - ImportSpecifier = 207, - ExportAssignment = 208, - ExportDeclaration = 209, - NamedExports = 210, - ExportSpecifier = 211, - ExternalModuleReference = 212, - CaseClause = 213, - DefaultClause = 214, - HeritageClause = 215, - CatchClause = 216, - PropertyAssignment = 217, - ShorthandPropertyAssignment = 218, - EnumMember = 219, - SourceFile = 220, - SyntaxList = 221, - Count = 222, + CaseBlock = 202, + ImportEqualsDeclaration = 203, + ImportDeclaration = 204, + ImportClause = 205, + NamespaceImport = 206, + NamedImports = 207, + ImportSpecifier = 208, + ExportAssignment = 209, + ExportDeclaration = 210, + NamedExports = 211, + ExportSpecifier = 212, + ExternalModuleReference = 213, + CaseClause = 214, + DefaultClause = 215, + HeritageClause = 216, + CatchClause = 217, + PropertyAssignment = 218, + ShorthandPropertyAssignment = 219, + EnumMember = 220, + SourceFile = 221, + SyntaxList = 222, + Count = 223, FirstAssignment = 52, LastAssignment = 63, FirstReservedWord = 65, @@ -656,6 +657,9 @@ declare module "typescript" { } interface SwitchStatement extends Statement { expression: Expression; + caseBlock: CaseBlock; + } + interface CaseBlock extends Node { clauses: NodeArray; } interface CaseClause extends Node { diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 40096915869..17ce175ebdf 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -801,67 +801,70 @@ declare module "typescript" { ModuleBlock = 201, >ModuleBlock : SyntaxKind - ImportEqualsDeclaration = 202, + CaseBlock = 202, +>CaseBlock : SyntaxKind + + ImportEqualsDeclaration = 203, >ImportEqualsDeclaration : SyntaxKind - ImportDeclaration = 203, + ImportDeclaration = 204, >ImportDeclaration : SyntaxKind - ImportClause = 204, + ImportClause = 205, >ImportClause : SyntaxKind - NamespaceImport = 205, + NamespaceImport = 206, >NamespaceImport : SyntaxKind - NamedImports = 206, + NamedImports = 207, >NamedImports : SyntaxKind - ImportSpecifier = 207, + ImportSpecifier = 208, >ImportSpecifier : SyntaxKind - ExportAssignment = 208, + ExportAssignment = 209, >ExportAssignment : SyntaxKind - ExportDeclaration = 209, + ExportDeclaration = 210, >ExportDeclaration : SyntaxKind - NamedExports = 210, + NamedExports = 211, >NamedExports : SyntaxKind - ExportSpecifier = 211, + ExportSpecifier = 212, >ExportSpecifier : SyntaxKind - ExternalModuleReference = 212, + ExternalModuleReference = 213, >ExternalModuleReference : SyntaxKind - CaseClause = 213, + CaseClause = 214, >CaseClause : SyntaxKind - DefaultClause = 214, + DefaultClause = 215, >DefaultClause : SyntaxKind - HeritageClause = 215, + HeritageClause = 216, >HeritageClause : SyntaxKind - CatchClause = 216, + CatchClause = 217, >CatchClause : SyntaxKind - PropertyAssignment = 217, + PropertyAssignment = 218, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 218, + ShorthandPropertyAssignment = 219, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 219, + EnumMember = 220, >EnumMember : SyntaxKind - SourceFile = 220, + SourceFile = 221, >SourceFile : SyntaxKind - SyntaxList = 221, + SyntaxList = 222, >SyntaxList : SyntaxKind - Count = 222, + Count = 223, >Count : SyntaxKind FirstAssignment = 52, @@ -1980,6 +1983,14 @@ declare module "typescript" { >expression : Expression >Expression : Expression + caseBlock: CaseBlock; +>caseBlock : CaseBlock +>CaseBlock : CaseBlock + } + interface CaseBlock extends Node { +>CaseBlock : CaseBlock +>Node : Node + clauses: NodeArray; >clauses : NodeArray >NodeArray : NodeArray diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index aa94796e3f1..4f1fc899a89 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -292,27 +292,28 @@ declare module "typescript" { EnumDeclaration = 199, ModuleDeclaration = 200, ModuleBlock = 201, - ImportEqualsDeclaration = 202, - ImportDeclaration = 203, - ImportClause = 204, - NamespaceImport = 205, - NamedImports = 206, - ImportSpecifier = 207, - ExportAssignment = 208, - ExportDeclaration = 209, - NamedExports = 210, - ExportSpecifier = 211, - ExternalModuleReference = 212, - CaseClause = 213, - DefaultClause = 214, - HeritageClause = 215, - CatchClause = 216, - PropertyAssignment = 217, - ShorthandPropertyAssignment = 218, - EnumMember = 219, - SourceFile = 220, - SyntaxList = 221, - Count = 222, + CaseBlock = 202, + ImportEqualsDeclaration = 203, + ImportDeclaration = 204, + ImportClause = 205, + NamespaceImport = 206, + NamedImports = 207, + ImportSpecifier = 208, + ExportAssignment = 209, + ExportDeclaration = 210, + NamedExports = 211, + ExportSpecifier = 212, + ExternalModuleReference = 213, + CaseClause = 214, + DefaultClause = 215, + HeritageClause = 216, + CatchClause = 217, + PropertyAssignment = 218, + ShorthandPropertyAssignment = 219, + EnumMember = 220, + SourceFile = 221, + SyntaxList = 222, + Count = 223, FirstAssignment = 52, LastAssignment = 63, FirstReservedWord = 65, @@ -687,6 +688,9 @@ declare module "typescript" { } interface SwitchStatement extends Statement { expression: Expression; + caseBlock: CaseBlock; + } + interface CaseBlock extends Node { clauses: NodeArray; } interface CaseClause extends Node { diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index f061125220d..d1dcad98d85 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -947,67 +947,70 @@ declare module "typescript" { ModuleBlock = 201, >ModuleBlock : SyntaxKind - ImportEqualsDeclaration = 202, + CaseBlock = 202, +>CaseBlock : SyntaxKind + + ImportEqualsDeclaration = 203, >ImportEqualsDeclaration : SyntaxKind - ImportDeclaration = 203, + ImportDeclaration = 204, >ImportDeclaration : SyntaxKind - ImportClause = 204, + ImportClause = 205, >ImportClause : SyntaxKind - NamespaceImport = 205, + NamespaceImport = 206, >NamespaceImport : SyntaxKind - NamedImports = 206, + NamedImports = 207, >NamedImports : SyntaxKind - ImportSpecifier = 207, + ImportSpecifier = 208, >ImportSpecifier : SyntaxKind - ExportAssignment = 208, + ExportAssignment = 209, >ExportAssignment : SyntaxKind - ExportDeclaration = 209, + ExportDeclaration = 210, >ExportDeclaration : SyntaxKind - NamedExports = 210, + NamedExports = 211, >NamedExports : SyntaxKind - ExportSpecifier = 211, + ExportSpecifier = 212, >ExportSpecifier : SyntaxKind - ExternalModuleReference = 212, + ExternalModuleReference = 213, >ExternalModuleReference : SyntaxKind - CaseClause = 213, + CaseClause = 214, >CaseClause : SyntaxKind - DefaultClause = 214, + DefaultClause = 215, >DefaultClause : SyntaxKind - HeritageClause = 215, + HeritageClause = 216, >HeritageClause : SyntaxKind - CatchClause = 216, + CatchClause = 217, >CatchClause : SyntaxKind - PropertyAssignment = 217, + PropertyAssignment = 218, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 218, + ShorthandPropertyAssignment = 219, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 219, + EnumMember = 220, >EnumMember : SyntaxKind - SourceFile = 220, + SourceFile = 221, >SourceFile : SyntaxKind - SyntaxList = 221, + SyntaxList = 222, >SyntaxList : SyntaxKind - Count = 222, + Count = 223, >Count : SyntaxKind FirstAssignment = 52, @@ -2126,6 +2129,14 @@ declare module "typescript" { >expression : Expression >Expression : Expression + caseBlock: CaseBlock; +>caseBlock : CaseBlock +>CaseBlock : CaseBlock + } + interface CaseBlock extends Node { +>CaseBlock : CaseBlock +>Node : Node + clauses: NodeArray; >clauses : NodeArray >NodeArray : NodeArray diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 6defcf64c70..3ef3d7bc0f5 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -293,27 +293,28 @@ declare module "typescript" { EnumDeclaration = 199, ModuleDeclaration = 200, ModuleBlock = 201, - ImportEqualsDeclaration = 202, - ImportDeclaration = 203, - ImportClause = 204, - NamespaceImport = 205, - NamedImports = 206, - ImportSpecifier = 207, - ExportAssignment = 208, - ExportDeclaration = 209, - NamedExports = 210, - ExportSpecifier = 211, - ExternalModuleReference = 212, - CaseClause = 213, - DefaultClause = 214, - HeritageClause = 215, - CatchClause = 216, - PropertyAssignment = 217, - ShorthandPropertyAssignment = 218, - EnumMember = 219, - SourceFile = 220, - SyntaxList = 221, - Count = 222, + CaseBlock = 202, + ImportEqualsDeclaration = 203, + ImportDeclaration = 204, + ImportClause = 205, + NamespaceImport = 206, + NamedImports = 207, + ImportSpecifier = 208, + ExportAssignment = 209, + ExportDeclaration = 210, + NamedExports = 211, + ExportSpecifier = 212, + ExternalModuleReference = 213, + CaseClause = 214, + DefaultClause = 215, + HeritageClause = 216, + CatchClause = 217, + PropertyAssignment = 218, + ShorthandPropertyAssignment = 219, + EnumMember = 220, + SourceFile = 221, + SyntaxList = 222, + Count = 223, FirstAssignment = 52, LastAssignment = 63, FirstReservedWord = 65, @@ -688,6 +689,9 @@ declare module "typescript" { } interface SwitchStatement extends Statement { expression: Expression; + caseBlock: CaseBlock; + } + interface CaseBlock extends Node { clauses: NodeArray; } interface CaseClause extends Node { diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 9fb0771cb2d..4bfac42f571 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -897,67 +897,70 @@ declare module "typescript" { ModuleBlock = 201, >ModuleBlock : SyntaxKind - ImportEqualsDeclaration = 202, + CaseBlock = 202, +>CaseBlock : SyntaxKind + + ImportEqualsDeclaration = 203, >ImportEqualsDeclaration : SyntaxKind - ImportDeclaration = 203, + ImportDeclaration = 204, >ImportDeclaration : SyntaxKind - ImportClause = 204, + ImportClause = 205, >ImportClause : SyntaxKind - NamespaceImport = 205, + NamespaceImport = 206, >NamespaceImport : SyntaxKind - NamedImports = 206, + NamedImports = 207, >NamedImports : SyntaxKind - ImportSpecifier = 207, + ImportSpecifier = 208, >ImportSpecifier : SyntaxKind - ExportAssignment = 208, + ExportAssignment = 209, >ExportAssignment : SyntaxKind - ExportDeclaration = 209, + ExportDeclaration = 210, >ExportDeclaration : SyntaxKind - NamedExports = 210, + NamedExports = 211, >NamedExports : SyntaxKind - ExportSpecifier = 211, + ExportSpecifier = 212, >ExportSpecifier : SyntaxKind - ExternalModuleReference = 212, + ExternalModuleReference = 213, >ExternalModuleReference : SyntaxKind - CaseClause = 213, + CaseClause = 214, >CaseClause : SyntaxKind - DefaultClause = 214, + DefaultClause = 215, >DefaultClause : SyntaxKind - HeritageClause = 215, + HeritageClause = 216, >HeritageClause : SyntaxKind - CatchClause = 216, + CatchClause = 217, >CatchClause : SyntaxKind - PropertyAssignment = 217, + PropertyAssignment = 218, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 218, + ShorthandPropertyAssignment = 219, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 219, + EnumMember = 220, >EnumMember : SyntaxKind - SourceFile = 220, + SourceFile = 221, >SourceFile : SyntaxKind - SyntaxList = 221, + SyntaxList = 222, >SyntaxList : SyntaxKind - Count = 222, + Count = 223, >Count : SyntaxKind FirstAssignment = 52, @@ -2076,6 +2079,14 @@ declare module "typescript" { >expression : Expression >Expression : Expression + caseBlock: CaseBlock; +>caseBlock : CaseBlock +>CaseBlock : CaseBlock + } + interface CaseBlock extends Node { +>CaseBlock : CaseBlock +>Node : Node + clauses: NodeArray; >clauses : NodeArray >NodeArray : NodeArray diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 6fabb4d8b3b..c85be654c89 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -330,27 +330,28 @@ declare module "typescript" { EnumDeclaration = 199, ModuleDeclaration = 200, ModuleBlock = 201, - ImportEqualsDeclaration = 202, - ImportDeclaration = 203, - ImportClause = 204, - NamespaceImport = 205, - NamedImports = 206, - ImportSpecifier = 207, - ExportAssignment = 208, - ExportDeclaration = 209, - NamedExports = 210, - ExportSpecifier = 211, - ExternalModuleReference = 212, - CaseClause = 213, - DefaultClause = 214, - HeritageClause = 215, - CatchClause = 216, - PropertyAssignment = 217, - ShorthandPropertyAssignment = 218, - EnumMember = 219, - SourceFile = 220, - SyntaxList = 221, - Count = 222, + CaseBlock = 202, + ImportEqualsDeclaration = 203, + ImportDeclaration = 204, + ImportClause = 205, + NamespaceImport = 206, + NamedImports = 207, + ImportSpecifier = 208, + ExportAssignment = 209, + ExportDeclaration = 210, + NamedExports = 211, + ExportSpecifier = 212, + ExternalModuleReference = 213, + CaseClause = 214, + DefaultClause = 215, + HeritageClause = 216, + CatchClause = 217, + PropertyAssignment = 218, + ShorthandPropertyAssignment = 219, + EnumMember = 220, + SourceFile = 221, + SyntaxList = 222, + Count = 223, FirstAssignment = 52, LastAssignment = 63, FirstReservedWord = 65, @@ -725,6 +726,9 @@ declare module "typescript" { } interface SwitchStatement extends Statement { expression: Expression; + caseBlock: CaseBlock; + } + interface CaseBlock extends Node { clauses: NodeArray; } interface CaseClause extends Node { diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index e2ad04b970e..e4b53feeac0 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -1070,67 +1070,70 @@ declare module "typescript" { ModuleBlock = 201, >ModuleBlock : SyntaxKind - ImportEqualsDeclaration = 202, + CaseBlock = 202, +>CaseBlock : SyntaxKind + + ImportEqualsDeclaration = 203, >ImportEqualsDeclaration : SyntaxKind - ImportDeclaration = 203, + ImportDeclaration = 204, >ImportDeclaration : SyntaxKind - ImportClause = 204, + ImportClause = 205, >ImportClause : SyntaxKind - NamespaceImport = 205, + NamespaceImport = 206, >NamespaceImport : SyntaxKind - NamedImports = 206, + NamedImports = 207, >NamedImports : SyntaxKind - ImportSpecifier = 207, + ImportSpecifier = 208, >ImportSpecifier : SyntaxKind - ExportAssignment = 208, + ExportAssignment = 209, >ExportAssignment : SyntaxKind - ExportDeclaration = 209, + ExportDeclaration = 210, >ExportDeclaration : SyntaxKind - NamedExports = 210, + NamedExports = 211, >NamedExports : SyntaxKind - ExportSpecifier = 211, + ExportSpecifier = 212, >ExportSpecifier : SyntaxKind - ExternalModuleReference = 212, + ExternalModuleReference = 213, >ExternalModuleReference : SyntaxKind - CaseClause = 213, + CaseClause = 214, >CaseClause : SyntaxKind - DefaultClause = 214, + DefaultClause = 215, >DefaultClause : SyntaxKind - HeritageClause = 215, + HeritageClause = 216, >HeritageClause : SyntaxKind - CatchClause = 216, + CatchClause = 217, >CatchClause : SyntaxKind - PropertyAssignment = 217, + PropertyAssignment = 218, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 218, + ShorthandPropertyAssignment = 219, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 219, + EnumMember = 220, >EnumMember : SyntaxKind - SourceFile = 220, + SourceFile = 221, >SourceFile : SyntaxKind - SyntaxList = 221, + SyntaxList = 222, >SyntaxList : SyntaxKind - Count = 222, + Count = 223, >Count : SyntaxKind FirstAssignment = 52, @@ -2249,6 +2252,14 @@ declare module "typescript" { >expression : Expression >Expression : Expression + caseBlock: CaseBlock; +>caseBlock : CaseBlock +>CaseBlock : CaseBlock + } + interface CaseBlock extends Node { +>CaseBlock : CaseBlock +>Node : Node + clauses: NodeArray; >clauses : NodeArray >NodeArray : NodeArray diff --git a/tests/baselines/reference/letConstInCaseClauses.errors.txt b/tests/baselines/reference/letConstInCaseClauses.errors.txt new file mode 100644 index 00000000000..af0777d56a4 --- /dev/null +++ b/tests/baselines/reference/letConstInCaseClauses.errors.txt @@ -0,0 +1,39 @@ +tests/cases/compiler/letConstInCaseClauses.ts(7,5): error TS2304: Cannot find name 'console'. +tests/cases/compiler/letConstInCaseClauses.ts(21,5): error TS2304: Cannot find name 'console'. + + +==== tests/cases/compiler/letConstInCaseClauses.ts (2 errors) ==== + + var x = 10; + var y = 20; + { + let x = 1; + let y = 2; + console.log(x) + ~~~~~~~ +!!! error TS2304: Cannot find name 'console'. + switch (x) { + case 10: + let x = 20; + } + switch (y) { + case 10: + let y = 20; + } + } + + { + const x = 1; + const y = 2; + console.log(x) + ~~~~~~~ +!!! error TS2304: Cannot find name 'console'. + switch (x) { + case 10: + const x = 20; + } + switch (y) { + case 10: + const y = 20; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/letConstInCaseClauses.js b/tests/baselines/reference/letConstInCaseClauses.js new file mode 100644 index 00000000000..94840a11a2c --- /dev/null +++ b/tests/baselines/reference/letConstInCaseClauses.js @@ -0,0 +1,61 @@ +//// [letConstInCaseClauses.ts] + +var x = 10; +var y = 20; +{ + let x = 1; + let y = 2; + console.log(x) + switch (x) { + case 10: + let x = 20; + } + switch (y) { + case 10: + let y = 20; + } +} + +{ + const x = 1; + const y = 2; + console.log(x) + switch (x) { + case 10: + const x = 20; + } + switch (y) { + case 10: + const y = 20; + } +} + +//// [letConstInCaseClauses.js] +var x = 10; +var y = 20; +{ + var _x = 1; + var _y = 2; + console.log(_x); + switch (_x) { + case 10: + var _x_1 = 20; + } + switch (_y) { + case 10: + var _y_1 = 20; + } +} +{ + var _x_2 = 1; + var _y_2 = 2; + console.log(_x_2); + switch (_x_2) { + case 10: + var _x_3 = 20; + } + switch (_y_2) { + case 10: + var _y_3 = 20; + } +} diff --git a/tests/cases/compiler/letConstInCaseClauses.ts b/tests/cases/compiler/letConstInCaseClauses.ts new file mode 100644 index 00000000000..4ed1c9fa363 --- /dev/null +++ b/tests/cases/compiler/letConstInCaseClauses.ts @@ -0,0 +1,31 @@ +// @target: es5 + +var x = 10; +var y = 20; +{ + let x = 1; + let y = 2; + console.log(x) + switch (x) { + case 10: + let x = 20; + } + switch (y) { + case 10: + let y = 20; + } +} + +{ + const x = 1; + const y = 2; + console.log(x) + switch (x) { + case 10: + const x = 20; + } + switch (y) { + case 10: + const y = 20; + } +} \ No newline at end of file