vite-plugin-remix-routes
vite-plugin-remix-routes copied to clipboard
Some route names do not parse correctly
I tried this module out and got an error on some files names:
Unexpected token
file: virtual:remix-routes:2:25
import RoutesApiMigration[name] from './src/routes/api/migration/[name].ts';
import RoutesApiDo-migrate from './src/routes/api/do-migrate.ts';
Actually I am planning to rename [name].ts
to $name.ts
but it would be nice if it could compile anyways. I think hyphens are used a lot in regular urls too.
Here are the restrictions for variable names according to MDN:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#variables
Maybe this function needs to be improved:
function getRouteComponentName(route: Route) {
return route.id
.split(/[/.]/)
.map((str) => str.replace(/^\w/, (c) => c.toUpperCase()))
.join("");
}
A really basic fix could be to just strip all non-word characters or replace with a character like _
, eg:
str.replace(/\W/g, '_')
Or, splitting on these non-word characters may be more aesthetic:
- .split(/[/.]/)
+ .split(/[/.\W]/)