"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringify = void 0;
const escape_1 = require("./escape");
const globalUrl_1 = require("./globalUrl");
function stringify(value) {
    const t = typeof value;
    switch (t) {
        case 'string':
            return `"${(0, escape_1.escape)(value)}"`;
        case 'number':
        case 'boolean':
            return `${value}`;
        case 'object':
            if (value === null) {
                return 'null';
            }
            else if (Array.isArray(value)) {
                return `[${value.map(stringify).join(',')}]`;
            }
            else {
                if (value.constructor.name === 'Object') {
                    return `{${Object.entries(value)
                        .filter(([key, value]) => {
                        return value !== undefined;
                    })
                        .map(([key, value]) => `${`"${(0, escape_1.escape)(key)}"`}:${stringify(value)}`)
                        .join(',')}}`;
                }
                else {
                    return (0, globalUrl_1.globalUrl)(value.__global_id);
                }
            }
        case 'function':
            if (value.__bundle) {
                return `$${stringify(value.__bundle)}`;
            }
            else {
                // throw new Error('invalid unit class')
                return 'null';
            }
        default:
            throw new Error('cannot stringify value');
    }
}
exports.stringify = stringify;
//# sourceMappingURL=stringify.js.map