TypeScript Deep Dive
  • README
  • 시작하기
    • 왜 타입스크립트인가
  • 자바스크립트
    • 비교 연산자
    • 참조 연산자
    • Null vs. Undefined
    • this
    • 클로저
    • Number
    • Truthy
  • 미래의 자바스크립트
    • 클래스
      • 즉시실행함수
    • 화살표 함수
    • 나머지 연산자
    • let
    • const
    • 비구조화 할당
    • 전개 연산자
    • for...of
    • 이터레이터
    • 템플릿 리터럴
    • 프로미스
    • 제네레이터
    • Async Await
  • 프로젝트
    • 컴파일러 제어
      • tsconfig.json
      • 파일 경로 지정
    • 선언
    • 모듈화
      • 파일을 이용한 모듈화
      • globals.d.ts
    • 네임스페이스
    • 동적 표현식 가져오기
  • Node.js 시작하기
  • Browser 시작하기
  • 타입스크립트 타입 시스템
    • 자바스크립트 마이그레이션 가이드
    • @types
    • 주변 선언
      • 파일 선언
      • 변수
    • 인터페이스
    • 열거형(Enums)
    • lib.d.ts
    • 함수
    • 콜러블(Callable)
    • 타입 표명(Type Assertion)
    • 신선도(Freshness)
    • 타입 가드
    • 리터럴(Literal)
    • 읽기 전용(readonly)
    • 제네릭
    • 타입 인터페이스
    • 타입 호환성
    • Never 타입
    • 구별된 유니온
    • 인덱스 서명(Index Signature)
    • 타입 이동하기
    • 예외 처리
    • 믹스인(Mixin)
  • JSX
    • React
    • Non React JSX
  • Options
    • noImplicitAny
    • strictNullChecks
  • 타입스크립트 에러
    • 에러 메세지
    • 공통 에러
  • NPM
  • 테스트
    • Jest
    • Cypress
  • Tools
    • Prettier
    • Husky
    • ESLint
    • Changelog
  • 팁
    • 문자열 Enums
    • 타입 단언
    • 상태 저장 함수
    • 커링
    • 제네릭 타입 예시
    • 객체 타입 설정
    • 유용한 클래스
    • Import / Export
    • 속성 Setters
    • outFile 주의사항
    • 제이쿼리 팁
    • 정적 생성자
    • 싱글톤 패턴
    • 함수 파라미터
    • 토글 생성
    • Import 여러개 하기
    • 배열 생성
    • 생성자에서 타입정의
  • 스타일 가이드
  • 타입스크립트 컴파일러 구조
    • Program
    • AST
      • TIP: Visit Children
      • TIP: SyntaxKind enum
      • Trivia
    • Scanner
    • Parser
      • Parser Functions
    • Binder
      • Binder Functions
      • Binder Declarations
      • Binder Container
      • Binder SymbolTable
      • Binder Error Reporting
    • Checker
      • Checker Diagnostics
      • Checker Error Reporting
    • Emitter
      • Emitter Functions
      • Emitter SourceMaps
    • Contributing
Powered by GitBook
On this page
  • Syntax vs. Semantics
  • Processing Overview
  • File: Utilities
  • File: Key Data Structures
  • File: System

Was this helpful?

타입스크립트 컴파일러 구조

Previous스타일 가이드NextProgram

Last updated 3 years ago

Was this helpful?

The TypeScript compiler source is located under the folder.

It is split into the follow key parts:

  • Scanner (scanner.ts)

  • Parser (parser.ts)

  • Binder (binder.ts)

  • Checker (checker.ts)

  • Emitter (emitter.ts)

Each of these get their own unique files in the source. These parts will be explained later on in this chapter.

Syntax vs. Semantics

Just because something is syntactically correct doesn't mean it is semantically correct. Consider the following piece of TypeScript code which although syntactically valid is semantically wrong

var foo: number = "not a number";

Semantic means "meaning" in English. This concept is useful to have in your head.

Processing Overview

The following is a quick review of how these key parts of the TypeScript compiler compose:

SourceCode ~~ scanner ~~> Token Stream
Token Stream ~~ parser ~~> AST
AST ~~ binder ~~> Symbols

Symbol is the primary building block of the TypeScript semantic system. As shown the symbols are created as a result of binding. Symbols connect declaration nodes in the AST to other declarations contributing to the same entity.

Symbols + AST are what is used by the checker to semantically validate the source code

AST + Symbols ~~ checker ~~> Type Validation

Finally When a JS output is requested:

AST + Checker ~~ emitter ~~> JS

There are a few additional files in the TypeScript compiler that provide utilities to many of these key portions which we cover next.

File: Utilities

core.ts : core utilities used by the TypeScript compiler. A few important ones:

  • let objectAllocator: ObjectAllocator : is a variable defined as a singleton global. It provides the definitions for getNodeConstructor (Nodes are covered when we look at parser / AST), getSymbolConstructor (Symbols are covered in binder), getTypeConstructor (Types are covered in checker), getSignatureConstructor (Signatures are the index, call and construct signatures).

File: Key Data Structures

types.ts contains key data structures and interfaces uses throughout the compiler. Here is a sampling of a few key ones:

  • SyntaxKind

    The AST node type is identified by the SyntaxKind enum.

  • TypeChecker

    This is the interface provided by the TypeChecker.

  • CompilerHost

    This is used by the Program to interact with the System.

  • Node

    An AST node.

File: System

system.ts. All interaction of the TypeScript compiler with the operating system goes through a System interface. Both the interface and its implementations (WScript and Node) are defined in system.ts. You can think of it as the Operating Environment (OE).

Now that you have an overview of the major files, we can look at the concept of Program

src/compiler