@@ -164,12 +164,11 @@ namespace ts {
164164 }
165165
166166 // A generated code block
167- interface CodeBlock {
168- kind : CodeBlockKind ;
169- }
167+ type CodeBlock = | ExceptionBlock | LabeledBlock | SwitchBlock | LoopBlock | WithBlock ;
170168
171169 // a generated exception block, used for 'try' statements
172- interface ExceptionBlock extends CodeBlock {
170+ interface ExceptionBlock {
171+ kind : CodeBlockKind . Exception ;
173172 state : ExceptionBlockState ;
174173 startLabel : Label ;
175174 catchVariable ?: Identifier ;
@@ -179,27 +178,31 @@ namespace ts {
179178 }
180179
181180 // A generated code that tracks the target for 'break' statements in a LabeledStatement.
182- interface LabeledBlock extends CodeBlock {
181+ interface LabeledBlock {
182+ kind : CodeBlockKind . Labeled ;
183183 labelText : string ;
184184 isScript : boolean ;
185185 breakLabel : Label ;
186186 }
187187
188188 // a generated block that tracks the target for 'break' statements in a 'switch' statement
189- interface SwitchBlock extends CodeBlock {
189+ interface SwitchBlock {
190+ kind : CodeBlockKind . Switch ;
190191 isScript : boolean ;
191192 breakLabel : Label ;
192193 }
193194
194195 // a generated block that tracks the targets for 'break' and 'continue' statements, used for iteration statements
195- interface LoopBlock extends CodeBlock {
196+ interface LoopBlock {
197+ kind : CodeBlockKind . Loop ;
196198 continueLabel : Label ;
197199 isScript : boolean ;
198200 breakLabel : Label ;
199201 }
200202
201203 // a generated block associated with a 'with' statement
202- interface WithBlock extends CodeBlock {
204+ interface WithBlock {
205+ kind : CodeBlockKind . With ;
203206 expression : Identifier ;
204207 startLabel : Label ;
205208 endLabel : Label ;
@@ -2070,7 +2073,7 @@ namespace ts {
20702073 const startLabel = defineLabel ( ) ;
20712074 const endLabel = defineLabel ( ) ;
20722075 markLabel ( startLabel ) ;
2073- beginBlock ( < WithBlock > {
2076+ beginBlock ( {
20742077 kind : CodeBlockKind . With ,
20752078 expression,
20762079 startLabel,
@@ -2087,18 +2090,14 @@ namespace ts {
20872090 markLabel ( block . endLabel ) ;
20882091 }
20892092
2090- function isWithBlock ( block : CodeBlock ) : block is WithBlock {
2091- return block . kind === CodeBlockKind . With ;
2092- }
2093-
20942093 /**
20952094 * Begins a code block for a generated `try` statement.
20962095 */
20972096 function beginExceptionBlock ( ) : Label {
20982097 const startLabel = defineLabel ( ) ;
20992098 const endLabel = defineLabel ( ) ;
21002099 markLabel ( startLabel ) ;
2101- beginBlock ( < ExceptionBlock > {
2100+ beginBlock ( {
21022101 kind : CodeBlockKind . Exception ,
21032102 state : ExceptionBlockState . Try ,
21042103 startLabel,
@@ -2188,18 +2187,14 @@ namespace ts {
21882187 exception . state = ExceptionBlockState . Done ;
21892188 }
21902189
2191- function isExceptionBlock ( block : CodeBlock ) : block is ExceptionBlock {
2192- return block . kind === CodeBlockKind . Exception ;
2193- }
2194-
21952190 /**
21962191 * Begins a code block that supports `break` or `continue` statements that are defined in
21972192 * the source tree and not from generated code.
21982193 *
21992194 * @param labelText Names from containing labeled statements.
22002195 */
22012196 function beginScriptLoopBlock ( ) : void {
2202- beginBlock ( < LoopBlock > {
2197+ beginBlock ( {
22032198 kind : CodeBlockKind . Loop ,
22042199 isScript : true ,
22052200 breakLabel : - 1 ,
@@ -2217,7 +2212,7 @@ namespace ts {
22172212 */
22182213 function beginLoopBlock ( continueLabel : Label ) : Label {
22192214 const breakLabel = defineLabel ( ) ;
2220- beginBlock ( < LoopBlock > {
2215+ beginBlock ( {
22212216 kind : CodeBlockKind . Loop ,
22222217 isScript : false ,
22232218 breakLabel,
@@ -2245,7 +2240,7 @@ namespace ts {
22452240 *
22462241 */
22472242 function beginScriptSwitchBlock ( ) : void {
2248- beginBlock ( < SwitchBlock > {
2243+ beginBlock ( {
22492244 kind : CodeBlockKind . Switch ,
22502245 isScript : true ,
22512246 breakLabel : - 1
@@ -2259,7 +2254,7 @@ namespace ts {
22592254 */
22602255 function beginSwitchBlock ( ) : Label {
22612256 const breakLabel = defineLabel ( ) ;
2262- beginBlock ( < SwitchBlock > {
2257+ beginBlock ( {
22632258 kind : CodeBlockKind . Switch ,
22642259 isScript : false ,
22652260 breakLabel,
@@ -2280,7 +2275,7 @@ namespace ts {
22802275 }
22812276
22822277 function beginScriptLabeledBlock ( labelText : string ) {
2283- beginBlock ( < LabeledBlock > {
2278+ beginBlock ( {
22842279 kind : CodeBlockKind . Labeled ,
22852280 isScript : true ,
22862281 labelText,
@@ -2290,7 +2285,7 @@ namespace ts {
22902285
22912286 function beginLabeledBlock ( labelText : string ) {
22922287 const breakLabel = defineLabel ( ) ;
2293- beginBlock ( < LabeledBlock > {
2288+ beginBlock ( {
22942289 kind : CodeBlockKind . Labeled ,
22952290 isScript : false ,
22962291 labelText,
@@ -2878,34 +2873,37 @@ namespace ts {
28782873 for ( ; blockIndex < blockActions . length && blockOffsets [ blockIndex ] <= operationIndex ; blockIndex ++ ) {
28792874 const block = blocks [ blockIndex ] ;
28802875 const blockAction = blockActions [ blockIndex ] ;
2881- if ( isExceptionBlock ( block ) ) {
2882- if ( blockAction === BlockAction . Open ) {
2883- if ( ! exceptionBlockStack ) {
2884- exceptionBlockStack = [ ] ;
2885- }
2876+ switch ( block . kind ) {
2877+ case CodeBlockKind . Exception :
2878+ if ( blockAction === BlockAction . Open ) {
2879+ if ( ! exceptionBlockStack ) {
2880+ exceptionBlockStack = [ ] ;
2881+ }
28862882
2887- if ( ! statements ) {
2888- statements = [ ] ;
2889- }
2883+ if ( ! statements ) {
2884+ statements = [ ] ;
2885+ }
28902886
2891- exceptionBlockStack . push ( currentExceptionBlock ) ;
2892- currentExceptionBlock = block ;
2893- }
2894- else if ( blockAction === BlockAction . Close ) {
2895- currentExceptionBlock = exceptionBlockStack . pop ( ) ;
2896- }
2897- }
2898- else if ( isWithBlock ( block ) ) {
2899- if ( blockAction === BlockAction . Open ) {
2900- if ( ! withBlockStack ) {
2901- withBlockStack = [ ] ;
2887+ exceptionBlockStack . push ( currentExceptionBlock ) ;
2888+ currentExceptionBlock = block ;
29022889 }
2890+ else if ( blockAction === BlockAction . Close ) {
2891+ currentExceptionBlock = exceptionBlockStack . pop ( ) ;
2892+ }
2893+ break ;
2894+ case CodeBlockKind . With :
2895+ if ( blockAction === BlockAction . Open ) {
2896+ if ( ! withBlockStack ) {
2897+ withBlockStack = [ ] ;
2898+ }
29032899
2904- withBlockStack . push ( block ) ;
2905- }
2906- else if ( blockAction === BlockAction . Close ) {
2907- withBlockStack . pop ( ) ;
2908- }
2900+ withBlockStack . push ( block ) ;
2901+ }
2902+ else if ( blockAction === BlockAction . Close ) {
2903+ withBlockStack . pop ( ) ;
2904+ }
2905+ break ;
2906+ // default: do nothing
29092907 }
29102908 }
29112909 }
0 commit comments