@@ -3,16 +3,11 @@ import { LuaTarget } from "../../CompilerOptions";
33import * as lua from "../../LuaAST" ;
44import { FunctionVisitor } from "../context" ;
55import { unsupportedForTarget } from "../utils/diagnostics" ;
6- import { UndefinedScope } from "../utils/errors" ;
76import { findScope , ScopeType } from "../utils/scope" ;
87
98export const transformBreakStatement : FunctionVisitor < ts . BreakStatement > = ( breakStatement , context ) => {
109 const breakableScope = findScope ( context , ScopeType . Loop | ScopeType . Switch ) ;
11- if ( breakableScope === undefined ) {
12- throw UndefinedScope ( ) ;
13- }
14-
15- if ( breakableScope . type === ScopeType . Switch ) {
10+ if ( breakableScope ?. type === ScopeType . Switch ) {
1611 return lua . createGotoStatement ( `____switch${ breakableScope . id } _end` ) ;
1712 } else {
1813 return lua . createBreakStatement ( breakStatement ) ;
@@ -25,10 +20,10 @@ export const transformContinueStatement: FunctionVisitor<ts.ContinueStatement> =
2520 }
2621
2722 const scope = findScope ( context , ScopeType . Loop ) ;
28- if ( scope === undefined ) {
29- throw UndefinedScope ( ) ;
23+
24+ if ( scope ) {
25+ scope . loopContinued = true ;
3026 }
3127
32- scope . loopContinued = true ;
33- return lua . createGotoStatement ( `__continue${ scope . id } ` , statement ) ;
28+ return lua . createGotoStatement ( `__continue${ scope ?. id ?? "" } ` , statement ) ;
3429} ;
0 commit comments