UNPKG

typedraft

Version:

TypeDraft is a superset of typescript with built-in support for DSL extension and literate programming.

45 lines (44 loc) 1.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class LocalContext { /** * binding is used to find all references to this context, thus we can replace them with resolved statements */ constructor(binding) { this.m_Binding = binding; } get m_Path() { return this.m_Binding.path; } get m_Code() { return this.m_Path.node; } get m_Refs() { return this.m_Binding.referencePaths; } get m_Name() { return this.m_Code.id.name; } /** * The context itself does nothing but expresses our intention. If it's used with a DSL, we can resolve it to get the "real" statements. */ Resolve(dsl) { /** * remove all directives, because we don't need "use ..." after resolved */ this.m_Code.body.directives = []; this.m_Code.body.body = dsl.Transcribe(this.ToStatements(), this.m_Path); } ToStatements() { return this.m_Code.body.body; } GetDSLName() { const [directive] = this.m_Code.body.directives; if (directive) { const [use, dsl_name] = directive.value.value.split(" "); return dsl_name; } return ""; } } exports.LocalContext = LocalContext;