@rolldown/browser 1.0.0-beta.47 → 1.0.0-beta.48
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/dist/cli.mjs +22 -9
- package/dist/config.d.mts +3 -2
- package/dist/config.mjs +6 -4
- package/dist/constructors-EhfoQfqh.js +68 -0
- package/dist/experimental-index.browser.mjs +36 -106
- package/dist/experimental-index.d.mts +18 -58
- package/dist/experimental-index.mjs +39 -108
- package/dist/filter-index.d.mts +3 -2
- package/dist/filter-index.mjs +1 -1
- package/dist/index.browser.mjs +2 -1
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +5 -3
- package/dist/{shared/parse-ast-index-BiBzSGZe.mjs → normalize-string-or-regex-d47jXr3r.js} +38 -109
- package/dist/parallel-plugin-worker.mjs +5 -3
- package/dist/parallel-plugin.d.mts +3 -2
- package/dist/parse-ast-index.d.mts +1 -1
- package/dist/parse-ast-index.mjs +2 -1
- package/dist/plugins-index.browser.mjs +39 -0
- package/dist/plugins-index.d.mts +31 -0
- package/dist/plugins-index.mjs +40 -0
- package/dist/rolldown-binding.wasi-browser.js +1 -1
- package/dist/rolldown-binding.wasi.cjs +1 -1
- package/dist/rolldown-binding.wasm32-wasi.wasm +0 -0
- package/dist/shared/{binding-CRSqCQIK.d.mts → binding-B4uTNiw2.d.mts} +19 -49
- package/dist/shared/constructors-CaN9lKj2.d.mts +32 -0
- package/dist/shared/constructors-DcEzB0nc.mjs +68 -0
- package/dist/shared/{define-config-pfDd6Le4.d.mts → define-config-Dv3i4cxM.d.mts} +4 -62
- package/dist/shared/{load-config-D508WsWM.mjs → load-config-B-QIvCpC.mjs} +1 -1
- package/dist/shared/logs-CPsamAuj.mjs +181 -0
- package/dist/shared/normalize-string-or-regex-CbDij6KB.mjs +46 -0
- package/dist/shared/parse-ast-index-D9jH_38U.mjs +81 -0
- package/dist/shared/{prompt-BDwA3jSr.mjs → prompt-Ckjl2FdJ.mjs} +1 -1
- package/dist/shared/{src-DE7RBSfl.mjs → src-CvsuRKGv.mjs} +218 -191
- package/dist/shared/utils-CduIqa7h.d.mts +18 -0
- package/dist/{src-Deywlnh0.js → src-DLQqj5Wo.js} +203 -405
- package/package.json +1 -1
- /package/dist/shared/{composable-filters-D_PY7Qa7.mjs → composable-filters-CBpK2Fbc.mjs} +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { L as ParserOptions, M as JsxOptions, N as MinifyOptions$1, O as BindingWatcherEvent, R as PreRenderedChunk, V as TransformOptions$1,
|
|
1
|
+
import { D as BindingWatcherBundler, L as ParserOptions, M as JsxOptions, N as MinifyOptions$1, O as BindingWatcherEvent, R as PreRenderedChunk, V as TransformOptions$1, d as BindingMagicString, g as BindingRenderedChunk, k as ExternalMemoryStatus, s as BindingHookResolveIdExtraArgs, y as BindingTransformHookExtraArgs } from "./binding-B4uTNiw2.mjs";
|
|
2
|
+
import { a as NullValue, i as MaybePromise, n as MakeAsync, o as PartialNull, r as MaybeArray, s as StringOrRegExp, t as BuiltinPlugin } from "./utils-CduIqa7h.mjs";
|
|
2
3
|
import { Program } from "@oxc-project/types";
|
|
3
4
|
import { TopLevelFilterExpression } from "@rolldown/pluginutils";
|
|
4
5
|
|
|
@@ -179,14 +180,6 @@ interface RolldownOutput extends ExternalMemoryHandle {
|
|
|
179
180
|
output: [OutputChunk, ...(OutputChunk | OutputAsset)[]];
|
|
180
181
|
}
|
|
181
182
|
//#endregion
|
|
182
|
-
//#region src/types/utils.d.ts
|
|
183
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
184
|
-
type NullValue<T = void> = T | undefined | null | void;
|
|
185
|
-
type PartialNull<T> = { [P in keyof T]: T[P] | null };
|
|
186
|
-
type MakeAsync<Function_> = Function_ extends ((this: infer This, ...parameters: infer Arguments) => infer Return) ? (this: This, ...parameters: Arguments) => Return | Promise<Return> : never;
|
|
187
|
-
type MaybeArray<T> = T | T[];
|
|
188
|
-
type StringOrRegExp = string | RegExp;
|
|
189
|
-
//#endregion
|
|
190
183
|
//#region src/options/output-options.d.ts
|
|
191
184
|
type GeneratedCodePreset = "es5" | "es2015";
|
|
192
185
|
interface GeneratedCodeOptions {
|
|
@@ -650,7 +643,6 @@ declare class RolldownBuild {
|
|
|
650
643
|
static asyncRuntimeShutdown: boolean;
|
|
651
644
|
constructor(inputOptions: InputOptions);
|
|
652
645
|
get closed(): boolean;
|
|
653
|
-
scan(): Promise<void>;
|
|
654
646
|
generate(outputOptions?: OutputOptions): Promise<RolldownOutput>;
|
|
655
647
|
write(outputOptions?: OutputOptions): Promise<RolldownOutput>;
|
|
656
648
|
/**
|
|
@@ -672,7 +664,7 @@ interface WatchOptions extends InputOptions {
|
|
|
672
664
|
//#region src/api/watch/watch-emitter.d.ts
|
|
673
665
|
type WatcherEvent = "close" | "event" | "restart" | "change";
|
|
674
666
|
type ChangeEvent$1 = "create" | "update" | "delete";
|
|
675
|
-
type RolldownWatchBuild =
|
|
667
|
+
type RolldownWatchBuild = BindingWatcherBundler;
|
|
676
668
|
type RolldownWatcherEvent = {
|
|
677
669
|
code: "START";
|
|
678
670
|
} | {
|
|
@@ -992,13 +984,6 @@ type SourceMapInput = ExistingRawSourceMap | string | null;
|
|
|
992
984
|
//#region src/index.d.ts
|
|
993
985
|
declare const VERSION: string;
|
|
994
986
|
//#endregion
|
|
995
|
-
//#region src/builtin-plugin/utils.d.ts
|
|
996
|
-
declare class BuiltinPlugin {
|
|
997
|
-
name: BindingBuiltinPluginName;
|
|
998
|
-
_options?: unknown;
|
|
999
|
-
constructor(name: BindingBuiltinPluginName, _options?: unknown);
|
|
1000
|
-
}
|
|
1001
|
-
//#endregion
|
|
1002
987
|
//#region src/constants/plugin.d.ts
|
|
1003
988
|
declare const ENUMERATED_INPUT_PLUGIN_HOOK_NAMES: readonly ["options", "buildStart", "resolveId", "load", "transform", "moduleParsed", "buildEnd", "onLog", "resolveDynamicImport", "closeBundle", "closeWatcher", "watchChange"];
|
|
1004
989
|
declare const ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES: readonly ["augmentChunkHash", "outputOptions", "renderChunk", "renderStart", "renderError", "writeBundle", "generateBundle"];
|
|
@@ -1602,33 +1587,6 @@ interface InputOptions {
|
|
|
1602
1587
|
nativeMagicString?: boolean;
|
|
1603
1588
|
};
|
|
1604
1589
|
/**
|
|
1605
|
-
* Replace global variables or [property accessors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors) with the provided values.
|
|
1606
|
-
*
|
|
1607
|
-
* @deprecated Use `transform.define` instead. This top-level option will be removed in a future release.
|
|
1608
|
-
*
|
|
1609
|
-
* See `transform.define` for detailed documentation and examples.
|
|
1610
|
-
*/
|
|
1611
|
-
define?: Record<string, string>;
|
|
1612
|
-
/**
|
|
1613
|
-
* Inject import statements on demand.
|
|
1614
|
-
*
|
|
1615
|
-
* @deprecated Use `transform.inject` instead. This top-level option will be removed in a future release.
|
|
1616
|
-
*
|
|
1617
|
-
* See `transform.inject` for detailed documentation and examples.
|
|
1618
|
-
*/
|
|
1619
|
-
inject?: Record<string, string | [string, string]>;
|
|
1620
|
-
/**
|
|
1621
|
-
* Whether to add readable names to internal variables for profiling purposes.
|
|
1622
|
-
*
|
|
1623
|
-
* When enabled, generated code will use descriptive variable names that correspond
|
|
1624
|
-
* to the original module names, making it easier to profile and debug the bundled code.
|
|
1625
|
-
*
|
|
1626
|
-
* @default true when minification is disabled, false when minification is enabled
|
|
1627
|
-
*
|
|
1628
|
-
* @deprecated Use `output.generatedCode.profilerNames` instead. This top-level option will be removed in a future release.
|
|
1629
|
-
*/
|
|
1630
|
-
profilerNames?: boolean;
|
|
1631
|
-
/**
|
|
1632
1590
|
* Configure how the code is transformed. This process happens after the `transform` hook.
|
|
1633
1591
|
*
|
|
1634
1592
|
* To transpile [legacy decorators](https://github.com/tc39/proposal-decorators/tree/4ac0f4cd31bd0f2e8170cb4c5136e51671e46c8d), you could use
|
|
@@ -1647,22 +1605,6 @@ interface InputOptions {
|
|
|
1647
1605
|
*/
|
|
1648
1606
|
transform?: TransformOptions;
|
|
1649
1607
|
watch?: WatcherOptions | false;
|
|
1650
|
-
/**
|
|
1651
|
-
* Remove labeled statements with these label names.
|
|
1652
|
-
*
|
|
1653
|
-
* @deprecated Use `transform.dropLabels` instead. This top-level option will be removed in a future release.
|
|
1654
|
-
*
|
|
1655
|
-
* See `transform.dropLabels` for detailed documentation and examples.
|
|
1656
|
-
*/
|
|
1657
|
-
dropLabels?: string[];
|
|
1658
|
-
/**
|
|
1659
|
-
* Keep function and class names after bundling.
|
|
1660
|
-
*
|
|
1661
|
-
* @deprecated Use `output.keepNames` instead. This top-level option will be removed in a future release.
|
|
1662
|
-
*
|
|
1663
|
-
* See `output.keepNames` for detailed documentation.
|
|
1664
|
-
*/
|
|
1665
|
-
keepNames?: boolean;
|
|
1666
1608
|
checks?: ChecksOptions;
|
|
1667
1609
|
makeAbsoluteExternalsRelative?: MakeAbsoluteExternalsRelative;
|
|
1668
1610
|
debug?: {
|
|
@@ -1701,4 +1643,4 @@ declare function defineConfig(config: RolldownOptions[]): RolldownOptions[];
|
|
|
1701
1643
|
declare function defineConfig(config: RolldownOptionsFunction): RolldownOptionsFunction;
|
|
1702
1644
|
declare function defineConfig(config: ConfigExport): ConfigExport;
|
|
1703
1645
|
//#endregion
|
|
1704
|
-
export {
|
|
1646
|
+
export { NormalizedOutputOptions as $, VERSION as A, LogLevel as At, PluginContext as B, ResolveIdResult as C, RenderedChunk as Ct, SourceDescription as D, freeExternalMemory as Dt, RolldownPluginOption as E, SourceMap as Et, TreeshakingOptions as F, RollupLogWithString as Ft, GeneralHookFilter as G, defineParallelPlugin as H, TransformPluginContext as I, BufferEncoding as J, HookFilter as K, EmittedAsset as L, SourceMapInput as M, LogOrStringHandler as Mt, RolldownOptionsFunction as N, RollupError as Nt, TransformResult as O, ModuleInfo as Ot, OutputBundle as P, RollupLog as Pt, InternalModuleFormat as Q, EmittedFile as R, ResolveIdExtraOptions as S, OutputChunk as St, RolldownPlugin as T, RolldownOutput as Tt, MinimalPluginContext as U, DefineParallelPluginResult as V, PluginContextMeta as W, RolldownFileStats as X, RolldownDirectoryEntry as Y, RolldownFsModule as Z, ModuleType as _, MinifyOptions as _t, InputOption as a, RolldownWatcherEvent as at, PartialResolvedId as b, PreRenderedAsset as bt, OptimizationOptions as c, RolldownBuild as ct, CustomPluginOptions as d, AddonFunction as dt, NormalizedInputOptions as et, FunctionPluginHooks as f, ChunkFileNamesFunction as ft, ModuleOptions as g, GlobalsFunction as gt, LoadResult as h, GeneratedCodePreset as ht, ExternalOption as i, RolldownWatcher as it, ExistingRawSourceMap as j, LogLevelOption as jt, withFilter as k, SourcemapIgnoreListOption as kt, WatcherOptions as l, BuildOptions as lt, ImportKind as m, GeneratedCodeOptions as mt, ConfigExport as n, WarningHandlerWithDefault as nt, InputOptions as o, WatchOptions as ot, HookFilterExtension as p, ChunkingContext as pt, ModuleTypeFilter as q, RolldownOptions as r, watch as rt, ModuleTypes as s, rolldown as st, defineConfig as t, LoggingFunction as tt, AsyncPluginHooks as u, build as ut, ObjectHook as v, ModuleFormat as vt, ResolvedId as w, RenderedModule as wt, Plugin as x, OutputAsset as xt, ParallelPluginHooks as y, OutputOptions as yt, GetModuleInfo as z };
|
|
@@ -0,0 +1,181 @@
|
|
|
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$1) => {
|
|
57
|
+
const end = start + line.length + 1;
|
|
58
|
+
/** @type {import('./types').Range} */
|
|
59
|
+
const range = {
|
|
60
|
+
start,
|
|
61
|
+
end,
|
|
62
|
+
line: i$1
|
|
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) {
|
|
104
|
+
return {
|
|
105
|
+
code: PARSE_ERROR,
|
|
106
|
+
message
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function logInvalidLogPosition(pluginName) {
|
|
110
|
+
return {
|
|
111
|
+
code: INVALID_LOG_POSITION,
|
|
112
|
+
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.`
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function logInputHookInOutputPlugin(pluginName, hookName) {
|
|
116
|
+
return {
|
|
117
|
+
code: INPUT_HOOK_IN_OUTPUT_PLUGIN,
|
|
118
|
+
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.`
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function logCycleLoading(pluginName, moduleId) {
|
|
122
|
+
return {
|
|
123
|
+
code: CYCLE_LOADING,
|
|
124
|
+
message: `Found the module "${moduleId}" cycle loading at ${pluginName} plugin, it maybe blocking fetching modules.`
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function logMultiplyNotifyOption() {
|
|
128
|
+
return {
|
|
129
|
+
code: MULTIPLY_NOTIFY_OPTION,
|
|
130
|
+
message: `Found multiply notify option at watch options, using first one to start notify watcher.`
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function logPluginError(error$1, plugin, { hook, id } = {}) {
|
|
134
|
+
try {
|
|
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
|
+
} catch (_) {} finally {
|
|
142
|
+
return error$1;
|
|
143
|
+
}
|
|
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
|
+
|
|
180
|
+
//#endregion
|
|
181
|
+
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,46 @@
|
|
|
1
|
+
import { c as logPluginError, n as error } from "./logs-CPsamAuj.mjs";
|
|
2
|
+
import { BindingCallableBuiltinPlugin } from "../rolldown-binding.wasi.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/builtin-plugin/utils.ts
|
|
5
|
+
var BuiltinPlugin = class {
|
|
6
|
+
constructor(name, _options) {
|
|
7
|
+
this.name = name;
|
|
8
|
+
this._options = _options;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
function makeBuiltinPluginCallable(plugin) {
|
|
12
|
+
let callablePlugin = new BindingCallableBuiltinPlugin(bindingifyBuiltInPlugin(plugin));
|
|
13
|
+
const wrappedPlugin = plugin;
|
|
14
|
+
for (const key in callablePlugin) wrappedPlugin[key] = async function(...args) {
|
|
15
|
+
try {
|
|
16
|
+
return await callablePlugin[key](...args);
|
|
17
|
+
} catch (e) {
|
|
18
|
+
if (e instanceof Error && !e.stack?.includes("at ")) Error.captureStackTrace(e, wrappedPlugin[key]);
|
|
19
|
+
return error(logPluginError(e, plugin.name, {
|
|
20
|
+
hook: key,
|
|
21
|
+
id: key === "transform" ? args[2] : void 0
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
return wrappedPlugin;
|
|
26
|
+
}
|
|
27
|
+
function bindingifyBuiltInPlugin(plugin) {
|
|
28
|
+
return {
|
|
29
|
+
__name: plugin.name,
|
|
30
|
+
options: plugin._options
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/utils/normalize-string-or-regex.ts
|
|
36
|
+
function normalizedStringOrRegex(pattern) {
|
|
37
|
+
if (!pattern) return;
|
|
38
|
+
if (!isReadonlyArray(pattern)) return [pattern];
|
|
39
|
+
return pattern;
|
|
40
|
+
}
|
|
41
|
+
function isReadonlyArray(input) {
|
|
42
|
+
return Array.isArray(input);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { makeBuiltinPluginCallable as i, BuiltinPlugin as n, bindingifyBuiltInPlugin as r, normalizedStringOrRegex as t };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { l as locate, n as error, s as logParseError, u as getCodeFrame } from "./logs-CPsamAuj.mjs";
|
|
2
|
+
import { parseAsync, parseSync } from "../rolldown-binding.wasi.cjs";
|
|
3
|
+
|
|
4
|
+
//#region ../../node_modules/.pnpm/oxc-parser@0.96.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/parse-ast-index.ts
|
|
42
|
+
function wrap(result, sourceText) {
|
|
43
|
+
result = wrap$1(result);
|
|
44
|
+
if (result.errors.length > 0) return normalizeParseError(sourceText, result.errors);
|
|
45
|
+
return result.program;
|
|
46
|
+
}
|
|
47
|
+
function normalizeParseError(sourceText, errors) {
|
|
48
|
+
let message = `Parse failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
|
|
49
|
+
for (let i = 0; i < errors.length; i++) {
|
|
50
|
+
if (i >= 5) {
|
|
51
|
+
message += "\n...";
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
const e = errors[i];
|
|
55
|
+
message += e.message + "\n" + e.labels.map((label) => {
|
|
56
|
+
const location = locate(sourceText, label.start, { offsetLine: 1 });
|
|
57
|
+
if (!location) return;
|
|
58
|
+
return getCodeFrame(sourceText, location.line, location.column);
|
|
59
|
+
}).filter(Boolean).join("\n");
|
|
60
|
+
}
|
|
61
|
+
return error(logParseError(message));
|
|
62
|
+
}
|
|
63
|
+
const defaultParserOptions = {
|
|
64
|
+
lang: "js",
|
|
65
|
+
preserveParens: false
|
|
66
|
+
};
|
|
67
|
+
function parseAst(sourceText, options, filename) {
|
|
68
|
+
return wrap(parseSync(filename ?? "file.js", sourceText, {
|
|
69
|
+
...defaultParserOptions,
|
|
70
|
+
...options
|
|
71
|
+
}), sourceText);
|
|
72
|
+
}
|
|
73
|
+
async function parseAstAsync(sourceText, options, filename) {
|
|
74
|
+
return wrap(await parseAsync(filename ?? "file.js", sourceText, {
|
|
75
|
+
...defaultParserOptions,
|
|
76
|
+
...options
|
|
77
|
+
}), sourceText);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
export { parseAstAsync as n, parseAst as t };
|