Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Matcher with param parsing #2415

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2ee6915
feat: wip new matcher
posva Jun 25, 2024
534bb1b
test: check parsed urls
posva Jun 25, 2024
b908aa7
chore: build location
posva Jun 25, 2024
bf52c6e
perf: parseURL minor improvements
posva Jun 26, 2024
a195cc8
refactor: avoid double decoding
posva Jun 26, 2024
eda52f6
refactor: add fullPath
posva Jun 26, 2024
6f2da87
chore: static path matcher
posva Jun 26, 2024
ef57c3e
chore: error matches
posva Jun 26, 2024
7ed433b
test: static matcher
posva Jun 26, 2024
8e650e6
refactor: unused code
posva Jul 9, 2024
49eb850
chore: ignore temp tsconfig
posva Dec 4, 2024
731c9ee
test: better IM after hash
posva Dec 5, 2024
d1dba9c
test: url parsing
posva Dec 5, 2024
9dcfd42
refactor: simplify parseURL
posva Dec 6, 2024
e76d256
chore: comment
posva Dec 6, 2024
b57cb21
chore: comments
posva Dec 6, 2024
d462758
refactor: renames and minor changes
posva Dec 6, 2024
1ca2a13
refactor: simplify matcher interfaces
posva Dec 9, 2024
82da018
refactor: remove unused code
posva Dec 9, 2024
b8eba1a
refactor: rename matcher-pattern
posva Dec 9, 2024
65a0940
refactor: add methods needed by router
posva Dec 10, 2024
2ab9c32
feat: new dynamic path matcher
posva Dec 16, 2024
a515a21
refactor: reorganize types and add initial experimental router
posva Dec 17, 2024
42c9849
chore: comments
posva Dec 23, 2024
4d2c23b
refactor: simplify router resolve
posva Dec 23, 2024
2d138b9
chore: wip encoding
posva Dec 24, 2024
94a7e25
chore: small fix
posva Jan 7, 2025
794fdd5
refactor: rename matcher to resolver
posva Jan 8, 2025
6b2a659
chore: remove unused
posva Jan 8, 2025
a02cab6
test: fix ts errors
posva Jan 8, 2025
49ee966
test: remove old matcher refs
posva Jan 8, 2025
1f717fb
chore: remove last ts errors
posva Jan 8, 2025
b879e54
feat: support partial locations
posva Jan 8, 2025
3416bd0
chore: rename
posva Jan 9, 2025
f20dbf1
feat: allow string in matcher resolve
posva Jan 9, 2025
60564fe
test: stricter no match test
posva Jan 9, 2025
db5a85c
feat: handle children
posva Jan 9, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ local.log
_selenium-server.log
packages/*/LICENSE
tracing_output
tsconfig.vitest-temp.json
103 changes: 99 additions & 4 deletions packages/router/__tests__/location.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,121 @@ describe('parseURL', () => {
})
})

it('parses ? after the hash', () => {
it('correctly parses a ? after the hash', () => {
expect(parseURL('/foo#?a=one')).toEqual({
fullPath: '/foo#?a=one',
path: '/foo',
hash: '#?a=one',
query: {},
})
expect(parseURL('/foo/#?a=one')).toEqual({
fullPath: '/foo/#?a=one',
expect(parseURL('/foo/?a=two#?a=one')).toEqual({
fullPath: '/foo/?a=two#?a=one',
path: '/foo/',
hash: '#?a=one',
query: { a: 'two' },
})
})

it('works with empty query', () => {
expect(parseURL('/foo?#hash')).toEqual({
fullPath: '/foo?#hash',
path: '/foo',
hash: '#hash',
query: {},
})
expect(parseURL('/foo#hash')).toEqual({
fullPath: '/foo#hash',
path: '/foo',
hash: '#hash',
query: {},
})
expect(parseURL('/foo?')).toEqual({
fullPath: '/foo?',
path: '/foo',
hash: '',
query: {},
})
expect(parseURL('/foo')).toEqual({
fullPath: '/foo',
path: '/foo',
hash: '',
query: {},
})
})

it('works with empty hash', () => {
expect(parseURL('/foo#')).toEqual({
fullPath: '/foo#',
path: '/foo',
hash: '#',
query: {},
})
expect(parseURL('/foo?#')).toEqual({
fullPath: '/foo?#',
path: '/foo',
hash: '#',
query: {},
})
expect(parseURL('/foo')).toEqual({
fullPath: '/foo',
path: '/foo',
hash: '',
query: {},
})
})

it('works with a relative paths', () => {
expect(parseURL('foo', '/parent/bar')).toEqual({
fullPath: '/parent/foo',
path: '/parent/foo',
hash: '',
query: {},
})
expect(parseURL('./foo', '/parent/bar')).toEqual({
fullPath: '/parent/foo',
path: '/parent/foo',
hash: '',
query: {},
})
expect(parseURL('../foo', '/parent/bar')).toEqual({
fullPath: '/foo',
path: '/foo',
hash: '',
query: {},
})
// cannot go below root
expect(parseURL('../../foo', '/parent/bar')).toEqual({
fullPath: '/foo',
path: '/foo',
hash: '',
query: {},
})

expect(parseURL('', '/parent/bar')).toEqual({
fullPath: '/parent/bar',
path: '/parent/bar',
hash: '',
query: {},
})
expect(parseURL('#foo', '/parent/bar')).toEqual({
fullPath: '/parent/bar#foo',
path: '/parent/bar',
hash: '#foo',
query: {},
})
expect(parseURL('?o=o', '/parent/bar')).toEqual({
fullPath: '/parent/bar?o=o',
path: '/parent/bar',
hash: '',
query: { o: 'o' },
})
})

it('calls parseQuery', () => {
const parseQuery = vi.fn()
originalParseURL(parseQuery, '/?é=é&é=a')
expect(parseQuery).toHaveBeenCalledTimes(1)
expect(parseQuery).toHaveBeenCalledWith('é=é&é=a')
expect(parseQuery).toHaveBeenCalledWith('?é=é&é=a')
})
})

Expand Down
10 changes: 0 additions & 10 deletions packages/router/__tests__/matcher/pathRanking.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,9 @@ describe('Path ranking', () => {
return comparePathParserScore(
{
score: a,
re: /a/,
// @ts-expect-error
stringify: v => v,
// @ts-expect-error
parse: v => v,
keys: [],
},
{
score: b,
re: /a/,
stringify: v => v,
parse: v => v,
keys: [],
}
)
}
Expand Down
4 changes: 1 addition & 3 deletions packages/router/__tests__/router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import { START_LOCATION_NORMALIZED } from '../src/location'
import { vi, describe, expect, it, beforeAll } from 'vitest'
import { mockWarn } from './vitest-mock-warn'

declare var __DEV__: boolean

const routes: RouteRecordRaw[] = [
{ path: '/', component: components.Home, name: 'home' },
{ path: '/home', redirect: '/' },
Expand Down Expand Up @@ -173,7 +171,7 @@ describe('Router', () => {
const parseQuery = vi.fn(_ => ({}))
const { router } = await newRouter({ parseQuery })
const to = router.resolve('/foo?bar=baz')
expect(parseQuery).toHaveBeenCalledWith('bar=baz')
expect(parseQuery).toHaveBeenCalledWith('?bar=baz')
expect(to.query).toEqual({})
})

Expand Down
4 changes: 2 additions & 2 deletions packages/router/src/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { warn } from './warning'

const HASH_RE = /#/g // %23
const AMPERSAND_RE = /&/g // %26
const SLASH_RE = /\//g // %2F
export const SLASH_RE = /\//g // %2F
const EQUAL_RE = /=/g // %3D
const IM_RE = /\?/g // %3F
export const PLUS_RE = /\+/g // %2B
Expand Down Expand Up @@ -58,7 +58,7 @@ const ENC_SPACE_RE = /%20/g // }
* @param text - string to encode
* @returns encoded string
*/
function commonEncode(text: string | number): string {
export function commonEncode(text: string | number): string {
return encodeURI('' + text)
.replace(ENC_PIPE_RE, '|')
.replace(ENC_BRACKET_OPEN_RE, '[')
Expand Down
22 changes: 21 additions & 1 deletion packages/router/src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { MatcherLocationRaw, MatcherLocation } from './types'
import type { RouteLocationRaw, RouteLocationNormalized } from './typed-routes'
import type {
RouteLocationRaw,
RouteLocationNormalized,
RouteLocationNormalizedLoaded,
} from './typed-routes'
import { assign } from './utils'

/**
Expand Down Expand Up @@ -199,3 +203,19 @@ function stringifyRoute(to: RouteLocationRaw): string {
}
return JSON.stringify(location, null, 2)
}
/**
* Internal type to define an ErrorHandler
*
* @param error - error thrown
* @param to - location we were navigating to when the error happened
* @param from - location we were navigating from when the error happened
* @internal
*/

export interface _ErrorListener {
(
error: any,
to: RouteLocationNormalized,
from: RouteLocationNormalizedLoaded
): any
}
Loading
Loading