Skip to content

Commit

Permalink
Updated some dependencies (#461)
Browse files Browse the repository at this point in the history
* Updated some dependencies

* fixed property decorator issue

* Explicit gulp test

* Implements 457

* Rollback harmonize
  • Loading branch information
remojansen authored Dec 28, 2016
1 parent 9eecd1f commit 627a551
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 15 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@
"devDependencies": {
"@types/chai": "^3.4.32",
"@types/harmony-proxy": "^1.0.27",
"@types/mocha": "^2.2.31",
"@types/mocha": "^ 2.2.35",
"@types/sinon": "^1.16.29",
"bluebird": "^3.4.1",
"bluebird": "^3.4.7",
"browserify": "^13.0.0",
"chai": "^3.4.1",
"es6-symbol": "^3.1.0",
"gulp": "^3.9.0",
"gulp-istanbul": "^1.0.0",
"gulp-mocha": "^3.0.0",
"gulp-rename": "^1.2.2",
"gulp-sourcemaps": "^2.1.1",
"gulp-sourcemaps": "^2.2.1",
"gulp-tslint": "^7.0.0",
"gulp-typescript": "^3.0.0",
"gulp-uglify": "^2.0.0",
Expand All @@ -68,10 +68,10 @@
"mocha": "^3.0.1",
"performance-now": "^0.2.0",
"publish-please": "^2.1.4",
"reflect-metadata": "^0.1.3",
"reflect-metadata": "^0.1.9",
"run-sequence": "^1.2.0",
"sinon": "^1.17.3",
"tslint": "^4.0.1",
"tslint": "^4.2.0",
"typescript": "^2.1.1",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
Expand Down
6 changes: 2 additions & 4 deletions src/annotation/decorator_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function tagParameter(
metadata: interfaces.Metadata
) {
let metadataKey = METADATA_KEY.TAGGED;
return _tagParameterOrProperty(metadataKey, annotationTarget, propertyName, metadata, parameterIndex);
_tagParameterOrProperty(metadataKey, annotationTarget, propertyName, metadata, parameterIndex);
}

function tagProperty(
Expand All @@ -18,7 +18,7 @@ function tagProperty(
metadata: interfaces.Metadata
) {
let metadataKey = METADATA_KEY.TAGGED_PROP;
return _tagParameterOrProperty(metadataKey, annotationTarget.constructor, propertyName, metadata);
_tagParameterOrProperty(metadataKey, annotationTarget.constructor, propertyName, metadata);
}

function _tagParameterOrProperty(
Expand Down Expand Up @@ -60,8 +60,6 @@ function _tagParameterOrProperty(
paramOrPropertyMetadata.push(metadata);
paramsOrPropertiesMetadata[key] = paramOrPropertyMetadata;
Reflect.defineMetadata(metadataKey, paramsOrPropertiesMetadata, annotationTarget);
return annotationTarget;

}

function _decorate(decorators: any[], target: any): void {
Expand Down
6 changes: 3 additions & 3 deletions src/annotation/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { tagParameter, tagProperty } from "./decorator_utils";
import * as METADATA_KEY from "../constants/metadata_keys";

function inject(serviceIdentifier: interfaces.ServiceIdentifier<any>) {
return function(target: any, targetKey: string, index?: number) {
return function(target: any, targetKey: string, index?: number): void {

let metadata = new Metadata(METADATA_KEY.INJECT_TAG, serviceIdentifier);

if (typeof index === "number") {
return tagParameter(target, targetKey, index, metadata);
tagParameter(target, targetKey, index, metadata);
} else {
return tagProperty(target, targetKey, metadata);
tagProperty(target, targetKey, metadata);
}

};
Expand Down
3 changes: 3 additions & 0 deletions src/constants/error_msgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export const NO_MORE_SNAPSHOTS_AVAILABLE = "No snapshot available to restore.";
export const INVALID_MIDDLEWARE_RETURN = "Invalid return type in middleware. Middleware must return!";
export const INVALID_FUNCTION_BINDING = "Value provided to function binding must be a function!";

export const INVALID_TO_SELF_VALUE = "The toSelf function can only be applied when a constructor is " +
"used as service identifier";

export const INVALID_DECORATOR_OPERATION = "The @inject @multiInject @tagged and @named decorators " +
"must be applied to the parameters of a class constructor or a class property.";

Expand Down
3 changes: 3 additions & 0 deletions src/syntax/binding_to_syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class BindingToSyntax<T> implements interfaces.BindingToSyntax<T> {
}

public toSelf(): interfaces.BindingInWhenOnSyntax<T> {
if (typeof this._binding.serviceIdentifier !== "function") {
throw new Error(`${ERROR_MSGS.INVALID_TO_SELF_VALUE}`);
}
let self: any = this._binding.serviceIdentifier;
return this.to(self);
}
Expand Down
6 changes: 6 additions & 0 deletions test/bugs/bugs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,4 +523,10 @@ describe("Bugs", () => {

});

it("Should throw a friendly error when binding a non-class using toSelf", () => {
let container = new Container();
let throws = () => { container.bind("testId").toSelf(); };
expect(throws).to.throw(ERROR_MSGS.INVALID_TO_SELF_VALUE);
});

});
9 changes: 6 additions & 3 deletions test/syntax/binding_to_syntax.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe("BindingToSyntax", () => {
let ninjaIdentifier = "Ninja";

let binding = new Binding<Ninja>(ninjaIdentifier, BindingScopeEnum.Transient);
// let bindingWithClassAsId = new Binding<Ninja>(Ninja, BindingScopeEnum.Transient);
let bindingToSyntax = new BindingToSyntax<Ninja>(binding);

expect(binding.type).eql(BindingTypeEnum.Invalid);
Expand All @@ -40,10 +41,12 @@ describe("BindingToSyntax", () => {
expect(binding.type).eql(BindingTypeEnum.Instance);
expect(binding.implementationType).not.to.eql(null);

bindingToSyntax.toSelf();
expect(binding.type).eql(BindingTypeEnum.Instance);
expect(binding.implementationType).not.to.eql(null);
// (bindingToSyntax as any)._binding = bindingWithClassAsId;
// bindingToSyntax.toSelf();
// expect(binding.type).eql(BindingTypeEnum.Instance);
// expect(binding.implementationType).not.to.eql(null);

(bindingToSyntax as any)._binding = binding;
bindingToSyntax.toConstantValue(new Ninja());
expect(binding.type).eql(BindingTypeEnum.ConstantValue);
expect(binding.cache instanceof Ninja).eql(true);
Expand Down

0 comments on commit 627a551

Please sign in to comment.