Design stratification

Each of the following components corresponds to a file or directory:

src/compiler

  • Parser. Ts: Parser: Source code → AST
  • Ts: Binder: Use Symbol to collect type information,
  • Checker. Ts: Type Resolver/Checker: Resolves the Type of each structure, checks semantic operations, and generates diagnostic information as needed
  • Emitter. Ts: Emitter code generator: Generates JS, D.ts, map files
  • Pre-processor:program.ts ??: Iterates through all input files, passingimportand/// <reference path>Build the Reference graph to produce an ordered list of source files.

src/tsc

  • Standalone Compiler (TSC) : Command line compiler

/ SRC/TSC/TSC. Ts only on SRC/executeCommandLine/executeCommandLine ts simple packaging ExecuteCommandLine. Ts executeCommandLine(…) :

ExecuteCommandLine () -> executeCommandLineWorker() -> reportDiagnostic = createDiagnosticReporter() // DiagnosticReporter -> options = parseConfigFileWithSystem () / / parsing configuration - > performCompilation (options, Program = createProgram(options) // createProgram -> EmitFilesAndReportErrorsAndGetExitStatus (program) / / output file; An errorCopy the code

src/services

  • Language Service Language Service

src/tsserver

  • Standalone Server

TypeScript source

The root directory

├─ bin # Includes TSC and TSServer command lines ├─ Built /local # ├─ doc # Document ├─ lib #LKG typescript ├─ Loc # Localised ├─ scripts ├─ SRC # ├─ exercises # 9 directoriesCopy the code

SRC directory

# Core ├── Compiler ├─ TSC ├─ executeCommandLine ├─ Services ├─ Shims ├─ deprecatedCompat # Deprecation And Compatibility # TS # School Exercises for TsServer # School Exercises for TsServer # School Exercises for TsServer # School Exercises for TsServer # School Exercises for TsServer # School Exercises for TsServer # School Exercises for TsServer Ts. The web server mode ├ ─ ─ # ts server. The server node model # ts. The server typingsInstaller ├ ─ ─ typingsInstaller # Ts. Server. TypingsInstaller ├ ─ ─ typingsInstallerCore # *. Which s ├ ─ ─ lib built-in type declaration # localization ├ ─ ─ loc # other (with the namespace) ├ ─ ─ ├─ How to play guitar, how to play guitar, how to play guitar, how to play guitar watchGuardCopy the code

SRC/compiler directory

4 directories, 70 files

# configuration├ ─ ─ tsconfig. Json ├ ─ ─ tsconfig. The json# Infrastructure and tool code├ ─ ─ core. Ts ├ ─ ─ corePublic. Ts ├ ─ ─ the debug. Ts ├ ─ ─ path. The ts ├ ─ ─ sys. Ts ├ ─ ─ tracing. The ts ├ ─ ─ utilities. The ts ├ ─ ─ utilitiesPublic. Ts └ ─ Semver. Ts └ ─ Sourcemap. Ts └ ─ commandLineParser# Core componentsSchool Exercises ─ Program. School Exercises ─ Types. School Exercises ─ Scanner. School Exercises ─ Parser BuilderPublic. ├─ builderState ├─ builderStatePublic# diagnosis├ ─ ─ diagnosticInformationMap. Generated. Ts ├ ─ ─ diagnosticMessages. Generated. The json ├ ─ ─ diagnosticMessages. Json# performanceBass Exercises ── Bass Exercises for performance.Ts# tsbuild├ ─ ─ tsbuild. Ts ├ ─ ─ tsbuildPublic. Ts# walker&visitor├ ─ ─ symbolWalker. Ts ├ ─ ─ visitorPublic. Ts# watchBass Exercises ── Watch. Bass Exercises ── Bass Exercises# module parsingBass Exercises ── Bass Exercises for moduleNameResolver. Ts Bass Exercises ─ Modulespecial. ts Bass Exercises ─ resolutionCache# Node factory├ ─ ─ factory │ ├ ─ ─ baseNodeFactory. Ts │ ├ ─ ─ emitHelpers. Ts │ ├ ─ ─ emitNode. Ts │ ├ ─ ─ nodeConverters. Ts │ ├ ─ ─ nodeFactory. Ts │ ├─ Heavy Exercises. │ ├─ Utilities. │ ├─ utilitiesPublic# Transformer├ ─ ─ transformer. Ts └ ─ ─ transformers ├ ─ ─ classFields. Ts ├ ─ ─ declarations │ └ ─ ─ diagnostics. Ts ├ ─ ─ declarations. Ts ├ ─ ─ Bass Exercises ── Es2015. Bass Exercises ── ES2016. Bass Exercises ── ES2017. Bass Exercises ── ES2019 Esnext. Ts ├ ─ ─ generators. Ts ├ ─ ─ JSX. Ts ├ ─ ─ the module │ ├ ─ ─ esnextAnd2015. Ts │ ├ ─ ─ the module. The ts │ └ ─ ─ system. Ts ├ ─ ─ ├── ├─ exercises. TaggedTemplateCopy the code

SRC/tsserver directory

├ ─ ─ for server ts ├ ─ ─ nodeServer. Ts # reference SRC/server └ ─ ─ webServer. Ts # reference SRC/webServerCopy the code

In server.ts, start nodeServer or webServer based on the environment.

if (node env) {
  start(initializeNodeSystem(), platform);
} else {
  start(initializeWebSystem(), 'web');
}

initializeNodeSystem()
  -> startNodeSession()
    -> new IoSession().listen() # IoSession extends ts.server.Session
    
initializeWebSystem()
  -> startWebSession()
    -> new WorkerSession.listen() # src/webServer/ ts.server.WorkerSession
Copy the code

The main tsServer code is still in SRC/Server. Servers communicate through websockets. The communication protocol is defined in SRC /server/protocol.ts. The build will result in lib/protocol.d.ts.

The SRC/directory server

.School exercises ── School Exercises. School Exercises ── School Exercises. School Exercises ── School Exercises ScriptVersionCache. Ts # types ├ ─ ─ types. The ts ├ ─ ─ typesMap. Json ├ ─ ─ typingsCache. Ts ├ ─ ─ watchType. Ts # tool ├ ─ ─ utilities. The ts └ ─ ─ utilitiesPublic. TsCopy the code

Core data structure

  • Node
  • SourceFile
  • Program
  • Symbol
  • Type
  • Signature

The build process

TODO:

build

The entire TypeScript project is built through a series of Gulp tasks.

Question: TSC itself is written in TS, so how is tsc.js compiled? A: The normal language development process is to first develop a compiler in another language. When the language is sufficient to write a compiler, implement the editor in the language itself. This process is called “Bootstrap.” So, the first tsc.js should be written in JS. But in the

The default task

# Default
default                         Runs 'local'
Copy the code

Build tasks

# Build local Builds the full compiler and services ⭐️ TSC Builds the command-line compiler ⭐️ services Builds the Language service ⭐️ tsServer Builds the language server ⭐️ scripts Builds files in the 'scripts' folder The Library targets ⭐️ min Builds only TSC and TSServer ⭐️ LSSL Builds language Service Server library port tests Builds the test infrastructure other-outputs Builds miscelaneous scripts and documents distributed with the LKG ??? tsc-instrumented Builds an instrumented tsc.js build-eslint-rules Compiles eslint rules to js LKG Makes a new LKG out of  the built js files baseline-accept Makes the most recent test results the new baseline, overwriting the old baseline baseline-accept-rwc Makes the most recent rwc test results the new baseline, overwriting the old baselineCopy the code

LKG = Last Known Good. TypeScript published to NPM is the LKG version from the lib directory. The LKG version of Typecript is generated by the gulp LKG task. This is why there is a lib directory in TS source code.

lssl=Language Service Server Library

generate

# Generate
generate-diagnostics            Generates a diagnostic file in TypeScript based on an input JSON file
generate-code-coverage          Generates code coverage data via istanbul
generate-spec                   Generates a Markdown version of the Language Specification
Copy the code

Watch mode

# Watch watch Watches for changes and rebuilds and runs tests in parallel. watch-tsc Watch for changes and rebuild the Command-line compiler only. ⭐️ watch-tsserver Watch for changes and rebuild the language server only ⭐️ watch-lssl watch For changes and rebuild tsServerlibrary only ⭐️ watch-services Watches for changes and rebuild language service only ⭐️  watch-min Watches for changes to a tsc and tsserver only watch-local Watches for changes to projects in src/ (but does Not the execute tests). ⭐ ️Copy the code

Clean up the output

# Clean clean Cleans build outputs clean-tsc Cleans outputs for the command-line compiler clean-services Cleans outputs for the language service clean-tsserver Cleans outputs for the language server clean-min Cleans outputs for tsc and tsserver clean-tests Cleans the outputs for the test infrastructure clean-eslint-rules Cleans the outputs for the eslint  rules clean-lssl Clean outputs for the language service server libraryCopy the code

Running various scripts

# Runs scripts ## eslint related run-eslint-rules-tests Runs the ESlint rule tests lint-scripts Runs eslint on the scripts Sources.lint - Compiler Runs eslint on the compiler sources. Lint Runs eslint on the compiler and scripts sources. ## Test runtests Runs the tests using the built run.js file. runtests-parallel Runs all the tests in parallel using the built run.js file. test-browser-integration Runs scripts/browserIntegrationTest.ts which tests that typescript.js loads in a browser importDefinitelyTypedTests Runs the importDefinitelyTypedTests script to copy DT's tests to the TS-internal RWC Tests # # to generate the configure to build configuration file - the nightly Runs scripts/configurePrerelease. Ts to prepare a build for the nightly publishing configure-insiders Runs scripts/configurePrerelease.ts to prepare a build for insiders publishing configure-experimental  Runs scripts/configurePrerelease.ts to prepare a build for experimental publishing create-language-services-build Runs To prepare a build scripts/createLanguageServicesBuild. Ts which only has the require (' typescript) JS. # # publish-nightly Runs `npm publish --tag next` to create a new nightly build on npmCopy the code

Diff

# Diff diff Diffs the compiler baselines using the diff tool specified by the 'DIFF' environment variable diff-rwc Diffs  the RWC baselines using the diff tool specified by the 'DIFF' environment variableCopy the code

other

# Misc
update-sublime                  Updates the sublime plugin's tsserver
generate-types-map
Copy the code

Build output

Build the entire project by running NPM run gulp. The built/local directory is generated in the project directory. It contains some *.tsBuildinfo files. This file describes the build information for the corresponding JS file. SourceFiles lists the TS files from which JS is built.

Question: How is this LIST of Ts generated? How does this tsBuildinfo file relate to tsbuild.ts? Guess: the list should come from the files field corresponding to tsconfig.json and then be built by parsing tsconfig with tsBuild.

Cs ├ # localization ├ ─ ─ ─ ─ DE ├ ─ ─ emu. LCG ├ ─ ─ es ├ ─ ─ fr ├ ─ ─ it ├ ─ ─ ja ├ ─ ─ ko ├ ─ ─ pl ├ ─ ─ pt - br ├ ─ ─ ru ├ ─ ─ the tr ├ ─ ─ useful - cn ├ ─ ─ useful - tw # Built-in types defined ├ ─ ─ lib. Which s ├ ─ ─ lib. The dom, which s ├ ─ ─ lib. Dom. Iterable. Which s ├ ─ ─ lib. Es2015. Collections. Which s ├ ─ ─ lib. Es2015. Core. Which s ├ ─ ─ lib. Es2015. Which s ├ ─ ─ lib. Es2015. The generator, which s ├ ─ ─ lib. Es2015. Iterable. Which s ├ ─ ─ lib. Es2015. Promise. Which s ├ ─ ─ Lib. Es2015. Proxy. Which s ├ ─ ─ lib. Es2015. Reflect. Which s ├ ─ ─ lib. Es2015. The symbol, which s ├ ─ ─ lib. Es2015. Symbol. Wellknown. Which s ├ ─ ─ Lib. Es2016. Array. An include. Which s ├ ─ ─ lib. Es2016. Which s ├ ─ ─ lib. Es2016. Full, which s ├ ─ ─ lib. Es2017. Which s ├ ─ ─ lib. Es2017. Full. Which s ├ ─ ─ lib. Es2017. Intl. Which s ├ ─ ─ lib. Es2017. Object. Which s ├ ─ ─ lib. Es2017. Sharedmemory. Which s ├ ─ ─ lib. Es2017. String. Which s ├ ─ ─ Lib. Es2017. Typedarrays. Which s ├ ─ ─ lib. Es2018. Asyncgenerator. Which s ├ ─ ─ lib. Es2018. Asynciterable. Which s ├ ─ ─ lib. Es2018. Which s ├ ─ ─ Lib.es2018.full.d.Bass Exercises ── Lib.es2018.intl.d.Bass Exercises ── lib.es2018.promise.d.Bass Exercises ── Lib.es2018.regexp Lib.es195.array. D.bass Exercises ── Lib.es195.d.Bass Exercises ─ lib.es195.d.Bass Exercises ─ lib.es195.d.Bass Exercises ─ lib.es195.d.Bass Exercises ─ Lib.es195.d.Bass Exercises ─ Lib.es195.d.Bass Exercises ─ Lib.es195.d.Bass Exercises ─ Lib.es195.d.Bass Exercises ─ Lib.es195.d.Bass Exercises ├── Lib.es209.symbol.d.Bass Exercises ─ lib.es209.d.Bass Exercises ── Lib.es209.d.Bass Exercises ── Lib.es209.d.Bass Exercises ── Lib.es209.d.Bass Exercises ── Lib.es209.d.Bass Exercises ── Lib.es209.d.Bass Exercises ── Lib. Es2020. Intl. Which s ├ ─ ─ lib. Es2020. Promise. Which s ├ ─ ─ lib. Es2020. Sharedmemory. Which s ├ ─ ─ lib. Es2020. String. Which s ├ ─ ─ Lib. Es2020. Symbol. Wellknown. Which s ├ ─ ─ lib. Es5. Which s ├ ─ ─ lib. Es6. Which s ├ ─ ─ lib. Esnext. Which s ├ ─ ─ lib. Esnext. Full, which s ├ ─ ─ Lib.esnext.intl.d.Bass Exercises ─ lib.esnext.Promise.d.Bass Exercises ─ lib.esNext.string.d.Bass Exercises ─ lib.esNext.weakRef.d.Bass Exercises ── Lib. Scripthost. Which s ├ ─ ─ lib. Webworker. Which s ├ ─ ─ lib. Webworker. Importscripts. Which s ├ ─ ─ lib. Webworker. Iterable. Which s # diagnostic information ├ ─ ─ diagnosticMessages. Generated. Json ├ ─ ─ cancellationToken. Js (cancellationToken. Js. Map) # typescript ├ ─ ─ D.ts # TSC ├─ Tsc.js (tsc.js.map) ├─ typescript.js (tsc.js.map) ├─ typescript.js (tsc.js.map) ├─ typescript.js (tsc.js.map) ├─ TSC. Tsbuildinfo ├ ─ ─ executeCommandLine. Which s (executeCommandLine. Which s.m ap) ├ ─ ─ ExecuteCommandLine. Js (executeCommandLine. Js. Map) ├ ─ ─ executeCommandLine. # tsbuildinfo tsserver ├ ─ ─ Flag School for TsServer.js (tsserver.js.map) flag School ── Flag School for TSServer.d.ts (Server.d.ts) Flag School ── Flag School for TSServer.js (tsserver.js.map) Flag School ── Flag School for TSServer.d.ts (Server.d.ts) Flag School ── .js (server.js.map) ├──.tsbuildinfo # Services ├── Services.d.ts (Services.d.ts) ├── Services.js (services.js.map) ├── Services.tsBuildinfo # Compiler ├── Compiler.d.ts (Compiler.d.ts) ├── Compiler. Js (compiler.js.map) ├── Compiler.tsbuildinfo ├── Compiler-debug. Js (compiler-debug # compiler - debug. Tsbuildinfo deprecatedCompat ├ ─ ─ deprecatedCompat. Which s (deprecatedCompat. Which s.m ap) ├ ─ ─ DeprecatedCompat. Js (deprecatedCompat. Js. Map) ├ ─ ─ deprecatedCompat. # tsbuildinfo jsTyping ├ ─ ─ D.ts (jstyping.d.ts) ├── Jstyping.js (jstyping.js.map) ├── Jstyping.tsbuildinfo # Shims ├── S (shims.d.MAP.) ├── Shims.js (Shims.js.map) ├─ Shims.tsBuildinfo # TsServerLibrary.d.TS ├── TsServerLibrary.js (tsServerLibrary.js.map) ├─ TsServerLibrary.out.d.Bass Exercises ── Tsserverlibrary. Out. Js (tsserverlibrary. Out. Js. Map) ├ ─ ─ tsserverlibrary. Out. Tsbuildinfo #??? ├ ─ ─ typesMap. Json ├ ─ ─ TypescriptServices. Which s ├ ─ ─ typescriptServices. Js (typescriptServices. Js. Map) ├ ─ ─ typescriptServices. Out. Which s ├ ─ ─ TypescriptServices. Out. Js (typescriptServices. Out. Js. Map) ├ ─ ─ typescriptServices. Out. Tsbuildinfo ├ ─ ─ TypingsInstaller. Js (typingsInstaller. Js. Map) ├ ─ ─ typingsInstaller. Tsbuildinfo ├ ─ ─ TypingsInstallerCore. Which s (typingsInstallerCore. Which s.m ap) ├ ─ ─ typingsInstallerCore. Js (typingsInstallerCore. Js. Map) ├ ─ ─ TypingsInstallerCore. Tsbuildinfo ├ ─ ─ watchGuard. Js (watchGuard. Js. Map) ├ ─ ─ webServer. Which s (webServer. Which s.m ap) ├ ─ ─ WebServer. Js (webServer. Js. Map) └ ─ ─ webServer. TsbuildinfoCopy the code

Refer to the link

  • Github.com/microsoft/T…