fix: dots in island + route name not working (#2105)
This commit is contained in:
+2
-20
@@ -1,7 +1,4 @@
|
||||
import {
|
||||
isIdentifierChar,
|
||||
isIdentifierStart,
|
||||
} from "../server/init_safe_deps.ts";
|
||||
import { stringToIdentifier } from "../server/init_safe_deps.ts";
|
||||
import { extname, join, normalize } from "./deps.ts";
|
||||
|
||||
/**
|
||||
@@ -26,22 +23,7 @@ export function specifierToIdentifier(specifier: string, used: Set<string>) {
|
||||
if (ext) specifier = specifier.slice(0, -ext.length);
|
||||
|
||||
// Turn the specifier into a readable JS identifier
|
||||
let ident = "";
|
||||
for (let i = 0; i < specifier.length; i++) {
|
||||
const char = specifier.charCodeAt(i);
|
||||
if (i === 0 && !isIdentifierStart(char)) {
|
||||
ident += "_";
|
||||
if (isIdentifierChar(char)) {
|
||||
ident += specifier[i];
|
||||
}
|
||||
} else if (!isIdentifierChar(char)) {
|
||||
if (ident[ident.length - 1] !== "_") {
|
||||
ident += "_";
|
||||
}
|
||||
} else if (ident[ident.length - 1] !== "_" || specifier[i] !== "_") {
|
||||
ident += specifier[i];
|
||||
}
|
||||
}
|
||||
let ident = stringToIdentifier(specifier);
|
||||
|
||||
if (used.has(ident)) {
|
||||
let check = ident;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user