UNPKG

typedraft

Version:

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

37 lines (36 loc) 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const toposort = require("toposort"); class LocalContextPlugin { constructor(transcriber) { this.m_Transcriber = transcriber; } Transcribe() { const to_transcribe = this.GetContextList(); to_transcribe.forEach(name => { const context = this.m_Transcriber.GetLocalContext(name); context.m_Refs.forEach(path => path .findParent(path => path.isExpressionStatement()) .replaceWithMultiple(context.ToStatements())); }); } GetContextList() { const graph = []; this.m_Transcriber.TraverseLocalContext((context, name) => { context.m_Refs.forEach(path => { const parent = path.findParent(path => path.isFunctionDeclaration() || path.isFunctionExpression() || path.isExportDeclaration()); if (parent) { graph.push([name, parent.node.id.name]); } }); }); const context_list = toposort(graph).filter(name => this.m_Transcriber.GetLocalContext(name)); return context_list; } } exports.LocalContextPlugin = LocalContextPlugin; class ILocalContextPlugin { } exports.ILocalContextPlugin = ILocalContextPlugin;