Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/transformation/utils/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export interface Scope {
loopContinued?: LoopContinued;
functionReturned?: boolean;
asyncTryHasReturn?: boolean;
asyncTryHasBreak?: boolean;
asyncTryHasContinue?: LoopContinued;
tryHasBreak?: boolean;
tryHasContinue?: LoopContinued;
}

export interface HoistingResult {
Expand Down Expand Up @@ -96,7 +96,7 @@ export function findAsyncTryScopeInStack(context: TransformationContext): Scope
}

/** Like findAsyncTryScopeInStack, but also stops at Loop boundaries. */
export function findAsyncTryScopeBeforeLoop(context: TransformationContext): Scope | undefined {
export function findTryScopeBeforeLoop(context: TransformationContext): Scope | undefined {
for (const scope of walkScopesUp(context)) {
if (scope.type === ScopeType.Function || scope.type === ScopeType.Loop) return undefined;
if (scope.type === ScopeType.Try || scope.type === ScopeType.Catch) return scope;
Expand Down
11 changes: 5 additions & 6 deletions src/transformation/visitors/break-continue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import * as ts from "typescript";
import { LuaTarget } from "../../CompilerOptions";
import * as lua from "../../LuaAST";
import { FunctionVisitor } from "../context";
import { findAsyncTryScopeBeforeLoop, findScope, LoopContinued, ScopeType } from "../utils/scope";
import { isInAsyncFunction } from "../utils/typescript";
import { findScope, findTryScopeBeforeLoop, LoopContinued, ScopeType } from "../utils/scope";

export const transformBreakStatement: FunctionVisitor<ts.BreakStatement> = (breakStatement, context) => {
const tryScope = isInAsyncFunction(breakStatement) ? findAsyncTryScopeBeforeLoop(context) : undefined;
const tryScope = findTryScopeBeforeLoop(context);
if (tryScope) {
tryScope.asyncTryHasBreak = true;
tryScope.tryHasBreak = true;
return [
lua.createAssignmentStatement(
lua.createIdentifier("____hasBroken"),
Expand Down Expand Up @@ -40,9 +39,9 @@ export const transformContinueStatement: FunctionVisitor<ts.ContinueStatement> =
scope.loopContinued = continuedWith;
}

const tryScope = isInAsyncFunction(statement) ? findAsyncTryScopeBeforeLoop(context) : undefined;
const tryScope = findTryScopeBeforeLoop(context);
if (tryScope) {
tryScope.asyncTryHasContinue = continuedWith;
tryScope.tryHasContinue = continuedWith;
return [
lua.createAssignmentStatement(
lua.createIdentifier("____hasContinued"),
Expand Down
Loading
Loading