@rollipop/rolldown 0.0.0 → 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 (46) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +11 -1
  3. package/bin/cli.mjs +3 -0
  4. package/dist/cli-setup.d.mts +1 -0
  5. package/dist/cli-setup.mjs +17 -0
  6. package/dist/cli.d.mts +1 -0
  7. package/dist/cli.mjs +1588 -0
  8. package/dist/config.d.mts +10 -0
  9. package/dist/config.mjs +14 -0
  10. package/dist/experimental-index.d.mts +181 -0
  11. package/dist/experimental-index.mjs +266 -0
  12. package/dist/experimental-runtime-types.d.ts +103 -0
  13. package/dist/filter-index.d.mts +197 -0
  14. package/dist/filter-index.mjs +369 -0
  15. package/dist/get-log-filter.d.mts +7 -0
  16. package/dist/get-log-filter.mjs +48 -0
  17. package/dist/index.d.mts +4 -0
  18. package/dist/index.mjs +57 -0
  19. package/dist/parallel-plugin-worker.d.mts +1 -0
  20. package/dist/parallel-plugin-worker.mjs +32 -0
  21. package/dist/parallel-plugin.d.mts +14 -0
  22. package/dist/parallel-plugin.mjs +7 -0
  23. package/dist/parse-ast-index.d.mts +8 -0
  24. package/dist/parse-ast-index.mjs +4 -0
  25. package/dist/plugins-index.d.mts +30 -0
  26. package/dist/plugins-index.mjs +40 -0
  27. package/dist/shared/binding-B92Lq__Q.d.mts +1687 -0
  28. package/dist/shared/binding-tNJoEqAa.mjs +585 -0
  29. package/dist/shared/bindingify-input-options-CfhrNd_y.mjs +2233 -0
  30. package/dist/shared/constructors--k1uxZrh.d.mts +28 -0
  31. package/dist/shared/constructors-414MPkgB.mjs +61 -0
  32. package/dist/shared/define-config-BVG4QvnP.mjs +7 -0
  33. package/dist/shared/define-config-D8xP5iyL.d.mts +3463 -0
  34. package/dist/shared/load-config-Qtd9pHJ5.mjs +114 -0
  35. package/dist/shared/logging-wIy4zY9I.d.mts +50 -0
  36. package/dist/shared/logs-NH298mHo.mjs +183 -0
  37. package/dist/shared/misc-CCZIsXVO.mjs +22 -0
  38. package/dist/shared/normalize-string-or-regex-DeB7vQ75.mjs +61 -0
  39. package/dist/shared/parse-ast-index-BcP4Ts_P.mjs +99 -0
  40. package/dist/shared/prompt-tlfjalEt.mjs +847 -0
  41. package/dist/shared/rolldown-BMzJcmQ7.mjs +42 -0
  42. package/dist/shared/rolldown-build-DWeKtJOy.mjs +2371 -0
  43. package/dist/shared/watch-HmN4U4B9.mjs +379 -0
  44. package/package.json +128 -2
  45. package/.editorconfig +0 -10
  46. package/.gitattributes +0 -4
@@ -0,0 +1,114 @@
1
+ import { t as rolldown } from "./rolldown-BMzJcmQ7.mjs";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { readdir } from "node:fs/promises";
5
+ import { pathToFileURL } from "node:url";
6
+ import { cwd } from "node:process";
7
+
8
+ //#region src/utils/load-config.ts
9
+ async function bundleTsConfig(configFile, isEsm) {
10
+ const dirnameVarName = "injected_original_dirname";
11
+ const filenameVarName = "injected_original_filename";
12
+ const importMetaUrlVarName = "injected_original_import_meta_url";
13
+ const bundle = await rolldown({
14
+ input: configFile,
15
+ platform: "node",
16
+ resolve: { mainFields: ["main"] },
17
+ transform: { define: {
18
+ __dirname: dirnameVarName,
19
+ __filename: filenameVarName,
20
+ "import.meta.url": importMetaUrlVarName,
21
+ "import.meta.dirname": dirnameVarName,
22
+ "import.meta.filename": filenameVarName
23
+ } },
24
+ treeshake: false,
25
+ external: [/^[\w@][^:]/],
26
+ plugins: [{
27
+ name: "inject-file-scope-variables",
28
+ transform: {
29
+ filter: { id: /\.[cm]?[jt]s$/ },
30
+ async handler(code, id) {
31
+ return {
32
+ code: `const ${dirnameVarName} = ${JSON.stringify(path.dirname(id))};const ${filenameVarName} = ${JSON.stringify(id)};const ${importMetaUrlVarName} = ${JSON.stringify(pathToFileURL(id).href)};` + code,
33
+ map: null
34
+ };
35
+ }
36
+ }
37
+ }]
38
+ });
39
+ const outputDir = path.dirname(configFile);
40
+ const fileName = (await bundle.write({
41
+ dir: outputDir,
42
+ format: isEsm ? "esm" : "cjs",
43
+ sourcemap: "inline",
44
+ entryFileNames: `rolldown.config.[hash]${path.extname(configFile).replace("ts", "js")}`
45
+ })).output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
46
+ return path.join(outputDir, fileName);
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";
60
+ async function findConfigFileNameInCwd() {
61
+ const filesInWorkingDirectory = new Set(await readdir(cwd()));
62
+ for (const extension of SUPPORTED_CONFIG_FORMATS) {
63
+ const fileName = `${DEFAULT_CONFIG_BASE}${extension}`;
64
+ if (filesInWorkingDirectory.has(fileName)) return fileName;
65
+ }
66
+ throw new Error("No `rolldown.config` configuration file found.");
67
+ }
68
+ async function loadTsConfig(configFile) {
69
+ const file = await bundleTsConfig(configFile, isFilePathESM(configFile));
70
+ try {
71
+ return (await import(pathToFileURL(file).href)).default;
72
+ } finally {
73
+ fs.unlink(file, () => {});
74
+ }
75
+ }
76
+ function isFilePathESM(filePath) {
77
+ if (/\.m[jt]s$/.test(filePath)) return true;
78
+ else if (/\.c[jt]s$/.test(filePath)) return false;
79
+ else {
80
+ const pkg = findNearestPackageData(path.dirname(filePath));
81
+ if (pkg) return pkg.type === "module";
82
+ return false;
83
+ }
84
+ }
85
+ function findNearestPackageData(basedir) {
86
+ while (basedir) {
87
+ const pkgPath = path.join(basedir, "package.json");
88
+ if (tryStatSync(pkgPath)?.isFile()) try {
89
+ return JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
90
+ } catch {}
91
+ const nextBasedir = path.dirname(basedir);
92
+ if (nextBasedir === basedir) break;
93
+ basedir = nextBasedir;
94
+ }
95
+ return null;
96
+ }
97
+ function tryStatSync(file) {
98
+ try {
99
+ return fs.statSync(file, { throwIfNoEntry: false });
100
+ } catch {}
101
+ }
102
+ async function loadConfig(configPath) {
103
+ const ext = path.extname(configPath = configPath || await findConfigFileNameInCwd());
104
+ try {
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;
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}\``);
108
+ } catch (err) {
109
+ throw new Error("Error happened while loading config.", { cause: err });
110
+ }
111
+ }
112
+
113
+ //#endregion
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 };
@@ -0,0 +1,22 @@
1
+ //#region src/utils/misc.ts
2
+ function arraify(value) {
3
+ return Array.isArray(value) ? value : [value];
4
+ }
5
+ function isPromiseLike(value) {
6
+ return value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
7
+ }
8
+ function unimplemented(info) {
9
+ if (info) throw new Error(`unimplemented: ${info}`);
10
+ throw new Error("unimplemented");
11
+ }
12
+ function unreachable(info) {
13
+ if (info) throw new Error(`unreachable: ${info}`);
14
+ throw new Error("unreachable");
15
+ }
16
+ function unsupported(info) {
17
+ throw new Error(`UNSUPPORTED: ${info}`);
18
+ }
19
+ function noop(..._args) {}
20
+
21
+ //#endregion
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-tNJoEqAa.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-tNJoEqAa.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 };