UNPKG

tstosc

Version:

A transpiler that convert TypeScript to SuperCollider's SCLang.

67 lines (64 loc) 3.08 kB
import ts from 'typescript'; import { GeneratorContext } from './context.js'; import '../../cli/args.js'; /** * This scans the variable/constant defined in this scope, and output the SCLang code as string. * * In variable statement. * * Identifier in `for` or `while` statement. * * Note that due to SCLang's settings, class should be defined beforehand in specific files. * For processing class, see `extractClassDeclarationAndDefinition`. */ declare function generateVarConstDeclarationAndDefinition(node: ts.BlockLike, generator_context?: GeneratorContext): string; /** * This scans the variable/constant defined in this scope, and output them in an object. * * In variable statement. * * Identifier in `for` or `while` statement. * * Note that due to SCLang's settings, class should be defined beforehand in specific files. * For processing class, see `extractClassDeclarationAndDefinition`. */ declare function extractVarConstDeclarationAndDefinition(node: ts.BlockLike, generator_context?: GeneratorContext): { lets: DefDeclCollection; consts: DefDeclCollection; vars: DefDeclCollection; loopvars: DefDeclCollection; functions: DefDeclCollection; }; /** * ### Generate Context Relationship * * * `indent_level` (`is_standalone_statement`): * This function generate a whole statement. * If the statement is explicitly stand-alone, indent will be generated. * * ### Warning * * * If self-indecr happens in the initialisation, skip it, initialise after. * (since `var` declaration cannot after global-variables assignment.s) */ declare function getDefDeclOutput(type: "let" | "const" | "var" | "param" | "loopvar" | "function" | "catchvar", collection: DefDeclCollection, generator_context?: GeneratorContext): string; /** * Check if a initialiser can be directly put after hoisted var declaration, * or if it contains things such as self-indecr operator that need to be converted later. */ declare function isAfterwhileInitInitialiser(v: ts.Expression): boolean; type DefDeclCollection = [ts.Identifier["text"], ts.VariableDeclaration["initializer"]][]; /** * Recursion solver for the array-binding or object-binding. * * Pair the name and the value, and add to the `collection` * (in function `extractNameDeclarationAndDefinition`). * * Example: * ```ts * let [d,[e,f]]=[0,[1,2]] * let obj={l:1,x:{m:2,n:3}} * let {l,x:{m,n}}=obj * ``` */ declare function solveRecurBinding(pattern: ts.BindingName, initialiser: ts.AssignmentPattern | ts.Identifier | ts.Expression): DefDeclCollection; declare function isLetDeclarationList(decl_list: ts.VariableDeclarationList): boolean; declare function isConstDeclarationList(decl_list: ts.VariableDeclarationList): boolean; declare function isVarDeclarationList(decl_list: ts.VariableDeclarationList): boolean; export { type DefDeclCollection, extractVarConstDeclarationAndDefinition, generateVarConstDeclarationAndDefinition, getDefDeclOutput, isAfterwhileInitInitialiser, isConstDeclarationList, isLetDeclarationList, isVarDeclarationList, solveRecurBinding };