all files / dist/writers/ FunctionWriter.js

100% Statements 56/56
91.67% Branches 11/12
100% Functions 9/9
100% Lines 56/56
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73  19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19×   15× 15× 15× 15×   15× 14× 14× 14×       14× 14× 14× 14× 14×   17× 14× 14×       17× 17× 17× 17× 17×              
"use strict";
var definitions_1 = require("./../definitions");
var WriteFlags_1 = require("./../WriteFlags");
var FunctionWriter = (function () {
    function FunctionWriter(writer, baseDefinitionWriter, documentationedWriter, decoratorsWriter, exportableWriter, ambientWriter, asyncableWriter, scopeWriter, callSignatureWriter, typeParametersWriter, parametersWriter, functionBodyWriter, functionReturnTypeWriter) {
        this.writer = writer;
        this.baseDefinitionWriter = baseDefinitionWriter;
        this.documentationedWriter = documentationedWriter;
        this.decoratorsWriter = decoratorsWriter;
        this.exportableWriter = exportableWriter;
        this.ambientWriter = ambientWriter;
        this.asyncableWriter = asyncableWriter;
        this.scopeWriter = scopeWriter;
        this.callSignatureWriter = callSignatureWriter;
        this.typeParametersWriter = typeParametersWriter;
        this.parametersWriter = parametersWriter;
        this.functionBodyWriter = functionBodyWriter;
        this.functionReturnTypeWriter = functionReturnTypeWriter;
    }
    FunctionWriter.prototype.write = function (def, flags) {
        var _this = this;
        this.baseDefinitionWriter.writeWrap(def, function () {
            var shouldWriteImplementation = def.overloadSignatures.length === 0 || (flags & WriteFlags_1.WriteFlags.HideFunctionImplementations) === 0;
            (def.overloadSignatures || []).forEach(function (s) {
                _this.documentationedWriter.write(s);
                _this.writeStartOfFunctionHeader(def, flags);
                _this.callSignatureWriter.write(s, flags);
                _this.writer.write(";").newLine();
            });
            if (shouldWriteImplementation) {
                _this.documentationedWriter.write(def);
                _this.decoratorsWriter.write(def, flags);
                _this.writeImplementation(def, flags);
            }
        });
    };
    FunctionWriter.prototype.writeImplementation = function (def, flags) {
        this.writeStartOfFunctionHeader(def, flags);
        this.typeParametersWriter.write(def.typeParameters);
        this.parametersWriter.write(def, flags);
        this.functionReturnTypeWriter.write(def, flags);
        this.functionBodyWriter.write(def, flags);
    };
    FunctionWriter.prototype.writeStartOfFunctionHeader = function (def, flags) {
        if (def instanceof definitions_1.FunctionDefinition) {
            this.exportableWriter.writeExportKeyword(def, flags);
            this.ambientWriter.writeDeclareKeyword(def);
        }
        else {
            this.scopeWriter.writeScope(def.scope);
            this.writeStatic(def);
            this.writeAbstract(def);
        }
        this.asyncableWriter.writeAsyncKeyword(def);
        this.writer.conditionalWrite(def instanceof definitions_1.FunctionDefinition, "function");
        this.writer.conditionalWrite(def.isGenerator, "*");
        this.writer.conditionalWrite(def instanceof definitions_1.FunctionDefinition, " ");
        this.writer.write(def.name);
    };
    FunctionWriter.prototype.writeStatic = function (def) {
        if (def instanceof definitions_1.ClassStaticMethodDefinition)
            this.writer.write("static ");
    };
    FunctionWriter.prototype.writeAbstract = function (def) {
        if (def.isAbstract)
            this.writer.write("abstract ");
    };
    return FunctionWriter;
}());
exports.FunctionWriter = FunctionWriter;
 
//# sourceMappingURL=FunctionWriter.js.map