mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
Merge pull request #6911 from Microsoft/fix6901
Fix emitting super-call when using prologue directives
This commit is contained in:
commit
aaea852609
28 files changed
+630
-18
No files matched your search
@@ -11813,10 +11813,6 @@ namespace ts {
|
||||
return;
|
||||
}
|
||||
|
||||
function isSuperCallExpression(n: Node): boolean {
|
||||
return n.kind === SyntaxKind.CallExpression && (<CallExpression>n).expression.kind === SyntaxKind.SuperKeyword;
|
||||
}
|
||||
|
||||
function containsSuperCallAsComputedPropertyName(n: Declaration): boolean {
|
||||
return n.name && containsSuperCall(n.name);
|
||||
}
|
||||
|
||||
+21
-13
@@ -4871,18 +4871,24 @@ const _super = (function (geti, seti) {
|
||||
emitToken(SyntaxKind.CloseBraceToken, body.statements.end);
|
||||
}
|
||||
|
||||
function findInitialSuperCall(ctor: ConstructorDeclaration): ExpressionStatement {
|
||||
if (ctor.body) {
|
||||
const statement = (<Block>ctor.body).statements[0];
|
||||
if (statement && statement.kind === SyntaxKind.ExpressionStatement) {
|
||||
const expr = (<ExpressionStatement>statement).expression;
|
||||
if (expr && expr.kind === SyntaxKind.CallExpression) {
|
||||
const func = (<CallExpression>expr).expression;
|
||||
if (func && func.kind === SyntaxKind.SuperKeyword) {
|
||||
return <ExpressionStatement>statement;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Return the statement at a given index if it is a super-call statement
|
||||
* @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) {
|
||||
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((<ExpressionStatement>statement).expression) ? <ExpressionStatement>statement : undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5166,13 +5172,15 @@ const _super = (function (geti, seti) {
|
||||
if (ctor) {
|
||||
emitDefaultValueAssignments(ctor);
|
||||
emitRestParameter(ctor);
|
||||
|
||||
if (baseTypeElement) {
|
||||
superCall = findInitialSuperCall(ctor);
|
||||
superCall = getSuperCallAtGivenIndex(ctor, startIndex);
|
||||
if (superCall) {
|
||||
writeLine();
|
||||
emit(superCall);
|
||||
}
|
||||
}
|
||||
|
||||
emitParameterPropertyAssignments(ctor);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -464,6 +464,10 @@ namespace ts {
|
||||
return !!(getCombinedNodeFlags(node) & NodeFlags.Let);
|
||||
}
|
||||
|
||||
export function isSuperCallExpression(n: Node): boolean {
|
||||
return n.kind === SyntaxKind.CallExpression && (<CallExpression>n).expression.kind === SyntaxKind.SuperKeyword;
|
||||
}
|
||||
|
||||
export function isPrologueDirective(node: Node): boolean {
|
||||
return node.kind === SyntaxKind.ExpressionStatement && (<ExpressionStatement>node).expression.kind === SyntaxKind.StringLiteral;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user