From c2dc1fa32ed56f036f881ea9d9a9a2191792c004 Mon Sep 17 00:00:00 2001 From: tkqubo Date: Tue, 15 Sep 2015 05:03:14 +0900 Subject: [PATCH 1/4] Add core-decorators@0.1.5 --- core-decorators/core-decorators-tests.ts | 169 +++++++++++++++++++++++ core-decorators/core-decorators.d.ts | 89 ++++++++++++ 2 files changed, 258 insertions(+) create mode 100644 core-decorators/core-decorators-tests.ts create mode 100644 core-decorators/core-decorators.d.ts diff --git a/core-decorators/core-decorators-tests.ts b/core-decorators/core-decorators-tests.ts new file mode 100644 index 000000000..e4a31432b --- /dev/null +++ b/core-decorators/core-decorators-tests.ts @@ -0,0 +1,169 @@ +/// + +// +// @autobind +// + +import { autobind } from 'core-decorators'; + +class Person { + @autobind + getPerson() { + return this; + } +} + +let person = new Person(); +let getPerson = person.getPerson; + +getPerson() === person; + +// +// @readonly +// + +import { readonly } from 'core-decorators'; + +class Meal { + @readonly + entree: string = 'steak'; +} + +var dinner = new Meal(); +dinner.entree = 'salmon'; + +// +// @override +// + +import { override } from 'core-decorators'; + +class Parent { + speak(first: string, second: string) {} +} + +class Child extends Parent { + @override + speak() {} + // SyntaxError: Child#speak() does not properly override Parent#speak(first, second) +} + +// or + +class Child2 extends Parent { + @override + speaks() {} + // SyntaxError: No descriptor matching Child#speaks() was found on the prototype chain. + // + // Did you mean "speak"? +} + +// +// @deprecate (alias: @deprecated) +// + +import { deprecate, deprecated } from 'core-decorators'; + +class Person2 { + @deprecate + facepalm() {} + + @deprecate('We stopped facepalming') + facepalmHard() {} + + @deprecate('We stopped facepalming', { url: 'http://knowyourmeme.com/memes/facepalm' }) + facepalmHarder() {} +} + +let person2 = new Person2(); + +person2.facepalm(); +// DEPRECATION Person#facepalm: This function will be removed in future versions. + +person2.facepalmHard(); +// DEPRECATION Person#facepalmHard: We stopped facepalming + +person2.facepalmHarder(); +// DEPRECATION Person#facepalmHarder: We stopped facepalming +// +// See http://knowyourmeme.com/memes/facepalm for more details. +// + +// +// @debounce +// + +import { debounce } from 'core-decorators'; + +class Editor { + + content = ''; + + @debounce(500) + updateContent(content: string) { + this.content = content; + } +} + +// +// @suppressWarnings +// + +import { suppressWarnings } from 'core-decorators'; + +class Person3 { + @deprecated + facepalm() {} + + @suppressWarnings + facepalmWithoutWarning() { + this.facepalm(); + } +} + +let person3 = new Person3(); + +person3.facepalmWithoutWarning(); +// no warning is logged + +// +// @nonenumerable +// + +import { nonenumerable } from 'core-decorators'; + +class Meal2 { + entree = 'steak'; + + @nonenumerable + cost: number = 4.44; +} + +var dinner2 = new Meal2(); +for (var key in dinner2) { + key; + // "entree" only, not "cost" +} + +Object.keys(dinner2); +// ["entree"] + +// +// @nonconfigurable +// + +import { nonconfigurable } from 'core-decorators'; + +class Meal3 { + @nonconfigurable + entree: string = 'steak'; +} + +var dinner3 = new Meal3(); + +Object.defineProperty(dinner3, 'entree', { + enumerable: false +}); +// Cannot redefine property: entree + + diff --git a/core-decorators/core-decorators.d.ts b/core-decorators/core-decorators.d.ts new file mode 100644 index 000000000..20ca4cfe8 --- /dev/null +++ b/core-decorators/core-decorators.d.ts @@ -0,0 +1,89 @@ +// Type definitions for core-decorators.js +// Project: https://github.com/jayphelps/core-decorators.js +// Definitions by: Qubo +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "core-decorators" { + export interface ClassDecorator { + (target: TFunction): TFunction|void; + } + + export interface ParameterDecorator { + (target: Object, propertyKey: string|symbol, parameterIndex: number): void; + } + + export interface PropertyDecorator { + (target: Object, propertyKey: string|symbol): void; + } + + export interface MethodDecorator { + (target: Object, propertyKey: string|symbol, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor|void; + } + + export interface PropertyOrMethodDecorator extends MethodDecorator, PropertyDecorator { + (target: Object, propertyKey: string|symbol): void; + } + + export interface Deprecate extends MethodDecorator { + (message?: string, option?: DeprecateOption): MethodDecorator; + } + + export interface DeprecateOption { + url: string; + } + + /** + * Forces invocations of this function to always have this refer to the class instance, + * even if the function is passed around or would otherwise lose its this context. e.g. var fn = context.method; + */ + var autobind: MethodDecorator; + /** + * Marks a property or method as not being writable. + */ + var readonly: PropertyOrMethodDecorator; + /** + * Checks that the marked method indeed overrides a function with the same signature somewhere on the prototype chain. + */ + var override: MethodDecorator; + /** + * Calls console.warn() with a deprecation message. Provide a custom message to override the default one. You can also provide an options hash with a url, for further reading. + */ + var deprecate: Deprecate; + /** + * Calls console.warn() with a deprecation message. Provide a custom message to override the default one. You can also provide an options hash with a url, for further reading. + */ + var deprecated: Deprecate; + /** + * Creates a new debounced function which will be invoked after wait milliseconds since the time it was invoked. Default timeout is 300 ms. + */ + var debounce: (wait: number) => MethodDecorator; + /** + * Suppresses any JavaScript console.warn() call while the decorated function is called. (i.e. on the stack) + */ + var suppressWarnings: MethodDecorator; + /** + * Marks a property or method as not being enumerable. + */ + var nonenumerable: PropertyOrMethodDecorator; + /** + * Marks a property or method as not being writable. + */ + var nonconfigurable: PropertyOrMethodDecorator; + /** + * Initial implementation included, likely slow. WIP. + */ + var memoize: MethodDecorator; + + export { + autobind, + readonly, + override, + deprecate, + deprecated, + debounce, + suppressWarnings, + nonenumerable, + nonconfigurable, + memoize // WIP + }; +} From 097a226abdbdc8049377dcbbee5457b5c5284097 Mon Sep 17 00:00:00 2001 From: tkqubo Date: Tue, 15 Sep 2015 05:05:25 +0900 Subject: [PATCH 2/4] Add version to d.ts comment --- core-decorators/core-decorators.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-decorators/core-decorators.d.ts b/core-decorators/core-decorators.d.ts index 20ca4cfe8..160802fc1 100644 --- a/core-decorators/core-decorators.d.ts +++ b/core-decorators/core-decorators.d.ts @@ -1,4 +1,4 @@ -// Type definitions for core-decorators.js +// Type definitions for core-decorators.js v0.1.5 // Project: https://github.com/jayphelps/core-decorators.js // Definitions by: Qubo // Definitions: https://github.com/borisyankov/DefinitelyTyped From 62a031c2b200b809eb8e442bc20cb1571bb70b31 Mon Sep 17 00:00:00 2001 From: tkqubo Date: Tue, 15 Sep 2015 05:20:11 +0900 Subject: [PATCH 3/4] Comment out all the test code --- core-decorators/core-decorators-tests.ts | 302 +++++++++++------------ 1 file changed, 151 insertions(+), 151 deletions(-) diff --git a/core-decorators/core-decorators-tests.ts b/core-decorators/core-decorators-tests.ts index e4a31432b..7ec80d2f3 100644 --- a/core-decorators/core-decorators-tests.ts +++ b/core-decorators/core-decorators-tests.ts @@ -1,169 +1,169 @@ -/// - +///// // -// @autobind +//// +//// @autobind +//// // - -import { autobind } from 'core-decorators'; - -class Person { - @autobind - getPerson() { - return this; - } -} - -let person = new Person(); -let getPerson = person.getPerson; - -getPerson() === person; - +//import { autobind } from 'core-decorators'; // -// @readonly +//class Person { +// @autobind +// getPerson() { +// return this; +// } +//} // - -import { readonly } from 'core-decorators'; - -class Meal { - @readonly - entree: string = 'steak'; -} - -var dinner = new Meal(); -dinner.entree = 'salmon'; - +//let person = new Person(); +//let getPerson = person.getPerson; // -// @override +//getPerson() === person; // - -import { override } from 'core-decorators'; - -class Parent { - speak(first: string, second: string) {} -} - -class Child extends Parent { - @override - speak() {} - // SyntaxError: Child#speak() does not properly override Parent#speak(first, second) -} - -// or - -class Child2 extends Parent { - @override - speaks() {} - // SyntaxError: No descriptor matching Child#speaks() was found on the prototype chain. - // - // Did you mean "speak"? -} - +//// +//// @readonly +//// // -// @deprecate (alias: @deprecated) +//import { readonly } from 'core-decorators'; // - -import { deprecate, deprecated } from 'core-decorators'; - -class Person2 { - @deprecate - facepalm() {} - - @deprecate('We stopped facepalming') - facepalmHard() {} - - @deprecate('We stopped facepalming', { url: 'http://knowyourmeme.com/memes/facepalm' }) - facepalmHarder() {} -} - -let person2 = new Person2(); - -person2.facepalm(); -// DEPRECATION Person#facepalm: This function will be removed in future versions. - -person2.facepalmHard(); -// DEPRECATION Person#facepalmHard: We stopped facepalming - -person2.facepalmHarder(); -// DEPRECATION Person#facepalmHarder: We stopped facepalming +//class Meal { +// @readonly +// entree: string = 'steak'; +//} // -// See http://knowyourmeme.com/memes/facepalm for more details. +//var dinner = new Meal(); +//dinner.entree = 'salmon'; // - +//// +//// @override +//// // -// @debounce +//import { override } from 'core-decorators'; // - -import { debounce } from 'core-decorators'; - -class Editor { - - content = ''; - - @debounce(500) - updateContent(content: string) { - this.content = content; - } -} - +//class Parent { +// speak(first: string, second: string) {} +//} // -// @suppressWarnings +//class Child extends Parent { +// @override +// speak() {} +// // SyntaxError: Child#speak() does not properly override Parent#speak(first, second) +//} // - -import { suppressWarnings } from 'core-decorators'; - -class Person3 { - @deprecated - facepalm() {} - - @suppressWarnings - facepalmWithoutWarning() { - this.facepalm(); - } -} - -let person3 = new Person3(); - -person3.facepalmWithoutWarning(); -// no warning is logged - +//// or // -// @nonenumerable +//class Child2 extends Parent { +// @override +// speaks() {} +// // SyntaxError: No descriptor matching Child#speaks() was found on the prototype chain. +// // +// // Did you mean "speak"? +//} // - -import { nonenumerable } from 'core-decorators'; - -class Meal2 { - entree = 'steak'; - - @nonenumerable - cost: number = 4.44; -} - -var dinner2 = new Meal2(); -for (var key in dinner2) { - key; - // "entree" only, not "cost" -} - -Object.keys(dinner2); -// ["entree"] - +//// +//// @deprecate (alias: @deprecated) +//// +// +//import { deprecate, deprecated } from 'core-decorators'; +// +//class Person2 { +// @deprecate +// facepalm() {} +// +// @deprecate('We stopped facepalming') +// facepalmHard() {} +// +// @deprecate('We stopped facepalming', { url: 'http://knowyourmeme.com/memes/facepalm' }) +// facepalmHarder() {} +//} +// +//let person2 = new Person2(); +// +//person2.facepalm(); +//// DEPRECATION Person#facepalm: This function will be removed in future versions. +// +//person2.facepalmHard(); +//// DEPRECATION Person#facepalmHard: We stopped facepalming +// +//person2.facepalmHarder(); +//// DEPRECATION Person#facepalmHarder: We stopped facepalming +//// +//// See http://knowyourmeme.com/memes/facepalm for more details. +//// +// +//// +//// @debounce +//// +// +//import { debounce } from 'core-decorators'; +// +//class Editor { +// +// content = ''; +// +// @debounce(500) +// updateContent(content: string) { +// this.content = content; +// } +//} +// +//// +//// @suppressWarnings +//// +// +//import { suppressWarnings } from 'core-decorators'; +// +//class Person3 { +// @deprecated +// facepalm() {} +// +// @suppressWarnings +// facepalmWithoutWarning() { +// this.facepalm(); +// } +//} +// +//let person3 = new Person3(); +// +//person3.facepalmWithoutWarning(); +//// no warning is logged +// +//// +//// @nonenumerable +//// +// +//import { nonenumerable } from 'core-decorators'; +// +//class Meal2 { +// entree = 'steak'; +// +// @nonenumerable +// cost: number = 4.44; +//} +// +//var dinner2 = new Meal2(); +//for (var key in dinner2) { +// key; +// // "entree" only, not "cost" +//} +// +//Object.keys(dinner2); +//// ["entree"] +// +//// +//// @nonconfigurable +//// +// +//import { nonconfigurable } from 'core-decorators'; +// +//class Meal3 { +// @nonconfigurable +// entree: string = 'steak'; +//} +// +//var dinner3 = new Meal3(); +// +//Object.defineProperty(dinner3, 'entree', { +// enumerable: false +//}); +//// Cannot redefine property: entree // -// @nonconfigurable // - -import { nonconfigurable } from 'core-decorators'; - -class Meal3 { - @nonconfigurable - entree: string = 'steak'; -} - -var dinner3 = new Meal3(); - -Object.defineProperty(dinner3, 'entree', { - enumerable: false -}); -// Cannot redefine property: entree - - From 4dcbaa948eb967877f210b49c5b6996465ab63e2 Mon Sep 17 00:00:00 2001 From: tkqubo Date: Tue, 15 Sep 2015 05:23:17 +0900 Subject: [PATCH 4/4] Add tscparams file and uncomment all the test codes --- core-decorators/core-decorators-tests.ts | 302 +++++++++--------- .../core-decorators-tests.ts.tscparams | 1 + 2 files changed, 152 insertions(+), 151 deletions(-) create mode 100644 core-decorators/core-decorators-tests.ts.tscparams diff --git a/core-decorators/core-decorators-tests.ts b/core-decorators/core-decorators-tests.ts index 7ec80d2f3..e4a31432b 100644 --- a/core-decorators/core-decorators-tests.ts +++ b/core-decorators/core-decorators-tests.ts @@ -1,169 +1,169 @@ -///// +/// + // -//// -//// @autobind -//// +// @autobind // -//import { autobind } from 'core-decorators'; + +import { autobind } from 'core-decorators'; + +class Person { + @autobind + getPerson() { + return this; + } +} + +let person = new Person(); +let getPerson = person.getPerson; + +getPerson() === person; + // -//class Person { -// @autobind -// getPerson() { -// return this; -// } -//} +// @readonly // -//let person = new Person(); -//let getPerson = person.getPerson; + +import { readonly } from 'core-decorators'; + +class Meal { + @readonly + entree: string = 'steak'; +} + +var dinner = new Meal(); +dinner.entree = 'salmon'; + // -//getPerson() === person; +// @override // -//// -//// @readonly -//// + +import { override } from 'core-decorators'; + +class Parent { + speak(first: string, second: string) {} +} + +class Child extends Parent { + @override + speak() {} + // SyntaxError: Child#speak() does not properly override Parent#speak(first, second) +} + +// or + +class Child2 extends Parent { + @override + speaks() {} + // SyntaxError: No descriptor matching Child#speaks() was found on the prototype chain. + // + // Did you mean "speak"? +} + // -//import { readonly } from 'core-decorators'; +// @deprecate (alias: @deprecated) // -//class Meal { -// @readonly -// entree: string = 'steak'; -//} + +import { deprecate, deprecated } from 'core-decorators'; + +class Person2 { + @deprecate + facepalm() {} + + @deprecate('We stopped facepalming') + facepalmHard() {} + + @deprecate('We stopped facepalming', { url: 'http://knowyourmeme.com/memes/facepalm' }) + facepalmHarder() {} +} + +let person2 = new Person2(); + +person2.facepalm(); +// DEPRECATION Person#facepalm: This function will be removed in future versions. + +person2.facepalmHard(); +// DEPRECATION Person#facepalmHard: We stopped facepalming + +person2.facepalmHarder(); +// DEPRECATION Person#facepalmHarder: We stopped facepalming // -//var dinner = new Meal(); -//dinner.entree = 'salmon'; +// See http://knowyourmeme.com/memes/facepalm for more details. // -//// -//// @override -//// + // -//import { override } from 'core-decorators'; +// @debounce // -//class Parent { -// speak(first: string, second: string) {} -//} + +import { debounce } from 'core-decorators'; + +class Editor { + + content = ''; + + @debounce(500) + updateContent(content: string) { + this.content = content; + } +} + // -//class Child extends Parent { -// @override -// speak() {} -// // SyntaxError: Child#speak() does not properly override Parent#speak(first, second) -//} +// @suppressWarnings // -//// or + +import { suppressWarnings } from 'core-decorators'; + +class Person3 { + @deprecated + facepalm() {} + + @suppressWarnings + facepalmWithoutWarning() { + this.facepalm(); + } +} + +let person3 = new Person3(); + +person3.facepalmWithoutWarning(); +// no warning is logged + // -//class Child2 extends Parent { -// @override -// speaks() {} -// // SyntaxError: No descriptor matching Child#speaks() was found on the prototype chain. -// // -// // Did you mean "speak"? -//} +// @nonenumerable // -//// -//// @deprecate (alias: @deprecated) -//// -// -//import { deprecate, deprecated } from 'core-decorators'; -// -//class Person2 { -// @deprecate -// facepalm() {} -// -// @deprecate('We stopped facepalming') -// facepalmHard() {} -// -// @deprecate('We stopped facepalming', { url: 'http://knowyourmeme.com/memes/facepalm' }) -// facepalmHarder() {} -//} -// -//let person2 = new Person2(); -// -//person2.facepalm(); -//// DEPRECATION Person#facepalm: This function will be removed in future versions. -// -//person2.facepalmHard(); -//// DEPRECATION Person#facepalmHard: We stopped facepalming -// -//person2.facepalmHarder(); -//// DEPRECATION Person#facepalmHarder: We stopped facepalming -//// -//// See http://knowyourmeme.com/memes/facepalm for more details. -//// -// -//// -//// @debounce -//// -// -//import { debounce } from 'core-decorators'; -// -//class Editor { -// -// content = ''; -// -// @debounce(500) -// updateContent(content: string) { -// this.content = content; -// } -//} -// -//// -//// @suppressWarnings -//// -// -//import { suppressWarnings } from 'core-decorators'; -// -//class Person3 { -// @deprecated -// facepalm() {} -// -// @suppressWarnings -// facepalmWithoutWarning() { -// this.facepalm(); -// } -//} -// -//let person3 = new Person3(); -// -//person3.facepalmWithoutWarning(); -//// no warning is logged -// -//// -//// @nonenumerable -//// -// -//import { nonenumerable } from 'core-decorators'; -// -//class Meal2 { -// entree = 'steak'; -// -// @nonenumerable -// cost: number = 4.44; -//} -// -//var dinner2 = new Meal2(); -//for (var key in dinner2) { -// key; -// // "entree" only, not "cost" -//} -// -//Object.keys(dinner2); -//// ["entree"] -// -//// -//// @nonconfigurable -//// -// -//import { nonconfigurable } from 'core-decorators'; -// -//class Meal3 { -// @nonconfigurable -// entree: string = 'steak'; -//} -// -//var dinner3 = new Meal3(); -// -//Object.defineProperty(dinner3, 'entree', { -// enumerable: false -//}); -//// Cannot redefine property: entree + +import { nonenumerable } from 'core-decorators'; + +class Meal2 { + entree = 'steak'; + + @nonenumerable + cost: number = 4.44; +} + +var dinner2 = new Meal2(); +for (var key in dinner2) { + key; + // "entree" only, not "cost" +} + +Object.keys(dinner2); +// ["entree"] + // +// @nonconfigurable // + +import { nonconfigurable } from 'core-decorators'; + +class Meal3 { + @nonconfigurable + entree: string = 'steak'; +} + +var dinner3 = new Meal3(); + +Object.defineProperty(dinner3, 'entree', { + enumerable: false +}); +// Cannot redefine property: entree + + diff --git a/core-decorators/core-decorators-tests.ts.tscparams b/core-decorators/core-decorators-tests.ts.tscparams new file mode 100644 index 000000000..3f0863ac6 --- /dev/null +++ b/core-decorators/core-decorators-tests.ts.tscparams @@ -0,0 +1 @@ +--experimentalDecorators --noImplicitAny --target ES5