mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Add handleing for classes
This commit is contained in:
parent
18a875807c
commit
8360bc7961
@ -5559,7 +5559,11 @@ const _super = (function (geti, seti) {
|
||||
}
|
||||
|
||||
function emitClassLikeDeclarationBelowES6(node: ClassLikeDeclaration) {
|
||||
const isES6ExportedClass = isES6ExportedDeclaration(node);
|
||||
if (node.kind === SyntaxKind.ClassDeclaration) {
|
||||
if (isES6ExportedClass && !(node.flags & NodeFlags.Default)) {
|
||||
write("export ");
|
||||
}
|
||||
// source file level classes in system modules are hoisted so 'var's for them are already defined
|
||||
if (!shouldHoistDeclarationInSystemJsModule(node)) {
|
||||
write("var ");
|
||||
@ -5629,9 +5633,15 @@ const _super = (function (geti, seti) {
|
||||
}
|
||||
emitEnd(node);
|
||||
|
||||
if (node.kind === SyntaxKind.ClassDeclaration) {
|
||||
if (node.kind === SyntaxKind.ClassDeclaration && !isES6ExportedClass) {
|
||||
emitExportMemberAssignment(<ClassDeclaration>node);
|
||||
}
|
||||
else if (isES6ExportedClass && (node.flags & NodeFlags.Default)) {
|
||||
writeLine();
|
||||
write("export default ");
|
||||
emitDeclarationName(node);
|
||||
write(";");
|
||||
}
|
||||
}
|
||||
|
||||
function emitClassMemberPrefix(node: ClassLikeDeclaration, member: Node) {
|
||||
|
||||
51
tests/baselines/reference/es6modulekindWithES5Target.js
Normal file
51
tests/baselines/reference/es6modulekindWithES5Target.js
Normal file
@ -0,0 +1,51 @@
|
||||
//// [es6modulekindWithES5Target.ts]
|
||||
|
||||
export class C {
|
||||
static s = 0;
|
||||
p = 1;
|
||||
method() { }
|
||||
}
|
||||
|
||||
declare function foo(...args: any[]): any;
|
||||
@foo
|
||||
export class D {
|
||||
static s = 0;
|
||||
p = 1;
|
||||
method() { }
|
||||
}
|
||||
|
||||
class E { }
|
||||
export {E};
|
||||
|
||||
//// [es6modulekindWithES5Target.js]
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
export var C = (function () {
|
||||
function C() {
|
||||
this.p = 1;
|
||||
}
|
||||
C.prototype.method = function () { };
|
||||
C.s = 0;
|
||||
return C;
|
||||
}());
|
||||
export var D = (function () {
|
||||
function D() {
|
||||
this.p = 1;
|
||||
}
|
||||
D.prototype.method = function () { };
|
||||
D.s = 0;
|
||||
D = __decorate([
|
||||
foo
|
||||
], D);
|
||||
return D;
|
||||
}());
|
||||
var E = (function () {
|
||||
function E() {
|
||||
}
|
||||
return E;
|
||||
}());
|
||||
export { E };
|
||||
41
tests/baselines/reference/es6modulekindWithES5Target.symbols
Normal file
41
tests/baselines/reference/es6modulekindWithES5Target.symbols
Normal file
@ -0,0 +1,41 @@
|
||||
=== tests/cases/compiler/es6modulekindWithES5Target.ts ===
|
||||
|
||||
export class C {
|
||||
>C : Symbol(C, Decl(es6modulekindWithES5Target.ts, 0, 0))
|
||||
|
||||
static s = 0;
|
||||
>s : Symbol(C.s, Decl(es6modulekindWithES5Target.ts, 1, 16))
|
||||
|
||||
p = 1;
|
||||
>p : Symbol(C.p, Decl(es6modulekindWithES5Target.ts, 2, 17))
|
||||
|
||||
method() { }
|
||||
>method : Symbol(C.method, Decl(es6modulekindWithES5Target.ts, 3, 10))
|
||||
}
|
||||
|
||||
declare function foo(...args: any[]): any;
|
||||
>foo : Symbol(foo, Decl(es6modulekindWithES5Target.ts, 5, 1))
|
||||
>args : Symbol(args, Decl(es6modulekindWithES5Target.ts, 7, 21))
|
||||
|
||||
@foo
|
||||
>foo : Symbol(foo, Decl(es6modulekindWithES5Target.ts, 5, 1))
|
||||
|
||||
export class D {
|
||||
>D : Symbol(D, Decl(es6modulekindWithES5Target.ts, 7, 42))
|
||||
|
||||
static s = 0;
|
||||
>s : Symbol(D.s, Decl(es6modulekindWithES5Target.ts, 9, 16))
|
||||
|
||||
p = 1;
|
||||
>p : Symbol(D.p, Decl(es6modulekindWithES5Target.ts, 10, 17))
|
||||
|
||||
method() { }
|
||||
>method : Symbol(D.method, Decl(es6modulekindWithES5Target.ts, 11, 10))
|
||||
}
|
||||
|
||||
class E { }
|
||||
>E : Symbol(E, Decl(es6modulekindWithES5Target.ts, 13, 1))
|
||||
|
||||
export {E};
|
||||
>E : Symbol(E, Decl(es6modulekindWithES5Target.ts, 16, 8))
|
||||
|
||||
45
tests/baselines/reference/es6modulekindWithES5Target.types
Normal file
45
tests/baselines/reference/es6modulekindWithES5Target.types
Normal file
@ -0,0 +1,45 @@
|
||||
=== tests/cases/compiler/es6modulekindWithES5Target.ts ===
|
||||
|
||||
export class C {
|
||||
>C : C
|
||||
|
||||
static s = 0;
|
||||
>s : number
|
||||
>0 : number
|
||||
|
||||
p = 1;
|
||||
>p : number
|
||||
>1 : number
|
||||
|
||||
method() { }
|
||||
>method : () => void
|
||||
}
|
||||
|
||||
declare function foo(...args: any[]): any;
|
||||
>foo : (...args: any[]) => any
|
||||
>args : any[]
|
||||
|
||||
@foo
|
||||
>foo : (...args: any[]) => any
|
||||
|
||||
export class D {
|
||||
>D : D
|
||||
|
||||
static s = 0;
|
||||
>s : number
|
||||
>0 : number
|
||||
|
||||
p = 1;
|
||||
>p : number
|
||||
>1 : number
|
||||
|
||||
method() { }
|
||||
>method : () => void
|
||||
}
|
||||
|
||||
class E { }
|
||||
>E : E
|
||||
|
||||
export {E};
|
||||
>E : typeof E
|
||||
|
||||
19
tests/baselines/reference/es6modulekindWithES5Target2.js
Normal file
19
tests/baselines/reference/es6modulekindWithES5Target2.js
Normal file
@ -0,0 +1,19 @@
|
||||
//// [es6modulekindWithES5Target2.ts]
|
||||
|
||||
export default class C {
|
||||
static s = 0;
|
||||
p = 1;
|
||||
method() { }
|
||||
}
|
||||
|
||||
|
||||
//// [es6modulekindWithES5Target2.js]
|
||||
var C = (function () {
|
||||
function C() {
|
||||
this.p = 1;
|
||||
}
|
||||
C.prototype.method = function () { };
|
||||
C.s = 0;
|
||||
return C;
|
||||
}());
|
||||
export default C;
|
||||
@ -0,0 +1,15 @@
|
||||
=== tests/cases/compiler/es6modulekindWithES5Target2.ts ===
|
||||
|
||||
export default class C {
|
||||
>C : Symbol(C, Decl(es6modulekindWithES5Target2.ts, 0, 0))
|
||||
|
||||
static s = 0;
|
||||
>s : Symbol(C.s, Decl(es6modulekindWithES5Target2.ts, 1, 24))
|
||||
|
||||
p = 1;
|
||||
>p : Symbol(C.p, Decl(es6modulekindWithES5Target2.ts, 2, 17))
|
||||
|
||||
method() { }
|
||||
>method : Symbol(C.method, Decl(es6modulekindWithES5Target2.ts, 3, 10))
|
||||
}
|
||||
|
||||
17
tests/baselines/reference/es6modulekindWithES5Target2.types
Normal file
17
tests/baselines/reference/es6modulekindWithES5Target2.types
Normal file
@ -0,0 +1,17 @@
|
||||
=== tests/cases/compiler/es6modulekindWithES5Target2.ts ===
|
||||
|
||||
export default class C {
|
||||
>C : C
|
||||
|
||||
static s = 0;
|
||||
>s : number
|
||||
>0 : number
|
||||
|
||||
p = 1;
|
||||
>p : number
|
||||
>1 : number
|
||||
|
||||
method() { }
|
||||
>method : () => void
|
||||
}
|
||||
|
||||
30
tests/baselines/reference/es6modulekindWithES5Target3.js
Normal file
30
tests/baselines/reference/es6modulekindWithES5Target3.js
Normal file
@ -0,0 +1,30 @@
|
||||
//// [es6modulekindWithES5Target3.ts]
|
||||
|
||||
|
||||
declare function foo(...args: any[]): any;
|
||||
@foo
|
||||
export default class D {
|
||||
static s = 0;
|
||||
p = 1;
|
||||
method() { }
|
||||
}
|
||||
|
||||
//// [es6modulekindWithES5Target3.js]
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var D = (function () {
|
||||
function D() {
|
||||
this.p = 1;
|
||||
}
|
||||
D.prototype.method = function () { };
|
||||
D.s = 0;
|
||||
D = __decorate([
|
||||
foo
|
||||
], D);
|
||||
return D;
|
||||
}());
|
||||
export default D;
|
||||
@ -0,0 +1,22 @@
|
||||
=== tests/cases/compiler/es6modulekindWithES5Target3.ts ===
|
||||
|
||||
|
||||
declare function foo(...args: any[]): any;
|
||||
>foo : Symbol(foo, Decl(es6modulekindWithES5Target3.ts, 0, 0))
|
||||
>args : Symbol(args, Decl(es6modulekindWithES5Target3.ts, 2, 21))
|
||||
|
||||
@foo
|
||||
>foo : Symbol(foo, Decl(es6modulekindWithES5Target3.ts, 0, 0))
|
||||
|
||||
export default class D {
|
||||
>D : Symbol(D, Decl(es6modulekindWithES5Target3.ts, 2, 42))
|
||||
|
||||
static s = 0;
|
||||
>s : Symbol(D.s, Decl(es6modulekindWithES5Target3.ts, 4, 24))
|
||||
|
||||
p = 1;
|
||||
>p : Symbol(D.p, Decl(es6modulekindWithES5Target3.ts, 5, 17))
|
||||
|
||||
method() { }
|
||||
>method : Symbol(D.method, Decl(es6modulekindWithES5Target3.ts, 6, 10))
|
||||
}
|
||||
24
tests/baselines/reference/es6modulekindWithES5Target3.types
Normal file
24
tests/baselines/reference/es6modulekindWithES5Target3.types
Normal file
@ -0,0 +1,24 @@
|
||||
=== tests/cases/compiler/es6modulekindWithES5Target3.ts ===
|
||||
|
||||
|
||||
declare function foo(...args: any[]): any;
|
||||
>foo : (...args: any[]) => any
|
||||
>args : any[]
|
||||
|
||||
@foo
|
||||
>foo : (...args: any[]) => any
|
||||
|
||||
export default class D {
|
||||
>D : D
|
||||
|
||||
static s = 0;
|
||||
>s : number
|
||||
>0 : number
|
||||
|
||||
p = 1;
|
||||
>p : number
|
||||
>1 : number
|
||||
|
||||
method() { }
|
||||
>method : () => void
|
||||
}
|
||||
12
tests/baselines/reference/es6modulekindWithES5Target4.js
Normal file
12
tests/baselines/reference/es6modulekindWithES5Target4.js
Normal file
@ -0,0 +1,12 @@
|
||||
//// [es6modulekindWithES5Target4.ts]
|
||||
|
||||
class E { }
|
||||
export default E;
|
||||
|
||||
//// [es6modulekindWithES5Target4.js]
|
||||
var E = (function () {
|
||||
function E() {
|
||||
}
|
||||
return E;
|
||||
}());
|
||||
export default E;
|
||||
@ -0,0 +1,8 @@
|
||||
=== tests/cases/compiler/es6modulekindWithES5Target4.ts ===
|
||||
|
||||
class E { }
|
||||
>E : Symbol(E, Decl(es6modulekindWithES5Target4.ts, 0, 0))
|
||||
|
||||
export default E;
|
||||
>E : Symbol(E, Decl(es6modulekindWithES5Target4.ts, 0, 0))
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
=== tests/cases/compiler/es6modulekindWithES5Target4.ts ===
|
||||
|
||||
class E { }
|
||||
>E : E
|
||||
|
||||
export default E;
|
||||
>E : E
|
||||
|
||||
20
tests/cases/compiler/es6modulekindWithES5Target.ts
Normal file
20
tests/cases/compiler/es6modulekindWithES5Target.ts
Normal file
@ -0,0 +1,20 @@
|
||||
// @target: es5
|
||||
// @module: es2015
|
||||
// @experimentalDecorators: true
|
||||
|
||||
export class C {
|
||||
static s = 0;
|
||||
p = 1;
|
||||
method() { }
|
||||
}
|
||||
|
||||
declare function foo(...args: any[]): any;
|
||||
@foo
|
||||
export class D {
|
||||
static s = 0;
|
||||
p = 1;
|
||||
method() { }
|
||||
}
|
||||
|
||||
class E { }
|
||||
export {E};
|
||||
8
tests/cases/compiler/es6modulekindWithES5Target2.ts
Normal file
8
tests/cases/compiler/es6modulekindWithES5Target2.ts
Normal file
@ -0,0 +1,8 @@
|
||||
// @target: es5
|
||||
// @module: es2015
|
||||
|
||||
export default class C {
|
||||
static s = 0;
|
||||
p = 1;
|
||||
method() { }
|
||||
}
|
||||
12
tests/cases/compiler/es6modulekindWithES5Target3.ts
Normal file
12
tests/cases/compiler/es6modulekindWithES5Target3.ts
Normal file
@ -0,0 +1,12 @@
|
||||
// @target: es5
|
||||
// @module: es2015
|
||||
// @experimentalDecorators: true
|
||||
|
||||
|
||||
declare function foo(...args: any[]): any;
|
||||
@foo
|
||||
export default class D {
|
||||
static s = 0;
|
||||
p = 1;
|
||||
method() { }
|
||||
}
|
||||
5
tests/cases/compiler/es6modulekindWithES5Target4.ts
Normal file
5
tests/cases/compiler/es6modulekindWithES5Target4.ts
Normal file
@ -0,0 +1,5 @@
|
||||
// @target: es5
|
||||
// @module: es2015
|
||||
|
||||
class E { }
|
||||
export default E;
|
||||
Loading…
x
Reference in New Issue
Block a user