Skip to content

Commit

Permalink
Improved @override error messaging (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlhaufe authored May 2, 2021
1 parent 8bb8f2a commit f84e8c6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v0.20.4

* Improved error messaging with `@override` when feature is missing
* Fixed source code typos

## v0.20.3

* Fixed bug [#202](https://github.com/final-hill/decorator-contracts/issues/202)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@final-hill/decorator-contracts",
"version": "0.20.3",
"version": "0.20.4",
"description": "Code Contracts for TypeScript and ECMAScript classes",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
12 changes: 6 additions & 6 deletions src/lib/Feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import ClassRegistration from './ClassRegistration';

class Feature {
#descriptor: PropertyDescriptor;
#overridenOriginalDescriptor: PropertyDescriptor | undefined;
#overriddenOriginalDescriptor: PropertyDescriptor | undefined;

/**
* Does the current feature have an @override declaration?
* Does the current feature have an `@override` declaration?
*/
hasOverrides = false;

Expand Down Expand Up @@ -98,16 +98,16 @@ class Feature {
/**
* Returns the original feature descriptor which was replaced by the `override` decorator
*/
get overridenOriginalDescriptor(): PropertyDescriptor| undefined {
return this.#overridenOriginalDescriptor;
get overriddenOriginalDescriptor(): PropertyDescriptor| undefined {
return this.#overriddenOriginalDescriptor;
}

/**
* Sets the feature descriptor. Used by the `override` decorator.
* @param {PropertyDescriptor} value - The descriptor to save
*/
set overridenOriginalDescriptor(value: PropertyDescriptor | undefined) {
this.#overridenOriginalDescriptor = value;
set overriddenOriginalDescriptor(value: PropertyDescriptor | undefined) {
this.#overriddenOriginalDescriptor = value;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/override.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function override(target: Record<PropertyKey, any>, propertyKey: PropertyKey, de
const registration = CLASS_REGISTRY.getOrCreate(Class),
feature = registration.findFeature(propertyKey);

assert(feature != null, MSG_MISSING_FEATURE);
assert(feature != null, `${MSG_MISSING_FEATURE}: ${registration.Class.name}.prototype.${String(propertyKey)}`);

const ancFeature = feature.ancestorFeature;

Expand All @@ -42,7 +42,7 @@ function override(target: Record<PropertyKey, any>, propertyKey: PropertyKey, de
assert(thisMethod.length == ancMethod.length, MSG_INVALID_ARG_LENGTH);
}

feature.overridenOriginalDescriptor = descriptor;
feature.overriddenOriginalDescriptor = descriptor;

// method decorators are evaluated before class decorators
return {
Expand Down

0 comments on commit f84e8c6

Please sign in to comment.