var TypeScript = require("../typescript/tss");

function createCompilationSettings() {
    return new TypeScript.CompilationSettings();
}
exports.createCompilationSettings = createCompilationSettings;

function createImmutableCompilationSettings(settings) {
    if (typeof settings === "undefined") { settings = exports.createCompilationSettings(); }
    return TypeScript.ImmutableCompilationSettings.fromCompilationSettings(settings);
}
exports.createImmutableCompilationSettings = createImmutableCompilationSettings;

function compileWithContent(content, compilationSettings) {
    var immutableCompilationSettings;
    if (compilationSettings instanceof TypeScript.ImmutableCompilationSettings) {
        immutableCompilationSettings = compilationSettings;
    } else {
        immutableCompilationSettings = TypeScript.ImmutableCompilationSettings.fromCompilationSettings(compilationSettings);
    }

    var logger = new TypeScript.NullLogger();

    var compiler = new TypeScript.TypeScriptCompiler(logger, immutableCompilationSettings);
    var scriptSnapshot = TypeScript.ScriptSnapshot.fromString(content);
    compiler.addFile("tmp.ts", scriptSnapshot, 0 /* None */, 0, false, []);

    return compiler.compile(function (path) {
        return path;
    });
}
exports.compileWithContent = compileWithContent;
