Skip to content

Commit 9cc8b2e

Browse files
Merge pull request #10189 from chancancode/constructor-splat-arguments
Emit more efficient/concise "empty" ES6 ctor
2 parents 2a62917 + cc2dc3a commit 9cc8b2e

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed

src/compiler/emitter.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5311,18 +5311,7 @@ const _super = (function (geti, seti) {
53115311
emitSignatureParameters(ctor);
53125312
}
53135313
else {
5314-
// Based on EcmaScript6 section 14.5.14: Runtime Semantics: ClassDefinitionEvaluation.
5315-
// If constructor is empty, then,
5316-
// If ClassHeritageopt is present, then
5317-
// Let constructor be the result of parsing the String "constructor(... args){ super (...args);}" using the syntactic grammar with the goal symbol MethodDefinition.
5318-
// Else,
5319-
// Let constructor be the result of parsing the String "constructor( ){ }" using the syntactic grammar with the goal symbol MethodDefinition
5320-
if (baseTypeElement) {
5321-
write("(...args)");
5322-
}
5323-
else {
5324-
write("()");
5325-
}
5314+
write("()");
53265315
}
53275316
}
53285317

@@ -5360,7 +5349,7 @@ const _super = (function (geti, seti) {
53605349
write("_super.apply(this, arguments);");
53615350
}
53625351
else {
5363-
write("super(...args);");
5352+
write("super(...arguments);");
53645353
}
53655354
emitEnd(baseTypeElement);
53665355
}

tests/baselines/reference/classExpressionES63.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ let C = class extends class extends class {
1313
}
1414
}
1515
{
16-
constructor(...args) {
17-
super(...args);
16+
constructor() {
17+
super(...arguments);
1818
this.b = 2;
1919
}
2020
}
2121
{
22-
constructor(...args) {
23-
super(...args);
22+
constructor() {
23+
super(...arguments);
2424
this.c = 3;
2525
}
2626
}

tests/baselines/reference/emitClassDeclarationWithPropertyAssignmentInES6.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class D {
3737
}
3838
}
3939
class E extends D {
40-
constructor(...args) {
41-
super(...args);
40+
constructor() {
41+
super(...arguments);
4242
this.z = true;
4343
}
4444
}

0 commit comments

Comments
 (0)