From c02816feaddd97a6b915b68ac5f0fe2e9c6bde0e Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Thu, 4 Feb 2016 18:20:25 -0800 Subject: [PATCH] Address PR --- src/compiler/checker.ts | 4 ---- src/compiler/emitter.ts | 25 +++++++++++++------------ src/compiler/utilities.ts | 4 ++++ 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e0caf84fa9d..3e45ce0ab53 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11766,10 +11766,6 @@ namespace ts { return; } - function isSuperCallExpression(n: Node): boolean { - return n.kind === SyntaxKind.CallExpression && (n).expression.kind === SyntaxKind.SuperKeyword; - } - function containsSuperCallAsComputedPropertyName(n: Declaration): boolean { return n.name && containsSuperCall(n.name); } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 3d173c4cf58..7bcbf906f53 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4768,21 +4768,22 @@ const _super = (function (geti, seti) { /** * Return the statement at a given index if it is a super-call statement - * @param ctor constructor declaration + * @param ctor a constructor declaration * @param index an index to constructor's body to check */ function getSuperCallAtGivenIndex(ctor: ConstructorDeclaration, index: number): ExpressionStatement { - if (ctor.body) { - const statement = (ctor.body).statements[index]; - if (statement && statement.kind === SyntaxKind.ExpressionStatement) { - const expr = (statement).expression; - if (expr && expr.kind === SyntaxKind.CallExpression) { - const func = (expr).expression; - if (func && func.kind === SyntaxKind.SuperKeyword) { - return statement; - } - } - } + if (!ctor.body) { + return undefined; + } + const statements = ctor.body.statements; + + if (!statements || index >= statements.length) { + return undefined; + } + + const statement = statements[index]; + if (statement.kind === SyntaxKind.ExpressionStatement) { + return isSuperCallExpression((statement).expression) ? statement : undefined; } } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 8bcf89ce1f2..ce959b2a369 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -464,6 +464,10 @@ namespace ts { return !!(getCombinedNodeFlags(node) & NodeFlags.Let); } + export function isSuperCallExpression(n: Node): boolean { + return n.kind === SyntaxKind.CallExpression && (n).expression.kind === SyntaxKind.SuperKeyword; + } + export function isPrologueDirective(node: Node): boolean { return node.kind === SyntaxKind.ExpressionStatement && (node).expression.kind === SyntaxKind.StringLiteral; }