(node: ts.Statement)
| 300 | } |
| 301 | |
| 302 | parseStatement(node: ts.Statement): syntax.Statement { |
| 303 | switch (node.kind) { |
| 304 | case ts.SyntaxKind.Block: { |
| 305 | // { xxx; yyy; zzz; } |
| 306 | const {statements} = node as ts.Block; |
| 307 | return new syntax.Block(statements.map(this.parseStatement.bind(this))); |
| 308 | } |
| 309 | case ts.SyntaxKind.VariableStatement: { |
| 310 | // let a = xxx, b = xxx; |
| 311 | const {declarationList} = node as ts.VariableStatement; |
| 312 | return new syntax.VariableStatement(this.parseVariableDeclarationList(declarationList)); |
| 313 | } |
| 314 | case ts.SyntaxKind.ExpressionStatement: { |
| 315 | // xxxx; |
| 316 | const expr = this.parseExpression((node as ts.ExpressionStatement).expression); |
| 317 | return new syntax.ExpressionStatement(expr); |
| 318 | } |
| 319 | case ts.SyntaxKind.IfStatement: { |
| 320 | // if (xxx) { yyy } else { zzz } |
| 321 | const {expression, thenStatement, elseStatement} = node as ts.IfStatement; |
| 322 | return new syntax.IfStatement(this.parseExpression(expression), |
| 323 | this.parseStatement(thenStatement), |
| 324 | elseStatement ? this.parseStatement(elseStatement) : undefined); |
| 325 | } |
| 326 | case ts.SyntaxKind.DoStatement: { |
| 327 | // do { xxx } while (yyy) |
| 328 | const {expression, statement} = node as ts.DoStatement; |
| 329 | return new syntax.DoStatement(this.parseStatement(statement), |
| 330 | this.parseExpression(expression)); |
| 331 | } |
| 332 | case ts.SyntaxKind.WhileStatement: { |
| 333 | // while (yyy) { xxx } |
| 334 | const {expression, statement} = node as ts.WhileStatement; |
| 335 | return new syntax.WhileStatement(this.parseStatement(statement), |
| 336 | this.parseExpression(expression)); |
| 337 | } |
| 338 | case ts.SyntaxKind.ForStatement: { |
| 339 | // for (let i = 0; i < N; ++i) { xxx } |
| 340 | const {initializer, condition, incrementor, statement} = node as ts.ForStatement; |
| 341 | let init: undefined | syntax.VariableDeclarationList | syntax.Expression; |
| 342 | if (initializer) { |
| 343 | if (initializer?.kind == ts.SyntaxKind.VariableDeclarationList) |
| 344 | init = this.parseVariableDeclarationList(initializer as ts.VariableDeclarationList); |
| 345 | else |
| 346 | init = this.parseExpression(initializer as ts.Expression); |
| 347 | } |
| 348 | return new syntax.ForStatement(this.parseStatement(statement), |
| 349 | init, |
| 350 | condition ? this.parseExpression(condition) : undefined, |
| 351 | incrementor ? this.parseExpression(incrementor) : undefined); |
| 352 | } |
| 353 | case ts.SyntaxKind.ReturnStatement: { |
| 354 | // return xxx |
| 355 | const {expression} = node as ts.ReturnStatement; |
| 356 | let returnType = syntax.Type.createVoidType(); |
| 357 | if (expression) { |
| 358 | const func = ts.findAncestor(node.parent, isFunctionLikeNode); |
| 359 | if (!func) |
no test coverage detected