Skip to content

Commit 246ec9f

Browse files
committed
Standalone modifiers act like unnamed params
1 parent 8b4d1fb commit 246ec9f

File tree

2 files changed

+22
-33
lines changed

2 files changed

+22
-33
lines changed

src/index.spec.ts

+19-19
Original file line numberDiff line numberDiff line change
@@ -1705,69 +1705,69 @@ const TESTS: Test[] = [
17051705
"/*",
17061706
undefined,
17071707
[
1708-
"/",
17091708
{
17101709
name: 0,
1711-
prefix: "",
1710+
prefix: "/",
17121711
suffix: "",
1713-
modifier: "",
1714-
pattern: ".*",
1712+
modifier: "*",
1713+
pattern: "[^\\/#\\?]+?",
17151714
},
17161715
],
17171716
[
1718-
["/", ["/", ""]],
1717+
["/", ["/", undefined]],
17191718
["/route", ["/route", "route"]],
17201719
["/route/nested", ["/route/nested", "route/nested"]],
17211720
],
17221721
[
1723-
[{ 0: "" }, "/"],
1724-
[{ 0: "123" }, "/123"],
1722+
[{ 0: null }, ""],
1723+
[{ 0: "x" }, "/x"],
1724+
[{ 0: ["a", "b", "c"] }, "/a/b/c"],
17251725
],
17261726
],
17271727
[
17281728
"/+",
17291729
undefined,
17301730
[
1731-
"/",
17321731
{
17331732
name: 0,
1734-
prefix: "",
1733+
prefix: "/",
17351734
suffix: "",
1736-
modifier: "",
1737-
pattern: ".+",
1735+
modifier: "+",
1736+
pattern: "[^\\/#\\?]+?",
17381737
},
17391738
],
17401739
[
17411740
["/", null],
17421741
["/x", ["/x", "x"]],
17431742
["/route", ["/route", "route"]],
1743+
["/a/b/c", ["/a/b/c", "a/b/c"]],
17441744
],
17451745
[
17461746
[{ 0: "" }, null],
17471747
[{ 0: "x" }, "/x"],
1748-
[{ 0: "xyz" }, "/xyz"],
1748+
[{ 0: "route" }, "/route"],
1749+
[{ 0: ["a", "b", "c"] }, "/a/b/c"],
17491750
],
17501751
],
17511752
[
17521753
"/?",
17531754
undefined,
17541755
[
1755-
"/",
17561756
{
17571757
name: 0,
1758-
prefix: "",
1758+
prefix: "/",
17591759
suffix: "",
1760-
modifier: "",
1761-
pattern: ".?",
1760+
modifier: "?",
1761+
pattern: "[^\\/#\\?]+?",
17621762
},
17631763
],
17641764
[
1765-
["/", ["/", ""]],
1765+
["/", ["/", undefined]],
17661766
["/x", ["/x", "x"]],
1767-
["/route", null],
1767+
["/route", ["/route", "route"]],
17681768
],
17691769
[
1770-
[{ 0: "" }, "/"],
1770+
[{ 0: undefined }, ""],
17711771
[{ 0: "x" }, "/x"],
17721772
],
17731773
],

src/index.ts

+3-14
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,9 @@ export function parse(str: string, options: ParseOptions = {}): Token[] {
190190
const char = tokens.tryConsume("CHAR");
191191
const name = tokens.tryConsume("NAME");
192192
const pattern = tokens.tryConsume("PATTERN");
193+
const modifier = tokens.tryConsume("MODIFIER");
193194

194-
if (name || pattern) {
195+
if (name || pattern || modifier) {
195196
let prefix = char || "";
196197

197198
if (prefixes.indexOf(prefix) === -1) {
@@ -209,7 +210,7 @@ export function parse(str: string, options: ParseOptions = {}): Token[] {
209210
prefix,
210211
suffix: "",
211212
pattern: pattern || defaultPattern,
212-
modifier: tokens.tryConsume("MODIFIER") || "",
213+
modifier: modifier || "",
213214
});
214215
continue;
215216
}
@@ -244,18 +245,6 @@ export function parse(str: string, options: ParseOptions = {}): Token[] {
244245
continue;
245246
}
246247

247-
const modifier = tokens.tryConsume("MODIFIER");
248-
if (modifier) {
249-
result.push({
250-
name: key++,
251-
prefix: "",
252-
suffix: "",
253-
pattern: `.${modifier}`,
254-
modifier: "",
255-
});
256-
continue;
257-
}
258-
259248
tokens.consume("END");
260249
break;
261250
} while (true);

0 commit comments

Comments
 (0)