New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(directive): throw if output the same event more than once #5113
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import {resolveForwardRef, Injectable} from 'angular2/src/core/di'; | |
import {Type, isPresent, isBlank, stringify} from 'angular2/src/facade/lang'; | ||
import {BaseException} from 'angular2/src/facade/exceptions'; | ||
import {ListWrapper, StringMapWrapper} from 'angular2/src/facade/collection'; | ||
|
||
import { | ||
DirectiveMetadata, | ||
ComponentMetadata, | ||
|
@@ -38,15 +39,16 @@ export class DirectiveResolver { | |
var metadata = typeMetadata.find(_isDirectiveMetadata); | ||
if (isPresent(metadata)) { | ||
var propertyMetadata = reflector.propMetadata(type); | ||
return this._mergeWithPropertyMetadata(metadata, propertyMetadata); | ||
return this._mergeWithPropertyMetadata(metadata, propertyMetadata, type); | ||
} | ||
} | ||
|
||
throw new BaseException(`No Directive annotation found on ${stringify(type)}`); | ||
} | ||
|
||
private _mergeWithPropertyMetadata(dm: DirectiveMetadata, | ||
propertyMetadata: {[key: string]: any[]}): DirectiveMetadata { | ||
propertyMetadata: {[key: string]: any[]}, | ||
directiveType: Type): DirectiveMetadata { | ||
var inputs = []; | ||
var outputs = []; | ||
var host: {[key: string]: string} = {}; | ||
|
@@ -100,13 +102,27 @@ export class DirectiveResolver { | |
} | ||
}); | ||
}); | ||
return this._merge(dm, inputs, outputs, host, queries); | ||
return this._merge(dm, inputs, outputs, host, queries, directiveType); | ||
} | ||
|
||
private _merge(dm: DirectiveMetadata, inputs: string[], outputs: string[], | ||
host: {[key: string]: string}, queries: {[key: string]: any}): DirectiveMetadata { | ||
host: {[key: string]: string}, queries: {[key: string]: any}, | ||
directiveType: Type): DirectiveMetadata { | ||
var mergedInputs = isPresent(dm.inputs) ? ListWrapper.concat(dm.inputs, inputs) : inputs; | ||
var mergedOutputs = isPresent(dm.outputs) ? ListWrapper.concat(dm.outputs, outputs) : outputs; | ||
|
||
var mergedOutputs; | ||
if (isPresent(dm.outputs)) { | ||
dm.outputs.forEach((propName: string) => { | ||
if (ListWrapper.contains(outputs, propName)) { | ||
throw new BaseException( | ||
`Output event '${propName}' defined multiple times in '${stringify(directiveType)}'`); | ||
} | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could it be that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about it. I decided not to check since |
||
mergedOutputs = ListWrapper.concat(dm.outputs, outputs); | ||
} else { | ||
mergedOutputs = outputs; | ||
} | ||
|
||
var mergedHost = isPresent(dm.host) ? StringMapWrapper.merge(dm.host, host) : host; | ||
var mergedQueries = | ||
isPresent(dm.queries) ? StringMapWrapper.merge(dm.queries, queries) : queries; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you include the type name as well in the error message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced selector with type name