method ReplSession.whereFrom
ReplSession.whereFrom(name: string): string | null

Where a name came into this session from — the file it was imported from, or the input that declared it. null for a name the page already had, and for anything that is not a bare name.

What ReplSession.declaredAt cannot answer: V8 knows the source of functions and of nothing else, while this session watched every other name arrive. Without it, .doc on the string, the number or the imported namespace you just brought in says nothing at all — which is most of what a prompt is asked about.

Synchronous, because the session already knows: it is a lookup in what it recorded, not a question for the page.

import type { ReplSession } from './session.ts';

// Defined, not invoked: a real session owns a browser and a bound port.
function whereFrom(session: ReplSession) {
  session.whereFrom('GREETING'); // 'test/fixtures/repl-helpers.ts'
  session.whereFrom('answer'); // 'line 1' — declared at the prompt, not in a file

  return session.whereFrom('document'); // null — the page already had it
}

Parameters

name: string

Return Type

string | null

Usage

import { type ReplSession } from "lib/repl/session.ts";