/** * Naming a file inside a package. * * Stdlib files already carry a `zena:` id. Every other package resolves * to filesystem paths, and a path is not something a reader or a link * can use, so a path under the package root is rewritten to the * specifier an import would use, `/`. */ export final class Naming { #prefix: String; #root: String; new(name: String, root: String) : #prefix = modulePrefix(name), #root = root; idOf(canonical: String): String { if (canonical.startsWith(this.#prefix)) { return canonical; } let prefix = this.#root + '/'; if (canonical.startsWith(prefix)) { return this.#prefix + canonical.sliceBytes(prefix.length, canonical.length); } return canonical; } } /** * The specifier that imports `module` of the package `name`: * `zena:` in the standard library, `/` in any other * package (docs/design/import-names.md). */ export function moduleId(name: String, module: String): String { return `${modulePrefix(name)}${module}`; } function modulePrefix(name: String): String { return if (name == 'zena') 'zena:' else `${name}/`; }