]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
chore: error matches
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 26 Jun 2024 14:12:40 +0000 (16:12 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 4 Dec 2024 15:10:35 +0000 (16:10 +0100)
packages/router/src/new-route-resolver/matcher-pattern.ts
packages/router/src/new-route-resolver/matchers/errors.ts [new file with mode: 0644]
packages/router/src/new-route-resolver/matchers/path-static.ts
packages/router/vue-router-auto.d.ts

index a9f8f5e83b035884ae7d79198c8fb04853827478..2e066bf87ab34a39e4bcacf59a67c0c659ff9ce0 100644 (file)
@@ -9,7 +9,8 @@ import type { MatcherParamsFormatted } from './matcher-location'
 /**
  * Allows to match, extract, parse and build a path. Tailored to iterate through route records and check if a location
  * matches. When it cannot match, it returns `null` instead of throwing to not force a try/catch block around each
- * iteration in for loops.
+ * iteration in for loops. Not meant to handle encoding/decoding. It expects different parts of the URL to be either
+ * encoded or decoded depending on the method.
  */
 export interface MatcherPattern {
   /**
@@ -36,8 +37,8 @@ export interface MatcherPattern {
     | null
 
   /**
-   * Extracts the defined params from an encoded path, query, and hash parsed from a URL. Does not apply formatting or
-   * decoding. If the URL does not match the pattern, returns `null`.
+   * Extracts the defined params from an encoded path, decoded query, and decoded hash parsed from a URL. Does not apply
+   * formatting or decoding. If the URL does not match the pattern, returns `null`.
    *
    * @example
    * ```ts
@@ -54,6 +55,11 @@ export interface MatcherPattern {
    * pattern.parseLocation({ path: '/foo', query: {}, hash: '#hello' })
    * // null // the query param is missing
    * ```
+   *
+   * @param location - URL parts to extract from
+   * @param location.path - encoded path
+   * @param location.query - decoded query
+   * @param location.hash - decoded hash
    */
   matchLocation(location: {
     path: string
diff --git a/packages/router/src/new-route-resolver/matchers/errors.ts b/packages/router/src/new-route-resolver/matchers/errors.ts
new file mode 100644 (file)
index 0000000..51c5574
--- /dev/null
@@ -0,0 +1,13 @@
+export class MatchMiss extends Error {
+  name = 'MatchMiss'
+}
+
+export const miss = () => new MatchMiss()
+
+export class ParamInvalid extends Error {
+  name = 'ParamInvalid'
+  constructor(public param: string) {
+    super()
+  }
+}
+export const invalid = (param: string) => new ParamInvalid(param)
index 0d6ebd3fe494c1959a911831cb5b0c781daedd63..7d5e968ff471336702847837419e933f6c92bec8 100644 (file)
@@ -1,12 +1,12 @@
 import type { MatcherPatternPath } from '../matcher-pattern'
+import { miss } from './errors'
 
-export class PathMatcherStatic implements MatcherPatternPath {
+export class MatcherPathStatic implements MatcherPatternPath {
   constructor(private path: string) {}
 
   match(path: string) {
     if (this.path === path) return {}
-    throw new Error()
-    // return this.path === path ? {} : null
+    throw miss()
   }
 
   buildPath() {
index 56e8a0979db17d56c0b6c4e34cac9cc86db49831..797a7059900ff95bbebccb5c22291e90b4442da8 100644 (file)
@@ -1,4 +1 @@
-/**
- * Extended by unplugin-vue-router to create typed routes.
- */
-export interface RouteNamedMap {}
+// augmented by unplugin-vue-router