From 7e87b3b0921a608d44441fbdec66613542c87d2a Mon Sep 17 00:00:00 2001 From: Vlad Rindevich Date: Thu, 7 Nov 2024 13:31:20 +0200 Subject: [PATCH] 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 --- src/resolver/matchPath.ts | 2 +- src/resolver/resolver.ts | 11 +++++++++-- test/resolver/resolver.spec.ts | 2 +- test/router/lifecycle-events.spec.ts | 2 +- tsconfig.json | 4 ++-- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/resolver/matchPath.ts b/src/resolver/matchPath.ts index 1783fabb..6361619d 100644 --- a/src/resolver/matchPath.ts +++ b/src/resolver/matchPath.ts @@ -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 `?`. diff --git a/src/resolver/resolver.ts b/src/resolver/resolver.ts index 2ca4fdb3..53a6c6f2 100644 --- a/src/resolver/resolver.ts +++ b/src/resolver/resolver.ts @@ -37,14 +37,20 @@ function isRouteContext(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 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. */ @@ -61,7 +67,8 @@ export class ResolutionError { expect(context).to.have.property('result').that.equals(errorResult); expect(errorHandler).to.be.calledOnce; - const error: ResolutionError = errorHandler.firstCall.firstArg; + const error: ResolutionError = 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'); diff --git a/test/router/lifecycle-events.spec.ts b/test/router/lifecycle-events.spec.ts index 407e9cc7..213c4b70 100644 --- a/test/router/lifecycle-events.spec.ts +++ b/test/router/lifecycle-events.spec.ts @@ -2390,7 +2390,7 @@ describe('Vaadin Router lifecycle events', () => { resolve(); }) .catch((e: unknown) => { - reject(new Error('Error happened', { cause: e })); + reject(e); }); } }, diff --git a/tsconfig.json b/tsconfig.json index 7a89a309..f84a327a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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,