@rolldown/browser 1.0.0-beta.9-commit.0ec9e7d → 1.0.0-rc.10

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 (82) hide show
  1. package/dist/cli.mjs +961 -1551
  2. package/dist/config.d.mts +9 -6
  3. package/dist/config.mjs +9 -11
  4. package/dist/constructors-DsfxKD6A.js +68 -0
  5. package/dist/error-BeZaDkS8.js +157 -0
  6. package/dist/experimental-index.browser.mjs +278 -44
  7. package/dist/experimental-index.d.mts +228 -68
  8. package/dist/experimental-index.mjs +274 -55
  9. package/dist/experimental-runtime-types.d.ts +98 -0
  10. package/dist/filter-index.d.mts +104 -2
  11. package/dist/filter-index.mjs +144 -5
  12. package/dist/get-log-filter.d.mts +3 -0
  13. package/dist/get-log-filter.mjs +68 -0
  14. package/dist/index.browser.mjs +238 -3
  15. package/dist/index.d.mts +4 -3
  16. package/dist/index.mjs +53 -6
  17. package/dist/{shared/parse-ast-index-BHaE0ECV.cjs → normalize-string-or-regex-TtAGUp42.js} +74 -147
  18. package/dist/parallel-plugin-worker.mjs +27 -35
  19. package/dist/parallel-plugin.d.mts +7 -7
  20. package/dist/parallel-plugin.mjs +1 -2
  21. package/dist/parse-ast-index.d.mts +28 -5
  22. package/dist/parse-ast-index.mjs +60 -4
  23. package/dist/plugins-index.browser.mjs +40 -0
  24. package/dist/plugins-index.d.mts +33 -0
  25. package/dist/plugins-index.mjs +40 -0
  26. package/dist/resolve-tsconfig-DThkUPSZ.js +112 -0
  27. package/dist/rolldown-binding.wasi-browser.js +46 -24
  28. package/dist/rolldown-binding.wasi.cjs +67 -24
  29. package/dist/rolldown-binding.wasm32-wasi.wasm +0 -0
  30. package/dist/rolldown-build-Chx5S-TB.js +5349 -0
  31. package/dist/shared/bindingify-input-options-Czbczr8Z.mjs +2168 -0
  32. package/dist/shared/composable-filters-B2ByPP8y.mjs +224 -0
  33. package/dist/shared/constructors-BVnf_fH1.d.mts +37 -0
  34. package/dist/shared/constructors-CemeNi29.mjs +68 -0
  35. package/dist/shared/define-config-DJOr6Iwt.mjs +6 -0
  36. package/dist/shared/define-config-i6TWE2hm.d.mts +3855 -0
  37. package/dist/shared/error-CQ6njWsV.mjs +86 -0
  38. package/dist/shared/get-log-filter-semyr3Lj.d.mts +35 -0
  39. package/dist/shared/{load-config-D7UduHRZ.mjs → load-config-CxvL5JxT.mjs} +32 -36
  40. package/dist/shared/logging-C6h4g8dA.d.mts +50 -0
  41. package/dist/shared/{parse-ast-index-vu376yZ1.mjs → logs-D80CXhvg.mjs} +25 -123
  42. package/dist/shared/normalize-string-or-regex-CF3Uz6aU.mjs +57 -0
  43. package/dist/shared/parse-CRhjbrcT.mjs +73 -0
  44. package/dist/shared/{prompt-CxjDC0Gn.cjs → prompt-BYQIwEjg.mjs} +301 -310
  45. package/dist/shared/resolve-tsconfig-Cwoo4h_o.mjs +112 -0
  46. package/dist/shared/rolldown-C3wFxOwq.mjs +40 -0
  47. package/dist/shared/rolldown-build-ChZOz6BP.mjs +3318 -0
  48. package/dist/shared/transform-DEgNAQOQ.d.mts +149 -0
  49. package/dist/shared/types-Cx3HYorz.d.mts +1302 -0
  50. package/dist/shared/utils-6wxe_LMG.d.mts +22 -0
  51. package/dist/shared/watch-C1jC1oFT.mjs +373 -0
  52. package/dist/utils-index.browser.mjs +2414 -0
  53. package/dist/utils-index.d.mts +374 -0
  54. package/dist/utils-index.mjs +2415 -0
  55. package/package.json +33 -38
  56. package/dist/cli.cjs +0 -1748
  57. package/dist/cli.d.cts +0 -1
  58. package/dist/config.cjs +0 -12
  59. package/dist/config.d.cts +0 -11
  60. package/dist/experimental-index.cjs +0 -129
  61. package/dist/experimental-index.d.cts +0 -96
  62. package/dist/filter-index.cjs +0 -53
  63. package/dist/filter-index.d.cts +0 -3
  64. package/dist/index.cjs +0 -9
  65. package/dist/index.d.cts +0 -3
  66. package/dist/parallel-plugin-worker.cjs +0 -33
  67. package/dist/parallel-plugin-worker.d.cts +0 -1
  68. package/dist/parallel-plugin.cjs +0 -8
  69. package/dist/parallel-plugin.d.cts +0 -14
  70. package/dist/parse-ast-index.cjs +0 -4
  71. package/dist/parse-ast-index.d.cts +0 -9
  72. package/dist/shared/chunk-DDkG_k5U.cjs +0 -39
  73. package/dist/shared/chunk-DSsiIF1Z.mjs +0 -30
  74. package/dist/shared/define-config.d-D4lKXE9V.d.cts +0 -1165
  75. package/dist/shared/define-config.d-Dm9iNdt9.d.mts +0 -1165
  76. package/dist/shared/dist-BMVjvV-v.cjs +0 -249
  77. package/dist/shared/dist-CAn6dxW6.mjs +0 -153
  78. package/dist/shared/load-config-CtKjQ8Mn.cjs +0 -125
  79. package/dist/shared/prompt-GFYxfPw7.mjs +0 -854
  80. package/dist/shared/src-D0nc44MQ.mjs +0 -4691
  81. package/dist/shared/src-s89s870G.cjs +0 -4647
  82. package/dist/src-CeWghjQt.js +0 -4329
@@ -1,6 +1,4 @@
1
- const require_chunk = require('./chunk-DDkG_k5U.cjs');
2
- const src_rolldown_binding_wasi_cjs = require_chunk.__toESM(require("../rolldown-binding.wasi.cjs"));
3
-
1
+ import { BindingCallableBuiltinPlugin } from "./rolldown-binding.wasi-browser.js";
4
2
  //#region src/utils/code-frame.ts
5
3
  function spaces(index) {
6
4
  let result = "";
@@ -16,7 +14,7 @@ const ELLIPSIS = "...";
16
14
  function getCodeFrame(source, line, column) {
17
15
  let lines = source.split("\n");
18
16
  if (line > lines.length) return "";
19
- const maxLineLength = Math.max(tabsToSpaces(lines[line - 1].slice(0, column)).length + MIN_CHARACTERS_SHOWN_AFTER_LOCATION + ELLIPSIS.length, LINE_TRUNCATE_LENGTH);
17
+ const maxLineLength = Math.max(tabsToSpaces(lines[line - 1].slice(0, column)).length + MIN_CHARACTERS_SHOWN_AFTER_LOCATION + 3, LINE_TRUNCATE_LENGTH);
20
18
  const frameStart = Math.max(0, line - 3);
21
19
  let frameEnd = Math.min(line + 2, lines.length);
22
20
  lines = lines.slice(frameStart, frameEnd);
@@ -30,7 +28,7 @@ function getCodeFrame(source, line, column) {
30
28
  let lineNumber = String(index + frameStart + 1);
31
29
  while (lineNumber.length < digits) lineNumber = ` ${lineNumber}`;
32
30
  let displayedLine = tabsToSpaces(sourceLine);
33
- if (displayedLine.length > maxLineLength) displayedLine = `${displayedLine.slice(0, maxLineLength - ELLIPSIS.length)}${ELLIPSIS}`;
31
+ if (displayedLine.length > maxLineLength) displayedLine = `${displayedLine.slice(0, maxLineLength - 3)}${ELLIPSIS}`;
34
32
  if (isErrorLine) {
35
33
  const indicator = spaces(digits + 2 + tabsToSpaces(sourceLine.slice(0, column)).length) + "^";
36
34
  return `${lineNumber}: ${displayedLine}\n${indicator}`;
@@ -38,7 +36,6 @@ function getCodeFrame(source, line, column) {
38
36
  return `${lineNumber}: ${displayedLine}`;
39
37
  }).join("\n");
40
38
  }
41
-
42
39
  //#endregion
43
40
  //#region src/log/locate-character/index.js
44
41
  /** @typedef {import('./types').Location} Location */
@@ -56,13 +53,13 @@ function rangeContains(range, index) {
56
53
  function getLocator(source, options = {}) {
57
54
  const { offsetLine = 0, offsetColumn = 0 } = options;
58
55
  let start = 0;
59
- const ranges = source.split("\n").map((line, i$1) => {
56
+ const ranges = source.split("\n").map((line, i) => {
60
57
  const end = start + line.length + 1;
61
58
  /** @type {import('./types').Range} */
62
59
  const range = {
63
60
  start,
64
61
  end,
65
- line: i$1
62
+ line: i
66
63
  };
67
64
  start = end;
68
65
  return range;
@@ -99,14 +96,15 @@ function getLocator(source, options = {}) {
99
96
  function locate(source, search, options) {
100
97
  return getLocator(source, options)(search, options && options.startIndex);
101
98
  }
102
-
103
99
  //#endregion
104
100
  //#region src/log/logs.ts
105
- 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";
106
- function logParseError(message) {
101
+ 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", MULTIPLE_WATCHER_OPTION = "MULTIPLE_WATCHER_OPTION", PARSE_ERROR = "PARSE_ERROR", NO_FS_IN_BROWSER = "NO_FS_IN_BROWSER";
102
+ function logParseError(message, id, pos) {
107
103
  return {
108
104
  code: PARSE_ERROR,
109
- message
105
+ id,
106
+ message,
107
+ pos
110
108
  };
111
109
  }
112
110
  function logInvalidLogPosition(pluginName) {
@@ -127,29 +125,35 @@ function logCycleLoading(pluginName, moduleId) {
127
125
  message: `Found the module "${moduleId}" cycle loading at ${pluginName} plugin, it maybe blocking fetching modules.`
128
126
  };
129
127
  }
130
- function logMultiplyNotifyOption() {
128
+ function logMultipleWatcherOption() {
131
129
  return {
132
- code: MULTIPLY_NOTIFY_OPTION,
133
- message: `Found multiply notify option at watch options, using first one to start notify watcher.`
130
+ code: MULTIPLE_WATCHER_OPTION,
131
+ message: `Found multiple watcher options at watch options, using first one to start watcher.`
134
132
  };
135
133
  }
136
- function logPluginError(error$1, plugin, { hook, id } = {}) {
134
+ function logNoFileSystemInBrowser(method) {
135
+ return {
136
+ code: NO_FS_IN_BROWSER,
137
+ message: `Cannot access the file system (via "${method}") when using the browser build of Rolldown.`
138
+ };
139
+ }
140
+ function logPluginError(error, plugin, { hook, id } = {}) {
137
141
  try {
138
- const code = error$1.code;
139
- if (!error$1.pluginCode && code != null && (typeof code !== "string" || !code.startsWith("PLUGIN_"))) error$1.pluginCode = code;
140
- error$1.code = PLUGIN_ERROR;
141
- error$1.plugin = plugin;
142
- if (hook) error$1.hook = hook;
143
- if (id) error$1.id = id;
142
+ const code = error.code;
143
+ if (!error.pluginCode && code != null && (typeof code !== "string" || !code.startsWith("PLUGIN_"))) error.pluginCode = code;
144
+ error.code = PLUGIN_ERROR;
145
+ error.plugin = plugin;
146
+ if (hook) error.hook = hook;
147
+ if (id) error.id = id;
144
148
  } catch (_) {} finally {
145
- return error$1;
149
+ return error;
146
150
  }
147
151
  }
148
152
  function error(base) {
149
153
  if (!(base instanceof Error)) {
150
154
  base = Object.assign(new Error(base.message), base);
151
155
  Object.defineProperty(base, "name", {
152
- value: "RollupError",
156
+ value: "RolldownError",
153
157
  writable: true
154
158
  });
155
159
  }
@@ -179,136 +183,59 @@ function augmentCodeLocation(properties, pos, source, id) {
179
183
  properties.frame = getCodeFrame(source, line, column);
180
184
  }
181
185
  }
182
-
183
186
  //#endregion
184
- //#region ../../node_modules/.pnpm/oxc-parser@0.72.0/node_modules/oxc-parser/wrap.mjs
185
- function wrap$1(result) {
186
- let program, module$1, comments, errors;
187
- return {
188
- get program() {
189
- if (!program) program = jsonParseAst(result.program);
190
- return program;
191
- },
192
- get module() {
193
- if (!module$1) module$1 = result.module;
194
- return module$1;
195
- },
196
- get comments() {
197
- if (!comments) comments = result.comments;
198
- return comments;
199
- },
200
- get errors() {
201
- if (!errors) errors = result.errors;
202
- return errors;
187
+ //#region src/builtin-plugin/utils.ts
188
+ var BuiltinPlugin = class {
189
+ /** Vite-specific option to control plugin ordering */
190
+ enforce;
191
+ constructor(name, _options) {
192
+ this.name = name;
193
+ this._options = _options;
194
+ }
195
+ };
196
+ function makeBuiltinPluginCallable(plugin) {
197
+ let callablePlugin = new BindingCallableBuiltinPlugin(bindingifyBuiltInPlugin(plugin));
198
+ const wrappedPlugin = plugin;
199
+ for (const key in callablePlugin) wrappedPlugin[key] = async function(...args) {
200
+ try {
201
+ return await callablePlugin[key](...args);
202
+ } catch (e) {
203
+ if (e instanceof Error && !e.stack?.includes("at ")) Error.captureStackTrace(e, wrappedPlugin[key]);
204
+ return error(logPluginError(e, plugin.name, {
205
+ hook: key,
206
+ id: key === "transform" ? args[2] : void 0
207
+ }));
203
208
  }
204
209
  };
210
+ return wrappedPlugin;
205
211
  }
206
- function jsonParseAst(programJson) {
207
- const { node: program, fixes } = JSON.parse(programJson);
208
- for (const fixPath of fixes) applyFix(program, fixPath);
209
- return program;
210
- }
211
- function applyFix(program, fixPath) {
212
- let node = program;
213
- for (const key of fixPath) node = node[key];
214
- if (node.bigint) node.value = BigInt(node.bigint);
215
- else try {
216
- node.value = RegExp(node.regex.pattern, node.regex.flags);
217
- } catch (_err) {}
218
- }
219
-
220
- //#endregion
221
- //#region src/parse-ast-index.ts
222
- function wrap(result, sourceText) {
223
- result = wrap$1(result);
224
- if (result.errors.length > 0) return normalizeParseError(sourceText, result.errors);
225
- return result.program;
212
+ function bindingifyBuiltInPlugin(plugin) {
213
+ return {
214
+ __name: plugin.name,
215
+ options: plugin._options
216
+ };
226
217
  }
227
- function normalizeParseError(sourceText, errors) {
228
- let message = `Parse failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
229
- for (let i = 0; i < errors.length; i++) {
230
- if (i >= 5) {
231
- message += "\n...";
232
- break;
218
+ function bindingifyManifestPlugin(plugin, pluginContextData) {
219
+ const { isOutputOptionsForLegacyChunks, ...options } = plugin._options;
220
+ return {
221
+ __name: plugin.name,
222
+ options: {
223
+ ...options,
224
+ isLegacy: isOutputOptionsForLegacyChunks ? (opts) => {
225
+ return isOutputOptionsForLegacyChunks(pluginContextData.getOutputOptions(opts));
226
+ } : void 0
233
227
  }
234
- const e = errors[i];
235
- message += e.message + "\n" + e.labels.map((label) => {
236
- const location = locate(sourceText, label.start, { offsetLine: 1 });
237
- if (!location) return;
238
- return getCodeFrame(sourceText, location.line, location.column);
239
- }).filter(Boolean).join("\n");
240
- }
241
- return error(logParseError(message));
228
+ };
242
229
  }
243
- const defaultParserOptions = {
244
- lang: "js",
245
- preserveParens: false
246
- };
247
- function parseAst(sourceText, options, filename) {
248
- return wrap((0, src_rolldown_binding_wasi_cjs.parseSync)(filename ?? "file.js", sourceText, {
249
- ...defaultParserOptions,
250
- ...options
251
- }), sourceText);
230
+ //#endregion
231
+ //#region src/utils/normalize-string-or-regex.ts
232
+ function normalizedStringOrRegex(pattern) {
233
+ if (!pattern) return;
234
+ if (!isReadonlyArray(pattern)) return [pattern];
235
+ return pattern;
252
236
  }
253
- async function parseAstAsync(sourceText, options, filename) {
254
- return wrap(await (0, src_rolldown_binding_wasi_cjs.parseAsync)(filename ?? "file.js", sourceText, {
255
- ...defaultParserOptions,
256
- ...options
257
- }), sourceText);
237
+ function isReadonlyArray(input) {
238
+ return Array.isArray(input);
258
239
  }
259
-
260
240
  //#endregion
261
- Object.defineProperty(exports, 'augmentCodeLocation', {
262
- enumerable: true,
263
- get: function () {
264
- return augmentCodeLocation;
265
- }
266
- });
267
- Object.defineProperty(exports, 'error', {
268
- enumerable: true,
269
- get: function () {
270
- return error;
271
- }
272
- });
273
- Object.defineProperty(exports, 'logCycleLoading', {
274
- enumerable: true,
275
- get: function () {
276
- return logCycleLoading;
277
- }
278
- });
279
- Object.defineProperty(exports, 'logInputHookInOutputPlugin', {
280
- enumerable: true,
281
- get: function () {
282
- return logInputHookInOutputPlugin;
283
- }
284
- });
285
- Object.defineProperty(exports, 'logInvalidLogPosition', {
286
- enumerable: true,
287
- get: function () {
288
- return logInvalidLogPosition;
289
- }
290
- });
291
- Object.defineProperty(exports, 'logMultiplyNotifyOption', {
292
- enumerable: true,
293
- get: function () {
294
- return logMultiplyNotifyOption;
295
- }
296
- });
297
- Object.defineProperty(exports, 'logPluginError', {
298
- enumerable: true,
299
- get: function () {
300
- return logPluginError;
301
- }
302
- });
303
- Object.defineProperty(exports, 'parseAst', {
304
- enumerable: true,
305
- get: function () {
306
- return parseAst;
307
- }
308
- });
309
- Object.defineProperty(exports, 'parseAstAsync', {
310
- enumerable: true,
311
- get: function () {
312
- return parseAstAsync;
313
- }
314
- });
241
+ export { makeBuiltinPluginCallable as a, logCycleLoading as c, logMultipleWatcherOption as d, logNoFileSystemInBrowser as f, getCodeFrame as g, locate as h, bindingifyManifestPlugin as i, logInputHookInOutputPlugin as l, logPluginError as m, BuiltinPlugin as n, augmentCodeLocation as o, logParseError as p, bindingifyBuiltInPlugin as r, error as s, normalizedStringOrRegex as t, logInvalidLogPosition as u };
@@ -1,38 +1,30 @@
1
- import { __commonJS } from "./shared/chunk-DSsiIF1Z.mjs";
2
- import { PluginContextData, bindingifyPlugin, init_bindingify_plugin, init_plugin_context_data } from "./shared/src-D0nc44MQ.mjs";
3
- import "./shared/dist-CAn6dxW6.mjs";
4
- import "./shared/parse-ast-index-vu376yZ1.mjs";
5
- import { registerPlugins } from "./rolldown-binding.wasi.cjs";
1
+ import "./shared/normalize-string-or-regex-CF3Uz6aU.mjs";
2
+ import { n as PluginContextData, r as bindingifyPlugin } from "./shared/bindingify-input-options-Czbczr8Z.mjs";
3
+ import "./shared/error-CQ6njWsV.mjs";
4
+ import "./shared/parse-CRhjbrcT.mjs";
6
5
  import { parentPort, workerData } from "node:worker_threads";
7
-
6
+ import { registerPlugins } from "./rolldown-binding.wasi.cjs";
8
7
  //#region src/parallel-plugin-worker.ts
9
- var require_parallel_plugin_worker = __commonJS({ "src/parallel-plugin-worker.ts"() {
10
- init_bindingify_plugin();
11
- init_plugin_context_data();
12
- const { registryId, pluginInfos, threadNumber } = workerData;
13
- (async () => {
14
- try {
15
- const plugins = await Promise.all(pluginInfos.map(async (pluginInfo) => {
16
- const pluginModule = await import(pluginInfo.fileUrl);
17
- const definePluginImpl = pluginModule.default;
18
- const plugin = await definePluginImpl(pluginInfo.options, { threadNumber });
19
- return {
20
- index: pluginInfo.index,
21
- plugin: bindingifyPlugin(plugin, {}, {}, new PluginContextData(), [], () => {}, "info", false)
22
- };
23
- }));
24
- registerPlugins(registryId, plugins);
25
- parentPort.postMessage({ type: "success" });
26
- } catch (error) {
27
- parentPort.postMessage({
28
- type: "error",
29
- error
30
- });
31
- } finally {
32
- parentPort.unref();
33
- }
34
- })();
35
- } });
36
-
8
+ const { registryId, pluginInfos, threadNumber } = workerData;
9
+ (async () => {
10
+ try {
11
+ registerPlugins(registryId, await Promise.all(pluginInfos.map(async (pluginInfo) => {
12
+ const definePluginImpl = (await import(pluginInfo.fileUrl)).default;
13
+ const plugin = await definePluginImpl(pluginInfo.options, { threadNumber });
14
+ return {
15
+ index: pluginInfo.index,
16
+ plugin: bindingifyPlugin(plugin, {}, {}, new PluginContextData(() => {}, {}, [], []), [], () => {}, "info", false)
17
+ };
18
+ })));
19
+ parentPort.postMessage({ type: "success" });
20
+ } catch (error) {
21
+ parentPort.postMessage({
22
+ type: "error",
23
+ error
24
+ });
25
+ } finally {
26
+ parentPort.unref();
27
+ }
28
+ })();
37
29
  //#endregion
38
- export default require_parallel_plugin_worker();
30
+ export {};
@@ -1,14 +1,14 @@
1
- import { MaybePromise, Plugin } from "./shared/define-config.d-Dm9iNdt9.mjs";
1
+ import { w as Plugin } from "./shared/define-config-i6TWE2hm.mjs";
2
+ import { i as MaybePromise } from "./shared/utils-6wxe_LMG.mjs";
2
3
 
3
4
  //#region src/plugin/parallel-plugin-implementation.d.ts
4
5
  type ParallelPluginImplementation = Plugin;
5
6
  type Context = {
6
- /**
7
- * Thread number
8
- */
9
- threadNumber: number
7
+ /**
8
+ * Thread number
9
+ */
10
+ threadNumber: number;
10
11
  };
11
12
  declare function defineParallelPluginImplementation<Options>(plugin: (Options: Options, context: Context) => MaybePromise<ParallelPluginImplementation>): (Options: Options, context: Context) => MaybePromise<ParallelPluginImplementation>;
12
-
13
13
  //#endregion
14
- export { Context, ParallelPluginImplementation, defineParallelPluginImplementation };
14
+ export { type Context, type ParallelPluginImplementation, defineParallelPluginImplementation };
@@ -2,6 +2,5 @@
2
2
  function defineParallelPluginImplementation(plugin) {
3
3
  return plugin;
4
4
  }
5
-
6
5
  //#endregion
7
- export { defineParallelPluginImplementation };
6
+ export { defineParallelPluginImplementation };
@@ -1,9 +1,32 @@
1
- import { ParseResult, ParserOptions } from "./rolldown-binding.wasi.cjs";
2
- import { Program } from "@oxc-project/types";
1
+ import { Dt as Program } from "./shared/types-Cx3HYorz.mjs";
2
+ import { ParseResult as ParseResult$1, ParserOptions as ParserOptions$1 } from "./binding.cjs";
3
3
 
4
4
  //#region src/parse-ast-index.d.ts
5
- declare function parseAst(sourceText: string, options?: ParserOptions | undefined | null, filename?: string): Program;
6
- declare function parseAstAsync(sourceText: string, options?: ParserOptions | undefined | null, filename?: string): Promise<Program>;
7
-
5
+ /**
6
+ * @hidden
7
+ */
8
+ type ParseResult = ParseResult$1;
9
+ /**
10
+ * @hidden
11
+ */
12
+ type ParserOptions = ParserOptions$1;
13
+ /**
14
+ * Parse code synchronously and return the AST.
15
+ *
16
+ * This function is similar to Rollup's `parseAst` function.
17
+ * Prefer using {@linkcode parseSync} instead of this function as it has more information in the return value.
18
+ *
19
+ * @category Utilities
20
+ */
21
+ declare function parseAst(sourceText: string, options?: ParserOptions | null, filename?: string): Program;
22
+ /**
23
+ * Parse code asynchronously and return the AST.
24
+ *
25
+ * This function is similar to Rollup's `parseAstAsync` function.
26
+ * Prefer using {@linkcode parseAsync} instead of this function as it has more information in the return value.
27
+ *
28
+ * @category Utilities
29
+ */
30
+ declare function parseAstAsync(sourceText: string, options?: ParserOptions | null, filename?: string): Promise<Program>;
8
31
  //#endregion
9
32
  export { ParseResult, ParserOptions, parseAst, parseAstAsync };
@@ -1,4 +1,60 @@
1
- import { init_parse_ast_index, parseAst, parseAstAsync } from "./shared/parse-ast-index-vu376yZ1.mjs";
2
-
3
- init_parse_ast_index();
4
- export { parseAst, parseAstAsync };
1
+ import { l as locate, n as error, s as logParseError, t as augmentCodeLocation, u as getCodeFrame } from "./shared/logs-D80CXhvg.mjs";
2
+ import { n as parseSync, t as parse } from "./shared/parse-CRhjbrcT.mjs";
3
+ //#region src/parse-ast-index.ts
4
+ function wrap(result, filename, sourceText) {
5
+ if (result.errors.length > 0) return normalizeParseError(filename, sourceText, result.errors);
6
+ return result.program;
7
+ }
8
+ function normalizeParseError(filename, sourceText, errors) {
9
+ let message = `Parse failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
10
+ const pos = errors[0]?.labels?.[0]?.start;
11
+ for (let i = 0; i < errors.length; i++) {
12
+ if (i >= 5) {
13
+ message += "\n...";
14
+ break;
15
+ }
16
+ const e = errors[i];
17
+ message += e.message + "\n" + e.labels.map((label) => {
18
+ const location = locate(sourceText, label.start, { offsetLine: 1 });
19
+ if (!location) return;
20
+ return getCodeFrame(sourceText, location.line, location.column);
21
+ }).filter(Boolean).join("\n");
22
+ }
23
+ const log = logParseError(message, filename, pos);
24
+ if (pos !== void 0 && filename) augmentCodeLocation(log, pos, sourceText, filename);
25
+ return error(log);
26
+ }
27
+ const defaultParserOptions = {
28
+ lang: "js",
29
+ preserveParens: false
30
+ };
31
+ /**
32
+ * Parse code synchronously and return the AST.
33
+ *
34
+ * This function is similar to Rollup's `parseAst` function.
35
+ * Prefer using {@linkcode parseSync} instead of this function as it has more information in the return value.
36
+ *
37
+ * @category Utilities
38
+ */
39
+ function parseAst(sourceText, options, filename) {
40
+ return wrap(parseSync(filename ?? "file.js", sourceText, {
41
+ ...defaultParserOptions,
42
+ ...options
43
+ }), filename, sourceText);
44
+ }
45
+ /**
46
+ * Parse code asynchronously and return the AST.
47
+ *
48
+ * This function is similar to Rollup's `parseAstAsync` function.
49
+ * Prefer using {@linkcode parseAsync} instead of this function as it has more information in the return value.
50
+ *
51
+ * @category Utilities
52
+ */
53
+ async function parseAstAsync(sourceText, options, filename) {
54
+ return wrap(await parse(filename ?? "file.js", sourceText, {
55
+ ...defaultParserOptions,
56
+ ...options
57
+ }), filename, sourceText);
58
+ }
59
+ //#endregion
60
+ export { parseAst, parseAstAsync };
@@ -0,0 +1,40 @@
1
+ import { a as makeBuiltinPluginCallable, n as BuiltinPlugin } from "./normalize-string-or-regex-TtAGUp42.js";
2
+ import { t as esmExternalRequirePlugin } from "./constructors-DsfxKD6A.js";
3
+ //#region src/builtin-plugin/replace-plugin.ts
4
+ /**
5
+ * Replaces targeted strings in files while bundling.
6
+ *
7
+ * @example
8
+ * **Basic usage**
9
+ * ```js
10
+ * replacePlugin({
11
+ * 'process.env.NODE_ENV': JSON.stringify('production'),
12
+ * __buildVersion: 15
13
+ * })
14
+ * ```
15
+ * @example
16
+ * **With options**
17
+ * ```js
18
+ * replacePlugin({
19
+ * 'process.env.NODE_ENV': JSON.stringify('production'),
20
+ * __buildVersion: 15
21
+ * }, {
22
+ * preventAssignment: false,
23
+ * })
24
+ * ```
25
+ *
26
+ * @see https://rolldown.rs/builtin-plugins/replace
27
+ * @category Builtin Plugins
28
+ */
29
+ function replacePlugin(values = {}, options = {}) {
30
+ Object.keys(values).forEach((key) => {
31
+ const value = values[key];
32
+ if (typeof value !== "string") values[key] = String(value);
33
+ });
34
+ return makeBuiltinPluginCallable(new BuiltinPlugin("builtin:replace", {
35
+ ...options,
36
+ values
37
+ }));
38
+ }
39
+ //#endregion
40
+ export { esmExternalRequirePlugin, replacePlugin };
@@ -0,0 +1,33 @@
1
+ import { t as BuiltinPlugin } from "./shared/utils-6wxe_LMG.mjs";
2
+ import { t as esmExternalRequirePlugin } from "./shared/constructors-BVnf_fH1.mjs";
3
+ import { BindingReplacePluginConfig } from "../binding.cjs";
4
+
5
+ //#region src/builtin-plugin/replace-plugin.d.ts
6
+ /**
7
+ * Replaces targeted strings in files while bundling.
8
+ *
9
+ * @example
10
+ * **Basic usage**
11
+ * ```js
12
+ * replacePlugin({
13
+ * 'process.env.NODE_ENV': JSON.stringify('production'),
14
+ * __buildVersion: 15
15
+ * })
16
+ * ```
17
+ * @example
18
+ * **With options**
19
+ * ```js
20
+ * replacePlugin({
21
+ * 'process.env.NODE_ENV': JSON.stringify('production'),
22
+ * __buildVersion: 15
23
+ * }, {
24
+ * preventAssignment: false,
25
+ * })
26
+ * ```
27
+ *
28
+ * @see https://rolldown.rs/builtin-plugins/replace
29
+ * @category Builtin Plugins
30
+ */
31
+ declare function replacePlugin(values?: BindingReplacePluginConfig["values"], options?: Omit<BindingReplacePluginConfig, "values">): BuiltinPlugin;
32
+ //#endregion
33
+ export { esmExternalRequirePlugin, replacePlugin };
@@ -0,0 +1,40 @@
1
+ import { a as makeBuiltinPluginCallable, n as BuiltinPlugin } from "./shared/normalize-string-or-regex-CF3Uz6aU.mjs";
2
+ import { t as esmExternalRequirePlugin } from "./shared/constructors-CemeNi29.mjs";
3
+ //#region src/builtin-plugin/replace-plugin.ts
4
+ /**
5
+ * Replaces targeted strings in files while bundling.
6
+ *
7
+ * @example
8
+ * **Basic usage**
9
+ * ```js
10
+ * replacePlugin({
11
+ * 'process.env.NODE_ENV': JSON.stringify('production'),
12
+ * __buildVersion: 15
13
+ * })
14
+ * ```
15
+ * @example
16
+ * **With options**
17
+ * ```js
18
+ * replacePlugin({
19
+ * 'process.env.NODE_ENV': JSON.stringify('production'),
20
+ * __buildVersion: 15
21
+ * }, {
22
+ * preventAssignment: false,
23
+ * })
24
+ * ```
25
+ *
26
+ * @see https://rolldown.rs/builtin-plugins/replace
27
+ * @category Builtin Plugins
28
+ */
29
+ function replacePlugin(values = {}, options = {}) {
30
+ Object.keys(values).forEach((key) => {
31
+ const value = values[key];
32
+ if (typeof value !== "string") values[key] = String(value);
33
+ });
34
+ return makeBuiltinPluginCallable(new BuiltinPlugin("builtin:replace", {
35
+ ...options,
36
+ values
37
+ }));
38
+ }
39
+ //#endregion
40
+ export { esmExternalRequirePlugin, replacePlugin };