diff --git a/src/emitter.ts b/src/emitter.ts index 86c30a3..fd60c4d 100644 --- a/src/emitter.ts +++ b/src/emitter.ts @@ -339,8 +339,8 @@ export function emitFile( // return emitLabeledStatement(node); case SyntaxKind.ThrowStatement: return emitThrowStatement(node); - // case SyntaxKind.TryStatement: - // return emitTryStatement(node); + case SyntaxKind.TryStatement: + return emitTryStatement(node); // case SyntaxKind.DebuggerStatement: // return emitDebuggerStatement(node); @@ -428,8 +428,8 @@ export function emitFile( return emitDefaultClause(node); case SyntaxKind.HeritageClause: return emitHeritageClause(node); - // case SyntaxKind.CatchClause: - // return emitCatchClause(node); + case SyntaxKind.CatchClause: + return emitCatchClause(node); // // Property assignments case SyntaxKind.PropertyAssignment: @@ -1655,21 +1655,21 @@ export function emitFile( writeSemicolon(); } - // function emitTryStatement(node: TryStatement) { - // emitTokenWithComment(SyntaxKind.TryKeyword, node.pos, writeKeyword, node); - // writeSpace(); - // emit(node.tryBlock); - // if (node.catchClause) { - // writeLineOrSpace(node); - // emit(node.catchClause); - // } - // if (node.finallyBlock) { - // writeLineOrSpace(node); - // emitTokenWithComment(SyntaxKind.FinallyKeyword, (node.catchClause || node.tryBlock).end, writeKeyword, node); - // writeSpace(); - // emit(node.finallyBlock); - // } - // } + function emitTryStatement(node: ts.TryStatement) { + emitTokenWithComment(SyntaxKind.TryKeyword, node.pos, writeKeyword, node); + writeSpace(); + emit(node.tryBlock); + if (node.catchClause) { + writeLineOrSpace(node); + emit(node.catchClause); + } + if (node.finallyBlock) { + writeLineOrSpace(node); + emitTokenWithComment(SyntaxKind.FinallyKeyword, (node.catchClause || node.tryBlock).end, writeKeyword, node); + writeSpace(); + emit(node.finallyBlock); + } + } // function emitDebuggerStatement(node: DebuggerStatement) { // writeToken(SyntaxKind.DebuggerKeyword, node.pos, writeKeyword); @@ -2328,17 +2328,18 @@ export function emitFile( emitList(node, node.types, ListFormat.HeritageClauseTypes); } - // function emitCatchClause(node: CatchClause) { - // const openParenPos = emitTokenWithComment(SyntaxKind.CatchKeyword, node.pos, writeKeyword, node); - // writeSpace(); - // if (node.variableDeclaration) { - // emitTokenWithComment(SyntaxKind.OpenParenToken, openParenPos, writePunctuation, node); - // emit(node.variableDeclaration); - // emitTokenWithComment(SyntaxKind.CloseParenToken, node.variableDeclaration.end, writePunctuation, node); - // writeSpace(); - // } - // emit(node.block); - // } + function emitCatchClause(node: ts.CatchClause) { + const openParenPos = emitTokenWithComment(SyntaxKind.CatchKeyword, node.pos, writeKeyword, node); + writeSpace(); + if (node.variableDeclaration) { + emitTokenWithComment(SyntaxKind.OpenParenToken, openParenPos, writePunctuation, node); + emitIdentifier(ts.createIdentifier('\\Exception')); + emitWithLeadingSpace(node.variableDeclaration); + emitTokenWithComment(SyntaxKind.CloseParenToken, node.variableDeclaration.end, writePunctuation, node); + writeSpace(); + } + emit(node.block); + } // // // // Property assignments diff --git a/test/features/exception.php b/test/features/exception.php index ba8264e..e7e59f9 100644 --- a/test/features/exception.php +++ b/test/features/exception.php @@ -1,6 +1,11 @@