@unified-latex/unified-latex 1.8.3 → 1.8.4
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/index.cjs +1545 -1085
- package/index.cjs.map +1 -1
- package/index.js +29 -13
- package/index.js.map +1 -1
- package/package.json +4 -4
package/index.cjs
CHANGED
|
@@ -1,311 +1,522 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
21
|
+
value: mod,
|
|
22
|
+
enumerable: true
|
|
23
|
+
}) : target, mod));
|
|
24
|
+
//#endregion
|
|
25
|
+
let _unified_latex_unified_latex_util_parse = require("@unified-latex/unified-latex-util-parse");
|
|
26
|
+
let _unified_latex_unified_latex_util_to_string = require("@unified-latex/unified-latex-util-to-string");
|
|
27
|
+
//#region ../../node_modules/bail/index.js
|
|
28
|
+
/**
|
|
29
|
+
* Throw a given error.
|
|
30
|
+
*
|
|
31
|
+
* @param {Error|null|undefined} [error]
|
|
32
|
+
* Maybe error.
|
|
33
|
+
* @returns {asserts error is null|undefined}
|
|
34
|
+
*/
|
|
5
35
|
function bail(error) {
|
|
6
|
-
|
|
7
|
-
throw error;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
function getDefaultExportFromCjs(x) {
|
|
11
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
12
|
-
}
|
|
13
|
-
/*!
|
|
14
|
-
* Determine if an object is a Buffer
|
|
15
|
-
*
|
|
16
|
-
* @author Feross Aboukhadijeh <https://feross.org>
|
|
17
|
-
* @license MIT
|
|
18
|
-
*/
|
|
19
|
-
var isBuffer$1;
|
|
20
|
-
var hasRequiredIsBuffer;
|
|
21
|
-
function requireIsBuffer() {
|
|
22
|
-
if (hasRequiredIsBuffer) return isBuffer$1;
|
|
23
|
-
hasRequiredIsBuffer = 1;
|
|
24
|
-
isBuffer$1 = function isBuffer2(obj) {
|
|
25
|
-
return obj != null && obj.constructor != null && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
|
|
26
|
-
};
|
|
27
|
-
return isBuffer$1;
|
|
36
|
+
if (error) throw error;
|
|
28
37
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
return target;
|
|
119
|
-
};
|
|
120
|
-
return extend$1;
|
|
121
|
-
}
|
|
122
|
-
var extendExports = requireExtend();
|
|
123
|
-
const extend = /* @__PURE__ */ getDefaultExportFromCjs(extendExports);
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region ../../node_modules/is-buffer/index.js
|
|
40
|
+
var require_is_buffer = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
41
|
+
/*!
|
|
42
|
+
* Determine if an object is a Buffer
|
|
43
|
+
*
|
|
44
|
+
* @author Feross Aboukhadijeh <https://feross.org>
|
|
45
|
+
* @license MIT
|
|
46
|
+
*/
|
|
47
|
+
module.exports = function isBuffer(obj) {
|
|
48
|
+
return obj != null && obj.constructor != null && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
|
|
49
|
+
};
|
|
50
|
+
}));
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region ../../node_modules/extend/index.js
|
|
53
|
+
var require_extend = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
54
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
55
|
+
var toStr = Object.prototype.toString;
|
|
56
|
+
var defineProperty = Object.defineProperty;
|
|
57
|
+
var gOPD = Object.getOwnPropertyDescriptor;
|
|
58
|
+
var isArray = function isArray(arr) {
|
|
59
|
+
if (typeof Array.isArray === "function") return Array.isArray(arr);
|
|
60
|
+
return toStr.call(arr) === "[object Array]";
|
|
61
|
+
};
|
|
62
|
+
var isPlainObject = function isPlainObject(obj) {
|
|
63
|
+
if (!obj || toStr.call(obj) !== "[object Object]") return false;
|
|
64
|
+
var hasOwnConstructor = hasOwn.call(obj, "constructor");
|
|
65
|
+
var hasIsPrototypeOf = obj.constructor && obj.constructor.prototype && hasOwn.call(obj.constructor.prototype, "isPrototypeOf");
|
|
66
|
+
if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) return false;
|
|
67
|
+
var key;
|
|
68
|
+
for (key in obj);
|
|
69
|
+
return typeof key === "undefined" || hasOwn.call(obj, key);
|
|
70
|
+
};
|
|
71
|
+
var setProperty = function setProperty(target, options) {
|
|
72
|
+
if (defineProperty && options.name === "__proto__") defineProperty(target, options.name, {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
value: options.newValue,
|
|
76
|
+
writable: true
|
|
77
|
+
});
|
|
78
|
+
else target[options.name] = options.newValue;
|
|
79
|
+
};
|
|
80
|
+
var getProperty = function getProperty(obj, name) {
|
|
81
|
+
if (name === "__proto__") {
|
|
82
|
+
if (!hasOwn.call(obj, name)) return;
|
|
83
|
+
else if (gOPD) return gOPD(obj, name).value;
|
|
84
|
+
}
|
|
85
|
+
return obj[name];
|
|
86
|
+
};
|
|
87
|
+
module.exports = function extend() {
|
|
88
|
+
var options, name, src, copy, copyIsArray, clone;
|
|
89
|
+
var target = arguments[0];
|
|
90
|
+
var i = 1;
|
|
91
|
+
var length = arguments.length;
|
|
92
|
+
var deep = false;
|
|
93
|
+
if (typeof target === "boolean") {
|
|
94
|
+
deep = target;
|
|
95
|
+
target = arguments[1] || {};
|
|
96
|
+
i = 2;
|
|
97
|
+
}
|
|
98
|
+
if (target == null || typeof target !== "object" && typeof target !== "function") target = {};
|
|
99
|
+
for (; i < length; ++i) {
|
|
100
|
+
options = arguments[i];
|
|
101
|
+
if (options != null) for (name in options) {
|
|
102
|
+
src = getProperty(target, name);
|
|
103
|
+
copy = getProperty(options, name);
|
|
104
|
+
if (target !== copy) {
|
|
105
|
+
if (deep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) {
|
|
106
|
+
if (copyIsArray) {
|
|
107
|
+
copyIsArray = false;
|
|
108
|
+
clone = src && isArray(src) ? src : [];
|
|
109
|
+
} else clone = src && isPlainObject(src) ? src : {};
|
|
110
|
+
setProperty(target, {
|
|
111
|
+
name,
|
|
112
|
+
newValue: extend(deep, clone, copy)
|
|
113
|
+
});
|
|
114
|
+
} else if (typeof copy !== "undefined") setProperty(target, {
|
|
115
|
+
name,
|
|
116
|
+
newValue: copy
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return target;
|
|
122
|
+
};
|
|
123
|
+
}));
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region node_modules/is-plain-obj/index.js
|
|
124
126
|
function isPlainObject(value) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const prototype = Object.getPrototypeOf(value);
|
|
129
|
-
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
127
|
+
if (typeof value !== "object" || value === null) return false;
|
|
128
|
+
const prototype = Object.getPrototypeOf(value);
|
|
129
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
130
130
|
}
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region ../../node_modules/trough/lib/index.js
|
|
133
|
+
/**
|
|
134
|
+
* @typedef {(error?: Error | null | undefined, ...output: Array<any>) => void} Callback
|
|
135
|
+
* Callback.
|
|
136
|
+
*
|
|
137
|
+
* @typedef {(...input: Array<any>) => any} Middleware
|
|
138
|
+
* Ware.
|
|
139
|
+
*
|
|
140
|
+
* @typedef Pipeline
|
|
141
|
+
* Pipeline.
|
|
142
|
+
* @property {Run} run
|
|
143
|
+
* Run the pipeline.
|
|
144
|
+
* @property {Use} use
|
|
145
|
+
* Add middleware.
|
|
146
|
+
*
|
|
147
|
+
* @typedef {(...input: Array<any>) => void} Run
|
|
148
|
+
* Call all middleware.
|
|
149
|
+
*
|
|
150
|
+
* Calls `done` on completion with either an error or the output of the
|
|
151
|
+
* last middleware.
|
|
152
|
+
*
|
|
153
|
+
* > 👉 **Note**: as the length of input defines whether async functions get a
|
|
154
|
+
* > `next` function,
|
|
155
|
+
* > it’s recommended to keep `input` at one value normally.
|
|
156
|
+
|
|
157
|
+
*
|
|
158
|
+
* @typedef {(fn: Middleware) => Pipeline} Use
|
|
159
|
+
* Add middleware.
|
|
160
|
+
*/
|
|
161
|
+
/**
|
|
162
|
+
* Create new middleware.
|
|
163
|
+
*
|
|
164
|
+
* @returns {Pipeline}
|
|
165
|
+
* Pipeline.
|
|
166
|
+
*/
|
|
131
167
|
function trough() {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
168
|
+
/** @type {Array<Middleware>} */
|
|
169
|
+
const fns = [];
|
|
170
|
+
/** @type {Pipeline} */
|
|
171
|
+
const pipeline = {
|
|
172
|
+
run,
|
|
173
|
+
use
|
|
174
|
+
};
|
|
175
|
+
return pipeline;
|
|
176
|
+
/** @type {Run} */
|
|
177
|
+
function run(...values) {
|
|
178
|
+
let middlewareIndex = -1;
|
|
179
|
+
/** @type {Callback} */
|
|
180
|
+
const callback = values.pop();
|
|
181
|
+
if (typeof callback !== "function") throw new TypeError("Expected function as last argument, not " + callback);
|
|
182
|
+
next(null, ...values);
|
|
183
|
+
/**
|
|
184
|
+
* Run the next `fn`, or we’re done.
|
|
185
|
+
*
|
|
186
|
+
* @param {Error | null | undefined} error
|
|
187
|
+
* @param {Array<any>} output
|
|
188
|
+
*/
|
|
189
|
+
function next(error, ...output) {
|
|
190
|
+
const fn = fns[++middlewareIndex];
|
|
191
|
+
let index = -1;
|
|
192
|
+
if (error) {
|
|
193
|
+
callback(error);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
while (++index < values.length) if (output[index] === null || output[index] === void 0) output[index] = values[index];
|
|
197
|
+
values = output;
|
|
198
|
+
if (fn) wrap(fn, next)(...output);
|
|
199
|
+
else callback(null, ...output);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/** @type {Use} */
|
|
203
|
+
function use(middelware) {
|
|
204
|
+
if (typeof middelware !== "function") throw new TypeError("Expected `middelware` to be a function, not " + middelware);
|
|
205
|
+
fns.push(middelware);
|
|
206
|
+
return pipeline;
|
|
207
|
+
}
|
|
171
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* Wrap `middleware` into a uniform interface.
|
|
211
|
+
*
|
|
212
|
+
* You can pass all input to the resulting function.
|
|
213
|
+
* `callback` is then called with the output of `middleware`.
|
|
214
|
+
*
|
|
215
|
+
* If `middleware` accepts more arguments than the later given in input,
|
|
216
|
+
* an extra `done` function is passed to it after that input,
|
|
217
|
+
* which must be called by `middleware`.
|
|
218
|
+
*
|
|
219
|
+
* The first value in `input` is the main input value.
|
|
220
|
+
* All other input values are the rest input values.
|
|
221
|
+
* The values given to `callback` are the input values,
|
|
222
|
+
* merged with every non-nullish output value.
|
|
223
|
+
*
|
|
224
|
+
* * if `middleware` throws an error,
|
|
225
|
+
* returns a promise that is rejected,
|
|
226
|
+
* or calls the given `done` function with an error,
|
|
227
|
+
* `callback` is called with that error
|
|
228
|
+
* * if `middleware` returns a value or returns a promise that is resolved,
|
|
229
|
+
* that value is the main output value
|
|
230
|
+
* * if `middleware` calls `done`,
|
|
231
|
+
* all non-nullish values except for the first one (the error) overwrite the
|
|
232
|
+
* output values
|
|
233
|
+
*
|
|
234
|
+
* @param {Middleware} middleware
|
|
235
|
+
* Function to wrap.
|
|
236
|
+
* @param {Callback} callback
|
|
237
|
+
* Callback called with the output of `middleware`.
|
|
238
|
+
* @returns {Run}
|
|
239
|
+
* Wrapped middleware.
|
|
240
|
+
*/
|
|
172
241
|
function wrap(middleware, callback) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
242
|
+
/** @type {boolean} */
|
|
243
|
+
let called;
|
|
244
|
+
return wrapped;
|
|
245
|
+
/**
|
|
246
|
+
* Call `middleware`.
|
|
247
|
+
* @this {any}
|
|
248
|
+
* @param {Array<any>} parameters
|
|
249
|
+
* @returns {void}
|
|
250
|
+
*/
|
|
251
|
+
function wrapped(...parameters) {
|
|
252
|
+
const fnExpectsCallback = middleware.length > parameters.length;
|
|
253
|
+
/** @type {any} */
|
|
254
|
+
let result;
|
|
255
|
+
if (fnExpectsCallback) parameters.push(done);
|
|
256
|
+
try {
|
|
257
|
+
result = middleware.apply(this, parameters);
|
|
258
|
+
} catch (error) {
|
|
259
|
+
const exception = error;
|
|
260
|
+
if (fnExpectsCallback && called) throw exception;
|
|
261
|
+
return done(exception);
|
|
262
|
+
}
|
|
263
|
+
if (!fnExpectsCallback) if (result && result.then && typeof result.then === "function") result.then(then, done);
|
|
264
|
+
else if (result instanceof Error) done(result);
|
|
265
|
+
else then(result);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Call `callback`, only once.
|
|
269
|
+
*
|
|
270
|
+
* @type {Callback}
|
|
271
|
+
*/
|
|
272
|
+
function done(error, ...output) {
|
|
273
|
+
if (!called) {
|
|
274
|
+
called = true;
|
|
275
|
+
callback(error, ...output);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Call `done` with one value.
|
|
280
|
+
*
|
|
281
|
+
* @param {any} [value]
|
|
282
|
+
*/
|
|
283
|
+
function then(value) {
|
|
284
|
+
done(null, value);
|
|
285
|
+
}
|
|
212
286
|
}
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region node_modules/unist-util-stringify-position/lib/index.js
|
|
289
|
+
/**
|
|
290
|
+
* @typedef {import('unist').Node} Node
|
|
291
|
+
* @typedef {import('unist').Point} Point
|
|
292
|
+
* @typedef {import('unist').Position} Position
|
|
293
|
+
*/
|
|
294
|
+
/**
|
|
295
|
+
* @typedef NodeLike
|
|
296
|
+
* @property {string} type
|
|
297
|
+
* @property {PositionLike | null | undefined} [position]
|
|
298
|
+
*
|
|
299
|
+
* @typedef PositionLike
|
|
300
|
+
* @property {PointLike | null | undefined} [start]
|
|
301
|
+
* @property {PointLike | null | undefined} [end]
|
|
302
|
+
*
|
|
303
|
+
* @typedef PointLike
|
|
304
|
+
* @property {number | null | undefined} [line]
|
|
305
|
+
* @property {number | null | undefined} [column]
|
|
306
|
+
* @property {number | null | undefined} [offset]
|
|
307
|
+
*/
|
|
308
|
+
/**
|
|
309
|
+
* Serialize the positional info of a point, position (start and end points),
|
|
310
|
+
* or node.
|
|
311
|
+
*
|
|
312
|
+
* @param {Node | NodeLike | Position | PositionLike | Point | PointLike | null | undefined} [value]
|
|
313
|
+
* Node, position, or point.
|
|
314
|
+
* @returns {string}
|
|
315
|
+
* Pretty printed positional info of a node (`string`).
|
|
316
|
+
*
|
|
317
|
+
* In the format of a range `ls:cs-le:ce` (when given `node` or `position`)
|
|
318
|
+
* or a point `l:c` (when given `point`), where `l` stands for line, `c` for
|
|
319
|
+
* column, `s` for `start`, and `e` for end.
|
|
320
|
+
* An empty string (`''`) is returned if the given value is neither `node`,
|
|
321
|
+
* `position`, nor `point`.
|
|
322
|
+
*/
|
|
213
323
|
function stringifyPosition(value) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
if ("start" in value || "end" in value) {
|
|
221
|
-
return position(value);
|
|
222
|
-
}
|
|
223
|
-
if ("line" in value || "column" in value) {
|
|
224
|
-
return point(value);
|
|
225
|
-
}
|
|
226
|
-
return "";
|
|
324
|
+
if (!value || typeof value !== "object") return "";
|
|
325
|
+
if ("position" in value || "type" in value) return position(value.position);
|
|
326
|
+
if ("start" in value || "end" in value) return position(value);
|
|
327
|
+
if ("line" in value || "column" in value) return point(value);
|
|
328
|
+
return "";
|
|
227
329
|
}
|
|
228
|
-
|
|
229
|
-
|
|
330
|
+
/**
|
|
331
|
+
* @param {Point | PointLike | null | undefined} point
|
|
332
|
+
* @returns {string}
|
|
333
|
+
*/
|
|
334
|
+
function point(point) {
|
|
335
|
+
return index(point && point.line) + ":" + index(point && point.column);
|
|
230
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* @param {Position | PositionLike | null | undefined} pos
|
|
339
|
+
* @returns {string}
|
|
340
|
+
*/
|
|
231
341
|
function position(pos) {
|
|
232
|
-
|
|
342
|
+
return point(pos && pos.start) + "-" + point(pos && pos.end);
|
|
233
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* @param {number | null | undefined} value
|
|
346
|
+
* @returns {number}
|
|
347
|
+
*/
|
|
234
348
|
function index(value) {
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
class VFileMessage extends Error {
|
|
238
|
-
/**
|
|
239
|
-
* Create a message for `reason` at `place` from `origin`.
|
|
240
|
-
*
|
|
241
|
-
* When an error is passed in as `reason`, the `stack` is copied.
|
|
242
|
-
*
|
|
243
|
-
* @param {string | Error | VFileMessage} reason
|
|
244
|
-
* Reason for message, uses the stack and message of the error if given.
|
|
245
|
-
*
|
|
246
|
-
* > 👉 **Note**: you should use markdown.
|
|
247
|
-
* @param {Node | NodeLike | Position | Point | null | undefined} [place]
|
|
248
|
-
* Place in file where the message occurred.
|
|
249
|
-
* @param {string | null | undefined} [origin]
|
|
250
|
-
* Place in code where the message originates (example:
|
|
251
|
-
* `'my-package:my-rule'` or `'my-rule'`).
|
|
252
|
-
* @returns
|
|
253
|
-
* Instance of `VFileMessage`.
|
|
254
|
-
*/
|
|
255
|
-
// To do: next major: expose `undefined` everywhere instead of `null`.
|
|
256
|
-
constructor(reason, place, origin) {
|
|
257
|
-
const parts = [null, null];
|
|
258
|
-
let position2 = {
|
|
259
|
-
// @ts-expect-error: we always follows the structure of `position`.
|
|
260
|
-
start: { line: null, column: null },
|
|
261
|
-
// @ts-expect-error: "
|
|
262
|
-
end: { line: null, column: null }
|
|
263
|
-
};
|
|
264
|
-
super();
|
|
265
|
-
if (typeof place === "string") {
|
|
266
|
-
origin = place;
|
|
267
|
-
place = void 0;
|
|
268
|
-
}
|
|
269
|
-
if (typeof origin === "string") {
|
|
270
|
-
const index2 = origin.indexOf(":");
|
|
271
|
-
if (index2 === -1) {
|
|
272
|
-
parts[1] = origin;
|
|
273
|
-
} else {
|
|
274
|
-
parts[0] = origin.slice(0, index2);
|
|
275
|
-
parts[1] = origin.slice(index2 + 1);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
if (place) {
|
|
279
|
-
if ("type" in place || "position" in place) {
|
|
280
|
-
if (place.position) {
|
|
281
|
-
position2 = place.position;
|
|
282
|
-
}
|
|
283
|
-
} else if ("start" in place || "end" in place) {
|
|
284
|
-
position2 = place;
|
|
285
|
-
} else if ("line" in place || "column" in place) {
|
|
286
|
-
position2.start = place;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
this.name = stringifyPosition(place) || "1:1";
|
|
290
|
-
this.message = typeof reason === "object" ? reason.message : reason;
|
|
291
|
-
this.stack = "";
|
|
292
|
-
if (typeof reason === "object" && reason.stack) {
|
|
293
|
-
this.stack = reason.stack;
|
|
294
|
-
}
|
|
295
|
-
this.reason = this.message;
|
|
296
|
-
this.fatal;
|
|
297
|
-
this.line = position2.start.line;
|
|
298
|
-
this.column = position2.start.column;
|
|
299
|
-
this.position = position2;
|
|
300
|
-
this.source = parts[0];
|
|
301
|
-
this.ruleId = parts[1];
|
|
302
|
-
this.file;
|
|
303
|
-
this.actual;
|
|
304
|
-
this.expected;
|
|
305
|
-
this.url;
|
|
306
|
-
this.note;
|
|
307
|
-
}
|
|
349
|
+
return value && typeof value === "number" ? value : 1;
|
|
308
350
|
}
|
|
351
|
+
//#endregion
|
|
352
|
+
//#region node_modules/vfile-message/lib/index.js
|
|
353
|
+
/**
|
|
354
|
+
* @typedef {import('unist').Node} Node
|
|
355
|
+
* @typedef {import('unist').Position} Position
|
|
356
|
+
* @typedef {import('unist').Point} Point
|
|
357
|
+
* @typedef {object & {type: string, position?: Position | undefined}} NodeLike
|
|
358
|
+
*/
|
|
359
|
+
/**
|
|
360
|
+
* Message.
|
|
361
|
+
*/
|
|
362
|
+
var VFileMessage = class extends Error {
|
|
363
|
+
/**
|
|
364
|
+
* Create a message for `reason` at `place` from `origin`.
|
|
365
|
+
*
|
|
366
|
+
* When an error is passed in as `reason`, the `stack` is copied.
|
|
367
|
+
*
|
|
368
|
+
* @param {string | Error | VFileMessage} reason
|
|
369
|
+
* Reason for message, uses the stack and message of the error if given.
|
|
370
|
+
*
|
|
371
|
+
* > 👉 **Note**: you should use markdown.
|
|
372
|
+
* @param {Node | NodeLike | Position | Point | null | undefined} [place]
|
|
373
|
+
* Place in file where the message occurred.
|
|
374
|
+
* @param {string | null | undefined} [origin]
|
|
375
|
+
* Place in code where the message originates (example:
|
|
376
|
+
* `'my-package:my-rule'` or `'my-rule'`).
|
|
377
|
+
* @returns
|
|
378
|
+
* Instance of `VFileMessage`.
|
|
379
|
+
*/
|
|
380
|
+
constructor(reason, place, origin) {
|
|
381
|
+
/** @type {[string | null, string | null]} */
|
|
382
|
+
const parts = [null, null];
|
|
383
|
+
/** @type {Position} */
|
|
384
|
+
let position = {
|
|
385
|
+
start: {
|
|
386
|
+
line: null,
|
|
387
|
+
column: null
|
|
388
|
+
},
|
|
389
|
+
end: {
|
|
390
|
+
line: null,
|
|
391
|
+
column: null
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
super();
|
|
395
|
+
if (typeof place === "string") {
|
|
396
|
+
origin = place;
|
|
397
|
+
place = void 0;
|
|
398
|
+
}
|
|
399
|
+
if (typeof origin === "string") {
|
|
400
|
+
const index = origin.indexOf(":");
|
|
401
|
+
if (index === -1) parts[1] = origin;
|
|
402
|
+
else {
|
|
403
|
+
parts[0] = origin.slice(0, index);
|
|
404
|
+
parts[1] = origin.slice(index + 1);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
if (place) {
|
|
408
|
+
if ("type" in place || "position" in place) {
|
|
409
|
+
if (place.position) position = place.position;
|
|
410
|
+
} else if ("start" in place || "end" in place) position = place;
|
|
411
|
+
else if ("line" in place || "column" in place) position.start = place;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Serialized positional info of error.
|
|
415
|
+
*
|
|
416
|
+
* On normal errors, this would be something like `ParseError`, buit in
|
|
417
|
+
* `VFile` messages we use this space to show where an error happened.
|
|
418
|
+
*/
|
|
419
|
+
this.name = stringifyPosition(place) || "1:1";
|
|
420
|
+
/**
|
|
421
|
+
* Reason for message.
|
|
422
|
+
*
|
|
423
|
+
* @type {string}
|
|
424
|
+
*/
|
|
425
|
+
this.message = typeof reason === "object" ? reason.message : reason;
|
|
426
|
+
/**
|
|
427
|
+
* Stack of message.
|
|
428
|
+
*
|
|
429
|
+
* This is used by normal errors to show where something happened in
|
|
430
|
+
* programming code, irrelevant for `VFile` messages,
|
|
431
|
+
*
|
|
432
|
+
* @type {string}
|
|
433
|
+
*/
|
|
434
|
+
this.stack = "";
|
|
435
|
+
if (typeof reason === "object" && reason.stack) this.stack = reason.stack;
|
|
436
|
+
/**
|
|
437
|
+
* Reason for message.
|
|
438
|
+
*
|
|
439
|
+
* > 👉 **Note**: you should use markdown.
|
|
440
|
+
*
|
|
441
|
+
* @type {string}
|
|
442
|
+
*/
|
|
443
|
+
this.reason = this.message;
|
|
444
|
+
/**
|
|
445
|
+
* State of problem.
|
|
446
|
+
*
|
|
447
|
+
* * `true` — marks associated file as no longer processable (error)
|
|
448
|
+
* * `false` — necessitates a (potential) change (warning)
|
|
449
|
+
* * `null | undefined` — for things that might not need changing (info)
|
|
450
|
+
*
|
|
451
|
+
* @type {boolean | null | undefined}
|
|
452
|
+
*/
|
|
453
|
+
this.fatal;
|
|
454
|
+
/**
|
|
455
|
+
* Starting line of error.
|
|
456
|
+
*
|
|
457
|
+
* @type {number | null}
|
|
458
|
+
*/
|
|
459
|
+
this.line = position.start.line;
|
|
460
|
+
/**
|
|
461
|
+
* Starting column of error.
|
|
462
|
+
*
|
|
463
|
+
* @type {number | null}
|
|
464
|
+
*/
|
|
465
|
+
this.column = position.start.column;
|
|
466
|
+
/**
|
|
467
|
+
* Full unist position.
|
|
468
|
+
*
|
|
469
|
+
* @type {Position | null}
|
|
470
|
+
*/
|
|
471
|
+
this.position = position;
|
|
472
|
+
/**
|
|
473
|
+
* Namespace of message (example: `'my-package'`).
|
|
474
|
+
*
|
|
475
|
+
* @type {string | null}
|
|
476
|
+
*/
|
|
477
|
+
this.source = parts[0];
|
|
478
|
+
/**
|
|
479
|
+
* Category of message (example: `'my-rule'`).
|
|
480
|
+
*
|
|
481
|
+
* @type {string | null}
|
|
482
|
+
*/
|
|
483
|
+
this.ruleId = parts[1];
|
|
484
|
+
/**
|
|
485
|
+
* Path of a file (used throughout the `VFile` ecosystem).
|
|
486
|
+
*
|
|
487
|
+
* @type {string | null}
|
|
488
|
+
*/
|
|
489
|
+
this.file;
|
|
490
|
+
/**
|
|
491
|
+
* Specify the source value that’s being reported, which is deemed
|
|
492
|
+
* incorrect.
|
|
493
|
+
*
|
|
494
|
+
* @type {string | null}
|
|
495
|
+
*/
|
|
496
|
+
this.actual;
|
|
497
|
+
/**
|
|
498
|
+
* Suggest acceptable values that can be used instead of `actual`.
|
|
499
|
+
*
|
|
500
|
+
* @type {Array<string> | null}
|
|
501
|
+
*/
|
|
502
|
+
this.expected;
|
|
503
|
+
/**
|
|
504
|
+
* Link to docs for the message.
|
|
505
|
+
*
|
|
506
|
+
* > 👉 **Note**: this must be an absolute URL that can be passed as `x`
|
|
507
|
+
* > to `new URL(x)`.
|
|
508
|
+
*
|
|
509
|
+
* @type {string | null}
|
|
510
|
+
*/
|
|
511
|
+
this.url;
|
|
512
|
+
/**
|
|
513
|
+
* Long form description of the message (you should use markdown).
|
|
514
|
+
*
|
|
515
|
+
* @type {string | null}
|
|
516
|
+
*/
|
|
517
|
+
this.note;
|
|
518
|
+
}
|
|
519
|
+
};
|
|
309
520
|
VFileMessage.prototype.file = "";
|
|
310
521
|
VFileMessage.prototype.name = "";
|
|
311
522
|
VFileMessage.prototype.reason = "";
|
|
@@ -317,844 +528,1093 @@ VFileMessage.prototype.line = null;
|
|
|
317
528
|
VFileMessage.prototype.source = null;
|
|
318
529
|
VFileMessage.prototype.ruleId = null;
|
|
319
530
|
VFileMessage.prototype.position = null;
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
531
|
+
//#endregion
|
|
532
|
+
//#region node_modules/vfile/lib/minpath.browser.js
|
|
533
|
+
var path = {
|
|
534
|
+
basename,
|
|
535
|
+
dirname,
|
|
536
|
+
extname,
|
|
537
|
+
join,
|
|
538
|
+
sep: "/"
|
|
539
|
+
};
|
|
540
|
+
/**
|
|
541
|
+
* Get the basename from a path.
|
|
542
|
+
*
|
|
543
|
+
* @param {string} path
|
|
544
|
+
* File path.
|
|
545
|
+
* @param {string | undefined} [ext]
|
|
546
|
+
* Extension to strip.
|
|
547
|
+
* @returns {string}
|
|
548
|
+
* Stem or basename.
|
|
549
|
+
*/
|
|
550
|
+
function basename(path, ext) {
|
|
551
|
+
if (ext !== void 0 && typeof ext !== "string") throw new TypeError("\"ext\" argument must be a string");
|
|
552
|
+
assertPath$1(path);
|
|
553
|
+
let start = 0;
|
|
554
|
+
let end = -1;
|
|
555
|
+
let index = path.length;
|
|
556
|
+
/** @type {boolean | undefined} */
|
|
557
|
+
let seenNonSlash;
|
|
558
|
+
if (ext === void 0 || ext.length === 0 || ext.length > path.length) {
|
|
559
|
+
while (index--) if (path.charCodeAt(index) === 47) {
|
|
560
|
+
if (seenNonSlash) {
|
|
561
|
+
start = index + 1;
|
|
562
|
+
break;
|
|
563
|
+
}
|
|
564
|
+
} else if (end < 0) {
|
|
565
|
+
seenNonSlash = true;
|
|
566
|
+
end = index + 1;
|
|
567
|
+
}
|
|
568
|
+
return end < 0 ? "" : path.slice(start, end);
|
|
569
|
+
}
|
|
570
|
+
if (ext === path) return "";
|
|
571
|
+
let firstNonSlashEnd = -1;
|
|
572
|
+
let extIndex = ext.length - 1;
|
|
573
|
+
while (index--) if (path.charCodeAt(index) === 47) {
|
|
574
|
+
if (seenNonSlash) {
|
|
575
|
+
start = index + 1;
|
|
576
|
+
break;
|
|
577
|
+
}
|
|
578
|
+
} else {
|
|
579
|
+
if (firstNonSlashEnd < 0) {
|
|
580
|
+
seenNonSlash = true;
|
|
581
|
+
firstNonSlashEnd = index + 1;
|
|
582
|
+
}
|
|
583
|
+
if (extIndex > -1) if (path.charCodeAt(index) === ext.charCodeAt(extIndex--)) {
|
|
584
|
+
if (extIndex < 0) end = index;
|
|
585
|
+
} else {
|
|
586
|
+
extIndex = -1;
|
|
587
|
+
end = firstNonSlashEnd;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
if (start === end) end = firstNonSlashEnd;
|
|
591
|
+
else if (end < 0) end = path.length;
|
|
592
|
+
return path.slice(start, end);
|
|
378
593
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
594
|
+
/**
|
|
595
|
+
* Get the dirname from a path.
|
|
596
|
+
*
|
|
597
|
+
* @param {string} path
|
|
598
|
+
* File path.
|
|
599
|
+
* @returns {string}
|
|
600
|
+
* File path.
|
|
601
|
+
*/
|
|
602
|
+
function dirname(path) {
|
|
603
|
+
assertPath$1(path);
|
|
604
|
+
if (path.length === 0) return ".";
|
|
605
|
+
let end = -1;
|
|
606
|
+
let index = path.length;
|
|
607
|
+
/** @type {boolean | undefined} */
|
|
608
|
+
let unmatchedSlash;
|
|
609
|
+
while (--index) if (path.charCodeAt(index) === 47) {
|
|
610
|
+
if (unmatchedSlash) {
|
|
611
|
+
end = index;
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
} else if (!unmatchedSlash) unmatchedSlash = true;
|
|
615
|
+
return end < 0 ? path.charCodeAt(0) === 47 ? "/" : "." : end === 1 && path.charCodeAt(0) === 47 ? "//" : path.slice(0, end);
|
|
398
616
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
617
|
+
/**
|
|
618
|
+
* Get an extname from a path.
|
|
619
|
+
*
|
|
620
|
+
* @param {string} path
|
|
621
|
+
* File path.
|
|
622
|
+
* @returns {string}
|
|
623
|
+
* Extname.
|
|
624
|
+
*/
|
|
625
|
+
function extname(path) {
|
|
626
|
+
assertPath$1(path);
|
|
627
|
+
let index = path.length;
|
|
628
|
+
let end = -1;
|
|
629
|
+
let startPart = 0;
|
|
630
|
+
let startDot = -1;
|
|
631
|
+
let preDotState = 0;
|
|
632
|
+
/** @type {boolean | undefined} */
|
|
633
|
+
let unmatchedSlash;
|
|
634
|
+
while (index--) {
|
|
635
|
+
const code = path.charCodeAt(index);
|
|
636
|
+
if (code === 47) {
|
|
637
|
+
if (unmatchedSlash) {
|
|
638
|
+
startPart = index + 1;
|
|
639
|
+
break;
|
|
640
|
+
}
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
if (end < 0) {
|
|
644
|
+
unmatchedSlash = true;
|
|
645
|
+
end = index + 1;
|
|
646
|
+
}
|
|
647
|
+
if (code === 46) {
|
|
648
|
+
if (startDot < 0) startDot = index;
|
|
649
|
+
else if (preDotState !== 1) preDotState = 1;
|
|
650
|
+
} else if (startDot > -1) preDotState = -1;
|
|
651
|
+
}
|
|
652
|
+
if (startDot < 0 || end < 0 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) return "";
|
|
653
|
+
return path.slice(startDot, end);
|
|
436
654
|
}
|
|
655
|
+
/**
|
|
656
|
+
* Join segments from a path.
|
|
657
|
+
*
|
|
658
|
+
* @param {Array<string>} segments
|
|
659
|
+
* Path segments.
|
|
660
|
+
* @returns {string}
|
|
661
|
+
* File path.
|
|
662
|
+
*/
|
|
437
663
|
function join(...segments) {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
return joined === void 0 ? "." : normalize(joined);
|
|
664
|
+
let index = -1;
|
|
665
|
+
/** @type {string | undefined} */
|
|
666
|
+
let joined;
|
|
667
|
+
while (++index < segments.length) {
|
|
668
|
+
assertPath$1(segments[index]);
|
|
669
|
+
if (segments[index]) joined = joined === void 0 ? segments[index] : joined + "/" + segments[index];
|
|
670
|
+
}
|
|
671
|
+
return joined === void 0 ? "." : normalize(joined);
|
|
447
672
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
673
|
+
/**
|
|
674
|
+
* Normalize a basic file path.
|
|
675
|
+
*
|
|
676
|
+
* @param {string} path
|
|
677
|
+
* File path.
|
|
678
|
+
* @returns {string}
|
|
679
|
+
* File path.
|
|
680
|
+
*/
|
|
681
|
+
function normalize(path) {
|
|
682
|
+
assertPath$1(path);
|
|
683
|
+
const absolute = path.charCodeAt(0) === 47;
|
|
684
|
+
let value = normalizeString(path, !absolute);
|
|
685
|
+
if (value.length === 0 && !absolute) value = ".";
|
|
686
|
+
if (value.length > 0 && path.charCodeAt(path.length - 1) === 47) value += "/";
|
|
687
|
+
return absolute ? "/" + value : value;
|
|
459
688
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
689
|
+
/**
|
|
690
|
+
* Resolve `.` and `..` elements in a path with directory names.
|
|
691
|
+
*
|
|
692
|
+
* @param {string} path
|
|
693
|
+
* File path.
|
|
694
|
+
* @param {boolean} allowAboveRoot
|
|
695
|
+
* Whether `..` can move above root.
|
|
696
|
+
* @returns {string}
|
|
697
|
+
* File path.
|
|
698
|
+
*/
|
|
699
|
+
function normalizeString(path, allowAboveRoot) {
|
|
700
|
+
let result = "";
|
|
701
|
+
let lastSegmentLength = 0;
|
|
702
|
+
let lastSlash = -1;
|
|
703
|
+
let dots = 0;
|
|
704
|
+
let index = -1;
|
|
705
|
+
/** @type {number | undefined} */
|
|
706
|
+
let code;
|
|
707
|
+
/** @type {number} */
|
|
708
|
+
let lastSlashIndex;
|
|
709
|
+
while (++index <= path.length) {
|
|
710
|
+
if (index < path.length) code = path.charCodeAt(index);
|
|
711
|
+
else if (code === 47) break;
|
|
712
|
+
else code = 47;
|
|
713
|
+
if (code === 47) {
|
|
714
|
+
if (lastSlash === index - 1 || dots === 1) {} else if (lastSlash !== index - 1 && dots === 2) {
|
|
715
|
+
if (result.length < 2 || lastSegmentLength !== 2 || result.charCodeAt(result.length - 1) !== 46 || result.charCodeAt(result.length - 2) !== 46) {
|
|
716
|
+
if (result.length > 2) {
|
|
717
|
+
lastSlashIndex = result.lastIndexOf("/");
|
|
718
|
+
if (lastSlashIndex !== result.length - 1) {
|
|
719
|
+
if (lastSlashIndex < 0) {
|
|
720
|
+
result = "";
|
|
721
|
+
lastSegmentLength = 0;
|
|
722
|
+
} else {
|
|
723
|
+
result = result.slice(0, lastSlashIndex);
|
|
724
|
+
lastSegmentLength = result.length - 1 - result.lastIndexOf("/");
|
|
725
|
+
}
|
|
726
|
+
lastSlash = index;
|
|
727
|
+
dots = 0;
|
|
728
|
+
continue;
|
|
729
|
+
}
|
|
730
|
+
} else if (result.length > 0) {
|
|
731
|
+
result = "";
|
|
732
|
+
lastSegmentLength = 0;
|
|
733
|
+
lastSlash = index;
|
|
734
|
+
dots = 0;
|
|
735
|
+
continue;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
if (allowAboveRoot) {
|
|
739
|
+
result = result.length > 0 ? result + "/.." : "..";
|
|
740
|
+
lastSegmentLength = 2;
|
|
741
|
+
}
|
|
742
|
+
} else {
|
|
743
|
+
if (result.length > 0) result += "/" + path.slice(lastSlash + 1, index);
|
|
744
|
+
else result = path.slice(lastSlash + 1, index);
|
|
745
|
+
lastSegmentLength = index - lastSlash - 1;
|
|
746
|
+
}
|
|
747
|
+
lastSlash = index;
|
|
748
|
+
dots = 0;
|
|
749
|
+
} else if (code === 46 && dots > -1) dots++;
|
|
750
|
+
else dots = -1;
|
|
751
|
+
}
|
|
752
|
+
return result;
|
|
523
753
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
754
|
+
/**
|
|
755
|
+
* Make sure `path` is a string.
|
|
756
|
+
*
|
|
757
|
+
* @param {string} path
|
|
758
|
+
* File path.
|
|
759
|
+
* @returns {asserts path is string}
|
|
760
|
+
* Nothing.
|
|
761
|
+
*/
|
|
762
|
+
function assertPath$1(path) {
|
|
763
|
+
if (typeof path !== "string") throw new TypeError("Path must be a string. Received " + JSON.stringify(path));
|
|
530
764
|
}
|
|
531
|
-
|
|
765
|
+
//#endregion
|
|
766
|
+
//#region node_modules/vfile/lib/minproc.browser.js
|
|
767
|
+
var proc = { cwd };
|
|
532
768
|
function cwd() {
|
|
533
|
-
|
|
769
|
+
return "/";
|
|
534
770
|
}
|
|
771
|
+
//#endregion
|
|
772
|
+
//#region node_modules/vfile/lib/minurl.shared.js
|
|
773
|
+
/**
|
|
774
|
+
* @typedef URL
|
|
775
|
+
* @property {string} hash
|
|
776
|
+
* @property {string} host
|
|
777
|
+
* @property {string} hostname
|
|
778
|
+
* @property {string} href
|
|
779
|
+
* @property {string} origin
|
|
780
|
+
* @property {string} password
|
|
781
|
+
* @property {string} pathname
|
|
782
|
+
* @property {string} port
|
|
783
|
+
* @property {string} protocol
|
|
784
|
+
* @property {string} search
|
|
785
|
+
* @property {any} searchParams
|
|
786
|
+
* @property {string} username
|
|
787
|
+
* @property {() => string} toString
|
|
788
|
+
* @property {() => string} toJSON
|
|
789
|
+
*/
|
|
790
|
+
/**
|
|
791
|
+
* Check if `fileUrlOrPath` looks like a URL.
|
|
792
|
+
*
|
|
793
|
+
* @param {unknown} fileUrlOrPath
|
|
794
|
+
* File path or URL.
|
|
795
|
+
* @returns {fileUrlOrPath is URL}
|
|
796
|
+
* Whether it’s a URL.
|
|
797
|
+
*/
|
|
535
798
|
function isUrl(fileUrlOrPath) {
|
|
536
|
-
|
|
537
|
-
fileUrlOrPath.href && // @ts-expect-error: indexable.
|
|
538
|
-
fileUrlOrPath.origin;
|
|
799
|
+
return fileUrlOrPath !== null && typeof fileUrlOrPath === "object" && fileUrlOrPath.href && fileUrlOrPath.origin;
|
|
539
800
|
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
801
|
+
//#endregion
|
|
802
|
+
//#region node_modules/vfile/lib/minurl.browser.js
|
|
803
|
+
/**
|
|
804
|
+
* @param {string | URL} path
|
|
805
|
+
* File URL.
|
|
806
|
+
* @returns {string}
|
|
807
|
+
* File URL.
|
|
808
|
+
*/
|
|
809
|
+
function urlToPath(path) {
|
|
810
|
+
if (typeof path === "string") path = new URL(path);
|
|
811
|
+
else if (!isUrl(path)) {
|
|
812
|
+
/** @type {NodeJS.ErrnoException} */
|
|
813
|
+
const error = /* @__PURE__ */ new TypeError("The \"path\" argument must be of type string or an instance of URL. Received `" + path + "`");
|
|
814
|
+
error.code = "ERR_INVALID_ARG_TYPE";
|
|
815
|
+
throw error;
|
|
816
|
+
}
|
|
817
|
+
if (path.protocol !== "file:") {
|
|
818
|
+
/** @type {NodeJS.ErrnoException} */
|
|
819
|
+
const error = /* @__PURE__ */ new TypeError("The URL must be of scheme file");
|
|
820
|
+
error.code = "ERR_INVALID_URL_SCHEME";
|
|
821
|
+
throw error;
|
|
822
|
+
}
|
|
823
|
+
return getPathFromURLPosix(path);
|
|
556
824
|
}
|
|
825
|
+
/**
|
|
826
|
+
* Get a path from a POSIX URL.
|
|
827
|
+
*
|
|
828
|
+
* @param {URL} url
|
|
829
|
+
* URL.
|
|
830
|
+
* @returns {string}
|
|
831
|
+
* File path.
|
|
832
|
+
*/
|
|
557
833
|
function getPathFromURLPosix(url) {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
return decodeURIComponent(pathname);
|
|
580
|
-
}
|
|
581
|
-
const order = ["history", "path", "basename", "stem", "extname", "dirname"];
|
|
582
|
-
class VFile {
|
|
583
|
-
/**
|
|
584
|
-
* Create a new virtual file.
|
|
585
|
-
*
|
|
586
|
-
* `options` is treated as:
|
|
587
|
-
*
|
|
588
|
-
* * `string` or `Buffer` — `{value: options}`
|
|
589
|
-
* * `URL` — `{path: options}`
|
|
590
|
-
* * `VFile` — shallow copies its data over to the new file
|
|
591
|
-
* * `object` — all fields are shallow copied over to the new file
|
|
592
|
-
*
|
|
593
|
-
* Path related fields are set in the following order (least specific to
|
|
594
|
-
* most specific): `history`, `path`, `basename`, `stem`, `extname`,
|
|
595
|
-
* `dirname`.
|
|
596
|
-
*
|
|
597
|
-
* You cannot set `dirname` or `extname` without setting either `history`,
|
|
598
|
-
* `path`, `basename`, or `stem` too.
|
|
599
|
-
*
|
|
600
|
-
* @param {Compatible | null | undefined} [value]
|
|
601
|
-
* File value.
|
|
602
|
-
* @returns
|
|
603
|
-
* New instance.
|
|
604
|
-
*/
|
|
605
|
-
constructor(value) {
|
|
606
|
-
let options;
|
|
607
|
-
if (!value) {
|
|
608
|
-
options = {};
|
|
609
|
-
} else if (typeof value === "string" || buffer(value)) {
|
|
610
|
-
options = { value };
|
|
611
|
-
} else if (isUrl(value)) {
|
|
612
|
-
options = { path: value };
|
|
613
|
-
} else {
|
|
614
|
-
options = value;
|
|
615
|
-
}
|
|
616
|
-
this.data = {};
|
|
617
|
-
this.messages = [];
|
|
618
|
-
this.history = [];
|
|
619
|
-
this.cwd = proc.cwd();
|
|
620
|
-
this.value;
|
|
621
|
-
this.stored;
|
|
622
|
-
this.result;
|
|
623
|
-
this.map;
|
|
624
|
-
let index2 = -1;
|
|
625
|
-
while (++index2 < order.length) {
|
|
626
|
-
const prop2 = order[index2];
|
|
627
|
-
if (prop2 in options && options[prop2] !== void 0 && options[prop2] !== null) {
|
|
628
|
-
this[prop2] = prop2 === "history" ? [...options[prop2]] : options[prop2];
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
let prop;
|
|
632
|
-
for (prop in options) {
|
|
633
|
-
if (!order.includes(prop)) {
|
|
634
|
-
this[prop] = options[prop];
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
/**
|
|
639
|
-
* Get the full path (example: `'~/index.min.js'`).
|
|
640
|
-
*
|
|
641
|
-
* @returns {string}
|
|
642
|
-
*/
|
|
643
|
-
get path() {
|
|
644
|
-
return this.history[this.history.length - 1];
|
|
645
|
-
}
|
|
646
|
-
/**
|
|
647
|
-
* Set the full path (example: `'~/index.min.js'`).
|
|
648
|
-
*
|
|
649
|
-
* Cannot be nullified.
|
|
650
|
-
* You can set a file URL (a `URL` object with a `file:` protocol) which will
|
|
651
|
-
* be turned into a path with `url.fileURLToPath`.
|
|
652
|
-
*
|
|
653
|
-
* @param {string | URL} path
|
|
654
|
-
*/
|
|
655
|
-
set path(path2) {
|
|
656
|
-
if (isUrl(path2)) {
|
|
657
|
-
path2 = urlToPath(path2);
|
|
658
|
-
}
|
|
659
|
-
assertNonEmpty(path2, "path");
|
|
660
|
-
if (this.path !== path2) {
|
|
661
|
-
this.history.push(path2);
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
/**
|
|
665
|
-
* Get the parent path (example: `'~'`).
|
|
666
|
-
*/
|
|
667
|
-
get dirname() {
|
|
668
|
-
return typeof this.path === "string" ? path.dirname(this.path) : void 0;
|
|
669
|
-
}
|
|
670
|
-
/**
|
|
671
|
-
* Set the parent path (example: `'~'`).
|
|
672
|
-
*
|
|
673
|
-
* Cannot be set if there’s no `path` yet.
|
|
674
|
-
*/
|
|
675
|
-
set dirname(dirname2) {
|
|
676
|
-
assertPath(this.basename, "dirname");
|
|
677
|
-
this.path = path.join(dirname2 || "", this.basename);
|
|
678
|
-
}
|
|
679
|
-
/**
|
|
680
|
-
* Get the basename (including extname) (example: `'index.min.js'`).
|
|
681
|
-
*/
|
|
682
|
-
get basename() {
|
|
683
|
-
return typeof this.path === "string" ? path.basename(this.path) : void 0;
|
|
684
|
-
}
|
|
685
|
-
/**
|
|
686
|
-
* Set basename (including extname) (`'index.min.js'`).
|
|
687
|
-
*
|
|
688
|
-
* Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
|
|
689
|
-
* on windows).
|
|
690
|
-
* Cannot be nullified (use `file.path = file.dirname` instead).
|
|
691
|
-
*/
|
|
692
|
-
set basename(basename2) {
|
|
693
|
-
assertNonEmpty(basename2, "basename");
|
|
694
|
-
assertPart(basename2, "basename");
|
|
695
|
-
this.path = path.join(this.dirname || "", basename2);
|
|
696
|
-
}
|
|
697
|
-
/**
|
|
698
|
-
* Get the extname (including dot) (example: `'.js'`).
|
|
699
|
-
*/
|
|
700
|
-
get extname() {
|
|
701
|
-
return typeof this.path === "string" ? path.extname(this.path) : void 0;
|
|
702
|
-
}
|
|
703
|
-
/**
|
|
704
|
-
* Set the extname (including dot) (example: `'.js'`).
|
|
705
|
-
*
|
|
706
|
-
* Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
|
|
707
|
-
* on windows).
|
|
708
|
-
* Cannot be set if there’s no `path` yet.
|
|
709
|
-
*/
|
|
710
|
-
set extname(extname2) {
|
|
711
|
-
assertPart(extname2, "extname");
|
|
712
|
-
assertPath(this.dirname, "extname");
|
|
713
|
-
if (extname2) {
|
|
714
|
-
if (extname2.charCodeAt(0) !== 46) {
|
|
715
|
-
throw new Error("`extname` must start with `.`");
|
|
716
|
-
}
|
|
717
|
-
if (extname2.includes(".", 1)) {
|
|
718
|
-
throw new Error("`extname` cannot contain multiple dots");
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
this.path = path.join(this.dirname, this.stem + (extname2 || ""));
|
|
722
|
-
}
|
|
723
|
-
/**
|
|
724
|
-
* Get the stem (basename w/o extname) (example: `'index.min'`).
|
|
725
|
-
*/
|
|
726
|
-
get stem() {
|
|
727
|
-
return typeof this.path === "string" ? path.basename(this.path, this.extname) : void 0;
|
|
728
|
-
}
|
|
729
|
-
/**
|
|
730
|
-
* Set the stem (basename w/o extname) (example: `'index.min'`).
|
|
731
|
-
*
|
|
732
|
-
* Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
|
|
733
|
-
* on windows).
|
|
734
|
-
* Cannot be nullified (use `file.path = file.dirname` instead).
|
|
735
|
-
*/
|
|
736
|
-
set stem(stem) {
|
|
737
|
-
assertNonEmpty(stem, "stem");
|
|
738
|
-
assertPart(stem, "stem");
|
|
739
|
-
this.path = path.join(this.dirname || "", stem + (this.extname || ""));
|
|
740
|
-
}
|
|
741
|
-
/**
|
|
742
|
-
* Serialize the file.
|
|
743
|
-
*
|
|
744
|
-
* @param {BufferEncoding | null | undefined} [encoding='utf8']
|
|
745
|
-
* Character encoding to understand `value` as when it’s a `Buffer`
|
|
746
|
-
* (default: `'utf8'`).
|
|
747
|
-
* @returns {string}
|
|
748
|
-
* Serialized file.
|
|
749
|
-
*/
|
|
750
|
-
toString(encoding) {
|
|
751
|
-
return (this.value || "").toString(encoding || void 0);
|
|
752
|
-
}
|
|
753
|
-
/**
|
|
754
|
-
* Create a warning message associated with the file.
|
|
755
|
-
*
|
|
756
|
-
* Its `fatal` is set to `false` and `file` is set to the current file path.
|
|
757
|
-
* Its added to `file.messages`.
|
|
758
|
-
*
|
|
759
|
-
* @param {string | Error | VFileMessage} reason
|
|
760
|
-
* Reason for message, uses the stack and message of the error if given.
|
|
761
|
-
* @param {Node | NodeLike | Position | Point | null | undefined} [place]
|
|
762
|
-
* Place in file where the message occurred.
|
|
763
|
-
* @param {string | null | undefined} [origin]
|
|
764
|
-
* Place in code where the message originates (example:
|
|
765
|
-
* `'my-package:my-rule'` or `'my-rule'`).
|
|
766
|
-
* @returns {VFileMessage}
|
|
767
|
-
* Message.
|
|
768
|
-
*/
|
|
769
|
-
message(reason, place, origin) {
|
|
770
|
-
const message = new VFileMessage(reason, place, origin);
|
|
771
|
-
if (this.path) {
|
|
772
|
-
message.name = this.path + ":" + message.name;
|
|
773
|
-
message.file = this.path;
|
|
774
|
-
}
|
|
775
|
-
message.fatal = false;
|
|
776
|
-
this.messages.push(message);
|
|
777
|
-
return message;
|
|
778
|
-
}
|
|
779
|
-
/**
|
|
780
|
-
* Create an info message associated with the file.
|
|
781
|
-
*
|
|
782
|
-
* Its `fatal` is set to `null` and `file` is set to the current file path.
|
|
783
|
-
* Its added to `file.messages`.
|
|
784
|
-
*
|
|
785
|
-
* @param {string | Error | VFileMessage} reason
|
|
786
|
-
* Reason for message, uses the stack and message of the error if given.
|
|
787
|
-
* @param {Node | NodeLike | Position | Point | null | undefined} [place]
|
|
788
|
-
* Place in file where the message occurred.
|
|
789
|
-
* @param {string | null | undefined} [origin]
|
|
790
|
-
* Place in code where the message originates (example:
|
|
791
|
-
* `'my-package:my-rule'` or `'my-rule'`).
|
|
792
|
-
* @returns {VFileMessage}
|
|
793
|
-
* Message.
|
|
794
|
-
*/
|
|
795
|
-
info(reason, place, origin) {
|
|
796
|
-
const message = this.message(reason, place, origin);
|
|
797
|
-
message.fatal = null;
|
|
798
|
-
return message;
|
|
799
|
-
}
|
|
800
|
-
/**
|
|
801
|
-
* Create a fatal error associated with the file.
|
|
802
|
-
*
|
|
803
|
-
* Its `fatal` is set to `true` and `file` is set to the current file path.
|
|
804
|
-
* Its added to `file.messages`.
|
|
805
|
-
*
|
|
806
|
-
* > 👉 **Note**: a fatal error means that a file is no longer processable.
|
|
807
|
-
*
|
|
808
|
-
* @param {string | Error | VFileMessage} reason
|
|
809
|
-
* Reason for message, uses the stack and message of the error if given.
|
|
810
|
-
* @param {Node | NodeLike | Position | Point | null | undefined} [place]
|
|
811
|
-
* Place in file where the message occurred.
|
|
812
|
-
* @param {string | null | undefined} [origin]
|
|
813
|
-
* Place in code where the message originates (example:
|
|
814
|
-
* `'my-package:my-rule'` or `'my-rule'`).
|
|
815
|
-
* @returns {never}
|
|
816
|
-
* Message.
|
|
817
|
-
* @throws {VFileMessage}
|
|
818
|
-
* Message.
|
|
819
|
-
*/
|
|
820
|
-
fail(reason, place, origin) {
|
|
821
|
-
const message = this.message(reason, place, origin);
|
|
822
|
-
message.fatal = true;
|
|
823
|
-
throw message;
|
|
824
|
-
}
|
|
834
|
+
if (url.hostname !== "") {
|
|
835
|
+
/** @type {NodeJS.ErrnoException} */
|
|
836
|
+
const error = /* @__PURE__ */ new TypeError("File URL host must be \"localhost\" or empty on darwin");
|
|
837
|
+
error.code = "ERR_INVALID_FILE_URL_HOST";
|
|
838
|
+
throw error;
|
|
839
|
+
}
|
|
840
|
+
const pathname = url.pathname;
|
|
841
|
+
let index = -1;
|
|
842
|
+
while (++index < pathname.length) if (pathname.charCodeAt(index) === 37 && pathname.charCodeAt(index + 1) === 50) {
|
|
843
|
+
const third = pathname.charCodeAt(index + 2);
|
|
844
|
+
if (third === 70 || third === 102) {
|
|
845
|
+
/** @type {NodeJS.ErrnoException} */
|
|
846
|
+
const error = /* @__PURE__ */ new TypeError("File URL path must not include encoded / characters");
|
|
847
|
+
error.code = "ERR_INVALID_FILE_URL_PATH";
|
|
848
|
+
throw error;
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
return decodeURIComponent(pathname);
|
|
825
852
|
}
|
|
853
|
+
//#endregion
|
|
854
|
+
//#region node_modules/vfile/lib/index.js
|
|
855
|
+
var import_is_buffer = /* @__PURE__ */ __toESM(require_is_buffer(), 1);
|
|
856
|
+
/**
|
|
857
|
+
* Order of setting (least specific to most), we need this because otherwise
|
|
858
|
+
* `{stem: 'a', path: '~/b.js'}` would throw, as a path is needed before a
|
|
859
|
+
* stem can be set.
|
|
860
|
+
*
|
|
861
|
+
* @type {Array<'basename' | 'dirname' | 'extname' | 'history' | 'path' | 'stem'>}
|
|
862
|
+
*/
|
|
863
|
+
var order = [
|
|
864
|
+
"history",
|
|
865
|
+
"path",
|
|
866
|
+
"basename",
|
|
867
|
+
"stem",
|
|
868
|
+
"extname",
|
|
869
|
+
"dirname"
|
|
870
|
+
];
|
|
871
|
+
var VFile = class {
|
|
872
|
+
/**
|
|
873
|
+
* Create a new virtual file.
|
|
874
|
+
*
|
|
875
|
+
* `options` is treated as:
|
|
876
|
+
*
|
|
877
|
+
* * `string` or `Buffer` — `{value: options}`
|
|
878
|
+
* * `URL` — `{path: options}`
|
|
879
|
+
* * `VFile` — shallow copies its data over to the new file
|
|
880
|
+
* * `object` — all fields are shallow copied over to the new file
|
|
881
|
+
*
|
|
882
|
+
* Path related fields are set in the following order (least specific to
|
|
883
|
+
* most specific): `history`, `path`, `basename`, `stem`, `extname`,
|
|
884
|
+
* `dirname`.
|
|
885
|
+
*
|
|
886
|
+
* You cannot set `dirname` or `extname` without setting either `history`,
|
|
887
|
+
* `path`, `basename`, or `stem` too.
|
|
888
|
+
*
|
|
889
|
+
* @param {Compatible | null | undefined} [value]
|
|
890
|
+
* File value.
|
|
891
|
+
* @returns
|
|
892
|
+
* New instance.
|
|
893
|
+
*/
|
|
894
|
+
constructor(value) {
|
|
895
|
+
/** @type {Options | VFile} */
|
|
896
|
+
let options;
|
|
897
|
+
if (!value) options = {};
|
|
898
|
+
else if (typeof value === "string" || buffer(value)) options = { value };
|
|
899
|
+
else if (isUrl(value)) options = { path: value };
|
|
900
|
+
else options = value;
|
|
901
|
+
/**
|
|
902
|
+
* Place to store custom information (default: `{}`).
|
|
903
|
+
*
|
|
904
|
+
* It’s OK to store custom data directly on the file but moving it to
|
|
905
|
+
* `data` is recommended.
|
|
906
|
+
*
|
|
907
|
+
* @type {Data}
|
|
908
|
+
*/
|
|
909
|
+
this.data = {};
|
|
910
|
+
/**
|
|
911
|
+
* List of messages associated with the file.
|
|
912
|
+
*
|
|
913
|
+
* @type {Array<VFileMessage>}
|
|
914
|
+
*/
|
|
915
|
+
this.messages = [];
|
|
916
|
+
/**
|
|
917
|
+
* List of filepaths the file moved between.
|
|
918
|
+
*
|
|
919
|
+
* The first is the original path and the last is the current path.
|
|
920
|
+
*
|
|
921
|
+
* @type {Array<string>}
|
|
922
|
+
*/
|
|
923
|
+
this.history = [];
|
|
924
|
+
/**
|
|
925
|
+
* Base of `path` (default: `process.cwd()` or `'/'` in browsers).
|
|
926
|
+
*
|
|
927
|
+
* @type {string}
|
|
928
|
+
*/
|
|
929
|
+
this.cwd = proc.cwd();
|
|
930
|
+
/**
|
|
931
|
+
* Raw value.
|
|
932
|
+
*
|
|
933
|
+
* @type {Value}
|
|
934
|
+
*/
|
|
935
|
+
this.value;
|
|
936
|
+
/**
|
|
937
|
+
* Whether a file was saved to disk.
|
|
938
|
+
*
|
|
939
|
+
* This is used by vfile reporters.
|
|
940
|
+
*
|
|
941
|
+
* @type {boolean}
|
|
942
|
+
*/
|
|
943
|
+
this.stored;
|
|
944
|
+
/**
|
|
945
|
+
* Custom, non-string, compiled, representation.
|
|
946
|
+
*
|
|
947
|
+
* This is used by unified to store non-string results.
|
|
948
|
+
* One example is when turning markdown into React nodes.
|
|
949
|
+
*
|
|
950
|
+
* @type {unknown}
|
|
951
|
+
*/
|
|
952
|
+
this.result;
|
|
953
|
+
/**
|
|
954
|
+
* Source map.
|
|
955
|
+
*
|
|
956
|
+
* This type is equivalent to the `RawSourceMap` type from the `source-map`
|
|
957
|
+
* module.
|
|
958
|
+
*
|
|
959
|
+
* @type {Map | null | undefined}
|
|
960
|
+
*/
|
|
961
|
+
this.map;
|
|
962
|
+
let index = -1;
|
|
963
|
+
while (++index < order.length) {
|
|
964
|
+
const prop = order[index];
|
|
965
|
+
if (prop in options && options[prop] !== void 0 && options[prop] !== null) this[prop] = prop === "history" ? [...options[prop]] : options[prop];
|
|
966
|
+
}
|
|
967
|
+
/** @type {string} */
|
|
968
|
+
let prop;
|
|
969
|
+
for (prop in options) if (!order.includes(prop)) this[prop] = options[prop];
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* Get the full path (example: `'~/index.min.js'`).
|
|
973
|
+
*
|
|
974
|
+
* @returns {string}
|
|
975
|
+
*/
|
|
976
|
+
get path() {
|
|
977
|
+
return this.history[this.history.length - 1];
|
|
978
|
+
}
|
|
979
|
+
/**
|
|
980
|
+
* Set the full path (example: `'~/index.min.js'`).
|
|
981
|
+
*
|
|
982
|
+
* Cannot be nullified.
|
|
983
|
+
* You can set a file URL (a `URL` object with a `file:` protocol) which will
|
|
984
|
+
* be turned into a path with `url.fileURLToPath`.
|
|
985
|
+
*
|
|
986
|
+
* @param {string | URL} path
|
|
987
|
+
*/
|
|
988
|
+
set path(path) {
|
|
989
|
+
if (isUrl(path)) path = urlToPath(path);
|
|
990
|
+
assertNonEmpty(path, "path");
|
|
991
|
+
if (this.path !== path) this.history.push(path);
|
|
992
|
+
}
|
|
993
|
+
/**
|
|
994
|
+
* Get the parent path (example: `'~'`).
|
|
995
|
+
*/
|
|
996
|
+
get dirname() {
|
|
997
|
+
return typeof this.path === "string" ? path.dirname(this.path) : void 0;
|
|
998
|
+
}
|
|
999
|
+
/**
|
|
1000
|
+
* Set the parent path (example: `'~'`).
|
|
1001
|
+
*
|
|
1002
|
+
* Cannot be set if there’s no `path` yet.
|
|
1003
|
+
*/
|
|
1004
|
+
set dirname(dirname) {
|
|
1005
|
+
assertPath(this.basename, "dirname");
|
|
1006
|
+
this.path = path.join(dirname || "", this.basename);
|
|
1007
|
+
}
|
|
1008
|
+
/**
|
|
1009
|
+
* Get the basename (including extname) (example: `'index.min.js'`).
|
|
1010
|
+
*/
|
|
1011
|
+
get basename() {
|
|
1012
|
+
return typeof this.path === "string" ? path.basename(this.path) : void 0;
|
|
1013
|
+
}
|
|
1014
|
+
/**
|
|
1015
|
+
* Set basename (including extname) (`'index.min.js'`).
|
|
1016
|
+
*
|
|
1017
|
+
* Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
|
|
1018
|
+
* on windows).
|
|
1019
|
+
* Cannot be nullified (use `file.path = file.dirname` instead).
|
|
1020
|
+
*/
|
|
1021
|
+
set basename(basename) {
|
|
1022
|
+
assertNonEmpty(basename, "basename");
|
|
1023
|
+
assertPart(basename, "basename");
|
|
1024
|
+
this.path = path.join(this.dirname || "", basename);
|
|
1025
|
+
}
|
|
1026
|
+
/**
|
|
1027
|
+
* Get the extname (including dot) (example: `'.js'`).
|
|
1028
|
+
*/
|
|
1029
|
+
get extname() {
|
|
1030
|
+
return typeof this.path === "string" ? path.extname(this.path) : void 0;
|
|
1031
|
+
}
|
|
1032
|
+
/**
|
|
1033
|
+
* Set the extname (including dot) (example: `'.js'`).
|
|
1034
|
+
*
|
|
1035
|
+
* Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
|
|
1036
|
+
* on windows).
|
|
1037
|
+
* Cannot be set if there’s no `path` yet.
|
|
1038
|
+
*/
|
|
1039
|
+
set extname(extname) {
|
|
1040
|
+
assertPart(extname, "extname");
|
|
1041
|
+
assertPath(this.dirname, "extname");
|
|
1042
|
+
if (extname) {
|
|
1043
|
+
if (extname.charCodeAt(0) !== 46) throw new Error("`extname` must start with `.`");
|
|
1044
|
+
if (extname.includes(".", 1)) throw new Error("`extname` cannot contain multiple dots");
|
|
1045
|
+
}
|
|
1046
|
+
this.path = path.join(this.dirname, this.stem + (extname || ""));
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Get the stem (basename w/o extname) (example: `'index.min'`).
|
|
1050
|
+
*/
|
|
1051
|
+
get stem() {
|
|
1052
|
+
return typeof this.path === "string" ? path.basename(this.path, this.extname) : void 0;
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* Set the stem (basename w/o extname) (example: `'index.min'`).
|
|
1056
|
+
*
|
|
1057
|
+
* Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
|
|
1058
|
+
* on windows).
|
|
1059
|
+
* Cannot be nullified (use `file.path = file.dirname` instead).
|
|
1060
|
+
*/
|
|
1061
|
+
set stem(stem) {
|
|
1062
|
+
assertNonEmpty(stem, "stem");
|
|
1063
|
+
assertPart(stem, "stem");
|
|
1064
|
+
this.path = path.join(this.dirname || "", stem + (this.extname || ""));
|
|
1065
|
+
}
|
|
1066
|
+
/**
|
|
1067
|
+
* Serialize the file.
|
|
1068
|
+
*
|
|
1069
|
+
* @param {BufferEncoding | null | undefined} [encoding='utf8']
|
|
1070
|
+
* Character encoding to understand `value` as when it’s a `Buffer`
|
|
1071
|
+
* (default: `'utf8'`).
|
|
1072
|
+
* @returns {string}
|
|
1073
|
+
* Serialized file.
|
|
1074
|
+
*/
|
|
1075
|
+
toString(encoding) {
|
|
1076
|
+
return (this.value || "").toString(encoding || void 0);
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* Create a warning message associated with the file.
|
|
1080
|
+
*
|
|
1081
|
+
* Its `fatal` is set to `false` and `file` is set to the current file path.
|
|
1082
|
+
* Its added to `file.messages`.
|
|
1083
|
+
*
|
|
1084
|
+
* @param {string | Error | VFileMessage} reason
|
|
1085
|
+
* Reason for message, uses the stack and message of the error if given.
|
|
1086
|
+
* @param {Node | NodeLike | Position | Point | null | undefined} [place]
|
|
1087
|
+
* Place in file where the message occurred.
|
|
1088
|
+
* @param {string | null | undefined} [origin]
|
|
1089
|
+
* Place in code where the message originates (example:
|
|
1090
|
+
* `'my-package:my-rule'` or `'my-rule'`).
|
|
1091
|
+
* @returns {VFileMessage}
|
|
1092
|
+
* Message.
|
|
1093
|
+
*/
|
|
1094
|
+
message(reason, place, origin) {
|
|
1095
|
+
const message = new VFileMessage(reason, place, origin);
|
|
1096
|
+
if (this.path) {
|
|
1097
|
+
message.name = this.path + ":" + message.name;
|
|
1098
|
+
message.file = this.path;
|
|
1099
|
+
}
|
|
1100
|
+
message.fatal = false;
|
|
1101
|
+
this.messages.push(message);
|
|
1102
|
+
return message;
|
|
1103
|
+
}
|
|
1104
|
+
/**
|
|
1105
|
+
* Create an info message associated with the file.
|
|
1106
|
+
*
|
|
1107
|
+
* Its `fatal` is set to `null` and `file` is set to the current file path.
|
|
1108
|
+
* Its added to `file.messages`.
|
|
1109
|
+
*
|
|
1110
|
+
* @param {string | Error | VFileMessage} reason
|
|
1111
|
+
* Reason for message, uses the stack and message of the error if given.
|
|
1112
|
+
* @param {Node | NodeLike | Position | Point | null | undefined} [place]
|
|
1113
|
+
* Place in file where the message occurred.
|
|
1114
|
+
* @param {string | null | undefined} [origin]
|
|
1115
|
+
* Place in code where the message originates (example:
|
|
1116
|
+
* `'my-package:my-rule'` or `'my-rule'`).
|
|
1117
|
+
* @returns {VFileMessage}
|
|
1118
|
+
* Message.
|
|
1119
|
+
*/
|
|
1120
|
+
info(reason, place, origin) {
|
|
1121
|
+
const message = this.message(reason, place, origin);
|
|
1122
|
+
message.fatal = null;
|
|
1123
|
+
return message;
|
|
1124
|
+
}
|
|
1125
|
+
/**
|
|
1126
|
+
* Create a fatal error associated with the file.
|
|
1127
|
+
*
|
|
1128
|
+
* Its `fatal` is set to `true` and `file` is set to the current file path.
|
|
1129
|
+
* Its added to `file.messages`.
|
|
1130
|
+
*
|
|
1131
|
+
* > 👉 **Note**: a fatal error means that a file is no longer processable.
|
|
1132
|
+
*
|
|
1133
|
+
* @param {string | Error | VFileMessage} reason
|
|
1134
|
+
* Reason for message, uses the stack and message of the error if given.
|
|
1135
|
+
* @param {Node | NodeLike | Position | Point | null | undefined} [place]
|
|
1136
|
+
* Place in file where the message occurred.
|
|
1137
|
+
* @param {string | null | undefined} [origin]
|
|
1138
|
+
* Place in code where the message originates (example:
|
|
1139
|
+
* `'my-package:my-rule'` or `'my-rule'`).
|
|
1140
|
+
* @returns {never}
|
|
1141
|
+
* Message.
|
|
1142
|
+
* @throws {VFileMessage}
|
|
1143
|
+
* Message.
|
|
1144
|
+
*/
|
|
1145
|
+
fail(reason, place, origin) {
|
|
1146
|
+
const message = this.message(reason, place, origin);
|
|
1147
|
+
message.fatal = true;
|
|
1148
|
+
throw message;
|
|
1149
|
+
}
|
|
1150
|
+
};
|
|
1151
|
+
/**
|
|
1152
|
+
* Assert that `part` is not a path (as in, does not contain `path.sep`).
|
|
1153
|
+
*
|
|
1154
|
+
* @param {string | null | undefined} part
|
|
1155
|
+
* File path part.
|
|
1156
|
+
* @param {string} name
|
|
1157
|
+
* Part name.
|
|
1158
|
+
* @returns {void}
|
|
1159
|
+
* Nothing.
|
|
1160
|
+
*/
|
|
826
1161
|
function assertPart(part, name) {
|
|
827
|
-
|
|
828
|
-
throw new Error(
|
|
829
|
-
"`" + name + "` cannot be a path: did not expect `" + path.sep + "`"
|
|
830
|
-
);
|
|
831
|
-
}
|
|
1162
|
+
if (part && part.includes(path.sep)) throw new Error("`" + name + "` cannot be a path: did not expect `" + path.sep + "`");
|
|
832
1163
|
}
|
|
1164
|
+
/**
|
|
1165
|
+
* Assert that `part` is not empty.
|
|
1166
|
+
*
|
|
1167
|
+
* @param {string | undefined} part
|
|
1168
|
+
* Thing.
|
|
1169
|
+
* @param {string} name
|
|
1170
|
+
* Part name.
|
|
1171
|
+
* @returns {asserts part is string}
|
|
1172
|
+
* Nothing.
|
|
1173
|
+
*/
|
|
833
1174
|
function assertNonEmpty(part, name) {
|
|
834
|
-
|
|
835
|
-
throw new Error("`" + name + "` cannot be empty");
|
|
836
|
-
}
|
|
1175
|
+
if (!part) throw new Error("`" + name + "` cannot be empty");
|
|
837
1176
|
}
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
1177
|
+
/**
|
|
1178
|
+
* Assert `path` exists.
|
|
1179
|
+
*
|
|
1180
|
+
* @param {string | undefined} path
|
|
1181
|
+
* Path.
|
|
1182
|
+
* @param {string} name
|
|
1183
|
+
* Dependency name.
|
|
1184
|
+
* @returns {asserts path is string}
|
|
1185
|
+
* Nothing.
|
|
1186
|
+
*/
|
|
1187
|
+
function assertPath(path, name) {
|
|
1188
|
+
if (!path) throw new Error("Setting `" + name + "` requires `path` to be set too");
|
|
842
1189
|
}
|
|
1190
|
+
/**
|
|
1191
|
+
* Assert `value` is a buffer.
|
|
1192
|
+
*
|
|
1193
|
+
* @param {unknown} value
|
|
1194
|
+
* thing.
|
|
1195
|
+
* @returns {value is Buffer}
|
|
1196
|
+
* Whether `value` is a Node.js buffer.
|
|
1197
|
+
*/
|
|
843
1198
|
function buffer(value) {
|
|
844
|
-
|
|
1199
|
+
return (0, import_is_buffer.default)(value);
|
|
845
1200
|
}
|
|
846
|
-
|
|
847
|
-
|
|
1201
|
+
//#endregion
|
|
1202
|
+
//#region node_modules/unified/lib/index.js
|
|
1203
|
+
/**
|
|
1204
|
+
* @typedef {import('unist').Node} Node
|
|
1205
|
+
* @typedef {import('vfile').VFileCompatible} VFileCompatible
|
|
1206
|
+
* @typedef {import('vfile').VFileValue} VFileValue
|
|
1207
|
+
* @typedef {import('..').Processor} Processor
|
|
1208
|
+
* @typedef {import('..').Plugin} Plugin
|
|
1209
|
+
* @typedef {import('..').Preset} Preset
|
|
1210
|
+
* @typedef {import('..').Pluggable} Pluggable
|
|
1211
|
+
* @typedef {import('..').PluggableList} PluggableList
|
|
1212
|
+
* @typedef {import('..').Transformer} Transformer
|
|
1213
|
+
* @typedef {import('..').Parser} Parser
|
|
1214
|
+
* @typedef {import('..').Compiler} Compiler
|
|
1215
|
+
* @typedef {import('..').RunCallback} RunCallback
|
|
1216
|
+
* @typedef {import('..').ProcessCallback} ProcessCallback
|
|
1217
|
+
*
|
|
1218
|
+
* @typedef Context
|
|
1219
|
+
* @property {Node} tree
|
|
1220
|
+
* @property {VFile} file
|
|
1221
|
+
*/
|
|
1222
|
+
var import_extend = /* @__PURE__ */ __toESM(require_extend(), 1);
|
|
1223
|
+
var unified = base().freeze();
|
|
1224
|
+
var own = {}.hasOwnProperty;
|
|
1225
|
+
/**
|
|
1226
|
+
* @returns {Processor}
|
|
1227
|
+
*/
|
|
848
1228
|
function base() {
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1229
|
+
const transformers = trough();
|
|
1230
|
+
/** @type {Processor['attachers']} */
|
|
1231
|
+
const attachers = [];
|
|
1232
|
+
/** @type {Record<string, unknown>} */
|
|
1233
|
+
let namespace = {};
|
|
1234
|
+
/** @type {boolean|undefined} */
|
|
1235
|
+
let frozen;
|
|
1236
|
+
let freezeIndex = -1;
|
|
1237
|
+
processor.data = data;
|
|
1238
|
+
processor.Parser = void 0;
|
|
1239
|
+
processor.Compiler = void 0;
|
|
1240
|
+
processor.freeze = freeze;
|
|
1241
|
+
processor.attachers = attachers;
|
|
1242
|
+
processor.use = use;
|
|
1243
|
+
processor.parse = parse;
|
|
1244
|
+
processor.stringify = stringify;
|
|
1245
|
+
processor.run = run;
|
|
1246
|
+
processor.runSync = runSync;
|
|
1247
|
+
processor.process = process;
|
|
1248
|
+
processor.processSync = processSync;
|
|
1249
|
+
return processor;
|
|
1250
|
+
/** @type {Processor} */
|
|
1251
|
+
function processor() {
|
|
1252
|
+
const destination = base();
|
|
1253
|
+
let index = -1;
|
|
1254
|
+
while (++index < attachers.length) destination.use(...attachers[index]);
|
|
1255
|
+
destination.data((0, import_extend.default)(true, {}, namespace));
|
|
1256
|
+
return destination;
|
|
1257
|
+
}
|
|
1258
|
+
/**
|
|
1259
|
+
* @param {string|Record<string, unknown>} [key]
|
|
1260
|
+
* @param {unknown} [value]
|
|
1261
|
+
* @returns {unknown}
|
|
1262
|
+
*/
|
|
1263
|
+
function data(key, value) {
|
|
1264
|
+
if (typeof key === "string") {
|
|
1265
|
+
if (arguments.length === 2) {
|
|
1266
|
+
assertUnfrozen("data", frozen);
|
|
1267
|
+
namespace[key] = value;
|
|
1268
|
+
return processor;
|
|
1269
|
+
}
|
|
1270
|
+
return own.call(namespace, key) && namespace[key] || null;
|
|
1271
|
+
}
|
|
1272
|
+
if (key) {
|
|
1273
|
+
assertUnfrozen("data", frozen);
|
|
1274
|
+
namespace = key;
|
|
1275
|
+
return processor;
|
|
1276
|
+
}
|
|
1277
|
+
return namespace;
|
|
1278
|
+
}
|
|
1279
|
+
/** @type {Processor['freeze']} */
|
|
1280
|
+
function freeze() {
|
|
1281
|
+
if (frozen) return processor;
|
|
1282
|
+
while (++freezeIndex < attachers.length) {
|
|
1283
|
+
const [attacher, ...options] = attachers[freezeIndex];
|
|
1284
|
+
if (options[0] === false) continue;
|
|
1285
|
+
if (options[0] === true) options[0] = void 0;
|
|
1286
|
+
/** @type {Transformer|void} */
|
|
1287
|
+
const transformer = attacher.call(processor, ...options);
|
|
1288
|
+
if (typeof transformer === "function") transformers.use(transformer);
|
|
1289
|
+
}
|
|
1290
|
+
frozen = true;
|
|
1291
|
+
freezeIndex = Number.POSITIVE_INFINITY;
|
|
1292
|
+
return processor;
|
|
1293
|
+
}
|
|
1294
|
+
/**
|
|
1295
|
+
* @param {Pluggable|null|undefined} [value]
|
|
1296
|
+
* @param {...unknown} options
|
|
1297
|
+
* @returns {Processor}
|
|
1298
|
+
*/
|
|
1299
|
+
function use(value, ...options) {
|
|
1300
|
+
/** @type {Record<string, unknown>|undefined} */
|
|
1301
|
+
let settings;
|
|
1302
|
+
assertUnfrozen("use", frozen);
|
|
1303
|
+
if (value === null || value === void 0) {} else if (typeof value === "function") addPlugin(value, ...options);
|
|
1304
|
+
else if (typeof value === "object") if (Array.isArray(value)) addList(value);
|
|
1305
|
+
else addPreset(value);
|
|
1306
|
+
else throw new TypeError("Expected usable value, not `" + value + "`");
|
|
1307
|
+
if (settings) namespace.settings = Object.assign(namespace.settings || {}, settings);
|
|
1308
|
+
return processor;
|
|
1309
|
+
/**
|
|
1310
|
+
* @param {import('..').Pluggable<unknown[]>} value
|
|
1311
|
+
* @returns {void}
|
|
1312
|
+
*/
|
|
1313
|
+
function add(value) {
|
|
1314
|
+
if (typeof value === "function") addPlugin(value);
|
|
1315
|
+
else if (typeof value === "object") if (Array.isArray(value)) {
|
|
1316
|
+
const [plugin, ...options] = value;
|
|
1317
|
+
addPlugin(plugin, ...options);
|
|
1318
|
+
} else addPreset(value);
|
|
1319
|
+
else throw new TypeError("Expected usable value, not `" + value + "`");
|
|
1320
|
+
}
|
|
1321
|
+
/**
|
|
1322
|
+
* @param {Preset} result
|
|
1323
|
+
* @returns {void}
|
|
1324
|
+
*/
|
|
1325
|
+
function addPreset(result) {
|
|
1326
|
+
addList(result.plugins);
|
|
1327
|
+
if (result.settings) settings = Object.assign(settings || {}, result.settings);
|
|
1328
|
+
}
|
|
1329
|
+
/**
|
|
1330
|
+
* @param {PluggableList|null|undefined} [plugins]
|
|
1331
|
+
* @returns {void}
|
|
1332
|
+
*/
|
|
1333
|
+
function addList(plugins) {
|
|
1334
|
+
let index = -1;
|
|
1335
|
+
if (plugins === null || plugins === void 0) {} else if (Array.isArray(plugins)) while (++index < plugins.length) {
|
|
1336
|
+
const thing = plugins[index];
|
|
1337
|
+
add(thing);
|
|
1338
|
+
}
|
|
1339
|
+
else throw new TypeError("Expected a list of plugins, not `" + plugins + "`");
|
|
1340
|
+
}
|
|
1341
|
+
/**
|
|
1342
|
+
* @param {Plugin} plugin
|
|
1343
|
+
* @param {...unknown} [value]
|
|
1344
|
+
* @returns {void}
|
|
1345
|
+
*/
|
|
1346
|
+
function addPlugin(plugin, value) {
|
|
1347
|
+
let index = -1;
|
|
1348
|
+
/** @type {Processor['attachers'][number]|undefined} */
|
|
1349
|
+
let entry;
|
|
1350
|
+
while (++index < attachers.length) if (attachers[index][0] === plugin) {
|
|
1351
|
+
entry = attachers[index];
|
|
1352
|
+
break;
|
|
1353
|
+
}
|
|
1354
|
+
if (entry) {
|
|
1355
|
+
if (isPlainObject(entry[1]) && isPlainObject(value)) value = (0, import_extend.default)(true, entry[1], value);
|
|
1356
|
+
entry[1] = value;
|
|
1357
|
+
} else attachers.push([...arguments]);
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
/** @type {Processor['parse']} */
|
|
1361
|
+
function parse(doc) {
|
|
1362
|
+
processor.freeze();
|
|
1363
|
+
const file = vfile(doc);
|
|
1364
|
+
const Parser = processor.Parser;
|
|
1365
|
+
assertParser("parse", Parser);
|
|
1366
|
+
if (newable(Parser, "parse")) return new Parser(String(file), file).parse();
|
|
1367
|
+
return Parser(String(file), file);
|
|
1368
|
+
}
|
|
1369
|
+
/** @type {Processor['stringify']} */
|
|
1370
|
+
function stringify(node, doc) {
|
|
1371
|
+
processor.freeze();
|
|
1372
|
+
const file = vfile(doc);
|
|
1373
|
+
const Compiler = processor.Compiler;
|
|
1374
|
+
assertCompiler("stringify", Compiler);
|
|
1375
|
+
assertNode(node);
|
|
1376
|
+
if (newable(Compiler, "compile")) return new Compiler(node, file).compile();
|
|
1377
|
+
return Compiler(node, file);
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* @param {Node} node
|
|
1381
|
+
* @param {VFileCompatible|RunCallback} [doc]
|
|
1382
|
+
* @param {RunCallback} [callback]
|
|
1383
|
+
* @returns {Promise<Node>|void}
|
|
1384
|
+
*/
|
|
1385
|
+
function run(node, doc, callback) {
|
|
1386
|
+
assertNode(node);
|
|
1387
|
+
processor.freeze();
|
|
1388
|
+
if (!callback && typeof doc === "function") {
|
|
1389
|
+
callback = doc;
|
|
1390
|
+
doc = void 0;
|
|
1391
|
+
}
|
|
1392
|
+
if (!callback) return new Promise(executor);
|
|
1393
|
+
executor(null, callback);
|
|
1394
|
+
/**
|
|
1395
|
+
* @param {null|((node: Node) => void)} resolve
|
|
1396
|
+
* @param {(error: Error) => void} reject
|
|
1397
|
+
* @returns {void}
|
|
1398
|
+
*/
|
|
1399
|
+
function executor(resolve, reject) {
|
|
1400
|
+
transformers.run(node, vfile(doc), done);
|
|
1401
|
+
/**
|
|
1402
|
+
* @param {Error|null} error
|
|
1403
|
+
* @param {Node} tree
|
|
1404
|
+
* @param {VFile} file
|
|
1405
|
+
* @returns {void}
|
|
1406
|
+
*/
|
|
1407
|
+
function done(error, tree, file) {
|
|
1408
|
+
tree = tree || node;
|
|
1409
|
+
if (error) reject(error);
|
|
1410
|
+
else if (resolve) resolve(tree);
|
|
1411
|
+
else callback(null, tree, file);
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
/** @type {Processor['runSync']} */
|
|
1416
|
+
function runSync(node, file) {
|
|
1417
|
+
/** @type {Node|undefined} */
|
|
1418
|
+
let result;
|
|
1419
|
+
/** @type {boolean|undefined} */
|
|
1420
|
+
let complete;
|
|
1421
|
+
processor.run(node, file, done);
|
|
1422
|
+
assertDone("runSync", "run", complete);
|
|
1423
|
+
return result;
|
|
1424
|
+
/**
|
|
1425
|
+
* @param {Error|null} [error]
|
|
1426
|
+
* @param {Node} [tree]
|
|
1427
|
+
* @returns {void}
|
|
1428
|
+
*/
|
|
1429
|
+
function done(error, tree) {
|
|
1430
|
+
bail(error);
|
|
1431
|
+
result = tree;
|
|
1432
|
+
complete = true;
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
/**
|
|
1436
|
+
* @param {VFileCompatible} doc
|
|
1437
|
+
* @param {ProcessCallback} [callback]
|
|
1438
|
+
* @returns {Promise<VFile>|undefined}
|
|
1439
|
+
*/
|
|
1440
|
+
function process(doc, callback) {
|
|
1441
|
+
processor.freeze();
|
|
1442
|
+
assertParser("process", processor.Parser);
|
|
1443
|
+
assertCompiler("process", processor.Compiler);
|
|
1444
|
+
if (!callback) return new Promise(executor);
|
|
1445
|
+
executor(null, callback);
|
|
1446
|
+
/**
|
|
1447
|
+
* @param {null|((file: VFile) => void)} resolve
|
|
1448
|
+
* @param {(error?: Error|null|undefined) => void} reject
|
|
1449
|
+
* @returns {void}
|
|
1450
|
+
*/
|
|
1451
|
+
function executor(resolve, reject) {
|
|
1452
|
+
const file = vfile(doc);
|
|
1453
|
+
processor.run(processor.parse(file), file, (error, tree, file) => {
|
|
1454
|
+
if (error || !tree || !file) done(error);
|
|
1455
|
+
else {
|
|
1456
|
+
/** @type {unknown} */
|
|
1457
|
+
const result = processor.stringify(tree, file);
|
|
1458
|
+
if (result === void 0 || result === null) {} else if (looksLikeAVFileValue(result)) file.value = result;
|
|
1459
|
+
else file.result = result;
|
|
1460
|
+
done(error, file);
|
|
1461
|
+
}
|
|
1462
|
+
});
|
|
1463
|
+
/**
|
|
1464
|
+
* @param {Error|null|undefined} [error]
|
|
1465
|
+
* @param {VFile|undefined} [file]
|
|
1466
|
+
* @returns {void}
|
|
1467
|
+
*/
|
|
1468
|
+
function done(error, file) {
|
|
1469
|
+
if (error || !file) reject(error);
|
|
1470
|
+
else if (resolve) resolve(file);
|
|
1471
|
+
else callback(null, file);
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
/** @type {Processor['processSync']} */
|
|
1476
|
+
function processSync(doc) {
|
|
1477
|
+
/** @type {boolean|undefined} */
|
|
1478
|
+
let complete;
|
|
1479
|
+
processor.freeze();
|
|
1480
|
+
assertParser("processSync", processor.Parser);
|
|
1481
|
+
assertCompiler("processSync", processor.Compiler);
|
|
1482
|
+
const file = vfile(doc);
|
|
1483
|
+
processor.process(file, done);
|
|
1484
|
+
assertDone("processSync", "process", complete);
|
|
1485
|
+
return file;
|
|
1486
|
+
/**
|
|
1487
|
+
* @param {Error|null|undefined} [error]
|
|
1488
|
+
* @returns {void}
|
|
1489
|
+
*/
|
|
1490
|
+
function done(error) {
|
|
1491
|
+
complete = true;
|
|
1492
|
+
bail(error);
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1090
1495
|
}
|
|
1496
|
+
/**
|
|
1497
|
+
* Check if `value` is a constructor.
|
|
1498
|
+
*
|
|
1499
|
+
* @param {unknown} value
|
|
1500
|
+
* @param {string} name
|
|
1501
|
+
* @returns {boolean}
|
|
1502
|
+
*/
|
|
1091
1503
|
function newable(value, name) {
|
|
1092
|
-
|
|
1093
|
-
// type-coverage:ignore-next-line
|
|
1094
|
-
value.prototype && // A function with keys in its prototype is probably a constructor.
|
|
1095
|
-
// Classes’ prototype methods are not enumerable, so we check if some value
|
|
1096
|
-
// exists in the prototype.
|
|
1097
|
-
// type-coverage:ignore-next-line
|
|
1098
|
-
(keys(value.prototype) || name in value.prototype);
|
|
1504
|
+
return typeof value === "function" && value.prototype && (keys(value.prototype) || name in value.prototype);
|
|
1099
1505
|
}
|
|
1506
|
+
/**
|
|
1507
|
+
* Check if `value` is an object with keys.
|
|
1508
|
+
*
|
|
1509
|
+
* @param {Record<string, unknown>} value
|
|
1510
|
+
* @returns {boolean}
|
|
1511
|
+
*/
|
|
1100
1512
|
function keys(value) {
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
return false;
|
|
1513
|
+
/** @type {string} */
|
|
1514
|
+
let key;
|
|
1515
|
+
for (key in value) if (own.call(value, key)) return true;
|
|
1516
|
+
return false;
|
|
1108
1517
|
}
|
|
1518
|
+
/**
|
|
1519
|
+
* Assert a parser is available.
|
|
1520
|
+
*
|
|
1521
|
+
* @param {string} name
|
|
1522
|
+
* @param {unknown} value
|
|
1523
|
+
* @returns {asserts value is Parser}
|
|
1524
|
+
*/
|
|
1109
1525
|
function assertParser(name, value) {
|
|
1110
|
-
|
|
1111
|
-
throw new TypeError("Cannot `" + name + "` without `Parser`");
|
|
1112
|
-
}
|
|
1526
|
+
if (typeof value !== "function") throw new TypeError("Cannot `" + name + "` without `Parser`");
|
|
1113
1527
|
}
|
|
1528
|
+
/**
|
|
1529
|
+
* Assert a compiler is available.
|
|
1530
|
+
*
|
|
1531
|
+
* @param {string} name
|
|
1532
|
+
* @param {unknown} value
|
|
1533
|
+
* @returns {asserts value is Compiler}
|
|
1534
|
+
*/
|
|
1114
1535
|
function assertCompiler(name, value) {
|
|
1115
|
-
|
|
1116
|
-
throw new TypeError("Cannot `" + name + "` without `Compiler`");
|
|
1117
|
-
}
|
|
1536
|
+
if (typeof value !== "function") throw new TypeError("Cannot `" + name + "` without `Compiler`");
|
|
1118
1537
|
}
|
|
1538
|
+
/**
|
|
1539
|
+
* Assert the processor is not frozen.
|
|
1540
|
+
*
|
|
1541
|
+
* @param {string} name
|
|
1542
|
+
* @param {unknown} frozen
|
|
1543
|
+
* @returns {asserts frozen is false}
|
|
1544
|
+
*/
|
|
1119
1545
|
function assertUnfrozen(name, frozen) {
|
|
1120
|
-
|
|
1121
|
-
throw new Error(
|
|
1122
|
-
"Cannot call `" + name + "` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`."
|
|
1123
|
-
);
|
|
1124
|
-
}
|
|
1546
|
+
if (frozen) throw new Error("Cannot call `" + name + "` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.");
|
|
1125
1547
|
}
|
|
1548
|
+
/**
|
|
1549
|
+
* Assert `node` is a unist node.
|
|
1550
|
+
*
|
|
1551
|
+
* @param {unknown} node
|
|
1552
|
+
* @returns {asserts node is Node}
|
|
1553
|
+
*/
|
|
1126
1554
|
function assertNode(node) {
|
|
1127
|
-
|
|
1128
|
-
throw new TypeError("Expected node, got `" + node + "`");
|
|
1129
|
-
}
|
|
1555
|
+
if (!isPlainObject(node) || typeof node.type !== "string") throw new TypeError("Expected node, got `" + node + "`");
|
|
1130
1556
|
}
|
|
1557
|
+
/**
|
|
1558
|
+
* Assert that `complete` is `true`.
|
|
1559
|
+
*
|
|
1560
|
+
* @param {string} name
|
|
1561
|
+
* @param {string} asyncName
|
|
1562
|
+
* @param {unknown} complete
|
|
1563
|
+
* @returns {asserts complete is true}
|
|
1564
|
+
*/
|
|
1131
1565
|
function assertDone(name, asyncName, complete) {
|
|
1132
|
-
|
|
1133
|
-
throw new Error(
|
|
1134
|
-
"`" + name + "` finished async. Use `" + asyncName + "` instead"
|
|
1135
|
-
);
|
|
1136
|
-
}
|
|
1566
|
+
if (!complete) throw new Error("`" + name + "` finished async. Use `" + asyncName + "` instead");
|
|
1137
1567
|
}
|
|
1568
|
+
/**
|
|
1569
|
+
* @param {VFileCompatible} [value]
|
|
1570
|
+
* @returns {VFile}
|
|
1571
|
+
*/
|
|
1138
1572
|
function vfile(value) {
|
|
1139
|
-
|
|
1573
|
+
return looksLikeAVFile(value) ? value : new VFile(value);
|
|
1140
1574
|
}
|
|
1575
|
+
/**
|
|
1576
|
+
* @param {VFileCompatible} [value]
|
|
1577
|
+
* @returns {value is VFile}
|
|
1578
|
+
*/
|
|
1141
1579
|
function looksLikeAVFile(value) {
|
|
1142
|
-
|
|
1143
|
-
value && typeof value === "object" && "message" in value && "messages" in value
|
|
1144
|
-
);
|
|
1580
|
+
return Boolean(value && typeof value === "object" && "message" in value && "messages" in value);
|
|
1145
1581
|
}
|
|
1582
|
+
/**
|
|
1583
|
+
* @param {unknown} [value]
|
|
1584
|
+
* @returns {value is VFileValue}
|
|
1585
|
+
*/
|
|
1146
1586
|
function looksLikeAVFileValue(value) {
|
|
1147
|
-
|
|
1587
|
+
return typeof value === "string" || (0, import_is_buffer.default)(value);
|
|
1148
1588
|
}
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1589
|
+
//#endregion
|
|
1590
|
+
//#region libs/unified-latex.ts
|
|
1591
|
+
/**
|
|
1592
|
+
* Use `unified()` to a string to an `Ast.Ast` and then pretty-print it.
|
|
1593
|
+
*/
|
|
1594
|
+
var processLatexViaUnified = (options) => {
|
|
1595
|
+
return unified().use(_unified_latex_unified_latex_util_parse.unifiedLatexFromString, options).use(_unified_latex_unified_latex_util_to_string.unifiedLatexStringCompiler, Object.assign({ pretty: true }, options));
|
|
1154
1596
|
};
|
|
1155
|
-
|
|
1156
|
-
|
|
1597
|
+
/**
|
|
1598
|
+
* Use `unified()` to a string to an `Ast.Ast` and then return it. This function
|
|
1599
|
+
* will not print/pretty-print the `Ast.Ast` back to a string.
|
|
1600
|
+
*/
|
|
1601
|
+
var processLatexToAstViaUnified = () => {
|
|
1602
|
+
return unified().use(_unified_latex_unified_latex_util_parse.unifiedLatexFromString).use(_unified_latex_unified_latex_util_parse.unifiedLatexAstComplier);
|
|
1157
1603
|
};
|
|
1604
|
+
//#endregion
|
|
1605
|
+
//#region index.ts
|
|
1606
|
+
/**
|
|
1607
|
+
* ## What is this?
|
|
1608
|
+
*
|
|
1609
|
+
* Functions parse strings to a `unified-latex` Abstract Syntax Tree (AST).
|
|
1610
|
+
*
|
|
1611
|
+
* ## When should I use this?
|
|
1612
|
+
*
|
|
1613
|
+
* If you have a string that you would like to parse to a `unified-latex` `Ast.Ast`, or
|
|
1614
|
+
* if you are building a plugin for `unified()` that manipulates LaTeX.
|
|
1615
|
+
*/
|
|
1616
|
+
//#endregion
|
|
1158
1617
|
exports.processLatexToAstViaUnified = processLatexToAstViaUnified;
|
|
1159
1618
|
exports.processLatexViaUnified = processLatexViaUnified;
|
|
1160
|
-
|
|
1619
|
+
|
|
1620
|
+
//# sourceMappingURL=index.cjs.map
|