testLocalNamesAreAlphaRenamable
Local names are alpha-renamable unless they become a runtime name.
import { hashes } from "#codebase/tcmts/core/test/hash"; import assert from "node:assert/strict"; export const testLocalNamesAreAlphaRenamable = () => { // parameters and plain locals: renaming is invisible assert.equal(hashes(`const f = (x: number) => { const y = x + 1; return y }`).f, hashes(`const f = (a: number) => { const b = a + 1; return b }`).f); // local function names, and bindings that name an anonymous function, are visible through .name assert.notEqual(hashes(`function outer() { function a() {} return a }`).outer, hashes(`function outer() { function b() {} return b }`).outer); assert.notEqual(hashes(`const f = () => { const g = () => 1; return g }`).f, hashes(`const f = () => { const h = () => 1; return h }`).f); assert.notEqual(hashes(`const f = (cb = () => 1) => cb`).f, hashes(`const f = (fn = () => 1) => fn`).f); assert.notEqual(hashes(`const f = () => { let g; g = () => 1; return g }`).f, hashes(`const f = () => { let h; h = () => 1; return h }`).f); }