Skip to content

Commit d830034

Browse files
Merge pull request #10404 from Microsoft/addCommentForEmptyCtorEmit
Restored comments to explain spreading 'arguments' into 'super' calls
2 parents 6facbf1 + 73a857b commit d830034

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/compiler/emitter.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5311,6 +5311,21 @@ const _super = (function (geti, seti) {
53115311
emitSignatureParameters(ctor);
53125312
}
53135313
else {
5314+
// The ES2015 spec specifies in 14.5.14. Runtime Semantics: ClassDefinitionEvaluation:
5315+
// If constructor is empty, then
5316+
// If ClassHeritag_eopt is present and protoParent is not null, then
5317+
// Let constructor be the result of parsing the source text
5318+
// constructor(...args) { super (...args);}
5319+
// using the syntactic grammar with the goal symbol MethodDefinition[~Yield].
5320+
// Else,
5321+
// Let constructor be the result of parsing the source text
5322+
// constructor( ){ }
5323+
// using the syntactic grammar with the goal symbol MethodDefinition[~Yield].
5324+
//
5325+
// While we could emit the '...args' rest parameter, certain later tools in the pipeline might
5326+
// downlevel the '...args' portion less efficiently by naively copying the contents of 'arguments' to an array.
5327+
// Instead, we'll avoid using a rest parameter and spread into the super call as
5328+
// 'super(...arguments)' instead of 'super(...args)', as you can see below.
53145329
write("()");
53155330
}
53165331
}
@@ -5349,6 +5364,7 @@ const _super = (function (geti, seti) {
53495364
write("_super.apply(this, arguments);");
53505365
}
53515366
else {
5367+
// See comment above on using '...arguments' instead of '...args'.
53525368
write("super(...arguments);");
53535369
}
53545370
emitEnd(baseTypeElement);

0 commit comments

Comments
 (0)