Skip to content
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

Remove unneeded ordinaryHasOwnMetadata method #5

Merged
merged 1 commit into from
Jul 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function getOwnMetadata(metadataKey: MetadataKey, target: Target, propert
}

export function hasOwnMetadata(metadataKey: MetadataKey, target: Target, propertyKey?: PropertyKey): boolean {
return ordinaryHasOwnMetadata(metadataKey, target, propertyKey);
return !!ordinaryGetOwnMetadata(metadataKey, target, propertyKey);
}

function decorateConstructor(decorators: ClassDecorator[], target: Function): Function {
Expand All @@ -63,10 +63,7 @@ function decorateConstructor(decorators: ClassDecorator[], target: Function): Fu

function decorateProperty(decorators: MemberDecorator[], target: Target, propertyKey: PropertyKey, descriptor?: PropertyDescriptor): PropertyDescriptor | undefined {
decorators.reverse().forEach((decorator: MemberDecorator) => {
const decorated = decorator(target, propertyKey, descriptor);
if (decorated) {
descriptor = decorated;
}
descriptor = decorator(target, propertyKey, descriptor) || descriptor;
});
return descriptor;
}
Expand All @@ -79,18 +76,13 @@ function ordinaryDefineOwnMetadata(metadataKey: MetadataKey, metadataValue: Meta
}

function ordinaryGetMetadata(metadataKey: MetadataKey, target: Target, propertyKey?: PropertyKey): Function | undefined {
return ordinaryHasOwnMetadata(metadataKey, target, propertyKey)
return !!ordinaryGetOwnMetadata(metadataKey, target, propertyKey)
? ordinaryGetOwnMetadata(metadataKey, target, propertyKey)
: Object.getPrototypeOf(target)
? ordinaryGetMetadata(metadataKey, Object.getPrototypeOf(target), propertyKey)
: undefined;
}

function ordinaryHasOwnMetadata(metadataKey: MetadataKey, target: Target, propertyKey?: PropertyKey): boolean {
const metadataMap = getMetadataMap(target, propertyKey);
return !!metadataMap && !!metadataMap.has(metadataKey);
}

function ordinaryGetOwnMetadata(metadataKey: MetadataKey, target: Target, propertyKey?: PropertyKey): Function | undefined {
if (target === undefined) throw new TypeError();
const metadataMap = getMetadataMap(target, propertyKey);
Expand Down