From 9af02b0b2661452be4f17b546ea4e5ea1bb04fab Mon Sep 17 00:00:00 2001 From: Bryan Smith Date: Fri, 7 Aug 2015 13:35:36 -0700 Subject: [PATCH] refactor(all): fix lint errors --- src/decorator-applicator.js | 26 +++++++-------- src/decorators.js | 24 +++++++------- src/metadata.js | 66 ++++++++++++++++++------------------- src/origin.js | 24 +++++++------- 4 files changed, 69 insertions(+), 71 deletions(-) diff --git a/src/decorator-applicator.js b/src/decorator-applicator.js index 8a729d1..4f9690e 100644 --- a/src/decorator-applicator.js +++ b/src/decorator-applicator.js @@ -1,5 +1,5 @@ export class DecoratorApplicator { - constructor(){ + constructor() { this._first = null; this._second = null; this._third = null; @@ -7,22 +7,22 @@ export class DecoratorApplicator { } decorator(decorator : Function) : DecoratorApplicator { - if(this._first === null){ + if (this._first === null) { this._first = decorator; return this; } - if(this._second === null){ + if (this._second === null) { this._second = decorator; return this; } - if(this._third === null){ + if (this._third === null) { this._third = decorator; return this; } - if(this._rest === null){ + if (this._rest === null) { this._rest = []; } @@ -31,24 +31,22 @@ export class DecoratorApplicator { return this; } - _decorate(target : Function) : void { - var i, ii, rest; - - if(this._first !== null){ + _decorate(target: Function): void { + if (this._first !== null) { this._first(target); } - if(this._second !== null){ + if (this._second !== null) { this._second(target); } - if(this._third !== null){ + if (this._third !== null) { this._third(target); } - rest = this._rest; - if(rest !== null){ - for(i = 0, ii = rest.length; i < ii; ++i){ + let rest = this._rest; + if (rest !== null) { + for (let i = 0, ii = rest.length; i < ii; ++i) { rest[i](target); } } diff --git a/src/decorators.js b/src/decorators.js index c88b61d..ad1056a 100644 --- a/src/decorators.js +++ b/src/decorators.js @@ -5,30 +5,30 @@ interface DecoratorsConfigType { } interface DecoratorsType { - configure : DecoratorsConfigType; + configure: DecoratorsConfigType; } -export let Decorators : DecoratorsType = { +export const Decorators: DecoratorsType = { configure: { - parameterizedDecorator(name : string, decorator : Function) : void { - Decorators[name] = function(){ - var applicator = new DecoratorApplicator(); + parameterizedDecorator(name: string, decorator: Function): void { + Decorators[name] = function() { + let applicator = new DecoratorApplicator(); return applicator[name].apply(applicator, arguments); }; - DecoratorApplicator.prototype[name] = function(){ - var result = decorator.apply(null, arguments); + DecoratorApplicator.prototype[name] = function() { + let result = decorator.apply(null, arguments); return this.decorator(result); }; }, - simpleDecorator(name : string, decorator : Function) : void { - Decorators[name] = function(){ + simpleDecorator(name: string, decorator: Function): void { + Decorators[name] = function() { return new DecoratorApplicator().decorator(decorator); }; - DecoratorApplicator.prototype[name] = function(){ + DecoratorApplicator.prototype[name] = function() { return this.decorator(decorator); - } + }; } } -} +}; diff --git a/src/metadata.js b/src/metadata.js index 4a8483b..30dfe00 100644 --- a/src/metadata.js +++ b/src/metadata.js @@ -16,53 +16,53 @@ const theGlobal = (function() { const emptyMetadata = Object.freeze({}); const metadataContainerKey = '__metadata__'; -if(typeof theGlobal.System === 'undefined'){ - theGlobal.System = { isFake:true }; +if (typeof theGlobal.System === 'undefined') { + theGlobal.System = {isFake: true}; } -if(typeof theGlobal.System.forEachModule === 'undefined'){ - theGlobal.System.forEachModule = function(){}; +if (typeof theGlobal.System.forEachModule === 'undefined') { + theGlobal.System.forEachModule = function() {}; } -if(typeof theGlobal.Reflect === 'undefined'){ +if (typeof theGlobal.Reflect === 'undefined') { theGlobal.Reflect = {}; } -if(typeof theGlobal.Reflect.getOwnMetadata === 'undefined'){ - Reflect.getOwnMetadata = function(metadataKey, target, targetKey){ +if (typeof theGlobal.Reflect.getOwnMetadata === 'undefined') { + Reflect.getOwnMetadata = function(metadataKey, target, targetKey) { return ((target[metadataContainerKey] || emptyMetadata)[targetKey] || emptyMetadata)[metadataKey]; }; } -if(typeof theGlobal.Reflect.defineMetadata === 'undefined'){ - Reflect.defineMetadata = function(metadataKey, metadataValue, target, targetKey){ - var metadataContainer = target.hasOwnProperty(metadataContainerKey) ? target[metadataContainerKey] : (target[metadataContainerKey] = {}); - var targetContainer = metadataContainer[targetKey] || (metadataContainer[targetKey] = {}); +if (typeof theGlobal.Reflect.defineMetadata === 'undefined') { + Reflect.defineMetadata = function(metadataKey, metadataValue, target, targetKey) { + let metadataContainer = target.hasOwnProperty(metadataContainerKey) ? target[metadataContainerKey] : (target[metadataContainerKey] = {}); + let targetContainer = metadataContainer[targetKey] || (metadataContainer[targetKey] = {}); targetContainer[metadataKey] = metadataValue; }; } -if(typeof theGlobal.Reflect.metadata === 'undefined'){ - Reflect.metadata = function(metadataKey, metadataValue){ - return function(target, targetKey){ +if (typeof theGlobal.Reflect.metadata === 'undefined') { + Reflect.metadata = function(metadataKey, metadataValue) { + return function(target, targetKey) { Reflect.defineMetadata(metadataKey, metadataValue, target, targetKey); }; }; } -function ensureDecorators(target){ - var applicator; +function ensureDecorators(target) { + let applicator; - if(typeof target.decorators === 'function'){ + if (typeof target.decorators === 'function') { applicator = target.decorators(); - }else{ + } else { applicator = target.decorators; } - if(typeof applicator._decorate === 'function'){ + if (typeof applicator._decorate === 'function') { delete target.decorators; applicator._decorate(target); - }else{ + } else { throw new Error('The return value of your decorator\'s method was not valid.'); } } @@ -80,41 +80,41 @@ interface MetadataType { * @class Metadata * @static */ -export var Metadata : MetadataType = { +export const Metadata: MetadataType = { global: theGlobal, - resource:'aurelia:resource', - paramTypes:'design:paramtypes', - properties:'design:properties', - get(metadataKey : string, target : Function, targetKey : string) : Object { - if(!target){ + resource: 'aurelia:resource', + paramTypes: 'design:paramtypes', + properties: 'design:properties', + get(metadataKey: string, target: Function, targetKey: string): Object { + if (!target) { return undefined; } let result = Metadata.getOwn(metadataKey, target, targetKey); return result === undefined ? Metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result; }, - getOwn(metadataKey : string, target : Function, targetKey : string) : Object { - if(!target){ + getOwn(metadataKey: string, target: Function, targetKey: string): Object { + if (!target) { return undefined; } - if(target.hasOwnProperty('decorators')){ + if (target.hasOwnProperty('decorators')) { ensureDecorators(target); } return Reflect.getOwnMetadata(metadataKey, target, targetKey); }, - define(metadataKey : string, metadataValue : Object, target : Function, targetKey : string) : void { + define(metadataKey: string, metadataValue: Object, target: Function, targetKey: string): void { Reflect.defineMetadata(metadataKey, metadataValue, target, targetKey); }, - getOrCreateOwn(metadataKey : string, Type : Function, target : Function, targetKey : string) : Object { + getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey: string): Object { let result = Metadata.getOwn(metadataKey, target, targetKey); - if(result === undefined){ + if (result === undefined) { result = new Type(); Reflect.defineMetadata(metadataKey, result, target, targetKey); } return result; } -} +}; diff --git a/src/origin.js b/src/origin.js index 206114a..34dc6bc 100644 --- a/src/origin.js +++ b/src/origin.js @@ -1,7 +1,7 @@ -import * as core from 'core-js'; +import 'core-js'; -let originStorage = new Map(), - unknownOrigin = Object.freeze({moduleId:undefined,moduleMember:undefined}); +let originStorage = new Map(); +let unknownOrigin = Object.freeze({moduleId: undefined, moduleMember: undefined}); /** * A metadata annotation that describes the origin module of the function to which it's attached. @@ -12,7 +12,7 @@ let originStorage = new Map(), * @param {string} moduleMember The name of the export in the origin module. */ export class Origin { - constructor(moduleId : string, moduleMember : string){ + constructor(moduleId: string, moduleMember: string) { this.moduleId = moduleId; this.moduleMember = moduleMember; } @@ -25,20 +25,20 @@ export class Origin { * @param {Function} fn The function to inspect for Origin metadata. * @return {Origin} Returns the Origin metadata. */ - static get(fn : Function) : Origin { - var origin = originStorage.get(fn); + static get(fn: Function): Origin { + let origin = originStorage.get(fn); - if(origin === undefined){ + if (origin === undefined) { System.forEachModule((key, value) => { - for(var name in value){ - var exp = value[name]; - if(exp === fn){ + for (let name in value) { + let exp = value[name]; + if (exp === fn) { originStorage.set(fn, origin = new Origin(key, name)); return true; } } - if(value === fn){ + if (value === fn) { originStorage.set(fn, origin = new Origin(key, 'default')); return true; } @@ -57,7 +57,7 @@ export class Origin { * @param {origin} fn The Origin metadata to store on the function. * @return {Origin} Returns the Origin metadata. */ - static set(fn : Function, origin : Origin) : void { + static set(fn: Function, origin: Origin): void { originStorage.set(fn, origin); } }