@rolldown/browser 1.0.0-beta.34 → 1.0.0-beta.36

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 (51) hide show
  1. package/dist/cli.mjs +219 -230
  2. package/dist/config.d.mts +2 -2
  3. package/dist/config.mjs +4 -4
  4. package/dist/experimental-index.browser.mjs +22 -6
  5. package/dist/experimental-index.d.mts +16 -4
  6. package/dist/experimental-index.mjs +24 -8
  7. package/dist/filter-index.d.mts +2 -2
  8. package/dist/filter-index.mjs +1 -1
  9. package/dist/index.browser.mjs +1 -1
  10. package/dist/index.d.mts +2 -2
  11. package/dist/index.mjs +3 -3
  12. package/dist/parallel-plugin-worker.mjs +5 -6
  13. package/dist/parallel-plugin.d.mts +2 -2
  14. package/dist/parse-ast-index.d.mts +1 -1
  15. package/dist/parse-ast-index.mjs +1 -1
  16. package/dist/rolldown-binding.wasi-browser.js +4 -0
  17. package/dist/rolldown-binding.wasi.cjs +4 -0
  18. package/dist/rolldown-binding.wasm32-wasi.wasm +0 -0
  19. package/dist/shared/{binding-9k0egz6L.d.mts → binding-wK0CRIMb.d.mts} +1 -0
  20. package/dist/shared/{define-config-DzIQxNqU.d.mts → define-config-BcNhk996.d.mts} +30 -3
  21. package/dist/shared/{dist-ByKQkexh.mjs → dist-CHTC3-kR.mjs} +1 -1
  22. package/dist/shared/{load-config--VYNOtUY.mjs → load-config-M8Gvqt1X.mjs} +4 -6
  23. package/dist/shared/{parse-ast-index-C_CZT4St.mjs → parse-ast-index-C3TkGcEQ.mjs} +1 -1
  24. package/dist/shared/{prompt-C5jz26Zn.mjs → prompt-DuG2i9ud.mjs} +4 -7
  25. package/dist/shared/{src-B4V64IkU.mjs → src-Dc4fRARy.mjs} +143 -72
  26. package/dist/{src-Bl12Y5ab.js → src-Cl6h35QH.js} +141 -71
  27. package/package.json +10 -24
  28. package/dist/cli.cjs +0 -1766
  29. package/dist/cli.d.cts +0 -1
  30. package/dist/config.cjs +0 -12
  31. package/dist/config.d.cts +0 -10
  32. package/dist/experimental-index.cjs +0 -160
  33. package/dist/experimental-index.d.cts +0 -90
  34. package/dist/filter-index.cjs +0 -53
  35. package/dist/filter-index.d.cts +0 -4
  36. package/dist/index.cjs +0 -9
  37. package/dist/index.d.cts +0 -3
  38. package/dist/parallel-plugin-worker.cjs +0 -33
  39. package/dist/parallel-plugin-worker.d.cts +0 -1
  40. package/dist/parallel-plugin.cjs +0 -8
  41. package/dist/parallel-plugin.d.cts +0 -14
  42. package/dist/parse-ast-index.cjs +0 -4
  43. package/dist/parse-ast-index.d.cts +0 -8
  44. package/dist/shared/binding-D13M6Llu.d.cts +0 -1425
  45. package/dist/shared/chunk-DDkG_k5U.cjs +0 -39
  46. package/dist/shared/define-config-D5AluabE.d.cts +0 -1394
  47. package/dist/shared/dist-CK0hotcm.cjs +0 -240
  48. package/dist/shared/load-config-DfHD1OI9.cjs +0 -125
  49. package/dist/shared/parse-ast-index-ChWj_C49.cjs +0 -326
  50. package/dist/shared/prompt-QNI93ne7.cjs +0 -854
  51. package/dist/shared/src-McCMqGpa.cjs +0 -4738
@@ -1,240 +0,0 @@
1
-
2
- //#region src/utils/misc.ts
3
- function arraify(value) {
4
- return Array.isArray(value) ? value : [value];
5
- }
6
- function isPromiseLike(value) {
7
- return value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
8
- }
9
- function unimplemented(info) {
10
- if (info) throw new Error(`unimplemented: ${info}`);
11
- throw new Error("unimplemented");
12
- }
13
- function unreachable(info) {
14
- if (info) throw new Error(`unreachable: ${info}`);
15
- throw new Error("unreachable");
16
- }
17
- function unsupported(info) {
18
- throw new Error(`UNSUPPORTED: ${info}`);
19
- }
20
- function noop(..._args) {}
21
-
22
- //#endregion
23
- //#region ../pluginutils/dist/index.js
24
- var And = class {
25
- kind;
26
- args;
27
- constructor(...args) {
28
- if (args.length === 0) throw new Error("`And` expects at least one operand");
29
- this.args = args;
30
- this.kind = "and";
31
- }
32
- };
33
- var Or = class {
34
- kind;
35
- args;
36
- constructor(...args) {
37
- if (args.length === 0) throw new Error("`Or` expects at least one operand");
38
- this.args = args;
39
- this.kind = "or";
40
- }
41
- };
42
- var Not = class {
43
- kind;
44
- expr;
45
- constructor(expr) {
46
- this.expr = expr;
47
- this.kind = "not";
48
- }
49
- };
50
- var Id = class {
51
- kind;
52
- pattern;
53
- params;
54
- constructor(pattern, params) {
55
- this.pattern = pattern;
56
- this.kind = "id";
57
- this.params = params ?? { cleanUrl: false };
58
- }
59
- };
60
- var ModuleType = class {
61
- kind;
62
- pattern;
63
- constructor(pattern) {
64
- this.pattern = pattern;
65
- this.kind = "moduleType";
66
- }
67
- };
68
- var Code = class {
69
- kind;
70
- pattern;
71
- constructor(expr) {
72
- this.pattern = expr;
73
- this.kind = "code";
74
- }
75
- };
76
- var Query = class {
77
- kind;
78
- key;
79
- pattern;
80
- constructor(key, pattern) {
81
- this.pattern = pattern;
82
- this.key = key;
83
- this.kind = "query";
84
- }
85
- };
86
- var Include = class {
87
- kind;
88
- expr;
89
- constructor(expr) {
90
- this.expr = expr;
91
- this.kind = "include";
92
- }
93
- };
94
- var Exclude = class {
95
- kind;
96
- expr;
97
- constructor(expr) {
98
- this.expr = expr;
99
- this.kind = "exclude";
100
- }
101
- };
102
- function and(...args) {
103
- return new And(...args);
104
- }
105
- function or(...args) {
106
- return new Or(...args);
107
- }
108
- function not(expr) {
109
- return new Not(expr);
110
- }
111
- function id(pattern, params) {
112
- return new Id(pattern, params);
113
- }
114
- function moduleType(pattern) {
115
- return new ModuleType(pattern);
116
- }
117
- function code(pattern) {
118
- return new Code(pattern);
119
- }
120
- function query(key, pattern) {
121
- return new Query(key, pattern);
122
- }
123
- function include(expr) {
124
- return new Include(expr);
125
- }
126
- function exclude(expr) {
127
- return new Exclude(expr);
128
- }
129
- /**
130
- * convert a queryObject to FilterExpression like
131
- * ```js
132
- * and(query(k1, v1), query(k2, v2))
133
- * ```
134
- * @param queryFilterObject The query filter object needs to be matched.
135
- * @returns a `And` FilterExpression
136
- */
137
- function queries(queryFilter) {
138
- let arr = Object.entries(queryFilter).map(([key, value]) => {
139
- return new Query(key, value);
140
- });
141
- return and(...arr);
142
- }
143
-
144
- //#endregion
145
- Object.defineProperty(exports, 'and', {
146
- enumerable: true,
147
- get: function () {
148
- return and;
149
- }
150
- });
151
- Object.defineProperty(exports, 'arraify', {
152
- enumerable: true,
153
- get: function () {
154
- return arraify;
155
- }
156
- });
157
- Object.defineProperty(exports, 'code', {
158
- enumerable: true,
159
- get: function () {
160
- return code;
161
- }
162
- });
163
- Object.defineProperty(exports, 'exclude', {
164
- enumerable: true,
165
- get: function () {
166
- return exclude;
167
- }
168
- });
169
- Object.defineProperty(exports, 'id', {
170
- enumerable: true,
171
- get: function () {
172
- return id;
173
- }
174
- });
175
- Object.defineProperty(exports, 'include', {
176
- enumerable: true,
177
- get: function () {
178
- return include;
179
- }
180
- });
181
- Object.defineProperty(exports, 'isPromiseLike', {
182
- enumerable: true,
183
- get: function () {
184
- return isPromiseLike;
185
- }
186
- });
187
- Object.defineProperty(exports, 'moduleType', {
188
- enumerable: true,
189
- get: function () {
190
- return moduleType;
191
- }
192
- });
193
- Object.defineProperty(exports, 'noop', {
194
- enumerable: true,
195
- get: function () {
196
- return noop;
197
- }
198
- });
199
- Object.defineProperty(exports, 'not', {
200
- enumerable: true,
201
- get: function () {
202
- return not;
203
- }
204
- });
205
- Object.defineProperty(exports, 'or', {
206
- enumerable: true,
207
- get: function () {
208
- return or;
209
- }
210
- });
211
- Object.defineProperty(exports, 'queries', {
212
- enumerable: true,
213
- get: function () {
214
- return queries;
215
- }
216
- });
217
- Object.defineProperty(exports, 'query', {
218
- enumerable: true,
219
- get: function () {
220
- return query;
221
- }
222
- });
223
- Object.defineProperty(exports, 'unimplemented', {
224
- enumerable: true,
225
- get: function () {
226
- return unimplemented;
227
- }
228
- });
229
- Object.defineProperty(exports, 'unreachable', {
230
- enumerable: true,
231
- get: function () {
232
- return unreachable;
233
- }
234
- });
235
- Object.defineProperty(exports, 'unsupported', {
236
- enumerable: true,
237
- get: function () {
238
- return unsupported;
239
- }
240
- });
@@ -1,125 +0,0 @@
1
- const require_chunk = require('./chunk-DDkG_k5U.cjs');
2
- const require_src = require('./src-McCMqGpa.cjs');
3
- const node_path = require_chunk.__toESM(require("node:path"));
4
- const node_url = require_chunk.__toESM(require("node:url"));
5
- const node_fs_promises = require_chunk.__toESM(require("node:fs/promises"));
6
- const node_process = require_chunk.__toESM(require("node:process"));
7
- const node_fs = require_chunk.__toESM(require("node:fs"));
8
-
9
- //#region src/utils/load-config.ts
10
- async function bundleTsConfig(configFile, isEsm) {
11
- const dirnameVarName = "injected_original_dirname";
12
- const filenameVarName = "injected_original_filename";
13
- const importMetaUrlVarName = "injected_original_import_meta_url";
14
- const bundle = await require_src.rolldown({
15
- input: configFile,
16
- platform: "node",
17
- resolve: { mainFields: ["main"] },
18
- define: {
19
- __dirname: dirnameVarName,
20
- __filename: filenameVarName,
21
- "import.meta.url": importMetaUrlVarName,
22
- "import.meta.dirname": dirnameVarName,
23
- "import.meta.filename": filenameVarName
24
- },
25
- treeshake: false,
26
- external: [/^[\w@][^:]/],
27
- plugins: [{
28
- name: "inject-file-scope-variables",
29
- transform: {
30
- filter: { id: /\.[cm]?[jt]s$/ },
31
- async handler(code, id) {
32
- const injectValues = `const ${dirnameVarName} = ${JSON.stringify(node_path.default.dirname(id))};const ${filenameVarName} = ${JSON.stringify(id)};const ${importMetaUrlVarName} = ${JSON.stringify((0, node_url.pathToFileURL)(id).href)};`;
33
- return {
34
- code: injectValues + code,
35
- map: null
36
- };
37
- }
38
- }
39
- }]
40
- });
41
- const outputDir = node_path.default.dirname(configFile);
42
- const result = await bundle.write({
43
- dir: outputDir,
44
- format: isEsm ? "esm" : "cjs",
45
- sourcemap: "inline",
46
- entryFileNames: `rolldown.config.[hash]${node_path.default.extname(configFile).replace("ts", "js")}`
47
- });
48
- const fileName = result.output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
49
- return node_path.default.join(outputDir, fileName);
50
- }
51
- const SUPPORTED_JS_CONFIG_FORMATS = [
52
- ".js",
53
- ".mjs",
54
- ".cjs"
55
- ];
56
- const SUPPORTED_TS_CONFIG_FORMATS = [
57
- ".ts",
58
- ".mts",
59
- ".cts"
60
- ];
61
- const SUPPORTED_CONFIG_FORMATS = [...SUPPORTED_JS_CONFIG_FORMATS, ...SUPPORTED_TS_CONFIG_FORMATS];
62
- const DEFAULT_CONFIG_BASE = "rolldown.config";
63
- async function findConfigFileNameInCwd() {
64
- const filesInWorkingDirectory = new Set(await (0, node_fs_promises.readdir)((0, node_process.cwd)()));
65
- for (const extension of SUPPORTED_CONFIG_FORMATS) {
66
- const fileName = `${DEFAULT_CONFIG_BASE}${extension}`;
67
- if (filesInWorkingDirectory.has(fileName)) return fileName;
68
- }
69
- throw new Error("No `rolldown.config` configuration file found.");
70
- }
71
- async function loadTsConfig(configFile) {
72
- const isEsm = isFilePathESM(configFile);
73
- const file = await bundleTsConfig(configFile, isEsm);
74
- try {
75
- return (await import((0, node_url.pathToFileURL)(file).href)).default;
76
- } finally {
77
- node_fs.default.unlink(file, () => {});
78
- }
79
- }
80
- function isFilePathESM(filePath) {
81
- if (/\.m[jt]s$/.test(filePath)) return true;
82
- else if (/\.c[jt]s$/.test(filePath)) return false;
83
- else {
84
- const pkg = findNearestPackageData(node_path.default.dirname(filePath));
85
- if (pkg) return pkg.type === "module";
86
- return false;
87
- }
88
- }
89
- function findNearestPackageData(basedir) {
90
- while (basedir) {
91
- const pkgPath = node_path.default.join(basedir, "package.json");
92
- if (tryStatSync(pkgPath)?.isFile()) try {
93
- return JSON.parse(node_fs.default.readFileSync(pkgPath, "utf-8"));
94
- } catch {}
95
- const nextBasedir = node_path.default.dirname(basedir);
96
- if (nextBasedir === basedir) break;
97
- basedir = nextBasedir;
98
- }
99
- return null;
100
- }
101
- function tryStatSync(file) {
102
- try {
103
- return node_fs.default.statSync(file, { throwIfNoEntry: false });
104
- } catch {}
105
- }
106
- async function loadConfig(configPath) {
107
- const ext = node_path.default.extname(configPath = configPath || await findConfigFileNameInCwd());
108
- try {
109
- if (SUPPORTED_JS_CONFIG_FORMATS.includes(ext) || process.env.NODE_OPTIONS?.includes("--import=tsx") && SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) return (await import((0, node_url.pathToFileURL)(configPath).href)).default;
110
- else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) {
111
- const rawConfigPath = node_path.default.resolve(configPath);
112
- return await loadTsConfig(rawConfigPath);
113
- } else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
114
- } catch (err) {
115
- throw new Error("Error happened while loading config.", { cause: err });
116
- }
117
- }
118
-
119
- //#endregion
120
- Object.defineProperty(exports, 'loadConfig', {
121
- enumerable: true,
122
- get: function () {
123
- return loadConfig;
124
- }
125
- });
@@ -1,326 +0,0 @@
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
-
4
- //#region src/utils/code-frame.ts
5
- function spaces(index) {
6
- let result = "";
7
- while (index--) result += " ";
8
- return result;
9
- }
10
- function tabsToSpaces(value) {
11
- return value.replace(/^\t+/, (match) => match.split(" ").join(" "));
12
- }
13
- const LINE_TRUNCATE_LENGTH = 120;
14
- const MIN_CHARACTERS_SHOWN_AFTER_LOCATION = 10;
15
- const ELLIPSIS = "...";
16
- function getCodeFrame(source, line, column) {
17
- let lines = source.split("\n");
18
- if (line > lines.length) return "";
19
- const maxLineLength = Math.max(tabsToSpaces(lines[line - 1].slice(0, column)).length + MIN_CHARACTERS_SHOWN_AFTER_LOCATION + 3, LINE_TRUNCATE_LENGTH);
20
- const frameStart = Math.max(0, line - 3);
21
- let frameEnd = Math.min(line + 2, lines.length);
22
- lines = lines.slice(frameStart, frameEnd);
23
- while (!/\S/.test(lines[lines.length - 1])) {
24
- lines.pop();
25
- frameEnd -= 1;
26
- }
27
- const digits = String(frameEnd).length;
28
- return lines.map((sourceLine, index) => {
29
- const isErrorLine = frameStart + index + 1 === line;
30
- let lineNumber = String(index + frameStart + 1);
31
- while (lineNumber.length < digits) lineNumber = ` ${lineNumber}`;
32
- let displayedLine = tabsToSpaces(sourceLine);
33
- if (displayedLine.length > maxLineLength) displayedLine = `${displayedLine.slice(0, maxLineLength - 3)}${ELLIPSIS}`;
34
- if (isErrorLine) {
35
- const indicator = spaces(digits + 2 + tabsToSpaces(sourceLine.slice(0, column)).length) + "^";
36
- return `${lineNumber}: ${displayedLine}\n${indicator}`;
37
- }
38
- return `${lineNumber}: ${displayedLine}`;
39
- }).join("\n");
40
- }
41
-
42
- //#endregion
43
- //#region src/log/locate-character/index.js
44
- /** @typedef {import('./types').Location} Location */
45
- /**
46
- * @param {import('./types').Range} range
47
- * @param {number} index
48
- */
49
- function rangeContains(range, index) {
50
- return range.start <= index && index < range.end;
51
- }
52
- /**
53
- * @param {string} source
54
- * @param {import('./types').Options} [options]
55
- */
56
- function getLocator(source, options = {}) {
57
- const { offsetLine = 0, offsetColumn = 0 } = options;
58
- let start = 0;
59
- const ranges = source.split("\n").map((line, i$1) => {
60
- const end = start + line.length + 1;
61
- /** @type {import('./types').Range} */
62
- const range = {
63
- start,
64
- end,
65
- line: i$1
66
- };
67
- start = end;
68
- return range;
69
- });
70
- let i = 0;
71
- /**
72
- * @param {string | number} search
73
- * @param {number} [index]
74
- * @returns {Location | undefined}
75
- */
76
- function locator(search, index) {
77
- if (typeof search === "string") search = source.indexOf(search, index ?? 0);
78
- if (search === -1) return void 0;
79
- let range = ranges[i];
80
- const d = search >= range.end ? 1 : -1;
81
- while (range) {
82
- if (rangeContains(range, search)) return {
83
- line: offsetLine + range.line,
84
- column: offsetColumn + search - range.start,
85
- character: search
86
- };
87
- i += d;
88
- range = ranges[i];
89
- }
90
- }
91
- return locator;
92
- }
93
- /**
94
- * @param {string} source
95
- * @param {string | number} search
96
- * @param {import('./types').Options} [options]
97
- * @returns {Location | undefined}
98
- */
99
- function locate(source, search, options) {
100
- return getLocator(source, options)(search, options && options.startIndex);
101
- }
102
-
103
- //#endregion
104
- //#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", DUPLICATE_JSX_CONFIG = "DUPLICATE_JSX_CONFIG", NO_FS_IN_BROWSER = "NO_FS_IN_BROWSER";
106
- function logParseError(message) {
107
- return {
108
- code: PARSE_ERROR,
109
- message
110
- };
111
- }
112
- function logInvalidLogPosition(pluginName) {
113
- return {
114
- code: INVALID_LOG_POSITION,
115
- 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.`
116
- };
117
- }
118
- function logInputHookInOutputPlugin(pluginName, hookName) {
119
- return {
120
- code: INPUT_HOOK_IN_OUTPUT_PLUGIN,
121
- 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.`
122
- };
123
- }
124
- function logCycleLoading(pluginName, moduleId) {
125
- return {
126
- code: CYCLE_LOADING,
127
- message: `Found the module "${moduleId}" cycle loading at ${pluginName} plugin, it maybe blocking fetching modules.`
128
- };
129
- }
130
- function logMultiplyNotifyOption() {
131
- return {
132
- code: MULTIPLY_NOTIFY_OPTION,
133
- message: `Found multiply notify option at watch options, using first one to start notify watcher.`
134
- };
135
- }
136
- function logDuplicateJsxConfig() {
137
- return {
138
- code: DUPLICATE_JSX_CONFIG,
139
- message: "Both `options.jsx` and `options.transform.jsx` are set so `options.jsx` is ignored"
140
- };
141
- }
142
- function logPluginError(error$1, plugin, { hook, id } = {}) {
143
- try {
144
- const code = error$1.code;
145
- if (!error$1.pluginCode && code != null && (typeof code !== "string" || !code.startsWith("PLUGIN_"))) error$1.pluginCode = code;
146
- error$1.code = PLUGIN_ERROR;
147
- error$1.plugin = plugin;
148
- if (hook) error$1.hook = hook;
149
- if (id) error$1.id = id;
150
- } catch (_) {} finally {
151
- return error$1;
152
- }
153
- }
154
- function error(base) {
155
- if (!(base instanceof Error)) {
156
- base = Object.assign(new Error(base.message), base);
157
- Object.defineProperty(base, "name", {
158
- value: "RollupError",
159
- writable: true
160
- });
161
- }
162
- throw base;
163
- }
164
- function augmentCodeLocation(properties, pos, source, id) {
165
- if (typeof pos === "object") {
166
- const { line, column } = pos;
167
- properties.loc = {
168
- column,
169
- file: id,
170
- line
171
- };
172
- } else {
173
- properties.pos = pos;
174
- const location = locate(source, pos, { offsetLine: 1 });
175
- if (!location) return;
176
- const { line, column } = location;
177
- properties.loc = {
178
- column,
179
- file: id,
180
- line
181
- };
182
- }
183
- if (properties.frame === void 0) {
184
- const { line, column } = properties.loc;
185
- properties.frame = getCodeFrame(source, line, column);
186
- }
187
- }
188
-
189
- //#endregion
190
- //#region ../../node_modules/.pnpm/oxc-parser@0.82.3/node_modules/oxc-parser/wrap.mjs
191
- function wrap$1(result) {
192
- let program, module$1, comments, errors;
193
- return {
194
- get program() {
195
- if (!program) program = jsonParseAst(result.program);
196
- return program;
197
- },
198
- get module() {
199
- if (!module$1) module$1 = result.module;
200
- return module$1;
201
- },
202
- get comments() {
203
- if (!comments) comments = result.comments;
204
- return comments;
205
- },
206
- get errors() {
207
- if (!errors) errors = result.errors;
208
- return errors;
209
- }
210
- };
211
- }
212
- function jsonParseAst(programJson) {
213
- const { node: program, fixes } = JSON.parse(programJson);
214
- for (const fixPath of fixes) applyFix(program, fixPath);
215
- return program;
216
- }
217
- function applyFix(program, fixPath) {
218
- let node = program;
219
- for (const key of fixPath) node = node[key];
220
- if (node.bigint) node.value = BigInt(node.bigint);
221
- else try {
222
- node.value = RegExp(node.regex.pattern, node.regex.flags);
223
- } catch (_err) {}
224
- }
225
-
226
- //#endregion
227
- //#region src/parse-ast-index.ts
228
- function wrap(result, sourceText) {
229
- result = wrap$1(result);
230
- if (result.errors.length > 0) return normalizeParseError(sourceText, result.errors);
231
- return result.program;
232
- }
233
- function normalizeParseError(sourceText, errors) {
234
- let message = `Parse failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
235
- for (let i = 0; i < errors.length; i++) {
236
- if (i >= 5) {
237
- message += "\n...";
238
- break;
239
- }
240
- const e = errors[i];
241
- message += e.message + "\n" + e.labels.map((label) => {
242
- const location = locate(sourceText, label.start, { offsetLine: 1 });
243
- if (!location) return;
244
- return getCodeFrame(sourceText, location.line, location.column);
245
- }).filter(Boolean).join("\n");
246
- }
247
- return error(logParseError(message));
248
- }
249
- const defaultParserOptions = {
250
- lang: "js",
251
- preserveParens: false
252
- };
253
- function parseAst(sourceText, options, filename) {
254
- return wrap((0, src_rolldown_binding_wasi_cjs.parseSync)(filename ?? "file.js", sourceText, {
255
- ...defaultParserOptions,
256
- ...options
257
- }), sourceText);
258
- }
259
- async function parseAstAsync(sourceText, options, filename) {
260
- return wrap(await (0, src_rolldown_binding_wasi_cjs.parseAsync)(filename ?? "file.js", sourceText, {
261
- ...defaultParserOptions,
262
- ...options
263
- }), sourceText);
264
- }
265
-
266
- //#endregion
267
- Object.defineProperty(exports, 'augmentCodeLocation', {
268
- enumerable: true,
269
- get: function () {
270
- return augmentCodeLocation;
271
- }
272
- });
273
- Object.defineProperty(exports, 'error', {
274
- enumerable: true,
275
- get: function () {
276
- return error;
277
- }
278
- });
279
- Object.defineProperty(exports, 'logCycleLoading', {
280
- enumerable: true,
281
- get: function () {
282
- return logCycleLoading;
283
- }
284
- });
285
- Object.defineProperty(exports, 'logDuplicateJsxConfig', {
286
- enumerable: true,
287
- get: function () {
288
- return logDuplicateJsxConfig;
289
- }
290
- });
291
- Object.defineProperty(exports, 'logInputHookInOutputPlugin', {
292
- enumerable: true,
293
- get: function () {
294
- return logInputHookInOutputPlugin;
295
- }
296
- });
297
- Object.defineProperty(exports, 'logInvalidLogPosition', {
298
- enumerable: true,
299
- get: function () {
300
- return logInvalidLogPosition;
301
- }
302
- });
303
- Object.defineProperty(exports, 'logMultiplyNotifyOption', {
304
- enumerable: true,
305
- get: function () {
306
- return logMultiplyNotifyOption;
307
- }
308
- });
309
- Object.defineProperty(exports, 'logPluginError', {
310
- enumerable: true,
311
- get: function () {
312
- return logPluginError;
313
- }
314
- });
315
- Object.defineProperty(exports, 'parseAst', {
316
- enumerable: true,
317
- get: function () {
318
- return parseAst;
319
- }
320
- });
321
- Object.defineProperty(exports, 'parseAstAsync', {
322
- enumerable: true,
323
- get: function () {
324
- return parseAstAsync;
325
- }
326
- });