TypeScript/JavaScript Script Execution and Debugging
Alongside component libraries for .NET and Python-based script compilation, execution, and debugging, we provide very similar components for TypeScript/JavaScript: ScriptRun and ScriptDebugger
These components are installed on the AlterNet Scripter.TypeScript tab in Visual Studio.
Script execution is based on Microsoft ClearScript, which provides the v8 high-performance open-source JavaScript engine. It supports executing JavaScript code and accessing .NET types and objects of the host application from the script.
ScriptRun provides a very similar interface to .NET ScriptRun; the main difference is that it does not create .NET assembly and executes JavaScript code using the ClearScript engine.
The main difference in API is that, unlike .NET Script Runner, the collection of referenced objects, types and .NET assemblies is specified via HostItemsConfiguration property; as opposed to GlobalItems/References properties; RunMethod/RunMethodAsync are replaced with RunFunction/RunFunctionAsync.
The following code adds references to the most commonly used assemblies and registers RunButton to be accessible from the script:
ScriptRun can execute single files, typescript projects (which can be loaded/saved to a JSON file), or evaluate TypeScript/JavaScript expressions.
Note that order of TypeScript/JavaScript files in a project is important, as they get executed one by one.
TypeScript compilation service uses host configuration to automatically create all support files containing typescript definitions. The following line needs to be placed on top of the user's script to access .NET types and objects from the host configuration:
///<reference path="clr.d.ts" />
ScriptDebugger is based on Google Chrome debugging development tools; it allows incorporating debugging logic in the same application and does not have the limitation of the .NET debugger, which requires a debugger and script to be debugged running in the separate application processes. It has most of the functionality that the .NET Script debugger provides, except for multi-threaded debugging and automatic retrieval/evaluation of local variables.