@powerlines/plugin-babel 0.12.261 → 0.12.263

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/dist/{chunk-CbDLau6x.cjs → _virtual/rolldown_runtime.cjs} +1 -6
  2. package/dist/helpers/ast-utils.cjs +34 -3
  3. package/dist/helpers/ast-utils.d.cts +20 -2
  4. package/dist/helpers/ast-utils.d.cts.map +1 -0
  5. package/dist/helpers/ast-utils.d.mts +20 -2
  6. package/dist/helpers/ast-utils.d.mts.map +1 -0
  7. package/dist/helpers/ast-utils.mjs +32 -2
  8. package/dist/helpers/ast-utils.mjs.map +1 -0
  9. package/dist/helpers/create-plugin.cjs +40 -2
  10. package/dist/helpers/create-plugin.d.cts +16 -2
  11. package/dist/helpers/create-plugin.d.cts.map +1 -0
  12. package/dist/helpers/create-plugin.d.mts +16 -2
  13. package/dist/helpers/create-plugin.d.mts.map +1 -0
  14. package/dist/helpers/create-plugin.mjs +39 -2
  15. package/dist/helpers/create-plugin.mjs.map +1 -0
  16. package/dist/helpers/filters.cjs +58 -5
  17. package/dist/helpers/filters.d.cts +43 -2
  18. package/dist/helpers/filters.d.cts.map +1 -0
  19. package/dist/helpers/filters.d.mts +43 -2
  20. package/dist/helpers/filters.d.mts.map +1 -0
  21. package/dist/helpers/filters.mjs +55 -2
  22. package/dist/helpers/filters.mjs.map +1 -0
  23. package/dist/helpers/index.cjs +21 -22
  24. package/dist/helpers/index.d.cts +5 -6
  25. package/dist/helpers/index.d.mts +5 -6
  26. package/dist/helpers/index.mjs +5 -6
  27. package/dist/helpers/module-helpers.cjs +102 -9
  28. package/dist/helpers/module-helpers.d.cts +50 -2
  29. package/dist/helpers/module-helpers.d.cts.map +1 -0
  30. package/dist/helpers/module-helpers.d.mts +50 -2
  31. package/dist/helpers/module-helpers.d.mts.map +1 -0
  32. package/dist/helpers/module-helpers.mjs +95 -3
  33. package/dist/helpers/module-helpers.mjs.map +1 -0
  34. package/dist/helpers/options.cjs +48 -4
  35. package/dist/helpers/options.d.cts +19 -2
  36. package/dist/helpers/options.d.cts.map +1 -0
  37. package/dist/helpers/options.d.mts +19 -2
  38. package/dist/helpers/options.d.mts.map +1 -0
  39. package/dist/helpers/options.mjs +46 -3
  40. package/dist/helpers/options.mjs.map +1 -0
  41. package/dist/index.cjs +27 -29
  42. package/dist/index.d.cts +8 -8
  43. package/dist/index.d.mts +8 -8
  44. package/dist/index.mjs +6 -8
  45. package/dist/index.mjs.map +1 -1
  46. package/dist/types/index.cjs +0 -2
  47. package/dist/types/index.d.cts +1 -2
  48. package/dist/types/index.d.mts +1 -2
  49. package/dist/types/index.mjs +0 -3
  50. package/dist/types/plugin.cjs +0 -1
  51. package/dist/types/plugin.d.cts +20 -2
  52. package/dist/types/plugin.d.cts.map +1 -0
  53. package/dist/types/plugin.d.mts +20 -2
  54. package/dist/types/plugin.d.mts.map +1 -0
  55. package/dist/types/plugin.mjs +0 -2
  56. package/package.json +8 -8
  57. package/dist/ast-utils-BcmWaIan.cjs +0 -45
  58. package/dist/ast-utils-Bs6DBkKg.d.mts +0 -20
  59. package/dist/ast-utils-Bs6DBkKg.d.mts.map +0 -1
  60. package/dist/ast-utils-DU1foCxH.mjs +0 -33
  61. package/dist/ast-utils-DU1foCxH.mjs.map +0 -1
  62. package/dist/ast-utils-DeuXcuqs.d.cts +0 -20
  63. package/dist/ast-utils-DeuXcuqs.d.cts.map +0 -1
  64. package/dist/create-plugin-BSNFeead.mjs +0 -40
  65. package/dist/create-plugin-BSNFeead.mjs.map +0 -1
  66. package/dist/create-plugin-Bf7dRYZB.cjs +0 -46
  67. package/dist/create-plugin-DU9FBfyz.d.cts +0 -16
  68. package/dist/create-plugin-DU9FBfyz.d.cts.map +0 -1
  69. package/dist/create-plugin-DgfkdI-s.d.mts +0 -16
  70. package/dist/create-plugin-DgfkdI-s.d.mts.map +0 -1
  71. package/dist/filters-CU0L1nIa.cjs +0 -79
  72. package/dist/filters-CpjboNi8.mjs +0 -56
  73. package/dist/filters-CpjboNi8.mjs.map +0 -1
  74. package/dist/filters-D75MrPzl.d.mts +0 -43
  75. package/dist/filters-D75MrPzl.d.mts.map +0 -1
  76. package/dist/filters-DKyk7Jxg.d.cts +0 -43
  77. package/dist/filters-DKyk7Jxg.d.cts.map +0 -1
  78. package/dist/helpers-BnW_4z5h.mjs +0 -1
  79. package/dist/helpers-Bx2yBrpn.cjs +0 -0
  80. package/dist/index-BXxhKmeA.d.mts +0 -1
  81. package/dist/index-CqdNToYT.d.cts +0 -1
  82. package/dist/index-DJOHDG5e.d.mts +0 -1
  83. package/dist/index-sQecLSpR.d.cts +0 -1
  84. package/dist/module-helpers-07-NCXys.d.cts +0 -50
  85. package/dist/module-helpers-07-NCXys.d.cts.map +0 -1
  86. package/dist/module-helpers-B1gnVB7F.d.mts +0 -50
  87. package/dist/module-helpers-B1gnVB7F.d.mts.map +0 -1
  88. package/dist/module-helpers-Ckq8sc4l.mjs +0 -96
  89. package/dist/module-helpers-Ckq8sc4l.mjs.map +0 -1
  90. package/dist/module-helpers-Non-jHMu.cjs +0 -138
  91. package/dist/options-2JL6WIXT.cjs +0 -59
  92. package/dist/options-CpZXObFr.d.mts +0 -19
  93. package/dist/options-CpZXObFr.d.mts.map +0 -1
  94. package/dist/options-DZkAyLff.d.cts +0 -19
  95. package/dist/options-DZkAyLff.d.cts.map +0 -1
  96. package/dist/options-DwynxlP6.mjs +0 -47
  97. package/dist/options-DwynxlP6.mjs.map +0 -1
  98. package/dist/plugin-BL8TLixo.mjs +0 -1
  99. package/dist/plugin-BSBH78mm.cjs +0 -0
  100. package/dist/plugin-C-FvkCBm.d.cts +0 -20
  101. package/dist/plugin-C-FvkCBm.d.cts.map +0 -1
  102. package/dist/plugin-Sxw1QP5p.d.mts +0 -20
  103. package/dist/plugin-Sxw1QP5p.d.mts.map +0 -1
  104. package/dist/types-CKPddlfS.cjs +0 -0
  105. package/dist/types-CvhspRRt.mjs +0 -1
@@ -1,8 +1,7 @@
1
- import { i as isDuplicatePlugin, n as filterPluginByFileId, r as getPluginName, t as addPluginFilter } from "../filters-CpjboNi8.mjs";
2
- import { n as resolvePluginFunction, t as resolveBabelPlugin } from "../options-DwynxlP6.mjs";
3
- import { n as parseAst, t as generateFromAst } from "../ast-utils-DU1foCxH.mjs";
4
- import { t as createBabelPlugin } from "../create-plugin-BSNFeead.mjs";
5
- import { a as isImportCall, i as getImport, n as addImportsToProgram, o as listExports, r as findExport, s as listImports, t as addImport } from "../module-helpers-Ckq8sc4l.mjs";
6
- import "../helpers-BnW_4z5h.mjs";
1
+ import { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin } from "./filters.mjs";
2
+ import { resolveBabelPlugin, resolvePluginFunction } from "./options.mjs";
3
+ import { generateFromAst, parseAst } from "./ast-utils.mjs";
4
+ import { createBabelPlugin } from "./create-plugin.mjs";
5
+ import { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports } from "./module-helpers.mjs";
7
6
 
8
7
  export { addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, isDuplicatePlugin, isImportCall, listExports, listImports, parseAst, resolveBabelPlugin, resolvePluginFunction };
@@ -1,10 +1,103 @@
1
- require('../ast-utils-BcmWaIan.cjs');
2
- const require_module_helpers = require('../module-helpers-Non-jHMu.cjs');
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_helpers_ast_utils = require('./ast-utils.cjs');
3
+ let __babel_types = require("@babel/types");
4
+ __babel_types = require_rolldown_runtime.__toESM(__babel_types);
5
+ let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
3
6
 
4
- exports.addImport = require_module_helpers.addImport;
5
- exports.addImportsToProgram = require_module_helpers.addImportsToProgram;
6
- exports.findExport = require_module_helpers.findExport;
7
- exports.getImport = require_module_helpers.getImport;
8
- exports.isImportCall = require_module_helpers.isImportCall;
9
- exports.listExports = require_module_helpers.listExports;
10
- exports.listImports = require_module_helpers.listImports;
7
+ //#region src/helpers/module-helpers.ts
8
+ /**
9
+ * Finds an export in the given Babel AST program by its key.
10
+ *
11
+ * @param ast - The parsed Babel AST result containing the program body.
12
+ * @param key - The name of the export to find (e.g., "default" or a named export).
13
+ * @returns The declaration of the export if found, otherwise undefined.
14
+ */
15
+ function findExport(ast, key) {
16
+ const type = key === "default" ? "ExportDefaultDeclaration" : "ExportNamedDeclaration";
17
+ for (const node of ast.program.body) if (node.type === type) {
18
+ if (key === "default") return node.declaration;
19
+ if (node.declaration && "declarations" in node.declaration) {
20
+ const declaration = node.declaration.declarations[0];
21
+ if (declaration && "name" in declaration.id && declaration.id.name === key) return declaration.init;
22
+ }
23
+ }
24
+ }
25
+ /**
26
+ * Lists all exports from the given Babel AST program.
27
+ *
28
+ * @param codeOrAst - The parsed Babel AST result containing the program body.
29
+ * @returns An array of export names, including "default" for default exports.
30
+ */
31
+ function listExports(codeOrAst) {
32
+ return ((0, __stryke_type_checks_is_string.isString)(codeOrAst) ? require_helpers_ast_utils.parseAst(codeOrAst) : codeOrAst).program.body.flatMap((i) => {
33
+ if (i.type === "ExportDefaultDeclaration") return ["default"];
34
+ if (i.type === "ExportNamedDeclaration" && i.declaration && "declarations" in i.declaration) return i.declaration.declarations.map((d) => "name" in d.id ? d.id.name : "");
35
+ return [];
36
+ }).filter(Boolean);
37
+ }
38
+ /**
39
+ * Lists all imports from the given Babel AST program.
40
+ *
41
+ * @param ast - The parsed Babel AST result containing the program body.
42
+ * @returns An array of import names, including "default" for default imports.
43
+ */
44
+ function listImports(ast) {
45
+ return ast.program.body.flatMap((i) => {
46
+ if (i.type === "ImportDeclaration") return i.specifiers.map((s) => {
47
+ if (s.type === "ImportDefaultSpecifier") return "default";
48
+ if (s.type === "ImportSpecifier" && "imported" in s) return s.imported.type === "Identifier" ? s.imported.name : s.imported.value;
49
+ return "";
50
+ });
51
+ return [];
52
+ }).filter(Boolean);
53
+ }
54
+ function isImportCall(calleePath) {
55
+ return __babel_types.isImport(calleePath.node.callee);
56
+ }
57
+ /**
58
+ * Gets the import declaration for a given name and specifier.
59
+ *
60
+ * @param specifier - The specifier of the import.
61
+ * @param name - The name of the import.
62
+ * @param named - Optional named import.
63
+ * @returns The import declaration.
64
+ */
65
+ function getImport(specifier, name, named) {
66
+ return __babel_types.importDeclaration([__babel_types.importSpecifier(__babel_types.identifier(name), __babel_types.stringLiteral(named || name))], __babel_types.stringLiteral(specifier));
67
+ }
68
+ /**
69
+ * Adds an import to the program if it doesn't already exist.
70
+ *
71
+ * @param path - The current NodePath in the AST.
72
+ * @param specifier - The import specifier.
73
+ */
74
+ function addImport(path, specifier) {
75
+ addImportsToProgram(path.scope.getProgramParent().path, specifier);
76
+ }
77
+ function isNonNamespacedImport(importDeclPath) {
78
+ return importDeclPath.get("specifiers").filter(Boolean).every((specifier) => specifier?.isImportSpecifier()) && importDeclPath.node.importKind !== "type" && importDeclPath.node.importKind !== "typeof";
79
+ }
80
+ function getExistingImports(program) {
81
+ const existingImports = /* @__PURE__ */ new Map();
82
+ program.traverse({ ImportDeclaration(path) {
83
+ if (isNonNamespacedImport(path)) existingImports.set(path.node.source.value, path);
84
+ } });
85
+ return existingImports;
86
+ }
87
+ function addImportsToProgram(path, specifier) {
88
+ /**
89
+ * If an existing import of this module exists (ie \`import \{ ... \} from
90
+ * '<moduleName>'\`), inject new imported specifiers into the list of
91
+ * destructured variables.
92
+ */
93
+ if (!getExistingImports(path).get(specifier.module)) path.unshiftContainer("body", __babel_types.importDeclaration([__babel_types.importSpecifier(__babel_types.identifier(specifier.name || specifier.imported), __babel_types.identifier(specifier.imported))], __babel_types.stringLiteral(specifier.module)));
94
+ }
95
+
96
+ //#endregion
97
+ exports.addImport = addImport;
98
+ exports.addImportsToProgram = addImportsToProgram;
99
+ exports.findExport = findExport;
100
+ exports.getImport = getImport;
101
+ exports.isImportCall = isImportCall;
102
+ exports.listExports = listExports;
103
+ exports.listImports = listImports;
@@ -1,2 +1,50 @@
1
- import { a as isImportCall, i as getImport, n as addImportsToProgram, o as listExports, r as findExport, s as listImports, t as addImport } from "../module-helpers-07-NCXys.cjs";
2
- export { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports };
1
+ import { ParseResult } from "@babel/parser";
2
+ import * as t from "@babel/types";
3
+ import { ImportSpecifier } from "powerlines/types/babel";
4
+ import { NodePath } from "@babel/core";
5
+
6
+ //#region src/helpers/module-helpers.d.ts
7
+
8
+ /**
9
+ * Finds an export in the given Babel AST program by its key.
10
+ *
11
+ * @param ast - The parsed Babel AST result containing the program body.
12
+ * @param key - The name of the export to find (e.g., "default" or a named export).
13
+ * @returns The declaration of the export if found, otherwise undefined.
14
+ */
15
+ declare function findExport(ast: ParseResult<t.File>, key: string): any;
16
+ /**
17
+ * Lists all exports from the given Babel AST program.
18
+ *
19
+ * @param codeOrAst - The parsed Babel AST result containing the program body.
20
+ * @returns An array of export names, including "default" for default exports.
21
+ */
22
+ declare function listExports(codeOrAst: ParseResult<t.File> | string): string[];
23
+ /**
24
+ * Lists all imports from the given Babel AST program.
25
+ *
26
+ * @param ast - The parsed Babel AST result containing the program body.
27
+ * @returns An array of import names, including "default" for default imports.
28
+ */
29
+ declare function listImports(ast: ParseResult<t.File> | t.File): string[];
30
+ declare function isImportCall(calleePath: NodePath<t.CallExpression | t.NewExpression>): boolean;
31
+ /**
32
+ * Gets the import declaration for a given name and specifier.
33
+ *
34
+ * @param specifier - The specifier of the import.
35
+ * @param name - The name of the import.
36
+ * @param named - Optional named import.
37
+ * @returns The import declaration.
38
+ */
39
+ declare function getImport(specifier: string, name: string, named?: string): t.ImportDeclaration;
40
+ /**
41
+ * Adds an import to the program if it doesn't already exist.
42
+ *
43
+ * @param path - The current NodePath in the AST.
44
+ * @param specifier - The import specifier.
45
+ */
46
+ declare function addImport(path: NodePath<any>, specifier: ImportSpecifier): void;
47
+ declare function addImportsToProgram(path: NodePath<t.Program>, specifier: ImportSpecifier): void;
48
+ //#endregion
49
+ export { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports };
50
+ //# sourceMappingURL=module-helpers.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-helpers.d.cts","names":[],"sources":["../../src/helpers/module-helpers.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAgCA;AA6BA;AA4BA;;;AAAyD,iBAzDzC,UAAA,CAyDyC,GAAA,EAzDzB,WAyDyB,CAzDb,CAAA,CAAE,IAyDW,CAAA,EAAA,GAAA,EAAA,MAAA,CAAA,EAAA,GAAA;;AAsBzD;;;;;AAcgB,iBAhEA,WAAA,CAoEX,SAAA,EApEkC,WAoEjB,CApE6B,CAAA,CAAE,IAoE/B,CAAA,GAAA,MAAA,CAAA,EAAA,MAAA,EAAA;AAatB;AAuCA;;;;;iBA5FgB,WAAA,MAAiB,YAAY,CAAA,CAAE,QAAQ,CAAA,CAAE;iBAsBzC,YAAA,aACF,SAAS,CAAA,CAAE,iBAAiB,CAAA,CAAE;;;;;;;;;iBAa5B,SAAA,mDAIb,CAAA,CAAE;;;;;;;iBAaW,SAAA,OAAgB,0BAA0B;iBAuC1C,mBAAA,OACR,SAAS,CAAA,CAAE,qBACN"}
@@ -1,2 +1,50 @@
1
- import { a as isImportCall, i as getImport, n as addImportsToProgram, o as listExports, r as findExport, s as listImports, t as addImport } from "../module-helpers-B1gnVB7F.mjs";
2
- export { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports };
1
+ import { NodePath } from "@babel/core";
2
+ import { ParseResult } from "@babel/parser";
3
+ import * as t from "@babel/types";
4
+ import { ImportSpecifier } from "powerlines/types/babel";
5
+
6
+ //#region src/helpers/module-helpers.d.ts
7
+
8
+ /**
9
+ * Finds an export in the given Babel AST program by its key.
10
+ *
11
+ * @param ast - The parsed Babel AST result containing the program body.
12
+ * @param key - The name of the export to find (e.g., "default" or a named export).
13
+ * @returns The declaration of the export if found, otherwise undefined.
14
+ */
15
+ declare function findExport(ast: ParseResult<t.File>, key: string): any;
16
+ /**
17
+ * Lists all exports from the given Babel AST program.
18
+ *
19
+ * @param codeOrAst - The parsed Babel AST result containing the program body.
20
+ * @returns An array of export names, including "default" for default exports.
21
+ */
22
+ declare function listExports(codeOrAst: ParseResult<t.File> | string): string[];
23
+ /**
24
+ * Lists all imports from the given Babel AST program.
25
+ *
26
+ * @param ast - The parsed Babel AST result containing the program body.
27
+ * @returns An array of import names, including "default" for default imports.
28
+ */
29
+ declare function listImports(ast: ParseResult<t.File> | t.File): string[];
30
+ declare function isImportCall(calleePath: NodePath<t.CallExpression | t.NewExpression>): boolean;
31
+ /**
32
+ * Gets the import declaration for a given name and specifier.
33
+ *
34
+ * @param specifier - The specifier of the import.
35
+ * @param name - The name of the import.
36
+ * @param named - Optional named import.
37
+ * @returns The import declaration.
38
+ */
39
+ declare function getImport(specifier: string, name: string, named?: string): t.ImportDeclaration;
40
+ /**
41
+ * Adds an import to the program if it doesn't already exist.
42
+ *
43
+ * @param path - The current NodePath in the AST.
44
+ * @param specifier - The import specifier.
45
+ */
46
+ declare function addImport(path: NodePath<any>, specifier: ImportSpecifier): void;
47
+ declare function addImportsToProgram(path: NodePath<t.Program>, specifier: ImportSpecifier): void;
48
+ //#endregion
49
+ export { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports };
50
+ //# sourceMappingURL=module-helpers.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-helpers.d.mts","names":[],"sources":["../../src/helpers/module-helpers.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAgCA;AA6BA;AA4BA;;;AAAyD,iBAzDzC,UAAA,CAyDyC,GAAA,EAzDzB,WAyDyB,CAzDb,CAAA,CAAE,IAyDW,CAAA,EAAA,GAAA,EAAA,MAAA,CAAA,EAAA,GAAA;;AAsBzD;;;;;AAcgB,iBAhEA,WAAA,CAoEX,SAAA,EApEkC,WAoEjB,CApE6B,CAAA,CAAE,IAoE/B,CAAA,GAAA,MAAA,CAAA,EAAA,MAAA,EAAA;AAatB;AAuCA;;;;;iBA5FgB,WAAA,MAAiB,YAAY,CAAA,CAAE,QAAQ,CAAA,CAAE;iBAsBzC,YAAA,aACF,SAAS,CAAA,CAAE,iBAAiB,CAAA,CAAE;;;;;;;;;iBAa5B,SAAA,mDAIb,CAAA,CAAE;;;;;;;iBAaW,SAAA,OAAgB,0BAA0B;iBAuC1C,mBAAA,OACR,SAAS,CAAA,CAAE,qBACN"}
@@ -1,4 +1,96 @@
1
- import "../ast-utils-DU1foCxH.mjs";
2
- import { a as isImportCall, i as getImport, n as addImportsToProgram, o as listExports, r as findExport, s as listImports, t as addImport } from "../module-helpers-Ckq8sc4l.mjs";
1
+ import { parseAst } from "./ast-utils.mjs";
2
+ import * as t from "@babel/types";
3
+ import { isString } from "@stryke/type-checks/is-string";
3
4
 
4
- export { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports };
5
+ //#region src/helpers/module-helpers.ts
6
+ /**
7
+ * Finds an export in the given Babel AST program by its key.
8
+ *
9
+ * @param ast - The parsed Babel AST result containing the program body.
10
+ * @param key - The name of the export to find (e.g., "default" or a named export).
11
+ * @returns The declaration of the export if found, otherwise undefined.
12
+ */
13
+ function findExport(ast, key) {
14
+ const type = key === "default" ? "ExportDefaultDeclaration" : "ExportNamedDeclaration";
15
+ for (const node of ast.program.body) if (node.type === type) {
16
+ if (key === "default") return node.declaration;
17
+ if (node.declaration && "declarations" in node.declaration) {
18
+ const declaration = node.declaration.declarations[0];
19
+ if (declaration && "name" in declaration.id && declaration.id.name === key) return declaration.init;
20
+ }
21
+ }
22
+ }
23
+ /**
24
+ * Lists all exports from the given Babel AST program.
25
+ *
26
+ * @param codeOrAst - The parsed Babel AST result containing the program body.
27
+ * @returns An array of export names, including "default" for default exports.
28
+ */
29
+ function listExports(codeOrAst) {
30
+ return (isString(codeOrAst) ? parseAst(codeOrAst) : codeOrAst).program.body.flatMap((i) => {
31
+ if (i.type === "ExportDefaultDeclaration") return ["default"];
32
+ if (i.type === "ExportNamedDeclaration" && i.declaration && "declarations" in i.declaration) return i.declaration.declarations.map((d) => "name" in d.id ? d.id.name : "");
33
+ return [];
34
+ }).filter(Boolean);
35
+ }
36
+ /**
37
+ * Lists all imports from the given Babel AST program.
38
+ *
39
+ * @param ast - The parsed Babel AST result containing the program body.
40
+ * @returns An array of import names, including "default" for default imports.
41
+ */
42
+ function listImports(ast) {
43
+ return ast.program.body.flatMap((i) => {
44
+ if (i.type === "ImportDeclaration") return i.specifiers.map((s) => {
45
+ if (s.type === "ImportDefaultSpecifier") return "default";
46
+ if (s.type === "ImportSpecifier" && "imported" in s) return s.imported.type === "Identifier" ? s.imported.name : s.imported.value;
47
+ return "";
48
+ });
49
+ return [];
50
+ }).filter(Boolean);
51
+ }
52
+ function isImportCall(calleePath) {
53
+ return t.isImport(calleePath.node.callee);
54
+ }
55
+ /**
56
+ * Gets the import declaration for a given name and specifier.
57
+ *
58
+ * @param specifier - The specifier of the import.
59
+ * @param name - The name of the import.
60
+ * @param named - Optional named import.
61
+ * @returns The import declaration.
62
+ */
63
+ function getImport(specifier, name, named) {
64
+ return t.importDeclaration([t.importSpecifier(t.identifier(name), t.stringLiteral(named || name))], t.stringLiteral(specifier));
65
+ }
66
+ /**
67
+ * Adds an import to the program if it doesn't already exist.
68
+ *
69
+ * @param path - The current NodePath in the AST.
70
+ * @param specifier - The import specifier.
71
+ */
72
+ function addImport(path, specifier) {
73
+ addImportsToProgram(path.scope.getProgramParent().path, specifier);
74
+ }
75
+ function isNonNamespacedImport(importDeclPath) {
76
+ return importDeclPath.get("specifiers").filter(Boolean).every((specifier) => specifier?.isImportSpecifier()) && importDeclPath.node.importKind !== "type" && importDeclPath.node.importKind !== "typeof";
77
+ }
78
+ function getExistingImports(program) {
79
+ const existingImports = /* @__PURE__ */ new Map();
80
+ program.traverse({ ImportDeclaration(path) {
81
+ if (isNonNamespacedImport(path)) existingImports.set(path.node.source.value, path);
82
+ } });
83
+ return existingImports;
84
+ }
85
+ function addImportsToProgram(path, specifier) {
86
+ /**
87
+ * If an existing import of this module exists (ie \`import \{ ... \} from
88
+ * '<moduleName>'\`), inject new imported specifiers into the list of
89
+ * destructured variables.
90
+ */
91
+ if (!getExistingImports(path).get(specifier.module)) path.unshiftContainer("body", t.importDeclaration([t.importSpecifier(t.identifier(specifier.name || specifier.imported), t.identifier(specifier.imported))], t.stringLiteral(specifier.module)));
92
+ }
93
+
94
+ //#endregion
95
+ export { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports };
96
+ //# sourceMappingURL=module-helpers.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-helpers.mjs","names":[],"sources":["../../src/helpers/module-helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { NodePath } from \"@babel/core\";\nimport { ParseResult } from \"@babel/parser\";\nimport * as t from \"@babel/types\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { ImportSpecifier } from \"powerlines/types/babel\";\nimport { parseAst } from \"./ast-utils\";\n\n/**\n * Finds an export in the given Babel AST program by its key.\n *\n * @param ast - The parsed Babel AST result containing the program body.\n * @param key - The name of the export to find (e.g., \"default\" or a named export).\n * @returns The declaration of the export if found, otherwise undefined.\n */\nexport function findExport(ast: ParseResult<t.File>, key: string) {\n const type =\n key === \"default\" ? \"ExportDefaultDeclaration\" : \"ExportNamedDeclaration\";\n\n for (const node of ast.program.body) {\n if (node.type === type) {\n if (key === \"default\") {\n return node.declaration;\n }\n if (node.declaration && \"declarations\" in node.declaration) {\n const declaration = node.declaration.declarations[0];\n if (\n declaration &&\n \"name\" in declaration.id &&\n declaration.id.name === key\n ) {\n return declaration.init as any;\n }\n }\n }\n }\n}\n\n/**\n * Lists all exports from the given Babel AST program.\n *\n * @param codeOrAst - The parsed Babel AST result containing the program body.\n * @returns An array of export names, including \"default\" for default exports.\n */\nexport function listExports(codeOrAst: ParseResult<t.File> | string) {\n const ast = isString(codeOrAst) ? parseAst(codeOrAst) : codeOrAst;\n\n return ast.program.body\n .flatMap(i => {\n if (i.type === \"ExportDefaultDeclaration\") {\n return [\"default\"];\n }\n if (\n i.type === \"ExportNamedDeclaration\" &&\n i.declaration &&\n \"declarations\" in i.declaration\n ) {\n return i.declaration.declarations.map(d =>\n \"name\" in d.id ? d.id.name : \"\"\n );\n }\n return [];\n })\n .filter(Boolean);\n}\n\n/**\n * Lists all imports from the given Babel AST program.\n *\n * @param ast - The parsed Babel AST result containing the program body.\n * @returns An array of import names, including \"default\" for default imports.\n */\nexport function listImports(ast: ParseResult<t.File> | t.File) {\n return ast.program.body\n .flatMap(i => {\n if (i.type === \"ImportDeclaration\") {\n return i.specifiers.map(s => {\n if (s.type === \"ImportDefaultSpecifier\") {\n return \"default\";\n }\n if (s.type === \"ImportSpecifier\" && \"imported\" in s) {\n return s.imported.type === \"Identifier\"\n ? s.imported.name\n : s.imported.value;\n }\n return \"\";\n });\n }\n\n return [];\n })\n .filter(Boolean);\n}\n\nexport function isImportCall(\n calleePath: NodePath<t.CallExpression | t.NewExpression>\n) {\n return t.isImport(calleePath.node.callee);\n}\n\n/**\n * Gets the import declaration for a given name and specifier.\n *\n * @param specifier - The specifier of the import.\n * @param name - The name of the import.\n * @param named - Optional named import.\n * @returns The import declaration.\n */\nexport function getImport(\n specifier: string,\n name: string,\n named?: string\n): t.ImportDeclaration {\n return t.importDeclaration(\n [t.importSpecifier(t.identifier(name), t.stringLiteral(named || name))],\n t.stringLiteral(specifier)\n );\n}\n\n/**\n * Adds an import to the program if it doesn't already exist.\n *\n * @param path - The current NodePath in the AST.\n * @param specifier - The import specifier.\n */\nexport function addImport(path: NodePath<any>, specifier: ImportSpecifier) {\n addImportsToProgram(\n path.scope.getProgramParent().path as NodePath<t.Program>,\n specifier\n );\n}\n\n/*\n * Matches `import { ... } from <moduleName>;`\n * but not `import * as React from <moduleName>;`\n * `import type { Foo } from <moduleName>;`\n */\nfunction isNonNamespacedImport(\n importDeclPath: NodePath<t.ImportDeclaration>\n): boolean {\n return (\n importDeclPath\n .get(\"specifiers\")\n .filter(Boolean)\n .every(specifier => specifier?.isImportSpecifier()) &&\n importDeclPath.node.importKind !== \"type\" &&\n importDeclPath.node.importKind !== \"typeof\"\n );\n}\n\nfunction getExistingImports(\n program: NodePath<t.Program>\n): Map<string, NodePath<t.ImportDeclaration>> {\n const existingImports = new Map<string, NodePath<t.ImportDeclaration>>();\n program.traverse({\n ImportDeclaration(path) {\n if (isNonNamespacedImport(path)) {\n existingImports.set(path.node.source.value, path);\n }\n }\n });\n return existingImports;\n}\n\nexport function addImportsToProgram(\n path: NodePath<t.Program>,\n specifier: ImportSpecifier\n): void {\n const existingImports = getExistingImports(path);\n\n /**\n * If an existing import of this module exists (ie \\`import \\{ ... \\} from\n * '<moduleName>'\\`), inject new imported specifiers into the list of\n * destructured variables.\n */\n if (!existingImports.get(specifier.module)) {\n path.unshiftContainer(\n \"body\",\n t.importDeclaration(\n [\n t.importSpecifier(\n t.identifier(specifier.name || specifier.imported),\n t.identifier(specifier.imported)\n )\n ],\n t.stringLiteral(specifier.module)\n )\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;AAgCA,SAAgB,WAAW,KAA0B,KAAa;CAChE,MAAM,OACJ,QAAQ,YAAY,6BAA6B;AAEnD,MAAK,MAAM,QAAQ,IAAI,QAAQ,KAC7B,KAAI,KAAK,SAAS,MAAM;AACtB,MAAI,QAAQ,UACV,QAAO,KAAK;AAEd,MAAI,KAAK,eAAe,kBAAkB,KAAK,aAAa;GAC1D,MAAM,cAAc,KAAK,YAAY,aAAa;AAClD,OACE,eACA,UAAU,YAAY,MACtB,YAAY,GAAG,SAAS,IAExB,QAAO,YAAY;;;;;;;;;;AAa7B,SAAgB,YAAY,WAAyC;AAGnE,SAFY,SAAS,UAAU,GAAG,SAAS,UAAU,GAAG,WAE7C,QAAQ,KAChB,SAAQ,MAAK;AACZ,MAAI,EAAE,SAAS,2BACb,QAAO,CAAC,UAAU;AAEpB,MACE,EAAE,SAAS,4BACX,EAAE,eACF,kBAAkB,EAAE,YAEpB,QAAO,EAAE,YAAY,aAAa,KAAI,MACpC,UAAU,EAAE,KAAK,EAAE,GAAG,OAAO,GAC9B;AAEH,SAAO,EAAE;GACT,CACD,OAAO,QAAQ;;;;;;;;AASpB,SAAgB,YAAY,KAAmC;AAC7D,QAAO,IAAI,QAAQ,KAChB,SAAQ,MAAK;AACZ,MAAI,EAAE,SAAS,oBACb,QAAO,EAAE,WAAW,KAAI,MAAK;AAC3B,OAAI,EAAE,SAAS,yBACb,QAAO;AAET,OAAI,EAAE,SAAS,qBAAqB,cAAc,EAChD,QAAO,EAAE,SAAS,SAAS,eACvB,EAAE,SAAS,OACX,EAAE,SAAS;AAEjB,UAAO;IACP;AAGJ,SAAO,EAAE;GACT,CACD,OAAO,QAAQ;;AAGpB,SAAgB,aACd,YACA;AACA,QAAO,EAAE,SAAS,WAAW,KAAK,OAAO;;;;;;;;;;AAW3C,SAAgB,UACd,WACA,MACA,OACqB;AACrB,QAAO,EAAE,kBACP,CAAC,EAAE,gBAAgB,EAAE,WAAW,KAAK,EAAE,EAAE,cAAc,SAAS,KAAK,CAAC,CAAC,EACvE,EAAE,cAAc,UAAU,CAC3B;;;;;;;;AASH,SAAgB,UAAU,MAAqB,WAA4B;AACzE,qBACE,KAAK,MAAM,kBAAkB,CAAC,MAC9B,UACD;;AAQH,SAAS,sBACP,gBACS;AACT,QACE,eACG,IAAI,aAAa,CACjB,OAAO,QAAQ,CACf,OAAM,cAAa,WAAW,mBAAmB,CAAC,IACrD,eAAe,KAAK,eAAe,UACnC,eAAe,KAAK,eAAe;;AAIvC,SAAS,mBACP,SAC4C;CAC5C,MAAM,kCAAkB,IAAI,KAA4C;AACxE,SAAQ,SAAS,EACf,kBAAkB,MAAM;AACtB,MAAI,sBAAsB,KAAK,CAC7B,iBAAgB,IAAI,KAAK,KAAK,OAAO,OAAO,KAAK;IAGtD,CAAC;AACF,QAAO;;AAGT,SAAgB,oBACd,MACA,WACM;;;;;;AAQN,KAAI,CAPoB,mBAAmB,KAAK,CAO3B,IAAI,UAAU,OAAO,CACxC,MAAK,iBACH,QACA,EAAE,kBACA,CACE,EAAE,gBACA,EAAE,WAAW,UAAU,QAAQ,UAAU,SAAS,EAClD,EAAE,WAAW,UAAU,SAAS,CACjC,CACF,EACD,EAAE,cAAc,UAAU,OAAO,CAClC,CACF"}
@@ -1,5 +1,49 @@
1
- require('../filters-CU0L1nIa.cjs');
2
- const require_options = require('../options-2JL6WIXT.cjs');
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_helpers_filters = require('./filters.cjs');
3
+ let __stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
4
+ let chalk = require("chalk");
5
+ chalk = require_rolldown_runtime.__toESM(chalk);
3
6
 
4
- exports.resolveBabelPlugin = require_options.resolveBabelPlugin;
5
- exports.resolvePluginFunction = require_options.resolvePluginFunction;
7
+ //#region src/helpers/options.ts
8
+ function resolvePluginFunction(context, plugin) {
9
+ try {
10
+ return Array.isArray(plugin) && plugin.length > 0 && plugin[0] ? (0, __stryke_type_checks_is_function.isFunction)(plugin[0]) ? plugin[0](context) : plugin[0] : (0, __stryke_type_checks_is_function.isFunction)(plugin) ? plugin(context) : plugin;
11
+ } catch {
12
+ return plugin[0];
13
+ }
14
+ }
15
+ /**
16
+ * Resolve the [Babel](https://babeljs.io/) plugin.
17
+ *
18
+ * @param context - The context for the transformation.
19
+ * @param code - The code to be transformed.
20
+ * @param id - The ID of the source file.
21
+ * @param plugin - The Babel plugin to resolve.
22
+ * @returns The resolved Babel plugin options, or undefined if the plugin is filtered out.
23
+ */
24
+ function resolveBabelPlugin(context, code, id, plugin) {
25
+ if (Array.isArray(plugin) && plugin.length > 0 && plugin[0]) {
26
+ if (plugin.length > 2 && plugin[2] && (0, __stryke_type_checks_is_function.isFunction)(plugin[2]) && !plugin[2](code, id)) {
27
+ context.trace(`Skipping filtered Babel plugin ${chalk.default.bold.cyanBright(require_helpers_filters.getPluginName(plugin) || "unnamed")} for ${id}`);
28
+ return;
29
+ }
30
+ return plugin.length > 2 ? [
31
+ resolvePluginFunction(context, plugin),
32
+ plugin[1],
33
+ plugin[2]
34
+ ] : [
35
+ resolvePluginFunction(context, plugin),
36
+ plugin[1],
37
+ null
38
+ ];
39
+ }
40
+ return [
41
+ resolvePluginFunction(context, plugin),
42
+ {},
43
+ null
44
+ ];
45
+ }
46
+
47
+ //#endregion
48
+ exports.resolveBabelPlugin = resolveBabelPlugin;
49
+ exports.resolvePluginFunction = resolvePluginFunction;
@@ -1,2 +1,19 @@
1
- import { n as resolvePluginFunction, t as resolveBabelPlugin } from "../options-DZkAyLff.cjs";
2
- export { resolveBabelPlugin, resolvePluginFunction };
1
+ import { BabelTransformPluginOptions, ResolvedBabelTransformPluginOptions } from "powerlines/types/babel";
2
+ import { Context } from "powerlines/types/context";
3
+ import { PluginOptions, PluginTarget } from "@babel/core";
4
+
5
+ //#region src/helpers/options.d.ts
6
+ declare function resolvePluginFunction(context: Context, plugin: any | PluginTarget | any[] | [PluginTarget, PluginOptions] | [PluginTarget, PluginOptions, string | undefined]): BabelTransformPluginOptions;
7
+ /**
8
+ * Resolve the [Babel](https://babeljs.io/) plugin.
9
+ *
10
+ * @param context - The context for the transformation.
11
+ * @param code - The code to be transformed.
12
+ * @param id - The ID of the source file.
13
+ * @param plugin - The Babel plugin to resolve.
14
+ * @returns The resolved Babel plugin options, or undefined if the plugin is filtered out.
15
+ */
16
+ declare function resolveBabelPlugin(context: Context, code: string, id: string, plugin: BabelTransformPluginOptions): ResolvedBabelTransformPluginOptions | undefined;
17
+ //#endregion
18
+ export { resolveBabelPlugin, resolvePluginFunction };
19
+ //# sourceMappingURL=options.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.cts","names":[],"sources":["../../src/helpers/options.ts"],"sourcesContent":[],"mappings":";;;;;iBA4BgB,qBAAA,UACL,uBAGL,wBAEC,cAAc,kBACd,cAAc,qCAClB;;AARH;;;;;;;;AAQ8B,iBAuBd,kBAAA,CAvBc,OAAA,EAwBnB,OAxBmB,EAAA,IAAA,EAAA,MAAA,EAAA,EAAA,EAAA,MAAA,EAAA,MAAA,EA2BpB,2BA3BoB,CAAA,EA4B3B,mCA5B2B,GAAA,SAAA"}
@@ -1,2 +1,19 @@
1
- import { n as resolvePluginFunction, t as resolveBabelPlugin } from "../options-CpZXObFr.mjs";
2
- export { resolveBabelPlugin, resolvePluginFunction };
1
+ import { PluginOptions, PluginTarget } from "@babel/core";
2
+ import { BabelTransformPluginOptions, ResolvedBabelTransformPluginOptions } from "powerlines/types/babel";
3
+ import { Context } from "powerlines/types/context";
4
+
5
+ //#region src/helpers/options.d.ts
6
+ declare function resolvePluginFunction(context: Context, plugin: any | PluginTarget | any[] | [PluginTarget, PluginOptions] | [PluginTarget, PluginOptions, string | undefined]): BabelTransformPluginOptions;
7
+ /**
8
+ * Resolve the [Babel](https://babeljs.io/) plugin.
9
+ *
10
+ * @param context - The context for the transformation.
11
+ * @param code - The code to be transformed.
12
+ * @param id - The ID of the source file.
13
+ * @param plugin - The Babel plugin to resolve.
14
+ * @returns The resolved Babel plugin options, or undefined if the plugin is filtered out.
15
+ */
16
+ declare function resolveBabelPlugin(context: Context, code: string, id: string, plugin: BabelTransformPluginOptions): ResolvedBabelTransformPluginOptions | undefined;
17
+ //#endregion
18
+ export { resolveBabelPlugin, resolvePluginFunction };
19
+ //# sourceMappingURL=options.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.mts","names":[],"sources":["../../src/helpers/options.ts"],"sourcesContent":[],"mappings":";;;;;iBA4BgB,qBAAA,UACL,uBAGL,wBAEC,cAAc,kBACd,cAAc,qCAClB;;AARH;;;;;;;;AAQ8B,iBAuBd,kBAAA,CAvBc,OAAA,EAwBnB,OAxBmB,EAAA,IAAA,EAAA,MAAA,EAAA,EAAA,EAAA,MAAA,EAAA,MAAA,EA2BpB,2BA3BoB,CAAA,EA4B3B,mCA5B2B,GAAA,SAAA"}
@@ -1,4 +1,47 @@
1
- import "../filters-CpjboNi8.mjs";
2
- import { n as resolvePluginFunction, t as resolveBabelPlugin } from "../options-DwynxlP6.mjs";
1
+ import { getPluginName } from "./filters.mjs";
2
+ import { isFunction } from "@stryke/type-checks/is-function";
3
+ import chalk from "chalk";
3
4
 
4
- export { resolveBabelPlugin, resolvePluginFunction };
5
+ //#region src/helpers/options.ts
6
+ function resolvePluginFunction(context, plugin) {
7
+ try {
8
+ return Array.isArray(plugin) && plugin.length > 0 && plugin[0] ? isFunction(plugin[0]) ? plugin[0](context) : plugin[0] : isFunction(plugin) ? plugin(context) : plugin;
9
+ } catch {
10
+ return plugin[0];
11
+ }
12
+ }
13
+ /**
14
+ * Resolve the [Babel](https://babeljs.io/) plugin.
15
+ *
16
+ * @param context - The context for the transformation.
17
+ * @param code - The code to be transformed.
18
+ * @param id - The ID of the source file.
19
+ * @param plugin - The Babel plugin to resolve.
20
+ * @returns The resolved Babel plugin options, or undefined if the plugin is filtered out.
21
+ */
22
+ function resolveBabelPlugin(context, code, id, plugin) {
23
+ if (Array.isArray(plugin) && plugin.length > 0 && plugin[0]) {
24
+ if (plugin.length > 2 && plugin[2] && isFunction(plugin[2]) && !plugin[2](code, id)) {
25
+ context.trace(`Skipping filtered Babel plugin ${chalk.bold.cyanBright(getPluginName(plugin) || "unnamed")} for ${id}`);
26
+ return;
27
+ }
28
+ return plugin.length > 2 ? [
29
+ resolvePluginFunction(context, plugin),
30
+ plugin[1],
31
+ plugin[2]
32
+ ] : [
33
+ resolvePluginFunction(context, plugin),
34
+ plugin[1],
35
+ null
36
+ ];
37
+ }
38
+ return [
39
+ resolvePluginFunction(context, plugin),
40
+ {},
41
+ null
42
+ ];
43
+ }
44
+
45
+ //#endregion
46
+ export { resolveBabelPlugin, resolvePluginFunction };
47
+ //# sourceMappingURL=options.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.mjs","names":[],"sources":["../../src/helpers/options.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { PluginOptions, PluginTarget } from \"@babel/core\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport chalk from \"chalk\";\nimport {\n BabelTransformPluginOptions,\n ResolvedBabelTransformPluginOptions\n} from \"powerlines/types/babel\";\nimport { Context } from \"powerlines/types/context\";\nimport { getPluginName } from \"./filters\";\n\nexport function resolvePluginFunction(\n context: Context,\n plugin:\n | any\n | PluginTarget\n | any[]\n | [PluginTarget, PluginOptions]\n | [PluginTarget, PluginOptions, string | undefined]\n): BabelTransformPluginOptions {\n try {\n return Array.isArray(plugin) && plugin.length > 0 && plugin[0]\n ? isFunction(plugin[0])\n ? plugin[0](context)\n : plugin[0]\n : isFunction(plugin)\n ? plugin(context)\n : plugin;\n } catch {\n return plugin[0];\n }\n}\n\n/**\n * Resolve the [Babel](https://babeljs.io/) plugin.\n *\n * @param context - The context for the transformation.\n * @param code - The code to be transformed.\n * @param id - The ID of the source file.\n * @param plugin - The Babel plugin to resolve.\n * @returns The resolved Babel plugin options, or undefined if the plugin is filtered out.\n */\nexport function resolveBabelPlugin(\n context: Context,\n code: string,\n id: string,\n plugin: BabelTransformPluginOptions\n): ResolvedBabelTransformPluginOptions | undefined {\n if (Array.isArray(plugin) && plugin.length > 0 && plugin[0]) {\n if (\n plugin.length > 2 &&\n plugin[2] &&\n isFunction(plugin[2]) &&\n !plugin[2](code, id)\n ) {\n context.trace(\n `Skipping filtered Babel plugin ${chalk.bold.cyanBright(\n getPluginName(plugin) || \"unnamed\"\n )} for ${id}`\n );\n\n return undefined;\n }\n\n return plugin.length > 2\n ? [resolvePluginFunction(context, plugin), plugin[1], plugin[2]]\n : [resolvePluginFunction(context, plugin), plugin[1], null];\n }\n\n return [resolvePluginFunction(context, plugin), {}, null];\n}\n"],"mappings":";;;;;AA4BA,SAAgB,sBACd,SACA,QAM6B;AAC7B,KAAI;AACF,SAAO,MAAM,QAAQ,OAAO,IAAI,OAAO,SAAS,KAAK,OAAO,KACxD,WAAW,OAAO,GAAG,GACnB,OAAO,GAAG,QAAQ,GAClB,OAAO,KACT,WAAW,OAAO,GAChB,OAAO,QAAQ,GACf;SACA;AACN,SAAO,OAAO;;;;;;;;;;;;AAalB,SAAgB,mBACd,SACA,MACA,IACA,QACiD;AACjD,KAAI,MAAM,QAAQ,OAAO,IAAI,OAAO,SAAS,KAAK,OAAO,IAAI;AAC3D,MACE,OAAO,SAAS,KAChB,OAAO,MACP,WAAW,OAAO,GAAG,IACrB,CAAC,OAAO,GAAG,MAAM,GAAG,EACpB;AACA,WAAQ,MACN,kCAAkC,MAAM,KAAK,WAC3C,cAAc,OAAO,IAAI,UAC1B,CAAC,OAAO,KACV;AAED;;AAGF,SAAO,OAAO,SAAS,IACnB;GAAC,sBAAsB,SAAS,OAAO;GAAE,OAAO;GAAI,OAAO;GAAG,GAC9D;GAAC,sBAAsB,SAAS,OAAO;GAAE,OAAO;GAAI;GAAK;;AAG/D,QAAO;EAAC,sBAAsB,SAAS,OAAO;EAAE,EAAE;EAAE;EAAK"}
package/dist/index.cjs CHANGED
@@ -1,19 +1,17 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
- const require_chunk = require('./chunk-CbDLau6x.cjs');
3
- const require_filters = require('./filters-CU0L1nIa.cjs');
4
- const require_options = require('./options-2JL6WIXT.cjs');
5
- const require_ast_utils = require('./ast-utils-BcmWaIan.cjs');
6
- const require_create_plugin = require('./create-plugin-Bf7dRYZB.cjs');
7
- const require_module_helpers = require('./module-helpers-Non-jHMu.cjs');
8
- require('./helpers-Bx2yBrpn.cjs');
9
- require('./plugin-BSBH78mm.cjs');
10
- require('./types-CKPddlfS.cjs');
2
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
3
+ const require_helpers_filters = require('./helpers/filters.cjs');
4
+ const require_helpers_options = require('./helpers/options.cjs');
5
+ const require_helpers_ast_utils = require('./helpers/ast-utils.cjs');
6
+ const require_helpers_create_plugin = require('./helpers/create-plugin.cjs');
7
+ const require_helpers_module_helpers = require('./helpers/module-helpers.cjs');
8
+ require('./helpers/index.cjs');
11
9
  let __babel_core = require("@babel/core");
12
10
  let __stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
13
11
  let __stryke_path_is_parent_path = require("@stryke/path/is-parent-path");
14
12
  let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
15
13
  let defu = require("defu");
16
- defu = require_chunk.__toESM(defu);
14
+ defu = require_rolldown_runtime.__toESM(defu);
17
15
 
18
16
  //#region src/index.ts
19
17
  /**
@@ -46,13 +44,13 @@ const plugin = (options = {}) => {
46
44
  id
47
45
  };
48
46
  }
49
- const plugins = this.config.transform.babel.plugins.map((plugin$1) => require_options.resolveBabelPlugin(this, code, id, plugin$1)).filter((plugin$1, _, arr) => plugin$1 && !require_filters.isDuplicatePlugin(arr, plugin$1));
50
- const presets = this.config.transform.babel.presets.map((preset) => require_options.resolveBabelPlugin(this, code, id, preset)).filter((preset, _, arr) => preset && !require_filters.isDuplicatePlugin(arr, preset));
47
+ const plugins = this.config.transform.babel.plugins.map((plugin$1) => require_helpers_options.resolveBabelPlugin(this, code, id, plugin$1)).filter((plugin$1, _, arr) => plugin$1 && !require_helpers_filters.isDuplicatePlugin(arr, plugin$1));
48
+ const presets = this.config.transform.babel.presets.map((preset) => require_helpers_options.resolveBabelPlugin(this, code, id, preset)).filter((preset, _, arr) => preset && !require_helpers_filters.isDuplicatePlugin(arr, preset));
51
49
  if (Array.isArray(plugins) && plugins.length === 0 && Array.isArray(presets) && presets.length === 0) return {
52
50
  code,
53
51
  id
54
52
  };
55
- if (/^(?:m|c)?tsx?$/.test((0, __stryke_path_file_path_fns.findFileExtensionSafe)(id, { fullExtension: true })) && !require_filters.isDuplicatePlugin(plugins, "@babel/plugin-syntax-typescript") && !require_filters.isDuplicatePlugin(presets, "@babel/preset-typescript")) plugins.unshift(["@babel/plugin-syntax-typescript", { isTSX: (0, __stryke_path_file_path_fns.findFileExtension)(id) === "tsx" }]);
53
+ if (/^(?:m|c)?tsx?$/.test((0, __stryke_path_file_path_fns.findFileExtensionSafe)(id, { fullExtension: true })) && !require_helpers_filters.isDuplicatePlugin(plugins, "@babel/plugin-syntax-typescript") && !require_helpers_filters.isDuplicatePlugin(presets, "@babel/preset-typescript")) plugins.unshift(["@babel/plugin-syntax-typescript", { isTSX: (0, __stryke_path_file_path_fns.findFileExtension)(id) === "tsx" }]);
56
54
  this.trace(`Running babel transformations with ${plugins.length} plugins and ${presets.length} presets for file: ${id}`);
57
55
  const result = await (0, __babel_core.transformAsync)(code, {
58
56
  highlightCode: true,
@@ -86,21 +84,21 @@ const plugin = (options = {}) => {
86
84
  var src_default = plugin;
87
85
 
88
86
  //#endregion
89
- exports.addImport = require_module_helpers.addImport;
90
- exports.addImportsToProgram = require_module_helpers.addImportsToProgram;
91
- exports.addPluginFilter = require_filters.addPluginFilter;
92
- exports.createBabelPlugin = require_create_plugin.createBabelPlugin;
87
+ exports.addImport = require_helpers_module_helpers.addImport;
88
+ exports.addImportsToProgram = require_helpers_module_helpers.addImportsToProgram;
89
+ exports.addPluginFilter = require_helpers_filters.addPluginFilter;
90
+ exports.createBabelPlugin = require_helpers_create_plugin.createBabelPlugin;
93
91
  exports.default = src_default;
94
- exports.filterPluginByFileId = require_filters.filterPluginByFileId;
95
- exports.findExport = require_module_helpers.findExport;
96
- exports.generateFromAst = require_ast_utils.generateFromAst;
97
- exports.getImport = require_module_helpers.getImport;
98
- exports.getPluginName = require_filters.getPluginName;
99
- exports.isDuplicatePlugin = require_filters.isDuplicatePlugin;
100
- exports.isImportCall = require_module_helpers.isImportCall;
101
- exports.listExports = require_module_helpers.listExports;
102
- exports.listImports = require_module_helpers.listImports;
103
- exports.parseAst = require_ast_utils.parseAst;
92
+ exports.filterPluginByFileId = require_helpers_filters.filterPluginByFileId;
93
+ exports.findExport = require_helpers_module_helpers.findExport;
94
+ exports.generateFromAst = require_helpers_ast_utils.generateFromAst;
95
+ exports.getImport = require_helpers_module_helpers.getImport;
96
+ exports.getPluginName = require_helpers_filters.getPluginName;
97
+ exports.isDuplicatePlugin = require_helpers_filters.isDuplicatePlugin;
98
+ exports.isImportCall = require_helpers_module_helpers.isImportCall;
99
+ exports.listExports = require_helpers_module_helpers.listExports;
100
+ exports.listImports = require_helpers_module_helpers.listImports;
101
+ exports.parseAst = require_helpers_ast_utils.parseAst;
104
102
  exports.plugin = plugin;
105
- exports.resolveBabelPlugin = require_options.resolveBabelPlugin;
106
- exports.resolvePluginFunction = require_options.resolvePluginFunction;
103
+ exports.resolveBabelPlugin = require_helpers_options.resolveBabelPlugin;
104
+ exports.resolvePluginFunction = require_helpers_options.resolvePluginFunction;