Add test for the decorated method beginning with underscore

This commit is contained in:
Sheetal Nandi 2016-11-30 10:35:44 -08:00 committed by Mohamed Hegazy
parent 2cec8dbe84
commit 86f69f13fa
4 changed files with 143 additions and 0 deletions

View File

@ -0,0 +1,37 @@
//// [decoratorWithUnderscoreMethod.ts]
declare var console : { log(arg: string): void };
function dec(): Function {
return function (target: any, propKey: string, descr: PropertyDescriptor): void {
console.log(target[propKey]);
//logs undefined
//propKey has three underscores as prefix, but the method has only two underscores
};
}
class A {
@dec()
private __foo(bar: string): void {
// do something with bar
}
}
//// [decoratorWithUnderscoreMethod.js]
function dec() {
return function (target, propKey, descr) {
console.log(target[propKey]);
//logs undefined
//propKey has three underscores as prefix, but the method has only two underscores
};
}
var A = (function () {
function A() {
}
A.prototype.__foo = function (bar) {
// do something with bar
};
return A;
}());
__decorate([
dec()
], A.prototype, "___foo");

View File

@ -0,0 +1,42 @@
=== tests/cases/compiler/decoratorWithUnderscoreMethod.ts ===
declare var console : { log(arg: string): void };
>console : Symbol(console, Decl(decoratorWithUnderscoreMethod.ts, 1, 11))
>log : Symbol(log, Decl(decoratorWithUnderscoreMethod.ts, 1, 23))
>arg : Symbol(arg, Decl(decoratorWithUnderscoreMethod.ts, 1, 28))
function dec(): Function {
>dec : Symbol(dec, Decl(decoratorWithUnderscoreMethod.ts, 1, 49))
>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
return function (target: any, propKey: string, descr: PropertyDescriptor): void {
>target : Symbol(target, Decl(decoratorWithUnderscoreMethod.ts, 3, 21))
>propKey : Symbol(propKey, Decl(decoratorWithUnderscoreMethod.ts, 3, 33))
>descr : Symbol(descr, Decl(decoratorWithUnderscoreMethod.ts, 3, 50))
>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(lib.d.ts, --, --))
console.log(target[propKey]);
>console.log : Symbol(log, Decl(decoratorWithUnderscoreMethod.ts, 1, 23))
>console : Symbol(console, Decl(decoratorWithUnderscoreMethod.ts, 1, 11))
>log : Symbol(log, Decl(decoratorWithUnderscoreMethod.ts, 1, 23))
>target : Symbol(target, Decl(decoratorWithUnderscoreMethod.ts, 3, 21))
>propKey : Symbol(propKey, Decl(decoratorWithUnderscoreMethod.ts, 3, 33))
//logs undefined
//propKey has three underscores as prefix, but the method has only two underscores
};
}
class A {
>A : Symbol(A, Decl(decoratorWithUnderscoreMethod.ts, 8, 1))
@dec()
>dec : Symbol(dec, Decl(decoratorWithUnderscoreMethod.ts, 1, 49))
private __foo(bar: string): void {
>__foo : Symbol(A.__foo, Decl(decoratorWithUnderscoreMethod.ts, 10, 9))
>bar : Symbol(bar, Decl(decoratorWithUnderscoreMethod.ts, 12, 18))
// do something with bar
}
}

View File

@ -0,0 +1,46 @@
=== tests/cases/compiler/decoratorWithUnderscoreMethod.ts ===
declare var console : { log(arg: string): void };
>console : { log(arg: string): void; }
>log : (arg: string) => void
>arg : string
function dec(): Function {
>dec : () => Function
>Function : Function
return function (target: any, propKey: string, descr: PropertyDescriptor): void {
>function (target: any, propKey: string, descr: PropertyDescriptor): void { console.log(target[propKey]); //logs undefined //propKey has three underscores as prefix, but the method has only two underscores } : (target: any, propKey: string, descr: PropertyDescriptor) => void
>target : any
>propKey : string
>descr : PropertyDescriptor
>PropertyDescriptor : PropertyDescriptor
console.log(target[propKey]);
>console.log(target[propKey]) : void
>console.log : (arg: string) => void
>console : { log(arg: string): void; }
>log : (arg: string) => void
>target[propKey] : any
>target : any
>propKey : string
//logs undefined
//propKey has three underscores as prefix, but the method has only two underscores
};
}
class A {
>A : A
@dec()
>dec() : Function
>dec : () => Function
private __foo(bar: string): void {
>__foo : (bar: string) => void
>bar : string
// do something with bar
}
}

View File

@ -0,0 +1,18 @@
// @noemithelpers: true
// @experimentaldecorators: true
declare var console : { log(arg: string): void };
function dec(): Function {
return function (target: any, propKey: string, descr: PropertyDescriptor): void {
console.log(target[propKey]);
//logs undefined
//propKey has three underscores as prefix, but the method has only two underscores
};
}
class A {
@dec()
private __foo(bar: string): void {
// do something with bar
}
}