UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for static analysis and code manipulation.

52 lines (51 loc) 2.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var utils_1 = require("../../utils"); var FactoryStructurePrinter_1 = require("../FactoryStructurePrinter"); var formatting_1 = require("../formatting"); var NamedImportExportSpecifierStructurePrinter = /** @class */ (function (_super) { tslib_1.__extends(NamedImportExportSpecifierStructurePrinter, _super); function NamedImportExportSpecifierStructurePrinter() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.multipleWriter = new formatting_1.CommaSeparatedStructuresPrinter(_this); return _this; } NamedImportExportSpecifierStructurePrinter.prototype.printTextsWithBraces = function (writer, structures) { var formatSettings = this.factory.getFormatCodeSettings(); writer.write("{"); var specifierWriter = this.getNewWriter(writer); this.printTexts(specifierWriter, structures); var specifierText = specifierWriter.toString(); if (formatSettings.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces && !utils_1.StringUtils.startsWithNewLine(specifierText)) writer.space(); writer.write(specifierText); if (formatSettings.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces && !utils_1.StringUtils.endsWithNewLine(specifierText)) writer.space(); writer.write("}"); }; NamedImportExportSpecifierStructurePrinter.prototype.printTexts = function (writer, structures) { if (structures instanceof Function) this.printText(writer, structures); else this.multipleWriter.printText(writer, structures); }; NamedImportExportSpecifierStructurePrinter.prototype.printText = function (writer, structure) { var specifierWriter = this.getNewWriterWithQueuedChildIndentation(writer); if (typeof structure === "string") specifierWriter.write(structure); else if (structure instanceof Function) structure(specifierWriter); else { specifierWriter.write(structure.name); if (!utils_1.StringUtils.isNullOrWhitespace(structure.alias)) { if (!specifierWriter.isLastNewLine()) specifierWriter.space(); specifierWriter.write("as " + structure.alias); } } writer.write(specifierWriter.toString()); }; return NamedImportExportSpecifierStructurePrinter; }(FactoryStructurePrinter_1.FactoryStructurePrinter)); exports.NamedImportExportSpecifierStructurePrinter = NamedImportExportSpecifierStructurePrinter;