UNPKG

typedraft

Version:

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

35 lines (34 loc) 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const common_1 = require("../common"); const draft_dsl_match_1 = require("draft-dsl-match"); class InplaceContextPlugin { constructor(transcriber) { this.m_Transcriber = transcriber; } Transcribe() { const transcriber = this.m_Transcriber; transcriber.m_Module.Traverse({ TaggedTemplateExpression(path) { draft_dsl_match_1.MatchDSL(path.node).with({ tag: { type: "CallExpression", typeParameters: draft_dsl_match_1.use("typeParams"), arguments: draft_dsl_match_1.use("args"), callee: { type: "Identifier", name: draft_dsl_match_1.when(name => name === "context" || name === "Λ") } } }, (_, { args, typeParams }) => { const dsl = transcriber.m_DSLMap.get(args[0].value); if (dsl) { const type = typeParams ? common_1.ToString(typeParams.params[0]) : ""; path.replaceWith(dsl.InplaceTranscribe(path.get("quasi"), type)); } }).with(draft_dsl_match_1.__, () => { }).run(); } }); } } exports.InplaceContextPlugin = InplaceContextPlugin;