<commit_before>'use strict';

var extend = require('xtend');

var serializers = {
    program: serializeProgram,
    typeDeclaration: serializeTypeDeclaration,
    assignment: serializeAssignment,
    'import': serializeImportStatement,
    object: serializeObject,
    unionType: serializeUnion,
    intersectionType: serializeIntersection,
    typeLiteral: serializeLiteral,
    keyValue: serializeKeyValue,
    valueLiteral: serializeValue,
    function: serializeFunctionType,
    genericLiteral: serializeGeneric,
    tuple: serializeTuple
};

module.exports = serialize;

function serialize(ast, opts) {
    opts = opts || { indent: 0, lineStart: 0 };
    var fn = serializers[ast.type];

    if (!fn) {
        throw new Error('unknown ast type: ' + ast.type);
    }

    return fn(ast, opts);
}

function serializeProgram(node, opts) {
    return node.statements.map(function s(n) {
        return serialize(n, opts);
    }).join('\n\n');
}

function serializeTypeDeclaration(node, opts) {
    var generics = node.generics.length ? 
        '<' + node.generics.map(function s(n) {
            return serialize(n, opts);
        }).join(', ') + '>' : '';
    var str = 'type ' + node.identifier + generics + ' : ';

    return str + serialize(node.typeExpression, extend(opts, {<commit_msg>serialize: support _raw<commit_after>'use strict';

var extend = require('xtend');

var serializers = {
    program: serializeProgram,
    typeDeclaration: serializeTypeDeclaration,
    assignment: serializeAssignment,
    'import': serializeImportStatement,
    object: serializeObject,
    unionType: serializeUnion,
    intersectionType: serializeIntersection,
    typeLiteral: serializeLiteral,
    keyValue: serializeKeyValue,
    valueLiteral: serializeValue,
    function: serializeFunctionType,
    genericLiteral: serializeGeneric,
    tuple: serializeTuple
};

module.exports = serialize;

function serialize(ast, opts) {
    opts = opts || { indent: 0, lineStart: 0 };

    if (ast._raw) {
        return serialize(ast._raw, opts);
    }

    var fn = serializers[ast.type];

    if (!fn) {
        throw new Error('unknown ast type: ' + ast.type);
    }

    return fn(ast, opts);
}

function serializeProgram(node, opts) {
    return node.statements.map(function s(n) {
        return serialize(n, opts);
    }).join('\n\n');
}

function serializeTypeDeclaration(node, opts) {
    var generics = node.generics.length ? 
        '<' + node.generics.map(function s(n) {
            return serialize(n, opts);
        }).join(', ') + '>' : '';
    var str = 'type ' + node.identifier + generics + ' : ';

    return str + serialize(node.typeExpression, extend(opts, {
{'fraction_non_alphanumeric': 0.12602842183994017, 'fraction_numerical': 0.0014958863126402393, 'mean_word_length': 3.3996710526315788, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1399238', 'n_tokens_mistral': 811, 'n_tokens_neox': 804, 'n_words': 185}