Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.12.2] - 2026-04-01

### Fixed
- Route guard property `"?"` is now restricted to function type only, preventing accidental assignment of sub-routes objects (closes #10)

## [0.12.1] - 2026-04-01
Comment on lines +8 to +15
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Missing changelog entry for version 0.12.2.

The package version is bumped to 0.12.2, but there's no corresponding changelog entry documenting the type safety fix for the "?" guard key (issue #10). Add a section between [Unreleased] and [0.12.1]:

📝 Suggested changelog entry
 ## [Unreleased]
 
+## [0.12.2] - 2026-04-XX
+
+### Fixed
+- Route guard property `"?"` is now restricted to function type only, preventing accidental assignment of sub-routes objects (closes `#10`)
+
 ## [0.12.1] - 2026-04-01
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## [Unreleased]
## [0.12.1] - 2026-04-01
## [Unreleased]
## [0.12.2] - 2026-04-XX
### Fixed
- Route guard property `"?"` is now restricted to function type only, preventing accidental assignment of sub-routes objects (closes `#10`)
## [0.12.1] - 2026-04-01
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@CHANGELOG.md` around lines 8 - 10, Add a new changelog section for version
0.12.2 between the existing [Unreleased] and [0.12.1] headings documenting the
type-safety fix for the "?" guard key (issue `#10`); include a concise entry under
"## [0.12.2] - 2026-04-01" (or the correct release date) that mentions the fix
to the "?" guard key type safety and references issue `#10`.

✅ Addressed in commit 60c5346


### Fixed
Expand Down
4 changes: 2 additions & 2 deletions packages/esroute-lit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@esroute/lit",
"version": "0.12.1",
"version": "0.12.2",
"description": "A small efficient client-side routing library for lit, written in TypeScript.",
"main": "dist/index.js",
"sideEffects": false,
Expand All @@ -22,7 +22,7 @@
"typescript": "^5.4.5"
},
"dependencies": {
"esroute": "^0.12.1",
"esroute": "^0.12.2",
"lit": "^3.1.1"
}
}
2 changes: 1 addition & 1 deletion packages/esroute/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "esroute",
"version": "0.12.1",
"version": "0.12.2",
"description": "A small efficient framework-agnostic client-side routing library, written in TypeScript.",
"types": "dist/index.d.ts",
"main": "dist/index.js",
Expand Down
11 changes: 11 additions & 0 deletions packages/esroute/src/route-resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,17 @@ describe("Resolver", () => {
});
});

describe("types", () => {
it("should not allow a route object as guard", () => {
// @ts-expect-error "?" must be a function, not a sub-routes object
const _routes: Routes = { "?": { foo: () => "foo" } };
});

it("should allow a function as guard", () => {
const _routes: Routes = { "?": () => undefined };
});
});

describe("redirects", () => {
it("should resolve a redirect via calling 'go()'", async () => {
const navOpts = new NavOpts("/foo");
Expand Down
5 changes: 3 additions & 2 deletions packages/esroute/src/route-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ const getResolves = async (
): Promise<Resolve[] | null> => {
const { path, params } = opts;
const resolves: Resolve[] = [];
let routes: Routes | Resolve | null = root;
let routes: Routes | Resolve | null | undefined = root;
for (let i = 0; i < path.length; i++) {
const part = path[i];
if (!routes || typeof routes === "function") return null;
const redirect = await checkGuard(routes, opts);
if (redirect) return [() => redirect];
const virtual: Routes | Resolve | void = routes[""];
const virtual: Routes | Resolve | undefined = routes[""];
if (typeof virtual === "function") resolves.unshift(virtual);
if (part in routes) routes = routes[part];
else if ("*" in routes) {
Expand All @@ -73,6 +73,7 @@ const getResolves = async (
resolves.unshift(routes);
return resolves;
}
if (!routes) return null;
const redirect = await checkGuard(routes, opts);
if (redirect) return [() => redirect];
} while ((routes = routes[""]));
Expand Down
3 changes: 2 additions & 1 deletion packages/esroute/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export type Resolve<T = any, S = any> = (
) => T | NavOpts<S> | Promise<T | NavOpts<S>>;

export interface Routes<T = any, S = any> {
[k: string]: Routes<T, S> | Resolve<T, S>;
"?"?: Resolve<T, S>;
[k: string]: Routes<T, S> | Resolve<T, S> | undefined;
}

// Depth counter using a string to track recursion depth (max 10 levels)
Expand Down
Loading