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

Method unique

packages/svelte/src/compiler/phases/scope.js:891–912  ·  view source on GitHub ↗

* @param {string} preferred_name

(preferred_name)

Source from the content-addressed store, hash-verified

889 * @param {string} preferred_name
890 */
891 unique(preferred_name) {
892 preferred_name = preferred_name.replace(/[^a-zA-Z0-9_$]/g, '_');
893 let n = this.#name_counters.get(preferred_name) ?? 0;
894 let final_name;
895
896 if (n === 0) {
897 final_name = preferred_name;
898 n = 1;
899 } else {
900 final_name = `${preferred_name}_${n}`;
901 n++;
902 }
903
904 while (this.conflicts.has(final_name)) {
905 final_name = `${preferred_name}_${n++}`;
906 }
907
908 this.#name_counters.set(preferred_name, n);
909 this.conflicts.add(final_name);
910 const id = b.id(final_name);
911 return id;
912 }
913}
914
915/**

Callers 8

migrateFunction · 0.80
EachBlockFunction · 0.80
EachBlockFunction · 0.80
VariableDeclarationFunction · 0.80
transform_templateFunction · 0.80
EachBlockFunction · 0.80
mark_async_declarationFunction · 0.80
BindDirectiveFunction · 0.80

Calls 4

setMethod · 0.65
getMethod · 0.45
hasMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected