Skip to content

Commit 8b4d1fb

Browse files
committed
Allow standalone modifiers
1 parent 0b3aba6 commit 8b4d1fb

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

src/index.spec.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,79 @@ const TESTS: Test[] = [
16981698
],
16991699
[[{ 0: "test" }, "/test"]],
17001700
],
1701+
/**
1702+
* Standalone modifiers.
1703+
*/
1704+
[
1705+
"/*",
1706+
undefined,
1707+
[
1708+
"/",
1709+
{
1710+
name: 0,
1711+
prefix: "",
1712+
suffix: "",
1713+
modifier: "",
1714+
pattern: ".*",
1715+
},
1716+
],
1717+
[
1718+
["/", ["/", ""]],
1719+
["/route", ["/route", "route"]],
1720+
["/route/nested", ["/route/nested", "route/nested"]],
1721+
],
1722+
[
1723+
[{ 0: "" }, "/"],
1724+
[{ 0: "123" }, "/123"],
1725+
],
1726+
],
1727+
[
1728+
"/+",
1729+
undefined,
1730+
[
1731+
"/",
1732+
{
1733+
name: 0,
1734+
prefix: "",
1735+
suffix: "",
1736+
modifier: "",
1737+
pattern: ".+",
1738+
},
1739+
],
1740+
[
1741+
["/", null],
1742+
["/x", ["/x", "x"]],
1743+
["/route", ["/route", "route"]],
1744+
],
1745+
[
1746+
[{ 0: "" }, null],
1747+
[{ 0: "x" }, "/x"],
1748+
[{ 0: "xyz" }, "/xyz"],
1749+
],
1750+
],
1751+
[
1752+
"/?",
1753+
undefined,
1754+
[
1755+
"/",
1756+
{
1757+
name: 0,
1758+
prefix: "",
1759+
suffix: "",
1760+
modifier: "",
1761+
pattern: ".?",
1762+
},
1763+
],
1764+
[
1765+
["/", ["/", ""]],
1766+
["/x", ["/x", "x"]],
1767+
["/route", null],
1768+
],
1769+
[
1770+
[{ 0: "" }, "/"],
1771+
[{ 0: "x" }, "/x"],
1772+
],
1773+
],
17011774

17021775
/**
17031776
* Regexps.

src/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,18 @@ export function parse(str: string, options: ParseOptions = {}): Token[] {
244244
continue;
245245
}
246246

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+
247259
tokens.consume("END");
248260
break;
249261
} while (true);

0 commit comments

Comments
 (0)