Skip to content

Latest commit

 

History

History
33 lines (27 loc) · 1.6 KB

checker.md

File metadata and controls

33 lines (27 loc) · 1.6 KB

Checker

Like we mentioned before checker is the thing that makes TypeScript uniquely more powerful than just another JavaScript transpiler. The checker is located in checker.ts and at this moment it is 23k+ lines of TypeScript (largest part of the compiler).

Usage by Program

The checker is initialized by program. The following is a sampling of the call stack (we showed the same one when looking at binder):

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)

Association with Emitter

True type checking happens once a call is made to getDiagnostics. This function is called e.g. once a request is made to Program.emit, in which case the checker returns an EmitResolver (program calls the checkers getEmitResolver function) which is just a set of functions local to createTypeChecker. We will mention this again when we look at the emitter.

Here is the call stack right down to checkSourceFile (a function local to createTypeChecker).

program.emit ->
    emitWorker (program local) ->
        createTypeChecker.getEmitResolver ->
            // First call the following functions local to createTypeChecker
            call getDiagnostics ->
                getDiagnosticsWorker ->
                    checkSourceFile

            // then
            return resolver
            (already initialized in createTypeChecker using a call to local createResolver())