From 90a0d7b86c9852a627d0c89cf79b1f4e623b57a8 Mon Sep 17 00:00:00 2001 From: Ricci Adams Date: Sat, 6 May 2023 23:40:41 -0700 Subject: [PATCH] More Typechecker improvements (#173) --- README.md | 32 ++-- lib/api.js | 15 +- src/Compiler.js | 100 +++++------ src/Generator.js | 9 +- src/Utils.js | 18 -- src/model/NSFile.js | 20 +-- src/typechecker/Typechecker.js | 316 ++++++++++++++++++++++----------- 7 files changed, 305 insertions(+), 205 deletions(-) diff --git a/README.md b/README.md index fdb2cc9..03105b4 100644 --- a/README.md +++ b/README.md @@ -728,8 +728,6 @@ foo(1, 2, 3); // Error in TS --- -For performance reasons, we recommend a separate typechecker pass (in parallel with the main build), with `--check-types` enabled, `--output-language` set to `none`, and TypeScript type definitions (such as those found at [DefinitelyTyped](http://definitelytyped.org)) specified using the `--prepend` option. - NilScript tries to convert TypeScript error messages back into NilScript syntax. Please report any confusing error messages. --- @@ -843,8 +841,7 @@ squeeze | Object | Map of squeezed identifiers to original identifiers. See [S The `before-compile` key specifies a callback which is called prior to the compiler's NilScript->js stage. This allows you to preprocess files. The callback must return a Promise. Once the promise is resolved, a file's content must be valid NilScript or JavaScript. -The `after-compile` key specifies a callback which is called each time the compiler generates JavaScript code for a file. This allows you to run the generated JavaScript through a linter (such as [ESLint](http://eslint.org)), or allows further transformations via [Babel](https://babeljs.io). -The callback must return a Promise. When this callback is invoked, a file's content will be valid JavaScript. +The `after-compile` key specifies a callback which is called each time the compiler generates JavaScript code for a file. This allows you to run the generated JavaScript through a linter (such as [ESLint](http://eslint.org)), or allows further transformations via [Babel](https://babeljs.io). The callback must return a Promise. When this callback is invoked, a file's content will be valid JavaScript. ```javascript @@ -906,6 +903,24 @@ Note: `options.state` and `result.state` are private objects and the format/cont NilScript 2.x also adds the `symbolicate` function as API. This converts an internal NilScript identifier such as `N$_f_stringWithString_` to a human-readable string (`"stringWithString:"`). See [Squeezing and Symbolication](#squeeze) below. +-- + +To improve type checker performance, NilScript 3.x adds a `tuneTypecheckerPerformance` API: + +`nilscript.tuneTypecheckerPerformance(includeInCompileResults, workerCount)` + +Key | Type | Default | +------------------------- | -------- | ------- | +includeInCompileResults | Boolean | `true` | +workerCount | Number | `4` | + +When `includeInCompileResults` is `true`, Each call to `Compiler#compile` will wait for its associated type checker to finish. Type checker warnings are then merged with `results.warnings`. + +When `includeInCompileResults` is `false`, `Compiler#compile` will start the type checker but not wait for it to finish. Warnings are accessed via the `Promise` returned from `Compiler#collectTypecheckerWarnings`. In complex projects with several `Compiler` objects, this option can result in faster compile times. + +`workerCount` sets the number of node `worker_threads` used to run TypeScript compilers. + + --- ## Compiling Projects @@ -960,15 +975,6 @@ function doWebAppCompile(callback) { 5. Both `core.js` and `webapp.js` are included (in that order) in various HTML files via `