Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
1e441fe4
Unverified
Commit
1e441fe4
authored
Apr 29, 2021
by
JJ Kasper
Committed by
GitHub
Apr 29, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace regex lexer with minimal regex for named groups (#24604)
parent
89d2c4e1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
8 additions
and
30 deletions
+8
-30
load-custom-routes.ts
packages/next/lib/load-custom-routes.ts
+6
-12
package.json
packages/next/package.json
+0
-1
taskfile.js
packages/next/taskfile.js
+2
-13
yarn.lock
yarn.lock
+0
-4
No files found.
packages/next/lib/load-custom-routes.ts
View file @
1e441fe4
...
@@ -6,10 +6,6 @@ import {
...
@@ -6,10 +6,6 @@ import {
PERMANENT_REDIRECT_STATUS
,
PERMANENT_REDIRECT_STATUS
,
TEMPORARY_REDIRECT_STATUS
,
TEMPORARY_REDIRECT_STATUS
,
}
from
'../next-server/lib/constants'
}
from
'../next-server/lib/constants'
// @ts-ignore
import
Lexer
from
'next/dist/compiled/regexr-lexer/lexer'
// @ts-ignore
import
lexerProfiles
from
'next/dist/compiled/regexr-lexer/profiles'
export
type
RouteHas
=
export
type
RouteHas
=
|
{
|
{
...
@@ -52,6 +48,7 @@ export type Redirect = {
...
@@ -52,6 +48,7 @@ export type Redirect = {
export
const
allowedStatusCodes
=
new
Set
([
301
,
302
,
303
,
307
,
308
])
export
const
allowedStatusCodes
=
new
Set
([
301
,
302
,
303
,
307
,
308
])
const
allowedHasTypes
=
new
Set
([
'header'
,
'cookie'
,
'query'
,
'host'
])
const
allowedHasTypes
=
new
Set
([
'header'
,
'cookie'
,
'query'
,
'host'
])
const
namedGroupsRegex
=
/
\(\?
<
([
a-zA-Z
][
a-zA-Z0-9
]
*
)
>/g
export
function
getRedirectStatus
(
route
:
{
export
function
getRedirectStatus
(
route
:
{
statusCode
?:
number
statusCode
?:
number
...
@@ -330,14 +327,11 @@ function checkCustomRoutes(
...
@@ -330,14 +327,11 @@ function checkCustomRoutes(
}
}
if
(
hasItem
.
value
)
{
if
(
hasItem
.
value
)
{
const
matcher
=
new
RegExp
(
`^
${
hasItem
.
value
}
$`
)
for
(
const
match
of
hasItem
.
value
.
matchAll
(
namedGroupsRegex
))
{
const
lexer
=
new
Lexer
()
if
(
match
[
1
])
{
lexer
.
profile
=
lexerProfiles
.
js
hasSegments
.
add
(
match
[
1
])
lexer
.
parse
(
`/
${
matcher
.
source
}
/`
)
}
}
Object
.
keys
(
lexer
.
namedGroups
).
forEach
((
groupKey
)
=>
{
hasSegments
.
add
(
groupKey
)
})
if
(
hasItem
.
type
===
'host'
)
{
if
(
hasItem
.
type
===
'host'
)
{
hasSegments
.
add
(
'host'
)
hasSegments
.
add
(
'host'
)
...
...
packages/next/package.json
View file @
1e441fe4
...
@@ -229,7 +229,6 @@
...
@@ -229,7 +229,6 @@
"postcss-preset-env"
:
"6.7.0"
,
"postcss-preset-env"
:
"6.7.0"
,
"postcss-scss"
:
"3.0.5"
,
"postcss-scss"
:
"3.0.5"
,
"recast"
:
"0.18.5"
,
"recast"
:
"0.18.5"
,
"regexr"
:
"https://github.com/ijjk/regexr-lexer.git#3bcf3d1c4bc6dd9239c47acb1fb7b419823f8337"
,
"resolve-url-loader"
:
"3.1.2"
,
"resolve-url-loader"
:
"3.1.2"
,
"sass-loader"
:
"10.0.5"
,
"sass-loader"
:
"10.0.5"
,
"schema-utils"
:
"2.7.1"
,
"schema-utils"
:
"2.7.1"
,
...
...
packages/next/taskfile.js
View file @
1e441fe4
// eslint-disable-next-line import/no-extraneous-dependencies
// eslint-disable-next-line import/no-extraneous-dependencies
const
notifier
=
require
(
'node-notifier'
)
const
notifier
=
require
(
'node-notifier'
)
const
{
relative
,
basename
,
resolve
,
join
,
dirname
}
=
require
(
'path'
)
const
{
relative
,
basename
,
resolve
}
=
require
(
'path'
)
const
{
Module
}
=
require
(
'module'
)
const
{
Module
}
=
require
(
'module'
)
// Note:
// Note:
...
@@ -687,20 +687,9 @@ export async function path_to_regexp(task, opts) {
...
@@ -687,20 +687,9 @@ export async function path_to_regexp(task, opts) {
.
target
(
'dist/compiled/path-to-regexp'
)
.
target
(
'dist/compiled/path-to-regexp'
)
}
}
export
async
function
copy_regexr_lexer
(
task
,
opts
)
{
await
task
.
source
(
join
(
relative
(
__dirname
,
dirname
(
require
.
resolve
(
'regexr/package.json'
))),
'lexer-dist/**/*'
)
)
.
target
(
'dist/compiled/regexr-lexer'
)
}
export
async
function
precompile
(
task
,
opts
)
{
export
async
function
precompile
(
task
,
opts
)
{
await
task
.
parallel
(
await
task
.
parallel
(
[
'browser_polyfills'
,
'path_to_regexp'
,
'copy_ncced'
,
'copy_regexr_lexer'
],
[
'browser_polyfills'
,
'path_to_regexp'
,
'copy_ncced'
],
opts
opts
)
)
}
}
...
...
yarn.lock
View file @
1e441fe4
...
@@ -13957,10 +13957,6 @@ regexpu-core@^4.7.1:
...
@@ -13957,10 +13957,6 @@ regexpu-core@^4.7.1:
unicode-match-property-ecmascript "^1.0.4"
unicode-match-property-ecmascript "^1.0.4"
unicode-match-property-value-ecmascript "^1.2.0"
unicode-match-property-value-ecmascript "^1.2.0"
"regexr@https://github.com/ijjk/regexr-lexer.git#3bcf3d1c4bc6dd9239c47acb1fb7b419823f8337":
version "3.8.0"
resolved "https://github.com/ijjk/regexr-lexer.git#3bcf3d1c4bc6dd9239c47acb1fb7b419823f8337"
registry-auth-token@3.3.2:
registry-auth-token@3.3.2:
version "3.3.2"
version "3.3.2"
resolved "https://registry.yarnpkg.com/registry-auth-token/-/registry-auth-token-3.3.2.tgz#851fd49038eecb586911115af845260eec983f20"
resolved "https://registry.yarnpkg.com/registry-auth-token/-/registry-auth-token-3.3.2.tgz#851fd49038eecb586911115af845260eec983f20"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment