Debian Codegraph @

packages/babel-preset-env/src/debug.ts

raw symbols SCIP
1 import {
2 getInclusionReasons,
3 type Targets,
4 type Target,
5 } from "@babel/helper-compilation-targets";
6 import compatData from "@babel/compat-data/plugins";
7
8 // Outputs a message that shows which target(s) caused an item to be included:
9 // transform-foo { "edge":"13", "firefox":"49", "ie":"10" }
10 export const logPlugin = (
11 item: string,
12 targetVersions: Targets,
13 list: { [key: string]: Targets },
14 ) => {
15 const filteredList = getInclusionReasons(item, targetVersions, list);
16
17 const support = list[item];
18
19 // TODO(Babel 8): Remove this. It's needed to keep outputting proposal-
20 // in the debug log.
21 if (item.startsWith("transform-")) {
22 const proposalName = `proposal-${item.slice(10)}`;
23 if (
24 proposalName === "proposal-dynamic-import" ||
25 Object.prototype.hasOwnProperty.call(compatData, proposalName)
26 ) {
27 item = proposalName;
28 }
29 }
30
31 if (!support) {
32 console.log(` ${item}`);
33 return;
34 }
35
36 let formattedTargets = `{`;
37 let first = true;
38 for (const target of Object.keys(filteredList) as Target[]) {
39 if (!first) formattedTargets += `,`;
40 first = false;
41 formattedTargets += ` ${target}`;
42 if (support[target]) formattedTargets += ` < ${support[target]}`;
43 }
44 formattedTargets += ` }`;
45
46 console.log(` ${item} ${formattedTargets}`);
47 };