all files / dist/writers/ ImportWriter.js

100% Statements 39/39
91.3% Branches 21/23
100% Functions 9/9
100% Lines 38/38
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51  17× 17×   10× 10×   10× 10× 10× 10× 10×   10× 10× 10×                  
"use strict";
var ImportWriter = (function () {
    function ImportWriter(writer, baseDefinitionWriter) {
        this.writer = writer;
        this.baseDefinitionWriter = baseDefinitionWriter;
    }
    ImportWriter.prototype.write = function (def) {
        var _this = this;
        this.baseDefinitionWriter.writeWrap(def, function () { return _this.writeInternal(def); });
    };
    ImportWriter.prototype.writeInternal = function (def) {
        var hasDefaultImport = def.defaultImport != null;
        var hasStarImport = def.starImportName != null && def.starImportName.length > 0;
        var hasNamedImports = (def.namedImports || []).length > 0;
        this.writer.write("import ");
        if (hasDefaultImport) {
            this.writeDefaultImport(def.defaultImport);
            this.writer.conditionalWrite(hasStarImport || hasNamedImports, ", ");
        }
        if (hasStarImport)
            this.writeStarImport(def);
        else if (hasNamedImports)
            this.writeNamedImports(def);
        if (hasDefaultImport || hasStarImport || hasNamedImports)
            this.writer.write(" from ");
        this.writer.write("\"" + def.moduleSpecifier + "\";");
    };
    ImportWriter.prototype.writeStarImport = function (def) {
        this.writer.write("* as " + def.starImportName);
    };
    ImportWriter.prototype.writeDefaultImport = function (defaultImport) {
        this.writer.write(defaultImport.name);
    };
    ImportWriter.prototype.writeNamedImports = function (def) {
        var _this = this;
        this.writer.write("{");
        (def.namedImports || []).forEach(function (namedImport, i) {
            var name = namedImport.name, alias = namedImport.alias;
            _this.writer.conditionalWrite(i !== 0, ", ");
            _this.writer.write(name);
            if (alias != null && name !== alias)
                _this.writer.write(" as " + alias);
        });
        this.writer.write("}");
    };
    return ImportWriter;
}());
exports.ImportWriter = ImportWriter;
 
//# sourceMappingURL=ImportWriter.js.map