# Binder

ほとんどのJavaScriptトランスパイラはTypeScriptよりもシンプルです。コード解析の方法がほとんどないためです。典型的なJavaScriptのトランスパイラは、次のようなフローしかありません：

```typescript
SourceCode ~~Scanner~~> Tokens ~~Parser~~> AST ~~Emitter~~> JavaScript
```

上記のアーキテクチャーはTypeScriptのJS生成の単純化された理解と同じですが、TypeScriptの主な特徴は\_Semantic\_システムです。型チェック(`checker`によって実行される)を助けるために、`binder`(`binder.ts`)は、ソースコードの様々な部分を正しい型システムに接続するために使用されます。そして、`checker`により使用されます。`binder`の主な役目はSymbolの作成です。

## Symbol

シンボルは、AST内の宣言ノードを、同じエンティティに寄与する他の宣言に接続します。Symbolは、セマンティックシステムの基本的な建設部材です。Symbolコンストラクタは `core.ts`で定義されています(そして`binder`は実際に`objectAllocator.getSymbolConstructor`を使ってそれを手に入れます)。以下はSymbolコンストラクタです：

```typescript
function Symbol(flags: SymbolFlags, name: string) {
    this.flags = flags;
    this.name = name;
    this.declarations = undefined;
}
```

`SymbolFlags`はフラグ列挙型であり、Symbolの更なる分類を識別するために本当に使用されます(例えば変数スコープフラグ`FunctionScopedVariable`や `BlockScopedVariable`など)

## Checkerによる使用法

`binder`は実際に`checker`型で内部的に使用され、`checker`は`program`によって使用されます。単純化したコールスタックは次のようになります。

```
program.getTypeChecker ->
    ts.createTypeChecker (in checker)->
        initializeTypeChecker (in checker) ->
            for each SourceFile `ts.bindSourceFile` (in binder)
            // followed by
            for each SourceFile `ts.mergeSymbolTable` (in checker)
```

binderの作業単位はSourceFileです。`binder.ts`は`checker.ts`によって駆動されます。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://typescript-jp.gitbook.io/deep-dive/overview/binder.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
