mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
check functions in class expressions
This commit is contained in:
parent
1b5dc0d7d1
commit
a0683276d1
@ -13897,6 +13897,7 @@ namespace ts {
|
||||
break;
|
||||
case SyntaxKind.ClassExpression:
|
||||
forEach((<ClassExpression>node).members, checkSourceElement);
|
||||
forEachChild(node, checkFunctionAndClassExpressionBodies);
|
||||
break;
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.MethodSignature:
|
||||
|
||||
25
tests/baselines/reference/functionsInClassExpressions.js
Normal file
25
tests/baselines/reference/functionsInClassExpressions.js
Normal file
@ -0,0 +1,25 @@
|
||||
//// [functionsInClassExpressions.ts]
|
||||
let Foo = class {
|
||||
constructor() {
|
||||
this.bar++;
|
||||
}
|
||||
bar = 0;
|
||||
inc = () => {
|
||||
this.bar++;
|
||||
}
|
||||
m() { return this.bar; }
|
||||
}
|
||||
|
||||
//// [functionsInClassExpressions.js]
|
||||
var Foo = (function () {
|
||||
function class_1() {
|
||||
var _this = this;
|
||||
this.bar = 0;
|
||||
this.inc = function () {
|
||||
_this.bar++;
|
||||
};
|
||||
this.bar++;
|
||||
}
|
||||
class_1.prototype.m = function () { return this.bar; };
|
||||
return class_1;
|
||||
})();
|
||||
@ -0,0 +1,27 @@
|
||||
=== tests/cases/compiler/functionsInClassExpressions.ts ===
|
||||
let Foo = class {
|
||||
>Foo : Symbol(Foo, Decl(functionsInClassExpressions.ts, 0, 3))
|
||||
|
||||
constructor() {
|
||||
this.bar++;
|
||||
>this.bar : Symbol((Anonymous class).bar, Decl(functionsInClassExpressions.ts, 3, 5))
|
||||
>this : Symbol((Anonymous class), Decl(functionsInClassExpressions.ts, 0, 9))
|
||||
>bar : Symbol((Anonymous class).bar, Decl(functionsInClassExpressions.ts, 3, 5))
|
||||
}
|
||||
bar = 0;
|
||||
>bar : Symbol((Anonymous class).bar, Decl(functionsInClassExpressions.ts, 3, 5))
|
||||
|
||||
inc = () => {
|
||||
>inc : Symbol((Anonymous class).inc, Decl(functionsInClassExpressions.ts, 4, 12))
|
||||
|
||||
this.bar++;
|
||||
>this.bar : Symbol((Anonymous class).bar, Decl(functionsInClassExpressions.ts, 3, 5))
|
||||
>this : Symbol((Anonymous class), Decl(functionsInClassExpressions.ts, 0, 9))
|
||||
>bar : Symbol((Anonymous class).bar, Decl(functionsInClassExpressions.ts, 3, 5))
|
||||
}
|
||||
m() { return this.bar; }
|
||||
>m : Symbol((Anonymous class).m, Decl(functionsInClassExpressions.ts, 7, 5))
|
||||
>this.bar : Symbol((Anonymous class).bar, Decl(functionsInClassExpressions.ts, 3, 5))
|
||||
>this : Symbol((Anonymous class), Decl(functionsInClassExpressions.ts, 0, 9))
|
||||
>bar : Symbol((Anonymous class).bar, Decl(functionsInClassExpressions.ts, 3, 5))
|
||||
}
|
||||
32
tests/baselines/reference/functionsInClassExpressions.types
Normal file
32
tests/baselines/reference/functionsInClassExpressions.types
Normal file
@ -0,0 +1,32 @@
|
||||
=== tests/cases/compiler/functionsInClassExpressions.ts ===
|
||||
let Foo = class {
|
||||
>Foo : typeof (Anonymous class)
|
||||
>class { constructor() { this.bar++; } bar = 0; inc = () => { this.bar++; } m() { return this.bar; }} : typeof (Anonymous class)
|
||||
|
||||
constructor() {
|
||||
this.bar++;
|
||||
>this.bar++ : number
|
||||
>this.bar : number
|
||||
>this : this
|
||||
>bar : number
|
||||
}
|
||||
bar = 0;
|
||||
>bar : number
|
||||
>0 : number
|
||||
|
||||
inc = () => {
|
||||
>inc : () => void
|
||||
>() => { this.bar++; } : () => void
|
||||
|
||||
this.bar++;
|
||||
>this.bar++ : number
|
||||
>this.bar : number
|
||||
>this : this
|
||||
>bar : number
|
||||
}
|
||||
m() { return this.bar; }
|
||||
>m : () => number
|
||||
>this.bar : number
|
||||
>this : this
|
||||
>bar : number
|
||||
}
|
||||
10
tests/cases/compiler/functionsInClassExpressions.ts
Normal file
10
tests/cases/compiler/functionsInClassExpressions.ts
Normal file
@ -0,0 +1,10 @@
|
||||
let Foo = class {
|
||||
constructor() {
|
||||
this.bar++;
|
||||
}
|
||||
bar = 0;
|
||||
inc = () => {
|
||||
this.bar++;
|
||||
}
|
||||
m() { return this.bar; }
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user