@@ -164,12 +164,11 @@ namespace ts {
164
164
}
165
165
166
166
// A generated code block
167
- interface CodeBlock {
168
- kind : CodeBlockKind ;
169
- }
167
+ type CodeBlock = | ExceptionBlock | LabeledBlock | SwitchBlock | LoopBlock | WithBlock ;
170
168
171
169
// a generated exception block, used for 'try' statements
172
- interface ExceptionBlock extends CodeBlock {
170
+ interface ExceptionBlock {
171
+ kind : CodeBlockKind . Exception ;
173
172
state : ExceptionBlockState ;
174
173
startLabel : Label ;
175
174
catchVariable ?: Identifier ;
@@ -179,27 +178,31 @@ namespace ts {
179
178
}
180
179
181
180
// 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 ;
183
183
labelText : string ;
184
184
isScript : boolean ;
185
185
breakLabel : Label ;
186
186
}
187
187
188
188
// 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 ;
190
191
isScript : boolean ;
191
192
breakLabel : Label ;
192
193
}
193
194
194
195
// 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 ;
196
198
continueLabel : Label ;
197
199
isScript : boolean ;
198
200
breakLabel : Label ;
199
201
}
200
202
201
203
// a generated block associated with a 'with' statement
202
- interface WithBlock extends CodeBlock {
204
+ interface WithBlock {
205
+ kind : CodeBlockKind . With ;
203
206
expression : Identifier ;
204
207
startLabel : Label ;
205
208
endLabel : Label ;
@@ -2070,7 +2073,7 @@ namespace ts {
2070
2073
const startLabel = defineLabel ( ) ;
2071
2074
const endLabel = defineLabel ( ) ;
2072
2075
markLabel ( startLabel ) ;
2073
- beginBlock ( < WithBlock > {
2076
+ beginBlock ( {
2074
2077
kind : CodeBlockKind . With ,
2075
2078
expression,
2076
2079
startLabel,
@@ -2087,18 +2090,14 @@ namespace ts {
2087
2090
markLabel ( block . endLabel ) ;
2088
2091
}
2089
2092
2090
- function isWithBlock ( block : CodeBlock ) : block is WithBlock {
2091
- return block . kind === CodeBlockKind . With ;
2092
- }
2093
-
2094
2093
/**
2095
2094
* Begins a code block for a generated `try` statement.
2096
2095
*/
2097
2096
function beginExceptionBlock ( ) : Label {
2098
2097
const startLabel = defineLabel ( ) ;
2099
2098
const endLabel = defineLabel ( ) ;
2100
2099
markLabel ( startLabel ) ;
2101
- beginBlock ( < ExceptionBlock > {
2100
+ beginBlock ( {
2102
2101
kind : CodeBlockKind . Exception ,
2103
2102
state : ExceptionBlockState . Try ,
2104
2103
startLabel,
@@ -2188,18 +2187,14 @@ namespace ts {
2188
2187
exception . state = ExceptionBlockState . Done ;
2189
2188
}
2190
2189
2191
- function isExceptionBlock ( block : CodeBlock ) : block is ExceptionBlock {
2192
- return block . kind === CodeBlockKind . Exception ;
2193
- }
2194
-
2195
2190
/**
2196
2191
* Begins a code block that supports `break` or `continue` statements that are defined in
2197
2192
* the source tree and not from generated code.
2198
2193
*
2199
2194
* @param labelText Names from containing labeled statements.
2200
2195
*/
2201
2196
function beginScriptLoopBlock ( ) : void {
2202
- beginBlock ( < LoopBlock > {
2197
+ beginBlock ( {
2203
2198
kind : CodeBlockKind . Loop ,
2204
2199
isScript : true ,
2205
2200
breakLabel : - 1 ,
@@ -2217,7 +2212,7 @@ namespace ts {
2217
2212
*/
2218
2213
function beginLoopBlock ( continueLabel : Label ) : Label {
2219
2214
const breakLabel = defineLabel ( ) ;
2220
- beginBlock ( < LoopBlock > {
2215
+ beginBlock ( {
2221
2216
kind : CodeBlockKind . Loop ,
2222
2217
isScript : false ,
2223
2218
breakLabel,
@@ -2245,7 +2240,7 @@ namespace ts {
2245
2240
*
2246
2241
*/
2247
2242
function beginScriptSwitchBlock ( ) : void {
2248
- beginBlock ( < SwitchBlock > {
2243
+ beginBlock ( {
2249
2244
kind : CodeBlockKind . Switch ,
2250
2245
isScript : true ,
2251
2246
breakLabel : - 1
@@ -2259,7 +2254,7 @@ namespace ts {
2259
2254
*/
2260
2255
function beginSwitchBlock ( ) : Label {
2261
2256
const breakLabel = defineLabel ( ) ;
2262
- beginBlock ( < SwitchBlock > {
2257
+ beginBlock ( {
2263
2258
kind : CodeBlockKind . Switch ,
2264
2259
isScript : false ,
2265
2260
breakLabel,
@@ -2280,7 +2275,7 @@ namespace ts {
2280
2275
}
2281
2276
2282
2277
function beginScriptLabeledBlock ( labelText : string ) {
2283
- beginBlock ( < LabeledBlock > {
2278
+ beginBlock ( {
2284
2279
kind : CodeBlockKind . Labeled ,
2285
2280
isScript : true ,
2286
2281
labelText,
@@ -2290,7 +2285,7 @@ namespace ts {
2290
2285
2291
2286
function beginLabeledBlock ( labelText : string ) {
2292
2287
const breakLabel = defineLabel ( ) ;
2293
- beginBlock ( < LabeledBlock > {
2288
+ beginBlock ( {
2294
2289
kind : CodeBlockKind . Labeled ,
2295
2290
isScript : false ,
2296
2291
labelText,
@@ -2878,34 +2873,37 @@ namespace ts {
2878
2873
for ( ; blockIndex < blockActions . length && blockOffsets [ blockIndex ] <= operationIndex ; blockIndex ++ ) {
2879
2874
const block = blocks [ blockIndex ] ;
2880
2875
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
+ }
2886
2882
2887
- if ( ! statements ) {
2888
- statements = [ ] ;
2889
- }
2883
+ if ( ! statements ) {
2884
+ statements = [ ] ;
2885
+ }
2890
2886
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 ;
2902
2889
}
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
+ }
2903
2899
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
2909
2907
}
2910
2908
}
2911
2909
}
0 commit comments