# CodeFileBase

CLASS in `@skmtc/core 0.63.4`

The base every language's *code* file extends - a `FileBase` that
holds definitions, imports, and re-exports. (`JsonFile`, with none of
these, extends `FileBase` directly.)

Its definitions are its `index`, the root Index every generator
reaches; the file only passes writes and reads on to it. Imports and
re-exports, and their merge policy, are the language subclass's. The
engine speaks only these four neutral operations - three writers driven by
`register`, plus `findDefinitions`, the read seam the cross-generator
cache and file inspection use. The cache resolves a single primary by name
via `findDefinitions({ name })?.[0]`.

## Signature

```ts
import { CodeFileBase } from '@skmtc/core'

abstract class CodeFileBase extends FileBase
```

## Properties

- `index` (Index): The file's content: the root Index of its definitions. Most languages use core's `FileIndex`; a language with rules of its own at the file level (one document per Markdown file) gives its own Index.

## Methods

### addDefinition

```ts
addDefinition(definition: DefinitionBase): void
```

Add a definition to the file's Index. Called by the engine's `register`.

### addImports

```ts
addImports(imports: ImportBase[]): void
```

Merge imports in, applying the language's collapse rule (typically
keyed by `ImportBase.mergeKey` and combined via
`ImportBase.merge`). Called by the engine's `register`.

### addReExports

```ts
addReExports(reExports: ReExportBase[]): void
```

Merge re-exports in, applying the language's collapse rule. Called by the
engine's `register`; a language without re-exports never receives any.

### findDefinitions

```ts
findDefinitions(query?: FindDefinitionsQuery): DefinitionBase[] | undefined
```

Query the file's definitions. With no `name`/`type` → every definition (an
array; the neutral "list all" used to inspect a file, e.g. assert the
peer-dedup invariant). With `name` and/or `type` → the matching subset, or
`undefined` when nothing matches. `type` is the declaration type as the
opaque `string`.
