1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | exports.BuildBrowserFeatures = void 0;
|
11 | const browserslist = require("browserslist");
|
12 | const caniuse_lite_1 = require("caniuse-lite");
|
13 | const ts = require("typescript");
|
14 | class BuildBrowserFeatures {
|
15 | constructor(projectRoot) {
|
16 | this.projectRoot = projectRoot;
|
17 | this.supportedBrowsers = browserslist(undefined, { path: this.projectRoot });
|
18 | }
|
19 | |
20 |
|
21 |
|
22 |
|
23 | isDifferentialLoadingNeeded(scriptTarget) {
|
24 | const es6TargetOrLater = scriptTarget > ts.ScriptTarget.ES5;
|
25 | return es6TargetOrLater && this.isEs5SupportNeeded();
|
26 | }
|
27 | |
28 |
|
29 |
|
30 | isEs5SupportNeeded() {
|
31 | return !this.isFeatureSupported('es6-module');
|
32 | }
|
33 | |
34 |
|
35 |
|
36 | isFeatureSupported(featureId) {
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | const criteria = ['y', 'a'];
|
42 | const data = caniuse_lite_1.feature(caniuse_lite_1.features[featureId]);
|
43 | return !this.supportedBrowsers.some((browser) => {
|
44 | const [agentId, version] = browser.split(' ');
|
45 | const browserData = data.stats[agentId];
|
46 | const featureStatus = (browserData && browserData[version]);
|
47 |
|
48 |
|
49 |
|
50 | return !featureStatus || !criteria.includes(featureStatus.charAt(0));
|
51 | });
|
52 | }
|
53 | }
|
54 | exports.BuildBrowserFeatures = BuildBrowserFeatures;
|