UNPKG

@carlosv2/glue

Version:

Dependency injection library that stays out of the way

43 lines (42 loc) 1.57 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Importation = void 0; const typescript_1 = __importDefault(require("typescript")); const compilable_js_1 = require("../compilable.js"); const utils_js_1 = require("../utils.js"); const error_js_1 = require("../error.js"); const { factory } = typescript_1.default; const moduleSymbol = Symbol(); const defaultSymbol = Symbol(); class Importation extends compilable_js_1.Compilable { constructor(path, symbol) { super(); this.path = path; this.symbol = symbol; } compile(importer) { if (this.symbol === moduleSymbol) { return factory.createIdentifier(importer.module(this.path)); } else if (this.symbol === defaultSymbol) { return factory.createIdentifier(importer.default(this.path)); } else if (!(0, utils_js_1.isSymbol)(this.symbol)) { return factory.createIdentifier(importer.symbol(this.path, this.symbol)); } throw new error_js_1.DiError(`Unable to determine the import declaration for ${String(this.symbol)}`); } static module(path) { return new Importation(path, moduleSymbol); } static default(path) { return new Importation(path, defaultSymbol); } static named(path, symbol) { return new Importation(path, symbol); } } exports.Importation = Importation;