diff --git a/ts2panda/src/compiler.ts b/ts2panda/src/compiler.ts index 5ad1fc05044da80118a45a02defea09347913a4b..38596ff38f7a6462911af4b6569b046211a4022f 100644 --- a/ts2panda/src/compiler.ts +++ b/ts2panda/src/compiler.ts @@ -713,7 +713,27 @@ export class Compiler { // restore pandaGen.tryStatement TryStatement.setCurrentTryStatement(saveTry); - updateCatchTables(originTry, startTry, inlinedLabelPair); + /* + * split the catchZone in most Inner try & add the insertedZone by the finally-nearset TryZone. + * the inserted innerTry's FinallyBlock can only be catched by the outer's tryBlock. so here just + * need append the inserted finally's Zone into the outerTry's catchTable in order. + * OuterTryBegin ---- + * | + * InnerTryBegin ---- + * + * ---- InnerTry's FinallyBegin -- + * | | + * ---- InnerTry's FinallyEnd -- + * return; + * InnerTryEnd ---- + * | + * OuterTryEnd ---- + */ + originTry.getCatchTable().splitLabelPair(inlinedLabelPair); + if (startTry.getOuterTryStatement()) { + let outerLabelPairs: LabelPair[] = startTry.getOuterTryStatement().getCatchTable().getLabelPairs(); + outerLabelPairs.splice(outerLabelPairs.length - 2, 0, inlinedLabelPair); + } } } this.scope = currentScope; @@ -941,8 +961,8 @@ export class Compiler { this.compileExpression(findInnerExprOfParenthesis(expr)); break; case ts.SyntaxKind.CommaListExpression: - compileCommaListExpression(this, expr); - break; + compileCommaListExpression(this, expr); + break; default: throw new Error("Expression of type " + this.getNodeName(expr) + " is unimplemented"); } diff --git a/ts2panda/src/compilerUtils.ts b/ts2panda/src/compilerUtils.ts index 01734351a4c0cd8a55162cf70c2ddaef4dcc687d..79979cf0e04016401c0dac217158f55fbc68e78d 100644 --- a/ts2panda/src/compilerUtils.ts +++ b/ts2panda/src/compilerUtils.ts @@ -94,6 +94,7 @@ function compileArrayDestructuring(arr: ts.ArrayBindingOrAssignmentPattern, pand // if a hole exist, just let the iterator step ahead if (ts.isOmittedExpression(element)) { + iterator.iteratorComplete(nextResult); continue; } diff --git a/ts2panda/src/statement/tryStatement.ts b/ts2panda/src/statement/tryStatement.ts index bdc0a632df752d4ff1aebc9de86e470c10add869..05f8e9bea4feb93f15accd90c014cd71ebd8a15b 100644 --- a/ts2panda/src/statement/tryStatement.ts +++ b/ts2panda/src/statement/tryStatement.ts @@ -26,8 +26,6 @@ import { getVregisterCache } from "../base/vregisterCache"; import { IteratorRecord } from "./forOfStatement"; -import * as astutils from "../astutils"; -import { VarDeclarationKind } from "../variable"; import * as jshelpers from "../jshelpers"; // adjust the try...catch...finally into nested try(try...catch) finally @@ -117,6 +115,20 @@ export class TryStatement { constructor(stmt: ts.Statement, catchTable: CatchTable, trybuilder?: TryBuilderBase) { TryStatement.currentTryStatementDepth++; this.outer = TryStatement.currentTryStatement; + /* + * split the outer TryStatment's try block + * OuterTryBegin ---- OuterTryBegin ---- + * outerTry | outerTry | + * InnerTryBegin -- | InnerTryBegin -- ---- + * innerTry | | ==> innerTry | + * InnerTryEnd -- | InnerTryEnd -- ---- + * | outerTry | + * OuterTryEnd ---- OuterTryEnd ---- + */ + if (this.outer) { + let labelPairs: LabelPair[] = catchTable.getLabelPairs(); + this.outer.catchTable.splitLabelPair(labelPairs[labelPairs.length - 1]); + } this.stmt = stmt; this.catchTable = catchTable; if (trybuilder) {