From c25170558e57cf92a5f36c079519723edc5b24fe Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 9 Apr 2015 16:06:26 -0700 Subject: [PATCH 1/3] Added test for super method calls in ES6 classes. --- ...itClassDeclarationWithSuperMethodCall01.js | 24 +++++++++++++++++ ...lassDeclarationWithSuperMethodCall01.types | 26 +++++++++++++++++++ ...itClassDeclarationWithSuperMethodCall01.ts | 12 +++++++++ 3 files changed, 62 insertions(+) create mode 100644 tests/baselines/reference/emitClassDeclarationWithSuperMethodCall01.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithSuperMethodCall01.types create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithSuperMethodCall01.ts diff --git a/tests/baselines/reference/emitClassDeclarationWithSuperMethodCall01.js b/tests/baselines/reference/emitClassDeclarationWithSuperMethodCall01.js new file mode 100644 index 00000000000..f0712f8e131 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithSuperMethodCall01.js @@ -0,0 +1,24 @@ +//// [emitClassDeclarationWithSuperMethodCall01.ts] + +class Parent { + foo() { + } +} + +class Foo extends Parent { + foo() { + var x = () => super.foo(); + } +} + +//// [emitClassDeclarationWithSuperMethodCall01.js] +class Parent { + foo() { + } +} +class Foo extends Parent { + foo() { + var _this = this; + var x = () => super.foo(); + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithSuperMethodCall01.types b/tests/baselines/reference/emitClassDeclarationWithSuperMethodCall01.types new file mode 100644 index 00000000000..8b68af897ac --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithSuperMethodCall01.types @@ -0,0 +1,26 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithSuperMethodCall01.ts === + +class Parent { +>Parent : Parent + + foo() { +>foo : () => void + } +} + +class Foo extends Parent { +>Foo : Foo +>Parent : Parent + + foo() { +>foo : () => void + + var x = () => super.foo(); +>x : () => void +>() => super.foo() : () => void +>super.foo() : void +>super.foo : () => void +>super : Parent +>foo : () => void + } +} diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithSuperMethodCall01.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithSuperMethodCall01.ts new file mode 100644 index 00000000000..d9fdcc167eb --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithSuperMethodCall01.ts @@ -0,0 +1,12 @@ +//@target: es6 + +class Parent { + foo() { + } +} + +class Foo extends Parent { + foo() { + var x = () => super.foo(); + } +} \ No newline at end of file From fb8cc0c40a9c79f4ee31c226cd266b3e0df37aa8 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 9 Apr 2015 16:29:38 -0700 Subject: [PATCH 2/3] Don't emit '_this' declaration in ES6 or later. --- src/compiler/checker.ts | 2 +- tests/baselines/reference/computedPropertyNames31_ES6.js | 1 - .../reference/emitClassDeclarationWithSuperMethodCall01.js | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ea38a8f4b31..ea86b2b9b04 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5582,7 +5582,7 @@ module ts { needToCaptureLexicalThis = false; while (container && container.kind === SyntaxKind.ArrowFunction) { container = getSuperContainer(container, /*includeFunctions*/ true); - needToCaptureLexicalThis = true; + needToCaptureLexicalThis = languageVersion < ScriptTarget.ES6; } // topmost container must be something that is directly nested in the class declaration diff --git a/tests/baselines/reference/computedPropertyNames31_ES6.js b/tests/baselines/reference/computedPropertyNames31_ES6.js index 2c63dcee077..d17423223e3 100644 --- a/tests/baselines/reference/computedPropertyNames31_ES6.js +++ b/tests/baselines/reference/computedPropertyNames31_ES6.js @@ -23,7 +23,6 @@ class Base { } class C extends Base { foo() { - var _this = this; (() => { var obj = { [super.bar()]() { } // needs capture diff --git a/tests/baselines/reference/emitClassDeclarationWithSuperMethodCall01.js b/tests/baselines/reference/emitClassDeclarationWithSuperMethodCall01.js index f0712f8e131..77b91730156 100644 --- a/tests/baselines/reference/emitClassDeclarationWithSuperMethodCall01.js +++ b/tests/baselines/reference/emitClassDeclarationWithSuperMethodCall01.js @@ -18,7 +18,6 @@ class Parent { } class Foo extends Parent { foo() { - var _this = this; var x = () => super.foo(); } } From 63bb38157be0b5952e488647256b79f0d513f75c Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 9 Apr 2015 17:00:22 -0700 Subject: [PATCH 3/3] Ragga fragga newlines. --- .../class/method/decoratorOnClassMethod11.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod11.ts b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod11.ts index e3d94ff25d2..6f80fa00bca 100644 --- a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod11.ts +++ b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod11.ts @@ -1,9 +1,9 @@ -// @target: ES5 -module M { - class C { - decorator(target: Object, key: string): void { } - - @this.decorator - method() { } - } +// @target: ES5 +module M { + class C { + decorator(target: Object, key: string): void { } + + @this.decorator + method() { } + } } \ No newline at end of file