tstosc
Version:
A transpiler that convert TypeScript to SuperCollider's SCLang.
88 lines (85 loc) • 2.99 kB
JavaScript
import ts from 'typescript';
import { getDefaultUserExtensionDir } from '../../util/sc.js';
const default_transpiler_option = {
global: {
output_dir: ".",
user_extension_dir: getDefaultUserExtensionDir(),
project_name: "tstosc",
yes_to_all: false,
flatten: false
},
files: []
};
const default_generator_context = {
compiler_program: ts.createProgram({ rootNames: [], options: {} }),
transpiler_option: default_transpiler_option,
indent_level: 0,
class_info: { name: "Error_NoClassSpecified", super_class_name: "Object" },
is_generating_method: false,
is_generating_constructor: false,
is_generating_class_name: false,
is_generating_member_of_object_literal: false,
with_early_return: false,
with_loop_interrupt: null,
statement_label: "",
is_nested_loop: false,
break_means: "nothing",
super_means: "nothing",
this_coming_from: "nothing",
has_unhandled_self_indecr_operator: false,
expression_temporise_dict: /* @__PURE__ */ new Map(),
is_standalone_statement: true,
indent: function(level = 1) {
return { ...this, indent_level: this.indent_level + level };
},
outdent: function(level = 1) {
return { ...this, indent_level: Math.max(0, this.indent_level - level) };
},
withClassInfo: function(info) {
const super_class_name = info.super_class_name != void 0 && info.super_class_name.length > 0 ? info.super_class_name : "Object";
return { ...this, class_info: { name: info.name, super_class_name } };
},
atValuePosition: function(value = true) {
return { ...this, is_standalone_statement: !value };
},
isStandalongStatement: function(value = true) {
return { ...this, is_standalone_statement: value };
},
willGenerateMethod: function(value = true) {
return { ...this, is_generating_method: value };
},
willGenerateConstructor: function(value = true) {
return { ...this, is_generating_constructor: value };
},
willGenerateClassName: function(value = true) {
return { ...this, is_generating_class_name: value };
},
willGenerateMemberOfObjectLiteral: function(value = true) {
return { ...this, is_generating_member_of_object_literal: value };
},
withEarlyReturn: function(value = true) {
return { ...this, with_early_return: value };
},
withLoopInterrupt: function(value = true) {
return { ...this, with_loop_interrupt: value };
},
withStatementLabel: function(value) {
return { ...this, statement_label: value };
},
clearedStatementLabel: function() {
return { ...this, statement_label: "" };
},
isNestedLoop: function(value = true) {
return { ...this, is_nested_loop: value };
},
makeBreakMeans: function(value) {
return { ...this, break_means: value };
},
makeSuperMeans: function(value) {
return { ...this, super_means: value };
},
makeThisComingFrom: function(value) {
return { ...this, this_coming_from: value };
}
};
export { default_generator_context, default_transpiler_option };