"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEcmaVersion = void 0;
const utils_1 = require("@modern-js/utils");
const caniuse_lite_1 = require("caniuse-lite");
function getEcmaVersion(targets) {
    let version = 5;
    if (targets.every(target => checkIsSupportBrowser(`es6`, target))) {
        version = 6;
    }
    return version;
}
exports.getEcmaVersion = getEcmaVersion;
function checkIsSupportBrowser(feature, browsers) {
    const data = (0, caniuse_lite_1.feature)(caniuse_lite_1.features[feature]);
    return (0, utils_1.browserslist)(browsers, { ignoreUnknownVersions: true })
        .map(browser => browser.split(' '))
        .every(browser => {
        var _a, _b, _c, _d;
        return ((_b = (_a = data.stats[browser[0]]) === null || _a === void 0 ? void 0 : _a[browser[1]]) === null || _b === void 0 ? void 0 : _b.includes('y')) ||
            ((_d = (_c = data.stats[browser[0]]) === null || _c === void 0 ? void 0 : _c[browser[1]]) === null || _d === void 0 ? void 0 : _d.includes('a'));
    });
}
