Skip to content

Commit 7e87b3b

Browse files
Lodinplatosha
andauthored
fix: use es2021 as a target for TypeScript (#900)
* fix: use es2021 as a target for TypeScript * fix: get rid of es2022 code * fix: restore error.cause --------- Co-authored-by: Anton Platonov <platosha@gmail.com>
1 parent 842b6f7 commit 7e87b3b

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

src/resolver/matchPath.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function matchPath(
7979
const key = regexp.keys[i - 1];
8080
const prop = key.name;
8181
const value = m[i];
82-
if (value !== undefined || !Object.hasOwn(params, prop)) {
82+
if (value !== undefined || !Object.prototype.hasOwnProperty.call(params, prop)) {
8383
if (key.modifier === '+' || key.modifier === '*') {
8484
// by default, as of path-to-regexp 6.0.0, the default delimiters
8585
// are `/`, `#` and `?`.

src/resolver/resolver.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,20 @@ function isRouteContext<T, R extends object, C extends object>(value: unknown):
3737
);
3838
}
3939

40-
export interface ResolutionErrorOptions extends ErrorOptions {
40+
export interface ResolutionErrorOptions {
4141
code?: number;
42+
cause?: unknown;
4243
}
4344

4445
/**
4546
* An error that is thrown when a route resolution fails.
4647
*/
4748
export class ResolutionError<T, R extends object = EmptyObject, C extends object = EmptyObject> extends Error {
49+
/**
50+
* The resolution error cause, possibly an error thrown from the action callback.
51+
*/
52+
readonly cause?: unknown;
53+
4854
/**
4955
* A HTTP status code associated with the error.
5056
*/
@@ -61,7 +67,8 @@ export class ResolutionError<T, R extends object = EmptyObject, C extends object
6167
if (routePath) {
6268
errorMessage += ` Resolution had failed on route: '${routePath}'`;
6369
}
64-
super(errorMessage, options);
70+
super(errorMessage);
71+
this.cause = options?.cause;
6572
this.code = options?.code;
6673
this.context = context;
6774
}

test/resolver/resolver.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe('Resolver', () => {
8787
expect(context).to.have.property('result').that.equals(errorResult);
8888
expect(errorHandler).to.be.calledOnce;
8989

90-
const error: ResolutionError<Error> = errorHandler.firstCall.firstArg;
90+
const error: ResolutionError<HTMLElement> = errorHandler.firstCall.firstArg;
9191
expect(error).to.be.instanceof(ResolutionError);
9292
expect(error.cause).to.be.an('error');
9393
expect(error.cause).to.have.property('message').that.equals('custom');

test/router/lifecycle-events.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2390,7 +2390,7 @@ describe('Vaadin Router lifecycle events', () => {
23902390
resolve();
23912391
})
23922392
.catch((e: unknown) => {
2393-
reject(new Error('Error happened', { cause: e }));
2393+
reject(e);
23942394
});
23952395
}
23962396
},

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"allowSyntheticDefaultImports": true,
55
"declaration": true,
66
"declarationMap": true,
7-
"target": "es2022",
7+
"target": "es2021",
88
"module": "esnext",
99
"moduleResolution": "bundler",
10-
"lib": ["es2022", "dom", "DOM.Iterable"],
10+
"lib": ["es2021", "dom", "DOM.Iterable"],
1111
"allowArbitraryExtensions": true,
1212
"skipLibCheck": true,
1313
"strict": true,

0 commit comments

Comments
 (0)