Skip to content

Commit 6493980

Browse files
Merge pull request #2701 from Microsoft/superAnnoyingEmitInEs6Classes
Don't emit '_this' when encountering 'super' in ES6 emit
2 parents 97a3e71 + 63bb381 commit 6493980

File tree

6 files changed

+70
-10
lines changed

6 files changed

+70
-10
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5582,7 +5582,7 @@ module ts {
55825582
needToCaptureLexicalThis = false;
55835583
while (container && container.kind === SyntaxKind.ArrowFunction) {
55845584
container = getSuperContainer(container, /*includeFunctions*/ true);
5585-
needToCaptureLexicalThis = true;
5585+
needToCaptureLexicalThis = languageVersion < ScriptTarget.ES6;
55865586
}
55875587

55885588
// topmost container must be something that is directly nested in the class declaration

tests/baselines/reference/computedPropertyNames31_ES6.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class Base {
2323
}
2424
class C extends Base {
2525
foo() {
26-
var _this = this;
2726
(() => {
2827
var obj = {
2928
[super.bar()]() { } // needs capture
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//// [emitClassDeclarationWithSuperMethodCall01.ts]
2+
3+
class Parent {
4+
foo() {
5+
}
6+
}
7+
8+
class Foo extends Parent {
9+
foo() {
10+
var x = () => super.foo();
11+
}
12+
}
13+
14+
//// [emitClassDeclarationWithSuperMethodCall01.js]
15+
class Parent {
16+
foo() {
17+
}
18+
}
19+
class Foo extends Parent {
20+
foo() {
21+
var x = () => super.foo();
22+
}
23+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithSuperMethodCall01.ts ===
2+
3+
class Parent {
4+
>Parent : Parent
5+
6+
foo() {
7+
>foo : () => void
8+
}
9+
}
10+
11+
class Foo extends Parent {
12+
>Foo : Foo
13+
>Parent : Parent
14+
15+
foo() {
16+
>foo : () => void
17+
18+
var x = () => super.foo();
19+
>x : () => void
20+
>() => super.foo() : () => void
21+
>super.foo() : void
22+
>super.foo : () => void
23+
>super : Parent
24+
>foo : () => void
25+
}
26+
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// @target: ES5
2-
module M {
3-
class C {
4-
decorator(target: Object, key: string): void { }
5-
6-
@this.decorator
7-
method() { }
8-
}
1+
// @target: ES5
2+
module M {
3+
class C {
4+
decorator(target: Object, key: string): void { }
5+
6+
@this.decorator
7+
method() { }
8+
}
99
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@target: es6
2+
3+
class Parent {
4+
foo() {
5+
}
6+
}
7+
8+
class Foo extends Parent {
9+
foo() {
10+
var x = () => super.foo();
11+
}
12+
}

0 commit comments

Comments
 (0)