rolldown 1.0.0-beta.9-commit.0ec9e7d → 1.0.0-rc.1

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 (68) hide show
  1. package/README.md +11 -0
  2. package/bin/cli.mjs +1 -0
  3. package/dist/cli-setup.mjs +17 -0
  4. package/dist/cli.mjs +1085 -1281
  5. package/dist/config.d.mts +2 -4
  6. package/dist/config.mjs +8 -5
  7. package/dist/experimental-index.d.mts +161 -76
  8. package/dist/experimental-index.mjs +227 -61
  9. package/dist/experimental-runtime-types.d.ts +98 -0
  10. package/dist/filter-index.d.mts +196 -4
  11. package/dist/filter-index.mjs +328 -4
  12. package/dist/get-log-filter.d.mts +7 -0
  13. package/dist/get-log-filter.mjs +48 -0
  14. package/dist/index.d.mts +4 -4
  15. package/dist/index.mjs +56 -5
  16. package/dist/parallel-plugin-worker.mjs +27 -33
  17. package/dist/parallel-plugin.d.mts +7 -8
  18. package/dist/parse-ast-index.d.mts +4 -5
  19. package/dist/parse-ast-index.mjs +2 -2
  20. package/dist/plugins-index.d.mts +30 -0
  21. package/dist/plugins-index.mjs +40 -0
  22. package/dist/shared/binding-B92Lq__Q.d.mts +1687 -0
  23. package/dist/shared/binding-C-UNREnT.mjs +585 -0
  24. package/dist/shared/bindingify-input-options-Cb-01HR1.mjs +2233 -0
  25. package/dist/shared/constructors-D_KFsTQ-.d.mts +28 -0
  26. package/dist/shared/constructors-aZ82R2dj.mjs +61 -0
  27. package/dist/shared/define-config-BVG4QvnP.mjs +7 -0
  28. package/dist/shared/define-config-DO4TBkJV.d.mts +3457 -0
  29. package/dist/shared/{load-config-Dll-92l5.mjs → load-config-D6cey0o1.mjs} +23 -33
  30. package/dist/shared/logging-wIy4zY9I.d.mts +50 -0
  31. package/dist/shared/logs-NH298mHo.mjs +183 -0
  32. package/dist/shared/{misc-DGAe2XOW.mjs → misc-CCZIsXVO.mjs} +1 -7
  33. package/dist/shared/normalize-string-or-regex-Dq50a7l9.mjs +61 -0
  34. package/dist/shared/parse-ast-index-B6LAhWD8.mjs +99 -0
  35. package/dist/shared/{prompt-CxjDC0Gn.cjs → prompt-tlfjalEt.mjs} +301 -308
  36. package/dist/shared/rolldown-CIC_OHw3.mjs +42 -0
  37. package/dist/shared/rolldown-build-KB1YaNe-.mjs +2369 -0
  38. package/dist/shared/watch-B2WRkpw2.mjs +379 -0
  39. package/package.json +86 -98
  40. package/dist/cli.cjs +0 -1748
  41. package/dist/config.cjs +0 -12
  42. package/dist/config.d.cts +0 -12
  43. package/dist/experimental-index.cjs +0 -132
  44. package/dist/experimental-index.d.cts +0 -96
  45. package/dist/filter-index.cjs +0 -105
  46. package/dist/filter-index.d.cts +0 -5
  47. package/dist/index.cjs +0 -9
  48. package/dist/index.d.cts +0 -4
  49. package/dist/parallel-plugin-worker.cjs +0 -33
  50. package/dist/parallel-plugin-worker.d.cts +0 -1
  51. package/dist/parallel-plugin.cjs +0 -8
  52. package/dist/parallel-plugin.d.cts +0 -15
  53. package/dist/parse-ast-index.cjs +0 -4
  54. package/dist/parse-ast-index.d.cts +0 -9
  55. package/dist/shared/binding.d-Dz3qQrbl.d.mts +0 -1682
  56. package/dist/shared/binding.d-QXzDcVmm.d.cts +0 -1682
  57. package/dist/shared/chunk--iN_1bjD.mjs +0 -33
  58. package/dist/shared/chunk-DDkG_k5U.cjs +0 -39
  59. package/dist/shared/define-config.d-CUcDq_vm.d.cts +0 -1080
  60. package/dist/shared/define-config.d-qV1PzX_C.d.mts +0 -1080
  61. package/dist/shared/load-config-Bx9W9x2a.cjs +0 -125
  62. package/dist/shared/misc-BKp5iIef.cjs +0 -67
  63. package/dist/shared/parse-ast-index-0m6JgGc9.mjs +0 -655
  64. package/dist/shared/parse-ast-index-Cn_efzjO.cjs +0 -697
  65. package/dist/shared/prompt-uGrwvyp0.mjs +0 -854
  66. package/dist/shared/src-B4EklR3U.mjs +0 -4704
  67. package/dist/shared/src-BzFe16tX.cjs +0 -4654
  68. /package/dist/{cli.d.cts → cli-setup.d.mts} +0 -0
@@ -1,10 +1,9 @@
1
- import { __esm } from "./chunk--iN_1bjD.mjs";
2
- import { init_rolldown, rolldown } from "./src-B4EklR3U.mjs";
1
+ import { t as rolldown } from "./rolldown-CIC_OHw3.mjs";
3
2
  import fs from "node:fs";
4
3
  import path from "node:path";
4
+ import { readdir } from "node:fs/promises";
5
5
  import { pathToFileURL } from "node:url";
6
6
  import { cwd } from "node:process";
7
- import { readdir } from "node:fs/promises";
8
7
 
9
8
  //#region src/utils/load-config.ts
10
9
  async function bundleTsConfig(configFile, isEsm) {
@@ -15,13 +14,13 @@ async function bundleTsConfig(configFile, isEsm) {
15
14
  input: configFile,
16
15
  platform: "node",
17
16
  resolve: { mainFields: ["main"] },
18
- define: {
17
+ transform: { define: {
19
18
  __dirname: dirnameVarName,
20
19
  __filename: filenameVarName,
21
20
  "import.meta.url": importMetaUrlVarName,
22
21
  "import.meta.dirname": dirnameVarName,
23
22
  "import.meta.filename": filenameVarName
24
- },
23
+ } },
25
24
  treeshake: false,
26
25
  external: [/^[\w@][^:]/],
27
26
  plugins: [{
@@ -29,9 +28,8 @@ async function bundleTsConfig(configFile, isEsm) {
29
28
  transform: {
30
29
  filter: { id: /\.[cm]?[jt]s$/ },
31
30
  async handler(code, id) {
32
- const injectValues = `const ${dirnameVarName} = ${JSON.stringify(path.dirname(id))};const ${filenameVarName} = ${JSON.stringify(id)};const ${importMetaUrlVarName} = ${JSON.stringify(pathToFileURL(id).href)};`;
33
31
  return {
34
- code: injectValues + code,
32
+ code: `const ${dirnameVarName} = ${JSON.stringify(path.dirname(id))};const ${filenameVarName} = ${JSON.stringify(id)};const ${importMetaUrlVarName} = ${JSON.stringify(pathToFileURL(id).href)};` + code,
35
33
  map: null
36
34
  };
37
35
  }
@@ -39,15 +37,26 @@ async function bundleTsConfig(configFile, isEsm) {
39
37
  }]
40
38
  });
41
39
  const outputDir = path.dirname(configFile);
42
- const result = await bundle.write({
40
+ const fileName = (await bundle.write({
43
41
  dir: outputDir,
44
42
  format: isEsm ? "esm" : "cjs",
45
43
  sourcemap: "inline",
46
44
  entryFileNames: `rolldown.config.[hash]${path.extname(configFile).replace("ts", "js")}`
47
- });
48
- const fileName = result.output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
45
+ })).output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
49
46
  return path.join(outputDir, fileName);
50
47
  }
48
+ const SUPPORTED_JS_CONFIG_FORMATS = [
49
+ ".js",
50
+ ".mjs",
51
+ ".cjs"
52
+ ];
53
+ const SUPPORTED_TS_CONFIG_FORMATS = [
54
+ ".ts",
55
+ ".mts",
56
+ ".cts"
57
+ ];
58
+ const SUPPORTED_CONFIG_FORMATS = [...SUPPORTED_JS_CONFIG_FORMATS, ...SUPPORTED_TS_CONFIG_FORMATS];
59
+ const DEFAULT_CONFIG_BASE = "rolldown.config";
51
60
  async function findConfigFileNameInCwd() {
52
61
  const filesInWorkingDirectory = new Set(await readdir(cwd()));
53
62
  for (const extension of SUPPORTED_CONFIG_FORMATS) {
@@ -57,8 +66,7 @@ async function findConfigFileNameInCwd() {
57
66
  throw new Error("No `rolldown.config` configuration file found.");
58
67
  }
59
68
  async function loadTsConfig(configFile) {
60
- const isEsm = isFilePathESM(configFile);
61
- const file = await bundleTsConfig(configFile, isEsm);
69
+ const file = await bundleTsConfig(configFile, isFilePathESM(configFile));
62
70
  try {
63
71
  return (await import(pathToFileURL(file).href)).default;
64
72
  } finally {
@@ -95,30 +103,12 @@ async function loadConfig(configPath) {
95
103
  const ext = path.extname(configPath = configPath || await findConfigFileNameInCwd());
96
104
  try {
97
105
  if (SUPPORTED_JS_CONFIG_FORMATS.includes(ext) || process.env.NODE_OPTIONS?.includes("--import=tsx") && SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) return (await import(pathToFileURL(configPath).href)).default;
98
- else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) {
99
- const rawConfigPath = path.resolve(configPath);
100
- return await loadTsConfig(rawConfigPath);
101
- } else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
106
+ else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) return await loadTsConfig(path.resolve(configPath));
107
+ else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
102
108
  } catch (err) {
103
109
  throw new Error("Error happened while loading config.", { cause: err });
104
110
  }
105
111
  }
106
- var SUPPORTED_JS_CONFIG_FORMATS, SUPPORTED_TS_CONFIG_FORMATS, SUPPORTED_CONFIG_FORMATS, DEFAULT_CONFIG_BASE;
107
- var init_load_config = __esm({ "src/utils/load-config.ts"() {
108
- init_rolldown();
109
- SUPPORTED_JS_CONFIG_FORMATS = [
110
- ".js",
111
- ".mjs",
112
- ".cjs"
113
- ];
114
- SUPPORTED_TS_CONFIG_FORMATS = [
115
- ".ts",
116
- ".mts",
117
- ".cts"
118
- ];
119
- SUPPORTED_CONFIG_FORMATS = [...SUPPORTED_JS_CONFIG_FORMATS, ...SUPPORTED_TS_CONFIG_FORMATS];
120
- DEFAULT_CONFIG_BASE = "rolldown.config";
121
- } });
122
112
 
123
113
  //#endregion
124
- export { init_load_config, loadConfig };
114
+ export { loadConfig as t };
@@ -0,0 +1,50 @@
1
+ //#region src/log/logging.d.ts
2
+ /** @inline */
3
+ type LogLevel = "info" | "debug" | "warn";
4
+ /** @inline */
5
+ type LogLevelOption = LogLevel | "silent";
6
+ /** @inline */
7
+ type LogLevelWithError = LogLevel | "error";
8
+ interface RolldownLog {
9
+ binding?: string;
10
+ cause?: unknown;
11
+ /**
12
+ * The log code for this log object.
13
+ * @example 'PLUGIN_ERROR'
14
+ */
15
+ code?: string;
16
+ exporter?: string;
17
+ frame?: string;
18
+ hook?: string;
19
+ id?: string;
20
+ ids?: string[];
21
+ loc?: {
22
+ column: number;
23
+ file?: string;
24
+ line: number;
25
+ };
26
+ /**
27
+ * The message for this log object.
28
+ * @example 'The "transform" hook used by the output plugin "rolldown-plugin-foo" is a build time hook and will not be run for that plugin. Either this plugin cannot be used as an output plugin, or it should have an option to configure it as an output plugin.'
29
+ */
30
+ message: string;
31
+ meta?: any;
32
+ names?: string[];
33
+ plugin?: string;
34
+ pluginCode?: unknown;
35
+ pos?: number;
36
+ reexporter?: string;
37
+ stack?: string;
38
+ url?: string;
39
+ }
40
+ /** @inline */
41
+ type RolldownLogWithString = RolldownLog | string;
42
+ /** @category Plugin APIs */
43
+ interface RolldownError extends RolldownLog {
44
+ name?: string;
45
+ stack?: string;
46
+ watchFiles?: string[];
47
+ }
48
+ type LogOrStringHandler = (level: LogLevelWithError, log: RolldownLogWithString) => void;
49
+ //#endregion
50
+ export { RolldownLog as a, RolldownError as i, LogLevelOption as n, RolldownLogWithString as o, LogOrStringHandler as r, LogLevel as t };
@@ -0,0 +1,183 @@
1
+ //#region src/utils/code-frame.ts
2
+ function spaces(index) {
3
+ let result = "";
4
+ while (index--) result += " ";
5
+ return result;
6
+ }
7
+ function tabsToSpaces(value) {
8
+ return value.replace(/^\t+/, (match) => match.split(" ").join(" "));
9
+ }
10
+ const LINE_TRUNCATE_LENGTH = 120;
11
+ const MIN_CHARACTERS_SHOWN_AFTER_LOCATION = 10;
12
+ const ELLIPSIS = "...";
13
+ function getCodeFrame(source, line, column) {
14
+ let lines = source.split("\n");
15
+ if (line > lines.length) return "";
16
+ const maxLineLength = Math.max(tabsToSpaces(lines[line - 1].slice(0, column)).length + MIN_CHARACTERS_SHOWN_AFTER_LOCATION + 3, LINE_TRUNCATE_LENGTH);
17
+ const frameStart = Math.max(0, line - 3);
18
+ let frameEnd = Math.min(line + 2, lines.length);
19
+ lines = lines.slice(frameStart, frameEnd);
20
+ while (!/\S/.test(lines[lines.length - 1])) {
21
+ lines.pop();
22
+ frameEnd -= 1;
23
+ }
24
+ const digits = String(frameEnd).length;
25
+ return lines.map((sourceLine, index) => {
26
+ const isErrorLine = frameStart + index + 1 === line;
27
+ let lineNumber = String(index + frameStart + 1);
28
+ while (lineNumber.length < digits) lineNumber = ` ${lineNumber}`;
29
+ let displayedLine = tabsToSpaces(sourceLine);
30
+ if (displayedLine.length > maxLineLength) displayedLine = `${displayedLine.slice(0, maxLineLength - 3)}${ELLIPSIS}`;
31
+ if (isErrorLine) {
32
+ const indicator = spaces(digits + 2 + tabsToSpaces(sourceLine.slice(0, column)).length) + "^";
33
+ return `${lineNumber}: ${displayedLine}\n${indicator}`;
34
+ }
35
+ return `${lineNumber}: ${displayedLine}`;
36
+ }).join("\n");
37
+ }
38
+
39
+ //#endregion
40
+ //#region src/log/locate-character/index.js
41
+ /** @typedef {import('./types').Location} Location */
42
+ /**
43
+ * @param {import('./types').Range} range
44
+ * @param {number} index
45
+ */
46
+ function rangeContains(range, index) {
47
+ return range.start <= index && index < range.end;
48
+ }
49
+ /**
50
+ * @param {string} source
51
+ * @param {import('./types').Options} [options]
52
+ */
53
+ function getLocator(source, options = {}) {
54
+ const { offsetLine = 0, offsetColumn = 0 } = options;
55
+ let start = 0;
56
+ const ranges = source.split("\n").map((line, i) => {
57
+ const end = start + line.length + 1;
58
+ /** @type {import('./types').Range} */
59
+ const range = {
60
+ start,
61
+ end,
62
+ line: i
63
+ };
64
+ start = end;
65
+ return range;
66
+ });
67
+ let i = 0;
68
+ /**
69
+ * @param {string | number} search
70
+ * @param {number} [index]
71
+ * @returns {Location | undefined}
72
+ */
73
+ function locator(search, index) {
74
+ if (typeof search === "string") search = source.indexOf(search, index ?? 0);
75
+ if (search === -1) return void 0;
76
+ let range = ranges[i];
77
+ const d = search >= range.end ? 1 : -1;
78
+ while (range) {
79
+ if (rangeContains(range, search)) return {
80
+ line: offsetLine + range.line,
81
+ column: offsetColumn + search - range.start,
82
+ character: search
83
+ };
84
+ i += d;
85
+ range = ranges[i];
86
+ }
87
+ }
88
+ return locator;
89
+ }
90
+ /**
91
+ * @param {string} source
92
+ * @param {string | number} search
93
+ * @param {import('./types').Options} [options]
94
+ * @returns {Location | undefined}
95
+ */
96
+ function locate(source, search, options) {
97
+ return getLocator(source, options)(search, options && options.startIndex);
98
+ }
99
+
100
+ //#endregion
101
+ //#region src/log/logs.ts
102
+ const INVALID_LOG_POSITION = "INVALID_LOG_POSITION", PLUGIN_ERROR = "PLUGIN_ERROR", INPUT_HOOK_IN_OUTPUT_PLUGIN = "INPUT_HOOK_IN_OUTPUT_PLUGIN", CYCLE_LOADING = "CYCLE_LOADING", MULTIPLY_NOTIFY_OPTION = "MULTIPLY_NOTIFY_OPTION", PARSE_ERROR = "PARSE_ERROR", NO_FS_IN_BROWSER = "NO_FS_IN_BROWSER";
103
+ function logParseError(message, id, pos) {
104
+ return {
105
+ code: PARSE_ERROR,
106
+ id,
107
+ message,
108
+ pos
109
+ };
110
+ }
111
+ function logInvalidLogPosition(pluginName) {
112
+ return {
113
+ code: INVALID_LOG_POSITION,
114
+ message: `Plugin "${pluginName}" tried to add a file position to a log or warning. This is only supported in the "transform" hook at the moment and will be ignored.`
115
+ };
116
+ }
117
+ function logInputHookInOutputPlugin(pluginName, hookName) {
118
+ return {
119
+ code: INPUT_HOOK_IN_OUTPUT_PLUGIN,
120
+ message: `The "${hookName}" hook used by the output plugin ${pluginName} is a build time hook and will not be run for that plugin. Either this plugin cannot be used as an output plugin, or it should have an option to configure it as an output plugin.`
121
+ };
122
+ }
123
+ function logCycleLoading(pluginName, moduleId) {
124
+ return {
125
+ code: CYCLE_LOADING,
126
+ message: `Found the module "${moduleId}" cycle loading at ${pluginName} plugin, it maybe blocking fetching modules.`
127
+ };
128
+ }
129
+ function logMultiplyNotifyOption() {
130
+ return {
131
+ code: MULTIPLY_NOTIFY_OPTION,
132
+ message: `Found multiply notify option at watch options, using first one to start notify watcher.`
133
+ };
134
+ }
135
+ function logPluginError(error, plugin, { hook, id } = {}) {
136
+ try {
137
+ const code = error.code;
138
+ if (!error.pluginCode && code != null && (typeof code !== "string" || !code.startsWith("PLUGIN_"))) error.pluginCode = code;
139
+ error.code = PLUGIN_ERROR;
140
+ error.plugin = plugin;
141
+ if (hook) error.hook = hook;
142
+ if (id) error.id = id;
143
+ } catch (_) {} finally {
144
+ return error;
145
+ }
146
+ }
147
+ function error(base) {
148
+ if (!(base instanceof Error)) {
149
+ base = Object.assign(new Error(base.message), base);
150
+ Object.defineProperty(base, "name", {
151
+ value: "RollupError",
152
+ writable: true
153
+ });
154
+ }
155
+ throw base;
156
+ }
157
+ function augmentCodeLocation(properties, pos, source, id) {
158
+ if (typeof pos === "object") {
159
+ const { line, column } = pos;
160
+ properties.loc = {
161
+ column,
162
+ file: id,
163
+ line
164
+ };
165
+ } else {
166
+ properties.pos = pos;
167
+ const location = locate(source, pos, { offsetLine: 1 });
168
+ if (!location) return;
169
+ const { line, column } = location;
170
+ properties.loc = {
171
+ column,
172
+ file: id,
173
+ line
174
+ };
175
+ }
176
+ if (properties.frame === void 0) {
177
+ const { line, column } = properties.loc;
178
+ properties.frame = getCodeFrame(source, line, column);
179
+ }
180
+ }
181
+
182
+ //#endregion
183
+ export { logInvalidLogPosition as a, logPluginError as c, logInputHookInOutputPlugin as i, locate as l, error as n, logMultiplyNotifyOption as o, logCycleLoading as r, logParseError as s, augmentCodeLocation as t, getCodeFrame as u };
@@ -1,12 +1,7 @@
1
- import { __esm } from "./chunk--iN_1bjD.mjs";
2
-
3
1
  //#region src/utils/misc.ts
4
2
  function arraify(value) {
5
3
  return Array.isArray(value) ? value : [value];
6
4
  }
7
- function isNullish(value) {
8
- return value === null || value === void 0;
9
- }
10
5
  function isPromiseLike(value) {
11
6
  return value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
12
7
  }
@@ -22,7 +17,6 @@ function unsupported(info) {
22
17
  throw new Error(`UNSUPPORTED: ${info}`);
23
18
  }
24
19
  function noop(..._args) {}
25
- var init_misc = __esm({ "src/utils/misc.ts"() {} });
26
20
 
27
21
  //#endregion
28
- export { arraify, init_misc, isNullish, isPromiseLike, noop, unimplemented, unreachable, unsupported };
22
+ export { unreachable as a, unimplemented as i, isPromiseLike as n, unsupported as o, noop as r, arraify as t };
@@ -0,0 +1,61 @@
1
+ import { n as __toESM, t as require_binding } from "./binding-C-UNREnT.mjs";
2
+ import { c as logPluginError, n as error } from "./logs-NH298mHo.mjs";
3
+
4
+ //#region src/builtin-plugin/utils.ts
5
+ var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
6
+ var BuiltinPlugin = class {
7
+ /** Vite-specific option to control plugin ordering */
8
+ enforce;
9
+ constructor(name, _options) {
10
+ this.name = name;
11
+ this._options = _options;
12
+ }
13
+ };
14
+ function makeBuiltinPluginCallable(plugin) {
15
+ let callablePlugin = new import_binding.BindingCallableBuiltinPlugin(bindingifyBuiltInPlugin(plugin));
16
+ const wrappedPlugin = plugin;
17
+ for (const key in callablePlugin) wrappedPlugin[key] = async function(...args) {
18
+ try {
19
+ return await callablePlugin[key](...args);
20
+ } catch (e) {
21
+ if (e instanceof Error && !e.stack?.includes("at ")) Error.captureStackTrace(e, wrappedPlugin[key]);
22
+ return error(logPluginError(e, plugin.name, {
23
+ hook: key,
24
+ id: key === "transform" ? args[2] : void 0
25
+ }));
26
+ }
27
+ };
28
+ return wrappedPlugin;
29
+ }
30
+ function bindingifyBuiltInPlugin(plugin) {
31
+ return {
32
+ __name: plugin.name,
33
+ options: plugin._options
34
+ };
35
+ }
36
+ function bindingifyManifestPlugin(plugin, pluginContextData) {
37
+ const { isOutputOptionsForLegacyChunks, ...options } = plugin._options;
38
+ return {
39
+ __name: plugin.name,
40
+ options: {
41
+ ...options,
42
+ isLegacy: isOutputOptionsForLegacyChunks ? (opts) => {
43
+ return isOutputOptionsForLegacyChunks(pluginContextData.getOutputOptions(opts));
44
+ } : void 0
45
+ }
46
+ };
47
+ }
48
+
49
+ //#endregion
50
+ //#region src/utils/normalize-string-or-regex.ts
51
+ function normalizedStringOrRegex(pattern) {
52
+ if (!pattern) return;
53
+ if (!isReadonlyArray(pattern)) return [pattern];
54
+ return pattern;
55
+ }
56
+ function isReadonlyArray(input) {
57
+ return Array.isArray(input);
58
+ }
59
+
60
+ //#endregion
61
+ export { makeBuiltinPluginCallable as a, bindingifyManifestPlugin as i, BuiltinPlugin as n, bindingifyBuiltInPlugin as r, normalizedStringOrRegex as t };
@@ -0,0 +1,99 @@
1
+ import { n as __toESM, t as require_binding } from "./binding-C-UNREnT.mjs";
2
+ import { l as locate, n as error, s as logParseError, t as augmentCodeLocation, u as getCodeFrame } from "./logs-NH298mHo.mjs";
3
+
4
+ //#region ../../node_modules/.pnpm/oxc-parser@0.110.0/node_modules/oxc-parser/src-js/wrap.js
5
+ function wrap$1(result) {
6
+ let program, module, comments, errors;
7
+ return {
8
+ get program() {
9
+ if (!program) program = jsonParseAst(result.program);
10
+ return program;
11
+ },
12
+ get module() {
13
+ if (!module) module = result.module;
14
+ return module;
15
+ },
16
+ get comments() {
17
+ if (!comments) comments = result.comments;
18
+ return comments;
19
+ },
20
+ get errors() {
21
+ if (!errors) errors = result.errors;
22
+ return errors;
23
+ }
24
+ };
25
+ }
26
+ function jsonParseAst(programJson) {
27
+ const { node: program, fixes } = JSON.parse(programJson);
28
+ for (const fixPath of fixes) applyFix(program, fixPath);
29
+ return program;
30
+ }
31
+ function applyFix(program, fixPath) {
32
+ let node = program;
33
+ for (const key of fixPath) node = node[key];
34
+ if (node.bigint) node.value = BigInt(node.bigint);
35
+ else try {
36
+ node.value = RegExp(node.regex.pattern, node.regex.flags);
37
+ } catch {}
38
+ }
39
+
40
+ //#endregion
41
+ //#region src/utils/parse.ts
42
+ var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
43
+ /**
44
+ * Parse asynchronously.
45
+ *
46
+ * Note: This function can be slower than `parseSync` due to the overhead of spawning a thread.
47
+ */
48
+ async function parse(filename, sourceText, options) {
49
+ return wrap$1(await (0, import_binding.parse)(filename, sourceText, options));
50
+ }
51
+ /** Parse synchronously. */
52
+ function parseSync(filename, sourceText, options) {
53
+ return wrap$1((0, import_binding.parseSync)(filename, sourceText, options));
54
+ }
55
+
56
+ //#endregion
57
+ //#region src/parse-ast-index.ts
58
+ function wrap(result, filename, sourceText) {
59
+ if (result.errors.length > 0) return normalizeParseError(filename, sourceText, result.errors);
60
+ return result.program;
61
+ }
62
+ function normalizeParseError(filename, sourceText, errors) {
63
+ let message = `Parse failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
64
+ const pos = errors[0]?.labels?.[0]?.start;
65
+ for (let i = 0; i < errors.length; i++) {
66
+ if (i >= 5) {
67
+ message += "\n...";
68
+ break;
69
+ }
70
+ const e = errors[i];
71
+ message += e.message + "\n" + e.labels.map((label) => {
72
+ const location = locate(sourceText, label.start, { offsetLine: 1 });
73
+ if (!location) return;
74
+ return getCodeFrame(sourceText, location.line, location.column);
75
+ }).filter(Boolean).join("\n");
76
+ }
77
+ const log = logParseError(message, filename, pos);
78
+ if (pos !== void 0 && filename) augmentCodeLocation(log, pos, sourceText, filename);
79
+ return error(log);
80
+ }
81
+ const defaultParserOptions = {
82
+ lang: "js",
83
+ preserveParens: false
84
+ };
85
+ function parseAst(sourceText, options, filename) {
86
+ return wrap(parseSync(filename ?? "file.js", sourceText, {
87
+ ...defaultParserOptions,
88
+ ...options
89
+ }), filename, sourceText);
90
+ }
91
+ async function parseAstAsync(sourceText, options, filename) {
92
+ return wrap(await parse(filename ?? "file.js", sourceText, {
93
+ ...defaultParserOptions,
94
+ ...options
95
+ }), filename, sourceText);
96
+ }
97
+
98
+ //#endregion
99
+ export { parseSync as i, parseAstAsync as n, parse as r, parseAst as t };