fix: dots in island + route name not working (#2105)

This commit is contained in:
Marvin Hagemeister
2023-11-30 18:14:59 +01:00
committed by GitHub
parent a0483bc357
commit 054ffbb44a
7 changed files with 54 additions and 21 deletions
+2 -1
View File
@@ -32,6 +32,7 @@ import {
} from "./deps.ts";
import { BUILD_ID } from "./build_id.ts";
import { toBaseRoute } from "./compose.ts";
import { stringToIdentifier } from "./init_safe_deps.ts";
export const ROOT_BASE_ROUTE = toBaseRoute("/");
@@ -525,7 +526,7 @@ function toPascalCase(text: string): string {
}
function sanitizeIslandName(name: string): string {
const fileName = name.replaceAll(/[/\\\\\(\)\[\]]/g, "_");
const fileName = stringToIdentifier(name);
return toPascalCase(fileName);
}
+25
View File
@@ -7,3 +7,28 @@ export {
isIdentifierChar,
isIdentifierStart,
} from "https://esm.sh/@babel/helper-validator-identifier@7.22.20";
import {
isIdentifierChar,
isIdentifierStart,
} from "https://esm.sh/@babel/helper-validator-identifier@7.22.20";
export function stringToIdentifier(str: string): string {
let ident = "";
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i);
if (i === 0 && !isIdentifierStart(char)) {
ident += "_";
if (isIdentifierChar(char)) {
ident += str[i];
}
} else if (!isIdentifierChar(char)) {
if (ident[ident.length - 1] !== "_") {
ident += "_";
}
} else if (ident[ident.length - 1] !== "_" || str[i] !== "_") {
ident += str[i];
}
}
return ident;
}