/* Copyright 2026 Marimo. All rights reserved. */ import type { CellId } from "@/core/cells/ids"; /** * The marimo compiler rewrites underscore-prefixed references inside a cell * (which Python would treat as module-private) into `_cell__` * so each cell gets its own private namespace. When such a reference fails at * runtime (`NameError: name '_cell_Hbol_a' is not defined`), the mangled name * leaks into the error UI. These helpers undo that mangling for display. * * Mirrors `marimo/_ast/variables.py`. */ // Matches `_cell_` for normal ids and UUIDs. The `[\w-]` // id class admits hyphens; the `_\w*` name group admits the bare `_` // local; the `(? lastIndex) { segments.push(text.slice(lastIndex, match.index)); } segments.push({ cellId: match[1] as CellId, name: match[2] }); lastIndex = match.index + match[0].length; match = GLOBAL_RE.exec(text); } if (lastIndex < text.length) { segments.push(text.slice(lastIndex)); } return segments; } export function containsMangledLocal(text: string): boolean { return UNANCHORED_RE.test(text); }