MCPcopy
hub / github.com/sveltejs/svelte / get_relative_path

Function get_relative_path

packages/svelte/src/compiler/utils/mapped_code.js:423–437  ·  view source on GitHub ↗

* @param {string} from * @param {string} to

(from, to)

Source from the content-addressed store, hash-verified

421 * @param {string} to
422 */
423function get_relative_path(from, to) {
424 // Don't use node's utils here to ensure the compiler is usable in a browser environment
425 const from_parts = from.split(/[/\\]/);
426 const to_parts = to.split(/[/\\]/);
427 from_parts.pop(); // get dirname
428 while (from_parts[0] === to_parts[0]) {
429 from_parts.shift();
430 to_parts.shift();
431 }
432 if (from_parts.length) {
433 let i = from_parts.length;
434 while (i--) from_parts[i] = '..';
435 }
436 return from_parts.concat(to_parts).join('/');
437}
438
439/**
440 * Like node's `basename`, but doesn't use it to ensure the compiler is usable in a browser environment

Callers 2

get_source_nameFunction · 0.85

Calls 2

popMethod · 0.80
concatMethod · 0.80

Tested by

no test coverage detected