@rolldown/browser 1.0.0-beta.7-commit.a0a7d95
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.
- package/LICENSE +25 -0
- package/bin/cli.mjs +2 -0
- package/dist/browser-bundler.mjs +3514 -0
- package/dist/browser.js +4626 -0
- package/dist/cli.cjs +1759 -0
- package/dist/cli.mjs +1828 -0
- package/dist/experimental-index.cjs +87 -0
- package/dist/experimental-index.mjs +67 -0
- package/dist/index.cjs +9 -0
- package/dist/index.mjs +5 -0
- package/dist/parallel-plugin-worker.cjs +43 -0
- package/dist/parallel-plugin-worker.mjs +48 -0
- package/dist/parallel-plugin.cjs +9 -0
- package/dist/parallel-plugin.mjs +8 -0
- package/dist/parse-ast-index.cjs +4 -0
- package/dist/parse-ast-index.mjs +4 -0
- package/dist/rolldown-binding.wasi-browser.js +102 -0
- package/dist/rolldown-binding.wasi.cjs +127 -0
- package/dist/rolldown-binding.wasm32-wasi.wasm +0 -0
- package/dist/shared/chunk-BuCFLigr.mjs +12 -0
- package/dist/shared/chunk-Dc32QXFI.cjs +31 -0
- package/dist/shared/parse-ast-index-C29iO6Jv.cjs +316 -0
- package/dist/shared/parse-ast-index-GcZLh6_d.mjs +273 -0
- package/dist/shared/prompt-B3VJLbs9.mjs +854 -0
- package/dist/shared/prompt-wpCBKCzA.cjs +855 -0
- package/dist/shared/src-6_rb-jCl.cjs +3147 -0
- package/dist/shared/src-QrPvO0Ec.mjs +4375 -0
- package/dist/types/api/build.d.ts +18 -0
- package/dist/types/api/experimental.d.ts +7 -0
- package/dist/types/api/rolldown/index.d.ts +3 -0
- package/dist/types/api/rolldown/rolldown-build.d.ts +15 -0
- package/dist/types/api/watch/index.d.ts +3 -0
- package/dist/types/api/watch/watch-emitter.d.ts +31 -0
- package/dist/types/api/watch/watcher.d.ts +13 -0
- package/dist/types/binding.d.ts +1504 -0
- package/dist/types/builtin-plugin/alias-plugin.d.ts +10 -0
- package/dist/types/builtin-plugin/constructors.d.ts +22 -0
- package/dist/types/builtin-plugin/replace-plugin.d.ts +27 -0
- package/dist/types/builtin-plugin/transform-plugin.d.ts +9 -0
- package/dist/types/builtin-plugin/utils.d.ts +8 -0
- package/dist/types/cli/arguments/alias.d.ts +16 -0
- package/dist/types/cli/arguments/index.d.ts +15 -0
- package/dist/types/cli/arguments/normalize.d.ts +16 -0
- package/dist/types/cli/arguments/utils.d.ts +8 -0
- package/dist/types/cli/commands/bundle.d.ts +3 -0
- package/dist/types/cli/commands/help.d.ts +1 -0
- package/dist/types/cli/index.d.ts +1 -0
- package/dist/types/cli/load-config.d.ts +5 -0
- package/dist/types/cli/logger.d.ts +5 -0
- package/dist/types/constants/plugin-context.d.ts +7 -0
- package/dist/types/constants/plugin.d.ts +45 -0
- package/dist/types/experimental-index.d.ts +9 -0
- package/dist/types/index.d.ts +31 -0
- package/dist/types/log/log-handler.d.ts +4 -0
- package/dist/types/log/logger.d.ts +6 -0
- package/dist/types/log/logging.d.ts +12 -0
- package/dist/types/log/logs.d.ts +18 -0
- package/dist/types/options/generated/checks-options.d.ts +57 -0
- package/dist/types/options/input-options.d.ts +185 -0
- package/dist/types/options/normalized-input-options.d.ts +18 -0
- package/dist/types/options/normalized-output-options.d.ts +70 -0
- package/dist/types/options/output-options.d.ts +182 -0
- package/dist/types/options/watch-options.d.ts +5 -0
- package/dist/types/parallel-plugin-worker.d.ts +1 -0
- package/dist/types/parallel-plugin.d.ts +1 -0
- package/dist/types/parse-ast-index.d.ts +5 -0
- package/dist/types/plugin/bindingify-build-hooks.d.ts +10 -0
- package/dist/types/plugin/bindingify-hook-filter.d.ts +7 -0
- package/dist/types/plugin/bindingify-output-hooks.d.ts +14 -0
- package/dist/types/plugin/bindingify-plugin-hook-meta.d.ts +8 -0
- package/dist/types/plugin/bindingify-plugin.d.ts +17 -0
- package/dist/types/plugin/bindingify-watch-hooks.d.ts +5 -0
- package/dist/types/plugin/hook-filter.d.ts +49 -0
- package/dist/types/plugin/index.d.ts +141 -0
- package/dist/types/plugin/minimal-plugin-context.d.ts +24 -0
- package/dist/types/plugin/parallel-plugin-implementation.d.ts +10 -0
- package/dist/types/plugin/parallel-plugin.d.ts +9 -0
- package/dist/types/plugin/plugin-context-data.d.ts +21 -0
- package/dist/types/plugin/plugin-context.d.ts +67 -0
- package/dist/types/plugin/plugin-driver.d.ts +10 -0
- package/dist/types/plugin/transform-plugin-context.d.ts +28 -0
- package/dist/types/plugin/with-filter.d.ts +10 -0
- package/dist/types/types/assert.d.ts +14 -0
- package/dist/types/types/config-export.d.ts +5 -0
- package/dist/types/types/misc.d.ts +40 -0
- package/dist/types/types/module-info.d.ts +15 -0
- package/dist/types/types/module-side-effects.d.ts +12 -0
- package/dist/types/types/output-bundle.d.ts +4 -0
- package/dist/types/types/rolldown-options.d.ts +5 -0
- package/dist/types/types/rolldown-output.d.ts +66 -0
- package/dist/types/types/schema.d.ts +33 -0
- package/dist/types/types/sourcemap.d.ts +14 -0
- package/dist/types/types/utils.d.ts +13 -0
- package/dist/types/types.d.ts +7 -0
- package/dist/types/utils/asset-source.d.ts +4 -0
- package/dist/types/utils/async-flatten.d.ts +1 -0
- package/dist/types/utils/bindingify-input-options.d.ts +7 -0
- package/dist/types/utils/bindingify-output-options.d.ts +5 -0
- package/dist/types/utils/code-frame.d.ts +1 -0
- package/dist/types/utils/compose-js-plugins.d.ts +2 -0
- package/dist/types/utils/create-bundler-option.d.ts +11 -0
- package/dist/types/utils/create-bundler.d.ts +9 -0
- package/dist/types/utils/define-config.d.ts +5 -0
- package/dist/types/utils/error.d.ts +2 -0
- package/dist/types/utils/initialize-parallel-plugins.d.ts +17 -0
- package/dist/types/utils/misc.d.ts +7 -0
- package/dist/types/utils/normalize-hook.d.ts +7 -0
- package/dist/types/utils/normalize-plugin-option.d.ts +13 -0
- package/dist/types/utils/normalize-string-or-regex.d.ts +2 -0
- package/dist/types/utils/plugin/index.d.ts +2 -0
- package/dist/types/utils/resolved-external.d.ts +4 -0
- package/dist/types/utils/transform-module-info.d.ts +4 -0
- package/dist/types/utils/transform-rendered-chunk.d.ts +4 -0
- package/dist/types/utils/transform-rendered-module.d.ts +3 -0
- package/dist/types/utils/transform-side-effects.d.ts +3 -0
- package/dist/types/utils/transform-sourcemap.d.ts +3 -0
- package/dist/types/utils/transform-to-rollup-output.d.ts +11 -0
- package/dist/types/utils/validator.d.ts +6 -0
- package/dist/wasi-worker-browser.mjs +39 -0
- package/dist/wasi-worker.mjs +63 -0
- package/package.json +85 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const require_chunk = require('./chunk-Dc32QXFI.cjs');
|
|
3
|
+
const src_rolldown_binding_wasi_cjs = require_chunk.__toESM(require("../rolldown-binding.wasi.cjs"));
|
|
4
|
+
const ansis = require_chunk.__toESM(require("ansis"));
|
|
5
|
+
|
|
6
|
+
//#region src/utils/code-frame.ts
|
|
7
|
+
function spaces(index) {
|
|
8
|
+
let result = "";
|
|
9
|
+
while (index--) result += " ";
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
function tabsToSpaces(value) {
|
|
13
|
+
return value.replace(/^\t+/, (match) => match.split(" ").join(" "));
|
|
14
|
+
}
|
|
15
|
+
const LINE_TRUNCATE_LENGTH = 120;
|
|
16
|
+
const MIN_CHARACTERS_SHOWN_AFTER_LOCATION = 10;
|
|
17
|
+
const ELLIPSIS = "...";
|
|
18
|
+
function getCodeFrame(source, line, column) {
|
|
19
|
+
let lines = source.split("\n");
|
|
20
|
+
if (line > lines.length) return "";
|
|
21
|
+
const maxLineLength = Math.max(tabsToSpaces(lines[line - 1].slice(0, column)).length + MIN_CHARACTERS_SHOWN_AFTER_LOCATION + ELLIPSIS.length, LINE_TRUNCATE_LENGTH);
|
|
22
|
+
const frameStart = Math.max(0, line - 3);
|
|
23
|
+
let frameEnd = Math.min(line + 2, lines.length);
|
|
24
|
+
lines = lines.slice(frameStart, frameEnd);
|
|
25
|
+
while (!/\S/.test(lines[lines.length - 1])) {
|
|
26
|
+
lines.pop();
|
|
27
|
+
frameEnd -= 1;
|
|
28
|
+
}
|
|
29
|
+
const digits = String(frameEnd).length;
|
|
30
|
+
return lines.map((sourceLine, index) => {
|
|
31
|
+
const isErrorLine = frameStart + index + 1 === line;
|
|
32
|
+
let lineNumber = String(index + frameStart + 1);
|
|
33
|
+
while (lineNumber.length < digits) lineNumber = ` ${lineNumber}`;
|
|
34
|
+
let displayedLine = tabsToSpaces(sourceLine);
|
|
35
|
+
if (displayedLine.length > maxLineLength) displayedLine = `${displayedLine.slice(0, maxLineLength - ELLIPSIS.length)}${ELLIPSIS}`;
|
|
36
|
+
if (isErrorLine) {
|
|
37
|
+
const indicator = spaces(digits + 2 + tabsToSpaces(sourceLine.slice(0, column)).length) + "^";
|
|
38
|
+
return `${lineNumber}: ${displayedLine}\n${indicator}`;
|
|
39
|
+
}
|
|
40
|
+
return `${lineNumber}: ${displayedLine}`;
|
|
41
|
+
}).join("\n");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/log/locate-character/index.js
|
|
46
|
+
/** @typedef {import('./types').Location} Location */
|
|
47
|
+
/**
|
|
48
|
+
* @param {import('./types').Range} range
|
|
49
|
+
* @param {number} index
|
|
50
|
+
*/
|
|
51
|
+
function rangeContains(range, index) {
|
|
52
|
+
return range.start <= index && index < range.end;
|
|
53
|
+
}
|
|
54
|
+
function getLocator(source, options = {}) {
|
|
55
|
+
const { offsetLine = 0, offsetColumn = 0 } = options;
|
|
56
|
+
let start = 0;
|
|
57
|
+
const ranges = source.split("\n").map((line, i$1) => {
|
|
58
|
+
const end = start + line.length + 1;
|
|
59
|
+
/** @type {import('./types').Range} */
|
|
60
|
+
const range = {
|
|
61
|
+
start,
|
|
62
|
+
end,
|
|
63
|
+
line: i$1
|
|
64
|
+
};
|
|
65
|
+
start = end;
|
|
66
|
+
return range;
|
|
67
|
+
});
|
|
68
|
+
let i = 0;
|
|
69
|
+
/**
|
|
70
|
+
* @param {string | number} search
|
|
71
|
+
* @param {number} [index]
|
|
72
|
+
* @returns {Location | undefined}
|
|
73
|
+
*/
|
|
74
|
+
function locator(search, index) {
|
|
75
|
+
if (typeof search === "string") search = source.indexOf(search, index ?? 0);
|
|
76
|
+
if (search === -1) return void 0;
|
|
77
|
+
let range = ranges[i];
|
|
78
|
+
const d = search >= range.end ? 1 : -1;
|
|
79
|
+
while (range) {
|
|
80
|
+
if (rangeContains(range, search)) return {
|
|
81
|
+
line: offsetLine + range.line,
|
|
82
|
+
column: offsetColumn + search - range.start,
|
|
83
|
+
character: search
|
|
84
|
+
};
|
|
85
|
+
i += d;
|
|
86
|
+
range = ranges[i];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return locator;
|
|
90
|
+
}
|
|
91
|
+
function locate(source, search, options) {
|
|
92
|
+
return getLocator(source, options)(search, options && options.startIndex);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/log/logs.ts
|
|
97
|
+
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", MINIFY_WARNING = "MINIFY_WARNING", PARSE_ERROR = "PARSE_ERROR";
|
|
98
|
+
function logParseError(message) {
|
|
99
|
+
return {
|
|
100
|
+
code: PARSE_ERROR,
|
|
101
|
+
message
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function logMinifyWarning() {
|
|
105
|
+
return {
|
|
106
|
+
code: MINIFY_WARNING,
|
|
107
|
+
message: ansis.default.yellow("The built-in minifier is still under development. Setting \"minify: true\" is not recommended for production use.")
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function logInvalidLogPosition(pluginName) {
|
|
111
|
+
return {
|
|
112
|
+
code: INVALID_LOG_POSITION,
|
|
113
|
+
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.`
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function logInputHookInOutputPlugin(pluginName, hookName) {
|
|
117
|
+
return {
|
|
118
|
+
code: INPUT_HOOK_IN_OUTPUT_PLUGIN,
|
|
119
|
+
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.`
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function logCycleLoading(pluginName, moduleId) {
|
|
123
|
+
return {
|
|
124
|
+
code: CYCLE_LOADING,
|
|
125
|
+
message: `Found the module "${moduleId}" cycle loading at ${pluginName} plugin, it maybe blocking fetching modules.`
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function logMultiplyNotifyOption() {
|
|
129
|
+
return {
|
|
130
|
+
code: MULTIPLY_NOTIFY_OPTION,
|
|
131
|
+
message: `Found multiply notify option at watch options, using first one to start notify watcher.`
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function logPluginError(error$1, plugin, { hook, id } = {}) {
|
|
135
|
+
const code = error$1.code;
|
|
136
|
+
if (!error$1.pluginCode && code != null && (typeof code !== "string" || !code.startsWith("PLUGIN_"))) error$1.pluginCode = code;
|
|
137
|
+
error$1.code = PLUGIN_ERROR;
|
|
138
|
+
error$1.plugin = plugin;
|
|
139
|
+
if (hook) error$1.hook = hook;
|
|
140
|
+
if (id) error$1.id = id;
|
|
141
|
+
return error$1;
|
|
142
|
+
}
|
|
143
|
+
function error(base) {
|
|
144
|
+
if (!(base instanceof Error)) {
|
|
145
|
+
base = Object.assign(new Error(base.message), base);
|
|
146
|
+
Object.defineProperty(base, "name", {
|
|
147
|
+
value: "RollupError",
|
|
148
|
+
writable: true
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
throw base;
|
|
152
|
+
}
|
|
153
|
+
function augmentCodeLocation(properties, pos, source, id) {
|
|
154
|
+
if (typeof pos === "object") {
|
|
155
|
+
const { line, column } = pos;
|
|
156
|
+
properties.loc = {
|
|
157
|
+
column,
|
|
158
|
+
file: id,
|
|
159
|
+
line
|
|
160
|
+
};
|
|
161
|
+
} else {
|
|
162
|
+
properties.pos = pos;
|
|
163
|
+
const location = locate(source, pos, { offsetLine: 1 });
|
|
164
|
+
if (!location) return;
|
|
165
|
+
const { line, column } = location;
|
|
166
|
+
properties.loc = {
|
|
167
|
+
column,
|
|
168
|
+
file: id,
|
|
169
|
+
line
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
if (properties.frame === void 0) {
|
|
173
|
+
const { line, column } = properties.loc;
|
|
174
|
+
properties.frame = getCodeFrame(source, line, column);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region ../../node_modules/.pnpm/oxc-parser@0.63.0/node_modules/oxc-parser/wrap.mjs
|
|
180
|
+
function wrap$1(result) {
|
|
181
|
+
let program, module$1, comments, errors;
|
|
182
|
+
return {
|
|
183
|
+
get program() {
|
|
184
|
+
if (!program) program = jsonParseAst(result.program);
|
|
185
|
+
return program;
|
|
186
|
+
},
|
|
187
|
+
get module() {
|
|
188
|
+
if (!module$1) module$1 = result.module;
|
|
189
|
+
return module$1;
|
|
190
|
+
},
|
|
191
|
+
get comments() {
|
|
192
|
+
if (!comments) comments = result.comments;
|
|
193
|
+
return comments;
|
|
194
|
+
},
|
|
195
|
+
get errors() {
|
|
196
|
+
if (!errors) errors = result.errors;
|
|
197
|
+
return errors;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function jsonParseAst(ast) {
|
|
202
|
+
return JSON.parse(ast, function(key, value) {
|
|
203
|
+
if (value === null && key === "value" && Object.hasOwn(this, "type") && this.type === "Literal") {
|
|
204
|
+
if (Object.hasOwn(this, "bigint")) return BigInt(this.bigint);
|
|
205
|
+
if (Object.hasOwn(this, "regex")) {
|
|
206
|
+
const { regex } = this;
|
|
207
|
+
try {
|
|
208
|
+
return RegExp(regex.pattern, regex.flags);
|
|
209
|
+
} catch (_err) {}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return value;
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src/parse-ast-index.ts
|
|
218
|
+
function wrap(result, sourceText) {
|
|
219
|
+
result = wrap$1(result);
|
|
220
|
+
if (result.errors.length > 0) return normalizeParseError(sourceText, result.errors);
|
|
221
|
+
return result.program;
|
|
222
|
+
}
|
|
223
|
+
function normalizeParseError(sourceText, errors) {
|
|
224
|
+
let message = `Parse failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
|
|
225
|
+
for (let i = 0; i < errors.length; i++) {
|
|
226
|
+
if (i >= 5) {
|
|
227
|
+
message += "\n...";
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
const e = errors[i];
|
|
231
|
+
message += e.message + "\n" + e.labels.map((label) => {
|
|
232
|
+
const location = locate(sourceText, label.start, { offsetLine: 1 });
|
|
233
|
+
if (!location) return;
|
|
234
|
+
return getCodeFrame(sourceText, location.line, location.column);
|
|
235
|
+
}).filter(Boolean).join("\n");
|
|
236
|
+
}
|
|
237
|
+
return error(logParseError(message));
|
|
238
|
+
}
|
|
239
|
+
const defaultParserOptions = {
|
|
240
|
+
lang: "js",
|
|
241
|
+
preserveParens: false
|
|
242
|
+
};
|
|
243
|
+
function parseAst(sourceText, options, filename) {
|
|
244
|
+
return wrap((0, src_rolldown_binding_wasi_cjs.parseSync)(filename ?? "file.js", sourceText, {
|
|
245
|
+
...defaultParserOptions,
|
|
246
|
+
...options
|
|
247
|
+
}), sourceText);
|
|
248
|
+
}
|
|
249
|
+
async function parseAstAsync(sourceText, options, filename) {
|
|
250
|
+
return wrap(await (0, src_rolldown_binding_wasi_cjs.parseAsync)(filename ?? "file.js", sourceText, {
|
|
251
|
+
...defaultParserOptions,
|
|
252
|
+
...options
|
|
253
|
+
}), sourceText);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
//#endregion
|
|
257
|
+
Object.defineProperty(exports, 'augmentCodeLocation', {
|
|
258
|
+
enumerable: true,
|
|
259
|
+
get: function () {
|
|
260
|
+
return augmentCodeLocation;
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
Object.defineProperty(exports, 'error', {
|
|
264
|
+
enumerable: true,
|
|
265
|
+
get: function () {
|
|
266
|
+
return error;
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
Object.defineProperty(exports, 'logCycleLoading', {
|
|
270
|
+
enumerable: true,
|
|
271
|
+
get: function () {
|
|
272
|
+
return logCycleLoading;
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
Object.defineProperty(exports, 'logInputHookInOutputPlugin', {
|
|
276
|
+
enumerable: true,
|
|
277
|
+
get: function () {
|
|
278
|
+
return logInputHookInOutputPlugin;
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
Object.defineProperty(exports, 'logInvalidLogPosition', {
|
|
282
|
+
enumerable: true,
|
|
283
|
+
get: function () {
|
|
284
|
+
return logInvalidLogPosition;
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
Object.defineProperty(exports, 'logMinifyWarning', {
|
|
288
|
+
enumerable: true,
|
|
289
|
+
get: function () {
|
|
290
|
+
return logMinifyWarning;
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
Object.defineProperty(exports, 'logMultiplyNotifyOption', {
|
|
294
|
+
enumerable: true,
|
|
295
|
+
get: function () {
|
|
296
|
+
return logMultiplyNotifyOption;
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
Object.defineProperty(exports, 'logPluginError', {
|
|
300
|
+
enumerable: true,
|
|
301
|
+
get: function () {
|
|
302
|
+
return logPluginError;
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
Object.defineProperty(exports, 'parseAst', {
|
|
306
|
+
enumerable: true,
|
|
307
|
+
get: function () {
|
|
308
|
+
return parseAst;
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
Object.defineProperty(exports, 'parseAstAsync', {
|
|
312
|
+
enumerable: true,
|
|
313
|
+
get: function () {
|
|
314
|
+
return parseAstAsync;
|
|
315
|
+
}
|
|
316
|
+
});
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { __esm } from "./chunk-BuCFLigr.mjs";
|
|
2
|
+
import { parseAsync, parseSync } from "../rolldown-binding.wasi.cjs";
|
|
3
|
+
import colors from "ansis";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/code-frame.ts
|
|
6
|
+
function spaces(index) {
|
|
7
|
+
let result = "";
|
|
8
|
+
while (index--) result += " ";
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
function tabsToSpaces(value) {
|
|
12
|
+
return value.replace(/^\t+/, (match) => match.split(" ").join(" "));
|
|
13
|
+
}
|
|
14
|
+
function getCodeFrame(source, line, column) {
|
|
15
|
+
let lines = source.split("\n");
|
|
16
|
+
if (line > lines.length) return "";
|
|
17
|
+
const maxLineLength = Math.max(tabsToSpaces(lines[line - 1].slice(0, column)).length + MIN_CHARACTERS_SHOWN_AFTER_LOCATION + ELLIPSIS.length, LINE_TRUNCATE_LENGTH);
|
|
18
|
+
const frameStart = Math.max(0, line - 3);
|
|
19
|
+
let frameEnd = Math.min(line + 2, lines.length);
|
|
20
|
+
lines = lines.slice(frameStart, frameEnd);
|
|
21
|
+
while (!/\S/.test(lines[lines.length - 1])) {
|
|
22
|
+
lines.pop();
|
|
23
|
+
frameEnd -= 1;
|
|
24
|
+
}
|
|
25
|
+
const digits = String(frameEnd).length;
|
|
26
|
+
return lines.map((sourceLine, index) => {
|
|
27
|
+
const isErrorLine = frameStart + index + 1 === line;
|
|
28
|
+
let lineNumber = String(index + frameStart + 1);
|
|
29
|
+
while (lineNumber.length < digits) lineNumber = ` ${lineNumber}`;
|
|
30
|
+
let displayedLine = tabsToSpaces(sourceLine);
|
|
31
|
+
if (displayedLine.length > maxLineLength) displayedLine = `${displayedLine.slice(0, maxLineLength - ELLIPSIS.length)}${ELLIPSIS}`;
|
|
32
|
+
if (isErrorLine) {
|
|
33
|
+
const indicator = spaces(digits + 2 + tabsToSpaces(sourceLine.slice(0, column)).length) + "^";
|
|
34
|
+
return `${lineNumber}: ${displayedLine}\n${indicator}`;
|
|
35
|
+
}
|
|
36
|
+
return `${lineNumber}: ${displayedLine}`;
|
|
37
|
+
}).join("\n");
|
|
38
|
+
}
|
|
39
|
+
var LINE_TRUNCATE_LENGTH, MIN_CHARACTERS_SHOWN_AFTER_LOCATION, ELLIPSIS;
|
|
40
|
+
var init_code_frame = __esm({ "src/utils/code-frame.ts"() {
|
|
41
|
+
LINE_TRUNCATE_LENGTH = 120;
|
|
42
|
+
MIN_CHARACTERS_SHOWN_AFTER_LOCATION = 10;
|
|
43
|
+
ELLIPSIS = "...";
|
|
44
|
+
} });
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/log/locate-character/index.js
|
|
48
|
+
/** @typedef {import('./types').Location} Location */
|
|
49
|
+
/**
|
|
50
|
+
* @param {import('./types').Range} range
|
|
51
|
+
* @param {number} index
|
|
52
|
+
*/
|
|
53
|
+
function rangeContains(range, index) {
|
|
54
|
+
return range.start <= index && index < range.end;
|
|
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
|
+
function locate(source, search, options) {
|
|
94
|
+
return getLocator(source, options)(search, options && options.startIndex);
|
|
95
|
+
}
|
|
96
|
+
var init_locate_character = __esm({ "src/log/locate-character/index.js"() {} });
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/log/logs.ts
|
|
100
|
+
function logParseError(message) {
|
|
101
|
+
return {
|
|
102
|
+
code: PARSE_ERROR,
|
|
103
|
+
message
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function logMinifyWarning() {
|
|
107
|
+
return {
|
|
108
|
+
code: MINIFY_WARNING,
|
|
109
|
+
message: colors.yellow("The built-in minifier is still under development. Setting \"minify: true\" is not recommended for production use.")
|
|
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 logPluginError(error$1, plugin, { hook, id } = {}) {
|
|
137
|
+
const code = error$1.code;
|
|
138
|
+
if (!error$1.pluginCode && code != null && (typeof code !== "string" || !code.startsWith("PLUGIN_"))) error$1.pluginCode = code;
|
|
139
|
+
error$1.code = PLUGIN_ERROR;
|
|
140
|
+
error$1.plugin = plugin;
|
|
141
|
+
if (hook) error$1.hook = hook;
|
|
142
|
+
if (id) error$1.id = id;
|
|
143
|
+
return error$1;
|
|
144
|
+
}
|
|
145
|
+
function error(base) {
|
|
146
|
+
if (!(base instanceof Error)) {
|
|
147
|
+
base = Object.assign(new Error(base.message), base);
|
|
148
|
+
Object.defineProperty(base, "name", {
|
|
149
|
+
value: "RollupError",
|
|
150
|
+
writable: true
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
throw base;
|
|
154
|
+
}
|
|
155
|
+
function augmentCodeLocation(properties, pos, source, id) {
|
|
156
|
+
if (typeof pos === "object") {
|
|
157
|
+
const { line, column } = pos;
|
|
158
|
+
properties.loc = {
|
|
159
|
+
column,
|
|
160
|
+
file: id,
|
|
161
|
+
line
|
|
162
|
+
};
|
|
163
|
+
} else {
|
|
164
|
+
properties.pos = pos;
|
|
165
|
+
const location = locate(source, pos, { offsetLine: 1 });
|
|
166
|
+
if (!location) return;
|
|
167
|
+
const { line, column } = location;
|
|
168
|
+
properties.loc = {
|
|
169
|
+
column,
|
|
170
|
+
file: id,
|
|
171
|
+
line
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
if (properties.frame === void 0) {
|
|
175
|
+
const { line, column } = properties.loc;
|
|
176
|
+
properties.frame = getCodeFrame(source, line, column);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
var INVALID_LOG_POSITION, PLUGIN_ERROR, INPUT_HOOK_IN_OUTPUT_PLUGIN, CYCLE_LOADING, MULTIPLY_NOTIFY_OPTION, MINIFY_WARNING, PARSE_ERROR;
|
|
180
|
+
var init_logs = __esm({ "src/log/logs.ts"() {
|
|
181
|
+
init_code_frame();
|
|
182
|
+
init_locate_character();
|
|
183
|
+
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", MINIFY_WARNING = "MINIFY_WARNING", PARSE_ERROR = "PARSE_ERROR";
|
|
184
|
+
} });
|
|
185
|
+
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region ../../node_modules/.pnpm/oxc-parser@0.63.0/node_modules/oxc-parser/wrap.mjs
|
|
188
|
+
function wrap$1(result) {
|
|
189
|
+
let program, module, comments, errors;
|
|
190
|
+
return {
|
|
191
|
+
get program() {
|
|
192
|
+
if (!program) program = jsonParseAst(result.program);
|
|
193
|
+
return program;
|
|
194
|
+
},
|
|
195
|
+
get module() {
|
|
196
|
+
if (!module) module = result.module;
|
|
197
|
+
return module;
|
|
198
|
+
},
|
|
199
|
+
get comments() {
|
|
200
|
+
if (!comments) comments = result.comments;
|
|
201
|
+
return comments;
|
|
202
|
+
},
|
|
203
|
+
get errors() {
|
|
204
|
+
if (!errors) errors = result.errors;
|
|
205
|
+
return errors;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function jsonParseAst(ast) {
|
|
210
|
+
return JSON.parse(ast, function(key, value) {
|
|
211
|
+
if (value === null && key === "value" && Object.hasOwn(this, "type") && this.type === "Literal") {
|
|
212
|
+
if (Object.hasOwn(this, "bigint")) return BigInt(this.bigint);
|
|
213
|
+
if (Object.hasOwn(this, "regex")) {
|
|
214
|
+
const { regex } = this;
|
|
215
|
+
try {
|
|
216
|
+
return RegExp(regex.pattern, regex.flags);
|
|
217
|
+
} catch (_err) {}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return value;
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
var init_wrap = __esm({ "../../node_modules/.pnpm/oxc-parser@0.63.0/node_modules/oxc-parser/wrap.mjs"() {} });
|
|
224
|
+
|
|
225
|
+
//#endregion
|
|
226
|
+
//#region src/parse-ast-index.ts
|
|
227
|
+
function wrap(result, sourceText) {
|
|
228
|
+
result = wrap$1(result);
|
|
229
|
+
if (result.errors.length > 0) return normalizeParseError(sourceText, result.errors);
|
|
230
|
+
return result.program;
|
|
231
|
+
}
|
|
232
|
+
function normalizeParseError(sourceText, errors) {
|
|
233
|
+
let message = `Parse failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
|
|
234
|
+
for (let i = 0; i < errors.length; i++) {
|
|
235
|
+
if (i >= 5) {
|
|
236
|
+
message += "\n...";
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
const e = errors[i];
|
|
240
|
+
message += e.message + "\n" + e.labels.map((label) => {
|
|
241
|
+
const location = locate(sourceText, label.start, { offsetLine: 1 });
|
|
242
|
+
if (!location) return;
|
|
243
|
+
return getCodeFrame(sourceText, location.line, location.column);
|
|
244
|
+
}).filter(Boolean).join("\n");
|
|
245
|
+
}
|
|
246
|
+
return error(logParseError(message));
|
|
247
|
+
}
|
|
248
|
+
function parseAst(sourceText, options, filename) {
|
|
249
|
+
return wrap(parseSync(filename ?? "file.js", sourceText, {
|
|
250
|
+
...defaultParserOptions,
|
|
251
|
+
...options
|
|
252
|
+
}), sourceText);
|
|
253
|
+
}
|
|
254
|
+
async function parseAstAsync(sourceText, options, filename) {
|
|
255
|
+
return wrap(await parseAsync(filename ?? "file.js", sourceText, {
|
|
256
|
+
...defaultParserOptions,
|
|
257
|
+
...options
|
|
258
|
+
}), sourceText);
|
|
259
|
+
}
|
|
260
|
+
var defaultParserOptions;
|
|
261
|
+
var init_parse_ast_index = __esm({ "src/parse-ast-index.ts"() {
|
|
262
|
+
init_locate_character();
|
|
263
|
+
init_logs();
|
|
264
|
+
init_code_frame();
|
|
265
|
+
init_wrap();
|
|
266
|
+
defaultParserOptions = {
|
|
267
|
+
lang: "js",
|
|
268
|
+
preserveParens: false
|
|
269
|
+
};
|
|
270
|
+
} });
|
|
271
|
+
|
|
272
|
+
//#endregion
|
|
273
|
+
export { augmentCodeLocation, error, init_logs, init_parse_ast_index, logCycleLoading, logInputHookInOutputPlugin, logInvalidLogPosition, logMinifyWarning, logMultiplyNotifyOption, logPluginError, parseAst, parseAstAsync };
|