Skip to content

Commit

Permalink
fix: use es2021 as a target for TypeScript (#900)
Browse files Browse the repository at this point in the history
* fix: use es2021 as a target for TypeScript

* fix: get rid of es2022 code

* fix: restore error.cause

---------

Co-authored-by: Anton Platonov <[email protected]>
  • Loading branch information
Lodin and platosha authored Nov 7, 2024
1 parent 842b6f7 commit 7e87b3b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/resolver/matchPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function matchPath(
const key = regexp.keys[i - 1];
const prop = key.name;
const value = m[i];
if (value !== undefined || !Object.hasOwn(params, prop)) {
if (value !== undefined || !Object.prototype.hasOwnProperty.call(params, prop)) {
if (key.modifier === '+' || key.modifier === '*') {
// by default, as of path-to-regexp 6.0.0, the default delimiters
// are `/`, `#` and `?`.
Expand Down
11 changes: 9 additions & 2 deletions src/resolver/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,20 @@ function isRouteContext<T, R extends object, C extends object>(value: unknown):
);
}

export interface ResolutionErrorOptions extends ErrorOptions {
export interface ResolutionErrorOptions {
code?: number;
cause?: unknown;
}

/**
* An error that is thrown when a route resolution fails.
*/
export class ResolutionError<T, R extends object = EmptyObject, C extends object = EmptyObject> extends Error {
/**
* The resolution error cause, possibly an error thrown from the action callback.
*/
readonly cause?: unknown;

/**
* A HTTP status code associated with the error.
*/
Expand All @@ -61,7 +67,8 @@ export class ResolutionError<T, R extends object = EmptyObject, C extends object
if (routePath) {
errorMessage += ` Resolution had failed on route: '${routePath}'`;
}
super(errorMessage, options);
super(errorMessage);
this.cause = options?.cause;
this.code = options?.code;
this.context = context;
}
Expand Down
2 changes: 1 addition & 1 deletion test/resolver/resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('Resolver', () => {
expect(context).to.have.property('result').that.equals(errorResult);
expect(errorHandler).to.be.calledOnce;

const error: ResolutionError<Error> = errorHandler.firstCall.firstArg;
const error: ResolutionError<HTMLElement> = errorHandler.firstCall.firstArg;
expect(error).to.be.instanceof(ResolutionError);
expect(error.cause).to.be.an('error');
expect(error.cause).to.have.property('message').that.equals('custom');
Expand Down
2 changes: 1 addition & 1 deletion test/router/lifecycle-events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2390,7 +2390,7 @@ describe('Vaadin Router lifecycle events', () => {
resolve();
})
.catch((e: unknown) => {
reject(new Error('Error happened', { cause: e }));
reject(e);
});
}
},
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"allowSyntheticDefaultImports": true,
"declaration": true,
"declarationMap": true,
"target": "es2022",
"target": "es2021",
"module": "esnext",
"moduleResolution": "bundler",
"lib": ["es2022", "dom", "DOM.Iterable"],
"lib": ["es2021", "dom", "DOM.Iterable"],
"allowArbitraryExtensions": true,
"skipLibCheck": true,
"strict": true,
Expand Down

0 comments on commit 7e87b3b

Please sign in to comment.