"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var common_1 = require("../common");
var ADDED_TYPES = [];
var ECMASCRIPT_DEFS = common_1.constants.IS_BROWSER && {
    es5: require('../../static/@tdb/editor.code.d/lib.es5.d.ts'),
    es2015core: require('../../static/@tdb/editor.code.d/lib.es2015.core.d.ts'),
    es2015collection: require('../../static/@tdb/editor.code.d/lib.es2015.collection.d.ts'),
    es2015generator: require('../../static/@tdb/editor.code.d/lib.es2015.generator.d.ts'),
    es2015promise: require('../../static/@tdb/editor.code.d/lib.es2015.promise.d.ts'),
    es2015iterable: require('../../static/@tdb/editor.code.d/lib.es2015.iterable.d.ts'),
    es2015proxy: require('../../static/@tdb/editor.code.d/lib.es2015.proxy.d.ts'),
    es2015reflect: require('../../static/@tdb/editor.code.d/lib.es2015.reflect.d.ts'),
    es2015symbol: require('../../static/@tdb/editor.code.d/lib.es2015.symbol.d.ts'),
};
function configureLanguage(settings, languageService) {
    languageService.setCompilerOptions({
        allowNonTsExtensions: true,
        noLib: true,
    });
    var libs = '';
    var types = settings.types.map(function (code) { return clean(code); }).join('\n');
    if (!ADDED_TYPES.includes(types)) {
        ADDED_TYPES.push(types);
        libs += types;
    }
    if (ECMASCRIPT_DEFS) {
        Object.keys(ECMASCRIPT_DEFS)
            .map(function (key) { return ECMASCRIPT_DEFS[key]; })
            .forEach(function (lib) { return (libs += lib); });
    }
    if (libs) {
        languageService.addExtraLib(libs);
    }
}
exports.configureLanguage = configureLanguage;
function clean(code) {
    var lines = code.split('\n').map(function (line) {
        if (line.startsWith('import ')) {
            return '';
        }
        if (line.startsWith('export ')) {
            line = line.replace(/^export /, '');
        }
        return line;
    });
    return lines.join('\n');
}
//# sourceMappingURL=language.js.map