| 1 | // trusted nonexecuting DSH composition reviewer; third-party notices: LICENSES.txt |
| 2 | var __defProp = Object.defineProperty; |
| 3 | var __getOwnPropNames = Object.getOwnPropertyNames; |
| 4 | var __esm = (fn, res, err) => function __init() { |
| 5 | if (err) throw err[0]; |
| 6 | try { |
| 7 | return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res; |
| 8 | } catch (e) { |
| 9 | throw err = [e], e; |
| 10 | } |
| 11 | }; |
| 12 | var __export = (target, all) => { |
| 13 | for (var name in all) |
| 14 | __defProp(target, name, { get: all[name], enumerable: true }); |
| 15 | }; |
| 16 | |
| 17 | // node_modules/@deepseek-ai/cosmokit/lib/index.js |
| 18 | function isNullable(value) { |
| 19 | return value === null || value === void 0; |
| 20 | } |
| 21 | function isNonNullable(value) { |
| 22 | return !isNullable(value); |
| 23 | } |
| 24 | function mapValues(object, transform) { |
| 25 | return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, transform(value, key)])); |
| 26 | } |
| 27 | function defineProperty(object, key, value) { |
| 28 | return Object.defineProperty(object, key, { |
| 29 | writable: true, |
| 30 | value, |
| 31 | enumerable: false |
| 32 | }); |
| 33 | } |
| 34 | function isVolatile(value) { |
| 35 | return typeof value === "object" && value !== null && write in value; |
| 36 | } |
| 37 | function is(type2, value) { |
| 38 | if (arguments.length === 1) return (value2) => is(type2, value2); |
| 39 | return type2 in globalThis && value instanceof globalThis[type2] || Object.prototype.toString.call(value).slice(8, -1) === type2; |
| 40 | } |
| 41 | function isArrayBufferLike(value) { |
| 42 | return is("ArrayBuffer", value) || is("SharedArrayBuffer", value); |
| 43 | } |
| 44 | function isArrayBufferSource(value) { |
| 45 | return isArrayBufferLike(value) || ArrayBuffer.isView(value); |
| 46 | } |
| 47 | function deepEqual(a, b, strict) { |
| 48 | const ancestors = /* @__PURE__ */ new Set(); |
| 49 | function compare(a2, b2) { |
| 50 | if (a2 === b2) return true; |
| 51 | if (isVolatile(a2) || isVolatile(b2)) return isVolatile(a2) && isVolatile(b2); |
| 52 | if (!strict && isNullable(a2) && isNullable(b2)) return true; |
| 53 | if (typeof a2 !== typeof b2 || typeof a2 !== "object" || !a2 || !b2) return false; |
| 54 | if (ancestors.has(a2)) return false; |
| 55 | function check(test, then) { |
| 56 | return test(a2) ? test(b2) ? then(a2, b2) : false : test(b2) ? false : void 0; |
| 57 | } |
| 58 | ancestors.add(a2); |
| 59 | try { |
| 60 | return check(Array.isArray, (a3, b3) => { |
| 61 | if (a3.length !== b3.length) return false; |
| 62 | for (let index = 0; index < a3.length; index++) if (!compare(a3[index], b3[index])) return false; |
| 63 | return true; |
| 64 | }) ?? check(is("Date"), (a3, b3) => a3.valueOf() === b3.valueOf()) ?? check(is("URL"), (a3, b3) => a3.href === b3.href) ?? check(is("RegExp"), (a3, b3) => a3.source === b3.source && a3.flags === b3.flags) ?? check(isArrayBufferLike, (a3, b3) => { |
| 65 | if (a3.byteLength !== b3.byteLength) return false; |
| 66 | const viewA = new Uint8Array(a3); |
| 67 | const viewB = new Uint8Array(b3); |
| 68 | for (let i2 = 0; i2 < viewA.length; i2++) if (viewA[i2] !== viewB[i2]) return false; |
| 69 | return true; |
| 70 | }) ?? ((!strict || [a2, b2].every((value) => Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)) && Object.keys({ |
| 71 | ...a2, |
| 72 | ...b2 |
| 73 | }).every((key) => compare(a2[key], b2[key]))); |
| 74 | } finally { |
| 75 | ancestors.delete(a2); |
| 76 | } |
| 77 | } |
| 78 | return compare(a, b); |
| 79 | } |
| 80 | function tokenize(source, delimiters, delimiter) { |
| 81 | const output = []; |
| 82 | let state = 0; |
| 83 | for (let i2 = 0; i2 < source.length; i2++) { |
| 84 | const code = source.charCodeAt(i2); |
| 85 | if (code >= 65 && code <= 90) { |
| 86 | if (state === 1) { |
| 87 | const next = source.charCodeAt(i2 + 1); |
| 88 | if (next >= 97 && next <= 122) output.push(delimiter); |
| 89 | output.push(code + 32); |
| 90 | } else { |
| 91 | if (state !== 0) output.push(delimiter); |
| 92 | output.push(code + 32); |
| 93 | } |
| 94 | state = 1; |
| 95 | } else if (code >= 97 && code <= 122) { |
| 96 | output.push(code); |
| 97 | state = 2; |
| 98 | } else if (delimiters.includes(code)) { |
| 99 | if (state !== 0) output.push(delimiter); |
| 100 | state = 0; |
| 101 | } else output.push(code); |
| 102 | } |
| 103 | return String.fromCharCode(...output); |
| 104 | } |
| 105 | function paramCase(source) { |
| 106 | return tokenize(source, [45, 95], 45); |
| 107 | } |
| 108 | var write, Binary, base64ToArrayBuffer, arrayBufferToBase64, hexToArrayBuffer, arrayBufferToHex, hyphenate, Time; |
| 109 | var init_lib = __esm({ |
| 110 | "node_modules/@deepseek-ai/cosmokit/lib/index.js"() { |
| 111 | write = /* @__PURE__ */ Symbol.for("cosmokit.volatile.write"); |
| 112 | (function(Binary2) { |
| 113 | Binary2.is = isArrayBufferLike; |
| 114 | Binary2.isSource = isArrayBufferSource; |
| 115 | function fromSource(source) { |
| 116 | if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength); |
| 117 | else return source; |
| 118 | } |
| 119 | Binary2.fromSource = fromSource; |
| 120 | function toBase64(source) { |
| 121 | source = fromSource(source); |
| 122 | if (typeof Buffer !== "undefined") return Buffer.from(source).toString("base64"); |
| 123 | let binary2 = ""; |
| 124 | const bytes = new Uint8Array(source); |
| 125 | for (let i2 = 0; i2 < bytes.byteLength; i2++) binary2 += String.fromCharCode(bytes[i2]); |
| 126 | return btoa(binary2); |
| 127 | } |
| 128 | Binary2.toBase64 = toBase64; |
| 129 | function fromBase64(source) { |
| 130 | if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "base64")); |
| 131 | return Uint8Array.from(atob(source), (c) => c.charCodeAt(0)); |
| 132 | } |
| 133 | Binary2.fromBase64 = fromBase64; |
| 134 | function toHex(source) { |
| 135 | source = fromSource(source); |
| 136 | if (typeof Buffer !== "undefined") return Buffer.from(source).toString("hex"); |
| 137 | return Array.from(new Uint8Array(source), (byte) => byte.toString(16).padStart(2, "0")).join(""); |
| 138 | } |
| 139 | Binary2.toHex = toHex; |
| 140 | function fromHex(source) { |
| 141 | if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "hex")); |
| 142 | const hex = source.length % 2 === 0 ? source : source.slice(0, source.length - 1); |
| 143 | const buffer = []; |
| 144 | for (let i2 = 0; i2 < hex.length; i2 += 2) buffer.push(parseInt(`${hex[i2]}${hex[i2 + 1]}`, 16)); |
| 145 | return Uint8Array.from(buffer).buffer; |
| 146 | } |
| 147 | Binary2.fromHex = fromHex; |
| 148 | })(Binary || (Binary = {})); |
| 149 | base64ToArrayBuffer = Binary.fromBase64; |
| 150 | arrayBufferToBase64 = Binary.toBase64; |
| 151 | hexToArrayBuffer = Binary.fromHex; |
| 152 | arrayBufferToHex = Binary.toHex; |
| 153 | hyphenate = paramCase; |
| 154 | (function(Time2) { |
| 155 | Time2.millisecond = 1; |
| 156 | Time2.second = 1e3; |
| 157 | Time2.minute = Time2.second * 60; |
| 158 | Time2.hour = Time2.minute * 60; |
| 159 | Time2.day = Time2.hour * 24; |
| 160 | Time2.week = Time2.day * 7; |
| 161 | let timezoneOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset(); |
| 162 | function setTimezoneOffset(offset2) { |
| 163 | timezoneOffset = offset2; |
| 164 | } |
| 165 | Time2.setTimezoneOffset = setTimezoneOffset; |
| 166 | function getTimezoneOffset() { |
| 167 | return timezoneOffset; |
| 168 | } |
| 169 | Time2.getTimezoneOffset = getTimezoneOffset; |
| 170 | function getDateNumber(date = /* @__PURE__ */ new Date(), offset2) { |
| 171 | if (typeof date === "number") date = new Date(date); |
| 172 | if (offset2 === void 0) offset2 = timezoneOffset; |
| 173 | return Math.floor((date.valueOf() / Time2.minute - offset2) / 1440); |
| 174 | } |
| 175 | Time2.getDateNumber = getDateNumber; |
| 176 | function fromDateNumber(value, offset2) { |
| 177 | const date = new Date(value * Time2.day); |
| 178 | if (offset2 === void 0) offset2 = timezoneOffset; |
| 179 | return new Date(+date + offset2 * Time2.minute); |
| 180 | } |
| 181 | Time2.fromDateNumber = fromDateNumber; |
| 182 | const numeric = /\d+(?:\.\d+)?/.source; |
| 183 | const timeRegExp = new RegExp(`^${[ |
| 184 | "w(?:eek(?:s)?)?", |
| 185 | "d(?:ay(?:s)?)?", |
| 186 | "h(?:our(?:s)?)?", |
| 187 | "m(?:in(?:ute)?(?:s)?)?", |
| 188 | "s(?:ec(?:ond)?(?:s)?)?" |
| 189 | ].map((unit) => `(${numeric}${unit})?`).join("")}$`); |
| 190 | function parseTime(source) { |
| 191 | const capture = timeRegExp.exec(source); |
| 192 | if (!capture) return 0; |
| 193 | return (parseFloat(capture[1]) * Time2.week || 0) + (parseFloat(capture[2]) * Time2.day || 0) + (parseFloat(capture[3]) * Time2.hour || 0) + (parseFloat(capture[4]) * Time2.minute || 0) + (parseFloat(capture[5]) * Time2.second || 0); |
| 194 | } |
| 195 | Time2.parseTime = parseTime; |
| 196 | function parseDate(date) { |
| 197 | const parsed = parseTime(date); |
| 198 | if (parsed) date = Date.now() + parsed; |
| 199 | else if (/^\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${date}`; |
| 200 | else if (/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).getFullYear()}-${date}`; |
| 201 | return date ? new Date(date) : /* @__PURE__ */ new Date(); |
| 202 | } |
| 203 | Time2.parseDate = parseDate; |
| 204 | function format(ms) { |
| 205 | const abs = Math.abs(ms); |
| 206 | if (abs >= Time2.day - Time2.hour / 2) return Math.round(ms / Time2.day) + "d"; |
| 207 | else if (abs >= Time2.hour - Time2.minute / 2) return Math.round(ms / Time2.hour) + "h"; |
| 208 | else if (abs >= Time2.minute - Time2.second / 2) return Math.round(ms / Time2.minute) + "m"; |
| 209 | else if (abs >= Time2.second) return Math.round(ms / Time2.second) + "s"; |
| 210 | return ms + "ms"; |
| 211 | } |
| 212 | Time2.format = format; |
| 213 | function toDigits(source, length = 2) { |
| 214 | return source.toString().padStart(length, "0"); |
| 215 | } |
| 216 | Time2.toDigits = toDigits; |
| 217 | function template(template2, time = /* @__PURE__ */ new Date()) { |
| 218 | return template2.replace("yyyy", time.getFullYear().toString()).replace("yy", time.getFullYear().toString().slice(2)).replace("MM", toDigits(time.getMonth() + 1)).replace("dd", toDigits(time.getDate())).replace("hh", toDigits(time.getHours())).replace("mm", toDigits(time.getMinutes())).replace("ss", toDigits(time.getSeconds())).replace("SSS", toDigits(time.getMilliseconds(), 3)); |
| 219 | } |
| 220 | Time2.template = template; |
| 221 | })(Time || (Time = {})); |
| 222 | } |
| 223 | }); |
| 224 | |
| 225 | // node_modules/@deepseek-ai/cordis/lib/index.js |
| 226 | function isConstructor(func) { |
| 227 | if (!func.prototype) return false; |
| 228 | if (func instanceof GeneratorFunction) return false; |
| 229 | if (AsyncGeneratorFunction !== Function && func instanceof AsyncGeneratorFunction) return false; |
| 230 | return true; |
| 231 | } |
| 232 | function joinPrototype(proto1, proto2) { |
| 233 | if (proto1 === Object.prototype) return proto2; |
| 234 | const result = Object.create(joinPrototype(Object.getPrototypeOf(proto1), proto2)); |
| 235 | for (const key of Reflect.ownKeys(proto1)) Object.defineProperty(result, key, Object.getOwnPropertyDescriptor(proto1, key)); |
| 236 | return result; |
| 237 | } |
| 238 | function isObject(value) { |
| 239 | return value && (typeof value === "object" || typeof value === "function"); |
| 240 | } |
| 241 | function getPropertyDescriptor(target, prop) { |
| 242 | let proto = target; |
| 243 | while (proto) { |
| 244 | const desc = Reflect.getOwnPropertyDescriptor(proto, prop); |
| 245 | if (desc) return desc; |
| 246 | proto = Object.getPrototypeOf(proto); |
| 247 | } |
| 248 | } |
| 249 | function getTraceable(ctx, value) { |
| 250 | if (!isObject(value)) return value; |
| 251 | if (Object.hasOwn(value, symbols.shadow)) return Object.getPrototypeOf(value); |
| 252 | const tracker = value[symbols.tracker]; |
| 253 | if (!tracker) return value; |
| 254 | return createTraceable(ctx, value, tracker); |
| 255 | } |
| 256 | function withProps(target, props) { |
| 257 | if (!props) return target; |
| 258 | return new Proxy(target, { |
| 259 | get: (target2, prop, receiver) => { |
| 260 | if (prop in props && prop !== "constructor") return Reflect.get(props, prop, receiver); |
| 261 | return Reflect.get(target2, prop, receiver); |
| 262 | }, |
| 263 | set: (target2, prop, value, receiver) => { |
| 264 | if (prop in props && prop !== "constructor") return Reflect.set(props, prop, value, receiver); |
| 265 | return Reflect.set(target2, prop, value, receiver); |
| 266 | } |
| 267 | }); |
| 268 | } |
| 269 | function withProp(target, prop, value) { |
| 270 | return withProps(target, Object.defineProperty(/* @__PURE__ */ Object.create(null), prop, { |
| 271 | value, |
| 272 | writable: false |
| 273 | })); |
| 274 | } |
| 275 | function createShadow(ctx, target, property, receiver) { |
| 276 | if (!property) return receiver; |
| 277 | const origin = Reflect.getOwnPropertyDescriptor(target, property)?.value; |
| 278 | if (!origin) return receiver; |
| 279 | return withProp(receiver, property, ctx.extend({ [symbols.shadow]: origin })); |
| 280 | } |
| 281 | function createShadowMethod(ctx, value, outer, shadow) { |
| 282 | return new Proxy(value, { apply: (target, thisArg, args) => { |
| 283 | if (thisArg === outer) thisArg = shadow; |
| 284 | return getTraceable(ctx, Reflect.apply(target, thisArg, args)); |
| 285 | } }); |
| 286 | } |
| 287 | function createTraceable(ctx, value, tracker) { |
| 288 | if (ctx[symbols.shadow] && !tracker.noShadow) ctx = Object.getPrototypeOf(ctx); |
| 289 | const proxy = new Proxy(value, { |
| 290 | get: (target, prop, receiver) => { |
| 291 | if (prop === symbols.original) return target; |
| 292 | if (prop === tracker.property) return ctx; |
| 293 | if (typeof prop === "symbol") return Reflect.get(target, prop, receiver); |
| 294 | if (tracker.associate && ctx.reflect.props[`${tracker.associate}.${prop}`]) return Reflect.get(ctx, `${tracker.associate}.${prop}`, withProp(ctx, symbols.receiver, receiver)); |
| 295 | let shadow, innerValue; |
| 296 | const desc = getPropertyDescriptor(target, prop); |
| 297 | if (desc && "value" in desc) innerValue = desc.value; |
| 298 | else { |
| 299 | shadow = createShadow(ctx, target, tracker.property, receiver); |
| 300 | innerValue = Reflect.get(target, prop, shadow); |
| 301 | } |
| 302 | const innerTracker = innerValue?.[symbols.tracker]; |
| 303 | if (innerTracker) return createTraceable(ctx, innerValue, innerTracker); |
| 304 | else if (!tracker.noShadow && typeof innerValue === "function") { |
| 305 | shadow ??= createShadow(ctx, target, tracker.property, receiver); |
| 306 | return createShadowMethod(ctx, innerValue, receiver, shadow); |
| 307 | } else return innerValue; |
| 308 | }, |
| 309 | set: (target, prop, value2, receiver) => { |
| 310 | if (prop === symbols.original) return false; |
| 311 | if (prop === tracker.property) return false; |
| 312 | if (typeof prop === "symbol") return Reflect.set(target, prop, value2, receiver); |
| 313 | if (tracker.associate && ctx.reflect.props[`${tracker.associate}.${prop}`]) return Reflect.set(ctx, `${tracker.associate}.${prop}`, value2, withProp(ctx, symbols.receiver, receiver)); |
| 314 | const shadow = createShadow(ctx, target, tracker.property, receiver); |
| 315 | return Reflect.set(target, prop, value2, shadow); |
| 316 | }, |
| 317 | apply: (target, thisArg, args) => { |
| 318 | return applyTraceable(proxy, target, thisArg, args); |
| 319 | } |
| 320 | }); |
| 321 | return proxy; |
| 322 | } |
| 323 | function applyTraceable(proxy, value, thisArg, args) { |
| 324 | if (!value[symbols.invoke]) return Reflect.apply(value, thisArg, args); |
| 325 | return value[symbols.invoke].apply(proxy, args); |
| 326 | } |
| 327 | function createCallable(name, proto, tracker) { |
| 328 | const self = function(...args) { |
| 329 | return applyTraceable(createTraceable(self["ctx"], self, tracker), self, this, args); |
| 330 | }; |
| 331 | defineProperty(self, "name", name); |
| 332 | return Object.setPrototypeOf(self, proto); |
| 333 | } |
| 334 | function handleError(info, reason, getOuterStack) { |
| 335 | const innerLines = info.error.stack.split("\n"); |
| 336 | if (typeof reason?.stack !== "string") { |
| 337 | const outerError = new Error(reason); |
| 338 | const lines2 = outerError.stack.split("\n"); |
| 339 | lines2.splice(1, Infinity, ...getOuterStack()); |
| 340 | outerError.stack = lines2.join("\n"); |
| 341 | throw outerError; |
| 342 | } |
| 343 | const lines = reason.stack.split("\n"); |
| 344 | let index = lines.indexOf(innerLines[2]); |
| 345 | if (index === -1) throw reason; |
| 346 | index -= info.offset; |
| 347 | while (index > 0) { |
| 348 | if (!lines[index - 1].endsWith(" (<anonymous>)")) break; |
| 349 | index -= 1; |
| 350 | } |
| 351 | lines.splice(index, Infinity, ...getOuterStack()); |
| 352 | reason.stack = lines.join("\n"); |
| 353 | throw reason; |
| 354 | } |
| 355 | function composeError(callback, getOuterStack = buildOuterStack()) { |
| 356 | const info = { |
| 357 | offset: 1, |
| 358 | error: /* @__PURE__ */ new Error() |
| 359 | }; |
| 360 | try { |
| 361 | const result = callback(info); |
| 362 | if (isObject(result) && "then" in result) return result.then(void 0, (reason) => handleError(info, reason, getOuterStack)); |
| 363 | else return result; |
| 364 | } catch (reason) { |
| 365 | handleError(info, reason, getOuterStack); |
| 366 | } |
| 367 | } |
| 368 | function buildOuterStack(offset2 = 0) { |
| 369 | const outerError = /* @__PURE__ */ new Error(); |
| 370 | return () => outerError.stack.split("\n").slice(3 + offset2); |
| 371 | } |
| 372 | function isBailed(value) { |
| 373 | return value !== null && value !== false && value !== void 0; |
| 374 | } |
| 375 | function isAggregateError(error) { |
| 376 | return error instanceof Error && Array.isArray(error["errors"]); |
| 377 | } |
| 378 | function enhanceError(error) { |
| 379 | const lines = error.stack.split("\n"); |
| 380 | lines.splice(0, 2, `Error: ${error.message}`); |
| 381 | error.stack = lines.join("\n"); |
| 382 | return error; |
| 383 | } |
| 384 | function isSpecialProperty(prop) { |
| 385 | return typeof prop === "symbol" || RESERVED_WORDS.includes(prop) || parseInt(prop).toString() === prop || prop.startsWith("_"); |
| 386 | } |
| 387 | function resolveConfig(runtime, config) { |
| 388 | if (!runtime.Config) return config; |
| 389 | const result = runtime.Config["~standard"].validate(config); |
| 390 | if ("then" in result) throw new TypeError("Async config validation is not supported"); |
| 391 | if (result.issues) throw new ValidationError(result.issues); |
| 392 | else return result.value; |
| 393 | } |
| 394 | function runDisposable(dispose) { |
| 395 | const result = dispose(); |
| 396 | return effectInertia.get(dispose)?.() ?? result; |
| 397 | } |
| 398 | function emitPluginDisposed(context, fiber) { |
| 399 | const args = ["internal/plugin", fiber]; |
| 400 | let callbacks; |
| 401 | try { |
| 402 | callbacks = context.events.dispatch("emit", args); |
| 403 | } catch (error) { |
| 404 | context.logger.error(error); |
| 405 | return; |
| 406 | } |
| 407 | for (const callback of callbacks) try { |
| 408 | const returned = callback(...args); |
| 409 | Promise.resolve(returned).catch((error) => context.logger.error(error)); |
| 410 | } catch (error) { |
| 411 | context.logger.error(error); |
| 412 | } |
| 413 | } |
| 414 | function isApplicable(object) { |
| 415 | return object && typeof object === "object" && typeof object.apply === "function"; |
| 416 | } |
| 417 | function Inject(name, config) { |
| 418 | return function(value, decorator) { |
| 419 | if (decorator.kind === "class") { |
| 420 | if (!Object.hasOwn(value, "inject")) { |
| 421 | defineProperty(value, "inject", Object.create(Object.getPrototypeOf(value).inject ?? null)); |
| 422 | defineProperty(value.inject, symbols.checkProto, true); |
| 423 | } |
| 424 | value.inject[name] = config; |
| 425 | } else if (decorator.kind === "method") { |
| 426 | const inject = (value[symbols.metadata] ??= {}).inject ??= /* @__PURE__ */ Object.create(null); |
| 427 | inject[name] = config; |
| 428 | decorator.addInitializer(function() { |
| 429 | const property = this[symbols.tracker]?.property; |
| 430 | (this[symbols.initHooks] ??= []).push(() => { |
| 431 | this.ctx.inject(inject, (ctx) => { |
| 432 | return value.call(property ? withProps(this, { [property]: ctx }) : this); |
| 433 | }); |
| 434 | }); |
| 435 | }); |
| 436 | } else throw new Error("@Inject() can only be used on class or class methods"); |
| 437 | }; |
| 438 | } |
| 439 | var DisposableList, symbols, GeneratorFunction, AsyncGeneratorFunction, EventsService, defaultFormatters, Logger, c16, c256, LoggerService, RESERVED_WORDS, ReflectService, kValidationError, ValidationError, effectInertia, CordisError, INACTIVE, Fiber, RegistryService, Context, Service; |
| 440 | var init_lib2 = __esm({ |
| 441 | "node_modules/@deepseek-ai/cordis/lib/index.js"() { |
| 442 | init_lib(); |
| 443 | DisposableList = class { |
| 444 | sn = 0; |
| 445 | map = /* @__PURE__ */ new Map(); |
| 446 | weak = /* @__PURE__ */ new WeakMap(); |
| 447 | get length() { |
| 448 | return this.map.size; |
| 449 | } |
| 450 | push(value) { |
| 451 | const sn = ++this.sn; |
| 452 | this.map.set(sn, value); |
| 453 | this.weak.set(value, sn); |
| 454 | return () => this.map.delete(sn); |
| 455 | } |
| 456 | delete(value) { |
| 457 | const sn = this.weak.get(value); |
| 458 | if (!sn) return false; |
| 459 | return this.map.delete(sn); |
| 460 | } |
| 461 | clear() { |
| 462 | const values = [...this.map.values()]; |
| 463 | this.map.clear(); |
| 464 | return values.reverse(); |
| 465 | } |
| 466 | [Symbol.iterator]() { |
| 467 | return this.map.values(); |
| 468 | } |
| 469 | [/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() { |
| 470 | return [...this]; |
| 471 | } |
| 472 | }; |
| 473 | symbols = { |
| 474 | shadow: /* @__PURE__ */ Symbol.for("cordis.shadow"), |
| 475 | receiver: /* @__PURE__ */ Symbol.for("cordis.receiver"), |
| 476 | original: /* @__PURE__ */ Symbol.for("cordis.original"), |
| 477 | metadata: /* @__PURE__ */ Symbol.for("cordis.metadata"), |
| 478 | initHooks: /* @__PURE__ */ Symbol.for("cordis.initHooks"), |
| 479 | checkProto: /* @__PURE__ */ Symbol.for("cordis.checkProto"), |
| 480 | effect: /* @__PURE__ */ Symbol.for("cordis.effect"), |
| 481 | filter: /* @__PURE__ */ Symbol.for("cordis.filter"), |
| 482 | isolate: /* @__PURE__ */ Symbol.for("cordis.isolate"), |
| 483 | intercept: /* @__PURE__ */ Symbol.for("cordis.intercept"), |
| 484 | init: /* @__PURE__ */ Symbol.for("cordis.init"), |
| 485 | check: /* @__PURE__ */ Symbol.for("cordis.check"), |
| 486 | config: /* @__PURE__ */ Symbol.for("cordis.config"), |
| 487 | invoke: /* @__PURE__ */ Symbol.for("cordis.invoke"), |
| 488 | extend: /* @__PURE__ */ Symbol.for("cordis.extend"), |
| 489 | tracker: /* @__PURE__ */ Symbol.for("cordis.tracker"), |
| 490 | resolveConfig: /* @__PURE__ */ Symbol.for("cordis.resolveConfig") |
| 491 | }; |
| 492 | GeneratorFunction = function* () { |
| 493 | }.constructor; |
| 494 | AsyncGeneratorFunction = async function* () { |
| 495 | }.constructor; |
| 496 | EventsService = class { |
| 497 | ctx; |
| 498 | _hooks = {}; |
| 499 | constructor(ctx) { |
| 500 | this.ctx = ctx; |
| 501 | defineProperty(this, symbols.tracker, { |
| 502 | property: "ctx", |
| 503 | noShadow: true |
| 504 | }); |
| 505 | this.on("internal/listener", function(name, listener, options) { |
| 506 | if (name === "internal/update" && !options.global) return (this.fiber._hooks["internal/update"] ??= new DisposableList())[options.prepend ? "unshift" : "push"](listener); |
| 507 | }); |
| 508 | this.on("internal/update", function(config, noSave, next) { |
| 509 | const cbs = [...this._hooks["internal/update"] || []]; |
| 510 | const _next = () => { |
| 511 | return (cbs.shift() ?? next).call(this, config, noSave, _next); |
| 512 | }; |
| 513 | return _next(); |
| 514 | }, { |
| 515 | global: true, |
| 516 | prepend: true |
| 517 | }); |
| 518 | } |
| 519 | /** |
| 520 | * Resolve listeners for one dispatch and apply context filtering. |
| 521 | * |
| 522 | * @param type — the dispatch mode, reported on `internal/dispatch`. |
| 523 | * @param args — the raw dispatch arguments; consumed up to the event name. |
| 524 | * @returns the matching listener callbacks, bound to the dispatch `this`. |
| 525 | */ |
| 526 | dispatch(type2, args) { |
| 527 | const thisArg = typeof args[0] === "object" || typeof args[0] === "function" ? args.shift() : null; |
| 528 | const name = args.shift(); |
| 529 | if (!name.startsWith("internal/")) this.emit("internal/dispatch", type2, name, args, thisArg); |
| 530 | const filter = thisArg?.[Context.filter]; |
| 531 | return (this._hooks[name] || []).filter((hook) => hook.global || !filter || filter.call(thisArg, hook.ctx)).map((hook) => hook.callback.bind(thisArg)); |
| 532 | } |
| 533 | /** |
| 534 | * Run listeners concurrently and wait for all of them. |
| 535 | * |
| 536 | * @param args — optional `this`, the event name, then listener arguments. |
| 537 | * @returns a promise resolving once every listener has settled. |
| 538 | */ |
| 539 | async parallel(...args) { |
| 540 | const errors = (await Promise.allSettled(this.dispatch("emit", args).map(async (cb) => cb(...args)))).filter((result) => result.status === "rejected"); |
| 541 | if (errors.length) throw new AggregateError(errors.map((error) => error.reason)); |
| 542 | } |
| 543 | /** |
| 544 | * Run listeners synchronously without waiting for returned promises. |
| 545 | * |
| 546 | * @param args — optional `this`, the event name, then listener arguments. |
| 547 | */ |
| 548 | emit(...args) { |
| 549 | this.dispatch("emit", args).map((cb) => cb(...args)); |
| 550 | } |
| 551 | /** |
| 552 | * Run listeners in order, awaiting each, until one returns a bail value. |
| 553 | * |
| 554 | * @param args — optional `this`, the event name, then listener arguments. |
| 555 | * @returns the first bail value (see {@link isBailed}), if any. |
| 556 | */ |
| 557 | async serial(...args) { |
| 558 | for (const cb of this.dispatch("serial", args)) { |
| 559 | const result = await cb(...args); |
| 560 | if (isBailed(result)) return result; |
| 561 | } |
| 562 | } |
| 563 | /** |
| 564 | * Run listeners synchronously until one returns a bail value. |
| 565 | * |
| 566 | * @param args — optional `this`, the event name, then listener arguments. |
| 567 | * @returns the first bail value (see {@link isBailed}), if any. |
| 568 | */ |
| 569 | bail(...args) { |
| 570 | for (const cb of this.dispatch("bail", args)) { |
| 571 | const result = cb(...args); |
| 572 | if (isBailed(result)) return result; |
| 573 | } |
| 574 | } |
| 575 | /** |
| 576 | * Compose listeners around the final `next` callback. |
| 577 | * |
| 578 | * The last dispatch argument is treated as the innermost `next`. Listeners |
| 579 | * run outermost-first; a listener that does not call `next()` vetoes the |
| 580 | * rest of the chain, including the built-in behavior. |
| 581 | * |
| 582 | * @param args — optional `this`, the event name, listener arguments, then `next`. |
| 583 | * @returns the outermost listener's return value. |
| 584 | */ |
| 585 | waterfall(...args) { |
| 586 | const cbs = this.dispatch("waterfall", args); |
| 587 | const inner = args.pop(); |
| 588 | const next = () => { |
| 589 | return (cbs.shift() ?? inner)(...args); |
| 590 | }; |
| 591 | args.push(next); |
| 592 | return next(); |
| 593 | } |
| 594 | /** |
| 595 | * Store a listener record as an effect on the current fiber. |
| 596 | * |
| 597 | * @param label — effect label shown in fiber diagnostics. |
| 598 | * @param hooks — the listener list for one event. |
| 599 | * @param callback — the listener to store. |
| 600 | * @param options — placement and filtering options. |
| 601 | * @returns a disposer that unregisters the listener. |
| 602 | */ |
| 603 | register(label, hooks, callback, options) { |
| 604 | const method = options.prepend ? "unshift" : "push"; |
| 605 | return this.ctx.fiber.effect(() => { |
| 606 | hooks[method]({ |
| 607 | ctx: this.ctx, |
| 608 | callback, |
| 609 | ...options |
| 610 | }); |
| 611 | return () => this.unregister(hooks, callback); |
| 612 | }, label); |
| 613 | } |
| 614 | /** |
| 615 | * Remove a stored listener record. |
| 616 | * |
| 617 | * @param hooks — the listener list for one event. |
| 618 | * @param callback — the listener to remove. |
| 619 | * @returns `true` if the listener was found and removed. |
| 620 | */ |
| 621 | unregister(hooks, callback) { |
| 622 | const index = hooks.findIndex((hook) => hook.callback === callback); |
| 623 | if (index >= 0) { |
| 624 | hooks.splice(index, 1); |
| 625 | return true; |
| 626 | } |
| 627 | } |
| 628 | /** |
| 629 | * Register an event listener owned by the current fiber. |
| 630 | * |
| 631 | * The listener is removed automatically when the fiber unloads. Throws |
| 632 | * `CordisError('INACTIVE_EFFECT')` if the fiber is already disposed. |
| 633 | * |
| 634 | * @param name — the event name to listen for. |
| 635 | * @param listener — called with the dispatch arguments. |
| 636 | * @param options — listener options; a boolean is shorthand for `prepend`. |
| 637 | * @returns a disposer removing the listener; `true` if it was still registered. |
| 638 | */ |
| 639 | on(name, listener, options) { |
| 640 | if (typeof options !== "object") options = { prepend: options }; |
| 641 | this.ctx.fiber.assertActive(); |
| 642 | listener = this.ctx.reflect.bind(listener); |
| 643 | const result = this.bail(this.ctx, "internal/listener", name, listener, options); |
| 644 | if (result) return result; |
| 645 | const hooks = this._hooks[name] ||= []; |
| 646 | const label = `ctx.on(${typeof name === "string" ? JSON.stringify(name) : name.toString()})`; |
| 647 | return this.register(label, hooks, listener, options); |
| 648 | } |
| 649 | /** |
| 650 | * Register an event listener that disposes itself after the first call. |
| 651 | * |
| 652 | * @param name — the event name to listen for. |
| 653 | * @param listener — called at most once with the dispatch arguments. |
| 654 | * @param options — listener options; a boolean is shorthand for `prepend`. |
| 655 | * @returns a disposer removing the listener; `true` if it was still registered. |
| 656 | */ |
| 657 | once(name, listener, options) { |
| 658 | const dispose = this.on(name, function(...args) { |
| 659 | dispose(); |
| 660 | return listener.apply(this, args); |
| 661 | }, options); |
| 662 | return dispose; |
| 663 | } |
| 664 | }; |
| 665 | defaultFormatters = { |
| 666 | s: (value) => String(value), |
| 667 | d: (value) => Math.trunc(Number(value)), |
| 668 | i: (value) => Math.trunc(Number(value)), |
| 669 | f: (value) => Number(value), |
| 670 | o: (value) => JSON.stringify(value), |
| 671 | O: (value) => JSON.stringify(value), |
| 672 | c: () => "", |
| 673 | C: (value, exporter, message) => { |
| 674 | return Logger.color(exporter, Logger.code(message.name, exporter.colors), value); |
| 675 | } |
| 676 | }; |
| 677 | Logger = class { |
| 678 | service; |
| 679 | static color(exporter, code, value, decoration = "") { |
| 680 | if (!exporter.colors) return "" + value; |
| 681 | return `\x1B[3${code < 8 ? code : "8;5;" + code}${exporter.colors >= 2 ? decoration : ""}m${value}\x1B[0m`; |
| 682 | } |
| 683 | static code(name, level) { |
| 684 | let hash2 = 0; |
| 685 | for (let i2 = 0; i2 < name.length; i2++) { |
| 686 | hash2 = (hash2 << 3) - hash2 + name.charCodeAt(i2) + 13; |
| 687 | hash2 |= 0; |
| 688 | } |
| 689 | const colors = !level ? [] : level >= 2 ? c256 : c16; |
| 690 | return colors[Math.abs(hash2) % colors.length]; |
| 691 | } |
| 692 | static format(exporter, message) { |
| 693 | const args = message.args.slice(); |
| 694 | if (args[0] instanceof Error) { |
| 695 | args[0] = args[0].stack || args[0].message; |
| 696 | args.unshift("%s"); |
| 697 | } else if (typeof args[0] !== "string") args.unshift("%o"); |
| 698 | let format = args.shift(); |
| 699 | format = format.replace(/%([a-zA-Z%])/g, (match, char) => { |
| 700 | if (match === "%%") return "%"; |
| 701 | const formatter = exporter.formatters?.[char] ?? defaultFormatters[char]; |
| 702 | if (typeof formatter === "function") return formatter(args.shift(), exporter, message); |
| 703 | return match; |
| 704 | }); |
| 705 | const oFormatter = exporter.formatters?.o ?? defaultFormatters.o; |
| 706 | for (let arg of args) { |
| 707 | if (typeof arg === "object" && arg) arg = oFormatter(arg, exporter, message); |
| 708 | format += " " + arg; |
| 709 | } |
| 710 | const { maxLength = 10240 } = exporter; |
| 711 | return format.split(/\r?\n/g).map((line) => { |
| 712 | return line.slice(0, maxLength) + (line.length > maxLength ? "..." : ""); |
| 713 | }).join("\n"); |
| 714 | } |
| 715 | constructor(options, service) { |
| 716 | this.service = service; |
| 717 | Object.assign(this, options); |
| 718 | this.error = this._method("error", 0); |
| 719 | this.info = this._method("info", 1); |
| 720 | this.warn = this._method("warn", 2); |
| 721 | this.debug = this._method("debug", 3); |
| 722 | } |
| 723 | _method(type2, level) { |
| 724 | return (...args) => { |
| 725 | if (args.length === 1 && args[0] instanceof Error) { |
| 726 | if (args[0].cause) this[type2](args[0].cause); |
| 727 | else if (isAggregateError(args[0])) { |
| 728 | args[0].errors.forEach((error) => this[type2](error)); |
| 729 | return; |
| 730 | } |
| 731 | } |
| 732 | const sn = ++this.service._snMessage; |
| 733 | const ts = Date.now(); |
| 734 | for (const exporter of this.service.exporters.values()) { |
| 735 | if ((exporter.levels?.[this.name] ?? exporter.levels?.default ?? this.level ?? 1) < level) continue; |
| 736 | const message = { |
| 737 | sn, |
| 738 | ts, |
| 739 | type: type2, |
| 740 | level, |
| 741 | name: this.name, |
| 742 | ...this.meta, |
| 743 | args |
| 744 | }; |
| 745 | exporter.export(message); |
| 746 | } |
| 747 | }; |
| 748 | } |
| 749 | }; |
| 750 | c16 = [ |
| 751 | 6, |
| 752 | 2, |
| 753 | 3, |
| 754 | 4, |
| 755 | 5, |
| 756 | 1 |
| 757 | ]; |
| 758 | c256 = [ |
| 759 | 20, |
| 760 | 21, |
| 761 | 26, |
| 762 | 27, |
| 763 | 32, |
| 764 | 33, |
| 765 | 38, |
| 766 | 39, |
| 767 | 40, |
| 768 | 41, |
| 769 | 42, |
| 770 | 43, |
| 771 | 44, |
| 772 | 45, |
| 773 | 56, |
| 774 | 57, |
| 775 | 62, |
| 776 | 63, |
| 777 | 68, |
| 778 | 69, |
| 779 | 74, |
| 780 | 75, |
| 781 | 76, |
| 782 | 77, |
| 783 | 78, |
| 784 | 79, |
| 785 | 80, |
| 786 | 81, |
| 787 | 92, |
| 788 | 93, |
| 789 | 98, |
| 790 | 99, |
| 791 | 112, |
| 792 | 113, |
| 793 | 129, |
| 794 | 134, |
| 795 | 135, |
| 796 | 148, |
| 797 | 149, |
| 798 | 160, |
| 799 | 161, |
| 800 | 162, |
| 801 | 163, |
| 802 | 164, |
| 803 | 165, |
| 804 | 166, |
| 805 | 167, |
| 806 | 168, |
| 807 | 169, |
| 808 | 170, |
| 809 | 171, |
| 810 | 172, |
| 811 | 173, |
| 812 | 178, |
| 813 | 179, |
| 814 | 184, |
| 815 | 185, |
| 816 | 196, |
| 817 | 197, |
| 818 | 198, |
| 819 | 199, |
| 820 | 200, |
| 821 | 201, |
| 822 | 202, |
| 823 | 203, |
| 824 | 204, |
| 825 | 205, |
| 826 | 206, |
| 827 | 207, |
| 828 | 208, |
| 829 | 209, |
| 830 | 214, |
| 831 | 215, |
| 832 | 220, |
| 833 | 221 |
| 834 | ]; |
| 835 | LoggerService = class LoggerService2 { |
| 836 | bufferSize = 1e3; |
| 837 | buffer = []; |
| 838 | ctx; |
| 839 | _snMessage = 0; |
| 840 | _snExporter = 0; |
| 841 | exporters = /* @__PURE__ */ new Map(); |
| 842 | constructor(ctx) { |
| 843 | const tracker = { |
| 844 | property: "ctx", |
| 845 | noShadow: true |
| 846 | }; |
| 847 | const self = createCallable("logger", joinPrototype(Object.getPrototypeOf(this), Function.prototype), tracker); |
| 848 | Object.assign(self, this); |
| 849 | self.ctx = ctx; |
| 850 | defineProperty(self, symbols.tracker, tracker); |
| 851 | self.exporter({ |
| 852 | colors: 3, |
| 853 | export: (message) => { |
| 854 | self.buffer.push(message); |
| 855 | if (self.buffer.length > self.bufferSize) self.buffer = self.buffer.slice(-self.bufferSize); |
| 856 | } |
| 857 | }); |
| 858 | return self; |
| 859 | } |
| 860 | /** |
| 861 | * Register an exporter and dispose it with the current fiber. |
| 862 | * |
| 863 | * @param exporter — the sink that receives structured log messages. |
| 864 | * @returns a disposer that removes the exporter. |
| 865 | */ |
| 866 | exporter(exporter) { |
| 867 | return this.ctx.effect(() => { |
| 868 | const id = ++this._snExporter; |
| 869 | this.exporters.set(id, exporter); |
| 870 | return () => this.exporters.delete(id); |
| 871 | }, "ctx.logger.exporter()"); |
| 872 | } |
| 873 | _resolveConfig() { |
| 874 | let intercept = this.ctx[symbols.intercept]; |
| 875 | const configs = []; |
| 876 | while ("logger" in intercept) { |
| 877 | if (Object.hasOwn(intercept, "logger")) configs.unshift(intercept["logger"]); |
| 878 | intercept = Object.getPrototypeOf(intercept); |
| 879 | } |
| 880 | return Object.assign({}, ...configs); |
| 881 | } |
| 882 | [symbols.invoke](name) { |
| 883 | const config = this._resolveConfig(); |
| 884 | const fiber = (this.ctx[symbols.shadow] ?? this.ctx).fiber; |
| 885 | name ??= config.name; |
| 886 | name ??= hyphenate(fiber.name); |
| 887 | return new Logger({ |
| 888 | name, |
| 889 | level: config.level, |
| 890 | meta: { fiber: new WeakRef(fiber) } |
| 891 | }, this); |
| 892 | } |
| 893 | static { |
| 894 | for (const type2 of [ |
| 895 | "error", |
| 896 | "info", |
| 897 | "warn", |
| 898 | "debug" |
| 899 | ]) LoggerService2.prototype[type2] = function(...args) { |
| 900 | return this()[type2](...args); |
| 901 | }; |
| 902 | } |
| 903 | }; |
| 904 | RESERVED_WORDS = ["prototype", "then"]; |
| 905 | ReflectService = class { |
| 906 | ctx; |
| 907 | /** Proxy traps implementing service resolution for every context object. */ |
| 908 | static handler = { |
| 909 | get: (target, prop, ctx) => { |
| 910 | if (isSpecialProperty(prop)) return Reflect.get(target, prop, ctx); |
| 911 | if (Reflect.has(target, prop)) return getTraceable(ctx, Reflect.get(target, prop, ctx)); |
| 912 | const error = /* @__PURE__ */ new Error(`cannot get property "${prop}" without inject`); |
| 913 | try { |
| 914 | const def = target.reflect.props[prop]; |
| 915 | if (def?.type === "accessor") return def.get.call(ctx, ctx[symbols.receiver], error); |
| 916 | if (!ctx.fiber.runtime) return ctx.reflect.get(prop, false); |
| 917 | return ctx.events.waterfall("internal/get", ctx, prop, error, () => { |
| 918 | const key = target[symbols.isolate][prop]; |
| 919 | let fiber = (ctx[symbols.shadow] ?? ctx).fiber; |
| 920 | while (true) { |
| 921 | const impl = fiber.store?.[prop]; |
| 922 | if (impl) return getTraceable(ctx, impl.value); |
| 923 | if (prop in fiber.inject) { |
| 924 | error.message = `cannot get required service "${prop}" in inactive context`; |
| 925 | throw error; |
| 926 | } |
| 927 | if (!fiber.runtime) throw error; |
| 928 | if (fiber.parent[symbols.isolate][prop] !== key) throw error; |
| 929 | fiber = fiber.parent.fiber; |
| 930 | } |
| 931 | }); |
| 932 | } catch (e) { |
| 933 | throw e === error ? enhanceError(e) : e; |
| 934 | } |
| 935 | }, |
| 936 | set: (target, prop, value, ctx) => { |
| 937 | if (isSpecialProperty(prop)) return Reflect.set(target, prop, value, ctx); |
| 938 | const error = /* @__PURE__ */ new Error(`cannot set property "${prop}" without provide`); |
| 939 | const def = target.reflect.props[prop]; |
| 940 | if (!def) { |
| 941 | if (!ctx.fiber.runtime) return Reflect.set(target, prop, value, ctx); |
| 942 | throw enhanceError(error); |
| 943 | } |
| 944 | try { |
| 945 | if (def.type === "accessor") { |
| 946 | if (!def.set) return false; |
| 947 | return def.set.call(ctx, value, ctx[symbols.receiver], error); |
| 948 | } |
| 949 | return ctx.events.waterfall("internal/set", ctx, prop, value, error, () => { |
| 950 | return ctx.reflect.set(prop, value, error); |
| 951 | }); |
| 952 | } catch (e) { |
| 953 | throw e === error ? enhanceError(e) : e; |
| 954 | } |
| 955 | }, |
| 956 | has: (target, prop) => { |
| 957 | if (isSpecialProperty(prop)) return Reflect.has(target, prop); |
| 958 | if (Reflect.has(target, prop)) return true; |
| 959 | return !!target.reflect.props[prop]; |
| 960 | } |
| 961 | }; |
| 962 | /** Service implementations, keyed by isolation label. */ |
| 963 | store = /* @__PURE__ */ Object.create(null); |
| 964 | /** Declared context properties (services and accessors), by name. */ |
| 965 | props = /* @__PURE__ */ Object.create(null); |
| 966 | constructor(ctx) { |
| 967 | this.ctx = ctx; |
| 968 | defineProperty(this, symbols.tracker, { |
| 969 | property: "ctx", |
| 970 | noShadow: true |
| 971 | }); |
| 972 | this.mixin("reflect", [ |
| 973 | "get", |
| 974 | "set", |
| 975 | "provide", |
| 976 | "accessor", |
| 977 | "mixin" |
| 978 | ]); |
| 979 | this.mixin("fiber", ["runtime", "effect"]); |
| 980 | this.mixin("registry", ["inject", "plugin"]); |
| 981 | this.mixin("events", [ |
| 982 | "on", |
| 983 | "once", |
| 984 | "parallel", |
| 985 | "emit", |
| 986 | "serial", |
| 987 | "bail", |
| 988 | "waterfall" |
| 989 | ]); |
| 990 | } |
| 991 | /** |
| 992 | * Read a service from the store without the inject requirement. |
| 993 | * |
| 994 | * @param name — the service name. |
| 995 | * @param strict — when `true`, only return implementations whose providing |
| 996 | * fiber is currently active. |
| 997 | * @returns the service value, or `undefined` when not (yet) provided. |
| 998 | */ |
| 999 | get(name, strict = true) { |
| 1000 | return getTraceable(this.ctx, this._getImpl(name, strict)?.value); |
| 1001 | } |
| 1002 | _getImpl(name, strict = true) { |
| 1003 | const key = this.ctx[symbols.isolate][name]; |
| 1004 | const impl = key && this.store[key]; |
| 1005 | if (!impl) return; |
| 1006 | if (strict && impl.fiber.state !== 2) return; |
| 1007 | return impl; |
| 1008 | } |
| 1009 | /** |
| 1010 | * Overwrite a provided service's value. |
| 1011 | * |
| 1012 | * @param name — the service name. |
| 1013 | * @param value — the new service value. |
| 1014 | * @param error — carrier for the caller stack in diagnostics. |
| 1015 | * @returns `true` on success. |
| 1016 | * @throws when `name` was never provided, or was provided by another fiber. |
| 1017 | */ |
| 1018 | set(name, value, error) { |
| 1019 | const key = this.ctx[symbols.isolate][name]; |
| 1020 | const impl = this.store[key]; |
| 1021 | if (!impl) throw new Error(`cannot set property "${name}" without provide`); |
| 1022 | if (impl.fiber !== this.ctx.fiber) throw new Error(`cannot set property "${name}" in multiple fibers`); |
| 1023 | impl.value = value; |
| 1024 | return true; |
| 1025 | } |
| 1026 | /** |
| 1027 | * Register a service implementation owned by the current fiber. |
| 1028 | * |
| 1029 | * See the `ctx.provide()` overload above for the full contract. |
| 1030 | * |
| 1031 | * @param name — the service name. |
| 1032 | * @param value — the service value. |
| 1033 | * @param check — optional availability predicate for dependents. |
| 1034 | * @returns a disposer that unregisters the service. |
| 1035 | */ |
| 1036 | provide(name, value, check) { |
| 1037 | return this.ctx.fiber.effect(() => { |
| 1038 | if (!this.props[name]) this.props[name] ??= { type: "service" }; |
| 1039 | else if (this.props[name].type !== "service") throw new Error(`property "${name}" is already declared as ${this.props[name].type}`); |
| 1040 | this.props[name] = { type: "service" }; |
| 1041 | this.ctx.root[symbols.isolate][name] ??= Symbol(name); |
| 1042 | const key = this.ctx[symbols.isolate][name]; |
| 1043 | const impl = { |
| 1044 | name, |
| 1045 | value, |
| 1046 | fiber: this.ctx.fiber, |
| 1047 | check |
| 1048 | }; |
| 1049 | if (this.store[key]) throw new Error(`service "${name}" has been registered at <${this.store[key].fiber.name}>`); |
| 1050 | this.store[key] = impl; |
| 1051 | this.ctx.fiber.store[name] = impl; |
| 1052 | if (this.ctx.fiber.state === 2) this.notify([name]); |
| 1053 | return async () => { |
| 1054 | delete this.store[key]; |
| 1055 | const fibers = this.notify([name]); |
| 1056 | await Promise.allSettled(fibers.map((fiber) => fiber.await())); |
| 1057 | delete this.ctx.fiber.store[name]; |
| 1058 | }; |
| 1059 | }, `ctx.provide(${JSON.stringify(name)})`); |
| 1060 | } |
| 1061 | /** |
| 1062 | * Re-evaluate every fiber that requires one of the given services. |
| 1063 | * |
| 1064 | * @param names — the service names that changed. |
| 1065 | * @param filter — restricts notification to matching isolation scopes. |
| 1066 | * @returns the fibers whose dependency state was refreshed. |
| 1067 | */ |
| 1068 | notify(names, filter = (ctx, name) => ctx[symbols.isolate][name] === this.ctx[symbols.isolate][name]) { |
| 1069 | const fibers = []; |
| 1070 | for (const runtime of this.ctx.registry.values()) for (const fiber of runtime.fibers) { |
| 1071 | let hasUpdate = false; |
| 1072 | for (const name of names) { |
| 1073 | if (!(name in fiber.inject)) continue; |
| 1074 | if (!filter(fiber.ctx, name)) continue; |
| 1075 | hasUpdate = true; |
| 1076 | fiber._checkImpl(name); |
| 1077 | } |
| 1078 | if (!hasUpdate) continue; |
| 1079 | fiber._refresh(); |
| 1080 | fibers.push(fiber); |
| 1081 | } |
| 1082 | for (const name of names) { |
| 1083 | const self = Object.create(this.ctx); |
| 1084 | self[symbols.filter] = (target) => filter(target, name); |
| 1085 | this.ctx.events.emit(self, "internal/service", name, this._getImpl(name, false)?.value); |
| 1086 | } |
| 1087 | return fibers; |
| 1088 | } |
| 1089 | /** |
| 1090 | * Define a computed context property backed by get/set hooks. |
| 1091 | * |
| 1092 | * @param name — the context property name. |
| 1093 | * @param options — the `get` hook and optional `set` hook. |
| 1094 | * @returns a disposer that removes the accessor. |
| 1095 | */ |
| 1096 | accessor(name, options) { |
| 1097 | return this.ctx.fiber.effect(() => { |
| 1098 | if (name in this.props) throw new Error(`property "${name}" is already declared as ${this.props[name].type}`); |
| 1099 | this.props[name] = { |
| 1100 | type: "accessor", |
| 1101 | ...options |
| 1102 | }; |
| 1103 | return () => delete this.props[name]; |
| 1104 | }, `ctx.accessor(${JSON.stringify(name)})`); |
| 1105 | } |
| 1106 | /** |
| 1107 | * Expose selected members of a service directly on `ctx`. |
| 1108 | * |
| 1109 | * See the `ctx.mixin()` overload above for the full contract. |
| 1110 | * |
| 1111 | * @param source — a context property name or a source object. |
| 1112 | * @param mixins — keys to forward, or a source-key → ctx-key map. |
| 1113 | * @returns a disposer that removes all created accessors. |
| 1114 | */ |
| 1115 | mixin(source, mixins) { |
| 1116 | const self = this; |
| 1117 | return this.ctx.fiber.effect(function* () { |
| 1118 | const entries = Array.isArray(mixins) ? mixins.map((key) => [key, key]) : Object.entries(mixins); |
| 1119 | const getTarget = (ctx, error) => { |
| 1120 | return ctx[source]; |
| 1121 | }; |
| 1122 | for (const [key, value] of entries) yield self.accessor(value, { |
| 1123 | get(receiver, error) { |
| 1124 | const service = getTarget(this, error); |
| 1125 | if (isNullable(service)) return service; |
| 1126 | const mixin = receiver ? withProps(receiver, service) : service; |
| 1127 | const value2 = Reflect.get(service, key, mixin); |
| 1128 | if (typeof value2 !== "function") return value2; |
| 1129 | return value2.bind(mixin ?? service); |
| 1130 | }, |
| 1131 | set(value2, receiver, error) { |
| 1132 | const service = getTarget(this, error); |
| 1133 | const mixin = receiver ? withProps(receiver, service) : service; |
| 1134 | return Reflect.set(service, key, value2, mixin); |
| 1135 | } |
| 1136 | }); |
| 1137 | }, `ctx.mixin(${JSON.stringify(source)})`); |
| 1138 | } |
| 1139 | /** |
| 1140 | * Attach this context's tracing wrapper to a value. |
| 1141 | * |
| 1142 | * @param value — the value to wrap. |
| 1143 | * @returns the traceable wrapper (or the value itself when not applicable). |
| 1144 | */ |
| 1145 | trace(value) { |
| 1146 | return getTraceable(this.ctx, value); |
| 1147 | } |
| 1148 | /** |
| 1149 | * Wrap a callback so calls trace `this` and arguments to this context. |
| 1150 | * |
| 1151 | * @param callback — the function to wrap. |
| 1152 | * @returns a proxy delegating to `callback` with traced values. |
| 1153 | */ |
| 1154 | bind(callback) { |
| 1155 | return new Proxy(callback, { |
| 1156 | apply: (target, thisArg, args) => { |
| 1157 | return Reflect.apply(target, this.trace(thisArg), args.map((arg) => this.trace(arg))); |
| 1158 | }, |
| 1159 | construct: (target, args, newTarget) => { |
| 1160 | return Reflect.construct(target, args.map((arg) => this.trace(arg)), newTarget); |
| 1161 | } |
| 1162 | }); |
| 1163 | } |
| 1164 | }; |
| 1165 | kValidationError = /* @__PURE__ */ Symbol.for("ValidationError"); |
| 1166 | ValidationError = class extends TypeError { |
| 1167 | name = "ValidationError"; |
| 1168 | /** |
| 1169 | * Build the aggregated message from schema issues. |
| 1170 | * |
| 1171 | * @param issues — the standard-schema issues, one message line each. |
| 1172 | */ |
| 1173 | constructor(issues) { |
| 1174 | super(`invalid config: |
| 1175 | ` + issues.map((issue) => { |
| 1176 | if (issue.path) return ` - ${issue.message} (at ${issue.path.join(".")})`; |
| 1177 | else return ` - ${issue.message}`; |
| 1178 | }).join("\n")); |
| 1179 | } |
| 1180 | }; |
| 1181 | Object.defineProperty(ValidationError.prototype, kValidationError, { value: true }); |
| 1182 | effectInertia = /* @__PURE__ */ new WeakMap(); |
| 1183 | CordisError = class CordisError2 extends Error { |
| 1184 | code; |
| 1185 | /** |
| 1186 | * @param code — the stable error code; also the default message. |
| 1187 | * @param message — optional human-readable override. |
| 1188 | */ |
| 1189 | constructor(code, message) { |
| 1190 | super(message ?? CordisError2.Code[code]); |
| 1191 | this.code = code; |
| 1192 | } |
| 1193 | }; |
| 1194 | (function(CordisError3) { |
| 1195 | CordisError3.Code = { INACTIVE_EFFECT: "cannot create effect on inactive context" }; |
| 1196 | })(CordisError || (CordisError = {})); |
| 1197 | INACTIVE = "__INACTIVE__"; |
| 1198 | Fiber = class { |
| 1199 | parent; |
| 1200 | inject; |
| 1201 | runtime; |
| 1202 | /** Unique id within the registry; 0 for the root fiber, `null` once disposed. */ |
| 1203 | uid; |
| 1204 | /** The context this fiber's plugin runs in (extends the parent context). */ |
| 1205 | ctx; |
| 1206 | /** The validated plugin config (updated by `update()`). */ |
| 1207 | config; |
| 1208 | /** The raw plugin config, re-resolved before each activation. */ |
| 1209 | _config; |
| 1210 | /** Current lifecycle state; transitions emit `internal/status`. */ |
| 1211 | state = 0; |
| 1212 | /** Dispose this fiber: unload the plugin, then settle once cleanup finished. */ |
| 1213 | dispose; |
| 1214 | /** Snapshot of required service implementations while loaded; `undefined` otherwise. */ |
| 1215 | store; |
| 1216 | /** The in-flight load/unload transition, if one is currently running. */ |
| 1217 | inertia; |
| 1218 | _hooks = /* @__PURE__ */ Object.create(null); |
| 1219 | _disposables = new DisposableList(); |
| 1220 | context; |
| 1221 | _error; |
| 1222 | _runner; |
| 1223 | _store = /* @__PURE__ */ Object.create(null); |
| 1224 | /** |
| 1225 | * Create a fiber. Plugin authors normally obtain fibers from `ctx.plugin()` |
| 1226 | * rather than constructing them directly. |
| 1227 | * |
| 1228 | * @param parent — the context the plugin was loaded from. |
| 1229 | * @param config — raw config, validated against the runtime's schema. |
| 1230 | * @param inject — resolved dependency map (service name → intercept config). |
| 1231 | * @param runtime — the shared plugin runtime, or `null` for the root fiber. |
| 1232 | * @param getOuterStack — captures the caller stack for effect diagnostics. |
| 1233 | */ |
| 1234 | constructor(parent, config, inject, runtime, getOuterStack) { |
| 1235 | this.parent = parent; |
| 1236 | this.inject = inject; |
| 1237 | this.runtime = runtime; |
| 1238 | this._config = config; |
| 1239 | const collect = (dispose) => { |
| 1240 | this._disposables.push(dispose); |
| 1241 | }; |
| 1242 | if (runtime) { |
| 1243 | this.uid = parent.registry.counter; |
| 1244 | this.ctx = this.context = parent.extend({ fiber: this }); |
| 1245 | const injectEntries = Object.entries(this.inject); |
| 1246 | if (injectEntries.length) { |
| 1247 | this.ctx[Context.intercept] = Object.create(parent[Context.intercept]); |
| 1248 | for (const [name, config2] of injectEntries) { |
| 1249 | if (isNullable(config2)) continue; |
| 1250 | this.ctx[Context.intercept][name] = config2; |
| 1251 | } |
| 1252 | } |
| 1253 | this._runner = { |
| 1254 | epoch: INACTIVE, |
| 1255 | getOuterStack, |
| 1256 | execute: function() { |
| 1257 | if (isConstructor(runtime.callback)) { |
| 1258 | const instance = new runtime.callback(this.ctx, this.config); |
| 1259 | for (const hook of instance?.[symbols.initHooks] ?? []) hook(); |
| 1260 | return instance?.[symbols.init]?.(); |
| 1261 | } else return runtime.callback(this.ctx, this.config); |
| 1262 | }, |
| 1263 | collect |
| 1264 | }; |
| 1265 | this.dispose = parent.fiber.effect(() => { |
| 1266 | const remove = runtime.fibers.push(this); |
| 1267 | return async () => { |
| 1268 | this.uid = null; |
| 1269 | emitPluginDisposed(this.context, this); |
| 1270 | if (this.ctx.registry.has(runtime.callback)) { |
| 1271 | remove(); |
| 1272 | if (!runtime.fibers.length) this.ctx.registry.delete(runtime.callback); |
| 1273 | } |
| 1274 | this._setEpoch(INACTIVE); |
| 1275 | if (!this.inertia) this._updateState(() => { |
| 1276 | this.inertia = this._unload(); |
| 1277 | return 5; |
| 1278 | }); |
| 1279 | while (this.inertia) await this.inertia; |
| 1280 | }; |
| 1281 | }, "ctx.plugin()"); |
| 1282 | try { |
| 1283 | this.context.emit("internal/plugin", this); |
| 1284 | } catch (error) { |
| 1285 | Promise.resolve(this.dispose()).catch((reason) => this.ctx.logger.error(reason)); |
| 1286 | throw error; |
| 1287 | } |
| 1288 | if (this.uid !== null && parent.fiber.state !== 5) { |
| 1289 | for (const name of Object.keys(this.inject)) this._checkImpl(name); |
| 1290 | this._refresh(); |
| 1291 | } |
| 1292 | } else { |
| 1293 | this.uid = 0; |
| 1294 | this.ctx = this.context = parent; |
| 1295 | this.state = 2; |
| 1296 | this.store = /* @__PURE__ */ Object.create(null); |
| 1297 | this._runner = { |
| 1298 | epoch: "", |
| 1299 | getOuterStack, |
| 1300 | execute: () => { |
| 1301 | }, |
| 1302 | collect |
| 1303 | }; |
| 1304 | this.dispose = () => this.restart(); |
| 1305 | } |
| 1306 | } |
| 1307 | /** The plugin's display name, inherited from the nearest named ancestor, else `'root'`. */ |
| 1308 | get name() { |
| 1309 | let fiber = this; |
| 1310 | do { |
| 1311 | if (fiber.runtime?.name) return fiber.runtime.name; |
| 1312 | fiber = fiber.parent.fiber; |
| 1313 | } while (fiber !== fiber.parent.fiber); |
| 1314 | return "root"; |
| 1315 | } |
| 1316 | /** |
| 1317 | * Throw if the fiber has already been disposed. |
| 1318 | * |
| 1319 | * @returns nothing when the fiber is still active. |
| 1320 | * @throws {CordisError} `INACTIVE_EFFECT` when the fiber's uid has been cleared. |
| 1321 | */ |
| 1322 | assertActive() { |
| 1323 | if (this.uid !== null) return; |
| 1324 | throw new CordisError("INACTIVE_EFFECT"); |
| 1325 | } |
| 1326 | _execute(runner) { |
| 1327 | const oldEpoch = runner.epoch; |
| 1328 | return composeError((info) => { |
| 1329 | const safeCollect = (dispose) => { |
| 1330 | if (typeof dispose === "function") runner.collect(dispose); |
| 1331 | else if (!isNullable(dispose)) throw new TypeError("Invalid effect"); |
| 1332 | }; |
| 1333 | const effect = runner.execute.call(this); |
| 1334 | if (typeof effect === "function") return runner.collect(effect); |
| 1335 | else if (isNullable(effect)) { |
| 1336 | } else if (!isObject(effect)) throw new TypeError("Invalid effect"); |
| 1337 | else if ("then" in effect) return effect.then(safeCollect); |
| 1338 | else if (Symbol.iterator in effect) { |
| 1339 | info.error = /* @__PURE__ */ new Error(); |
| 1340 | const iter = effect[Symbol.iterator](); |
| 1341 | while (true) { |
| 1342 | const result = iter.next(); |
| 1343 | safeCollect(result.value); |
| 1344 | if (result.done) return; |
| 1345 | } |
| 1346 | } else if (Symbol.asyncIterator in effect) { |
| 1347 | const iter = effect[Symbol.asyncIterator](); |
| 1348 | return (async () => { |
| 1349 | await Promise.resolve(); |
| 1350 | info.error = /* @__PURE__ */ new Error(); |
| 1351 | while (true) { |
| 1352 | if (runner.epoch !== oldEpoch) return; |
| 1353 | const result = await iter.next(); |
| 1354 | safeCollect(result.value); |
| 1355 | if (result.done) return; |
| 1356 | } |
| 1357 | })(); |
| 1358 | } else throw new TypeError("Invalid effect"); |
| 1359 | }, runner.getOuterStack); |
| 1360 | } |
| 1361 | effect(execute, label = "anonymous") { |
| 1362 | this.assertActive(); |
| 1363 | if (this.state === 5) throw new CordisError("INACTIVE_EFFECT"); |
| 1364 | const disposables = []; |
| 1365 | let disposing = false; |
| 1366 | let disposalTask; |
| 1367 | const dispose = () => { |
| 1368 | if (disposing) return disposalTask; |
| 1369 | disposing = true; |
| 1370 | let task2; |
| 1371 | for (const disposable of disposables.splice(0).reverse()) if (task2) task2 = task2.then(() => runDisposable(disposable)); |
| 1372 | else { |
| 1373 | const result = runDisposable(disposable); |
| 1374 | if (isObject(result) && "then" in result) task2 = result; |
| 1375 | } |
| 1376 | return disposalTask = task2; |
| 1377 | }; |
| 1378 | const meta = { |
| 1379 | label, |
| 1380 | children: [] |
| 1381 | }; |
| 1382 | const runner = { |
| 1383 | execute, |
| 1384 | epoch: true, |
| 1385 | collect: (dispose2) => { |
| 1386 | disposables.push(dispose2); |
| 1387 | this._disposables.delete(dispose2); |
| 1388 | if (dispose2[symbols.effect]) meta.children.push(dispose2[symbols.effect]); |
| 1389 | }, |
| 1390 | getOuterStack: buildOuterStack() |
| 1391 | }; |
| 1392 | let task; |
| 1393 | let executing = true; |
| 1394 | let resolveSetup; |
| 1395 | let rejectSetup; |
| 1396 | let setupBarrier; |
| 1397 | let setupFailed = false; |
| 1398 | let inFlight; |
| 1399 | let removeWrapper = () => false; |
| 1400 | const waitForSetup = () => { |
| 1401 | setupBarrier ??= new Promise((resolve6, reject) => { |
| 1402 | resolveSetup = resolve6; |
| 1403 | rejectSetup = reject; |
| 1404 | }); |
| 1405 | return setupBarrier; |
| 1406 | }; |
| 1407 | const disposeAfter = (setup) => { |
| 1408 | return Promise.resolve(setup).then(() => dispose(), async (reason) => { |
| 1409 | await dispose(); |
| 1410 | throw reason; |
| 1411 | }); |
| 1412 | }; |
| 1413 | const finalizeDisposal = (callback) => { |
| 1414 | let result; |
| 1415 | try { |
| 1416 | result = callback(); |
| 1417 | } catch (error) { |
| 1418 | removeWrapper(); |
| 1419 | throw error; |
| 1420 | } |
| 1421 | if (isObject(result) && "then" in result) { |
| 1422 | const pending = Promise.resolve(result).finally(() => { |
| 1423 | removeWrapper(); |
| 1424 | if (inFlight === pending) inFlight = void 0; |
| 1425 | }); |
| 1426 | return inFlight = pending; |
| 1427 | } |
| 1428 | removeWrapper(); |
| 1429 | return result; |
| 1430 | }; |
| 1431 | const wrapper = defineProperty(() => { |
| 1432 | if (!runner.epoch) return setupFailed ? inFlight : void 0; |
| 1433 | runner.epoch = false; |
| 1434 | return finalizeDisposal(() => { |
| 1435 | if (executing) return disposeAfter(waitForSetup()); |
| 1436 | return task ? disposeAfter(task) : dispose(); |
| 1437 | }); |
| 1438 | }, symbols.effect, meta); |
| 1439 | effectInertia.set(wrapper, () => inFlight); |
| 1440 | removeWrapper = this._disposables.push(wrapper); |
| 1441 | try { |
| 1442 | task = this._execute(runner); |
| 1443 | } catch (reason) { |
| 1444 | executing = false; |
| 1445 | setupFailed = true; |
| 1446 | runner.epoch = false; |
| 1447 | let cleanup; |
| 1448 | try { |
| 1449 | cleanup = finalizeDisposal(dispose); |
| 1450 | } finally { |
| 1451 | rejectSetup?.(reason); |
| 1452 | } |
| 1453 | if (isObject(cleanup) && "then" in cleanup) cleanup.catch((error) => this.ctx.logger.error(error)); |
| 1454 | throw reason; |
| 1455 | } |
| 1456 | executing = false; |
| 1457 | if (setupBarrier) Promise.resolve(task).then(resolveSetup, rejectSetup); |
| 1458 | task?.catch(() => { |
| 1459 | if (!runner.epoch) return dispose(); |
| 1460 | return finalizeDisposal(dispose); |
| 1461 | }).catch((error) => this.ctx.logger.error(error)); |
| 1462 | const disposeAsync = () => { |
| 1463 | if (!runner.epoch) return; |
| 1464 | runner.epoch = false; |
| 1465 | return finalizeDisposal(dispose); |
| 1466 | }; |
| 1467 | wrapper.then = async (onFulfilled, onRejected) => { |
| 1468 | return Promise.resolve(task).then(() => disposeAsync).then(onFulfilled, onRejected); |
| 1469 | }; |
| 1470 | return wrapper; |
| 1471 | } |
| 1472 | /** |
| 1473 | * Return metadata for currently registered effects. |
| 1474 | * |
| 1475 | * @returns one {@link EffectMeta} tree per labeled live effect. |
| 1476 | */ |
| 1477 | getEffects() { |
| 1478 | return [...this._disposables].map((dispose) => dispose[symbols.effect]).filter(Boolean); |
| 1479 | } |
| 1480 | _getState() { |
| 1481 | if (this.uid === null) return 4; |
| 1482 | if (this._error) return 3; |
| 1483 | if (this._runner.epoch !== INACTIVE) return 2; |
| 1484 | return 0; |
| 1485 | } |
| 1486 | _updateState(callback) { |
| 1487 | const oldState = this.state; |
| 1488 | this.state = callback() ?? this._getState(); |
| 1489 | if (oldState === this.state) return; |
| 1490 | this.context.emit("internal/status", this, oldState); |
| 1491 | if (oldState !== 2 && this.state !== 2) return; |
| 1492 | for (const key of Reflect.ownKeys(this.ctx.reflect.store)) { |
| 1493 | const impl = this.ctx.reflect.store[key]; |
| 1494 | if (impl.fiber !== this) continue; |
| 1495 | this.ctx.reflect.notify([impl.name]); |
| 1496 | } |
| 1497 | } |
| 1498 | _checkImpl(name) { |
| 1499 | const impl = this.ctx.reflect._getImpl(name, true); |
| 1500 | if (!impl) return delete this._store[name]; |
| 1501 | try { |
| 1502 | if (impl.check && !impl.check.call(getTraceable(this.ctx, impl.value))) return delete this._store[name]; |
| 1503 | } catch (error) { |
| 1504 | impl.fiber.ctx.logger.error(error); |
| 1505 | return delete this._store[name]; |
| 1506 | } |
| 1507 | this._store[name] = impl; |
| 1508 | } |
| 1509 | _refresh() { |
| 1510 | let epoch = false; |
| 1511 | epoch = ""; |
| 1512 | for (const name of Object.keys(this.inject)) { |
| 1513 | const impl = this._store[name]; |
| 1514 | if (!impl) { |
| 1515 | epoch = INACTIVE; |
| 1516 | break; |
| 1517 | } |
| 1518 | epoch += ":" + impl.fiber.uid; |
| 1519 | } |
| 1520 | this._setEpoch(epoch); |
| 1521 | } |
| 1522 | _setEpoch(epoch) { |
| 1523 | const oldEpoch = this._runner.epoch; |
| 1524 | if (epoch === oldEpoch) return; |
| 1525 | this._runner.epoch = epoch; |
| 1526 | if (this.inertia) return; |
| 1527 | this._updateState(() => { |
| 1528 | if (epoch !== INACTIVE && oldEpoch === INACTIVE) { |
| 1529 | this.inertia = this._reload(); |
| 1530 | return 1; |
| 1531 | } else { |
| 1532 | this.inertia = this._unload(); |
| 1533 | return 5; |
| 1534 | } |
| 1535 | }); |
| 1536 | } |
| 1537 | _resolveConfig(config) { |
| 1538 | config = this.context.waterfall(this, "internal/config", config, () => config); |
| 1539 | return this.runtime ? resolveConfig(this.runtime, config) : config; |
| 1540 | } |
| 1541 | async _reload() { |
| 1542 | this.store = { ...this._store }; |
| 1543 | const oldEpoch = this._runner.epoch; |
| 1544 | try { |
| 1545 | await Promise.resolve(); |
| 1546 | if (this._runner.epoch === oldEpoch) { |
| 1547 | this.config = this._resolveConfig(this._config); |
| 1548 | await this._execute(this._runner); |
| 1549 | this._error = void 0; |
| 1550 | } |
| 1551 | } catch (reason) { |
| 1552 | this.ctx.logger.error(reason); |
| 1553 | this._error = reason; |
| 1554 | this._runner.epoch = INACTIVE; |
| 1555 | } |
| 1556 | this._updateState(() => { |
| 1557 | if (this._runner.epoch === oldEpoch) this.inertia = void 0; |
| 1558 | else { |
| 1559 | this.inertia = this._unload(); |
| 1560 | return 5; |
| 1561 | } |
| 1562 | }); |
| 1563 | } |
| 1564 | async _unload() { |
| 1565 | await Promise.all(this._disposables.clear().map(async (dispose) => { |
| 1566 | try { |
| 1567 | await composeError(async (info) => { |
| 1568 | await Promise.resolve(); |
| 1569 | info.error = /* @__PURE__ */ new Error(); |
| 1570 | await runDisposable(dispose); |
| 1571 | }, this._runner.getOuterStack); |
| 1572 | } catch (reason) { |
| 1573 | this.ctx.logger.error(reason); |
| 1574 | } |
| 1575 | })); |
| 1576 | this.store = void 0; |
| 1577 | this._updateState(() => { |
| 1578 | if (this._runner.epoch === INACTIVE) this.inertia = void 0; |
| 1579 | else { |
| 1580 | this.inertia = this._reload(); |
| 1581 | return 1; |
| 1582 | } |
| 1583 | }); |
| 1584 | } |
| 1585 | /** |
| 1586 | * Wait for current lifecycle work and rethrow startup errors. |
| 1587 | * |
| 1588 | * @returns this fiber, once it has settled into a stable state. |
| 1589 | * @throws the config-validation or plugin-startup error, if any. |
| 1590 | */ |
| 1591 | async await() { |
| 1592 | while (this.inertia) await this.inertia; |
| 1593 | if (this._error) throw this._error; |
| 1594 | return this; |
| 1595 | } |
| 1596 | /** |
| 1597 | * Dispose and immediately reload this plugin with its current config. |
| 1598 | * |
| 1599 | * @returns a promise resolving once the reload settled. |
| 1600 | * @throws {CordisError} `INACTIVE_EFFECT` when the fiber is already disposed. |
| 1601 | */ |
| 1602 | async restart() { |
| 1603 | this.assertActive(); |
| 1604 | this._setEpoch(INACTIVE); |
| 1605 | this._refresh(); |
| 1606 | await this.await(); |
| 1607 | } |
| 1608 | /** |
| 1609 | * Validate and apply new config, then restart the plugin. |
| 1610 | * |
| 1611 | * Runs the `internal/update` waterfall first, so update hooks (and HMR) |
| 1612 | * can veto or replace the restart. |
| 1613 | * |
| 1614 | * @param config — the new raw config; validated before anything restarts. |
| 1615 | * @param noSave — hint for persistence hooks not to write the change back. |
| 1616 | * @returns nothing; the restart runs behind the `internal/update` waterfall. |
| 1617 | * @throws {ValidationError} when the new config fails validation. |
| 1618 | */ |
| 1619 | update(config, noSave = false) { |
| 1620 | this.assertActive(); |
| 1621 | this._config = config; |
| 1622 | if (this.state !== 2) { |
| 1623 | this._error = void 0; |
| 1624 | this._setEpoch(INACTIVE); |
| 1625 | this._refresh(); |
| 1626 | return; |
| 1627 | } |
| 1628 | config = this._resolveConfig(config); |
| 1629 | this.context.waterfall(this, "internal/update", config, noSave, () => { |
| 1630 | this.config = config; |
| 1631 | this._error = void 0; |
| 1632 | return this.restart(); |
| 1633 | }); |
| 1634 | } |
| 1635 | }; |
| 1636 | (function(Inject2) { |
| 1637 | function resolve6(inject, result = /* @__PURE__ */ Object.create(null)) { |
| 1638 | if (!inject) return result; |
| 1639 | if (Array.isArray(inject)) for (const name of inject) result[name] = null; |
| 1640 | else if (Reflect.has(inject, symbols.checkProto)) { |
| 1641 | Object.assign(result, resolve6(Object.getPrototypeOf(inject))); |
| 1642 | for (const name of Object.keys(inject)) result[name] = inject[name] ?? null; |
| 1643 | } else for (const name of Object.keys(inject)) result[name] = inject[name] ?? null; |
| 1644 | return result; |
| 1645 | } |
| 1646 | Inject2.resolve = resolve6; |
| 1647 | })(Inject || (Inject = {})); |
| 1648 | RegistryService = class { |
| 1649 | ctx; |
| 1650 | _counter = 0; |
| 1651 | _internal = /* @__PURE__ */ new Map(); |
| 1652 | constructor(ctx) { |
| 1653 | this.ctx = ctx; |
| 1654 | defineProperty(this, symbols.tracker, { |
| 1655 | property: "ctx", |
| 1656 | noShadow: true |
| 1657 | }); |
| 1658 | } |
| 1659 | /** Allocate the next fiber uid (increments on every read). */ |
| 1660 | get counter() { |
| 1661 | return ++this._counter; |
| 1662 | } |
| 1663 | /** Number of registered plugin runtimes. */ |
| 1664 | get size() { |
| 1665 | return this._internal.size; |
| 1666 | } |
| 1667 | /** |
| 1668 | * Resolve a supported plugin shape to its executable callback. |
| 1669 | * |
| 1670 | * @param plugin — a function, class, or `{ apply }` object plugin. |
| 1671 | * @returns the callback identifying the plugin, or `undefined` if invalid. |
| 1672 | */ |
| 1673 | resolve(plugin) { |
| 1674 | try { |
| 1675 | if (typeof plugin === "function") return plugin; |
| 1676 | if (isApplicable(plugin)) return plugin.apply; |
| 1677 | } catch { |
| 1678 | } |
| 1679 | } |
| 1680 | /** |
| 1681 | * Look up the runtime record for a plugin. |
| 1682 | * |
| 1683 | * @param plugin — any supported plugin shape. |
| 1684 | * @returns the runtime, or `undefined` when the plugin is not registered. |
| 1685 | */ |
| 1686 | get(plugin) { |
| 1687 | const key = this.resolve(plugin); |
| 1688 | return key && this._internal.get(key); |
| 1689 | } |
| 1690 | /** |
| 1691 | * Check whether a plugin has a registered runtime. |
| 1692 | * |
| 1693 | * @param plugin — any supported plugin shape. |
| 1694 | * @returns `true` when at least one fiber of the plugin exists. |
| 1695 | */ |
| 1696 | has(plugin) { |
| 1697 | const key = this.resolve(plugin); |
| 1698 | return !!key && this._internal.has(key); |
| 1699 | } |
| 1700 | /** |
| 1701 | * Dispose every running fiber for a plugin and remove its runtime record. |
| 1702 | * |
| 1703 | * @param plugin — any supported plugin shape. |
| 1704 | * @returns the removed runtime, or `undefined` when none was registered. |
| 1705 | */ |
| 1706 | delete(plugin) { |
| 1707 | const key = this.resolve(plugin); |
| 1708 | const runtime = key && this._internal.get(key); |
| 1709 | if (!runtime) return; |
| 1710 | this._internal.delete(key); |
| 1711 | for (const fiber of runtime.fibers) fiber.dispose(); |
| 1712 | return runtime; |
| 1713 | } |
| 1714 | /** Iterate the registered plugin callbacks. */ |
| 1715 | keys() { |
| 1716 | return this._internal.keys(); |
| 1717 | } |
| 1718 | /** Iterate the registered plugin runtimes. */ |
| 1719 | values() { |
| 1720 | return this._internal.values(); |
| 1721 | } |
| 1722 | /** Iterate `[callback, runtime]` pairs. */ |
| 1723 | entries() { |
| 1724 | return this._internal.entries(); |
| 1725 | } |
| 1726 | /** |
| 1727 | * Visit every registered runtime. |
| 1728 | * |
| 1729 | * @param callback — receives each runtime and its identifying callback. |
| 1730 | */ |
| 1731 | forEach(callback) { |
| 1732 | return this._internal.forEach(callback); |
| 1733 | } |
| 1734 | /** |
| 1735 | * Start a callback once the requested dependencies are available. |
| 1736 | * |
| 1737 | * @param inject — required services, as an array or a name → config map. |
| 1738 | * @param callback — plugin body called with `(ctx, config)`. |
| 1739 | * @returns the fiber; awaiting it settles once loading finished. |
| 1740 | */ |
| 1741 | inject(inject, callback) { |
| 1742 | return this.plugin({ |
| 1743 | inject, |
| 1744 | apply: callback, |
| 1745 | name: callback.name |
| 1746 | }); |
| 1747 | } |
| 1748 | /** |
| 1749 | * Start a plugin in the current context and return its fiber. |
| 1750 | * |
| 1751 | * Creates (or reuses) the plugin's runtime record, then starts a new fiber |
| 1752 | * under the current context. Throws if `plugin` is not a supported shape or |
| 1753 | * if the current fiber is already disposed. |
| 1754 | * |
| 1755 | * @param plugin — a function, class, or `{ apply }` object plugin. |
| 1756 | * @param config — the plugin config, validated against its `Config` schema. |
| 1757 | * @param getOuterStack — captures the caller stack for effect diagnostics. |
| 1758 | * @returns the fiber; awaiting it settles once loading finished. |
| 1759 | */ |
| 1760 | plugin(plugin, config, getOuterStack = buildOuterStack()) { |
| 1761 | const callback = this.resolve(plugin); |
| 1762 | if (!callback) throw new Error('invalid plugin, expect function or object with an "apply" method, received ' + typeof plugin); |
| 1763 | this.ctx.fiber.assertActive(); |
| 1764 | let runtime = this._internal.get(callback); |
| 1765 | if (!runtime) { |
| 1766 | let name = plugin.name; |
| 1767 | if (name === "apply") name = void 0; |
| 1768 | runtime = { |
| 1769 | name, |
| 1770 | callback, |
| 1771 | fibers: new DisposableList(), |
| 1772 | Config: plugin.Config |
| 1773 | }; |
| 1774 | this._internal.set(callback, runtime); |
| 1775 | } |
| 1776 | const fiber = new Fiber(this.ctx, config, Inject.resolve(plugin.inject), runtime, getOuterStack); |
| 1777 | const wrapped = Object.create(fiber); |
| 1778 | wrapped.then = (onFulfilled, onRejected) => { |
| 1779 | return fiber.await().then(onFulfilled, onRejected); |
| 1780 | }; |
| 1781 | return wrapped; |
| 1782 | } |
| 1783 | }; |
| 1784 | Context = class Context2 { |
| 1785 | /** Symbol key under which a disposer exposes its {@link EffectMeta} diagnostics tree. */ |
| 1786 | static effect = symbols.effect; |
| 1787 | /** Symbol key for a context's listener filter, consulted on every event dispatch. */ |
| 1788 | static filter = symbols.filter; |
| 1789 | /** Symbol key of the isolation map (see the `Context[symbols.isolate]` property). */ |
| 1790 | static isolate = symbols.isolate; |
| 1791 | /** Symbol key of the intercept map (see the `Context[symbols.intercept]` property). */ |
| 1792 | static intercept = symbols.intercept; |
| 1793 | /** |
| 1794 | * Returns true for Cordis context proxies and context prototypes. |
| 1795 | * |
| 1796 | * Works across realms and across multiple copies of cordis, because the |
| 1797 | * brand is keyed by a global symbol rather than by `instanceof`. |
| 1798 | * |
| 1799 | * @param value — the value to test. |
| 1800 | * @returns `true` if `value` is a Cordis context, narrowing its type. |
| 1801 | */ |
| 1802 | static is(value) { |
| 1803 | return !!value?.[Context2.is]; |
| 1804 | } |
| 1805 | static { |
| 1806 | Context2.is[Symbol.toPrimitive] = () => /* @__PURE__ */ Symbol.for("cordis.is"); |
| 1807 | Context2.prototype[Context2.is] = true; |
| 1808 | } |
| 1809 | /** Create the root context and install the built-in services. */ |
| 1810 | constructor() { |
| 1811 | this[symbols.isolate] = /* @__PURE__ */ Object.create(null); |
| 1812 | this[symbols.intercept] = /* @__PURE__ */ Object.create(null); |
| 1813 | const self = new Proxy(this, ReflectService.handler); |
| 1814 | this.root = self; |
| 1815 | this.baseUrl = void 0; |
| 1816 | this.fiber = new Fiber(self, {}, /* @__PURE__ */ Object.create(null), null, () => []); |
| 1817 | this.reflect = new ReflectService(self); |
| 1818 | this.registry = new RegistryService(self); |
| 1819 | this.events = new EventsService(self); |
| 1820 | this.logger = new LoggerService(self); |
| 1821 | this.fiber._disposables.clear(); |
| 1822 | return self; |
| 1823 | } |
| 1824 | [/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() { |
| 1825 | return `Context <${this.fiber.name}>`; |
| 1826 | } |
| 1827 | /** |
| 1828 | * Create a child context with extra metadata on top of the current scope. |
| 1829 | * |
| 1830 | * The child prototypally inherits every property of this context; own |
| 1831 | * properties of `meta` shadow the inherited ones. The parent is not mutated. |
| 1832 | * |
| 1833 | * @param meta — own properties (including symbol keys) to define on the child. |
| 1834 | * @returns a child context inheriting from this one. |
| 1835 | */ |
| 1836 | extend(meta = {}) { |
| 1837 | const shadow = Reflect.getOwnPropertyDescriptor(this, symbols.shadow)?.value; |
| 1838 | const self = Object.create(getTraceable(this, this)); |
| 1839 | for (const prop of Reflect.ownKeys(meta)) Object.defineProperty(self, prop, Reflect.getOwnPropertyDescriptor(meta, prop)); |
| 1840 | if (!shadow) return self; |
| 1841 | return Object.assign(Object.create(self), { [symbols.shadow]: shadow }); |
| 1842 | } |
| 1843 | /** |
| 1844 | * Create a child context with an independent service scope for `name`. |
| 1845 | * |
| 1846 | * Below the returned context, reads and writes of the service `name` |
| 1847 | * resolve against the new label instead of the parent's, so a different |
| 1848 | * implementation can be provided without affecting the parent scope. |
| 1849 | * Passing the same `label` to two `isolate()` calls joins their scopes. |
| 1850 | * |
| 1851 | * @param name — the service name to isolate. |
| 1852 | * @param label — scope label to join; defaults to a fresh unique symbol. |
| 1853 | * @returns a child context whose `name` service resolves in the new scope. |
| 1854 | */ |
| 1855 | isolate(name, label) { |
| 1856 | const shadow = Object.create(this[symbols.isolate]); |
| 1857 | shadow[name] = label ?? Symbol(name); |
| 1858 | return this.extend({ [symbols.isolate]: shadow }); |
| 1859 | } |
| 1860 | intercept(name, config) { |
| 1861 | const intercept = Object.create(this[symbols.intercept]); |
| 1862 | intercept[name] = config; |
| 1863 | return this.extend({ [symbols.intercept]: intercept }); |
| 1864 | } |
| 1865 | }; |
| 1866 | Service = class Service2 { |
| 1867 | ctx; |
| 1868 | /** Symbol key of an instance method run after construction (class plugins). */ |
| 1869 | static init = symbols.init; |
| 1870 | /** Symbol key of the availability predicate passed to `ctx.provide()`. */ |
| 1871 | static check = symbols.check; |
| 1872 | /** Symbol key of the phantom intercept-config type parameter. */ |
| 1873 | static config = symbols.config; |
| 1874 | /** Symbol key of the call body making a service callable (e.g. `ctx.logger()`). */ |
| 1875 | static invoke = symbols.invoke; |
| 1876 | /** Symbol key of the helper deriving an extended service instance. */ |
| 1877 | static extend = symbols.extend; |
| 1878 | /** Symbol key of the tracker metadata used for context tracing. */ |
| 1879 | static tracker = symbols.tracker; |
| 1880 | /** Symbol key of the intercept-config resolution helper below. */ |
| 1881 | static resolveConfig = symbols.resolveConfig; |
| 1882 | /** The service name this instance is registered under. */ |
| 1883 | name; |
| 1884 | /** |
| 1885 | * Register this instance as `name` in the current context. |
| 1886 | * |
| 1887 | * Calls `ctx.reflect.provide(name, this, this[Service.check])`, so the |
| 1888 | * service is unregistered automatically when the owning fiber unloads. |
| 1889 | * Services with a `[Service.invoke]` body return a callable instance. |
| 1890 | * |
| 1891 | * @param ctx — the context to register in (stored as `this.ctx`). |
| 1892 | * @param name — the service name; defaults to the static `provide` field. |
| 1893 | */ |
| 1894 | constructor(ctx, name) { |
| 1895 | this.ctx = ctx; |
| 1896 | name ??= this.constructor["provide"]; |
| 1897 | let self = this; |
| 1898 | const tracker = { |
| 1899 | associate: name, |
| 1900 | property: "ctx" |
| 1901 | }; |
| 1902 | if (self[symbols.invoke]) self = createCallable(name, joinPrototype(Object.getPrototypeOf(this), Function.prototype), tracker); |
| 1903 | self.ctx = ctx; |
| 1904 | self.name = name; |
| 1905 | defineProperty(self, symbols.tracker, tracker); |
| 1906 | self.ctx.reflect.provide(name, self, this[symbols.check]); |
| 1907 | return self; |
| 1908 | } |
| 1909 | [symbols.filter](ctx) { |
| 1910 | return ctx[symbols.isolate][this.name] === this.ctx[symbols.isolate][this.name]; |
| 1911 | } |
| 1912 | [symbols.extend](props) { |
| 1913 | let self; |
| 1914 | if (this[Service2.invoke]) self = createCallable(this.name, this, this[symbols.tracker]); |
| 1915 | else self = Object.create(this); |
| 1916 | return Object.assign(self, props); |
| 1917 | } |
| 1918 | /** |
| 1919 | * Merge intercept config from ancestors with optional base and head values. |
| 1920 | * |
| 1921 | * Entries added closer to the root apply first; `base` is prepended and |
| 1922 | * `head` appended. Uses `Config.merge` when the service declares one, |
| 1923 | * otherwise a shallow `Object.assign`. |
| 1924 | * |
| 1925 | * @param base — lowest-precedence config merged before all intercepts. |
| 1926 | * @param head — highest-precedence config merged after all intercepts. |
| 1927 | * @returns the merged config. |
| 1928 | */ |
| 1929 | [symbols.resolveConfig](base, head) { |
| 1930 | let intercept = this.ctx[Context.intercept]; |
| 1931 | const configs = []; |
| 1932 | while (this.name in intercept) { |
| 1933 | if (Object.hasOwn(intercept, this.name)) configs.unshift(intercept[this.name]); |
| 1934 | intercept = Object.getPrototypeOf(intercept); |
| 1935 | } |
| 1936 | if (base) configs.unshift(base); |
| 1937 | if (head) configs.push(head); |
| 1938 | if (this["Config"]?.merge) return this["Config"].merge(...configs); |
| 1939 | else return Object.assign({}, ...configs); |
| 1940 | } |
| 1941 | static [Symbol.hasInstance](instance) { |
| 1942 | if (!instance) return false; |
| 1943 | let constructor = instance.constructor; |
| 1944 | while (constructor) { |
| 1945 | constructor = constructor.prototype?.constructor; |
| 1946 | if (constructor === this) return true; |
| 1947 | constructor &&= Object.getPrototypeOf(constructor); |
| 1948 | } |
| 1949 | return false; |
| 1950 | } |
| 1951 | }; |
| 1952 | } |
| 1953 | }); |
| 1954 | |
| 1955 | // src/dsh/fiber-state.ts |
| 1956 | var FiberState; |
| 1957 | var init_fiber_state = __esm({ |
| 1958 | "src/dsh/fiber-state.ts"() { |
| 1959 | "use strict"; |
| 1960 | FiberState = { |
| 1961 | PENDING: 0, |
| 1962 | LOADING: 1, |
| 1963 | ACTIVE: 2, |
| 1964 | FAILED: 3, |
| 1965 | DISPOSED: 4, |
| 1966 | UNLOADING: 5 |
| 1967 | }; |
| 1968 | } |
| 1969 | }); |
| 1970 | |
| 1971 | // src/dsh/upstream/loader/src/config/group.ts |
| 1972 | var EntryGroup, Group; |
| 1973 | var init_group = __esm({ |
| 1974 | "src/dsh/upstream/loader/src/config/group.ts"() { |
| 1975 | "use strict"; |
| 1976 | init_lib2(); |
| 1977 | init_entry(); |
| 1978 | EntryGroup = class { |
| 1979 | constructor(ctx, tree) { |
| 1980 | this.ctx = ctx; |
| 1981 | this.tree = tree; |
| 1982 | const entry = ctx.fiber.entry; |
| 1983 | if (entry) entry.subgroup = this; |
| 1984 | } |
| 1985 | ctx; |
| 1986 | tree; |
| 1987 | static key = /* @__PURE__ */ Symbol.for("cordis.group"); |
| 1988 | data = []; |
| 1989 | get context() { |
| 1990 | return this.ctx; |
| 1991 | } |
| 1992 | async create(options) { |
| 1993 | const id = this.tree.ensureId(options); |
| 1994 | const entry = this.tree.store[id] ??= new Entry(this.ctx.loader); |
| 1995 | entry.parent = this; |
| 1996 | await entry.update(options, true, true); |
| 1997 | return entry.id; |
| 1998 | } |
| 1999 | unlink(options) { |
| 2000 | const config = this.data; |
| 2001 | const index = config.indexOf(options); |
| 2002 | if (index >= 0) config.splice(index, 1); |
| 2003 | } |
| 2004 | remove(id, isDispose = false) { |
| 2005 | const entry = this.tree.store[id]; |
| 2006 | if (!entry) return; |
| 2007 | entry.fiber?.dispose(); |
| 2008 | if (!isDispose) { |
| 2009 | this.unlink(entry.options); |
| 2010 | } |
| 2011 | delete this.tree.store[id]; |
| 2012 | this.context.emit("loader/partial-dispose", entry, entry.options, false); |
| 2013 | } |
| 2014 | async update(config) { |
| 2015 | const oldConfig = this.data; |
| 2016 | this.data = config; |
| 2017 | const oldMap = Object.fromEntries(oldConfig.map((options) => [options.id, options])); |
| 2018 | const newMap = Object.fromEntries(config.map((options) => [options.id ?? /* @__PURE__ */ Symbol("anonymous"), options])); |
| 2019 | const ids = Reflect.ownKeys({ ...oldMap, ...newMap }); |
| 2020 | await Promise.all(ids.map(async (id) => { |
| 2021 | if (newMap[id]) { |
| 2022 | await this.create(newMap[id]).catch((error) => { |
| 2023 | this.ctx.logger.error(error); |
| 2024 | }); |
| 2025 | } else { |
| 2026 | this.remove(id); |
| 2027 | } |
| 2028 | })); |
| 2029 | } |
| 2030 | stop() { |
| 2031 | for (const options of this.data) { |
| 2032 | this.remove(options.id, true); |
| 2033 | } |
| 2034 | } |
| 2035 | }; |
| 2036 | Group = class extends EntryGroup { |
| 2037 | constructor(ctx, config) { |
| 2038 | super(ctx, ctx.fiber.entry.parent.tree); |
| 2039 | this.ctx = ctx; |
| 2040 | this.config = config; |
| 2041 | ctx.on("internal/update", (config2) => { |
| 2042 | this.update(config2); |
| 2043 | }); |
| 2044 | } |
| 2045 | ctx; |
| 2046 | config; |
| 2047 | static initial = []; |
| 2048 | static [EntryGroup.key] = true; |
| 2049 | async *[Service.init]() { |
| 2050 | yield () => this.stop(); |
| 2051 | await this.update(this.config); |
| 2052 | } |
| 2053 | }; |
| 2054 | } |
| 2055 | }); |
| 2056 | |
| 2057 | // src/dsh/upstream/loader/src/config/tree.ts |
| 2058 | var EntryTree; |
| 2059 | var init_tree = __esm({ |
| 2060 | "src/dsh/upstream/loader/src/config/tree.ts"() { |
| 2061 | "use strict"; |
| 2062 | init_lib2(); |
| 2063 | init_lib(); |
| 2064 | init_group(); |
| 2065 | EntryTree = class _EntryTree { |
| 2066 | static sep = ":"; |
| 2067 | ctx; |
| 2068 | enableLogs; |
| 2069 | root; |
| 2070 | store = /* @__PURE__ */ Object.create(null); |
| 2071 | constructor(ctx) { |
| 2072 | this.ctx = ctx.extend({ baseUrl: ctx.baseUrl }); |
| 2073 | this.root = new EntryGroup(this.ctx, this); |
| 2074 | const entry = this.ctx.fiber.entry; |
| 2075 | if (entry) entry.subtree = this; |
| 2076 | } |
| 2077 | get context() { |
| 2078 | return this.ctx; |
| 2079 | } |
| 2080 | /** Iterate entries in this tree and any nested subtrees. */ |
| 2081 | *entries() { |
| 2082 | for (const entry of Object.values(this.store)) { |
| 2083 | yield entry; |
| 2084 | if (!entry.subtree) continue; |
| 2085 | yield* entry.subtree.entries(); |
| 2086 | } |
| 2087 | } |
| 2088 | /** Return pending import and lifecycle tasks owned by this tree. */ |
| 2089 | getTasks() { |
| 2090 | return [...this.entries()].map((entry) => entry._initTask || entry.fiber?.inertia).filter(isNonNullable); |
| 2091 | } |
| 2092 | /** Wait until this tree has no pending import or lifecycle tasks. */ |
| 2093 | async await() { |
| 2094 | while (true) { |
| 2095 | const tasks = this.getTasks(); |
| 2096 | if (!tasks.length) return; |
| 2097 | await Promise.allSettled(tasks); |
| 2098 | } |
| 2099 | } |
| 2100 | ensureId(options) { |
| 2101 | if (!options.id) { |
| 2102 | do { |
| 2103 | options.id = Math.random().toString(16).slice(2, 10); |
| 2104 | } while (this.store[options.id]); |
| 2105 | } |
| 2106 | return options.id; |
| 2107 | } |
| 2108 | /** Resolve an entry by id, including nested ids separated by `EntryTree.sep`. */ |
| 2109 | resolve(id) { |
| 2110 | const parts = id.split(_EntryTree.sep); |
| 2111 | let tree = this; |
| 2112 | const final = parts.pop(); |
| 2113 | for (const part of parts) { |
| 2114 | tree = tree.store[part]?.subtree; |
| 2115 | if (!tree) throw new Error(`cannot resolve entry ${id}`); |
| 2116 | } |
| 2117 | const entry = tree.store[final]; |
| 2118 | if (!entry) throw new Error(`cannot resolve entry ${id}`); |
| 2119 | return entry; |
| 2120 | } |
| 2121 | resolveGroup(id) { |
| 2122 | if (!id) return this.root; |
| 2123 | const entry = this.resolve(id); |
| 2124 | if (!entry.subgroup) throw new Error(`entry ${id} is not a group`); |
| 2125 | return entry.subgroup; |
| 2126 | } |
| 2127 | /** Create an entry in the root group or a nested group. */ |
| 2128 | async create(options, parent = null, position = Infinity) { |
| 2129 | const group = this.resolveGroup(parent); |
| 2130 | group.data.splice(position, 0, options); |
| 2131 | group.tree.write(); |
| 2132 | return group.create(options); |
| 2133 | } |
| 2134 | /** Stop and remove an entry from its parent group. */ |
| 2135 | remove(id) { |
| 2136 | const entry = this.resolve(id); |
| 2137 | entry.parent.remove(id); |
| 2138 | entry.parent.tree.write(); |
| 2139 | } |
| 2140 | /** Update an entry and optionally move it to another group. */ |
| 2141 | async update(id, options, parent, position) { |
| 2142 | const entry = this.resolve(id); |
| 2143 | const source = entry.parent; |
| 2144 | if (parent !== void 0) { |
| 2145 | const target = this.resolveGroup(parent); |
| 2146 | source.unlink(entry.options); |
| 2147 | target.data.splice(position ?? Infinity, 0, entry.options); |
| 2148 | target.tree.write(); |
| 2149 | entry.parent = target; |
| 2150 | } |
| 2151 | source.tree.write(); |
| 2152 | return entry.update(options, false, true); |
| 2153 | } |
| 2154 | /** Import a plugin module from a specifier or `cordis:` builtin. */ |
| 2155 | import(name, getOuterStack) { |
| 2156 | if (name.startsWith("cordis:")) { |
| 2157 | return this.ctx.loader.builtins[name.slice(7)]; |
| 2158 | } |
| 2159 | return composeError(async (info) => { |
| 2160 | info.offset += 3; |
| 2161 | if (this.ctx.loader.internal) { |
| 2162 | return await this.ctx.loader.internal.import(name, this.ctx.baseUrl, {}); |
| 2163 | } else if (name.startsWith(".")) { |
| 2164 | return await import( |
| 2165 | /* @vite-ignore */ |
| 2166 | new URL(name, this.ctx.baseUrl).href |
| 2167 | ); |
| 2168 | } else { |
| 2169 | return await import( |
| 2170 | /* @vite-ignore */ |
| 2171 | name |
| 2172 | ); |
| 2173 | } |
| 2174 | }, getOuterStack); |
| 2175 | } |
| 2176 | }; |
| 2177 | } |
| 2178 | }); |
| 2179 | |
| 2180 | // src/dsh/upstream/loader/src/config/utils.ts |
| 2181 | function interpolate(ctx, value) { |
| 2182 | if (isJsExpr(value)) { |
| 2183 | return evaluate(ctx, value.__jsExpr); |
| 2184 | } else if (!value || typeof value !== "object") { |
| 2185 | return value; |
| 2186 | } else if (Array.isArray(value)) { |
| 2187 | return value.map((item) => interpolate(ctx, item)); |
| 2188 | } else { |
| 2189 | return mapValues(value, (item) => interpolate(ctx, item)); |
| 2190 | } |
| 2191 | } |
| 2192 | function isJsExpr(value) { |
| 2193 | return value instanceof Object && "__jsExpr" in value; |
| 2194 | } |
| 2195 | var evaluate; |
| 2196 | var init_utils = __esm({ |
| 2197 | "src/dsh/upstream/loader/src/config/utils.ts"() { |
| 2198 | "use strict"; |
| 2199 | init_lib(); |
| 2200 | evaluate = new Function("ctx", "expr", ` |
| 2201 | with (ctx) { |
| 2202 | return eval(expr) |
| 2203 | } |
| 2204 | `); |
| 2205 | } |
| 2206 | }); |
| 2207 | |
| 2208 | // src/dsh/upstream/loader/src/config/entry.ts |
| 2209 | function takeEntries(object, keys) { |
| 2210 | const indexed = object; |
| 2211 | const result = []; |
| 2212 | for (const key of keys) { |
| 2213 | if (!(key in object)) continue; |
| 2214 | result.push([key, indexed[key]]); |
| 2215 | delete indexed[key]; |
| 2216 | } |
| 2217 | return result; |
| 2218 | } |
| 2219 | function sortKeys(object, prepend = ["id", "name"], append = ["config"]) { |
| 2220 | const part1 = takeEntries(object, prepend); |
| 2221 | const part2 = takeEntries(object, append); |
| 2222 | const rest = takeEntries(object, Object.keys(object)).sort(([a], [b]) => a.localeCompare(b)); |
| 2223 | return Object.assign(object, Object.fromEntries([...part1, ...rest, ...part2])); |
| 2224 | } |
| 2225 | var Entry; |
| 2226 | var init_entry = __esm({ |
| 2227 | "src/dsh/upstream/loader/src/config/entry.ts"() { |
| 2228 | "use strict"; |
| 2229 | init_lib(); |
| 2230 | init_tree(); |
| 2231 | init_utils(); |
| 2232 | Entry = class _Entry { |
| 2233 | constructor(loader2) { |
| 2234 | this.loader = loader2; |
| 2235 | this.ctx = loader2.ctx.extend({ [_Entry.key]: this }); |
| 2236 | this.context.emit("loader/entry-init", this); |
| 2237 | } |
| 2238 | loader; |
| 2239 | static key = /* @__PURE__ */ Symbol.for("cordis.entry"); |
| 2240 | ctx; |
| 2241 | fiber; |
| 2242 | parent; |
| 2243 | // safety: call `entry.update()` immediately after creating an entry |
| 2244 | options = {}; |
| 2245 | subgroup; |
| 2246 | subtree; |
| 2247 | _initTask; |
| 2248 | get context() { |
| 2249 | return this.ctx; |
| 2250 | } |
| 2251 | get id() { |
| 2252 | let id = this.options.id; |
| 2253 | if (this.parent.tree.ctx.fiber.entry) { |
| 2254 | id = this.parent.tree.ctx.fiber.entry.id + EntryTree.sep + id; |
| 2255 | } |
| 2256 | return id; |
| 2257 | } |
| 2258 | /** True when this entry or any owning parent entry is disabled. */ |
| 2259 | get disabled() { |
| 2260 | if (this.options.group) return false; |
| 2261 | let entry = this; |
| 2262 | do { |
| 2263 | if (this.disabledOf(entry.options)) return true; |
| 2264 | entry = entry.parent.ctx.fiber.entry; |
| 2265 | } while (entry); |
| 2266 | return false; |
| 2267 | } |
| 2268 | /** |
| 2269 | * Effective disabled state: a `!!js` expression evaluates against the loader |
| 2270 | * context. The raw node stays in the options, so write-back keeps the form. |
| 2271 | */ |
| 2272 | disabledOf(options) { |
| 2273 | return isJsExpr(options.disabled) ? Boolean(this.evaluate(options.disabled.__jsExpr)) : Boolean(options.disabled); |
| 2274 | } |
| 2275 | evaluate(expr) { |
| 2276 | return evaluate(this.ctx, expr); |
| 2277 | } |
| 2278 | _patchContext(diff) { |
| 2279 | this.context.waterfall("loader/patch-context", this, () => { |
| 2280 | Object.setPrototypeOf(this.ctx, this.parent.ctx); |
| 2281 | if (this.fiber?.uid && (diff.includes("config") || this.options.group)) { |
| 2282 | this.fiber.update(this.options.config, true); |
| 2283 | } |
| 2284 | }); |
| 2285 | } |
| 2286 | async refresh() { |
| 2287 | if (this.fiber) return; |
| 2288 | if (this.disabled) return; |
| 2289 | await this.init(); |
| 2290 | } |
| 2291 | /** Merge new options, restart as needed, and persist through the parent tree. */ |
| 2292 | async update(options, create = false, force = false) { |
| 2293 | const legacy = { ...this.options }; |
| 2294 | if (create) { |
| 2295 | this.options = options; |
| 2296 | } else { |
| 2297 | for (const [key, value] of Object.entries(options)) { |
| 2298 | if (isNullable(value)) { |
| 2299 | delete this.options[key]; |
| 2300 | } else { |
| 2301 | this.options[key] = value; |
| 2302 | } |
| 2303 | } |
| 2304 | } |
| 2305 | sortKeys(this.options); |
| 2306 | if (this.disabled) { |
| 2307 | this.fiber?.dispose(); |
| 2308 | return; |
| 2309 | } |
| 2310 | if (this.fiber?.uid) { |
| 2311 | const diff = Object.keys({ ...this.options, ...legacy }).filter((key) => !deepEqual( |
| 2312 | this.options[key], |
| 2313 | legacy[key] |
| 2314 | )); |
| 2315 | if (!diff.length && !force) return; |
| 2316 | this.context.emit("loader/partial-dispose", this, legacy, true); |
| 2317 | this._patchContext(diff); |
| 2318 | } else { |
| 2319 | await this.init(); |
| 2320 | } |
| 2321 | } |
| 2322 | getOuterStack = () => { |
| 2323 | let entry = this; |
| 2324 | const result = []; |
| 2325 | do { |
| 2326 | result.push(` at ${entry.parent.tree.ctx.baseUrl}#${entry.options.id}`); |
| 2327 | entry = entry.parent.ctx.fiber.entry; |
| 2328 | } while (entry); |
| 2329 | return result; |
| 2330 | }; |
| 2331 | /** Import and start the configured plugin if it is not already running. */ |
| 2332 | async init() { |
| 2333 | try { |
| 2334 | await (this._initTask ??= this._init()); |
| 2335 | } finally { |
| 2336 | this._initTask = void 0; |
| 2337 | } |
| 2338 | const notify = () => { |
| 2339 | if (this.loader.getTasks().length) return; |
| 2340 | this.ctx.reflect.notify(["loader"]); |
| 2341 | }; |
| 2342 | this.fiber?.await().then(notify, notify); |
| 2343 | } |
| 2344 | async _init() { |
| 2345 | let exports; |
| 2346 | try { |
| 2347 | exports = await this.parent.tree.import(this.options.name, this.getOuterStack); |
| 2348 | } catch (error) { |
| 2349 | this.ctx.logger.error(error); |
| 2350 | return; |
| 2351 | } finally { |
| 2352 | this._initTask = void 0; |
| 2353 | } |
| 2354 | const plugin = this.loader.unwrapExports(exports); |
| 2355 | this._patchContext([]); |
| 2356 | this.loader.showLog(this, "apply"); |
| 2357 | this.fiber = this.ctx.registry.plugin(plugin, this.options.config, this.getOuterStack); |
| 2358 | } |
| 2359 | }; |
| 2360 | } |
| 2361 | }); |
| 2362 | |
| 2363 | // src/dsh/upstream/loader/src/config/isolate.ts |
| 2364 | function swap(target, source) { |
| 2365 | for (const key of Reflect.ownKeys(target)) { |
| 2366 | Reflect.deleteProperty(target, key); |
| 2367 | } |
| 2368 | for (const key of Reflect.ownKeys(source || {})) { |
| 2369 | Reflect.defineProperty(target, key, Reflect.getOwnPropertyDescriptor(source, key)); |
| 2370 | } |
| 2371 | } |
| 2372 | function isolate(ctx) { |
| 2373 | const realms = /* @__PURE__ */ Object.create(null); |
| 2374 | const delims = /* @__PURE__ */ Object.create(null); |
| 2375 | function access2(entry, name, create = false) { |
| 2376 | let realm; |
| 2377 | const label = entry.options.isolate?.[name]; |
| 2378 | if (!label) return; |
| 2379 | if (label === true) { |
| 2380 | realm = entry.realm ??= new LocalRealm(entry); |
| 2381 | } else if (create) { |
| 2382 | realm = realms[label] ??= new GlobalRealm(label); |
| 2383 | } else { |
| 2384 | realm = realms[label]; |
| 2385 | } |
| 2386 | return realm?.access(name, create); |
| 2387 | } |
| 2388 | ctx.on("loader/entry-init", (entry) => { |
| 2389 | entry.ctx[Context.intercept] = Object.create(entry.ctx[Context.intercept]); |
| 2390 | entry.ctx[Context.isolate] = Object.create(entry.ctx[Context.isolate]); |
| 2391 | }); |
| 2392 | ctx.on("loader/patch-context", (entry, next) => { |
| 2393 | const newMap = Object.create(entry.parent.ctx[Context.isolate]); |
| 2394 | for (const name of Object.keys(entry.options.isolate ?? {})) { |
| 2395 | newMap[name] = access2(entry, name, true); |
| 2396 | } |
| 2397 | const diff = /* @__PURE__ */ Object.create(null); |
| 2398 | const oldMap = entry.ctx[Context.isolate]; |
| 2399 | for (const name in { ...newMap, ...delims }) { |
| 2400 | if (newMap[name] === oldMap[name]) continue; |
| 2401 | const delim = delims[name] ??= /* @__PURE__ */ Symbol(`delim:${name}`); |
| 2402 | entry.ctx[delim] = /* @__PURE__ */ Symbol(`${name}#${entry.id}`); |
| 2403 | for (const symbol of [oldMap[name], newMap[name]]) { |
| 2404 | const impl = symbol && entry.ctx.reflect.store[symbol]; |
| 2405 | if (!impl) continue; |
| 2406 | if (!impl.fiber) { |
| 2407 | entry.ctx.logger.warn(new Error(`expected service ${name} to be implemented`)); |
| 2408 | continue; |
| 2409 | } |
| 2410 | diff[name] = [oldMap[name], newMap[name], entry.ctx[delim], impl.fiber.ctx[delim]]; |
| 2411 | if (entry.ctx[delim] !== impl.fiber.ctx[delim]) break; |
| 2412 | } |
| 2413 | } |
| 2414 | Object.setPrototypeOf(entry.ctx[Context.isolate], entry.parent.ctx[Context.isolate]); |
| 2415 | Object.setPrototypeOf(entry.ctx[Context.intercept], entry.parent.ctx[Context.intercept]); |
| 2416 | swap(entry.ctx[Context.isolate], newMap); |
| 2417 | swap(entry.ctx[Context.intercept], entry.options.intercept); |
| 2418 | next(); |
| 2419 | for (const [symbol1, symbol2, flag1, flag2] of Object.values(diff)) { |
| 2420 | if (flag1 === flag2 && entry.ctx.reflect.store[symbol1] && !entry.ctx.reflect.store[symbol2]) { |
| 2421 | entry.ctx.reflect.store[symbol2] = entry.ctx.reflect.store[symbol1]; |
| 2422 | delete entry.ctx.reflect.store[symbol1]; |
| 2423 | } |
| 2424 | } |
| 2425 | ctx.reflect.notify(Object.keys(diff), (ctx2, name) => { |
| 2426 | const [symbol1, symbol2, flag1, flag2] = diff[name]; |
| 2427 | const symbol3 = ctx2[Context.isolate][name]; |
| 2428 | const flag3 = ctx2[delims[name]]; |
| 2429 | return (symbol1 === symbol3 || symbol2 === symbol3) && flag1 === flag3 !== (flag1 === flag2); |
| 2430 | }); |
| 2431 | for (const name in delims) { |
| 2432 | if (!Reflect.ownKeys(newMap).includes(name)) { |
| 2433 | delete entry.ctx[delims[name]]; |
| 2434 | } |
| 2435 | } |
| 2436 | }); |
| 2437 | ctx.on("loader/partial-dispose", (entry, legacy, active) => { |
| 2438 | for (const [name, label] of Object.entries(legacy.isolate ?? {})) { |
| 2439 | if (label === true) continue; |
| 2440 | if (active && entry.options.isolate?.[name] === label) continue; |
| 2441 | const realm = realms[label]; |
| 2442 | if (!realm) continue; |
| 2443 | for (const entry2 of ctx.loader.entries()) { |
| 2444 | if (entry2.options.isolate?.[name] === realm.label) return; |
| 2445 | } |
| 2446 | realm.delete(name); |
| 2447 | if (!realm.size) { |
| 2448 | delete realms[realm.label]; |
| 2449 | } |
| 2450 | } |
| 2451 | }); |
| 2452 | } |
| 2453 | var Realm, LocalRealm, GlobalRealm; |
| 2454 | var init_isolate = __esm({ |
| 2455 | "src/dsh/upstream/loader/src/config/isolate.ts"() { |
| 2456 | "use strict"; |
| 2457 | init_lib2(); |
| 2458 | Realm = class { |
| 2459 | store = /* @__PURE__ */ Object.create(null); |
| 2460 | access(key, create = false) { |
| 2461 | if (create) { |
| 2462 | return this.store[key] ??= /* @__PURE__ */ Symbol(`${key}${this.suffix}`); |
| 2463 | } else { |
| 2464 | return this.store[key] ?? /* @__PURE__ */ Symbol(`${key}${this.suffix}`); |
| 2465 | } |
| 2466 | } |
| 2467 | delete(key) { |
| 2468 | delete this.store[key]; |
| 2469 | } |
| 2470 | get size() { |
| 2471 | return Object.keys(this.store).length; |
| 2472 | } |
| 2473 | }; |
| 2474 | LocalRealm = class extends Realm { |
| 2475 | constructor(entry) { |
| 2476 | super(); |
| 2477 | this.entry = entry; |
| 2478 | } |
| 2479 | entry; |
| 2480 | get suffix() { |
| 2481 | return "#" + this.entry.options.id; |
| 2482 | } |
| 2483 | }; |
| 2484 | GlobalRealm = class extends Realm { |
| 2485 | constructor(label) { |
| 2486 | super(); |
| 2487 | this.label = label; |
| 2488 | } |
| 2489 | label; |
| 2490 | get suffix() { |
| 2491 | return "@" + this.label; |
| 2492 | } |
| 2493 | }; |
| 2494 | } |
| 2495 | }); |
| 2496 | |
| 2497 | // src/dsh/upstream/loader/src/internal.ts |
| 2498 | import { createRequire } from "node:module"; |
| 2499 | var ModuleLoader; |
| 2500 | var init_internal = __esm({ |
| 2501 | "src/dsh/upstream/loader/src/internal.ts"() { |
| 2502 | "use strict"; |
| 2503 | ((ModuleLoader2) => { |
| 2504 | let _cachedLoader; |
| 2505 | function requireInternal(id) { |
| 2506 | const require3 = createRequire(import.meta.url); |
| 2507 | if (process.execArgv.includes("--expose-internals")) { |
| 2508 | try { |
| 2509 | return require3(id); |
| 2510 | } catch { |
| 2511 | } |
| 2512 | } |
| 2513 | try { |
| 2514 | return require3("node-addon-require-builtin").requireBuiltin(id); |
| 2515 | } catch { |
| 2516 | } |
| 2517 | } |
| 2518 | function fromInternal() { |
| 2519 | if (_cachedLoader) return _cachedLoader; |
| 2520 | const [major] = process.versions.node.split(".").map(Number); |
| 2521 | if (major < 22) return; |
| 2522 | const raw = requireInternal("internal/modules/esm/loader")?.getOrInitializeCascadedLoader(); |
| 2523 | if (!raw) return; |
| 2524 | const version2 = typeof raw.getOrCreateModuleJob === "function" ? "v2" : typeof raw.getModuleJobForImport === "function" ? "v1" : void 0; |
| 2525 | if (!version2) return; |
| 2526 | return _cachedLoader = Object.assign(raw, { version: version2 }); |
| 2527 | } |
| 2528 | ModuleLoader2.fromInternal = fromInternal; |
| 2529 | })(ModuleLoader || (ModuleLoader = {})); |
| 2530 | } |
| 2531 | }); |
| 2532 | |
| 2533 | // src/dsh/upstream/loader/src/index.ts |
| 2534 | var Loader; |
| 2535 | var init_src = __esm({ |
| 2536 | "src/dsh/upstream/loader/src/index.ts"() { |
| 2537 | "use strict"; |
| 2538 | init_lib2(); |
| 2539 | init_lib(); |
| 2540 | init_entry(); |
| 2541 | init_group(); |
| 2542 | init_isolate(); |
| 2543 | init_tree(); |
| 2544 | init_utils(); |
| 2545 | init_fiber_state(); |
| 2546 | init_entry(); |
| 2547 | init_group(); |
| 2548 | init_isolate(); |
| 2549 | init_tree(); |
| 2550 | init_utils(); |
| 2551 | init_internal(); |
| 2552 | Loader = class extends EntryTree { |
| 2553 | constructor(ctx, config = {}) { |
| 2554 | super(ctx); |
| 2555 | this.config = config; |
| 2556 | if (config.baseUrl) { |
| 2557 | this.ctx.baseUrl = config.baseUrl; |
| 2558 | } |
| 2559 | const self = this; |
| 2560 | defineProperty(this, Service.tracker, { |
| 2561 | associate: "loader", |
| 2562 | property: "ctx", |
| 2563 | noShadow: true |
| 2564 | }); |
| 2565 | ctx.reflect.provide("loader", this, this[Service.check]); |
| 2566 | ctx.on("internal/config", function(_config, next) { |
| 2567 | const config2 = next(); |
| 2568 | if (!this.entry || this.parent.fiber?.entry === this.entry) return config2; |
| 2569 | const plugin = this.runtime?.callback; |
| 2570 | if (plugin?.[EntryGroup.key]) return config2; |
| 2571 | return interpolate(this.ctx, config2); |
| 2572 | }, { global: true }); |
| 2573 | ctx.on("internal/update", function(config2, noSave, next) { |
| 2574 | if (!this.entry || noSave || this.parent.fiber?.entry === this.entry) return next(); |
| 2575 | const unparse = this.runtime?.Config?.simplify; |
| 2576 | this.entry.options.config = unparse ? unparse(config2) : config2; |
| 2577 | this.entry.parent.tree.write(); |
| 2578 | return next(); |
| 2579 | }, { global: true, prepend: true }); |
| 2580 | ctx.on("internal/update", function(config2, _, next) { |
| 2581 | if (!this.entry || this.parent.fiber?.entry === this.entry) return next(); |
| 2582 | self.showLog(this.entry, "reload"); |
| 2583 | return next(); |
| 2584 | }, { global: true }); |
| 2585 | ctx.on("internal/plugin", (fiber) => { |
| 2586 | if (fiber.parent[Entry.key] && !fiber.entry) { |
| 2587 | fiber.entry = fiber.parent[Entry.key]; |
| 2588 | Inject.resolve(fiber.entry.options.inject, fiber.inject); |
| 2589 | } |
| 2590 | if (fiber.uid) return; |
| 2591 | if (!fiber.entry) return; |
| 2592 | if (fiber.parent.fiber?.entry === fiber.entry) return; |
| 2593 | if (!ctx.registry.has(fiber.runtime.callback)) return; |
| 2594 | const treeOwner = fiber.entry.parent.tree.ctx.fiber; |
| 2595 | if (!treeOwner.uid || treeOwner.state === FiberState.UNLOADING) return; |
| 2596 | this.showLog(fiber.entry, "unload"); |
| 2597 | if (fiber.entry.disabled) return; |
| 2598 | fiber.entry.options.disabled = true; |
| 2599 | fiber.entry.parent.tree.write(); |
| 2600 | }); |
| 2601 | ctx.plugin(isolate); |
| 2602 | } |
| 2603 | config; |
| 2604 | envData = process.env.CORDIS_SHARED ? JSON.parse(process.env.CORDIS_SHARED) : { startTime: Date.now() }; |
| 2605 | name = "loader"; |
| 2606 | // Codewhale host delta: native internals/addon probing is unavailable. |
| 2607 | // EntryTree retains upstream's documented native ESM fallback. |
| 2608 | internal = void 0; |
| 2609 | builtins = /* @__PURE__ */ Object.create(null); |
| 2610 | write() { |
| 2611 | } |
| 2612 | [Service.check]() { |
| 2613 | const config = Service.prototype[Service.resolveConfig].call(this); |
| 2614 | if (config.await && this.getTasks().length) return false; |
| 2615 | return true; |
| 2616 | } |
| 2617 | showLog(entry, type2) { |
| 2618 | if (entry.options.group || !entry.parent.tree.enableLogs) return; |
| 2619 | this.ctx.root.logger?.("loader").info("%s plugin %C", type2, entry.options.name); |
| 2620 | } |
| 2621 | /** Return the loader entry id that owns `fiber`, if any. */ |
| 2622 | locate(fiber = this.ctx.fiber) { |
| 2623 | while (1) { |
| 2624 | if (fiber.entry) return fiber.entry.id; |
| 2625 | const next = fiber.parent.fiber; |
| 2626 | if (fiber === next) return; |
| 2627 | fiber = next; |
| 2628 | } |
| 2629 | } |
| 2630 | /** Hook for hosts that can restart the process on full-reload requests. */ |
| 2631 | exit() { |
| 2632 | } |
| 2633 | /** Normalize ESM/CJS/default export shapes before applying a plugin. */ |
| 2634 | unwrapExports(exports) { |
| 2635 | if (isNullable(exports)) return exports; |
| 2636 | exports = exports.default ?? exports; |
| 2637 | if (!exports.__esModule) return exports; |
| 2638 | return exports.default ?? exports; |
| 2639 | } |
| 2640 | }; |
| 2641 | } |
| 2642 | }); |
| 2643 | |
| 2644 | // node_modules/js-yaml/dist/js-yaml.mjs |
| 2645 | function getDefaultExportFromCjs(x) { |
| 2646 | return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x; |
| 2647 | } |
| 2648 | function requireCommon() { |
| 2649 | if (hasRequiredCommon) return common; |
| 2650 | hasRequiredCommon = 1; |
| 2651 | function isNothing(subject) { |
| 2652 | return typeof subject === "undefined" || subject === null; |
| 2653 | } |
| 2654 | function isObject2(subject) { |
| 2655 | return typeof subject === "object" && subject !== null; |
| 2656 | } |
| 2657 | function toArray(sequence) { |
| 2658 | if (Array.isArray(sequence)) return sequence; |
| 2659 | else if (isNothing(sequence)) return []; |
| 2660 | return [sequence]; |
| 2661 | } |
| 2662 | function extend2(target, source) { |
| 2663 | if (source) { |
| 2664 | const sourceKeys = Object.keys(source); |
| 2665 | for (let index = 0, length = sourceKeys.length; index < length; index += 1) { |
| 2666 | const key = sourceKeys[index]; |
| 2667 | target[key] = source[key]; |
| 2668 | } |
| 2669 | } |
| 2670 | return target; |
| 2671 | } |
| 2672 | function repeat(string, count) { |
| 2673 | let result = ""; |
| 2674 | for (let cycle = 0; cycle < count; cycle += 1) { |
| 2675 | result += string; |
| 2676 | } |
| 2677 | return result; |
| 2678 | } |
| 2679 | function isNegativeZero(number) { |
| 2680 | return number === 0 && Number.NEGATIVE_INFINITY === 1 / number; |
| 2681 | } |
| 2682 | common.isNothing = isNothing; |
| 2683 | common.isObject = isObject2; |
| 2684 | common.toArray = toArray; |
| 2685 | common.repeat = repeat; |
| 2686 | common.isNegativeZero = isNegativeZero; |
| 2687 | common.extend = extend2; |
| 2688 | return common; |
| 2689 | } |
| 2690 | function requireException() { |
| 2691 | if (hasRequiredException) return exception; |
| 2692 | hasRequiredException = 1; |
| 2693 | function formatError(exception2, compact) { |
| 2694 | let where = ""; |
| 2695 | const message = exception2.reason || "(unknown reason)"; |
| 2696 | if (!exception2.mark) return message; |
| 2697 | if (exception2.mark.name) { |
| 2698 | where += 'in "' + exception2.mark.name + '" '; |
| 2699 | } |
| 2700 | where += "(" + (exception2.mark.line + 1) + ":" + (exception2.mark.column + 1) + ")"; |
| 2701 | if (!compact && exception2.mark.snippet) { |
| 2702 | where += "\n\n" + exception2.mark.snippet; |
| 2703 | } |
| 2704 | return message + " " + where; |
| 2705 | } |
| 2706 | function YAMLException2(reason, mark) { |
| 2707 | Error.call(this); |
| 2708 | this.name = "YAMLException"; |
| 2709 | this.reason = reason; |
| 2710 | this.mark = mark; |
| 2711 | this.message = formatError(this, false); |
| 2712 | if (Error.captureStackTrace) { |
| 2713 | Error.captureStackTrace(this, this.constructor); |
| 2714 | } else { |
| 2715 | this.stack = new Error().stack || ""; |
| 2716 | } |
| 2717 | } |
| 2718 | YAMLException2.prototype = Object.create(Error.prototype); |
| 2719 | YAMLException2.prototype.constructor = YAMLException2; |
| 2720 | YAMLException2.prototype.toString = function toString2(compact) { |
| 2721 | return this.name + ": " + formatError(this, compact); |
| 2722 | }; |
| 2723 | exception = YAMLException2; |
| 2724 | return exception; |
| 2725 | } |
| 2726 | function requireSnippet() { |
| 2727 | if (hasRequiredSnippet) return snippet; |
| 2728 | hasRequiredSnippet = 1; |
| 2729 | const common2 = requireCommon(); |
| 2730 | function getLine(buffer, lineStart, lineEnd, position, maxLineLength) { |
| 2731 | let head = ""; |
| 2732 | let tail = ""; |
| 2733 | const maxHalfLength = Math.floor(maxLineLength / 2) - 1; |
| 2734 | if (position - lineStart > maxHalfLength) { |
| 2735 | head = " ... "; |
| 2736 | lineStart = position - maxHalfLength + head.length; |
| 2737 | } |
| 2738 | if (lineEnd - position > maxHalfLength) { |
| 2739 | tail = " ..."; |
| 2740 | lineEnd = position + maxHalfLength - tail.length; |
| 2741 | } |
| 2742 | return { |
| 2743 | str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "→") + tail, |
| 2744 | pos: position - lineStart + head.length |
| 2745 | // relative position |
| 2746 | }; |
| 2747 | } |
| 2748 | function padStart(string, max) { |
| 2749 | return common2.repeat(" ", max - string.length) + string; |
| 2750 | } |
| 2751 | function makeSnippet(mark, options) { |
| 2752 | options = Object.create(options || null); |
| 2753 | if (!mark.buffer) return null; |
| 2754 | if (!options.maxLength) options.maxLength = 79; |
| 2755 | if (typeof options.indent !== "number") options.indent = 1; |
| 2756 | if (typeof options.linesBefore !== "number") options.linesBefore = 3; |
| 2757 | if (typeof options.linesAfter !== "number") options.linesAfter = 2; |
| 2758 | const re = /\r?\n|\r|\0/g; |
| 2759 | const lineStarts = [0]; |
| 2760 | const lineEnds = []; |
| 2761 | let match; |
| 2762 | let foundLineNo = -1; |
| 2763 | while (match = re.exec(mark.buffer)) { |
| 2764 | lineEnds.push(match.index); |
| 2765 | lineStarts.push(match.index + match[0].length); |
| 2766 | if (mark.position <= match.index && foundLineNo < 0) { |
| 2767 | foundLineNo = lineStarts.length - 2; |
| 2768 | } |
| 2769 | } |
| 2770 | if (foundLineNo < 0) foundLineNo = lineStarts.length - 1; |
| 2771 | let result = ""; |
| 2772 | const lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length; |
| 2773 | const maxLineLength = options.maxLength - (options.indent + lineNoLength + 3); |
| 2774 | for (let i2 = 1; i2 <= options.linesBefore; i2++) { |
| 2775 | if (foundLineNo - i2 < 0) break; |
| 2776 | const line2 = getLine( |
| 2777 | mark.buffer, |
| 2778 | lineStarts[foundLineNo - i2], |
| 2779 | lineEnds[foundLineNo - i2], |
| 2780 | mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i2]), |
| 2781 | maxLineLength |
| 2782 | ); |
| 2783 | result = common2.repeat(" ", options.indent) + padStart((mark.line - i2 + 1).toString(), lineNoLength) + " | " + line2.str + "\n" + result; |
| 2784 | } |
| 2785 | const line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength); |
| 2786 | result += common2.repeat(" ", options.indent) + padStart((mark.line + 1).toString(), lineNoLength) + " | " + line.str + "\n"; |
| 2787 | result += common2.repeat("-", options.indent + lineNoLength + 3 + line.pos) + "^\n"; |
| 2788 | for (let i2 = 1; i2 <= options.linesAfter; i2++) { |
| 2789 | if (foundLineNo + i2 >= lineEnds.length) break; |
| 2790 | const line2 = getLine( |
| 2791 | mark.buffer, |
| 2792 | lineStarts[foundLineNo + i2], |
| 2793 | lineEnds[foundLineNo + i2], |
| 2794 | mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i2]), |
| 2795 | maxLineLength |
| 2796 | ); |
| 2797 | result += common2.repeat(" ", options.indent) + padStart((mark.line + i2 + 1).toString(), lineNoLength) + " | " + line2.str + "\n"; |
| 2798 | } |
| 2799 | return result.replace(/\n$/, ""); |
| 2800 | } |
| 2801 | snippet = makeSnippet; |
| 2802 | return snippet; |
| 2803 | } |
| 2804 | function requireType() { |
| 2805 | if (hasRequiredType) return type; |
| 2806 | hasRequiredType = 1; |
| 2807 | const YAMLException2 = requireException(); |
| 2808 | const TYPE_CONSTRUCTOR_OPTIONS = [ |
| 2809 | "kind", |
| 2810 | "multi", |
| 2811 | "resolve", |
| 2812 | "construct", |
| 2813 | "instanceOf", |
| 2814 | "predicate", |
| 2815 | "represent", |
| 2816 | "representName", |
| 2817 | "defaultStyle", |
| 2818 | "styleAliases" |
| 2819 | ]; |
| 2820 | const YAML_NODE_KINDS = [ |
| 2821 | "scalar", |
| 2822 | "sequence", |
| 2823 | "mapping" |
| 2824 | ]; |
| 2825 | function compileStyleAliases(map2) { |
| 2826 | const result = {}; |
| 2827 | if (map2 !== null) { |
| 2828 | Object.keys(map2).forEach(function(style) { |
| 2829 | map2[style].forEach(function(alias) { |
| 2830 | result[String(alias)] = style; |
| 2831 | }); |
| 2832 | }); |
| 2833 | } |
| 2834 | return result; |
| 2835 | } |
| 2836 | function Type2(tag, options) { |
| 2837 | options = options || {}; |
| 2838 | Object.keys(options).forEach(function(name) { |
| 2839 | if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) { |
| 2840 | throw new YAMLException2('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.'); |
| 2841 | } |
| 2842 | }); |
| 2843 | this.options = options; |
| 2844 | this.tag = tag; |
| 2845 | this.kind = options["kind"] || null; |
| 2846 | this.resolve = options["resolve"] || function() { |
| 2847 | return true; |
| 2848 | }; |
| 2849 | this.construct = options["construct"] || function(data2) { |
| 2850 | return data2; |
| 2851 | }; |
| 2852 | this.instanceOf = options["instanceOf"] || null; |
| 2853 | this.predicate = options["predicate"] || null; |
| 2854 | this.represent = options["represent"] || null; |
| 2855 | this.representName = options["representName"] || null; |
| 2856 | this.defaultStyle = options["defaultStyle"] || null; |
| 2857 | this.multi = options["multi"] || false; |
| 2858 | this.styleAliases = compileStyleAliases(options["styleAliases"] || null); |
| 2859 | if (YAML_NODE_KINDS.indexOf(this.kind) === -1) { |
| 2860 | throw new YAMLException2('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.'); |
| 2861 | } |
| 2862 | } |
| 2863 | type = Type2; |
| 2864 | return type; |
| 2865 | } |
| 2866 | function requireSchema() { |
| 2867 | if (hasRequiredSchema) return schema; |
| 2868 | hasRequiredSchema = 1; |
| 2869 | const YAMLException2 = requireException(); |
| 2870 | const Type2 = requireType(); |
| 2871 | function compileList(schema22, name) { |
| 2872 | const result = []; |
| 2873 | schema22[name].forEach(function(currentType) { |
| 2874 | let newIndex = result.length; |
| 2875 | result.forEach(function(previousType, previousIndex) { |
| 2876 | if (previousType.tag === currentType.tag && previousType.kind === currentType.kind && previousType.multi === currentType.multi) { |
| 2877 | newIndex = previousIndex; |
| 2878 | } |
| 2879 | }); |
| 2880 | result[newIndex] = currentType; |
| 2881 | }); |
| 2882 | return result; |
| 2883 | } |
| 2884 | function compileMap() { |
| 2885 | const result = { |
| 2886 | scalar: {}, |
| 2887 | sequence: {}, |
| 2888 | mapping: {}, |
| 2889 | fallback: {}, |
| 2890 | multi: { |
| 2891 | scalar: [], |
| 2892 | sequence: [], |
| 2893 | mapping: [], |
| 2894 | fallback: [] |
| 2895 | } |
| 2896 | }; |
| 2897 | function collectType(type2) { |
| 2898 | if (type2.multi) { |
| 2899 | result.multi[type2.kind].push(type2); |
| 2900 | result.multi["fallback"].push(type2); |
| 2901 | } else { |
| 2902 | result[type2.kind][type2.tag] = result["fallback"][type2.tag] = type2; |
| 2903 | } |
| 2904 | } |
| 2905 | for (let index = 0, length = arguments.length; index < length; index += 1) { |
| 2906 | arguments[index].forEach(collectType); |
| 2907 | } |
| 2908 | return result; |
| 2909 | } |
| 2910 | function Schema2(definition) { |
| 2911 | return this.extend(definition); |
| 2912 | } |
| 2913 | Schema2.prototype.extend = function extend2(definition) { |
| 2914 | let implicit = []; |
| 2915 | let explicit = []; |
| 2916 | if (definition instanceof Type2) { |
| 2917 | explicit.push(definition); |
| 2918 | } else if (Array.isArray(definition)) { |
| 2919 | explicit = explicit.concat(definition); |
| 2920 | } else if (definition && (Array.isArray(definition.implicit) || Array.isArray(definition.explicit))) { |
| 2921 | if (definition.implicit) implicit = implicit.concat(definition.implicit); |
| 2922 | if (definition.explicit) explicit = explicit.concat(definition.explicit); |
| 2923 | } else { |
| 2924 | throw new YAMLException2("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })"); |
| 2925 | } |
| 2926 | implicit.forEach(function(type2) { |
| 2927 | if (!(type2 instanceof Type2)) { |
| 2928 | throw new YAMLException2("Specified list of YAML types (or a single Type object) contains a non-Type object."); |
| 2929 | } |
| 2930 | if (type2.loadKind && type2.loadKind !== "scalar") { |
| 2931 | throw new YAMLException2("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported."); |
| 2932 | } |
| 2933 | if (type2.multi) { |
| 2934 | throw new YAMLException2("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit."); |
| 2935 | } |
| 2936 | }); |
| 2937 | explicit.forEach(function(type2) { |
| 2938 | if (!(type2 instanceof Type2)) { |
| 2939 | throw new YAMLException2("Specified list of YAML types (or a single Type object) contains a non-Type object."); |
| 2940 | } |
| 2941 | }); |
| 2942 | const result = Object.create(Schema2.prototype); |
| 2943 | result.implicit = (this.implicit || []).concat(implicit); |
| 2944 | result.explicit = (this.explicit || []).concat(explicit); |
| 2945 | result.compiledImplicit = compileList(result, "implicit"); |
| 2946 | result.compiledExplicit = compileList(result, "explicit"); |
| 2947 | result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit); |
| 2948 | return result; |
| 2949 | }; |
| 2950 | schema = Schema2; |
| 2951 | return schema; |
| 2952 | } |
| 2953 | function requireStr() { |
| 2954 | if (hasRequiredStr) return str; |
| 2955 | hasRequiredStr = 1; |
| 2956 | const Type2 = requireType(); |
| 2957 | str = new Type2("tag:yaml.org,2002:str", { |
| 2958 | kind: "scalar", |
| 2959 | construct: function(data2) { |
| 2960 | return data2 !== null ? data2 : ""; |
| 2961 | } |
| 2962 | }); |
| 2963 | return str; |
| 2964 | } |
| 2965 | function requireSeq() { |
| 2966 | if (hasRequiredSeq) return seq; |
| 2967 | hasRequiredSeq = 1; |
| 2968 | const Type2 = requireType(); |
| 2969 | seq = new Type2("tag:yaml.org,2002:seq", { |
| 2970 | kind: "sequence", |
| 2971 | construct: function(data2) { |
| 2972 | return data2 !== null ? data2 : []; |
| 2973 | } |
| 2974 | }); |
| 2975 | return seq; |
| 2976 | } |
| 2977 | function requireMap() { |
| 2978 | if (hasRequiredMap) return map; |
| 2979 | hasRequiredMap = 1; |
| 2980 | const Type2 = requireType(); |
| 2981 | map = new Type2("tag:yaml.org,2002:map", { |
| 2982 | kind: "mapping", |
| 2983 | construct: function(data2) { |
| 2984 | return data2 !== null ? data2 : {}; |
| 2985 | } |
| 2986 | }); |
| 2987 | return map; |
| 2988 | } |
| 2989 | function requireFailsafe() { |
| 2990 | if (hasRequiredFailsafe) return failsafe; |
| 2991 | hasRequiredFailsafe = 1; |
| 2992 | const Schema2 = requireSchema(); |
| 2993 | failsafe = new Schema2({ |
| 2994 | explicit: [ |
| 2995 | requireStr(), |
| 2996 | requireSeq(), |
| 2997 | requireMap() |
| 2998 | ] |
| 2999 | }); |
| 3000 | return failsafe; |
| 3001 | } |
| 3002 | function require_null() { |
| 3003 | if (hasRequired_null) return _null; |
| 3004 | hasRequired_null = 1; |
| 3005 | const Type2 = requireType(); |
| 3006 | function resolveYamlNull(data2) { |
| 3007 | if (data2 === null) return true; |
| 3008 | const max = data2.length; |
| 3009 | return max === 1 && data2 === "~" || max === 4 && (data2 === "null" || data2 === "Null" || data2 === "NULL"); |
| 3010 | } |
| 3011 | function constructYamlNull() { |
| 3012 | return null; |
| 3013 | } |
| 3014 | function isNull(object) { |
| 3015 | return object === null; |
| 3016 | } |
| 3017 | _null = new Type2("tag:yaml.org,2002:null", { |
| 3018 | kind: "scalar", |
| 3019 | resolve: resolveYamlNull, |
| 3020 | construct: constructYamlNull, |
| 3021 | predicate: isNull, |
| 3022 | represent: { |
| 3023 | canonical: function() { |
| 3024 | return "~"; |
| 3025 | }, |
| 3026 | lowercase: function() { |
| 3027 | return "null"; |
| 3028 | }, |
| 3029 | uppercase: function() { |
| 3030 | return "NULL"; |
| 3031 | }, |
| 3032 | camelcase: function() { |
| 3033 | return "Null"; |
| 3034 | }, |
| 3035 | empty: function() { |
| 3036 | return ""; |
| 3037 | } |
| 3038 | }, |
| 3039 | defaultStyle: "lowercase" |
| 3040 | }); |
| 3041 | return _null; |
| 3042 | } |
| 3043 | function requireBool() { |
| 3044 | if (hasRequiredBool) return bool; |
| 3045 | hasRequiredBool = 1; |
| 3046 | const Type2 = requireType(); |
| 3047 | function resolveYamlBoolean(data2) { |
| 3048 | if (data2 === null) return false; |
| 3049 | const max = data2.length; |
| 3050 | return max === 4 && (data2 === "true" || data2 === "True" || data2 === "TRUE") || max === 5 && (data2 === "false" || data2 === "False" || data2 === "FALSE"); |
| 3051 | } |
| 3052 | function constructYamlBoolean(data2) { |
| 3053 | return data2 === "true" || data2 === "True" || data2 === "TRUE"; |
| 3054 | } |
| 3055 | function isBoolean(object) { |
| 3056 | return Object.prototype.toString.call(object) === "[object Boolean]"; |
| 3057 | } |
| 3058 | bool = new Type2("tag:yaml.org,2002:bool", { |
| 3059 | kind: "scalar", |
| 3060 | resolve: resolveYamlBoolean, |
| 3061 | construct: constructYamlBoolean, |
| 3062 | predicate: isBoolean, |
| 3063 | represent: { |
| 3064 | lowercase: function(object) { |
| 3065 | return object ? "true" : "false"; |
| 3066 | }, |
| 3067 | uppercase: function(object) { |
| 3068 | return object ? "TRUE" : "FALSE"; |
| 3069 | }, |
| 3070 | camelcase: function(object) { |
| 3071 | return object ? "True" : "False"; |
| 3072 | } |
| 3073 | }, |
| 3074 | defaultStyle: "lowercase" |
| 3075 | }); |
| 3076 | return bool; |
| 3077 | } |
| 3078 | function requireInt() { |
| 3079 | if (hasRequiredInt) return int; |
| 3080 | hasRequiredInt = 1; |
| 3081 | const common2 = requireCommon(); |
| 3082 | const Type2 = requireType(); |
| 3083 | function isHexCode(c) { |
| 3084 | return c >= 48 && c <= 57 || c >= 65 && c <= 70 || c >= 97 && c <= 102; |
| 3085 | } |
| 3086 | function isOctCode(c) { |
| 3087 | return c >= 48 && c <= 55; |
| 3088 | } |
| 3089 | function isDecCode(c) { |
| 3090 | return c >= 48 && c <= 57; |
| 3091 | } |
| 3092 | function resolveYamlInteger(data2) { |
| 3093 | if (data2 === null) return false; |
| 3094 | const max = data2.length; |
| 3095 | let index = 0; |
| 3096 | let hasDigits = false; |
| 3097 | if (!max) return false; |
| 3098 | let ch = data2[index]; |
| 3099 | if (ch === "-" || ch === "+") { |
| 3100 | ch = data2[++index]; |
| 3101 | } |
| 3102 | if (ch === "0") { |
| 3103 | if (index + 1 === max) return true; |
| 3104 | ch = data2[++index]; |
| 3105 | if (ch === "b") { |
| 3106 | index++; |
| 3107 | for (; index < max; index++) { |
| 3108 | ch = data2[index]; |
| 3109 | if (ch !== "0" && ch !== "1") return false; |
| 3110 | hasDigits = true; |
| 3111 | } |
| 3112 | return hasDigits && isFinite(parseYamlInteger(data2)); |
| 3113 | } |
| 3114 | if (ch === "x") { |
| 3115 | index++; |
| 3116 | for (; index < max; index++) { |
| 3117 | if (!isHexCode(data2.charCodeAt(index))) return false; |
| 3118 | hasDigits = true; |
| 3119 | } |
| 3120 | return hasDigits && isFinite(parseYamlInteger(data2)); |
| 3121 | } |
| 3122 | if (ch === "o") { |
| 3123 | index++; |
| 3124 | for (; index < max; index++) { |
| 3125 | if (!isOctCode(data2.charCodeAt(index))) return false; |
| 3126 | hasDigits = true; |
| 3127 | } |
| 3128 | return hasDigits && isFinite(parseYamlInteger(data2)); |
| 3129 | } |
| 3130 | } |
| 3131 | for (; index < max; index++) { |
| 3132 | if (!isDecCode(data2.charCodeAt(index))) { |
| 3133 | return false; |
| 3134 | } |
| 3135 | hasDigits = true; |
| 3136 | } |
| 3137 | if (!hasDigits) return false; |
| 3138 | return isFinite(parseYamlInteger(data2)); |
| 3139 | } |
| 3140 | function parseYamlInteger(data2) { |
| 3141 | let value = data2; |
| 3142 | let sign = 1; |
| 3143 | let ch = value[0]; |
| 3144 | if (ch === "-" || ch === "+") { |
| 3145 | if (ch === "-") sign = -1; |
| 3146 | value = value.slice(1); |
| 3147 | ch = value[0]; |
| 3148 | } |
| 3149 | if (value === "0") return 0; |
| 3150 | if (ch === "0") { |
| 3151 | if (value[1] === "b") return sign * parseInt(value.slice(2), 2); |
| 3152 | if (value[1] === "x") return sign * parseInt(value.slice(2), 16); |
| 3153 | if (value[1] === "o") return sign * parseInt(value.slice(2), 8); |
| 3154 | } |
| 3155 | return sign * parseInt(value, 10); |
| 3156 | } |
| 3157 | function constructYamlInteger(data2) { |
| 3158 | return parseYamlInteger(data2); |
| 3159 | } |
| 3160 | function isInteger(object) { |
| 3161 | return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 === 0 && !common2.isNegativeZero(object)); |
| 3162 | } |
| 3163 | int = new Type2("tag:yaml.org,2002:int", { |
| 3164 | kind: "scalar", |
| 3165 | resolve: resolveYamlInteger, |
| 3166 | construct: constructYamlInteger, |
| 3167 | predicate: isInteger, |
| 3168 | represent: { |
| 3169 | binary: function(obj) { |
| 3170 | return obj >= 0 ? "0b" + obj.toString(2) : "-0b" + obj.toString(2).slice(1); |
| 3171 | }, |
| 3172 | octal: function(obj) { |
| 3173 | return obj >= 0 ? "0o" + obj.toString(8) : "-0o" + obj.toString(8).slice(1); |
| 3174 | }, |
| 3175 | decimal: function(obj) { |
| 3176 | return obj.toString(10); |
| 3177 | }, |
| 3178 | hexadecimal: function(obj) { |
| 3179 | return obj >= 0 ? "0x" + obj.toString(16).toUpperCase() : "-0x" + obj.toString(16).toUpperCase().slice(1); |
| 3180 | } |
| 3181 | }, |
| 3182 | defaultStyle: "decimal", |
| 3183 | styleAliases: { |
| 3184 | binary: [2, "bin"], |
| 3185 | octal: [8, "oct"], |
| 3186 | decimal: [10, "dec"], |
| 3187 | hexadecimal: [16, "hex"] |
| 3188 | } |
| 3189 | }); |
| 3190 | return int; |
| 3191 | } |
| 3192 | function requireFloat() { |
| 3193 | if (hasRequiredFloat) return float; |
| 3194 | hasRequiredFloat = 1; |
| 3195 | const common2 = requireCommon(); |
| 3196 | const Type2 = requireType(); |
| 3197 | const YAML_FLOAT_PATTERN = new RegExp( |
| 3198 | // 2.5e4, 2.5 and integers |
| 3199 | "^(?:[-+]?(?:[0-9]+)(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$" |
| 3200 | ); |
| 3201 | const YAML_FLOAT_SPECIAL_PATTERN = new RegExp( |
| 3202 | "^(?:[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$" |
| 3203 | ); |
| 3204 | function resolveYamlFloat(data2) { |
| 3205 | if (data2 === null) return false; |
| 3206 | if (!YAML_FLOAT_PATTERN.test(data2)) { |
| 3207 | return false; |
| 3208 | } |
| 3209 | if (isFinite(parseFloat(data2, 10))) { |
| 3210 | return true; |
| 3211 | } |
| 3212 | return YAML_FLOAT_SPECIAL_PATTERN.test(data2); |
| 3213 | } |
| 3214 | function constructYamlFloat(data2) { |
| 3215 | let value = data2.toLowerCase(); |
| 3216 | const sign = value[0] === "-" ? -1 : 1; |
| 3217 | if ("+-".indexOf(value[0]) >= 0) { |
| 3218 | value = value.slice(1); |
| 3219 | } |
| 3220 | if (value === ".inf") { |
| 3221 | return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY; |
| 3222 | } else if (value === ".nan") { |
| 3223 | return NaN; |
| 3224 | } |
| 3225 | return sign * parseFloat(value, 10); |
| 3226 | } |
| 3227 | const SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/; |
| 3228 | function representYamlFloat(object, style) { |
| 3229 | if (isNaN(object)) { |
| 3230 | switch (style) { |
| 3231 | case "lowercase": |
| 3232 | return ".nan"; |
| 3233 | case "uppercase": |
| 3234 | return ".NAN"; |
| 3235 | case "camelcase": |
| 3236 | return ".NaN"; |
| 3237 | } |
| 3238 | } else if (Number.POSITIVE_INFINITY === object) { |
| 3239 | switch (style) { |
| 3240 | case "lowercase": |
| 3241 | return ".inf"; |
| 3242 | case "uppercase": |
| 3243 | return ".INF"; |
| 3244 | case "camelcase": |
| 3245 | return ".Inf"; |
| 3246 | } |
| 3247 | } else if (Number.NEGATIVE_INFINITY === object) { |
| 3248 | switch (style) { |
| 3249 | case "lowercase": |
| 3250 | return "-.inf"; |
| 3251 | case "uppercase": |
| 3252 | return "-.INF"; |
| 3253 | case "camelcase": |
| 3254 | return "-.Inf"; |
| 3255 | } |
| 3256 | } else if (common2.isNegativeZero(object)) { |
| 3257 | return "-0.0"; |
| 3258 | } |
| 3259 | const res = object.toString(10); |
| 3260 | return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace("e", ".e") : res; |
| 3261 | } |
| 3262 | function isFloat(object) { |
| 3263 | return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 !== 0 || common2.isNegativeZero(object)); |
| 3264 | } |
| 3265 | float = new Type2("tag:yaml.org,2002:float", { |
| 3266 | kind: "scalar", |
| 3267 | resolve: resolveYamlFloat, |
| 3268 | construct: constructYamlFloat, |
| 3269 | predicate: isFloat, |
| 3270 | represent: representYamlFloat, |
| 3271 | defaultStyle: "lowercase" |
| 3272 | }); |
| 3273 | return float; |
| 3274 | } |
| 3275 | function requireJson() { |
| 3276 | if (hasRequiredJson) return json; |
| 3277 | hasRequiredJson = 1; |
| 3278 | json = requireFailsafe().extend({ |
| 3279 | implicit: [ |
| 3280 | require_null(), |
| 3281 | requireBool(), |
| 3282 | requireInt(), |
| 3283 | requireFloat() |
| 3284 | ] |
| 3285 | }); |
| 3286 | return json; |
| 3287 | } |
| 3288 | function requireCore() { |
| 3289 | if (hasRequiredCore) return core; |
| 3290 | hasRequiredCore = 1; |
| 3291 | core = requireJson(); |
| 3292 | return core; |
| 3293 | } |
| 3294 | function requireTimestamp() { |
| 3295 | if (hasRequiredTimestamp) return timestamp; |
| 3296 | hasRequiredTimestamp = 1; |
| 3297 | const Type2 = requireType(); |
| 3298 | const YAML_DATE_REGEXP = new RegExp( |
| 3299 | "^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$" |
| 3300 | ); |
| 3301 | const YAML_TIMESTAMP_REGEXP = new RegExp( |
| 3302 | "^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$" |
| 3303 | ); |
| 3304 | function resolveYamlTimestamp(data2) { |
| 3305 | if (data2 === null) return false; |
| 3306 | if (YAML_DATE_REGEXP.exec(data2) !== null) return true; |
| 3307 | if (YAML_TIMESTAMP_REGEXP.exec(data2) !== null) return true; |
| 3308 | return false; |
| 3309 | } |
| 3310 | function constructYamlTimestamp(data2) { |
| 3311 | let fraction = 0; |
| 3312 | let delta = null; |
| 3313 | let match = YAML_DATE_REGEXP.exec(data2); |
| 3314 | if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data2); |
| 3315 | if (match === null) throw new Error("Date resolve error"); |
| 3316 | const year = +match[1]; |
| 3317 | const month = +match[2] - 1; |
| 3318 | const day = +match[3]; |
| 3319 | if (!match[4]) { |
| 3320 | return new Date(Date.UTC(year, month, day)); |
| 3321 | } |
| 3322 | const hour = +match[4]; |
| 3323 | const minute = +match[5]; |
| 3324 | const second = +match[6]; |
| 3325 | if (match[7]) { |
| 3326 | fraction = match[7].slice(0, 3); |
| 3327 | while (fraction.length < 3) { |
| 3328 | fraction += "0"; |
| 3329 | } |
| 3330 | fraction = +fraction; |
| 3331 | } |
| 3332 | if (match[9]) { |
| 3333 | const tzHour = +match[10]; |
| 3334 | const tzMinute = +(match[11] || 0); |
| 3335 | delta = (tzHour * 60 + tzMinute) * 6e4; |
| 3336 | if (match[9] === "-") delta = -delta; |
| 3337 | } |
| 3338 | const date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction)); |
| 3339 | if (delta) date.setTime(date.getTime() - delta); |
| 3340 | return date; |
| 3341 | } |
| 3342 | function representYamlTimestamp(object) { |
| 3343 | return object.toISOString(); |
| 3344 | } |
| 3345 | timestamp = new Type2("tag:yaml.org,2002:timestamp", { |
| 3346 | kind: "scalar", |
| 3347 | resolve: resolveYamlTimestamp, |
| 3348 | construct: constructYamlTimestamp, |
| 3349 | instanceOf: Date, |
| 3350 | represent: representYamlTimestamp |
| 3351 | }); |
| 3352 | return timestamp; |
| 3353 | } |
| 3354 | function requireMerge() { |
| 3355 | if (hasRequiredMerge) return merge; |
| 3356 | hasRequiredMerge = 1; |
| 3357 | const Type2 = requireType(); |
| 3358 | function resolveYamlMerge(data2) { |
| 3359 | return data2 === "<<" || data2 === null; |
| 3360 | } |
| 3361 | merge = new Type2("tag:yaml.org,2002:merge", { |
| 3362 | kind: "scalar", |
| 3363 | resolve: resolveYamlMerge |
| 3364 | }); |
| 3365 | return merge; |
| 3366 | } |
| 3367 | function requireBinary() { |
| 3368 | if (hasRequiredBinary) return binary; |
| 3369 | hasRequiredBinary = 1; |
| 3370 | const Type2 = requireType(); |
| 3371 | const BASE64_MAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r"; |
| 3372 | function resolveYamlBinary(data2) { |
| 3373 | if (data2 === null) return false; |
| 3374 | let bitlen = 0; |
| 3375 | const max = data2.length; |
| 3376 | const map2 = BASE64_MAP; |
| 3377 | for (let idx = 0; idx < max; idx++) { |
| 3378 | const code = map2.indexOf(data2.charAt(idx)); |
| 3379 | if (code > 64) continue; |
| 3380 | if (code < 0) return false; |
| 3381 | bitlen += 6; |
| 3382 | } |
| 3383 | return bitlen % 8 === 0; |
| 3384 | } |
| 3385 | function constructYamlBinary(data2) { |
| 3386 | const input = data2.replace(/[\r\n=]/g, ""); |
| 3387 | const max = input.length; |
| 3388 | const map2 = BASE64_MAP; |
| 3389 | let bits = 0; |
| 3390 | const result = []; |
| 3391 | for (let idx = 0; idx < max; idx++) { |
| 3392 | if (idx % 4 === 0 && idx) { |
| 3393 | result.push(bits >> 16 & 255); |
| 3394 | result.push(bits >> 8 & 255); |
| 3395 | result.push(bits & 255); |
| 3396 | } |
| 3397 | bits = bits << 6 | map2.indexOf(input.charAt(idx)); |
| 3398 | } |
| 3399 | const tailbits = max % 4 * 6; |
| 3400 | if (tailbits === 0) { |
| 3401 | result.push(bits >> 16 & 255); |
| 3402 | result.push(bits >> 8 & 255); |
| 3403 | result.push(bits & 255); |
| 3404 | } else if (tailbits === 18) { |
| 3405 | result.push(bits >> 10 & 255); |
| 3406 | result.push(bits >> 2 & 255); |
| 3407 | } else if (tailbits === 12) { |
| 3408 | result.push(bits >> 4 & 255); |
| 3409 | } |
| 3410 | return new Uint8Array(result); |
| 3411 | } |
| 3412 | function representYamlBinary(object) { |
| 3413 | let result = ""; |
| 3414 | let bits = 0; |
| 3415 | const max = object.length; |
| 3416 | const map2 = BASE64_MAP; |
| 3417 | for (let idx = 0; idx < max; idx++) { |
| 3418 | if (idx % 3 === 0 && idx) { |
| 3419 | result += map2[bits >> 18 & 63]; |
| 3420 | result += map2[bits >> 12 & 63]; |
| 3421 | result += map2[bits >> 6 & 63]; |
| 3422 | result += map2[bits & 63]; |
| 3423 | } |
| 3424 | bits = (bits << 8) + object[idx]; |
| 3425 | } |
| 3426 | const tail = max % 3; |
| 3427 | if (tail === 0) { |
| 3428 | result += map2[bits >> 18 & 63]; |
| 3429 | result += map2[bits >> 12 & 63]; |
| 3430 | result += map2[bits >> 6 & 63]; |
| 3431 | result += map2[bits & 63]; |
| 3432 | } else if (tail === 2) { |
| 3433 | result += map2[bits >> 10 & 63]; |
| 3434 | result += map2[bits >> 4 & 63]; |
| 3435 | result += map2[bits << 2 & 63]; |
| 3436 | result += map2[64]; |
| 3437 | } else if (tail === 1) { |
| 3438 | result += map2[bits >> 2 & 63]; |
| 3439 | result += map2[bits << 4 & 63]; |
| 3440 | result += map2[64]; |
| 3441 | result += map2[64]; |
| 3442 | } |
| 3443 | return result; |
| 3444 | } |
| 3445 | function isBinary(obj) { |
| 3446 | return Object.prototype.toString.call(obj) === "[object Uint8Array]"; |
| 3447 | } |
| 3448 | binary = new Type2("tag:yaml.org,2002:binary", { |
| 3449 | kind: "scalar", |
| 3450 | resolve: resolveYamlBinary, |
| 3451 | construct: constructYamlBinary, |
| 3452 | predicate: isBinary, |
| 3453 | represent: representYamlBinary |
| 3454 | }); |
| 3455 | return binary; |
| 3456 | } |
| 3457 | function requireOmap() { |
| 3458 | if (hasRequiredOmap) return omap; |
| 3459 | hasRequiredOmap = 1; |
| 3460 | const Type2 = requireType(); |
| 3461 | const _hasOwnProperty = Object.prototype.hasOwnProperty; |
| 3462 | const _toString = Object.prototype.toString; |
| 3463 | function resolveYamlOmap(data2) { |
| 3464 | if (data2 === null) return true; |
| 3465 | const objectKeys = {}; |
| 3466 | const object = data2; |
| 3467 | for (let index = 0, length = object.length; index < length; index += 1) { |
| 3468 | const pair = object[index]; |
| 3469 | let pairHasKey = false; |
| 3470 | if (_toString.call(pair) !== "[object Object]") return false; |
| 3471 | let pairKey; |
| 3472 | for (pairKey in pair) { |
| 3473 | if (_hasOwnProperty.call(pair, pairKey)) { |
| 3474 | if (!pairHasKey) pairHasKey = true; |
| 3475 | else return false; |
| 3476 | } |
| 3477 | } |
| 3478 | if (!pairHasKey) return false; |
| 3479 | if (_hasOwnProperty.call(objectKeys, pairKey)) return false; |
| 3480 | Object.defineProperty(objectKeys, pairKey, { value: true }); |
| 3481 | } |
| 3482 | return true; |
| 3483 | } |
| 3484 | function constructYamlOmap(data2) { |
| 3485 | return data2 !== null ? data2 : []; |
| 3486 | } |
| 3487 | omap = new Type2("tag:yaml.org,2002:omap", { |
| 3488 | kind: "sequence", |
| 3489 | resolve: resolveYamlOmap, |
| 3490 | construct: constructYamlOmap |
| 3491 | }); |
| 3492 | return omap; |
| 3493 | } |
| 3494 | function requirePairs() { |
| 3495 | if (hasRequiredPairs) return pairs; |
| 3496 | hasRequiredPairs = 1; |
| 3497 | const Type2 = requireType(); |
| 3498 | const _toString = Object.prototype.toString; |
| 3499 | function resolveYamlPairs(data2) { |
| 3500 | if (data2 === null) return true; |
| 3501 | const object = data2; |
| 3502 | const result = new Array(object.length); |
| 3503 | for (let index = 0, length = object.length; index < length; index += 1) { |
| 3504 | const pair = object[index]; |
| 3505 | if (_toString.call(pair) !== "[object Object]") return false; |
| 3506 | const keys = Object.keys(pair); |
| 3507 | if (keys.length !== 1) return false; |
| 3508 | result[index] = [keys[0], pair[keys[0]]]; |
| 3509 | } |
| 3510 | return true; |
| 3511 | } |
| 3512 | function constructYamlPairs(data2) { |
| 3513 | if (data2 === null) return []; |
| 3514 | const object = data2; |
| 3515 | const result = new Array(object.length); |
| 3516 | for (let index = 0, length = object.length; index < length; index += 1) { |
| 3517 | const pair = object[index]; |
| 3518 | const keys = Object.keys(pair); |
| 3519 | result[index] = [keys[0], pair[keys[0]]]; |
| 3520 | } |
| 3521 | return result; |
| 3522 | } |
| 3523 | pairs = new Type2("tag:yaml.org,2002:pairs", { |
| 3524 | kind: "sequence", |
| 3525 | resolve: resolveYamlPairs, |
| 3526 | construct: constructYamlPairs |
| 3527 | }); |
| 3528 | return pairs; |
| 3529 | } |
| 3530 | function requireSet() { |
| 3531 | if (hasRequiredSet) return set; |
| 3532 | hasRequiredSet = 1; |
| 3533 | const Type2 = requireType(); |
| 3534 | const _hasOwnProperty = Object.prototype.hasOwnProperty; |
| 3535 | function resolveYamlSet(data2) { |
| 3536 | if (data2 === null) return true; |
| 3537 | const object = data2; |
| 3538 | for (const key in object) { |
| 3539 | if (_hasOwnProperty.call(object, key)) { |
| 3540 | if (object[key] !== null) return false; |
| 3541 | } |
| 3542 | } |
| 3543 | return true; |
| 3544 | } |
| 3545 | function constructYamlSet(data2) { |
| 3546 | return data2 !== null ? data2 : {}; |
| 3547 | } |
| 3548 | set = new Type2("tag:yaml.org,2002:set", { |
| 3549 | kind: "mapping", |
| 3550 | resolve: resolveYamlSet, |
| 3551 | construct: constructYamlSet |
| 3552 | }); |
| 3553 | return set; |
| 3554 | } |
| 3555 | function require_default() { |
| 3556 | if (hasRequired_default) return _default; |
| 3557 | hasRequired_default = 1; |
| 3558 | _default = requireCore().extend({ |
| 3559 | implicit: [ |
| 3560 | requireTimestamp(), |
| 3561 | requireMerge() |
| 3562 | ], |
| 3563 | explicit: [ |
| 3564 | requireBinary(), |
| 3565 | requireOmap(), |
| 3566 | requirePairs(), |
| 3567 | requireSet() |
| 3568 | ] |
| 3569 | }); |
| 3570 | return _default; |
| 3571 | } |
| 3572 | function requireLoader() { |
| 3573 | if (hasRequiredLoader) return loader; |
| 3574 | hasRequiredLoader = 1; |
| 3575 | const common2 = requireCommon(); |
| 3576 | const YAMLException2 = requireException(); |
| 3577 | const makeSnippet = requireSnippet(); |
| 3578 | const DEFAULT_SCHEMA2 = require_default(); |
| 3579 | const _hasOwnProperty = Object.prototype.hasOwnProperty; |
| 3580 | const CONTEXT_FLOW_IN = 1; |
| 3581 | const CONTEXT_FLOW_OUT = 2; |
| 3582 | const CONTEXT_BLOCK_IN = 3; |
| 3583 | const CONTEXT_BLOCK_OUT = 4; |
| 3584 | const CHOMPING_CLIP = 1; |
| 3585 | const CHOMPING_STRIP = 2; |
| 3586 | const CHOMPING_KEEP = 3; |
| 3587 | const PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/; |
| 3588 | const PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/; |
| 3589 | const PATTERN_FLOW_INDICATORS = /[,\[\]{}]/; |
| 3590 | const PATTERN_TAG_HANDLE = /^(?:!|!!|![0-9A-Za-z-]+!)$/; |
| 3591 | const PATTERN_TAG_URI = /^(?:!|[^,\[\]{}])(?:%[0-9a-f]{2}|[0-9a-z\-#;/?:@&=+$,_.!~*'()\[\]])*$/i; |
| 3592 | function _class(obj) { |
| 3593 | return Object.prototype.toString.call(obj); |
| 3594 | } |
| 3595 | function isEol(c) { |
| 3596 | return c === 10 || c === 13; |
| 3597 | } |
| 3598 | function isWhiteSpace(c) { |
| 3599 | return c === 9 || c === 32; |
| 3600 | } |
| 3601 | function isWsOrEol(c) { |
| 3602 | return c === 9 || c === 32 || c === 10 || c === 13; |
| 3603 | } |
| 3604 | function isFlowIndicator(c) { |
| 3605 | return c === 44 || c === 91 || c === 93 || c === 123 || c === 125; |
| 3606 | } |
| 3607 | function fromHexCode(c) { |
| 3608 | if (c >= 48 && c <= 57) { |
| 3609 | return c - 48; |
| 3610 | } |
| 3611 | const lc = c | 32; |
| 3612 | if (lc >= 97 && lc <= 102) { |
| 3613 | return lc - 97 + 10; |
| 3614 | } |
| 3615 | return -1; |
| 3616 | } |
| 3617 | function escapedHexLen(c) { |
| 3618 | if (c === 120) { |
| 3619 | return 2; |
| 3620 | } |
| 3621 | if (c === 117) { |
| 3622 | return 4; |
| 3623 | } |
| 3624 | if (c === 85) { |
| 3625 | return 8; |
| 3626 | } |
| 3627 | return 0; |
| 3628 | } |
| 3629 | function fromDecimalCode(c) { |
| 3630 | if (c >= 48 && c <= 57) { |
| 3631 | return c - 48; |
| 3632 | } |
| 3633 | return -1; |
| 3634 | } |
| 3635 | function simpleEscapeSequence(c) { |
| 3636 | switch (c) { |
| 3637 | case 48: |
| 3638 | return "\0"; |
| 3639 | case 97: |
| 3640 | return "\x07"; |
| 3641 | case 98: |
| 3642 | return "\b"; |
| 3643 | case 116: |
| 3644 | return " "; |
| 3645 | case 9: |
| 3646 | return " "; |
| 3647 | case 110: |
| 3648 | return "\n"; |
| 3649 | case 118: |
| 3650 | return "\v"; |
| 3651 | case 102: |
| 3652 | return "\f"; |
| 3653 | case 114: |
| 3654 | return "\r"; |
| 3655 | case 101: |
| 3656 | return "\x1B"; |
| 3657 | case 32: |
| 3658 | return " "; |
| 3659 | case 34: |
| 3660 | return '"'; |
| 3661 | case 47: |
| 3662 | return "/"; |
| 3663 | case 92: |
| 3664 | return "\\"; |
| 3665 | case 78: |
| 3666 | return " "; |
| 3667 | case 95: |
| 3668 | return " "; |
| 3669 | case 76: |
| 3670 | return "\u2028"; |
| 3671 | case 80: |
| 3672 | return "\u2029"; |
| 3673 | default: |
| 3674 | return ""; |
| 3675 | } |
| 3676 | } |
| 3677 | function charFromCodepoint(c) { |
| 3678 | if (c <= 65535) { |
| 3679 | return String.fromCharCode(c); |
| 3680 | } |
| 3681 | return String.fromCharCode( |
| 3682 | (c - 65536 >> 10) + 55296, |
| 3683 | (c - 65536 & 1023) + 56320 |
| 3684 | ); |
| 3685 | } |
| 3686 | function setProperty(object, key, value) { |
| 3687 | if (key === "__proto__") { |
| 3688 | Object.defineProperty(object, key, { |
| 3689 | configurable: true, |
| 3690 | enumerable: true, |
| 3691 | writable: true, |
| 3692 | value |
| 3693 | }); |
| 3694 | } else { |
| 3695 | object[key] = value; |
| 3696 | } |
| 3697 | } |
| 3698 | const simpleEscapeCheck = new Array(256); |
| 3699 | const simpleEscapeMap = new Array(256); |
| 3700 | for (let i2 = 0; i2 < 256; i2++) { |
| 3701 | simpleEscapeCheck[i2] = simpleEscapeSequence(i2) ? 1 : 0; |
| 3702 | simpleEscapeMap[i2] = simpleEscapeSequence(i2); |
| 3703 | } |
| 3704 | function State(input, options) { |
| 3705 | this.input = input; |
| 3706 | this.filename = options["filename"] || null; |
| 3707 | this.schema = options["schema"] || DEFAULT_SCHEMA2; |
| 3708 | this.onWarning = options["onWarning"] || null; |
| 3709 | this.legacy = options["legacy"] || false; |
| 3710 | this.json = options["json"] || false; |
| 3711 | this.listener = options["listener"] || null; |
| 3712 | this.maxDepth = typeof options["maxDepth"] === "number" ? options["maxDepth"] : 100; |
| 3713 | this.maxTotalMergeKeys = typeof options["maxTotalMergeKeys"] === "number" ? options["maxTotalMergeKeys"] : 1e4; |
| 3714 | this.implicitTypes = this.schema.compiledImplicit; |
| 3715 | this.typeMap = this.schema.compiledTypeMap; |
| 3716 | this.length = input.length; |
| 3717 | this.position = 0; |
| 3718 | this.line = 0; |
| 3719 | this.lineStart = 0; |
| 3720 | this.lineIndent = 0; |
| 3721 | this.depth = 0; |
| 3722 | this.totalMergeKeys = 0; |
| 3723 | this.firstTabInLine = -1; |
| 3724 | this.documents = []; |
| 3725 | this.anchorMapTransactions = []; |
| 3726 | } |
| 3727 | function generateError(state, message) { |
| 3728 | const mark = { |
| 3729 | name: state.filename, |
| 3730 | buffer: state.input.slice(0, -1), |
| 3731 | // omit trailing \0 |
| 3732 | position: state.position, |
| 3733 | line: state.line, |
| 3734 | column: state.position - state.lineStart |
| 3735 | }; |
| 3736 | mark.snippet = makeSnippet(mark); |
| 3737 | return new YAMLException2(message, mark); |
| 3738 | } |
| 3739 | function throwError(state, message) { |
| 3740 | throw generateError(state, message); |
| 3741 | } |
| 3742 | function throwWarning(state, message) { |
| 3743 | if (state.onWarning) { |
| 3744 | state.onWarning.call(null, generateError(state, message)); |
| 3745 | } |
| 3746 | } |
| 3747 | function storeAnchor(state, name, value) { |
| 3748 | const transactions = state.anchorMapTransactions; |
| 3749 | if (transactions.length !== 0) { |
| 3750 | const transaction = transactions[transactions.length - 1]; |
| 3751 | if (!_hasOwnProperty.call(transaction, name)) { |
| 3752 | transaction[name] = { |
| 3753 | existed: _hasOwnProperty.call(state.anchorMap, name), |
| 3754 | value: state.anchorMap[name] |
| 3755 | }; |
| 3756 | } |
| 3757 | } |
| 3758 | state.anchorMap[name] = value; |
| 3759 | } |
| 3760 | function beginAnchorTransaction(state) { |
| 3761 | state.anchorMapTransactions.push(/* @__PURE__ */ Object.create(null)); |
| 3762 | } |
| 3763 | function commitAnchorTransaction(state) { |
| 3764 | const transaction = state.anchorMapTransactions.pop(); |
| 3765 | const transactions = state.anchorMapTransactions; |
| 3766 | if (transactions.length === 0) return; |
| 3767 | const parent = transactions[transactions.length - 1]; |
| 3768 | const names = Object.keys(transaction); |
| 3769 | for (let index = 0, length = names.length; index < length; index += 1) { |
| 3770 | const name = names[index]; |
| 3771 | if (!_hasOwnProperty.call(parent, name)) { |
| 3772 | parent[name] = transaction[name]; |
| 3773 | } |
| 3774 | } |
| 3775 | } |
| 3776 | function rollbackAnchorTransaction(state) { |
| 3777 | const transaction = state.anchorMapTransactions.pop(); |
| 3778 | const names = Object.keys(transaction); |
| 3779 | for (let index = names.length - 1; index >= 0; index -= 1) { |
| 3780 | const entry = transaction[names[index]]; |
| 3781 | if (entry.existed) { |
| 3782 | state.anchorMap[names[index]] = entry.value; |
| 3783 | } else { |
| 3784 | delete state.anchorMap[names[index]]; |
| 3785 | } |
| 3786 | } |
| 3787 | } |
| 3788 | function snapshotState(state) { |
| 3789 | return { |
| 3790 | position: state.position, |
| 3791 | line: state.line, |
| 3792 | lineStart: state.lineStart, |
| 3793 | lineIndent: state.lineIndent, |
| 3794 | firstTabInLine: state.firstTabInLine, |
| 3795 | tag: state.tag, |
| 3796 | anchor: state.anchor, |
| 3797 | kind: state.kind, |
| 3798 | result: state.result |
| 3799 | }; |
| 3800 | } |
| 3801 | function restoreState(state, snapshot) { |
| 3802 | state.position = snapshot.position; |
| 3803 | state.line = snapshot.line; |
| 3804 | state.lineStart = snapshot.lineStart; |
| 3805 | state.lineIndent = snapshot.lineIndent; |
| 3806 | state.firstTabInLine = snapshot.firstTabInLine; |
| 3807 | state.tag = snapshot.tag; |
| 3808 | state.anchor = snapshot.anchor; |
| 3809 | state.kind = snapshot.kind; |
| 3810 | state.result = snapshot.result; |
| 3811 | } |
| 3812 | const directiveHandlers = { |
| 3813 | YAML: function handleYamlDirective(state, name, args) { |
| 3814 | if (state.version !== null) { |
| 3815 | throwError(state, "duplication of %YAML directive"); |
| 3816 | } |
| 3817 | if (args.length !== 1) { |
| 3818 | throwError(state, "YAML directive accepts exactly one argument"); |
| 3819 | } |
| 3820 | const match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]); |
| 3821 | if (match === null) { |
| 3822 | throwError(state, "ill-formed argument of the YAML directive"); |
| 3823 | } |
| 3824 | const major = parseInt(match[1], 10); |
| 3825 | const minor = parseInt(match[2], 10); |
| 3826 | if (major !== 1) { |
| 3827 | throwError(state, "unacceptable YAML version of the document"); |
| 3828 | } |
| 3829 | state.version = args[0]; |
| 3830 | state.checkLineBreaks = minor < 2; |
| 3831 | if (minor !== 1 && minor !== 2) { |
| 3832 | throwWarning(state, "unsupported YAML version of the document"); |
| 3833 | } |
| 3834 | }, |
| 3835 | TAG: function handleTagDirective(state, name, args) { |
| 3836 | let prefix; |
| 3837 | if (args.length !== 2) { |
| 3838 | throwError(state, "TAG directive accepts exactly two arguments"); |
| 3839 | } |
| 3840 | const handle = args[0]; |
| 3841 | prefix = args[1]; |
| 3842 | if (!PATTERN_TAG_HANDLE.test(handle)) { |
| 3843 | throwError(state, "ill-formed tag handle (first argument) of the TAG directive"); |
| 3844 | } |
| 3845 | if (_hasOwnProperty.call(state.tagMap, handle)) { |
| 3846 | throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle'); |
| 3847 | } |
| 3848 | if (!PATTERN_TAG_URI.test(prefix)) { |
| 3849 | throwError(state, "ill-formed tag prefix (second argument) of the TAG directive"); |
| 3850 | } |
| 3851 | try { |
| 3852 | prefix = decodeURIComponent(prefix); |
| 3853 | } catch (err) { |
| 3854 | throwError(state, "tag prefix is malformed: " + prefix); |
| 3855 | } |
| 3856 | state.tagMap[handle] = prefix; |
| 3857 | } |
| 3858 | }; |
| 3859 | function captureSegment(state, start, end, checkJson) { |
| 3860 | if (start < end) { |
| 3861 | const _result = state.input.slice(start, end); |
| 3862 | if (checkJson) { |
| 3863 | for (let _position = 0, _length = _result.length; _position < _length; _position += 1) { |
| 3864 | const _character = _result.charCodeAt(_position); |
| 3865 | if (!(_character === 9 || _character >= 32 && _character <= 1114111)) { |
| 3866 | throwError(state, "expected valid JSON character"); |
| 3867 | } |
| 3868 | } |
| 3869 | } else if (PATTERN_NON_PRINTABLE.test(_result)) { |
| 3870 | throwError(state, "the stream contains non-printable characters"); |
| 3871 | } |
| 3872 | state.result += _result; |
| 3873 | } |
| 3874 | } |
| 3875 | function chargeMergeWork(state) { |
| 3876 | state.totalMergeKeys++; |
| 3877 | if (state.maxTotalMergeKeys !== -1 && state.totalMergeKeys > state.maxTotalMergeKeys) { |
| 3878 | throwError(state, "merge keys exceeded maxTotalMergeKeys (" + state.maxTotalMergeKeys + ")"); |
| 3879 | } |
| 3880 | } |
| 3881 | function mergeMappings(state, destination, source, overridableKeys) { |
| 3882 | if (!common2.isObject(source)) { |
| 3883 | throwError(state, "cannot merge mappings; the provided source object is unacceptable"); |
| 3884 | } |
| 3885 | chargeMergeWork(state); |
| 3886 | const sourceKeys = Object.keys(source); |
| 3887 | for (let index = 0, quantity = sourceKeys.length; index < quantity; index += 1) { |
| 3888 | const key = sourceKeys[index]; |
| 3889 | chargeMergeWork(state); |
| 3890 | if (!_hasOwnProperty.call(destination, key)) { |
| 3891 | setProperty(destination, key, source[key]); |
| 3892 | overridableKeys[key] = true; |
| 3893 | } |
| 3894 | } |
| 3895 | } |
| 3896 | function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startLineStart, startPos) { |
| 3897 | if (Array.isArray(keyNode)) { |
| 3898 | keyNode = Array.prototype.slice.call(keyNode); |
| 3899 | for (let index = 0, quantity = keyNode.length; index < quantity; index += 1) { |
| 3900 | if (Array.isArray(keyNode[index])) { |
| 3901 | throwError(state, "nested arrays are not supported inside keys"); |
| 3902 | } |
| 3903 | if (typeof keyNode === "object" && _class(keyNode[index]) === "[object Object]") { |
| 3904 | keyNode[index] = "[object Object]"; |
| 3905 | } |
| 3906 | } |
| 3907 | } |
| 3908 | if (typeof keyNode === "object" && _class(keyNode) === "[object Object]") { |
| 3909 | keyNode = "[object Object]"; |
| 3910 | } |
| 3911 | keyNode = String(keyNode); |
| 3912 | if (_result === null) { |
| 3913 | _result = {}; |
| 3914 | } |
| 3915 | if (keyTag === "tag:yaml.org,2002:merge") { |
| 3916 | if (Array.isArray(valueNode)) { |
| 3917 | if (valueNode.length > 100) { |
| 3918 | throwError(state, "abnormal merge sequence size"); |
| 3919 | } |
| 3920 | for (let index = 0, quantity = valueNode.length; index < quantity; index += 1) { |
| 3921 | mergeMappings(state, _result, valueNode[index], overridableKeys); |
| 3922 | } |
| 3923 | } else { |
| 3924 | mergeMappings(state, _result, valueNode, overridableKeys); |
| 3925 | } |
| 3926 | } else { |
| 3927 | if (!state.json && !_hasOwnProperty.call(overridableKeys, keyNode) && _hasOwnProperty.call(_result, keyNode)) { |
| 3928 | state.line = startLine || state.line; |
| 3929 | state.lineStart = startLineStart || state.lineStart; |
| 3930 | state.position = startPos || state.position; |
| 3931 | throwError(state, "duplicated mapping key"); |
| 3932 | } |
| 3933 | setProperty(_result, keyNode, valueNode); |
| 3934 | delete overridableKeys[keyNode]; |
| 3935 | } |
| 3936 | return _result; |
| 3937 | } |
| 3938 | function readLineBreak(state) { |
| 3939 | const ch = state.input.charCodeAt(state.position); |
| 3940 | if (ch === 10) { |
| 3941 | state.position++; |
| 3942 | } else if (ch === 13) { |
| 3943 | state.position++; |
| 3944 | if (state.input.charCodeAt(state.position) === 10) { |
| 3945 | state.position++; |
| 3946 | } |
| 3947 | } else { |
| 3948 | throwError(state, "a line break is expected"); |
| 3949 | } |
| 3950 | state.line += 1; |
| 3951 | state.lineStart = state.position; |
| 3952 | state.firstTabInLine = -1; |
| 3953 | } |
| 3954 | function skipSeparationSpace(state, allowComments, checkIndent) { |
| 3955 | let lineBreaks = 0; |
| 3956 | let ch = state.input.charCodeAt(state.position); |
| 3957 | while (ch !== 0) { |
| 3958 | while (isWhiteSpace(ch)) { |
| 3959 | if (ch === 9 && state.firstTabInLine === -1) { |
| 3960 | state.firstTabInLine = state.position; |
| 3961 | } |
| 3962 | ch = state.input.charCodeAt(++state.position); |
| 3963 | } |
| 3964 | if (allowComments && ch === 35) { |
| 3965 | do { |
| 3966 | ch = state.input.charCodeAt(++state.position); |
| 3967 | } while (ch !== 10 && ch !== 13 && ch !== 0); |
| 3968 | } |
| 3969 | if (isEol(ch)) { |
| 3970 | readLineBreak(state); |
| 3971 | ch = state.input.charCodeAt(state.position); |
| 3972 | lineBreaks++; |
| 3973 | state.lineIndent = 0; |
| 3974 | while (ch === 32) { |
| 3975 | state.lineIndent++; |
| 3976 | ch = state.input.charCodeAt(++state.position); |
| 3977 | } |
| 3978 | } else { |
| 3979 | break; |
| 3980 | } |
| 3981 | } |
| 3982 | if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) { |
| 3983 | throwWarning(state, "deficient indentation"); |
| 3984 | } |
| 3985 | return lineBreaks; |
| 3986 | } |
| 3987 | function testDocumentSeparator(state) { |
| 3988 | let _position = state.position; |
| 3989 | let ch = state.input.charCodeAt(_position); |
| 3990 | if ((ch === 45 || ch === 46) && ch === state.input.charCodeAt(_position + 1) && ch === state.input.charCodeAt(_position + 2)) { |
| 3991 | _position += 3; |
| 3992 | ch = state.input.charCodeAt(_position); |
| 3993 | if (ch === 0 || isWsOrEol(ch)) { |
| 3994 | return true; |
| 3995 | } |
| 3996 | } |
| 3997 | return false; |
| 3998 | } |
| 3999 | function writeFoldedLines(state, count) { |
| 4000 | if (count === 1) { |
| 4001 | state.result += " "; |
| 4002 | } else if (count > 1) { |
| 4003 | state.result += common2.repeat("\n", count - 1); |
| 4004 | } |
| 4005 | } |
| 4006 | function readPlainScalar(state, nodeIndent, withinFlowCollection) { |
| 4007 | let captureStart; |
| 4008 | let captureEnd; |
| 4009 | let hasPendingContent; |
| 4010 | let _line; |
| 4011 | let _lineStart; |
| 4012 | let _lineIndent; |
| 4013 | const _kind = state.kind; |
| 4014 | const _result = state.result; |
| 4015 | let ch = state.input.charCodeAt(state.position); |
| 4016 | if (isWsOrEol(ch) || isFlowIndicator(ch) || ch === 35 || ch === 38 || ch === 42 || ch === 33 || ch === 124 || ch === 62 || ch === 39 || ch === 34 || ch === 37 || ch === 64 || ch === 96) { |
| 4017 | return false; |
| 4018 | } |
| 4019 | if (ch === 63 || ch === 45) { |
| 4020 | const following = state.input.charCodeAt(state.position + 1); |
| 4021 | if (isWsOrEol(following) || withinFlowCollection && isFlowIndicator(following)) { |
| 4022 | return false; |
| 4023 | } |
| 4024 | } |
| 4025 | state.kind = "scalar"; |
| 4026 | state.result = ""; |
| 4027 | captureStart = captureEnd = state.position; |
| 4028 | hasPendingContent = false; |
| 4029 | while (ch !== 0) { |
| 4030 | if (ch === 58) { |
| 4031 | const following = state.input.charCodeAt(state.position + 1); |
| 4032 | if (isWsOrEol(following) || withinFlowCollection && isFlowIndicator(following)) { |
| 4033 | break; |
| 4034 | } |
| 4035 | } else if (ch === 35) { |
| 4036 | const preceding = state.input.charCodeAt(state.position - 1); |
| 4037 | if (isWsOrEol(preceding)) { |
| 4038 | break; |
| 4039 | } |
| 4040 | } else if (state.position === state.lineStart && testDocumentSeparator(state) || withinFlowCollection && isFlowIndicator(ch)) { |
| 4041 | break; |
| 4042 | } else if (isEol(ch)) { |
| 4043 | _line = state.line; |
| 4044 | _lineStart = state.lineStart; |
| 4045 | _lineIndent = state.lineIndent; |
| 4046 | skipSeparationSpace(state, false, -1); |
| 4047 | if (state.lineIndent >= nodeIndent) { |
| 4048 | hasPendingContent = true; |
| 4049 | ch = state.input.charCodeAt(state.position); |
| 4050 | continue; |
| 4051 | } else { |
| 4052 | state.position = captureEnd; |
| 4053 | state.line = _line; |
| 4054 | state.lineStart = _lineStart; |
| 4055 | state.lineIndent = _lineIndent; |
| 4056 | break; |
| 4057 | } |
| 4058 | } |
| 4059 | if (hasPendingContent) { |
| 4060 | captureSegment(state, captureStart, captureEnd, false); |
| 4061 | writeFoldedLines(state, state.line - _line); |
| 4062 | captureStart = captureEnd = state.position; |
| 4063 | hasPendingContent = false; |
| 4064 | } |
| 4065 | if (!isWhiteSpace(ch)) { |
| 4066 | captureEnd = state.position + 1; |
| 4067 | } |
| 4068 | ch = state.input.charCodeAt(++state.position); |
| 4069 | } |
| 4070 | captureSegment(state, captureStart, captureEnd, false); |
| 4071 | if (state.result) { |
| 4072 | return true; |
| 4073 | } |
| 4074 | state.kind = _kind; |
| 4075 | state.result = _result; |
| 4076 | return false; |
| 4077 | } |
| 4078 | function readSingleQuotedScalar(state, nodeIndent) { |
| 4079 | let captureStart; |
| 4080 | let captureEnd; |
| 4081 | let ch = state.input.charCodeAt(state.position); |
| 4082 | if (ch !== 39) { |
| 4083 | return false; |
| 4084 | } |
| 4085 | state.kind = "scalar"; |
| 4086 | state.result = ""; |
| 4087 | state.position++; |
| 4088 | captureStart = captureEnd = state.position; |
| 4089 | while ((ch = state.input.charCodeAt(state.position)) !== 0) { |
| 4090 | if (ch === 39) { |
| 4091 | captureSegment(state, captureStart, state.position, true); |
| 4092 | ch = state.input.charCodeAt(++state.position); |
| 4093 | if (ch === 39) { |
| 4094 | captureStart = state.position; |
| 4095 | state.position++; |
| 4096 | captureEnd = state.position; |
| 4097 | } else { |
| 4098 | return true; |
| 4099 | } |
| 4100 | } else if (isEol(ch)) { |
| 4101 | captureSegment(state, captureStart, captureEnd, true); |
| 4102 | writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent)); |
| 4103 | captureStart = captureEnd = state.position; |
| 4104 | } else if (state.position === state.lineStart && testDocumentSeparator(state)) { |
| 4105 | throwError(state, "unexpected end of the document within a single quoted scalar"); |
| 4106 | } else { |
| 4107 | state.position++; |
| 4108 | if (!isWhiteSpace(ch)) { |
| 4109 | captureEnd = state.position; |
| 4110 | } |
| 4111 | } |
| 4112 | } |
| 4113 | throwError(state, "unexpected end of the stream within a single quoted scalar"); |
| 4114 | } |
| 4115 | function readDoubleQuotedScalar(state, nodeIndent) { |
| 4116 | let captureStart; |
| 4117 | let captureEnd; |
| 4118 | let tmp; |
| 4119 | let ch = state.input.charCodeAt(state.position); |
| 4120 | if (ch !== 34) { |
| 4121 | return false; |
| 4122 | } |
| 4123 | state.kind = "scalar"; |
| 4124 | state.result = ""; |
| 4125 | state.position++; |
| 4126 | captureStart = captureEnd = state.position; |
| 4127 | while ((ch = state.input.charCodeAt(state.position)) !== 0) { |
| 4128 | if (ch === 34) { |
| 4129 | captureSegment(state, captureStart, state.position, true); |
| 4130 | state.position++; |
| 4131 | return true; |
| 4132 | } else if (ch === 92) { |
| 4133 | captureSegment(state, captureStart, state.position, true); |
| 4134 | ch = state.input.charCodeAt(++state.position); |
| 4135 | if (isEol(ch)) { |
| 4136 | skipSeparationSpace(state, false, nodeIndent); |
| 4137 | } else if (ch < 256 && simpleEscapeCheck[ch]) { |
| 4138 | state.result += simpleEscapeMap[ch]; |
| 4139 | state.position++; |
| 4140 | } else if ((tmp = escapedHexLen(ch)) > 0) { |
| 4141 | let hexLength = tmp; |
| 4142 | let hexResult = 0; |
| 4143 | for (; hexLength > 0; hexLength--) { |
| 4144 | ch = state.input.charCodeAt(++state.position); |
| 4145 | if ((tmp = fromHexCode(ch)) >= 0) { |
| 4146 | hexResult = (hexResult << 4) + tmp; |
| 4147 | } else { |
| 4148 | throwError(state, "expected hexadecimal character"); |
| 4149 | } |
| 4150 | } |
| 4151 | state.result += charFromCodepoint(hexResult); |
| 4152 | state.position++; |
| 4153 | } else { |
| 4154 | throwError(state, "unknown escape sequence"); |
| 4155 | } |
| 4156 | captureStart = captureEnd = state.position; |
| 4157 | } else if (isEol(ch)) { |
| 4158 | captureSegment(state, captureStart, captureEnd, true); |
| 4159 | writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent)); |
| 4160 | captureStart = captureEnd = state.position; |
| 4161 | } else if (state.position === state.lineStart && testDocumentSeparator(state)) { |
| 4162 | throwError(state, "unexpected end of the document within a double quoted scalar"); |
| 4163 | } else { |
| 4164 | state.position++; |
| 4165 | if (!isWhiteSpace(ch)) { |
| 4166 | captureEnd = state.position; |
| 4167 | } |
| 4168 | } |
| 4169 | } |
| 4170 | throwError(state, "unexpected end of the stream within a double quoted scalar"); |
| 4171 | } |
| 4172 | function readFlowCollection(state, nodeIndent) { |
| 4173 | let readNext = true; |
| 4174 | let _line; |
| 4175 | let _lineStart; |
| 4176 | let _pos; |
| 4177 | const _tag = state.tag; |
| 4178 | let _result; |
| 4179 | const _anchor = state.anchor; |
| 4180 | let terminator; |
| 4181 | let isPair; |
| 4182 | let isExplicitPair; |
| 4183 | let isMapping; |
| 4184 | const overridableKeys = /* @__PURE__ */ Object.create(null); |
| 4185 | let keyNode; |
| 4186 | let keyTag; |
| 4187 | let valueNode; |
| 4188 | let ch = state.input.charCodeAt(state.position); |
| 4189 | if (ch === 91) { |
| 4190 | terminator = 93; |
| 4191 | isMapping = false; |
| 4192 | _result = []; |
| 4193 | } else if (ch === 123) { |
| 4194 | terminator = 125; |
| 4195 | isMapping = true; |
| 4196 | _result = {}; |
| 4197 | } else { |
| 4198 | return false; |
| 4199 | } |
| 4200 | if (state.anchor !== null) { |
| 4201 | storeAnchor(state, state.anchor, _result); |
| 4202 | } |
| 4203 | ch = state.input.charCodeAt(++state.position); |
| 4204 | while (ch !== 0) { |
| 4205 | skipSeparationSpace(state, true, nodeIndent); |
| 4206 | ch = state.input.charCodeAt(state.position); |
| 4207 | if (ch === terminator) { |
| 4208 | state.position++; |
| 4209 | state.tag = _tag; |
| 4210 | state.anchor = _anchor; |
| 4211 | state.kind = isMapping ? "mapping" : "sequence"; |
| 4212 | state.result = _result; |
| 4213 | return true; |
| 4214 | } else if (!readNext) { |
| 4215 | throwError(state, "missed comma between flow collection entries"); |
| 4216 | } else if (ch === 44) { |
| 4217 | throwError(state, "expected the node content, but found ','"); |
| 4218 | } |
| 4219 | keyTag = keyNode = valueNode = null; |
| 4220 | isPair = isExplicitPair = false; |
| 4221 | if (ch === 63) { |
| 4222 | const following = state.input.charCodeAt(state.position + 1); |
| 4223 | if (isWsOrEol(following)) { |
| 4224 | isPair = isExplicitPair = true; |
| 4225 | state.position++; |
| 4226 | skipSeparationSpace(state, true, nodeIndent); |
| 4227 | } |
| 4228 | } |
| 4229 | _line = state.line; |
| 4230 | _lineStart = state.lineStart; |
| 4231 | _pos = state.position; |
| 4232 | composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true); |
| 4233 | keyTag = state.tag; |
| 4234 | keyNode = state.result; |
| 4235 | skipSeparationSpace(state, true, nodeIndent); |
| 4236 | ch = state.input.charCodeAt(state.position); |
| 4237 | if ((isExplicitPair || state.line === _line) && ch === 58) { |
| 4238 | isPair = true; |
| 4239 | ch = state.input.charCodeAt(++state.position); |
| 4240 | skipSeparationSpace(state, true, nodeIndent); |
| 4241 | composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true); |
| 4242 | valueNode = state.result; |
| 4243 | } |
| 4244 | if (isMapping) { |
| 4245 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos); |
| 4246 | } else if (isPair) { |
| 4247 | _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos)); |
| 4248 | } else { |
| 4249 | _result.push(keyNode); |
| 4250 | } |
| 4251 | skipSeparationSpace(state, true, nodeIndent); |
| 4252 | ch = state.input.charCodeAt(state.position); |
| 4253 | if (ch === 44) { |
| 4254 | readNext = true; |
| 4255 | ch = state.input.charCodeAt(++state.position); |
| 4256 | } else { |
| 4257 | readNext = false; |
| 4258 | } |
| 4259 | } |
| 4260 | throwError(state, "unexpected end of the stream within a flow collection"); |
| 4261 | } |
| 4262 | function readBlockScalar(state, nodeIndent) { |
| 4263 | let folding; |
| 4264 | let chomping = CHOMPING_CLIP; |
| 4265 | let didReadContent = false; |
| 4266 | let detectedIndent = false; |
| 4267 | let textIndent = nodeIndent; |
| 4268 | let emptyLines = 0; |
| 4269 | let atMoreIndented = false; |
| 4270 | let tmp; |
| 4271 | let ch = state.input.charCodeAt(state.position); |
| 4272 | if (ch === 124) { |
| 4273 | folding = false; |
| 4274 | } else if (ch === 62) { |
| 4275 | folding = true; |
| 4276 | } else { |
| 4277 | return false; |
| 4278 | } |
| 4279 | state.kind = "scalar"; |
| 4280 | state.result = ""; |
| 4281 | while (ch !== 0) { |
| 4282 | ch = state.input.charCodeAt(++state.position); |
| 4283 | if (ch === 43 || ch === 45) { |
| 4284 | if (CHOMPING_CLIP === chomping) { |
| 4285 | chomping = ch === 43 ? CHOMPING_KEEP : CHOMPING_STRIP; |
| 4286 | } else { |
| 4287 | throwError(state, "repeat of a chomping mode identifier"); |
| 4288 | } |
| 4289 | } else if ((tmp = fromDecimalCode(ch)) >= 0) { |
| 4290 | if (tmp === 0) { |
| 4291 | throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one"); |
| 4292 | } else if (!detectedIndent) { |
| 4293 | textIndent = nodeIndent + tmp - 1; |
| 4294 | detectedIndent = true; |
| 4295 | } else { |
| 4296 | throwError(state, "repeat of an indentation width identifier"); |
| 4297 | } |
| 4298 | } else { |
| 4299 | break; |
| 4300 | } |
| 4301 | } |
| 4302 | if (isWhiteSpace(ch)) { |
| 4303 | do { |
| 4304 | ch = state.input.charCodeAt(++state.position); |
| 4305 | } while (isWhiteSpace(ch)); |
| 4306 | if (ch === 35) { |
| 4307 | do { |
| 4308 | ch = state.input.charCodeAt(++state.position); |
| 4309 | } while (!isEol(ch) && ch !== 0); |
| 4310 | } |
| 4311 | } |
| 4312 | while (ch !== 0) { |
| 4313 | readLineBreak(state); |
| 4314 | state.lineIndent = 0; |
| 4315 | ch = state.input.charCodeAt(state.position); |
| 4316 | while ((!detectedIndent || state.lineIndent < textIndent) && ch === 32) { |
| 4317 | state.lineIndent++; |
| 4318 | ch = state.input.charCodeAt(++state.position); |
| 4319 | } |
| 4320 | if (!detectedIndent && state.lineIndent > textIndent) { |
| 4321 | textIndent = state.lineIndent; |
| 4322 | } |
| 4323 | if (isEol(ch)) { |
| 4324 | emptyLines++; |
| 4325 | continue; |
| 4326 | } |
| 4327 | if (!detectedIndent && textIndent === 0) { |
| 4328 | throwError(state, "missing indentation for block scalar"); |
| 4329 | } |
| 4330 | if (state.lineIndent < textIndent) { |
| 4331 | if (chomping === CHOMPING_KEEP) { |
| 4332 | state.result += common2.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines); |
| 4333 | } else if (chomping === CHOMPING_CLIP) { |
| 4334 | if (didReadContent) { |
| 4335 | state.result += "\n"; |
| 4336 | } |
| 4337 | } |
| 4338 | break; |
| 4339 | } |
| 4340 | if (folding) { |
| 4341 | if (isWhiteSpace(ch)) { |
| 4342 | atMoreIndented = true; |
| 4343 | state.result += common2.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines); |
| 4344 | } else if (atMoreIndented) { |
| 4345 | atMoreIndented = false; |
| 4346 | state.result += common2.repeat("\n", emptyLines + 1); |
| 4347 | } else if (emptyLines === 0) { |
| 4348 | if (didReadContent) { |
| 4349 | state.result += " "; |
| 4350 | } |
| 4351 | } else { |
| 4352 | state.result += common2.repeat("\n", emptyLines); |
| 4353 | } |
| 4354 | } else { |
| 4355 | state.result += common2.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines); |
| 4356 | } |
| 4357 | didReadContent = true; |
| 4358 | detectedIndent = true; |
| 4359 | emptyLines = 0; |
| 4360 | const captureStart = state.position; |
| 4361 | while (!isEol(ch) && ch !== 0) { |
| 4362 | ch = state.input.charCodeAt(++state.position); |
| 4363 | } |
| 4364 | captureSegment(state, captureStart, state.position, false); |
| 4365 | } |
| 4366 | return true; |
| 4367 | } |
| 4368 | function readBlockSequence(state, nodeIndent) { |
| 4369 | const _tag = state.tag; |
| 4370 | const _anchor = state.anchor; |
| 4371 | const _result = []; |
| 4372 | let detected = false; |
| 4373 | if (state.firstTabInLine !== -1) return false; |
| 4374 | if (state.anchor !== null) { |
| 4375 | storeAnchor(state, state.anchor, _result); |
| 4376 | } |
| 4377 | let ch = state.input.charCodeAt(state.position); |
| 4378 | while (ch !== 0) { |
| 4379 | if (state.firstTabInLine !== -1) { |
| 4380 | state.position = state.firstTabInLine; |
| 4381 | throwError(state, "tab characters must not be used in indentation"); |
| 4382 | } |
| 4383 | if (ch !== 45) { |
| 4384 | break; |
| 4385 | } |
| 4386 | const following = state.input.charCodeAt(state.position + 1); |
| 4387 | if (!isWsOrEol(following)) { |
| 4388 | break; |
| 4389 | } |
| 4390 | detected = true; |
| 4391 | state.position++; |
| 4392 | if (skipSeparationSpace(state, true, -1)) { |
| 4393 | if (state.lineIndent <= nodeIndent) { |
| 4394 | _result.push(null); |
| 4395 | ch = state.input.charCodeAt(state.position); |
| 4396 | continue; |
| 4397 | } |
| 4398 | } |
| 4399 | const _line = state.line; |
| 4400 | composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true); |
| 4401 | _result.push(state.result); |
| 4402 | skipSeparationSpace(state, true, -1); |
| 4403 | ch = state.input.charCodeAt(state.position); |
| 4404 | if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) { |
| 4405 | throwError(state, "bad indentation of a sequence entry"); |
| 4406 | } else if (state.lineIndent < nodeIndent) { |
| 4407 | break; |
| 4408 | } |
| 4409 | } |
| 4410 | if (detected) { |
| 4411 | state.tag = _tag; |
| 4412 | state.anchor = _anchor; |
| 4413 | state.kind = "sequence"; |
| 4414 | state.result = _result; |
| 4415 | return true; |
| 4416 | } |
| 4417 | return false; |
| 4418 | } |
| 4419 | function readBlockMapping(state, nodeIndent, flowIndent) { |
| 4420 | let allowCompact; |
| 4421 | let _keyLine; |
| 4422 | let _keyLineStart; |
| 4423 | let _keyPos; |
| 4424 | const _tag = state.tag; |
| 4425 | const _anchor = state.anchor; |
| 4426 | const _result = {}; |
| 4427 | const overridableKeys = /* @__PURE__ */ Object.create(null); |
| 4428 | let keyTag = null; |
| 4429 | let keyNode = null; |
| 4430 | let valueNode = null; |
| 4431 | let atExplicitKey = false; |
| 4432 | let detected = false; |
| 4433 | if (state.firstTabInLine !== -1) return false; |
| 4434 | if (state.anchor !== null) { |
| 4435 | storeAnchor(state, state.anchor, _result); |
| 4436 | } |
| 4437 | let ch = state.input.charCodeAt(state.position); |
| 4438 | while (ch !== 0) { |
| 4439 | if (!atExplicitKey && state.firstTabInLine !== -1) { |
| 4440 | state.position = state.firstTabInLine; |
| 4441 | throwError(state, "tab characters must not be used in indentation"); |
| 4442 | } |
| 4443 | const following = state.input.charCodeAt(state.position + 1); |
| 4444 | const _line = state.line; |
| 4445 | if ((ch === 63 || ch === 58) && isWsOrEol(following)) { |
| 4446 | if (ch === 63) { |
| 4447 | if (atExplicitKey) { |
| 4448 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos); |
| 4449 | keyTag = keyNode = valueNode = null; |
| 4450 | } |
| 4451 | detected = true; |
| 4452 | atExplicitKey = true; |
| 4453 | allowCompact = true; |
| 4454 | } else if (atExplicitKey) { |
| 4455 | atExplicitKey = false; |
| 4456 | allowCompact = true; |
| 4457 | } else { |
| 4458 | throwError(state, "incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line"); |
| 4459 | } |
| 4460 | state.position += 1; |
| 4461 | ch = following; |
| 4462 | } else { |
| 4463 | _keyLine = state.line; |
| 4464 | _keyLineStart = state.lineStart; |
| 4465 | _keyPos = state.position; |
| 4466 | if (!composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) { |
| 4467 | break; |
| 4468 | } |
| 4469 | if (state.line === _line) { |
| 4470 | ch = state.input.charCodeAt(state.position); |
| 4471 | while (isWhiteSpace(ch)) { |
| 4472 | ch = state.input.charCodeAt(++state.position); |
| 4473 | } |
| 4474 | if (ch === 58) { |
| 4475 | ch = state.input.charCodeAt(++state.position); |
| 4476 | if (!isWsOrEol(ch)) { |
| 4477 | throwError(state, "a whitespace character is expected after the key-value separator within a block mapping"); |
| 4478 | } |
| 4479 | if (atExplicitKey) { |
| 4480 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos); |
| 4481 | keyTag = keyNode = valueNode = null; |
| 4482 | } |
| 4483 | detected = true; |
| 4484 | atExplicitKey = false; |
| 4485 | allowCompact = false; |
| 4486 | keyTag = state.tag; |
| 4487 | keyNode = state.result; |
| 4488 | } else if (detected) { |
| 4489 | throwError(state, "can not read an implicit mapping pair; a colon is missed"); |
| 4490 | } else { |
| 4491 | state.tag = _tag; |
| 4492 | state.anchor = _anchor; |
| 4493 | return true; |
| 4494 | } |
| 4495 | } else if (detected) { |
| 4496 | throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key"); |
| 4497 | } else { |
| 4498 | state.tag = _tag; |
| 4499 | state.anchor = _anchor; |
| 4500 | return true; |
| 4501 | } |
| 4502 | } |
| 4503 | if (state.line === _line || state.lineIndent > nodeIndent) { |
| 4504 | if (atExplicitKey) { |
| 4505 | _keyLine = state.line; |
| 4506 | _keyLineStart = state.lineStart; |
| 4507 | _keyPos = state.position; |
| 4508 | } |
| 4509 | if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) { |
| 4510 | if (atExplicitKey) { |
| 4511 | keyNode = state.result; |
| 4512 | } else { |
| 4513 | valueNode = state.result; |
| 4514 | } |
| 4515 | } |
| 4516 | if (!atExplicitKey) { |
| 4517 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _keyLine, _keyLineStart, _keyPos); |
| 4518 | keyTag = keyNode = valueNode = null; |
| 4519 | } |
| 4520 | skipSeparationSpace(state, true, -1); |
| 4521 | ch = state.input.charCodeAt(state.position); |
| 4522 | } |
| 4523 | if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) { |
| 4524 | throwError(state, "bad indentation of a mapping entry"); |
| 4525 | } else if (state.lineIndent < nodeIndent) { |
| 4526 | break; |
| 4527 | } |
| 4528 | } |
| 4529 | if (atExplicitKey) { |
| 4530 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos); |
| 4531 | } |
| 4532 | if (detected) { |
| 4533 | state.tag = _tag; |
| 4534 | state.anchor = _anchor; |
| 4535 | state.kind = "mapping"; |
| 4536 | state.result = _result; |
| 4537 | } |
| 4538 | return detected; |
| 4539 | } |
| 4540 | function readTagProperty(state) { |
| 4541 | let isVerbatim = false; |
| 4542 | let isNamed = false; |
| 4543 | let tagHandle; |
| 4544 | let tagName; |
| 4545 | let ch = state.input.charCodeAt(state.position); |
| 4546 | if (ch !== 33) return false; |
| 4547 | if (state.tag !== null) { |
| 4548 | throwError(state, "duplication of a tag property"); |
| 4549 | } |
| 4550 | ch = state.input.charCodeAt(++state.position); |
| 4551 | if (ch === 60) { |
| 4552 | isVerbatim = true; |
| 4553 | ch = state.input.charCodeAt(++state.position); |
| 4554 | } else if (ch === 33) { |
| 4555 | isNamed = true; |
| 4556 | tagHandle = "!!"; |
| 4557 | ch = state.input.charCodeAt(++state.position); |
| 4558 | } else { |
| 4559 | tagHandle = "!"; |
| 4560 | } |
| 4561 | let _position = state.position; |
| 4562 | if (isVerbatim) { |
| 4563 | do { |
| 4564 | ch = state.input.charCodeAt(++state.position); |
| 4565 | } while (ch !== 0 && ch !== 62); |
| 4566 | if (state.position < state.length) { |
| 4567 | tagName = state.input.slice(_position, state.position); |
| 4568 | ch = state.input.charCodeAt(++state.position); |
| 4569 | } else { |
| 4570 | throwError(state, "unexpected end of the stream within a verbatim tag"); |
| 4571 | } |
| 4572 | } else { |
| 4573 | while (ch !== 0 && !isWsOrEol(ch)) { |
| 4574 | if (ch === 33) { |
| 4575 | if (!isNamed) { |
| 4576 | tagHandle = state.input.slice(_position - 1, state.position + 1); |
| 4577 | if (!PATTERN_TAG_HANDLE.test(tagHandle)) { |
| 4578 | throwError(state, "named tag handle cannot contain such characters"); |
| 4579 | } |
| 4580 | isNamed = true; |
| 4581 | _position = state.position + 1; |
| 4582 | } else { |
| 4583 | throwError(state, "tag suffix cannot contain exclamation marks"); |
| 4584 | } |
| 4585 | } |
| 4586 | ch = state.input.charCodeAt(++state.position); |
| 4587 | } |
| 4588 | tagName = state.input.slice(_position, state.position); |
| 4589 | if (PATTERN_FLOW_INDICATORS.test(tagName)) { |
| 4590 | throwError(state, "tag suffix cannot contain flow indicator characters"); |
| 4591 | } |
| 4592 | } |
| 4593 | if (tagName && !PATTERN_TAG_URI.test(tagName)) { |
| 4594 | throwError(state, "tag name cannot contain such characters: " + tagName); |
| 4595 | } |
| 4596 | try { |
| 4597 | tagName = decodeURIComponent(tagName); |
| 4598 | } catch (err) { |
| 4599 | throwError(state, "tag name is malformed: " + tagName); |
| 4600 | } |
| 4601 | if (isVerbatim) { |
| 4602 | state.tag = tagName; |
| 4603 | } else if (_hasOwnProperty.call(state.tagMap, tagHandle)) { |
| 4604 | state.tag = state.tagMap[tagHandle] + tagName; |
| 4605 | } else if (tagHandle === "!") { |
| 4606 | state.tag = "!" + tagName; |
| 4607 | } else if (tagHandle === "!!") { |
| 4608 | state.tag = "tag:yaml.org,2002:" + tagName; |
| 4609 | } else { |
| 4610 | throwError(state, 'undeclared tag handle "' + tagHandle + '"'); |
| 4611 | } |
| 4612 | return true; |
| 4613 | } |
| 4614 | function readAnchorProperty(state) { |
| 4615 | let ch = state.input.charCodeAt(state.position); |
| 4616 | if (ch !== 38) return false; |
| 4617 | if (state.anchor !== null) { |
| 4618 | throwError(state, "duplication of an anchor property"); |
| 4619 | } |
| 4620 | ch = state.input.charCodeAt(++state.position); |
| 4621 | const _position = state.position; |
| 4622 | while (ch !== 0 && !isWsOrEol(ch) && !isFlowIndicator(ch)) { |
| 4623 | ch = state.input.charCodeAt(++state.position); |
| 4624 | } |
| 4625 | if (state.position === _position) { |
| 4626 | throwError(state, "name of an anchor node must contain at least one character"); |
| 4627 | } |
| 4628 | state.anchor = state.input.slice(_position, state.position); |
| 4629 | return true; |
| 4630 | } |
| 4631 | function readAlias(state) { |
| 4632 | let ch = state.input.charCodeAt(state.position); |
| 4633 | if (ch !== 42) return false; |
| 4634 | ch = state.input.charCodeAt(++state.position); |
| 4635 | const _position = state.position; |
| 4636 | while (ch !== 0 && !isWsOrEol(ch) && !isFlowIndicator(ch)) { |
| 4637 | ch = state.input.charCodeAt(++state.position); |
| 4638 | } |
| 4639 | if (state.position === _position) { |
| 4640 | throwError(state, "name of an alias node must contain at least one character"); |
| 4641 | } |
| 4642 | const alias = state.input.slice(_position, state.position); |
| 4643 | if (!_hasOwnProperty.call(state.anchorMap, alias)) { |
| 4644 | throwError(state, 'unidentified alias "' + alias + '"'); |
| 4645 | } |
| 4646 | state.result = state.anchorMap[alias]; |
| 4647 | skipSeparationSpace(state, true, -1); |
| 4648 | return true; |
| 4649 | } |
| 4650 | function tryReadBlockMappingFromProperty(state, propertyStart, nodeIndent, flowIndent) { |
| 4651 | const fallbackState = snapshotState(state); |
| 4652 | beginAnchorTransaction(state); |
| 4653 | restoreState(state, propertyStart); |
| 4654 | state.tag = null; |
| 4655 | state.anchor = null; |
| 4656 | state.kind = null; |
| 4657 | state.result = null; |
| 4658 | if (readBlockMapping(state, nodeIndent, flowIndent) && state.kind === "mapping") { |
| 4659 | commitAnchorTransaction(state); |
| 4660 | return true; |
| 4661 | } |
| 4662 | rollbackAnchorTransaction(state); |
| 4663 | restoreState(state, fallbackState); |
| 4664 | return false; |
| 4665 | } |
| 4666 | function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) { |
| 4667 | let allowBlockScalars; |
| 4668 | let allowBlockCollections; |
| 4669 | let indentStatus = 1; |
| 4670 | let atNewLine = false; |
| 4671 | let hasContent = false; |
| 4672 | let propertyStart = null; |
| 4673 | let type2; |
| 4674 | let flowIndent; |
| 4675 | let blockIndent; |
| 4676 | if (state.depth >= state.maxDepth) { |
| 4677 | throwError(state, "nesting exceeded maxDepth (" + state.maxDepth + ")"); |
| 4678 | } |
| 4679 | state.depth += 1; |
| 4680 | if (state.listener !== null) { |
| 4681 | state.listener("open", state); |
| 4682 | } |
| 4683 | state.tag = null; |
| 4684 | state.anchor = null; |
| 4685 | state.kind = null; |
| 4686 | state.result = null; |
| 4687 | const allowBlockStyles = allowBlockScalars = allowBlockCollections = CONTEXT_BLOCK_OUT === nodeContext || CONTEXT_BLOCK_IN === nodeContext; |
| 4688 | if (allowToSeek) { |
| 4689 | if (skipSeparationSpace(state, true, -1)) { |
| 4690 | atNewLine = true; |
| 4691 | if (state.lineIndent > parentIndent) { |
| 4692 | indentStatus = 1; |
| 4693 | } else if (state.lineIndent === parentIndent) { |
| 4694 | indentStatus = 0; |
| 4695 | } else if (state.lineIndent < parentIndent) { |
| 4696 | indentStatus = -1; |
| 4697 | } |
| 4698 | } |
| 4699 | } |
| 4700 | if (indentStatus === 1) { |
| 4701 | while (true) { |
| 4702 | const ch = state.input.charCodeAt(state.position); |
| 4703 | const propertyState = snapshotState(state); |
| 4704 | if (atNewLine && (ch === 33 && state.tag !== null || ch === 38 && state.anchor !== null)) { |
| 4705 | break; |
| 4706 | } |
| 4707 | if (!readTagProperty(state) && !readAnchorProperty(state)) { |
| 4708 | break; |
| 4709 | } |
| 4710 | if (propertyStart === null) { |
| 4711 | propertyStart = propertyState; |
| 4712 | } |
| 4713 | if (skipSeparationSpace(state, true, -1)) { |
| 4714 | atNewLine = true; |
| 4715 | allowBlockCollections = allowBlockStyles; |
| 4716 | if (state.lineIndent > parentIndent) { |
| 4717 | indentStatus = 1; |
| 4718 | } else if (state.lineIndent === parentIndent) { |
| 4719 | indentStatus = 0; |
| 4720 | } else if (state.lineIndent < parentIndent) { |
| 4721 | indentStatus = -1; |
| 4722 | } |
| 4723 | } else { |
| 4724 | allowBlockCollections = false; |
| 4725 | } |
| 4726 | } |
| 4727 | } |
| 4728 | if (allowBlockCollections) { |
| 4729 | allowBlockCollections = atNewLine || allowCompact; |
| 4730 | } |
| 4731 | if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) { |
| 4732 | if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) { |
| 4733 | flowIndent = parentIndent; |
| 4734 | } else { |
| 4735 | flowIndent = parentIndent + 1; |
| 4736 | } |
| 4737 | blockIndent = state.position - state.lineStart; |
| 4738 | if (indentStatus === 1) { |
| 4739 | if (allowBlockCollections && (readBlockSequence(state, blockIndent) || readBlockMapping(state, blockIndent, flowIndent)) || readFlowCollection(state, flowIndent)) { |
| 4740 | hasContent = true; |
| 4741 | } else { |
| 4742 | const ch = state.input.charCodeAt(state.position); |
| 4743 | if (propertyStart !== null && allowBlockStyles && !allowBlockCollections && ch !== 124 && ch !== 62 && tryReadBlockMappingFromProperty( |
| 4744 | state, |
| 4745 | propertyStart, |
| 4746 | propertyStart.position - propertyStart.lineStart, |
| 4747 | flowIndent |
| 4748 | )) { |
| 4749 | hasContent = true; |
| 4750 | } else if (allowBlockScalars && readBlockScalar(state, flowIndent) || readSingleQuotedScalar(state, flowIndent) || readDoubleQuotedScalar(state, flowIndent)) { |
| 4751 | hasContent = true; |
| 4752 | } else if (readAlias(state)) { |
| 4753 | hasContent = true; |
| 4754 | if (state.tag !== null || state.anchor !== null) { |
| 4755 | throwError(state, "alias node should not have any properties"); |
| 4756 | } |
| 4757 | } else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) { |
| 4758 | hasContent = true; |
| 4759 | if (state.tag === null) { |
| 4760 | state.tag = "?"; |
| 4761 | } |
| 4762 | } |
| 4763 | if (state.anchor !== null) { |
| 4764 | storeAnchor(state, state.anchor, state.result); |
| 4765 | } |
| 4766 | } |
| 4767 | } else if (indentStatus === 0) { |
| 4768 | hasContent = allowBlockCollections && readBlockSequence(state, blockIndent); |
| 4769 | } |
| 4770 | } |
| 4771 | if (state.tag === null) { |
| 4772 | if (state.anchor !== null) { |
| 4773 | storeAnchor(state, state.anchor, state.result); |
| 4774 | } |
| 4775 | } else if (state.tag === "?") { |
| 4776 | if (state.result !== null && state.kind !== "scalar") { |
| 4777 | throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"'); |
| 4778 | } |
| 4779 | for (let typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) { |
| 4780 | type2 = state.implicitTypes[typeIndex]; |
| 4781 | if (type2.resolve(state.result)) { |
| 4782 | state.result = type2.construct(state.result); |
| 4783 | state.tag = type2.tag; |
| 4784 | if (state.anchor !== null) { |
| 4785 | storeAnchor(state, state.anchor, state.result); |
| 4786 | } |
| 4787 | break; |
| 4788 | } |
| 4789 | } |
| 4790 | } else if (state.tag !== "!") { |
| 4791 | if (_hasOwnProperty.call(state.typeMap[state.kind || "fallback"], state.tag)) { |
| 4792 | type2 = state.typeMap[state.kind || "fallback"][state.tag]; |
| 4793 | } else { |
| 4794 | type2 = null; |
| 4795 | const typeList = state.typeMap.multi[state.kind || "fallback"]; |
| 4796 | for (let typeIndex = 0, typeQuantity = typeList.length; typeIndex < typeQuantity; typeIndex += 1) { |
| 4797 | if (state.tag.slice(0, typeList[typeIndex].tag.length) === typeList[typeIndex].tag) { |
| 4798 | type2 = typeList[typeIndex]; |
| 4799 | break; |
| 4800 | } |
| 4801 | } |
| 4802 | } |
| 4803 | if (!type2) { |
| 4804 | throwError(state, "unknown tag !<" + state.tag + ">"); |
| 4805 | } |
| 4806 | if (state.result !== null && type2.kind !== state.kind) { |
| 4807 | throwError(state, "unacceptable node kind for !<" + state.tag + '> tag; it should be "' + type2.kind + '", not "' + state.kind + '"'); |
| 4808 | } |
| 4809 | if (!type2.resolve(state.result, state.tag)) { |
| 4810 | throwError(state, "cannot resolve a node with !<" + state.tag + "> explicit tag"); |
| 4811 | } else { |
| 4812 | state.result = type2.construct(state.result, state.tag); |
| 4813 | if (state.anchor !== null) { |
| 4814 | storeAnchor(state, state.anchor, state.result); |
| 4815 | } |
| 4816 | } |
| 4817 | } |
| 4818 | if (state.listener !== null) { |
| 4819 | state.listener("close", state); |
| 4820 | } |
| 4821 | state.depth -= 1; |
| 4822 | return state.tag !== null || state.anchor !== null || hasContent; |
| 4823 | } |
| 4824 | function readDocument(state) { |
| 4825 | const documentStart = state.position; |
| 4826 | let hasDirectives = false; |
| 4827 | let ch; |
| 4828 | state.version = null; |
| 4829 | state.checkLineBreaks = state.legacy; |
| 4830 | state.tagMap = /* @__PURE__ */ Object.create(null); |
| 4831 | state.anchorMap = /* @__PURE__ */ Object.create(null); |
| 4832 | while ((ch = state.input.charCodeAt(state.position)) !== 0) { |
| 4833 | skipSeparationSpace(state, true, -1); |
| 4834 | ch = state.input.charCodeAt(state.position); |
| 4835 | if (state.lineIndent > 0 || ch !== 37) { |
| 4836 | break; |
| 4837 | } |
| 4838 | hasDirectives = true; |
| 4839 | ch = state.input.charCodeAt(++state.position); |
| 4840 | let _position = state.position; |
| 4841 | while (ch !== 0 && !isWsOrEol(ch)) { |
| 4842 | ch = state.input.charCodeAt(++state.position); |
| 4843 | } |
| 4844 | const directiveName = state.input.slice(_position, state.position); |
| 4845 | const directiveArgs = []; |
| 4846 | if (directiveName.length < 1) { |
| 4847 | throwError(state, "directive name must not be less than one character in length"); |
| 4848 | } |
| 4849 | while (ch !== 0) { |
| 4850 | while (isWhiteSpace(ch)) { |
| 4851 | ch = state.input.charCodeAt(++state.position); |
| 4852 | } |
| 4853 | if (ch === 35) { |
| 4854 | do { |
| 4855 | ch = state.input.charCodeAt(++state.position); |
| 4856 | } while (ch !== 0 && !isEol(ch)); |
| 4857 | break; |
| 4858 | } |
| 4859 | if (isEol(ch)) break; |
| 4860 | _position = state.position; |
| 4861 | while (ch !== 0 && !isWsOrEol(ch)) { |
| 4862 | ch = state.input.charCodeAt(++state.position); |
| 4863 | } |
| 4864 | directiveArgs.push(state.input.slice(_position, state.position)); |
| 4865 | } |
| 4866 | if (ch !== 0) readLineBreak(state); |
| 4867 | if (_hasOwnProperty.call(directiveHandlers, directiveName)) { |
| 4868 | directiveHandlers[directiveName](state, directiveName, directiveArgs); |
| 4869 | } else { |
| 4870 | throwWarning(state, 'unknown document directive "' + directiveName + '"'); |
| 4871 | } |
| 4872 | } |
| 4873 | skipSeparationSpace(state, true, -1); |
| 4874 | if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 45 && state.input.charCodeAt(state.position + 1) === 45 && state.input.charCodeAt(state.position + 2) === 45) { |
| 4875 | state.position += 3; |
| 4876 | skipSeparationSpace(state, true, -1); |
| 4877 | } else if (hasDirectives) { |
| 4878 | throwError(state, "directives end mark is expected"); |
| 4879 | } |
| 4880 | composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true); |
| 4881 | skipSeparationSpace(state, true, -1); |
| 4882 | if (state.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) { |
| 4883 | throwWarning(state, "non-ASCII line breaks are interpreted as content"); |
| 4884 | } |
| 4885 | state.documents.push(state.result); |
| 4886 | if (state.position === state.lineStart && testDocumentSeparator(state)) { |
| 4887 | if (state.input.charCodeAt(state.position) === 46) { |
| 4888 | state.position += 3; |
| 4889 | skipSeparationSpace(state, true, -1); |
| 4890 | } |
| 4891 | return; |
| 4892 | } |
| 4893 | if (state.position < state.length - 1) { |
| 4894 | throwError(state, "end of the stream or a document separator is expected"); |
| 4895 | } |
| 4896 | } |
| 4897 | function loadDocuments(input, options) { |
| 4898 | input = String(input); |
| 4899 | options = options || {}; |
| 4900 | if (input.length !== 0) { |
| 4901 | if (input.charCodeAt(input.length - 1) !== 10 && input.charCodeAt(input.length - 1) !== 13) { |
| 4902 | input += "\n"; |
| 4903 | } |
| 4904 | if (input.charCodeAt(0) === 65279) { |
| 4905 | input = input.slice(1); |
| 4906 | } |
| 4907 | } |
| 4908 | const state = new State(input, options); |
| 4909 | const nullpos = input.indexOf("\0"); |
| 4910 | if (nullpos !== -1) { |
| 4911 | state.position = nullpos; |
| 4912 | throwError(state, "null byte is not allowed in input"); |
| 4913 | } |
| 4914 | state.input += "\0"; |
| 4915 | while (state.input.charCodeAt(state.position) === 32) { |
| 4916 | state.lineIndent += 1; |
| 4917 | state.position += 1; |
| 4918 | } |
| 4919 | while (state.position < state.length - 1) { |
| 4920 | readDocument(state); |
| 4921 | } |
| 4922 | return state.documents; |
| 4923 | } |
| 4924 | function loadAll2(input, iterator, options) { |
| 4925 | if (iterator !== null && typeof iterator === "object" && typeof options === "undefined") { |
| 4926 | options = iterator; |
| 4927 | iterator = null; |
| 4928 | } |
| 4929 | const documents = loadDocuments(input, options); |
| 4930 | if (typeof iterator !== "function") { |
| 4931 | return documents; |
| 4932 | } |
| 4933 | for (let index = 0, length = documents.length; index < length; index += 1) { |
| 4934 | iterator(documents[index]); |
| 4935 | } |
| 4936 | } |
| 4937 | function load2(input, options) { |
| 4938 | const documents = loadDocuments(input, options); |
| 4939 | if (documents.length === 0) { |
| 4940 | return void 0; |
| 4941 | } else if (documents.length === 1) { |
| 4942 | return documents[0]; |
| 4943 | } |
| 4944 | throw new YAMLException2("expected a single document in the stream, but found more"); |
| 4945 | } |
| 4946 | loader.loadAll = loadAll2; |
| 4947 | loader.load = load2; |
| 4948 | return loader; |
| 4949 | } |
| 4950 | function requireDumper() { |
| 4951 | if (hasRequiredDumper) return dumper; |
| 4952 | hasRequiredDumper = 1; |
| 4953 | const common2 = requireCommon(); |
| 4954 | const YAMLException2 = requireException(); |
| 4955 | const DEFAULT_SCHEMA2 = require_default(); |
| 4956 | const _toString = Object.prototype.toString; |
| 4957 | const _hasOwnProperty = Object.prototype.hasOwnProperty; |
| 4958 | const CHAR_BOM = 65279; |
| 4959 | const CHAR_TAB = 9; |
| 4960 | const CHAR_LINE_FEED = 10; |
| 4961 | const CHAR_CARRIAGE_RETURN = 13; |
| 4962 | const CHAR_SPACE = 32; |
| 4963 | const CHAR_EXCLAMATION = 33; |
| 4964 | const CHAR_DOUBLE_QUOTE = 34; |
| 4965 | const CHAR_SHARP = 35; |
| 4966 | const CHAR_PERCENT = 37; |
| 4967 | const CHAR_AMPERSAND = 38; |
| 4968 | const CHAR_SINGLE_QUOTE = 39; |
| 4969 | const CHAR_ASTERISK = 42; |
| 4970 | const CHAR_COMMA = 44; |
| 4971 | const CHAR_MINUS = 45; |
| 4972 | const CHAR_COLON = 58; |
| 4973 | const CHAR_EQUALS = 61; |
| 4974 | const CHAR_GREATER_THAN = 62; |
| 4975 | const CHAR_QUESTION = 63; |
| 4976 | const CHAR_COMMERCIAL_AT = 64; |
| 4977 | const CHAR_LEFT_SQUARE_BRACKET = 91; |
| 4978 | const CHAR_RIGHT_SQUARE_BRACKET = 93; |
| 4979 | const CHAR_GRAVE_ACCENT = 96; |
| 4980 | const CHAR_LEFT_CURLY_BRACKET = 123; |
| 4981 | const CHAR_VERTICAL_LINE = 124; |
| 4982 | const CHAR_RIGHT_CURLY_BRACKET = 125; |
| 4983 | const ESCAPE_SEQUENCES = {}; |
| 4984 | ESCAPE_SEQUENCES[0] = "\\0"; |
| 4985 | ESCAPE_SEQUENCES[7] = "\\a"; |
| 4986 | ESCAPE_SEQUENCES[8] = "\\b"; |
| 4987 | ESCAPE_SEQUENCES[9] = "\\t"; |
| 4988 | ESCAPE_SEQUENCES[10] = "\\n"; |
| 4989 | ESCAPE_SEQUENCES[11] = "\\v"; |
| 4990 | ESCAPE_SEQUENCES[12] = "\\f"; |
| 4991 | ESCAPE_SEQUENCES[13] = "\\r"; |
| 4992 | ESCAPE_SEQUENCES[27] = "\\e"; |
| 4993 | ESCAPE_SEQUENCES[34] = '\\"'; |
| 4994 | ESCAPE_SEQUENCES[92] = "\\\\"; |
| 4995 | ESCAPE_SEQUENCES[133] = "\\N"; |
| 4996 | ESCAPE_SEQUENCES[160] = "\\_"; |
| 4997 | ESCAPE_SEQUENCES[8232] = "\\L"; |
| 4998 | ESCAPE_SEQUENCES[8233] = "\\P"; |
| 4999 | const DEPRECATED_BOOLEANS_SYNTAX = [ |
| 5000 | "y", |
| 5001 | "Y", |
| 5002 | "yes", |
| 5003 | "Yes", |
| 5004 | "YES", |
| 5005 | "on", |
| 5006 | "On", |
| 5007 | "ON", |
| 5008 | "n", |
| 5009 | "N", |
| 5010 | "no", |
| 5011 | "No", |
| 5012 | "NO", |
| 5013 | "off", |
| 5014 | "Off", |
| 5015 | "OFF" |
| 5016 | ]; |
| 5017 | const DEPRECATED_BASE60_SYNTAX = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/; |
| 5018 | function compileStyleMap(schema22, map2) { |
| 5019 | if (map2 === null) return {}; |
| 5020 | const result = {}; |
| 5021 | const keys = Object.keys(map2); |
| 5022 | for (let index = 0, length = keys.length; index < length; index += 1) { |
| 5023 | let tag = keys[index]; |
| 5024 | let style = String(map2[tag]); |
| 5025 | if (tag.slice(0, 2) === "!!") { |
| 5026 | tag = "tag:yaml.org,2002:" + tag.slice(2); |
| 5027 | } |
| 5028 | const type2 = schema22.compiledTypeMap["fallback"][tag]; |
| 5029 | if (type2 && _hasOwnProperty.call(type2.styleAliases, style)) { |
| 5030 | style = type2.styleAliases[style]; |
| 5031 | } |
| 5032 | result[tag] = style; |
| 5033 | } |
| 5034 | return result; |
| 5035 | } |
| 5036 | function encodeHex(character) { |
| 5037 | let handle; |
| 5038 | let length; |
| 5039 | const string = character.toString(16).toUpperCase(); |
| 5040 | if (character <= 255) { |
| 5041 | handle = "x"; |
| 5042 | length = 2; |
| 5043 | } else if (character <= 65535) { |
| 5044 | handle = "u"; |
| 5045 | length = 4; |
| 5046 | } else if (character <= 4294967295) { |
| 5047 | handle = "U"; |
| 5048 | length = 8; |
| 5049 | } else { |
| 5050 | throw new YAMLException2("code point within a string may not be greater than 0xFFFFFFFF"); |
| 5051 | } |
| 5052 | return "\\" + handle + common2.repeat("0", length - string.length) + string; |
| 5053 | } |
| 5054 | const QUOTING_TYPE_SINGLE = 1; |
| 5055 | const QUOTING_TYPE_DOUBLE = 2; |
| 5056 | function State(options) { |
| 5057 | this.schema = options["schema"] || DEFAULT_SCHEMA2; |
| 5058 | this.indent = Math.max(1, options["indent"] || 2); |
| 5059 | this.noArrayIndent = options["noArrayIndent"] || false; |
| 5060 | this.skipInvalid = options["skipInvalid"] || false; |
| 5061 | this.flowLevel = common2.isNothing(options["flowLevel"]) ? -1 : options["flowLevel"]; |
| 5062 | this.styleMap = compileStyleMap(this.schema, options["styles"] || null); |
| 5063 | this.sortKeys = options["sortKeys"] || false; |
| 5064 | this.lineWidth = options["lineWidth"] || 80; |
| 5065 | this.noRefs = options["noRefs"] || false; |
| 5066 | this.noCompatMode = options["noCompatMode"] || false; |
| 5067 | this.condenseFlow = options["condenseFlow"] || false; |
| 5068 | this.quotingType = options["quotingType"] === '"' ? QUOTING_TYPE_DOUBLE : QUOTING_TYPE_SINGLE; |
| 5069 | this.forceQuotes = options["forceQuotes"] || false; |
| 5070 | this.replacer = typeof options["replacer"] === "function" ? options["replacer"] : null; |
| 5071 | this.implicitTypes = this.schema.compiledImplicit; |
| 5072 | this.explicitTypes = this.schema.compiledExplicit; |
| 5073 | this.tag = null; |
| 5074 | this.result = ""; |
| 5075 | this.duplicates = []; |
| 5076 | this.usedDuplicates = null; |
| 5077 | } |
| 5078 | function indentString(string, spaces) { |
| 5079 | const ind = common2.repeat(" ", spaces); |
| 5080 | let position = 0; |
| 5081 | let result = ""; |
| 5082 | const length = string.length; |
| 5083 | while (position < length) { |
| 5084 | let line; |
| 5085 | const next = string.indexOf("\n", position); |
| 5086 | if (next === -1) { |
| 5087 | line = string.slice(position); |
| 5088 | position = length; |
| 5089 | } else { |
| 5090 | line = string.slice(position, next + 1); |
| 5091 | position = next + 1; |
| 5092 | } |
| 5093 | if (line.length && line !== "\n") result += ind; |
| 5094 | result += line; |
| 5095 | } |
| 5096 | return result; |
| 5097 | } |
| 5098 | function generateNextLine(state, level) { |
| 5099 | return "\n" + common2.repeat(" ", state.indent * level); |
| 5100 | } |
| 5101 | function testImplicitResolving(state, str2) { |
| 5102 | for (let index = 0, length = state.implicitTypes.length; index < length; index += 1) { |
| 5103 | const type2 = state.implicitTypes[index]; |
| 5104 | if (type2.resolve(str2)) { |
| 5105 | return true; |
| 5106 | } |
| 5107 | } |
| 5108 | return false; |
| 5109 | } |
| 5110 | function isWhitespace(c) { |
| 5111 | return c === CHAR_SPACE || c === CHAR_TAB; |
| 5112 | } |
| 5113 | function isPrintable(c) { |
| 5114 | return c >= 32 && c <= 126 || c >= 161 && c <= 55295 && c !== 8232 && c !== 8233 || c >= 57344 && c <= 65533 && c !== CHAR_BOM || c >= 65536 && c <= 1114111; |
| 5115 | } |
| 5116 | function isNsCharOrWhitespace(c) { |
| 5117 | return isPrintable(c) && c !== CHAR_BOM && // - b-char |
| 5118 | c !== CHAR_CARRIAGE_RETURN && c !== CHAR_LINE_FEED; |
| 5119 | } |
| 5120 | function isPlainSafe(c, prev, inblock) { |
| 5121 | const cIsNsCharOrWhitespace = isNsCharOrWhitespace(c); |
| 5122 | const cIsNsChar = cIsNsCharOrWhitespace && !isWhitespace(c); |
| 5123 | return ( |
| 5124 | // ns-plain-safe |
| 5125 | (inblock ? cIsNsCharOrWhitespace : cIsNsCharOrWhitespace && // - c-flow-indicator |
| 5126 | c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET) && // ns-plain-char |
| 5127 | c !== CHAR_SHARP && // false on '#' |
| 5128 | !(prev === CHAR_COLON && !cIsNsChar) || // false on ': ' |
| 5129 | isNsCharOrWhitespace(prev) && !isWhitespace(prev) && c === CHAR_SHARP || // change to true on '[^ ]#' |
| 5130 | prev === CHAR_COLON && cIsNsChar |
| 5131 | ); |
| 5132 | } |
| 5133 | function isPlainSafeFirst(c) { |
| 5134 | return isPrintable(c) && c !== CHAR_BOM && !isWhitespace(c) && // - s-white |
| 5135 | // - (c-indicator ::= |
| 5136 | // “-” | “?” | “:” | “,” | “[” | “]” | “{” | “}” |
| 5137 | c !== CHAR_MINUS && c !== CHAR_QUESTION && c !== CHAR_COLON && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET && // | “#” | “&” | “*” | “!” | “|” | “=” | “>” | “'” | “"” |
| 5138 | c !== CHAR_SHARP && c !== CHAR_AMPERSAND && c !== CHAR_ASTERISK && c !== CHAR_EXCLAMATION && c !== CHAR_VERTICAL_LINE && c !== CHAR_EQUALS && c !== CHAR_GREATER_THAN && c !== CHAR_SINGLE_QUOTE && c !== CHAR_DOUBLE_QUOTE && // | “%” | “@” | “`”) |
| 5139 | c !== CHAR_PERCENT && c !== CHAR_COMMERCIAL_AT && c !== CHAR_GRAVE_ACCENT; |
| 5140 | } |
| 5141 | function isPlainSafeLast(c) { |
| 5142 | return !isWhitespace(c) && c !== CHAR_COLON; |
| 5143 | } |
| 5144 | function codePointAt(string, pos) { |
| 5145 | const first = string.charCodeAt(pos); |
| 5146 | let second; |
| 5147 | if (first >= 55296 && first <= 56319 && pos + 1 < string.length) { |
| 5148 | second = string.charCodeAt(pos + 1); |
| 5149 | if (second >= 56320 && second <= 57343) { |
| 5150 | return (first - 55296) * 1024 + second - 56320 + 65536; |
| 5151 | } |
| 5152 | } |
| 5153 | return first; |
| 5154 | } |
| 5155 | function needIndentIndicator(string) { |
| 5156 | const leadingSpaceRe = /^\n* /; |
| 5157 | return leadingSpaceRe.test(string); |
| 5158 | } |
| 5159 | const STYLE_PLAIN = 1; |
| 5160 | const STYLE_SINGLE = 2; |
| 5161 | const STYLE_LITERAL = 3; |
| 5162 | const STYLE_FOLDED = 4; |
| 5163 | const STYLE_DOUBLE = 5; |
| 5164 | function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType, quotingType, forceQuotes, inblock) { |
| 5165 | let i2; |
| 5166 | let char = 0; |
| 5167 | let prevChar = null; |
| 5168 | let hasLineBreak = false; |
| 5169 | let hasFoldableLine = false; |
| 5170 | const shouldTrackWidth = lineWidth !== -1; |
| 5171 | let previousLineBreak = -1; |
| 5172 | let plain2 = isPlainSafeFirst(codePointAt(string, 0)) && isPlainSafeLast(codePointAt(string, string.length - 1)); |
| 5173 | if (singleLineOnly || forceQuotes) { |
| 5174 | for (i2 = 0; i2 < string.length; char >= 65536 ? i2 += 2 : i2++) { |
| 5175 | char = codePointAt(string, i2); |
| 5176 | if (!isPrintable(char)) { |
| 5177 | return STYLE_DOUBLE; |
| 5178 | } |
| 5179 | plain2 = plain2 && isPlainSafe(char, prevChar, inblock); |
| 5180 | prevChar = char; |
| 5181 | } |
| 5182 | } else { |
| 5183 | for (i2 = 0; i2 < string.length; char >= 65536 ? i2 += 2 : i2++) { |
| 5184 | char = codePointAt(string, i2); |
| 5185 | if (char === CHAR_LINE_FEED) { |
| 5186 | hasLineBreak = true; |
| 5187 | if (shouldTrackWidth) { |
| 5188 | hasFoldableLine = hasFoldableLine || // Foldable line = too long, and not more-indented. |
| 5189 | i2 - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " "; |
| 5190 | previousLineBreak = i2; |
| 5191 | } |
| 5192 | } else if (!isPrintable(char)) { |
| 5193 | return STYLE_DOUBLE; |
| 5194 | } |
| 5195 | plain2 = plain2 && isPlainSafe(char, prevChar, inblock); |
| 5196 | prevChar = char; |
| 5197 | } |
| 5198 | hasFoldableLine = hasFoldableLine || shouldTrackWidth && (i2 - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " "); |
| 5199 | } |
| 5200 | if (!hasLineBreak && !hasFoldableLine) { |
| 5201 | if (plain2 && !forceQuotes && !testAmbiguousType(string)) { |
| 5202 | return STYLE_PLAIN; |
| 5203 | } |
| 5204 | return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE; |
| 5205 | } |
| 5206 | if (indentPerLevel > 9 && needIndentIndicator(string)) { |
| 5207 | return STYLE_DOUBLE; |
| 5208 | } |
| 5209 | if (!forceQuotes) { |
| 5210 | return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL; |
| 5211 | } |
| 5212 | return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE; |
| 5213 | } |
| 5214 | function writeScalar(state, string, level, iskey, inblock) { |
| 5215 | state.dump = (function() { |
| 5216 | if (string.length === 0) { |
| 5217 | return state.quotingType === QUOTING_TYPE_DOUBLE ? '""' : "''"; |
| 5218 | } |
| 5219 | if (!state.noCompatMode) { |
| 5220 | if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1 || DEPRECATED_BASE60_SYNTAX.test(string)) { |
| 5221 | return state.quotingType === QUOTING_TYPE_DOUBLE ? '"' + string + '"' : "'" + string + "'"; |
| 5222 | } |
| 5223 | } |
| 5224 | const indent = state.indent * Math.max(1, level); |
| 5225 | const lineWidth = state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent); |
| 5226 | const singleLineOnly = iskey || // No block styles in flow mode. |
| 5227 | state.flowLevel > -1 && level >= state.flowLevel; |
| 5228 | function testAmbiguity(string2) { |
| 5229 | return testImplicitResolving(state, string2); |
| 5230 | } |
| 5231 | switch (chooseScalarStyle( |
| 5232 | string, |
| 5233 | singleLineOnly, |
| 5234 | state.indent, |
| 5235 | lineWidth, |
| 5236 | testAmbiguity, |
| 5237 | state.quotingType, |
| 5238 | state.forceQuotes && !iskey, |
| 5239 | inblock |
| 5240 | )) { |
| 5241 | case STYLE_PLAIN: |
| 5242 | return string; |
| 5243 | case STYLE_SINGLE: |
| 5244 | return "'" + string.replace(/'/g, "''") + "'"; |
| 5245 | case STYLE_LITERAL: |
| 5246 | return "|" + blockHeader(string, state.indent) + dropEndingNewline(indentString(string, indent)); |
| 5247 | case STYLE_FOLDED: |
| 5248 | return ">" + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent)); |
| 5249 | case STYLE_DOUBLE: |
| 5250 | return '"' + escapeString(string) + '"'; |
| 5251 | default: |
| 5252 | throw new YAMLException2("impossible error: invalid scalar style"); |
| 5253 | } |
| 5254 | })(); |
| 5255 | } |
| 5256 | function blockHeader(string, indentPerLevel) { |
| 5257 | const indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : ""; |
| 5258 | const clip = string[string.length - 1] === "\n"; |
| 5259 | const keep = clip && (string[string.length - 2] === "\n" || string === "\n"); |
| 5260 | const chomp = keep ? "+" : clip ? "" : "-"; |
| 5261 | return indentIndicator + chomp + "\n"; |
| 5262 | } |
| 5263 | function dropEndingNewline(string) { |
| 5264 | return string[string.length - 1] === "\n" ? string.slice(0, -1) : string; |
| 5265 | } |
| 5266 | function foldString(string, width) { |
| 5267 | const lineRe = /(\n+)([^\n]*)/g; |
| 5268 | let result = (function() { |
| 5269 | let nextLF = string.indexOf("\n"); |
| 5270 | nextLF = nextLF !== -1 ? nextLF : string.length; |
| 5271 | lineRe.lastIndex = nextLF; |
| 5272 | return foldLine(string.slice(0, nextLF), width); |
| 5273 | })(); |
| 5274 | let prevMoreIndented = string[0] === "\n" || string[0] === " "; |
| 5275 | let moreIndented; |
| 5276 | let match; |
| 5277 | while (match = lineRe.exec(string)) { |
| 5278 | const prefix = match[1]; |
| 5279 | const line = match[2]; |
| 5280 | moreIndented = line[0] === " "; |
| 5281 | result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width); |
| 5282 | prevMoreIndented = moreIndented; |
| 5283 | } |
| 5284 | return result; |
| 5285 | } |
| 5286 | function foldLine(line, width) { |
| 5287 | if (line === "" || line[0] === " ") return line; |
| 5288 | const breakRe = / [^ ]/g; |
| 5289 | let match; |
| 5290 | let start = 0; |
| 5291 | let end; |
| 5292 | let curr = 0; |
| 5293 | let next = 0; |
| 5294 | let result = ""; |
| 5295 | while (match = breakRe.exec(line)) { |
| 5296 | next = match.index; |
| 5297 | if (next - start > width) { |
| 5298 | end = curr > start ? curr : next; |
| 5299 | result += "\n" + line.slice(start, end); |
| 5300 | start = end + 1; |
| 5301 | } |
| 5302 | curr = next; |
| 5303 | } |
| 5304 | result += "\n"; |
| 5305 | if (line.length - start > width && curr > start) { |
| 5306 | result += line.slice(start, curr) + "\n" + line.slice(curr + 1); |
| 5307 | } else { |
| 5308 | result += line.slice(start); |
| 5309 | } |
| 5310 | return result.slice(1); |
| 5311 | } |
| 5312 | function escapeString(string) { |
| 5313 | let result = ""; |
| 5314 | let char = 0; |
| 5315 | for (let i2 = 0; i2 < string.length; char >= 65536 ? i2 += 2 : i2++) { |
| 5316 | char = codePointAt(string, i2); |
| 5317 | const escapeSeq = ESCAPE_SEQUENCES[char]; |
| 5318 | if (!escapeSeq && isPrintable(char)) { |
| 5319 | result += string[i2]; |
| 5320 | if (char >= 65536) result += string[i2 + 1]; |
| 5321 | } else { |
| 5322 | result += escapeSeq || encodeHex(char); |
| 5323 | } |
| 5324 | } |
| 5325 | return result; |
| 5326 | } |
| 5327 | function writeFlowSequence(state, level, object) { |
| 5328 | let _result = ""; |
| 5329 | const _tag = state.tag; |
| 5330 | for (let index = 0, length = object.length; index < length; index += 1) { |
| 5331 | let value = object[index]; |
| 5332 | if (state.replacer) { |
| 5333 | value = state.replacer.call(object, String(index), value); |
| 5334 | } |
| 5335 | if (writeNode(state, level, value, false, false) || typeof value === "undefined" && writeNode(state, level, null, false, false)) { |
| 5336 | if (_result !== "") _result += "," + (!state.condenseFlow ? " " : ""); |
| 5337 | _result += state.dump; |
| 5338 | } |
| 5339 | } |
| 5340 | state.tag = _tag; |
| 5341 | state.dump = "[" + _result + "]"; |
| 5342 | } |
| 5343 | function writeBlockSequence(state, level, object, compact) { |
| 5344 | let _result = ""; |
| 5345 | const _tag = state.tag; |
| 5346 | for (let index = 0, length = object.length; index < length; index += 1) { |
| 5347 | let value = object[index]; |
| 5348 | if (state.replacer) { |
| 5349 | value = state.replacer.call(object, String(index), value); |
| 5350 | } |
| 5351 | if (writeNode(state, level + 1, value, true, true, false, true) || typeof value === "undefined" && writeNode(state, level + 1, null, true, true, false, true)) { |
| 5352 | if (!compact || _result !== "") { |
| 5353 | _result += generateNextLine(state, level); |
| 5354 | } |
| 5355 | if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) { |
| 5356 | _result += "-"; |
| 5357 | } else { |
| 5358 | _result += "- "; |
| 5359 | } |
| 5360 | _result += state.dump; |
| 5361 | } |
| 5362 | } |
| 5363 | state.tag = _tag; |
| 5364 | state.dump = _result || "[]"; |
| 5365 | } |
| 5366 | function writeFlowMapping(state, level, object) { |
| 5367 | let _result = ""; |
| 5368 | const _tag = state.tag; |
| 5369 | const objectKeyList = Object.keys(object); |
| 5370 | for (let index = 0, length = objectKeyList.length; index < length; index += 1) { |
| 5371 | let pairBuffer = ""; |
| 5372 | if (_result !== "") pairBuffer += ", "; |
| 5373 | if (state.condenseFlow) pairBuffer += '"'; |
| 5374 | const objectKey = objectKeyList[index]; |
| 5375 | let objectValue = object[objectKey]; |
| 5376 | if (state.replacer) { |
| 5377 | objectValue = state.replacer.call(object, objectKey, objectValue); |
| 5378 | } |
| 5379 | if (!writeNode(state, level, objectKey, false, false)) { |
| 5380 | continue; |
| 5381 | } |
| 5382 | if (state.dump.length > 1024) pairBuffer += "? "; |
| 5383 | pairBuffer += state.dump + (state.condenseFlow ? '"' : "") + ":" + (state.condenseFlow ? "" : " "); |
| 5384 | if (!writeNode(state, level, objectValue, false, false)) { |
| 5385 | continue; |
| 5386 | } |
| 5387 | pairBuffer += state.dump; |
| 5388 | _result += pairBuffer; |
| 5389 | } |
| 5390 | state.tag = _tag; |
| 5391 | state.dump = "{" + _result + "}"; |
| 5392 | } |
| 5393 | function writeBlockMapping(state, level, object, compact) { |
| 5394 | let _result = ""; |
| 5395 | const _tag = state.tag; |
| 5396 | const objectKeyList = Object.keys(object); |
| 5397 | if (state.sortKeys === true) { |
| 5398 | objectKeyList.sort(); |
| 5399 | } else if (typeof state.sortKeys === "function") { |
| 5400 | objectKeyList.sort(state.sortKeys); |
| 5401 | } else if (state.sortKeys) { |
| 5402 | throw new YAMLException2("sortKeys must be a boolean or a function"); |
| 5403 | } |
| 5404 | for (let index = 0, length = objectKeyList.length; index < length; index += 1) { |
| 5405 | let pairBuffer = ""; |
| 5406 | if (!compact || _result !== "") { |
| 5407 | pairBuffer += generateNextLine(state, level); |
| 5408 | } |
| 5409 | const objectKey = objectKeyList[index]; |
| 5410 | let objectValue = object[objectKey]; |
| 5411 | if (state.replacer) { |
| 5412 | objectValue = state.replacer.call(object, objectKey, objectValue); |
| 5413 | } |
| 5414 | if (!writeNode(state, level + 1, objectKey, true, true, true)) { |
| 5415 | continue; |
| 5416 | } |
| 5417 | const explicitPair = state.tag !== null && state.tag !== "?" || state.dump && state.dump.length > 1024; |
| 5418 | if (explicitPair) { |
| 5419 | if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) { |
| 5420 | pairBuffer += "?"; |
| 5421 | } else { |
| 5422 | pairBuffer += "? "; |
| 5423 | } |
| 5424 | } |
| 5425 | pairBuffer += state.dump; |
| 5426 | if (explicitPair) { |
| 5427 | pairBuffer += generateNextLine(state, level); |
| 5428 | } |
| 5429 | if (!writeNode(state, level + 1, objectValue, true, explicitPair)) { |
| 5430 | continue; |
| 5431 | } |
| 5432 | if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) { |
| 5433 | pairBuffer += ":"; |
| 5434 | } else { |
| 5435 | pairBuffer += ": "; |
| 5436 | } |
| 5437 | pairBuffer += state.dump; |
| 5438 | _result += pairBuffer; |
| 5439 | } |
| 5440 | state.tag = _tag; |
| 5441 | state.dump = _result || "{}"; |
| 5442 | } |
| 5443 | function detectType(state, object, explicit) { |
| 5444 | const typeList = explicit ? state.explicitTypes : state.implicitTypes; |
| 5445 | for (let index = 0, length = typeList.length; index < length; index += 1) { |
| 5446 | const type2 = typeList[index]; |
| 5447 | if ((type2.instanceOf || type2.predicate) && (!type2.instanceOf || typeof object === "object" && object instanceof type2.instanceOf) && (!type2.predicate || type2.predicate(object))) { |
| 5448 | if (explicit) { |
| 5449 | if (type2.multi && type2.representName) { |
| 5450 | state.tag = type2.representName(object); |
| 5451 | } else { |
| 5452 | state.tag = type2.tag; |
| 5453 | } |
| 5454 | } else { |
| 5455 | state.tag = "?"; |
| 5456 | } |
| 5457 | if (type2.represent) { |
| 5458 | const style = state.styleMap[type2.tag] || type2.defaultStyle; |
| 5459 | let _result; |
| 5460 | if (_toString.call(type2.represent) === "[object Function]") { |
| 5461 | _result = type2.represent(object, style); |
| 5462 | } else if (_hasOwnProperty.call(type2.represent, style)) { |
| 5463 | _result = type2.represent[style](object, style); |
| 5464 | } else { |
| 5465 | throw new YAMLException2("!<" + type2.tag + '> tag resolver accepts not "' + style + '" style'); |
| 5466 | } |
| 5467 | state.dump = _result; |
| 5468 | } |
| 5469 | return true; |
| 5470 | } |
| 5471 | } |
| 5472 | return false; |
| 5473 | } |
| 5474 | function writeNode(state, level, object, block, compact, iskey, isblockseq) { |
| 5475 | state.tag = null; |
| 5476 | state.dump = object; |
| 5477 | if (!detectType(state, object, false)) { |
| 5478 | detectType(state, object, true); |
| 5479 | } |
| 5480 | const type2 = _toString.call(state.dump); |
| 5481 | const inblock = block; |
| 5482 | if (block) { |
| 5483 | block = state.flowLevel < 0 || state.flowLevel > level; |
| 5484 | } |
| 5485 | const objectOrArray = type2 === "[object Object]" || type2 === "[object Array]"; |
| 5486 | let duplicateIndex; |
| 5487 | let duplicate; |
| 5488 | if (objectOrArray) { |
| 5489 | duplicateIndex = state.duplicates.indexOf(object); |
| 5490 | duplicate = duplicateIndex !== -1; |
| 5491 | } |
| 5492 | if (state.tag !== null && state.tag !== "?" || duplicate || state.indent !== 2 && level > 0) { |
| 5493 | compact = false; |
| 5494 | } |
| 5495 | if (duplicate && state.usedDuplicates[duplicateIndex]) { |
| 5496 | state.dump = "*ref_" + duplicateIndex; |
| 5497 | } else { |
| 5498 | if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) { |
| 5499 | state.usedDuplicates[duplicateIndex] = true; |
| 5500 | } |
| 5501 | if (type2 === "[object Object]") { |
| 5502 | if (block && Object.keys(state.dump).length !== 0) { |
| 5503 | writeBlockMapping(state, level, state.dump, compact); |
| 5504 | if (duplicate) { |
| 5505 | state.dump = "&ref_" + duplicateIndex + state.dump; |
| 5506 | } |
| 5507 | } else { |
| 5508 | writeFlowMapping(state, level, state.dump); |
| 5509 | if (duplicate) { |
| 5510 | state.dump = "&ref_" + duplicateIndex + " " + state.dump; |
| 5511 | } |
| 5512 | } |
| 5513 | } else if (type2 === "[object Array]") { |
| 5514 | if (block && state.dump.length !== 0) { |
| 5515 | if (state.noArrayIndent && !isblockseq && level > 0) { |
| 5516 | writeBlockSequence(state, level - 1, state.dump, compact); |
| 5517 | } else { |
| 5518 | writeBlockSequence(state, level, state.dump, compact); |
| 5519 | } |
| 5520 | if (duplicate) { |
| 5521 | state.dump = "&ref_" + duplicateIndex + state.dump; |
| 5522 | } |
| 5523 | } else { |
| 5524 | writeFlowSequence(state, level, state.dump); |
| 5525 | if (duplicate) { |
| 5526 | state.dump = "&ref_" + duplicateIndex + " " + state.dump; |
| 5527 | } |
| 5528 | } |
| 5529 | } else if (type2 === "[object String]") { |
| 5530 | if (state.tag !== "?") { |
| 5531 | writeScalar(state, state.dump, level, iskey, inblock); |
| 5532 | } |
| 5533 | } else if (type2 === "[object Undefined]") { |
| 5534 | return false; |
| 5535 | } else { |
| 5536 | if (state.skipInvalid) return false; |
| 5537 | throw new YAMLException2("unacceptable kind of an object to dump " + type2); |
| 5538 | } |
| 5539 | if (state.tag !== null && state.tag !== "?") { |
| 5540 | let tagStr = encodeURI( |
| 5541 | state.tag[0] === "!" ? state.tag.slice(1) : state.tag |
| 5542 | ).replace(/!/g, "%21"); |
| 5543 | if (state.tag[0] === "!") { |
| 5544 | tagStr = "!" + tagStr; |
| 5545 | } else if (tagStr.slice(0, 18) === "tag:yaml.org,2002:") { |
| 5546 | tagStr = "!!" + tagStr.slice(18); |
| 5547 | } else { |
| 5548 | tagStr = "!<" + tagStr + ">"; |
| 5549 | } |
| 5550 | state.dump = tagStr + " " + state.dump; |
| 5551 | } |
| 5552 | } |
| 5553 | return true; |
| 5554 | } |
| 5555 | function getDuplicateReferences(object, state) { |
| 5556 | const objects = []; |
| 5557 | const duplicatesIndexes = []; |
| 5558 | inspectNode(object, objects, duplicatesIndexes); |
| 5559 | const length = duplicatesIndexes.length; |
| 5560 | for (let index = 0; index < length; index += 1) { |
| 5561 | state.duplicates.push(objects[duplicatesIndexes[index]]); |
| 5562 | } |
| 5563 | state.usedDuplicates = new Array(length); |
| 5564 | } |
| 5565 | function inspectNode(object, objects, duplicatesIndexes) { |
| 5566 | if (object !== null && typeof object === "object") { |
| 5567 | const index = objects.indexOf(object); |
| 5568 | if (index !== -1) { |
| 5569 | if (duplicatesIndexes.indexOf(index) === -1) { |
| 5570 | duplicatesIndexes.push(index); |
| 5571 | } |
| 5572 | } else { |
| 5573 | objects.push(object); |
| 5574 | if (Array.isArray(object)) { |
| 5575 | for (let i2 = 0, length = object.length; i2 < length; i2 += 1) { |
| 5576 | inspectNode(object[i2], objects, duplicatesIndexes); |
| 5577 | } |
| 5578 | } else { |
| 5579 | const objectKeyList = Object.keys(object); |
| 5580 | for (let i2 = 0, length = objectKeyList.length; i2 < length; i2 += 1) { |
| 5581 | inspectNode(object[objectKeyList[i2]], objects, duplicatesIndexes); |
| 5582 | } |
| 5583 | } |
| 5584 | } |
| 5585 | } |
| 5586 | } |
| 5587 | function dump2(input, options) { |
| 5588 | options = options || {}; |
| 5589 | const state = new State(options); |
| 5590 | if (!state.noRefs) getDuplicateReferences(input, state); |
| 5591 | let value = input; |
| 5592 | if (state.replacer) { |
| 5593 | value = state.replacer.call({ "": value }, "", value); |
| 5594 | } |
| 5595 | if (writeNode(state, 0, value, true, true)) return state.dump + "\n"; |
| 5596 | return ""; |
| 5597 | } |
| 5598 | dumper.dump = dump2; |
| 5599 | return dumper; |
| 5600 | } |
| 5601 | function requireJsYaml() { |
| 5602 | if (hasRequiredJsYaml) return jsYaml; |
| 5603 | hasRequiredJsYaml = 1; |
| 5604 | const loader2 = requireLoader(); |
| 5605 | const dumper2 = requireDumper(); |
| 5606 | function renamed(from, to) { |
| 5607 | return function() { |
| 5608 | throw new Error("Function yaml." + from + " is removed in js-yaml 4. Use yaml." + to + " instead, which is now safe by default."); |
| 5609 | }; |
| 5610 | } |
| 5611 | jsYaml.Type = requireType(); |
| 5612 | jsYaml.Schema = requireSchema(); |
| 5613 | jsYaml.FAILSAFE_SCHEMA = requireFailsafe(); |
| 5614 | jsYaml.JSON_SCHEMA = requireJson(); |
| 5615 | jsYaml.CORE_SCHEMA = requireCore(); |
| 5616 | jsYaml.DEFAULT_SCHEMA = require_default(); |
| 5617 | jsYaml.load = loader2.load; |
| 5618 | jsYaml.loadAll = loader2.loadAll; |
| 5619 | jsYaml.dump = dumper2.dump; |
| 5620 | jsYaml.YAMLException = requireException(); |
| 5621 | jsYaml.types = { |
| 5622 | binary: requireBinary(), |
| 5623 | float: requireFloat(), |
| 5624 | map: requireMap(), |
| 5625 | null: require_null(), |
| 5626 | pairs: requirePairs(), |
| 5627 | set: requireSet(), |
| 5628 | timestamp: requireTimestamp(), |
| 5629 | bool: requireBool(), |
| 5630 | int: requireInt(), |
| 5631 | merge: requireMerge(), |
| 5632 | omap: requireOmap(), |
| 5633 | seq: requireSeq(), |
| 5634 | str: requireStr() |
| 5635 | }; |
| 5636 | jsYaml.safeLoad = renamed("safeLoad", "load"); |
| 5637 | jsYaml.safeLoadAll = renamed("safeLoadAll", "loadAll"); |
| 5638 | jsYaml.safeDump = renamed("safeDump", "dump"); |
| 5639 | return jsYaml; |
| 5640 | } |
| 5641 | var jsYaml, loader, common, hasRequiredCommon, exception, hasRequiredException, snippet, hasRequiredSnippet, type, hasRequiredType, schema, hasRequiredSchema, str, hasRequiredStr, seq, hasRequiredSeq, map, hasRequiredMap, failsafe, hasRequiredFailsafe, _null, hasRequired_null, bool, hasRequiredBool, int, hasRequiredInt, float, hasRequiredFloat, json, hasRequiredJson, core, hasRequiredCore, timestamp, hasRequiredTimestamp, merge, hasRequiredMerge, binary, hasRequiredBinary, omap, hasRequiredOmap, pairs, hasRequiredPairs, set, hasRequiredSet, _default, hasRequired_default, hasRequiredLoader, dumper, hasRequiredDumper, hasRequiredJsYaml, jsYamlExports, yaml, Type, Schema, FAILSAFE_SCHEMA, JSON_SCHEMA, CORE_SCHEMA, DEFAULT_SCHEMA, load, loadAll, dump, YAMLException, types, safeLoad, safeLoadAll, safeDump; |
| 5642 | var init_js_yaml = __esm({ |
| 5643 | "node_modules/js-yaml/dist/js-yaml.mjs"() { |
| 5644 | jsYaml = {}; |
| 5645 | loader = {}; |
| 5646 | common = {}; |
| 5647 | dumper = {}; |
| 5648 | jsYamlExports = requireJsYaml(); |
| 5649 | yaml = /* @__PURE__ */ getDefaultExportFromCjs(jsYamlExports); |
| 5650 | ({ |
| 5651 | Type, |
| 5652 | Schema, |
| 5653 | FAILSAFE_SCHEMA, |
| 5654 | JSON_SCHEMA, |
| 5655 | CORE_SCHEMA, |
| 5656 | DEFAULT_SCHEMA, |
| 5657 | load, |
| 5658 | loadAll, |
| 5659 | dump, |
| 5660 | YAMLException, |
| 5661 | types, |
| 5662 | safeLoad, |
| 5663 | safeLoadAll, |
| 5664 | safeDump |
| 5665 | } = yaml); |
| 5666 | } |
| 5667 | }); |
| 5668 | |
| 5669 | // src/dsh/upstream/include/src/index.ts |
| 5670 | import { extname } from "node:path"; |
| 5671 | import { access, constants, readFile, rename, writeFile } from "node:fs/promises"; |
| 5672 | import { setTimeout as delay } from "node:timers/promises"; |
| 5673 | import { fileURLToPath, pathToFileURL } from "node:url"; |
| 5674 | function retryableWriteError(error) { |
| 5675 | const code = error?.code; |
| 5676 | return code === "EACCES" || code === "EBUSY" || code === "EPERM"; |
| 5677 | } |
| 5678 | function applyEntryPatches(data2, patches, warn) { |
| 5679 | if (!patches?.length) return [...data2]; |
| 5680 | data2 = structuredClone(data2); |
| 5681 | const entryMap = /* @__PURE__ */ new Map(); |
| 5682 | const buildMap = (entries) => { |
| 5683 | for (const entry of entries) { |
| 5684 | if (entry.id) entryMap.set(entry.id, entry); |
| 5685 | if (entry.group && Array.isArray(entry.config)) { |
| 5686 | buildMap(entry.config); |
| 5687 | } |
| 5688 | } |
| 5689 | }; |
| 5690 | buildMap(data2); |
| 5691 | for (const patch of patches) { |
| 5692 | const { id, insert, name, ...overrides } = patch; |
| 5693 | if (insert) { |
| 5694 | if (id) { |
| 5695 | const target2 = entryMap.get(id); |
| 5696 | if (!target2) { |
| 5697 | warn("patch insert: entry %C not found", id); |
| 5698 | continue; |
| 5699 | } |
| 5700 | if (!target2.group) { |
| 5701 | warn("patch insert: entry %C is not a group", id); |
| 5702 | continue; |
| 5703 | } |
| 5704 | if (!Array.isArray(target2.config)) target2.config = []; |
| 5705 | target2.config.push(...insert); |
| 5706 | } else { |
| 5707 | data2.push(...insert); |
| 5708 | } |
| 5709 | buildMap(insert); |
| 5710 | continue; |
| 5711 | } |
| 5712 | if (!id) { |
| 5713 | warn("patch: id is required for non-insert patches"); |
| 5714 | continue; |
| 5715 | } |
| 5716 | const target = entryMap.get(id); |
| 5717 | if (!target) { |
| 5718 | warn("patch: entry %C not found", id); |
| 5719 | continue; |
| 5720 | } |
| 5721 | if (name && name !== target.name) { |
| 5722 | warn("patch: name mismatch for %C (expected %C, got %C), skipping", id, target.name, name); |
| 5723 | continue; |
| 5724 | } |
| 5725 | for (const [key, value] of Object.entries(overrides)) { |
| 5726 | if (key === "id") continue; |
| 5727 | target[key] = value; |
| 5728 | } |
| 5729 | } |
| 5730 | return data2; |
| 5731 | } |
| 5732 | var JsExpr, entryListSchema, schema2, writable, supported, WRITE_RETRY_LIMIT, WRITE_RETRY_DELAY_MS, Include; |
| 5733 | var init_src2 = __esm({ |
| 5734 | "src/dsh/upstream/include/src/index.ts"() { |
| 5735 | "use strict"; |
| 5736 | init_src(); |
| 5737 | init_lib2(); |
| 5738 | init_js_yaml(); |
| 5739 | JsExpr = new Type("tag:yaml.org,2002:js", { |
| 5740 | kind: "scalar", |
| 5741 | resolve: (data2) => typeof data2 === "string", |
| 5742 | construct: (data2) => ({ __jsExpr: data2 }), |
| 5743 | predicate: isJsExpr, |
| 5744 | represent: (data2) => data2.__jsExpr |
| 5745 | }); |
| 5746 | entryListSchema = JSON_SCHEMA.extend(JsExpr); |
| 5747 | schema2 = entryListSchema; |
| 5748 | writable = { |
| 5749 | ".json": "application/json", |
| 5750 | ".yaml": "application/yaml", |
| 5751 | ".yml": "application/yaml" |
| 5752 | }; |
| 5753 | supported = new Set(Object.keys(writable)); |
| 5754 | WRITE_RETRY_LIMIT = 10; |
| 5755 | WRITE_RETRY_DELAY_MS = 50; |
| 5756 | Include = class extends EntryTree { |
| 5757 | constructor(ctx, config) { |
| 5758 | super(ctx); |
| 5759 | this.config = config; |
| 5760 | this.enableLogs = config.enableLogs ?? ctx.fiber.entry?.parent.tree.enableLogs ?? false; |
| 5761 | this.filename = fileURLToPath(new URL(this.config.path, this.ctx.baseUrl)); |
| 5762 | const ext = extname(this.filename); |
| 5763 | if (!supported.has(ext)) { |
| 5764 | throw new Error(`extension "${ext}" not supported`); |
| 5765 | } |
| 5766 | this.type = writable[ext]; |
| 5767 | this.readonly = !this.type; |
| 5768 | this.ctx.baseUrl = new URL(".", pathToFileURL(this.filename)).href; |
| 5769 | ctx.on("internal/update", (config2, _, next) => { |
| 5770 | if (config2.path !== this.config.path) return next(); |
| 5771 | this.config = config2; |
| 5772 | this.root.update(this.applyPatches(this.data, config2.patches)).catch((error) => { |
| 5773 | this.ctx.logger.warn("config update at %C failed", this.filename); |
| 5774 | this.ctx.logger.warn(error); |
| 5775 | }); |
| 5776 | }); |
| 5777 | } |
| 5778 | config; |
| 5779 | static inject = ["loader"]; |
| 5780 | // Tree-carrier marker (the Group plugin declares the same): this config is |
| 5781 | // entry and patch lists, so the Loader's `internal/config` interpolation |
| 5782 | // keeps it literal — a `!!js` expression inside a nested row's config |
| 5783 | // belongs to that row's fiber, resolving lazily in the row's own context. |
| 5784 | // Include's own fields (`path`, `enableLogs`) therefore stay literal too. |
| 5785 | static [EntryGroup.key] = true; |
| 5786 | filename; |
| 5787 | type; |
| 5788 | readonly; |
| 5789 | content; |
| 5790 | data; |
| 5791 | writeTask; |
| 5792 | pendingWrite; |
| 5793 | writeQueue = Promise.resolve(); |
| 5794 | async checkAccess() { |
| 5795 | if (!this.type) return; |
| 5796 | try { |
| 5797 | await access(this.filename, constants.W_OK); |
| 5798 | } catch { |
| 5799 | this.readonly = true; |
| 5800 | } |
| 5801 | } |
| 5802 | async read(forced = false) { |
| 5803 | const content = await readFile(this.filename, "utf8"); |
| 5804 | if (!forced && this.content === content) return false; |
| 5805 | let data2; |
| 5806 | if (this.type === "application/yaml") { |
| 5807 | data2 = load(content, { schema: entryListSchema }); |
| 5808 | } else if (this.type === "application/json") { |
| 5809 | data2 = JSON.parse(content); |
| 5810 | } else { |
| 5811 | const module = await import( |
| 5812 | /* @vite-ignore */ |
| 5813 | this.filename |
| 5814 | ); |
| 5815 | data2 = module.default || module; |
| 5816 | } |
| 5817 | if (!Array.isArray(data2)) { |
| 5818 | throw new TypeError(`config file must be a top-level array of entries: ${this.filename}`); |
| 5819 | } |
| 5820 | this.content = content; |
| 5821 | this.data = data2; |
| 5822 | await this.checkAccess(); |
| 5823 | return true; |
| 5824 | } |
| 5825 | applyPatches(data2, patches = this.config.patches) { |
| 5826 | return applyEntryPatches(data2, patches, (message, ...args) => { |
| 5827 | this.ctx.root.logger?.("loader").warn(message, ...args); |
| 5828 | }); |
| 5829 | } |
| 5830 | async *[Service.init]() { |
| 5831 | try { |
| 5832 | await this.read(); |
| 5833 | } catch (error) { |
| 5834 | if (error?.code !== "ENOENT") throw error; |
| 5835 | if (this.config.initial) { |
| 5836 | await this._writeFile(this.config.initial); |
| 5837 | await this.read(true); |
| 5838 | } else { |
| 5839 | throw new Error(`config file not found: ${this.filename}`); |
| 5840 | } |
| 5841 | } |
| 5842 | yield () => this.stop(); |
| 5843 | await this.root.update(this.applyPatches(this.data)); |
| 5844 | } |
| 5845 | async stop() { |
| 5846 | try { |
| 5847 | await this.flushWrite(); |
| 5848 | } finally { |
| 5849 | this.root.stop(); |
| 5850 | await this.flushWrite(); |
| 5851 | } |
| 5852 | } |
| 5853 | /** |
| 5854 | * Re-read the file and refresh child entries when content changed. An |
| 5855 | * unreadable or unparsable file logs a warning and keeps the last good |
| 5856 | * tree: a hot-reload of a live app must never take the process down. |
| 5857 | */ |
| 5858 | async refresh() { |
| 5859 | try { |
| 5860 | if (!await this.read()) return; |
| 5861 | await this.root.update(this.applyPatches(this.data)); |
| 5862 | } catch (error) { |
| 5863 | this.ctx.logger.warn("config reload at %C failed; keeping the running tree", this.filename); |
| 5864 | this.ctx.logger.warn(error); |
| 5865 | } |
| 5866 | } |
| 5867 | async _writeFile(config) { |
| 5868 | if (this.readonly) { |
| 5869 | throw new Error(`cannot overwrite readonly config`); |
| 5870 | } |
| 5871 | if (this.type === "application/yaml") { |
| 5872 | this.content = dump(config, { schema: schema2 }); |
| 5873 | } else if (this.type === "application/json") { |
| 5874 | this.content = JSON.stringify(config, null, 2); |
| 5875 | } |
| 5876 | await writeFile(this.filename + ".tmp", this.content); |
| 5877 | for (let retry = 0; ; retry++) { |
| 5878 | try { |
| 5879 | await rename(this.filename + ".tmp", this.filename); |
| 5880 | return; |
| 5881 | } catch (error) { |
| 5882 | if (!retryableWriteError(error) || retry >= WRITE_RETRY_LIMIT) throw error; |
| 5883 | await delay((retry + 1) * WRITE_RETRY_DELAY_MS); |
| 5884 | } |
| 5885 | } |
| 5886 | } |
| 5887 | writeFile(config) { |
| 5888 | clearTimeout(this.writeTask); |
| 5889 | this.pendingWrite = config; |
| 5890 | this.writeTask = setTimeout(() => { |
| 5891 | void this.flushWrite(); |
| 5892 | }, 0); |
| 5893 | } |
| 5894 | flushWrite() { |
| 5895 | clearTimeout(this.writeTask); |
| 5896 | this.writeTask = void 0; |
| 5897 | const config = this.pendingWrite; |
| 5898 | this.pendingWrite = void 0; |
| 5899 | if (config === void 0) return this.writeQueue; |
| 5900 | const run = this.writeQueue.then( |
| 5901 | () => this._writeFile(config), |
| 5902 | () => this._writeFile(config) |
| 5903 | ); |
| 5904 | this.writeQueue = run; |
| 5905 | void run.catch((error) => { |
| 5906 | this.ctx.root.logger?.("loader").warn("failed to write config file %C", this.filename); |
| 5907 | this.ctx.root.logger?.("loader").warn(error); |
| 5908 | }); |
| 5909 | return run; |
| 5910 | } |
| 5911 | /** Schedule a write of the current root entry data. */ |
| 5912 | write() { |
| 5913 | this.context.emit("loader/config-update"); |
| 5914 | return this.writeFile(this.root.data); |
| 5915 | } |
| 5916 | }; |
| 5917 | } |
| 5918 | }); |
| 5919 | |
| 5920 | // src/json.ts |
| 5921 | function isJson(value, depth = 0) { |
| 5922 | if (depth > 64) return false; |
| 5923 | if (value === null) return true; |
| 5924 | switch (typeof value) { |
| 5925 | case "boolean": |
| 5926 | case "string": |
| 5927 | return true; |
| 5928 | case "number": |
| 5929 | return Number.isFinite(value); |
| 5930 | case "object": { |
| 5931 | const array = Array.isArray(value); |
| 5932 | if (!array && Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) return false; |
| 5933 | const keys = Reflect.ownKeys(value); |
| 5934 | if (array && keys.length !== value.length + 1) return false; |
| 5935 | for (const key of keys) { |
| 5936 | if (array && key === "length") continue; |
| 5937 | if (typeof key !== "string") return false; |
| 5938 | if (array && (!/^(0|[1-9]\d*)$/u.test(key) || Number(key) >= value.length)) return false; |
| 5939 | const descriptor = Object.getOwnPropertyDescriptor(value, key); |
| 5940 | if (!descriptor.enumerable || !("value" in descriptor) || !isJson(descriptor.value, depth + 1)) return false; |
| 5941 | } |
| 5942 | return true; |
| 5943 | } |
| 5944 | default: |
| 5945 | return false; |
| 5946 | } |
| 5947 | } |
| 5948 | var init_json = __esm({ |
| 5949 | "src/json.ts"() { |
| 5950 | "use strict"; |
| 5951 | } |
| 5952 | }); |
| 5953 | |
| 5954 | // src/shims/owned.ts |
| 5955 | var init_owned = __esm({ |
| 5956 | "src/shims/owned.ts"() { |
| 5957 | "use strict"; |
| 5958 | } |
| 5959 | }); |
| 5960 | |
| 5961 | // src/shims/mcp.ts |
| 5962 | function normalizeMcp(value) { |
| 5963 | if (!value || typeof value !== "object" || Array.isArray(value) || Object.keys(value).some((k) => k !== "serverName" && k !== "server")) throw new TypeError("MCP needs serverName and server"); |
| 5964 | const { serverName, server } = value; |
| 5965 | if (typeof serverName !== "string" || !/^[A-Za-z0-9][A-Za-z0-9_-]{0,31}$/.test(serverName) || !server || Array.isArray(server) || typeof server !== "object" || !isJson(server)) throw new TypeError("MCP definition must be bounded plain JSON"); |
| 5966 | for (const key of ["headers", "env"]) if (server[key] !== void 0 && (!server[key] || typeof server[key] !== "object" || Array.isArray(server[key]) || Object.keys(server[key]).length)) throw new TypeError("MCP credentials remain under Rust authentication authority"); |
| 5967 | if (typeof server.url === "string") { |
| 5968 | const url = new URL(server.url); |
| 5969 | if (url.username || url.password || url.search || url.hash) throw new TypeError("MCP endpoint credentials and query data remain under Rust authority"); |
| 5970 | } |
| 5971 | if (Buffer.byteLength(JSON.stringify(server)) > 64 * 1024) throw new RangeError("MCP definition exceeds 64 KiB"); |
| 5972 | return Object.freeze({ serverName, server: structuredClone(server) }); |
| 5973 | } |
| 5974 | var init_mcp = __esm({ |
| 5975 | "src/shims/mcp.ts"() { |
| 5976 | "use strict"; |
| 5977 | init_json(); |
| 5978 | init_owned(); |
| 5979 | } |
| 5980 | }); |
| 5981 | |
| 5982 | // src/dsh/mcp.ts |
| 5983 | function reviewedMcpModule() { |
| 5984 | return { |
| 5985 | name: "codewhale-reviewed-mcp", |
| 5986 | inject: ["mcp"], |
| 5987 | apply(ctx, config) { |
| 5988 | if (!config || Array.isArray(config) || Object.keys(config).some((k) => !["transport", "serverName", "command", "args", "env", "cwd", "url", "headers", "toolCallTimeoutMs", "failOnStartupError"].includes(k))) throw new Error("MCP row uses unsupported configuration; Core owns reconnect and instruction bounds"); |
| 5989 | if (typeof config.serverName !== "string") throw new Error("MCP serverName must be literal"); |
| 5990 | const options = {}; |
| 5991 | if (config.toolCallTimeoutMs !== void 0) { |
| 5992 | const timeout = config.toolCallTimeoutMs; |
| 5993 | if (typeof timeout !== "number" || !Number.isInteger(timeout) || timeout < 1e3 || timeout > 864e5 || timeout % 1e3 !== 0) throw new Error("MCP timeout must be whole seconds within Core bounds"); |
| 5994 | options.execute_timeout = timeout / 1e3; |
| 5995 | } |
| 5996 | if (config.failOnStartupError === true) throw new Error("failOnStartupError requires explicit Core MCP connection qualification before activation"); |
| 5997 | if (config.failOnStartupError !== void 0 && config.failOnStartupError !== false) throw new Error("MCP startup gate must be a boolean"); |
| 5998 | let server; |
| 5999 | if (config.transport === "stdio") { |
| 6000 | const cwd = config.cwd ?? ""; |
| 6001 | if (typeof cwd !== "string" || cwd !== "" && cwd !== "." && (!cwd || /[\\:\u0000-\u001f]/u.test(cwd) || cwd.split("/").some((p) => !p || p === "." || p === ".."))) throw new Error("MCP cwd must be a reviewed bundle-relative directory"); |
| 6002 | server = { type: "stdio", command: config.command, args: config.args ?? [], env: config.env ?? {}, cwd: cwd === "" || cwd === "." ? "source" : `source/${cwd}` }; |
| 6003 | } else if (config.transport === "streamable-http" || config.transport === "sse") server = { type: config.transport, url: config.url, headers: config.headers ?? {} }; |
| 6004 | else throw new Error("MCP transport must be stdio, streamable-http or sse"); |
| 6005 | if (Object.keys(options).length) server.extensions = { "net.codewhale": options }; |
| 6006 | ctx.mcp.registerServer(normalizeMcp({ serverName: config.serverName, server })); |
| 6007 | } |
| 6008 | }; |
| 6009 | } |
| 6010 | var init_mcp2 = __esm({ |
| 6011 | "src/dsh/mcp.ts"() { |
| 6012 | "use strict"; |
| 6013 | init_mcp(); |
| 6014 | } |
| 6015 | }); |
| 6016 | |
| 6017 | // src/shims/skills.ts |
| 6018 | function normalizeSkillRoot(value) { |
| 6019 | if (typeof value !== "object" || value === null || Array.isArray(value) || Object.keys(value).some((key) => key !== "path")) throw new TypeError("skill root supports only path"); |
| 6020 | const { path } = value; |
| 6021 | if (typeof path !== "string" || !path || Buffer.byteLength(path, "utf8") > 512 || /[\\:\u0000-\u001f\u007f-\u009f]/u.test(path) || path.split("/").some((part) => !part || part === "." || part === "..")) { |
| 6022 | throw new TypeError("skill root path must be a bounded bundle-relative path with normal slash-separated components"); |
| 6023 | } |
| 6024 | return Object.freeze({ path }); |
| 6025 | } |
| 6026 | var init_skills = __esm({ |
| 6027 | "src/shims/skills.ts"() { |
| 6028 | "use strict"; |
| 6029 | init_owned(); |
| 6030 | } |
| 6031 | }); |
| 6032 | |
| 6033 | // src/dsh/skill-filesystem.ts |
| 6034 | function reviewedSkillModule() { |
| 6035 | return { name: "codewhale-reviewed-skills", inject: ["skills"], apply(ctx, config) { |
| 6036 | if (!config || Array.isArray(config) || Object.keys(config).some((k) => !["providerName", "includeDefaultRoots", "customSkillDirs", "watch"].includes(k))) throw new Error("filesystem row requires reviewed roots; ambient roots and watcher controls are unsupported"); |
| 6037 | if (config.includeDefaultRoots !== false || config.watch !== false) throw new Error("filesystem row must explicitly disable default roots and watchers"); |
| 6038 | if (config.providerName !== void 0 && (typeof config.providerName !== "string" || !config.providerName || config.providerName.length > 64)) throw new Error("skill providerName must be bounded"); |
| 6039 | if (!Array.isArray(config.customSkillDirs) || !config.customSkillDirs.length || config.customSkillDirs.length > 8) throw new Error("filesystem row needs 1–8 reviewed roots"); |
| 6040 | const roots = config.customSkillDirs.map((path) => normalizeSkillRoot({ path })); |
| 6041 | const seen = /* @__PURE__ */ new Set(); |
| 6042 | for (const { path } of roots) { |
| 6043 | if (seen.has(path)) throw new Error("duplicate filesystem root"); |
| 6044 | seen.add(path); |
| 6045 | } |
| 6046 | for (const { path } of roots) ctx.skills.registerRoot({ path: `source/${path}` }); |
| 6047 | } }; |
| 6048 | } |
| 6049 | var init_skill_filesystem = __esm({ |
| 6050 | "src/dsh/skill-filesystem.ts"() { |
| 6051 | "use strict"; |
| 6052 | init_skills(); |
| 6053 | } |
| 6054 | }); |
| 6055 | |
| 6056 | // src/dsh/canonical-path.ts |
| 6057 | import { realpathSync } from "node:fs"; |
| 6058 | import { posix, win32 } from "node:path"; |
| 6059 | function canonicalPath(path, platform = process.platform) { |
| 6060 | if (platform !== "win32") return realpathSync(path); |
| 6061 | try { |
| 6062 | return stripVerbatim(realpathSync.native(path), platform); |
| 6063 | } catch (error) { |
| 6064 | const code = error && typeof error === "object" && "code" in error ? error.code : void 0; |
| 6065 | if (code === "EPERM" || code === "EACCES") { |
| 6066 | return stripVerbatim(win32.normalize(path), platform); |
| 6067 | } |
| 6068 | throw error; |
| 6069 | } |
| 6070 | } |
| 6071 | function stripVerbatim(path, platform = process.platform) { |
| 6072 | if (platform !== "win32") return path; |
| 6073 | if (/^[\\/]{2}\?[\\/]UNC[\\/]/i.test(path)) return `\\\\${path.slice(8)}`; |
| 6074 | if (/^[\\/]{2}\?[\\/]/.test(path)) return path.slice(4); |
| 6075 | return path; |
| 6076 | } |
| 6077 | function pathKey(path, platform = process.platform) { |
| 6078 | if (platform !== "win32") return posix.normalize(path); |
| 6079 | return win32.normalize(stripVerbatim(path, platform)).toLowerCase(); |
| 6080 | } |
| 6081 | function samePath(a, b, platform = process.platform) { |
| 6082 | return pathKey(a, platform) === pathKey(b, platform); |
| 6083 | } |
| 6084 | function insideKey(root, target, platform = process.platform) { |
| 6085 | const path = platform === "win32" ? win32 : posix; |
| 6086 | const inside = path.relative(stripVerbatim(root, platform), stripVerbatim(target, platform)); |
| 6087 | if (inside === ".." || inside.startsWith(`..${path.sep}`) || path.isAbsolute(inside)) return void 0; |
| 6088 | return platform === "win32" ? inside.split(win32.sep).join("/") : inside; |
| 6089 | } |
| 6090 | function isUnlinkedInside(root, key, target, platform = process.platform) { |
| 6091 | let canonicalRoot, canonicalTarget; |
| 6092 | try { |
| 6093 | canonicalRoot = canonicalPath(root, platform); |
| 6094 | canonicalTarget = canonicalPath(target, platform); |
| 6095 | } catch { |
| 6096 | return false; |
| 6097 | } |
| 6098 | return unlinkedKeyMatches(canonicalRoot, key, canonicalTarget, platform); |
| 6099 | } |
| 6100 | function unlinkedKeyMatches(canonicalRoot, key, canonicalTarget, platform = process.platform) { |
| 6101 | if (!key || key.split("/").some((part) => !part || part === "." || part === "..")) return false; |
| 6102 | const path = platform === "win32" ? win32 : posix; |
| 6103 | return samePath(path.join(stripVerbatim(canonicalRoot, platform), ...key.split("/")), canonicalTarget, platform); |
| 6104 | } |
| 6105 | var init_canonical_path = __esm({ |
| 6106 | "src/dsh/canonical-path.ts"() { |
| 6107 | "use strict"; |
| 6108 | } |
| 6109 | }); |
| 6110 | |
| 6111 | // src/dsh/upstream/hooks/hook-protocol/src/matcher.ts |
| 6112 | function isMatchAll(matcher) { |
| 6113 | return matcher === void 0 || matcher === "" || matcher === "*"; |
| 6114 | } |
| 6115 | function compileRegex(pattern) { |
| 6116 | try { |
| 6117 | return new RegExp(pattern); |
| 6118 | } catch (_syntaxError) { |
| 6119 | return void 0; |
| 6120 | } |
| 6121 | } |
| 6122 | function matcherDiagnostic(matcher, mode) { |
| 6123 | if (isMatchAll(matcher)) return void 0; |
| 6124 | const pattern = matcher; |
| 6125 | if (mode === "claude-code" && CLAUDE_LITERAL.test(pattern)) return void 0; |
| 6126 | return compileRegex(pattern) === void 0 ? `invalid ${mode} regex matcher ${JSON.stringify(pattern)}` : void 0; |
| 6127 | } |
| 6128 | var CLAUDE_LITERAL; |
| 6129 | var init_matcher = __esm({ |
| 6130 | "src/dsh/upstream/hooks/hook-protocol/src/matcher.ts"() { |
| 6131 | "use strict"; |
| 6132 | CLAUDE_LITERAL = /^[A-Za-z0-9_|]+$/; |
| 6133 | } |
| 6134 | }); |
| 6135 | |
| 6136 | // src/dsh/upstream/hooks/hooks-claude-code/src/config.ts |
| 6137 | function asObject(value) { |
| 6138 | return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0; |
| 6139 | } |
| 6140 | function substituteCommand(command, vars) { |
| 6141 | let out = command; |
| 6142 | if (vars.pluginRoot !== void 0) out = out.split("${CLAUDE_PLUGIN_ROOT}").join(vars.pluginRoot); |
| 6143 | if (vars.projectDir !== void 0) out = out.split("${CLAUDE_PROJECT_DIR}").join(vars.projectDir); |
| 6144 | return out; |
| 6145 | } |
| 6146 | function parseClaudeCodeConfig(raw, vars = {}) { |
| 6147 | const config = {}; |
| 6148 | const skipped = []; |
| 6149 | const root = asObject(raw); |
| 6150 | const hooksMap = root ? asObject(root.hooks) ?? root : void 0; |
| 6151 | if (!hooksMap) return { config, skipped }; |
| 6152 | for (const event of CLAUDE_EVENTS) { |
| 6153 | const rawGroups = hooksMap[event]; |
| 6154 | if (!Array.isArray(rawGroups)) continue; |
| 6155 | const groups = []; |
| 6156 | for (const rawGroup of rawGroups) { |
| 6157 | const group = asObject(rawGroup); |
| 6158 | if (!group || !Array.isArray(group.hooks)) continue; |
| 6159 | const commands = []; |
| 6160 | for (const rawHook of group.hooks) { |
| 6161 | const hook = asObject(rawHook); |
| 6162 | if (!hook) continue; |
| 6163 | const type2 = typeof hook.type === "string" ? hook.type : "command"; |
| 6164 | if (type2 !== "command") { |
| 6165 | skipped.push({ event, type: type2 }); |
| 6166 | continue; |
| 6167 | } |
| 6168 | if (typeof hook.command !== "string") continue; |
| 6169 | commands.push({ |
| 6170 | command: substituteCommand(hook.command, vars), |
| 6171 | ...typeof hook.timeout === "number" ? { timeoutSec: hook.timeout } : {} |
| 6172 | }); |
| 6173 | } |
| 6174 | if (commands.length === 0) continue; |
| 6175 | const matcher = event === "UserPromptSubmit" || event === "Stop" ? void 0 : typeof group.matcher === "string" ? group.matcher : void 0; |
| 6176 | const diagnostic = matcherDiagnostic(matcher, "claude-code"); |
| 6177 | if (diagnostic !== void 0) throw new SyntaxError(`${diagnostic} on event ${JSON.stringify(event)}`); |
| 6178 | groups.push({ |
| 6179 | ...matcher !== void 0 ? { matcher } : {}, |
| 6180 | hooks: commands |
| 6181 | }); |
| 6182 | } |
| 6183 | if (groups.length > 0) config[event] = groups; |
| 6184 | } |
| 6185 | return { config, skipped }; |
| 6186 | } |
| 6187 | var CLAUDE_EVENTS; |
| 6188 | var init_config = __esm({ |
| 6189 | "src/dsh/upstream/hooks/hooks-claude-code/src/config.ts"() { |
| 6190 | "use strict"; |
| 6191 | init_matcher(); |
| 6192 | CLAUDE_EVENTS = [ |
| 6193 | "SessionStart", |
| 6194 | "UserPromptSubmit", |
| 6195 | "PreToolUse", |
| 6196 | "PostToolUse", |
| 6197 | "Stop", |
| 6198 | "SubagentStart", |
| 6199 | "SubagentStop" |
| 6200 | ]; |
| 6201 | } |
| 6202 | }); |
| 6203 | |
| 6204 | // src/dsh/upstream/hooks/hooks-codex/src/config.ts |
| 6205 | function asObject2(value) { |
| 6206 | return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0; |
| 6207 | } |
| 6208 | function parseCodexConfig(raw) { |
| 6209 | const config = {}; |
| 6210 | const skipped = []; |
| 6211 | const root = asObject2(raw); |
| 6212 | const hooksMap = root ? asObject2(root.hooks) ?? root : void 0; |
| 6213 | if (!hooksMap) return { config, skipped }; |
| 6214 | for (const event of CODEX_EVENTS) { |
| 6215 | const rawGroups = hooksMap[event]; |
| 6216 | if (!Array.isArray(rawGroups)) continue; |
| 6217 | const groups = []; |
| 6218 | for (const rawGroup of rawGroups) { |
| 6219 | const group = asObject2(rawGroup); |
| 6220 | if (!group || !Array.isArray(group.hooks)) continue; |
| 6221 | const commands = []; |
| 6222 | for (const rawHook of group.hooks) { |
| 6223 | const hook = asObject2(rawHook); |
| 6224 | if (!hook) continue; |
| 6225 | const type2 = typeof hook.type === "string" ? hook.type : "command"; |
| 6226 | if (type2 !== "command") { |
| 6227 | skipped.push({ event, reason: `unsupported "${type2}" hook` }); |
| 6228 | continue; |
| 6229 | } |
| 6230 | if (hook.async === true) { |
| 6231 | skipped.push({ event, reason: "async hook" }); |
| 6232 | continue; |
| 6233 | } |
| 6234 | if (typeof hook.command !== "string") continue; |
| 6235 | const timeout = typeof hook.timeout === "number" ? hook.timeout : typeof hook.timeoutSec === "number" ? hook.timeoutSec : void 0; |
| 6236 | commands.push({ command: hook.command, ...timeout !== void 0 ? { timeoutSec: timeout } : {} }); |
| 6237 | } |
| 6238 | if (commands.length === 0) continue; |
| 6239 | const matcher = event === "UserPromptSubmit" || event === "Stop" ? void 0 : typeof group.matcher === "string" ? group.matcher : void 0; |
| 6240 | const diagnostic = matcherDiagnostic(matcher, "codex"); |
| 6241 | if (diagnostic !== void 0) throw new SyntaxError(`${diagnostic} on event ${JSON.stringify(event)}`); |
| 6242 | groups.push({ ...matcher !== void 0 ? { matcher } : {}, hooks: commands }); |
| 6243 | } |
| 6244 | if (groups.length > 0) config[event] = groups; |
| 6245 | } |
| 6246 | return { config, skipped }; |
| 6247 | } |
| 6248 | var CODEX_EVENTS; |
| 6249 | var init_config2 = __esm({ |
| 6250 | "src/dsh/upstream/hooks/hooks-codex/src/config.ts"() { |
| 6251 | "use strict"; |
| 6252 | init_matcher(); |
| 6253 | CODEX_EVENTS = ["PreToolUse", "PostToolUse", "SessionStart", "UserPromptSubmit", "Stop"]; |
| 6254 | } |
| 6255 | }); |
| 6256 | |
| 6257 | // src/dsh/shell-hooks.ts |
| 6258 | import { createHash } from "node:crypto"; |
| 6259 | import { readFileSync, lstatSync } from "node:fs"; |
| 6260 | import { resolve, relative, isAbsolute, sep } from "node:path"; |
| 6261 | function reviewedHookModule(dialect, root, files) { |
| 6262 | return { name: `hooks-${dialect}`, inject: ["shellHooks"], apply(ctx, config) { |
| 6263 | if (!config || typeof config.configPath !== "string") throw new Error("hook bridge needs its reviewed configPath"); |
| 6264 | const path = resolve(root, config.configPath); |
| 6265 | const inside = relative(root, path).split(sep).join("/"); |
| 6266 | if (!inside || inside.startsWith("../") || isAbsolute(inside) || !files[inside] || !isUnlinkedInside(root, inside, path) || !lstatSync(path).isFile()) throw new Error("hook config is absent from the reviewed regular-file closure"); |
| 6267 | const bytes = readFileSync(path); |
| 6268 | if (bytes.length > 1024 * 1024 || createHash("sha256").update(bytes).digest("hex") !== files[inside]) throw new Error("hook config changed after review or exceeds 1 MiB"); |
| 6269 | if (config.projectDir !== void 0) throw new Error("explicit projectDir is unsupported; each process uses its current core workspace"); |
| 6270 | if (config.pluginRoot !== void 0 && config.pluginRoot !== "." && config.pluginRoot !== root) throw new Error("pluginRoot must be this reviewed bundle root"); |
| 6271 | const raw = JSON.parse(bytes.toString("utf8")); |
| 6272 | const parsed = dialect === "claude-code" ? parseClaudeCodeConfig(raw, { pluginRoot: root }) : parseCodexConfig(raw); |
| 6273 | if (parsed.skipped.length) throw new Error("hook config contains unsupported non-command or asynchronous hooks"); |
| 6274 | let count = 0; |
| 6275 | for (const [point, groups] of Object.entries(parsed.config)) { |
| 6276 | if (point === "Stop") ctx.logger.warn("Stop runs at the core TurnEnd observer; forced continuation is unsupported"); |
| 6277 | for (const group of groups) for (const hook of group.hooks) { |
| 6278 | if (++count > 128) throw new Error("hook bridge exceeds 128 commands"); |
| 6279 | const seconds = hook.timeoutSec ?? (config.defaultTimeoutMs ?? 6e5) / 1e3; |
| 6280 | if (!Number.isSafeInteger(seconds) || seconds < 1 || seconds > 86400) throw new Error("hook timeout must be 1–86400 whole seconds"); |
| 6281 | ctx.shellHooks.register({ dialect, point, ...group.matcher === void 0 ? {} : { matcher: group.matcher }, hook: { event: EVENTS[point], command: hook.command, timeout_secs: seconds, background: false, continue_on_error: false, name: `${dialect}:${point}:${count}` } }); |
| 6282 | } |
| 6283 | } |
| 6284 | if (count === 0) throw new Error("reviewed hook config has no supported command hooks"); |
| 6285 | } }; |
| 6286 | } |
| 6287 | var EVENTS; |
| 6288 | var init_shell_hooks = __esm({ |
| 6289 | "src/dsh/shell-hooks.ts"() { |
| 6290 | "use strict"; |
| 6291 | init_canonical_path(); |
| 6292 | init_canonical_path(); |
| 6293 | init_config(); |
| 6294 | init_config2(); |
| 6295 | EVENTS = { SessionStart: "session_start", UserPromptSubmit: "message_submit", PreToolUse: "tool_call_before", PostToolUse: "tool_call_after", Stop: "turn_end", SubagentStart: "subagent_spawn", SubagentStop: "subagent_complete" }; |
| 6296 | } |
| 6297 | }); |
| 6298 | |
| 6299 | // src/runtime.ts |
| 6300 | import * as nodeModule from "node:module"; |
| 6301 | var require2, RUNTIME; |
| 6302 | var init_runtime = __esm({ |
| 6303 | "src/runtime.ts"() { |
| 6304 | "use strict"; |
| 6305 | require2 = nodeModule.createRequire(import.meta.url); |
| 6306 | RUNTIME = typeof process.versions.bun === "string" ? { name: "bun", version: process.versions.bun } : { name: "node", version: process.versions.node }; |
| 6307 | } |
| 6308 | }); |
| 6309 | |
| 6310 | // node_modules/acorn/dist/acorn.mjs |
| 6311 | function isInAstralSet(code, set2) { |
| 6312 | var pos = 65536; |
| 6313 | for (var i2 = 0; i2 < set2.length; i2 += 2) { |
| 6314 | pos += set2[i2]; |
| 6315 | if (pos > code) { |
| 6316 | return false; |
| 6317 | } |
| 6318 | pos += set2[i2 + 1]; |
| 6319 | if (pos >= code) { |
| 6320 | return true; |
| 6321 | } |
| 6322 | } |
| 6323 | return false; |
| 6324 | } |
| 6325 | function isIdentifierStart(code, astral) { |
| 6326 | if (code < 65) { |
| 6327 | return code === 36; |
| 6328 | } |
| 6329 | if (code < 91) { |
| 6330 | return true; |
| 6331 | } |
| 6332 | if (code < 97) { |
| 6333 | return code === 95; |
| 6334 | } |
| 6335 | if (code < 123) { |
| 6336 | return true; |
| 6337 | } |
| 6338 | if (code <= 65535) { |
| 6339 | return code >= 170 && nonASCIIidentifierStart.test(String.fromCharCode(code)); |
| 6340 | } |
| 6341 | if (astral === false) { |
| 6342 | return false; |
| 6343 | } |
| 6344 | return isInAstralSet(code, astralIdentifierStartCodes); |
| 6345 | } |
| 6346 | function isIdentifierChar(code, astral) { |
| 6347 | if (code < 48) { |
| 6348 | return code === 36; |
| 6349 | } |
| 6350 | if (code < 58) { |
| 6351 | return true; |
| 6352 | } |
| 6353 | if (code < 65) { |
| 6354 | return false; |
| 6355 | } |
| 6356 | if (code < 91) { |
| 6357 | return true; |
| 6358 | } |
| 6359 | if (code < 97) { |
| 6360 | return code === 95; |
| 6361 | } |
| 6362 | if (code < 123) { |
| 6363 | return true; |
| 6364 | } |
| 6365 | if (code <= 65535) { |
| 6366 | return code >= 170 && nonASCIIidentifier.test(String.fromCharCode(code)); |
| 6367 | } |
| 6368 | if (astral === false) { |
| 6369 | return false; |
| 6370 | } |
| 6371 | return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes); |
| 6372 | } |
| 6373 | function binop(name, prec) { |
| 6374 | return new TokenType(name, { beforeExpr: true, binop: prec }); |
| 6375 | } |
| 6376 | function kw(name, options) { |
| 6377 | if (options === void 0) options = {}; |
| 6378 | options.keyword = name; |
| 6379 | return keywords[name] = new TokenType(name, options); |
| 6380 | } |
| 6381 | function isNewLine(code) { |
| 6382 | return code === 10 || code === 13 || code === 8232 || code === 8233; |
| 6383 | } |
| 6384 | function nextLineBreak(code, from, end) { |
| 6385 | if (end === void 0) end = code.length; |
| 6386 | for (var i2 = from; i2 < end; i2++) { |
| 6387 | var next = code.charCodeAt(i2); |
| 6388 | if (isNewLine(next)) { |
| 6389 | return i2 < end - 1 && next === 13 && code.charCodeAt(i2 + 1) === 10 ? i2 + 2 : i2 + 1; |
| 6390 | } |
| 6391 | } |
| 6392 | return -1; |
| 6393 | } |
| 6394 | function wordsRegexp(words) { |
| 6395 | return regexpCache[words] || (regexpCache[words] = new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")); |
| 6396 | } |
| 6397 | function codePointToString(code) { |
| 6398 | if (code <= 65535) { |
| 6399 | return String.fromCharCode(code); |
| 6400 | } |
| 6401 | code -= 65536; |
| 6402 | return String.fromCharCode((code >> 10) + 55296, (code & 1023) + 56320); |
| 6403 | } |
| 6404 | function getLineInfo(input, offset2) { |
| 6405 | for (var line = 1, cur = 0; ; ) { |
| 6406 | var nextBreak = nextLineBreak(input, cur, offset2); |
| 6407 | if (nextBreak < 0) { |
| 6408 | return new Position(line, offset2 - cur); |
| 6409 | } |
| 6410 | ++line; |
| 6411 | cur = nextBreak; |
| 6412 | } |
| 6413 | } |
| 6414 | function getOptions(opts) { |
| 6415 | var options = {}; |
| 6416 | for (var opt in defaultOptions) { |
| 6417 | options[opt] = opts && hasOwn(opts, opt) ? opts[opt] : defaultOptions[opt]; |
| 6418 | } |
| 6419 | if (options.ecmaVersion === "latest") { |
| 6420 | options.ecmaVersion = 1e8; |
| 6421 | } else if (options.ecmaVersion == null) { |
| 6422 | if (!warnedAboutEcmaVersion && typeof console === "object" && console.warn) { |
| 6423 | warnedAboutEcmaVersion = true; |
| 6424 | console.warn("Since Acorn 8.0.0, options.ecmaVersion is required.\nDefaulting to 2020, but this will stop working in the future."); |
| 6425 | } |
| 6426 | options.ecmaVersion = 11; |
| 6427 | } else if (options.ecmaVersion >= 2015) { |
| 6428 | options.ecmaVersion -= 2009; |
| 6429 | } |
| 6430 | if (options.allowReserved == null) { |
| 6431 | options.allowReserved = options.ecmaVersion < 5; |
| 6432 | } |
| 6433 | if (!opts || opts.allowHashBang == null) { |
| 6434 | options.allowHashBang = options.ecmaVersion >= 14; |
| 6435 | } |
| 6436 | if (isArray(options.onToken)) { |
| 6437 | var tokens = options.onToken; |
| 6438 | options.onToken = function(token) { |
| 6439 | return tokens.push(token); |
| 6440 | }; |
| 6441 | } |
| 6442 | if (isArray(options.onComment)) { |
| 6443 | options.onComment = pushComment(options, options.onComment); |
| 6444 | } |
| 6445 | if (options.sourceType === "commonjs" && options.allowAwaitOutsideFunction) { |
| 6446 | throw new Error("Cannot use allowAwaitOutsideFunction with sourceType: commonjs"); |
| 6447 | } |
| 6448 | return options; |
| 6449 | } |
| 6450 | function pushComment(options, array) { |
| 6451 | return function(block, text2, start, end, startLoc, endLoc) { |
| 6452 | var comment = { |
| 6453 | type: block ? "Block" : "Line", |
| 6454 | value: text2, |
| 6455 | start, |
| 6456 | end |
| 6457 | }; |
| 6458 | if (options.locations) { |
| 6459 | comment.loc = new SourceLocation(this, startLoc, endLoc); |
| 6460 | } |
| 6461 | if (options.ranges) { |
| 6462 | comment.range = [start, end]; |
| 6463 | } |
| 6464 | array.push(comment); |
| 6465 | }; |
| 6466 | } |
| 6467 | function functionFlags(async, generator) { |
| 6468 | return SCOPE_FUNCTION | (async ? SCOPE_ASYNC : 0) | (generator ? SCOPE_GENERATOR : 0); |
| 6469 | } |
| 6470 | function isPrivateNameConflicted(privateNameMap, element) { |
| 6471 | var name = element.key.name; |
| 6472 | var curr = privateNameMap[name]; |
| 6473 | var next = "true"; |
| 6474 | if (element.type === "MethodDefinition" && (element.kind === "get" || element.kind === "set")) { |
| 6475 | next = (element.static ? "s" : "i") + element.kind; |
| 6476 | } |
| 6477 | if (curr === "iget" && next === "iset" || curr === "iset" && next === "iget" || curr === "sget" && next === "sset" || curr === "sset" && next === "sget") { |
| 6478 | privateNameMap[name] = "true"; |
| 6479 | return false; |
| 6480 | } else if (!curr) { |
| 6481 | privateNameMap[name] = next; |
| 6482 | return false; |
| 6483 | } else { |
| 6484 | return true; |
| 6485 | } |
| 6486 | } |
| 6487 | function checkKeyName(node, name) { |
| 6488 | var computed = node.computed; |
| 6489 | var key = node.key; |
| 6490 | return !computed && (key.type === "Identifier" && key.name === name || key.type === "Literal" && key.value === name); |
| 6491 | } |
| 6492 | function isLocalVariableAccess(node) { |
| 6493 | return node.type === "Identifier" || node.type === "ParenthesizedExpression" && isLocalVariableAccess(node.expression); |
| 6494 | } |
| 6495 | function isPrivateFieldAccess(node) { |
| 6496 | return node.type === "MemberExpression" && node.property.type === "PrivateIdentifier" || node.type === "ChainExpression" && isPrivateFieldAccess(node.expression) || node.type === "ParenthesizedExpression" && isPrivateFieldAccess(node.expression); |
| 6497 | } |
| 6498 | function finishNodeAt(node, type2, pos, loc) { |
| 6499 | node.type = type2; |
| 6500 | node.end = pos; |
| 6501 | if (this.options.locations) { |
| 6502 | node.loc.end = loc; |
| 6503 | } |
| 6504 | if (this.options.ranges) { |
| 6505 | node.range[1] = pos; |
| 6506 | } |
| 6507 | return node; |
| 6508 | } |
| 6509 | function buildUnicodeData(ecmaVersion2) { |
| 6510 | var d = data[ecmaVersion2] = { |
| 6511 | binary: wordsRegexp(unicodeBinaryProperties[ecmaVersion2] + " " + unicodeGeneralCategoryValues), |
| 6512 | binaryOfStrings: wordsRegexp(unicodeBinaryPropertiesOfStrings[ecmaVersion2]), |
| 6513 | nonBinary: { |
| 6514 | General_Category: wordsRegexp(unicodeGeneralCategoryValues), |
| 6515 | Script: wordsRegexp(unicodeScriptValues[ecmaVersion2]) |
| 6516 | } |
| 6517 | }; |
| 6518 | d.nonBinary.Script_Extensions = d.nonBinary.Script; |
| 6519 | d.nonBinary.gc = d.nonBinary.General_Category; |
| 6520 | d.nonBinary.sc = d.nonBinary.Script; |
| 6521 | d.nonBinary.scx = d.nonBinary.Script_Extensions; |
| 6522 | } |
| 6523 | function hasProp(obj) { |
| 6524 | for (var _ in obj) { |
| 6525 | return true; |
| 6526 | } |
| 6527 | return false; |
| 6528 | } |
| 6529 | function isRegularExpressionModifier(ch) { |
| 6530 | return ch === 105 || ch === 109 || ch === 115; |
| 6531 | } |
| 6532 | function isSyntaxCharacter(ch) { |
| 6533 | return ch === 36 || ch >= 40 && ch <= 43 || ch === 46 || ch === 63 || ch >= 91 && ch <= 94 || ch >= 123 && ch <= 125; |
| 6534 | } |
| 6535 | function isRegExpIdentifierStart(ch) { |
| 6536 | return isIdentifierStart(ch, true) || ch === 36 || ch === 95; |
| 6537 | } |
| 6538 | function isRegExpIdentifierPart(ch) { |
| 6539 | return isIdentifierChar(ch, true) || ch === 36 || ch === 95 || ch === 8204 || ch === 8205; |
| 6540 | } |
| 6541 | function isControlLetter(ch) { |
| 6542 | return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122; |
| 6543 | } |
| 6544 | function isValidUnicode(ch) { |
| 6545 | return ch >= 0 && ch <= 1114111; |
| 6546 | } |
| 6547 | function isCharacterClassEscape(ch) { |
| 6548 | return ch === 100 || ch === 68 || ch === 115 || ch === 83 || ch === 119 || ch === 87; |
| 6549 | } |
| 6550 | function isUnicodePropertyNameCharacter(ch) { |
| 6551 | return isControlLetter(ch) || ch === 95; |
| 6552 | } |
| 6553 | function isUnicodePropertyValueCharacter(ch) { |
| 6554 | return isUnicodePropertyNameCharacter(ch) || isDecimalDigit(ch); |
| 6555 | } |
| 6556 | function isClassSetReservedDoublePunctuatorCharacter(ch) { |
| 6557 | return ch === 33 || ch >= 35 && ch <= 38 || ch >= 42 && ch <= 44 || ch === 46 || ch >= 58 && ch <= 64 || ch === 94 || ch === 96 || ch === 126; |
| 6558 | } |
| 6559 | function isClassSetSyntaxCharacter(ch) { |
| 6560 | return ch === 40 || ch === 41 || ch === 45 || ch === 47 || ch >= 91 && ch <= 93 || ch >= 123 && ch <= 125; |
| 6561 | } |
| 6562 | function isClassSetReservedPunctuator(ch) { |
| 6563 | return ch === 33 || ch === 35 || ch === 37 || ch === 38 || ch === 44 || ch === 45 || ch >= 58 && ch <= 62 || ch === 64 || ch === 96 || ch === 126; |
| 6564 | } |
| 6565 | function isDecimalDigit(ch) { |
| 6566 | return ch >= 48 && ch <= 57; |
| 6567 | } |
| 6568 | function isHexDigit(ch) { |
| 6569 | return ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102; |
| 6570 | } |
| 6571 | function hexToInt(ch) { |
| 6572 | if (ch >= 65 && ch <= 70) { |
| 6573 | return 10 + (ch - 65); |
| 6574 | } |
| 6575 | if (ch >= 97 && ch <= 102) { |
| 6576 | return 10 + (ch - 97); |
| 6577 | } |
| 6578 | return ch - 48; |
| 6579 | } |
| 6580 | function isOctalDigit(ch) { |
| 6581 | return ch >= 48 && ch <= 55; |
| 6582 | } |
| 6583 | function stringToNumber(str2, isLegacyOctalNumericLiteral) { |
| 6584 | if (isLegacyOctalNumericLiteral) { |
| 6585 | return parseInt(str2, 8); |
| 6586 | } |
| 6587 | return parseFloat(str2.replace(/_/g, "")); |
| 6588 | } |
| 6589 | function stringToBigInt(str2) { |
| 6590 | if (typeof BigInt !== "function") { |
| 6591 | return null; |
| 6592 | } |
| 6593 | return BigInt(str2.replace(/_/g, "")); |
| 6594 | } |
| 6595 | var astralIdentifierCodes, astralIdentifierStartCodes, nonASCIIidentifierChars, nonASCIIidentifierStartChars, reservedWords, ecma5AndLessKeywords, keywords$1, keywordRelationalOperator, nonASCIIidentifierStart, nonASCIIidentifier, TokenType, beforeExpr, startsExpr, keywords, types$1, lineBreak, lineBreakG, nonASCIIwhitespace, skipWhiteSpace, ref, hasOwnProperty, toString, hasOwn, isArray, regexpCache, loneSurrogate, Position, SourceLocation, defaultOptions, warnedAboutEcmaVersion, SCOPE_TOP, SCOPE_FUNCTION, SCOPE_ASYNC, SCOPE_GENERATOR, SCOPE_ARROW, SCOPE_SIMPLE_CATCH, SCOPE_SUPER, SCOPE_DIRECT_SUPER, SCOPE_CLASS_STATIC_BLOCK, SCOPE_CLASS_FIELD_INIT, SCOPE_SWITCH, SCOPE_VAR, BIND_NONE, BIND_VAR, BIND_LEXICAL, BIND_FUNCTION, BIND_SIMPLE_CATCH, BIND_OUTSIDE, Parser, prototypeAccessors, pp$9, literal, DestructuringErrors, pp$8, loopLabel, switchLabel, empty$1, FUNC_STATEMENT, FUNC_HANGING_STATEMENT, FUNC_NULLABLE_ID, pp$7, TokContext, types2, pp$6, pp$5, empty, pp$4, pp$3, Scope, Node, pp$2, scriptValuesAddedInUnicode, ecma9BinaryProperties, ecma10BinaryProperties, ecma11BinaryProperties, ecma12BinaryProperties, ecma13BinaryProperties, ecma14BinaryProperties, unicodeBinaryProperties, ecma14BinaryPropertiesOfStrings, unicodeBinaryPropertiesOfStrings, unicodeGeneralCategoryValues, ecma9ScriptValues, ecma10ScriptValues, ecma11ScriptValues, ecma12ScriptValues, ecma13ScriptValues, ecma14ScriptValues, unicodeScriptValues, data, ecmaVersion, i, list, pp$1, BranchID, RegExpValidationState, CharSetNone, CharSetOk, CharSetString, Token, pp, INVALID_TEMPLATE_ESCAPE_ERROR, version; |
| 6596 | var init_acorn = __esm({ |
| 6597 | "node_modules/acorn/dist/acorn.mjs"() { |
| 6598 | astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 7, 9, 32, 4, 318, 1, 78, 5, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 68, 8, 2, 0, 3, 0, 2, 3, 2, 4, 2, 0, 15, 1, 83, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 7, 19, 58, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 199, 7, 137, 9, 54, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 55, 9, 266, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 10, 5350, 0, 7, 14, 11465, 27, 2343, 9, 87, 9, 39, 4, 60, 6, 26, 9, 535, 9, 470, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4178, 9, 519, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 245, 1, 2, 9, 233, 0, 3, 0, 8, 1, 6, 0, 475, 6, 110, 6, 6, 9, 4759, 9, 787719, 239]; |
| 6599 | astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 4, 51, 13, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 7, 25, 39, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 39, 27, 10, 22, 251, 41, 7, 1, 17, 5, 57, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 31, 9, 2, 0, 3, 0, 2, 37, 2, 0, 26, 0, 2, 0, 45, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 200, 32, 32, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 24, 43, 261, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 26, 3994, 6, 582, 6842, 29, 1763, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 433, 44, 212, 63, 33, 24, 3, 24, 45, 74, 6, 0, 67, 12, 65, 1, 2, 0, 15, 4, 10, 7381, 42, 31, 98, 114, 8702, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 229, 29, 3, 0, 208, 30, 2, 2, 2, 1, 2, 6, 3, 4, 10, 1, 225, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4381, 3, 5773, 3, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 8489]; |
| 6600 | nonASCIIidentifierChars = "·̀-ͯ·҃-֑҇-ׇֽֿׁׂׅׄؐ-ًؚ-٩ٰۖ-ۜ۟-۪ۤۧۨ-ۭ۰-۹ܑܰ-݊ަ-ް߀-߉߫-߽߳ࠖ-࠙ࠛ-ࠣࠥ-ࠧࠩ-࡙࠭-࡛-࢟࣊-ࣣ࣡-ःऺ-़ा-ॏ॑-ॗॢॣ०-९ঁ-ঃ়া-ৄেৈো-্ৗৢৣ০-৯৾ਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑ੦-ੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢૣ૦-૯ૺ-૿ଁ-ଃ଼ା-ୄେୈୋ-୍୕-ୗୢୣ୦-୯ஂா-ூெ-ைொ-்ௗ௦-௯ఀ-ఄ఼ా-ౄె-ైొ-్ౕౖౢౣ౦-౯ಁ-ಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢೣ೦-೯ೳഀ-ഃ഻഼ാ-ൄെ-ൈൊ-്ൗൢൣ൦-൯ඁ-ඃ්ා-ුූෘ-ෟ෦-෯ෲෳัิ-ฺ็-๎๐-๙ັິ-ຼ່-໎໐-໙༘༙༠-༩༹༵༷༾༿ཱ-྄྆྇ྍ-ྗྙ-ྼ࿆ါ-ှ၀-၉ၖ-ၙၞ-ၠၢ-ၤၧ-ၭၱ-ၴႂ-ႍႏ-ႝ፝-፟፩-፱ᜒ-᜕ᜲ-᜴ᝒᝓᝲᝳ឴-៓៝០-៩᠋-᠍᠏-᠙ᢩᤠ-ᤫᤰ-᤻᥆-᥏᧐-᧚ᨗ-ᨛᩕ-ᩞ᩠-᩿᩼-᪉᪐-᪙᪰-᪽ᪿ--ᬀ-ᬄ᬴-᭄᭐-᭙᭫-᭳ᮀ-ᮂᮡ-ᮭ᮰-᮹᯦-᯳ᰤ-᰷᱀-᱉᱐-᱙᳐-᳔᳒-᳨᳭᳴᳷-᳹᷀-᷿‿⁀⁔⃐-⃥⃜⃡-⃰⳯-⵿⳱ⷠ-〪ⷿ-゙゚〯・꘠-꘩꙯ꙴ-꙽ꚞꚟ꛰꛱ꠂ꠆ꠋꠣ-ꠧ꠬ꢀꢁꢴ-ꣅ꣐-꣙꣠-꣱ꣿ-꤉ꤦ-꤭ꥇ-꥓ꦀ-ꦃ꦳-꧀꧐-꧙ꧥ꧰-꧹ꨩ-ꨶꩃꩌꩍ꩐-꩙ꩻ-ꩽꪰꪲ-ꪴꪷꪸꪾ꪿꫁ꫫ-ꫯꫵ꫶ꯣ-ꯪ꯬꯭꯰-꯹ﬞ︀-️︠-︯︳︴﹍-﹏0-9_・"; |
| 6601 | nonASCIIidentifierStartChars = "ªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽͿΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԯԱ-Ֆՙՠ-ֈא-תׯ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࡠ-ࡪࡰ-ࢇࢉ-ࢠ-ࣉऄ-हऽॐक़-ॡॱ-ঀঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱৼਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡૹଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-హఽౘ-ౚౝౠౡಀಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽ-ೞೠೡೱೲഄ-ഌഎ-ഐഒ-ഺഽൎൔ-ൖൟ-ൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄຆ-ຊຌ-ຣລວ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏽᏸ-ᏽᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᛮ-ᛸᜀ-ᜑᜟ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡸᢀ-ᢨᢪᢰ-ᣵᤀ-ᤞᥐ-ᥭᥰ-ᥴᦀ-ᦫᦰ-ᧉᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭌᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᲀ-Ა-ᲺᲽ-Ჿᳩ-ᳬᳮ-ᳳᳵᳶᳺᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕ℘-ℝℤΩℨK-ℹℼ-ℿⅅ-ⅉⅎⅠ-ↈⰀ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞ々-〇〡-〩〱-〵〸-〼ぁ-ゖ゛-ゟァ-ヺー-ヿㄅ-ㄯㄱ-ㆎㆠ-ㆿㇰ-ㇿ㐀-䶿一-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚝꚠ-ꛯꜗ-ꜟꜢ-ꞈꞋ--ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꣽꣾꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꧠ-ꧤꧦ-ꧯꧺ-ꧾꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꩾ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꬰ-ꭚꭜ-ꭩꭰ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ff-stﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA-Za-zヲ-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ"; |
| 6602 | reservedWords = { |
| 6603 | 3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile", |
| 6604 | 5: "class enum extends super const export import", |
| 6605 | 6: "enum", |
| 6606 | strict: "implements interface let package private protected public static yield", |
| 6607 | strictBind: "eval arguments" |
| 6608 | }; |
| 6609 | ecma5AndLessKeywords = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this"; |
| 6610 | keywords$1 = { |
| 6611 | 5: ecma5AndLessKeywords, |
| 6612 | "5module": ecma5AndLessKeywords + " export import", |
| 6613 | 6: ecma5AndLessKeywords + " const class extends export import super" |
| 6614 | }; |
| 6615 | keywordRelationalOperator = /^in(stanceof)?$/; |
| 6616 | nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]"); |
| 6617 | nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]"); |
| 6618 | TokenType = function TokenType2(label, conf) { |
| 6619 | if (conf === void 0) conf = {}; |
| 6620 | this.label = label; |
| 6621 | this.keyword = conf.keyword; |
| 6622 | this.beforeExpr = !!conf.beforeExpr; |
| 6623 | this.startsExpr = !!conf.startsExpr; |
| 6624 | this.isLoop = !!conf.isLoop; |
| 6625 | this.isAssign = !!conf.isAssign; |
| 6626 | this.prefix = !!conf.prefix; |
| 6627 | this.postfix = !!conf.postfix; |
| 6628 | this.binop = conf.binop || null; |
| 6629 | this.updateContext = null; |
| 6630 | }; |
| 6631 | beforeExpr = { beforeExpr: true }; |
| 6632 | startsExpr = { startsExpr: true }; |
| 6633 | keywords = {}; |
| 6634 | types$1 = { |
| 6635 | num: new TokenType("num", startsExpr), |
| 6636 | regexp: new TokenType("regexp", startsExpr), |
| 6637 | string: new TokenType("string", startsExpr), |
| 6638 | name: new TokenType("name", startsExpr), |
| 6639 | privateId: new TokenType("privateId", startsExpr), |
| 6640 | eof: new TokenType("eof"), |
| 6641 | // Punctuation token types. |
| 6642 | bracketL: new TokenType("[", { beforeExpr: true, startsExpr: true }), |
| 6643 | bracketR: new TokenType("]"), |
| 6644 | braceL: new TokenType("{", { beforeExpr: true, startsExpr: true }), |
| 6645 | braceR: new TokenType("}"), |
| 6646 | parenL: new TokenType("(", { beforeExpr: true, startsExpr: true }), |
| 6647 | parenR: new TokenType(")"), |
| 6648 | comma: new TokenType(",", beforeExpr), |
| 6649 | semi: new TokenType(";", beforeExpr), |
| 6650 | colon: new TokenType(":", beforeExpr), |
| 6651 | dot: new TokenType("."), |
| 6652 | question: new TokenType("?", beforeExpr), |
| 6653 | questionDot: new TokenType("?."), |
| 6654 | arrow: new TokenType("=>", beforeExpr), |
| 6655 | template: new TokenType("template"), |
| 6656 | invalidTemplate: new TokenType("invalidTemplate"), |
| 6657 | ellipsis: new TokenType("...", beforeExpr), |
| 6658 | backQuote: new TokenType("`", startsExpr), |
| 6659 | dollarBraceL: new TokenType("${", { beforeExpr: true, startsExpr: true }), |
| 6660 | // Operators. These carry several kinds of properties to help the |
| 6661 | // parser use them properly (the presence of these properties is |
| 6662 | // what categorizes them as operators). |
| 6663 | // |
| 6664 | // `binop`, when present, specifies that this operator is a binary |
| 6665 | // operator, and will refer to its precedence. |
| 6666 | // |
| 6667 | // `prefix` and `postfix` mark the operator as a prefix or postfix |
| 6668 | // unary operator. |
| 6669 | // |
| 6670 | // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as |
| 6671 | // binary operators with a very low precedence, that should result |
| 6672 | // in AssignmentExpression nodes. |
| 6673 | eq: new TokenType("=", { beforeExpr: true, isAssign: true }), |
| 6674 | assign: new TokenType("_=", { beforeExpr: true, isAssign: true }), |
| 6675 | incDec: new TokenType("++/--", { prefix: true, postfix: true, startsExpr: true }), |
| 6676 | prefix: new TokenType("!/~", { beforeExpr: true, prefix: true, startsExpr: true }), |
| 6677 | logicalOR: binop("||", 1), |
| 6678 | logicalAND: binop("&&", 2), |
| 6679 | bitwiseOR: binop("|", 3), |
| 6680 | bitwiseXOR: binop("^", 4), |
| 6681 | bitwiseAND: binop("&", 5), |
| 6682 | equality: binop("==/!=/===/!==", 6), |
| 6683 | relational: binop("</>/<=/>=", 7), |
| 6684 | bitShift: binop("<</>>/>>>", 8), |
| 6685 | plusMin: new TokenType("+/-", { beforeExpr: true, binop: 9, prefix: true, startsExpr: true }), |
| 6686 | modulo: binop("%", 10), |
| 6687 | star: binop("*", 10), |
| 6688 | slash: binop("/", 10), |
| 6689 | starstar: new TokenType("**", { beforeExpr: true }), |
| 6690 | coalesce: binop("??", 1), |
| 6691 | // Keyword token types. |
| 6692 | _break: kw("break"), |
| 6693 | _case: kw("case", beforeExpr), |
| 6694 | _catch: kw("catch"), |
| 6695 | _continue: kw("continue"), |
| 6696 | _debugger: kw("debugger"), |
| 6697 | _default: kw("default", beforeExpr), |
| 6698 | _do: kw("do", { isLoop: true, beforeExpr: true }), |
| 6699 | _else: kw("else", beforeExpr), |
| 6700 | _finally: kw("finally"), |
| 6701 | _for: kw("for", { isLoop: true }), |
| 6702 | _function: kw("function", startsExpr), |
| 6703 | _if: kw("if"), |
| 6704 | _return: kw("return", beforeExpr), |
| 6705 | _switch: kw("switch"), |
| 6706 | _throw: kw("throw", beforeExpr), |
| 6707 | _try: kw("try"), |
| 6708 | _var: kw("var"), |
| 6709 | _const: kw("const"), |
| 6710 | _while: kw("while", { isLoop: true }), |
| 6711 | _with: kw("with"), |
| 6712 | _new: kw("new", { beforeExpr: true, startsExpr: true }), |
| 6713 | _this: kw("this", startsExpr), |
| 6714 | _super: kw("super", startsExpr), |
| 6715 | _class: kw("class", startsExpr), |
| 6716 | _extends: kw("extends", beforeExpr), |
| 6717 | _export: kw("export"), |
| 6718 | _import: kw("import", startsExpr), |
| 6719 | _null: kw("null", startsExpr), |
| 6720 | _true: kw("true", startsExpr), |
| 6721 | _false: kw("false", startsExpr), |
| 6722 | _in: kw("in", { beforeExpr: true, binop: 7 }), |
| 6723 | _instanceof: kw("instanceof", { beforeExpr: true, binop: 7 }), |
| 6724 | _typeof: kw("typeof", { beforeExpr: true, prefix: true, startsExpr: true }), |
| 6725 | _void: kw("void", { beforeExpr: true, prefix: true, startsExpr: true }), |
| 6726 | _delete: kw("delete", { beforeExpr: true, prefix: true, startsExpr: true }) |
| 6727 | }; |
| 6728 | lineBreak = /\r\n?|\n|\u2028|\u2029/; |
| 6729 | lineBreakG = new RegExp(lineBreak.source, "g"); |
| 6730 | nonASCIIwhitespace = /[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/; |
| 6731 | skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g; |
| 6732 | ref = Object.prototype; |
| 6733 | hasOwnProperty = ref.hasOwnProperty; |
| 6734 | toString = ref.toString; |
| 6735 | hasOwn = Object.hasOwn || (function(obj, propName) { |
| 6736 | return hasOwnProperty.call(obj, propName); |
| 6737 | }); |
| 6738 | isArray = Array.isArray || (function(obj) { |
| 6739 | return toString.call(obj) === "[object Array]"; |
| 6740 | }); |
| 6741 | regexpCache = /* @__PURE__ */ Object.create(null); |
| 6742 | loneSurrogate = /(?:[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/; |
| 6743 | Position = function Position2(line, col) { |
| 6744 | this.line = line; |
| 6745 | this.column = col; |
| 6746 | }; |
| 6747 | Position.prototype.offset = function offset(n) { |
| 6748 | return new Position(this.line, this.column + n); |
| 6749 | }; |
| 6750 | SourceLocation = function SourceLocation2(p, start, end) { |
| 6751 | this.start = start; |
| 6752 | this.end = end; |
| 6753 | if (p.sourceFile !== null) { |
| 6754 | this.source = p.sourceFile; |
| 6755 | } |
| 6756 | }; |
| 6757 | defaultOptions = { |
| 6758 | // `ecmaVersion` indicates the ECMAScript version to parse. Must be |
| 6759 | // either 3, 5, 6 (or 2015), 7 (2016), 8 (2017), 9 (2018), 10 |
| 6760 | // (2019), 11 (2020), 12 (2021), 13 (2022), 14 (2023), or `"latest"` |
| 6761 | // (the latest version the library supports). This influences |
| 6762 | // support for strict mode, the set of reserved words, and support |
| 6763 | // for new syntax features. |
| 6764 | ecmaVersion: null, |
| 6765 | // `sourceType` indicates the mode the code should be parsed in. |
| 6766 | // Can be either `"script"`, `"module"` or `"commonjs"`. This influences global |
| 6767 | // strict mode and parsing of `import` and `export` declarations. |
| 6768 | sourceType: "script", |
| 6769 | // When set to true, enable strict parsing mode even if `sourceType` |
| 6770 | // is `"script"`. |
| 6771 | strict: false, |
| 6772 | // `onInsertedSemicolon` can be a callback that will be called when |
| 6773 | // a semicolon is automatically inserted. It will be passed the |
| 6774 | // position of the inserted semicolon as an offset, and if |
| 6775 | // `locations` is enabled, it is given the location as a `{line, |
| 6776 | // column}` object as second argument. |
| 6777 | onInsertedSemicolon: null, |
| 6778 | // `onTrailingComma` is similar to `onInsertedSemicolon`, but for |
| 6779 | // trailing commas. |
| 6780 | onTrailingComma: null, |
| 6781 | // By default, reserved words are only enforced if ecmaVersion >= 5. |
| 6782 | // Set `allowReserved` to a boolean value to explicitly turn this on |
| 6783 | // an off. When this option has the value "never", reserved words |
| 6784 | // and keywords can also not be used as property names. |
| 6785 | allowReserved: null, |
| 6786 | // When enabled, a return at the top level is not considered an |
| 6787 | // error. |
| 6788 | allowReturnOutsideFunction: false, |
| 6789 | // When enabled, import/export statements are not constrained to |
| 6790 | // appearing at the top of the program, and an import.meta expression |
| 6791 | // in a script isn't considered an error. |
| 6792 | allowImportExportEverywhere: false, |
| 6793 | // By default, await identifiers are allowed to appear at the top-level scope only if ecmaVersion >= 2022. |
| 6794 | // When enabled, await identifiers are allowed to appear at the top-level scope, |
| 6795 | // but they are still not allowed in non-async functions. |
| 6796 | allowAwaitOutsideFunction: null, |
| 6797 | // When enabled, super identifiers are not constrained to |
| 6798 | // appearing in methods and do not raise an error when they appear elsewhere. |
| 6799 | allowSuperOutsideMethod: null, |
| 6800 | // When enabled, hashbang directive in the beginning of file is |
| 6801 | // allowed and treated as a line comment. Enabled by default when |
| 6802 | // `ecmaVersion` >= 2023. |
| 6803 | allowHashBang: false, |
| 6804 | // By default, the parser will verify that private properties are |
| 6805 | // only used in places where they are valid and have been declared. |
| 6806 | // Set this to false to turn such checks off. |
| 6807 | checkPrivateFields: true, |
| 6808 | // When `locations` is on, `loc` properties holding objects with |
| 6809 | // `start` and `end` properties in `{line, column}` form (with |
| 6810 | // line being 1-based and column 0-based) will be attached to the |
| 6811 | // nodes. |
| 6812 | locations: false, |
| 6813 | // Pass an optional `{line, column}` object to use for the start of |
| 6814 | // the parse. This is mostly useful when using `parseExpressionAt` |
| 6815 | // with `locations: true`, to prevent the parser from having to |
| 6816 | // determine the line position at the start position. |
| 6817 | startLocation: null, |
| 6818 | // A function can be passed as `onToken` option, which will |
| 6819 | // cause Acorn to call that function with object in the same |
| 6820 | // format as tokens returned from `tokenizer().getToken()`. Note |
| 6821 | // that you are not allowed to call the parser from the |
| 6822 | // callback—that will corrupt its internal state. |
| 6823 | onToken: null, |
| 6824 | // A function can be passed as `onComment` option, which will |
| 6825 | // cause Acorn to call that function with `(block, text, start, |
| 6826 | // end)` parameters whenever a comment is skipped. `block` is a |
| 6827 | // boolean indicating whether this is a block (`/* */`) comment, |
| 6828 | // `text` is the content of the comment, and `start` and `end` are |
| 6829 | // character offsets that denote the start and end of the comment. |
| 6830 | // When the `locations` option is on, two more parameters are |
| 6831 | // passed, the full `{line, column}` locations of the start and |
| 6832 | // end of the comments. Note that you are not allowed to call the |
| 6833 | // parser from the callback—that will corrupt its internal state. |
| 6834 | // When this option has an array as value, objects representing the |
| 6835 | // comments are pushed to it. |
| 6836 | onComment: null, |
| 6837 | // Nodes have their start and end characters offsets recorded in |
| 6838 | // `start` and `end` properties (directly on the node, rather than |
| 6839 | // the `loc` object, which holds line/column data. To also add a |
| 6840 | // [semi-standardized][range] `range` property holding a `[start, |
| 6841 | // end]` array with the same numbers, set the `ranges` option to |
| 6842 | // `true`. |
| 6843 | // |
| 6844 | // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678 |
| 6845 | ranges: false, |
| 6846 | // It is possible to parse multiple files into a single AST by |
| 6847 | // passing the tree produced by parsing the first file as |
| 6848 | // `program` option in subsequent parses. This will add the |
| 6849 | // toplevel forms of the parsed file to the `Program` (top) node |
| 6850 | // of an existing parse tree. |
| 6851 | program: null, |
| 6852 | // When `locations` is on, you can pass this to record the source |
| 6853 | // file in every node's `loc` object. |
| 6854 | sourceFile: null, |
| 6855 | // This value, if given, is stored in every node, whether |
| 6856 | // `locations` is on or off. |
| 6857 | directSourceFile: null, |
| 6858 | // When enabled, parenthesized expressions are represented by |
| 6859 | // (non-standard) ParenthesizedExpression nodes |
| 6860 | preserveParens: false |
| 6861 | }; |
| 6862 | warnedAboutEcmaVersion = false; |
| 6863 | SCOPE_TOP = 1; |
| 6864 | SCOPE_FUNCTION = 2; |
| 6865 | SCOPE_ASYNC = 4; |
| 6866 | SCOPE_GENERATOR = 8; |
| 6867 | SCOPE_ARROW = 16; |
| 6868 | SCOPE_SIMPLE_CATCH = 32; |
| 6869 | SCOPE_SUPER = 64; |
| 6870 | SCOPE_DIRECT_SUPER = 128; |
| 6871 | SCOPE_CLASS_STATIC_BLOCK = 256; |
| 6872 | SCOPE_CLASS_FIELD_INIT = 512; |
| 6873 | SCOPE_SWITCH = 1024; |
| 6874 | SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK; |
| 6875 | BIND_NONE = 0; |
| 6876 | BIND_VAR = 1; |
| 6877 | BIND_LEXICAL = 2; |
| 6878 | BIND_FUNCTION = 3; |
| 6879 | BIND_SIMPLE_CATCH = 4; |
| 6880 | BIND_OUTSIDE = 5; |
| 6881 | Parser = function Parser2(options, input, startPos) { |
| 6882 | this.options = options = getOptions(options); |
| 6883 | this.sourceFile = options.sourceFile; |
| 6884 | this.keywords = wordsRegexp(keywords$1[options.ecmaVersion >= 6 ? 6 : options.sourceType === "module" ? "5module" : 5]); |
| 6885 | var reserved = ""; |
| 6886 | if (options.allowReserved !== true) { |
| 6887 | reserved = reservedWords[options.ecmaVersion >= 6 ? 6 : options.ecmaVersion === 5 ? 5 : 3]; |
| 6888 | if (options.sourceType === "module") { |
| 6889 | reserved += " await"; |
| 6890 | } |
| 6891 | } |
| 6892 | this.reservedWords = wordsRegexp(reserved); |
| 6893 | var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict; |
| 6894 | this.reservedWordsStrict = wordsRegexp(reservedStrict); |
| 6895 | this.reservedWordsStrictBind = wordsRegexp(reservedStrict + " " + reservedWords.strictBind); |
| 6896 | this.input = String(input); |
| 6897 | this.containsEsc = false; |
| 6898 | this.pos = startPos || 0; |
| 6899 | this.curLine = 1; |
| 6900 | if (options.startLocation) { |
| 6901 | this.lineStart = this.pos - options.startLocation.column; |
| 6902 | this.curLine = options.startLocation.line; |
| 6903 | } else if (startPos) { |
| 6904 | this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1; |
| 6905 | if (this.options.locations) { |
| 6906 | this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length; |
| 6907 | } |
| 6908 | } else { |
| 6909 | this.lineStart = 0; |
| 6910 | } |
| 6911 | this.type = types$1.eof; |
| 6912 | this.value = null; |
| 6913 | this.start = this.end = this.pos; |
| 6914 | this.startLoc = this.endLoc = this.curPosition(); |
| 6915 | this.lastTokEndLoc = this.lastTokStartLoc = null; |
| 6916 | this.lastTokStart = this.lastTokEnd = this.pos; |
| 6917 | this.context = this.initialContext(); |
| 6918 | this.exprAllowed = true; |
| 6919 | this.inModule = options.sourceType === "module"; |
| 6920 | this.strict = this.inModule || options.strict === true || this.strictDirective(this.pos); |
| 6921 | this.potentialArrowAt = -1; |
| 6922 | this.potentialArrowInForAwait = false; |
| 6923 | this.yieldPos = this.awaitPos = this.awaitIdentPos = 0; |
| 6924 | this.labels = []; |
| 6925 | this.undefinedExports = /* @__PURE__ */ Object.create(null); |
| 6926 | if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!") { |
| 6927 | this.skipLineComment(2); |
| 6928 | } |
| 6929 | this.scopeStack = []; |
| 6930 | this.enterScope( |
| 6931 | this.options.sourceType === "commonjs" ? SCOPE_FUNCTION : SCOPE_TOP |
| 6932 | ); |
| 6933 | this.regexpState = null; |
| 6934 | this.privateNameStack = []; |
| 6935 | }; |
| 6936 | prototypeAccessors = { inFunction: { configurable: true }, inGenerator: { configurable: true }, inAsync: { configurable: true }, canAwait: { configurable: true }, allowReturn: { configurable: true }, allowSuper: { configurable: true }, allowDirectSuper: { configurable: true }, treatFunctionsAsVar: { configurable: true }, allowNewDotTarget: { configurable: true }, allowUsing: { configurable: true }, inClassStaticBlock: { configurable: true } }; |
| 6937 | Parser.prototype.parse = function parse() { |
| 6938 | var this$1$1 = this; |
| 6939 | var node = this.options.program || this.startNode(); |
| 6940 | this.nextToken(); |
| 6941 | return this.catchStackOverflow(function() { |
| 6942 | return this$1$1.parseTopLevel(node); |
| 6943 | }); |
| 6944 | }; |
| 6945 | prototypeAccessors.inFunction.get = function() { |
| 6946 | return (this.currentVarScope().flags & SCOPE_FUNCTION) > 0; |
| 6947 | }; |
| 6948 | prototypeAccessors.inGenerator.get = function() { |
| 6949 | return (this.currentVarScope().flags & SCOPE_GENERATOR) > 0; |
| 6950 | }; |
| 6951 | prototypeAccessors.inAsync.get = function() { |
| 6952 | return (this.currentVarScope().flags & SCOPE_ASYNC) > 0; |
| 6953 | }; |
| 6954 | prototypeAccessors.canAwait.get = function() { |
| 6955 | for (var i2 = this.scopeStack.length - 1; i2 >= 0; i2--) { |
| 6956 | var ref2 = this.scopeStack[i2]; |
| 6957 | var flags = ref2.flags; |
| 6958 | if (flags & (SCOPE_CLASS_STATIC_BLOCK | SCOPE_CLASS_FIELD_INIT)) { |
| 6959 | return false; |
| 6960 | } |
| 6961 | if (flags & SCOPE_FUNCTION) { |
| 6962 | return (flags & SCOPE_ASYNC) > 0; |
| 6963 | } |
| 6964 | } |
| 6965 | return this.inModule && this.options.ecmaVersion >= 13 || this.options.allowAwaitOutsideFunction; |
| 6966 | }; |
| 6967 | prototypeAccessors.allowReturn.get = function() { |
| 6968 | if (this.inFunction) { |
| 6969 | return true; |
| 6970 | } |
| 6971 | if (this.options.allowReturnOutsideFunction && this.currentVarScope().flags & SCOPE_TOP) { |
| 6972 | return true; |
| 6973 | } |
| 6974 | return false; |
| 6975 | }; |
| 6976 | prototypeAccessors.allowSuper.get = function() { |
| 6977 | var ref2 = this.currentThisScope(); |
| 6978 | var flags = ref2.flags; |
| 6979 | return (flags & SCOPE_SUPER) > 0 || this.options.allowSuperOutsideMethod; |
| 6980 | }; |
| 6981 | prototypeAccessors.allowDirectSuper.get = function() { |
| 6982 | return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0; |
| 6983 | }; |
| 6984 | prototypeAccessors.treatFunctionsAsVar.get = function() { |
| 6985 | return this.treatFunctionsAsVarInScope(this.currentScope()); |
| 6986 | }; |
| 6987 | prototypeAccessors.allowNewDotTarget.get = function() { |
| 6988 | for (var i2 = this.scopeStack.length - 1; i2 >= 0; i2--) { |
| 6989 | var ref2 = this.scopeStack[i2]; |
| 6990 | var flags = ref2.flags; |
| 6991 | if (flags & (SCOPE_CLASS_STATIC_BLOCK | SCOPE_CLASS_FIELD_INIT) || flags & SCOPE_FUNCTION && !(flags & SCOPE_ARROW)) { |
| 6992 | return true; |
| 6993 | } |
| 6994 | } |
| 6995 | return false; |
| 6996 | }; |
| 6997 | prototypeAccessors.allowUsing.get = function() { |
| 6998 | var ref2 = this.currentScope(); |
| 6999 | var flags = ref2.flags; |
| 7000 | if (flags & SCOPE_SWITCH) { |
| 7001 | return false; |
| 7002 | } |
| 7003 | if (!this.inModule && flags & SCOPE_TOP) { |
| 7004 | return false; |
| 7005 | } |
| 7006 | return true; |
| 7007 | }; |
| 7008 | prototypeAccessors.inClassStaticBlock.get = function() { |
| 7009 | return (this.currentVarScope().flags & SCOPE_CLASS_STATIC_BLOCK) > 0; |
| 7010 | }; |
| 7011 | Parser.extend = function extend() { |
| 7012 | var plugins = [], len = arguments.length; |
| 7013 | while (len--) plugins[len] = arguments[len]; |
| 7014 | var cls = this; |
| 7015 | for (var i2 = 0; i2 < plugins.length; i2++) { |
| 7016 | cls = plugins[i2](cls); |
| 7017 | } |
| 7018 | return cls; |
| 7019 | }; |
| 7020 | Parser.parse = function parse2(input, options) { |
| 7021 | return new this(options, input).parse(); |
| 7022 | }; |
| 7023 | Parser.parseExpressionAt = function parseExpressionAt(input, pos, options) { |
| 7024 | var parser = new this(options, input, pos); |
| 7025 | parser.nextToken(); |
| 7026 | return parser.parseExpression(); |
| 7027 | }; |
| 7028 | Parser.tokenizer = function tokenizer(input, options) { |
| 7029 | return new this(options, input); |
| 7030 | }; |
| 7031 | Object.defineProperties(Parser.prototype, prototypeAccessors); |
| 7032 | pp$9 = Parser.prototype; |
| 7033 | literal = /^(?:'((?:\\[^]|[^'\\])*?)'|"((?:\\[^]|[^"\\])*?)")/; |
| 7034 | pp$9.strictDirective = function(start) { |
| 7035 | if (this.options.ecmaVersion < 5) { |
| 7036 | return false; |
| 7037 | } |
| 7038 | for (; ; ) { |
| 7039 | skipWhiteSpace.lastIndex = start; |
| 7040 | start += skipWhiteSpace.exec(this.input)[0].length; |
| 7041 | var match = literal.exec(this.input.slice(start)); |
| 7042 | if (!match) { |
| 7043 | return false; |
| 7044 | } |
| 7045 | if ((match[1] || match[2]) === "use strict") { |
| 7046 | skipWhiteSpace.lastIndex = start + match[0].length; |
| 7047 | var spaceAfter = skipWhiteSpace.exec(this.input), end = spaceAfter.index + spaceAfter[0].length; |
| 7048 | var next = this.input.charAt(end); |
| 7049 | return next === ";" || next === "}" || lineBreak.test(spaceAfter[0]) && !(/[(`.[+\-/*%<>=,?^&]/.test(next) || next === "!" && this.input.charAt(end + 1) === "="); |
| 7050 | } |
| 7051 | start += match[0].length; |
| 7052 | skipWhiteSpace.lastIndex = start; |
| 7053 | start += skipWhiteSpace.exec(this.input)[0].length; |
| 7054 | if (this.input[start] === ";") { |
| 7055 | start++; |
| 7056 | } |
| 7057 | } |
| 7058 | }; |
| 7059 | pp$9.eat = function(type2) { |
| 7060 | if (this.type === type2) { |
| 7061 | this.next(); |
| 7062 | return true; |
| 7063 | } else { |
| 7064 | return false; |
| 7065 | } |
| 7066 | }; |
| 7067 | pp$9.isContextual = function(name) { |
| 7068 | return this.type === types$1.name && this.value === name && !this.containsEsc; |
| 7069 | }; |
| 7070 | pp$9.eatContextual = function(name) { |
| 7071 | if (!this.isContextual(name)) { |
| 7072 | return false; |
| 7073 | } |
| 7074 | this.next(); |
| 7075 | return true; |
| 7076 | }; |
| 7077 | pp$9.catchStackOverflow = function(f) { |
| 7078 | try { |
| 7079 | return f(); |
| 7080 | } catch (e) { |
| 7081 | if (e instanceof Error && (/\bstack\b.*\b(exceeded|overflow)\b/i.test(e.message) || /\btoo much recursion\b/i.test(e.message))) { |
| 7082 | this.raise(this.start, "Not enough stack space to parse input"); |
| 7083 | } else { |
| 7084 | throw e; |
| 7085 | } |
| 7086 | } |
| 7087 | }; |
| 7088 | pp$9.expectContextual = function(name) { |
| 7089 | if (!this.eatContextual(name)) { |
| 7090 | this.unexpected(); |
| 7091 | } |
| 7092 | }; |
| 7093 | pp$9.canInsertSemicolon = function() { |
| 7094 | return this.type === types$1.eof || this.type === types$1.braceR || lineBreak.test(this.input.slice(this.lastTokEnd, this.start)); |
| 7095 | }; |
| 7096 | pp$9.insertSemicolon = function() { |
| 7097 | if (this.canInsertSemicolon()) { |
| 7098 | if (this.options.onInsertedSemicolon) { |
| 7099 | this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); |
| 7100 | } |
| 7101 | return true; |
| 7102 | } |
| 7103 | }; |
| 7104 | pp$9.semicolon = function() { |
| 7105 | if (!this.eat(types$1.semi) && !this.insertSemicolon()) { |
| 7106 | this.unexpected(); |
| 7107 | } |
| 7108 | }; |
| 7109 | pp$9.afterTrailingComma = function(tokType, notNext) { |
| 7110 | if (this.type === tokType) { |
| 7111 | if (this.options.onTrailingComma) { |
| 7112 | this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); |
| 7113 | } |
| 7114 | if (!notNext) { |
| 7115 | this.next(); |
| 7116 | } |
| 7117 | return true; |
| 7118 | } |
| 7119 | }; |
| 7120 | pp$9.expect = function(type2) { |
| 7121 | this.eat(type2) || this.unexpected(); |
| 7122 | }; |
| 7123 | pp$9.unexpected = function(pos) { |
| 7124 | this.raise(pos != null ? pos : this.start, "Unexpected token"); |
| 7125 | }; |
| 7126 | DestructuringErrors = function DestructuringErrors2() { |
| 7127 | this.shorthandAssign = this.trailingComma = this.parenthesizedAssign = this.parenthesizedBind = this.doubleProto = -1; |
| 7128 | }; |
| 7129 | pp$9.checkPatternErrors = function(refDestructuringErrors, isAssign) { |
| 7130 | if (!refDestructuringErrors) { |
| 7131 | return; |
| 7132 | } |
| 7133 | if (refDestructuringErrors.trailingComma > -1) { |
| 7134 | this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); |
| 7135 | } |
| 7136 | var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind; |
| 7137 | if (parens > -1) { |
| 7138 | this.raiseRecoverable(parens, isAssign ? "Assigning to rvalue" : "Parenthesized pattern"); |
| 7139 | } |
| 7140 | }; |
| 7141 | pp$9.checkExpressionErrors = function(refDestructuringErrors, andThrow) { |
| 7142 | if (!refDestructuringErrors) { |
| 7143 | return false; |
| 7144 | } |
| 7145 | var shorthandAssign = refDestructuringErrors.shorthandAssign; |
| 7146 | var doubleProto = refDestructuringErrors.doubleProto; |
| 7147 | if (!andThrow) { |
| 7148 | return shorthandAssign >= 0 || doubleProto >= 0; |
| 7149 | } |
| 7150 | if (shorthandAssign >= 0) { |
| 7151 | this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); |
| 7152 | } |
| 7153 | if (doubleProto >= 0) { |
| 7154 | this.raiseRecoverable(doubleProto, "Redefinition of __proto__ property"); |
| 7155 | } |
| 7156 | }; |
| 7157 | pp$9.checkYieldAwaitInDefaultParams = function() { |
| 7158 | if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos)) { |
| 7159 | this.raise(this.yieldPos, "Yield expression cannot be a default value"); |
| 7160 | } |
| 7161 | if (this.awaitPos) { |
| 7162 | this.raise(this.awaitPos, "Await expression cannot be a default value"); |
| 7163 | } |
| 7164 | }; |
| 7165 | pp$9.isSimpleAssignTarget = function(expr) { |
| 7166 | if (expr.type === "ParenthesizedExpression") { |
| 7167 | return this.isSimpleAssignTarget(expr.expression); |
| 7168 | } |
| 7169 | return expr.type === "Identifier" || expr.type === "MemberExpression"; |
| 7170 | }; |
| 7171 | pp$8 = Parser.prototype; |
| 7172 | pp$8.parseTopLevel = function(node) { |
| 7173 | var exports$1 = /* @__PURE__ */ Object.create(null); |
| 7174 | if (!node.body) { |
| 7175 | node.body = []; |
| 7176 | } |
| 7177 | while (this.type !== types$1.eof) { |
| 7178 | var stmt = this.parseStatement(null, true, exports$1); |
| 7179 | node.body.push(stmt); |
| 7180 | } |
| 7181 | if (this.inModule) { |
| 7182 | for (var i2 = 0, list2 = Object.keys(this.undefinedExports); i2 < list2.length; i2 += 1) { |
| 7183 | var name = list2[i2]; |
| 7184 | this.raiseRecoverable(this.undefinedExports[name].start, "Export '" + name + "' is not defined"); |
| 7185 | } |
| 7186 | } |
| 7187 | this.adaptDirectivePrologue(node.body); |
| 7188 | this.next(); |
| 7189 | node.sourceType = this.options.sourceType === "commonjs" ? "script" : this.options.sourceType; |
| 7190 | return this.finishNode(node, "Program"); |
| 7191 | }; |
| 7192 | loopLabel = { kind: "loop" }; |
| 7193 | switchLabel = { kind: "switch" }; |
| 7194 | pp$8.isLet = function(context) { |
| 7195 | if (this.options.ecmaVersion < 6 || !this.isContextual("let")) { |
| 7196 | return false; |
| 7197 | } |
| 7198 | skipWhiteSpace.lastIndex = this.pos; |
| 7199 | var skip = skipWhiteSpace.exec(this.input); |
| 7200 | var next = this.pos + skip[0].length, nextCh = this.fullCharCodeAt(next); |
| 7201 | if (nextCh === 91 || nextCh === 92) { |
| 7202 | return true; |
| 7203 | } |
| 7204 | if (context) { |
| 7205 | return false; |
| 7206 | } |
| 7207 | if (nextCh === 123) { |
| 7208 | return true; |
| 7209 | } |
| 7210 | if (isIdentifierStart(nextCh)) { |
| 7211 | var start = next; |
| 7212 | do { |
| 7213 | next += nextCh <= 65535 ? 1 : 2; |
| 7214 | } while (isIdentifierChar(nextCh = this.fullCharCodeAt(next))); |
| 7215 | if (nextCh === 92) { |
| 7216 | return true; |
| 7217 | } |
| 7218 | var ident = this.input.slice(start, next); |
| 7219 | if (!keywordRelationalOperator.test(ident)) { |
| 7220 | return true; |
| 7221 | } |
| 7222 | } |
| 7223 | return false; |
| 7224 | }; |
| 7225 | pp$8.isAsyncFunction = function() { |
| 7226 | if (this.options.ecmaVersion < 8 || !this.isContextual("async")) { |
| 7227 | return false; |
| 7228 | } |
| 7229 | skipWhiteSpace.lastIndex = this.pos; |
| 7230 | var skip = skipWhiteSpace.exec(this.input); |
| 7231 | var next = this.pos + skip[0].length, after; |
| 7232 | return !lineBreak.test(this.input.slice(this.pos, next)) && this.input.slice(next, next + 8) === "function" && (next + 8 === this.input.length || !(isIdentifierChar(after = this.fullCharCodeAt(next + 8)) || after === 92)); |
| 7233 | }; |
| 7234 | pp$8.isUsingKeyword = function(isAwaitUsing, isFor) { |
| 7235 | if (this.options.ecmaVersion < 17 || !this.isContextual(isAwaitUsing ? "await" : "using")) { |
| 7236 | return false; |
| 7237 | } |
| 7238 | skipWhiteSpace.lastIndex = this.pos; |
| 7239 | var skip = skipWhiteSpace.exec(this.input); |
| 7240 | var next = this.pos + skip[0].length; |
| 7241 | if (lineBreak.test(this.input.slice(this.pos, next))) { |
| 7242 | return false; |
| 7243 | } |
| 7244 | if (isAwaitUsing) { |
| 7245 | var usingEndPos = next + 5, after; |
| 7246 | if (this.input.slice(next, usingEndPos) !== "using" || usingEndPos === this.input.length || isIdentifierChar(after = this.fullCharCodeAt(usingEndPos)) || after === 92) { |
| 7247 | return false; |
| 7248 | } |
| 7249 | skipWhiteSpace.lastIndex = usingEndPos; |
| 7250 | var skipAfterUsing = skipWhiteSpace.exec(this.input); |
| 7251 | next = usingEndPos + skipAfterUsing[0].length; |
| 7252 | if (skipAfterUsing && lineBreak.test(this.input.slice(usingEndPos, next))) { |
| 7253 | return false; |
| 7254 | } |
| 7255 | } |
| 7256 | var ch = this.fullCharCodeAt(next); |
| 7257 | if (!isIdentifierStart(ch) && ch !== 92) { |
| 7258 | return false; |
| 7259 | } |
| 7260 | var idStart = next; |
| 7261 | do { |
| 7262 | next += ch <= 65535 ? 1 : 2; |
| 7263 | } while (isIdentifierChar(ch = this.fullCharCodeAt(next))); |
| 7264 | if (ch === 92) { |
| 7265 | return true; |
| 7266 | } |
| 7267 | var id = this.input.slice(idStart, next); |
| 7268 | if (keywordRelationalOperator.test(id)) { |
| 7269 | return false; |
| 7270 | } |
| 7271 | if (isFor && !isAwaitUsing && id === "of") { |
| 7272 | skipWhiteSpace.lastIndex = next; |
| 7273 | var skipAfterOf = skipWhiteSpace.exec(this.input); |
| 7274 | next = next + skipAfterOf[0].length; |
| 7275 | if (this.input.charCodeAt(next) !== 61 || // Check for ==, === and => operators |
| 7276 | (ch = this.input.charCodeAt(next + 1)) === 61 || ch === 62) { |
| 7277 | return false; |
| 7278 | } |
| 7279 | } |
| 7280 | return true; |
| 7281 | }; |
| 7282 | pp$8.isAwaitUsing = function(isFor) { |
| 7283 | return this.isUsingKeyword(true, isFor); |
| 7284 | }; |
| 7285 | pp$8.isUsing = function(isFor) { |
| 7286 | return this.isUsingKeyword(false, isFor); |
| 7287 | }; |
| 7288 | pp$8.parseStatement = function(context, topLevel, exports$1) { |
| 7289 | var starttype = this.type, node = this.startNode(), kind; |
| 7290 | if (this.isLet(context)) { |
| 7291 | starttype = types$1._var; |
| 7292 | kind = "let"; |
| 7293 | } |
| 7294 | switch (starttype) { |
| 7295 | case types$1._break: |
| 7296 | case types$1._continue: |
| 7297 | return this.parseBreakContinueStatement(node, starttype.keyword); |
| 7298 | case types$1._debugger: |
| 7299 | return this.parseDebuggerStatement(node); |
| 7300 | case types$1._do: |
| 7301 | return this.parseDoStatement(node); |
| 7302 | case types$1._for: |
| 7303 | return this.parseForStatement(node); |
| 7304 | case types$1._function: |
| 7305 | if (context && (this.strict || context !== "if" && context !== "label") && this.options.ecmaVersion >= 6) { |
| 7306 | this.unexpected(); |
| 7307 | } |
| 7308 | return this.parseFunctionStatement(node, false, !context); |
| 7309 | case types$1._class: |
| 7310 | if (context) { |
| 7311 | this.unexpected(); |
| 7312 | } |
| 7313 | return this.parseClass(node, true); |
| 7314 | case types$1._if: |
| 7315 | return this.parseIfStatement(node); |
| 7316 | case types$1._return: |
| 7317 | return this.parseReturnStatement(node); |
| 7318 | case types$1._switch: |
| 7319 | return this.parseSwitchStatement(node); |
| 7320 | case types$1._throw: |
| 7321 | return this.parseThrowStatement(node); |
| 7322 | case types$1._try: |
| 7323 | return this.parseTryStatement(node); |
| 7324 | case types$1._const: |
| 7325 | case types$1._var: |
| 7326 | kind = kind || this.value; |
| 7327 | if (context && kind !== "var") { |
| 7328 | this.unexpected(); |
| 7329 | } |
| 7330 | return this.parseVarStatement(node, kind); |
| 7331 | case types$1._while: |
| 7332 | return this.parseWhileStatement(node); |
| 7333 | case types$1._with: |
| 7334 | return this.parseWithStatement(node); |
| 7335 | case types$1.braceL: |
| 7336 | return this.parseBlock(true, node); |
| 7337 | case types$1.semi: |
| 7338 | return this.parseEmptyStatement(node); |
| 7339 | case types$1._export: |
| 7340 | case types$1._import: |
| 7341 | if (this.options.ecmaVersion > 10 && starttype === types$1._import) { |
| 7342 | skipWhiteSpace.lastIndex = this.pos; |
| 7343 | var skip = skipWhiteSpace.exec(this.input); |
| 7344 | var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next); |
| 7345 | if (nextCh === 40 || nextCh === 46) { |
| 7346 | return this.parseExpressionStatement(node, this.parseExpression()); |
| 7347 | } |
| 7348 | } |
| 7349 | if (!this.options.allowImportExportEverywhere) { |
| 7350 | if (!topLevel) { |
| 7351 | this.raise(this.start, "'import' and 'export' may only appear at the top level"); |
| 7352 | } |
| 7353 | if (!this.inModule) { |
| 7354 | this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); |
| 7355 | } |
| 7356 | } |
| 7357 | return starttype === types$1._import ? this.parseImport(node) : this.parseExport(node, exports$1); |
| 7358 | // If the statement does not start with a statement keyword or a |
| 7359 | // brace, it's an ExpressionStatement or LabeledStatement. We |
| 7360 | // simply start parsing an expression, and afterwards, if the |
| 7361 | // next token is a colon and the expression was a simple |
| 7362 | // Identifier node, we switch to interpreting it as a label. |
| 7363 | default: |
| 7364 | if (this.isAsyncFunction()) { |
| 7365 | if (context) { |
| 7366 | this.unexpected(); |
| 7367 | } |
| 7368 | this.next(); |
| 7369 | return this.parseFunctionStatement(node, true, !context); |
| 7370 | } |
| 7371 | var usingKind = this.isAwaitUsing(false) ? "await using" : this.isUsing(false) ? "using" : null; |
| 7372 | if (usingKind) { |
| 7373 | if (!this.allowUsing) { |
| 7374 | this.raise(this.start, "Using declaration cannot appear in the top level when source type is `script` or in the bare case statement"); |
| 7375 | } |
| 7376 | if (context) { |
| 7377 | this.raise(this.start, "Using declaration is not allowed in single-statement positions"); |
| 7378 | } |
| 7379 | if (usingKind === "await using") { |
| 7380 | if (!this.canAwait) { |
| 7381 | this.raise(this.start, "Await using cannot appear outside of async function"); |
| 7382 | } |
| 7383 | this.next(); |
| 7384 | } |
| 7385 | this.next(); |
| 7386 | this.parseVar(node, false, usingKind); |
| 7387 | this.semicolon(); |
| 7388 | return this.finishNode(node, "VariableDeclaration"); |
| 7389 | } |
| 7390 | var maybeName = this.value, expr = this.parseExpression(); |
| 7391 | if (starttype === types$1.name && expr.type === "Identifier" && this.eat(types$1.colon)) { |
| 7392 | return this.parseLabeledStatement(node, maybeName, expr, context); |
| 7393 | } else { |
| 7394 | return this.parseExpressionStatement(node, expr); |
| 7395 | } |
| 7396 | } |
| 7397 | }; |
| 7398 | pp$8.parseBreakContinueStatement = function(node, keyword) { |
| 7399 | var isBreak = keyword === "break"; |
| 7400 | this.next(); |
| 7401 | if (this.eat(types$1.semi) || this.insertSemicolon()) { |
| 7402 | node.label = null; |
| 7403 | } else if (this.type !== types$1.name) { |
| 7404 | this.unexpected(); |
| 7405 | } else { |
| 7406 | node.label = this.parseIdent(); |
| 7407 | this.semicolon(); |
| 7408 | } |
| 7409 | var i2 = 0; |
| 7410 | for (; i2 < this.labels.length; ++i2) { |
| 7411 | var lab = this.labels[i2]; |
| 7412 | if (node.label == null || lab.name === node.label.name) { |
| 7413 | if (lab.kind != null && (isBreak || lab.kind === "loop")) { |
| 7414 | break; |
| 7415 | } |
| 7416 | if (node.label && isBreak) { |
| 7417 | break; |
| 7418 | } |
| 7419 | } |
| 7420 | } |
| 7421 | if (i2 === this.labels.length) { |
| 7422 | this.raise(node.start, "Unsyntactic " + keyword); |
| 7423 | } |
| 7424 | return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement"); |
| 7425 | }; |
| 7426 | pp$8.parseDebuggerStatement = function(node) { |
| 7427 | this.next(); |
| 7428 | this.semicolon(); |
| 7429 | return this.finishNode(node, "DebuggerStatement"); |
| 7430 | }; |
| 7431 | pp$8.parseDoStatement = function(node) { |
| 7432 | this.next(); |
| 7433 | this.labels.push(loopLabel); |
| 7434 | node.body = this.parseStatement("do"); |
| 7435 | this.labels.pop(); |
| 7436 | this.expect(types$1._while); |
| 7437 | node.test = this.parseParenExpression(); |
| 7438 | if (this.options.ecmaVersion >= 6) { |
| 7439 | this.eat(types$1.semi); |
| 7440 | } else { |
| 7441 | this.semicolon(); |
| 7442 | } |
| 7443 | return this.finishNode(node, "DoWhileStatement"); |
| 7444 | }; |
| 7445 | pp$8.parseForStatement = function(node) { |
| 7446 | this.next(); |
| 7447 | var awaitAt = this.options.ecmaVersion >= 9 && this.canAwait && this.eatContextual("await") ? this.lastTokStart : -1; |
| 7448 | this.labels.push(loopLabel); |
| 7449 | this.enterScope(0); |
| 7450 | this.expect(types$1.parenL); |
| 7451 | if (this.type === types$1.semi) { |
| 7452 | if (awaitAt > -1) { |
| 7453 | this.unexpected(awaitAt); |
| 7454 | } |
| 7455 | return this.parseFor(node, null); |
| 7456 | } |
| 7457 | var isLet = this.isLet(); |
| 7458 | if (this.type === types$1._var || this.type === types$1._const || isLet) { |
| 7459 | var init$1 = this.startNode(), kind = isLet ? "let" : this.value; |
| 7460 | this.next(); |
| 7461 | this.parseVar(init$1, true, kind); |
| 7462 | this.finishNode(init$1, "VariableDeclaration"); |
| 7463 | return this.parseForAfterInit(node, init$1, awaitAt); |
| 7464 | } |
| 7465 | var startsWithLet = this.isContextual("let"), isForOf = false; |
| 7466 | var usingKind = this.isUsing(true) ? "using" : this.isAwaitUsing(true) ? "await using" : null; |
| 7467 | if (usingKind) { |
| 7468 | var init$2 = this.startNode(); |
| 7469 | this.next(); |
| 7470 | if (usingKind === "await using") { |
| 7471 | if (!this.canAwait) { |
| 7472 | this.raise(this.start, "Await using cannot appear outside of async function"); |
| 7473 | } |
| 7474 | this.next(); |
| 7475 | } |
| 7476 | this.parseVar(init$2, true, usingKind); |
| 7477 | this.finishNode(init$2, "VariableDeclaration"); |
| 7478 | return this.parseForAfterInit(node, init$2, awaitAt); |
| 7479 | } |
| 7480 | var containsEsc = this.containsEsc; |
| 7481 | var refDestructuringErrors = new DestructuringErrors(); |
| 7482 | var initPos = this.start; |
| 7483 | var init = awaitAt > -1 ? this.parseExprSubscripts(refDestructuringErrors, "await") : this.parseExpression(true, refDestructuringErrors); |
| 7484 | if (this.type === types$1._in || (isForOf = this.options.ecmaVersion >= 6 && this.isContextual("of"))) { |
| 7485 | if (awaitAt > -1) { |
| 7486 | if (this.type === types$1._in) { |
| 7487 | this.unexpected(awaitAt); |
| 7488 | } |
| 7489 | node.await = true; |
| 7490 | } else if (isForOf && this.options.ecmaVersion >= 8) { |
| 7491 | if (init.start === initPos && !containsEsc && init.type === "Identifier" && init.name === "async") { |
| 7492 | this.unexpected(); |
| 7493 | } else if (this.options.ecmaVersion >= 9) { |
| 7494 | node.await = false; |
| 7495 | } |
| 7496 | } |
| 7497 | if (startsWithLet && isForOf) { |
| 7498 | this.raise(init.start, "The left-hand side of a for-of loop may not start with 'let'."); |
| 7499 | } |
| 7500 | this.toAssignable(init, false, refDestructuringErrors); |
| 7501 | this.checkLValPattern(init); |
| 7502 | return this.parseForIn(node, init); |
| 7503 | } else { |
| 7504 | this.checkExpressionErrors(refDestructuringErrors, true); |
| 7505 | } |
| 7506 | if (awaitAt > -1) { |
| 7507 | this.unexpected(awaitAt); |
| 7508 | } |
| 7509 | return this.parseFor(node, init); |
| 7510 | }; |
| 7511 | pp$8.parseForAfterInit = function(node, init, awaitAt) { |
| 7512 | if ((this.type === types$1._in || this.options.ecmaVersion >= 6 && this.isContextual("of")) && init.declarations.length === 1) { |
| 7513 | if (this.type === types$1._in) { |
| 7514 | if ((init.kind === "using" || init.kind === "await using") && !init.declarations[0].init) { |
| 7515 | this.raise(this.start, "Using declaration is not allowed in for-in loops"); |
| 7516 | } |
| 7517 | if (this.options.ecmaVersion >= 9 && awaitAt > -1) { |
| 7518 | this.unexpected(awaitAt); |
| 7519 | } |
| 7520 | } else if (this.options.ecmaVersion >= 9) { |
| 7521 | node.await = awaitAt > -1; |
| 7522 | } |
| 7523 | return this.parseForIn(node, init); |
| 7524 | } |
| 7525 | if (awaitAt > -1) { |
| 7526 | this.unexpected(awaitAt); |
| 7527 | } |
| 7528 | return this.parseFor(node, init); |
| 7529 | }; |
| 7530 | pp$8.parseFunctionStatement = function(node, isAsync, declarationPosition) { |
| 7531 | this.next(); |
| 7532 | return this.parseFunction(node, FUNC_STATEMENT | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), false, isAsync); |
| 7533 | }; |
| 7534 | pp$8.parseIfStatement = function(node) { |
| 7535 | this.next(); |
| 7536 | node.test = this.parseParenExpression(); |
| 7537 | node.consequent = this.parseStatement("if"); |
| 7538 | node.alternate = this.eat(types$1._else) ? this.parseStatement("if") : null; |
| 7539 | return this.finishNode(node, "IfStatement"); |
| 7540 | }; |
| 7541 | pp$8.parseReturnStatement = function(node) { |
| 7542 | if (!this.allowReturn) { |
| 7543 | this.raise(this.start, "'return' outside of function"); |
| 7544 | } |
| 7545 | this.next(); |
| 7546 | if (this.eat(types$1.semi) || this.insertSemicolon()) { |
| 7547 | node.argument = null; |
| 7548 | } else { |
| 7549 | node.argument = this.parseExpression(); |
| 7550 | this.semicolon(); |
| 7551 | } |
| 7552 | return this.finishNode(node, "ReturnStatement"); |
| 7553 | }; |
| 7554 | pp$8.parseSwitchStatement = function(node) { |
| 7555 | this.next(); |
| 7556 | node.discriminant = this.parseParenExpression(); |
| 7557 | node.cases = []; |
| 7558 | this.expect(types$1.braceL); |
| 7559 | this.labels.push(switchLabel); |
| 7560 | this.enterScope(SCOPE_SWITCH); |
| 7561 | var cur; |
| 7562 | for (var sawDefault = false; this.type !== types$1.braceR; ) { |
| 7563 | if (this.type === types$1._case || this.type === types$1._default) { |
| 7564 | var isCase = this.type === types$1._case; |
| 7565 | if (cur) { |
| 7566 | this.finishNode(cur, "SwitchCase"); |
| 7567 | } |
| 7568 | node.cases.push(cur = this.startNode()); |
| 7569 | cur.consequent = []; |
| 7570 | this.next(); |
| 7571 | if (isCase) { |
| 7572 | cur.test = this.parseExpression(); |
| 7573 | } else { |
| 7574 | if (sawDefault) { |
| 7575 | this.raiseRecoverable(this.lastTokStart, "Multiple default clauses"); |
| 7576 | } |
| 7577 | sawDefault = true; |
| 7578 | cur.test = null; |
| 7579 | } |
| 7580 | this.expect(types$1.colon); |
| 7581 | } else { |
| 7582 | if (!cur) { |
| 7583 | this.unexpected(); |
| 7584 | } |
| 7585 | cur.consequent.push(this.parseStatement(null)); |
| 7586 | } |
| 7587 | } |
| 7588 | this.exitScope(); |
| 7589 | if (cur) { |
| 7590 | this.finishNode(cur, "SwitchCase"); |
| 7591 | } |
| 7592 | this.next(); |
| 7593 | this.labels.pop(); |
| 7594 | return this.finishNode(node, "SwitchStatement"); |
| 7595 | }; |
| 7596 | pp$8.parseThrowStatement = function(node) { |
| 7597 | this.next(); |
| 7598 | if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) { |
| 7599 | this.raise(this.lastTokEnd, "Illegal newline after throw"); |
| 7600 | } |
| 7601 | node.argument = this.parseExpression(); |
| 7602 | this.semicolon(); |
| 7603 | return this.finishNode(node, "ThrowStatement"); |
| 7604 | }; |
| 7605 | empty$1 = []; |
| 7606 | pp$8.parseCatchClauseParam = function() { |
| 7607 | var param = this.parseBindingAtom(); |
| 7608 | var simple = param.type === "Identifier"; |
| 7609 | this.enterScope(simple ? SCOPE_SIMPLE_CATCH : 0); |
| 7610 | this.checkLValPattern(param, simple ? BIND_SIMPLE_CATCH : BIND_LEXICAL); |
| 7611 | this.expect(types$1.parenR); |
| 7612 | return param; |
| 7613 | }; |
| 7614 | pp$8.parseTryStatement = function(node) { |
| 7615 | this.next(); |
| 7616 | node.block = this.parseBlock(); |
| 7617 | node.handler = null; |
| 7618 | if (this.type === types$1._catch) { |
| 7619 | var clause = this.startNode(); |
| 7620 | this.next(); |
| 7621 | if (this.eat(types$1.parenL)) { |
| 7622 | clause.param = this.parseCatchClauseParam(); |
| 7623 | } else { |
| 7624 | if (this.options.ecmaVersion < 10) { |
| 7625 | this.unexpected(); |
| 7626 | } |
| 7627 | clause.param = null; |
| 7628 | this.enterScope(0); |
| 7629 | } |
| 7630 | clause.body = this.parseBlock(false); |
| 7631 | this.exitScope(); |
| 7632 | node.handler = this.finishNode(clause, "CatchClause"); |
| 7633 | } |
| 7634 | node.finalizer = this.eat(types$1._finally) ? this.parseBlock() : null; |
| 7635 | if (!node.handler && !node.finalizer) { |
| 7636 | this.raise(node.start, "Missing catch or finally clause"); |
| 7637 | } |
| 7638 | return this.finishNode(node, "TryStatement"); |
| 7639 | }; |
| 7640 | pp$8.parseVarStatement = function(node, kind, allowMissingInitializer) { |
| 7641 | this.next(); |
| 7642 | this.parseVar(node, false, kind, allowMissingInitializer); |
| 7643 | this.semicolon(); |
| 7644 | return this.finishNode(node, "VariableDeclaration"); |
| 7645 | }; |
| 7646 | pp$8.parseWhileStatement = function(node) { |
| 7647 | this.next(); |
| 7648 | node.test = this.parseParenExpression(); |
| 7649 | this.labels.push(loopLabel); |
| 7650 | node.body = this.parseStatement("while"); |
| 7651 | this.labels.pop(); |
| 7652 | return this.finishNode(node, "WhileStatement"); |
| 7653 | }; |
| 7654 | pp$8.parseWithStatement = function(node) { |
| 7655 | if (this.strict) { |
| 7656 | this.raise(this.start, "'with' in strict mode"); |
| 7657 | } |
| 7658 | this.next(); |
| 7659 | node.object = this.parseParenExpression(); |
| 7660 | node.body = this.parseStatement("with"); |
| 7661 | return this.finishNode(node, "WithStatement"); |
| 7662 | }; |
| 7663 | pp$8.parseEmptyStatement = function(node) { |
| 7664 | this.next(); |
| 7665 | return this.finishNode(node, "EmptyStatement"); |
| 7666 | }; |
| 7667 | pp$8.parseLabeledStatement = function(node, maybeName, expr, context) { |
| 7668 | for (var i$1 = 0, list2 = this.labels; i$1 < list2.length; i$1 += 1) { |
| 7669 | var label = list2[i$1]; |
| 7670 | if (label.name === maybeName) { |
| 7671 | this.raise(expr.start, "Label '" + maybeName + "' is already declared"); |
| 7672 | } |
| 7673 | } |
| 7674 | var kind = this.type.isLoop ? "loop" : this.type === types$1._switch ? "switch" : null; |
| 7675 | for (var i2 = this.labels.length - 1; i2 >= 0; i2--) { |
| 7676 | var label$1 = this.labels[i2]; |
| 7677 | if (label$1.statementStart === node.start) { |
| 7678 | label$1.statementStart = this.start; |
| 7679 | label$1.kind = kind; |
| 7680 | } else { |
| 7681 | break; |
| 7682 | } |
| 7683 | } |
| 7684 | this.labels.push({ name: maybeName, kind, statementStart: this.start }); |
| 7685 | node.body = this.parseStatement(context ? context.indexOf("label") === -1 ? context + "label" : context : "label"); |
| 7686 | this.labels.pop(); |
| 7687 | node.label = expr; |
| 7688 | return this.finishNode(node, "LabeledStatement"); |
| 7689 | }; |
| 7690 | pp$8.parseExpressionStatement = function(node, expr) { |
| 7691 | node.expression = expr; |
| 7692 | this.semicolon(); |
| 7693 | return this.finishNode(node, "ExpressionStatement"); |
| 7694 | }; |
| 7695 | pp$8.parseBlock = function(createNewLexicalScope, node, exitStrict) { |
| 7696 | if (createNewLexicalScope === void 0) createNewLexicalScope = true; |
| 7697 | if (node === void 0) node = this.startNode(); |
| 7698 | node.body = []; |
| 7699 | this.expect(types$1.braceL); |
| 7700 | if (createNewLexicalScope) { |
| 7701 | this.enterScope(0); |
| 7702 | } |
| 7703 | while (this.type !== types$1.braceR) { |
| 7704 | var stmt = this.parseStatement(null); |
| 7705 | node.body.push(stmt); |
| 7706 | } |
| 7707 | if (exitStrict) { |
| 7708 | this.strict = false; |
| 7709 | } |
| 7710 | this.next(); |
| 7711 | if (createNewLexicalScope) { |
| 7712 | this.exitScope(); |
| 7713 | } |
| 7714 | return this.finishNode(node, "BlockStatement"); |
| 7715 | }; |
| 7716 | pp$8.parseFor = function(node, init) { |
| 7717 | node.init = init; |
| 7718 | this.expect(types$1.semi); |
| 7719 | node.test = this.type === types$1.semi ? null : this.parseExpression(); |
| 7720 | this.expect(types$1.semi); |
| 7721 | node.update = this.type === types$1.parenR ? null : this.parseExpression(); |
| 7722 | this.expect(types$1.parenR); |
| 7723 | node.body = this.parseStatement("for"); |
| 7724 | this.exitScope(); |
| 7725 | this.labels.pop(); |
| 7726 | return this.finishNode(node, "ForStatement"); |
| 7727 | }; |
| 7728 | pp$8.parseForIn = function(node, init) { |
| 7729 | var isForIn = this.type === types$1._in; |
| 7730 | this.next(); |
| 7731 | if (init.type === "VariableDeclaration" && init.declarations[0].init != null && (!isForIn || this.options.ecmaVersion < 8 || this.strict || init.kind !== "var" || init.declarations[0].id.type !== "Identifier")) { |
| 7732 | this.raise( |
| 7733 | init.start, |
| 7734 | (isForIn ? "for-in" : "for-of") + " loop variable declaration may not have an initializer" |
| 7735 | ); |
| 7736 | } |
| 7737 | node.left = init; |
| 7738 | node.right = isForIn ? this.parseExpression() : this.parseMaybeAssign(); |
| 7739 | this.expect(types$1.parenR); |
| 7740 | node.body = this.parseStatement("for"); |
| 7741 | this.exitScope(); |
| 7742 | this.labels.pop(); |
| 7743 | return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement"); |
| 7744 | }; |
| 7745 | pp$8.parseVar = function(node, isFor, kind, allowMissingInitializer) { |
| 7746 | node.declarations = []; |
| 7747 | node.kind = kind; |
| 7748 | for (; ; ) { |
| 7749 | var decl = this.startNode(); |
| 7750 | this.parseVarId(decl, kind); |
| 7751 | if (this.eat(types$1.eq)) { |
| 7752 | decl.init = this.parseMaybeAssign(isFor); |
| 7753 | } else if (!allowMissingInitializer && kind === "const" && !(this.type === types$1._in || this.options.ecmaVersion >= 6 && this.isContextual("of"))) { |
| 7754 | this.unexpected(); |
| 7755 | } else if (!allowMissingInitializer && (kind === "using" || kind === "await using") && this.options.ecmaVersion >= 17 && this.type !== types$1._in && !this.isContextual("of")) { |
| 7756 | this.raise(this.lastTokEnd, "Missing initializer in " + kind + " declaration"); |
| 7757 | } else if (!allowMissingInitializer && decl.id.type !== "Identifier" && !(isFor && (this.type === types$1._in || this.isContextual("of")))) { |
| 7758 | this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value"); |
| 7759 | } else { |
| 7760 | decl.init = null; |
| 7761 | } |
| 7762 | node.declarations.push(this.finishNode(decl, "VariableDeclarator")); |
| 7763 | if (!this.eat(types$1.comma)) { |
| 7764 | break; |
| 7765 | } |
| 7766 | } |
| 7767 | return node; |
| 7768 | }; |
| 7769 | pp$8.parseVarId = function(decl, kind) { |
| 7770 | decl.id = kind === "using" || kind === "await using" ? this.parseIdent() : this.parseBindingAtom(); |
| 7771 | this.checkLValPattern(decl.id, kind === "var" ? BIND_VAR : BIND_LEXICAL, false); |
| 7772 | }; |
| 7773 | FUNC_STATEMENT = 1; |
| 7774 | FUNC_HANGING_STATEMENT = 2; |
| 7775 | FUNC_NULLABLE_ID = 4; |
| 7776 | pp$8.parseFunction = function(node, statement, allowExpressionBody, isAsync, forInit) { |
| 7777 | this.initFunction(node); |
| 7778 | if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync) { |
| 7779 | if (this.type === types$1.star && statement & FUNC_HANGING_STATEMENT) { |
| 7780 | this.unexpected(); |
| 7781 | } |
| 7782 | node.generator = this.eat(types$1.star); |
| 7783 | } |
| 7784 | if (this.options.ecmaVersion >= 8) { |
| 7785 | node.async = !!isAsync; |
| 7786 | } |
| 7787 | if (statement & FUNC_STATEMENT) { |
| 7788 | node.id = statement & FUNC_NULLABLE_ID && this.type !== types$1.name ? null : this.parseIdent(); |
| 7789 | if (node.id && !(statement & FUNC_HANGING_STATEMENT)) { |
| 7790 | this.checkLValSimple(node.id, this.strict || node.generator || node.async ? this.treatFunctionsAsVar ? BIND_VAR : BIND_LEXICAL : BIND_FUNCTION); |
| 7791 | } |
| 7792 | } |
| 7793 | var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos; |
| 7794 | this.yieldPos = 0; |
| 7795 | this.awaitPos = 0; |
| 7796 | this.awaitIdentPos = 0; |
| 7797 | this.enterScope(functionFlags(node.async, node.generator)); |
| 7798 | if (!(statement & FUNC_STATEMENT)) { |
| 7799 | node.id = this.type === types$1.name ? this.parseIdent() : null; |
| 7800 | } |
| 7801 | this.parseFunctionParams(node); |
| 7802 | this.parseFunctionBody(node, allowExpressionBody, false, forInit); |
| 7803 | this.yieldPos = oldYieldPos; |
| 7804 | this.awaitPos = oldAwaitPos; |
| 7805 | this.awaitIdentPos = oldAwaitIdentPos; |
| 7806 | return this.finishNode(node, statement & FUNC_STATEMENT ? "FunctionDeclaration" : "FunctionExpression"); |
| 7807 | }; |
| 7808 | pp$8.parseFunctionParams = function(node) { |
| 7809 | this.expect(types$1.parenL); |
| 7810 | node.params = this.parseBindingList(types$1.parenR, false, this.options.ecmaVersion >= 8); |
| 7811 | this.checkYieldAwaitInDefaultParams(); |
| 7812 | }; |
| 7813 | pp$8.parseClass = function(node, isStatement) { |
| 7814 | this.next(); |
| 7815 | var oldStrict = this.strict; |
| 7816 | this.strict = true; |
| 7817 | this.parseClassId(node, isStatement); |
| 7818 | this.parseClassSuper(node); |
| 7819 | var privateNameMap = this.enterClassBody(); |
| 7820 | var classBody = this.startNode(); |
| 7821 | var hadConstructor = false; |
| 7822 | classBody.body = []; |
| 7823 | this.expect(types$1.braceL); |
| 7824 | while (this.type !== types$1.braceR) { |
| 7825 | var element = this.parseClassElement(node.superClass !== null); |
| 7826 | if (element) { |
| 7827 | classBody.body.push(element); |
| 7828 | if (element.type === "MethodDefinition" && element.kind === "constructor") { |
| 7829 | if (hadConstructor) { |
| 7830 | this.raiseRecoverable(element.start, "Duplicate constructor in the same class"); |
| 7831 | } |
| 7832 | hadConstructor = true; |
| 7833 | } else if (element.key && element.key.type === "PrivateIdentifier" && isPrivateNameConflicted(privateNameMap, element)) { |
| 7834 | this.raiseRecoverable(element.key.start, "Identifier '#" + element.key.name + "' has already been declared"); |
| 7835 | } |
| 7836 | } |
| 7837 | } |
| 7838 | this.strict = oldStrict; |
| 7839 | this.next(); |
| 7840 | node.body = this.finishNode(classBody, "ClassBody"); |
| 7841 | this.exitClassBody(); |
| 7842 | return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression"); |
| 7843 | }; |
| 7844 | pp$8.parseClassElement = function(constructorAllowsSuper) { |
| 7845 | if (this.eat(types$1.semi)) { |
| 7846 | return null; |
| 7847 | } |
| 7848 | var ecmaVersion2 = this.options.ecmaVersion; |
| 7849 | var node = this.startNode(); |
| 7850 | var keyName = ""; |
| 7851 | var isGenerator = false; |
| 7852 | var isAsync = false; |
| 7853 | var kind = "method"; |
| 7854 | var isStatic = false; |
| 7855 | if (this.eatContextual("static")) { |
| 7856 | if (ecmaVersion2 >= 13 && this.eat(types$1.braceL)) { |
| 7857 | this.parseClassStaticBlock(node); |
| 7858 | return node; |
| 7859 | } |
| 7860 | if (this.isClassElementNameStart() || this.type === types$1.star) { |
| 7861 | isStatic = true; |
| 7862 | } else { |
| 7863 | keyName = "static"; |
| 7864 | } |
| 7865 | } |
| 7866 | node.static = isStatic; |
| 7867 | if (!keyName && ecmaVersion2 >= 8 && this.eatContextual("async")) { |
| 7868 | if ((this.isClassElementNameStart() || this.type === types$1.star) && !this.canInsertSemicolon()) { |
| 7869 | isAsync = true; |
| 7870 | } else { |
| 7871 | keyName = "async"; |
| 7872 | } |
| 7873 | } |
| 7874 | if (!keyName && (ecmaVersion2 >= 9 || !isAsync) && this.eat(types$1.star)) { |
| 7875 | isGenerator = true; |
| 7876 | } |
| 7877 | if (!keyName && !isAsync && !isGenerator) { |
| 7878 | var lastValue = this.value; |
| 7879 | if (this.eatContextual("get") || this.eatContextual("set")) { |
| 7880 | if (this.isClassElementNameStart()) { |
| 7881 | kind = lastValue; |
| 7882 | } else { |
| 7883 | keyName = lastValue; |
| 7884 | } |
| 7885 | } |
| 7886 | } |
| 7887 | if (keyName) { |
| 7888 | node.computed = false; |
| 7889 | node.key = this.startNodeAt(this.lastTokStart, this.lastTokStartLoc); |
| 7890 | node.key.name = keyName; |
| 7891 | this.finishNode(node.key, "Identifier"); |
| 7892 | } else { |
| 7893 | this.parseClassElementName(node); |
| 7894 | } |
| 7895 | if (ecmaVersion2 < 13 || this.type === types$1.parenL || kind !== "method" || isGenerator || isAsync) { |
| 7896 | var isConstructor2 = !node.static && checkKeyName(node, "constructor"); |
| 7897 | var allowsDirectSuper = isConstructor2 && constructorAllowsSuper; |
| 7898 | if (isConstructor2 && kind !== "method") { |
| 7899 | this.raise(node.key.start, "Constructor can't have get/set modifier"); |
| 7900 | } |
| 7901 | node.kind = isConstructor2 ? "constructor" : kind; |
| 7902 | this.parseClassMethod(node, isGenerator, isAsync, allowsDirectSuper); |
| 7903 | } else { |
| 7904 | this.parseClassField(node); |
| 7905 | } |
| 7906 | return node; |
| 7907 | }; |
| 7908 | pp$8.isClassElementNameStart = function() { |
| 7909 | return this.type === types$1.name || this.type === types$1.privateId || this.type === types$1.num || this.type === types$1.string || this.type === types$1.bracketL || this.type.keyword; |
| 7910 | }; |
| 7911 | pp$8.parseClassElementName = function(element) { |
| 7912 | if (this.type === types$1.privateId) { |
| 7913 | if (this.value === "constructor") { |
| 7914 | this.raise(this.start, "Classes can't have an element named '#constructor'"); |
| 7915 | } |
| 7916 | element.computed = false; |
| 7917 | element.key = this.parsePrivateIdent(); |
| 7918 | } else { |
| 7919 | this.parsePropertyName(element); |
| 7920 | } |
| 7921 | }; |
| 7922 | pp$8.parseClassMethod = function(method, isGenerator, isAsync, allowsDirectSuper) { |
| 7923 | var key = method.key; |
| 7924 | if (method.kind === "constructor") { |
| 7925 | if (isGenerator) { |
| 7926 | this.raise(key.start, "Constructor can't be a generator"); |
| 7927 | } |
| 7928 | if (isAsync) { |
| 7929 | this.raise(key.start, "Constructor can't be an async method"); |
| 7930 | } |
| 7931 | } else if (method.static && checkKeyName(method, "prototype")) { |
| 7932 | this.raise(key.start, "Classes may not have a static property named prototype"); |
| 7933 | } |
| 7934 | var value = method.value = this.parseMethod(isGenerator, isAsync, allowsDirectSuper); |
| 7935 | if (method.kind === "get" && value.params.length !== 0) { |
| 7936 | this.raiseRecoverable(value.start, "getter should have no params"); |
| 7937 | } |
| 7938 | if (method.kind === "set" && value.params.length !== 1) { |
| 7939 | this.raiseRecoverable(value.start, "setter should have exactly one param"); |
| 7940 | } |
| 7941 | if (method.kind === "set" && value.params[0].type === "RestElement") { |
| 7942 | this.raiseRecoverable(value.params[0].start, "Setter cannot use rest params"); |
| 7943 | } |
| 7944 | return this.finishNode(method, "MethodDefinition"); |
| 7945 | }; |
| 7946 | pp$8.parseClassField = function(field) { |
| 7947 | if (checkKeyName(field, "constructor")) { |
| 7948 | this.raise(field.key.start, "Classes can't have a field named 'constructor'"); |
| 7949 | } else if (field.static && checkKeyName(field, "prototype")) { |
| 7950 | this.raise(field.key.start, "Classes can't have a static field named 'prototype'"); |
| 7951 | } |
| 7952 | if (this.eat(types$1.eq)) { |
| 7953 | this.enterScope(SCOPE_CLASS_FIELD_INIT | SCOPE_SUPER); |
| 7954 | field.value = this.parseMaybeAssign(); |
| 7955 | this.exitScope(); |
| 7956 | } else { |
| 7957 | field.value = null; |
| 7958 | } |
| 7959 | this.semicolon(); |
| 7960 | return this.finishNode(field, "PropertyDefinition"); |
| 7961 | }; |
| 7962 | pp$8.parseClassStaticBlock = function(node) { |
| 7963 | node.body = []; |
| 7964 | var oldLabels = this.labels; |
| 7965 | this.labels = []; |
| 7966 | this.enterScope(SCOPE_CLASS_STATIC_BLOCK | SCOPE_SUPER); |
| 7967 | while (this.type !== types$1.braceR) { |
| 7968 | var stmt = this.parseStatement(null); |
| 7969 | node.body.push(stmt); |
| 7970 | } |
| 7971 | this.next(); |
| 7972 | this.exitScope(); |
| 7973 | this.labels = oldLabels; |
| 7974 | return this.finishNode(node, "StaticBlock"); |
| 7975 | }; |
| 7976 | pp$8.parseClassId = function(node, isStatement) { |
| 7977 | if (this.type === types$1.name) { |
| 7978 | node.id = this.parseIdent(); |
| 7979 | if (isStatement) { |
| 7980 | this.checkLValSimple(node.id, BIND_LEXICAL, false); |
| 7981 | } |
| 7982 | } else { |
| 7983 | if (isStatement === true) { |
| 7984 | this.unexpected(); |
| 7985 | } |
| 7986 | node.id = null; |
| 7987 | } |
| 7988 | }; |
| 7989 | pp$8.parseClassSuper = function(node) { |
| 7990 | node.superClass = this.eat(types$1._extends) ? this.parseExprSubscripts(null, false) : null; |
| 7991 | }; |
| 7992 | pp$8.enterClassBody = function() { |
| 7993 | var element = { declared: /* @__PURE__ */ Object.create(null), used: [] }; |
| 7994 | this.privateNameStack.push(element); |
| 7995 | return element.declared; |
| 7996 | }; |
| 7997 | pp$8.exitClassBody = function() { |
| 7998 | var ref2 = this.privateNameStack.pop(); |
| 7999 | var declared = ref2.declared; |
| 8000 | var used = ref2.used; |
| 8001 | if (!this.options.checkPrivateFields) { |
| 8002 | return; |
| 8003 | } |
| 8004 | var len = this.privateNameStack.length; |
| 8005 | var parent = len === 0 ? null : this.privateNameStack[len - 1]; |
| 8006 | for (var i2 = 0; i2 < used.length; ++i2) { |
| 8007 | var id = used[i2]; |
| 8008 | if (!hasOwn(declared, id.name)) { |
| 8009 | if (parent) { |
| 8010 | parent.used.push(id); |
| 8011 | } else { |
| 8012 | this.raiseRecoverable(id.start, "Private field '#" + id.name + "' must be declared in an enclosing class"); |
| 8013 | } |
| 8014 | } |
| 8015 | } |
| 8016 | }; |
| 8017 | pp$8.parseExportAllDeclaration = function(node, exports$1) { |
| 8018 | if (this.options.ecmaVersion >= 11) { |
| 8019 | if (this.eatContextual("as")) { |
| 8020 | node.exported = this.parseModuleExportName(); |
| 8021 | this.checkExport(exports$1, node.exported, this.lastTokStart); |
| 8022 | } else { |
| 8023 | node.exported = null; |
| 8024 | } |
| 8025 | } |
| 8026 | this.expectContextual("from"); |
| 8027 | if (this.type !== types$1.string) { |
| 8028 | this.unexpected(); |
| 8029 | } |
| 8030 | node.source = this.parseExprAtom(); |
| 8031 | if (this.options.ecmaVersion >= 16) { |
| 8032 | node.attributes = this.parseWithClause(); |
| 8033 | } |
| 8034 | this.semicolon(); |
| 8035 | return this.finishNode(node, "ExportAllDeclaration"); |
| 8036 | }; |
| 8037 | pp$8.parseExport = function(node, exports$1) { |
| 8038 | this.next(); |
| 8039 | if (this.eat(types$1.star)) { |
| 8040 | return this.parseExportAllDeclaration(node, exports$1); |
| 8041 | } |
| 8042 | if (this.eat(types$1._default)) { |
| 8043 | this.checkExport(exports$1, "default", this.lastTokStart); |
| 8044 | node.declaration = this.parseExportDefaultDeclaration(); |
| 8045 | return this.finishNode(node, "ExportDefaultDeclaration"); |
| 8046 | } |
| 8047 | if (this.shouldParseExportStatement()) { |
| 8048 | node.declaration = this.parseExportDeclaration(node); |
| 8049 | if (node.declaration.type === "VariableDeclaration") { |
| 8050 | this.checkVariableExport(exports$1, node.declaration.declarations); |
| 8051 | } else { |
| 8052 | this.checkExport(exports$1, node.declaration.id, node.declaration.id.start); |
| 8053 | } |
| 8054 | node.specifiers = []; |
| 8055 | node.source = null; |
| 8056 | if (this.options.ecmaVersion >= 16) { |
| 8057 | node.attributes = []; |
| 8058 | } |
| 8059 | } else { |
| 8060 | node.declaration = null; |
| 8061 | node.specifiers = this.parseExportSpecifiers(exports$1); |
| 8062 | if (this.eatContextual("from")) { |
| 8063 | if (this.type !== types$1.string) { |
| 8064 | this.unexpected(); |
| 8065 | } |
| 8066 | node.source = this.parseExprAtom(); |
| 8067 | if (this.options.ecmaVersion >= 16) { |
| 8068 | node.attributes = this.parseWithClause(); |
| 8069 | } |
| 8070 | } else { |
| 8071 | for (var i2 = 0, list2 = node.specifiers; i2 < list2.length; i2 += 1) { |
| 8072 | var spec = list2[i2]; |
| 8073 | this.checkUnreserved(spec.local); |
| 8074 | this.checkLocalExport(spec.local); |
| 8075 | if (spec.local.type === "Literal") { |
| 8076 | this.raise(spec.local.start, "A string literal cannot be used as an exported binding without `from`."); |
| 8077 | } |
| 8078 | } |
| 8079 | node.source = null; |
| 8080 | if (this.options.ecmaVersion >= 16) { |
| 8081 | node.attributes = []; |
| 8082 | } |
| 8083 | } |
| 8084 | this.semicolon(); |
| 8085 | } |
| 8086 | return this.finishNode(node, "ExportNamedDeclaration"); |
| 8087 | }; |
| 8088 | pp$8.parseExportDeclaration = function(node) { |
| 8089 | return this.parseStatement(null); |
| 8090 | }; |
| 8091 | pp$8.parseExportDefaultDeclaration = function() { |
| 8092 | var isAsync; |
| 8093 | if (this.type === types$1._function || (isAsync = this.isAsyncFunction())) { |
| 8094 | var fNode = this.startNode(); |
| 8095 | this.next(); |
| 8096 | if (isAsync) { |
| 8097 | this.next(); |
| 8098 | } |
| 8099 | return this.parseFunction(fNode, FUNC_STATEMENT | FUNC_NULLABLE_ID, false, isAsync); |
| 8100 | } else if (this.type === types$1._class) { |
| 8101 | var cNode = this.startNode(); |
| 8102 | return this.parseClass(cNode, "nullableID"); |
| 8103 | } else { |
| 8104 | var declaration = this.parseMaybeAssign(); |
| 8105 | this.semicolon(); |
| 8106 | return declaration; |
| 8107 | } |
| 8108 | }; |
| 8109 | pp$8.checkExport = function(exports$1, name, pos) { |
| 8110 | if (!exports$1) { |
| 8111 | return; |
| 8112 | } |
| 8113 | if (typeof name !== "string") { |
| 8114 | name = name.type === "Identifier" ? name.name : name.value; |
| 8115 | } |
| 8116 | if (hasOwn(exports$1, name)) { |
| 8117 | this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); |
| 8118 | } |
| 8119 | exports$1[name] = true; |
| 8120 | }; |
| 8121 | pp$8.checkPatternExport = function(exports$1, pat) { |
| 8122 | var type2 = pat.type; |
| 8123 | if (type2 === "Identifier") { |
| 8124 | this.checkExport(exports$1, pat, pat.start); |
| 8125 | } else if (type2 === "ObjectPattern") { |
| 8126 | for (var i2 = 0, list2 = pat.properties; i2 < list2.length; i2 += 1) { |
| 8127 | var prop = list2[i2]; |
| 8128 | this.checkPatternExport(exports$1, prop); |
| 8129 | } |
| 8130 | } else if (type2 === "ArrayPattern") { |
| 8131 | for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) { |
| 8132 | var elt = list$1[i$1]; |
| 8133 | if (elt) { |
| 8134 | this.checkPatternExport(exports$1, elt); |
| 8135 | } |
| 8136 | } |
| 8137 | } else if (type2 === "Property") { |
| 8138 | this.checkPatternExport(exports$1, pat.value); |
| 8139 | } else if (type2 === "AssignmentPattern") { |
| 8140 | this.checkPatternExport(exports$1, pat.left); |
| 8141 | } else if (type2 === "RestElement") { |
| 8142 | this.checkPatternExport(exports$1, pat.argument); |
| 8143 | } |
| 8144 | }; |
| 8145 | pp$8.checkVariableExport = function(exports$1, decls) { |
| 8146 | if (!exports$1) { |
| 8147 | return; |
| 8148 | } |
| 8149 | for (var i2 = 0, list2 = decls; i2 < list2.length; i2 += 1) { |
| 8150 | var decl = list2[i2]; |
| 8151 | this.checkPatternExport(exports$1, decl.id); |
| 8152 | } |
| 8153 | }; |
| 8154 | pp$8.shouldParseExportStatement = function() { |
| 8155 | return this.type.keyword === "var" || this.type.keyword === "const" || this.type.keyword === "class" || this.type.keyword === "function" || this.isLet() || this.isAsyncFunction(); |
| 8156 | }; |
| 8157 | pp$8.parseExportSpecifier = function(exports$1) { |
| 8158 | var node = this.startNode(); |
| 8159 | node.local = this.parseModuleExportName(); |
| 8160 | node.exported = this.eatContextual("as") ? this.parseModuleExportName() : node.local; |
| 8161 | this.checkExport( |
| 8162 | exports$1, |
| 8163 | node.exported, |
| 8164 | node.exported.start |
| 8165 | ); |
| 8166 | return this.finishNode(node, "ExportSpecifier"); |
| 8167 | }; |
| 8168 | pp$8.parseExportSpecifiers = function(exports$1) { |
| 8169 | var nodes = [], first = true; |
| 8170 | this.expect(types$1.braceL); |
| 8171 | while (!this.eat(types$1.braceR)) { |
| 8172 | if (!first) { |
| 8173 | this.expect(types$1.comma); |
| 8174 | if (this.afterTrailingComma(types$1.braceR)) { |
| 8175 | break; |
| 8176 | } |
| 8177 | } else { |
| 8178 | first = false; |
| 8179 | } |
| 8180 | nodes.push(this.parseExportSpecifier(exports$1)); |
| 8181 | } |
| 8182 | return nodes; |
| 8183 | }; |
| 8184 | pp$8.parseImport = function(node) { |
| 8185 | this.next(); |
| 8186 | if (this.type === types$1.string) { |
| 8187 | node.specifiers = empty$1; |
| 8188 | node.source = this.parseExprAtom(); |
| 8189 | } else { |
| 8190 | node.specifiers = this.parseImportSpecifiers(); |
| 8191 | this.expectContextual("from"); |
| 8192 | node.source = this.type === types$1.string ? this.parseExprAtom() : this.unexpected(); |
| 8193 | } |
| 8194 | if (this.options.ecmaVersion >= 16) { |
| 8195 | node.attributes = this.parseWithClause(); |
| 8196 | } |
| 8197 | this.semicolon(); |
| 8198 | return this.finishNode(node, "ImportDeclaration"); |
| 8199 | }; |
| 8200 | pp$8.parseImportSpecifier = function() { |
| 8201 | var node = this.startNode(); |
| 8202 | node.imported = this.parseModuleExportName(); |
| 8203 | if (this.eatContextual("as")) { |
| 8204 | node.local = this.parseIdent(); |
| 8205 | } else { |
| 8206 | this.checkUnreserved(node.imported); |
| 8207 | node.local = node.imported; |
| 8208 | } |
| 8209 | this.checkLValSimple(node.local, BIND_LEXICAL); |
| 8210 | return this.finishNode(node, "ImportSpecifier"); |
| 8211 | }; |
| 8212 | pp$8.parseImportDefaultSpecifier = function() { |
| 8213 | var node = this.startNode(); |
| 8214 | node.local = this.parseIdent(); |
| 8215 | this.checkLValSimple(node.local, BIND_LEXICAL); |
| 8216 | return this.finishNode(node, "ImportDefaultSpecifier"); |
| 8217 | }; |
| 8218 | pp$8.parseImportNamespaceSpecifier = function() { |
| 8219 | var node = this.startNode(); |
| 8220 | this.next(); |
| 8221 | this.expectContextual("as"); |
| 8222 | node.local = this.parseIdent(); |
| 8223 | this.checkLValSimple(node.local, BIND_LEXICAL); |
| 8224 | return this.finishNode(node, "ImportNamespaceSpecifier"); |
| 8225 | }; |
| 8226 | pp$8.parseImportSpecifiers = function() { |
| 8227 | var nodes = [], first = true; |
| 8228 | if (this.type === types$1.name) { |
| 8229 | nodes.push(this.parseImportDefaultSpecifier()); |
| 8230 | if (!this.eat(types$1.comma)) { |
| 8231 | return nodes; |
| 8232 | } |
| 8233 | } |
| 8234 | if (this.type === types$1.star) { |
| 8235 | nodes.push(this.parseImportNamespaceSpecifier()); |
| 8236 | return nodes; |
| 8237 | } |
| 8238 | this.expect(types$1.braceL); |
| 8239 | while (!this.eat(types$1.braceR)) { |
| 8240 | if (!first) { |
| 8241 | this.expect(types$1.comma); |
| 8242 | if (this.afterTrailingComma(types$1.braceR)) { |
| 8243 | break; |
| 8244 | } |
| 8245 | } else { |
| 8246 | first = false; |
| 8247 | } |
| 8248 | nodes.push(this.parseImportSpecifier()); |
| 8249 | } |
| 8250 | return nodes; |
| 8251 | }; |
| 8252 | pp$8.parseWithClause = function() { |
| 8253 | var nodes = []; |
| 8254 | if (!this.eat(types$1._with)) { |
| 8255 | return nodes; |
| 8256 | } |
| 8257 | this.expect(types$1.braceL); |
| 8258 | var attributeKeys = {}; |
| 8259 | var first = true; |
| 8260 | while (!this.eat(types$1.braceR)) { |
| 8261 | if (!first) { |
| 8262 | this.expect(types$1.comma); |
| 8263 | if (this.afterTrailingComma(types$1.braceR)) { |
| 8264 | break; |
| 8265 | } |
| 8266 | } else { |
| 8267 | first = false; |
| 8268 | } |
| 8269 | var attr = this.parseImportAttribute(); |
| 8270 | var keyName = attr.key.type === "Identifier" ? attr.key.name : attr.key.value; |
| 8271 | if (hasOwn(attributeKeys, keyName)) { |
| 8272 | this.raiseRecoverable(attr.key.start, "Duplicate attribute key '" + keyName + "'"); |
| 8273 | } |
| 8274 | attributeKeys[keyName] = true; |
| 8275 | nodes.push(attr); |
| 8276 | } |
| 8277 | return nodes; |
| 8278 | }; |
| 8279 | pp$8.parseImportAttribute = function() { |
| 8280 | var node = this.startNode(); |
| 8281 | node.key = this.type === types$1.string ? this.parseExprAtom() : this.parseIdent(this.options.allowReserved !== "never"); |
| 8282 | this.expect(types$1.colon); |
| 8283 | if (this.type !== types$1.string) { |
| 8284 | this.unexpected(); |
| 8285 | } |
| 8286 | node.value = this.parseExprAtom(); |
| 8287 | return this.finishNode(node, "ImportAttribute"); |
| 8288 | }; |
| 8289 | pp$8.parseModuleExportName = function() { |
| 8290 | if (this.options.ecmaVersion >= 13 && this.type === types$1.string) { |
| 8291 | var stringLiteral = this.parseLiteral(this.value); |
| 8292 | if (loneSurrogate.test(stringLiteral.value)) { |
| 8293 | this.raise(stringLiteral.start, "An export name cannot include a lone surrogate."); |
| 8294 | } |
| 8295 | return stringLiteral; |
| 8296 | } |
| 8297 | return this.parseIdent(true); |
| 8298 | }; |
| 8299 | pp$8.adaptDirectivePrologue = function(statements) { |
| 8300 | for (var i2 = 0; i2 < statements.length && this.isDirectiveCandidate(statements[i2]); ++i2) { |
| 8301 | statements[i2].directive = statements[i2].expression.raw.slice(1, -1); |
| 8302 | } |
| 8303 | }; |
| 8304 | pp$8.isDirectiveCandidate = function(statement) { |
| 8305 | return this.options.ecmaVersion >= 5 && statement.type === "ExpressionStatement" && statement.expression.type === "Literal" && typeof statement.expression.value === "string" && // Reject parenthesized strings. |
| 8306 | (this.input[statement.start] === '"' || this.input[statement.start] === "'"); |
| 8307 | }; |
| 8308 | pp$7 = Parser.prototype; |
| 8309 | pp$7.toAssignable = function(node, isBinding, refDestructuringErrors) { |
| 8310 | if (this.options.ecmaVersion >= 6 && node) { |
| 8311 | switch (node.type) { |
| 8312 | case "Identifier": |
| 8313 | if (this.inAsync && node.name === "await") { |
| 8314 | this.raise(node.start, "Cannot use 'await' as identifier inside an async function"); |
| 8315 | } |
| 8316 | break; |
| 8317 | case "ObjectPattern": |
| 8318 | case "ArrayPattern": |
| 8319 | case "AssignmentPattern": |
| 8320 | case "RestElement": |
| 8321 | break; |
| 8322 | case "ObjectExpression": |
| 8323 | node.type = "ObjectPattern"; |
| 8324 | if (refDestructuringErrors) { |
| 8325 | this.checkPatternErrors(refDestructuringErrors, true); |
| 8326 | } |
| 8327 | for (var i2 = 0, list2 = node.properties; i2 < list2.length; i2 += 1) { |
| 8328 | var prop = list2[i2]; |
| 8329 | this.toAssignable(prop, isBinding); |
| 8330 | if (prop.type === "RestElement" && (prop.argument.type === "ArrayPattern" || prop.argument.type === "ObjectPattern")) { |
| 8331 | this.raise(prop.argument.start, "Unexpected token"); |
| 8332 | } |
| 8333 | } |
| 8334 | break; |
| 8335 | case "Property": |
| 8336 | if (node.kind !== "init") { |
| 8337 | this.raise(node.key.start, "Object pattern can't contain getter or setter"); |
| 8338 | } |
| 8339 | this.toAssignable(node.value, isBinding); |
| 8340 | break; |
| 8341 | case "ArrayExpression": |
| 8342 | node.type = "ArrayPattern"; |
| 8343 | if (refDestructuringErrors) { |
| 8344 | this.checkPatternErrors(refDestructuringErrors, true); |
| 8345 | } |
| 8346 | this.toAssignableList(node.elements, isBinding); |
| 8347 | break; |
| 8348 | case "SpreadElement": |
| 8349 | node.type = "RestElement"; |
| 8350 | this.toAssignable(node.argument, isBinding); |
| 8351 | if (node.argument.type === "AssignmentPattern") { |
| 8352 | this.raise(node.argument.start, "Rest elements cannot have a default value"); |
| 8353 | } |
| 8354 | break; |
| 8355 | case "AssignmentExpression": |
| 8356 | if (node.operator !== "=") { |
| 8357 | this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); |
| 8358 | } |
| 8359 | node.type = "AssignmentPattern"; |
| 8360 | delete node.operator; |
| 8361 | this.toAssignable(node.left, isBinding); |
| 8362 | break; |
| 8363 | case "ParenthesizedExpression": |
| 8364 | this.toAssignable(node.expression, isBinding, refDestructuringErrors); |
| 8365 | break; |
| 8366 | case "ChainExpression": |
| 8367 | this.raiseRecoverable(node.start, "Optional chaining cannot appear in left-hand side"); |
| 8368 | break; |
| 8369 | case "MemberExpression": |
| 8370 | if (!isBinding) { |
| 8371 | break; |
| 8372 | } |
| 8373 | default: |
| 8374 | this.raise(node.start, "Assigning to rvalue"); |
| 8375 | } |
| 8376 | } else if (refDestructuringErrors) { |
| 8377 | this.checkPatternErrors(refDestructuringErrors, true); |
| 8378 | } |
| 8379 | return node; |
| 8380 | }; |
| 8381 | pp$7.toAssignableList = function(exprList, isBinding) { |
| 8382 | var end = exprList.length; |
| 8383 | for (var i2 = 0; i2 < end; i2++) { |
| 8384 | var elt = exprList[i2]; |
| 8385 | if (elt) { |
| 8386 | this.toAssignable(elt, isBinding); |
| 8387 | } |
| 8388 | } |
| 8389 | if (end) { |
| 8390 | var last = exprList[end - 1]; |
| 8391 | if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier") { |
| 8392 | this.unexpected(last.argument.start); |
| 8393 | } |
| 8394 | } |
| 8395 | return exprList; |
| 8396 | }; |
| 8397 | pp$7.parseSpread = function(refDestructuringErrors) { |
| 8398 | var node = this.startNode(); |
| 8399 | this.next(); |
| 8400 | node.argument = this.parseMaybeAssign(false, refDestructuringErrors); |
| 8401 | return this.finishNode(node, "SpreadElement"); |
| 8402 | }; |
| 8403 | pp$7.parseRestBinding = function() { |
| 8404 | var node = this.startNode(); |
| 8405 | this.next(); |
| 8406 | if (this.options.ecmaVersion === 6 && this.type !== types$1.name) { |
| 8407 | this.unexpected(); |
| 8408 | } |
| 8409 | node.argument = this.parseBindingAtom(); |
| 8410 | return this.finishNode(node, "RestElement"); |
| 8411 | }; |
| 8412 | pp$7.parseBindingAtom = function() { |
| 8413 | if (this.options.ecmaVersion >= 6) { |
| 8414 | switch (this.type) { |
| 8415 | case types$1.bracketL: |
| 8416 | var node = this.startNode(); |
| 8417 | this.next(); |
| 8418 | node.elements = this.parseBindingList(types$1.bracketR, true, true); |
| 8419 | return this.finishNode(node, "ArrayPattern"); |
| 8420 | case types$1.braceL: |
| 8421 | return this.parseObj(true); |
| 8422 | } |
| 8423 | } |
| 8424 | return this.parseIdent(); |
| 8425 | }; |
| 8426 | pp$7.parseBindingList = function(close, allowEmpty, allowTrailingComma, allowModifiers) { |
| 8427 | var elts = [], first = true; |
| 8428 | while (!this.eat(close)) { |
| 8429 | if (first) { |
| 8430 | first = false; |
| 8431 | } else { |
| 8432 | this.expect(types$1.comma); |
| 8433 | } |
| 8434 | if (allowEmpty && this.type === types$1.comma) { |
| 8435 | elts.push(null); |
| 8436 | } else if (allowTrailingComma && this.afterTrailingComma(close)) { |
| 8437 | break; |
| 8438 | } else if (this.type === types$1.ellipsis) { |
| 8439 | var rest = this.parseRestBinding(); |
| 8440 | this.parseBindingListItem(rest); |
| 8441 | elts.push(rest); |
| 8442 | if (this.type === types$1.comma) { |
| 8443 | this.raiseRecoverable(this.start, "Comma is not permitted after the rest element"); |
| 8444 | } |
| 8445 | this.expect(close); |
| 8446 | break; |
| 8447 | } else { |
| 8448 | elts.push(this.parseAssignableListItem(allowModifiers)); |
| 8449 | } |
| 8450 | } |
| 8451 | return elts; |
| 8452 | }; |
| 8453 | pp$7.parseAssignableListItem = function(allowModifiers) { |
| 8454 | var elem = this.parseMaybeDefault(this.start, this.startLoc); |
| 8455 | this.parseBindingListItem(elem); |
| 8456 | return elem; |
| 8457 | }; |
| 8458 | pp$7.parseBindingListItem = function(param) { |
| 8459 | return param; |
| 8460 | }; |
| 8461 | pp$7.parseMaybeDefault = function(startPos, startLoc, left) { |
| 8462 | left = left || this.parseBindingAtom(); |
| 8463 | if (this.options.ecmaVersion < 6 || !this.eat(types$1.eq)) { |
| 8464 | return left; |
| 8465 | } |
| 8466 | var node = this.startNodeAt(startPos, startLoc); |
| 8467 | node.left = left; |
| 8468 | node.right = this.parseMaybeAssign(); |
| 8469 | return this.finishNode(node, "AssignmentPattern"); |
| 8470 | }; |
| 8471 | pp$7.checkLValSimple = function(expr, bindingType, checkClashes) { |
| 8472 | if (bindingType === void 0) bindingType = BIND_NONE; |
| 8473 | var isBind = bindingType !== BIND_NONE; |
| 8474 | switch (expr.type) { |
| 8475 | case "Identifier": |
| 8476 | if (this.strict && this.reservedWordsStrictBind.test(expr.name)) { |
| 8477 | this.raiseRecoverable(expr.start, (isBind ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); |
| 8478 | } |
| 8479 | if (isBind) { |
| 8480 | if (bindingType === BIND_LEXICAL && expr.name === "let") { |
| 8481 | this.raiseRecoverable(expr.start, "let is disallowed as a lexically bound name"); |
| 8482 | } |
| 8483 | if (checkClashes) { |
| 8484 | if (hasOwn(checkClashes, expr.name)) { |
| 8485 | this.raiseRecoverable(expr.start, "Argument name clash"); |
| 8486 | } |
| 8487 | checkClashes[expr.name] = true; |
| 8488 | } |
| 8489 | if (bindingType !== BIND_OUTSIDE) { |
| 8490 | this.declareName(expr.name, bindingType, expr.start); |
| 8491 | } |
| 8492 | } |
| 8493 | break; |
| 8494 | case "ChainExpression": |
| 8495 | this.raiseRecoverable(expr.start, "Optional chaining cannot appear in left-hand side"); |
| 8496 | break; |
| 8497 | case "MemberExpression": |
| 8498 | if (isBind) { |
| 8499 | this.raiseRecoverable(expr.start, "Binding member expression"); |
| 8500 | } |
| 8501 | break; |
| 8502 | case "ParenthesizedExpression": |
| 8503 | if (isBind) { |
| 8504 | this.raiseRecoverable(expr.start, "Binding parenthesized expression"); |
| 8505 | } |
| 8506 | return this.checkLValSimple(expr.expression, bindingType, checkClashes); |
| 8507 | default: |
| 8508 | this.raise(expr.start, (isBind ? "Binding" : "Assigning to") + " rvalue"); |
| 8509 | } |
| 8510 | }; |
| 8511 | pp$7.checkLValPattern = function(expr, bindingType, checkClashes) { |
| 8512 | if (bindingType === void 0) bindingType = BIND_NONE; |
| 8513 | switch (expr.type) { |
| 8514 | case "ObjectPattern": |
| 8515 | for (var i2 = 0, list2 = expr.properties; i2 < list2.length; i2 += 1) { |
| 8516 | var prop = list2[i2]; |
| 8517 | this.checkLValInnerPattern(prop, bindingType, checkClashes); |
| 8518 | } |
| 8519 | break; |
| 8520 | case "ArrayPattern": |
| 8521 | for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) { |
| 8522 | var elem = list$1[i$1]; |
| 8523 | if (elem) { |
| 8524 | this.checkLValInnerPattern(elem, bindingType, checkClashes); |
| 8525 | } |
| 8526 | } |
| 8527 | break; |
| 8528 | default: |
| 8529 | this.checkLValSimple(expr, bindingType, checkClashes); |
| 8530 | } |
| 8531 | }; |
| 8532 | pp$7.checkLValInnerPattern = function(expr, bindingType, checkClashes) { |
| 8533 | if (bindingType === void 0) bindingType = BIND_NONE; |
| 8534 | switch (expr.type) { |
| 8535 | case "Property": |
| 8536 | this.checkLValInnerPattern(expr.value, bindingType, checkClashes); |
| 8537 | break; |
| 8538 | case "AssignmentPattern": |
| 8539 | this.checkLValPattern(expr.left, bindingType, checkClashes); |
| 8540 | break; |
| 8541 | case "RestElement": |
| 8542 | this.checkLValPattern(expr.argument, bindingType, checkClashes); |
| 8543 | break; |
| 8544 | default: |
| 8545 | this.checkLValPattern(expr, bindingType, checkClashes); |
| 8546 | } |
| 8547 | }; |
| 8548 | TokContext = function TokContext2(token, isExpr, preserveSpace, override, generator) { |
| 8549 | this.token = token; |
| 8550 | this.isExpr = !!isExpr; |
| 8551 | this.preserveSpace = !!preserveSpace; |
| 8552 | this.override = override; |
| 8553 | this.generator = !!generator; |
| 8554 | }; |
| 8555 | types2 = { |
| 8556 | b_stat: new TokContext("{", false), |
| 8557 | b_expr: new TokContext("{", true), |
| 8558 | b_tmpl: new TokContext("${", false), |
| 8559 | p_stat: new TokContext("(", false), |
| 8560 | p_expr: new TokContext("(", true), |
| 8561 | q_tmpl: new TokContext("`", true, true, function(p) { |
| 8562 | return p.tryReadTemplateToken(); |
| 8563 | }), |
| 8564 | f_stat: new TokContext("function", false), |
| 8565 | f_expr: new TokContext("function", true), |
| 8566 | f_expr_gen: new TokContext("function", true, false, null, true), |
| 8567 | f_gen: new TokContext("function", false, false, null, true) |
| 8568 | }; |
| 8569 | pp$6 = Parser.prototype; |
| 8570 | pp$6.initialContext = function() { |
| 8571 | return [types2.b_stat]; |
| 8572 | }; |
| 8573 | pp$6.curContext = function() { |
| 8574 | return this.context[this.context.length - 1]; |
| 8575 | }; |
| 8576 | pp$6.braceIsBlock = function(prevType) { |
| 8577 | var parent = this.curContext(); |
| 8578 | if (parent === types2.f_expr || parent === types2.f_stat) { |
| 8579 | return true; |
| 8580 | } |
| 8581 | if (prevType === types$1.colon && (parent === types2.b_stat || parent === types2.b_expr)) { |
| 8582 | return !parent.isExpr; |
| 8583 | } |
| 8584 | if (prevType === types$1._return || prevType === types$1.name && this.exprAllowed) { |
| 8585 | return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)); |
| 8586 | } |
| 8587 | if (prevType === types$1._else || prevType === types$1.semi || prevType === types$1.eof || prevType === types$1.parenR || prevType === types$1.arrow) { |
| 8588 | return true; |
| 8589 | } |
| 8590 | if (prevType === types$1.braceL) { |
| 8591 | return parent === types2.b_stat; |
| 8592 | } |
| 8593 | if (prevType === types$1._var || prevType === types$1._const || prevType === types$1.name) { |
| 8594 | return false; |
| 8595 | } |
| 8596 | return !this.exprAllowed; |
| 8597 | }; |
| 8598 | pp$6.inGeneratorContext = function() { |
| 8599 | for (var i2 = this.context.length - 1; i2 >= 1; i2--) { |
| 8600 | var context = this.context[i2]; |
| 8601 | if (context.token === "function") { |
| 8602 | return context.generator; |
| 8603 | } |
| 8604 | } |
| 8605 | return false; |
| 8606 | }; |
| 8607 | pp$6.updateContext = function(prevType) { |
| 8608 | var update, type2 = this.type; |
| 8609 | if (type2.keyword && prevType === types$1.dot) { |
| 8610 | this.exprAllowed = false; |
| 8611 | } else if (update = type2.updateContext) { |
| 8612 | update.call(this, prevType); |
| 8613 | } else { |
| 8614 | this.exprAllowed = type2.beforeExpr; |
| 8615 | } |
| 8616 | }; |
| 8617 | pp$6.overrideContext = function(tokenCtx) { |
| 8618 | if (this.curContext() !== tokenCtx) { |
| 8619 | this.context[this.context.length - 1] = tokenCtx; |
| 8620 | } |
| 8621 | }; |
| 8622 | types$1.parenR.updateContext = types$1.braceR.updateContext = function() { |
| 8623 | if (this.context.length === 1) { |
| 8624 | this.exprAllowed = true; |
| 8625 | return; |
| 8626 | } |
| 8627 | var out = this.context.pop(); |
| 8628 | if (out === types2.b_stat && this.curContext().token === "function") { |
| 8629 | out = this.context.pop(); |
| 8630 | } |
| 8631 | this.exprAllowed = !out.isExpr; |
| 8632 | }; |
| 8633 | types$1.braceL.updateContext = function(prevType) { |
| 8634 | this.context.push(this.braceIsBlock(prevType) ? types2.b_stat : types2.b_expr); |
| 8635 | this.exprAllowed = true; |
| 8636 | }; |
| 8637 | types$1.dollarBraceL.updateContext = function() { |
| 8638 | this.context.push(types2.b_tmpl); |
| 8639 | this.exprAllowed = true; |
| 8640 | }; |
| 8641 | types$1.parenL.updateContext = function(prevType) { |
| 8642 | var statementParens = prevType === types$1._if || prevType === types$1._for || prevType === types$1._with || prevType === types$1._while; |
| 8643 | this.context.push(statementParens ? types2.p_stat : types2.p_expr); |
| 8644 | this.exprAllowed = true; |
| 8645 | }; |
| 8646 | types$1.incDec.updateContext = function() { |
| 8647 | }; |
| 8648 | types$1._function.updateContext = types$1._class.updateContext = function(prevType) { |
| 8649 | if (prevType.beforeExpr && prevType !== types$1._else && !(prevType === types$1.semi && this.curContext() !== types2.p_stat) && !(prevType === types$1._return && lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) && !((prevType === types$1.colon || prevType === types$1.braceL) && this.curContext() === types2.b_stat)) { |
| 8650 | this.context.push(types2.f_expr); |
| 8651 | } else { |
| 8652 | this.context.push(types2.f_stat); |
| 8653 | } |
| 8654 | this.exprAllowed = false; |
| 8655 | }; |
| 8656 | types$1.colon.updateContext = function() { |
| 8657 | if (this.curContext().token === "function") { |
| 8658 | this.context.pop(); |
| 8659 | } |
| 8660 | this.exprAllowed = true; |
| 8661 | }; |
| 8662 | types$1.backQuote.updateContext = function() { |
| 8663 | if (this.curContext() === types2.q_tmpl) { |
| 8664 | this.context.pop(); |
| 8665 | } else { |
| 8666 | this.context.push(types2.q_tmpl); |
| 8667 | } |
| 8668 | this.exprAllowed = false; |
| 8669 | }; |
| 8670 | types$1.star.updateContext = function(prevType) { |
| 8671 | if (prevType === types$1._function) { |
| 8672 | var index = this.context.length - 1; |
| 8673 | if (this.context[index] === types2.f_expr) { |
| 8674 | this.context[index] = types2.f_expr_gen; |
| 8675 | } else { |
| 8676 | this.context[index] = types2.f_gen; |
| 8677 | } |
| 8678 | } |
| 8679 | this.exprAllowed = true; |
| 8680 | }; |
| 8681 | types$1.name.updateContext = function(prevType) { |
| 8682 | var allowed = false; |
| 8683 | if (this.options.ecmaVersion >= 6 && prevType !== types$1.dot) { |
| 8684 | if (this.value === "of" && !this.exprAllowed || this.value === "yield" && this.inGeneratorContext()) { |
| 8685 | allowed = true; |
| 8686 | } |
| 8687 | } |
| 8688 | this.exprAllowed = allowed; |
| 8689 | }; |
| 8690 | pp$5 = Parser.prototype; |
| 8691 | pp$5.checkPropClash = function(prop, propHash, refDestructuringErrors) { |
| 8692 | if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement") { |
| 8693 | return; |
| 8694 | } |
| 8695 | if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand)) { |
| 8696 | return; |
| 8697 | } |
| 8698 | var key = prop.key; |
| 8699 | var name; |
| 8700 | switch (key.type) { |
| 8701 | case "Identifier": |
| 8702 | name = key.name; |
| 8703 | break; |
| 8704 | case "Literal": |
| 8705 | name = String(key.value); |
| 8706 | break; |
| 8707 | default: |
| 8708 | return; |
| 8709 | } |
| 8710 | var kind = prop.kind; |
| 8711 | if (this.options.ecmaVersion >= 6) { |
| 8712 | if (name === "__proto__" && kind === "init") { |
| 8713 | if (propHash.proto) { |
| 8714 | if (refDestructuringErrors) { |
| 8715 | if (refDestructuringErrors.doubleProto < 0) { |
| 8716 | refDestructuringErrors.doubleProto = key.start; |
| 8717 | } |
| 8718 | } else { |
| 8719 | this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); |
| 8720 | } |
| 8721 | } |
| 8722 | propHash.proto = true; |
| 8723 | } |
| 8724 | return; |
| 8725 | } |
| 8726 | name = "$" + name; |
| 8727 | var other = propHash[name]; |
| 8728 | if (other) { |
| 8729 | var redefinition; |
| 8730 | if (kind === "init") { |
| 8731 | redefinition = this.strict && other.init || other.get || other.set; |
| 8732 | } else { |
| 8733 | redefinition = other.init || other[kind]; |
| 8734 | } |
| 8735 | if (redefinition) { |
| 8736 | this.raiseRecoverable(key.start, "Redefinition of property"); |
| 8737 | } |
| 8738 | } else { |
| 8739 | other = propHash[name] = { |
| 8740 | init: false, |
| 8741 | get: false, |
| 8742 | set: false |
| 8743 | }; |
| 8744 | } |
| 8745 | other[kind] = true; |
| 8746 | }; |
| 8747 | pp$5.parseExpression = function(forInit, refDestructuringErrors) { |
| 8748 | var this$1$1 = this; |
| 8749 | return this.catchStackOverflow(function() { |
| 8750 | var startPos = this$1$1.start, startLoc = this$1$1.startLoc; |
| 8751 | var expr = this$1$1.parseMaybeAssign(forInit, refDestructuringErrors); |
| 8752 | if (this$1$1.type === types$1.comma) { |
| 8753 | var node = this$1$1.startNodeAt(startPos, startLoc); |
| 8754 | node.expressions = [expr]; |
| 8755 | while (this$1$1.eat(types$1.comma)) { |
| 8756 | node.expressions.push(this$1$1.parseMaybeAssign(forInit, refDestructuringErrors)); |
| 8757 | } |
| 8758 | return this$1$1.finishNode(node, "SequenceExpression"); |
| 8759 | } |
| 8760 | return expr; |
| 8761 | }); |
| 8762 | }; |
| 8763 | pp$5.parseMaybeAssign = function(forInit, refDestructuringErrors, afterLeftParse) { |
| 8764 | if (this.isContextual("yield")) { |
| 8765 | if (this.inGenerator) { |
| 8766 | return this.parseYield(forInit); |
| 8767 | } else { |
| 8768 | this.exprAllowed = false; |
| 8769 | } |
| 8770 | } |
| 8771 | var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1, oldDoubleProto = -1; |
| 8772 | if (refDestructuringErrors) { |
| 8773 | oldParenAssign = refDestructuringErrors.parenthesizedAssign; |
| 8774 | oldTrailingComma = refDestructuringErrors.trailingComma; |
| 8775 | oldDoubleProto = refDestructuringErrors.doubleProto; |
| 8776 | refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1; |
| 8777 | } else { |
| 8778 | refDestructuringErrors = new DestructuringErrors(); |
| 8779 | ownDestructuringErrors = true; |
| 8780 | } |
| 8781 | var startPos = this.start, startLoc = this.startLoc; |
| 8782 | if (this.type === types$1.parenL || this.type === types$1.name) { |
| 8783 | this.potentialArrowAt = this.start; |
| 8784 | this.potentialArrowInForAwait = forInit === "await"; |
| 8785 | } |
| 8786 | var left = this.parseMaybeConditional(forInit, refDestructuringErrors); |
| 8787 | if (afterLeftParse) { |
| 8788 | left = afterLeftParse.call(this, left, startPos, startLoc); |
| 8789 | } |
| 8790 | if (this.type.isAssign) { |
| 8791 | var node = this.startNodeAt(startPos, startLoc); |
| 8792 | node.operator = this.value; |
| 8793 | if (this.type === types$1.eq) { |
| 8794 | left = this.toAssignable(left, false, refDestructuringErrors); |
| 8795 | } |
| 8796 | if (!ownDestructuringErrors) { |
| 8797 | refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = refDestructuringErrors.doubleProto = -1; |
| 8798 | } |
| 8799 | if (refDestructuringErrors.shorthandAssign >= left.start) { |
| 8800 | refDestructuringErrors.shorthandAssign = -1; |
| 8801 | } |
| 8802 | if (this.type === types$1.eq) { |
| 8803 | this.checkLValPattern(left); |
| 8804 | } else { |
| 8805 | this.checkLValSimple(left); |
| 8806 | } |
| 8807 | node.left = left; |
| 8808 | this.next(); |
| 8809 | node.right = this.parseMaybeAssign(forInit); |
| 8810 | if (oldDoubleProto > -1) { |
| 8811 | refDestructuringErrors.doubleProto = oldDoubleProto; |
| 8812 | } |
| 8813 | return this.finishNode(node, "AssignmentExpression"); |
| 8814 | } else { |
| 8815 | if (ownDestructuringErrors) { |
| 8816 | this.checkExpressionErrors(refDestructuringErrors, true); |
| 8817 | } |
| 8818 | } |
| 8819 | if (oldParenAssign > -1) { |
| 8820 | refDestructuringErrors.parenthesizedAssign = oldParenAssign; |
| 8821 | } |
| 8822 | if (oldTrailingComma > -1) { |
| 8823 | refDestructuringErrors.trailingComma = oldTrailingComma; |
| 8824 | } |
| 8825 | return left; |
| 8826 | }; |
| 8827 | pp$5.parseMaybeConditional = function(forInit, refDestructuringErrors) { |
| 8828 | var startPos = this.start, startLoc = this.startLoc; |
| 8829 | var expr = this.parseExprOps(forInit, refDestructuringErrors); |
| 8830 | if (this.checkExpressionErrors(refDestructuringErrors)) { |
| 8831 | return expr; |
| 8832 | } |
| 8833 | if (!(expr.type === "ArrowFunctionExpression" && expr.start === startPos) && this.eat(types$1.question)) { |
| 8834 | var node = this.startNodeAt(startPos, startLoc); |
| 8835 | node.test = expr; |
| 8836 | node.consequent = this.parseMaybeAssign(); |
| 8837 | this.expect(types$1.colon); |
| 8838 | node.alternate = this.parseMaybeAssign(forInit); |
| 8839 | return this.finishNode(node, "ConditionalExpression"); |
| 8840 | } |
| 8841 | return expr; |
| 8842 | }; |
| 8843 | pp$5.parseExprOps = function(forInit, refDestructuringErrors) { |
| 8844 | var startPos = this.start, startLoc = this.startLoc; |
| 8845 | var expr = this.parseMaybeUnary(refDestructuringErrors, false, false, forInit); |
| 8846 | if (this.checkExpressionErrors(refDestructuringErrors)) { |
| 8847 | return expr; |
| 8848 | } |
| 8849 | return expr.start === startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, forInit); |
| 8850 | }; |
| 8851 | pp$5.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, forInit) { |
| 8852 | var prec = this.type.binop; |
| 8853 | if (prec != null && (!forInit || this.type !== types$1._in)) { |
| 8854 | if (prec > minPrec) { |
| 8855 | var logical = this.type === types$1.logicalOR || this.type === types$1.logicalAND; |
| 8856 | var coalesce = this.type === types$1.coalesce; |
| 8857 | if (coalesce) { |
| 8858 | prec = types$1.logicalAND.binop; |
| 8859 | } |
| 8860 | var op = this.value; |
| 8861 | this.next(); |
| 8862 | var startPos = this.start, startLoc = this.startLoc; |
| 8863 | var right = this.parseExprOp(this.parseMaybeUnary(null, false, false, forInit), startPos, startLoc, prec, forInit); |
| 8864 | var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical || coalesce); |
| 8865 | if (logical && this.type === types$1.coalesce || coalesce && (this.type === types$1.logicalOR || this.type === types$1.logicalAND)) { |
| 8866 | this.raiseRecoverable(this.start, "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses"); |
| 8867 | } |
| 8868 | return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, forInit); |
| 8869 | } |
| 8870 | } |
| 8871 | return left; |
| 8872 | }; |
| 8873 | pp$5.buildBinary = function(startPos, startLoc, left, right, op, logical) { |
| 8874 | if (right.type === "PrivateIdentifier") { |
| 8875 | this.raise(right.start, "Private identifier can only be left side of binary expression"); |
| 8876 | } |
| 8877 | var node = this.startNodeAt(startPos, startLoc); |
| 8878 | node.left = left; |
| 8879 | node.operator = op; |
| 8880 | node.right = right; |
| 8881 | return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression"); |
| 8882 | }; |
| 8883 | pp$5.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec, forInit) { |
| 8884 | var startPos = this.start, startLoc = this.startLoc, expr; |
| 8885 | if (this.isContextual("await") && this.canAwait) { |
| 8886 | expr = this.parseAwait(forInit); |
| 8887 | sawUnary = true; |
| 8888 | } else if (this.type.prefix) { |
| 8889 | var node = this.startNode(), update = this.type === types$1.incDec; |
| 8890 | node.operator = this.value; |
| 8891 | node.prefix = true; |
| 8892 | this.next(); |
| 8893 | node.argument = this.parseMaybeUnary(null, true, update, forInit); |
| 8894 | this.checkExpressionErrors(refDestructuringErrors, true); |
| 8895 | if (update) { |
| 8896 | this.checkLValSimple(node.argument); |
| 8897 | } else if (this.strict && node.operator === "delete" && isLocalVariableAccess(node.argument)) { |
| 8898 | this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); |
| 8899 | } else if (node.operator === "delete" && isPrivateFieldAccess(node.argument)) { |
| 8900 | this.raiseRecoverable(node.start, "Private fields can not be deleted"); |
| 8901 | } else { |
| 8902 | sawUnary = true; |
| 8903 | } |
| 8904 | expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression"); |
| 8905 | } else if (!sawUnary && this.type === types$1.privateId) { |
| 8906 | if ((forInit || this.privateNameStack.length === 0) && this.options.checkPrivateFields) { |
| 8907 | this.unexpected(); |
| 8908 | } |
| 8909 | expr = this.parsePrivateIdent(); |
| 8910 | if (this.type !== types$1._in) { |
| 8911 | this.unexpected(); |
| 8912 | } |
| 8913 | } else { |
| 8914 | expr = this.parseExprSubscripts(refDestructuringErrors, forInit); |
| 8915 | if (this.checkExpressionErrors(refDestructuringErrors)) { |
| 8916 | return expr; |
| 8917 | } |
| 8918 | while (this.type.postfix && !this.canInsertSemicolon()) { |
| 8919 | var node$1 = this.startNodeAt(startPos, startLoc); |
| 8920 | node$1.operator = this.value; |
| 8921 | node$1.prefix = false; |
| 8922 | node$1.argument = expr; |
| 8923 | this.checkLValSimple(expr); |
| 8924 | this.next(); |
| 8925 | expr = this.finishNode(node$1, "UpdateExpression"); |
| 8926 | } |
| 8927 | } |
| 8928 | if (!incDec && !(expr.type === "ArrowFunctionExpression" && expr.start === startPos) && this.eat(types$1.starstar)) { |
| 8929 | if (sawUnary) { |
| 8930 | this.unexpected(this.lastTokStart); |
| 8931 | } else { |
| 8932 | return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false, false, forInit), "**", false); |
| 8933 | } |
| 8934 | } else { |
| 8935 | return expr; |
| 8936 | } |
| 8937 | }; |
| 8938 | pp$5.parseExprSubscripts = function(refDestructuringErrors, forInit) { |
| 8939 | var startPos = this.start, startLoc = this.startLoc; |
| 8940 | var expr = this.parseExprAtom(refDestructuringErrors, forInit); |
| 8941 | if (expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")") { |
| 8942 | return expr; |
| 8943 | } |
| 8944 | var result = this.parseSubscripts(expr, startPos, startLoc, false, forInit); |
| 8945 | if (refDestructuringErrors && result.type === "MemberExpression") { |
| 8946 | if (refDestructuringErrors.parenthesizedAssign >= result.start) { |
| 8947 | refDestructuringErrors.parenthesizedAssign = -1; |
| 8948 | } |
| 8949 | if (refDestructuringErrors.parenthesizedBind >= result.start) { |
| 8950 | refDestructuringErrors.parenthesizedBind = -1; |
| 8951 | } |
| 8952 | if (refDestructuringErrors.trailingComma >= result.start) { |
| 8953 | refDestructuringErrors.trailingComma = -1; |
| 8954 | } |
| 8955 | } |
| 8956 | return result; |
| 8957 | }; |
| 8958 | pp$5.parseSubscripts = function(base, startPos, startLoc, noCalls, forInit) { |
| 8959 | var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" && this.lastTokEnd === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 && this.potentialArrowAt === base.start; |
| 8960 | var optionalChained = false; |
| 8961 | while (true) { |
| 8962 | var element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit); |
| 8963 | if (element.optional) { |
| 8964 | optionalChained = true; |
| 8965 | } |
| 8966 | if (element === base || element.type === "ArrowFunctionExpression") { |
| 8967 | if (optionalChained) { |
| 8968 | var chainNode = this.startNodeAt(startPos, startLoc); |
| 8969 | chainNode.expression = element; |
| 8970 | element = this.finishNode(chainNode, "ChainExpression"); |
| 8971 | } |
| 8972 | return element; |
| 8973 | } |
| 8974 | base = element; |
| 8975 | } |
| 8976 | }; |
| 8977 | pp$5.shouldParseAsyncArrow = function() { |
| 8978 | return !this.canInsertSemicolon() && this.eat(types$1.arrow); |
| 8979 | }; |
| 8980 | pp$5.parseSubscriptAsyncArrow = function(startPos, startLoc, exprList, forInit) { |
| 8981 | return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, true, forInit); |
| 8982 | }; |
| 8983 | pp$5.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit) { |
| 8984 | var optionalSupported = this.options.ecmaVersion >= 11; |
| 8985 | var optional = optionalSupported && this.eat(types$1.questionDot); |
| 8986 | if (noCalls && optional) { |
| 8987 | this.raise(this.lastTokStart, "Optional chaining cannot appear in the callee of new expressions"); |
| 8988 | } |
| 8989 | var computed = this.eat(types$1.bracketL); |
| 8990 | if (computed || optional && this.type !== types$1.parenL && this.type !== types$1.backQuote || this.eat(types$1.dot)) { |
| 8991 | var node = this.startNodeAt(startPos, startLoc); |
| 8992 | node.object = base; |
| 8993 | if (computed) { |
| 8994 | node.property = this.parseExpression(); |
| 8995 | this.expect(types$1.bracketR); |
| 8996 | } else if (this.type === types$1.privateId && base.type !== "Super") { |
| 8997 | node.property = this.parsePrivateIdent(); |
| 8998 | } else { |
| 8999 | node.property = this.parseIdent(this.options.allowReserved !== "never"); |
| 9000 | } |
| 9001 | node.computed = !!computed; |
| 9002 | if (optionalSupported) { |
| 9003 | node.optional = optional; |
| 9004 | } |
| 9005 | base = this.finishNode(node, "MemberExpression"); |
| 9006 | } else if (!noCalls && this.eat(types$1.parenL)) { |
| 9007 | var refDestructuringErrors = new DestructuringErrors(), oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos; |
| 9008 | this.yieldPos = 0; |
| 9009 | this.awaitPos = 0; |
| 9010 | this.awaitIdentPos = 0; |
| 9011 | var exprList = this.parseExprList(types$1.parenR, this.options.ecmaVersion >= 8, false, refDestructuringErrors); |
| 9012 | if (maybeAsyncArrow && !optional && this.shouldParseAsyncArrow()) { |
| 9013 | this.checkPatternErrors(refDestructuringErrors, false); |
| 9014 | this.checkYieldAwaitInDefaultParams(); |
| 9015 | if (this.awaitIdentPos > 0) { |
| 9016 | this.raise(this.awaitIdentPos, "Cannot use 'await' as identifier inside an async function"); |
| 9017 | } |
| 9018 | this.yieldPos = oldYieldPos; |
| 9019 | this.awaitPos = oldAwaitPos; |
| 9020 | this.awaitIdentPos = oldAwaitIdentPos; |
| 9021 | return this.parseSubscriptAsyncArrow(startPos, startLoc, exprList, forInit); |
| 9022 | } |
| 9023 | this.checkExpressionErrors(refDestructuringErrors, true); |
| 9024 | this.yieldPos = oldYieldPos || this.yieldPos; |
| 9025 | this.awaitPos = oldAwaitPos || this.awaitPos; |
| 9026 | this.awaitIdentPos = oldAwaitIdentPos || this.awaitIdentPos; |
| 9027 | var node$1 = this.startNodeAt(startPos, startLoc); |
| 9028 | node$1.callee = base; |
| 9029 | node$1.arguments = exprList; |
| 9030 | if (optionalSupported) { |
| 9031 | node$1.optional = optional; |
| 9032 | } |
| 9033 | base = this.finishNode(node$1, "CallExpression"); |
| 9034 | } else if (this.type === types$1.backQuote) { |
| 9035 | if (optional || optionalChained) { |
| 9036 | this.raise(this.start, "Optional chaining cannot appear in the tag of tagged template expressions"); |
| 9037 | } |
| 9038 | var node$2 = this.startNodeAt(startPos, startLoc); |
| 9039 | node$2.tag = base; |
| 9040 | node$2.quasi = this.parseTemplate({ isTagged: true }); |
| 9041 | base = this.finishNode(node$2, "TaggedTemplateExpression"); |
| 9042 | } |
| 9043 | return base; |
| 9044 | }; |
| 9045 | pp$5.parseExprAtom = function(refDestructuringErrors, forInit, forNew) { |
| 9046 | if (this.type === types$1.slash) { |
| 9047 | this.readRegexp(); |
| 9048 | } |
| 9049 | var node, canBeArrow = this.potentialArrowAt === this.start; |
| 9050 | switch (this.type) { |
| 9051 | case types$1._super: |
| 9052 | if (!this.allowSuper) { |
| 9053 | this.raise(this.start, "'super' keyword outside a method"); |
| 9054 | } |
| 9055 | node = this.startNode(); |
| 9056 | this.next(); |
| 9057 | if (this.type === types$1.parenL && !this.allowDirectSuper) { |
| 9058 | this.raise(node.start, "super() call outside constructor of a subclass"); |
| 9059 | } |
| 9060 | if (this.type !== types$1.dot && this.type !== types$1.bracketL && this.type !== types$1.parenL) { |
| 9061 | this.unexpected(); |
| 9062 | } |
| 9063 | return this.finishNode(node, "Super"); |
| 9064 | case types$1._this: |
| 9065 | node = this.startNode(); |
| 9066 | this.next(); |
| 9067 | return this.finishNode(node, "ThisExpression"); |
| 9068 | case types$1.name: |
| 9069 | var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc; |
| 9070 | var id = this.parseIdent(false); |
| 9071 | if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(types$1._function)) { |
| 9072 | this.overrideContext(types2.f_expr); |
| 9073 | return this.parseFunction(this.startNodeAt(startPos, startLoc), 0, false, true, forInit); |
| 9074 | } |
| 9075 | if (canBeArrow && !this.canInsertSemicolon()) { |
| 9076 | if (this.eat(types$1.arrow)) { |
| 9077 | return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false, forInit); |
| 9078 | } |
| 9079 | if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types$1.name && !containsEsc && (!this.potentialArrowInForAwait || this.value !== "of" || this.containsEsc)) { |
| 9080 | id = this.parseIdent(false); |
| 9081 | if (this.canInsertSemicolon() || !this.eat(types$1.arrow)) { |
| 9082 | this.unexpected(); |
| 9083 | } |
| 9084 | return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true, forInit); |
| 9085 | } |
| 9086 | } |
| 9087 | return id; |
| 9088 | case types$1.regexp: |
| 9089 | var value = this.value; |
| 9090 | node = this.parseLiteral(value.value); |
| 9091 | node.regex = { pattern: value.pattern, flags: value.flags }; |
| 9092 | return node; |
| 9093 | case types$1.num: |
| 9094 | case types$1.string: |
| 9095 | return this.parseLiteral(this.value); |
| 9096 | case types$1._null: |
| 9097 | case types$1._true: |
| 9098 | case types$1._false: |
| 9099 | node = this.startNode(); |
| 9100 | node.value = this.type === types$1._null ? null : this.type === types$1._true; |
| 9101 | node.raw = this.type.keyword; |
| 9102 | this.next(); |
| 9103 | return this.finishNode(node, "Literal"); |
| 9104 | case types$1.parenL: |
| 9105 | var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow, forInit); |
| 9106 | if (refDestructuringErrors) { |
| 9107 | if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr)) { |
| 9108 | refDestructuringErrors.parenthesizedAssign = start; |
| 9109 | } |
| 9110 | if (refDestructuringErrors.parenthesizedBind < 0) { |
| 9111 | refDestructuringErrors.parenthesizedBind = start; |
| 9112 | } |
| 9113 | } |
| 9114 | return expr; |
| 9115 | case types$1.bracketL: |
| 9116 | node = this.startNode(); |
| 9117 | this.next(); |
| 9118 | node.elements = this.parseExprList(types$1.bracketR, true, true, refDestructuringErrors); |
| 9119 | return this.finishNode(node, "ArrayExpression"); |
| 9120 | case types$1.braceL: |
| 9121 | this.overrideContext(types2.b_expr); |
| 9122 | return this.parseObj(false, refDestructuringErrors); |
| 9123 | case types$1._function: |
| 9124 | node = this.startNode(); |
| 9125 | this.next(); |
| 9126 | return this.parseFunction(node, 0); |
| 9127 | case types$1._class: |
| 9128 | return this.parseClass(this.startNode(), false); |
| 9129 | case types$1._new: |
| 9130 | return this.parseNew(); |
| 9131 | case types$1.backQuote: |
| 9132 | return this.parseTemplate(); |
| 9133 | case types$1._import: |
| 9134 | if (this.options.ecmaVersion >= 11) { |
| 9135 | return this.parseExprImport(forNew); |
| 9136 | } else { |
| 9137 | return this.unexpected(); |
| 9138 | } |
| 9139 | default: |
| 9140 | return this.parseExprAtomDefault(); |
| 9141 | } |
| 9142 | }; |
| 9143 | pp$5.parseExprAtomDefault = function() { |
| 9144 | this.unexpected(); |
| 9145 | }; |
| 9146 | pp$5.parseExprImport = function(forNew) { |
| 9147 | var node = this.startNode(); |
| 9148 | if (this.containsEsc) { |
| 9149 | this.raiseRecoverable(this.start, "Escape sequence in keyword import"); |
| 9150 | } |
| 9151 | this.next(); |
| 9152 | if (this.type === types$1.parenL && !forNew) { |
| 9153 | return this.parseDynamicImport(node); |
| 9154 | } else if (this.type === types$1.dot) { |
| 9155 | var meta = this.startNodeAt(node.start, node.loc && node.loc.start); |
| 9156 | meta.name = "import"; |
| 9157 | node.meta = this.finishNode(meta, "Identifier"); |
| 9158 | return this.parseImportMeta(node); |
| 9159 | } else { |
| 9160 | this.unexpected(); |
| 9161 | } |
| 9162 | }; |
| 9163 | pp$5.parseDynamicImport = function(node) { |
| 9164 | this.next(); |
| 9165 | node.source = this.parseMaybeAssign(); |
| 9166 | if (this.options.ecmaVersion >= 16) { |
| 9167 | if (!this.eat(types$1.parenR)) { |
| 9168 | this.expect(types$1.comma); |
| 9169 | if (!this.afterTrailingComma(types$1.parenR)) { |
| 9170 | node.options = this.parseMaybeAssign(); |
| 9171 | if (!this.eat(types$1.parenR)) { |
| 9172 | this.expect(types$1.comma); |
| 9173 | if (!this.afterTrailingComma(types$1.parenR)) { |
| 9174 | this.unexpected(); |
| 9175 | } |
| 9176 | } |
| 9177 | } else { |
| 9178 | node.options = null; |
| 9179 | } |
| 9180 | } else { |
| 9181 | node.options = null; |
| 9182 | } |
| 9183 | } else { |
| 9184 | if (!this.eat(types$1.parenR)) { |
| 9185 | var errorPos = this.start; |
| 9186 | if (this.eat(types$1.comma) && this.eat(types$1.parenR)) { |
| 9187 | this.raiseRecoverable(errorPos, "Trailing comma is not allowed in import()"); |
| 9188 | } else { |
| 9189 | this.unexpected(errorPos); |
| 9190 | } |
| 9191 | } |
| 9192 | } |
| 9193 | return this.finishNode(node, "ImportExpression"); |
| 9194 | }; |
| 9195 | pp$5.parseImportMeta = function(node) { |
| 9196 | this.next(); |
| 9197 | var containsEsc = this.containsEsc; |
| 9198 | node.property = this.parseIdent(true); |
| 9199 | if (node.property.name !== "meta") { |
| 9200 | this.raiseRecoverable(node.property.start, "The only valid meta property for import is 'import.meta'"); |
| 9201 | } |
| 9202 | if (containsEsc) { |
| 9203 | this.raiseRecoverable(node.start, "'import.meta' must not contain escaped characters"); |
| 9204 | } |
| 9205 | if (this.options.sourceType !== "module" && !this.options.allowImportExportEverywhere) { |
| 9206 | this.raiseRecoverable(node.start, "Cannot use 'import.meta' outside a module"); |
| 9207 | } |
| 9208 | return this.finishNode(node, "MetaProperty"); |
| 9209 | }; |
| 9210 | pp$5.parseLiteral = function(value) { |
| 9211 | var node = this.startNode(); |
| 9212 | node.value = value; |
| 9213 | node.raw = this.input.slice(this.start, this.end); |
| 9214 | if (node.raw.charCodeAt(node.raw.length - 1) === 110) { |
| 9215 | node.bigint = node.value != null ? node.value.toString() : node.raw.slice(0, -1).replace(/_/g, ""); |
| 9216 | } |
| 9217 | this.next(); |
| 9218 | return this.finishNode(node, "Literal"); |
| 9219 | }; |
| 9220 | pp$5.parseParenExpression = function() { |
| 9221 | this.expect(types$1.parenL); |
| 9222 | var val = this.parseExpression(); |
| 9223 | this.expect(types$1.parenR); |
| 9224 | return val; |
| 9225 | }; |
| 9226 | pp$5.shouldParseArrow = function(exprList) { |
| 9227 | return !this.canInsertSemicolon(); |
| 9228 | }; |
| 9229 | pp$5.parseParenAndDistinguishExpression = function(canBeArrow, forInit) { |
| 9230 | var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8; |
| 9231 | if (this.options.ecmaVersion >= 6) { |
| 9232 | this.next(); |
| 9233 | var innerStartPos = this.start, innerStartLoc = this.startLoc; |
| 9234 | var exprList = [], first = true, lastIsComma = false; |
| 9235 | var refDestructuringErrors = new DestructuringErrors(), oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart; |
| 9236 | this.yieldPos = 0; |
| 9237 | this.awaitPos = 0; |
| 9238 | while (this.type !== types$1.parenR) { |
| 9239 | first ? first = false : this.expect(types$1.comma); |
| 9240 | if (allowTrailingComma && this.afterTrailingComma(types$1.parenR, true)) { |
| 9241 | lastIsComma = true; |
| 9242 | break; |
| 9243 | } else if (this.type === types$1.ellipsis) { |
| 9244 | spreadStart = this.start; |
| 9245 | exprList.push(this.parseParenItem(this.parseRestBinding())); |
| 9246 | if (this.type === types$1.comma) { |
| 9247 | this.raiseRecoverable( |
| 9248 | this.start, |
| 9249 | "Comma is not permitted after the rest element" |
| 9250 | ); |
| 9251 | } |
| 9252 | break; |
| 9253 | } else { |
| 9254 | exprList.push(this.parseMaybeAssign(false, refDestructuringErrors, this.parseParenItem)); |
| 9255 | } |
| 9256 | } |
| 9257 | var innerEndPos = this.lastTokEnd, innerEndLoc = this.lastTokEndLoc; |
| 9258 | this.expect(types$1.parenR); |
| 9259 | if (canBeArrow && this.shouldParseArrow(exprList) && this.eat(types$1.arrow)) { |
| 9260 | this.checkPatternErrors(refDestructuringErrors, false); |
| 9261 | this.checkYieldAwaitInDefaultParams(); |
| 9262 | this.yieldPos = oldYieldPos; |
| 9263 | this.awaitPos = oldAwaitPos; |
| 9264 | return this.parseParenArrowList(startPos, startLoc, exprList, forInit); |
| 9265 | } |
| 9266 | if (!exprList.length || lastIsComma) { |
| 9267 | this.unexpected(this.lastTokStart); |
| 9268 | } |
| 9269 | if (spreadStart) { |
| 9270 | this.unexpected(spreadStart); |
| 9271 | } |
| 9272 | this.checkExpressionErrors(refDestructuringErrors, true); |
| 9273 | this.yieldPos = oldYieldPos || this.yieldPos; |
| 9274 | this.awaitPos = oldAwaitPos || this.awaitPos; |
| 9275 | if (exprList.length > 1) { |
| 9276 | val = this.startNodeAt(innerStartPos, innerStartLoc); |
| 9277 | val.expressions = exprList; |
| 9278 | this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc); |
| 9279 | } else { |
| 9280 | val = exprList[0]; |
| 9281 | } |
| 9282 | } else { |
| 9283 | val = this.parseParenExpression(); |
| 9284 | } |
| 9285 | if (this.options.preserveParens) { |
| 9286 | var par = this.startNodeAt(startPos, startLoc); |
| 9287 | par.expression = val; |
| 9288 | return this.finishNode(par, "ParenthesizedExpression"); |
| 9289 | } else { |
| 9290 | return val; |
| 9291 | } |
| 9292 | }; |
| 9293 | pp$5.parseParenItem = function(item) { |
| 9294 | return item; |
| 9295 | }; |
| 9296 | pp$5.parseParenArrowList = function(startPos, startLoc, exprList, forInit) { |
| 9297 | return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, false, forInit); |
| 9298 | }; |
| 9299 | empty = []; |
| 9300 | pp$5.parseNew = function() { |
| 9301 | if (this.containsEsc) { |
| 9302 | this.raiseRecoverable(this.start, "Escape sequence in keyword new"); |
| 9303 | } |
| 9304 | var node = this.startNode(); |
| 9305 | this.next(); |
| 9306 | if (this.options.ecmaVersion >= 6 && this.type === types$1.dot) { |
| 9307 | var meta = this.startNodeAt(node.start, node.loc && node.loc.start); |
| 9308 | meta.name = "new"; |
| 9309 | node.meta = this.finishNode(meta, "Identifier"); |
| 9310 | this.next(); |
| 9311 | var containsEsc = this.containsEsc; |
| 9312 | node.property = this.parseIdent(true); |
| 9313 | if (node.property.name !== "target") { |
| 9314 | this.raiseRecoverable(node.property.start, "The only valid meta property for new is 'new.target'"); |
| 9315 | } |
| 9316 | if (containsEsc) { |
| 9317 | this.raiseRecoverable(node.start, "'new.target' must not contain escaped characters"); |
| 9318 | } |
| 9319 | if (!this.allowNewDotTarget) { |
| 9320 | this.raiseRecoverable(node.start, "'new.target' can only be used in functions and class static block"); |
| 9321 | } |
| 9322 | return this.finishNode(node, "MetaProperty"); |
| 9323 | } |
| 9324 | var startPos = this.start, startLoc = this.startLoc; |
| 9325 | node.callee = this.parseSubscripts(this.parseExprAtom(null, false, true), startPos, startLoc, true, false); |
| 9326 | if (node.callee.type === "Super") { |
| 9327 | this.raiseRecoverable(startPos, "Invalid use of 'super'"); |
| 9328 | } |
| 9329 | if (this.eat(types$1.parenL)) { |
| 9330 | node.arguments = this.parseExprList(types$1.parenR, this.options.ecmaVersion >= 8, false); |
| 9331 | } else { |
| 9332 | node.arguments = empty; |
| 9333 | } |
| 9334 | return this.finishNode(node, "NewExpression"); |
| 9335 | }; |
| 9336 | pp$5.parseTemplateElement = function(ref2) { |
| 9337 | var isTagged = ref2.isTagged; |
| 9338 | var elem = this.startNode(); |
| 9339 | if (this.type === types$1.invalidTemplate) { |
| 9340 | if (!isTagged) { |
| 9341 | this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal"); |
| 9342 | } |
| 9343 | elem.value = { |
| 9344 | raw: this.value.replace(/\r\n?/g, "\n"), |
| 9345 | cooked: null |
| 9346 | }; |
| 9347 | } else { |
| 9348 | elem.value = { |
| 9349 | raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"), |
| 9350 | cooked: this.value |
| 9351 | }; |
| 9352 | } |
| 9353 | this.next(); |
| 9354 | elem.tail = this.type === types$1.backQuote; |
| 9355 | return this.finishNode(elem, "TemplateElement"); |
| 9356 | }; |
| 9357 | pp$5.parseTemplate = function(ref2) { |
| 9358 | if (ref2 === void 0) ref2 = {}; |
| 9359 | var isTagged = ref2.isTagged; |
| 9360 | if (isTagged === void 0) isTagged = false; |
| 9361 | var node = this.startNode(); |
| 9362 | this.next(); |
| 9363 | node.expressions = []; |
| 9364 | var curElt = this.parseTemplateElement({ isTagged }); |
| 9365 | node.quasis = [curElt]; |
| 9366 | while (!curElt.tail) { |
| 9367 | if (this.type === types$1.eof) { |
| 9368 | this.raise(this.pos, "Unterminated template literal"); |
| 9369 | } |
| 9370 | this.expect(types$1.dollarBraceL); |
| 9371 | node.expressions.push(this.parseExpression()); |
| 9372 | this.expect(types$1.braceR); |
| 9373 | node.quasis.push(curElt = this.parseTemplateElement({ isTagged })); |
| 9374 | } |
| 9375 | this.next(); |
| 9376 | return this.finishNode(node, "TemplateLiteral"); |
| 9377 | }; |
| 9378 | pp$5.isAsyncProp = function(prop) { |
| 9379 | return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" && (this.type === types$1.name || this.type === types$1.num || this.type === types$1.string || this.type === types$1.bracketL || this.type.keyword || this.options.ecmaVersion >= 9 && this.type === types$1.star) && !lineBreak.test(this.input.slice(this.lastTokEnd, this.start)); |
| 9380 | }; |
| 9381 | pp$5.parseObj = function(isPattern, refDestructuringErrors) { |
| 9382 | var node = this.startNode(), first = true, propHash = {}; |
| 9383 | node.properties = []; |
| 9384 | this.next(); |
| 9385 | while (!this.eat(types$1.braceR)) { |
| 9386 | if (!first) { |
| 9387 | this.expect(types$1.comma); |
| 9388 | if (this.options.ecmaVersion >= 5 && this.afterTrailingComma(types$1.braceR)) { |
| 9389 | break; |
| 9390 | } |
| 9391 | } else { |
| 9392 | first = false; |
| 9393 | } |
| 9394 | var prop = this.parseProperty(isPattern, refDestructuringErrors); |
| 9395 | if (!isPattern) { |
| 9396 | this.checkPropClash(prop, propHash, refDestructuringErrors); |
| 9397 | } |
| 9398 | node.properties.push(prop); |
| 9399 | } |
| 9400 | return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression"); |
| 9401 | }; |
| 9402 | pp$5.parseProperty = function(isPattern, refDestructuringErrors) { |
| 9403 | var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc; |
| 9404 | if (this.options.ecmaVersion >= 9 && this.eat(types$1.ellipsis)) { |
| 9405 | if (isPattern) { |
| 9406 | prop.argument = this.parseIdent(false); |
| 9407 | if (this.type === types$1.comma) { |
| 9408 | this.raiseRecoverable(this.start, "Comma is not permitted after the rest element"); |
| 9409 | } |
| 9410 | return this.finishNode(prop, "RestElement"); |
| 9411 | } |
| 9412 | prop.argument = this.parseMaybeAssign(false, refDestructuringErrors); |
| 9413 | if (this.type === types$1.comma && refDestructuringErrors && refDestructuringErrors.trailingComma < 0) { |
| 9414 | refDestructuringErrors.trailingComma = this.start; |
| 9415 | } |
| 9416 | return this.finishNode(prop, "SpreadElement"); |
| 9417 | } |
| 9418 | if (this.options.ecmaVersion >= 6) { |
| 9419 | prop.method = false; |
| 9420 | prop.shorthand = false; |
| 9421 | if (isPattern || refDestructuringErrors) { |
| 9422 | startPos = this.start; |
| 9423 | startLoc = this.startLoc; |
| 9424 | } |
| 9425 | if (!isPattern) { |
| 9426 | isGenerator = this.eat(types$1.star); |
| 9427 | } |
| 9428 | } |
| 9429 | var containsEsc = this.containsEsc; |
| 9430 | this.parsePropertyName(prop); |
| 9431 | if (!isPattern && !containsEsc && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) { |
| 9432 | isAsync = true; |
| 9433 | isGenerator = this.options.ecmaVersion >= 9 && this.eat(types$1.star); |
| 9434 | this.parsePropertyName(prop); |
| 9435 | } else { |
| 9436 | isAsync = false; |
| 9437 | } |
| 9438 | this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc); |
| 9439 | return this.finishNode(prop, "Property"); |
| 9440 | }; |
| 9441 | pp$5.parseGetterSetter = function(prop) { |
| 9442 | var kind = prop.key.name; |
| 9443 | this.parsePropertyName(prop); |
| 9444 | prop.value = this.parseMethod(false); |
| 9445 | prop.kind = kind; |
| 9446 | var paramCount = prop.kind === "get" ? 0 : 1; |
| 9447 | if (prop.value.params.length !== paramCount) { |
| 9448 | var start = prop.value.start; |
| 9449 | if (prop.kind === "get") { |
| 9450 | this.raiseRecoverable(start, "getter should have no params"); |
| 9451 | } else { |
| 9452 | this.raiseRecoverable(start, "setter should have exactly one param"); |
| 9453 | } |
| 9454 | } else { |
| 9455 | if (prop.kind === "set" && prop.value.params[0].type === "RestElement") { |
| 9456 | this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); |
| 9457 | } |
| 9458 | } |
| 9459 | }; |
| 9460 | pp$5.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) { |
| 9461 | if ((isGenerator || isAsync) && this.type === types$1.colon) { |
| 9462 | this.unexpected(); |
| 9463 | } |
| 9464 | if (this.eat(types$1.colon)) { |
| 9465 | prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors); |
| 9466 | prop.kind = "init"; |
| 9467 | } else if (this.options.ecmaVersion >= 6 && this.type === types$1.parenL) { |
| 9468 | if (isPattern) { |
| 9469 | this.unexpected(); |
| 9470 | } |
| 9471 | prop.method = true; |
| 9472 | prop.value = this.parseMethod(isGenerator, isAsync); |
| 9473 | prop.kind = "init"; |
| 9474 | } else if (!isPattern && !containsEsc && this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" && (prop.key.name === "get" || prop.key.name === "set") && (this.type !== types$1.comma && this.type !== types$1.braceR && this.type !== types$1.eq)) { |
| 9475 | if (isGenerator || isAsync) { |
| 9476 | this.unexpected(); |
| 9477 | } |
| 9478 | this.parseGetterSetter(prop); |
| 9479 | } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") { |
| 9480 | if (isGenerator || isAsync) { |
| 9481 | this.unexpected(); |
| 9482 | } |
| 9483 | this.checkUnreserved(prop.key); |
| 9484 | if (prop.key.name === "await" && !this.awaitIdentPos) { |
| 9485 | this.awaitIdentPos = startPos; |
| 9486 | } |
| 9487 | if (isPattern) { |
| 9488 | prop.value = this.parseMaybeDefault(startPos, startLoc, this.copyNode(prop.key)); |
| 9489 | } else if (this.type === types$1.eq && refDestructuringErrors) { |
| 9490 | if (refDestructuringErrors.shorthandAssign < 0) { |
| 9491 | refDestructuringErrors.shorthandAssign = this.start; |
| 9492 | } |
| 9493 | prop.value = this.parseMaybeDefault(startPos, startLoc, this.copyNode(prop.key)); |
| 9494 | } else { |
| 9495 | prop.value = this.copyNode(prop.key); |
| 9496 | } |
| 9497 | prop.kind = "init"; |
| 9498 | prop.shorthand = true; |
| 9499 | } else { |
| 9500 | this.unexpected(); |
| 9501 | } |
| 9502 | }; |
| 9503 | pp$5.parsePropertyName = function(prop) { |
| 9504 | if (this.options.ecmaVersion >= 6) { |
| 9505 | if (this.eat(types$1.bracketL)) { |
| 9506 | prop.computed = true; |
| 9507 | prop.key = this.parseMaybeAssign(); |
| 9508 | this.expect(types$1.bracketR); |
| 9509 | return prop.key; |
| 9510 | } else { |
| 9511 | prop.computed = false; |
| 9512 | } |
| 9513 | } |
| 9514 | return prop.key = this.type === types$1.num || this.type === types$1.string ? this.parseExprAtom() : this.parseIdent(this.options.allowReserved !== "never"); |
| 9515 | }; |
| 9516 | pp$5.initFunction = function(node) { |
| 9517 | node.id = null; |
| 9518 | if (this.options.ecmaVersion >= 6) { |
| 9519 | node.generator = node.expression = false; |
| 9520 | } |
| 9521 | if (this.options.ecmaVersion >= 8) { |
| 9522 | node.async = false; |
| 9523 | } |
| 9524 | }; |
| 9525 | pp$5.parseMethod = function(isGenerator, isAsync, allowDirectSuper) { |
| 9526 | var node = this.startNode(), oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos; |
| 9527 | this.initFunction(node); |
| 9528 | if (this.options.ecmaVersion >= 6) { |
| 9529 | node.generator = isGenerator; |
| 9530 | } |
| 9531 | if (this.options.ecmaVersion >= 8) { |
| 9532 | node.async = !!isAsync; |
| 9533 | } |
| 9534 | this.yieldPos = 0; |
| 9535 | this.awaitPos = 0; |
| 9536 | this.awaitIdentPos = 0; |
| 9537 | this.enterScope(functionFlags(isAsync, node.generator) | SCOPE_SUPER | (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0)); |
| 9538 | this.expect(types$1.parenL); |
| 9539 | node.params = this.parseBindingList(types$1.parenR, false, this.options.ecmaVersion >= 8); |
| 9540 | this.checkYieldAwaitInDefaultParams(); |
| 9541 | this.parseFunctionBody(node, false, true, false); |
| 9542 | this.yieldPos = oldYieldPos; |
| 9543 | this.awaitPos = oldAwaitPos; |
| 9544 | this.awaitIdentPos = oldAwaitIdentPos; |
| 9545 | return this.finishNode(node, "FunctionExpression"); |
| 9546 | }; |
| 9547 | pp$5.parseArrowExpression = function(node, params, isAsync, forInit) { |
| 9548 | var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos; |
| 9549 | this.enterScope(functionFlags(isAsync, false) | SCOPE_ARROW); |
| 9550 | this.initFunction(node); |
| 9551 | if (this.options.ecmaVersion >= 8) { |
| 9552 | node.async = !!isAsync; |
| 9553 | } |
| 9554 | this.yieldPos = 0; |
| 9555 | this.awaitPos = 0; |
| 9556 | this.awaitIdentPos = 0; |
| 9557 | node.params = this.toAssignableList(params, true); |
| 9558 | this.parseFunctionBody(node, true, false, forInit); |
| 9559 | this.yieldPos = oldYieldPos; |
| 9560 | this.awaitPos = oldAwaitPos; |
| 9561 | this.awaitIdentPos = oldAwaitIdentPos; |
| 9562 | return this.finishNode(node, "ArrowFunctionExpression"); |
| 9563 | }; |
| 9564 | pp$5.parseFunctionBody = function(node, isArrowFunction, isMethod, forInit) { |
| 9565 | var isExpression = isArrowFunction && this.type !== types$1.braceL; |
| 9566 | var oldStrict = this.strict, useStrict = false; |
| 9567 | if (isExpression) { |
| 9568 | node.body = this.parseMaybeAssign(forInit); |
| 9569 | node.expression = true; |
| 9570 | this.checkParams(node, false); |
| 9571 | } else { |
| 9572 | var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params); |
| 9573 | if (!oldStrict || nonSimple) { |
| 9574 | useStrict = this.strictDirective(this.end); |
| 9575 | if (useStrict && nonSimple) { |
| 9576 | this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); |
| 9577 | } |
| 9578 | } |
| 9579 | var oldLabels = this.labels; |
| 9580 | this.labels = []; |
| 9581 | if (useStrict) { |
| 9582 | this.strict = true; |
| 9583 | } |
| 9584 | this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && !isMethod && this.isSimpleParamList(node.params)); |
| 9585 | if (this.strict && node.id) { |
| 9586 | this.checkLValSimple(node.id, BIND_OUTSIDE); |
| 9587 | } |
| 9588 | node.body = this.parseBlock(false, void 0, useStrict && !oldStrict); |
| 9589 | node.expression = false; |
| 9590 | this.adaptDirectivePrologue(node.body.body); |
| 9591 | this.labels = oldLabels; |
| 9592 | } |
| 9593 | this.exitScope(); |
| 9594 | }; |
| 9595 | pp$5.isSimpleParamList = function(params) { |
| 9596 | for (var i2 = 0, list2 = params; i2 < list2.length; i2 += 1) { |
| 9597 | var param = list2[i2]; |
| 9598 | if (param.type !== "Identifier") { |
| 9599 | return false; |
| 9600 | } |
| 9601 | } |
| 9602 | return true; |
| 9603 | }; |
| 9604 | pp$5.checkParams = function(node, allowDuplicates) { |
| 9605 | var nameHash = /* @__PURE__ */ Object.create(null); |
| 9606 | for (var i2 = 0, list2 = node.params; i2 < list2.length; i2 += 1) { |
| 9607 | var param = list2[i2]; |
| 9608 | this.checkLValInnerPattern(param, BIND_VAR, allowDuplicates ? null : nameHash); |
| 9609 | } |
| 9610 | }; |
| 9611 | pp$5.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) { |
| 9612 | var elts = [], first = true; |
| 9613 | while (!this.eat(close)) { |
| 9614 | if (!first) { |
| 9615 | this.expect(types$1.comma); |
| 9616 | if (allowTrailingComma && this.afterTrailingComma(close)) { |
| 9617 | break; |
| 9618 | } |
| 9619 | } else { |
| 9620 | first = false; |
| 9621 | } |
| 9622 | var elt = void 0; |
| 9623 | if (allowEmpty && this.type === types$1.comma) { |
| 9624 | elt = null; |
| 9625 | } else if (this.type === types$1.ellipsis) { |
| 9626 | elt = this.parseSpread(refDestructuringErrors); |
| 9627 | if (refDestructuringErrors && this.type === types$1.comma && refDestructuringErrors.trailingComma < 0) { |
| 9628 | refDestructuringErrors.trailingComma = this.start; |
| 9629 | } |
| 9630 | } else { |
| 9631 | elt = this.parseMaybeAssign(false, refDestructuringErrors); |
| 9632 | } |
| 9633 | elts.push(elt); |
| 9634 | } |
| 9635 | return elts; |
| 9636 | }; |
| 9637 | pp$5.checkUnreserved = function(ref2) { |
| 9638 | var start = ref2.start; |
| 9639 | var end = ref2.end; |
| 9640 | var name = ref2.name; |
| 9641 | if (this.inGenerator && name === "yield") { |
| 9642 | this.raiseRecoverable(start, "Cannot use 'yield' as identifier inside a generator"); |
| 9643 | } |
| 9644 | if (this.inAsync && name === "await") { |
| 9645 | this.raiseRecoverable(start, "Cannot use 'await' as identifier inside an async function"); |
| 9646 | } |
| 9647 | if (!(this.currentThisScope().flags & SCOPE_VAR) && name === "arguments") { |
| 9648 | this.raiseRecoverable(start, "Cannot use 'arguments' in class field initializer"); |
| 9649 | } |
| 9650 | if (this.inClassStaticBlock && (name === "arguments" || name === "await")) { |
| 9651 | this.raise(start, "Cannot use " + name + " in class static initialization block"); |
| 9652 | } |
| 9653 | if (this.keywords.test(name)) { |
| 9654 | this.raise(start, "Unexpected keyword '" + name + "'"); |
| 9655 | } |
| 9656 | if (this.options.ecmaVersion < 6 && this.input.slice(start, end).indexOf("\\") !== -1) { |
| 9657 | return; |
| 9658 | } |
| 9659 | var re = this.strict ? this.reservedWordsStrict : this.reservedWords; |
| 9660 | if (re.test(name)) { |
| 9661 | if (!this.inAsync && name === "await") { |
| 9662 | this.raiseRecoverable(start, "Cannot use keyword 'await' outside an async function"); |
| 9663 | } |
| 9664 | this.raiseRecoverable(start, "The keyword '" + name + "' is reserved"); |
| 9665 | } |
| 9666 | }; |
| 9667 | pp$5.parseIdent = function(liberal) { |
| 9668 | var node = this.parseIdentNode(); |
| 9669 | this.next(!!liberal); |
| 9670 | this.finishNode(node, "Identifier"); |
| 9671 | if (!liberal) { |
| 9672 | this.checkUnreserved(node); |
| 9673 | if (node.name === "await" && !this.awaitIdentPos) { |
| 9674 | this.awaitIdentPos = node.start; |
| 9675 | } |
| 9676 | } |
| 9677 | return node; |
| 9678 | }; |
| 9679 | pp$5.parseIdentNode = function() { |
| 9680 | var node = this.startNode(); |
| 9681 | if (this.type === types$1.name) { |
| 9682 | node.name = this.value; |
| 9683 | } else if (this.type.keyword) { |
| 9684 | node.name = this.type.keyword; |
| 9685 | if ((node.name === "class" || node.name === "function") && (this.lastTokEnd !== this.lastTokStart + 1 || this.input.charCodeAt(this.lastTokStart) !== 46)) { |
| 9686 | this.context.pop(); |
| 9687 | } |
| 9688 | this.type = types$1.name; |
| 9689 | } else { |
| 9690 | this.unexpected(); |
| 9691 | } |
| 9692 | return node; |
| 9693 | }; |
| 9694 | pp$5.parsePrivateIdent = function() { |
| 9695 | var node = this.startNode(); |
| 9696 | if (this.type === types$1.privateId) { |
| 9697 | node.name = this.value; |
| 9698 | } else { |
| 9699 | this.unexpected(); |
| 9700 | } |
| 9701 | this.next(); |
| 9702 | this.finishNode(node, "PrivateIdentifier"); |
| 9703 | if (this.options.checkPrivateFields) { |
| 9704 | if (this.privateNameStack.length === 0) { |
| 9705 | this.raise(node.start, "Private field '#" + node.name + "' must be declared in an enclosing class"); |
| 9706 | } else { |
| 9707 | this.privateNameStack[this.privateNameStack.length - 1].used.push(node); |
| 9708 | } |
| 9709 | } |
| 9710 | return node; |
| 9711 | }; |
| 9712 | pp$5.parseYield = function(forInit) { |
| 9713 | if (!this.yieldPos) { |
| 9714 | this.yieldPos = this.start; |
| 9715 | } |
| 9716 | var node = this.startNode(); |
| 9717 | this.next(); |
| 9718 | if (this.type === types$1.semi || this.canInsertSemicolon() || this.type !== types$1.star && !this.type.startsExpr) { |
| 9719 | node.delegate = false; |
| 9720 | node.argument = null; |
| 9721 | } else { |
| 9722 | node.delegate = this.eat(types$1.star); |
| 9723 | node.argument = this.parseMaybeAssign(forInit); |
| 9724 | } |
| 9725 | return this.finishNode(node, "YieldExpression"); |
| 9726 | }; |
| 9727 | pp$5.parseAwait = function(forInit) { |
| 9728 | if (!this.awaitPos) { |
| 9729 | this.awaitPos = this.start; |
| 9730 | } |
| 9731 | var node = this.startNode(); |
| 9732 | this.next(); |
| 9733 | node.argument = this.parseMaybeUnary(null, true, false, forInit); |
| 9734 | return this.finishNode(node, "AwaitExpression"); |
| 9735 | }; |
| 9736 | pp$4 = Parser.prototype; |
| 9737 | pp$4.raise = function(pos, message) { |
| 9738 | var loc = getLineInfo(this.input, pos); |
| 9739 | message += " (" + loc.line + ":" + loc.column + ")"; |
| 9740 | if (this.sourceFile) { |
| 9741 | message += " in " + this.sourceFile; |
| 9742 | } |
| 9743 | var err = new SyntaxError(message); |
| 9744 | err.pos = pos; |
| 9745 | err.loc = loc; |
| 9746 | err.raisedAt = this.pos; |
| 9747 | throw err; |
| 9748 | }; |
| 9749 | pp$4.raiseRecoverable = pp$4.raise; |
| 9750 | pp$4.curPosition = function() { |
| 9751 | if (this.options.locations) { |
| 9752 | return new Position(this.curLine, this.pos - this.lineStart); |
| 9753 | } |
| 9754 | }; |
| 9755 | pp$3 = Parser.prototype; |
| 9756 | Scope = function Scope2(flags) { |
| 9757 | this.flags = flags; |
| 9758 | this.var = []; |
| 9759 | this.lexical = []; |
| 9760 | this.functions = []; |
| 9761 | }; |
| 9762 | pp$3.enterScope = function(flags) { |
| 9763 | this.scopeStack.push(new Scope(flags)); |
| 9764 | }; |
| 9765 | pp$3.exitScope = function() { |
| 9766 | this.scopeStack.pop(); |
| 9767 | }; |
| 9768 | pp$3.treatFunctionsAsVarInScope = function(scope) { |
| 9769 | return scope.flags & SCOPE_FUNCTION || !this.inModule && scope.flags & SCOPE_TOP; |
| 9770 | }; |
| 9771 | pp$3.declareName = function(name, bindingType, pos) { |
| 9772 | var redeclared = false; |
| 9773 | if (bindingType === BIND_LEXICAL) { |
| 9774 | var scope = this.currentScope(); |
| 9775 | redeclared = scope.lexical.indexOf(name) > -1 || scope.functions.indexOf(name) > -1 || scope.var.indexOf(name) > -1; |
| 9776 | scope.lexical.push(name); |
| 9777 | if (this.inModule && scope.flags & SCOPE_TOP) { |
| 9778 | delete this.undefinedExports[name]; |
| 9779 | } |
| 9780 | } else if (bindingType === BIND_SIMPLE_CATCH) { |
| 9781 | var scope$1 = this.currentScope(); |
| 9782 | scope$1.lexical.push(name); |
| 9783 | } else if (bindingType === BIND_FUNCTION) { |
| 9784 | var scope$2 = this.currentScope(); |
| 9785 | if (this.treatFunctionsAsVar) { |
| 9786 | redeclared = scope$2.lexical.indexOf(name) > -1; |
| 9787 | } else { |
| 9788 | redeclared = scope$2.lexical.indexOf(name) > -1 || scope$2.var.indexOf(name) > -1; |
| 9789 | } |
| 9790 | scope$2.functions.push(name); |
| 9791 | } else { |
| 9792 | for (var i2 = this.scopeStack.length - 1; i2 >= 0; --i2) { |
| 9793 | var scope$3 = this.scopeStack[i2]; |
| 9794 | if (scope$3.lexical.indexOf(name) > -1 && !(scope$3.flags & SCOPE_SIMPLE_CATCH && scope$3.lexical[0] === name) || !this.treatFunctionsAsVarInScope(scope$3) && scope$3.functions.indexOf(name) > -1) { |
| 9795 | redeclared = true; |
| 9796 | break; |
| 9797 | } |
| 9798 | scope$3.var.push(name); |
| 9799 | if (this.inModule && scope$3.flags & SCOPE_TOP) { |
| 9800 | delete this.undefinedExports[name]; |
| 9801 | } |
| 9802 | if (scope$3.flags & SCOPE_VAR) { |
| 9803 | break; |
| 9804 | } |
| 9805 | } |
| 9806 | } |
| 9807 | if (redeclared) { |
| 9808 | this.raiseRecoverable(pos, "Identifier '" + name + "' has already been declared"); |
| 9809 | } |
| 9810 | }; |
| 9811 | pp$3.checkLocalExport = function(id) { |
| 9812 | if (this.scopeStack[0].lexical.indexOf(id.name) === -1 && this.scopeStack[0].var.indexOf(id.name) === -1) { |
| 9813 | this.undefinedExports[id.name] = id; |
| 9814 | } |
| 9815 | }; |
| 9816 | pp$3.currentScope = function() { |
| 9817 | return this.scopeStack[this.scopeStack.length - 1]; |
| 9818 | }; |
| 9819 | pp$3.currentVarScope = function() { |
| 9820 | for (var i2 = this.scopeStack.length - 1; ; i2--) { |
| 9821 | var scope = this.scopeStack[i2]; |
| 9822 | if (scope.flags & (SCOPE_VAR | SCOPE_CLASS_FIELD_INIT | SCOPE_CLASS_STATIC_BLOCK)) { |
| 9823 | return scope; |
| 9824 | } |
| 9825 | } |
| 9826 | }; |
| 9827 | pp$3.currentThisScope = function() { |
| 9828 | for (var i2 = this.scopeStack.length - 1; ; i2--) { |
| 9829 | var scope = this.scopeStack[i2]; |
| 9830 | if (scope.flags & (SCOPE_VAR | SCOPE_CLASS_FIELD_INIT | SCOPE_CLASS_STATIC_BLOCK) && !(scope.flags & SCOPE_ARROW)) { |
| 9831 | return scope; |
| 9832 | } |
| 9833 | } |
| 9834 | }; |
| 9835 | Node = function Node2(parser, pos, loc) { |
| 9836 | this.type = ""; |
| 9837 | this.start = pos; |
| 9838 | this.end = 0; |
| 9839 | if (parser.options.locations) { |
| 9840 | this.loc = new SourceLocation(parser, loc); |
| 9841 | } |
| 9842 | if (parser.options.directSourceFile) { |
| 9843 | this.sourceFile = parser.options.directSourceFile; |
| 9844 | } |
| 9845 | if (parser.options.ranges) { |
| 9846 | this.range = [pos, 0]; |
| 9847 | } |
| 9848 | }; |
| 9849 | pp$2 = Parser.prototype; |
| 9850 | pp$2.startNode = function() { |
| 9851 | return new Node(this, this.start, this.startLoc); |
| 9852 | }; |
| 9853 | pp$2.startNodeAt = function(pos, loc) { |
| 9854 | return new Node(this, pos, loc); |
| 9855 | }; |
| 9856 | pp$2.finishNode = function(node, type2) { |
| 9857 | return finishNodeAt.call(this, node, type2, this.lastTokEnd, this.lastTokEndLoc); |
| 9858 | }; |
| 9859 | pp$2.finishNodeAt = function(node, type2, pos, loc) { |
| 9860 | return finishNodeAt.call(this, node, type2, pos, loc); |
| 9861 | }; |
| 9862 | pp$2.copyNode = function(node) { |
| 9863 | var newNode = new Node(this, node.start, this.startLoc); |
| 9864 | for (var prop in node) { |
| 9865 | newNode[prop] = node[prop]; |
| 9866 | } |
| 9867 | return newNode; |
| 9868 | }; |
| 9869 | scriptValuesAddedInUnicode = "Berf Beria_Erfe Gara Garay Gukh Gurung_Khema Hrkt Katakana_Or_Hiragana Kawi Kirat_Rai Krai Nag_Mundari Nagm Ol_Onal Onao Sidetic Sidt Sunu Sunuwar Tai_Yo Tayo Todhri Todr Tolong_Siki Tols Tulu_Tigalari Tutg Unknown Zzzz"; |
| 9870 | ecma9BinaryProperties = "ASCII ASCII_Hex_Digit AHex Alphabetic Alpha Any Assigned Bidi_Control Bidi_C Bidi_Mirrored Bidi_M Case_Ignorable CI Cased Changes_When_Casefolded CWCF Changes_When_Casemapped CWCM Changes_When_Lowercased CWL Changes_When_NFKC_Casefolded CWKCF Changes_When_Titlecased CWT Changes_When_Uppercased CWU Dash Default_Ignorable_Code_Point DI Deprecated Dep Diacritic Dia Emoji Emoji_Component Emoji_Modifier Emoji_Modifier_Base Emoji_Presentation Extender Ext Grapheme_Base Gr_Base Grapheme_Extend Gr_Ext Hex_Digit Hex IDS_Binary_Operator IDSB IDS_Trinary_Operator IDST ID_Continue IDC ID_Start IDS Ideographic Ideo Join_Control Join_C Logical_Order_Exception LOE Lowercase Lower Math Noncharacter_Code_Point NChar Pattern_Syntax Pat_Syn Pattern_White_Space Pat_WS Quotation_Mark QMark Radical Regional_Indicator RI Sentence_Terminal STerm Soft_Dotted SD Terminal_Punctuation Term Unified_Ideograph UIdeo Uppercase Upper Variation_Selector VS White_Space space XID_Continue XIDC XID_Start XIDS"; |
| 9871 | ecma10BinaryProperties = ecma9BinaryProperties + " Extended_Pictographic"; |
| 9872 | ecma11BinaryProperties = ecma10BinaryProperties; |
| 9873 | ecma12BinaryProperties = ecma11BinaryProperties + " EBase EComp EMod EPres ExtPict"; |
| 9874 | ecma13BinaryProperties = ecma12BinaryProperties; |
| 9875 | ecma14BinaryProperties = ecma13BinaryProperties; |
| 9876 | unicodeBinaryProperties = { |
| 9877 | 9: ecma9BinaryProperties, |
| 9878 | 10: ecma10BinaryProperties, |
| 9879 | 11: ecma11BinaryProperties, |
| 9880 | 12: ecma12BinaryProperties, |
| 9881 | 13: ecma13BinaryProperties, |
| 9882 | 14: ecma14BinaryProperties |
| 9883 | }; |
| 9884 | ecma14BinaryPropertiesOfStrings = "Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Flag_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence RGI_Emoji"; |
| 9885 | unicodeBinaryPropertiesOfStrings = { |
| 9886 | 9: "", |
| 9887 | 10: "", |
| 9888 | 11: "", |
| 9889 | 12: "", |
| 9890 | 13: "", |
| 9891 | 14: ecma14BinaryPropertiesOfStrings |
| 9892 | }; |
| 9893 | unicodeGeneralCategoryValues = "Cased_Letter LC Close_Punctuation Pe Connector_Punctuation Pc Control Cc cntrl Currency_Symbol Sc Dash_Punctuation Pd Decimal_Number Nd digit Enclosing_Mark Me Final_Punctuation Pf Format Cf Initial_Punctuation Pi Letter L Letter_Number Nl Line_Separator Zl Lowercase_Letter Ll Mark M Combining_Mark Math_Symbol Sm Modifier_Letter Lm Modifier_Symbol Sk Nonspacing_Mark Mn Number N Open_Punctuation Ps Other C Other_Letter Lo Other_Number No Other_Punctuation Po Other_Symbol So Paragraph_Separator Zp Private_Use Co Punctuation P punct Separator Z Space_Separator Zs Spacing_Mark Mc Surrogate Cs Symbol S Titlecase_Letter Lt Unassigned Cn Uppercase_Letter Lu"; |
| 9894 | ecma9ScriptValues = "Adlam Adlm Ahom Anatolian_Hieroglyphs Hluw Arabic Arab Armenian Armn Avestan Avst Balinese Bali Bamum Bamu Bassa_Vah Bass Batak Batk Bengali Beng Bhaiksuki Bhks Bopomofo Bopo Brahmi Brah Braille Brai Buginese Bugi Buhid Buhd Canadian_Aboriginal Cans Carian Cari Caucasian_Albanian Aghb Chakma Cakm Cham Cham Cherokee Cher Common Zyyy Coptic Copt Qaac Cuneiform Xsux Cypriot Cprt Cyrillic Cyrl Deseret Dsrt Devanagari Deva Duployan Dupl Egyptian_Hieroglyphs Egyp Elbasan Elba Ethiopic Ethi Georgian Geor Glagolitic Glag Gothic Goth Grantha Gran Greek Grek Gujarati Gujr Gurmukhi Guru Han Hani Hangul Hang Hanunoo Hano Hatran Hatr Hebrew Hebr Hiragana Hira Imperial_Aramaic Armi Inherited Zinh Qaai Inscriptional_Pahlavi Phli Inscriptional_Parthian Prti Javanese Java Kaithi Kthi Kannada Knda Katakana Kana Kayah_Li Kali Kharoshthi Khar Khmer Khmr Khojki Khoj Khudawadi Sind Lao Laoo Latin Latn Lepcha Lepc Limbu Limb Linear_A Lina Linear_B Linb Lisu Lisu Lycian Lyci Lydian Lydi Mahajani Mahj Malayalam Mlym Mandaic Mand Manichaean Mani Marchen Marc Masaram_Gondi Gonm Meetei_Mayek Mtei Mende_Kikakui Mend Meroitic_Cursive Merc Meroitic_Hieroglyphs Mero Miao Plrd Modi Mongolian Mong Mro Mroo Multani Mult Myanmar Mymr Nabataean Nbat New_Tai_Lue Talu Newa Newa Nko Nkoo Nushu Nshu Ogham Ogam Ol_Chiki Olck Old_Hungarian Hung Old_Italic Ital Old_North_Arabian Narb Old_Permic Perm Old_Persian Xpeo Old_South_Arabian Sarb Old_Turkic Orkh Oriya Orya Osage Osge Osmanya Osma Pahawh_Hmong Hmng Palmyrene Palm Pau_Cin_Hau Pauc Phags_Pa Phag Phoenician Phnx Psalter_Pahlavi Phlp Rejang Rjng Runic Runr Samaritan Samr Saurashtra Saur Sharada Shrd Shavian Shaw Siddham Sidd SignWriting Sgnw Sinhala Sinh Sora_Sompeng Sora Soyombo Soyo Sundanese Sund Syloti_Nagri Sylo Syriac Syrc Tagalog Tglg Tagbanwa Tagb Tai_Le Tale Tai_Tham Lana Tai_Viet Tavt Takri Takr Tamil Taml Tangut Tang Telugu Telu Thaana Thaa Thai Thai Tibetan Tibt Tifinagh Tfng Tirhuta Tirh Ugaritic Ugar Vai Vaii Warang_Citi Wara Yi Yiii Zanabazar_Square Zanb"; |
| 9895 | ecma10ScriptValues = ecma9ScriptValues + " Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd"; |
| 9896 | ecma11ScriptValues = ecma10ScriptValues + " Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho"; |
| 9897 | ecma12ScriptValues = ecma11ScriptValues + " Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi"; |
| 9898 | ecma13ScriptValues = ecma12ScriptValues + " Cypro_Minoan Cpmn Old_Uyghur Ougr Tangsa Tnsa Toto Vithkuqi Vith"; |
| 9899 | ecma14ScriptValues = ecma13ScriptValues + " " + scriptValuesAddedInUnicode; |
| 9900 | unicodeScriptValues = { |
| 9901 | 9: ecma9ScriptValues, |
| 9902 | 10: ecma10ScriptValues, |
| 9903 | 11: ecma11ScriptValues, |
| 9904 | 12: ecma12ScriptValues, |
| 9905 | 13: ecma13ScriptValues, |
| 9906 | 14: ecma14ScriptValues |
| 9907 | }; |
| 9908 | data = {}; |
| 9909 | for (i = 0, list = [9, 10, 11, 12, 13, 14]; i < list.length; i += 1) { |
| 9910 | ecmaVersion = list[i]; |
| 9911 | buildUnicodeData(ecmaVersion); |
| 9912 | } |
| 9913 | pp$1 = Parser.prototype; |
| 9914 | BranchID = function BranchID2(parent, base) { |
| 9915 | this.parent = parent; |
| 9916 | this.base = base || this; |
| 9917 | }; |
| 9918 | BranchID.prototype.separatedFrom = function separatedFrom(alt) { |
| 9919 | for (var self = this; self; self = self.parent) { |
| 9920 | for (var other = alt; other; other = other.parent) { |
| 9921 | if (self.base === other.base && self !== other) { |
| 9922 | return true; |
| 9923 | } |
| 9924 | } |
| 9925 | } |
| 9926 | return false; |
| 9927 | }; |
| 9928 | BranchID.prototype.sibling = function sibling() { |
| 9929 | return new BranchID(this.parent, this.base); |
| 9930 | }; |
| 9931 | RegExpValidationState = function RegExpValidationState2(parser) { |
| 9932 | this.parser = parser; |
| 9933 | this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : "") + (parser.options.ecmaVersion >= 13 ? "d" : "") + (parser.options.ecmaVersion >= 15 ? "v" : ""); |
| 9934 | this.unicodeProperties = data[parser.options.ecmaVersion >= 14 ? 14 : parser.options.ecmaVersion]; |
| 9935 | this.source = ""; |
| 9936 | this.flags = ""; |
| 9937 | this.start = 0; |
| 9938 | this.switchU = false; |
| 9939 | this.switchV = false; |
| 9940 | this.switchN = false; |
| 9941 | this.pos = 0; |
| 9942 | this.lastIntValue = 0; |
| 9943 | this.lastStringValue = ""; |
| 9944 | this.lastAssertionIsQuantifiable = false; |
| 9945 | this.numCapturingParens = 0; |
| 9946 | this.maxBackReference = 0; |
| 9947 | this.groupNames = /* @__PURE__ */ Object.create(null); |
| 9948 | this.backReferenceNames = []; |
| 9949 | this.branchID = null; |
| 9950 | }; |
| 9951 | RegExpValidationState.prototype.reset = function reset(start, pattern, flags) { |
| 9952 | var unicodeSets = flags.indexOf("v") !== -1; |
| 9953 | var unicode = flags.indexOf("u") !== -1; |
| 9954 | this.start = start | 0; |
| 9955 | this.source = pattern + ""; |
| 9956 | this.flags = flags; |
| 9957 | if (unicodeSets && this.parser.options.ecmaVersion >= 15) { |
| 9958 | this.switchU = true; |
| 9959 | this.switchV = true; |
| 9960 | this.switchN = true; |
| 9961 | } else { |
| 9962 | this.switchU = unicode && this.parser.options.ecmaVersion >= 6; |
| 9963 | this.switchV = false; |
| 9964 | this.switchN = unicode && this.parser.options.ecmaVersion >= 9; |
| 9965 | } |
| 9966 | }; |
| 9967 | RegExpValidationState.prototype.raise = function raise(message) { |
| 9968 | this.parser.raiseRecoverable(this.start, "Invalid regular expression: /" + this.source + "/: " + message); |
| 9969 | }; |
| 9970 | RegExpValidationState.prototype.at = function at(i2, forceU) { |
| 9971 | if (forceU === void 0) forceU = false; |
| 9972 | var s = this.source; |
| 9973 | var l = s.length; |
| 9974 | if (i2 >= l) { |
| 9975 | return -1; |
| 9976 | } |
| 9977 | var c = s.charCodeAt(i2); |
| 9978 | if (!(forceU || this.switchU) || c <= 55295 || c >= 57344 || i2 + 1 >= l) { |
| 9979 | return c; |
| 9980 | } |
| 9981 | var next = s.charCodeAt(i2 + 1); |
| 9982 | return next >= 56320 && next <= 57343 ? (c << 10) + next - 56613888 : c; |
| 9983 | }; |
| 9984 | RegExpValidationState.prototype.nextIndex = function nextIndex(i2, forceU) { |
| 9985 | if (forceU === void 0) forceU = false; |
| 9986 | var s = this.source; |
| 9987 | var l = s.length; |
| 9988 | if (i2 >= l) { |
| 9989 | return l; |
| 9990 | } |
| 9991 | var c = s.charCodeAt(i2), next; |
| 9992 | if (!(forceU || this.switchU) || c <= 55295 || c >= 57344 || i2 + 1 >= l || (next = s.charCodeAt(i2 + 1)) < 56320 || next > 57343) { |
| 9993 | return i2 + 1; |
| 9994 | } |
| 9995 | return i2 + 2; |
| 9996 | }; |
| 9997 | RegExpValidationState.prototype.current = function current(forceU) { |
| 9998 | if (forceU === void 0) forceU = false; |
| 9999 | return this.at(this.pos, forceU); |
| 10000 | }; |
| 10001 | RegExpValidationState.prototype.lookahead = function lookahead(forceU) { |
| 10002 | if (forceU === void 0) forceU = false; |
| 10003 | return this.at(this.nextIndex(this.pos, forceU), forceU); |
| 10004 | }; |
| 10005 | RegExpValidationState.prototype.advance = function advance(forceU) { |
| 10006 | if (forceU === void 0) forceU = false; |
| 10007 | this.pos = this.nextIndex(this.pos, forceU); |
| 10008 | }; |
| 10009 | RegExpValidationState.prototype.eat = function eat(ch, forceU) { |
| 10010 | if (forceU === void 0) forceU = false; |
| 10011 | if (this.current(forceU) === ch) { |
| 10012 | this.advance(forceU); |
| 10013 | return true; |
| 10014 | } |
| 10015 | return false; |
| 10016 | }; |
| 10017 | RegExpValidationState.prototype.eatChars = function eatChars(chs, forceU) { |
| 10018 | if (forceU === void 0) forceU = false; |
| 10019 | var pos = this.pos; |
| 10020 | for (var i2 = 0, list2 = chs; i2 < list2.length; i2 += 1) { |
| 10021 | var ch = list2[i2]; |
| 10022 | var current2 = this.at(pos, forceU); |
| 10023 | if (current2 === -1 || current2 !== ch) { |
| 10024 | return false; |
| 10025 | } |
| 10026 | pos = this.nextIndex(pos, forceU); |
| 10027 | } |
| 10028 | this.pos = pos; |
| 10029 | return true; |
| 10030 | }; |
| 10031 | pp$1.validateRegExpFlags = function(state) { |
| 10032 | var validFlags = state.validFlags; |
| 10033 | var flags = state.flags; |
| 10034 | var u = false; |
| 10035 | var v = false; |
| 10036 | for (var i2 = 0; i2 < flags.length; i2++) { |
| 10037 | var flag = flags.charAt(i2); |
| 10038 | if (validFlags.indexOf(flag) === -1) { |
| 10039 | this.raise(state.start, "Invalid regular expression flag"); |
| 10040 | } |
| 10041 | if (flags.indexOf(flag, i2 + 1) > -1) { |
| 10042 | this.raise(state.start, "Duplicate regular expression flag"); |
| 10043 | } |
| 10044 | if (flag === "u") { |
| 10045 | u = true; |
| 10046 | } |
| 10047 | if (flag === "v") { |
| 10048 | v = true; |
| 10049 | } |
| 10050 | } |
| 10051 | if (this.options.ecmaVersion >= 15 && u && v) { |
| 10052 | this.raise(state.start, "Invalid regular expression flag"); |
| 10053 | } |
| 10054 | }; |
| 10055 | pp$1.validateRegExpPattern = function(state) { |
| 10056 | this.regexp_pattern(state); |
| 10057 | if (!state.switchN && this.options.ecmaVersion >= 9 && hasProp(state.groupNames)) { |
| 10058 | state.switchN = true; |
| 10059 | this.regexp_pattern(state); |
| 10060 | } |
| 10061 | }; |
| 10062 | pp$1.regexp_pattern = function(state) { |
| 10063 | state.pos = 0; |
| 10064 | state.lastIntValue = 0; |
| 10065 | state.lastStringValue = ""; |
| 10066 | state.lastAssertionIsQuantifiable = false; |
| 10067 | state.numCapturingParens = 0; |
| 10068 | state.maxBackReference = 0; |
| 10069 | state.groupNames = /* @__PURE__ */ Object.create(null); |
| 10070 | state.backReferenceNames.length = 0; |
| 10071 | state.branchID = null; |
| 10072 | this.regexp_disjunction(state); |
| 10073 | if (state.pos !== state.source.length) { |
| 10074 | if (state.eat( |
| 10075 | 41 |
| 10076 | /* ) */ |
| 10077 | )) { |
| 10078 | state.raise("Unmatched ')'"); |
| 10079 | } |
| 10080 | if (state.eat( |
| 10081 | 93 |
| 10082 | /* ] */ |
| 10083 | ) || state.eat( |
| 10084 | 125 |
| 10085 | /* } */ |
| 10086 | )) { |
| 10087 | state.raise("Lone quantifier brackets"); |
| 10088 | } |
| 10089 | } |
| 10090 | if (state.maxBackReference > state.numCapturingParens) { |
| 10091 | state.raise("Invalid escape"); |
| 10092 | } |
| 10093 | for (var i2 = 0, list2 = state.backReferenceNames; i2 < list2.length; i2 += 1) { |
| 10094 | var name = list2[i2]; |
| 10095 | if (!state.groupNames[name]) { |
| 10096 | state.raise("Invalid named capture referenced"); |
| 10097 | } |
| 10098 | } |
| 10099 | }; |
| 10100 | pp$1.regexp_disjunction = function(state) { |
| 10101 | var trackDisjunction = this.options.ecmaVersion >= 16; |
| 10102 | if (trackDisjunction) { |
| 10103 | state.branchID = new BranchID(state.branchID, null); |
| 10104 | } |
| 10105 | this.regexp_alternative(state); |
| 10106 | while (state.eat( |
| 10107 | 124 |
| 10108 | /* | */ |
| 10109 | )) { |
| 10110 | if (trackDisjunction) { |
| 10111 | state.branchID = state.branchID.sibling(); |
| 10112 | } |
| 10113 | this.regexp_alternative(state); |
| 10114 | } |
| 10115 | if (trackDisjunction) { |
| 10116 | state.branchID = state.branchID.parent; |
| 10117 | } |
| 10118 | if (this.regexp_eatQuantifier(state, true)) { |
| 10119 | state.raise("Nothing to repeat"); |
| 10120 | } |
| 10121 | if (state.eat( |
| 10122 | 123 |
| 10123 | /* { */ |
| 10124 | )) { |
| 10125 | state.raise("Lone quantifier brackets"); |
| 10126 | } |
| 10127 | }; |
| 10128 | pp$1.regexp_alternative = function(state) { |
| 10129 | while (state.pos < state.source.length && this.regexp_eatTerm(state)) { |
| 10130 | } |
| 10131 | }; |
| 10132 | pp$1.regexp_eatTerm = function(state) { |
| 10133 | if (this.regexp_eatAssertion(state)) { |
| 10134 | if (state.lastAssertionIsQuantifiable && this.regexp_eatQuantifier(state)) { |
| 10135 | if (state.switchU) { |
| 10136 | state.raise("Invalid quantifier"); |
| 10137 | } |
| 10138 | } |
| 10139 | return true; |
| 10140 | } |
| 10141 | if (state.switchU ? this.regexp_eatAtom(state) : this.regexp_eatExtendedAtom(state)) { |
| 10142 | this.regexp_eatQuantifier(state); |
| 10143 | return true; |
| 10144 | } |
| 10145 | return false; |
| 10146 | }; |
| 10147 | pp$1.regexp_eatAssertion = function(state) { |
| 10148 | var start = state.pos; |
| 10149 | state.lastAssertionIsQuantifiable = false; |
| 10150 | if (state.eat( |
| 10151 | 94 |
| 10152 | /* ^ */ |
| 10153 | ) || state.eat( |
| 10154 | 36 |
| 10155 | /* $ */ |
| 10156 | )) { |
| 10157 | return true; |
| 10158 | } |
| 10159 | if (state.eat( |
| 10160 | 92 |
| 10161 | /* \ */ |
| 10162 | )) { |
| 10163 | if (state.eat( |
| 10164 | 66 |
| 10165 | /* B */ |
| 10166 | ) || state.eat( |
| 10167 | 98 |
| 10168 | /* b */ |
| 10169 | )) { |
| 10170 | return true; |
| 10171 | } |
| 10172 | state.pos = start; |
| 10173 | } |
| 10174 | if (state.eat( |
| 10175 | 40 |
| 10176 | /* ( */ |
| 10177 | ) && state.eat( |
| 10178 | 63 |
| 10179 | /* ? */ |
| 10180 | )) { |
| 10181 | var lookbehind = false; |
| 10182 | if (this.options.ecmaVersion >= 9) { |
| 10183 | lookbehind = state.eat( |
| 10184 | 60 |
| 10185 | /* < */ |
| 10186 | ); |
| 10187 | } |
| 10188 | if (state.eat( |
| 10189 | 61 |
| 10190 | /* = */ |
| 10191 | ) || state.eat( |
| 10192 | 33 |
| 10193 | /* ! */ |
| 10194 | )) { |
| 10195 | this.regexp_disjunction(state); |
| 10196 | if (!state.eat( |
| 10197 | 41 |
| 10198 | /* ) */ |
| 10199 | )) { |
| 10200 | state.raise("Unterminated group"); |
| 10201 | } |
| 10202 | state.lastAssertionIsQuantifiable = !lookbehind; |
| 10203 | return true; |
| 10204 | } |
| 10205 | } |
| 10206 | state.pos = start; |
| 10207 | return false; |
| 10208 | }; |
| 10209 | pp$1.regexp_eatQuantifier = function(state, noError) { |
| 10210 | if (noError === void 0) noError = false; |
| 10211 | if (this.regexp_eatQuantifierPrefix(state, noError)) { |
| 10212 | state.eat( |
| 10213 | 63 |
| 10214 | /* ? */ |
| 10215 | ); |
| 10216 | return true; |
| 10217 | } |
| 10218 | return false; |
| 10219 | }; |
| 10220 | pp$1.regexp_eatQuantifierPrefix = function(state, noError) { |
| 10221 | return state.eat( |
| 10222 | 42 |
| 10223 | /* * */ |
| 10224 | ) || state.eat( |
| 10225 | 43 |
| 10226 | /* + */ |
| 10227 | ) || state.eat( |
| 10228 | 63 |
| 10229 | /* ? */ |
| 10230 | ) || this.regexp_eatBracedQuantifier(state, noError); |
| 10231 | }; |
| 10232 | pp$1.regexp_eatBracedQuantifier = function(state, noError) { |
| 10233 | var start = state.pos; |
| 10234 | if (state.eat( |
| 10235 | 123 |
| 10236 | /* { */ |
| 10237 | )) { |
| 10238 | var min = 0, max = -1; |
| 10239 | if (this.regexp_eatDecimalDigits(state)) { |
| 10240 | min = state.lastIntValue; |
| 10241 | if (state.eat( |
| 10242 | 44 |
| 10243 | /* , */ |
| 10244 | ) && this.regexp_eatDecimalDigits(state)) { |
| 10245 | max = state.lastIntValue; |
| 10246 | } |
| 10247 | if (state.eat( |
| 10248 | 125 |
| 10249 | /* } */ |
| 10250 | )) { |
| 10251 | if (max !== -1 && max < min && !noError) { |
| 10252 | state.raise("numbers out of order in {} quantifier"); |
| 10253 | } |
| 10254 | return true; |
| 10255 | } |
| 10256 | } |
| 10257 | if (state.switchU && !noError) { |
| 10258 | state.raise("Incomplete quantifier"); |
| 10259 | } |
| 10260 | state.pos = start; |
| 10261 | } |
| 10262 | return false; |
| 10263 | }; |
| 10264 | pp$1.regexp_eatAtom = function(state) { |
| 10265 | return this.regexp_eatPatternCharacters(state) || state.eat( |
| 10266 | 46 |
| 10267 | /* . */ |
| 10268 | ) || this.regexp_eatReverseSolidusAtomEscape(state) || this.regexp_eatCharacterClass(state) || this.regexp_eatUncapturingGroup(state) || this.regexp_eatCapturingGroup(state); |
| 10269 | }; |
| 10270 | pp$1.regexp_eatReverseSolidusAtomEscape = function(state) { |
| 10271 | var start = state.pos; |
| 10272 | if (state.eat( |
| 10273 | 92 |
| 10274 | /* \ */ |
| 10275 | )) { |
| 10276 | if (this.regexp_eatAtomEscape(state)) { |
| 10277 | return true; |
| 10278 | } |
| 10279 | state.pos = start; |
| 10280 | } |
| 10281 | return false; |
| 10282 | }; |
| 10283 | pp$1.regexp_eatUncapturingGroup = function(state) { |
| 10284 | var start = state.pos; |
| 10285 | if (state.eat( |
| 10286 | 40 |
| 10287 | /* ( */ |
| 10288 | )) { |
| 10289 | if (state.eat( |
| 10290 | 63 |
| 10291 | /* ? */ |
| 10292 | )) { |
| 10293 | if (this.options.ecmaVersion >= 16) { |
| 10294 | var addModifiers = this.regexp_eatModifiers(state); |
| 10295 | var hasHyphen = state.eat( |
| 10296 | 45 |
| 10297 | /* - */ |
| 10298 | ); |
| 10299 | if (addModifiers || hasHyphen) { |
| 10300 | for (var i2 = 0; i2 < addModifiers.length; i2++) { |
| 10301 | var modifier = addModifiers.charAt(i2); |
| 10302 | if (addModifiers.indexOf(modifier, i2 + 1) > -1) { |
| 10303 | state.raise("Duplicate regular expression modifiers"); |
| 10304 | } |
| 10305 | } |
| 10306 | if (hasHyphen) { |
| 10307 | var removeModifiers = this.regexp_eatModifiers(state); |
| 10308 | if (!addModifiers && !removeModifiers && state.current() === 58) { |
| 10309 | state.raise("Invalid regular expression modifiers"); |
| 10310 | } |
| 10311 | for (var i$1 = 0; i$1 < removeModifiers.length; i$1++) { |
| 10312 | var modifier$1 = removeModifiers.charAt(i$1); |
| 10313 | if (removeModifiers.indexOf(modifier$1, i$1 + 1) > -1 || addModifiers.indexOf(modifier$1) > -1) { |
| 10314 | state.raise("Duplicate regular expression modifiers"); |
| 10315 | } |
| 10316 | } |
| 10317 | } |
| 10318 | } |
| 10319 | } |
| 10320 | if (state.eat( |
| 10321 | 58 |
| 10322 | /* : */ |
| 10323 | )) { |
| 10324 | this.regexp_disjunction(state); |
| 10325 | if (state.eat( |
| 10326 | 41 |
| 10327 | /* ) */ |
| 10328 | )) { |
| 10329 | return true; |
| 10330 | } |
| 10331 | state.raise("Unterminated group"); |
| 10332 | } |
| 10333 | } |
| 10334 | state.pos = start; |
| 10335 | } |
| 10336 | return false; |
| 10337 | }; |
| 10338 | pp$1.regexp_eatCapturingGroup = function(state) { |
| 10339 | if (state.eat( |
| 10340 | 40 |
| 10341 | /* ( */ |
| 10342 | )) { |
| 10343 | if (this.options.ecmaVersion >= 9) { |
| 10344 | this.regexp_groupSpecifier(state); |
| 10345 | } else if (state.current() === 63) { |
| 10346 | state.raise("Invalid group"); |
| 10347 | } |
| 10348 | this.regexp_disjunction(state); |
| 10349 | if (state.eat( |
| 10350 | 41 |
| 10351 | /* ) */ |
| 10352 | )) { |
| 10353 | state.numCapturingParens += 1; |
| 10354 | return true; |
| 10355 | } |
| 10356 | state.raise("Unterminated group"); |
| 10357 | } |
| 10358 | return false; |
| 10359 | }; |
| 10360 | pp$1.regexp_eatModifiers = function(state) { |
| 10361 | var modifiers = ""; |
| 10362 | var ch = 0; |
| 10363 | while ((ch = state.current()) !== -1 && isRegularExpressionModifier(ch)) { |
| 10364 | modifiers += codePointToString(ch); |
| 10365 | state.advance(); |
| 10366 | } |
| 10367 | return modifiers; |
| 10368 | }; |
| 10369 | pp$1.regexp_eatExtendedAtom = function(state) { |
| 10370 | return state.eat( |
| 10371 | 46 |
| 10372 | /* . */ |
| 10373 | ) || this.regexp_eatReverseSolidusAtomEscape(state) || this.regexp_eatCharacterClass(state) || this.regexp_eatUncapturingGroup(state) || this.regexp_eatCapturingGroup(state) || this.regexp_eatInvalidBracedQuantifier(state) || this.regexp_eatExtendedPatternCharacter(state); |
| 10374 | }; |
| 10375 | pp$1.regexp_eatInvalidBracedQuantifier = function(state) { |
| 10376 | if (this.regexp_eatBracedQuantifier(state, true)) { |
| 10377 | state.raise("Nothing to repeat"); |
| 10378 | } |
| 10379 | return false; |
| 10380 | }; |
| 10381 | pp$1.regexp_eatSyntaxCharacter = function(state) { |
| 10382 | var ch = state.current(); |
| 10383 | if (isSyntaxCharacter(ch)) { |
| 10384 | state.lastIntValue = ch; |
| 10385 | state.advance(); |
| 10386 | return true; |
| 10387 | } |
| 10388 | return false; |
| 10389 | }; |
| 10390 | pp$1.regexp_eatPatternCharacters = function(state) { |
| 10391 | var start = state.pos; |
| 10392 | var ch = 0; |
| 10393 | while ((ch = state.current()) !== -1 && !isSyntaxCharacter(ch)) { |
| 10394 | state.advance(); |
| 10395 | } |
| 10396 | return state.pos !== start; |
| 10397 | }; |
| 10398 | pp$1.regexp_eatExtendedPatternCharacter = function(state) { |
| 10399 | var ch = state.current(); |
| 10400 | if (ch !== -1 && ch !== 36 && !(ch >= 40 && ch <= 43) && ch !== 46 && ch !== 63 && ch !== 91 && ch !== 94 && ch !== 124) { |
| 10401 | state.advance(); |
| 10402 | return true; |
| 10403 | } |
| 10404 | return false; |
| 10405 | }; |
| 10406 | pp$1.regexp_groupSpecifier = function(state) { |
| 10407 | if (state.eat( |
| 10408 | 63 |
| 10409 | /* ? */ |
| 10410 | )) { |
| 10411 | if (!this.regexp_eatGroupName(state)) { |
| 10412 | state.raise("Invalid group"); |
| 10413 | } |
| 10414 | var trackDisjunction = this.options.ecmaVersion >= 16; |
| 10415 | var known = state.groupNames[state.lastStringValue]; |
| 10416 | if (known) { |
| 10417 | if (trackDisjunction) { |
| 10418 | for (var i2 = 0, list2 = known; i2 < list2.length; i2 += 1) { |
| 10419 | var altID = list2[i2]; |
| 10420 | if (!altID.separatedFrom(state.branchID)) { |
| 10421 | state.raise("Duplicate capture group name"); |
| 10422 | } |
| 10423 | } |
| 10424 | } else { |
| 10425 | state.raise("Duplicate capture group name"); |
| 10426 | } |
| 10427 | } |
| 10428 | if (trackDisjunction) { |
| 10429 | (known || (state.groupNames[state.lastStringValue] = [])).push(state.branchID); |
| 10430 | } else { |
| 10431 | state.groupNames[state.lastStringValue] = true; |
| 10432 | } |
| 10433 | } |
| 10434 | }; |
| 10435 | pp$1.regexp_eatGroupName = function(state) { |
| 10436 | state.lastStringValue = ""; |
| 10437 | if (state.eat( |
| 10438 | 60 |
| 10439 | /* < */ |
| 10440 | )) { |
| 10441 | if (this.regexp_eatRegExpIdentifierName(state) && state.eat( |
| 10442 | 62 |
| 10443 | /* > */ |
| 10444 | )) { |
| 10445 | return true; |
| 10446 | } |
| 10447 | state.raise("Invalid capture group name"); |
| 10448 | } |
| 10449 | return false; |
| 10450 | }; |
| 10451 | pp$1.regexp_eatRegExpIdentifierName = function(state) { |
| 10452 | state.lastStringValue = ""; |
| 10453 | if (this.regexp_eatRegExpIdentifierStart(state)) { |
| 10454 | state.lastStringValue += codePointToString(state.lastIntValue); |
| 10455 | while (this.regexp_eatRegExpIdentifierPart(state)) { |
| 10456 | state.lastStringValue += codePointToString(state.lastIntValue); |
| 10457 | } |
| 10458 | return true; |
| 10459 | } |
| 10460 | return false; |
| 10461 | }; |
| 10462 | pp$1.regexp_eatRegExpIdentifierStart = function(state) { |
| 10463 | var start = state.pos; |
| 10464 | var forceU = this.options.ecmaVersion >= 11; |
| 10465 | var ch = state.current(forceU); |
| 10466 | state.advance(forceU); |
| 10467 | if (ch === 92 && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) { |
| 10468 | ch = state.lastIntValue; |
| 10469 | } |
| 10470 | if (isRegExpIdentifierStart(ch)) { |
| 10471 | state.lastIntValue = ch; |
| 10472 | return true; |
| 10473 | } |
| 10474 | state.pos = start; |
| 10475 | return false; |
| 10476 | }; |
| 10477 | pp$1.regexp_eatRegExpIdentifierPart = function(state) { |
| 10478 | var start = state.pos; |
| 10479 | var forceU = this.options.ecmaVersion >= 11; |
| 10480 | var ch = state.current(forceU); |
| 10481 | state.advance(forceU); |
| 10482 | if (ch === 92 && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) { |
| 10483 | ch = state.lastIntValue; |
| 10484 | } |
| 10485 | if (isRegExpIdentifierPart(ch)) { |
| 10486 | state.lastIntValue = ch; |
| 10487 | return true; |
| 10488 | } |
| 10489 | state.pos = start; |
| 10490 | return false; |
| 10491 | }; |
| 10492 | pp$1.regexp_eatAtomEscape = function(state) { |
| 10493 | if (this.regexp_eatBackReference(state) || this.regexp_eatCharacterClassEscape(state) || this.regexp_eatCharacterEscape(state) || state.switchN && this.regexp_eatKGroupName(state)) { |
| 10494 | return true; |
| 10495 | } |
| 10496 | if (state.switchU) { |
| 10497 | if (state.current() === 99) { |
| 10498 | state.raise("Invalid unicode escape"); |
| 10499 | } |
| 10500 | state.raise("Invalid escape"); |
| 10501 | } |
| 10502 | return false; |
| 10503 | }; |
| 10504 | pp$1.regexp_eatBackReference = function(state) { |
| 10505 | var start = state.pos; |
| 10506 | if (this.regexp_eatDecimalEscape(state)) { |
| 10507 | var n = state.lastIntValue; |
| 10508 | if (state.switchU) { |
| 10509 | if (n > state.maxBackReference) { |
| 10510 | state.maxBackReference = n; |
| 10511 | } |
| 10512 | return true; |
| 10513 | } |
| 10514 | if (n <= state.numCapturingParens) { |
| 10515 | return true; |
| 10516 | } |
| 10517 | state.pos = start; |
| 10518 | } |
| 10519 | return false; |
| 10520 | }; |
| 10521 | pp$1.regexp_eatKGroupName = function(state) { |
| 10522 | if (state.eat( |
| 10523 | 107 |
| 10524 | /* k */ |
| 10525 | )) { |
| 10526 | if (this.regexp_eatGroupName(state)) { |
| 10527 | state.backReferenceNames.push(state.lastStringValue); |
| 10528 | return true; |
| 10529 | } |
| 10530 | state.raise("Invalid named reference"); |
| 10531 | } |
| 10532 | return false; |
| 10533 | }; |
| 10534 | pp$1.regexp_eatCharacterEscape = function(state) { |
| 10535 | return this.regexp_eatControlEscape(state) || this.regexp_eatCControlLetter(state) || this.regexp_eatZero(state) || this.regexp_eatHexEscapeSequence(state) || this.regexp_eatRegExpUnicodeEscapeSequence(state, false) || !state.switchU && this.regexp_eatLegacyOctalEscapeSequence(state) || this.regexp_eatIdentityEscape(state); |
| 10536 | }; |
| 10537 | pp$1.regexp_eatCControlLetter = function(state) { |
| 10538 | var start = state.pos; |
| 10539 | if (state.eat( |
| 10540 | 99 |
| 10541 | /* c */ |
| 10542 | )) { |
| 10543 | if (this.regexp_eatControlLetter(state)) { |
| 10544 | return true; |
| 10545 | } |
| 10546 | state.pos = start; |
| 10547 | } |
| 10548 | return false; |
| 10549 | }; |
| 10550 | pp$1.regexp_eatZero = function(state) { |
| 10551 | if (state.current() === 48 && !isDecimalDigit(state.lookahead())) { |
| 10552 | state.lastIntValue = 0; |
| 10553 | state.advance(); |
| 10554 | return true; |
| 10555 | } |
| 10556 | return false; |
| 10557 | }; |
| 10558 | pp$1.regexp_eatControlEscape = function(state) { |
| 10559 | var ch = state.current(); |
| 10560 | if (ch === 116) { |
| 10561 | state.lastIntValue = 9; |
| 10562 | state.advance(); |
| 10563 | return true; |
| 10564 | } |
| 10565 | if (ch === 110) { |
| 10566 | state.lastIntValue = 10; |
| 10567 | state.advance(); |
| 10568 | return true; |
| 10569 | } |
| 10570 | if (ch === 118) { |
| 10571 | state.lastIntValue = 11; |
| 10572 | state.advance(); |
| 10573 | return true; |
| 10574 | } |
| 10575 | if (ch === 102) { |
| 10576 | state.lastIntValue = 12; |
| 10577 | state.advance(); |
| 10578 | return true; |
| 10579 | } |
| 10580 | if (ch === 114) { |
| 10581 | state.lastIntValue = 13; |
| 10582 | state.advance(); |
| 10583 | return true; |
| 10584 | } |
| 10585 | return false; |
| 10586 | }; |
| 10587 | pp$1.regexp_eatControlLetter = function(state) { |
| 10588 | var ch = state.current(); |
| 10589 | if (isControlLetter(ch)) { |
| 10590 | state.lastIntValue = ch % 32; |
| 10591 | state.advance(); |
| 10592 | return true; |
| 10593 | } |
| 10594 | return false; |
| 10595 | }; |
| 10596 | pp$1.regexp_eatRegExpUnicodeEscapeSequence = function(state, forceU) { |
| 10597 | if (forceU === void 0) forceU = false; |
| 10598 | var start = state.pos; |
| 10599 | var switchU = forceU || state.switchU; |
| 10600 | if (state.eat( |
| 10601 | 117 |
| 10602 | /* u */ |
| 10603 | )) { |
| 10604 | if (this.regexp_eatFixedHexDigits(state, 4)) { |
| 10605 | var lead = state.lastIntValue; |
| 10606 | if (switchU && lead >= 55296 && lead <= 56319) { |
| 10607 | var leadSurrogateEnd = state.pos; |
| 10608 | if (state.eat( |
| 10609 | 92 |
| 10610 | /* \ */ |
| 10611 | ) && state.eat( |
| 10612 | 117 |
| 10613 | /* u */ |
| 10614 | ) && this.regexp_eatFixedHexDigits(state, 4)) { |
| 10615 | var trail = state.lastIntValue; |
| 10616 | if (trail >= 56320 && trail <= 57343) { |
| 10617 | state.lastIntValue = (lead - 55296) * 1024 + (trail - 56320) + 65536; |
| 10618 | return true; |
| 10619 | } |
| 10620 | } |
| 10621 | state.pos = leadSurrogateEnd; |
| 10622 | state.lastIntValue = lead; |
| 10623 | } |
| 10624 | return true; |
| 10625 | } |
| 10626 | if (switchU && state.eat( |
| 10627 | 123 |
| 10628 | /* { */ |
| 10629 | ) && this.regexp_eatHexDigits(state) && state.eat( |
| 10630 | 125 |
| 10631 | /* } */ |
| 10632 | ) && isValidUnicode(state.lastIntValue)) { |
| 10633 | return true; |
| 10634 | } |
| 10635 | if (switchU) { |
| 10636 | state.raise("Invalid unicode escape"); |
| 10637 | } |
| 10638 | state.pos = start; |
| 10639 | } |
| 10640 | return false; |
| 10641 | }; |
| 10642 | pp$1.regexp_eatIdentityEscape = function(state) { |
| 10643 | if (state.switchU) { |
| 10644 | if (this.regexp_eatSyntaxCharacter(state)) { |
| 10645 | return true; |
| 10646 | } |
| 10647 | if (state.eat( |
| 10648 | 47 |
| 10649 | /* / */ |
| 10650 | )) { |
| 10651 | state.lastIntValue = 47; |
| 10652 | return true; |
| 10653 | } |
| 10654 | return false; |
| 10655 | } |
| 10656 | var ch = state.current(); |
| 10657 | if (ch !== 99 && (!state.switchN || ch !== 107)) { |
| 10658 | state.lastIntValue = ch; |
| 10659 | state.advance(); |
| 10660 | return true; |
| 10661 | } |
| 10662 | return false; |
| 10663 | }; |
| 10664 | pp$1.regexp_eatDecimalEscape = function(state) { |
| 10665 | state.lastIntValue = 0; |
| 10666 | var ch = state.current(); |
| 10667 | if (ch >= 49 && ch <= 57) { |
| 10668 | do { |
| 10669 | state.lastIntValue = 10 * state.lastIntValue + (ch - 48); |
| 10670 | state.advance(); |
| 10671 | } while ((ch = state.current()) >= 48 && ch <= 57); |
| 10672 | return true; |
| 10673 | } |
| 10674 | return false; |
| 10675 | }; |
| 10676 | CharSetNone = 0; |
| 10677 | CharSetOk = 1; |
| 10678 | CharSetString = 2; |
| 10679 | pp$1.regexp_eatCharacterClassEscape = function(state) { |
| 10680 | var ch = state.current(); |
| 10681 | if (isCharacterClassEscape(ch)) { |
| 10682 | state.lastIntValue = -1; |
| 10683 | state.advance(); |
| 10684 | return CharSetOk; |
| 10685 | } |
| 10686 | var negate = false; |
| 10687 | if (state.switchU && this.options.ecmaVersion >= 9 && ((negate = ch === 80) || ch === 112)) { |
| 10688 | state.lastIntValue = -1; |
| 10689 | state.advance(); |
| 10690 | var result; |
| 10691 | if (state.eat( |
| 10692 | 123 |
| 10693 | /* { */ |
| 10694 | ) && (result = this.regexp_eatUnicodePropertyValueExpression(state)) && state.eat( |
| 10695 | 125 |
| 10696 | /* } */ |
| 10697 | )) { |
| 10698 | if (negate && result === CharSetString) { |
| 10699 | state.raise("Invalid property name"); |
| 10700 | } |
| 10701 | return result; |
| 10702 | } |
| 10703 | state.raise("Invalid property name"); |
| 10704 | } |
| 10705 | return CharSetNone; |
| 10706 | }; |
| 10707 | pp$1.regexp_eatUnicodePropertyValueExpression = function(state) { |
| 10708 | var start = state.pos; |
| 10709 | if (this.regexp_eatUnicodePropertyName(state) && state.eat( |
| 10710 | 61 |
| 10711 | /* = */ |
| 10712 | )) { |
| 10713 | var name = state.lastStringValue; |
| 10714 | if (this.regexp_eatUnicodePropertyValue(state)) { |
| 10715 | var value = state.lastStringValue; |
| 10716 | this.regexp_validateUnicodePropertyNameAndValue(state, name, value); |
| 10717 | return CharSetOk; |
| 10718 | } |
| 10719 | } |
| 10720 | state.pos = start; |
| 10721 | if (this.regexp_eatLoneUnicodePropertyNameOrValue(state)) { |
| 10722 | var nameOrValue = state.lastStringValue; |
| 10723 | return this.regexp_validateUnicodePropertyNameOrValue(state, nameOrValue); |
| 10724 | } |
| 10725 | return CharSetNone; |
| 10726 | }; |
| 10727 | pp$1.regexp_validateUnicodePropertyNameAndValue = function(state, name, value) { |
| 10728 | if (!hasOwn(state.unicodeProperties.nonBinary, name)) { |
| 10729 | state.raise("Invalid property name"); |
| 10730 | } |
| 10731 | if (!state.unicodeProperties.nonBinary[name].test(value)) { |
| 10732 | state.raise("Invalid property value"); |
| 10733 | } |
| 10734 | }; |
| 10735 | pp$1.regexp_validateUnicodePropertyNameOrValue = function(state, nameOrValue) { |
| 10736 | if (state.unicodeProperties.binary.test(nameOrValue)) { |
| 10737 | return CharSetOk; |
| 10738 | } |
| 10739 | if (state.switchV && state.unicodeProperties.binaryOfStrings.test(nameOrValue)) { |
| 10740 | return CharSetString; |
| 10741 | } |
| 10742 | state.raise("Invalid property name"); |
| 10743 | }; |
| 10744 | pp$1.regexp_eatUnicodePropertyName = function(state) { |
| 10745 | var ch = 0; |
| 10746 | state.lastStringValue = ""; |
| 10747 | while (isUnicodePropertyNameCharacter(ch = state.current())) { |
| 10748 | state.lastStringValue += codePointToString(ch); |
| 10749 | state.advance(); |
| 10750 | } |
| 10751 | return state.lastStringValue !== ""; |
| 10752 | }; |
| 10753 | pp$1.regexp_eatUnicodePropertyValue = function(state) { |
| 10754 | var ch = 0; |
| 10755 | state.lastStringValue = ""; |
| 10756 | while (isUnicodePropertyValueCharacter(ch = state.current())) { |
| 10757 | state.lastStringValue += codePointToString(ch); |
| 10758 | state.advance(); |
| 10759 | } |
| 10760 | return state.lastStringValue !== ""; |
| 10761 | }; |
| 10762 | pp$1.regexp_eatLoneUnicodePropertyNameOrValue = function(state) { |
| 10763 | return this.regexp_eatUnicodePropertyValue(state); |
| 10764 | }; |
| 10765 | pp$1.regexp_eatCharacterClass = function(state) { |
| 10766 | if (state.eat( |
| 10767 | 91 |
| 10768 | /* [ */ |
| 10769 | )) { |
| 10770 | var negate = state.eat( |
| 10771 | 94 |
| 10772 | /* ^ */ |
| 10773 | ); |
| 10774 | var result = this.regexp_classContents(state); |
| 10775 | if (!state.eat( |
| 10776 | 93 |
| 10777 | /* ] */ |
| 10778 | )) { |
| 10779 | state.raise("Unterminated character class"); |
| 10780 | } |
| 10781 | if (negate && result === CharSetString) { |
| 10782 | state.raise("Negated character class may contain strings"); |
| 10783 | } |
| 10784 | return true; |
| 10785 | } |
| 10786 | return false; |
| 10787 | }; |
| 10788 | pp$1.regexp_classContents = function(state) { |
| 10789 | if (state.current() === 93) { |
| 10790 | return CharSetOk; |
| 10791 | } |
| 10792 | if (state.switchV) { |
| 10793 | return this.regexp_classSetExpression(state); |
| 10794 | } |
| 10795 | this.regexp_nonEmptyClassRanges(state); |
| 10796 | return CharSetOk; |
| 10797 | }; |
| 10798 | pp$1.regexp_nonEmptyClassRanges = function(state) { |
| 10799 | while (this.regexp_eatClassAtom(state)) { |
| 10800 | var left = state.lastIntValue; |
| 10801 | if (state.eat( |
| 10802 | 45 |
| 10803 | /* - */ |
| 10804 | ) && this.regexp_eatClassAtom(state)) { |
| 10805 | var right = state.lastIntValue; |
| 10806 | if (state.switchU && (left === -1 || right === -1)) { |
| 10807 | state.raise("Invalid character class"); |
| 10808 | } |
| 10809 | if (left !== -1 && right !== -1 && left > right) { |
| 10810 | state.raise("Range out of order in character class"); |
| 10811 | } |
| 10812 | } |
| 10813 | } |
| 10814 | }; |
| 10815 | pp$1.regexp_eatClassAtom = function(state) { |
| 10816 | var start = state.pos; |
| 10817 | if (state.eat( |
| 10818 | 92 |
| 10819 | /* \ */ |
| 10820 | )) { |
| 10821 | if (this.regexp_eatClassEscape(state)) { |
| 10822 | return true; |
| 10823 | } |
| 10824 | if (state.switchU) { |
| 10825 | var ch$1 = state.current(); |
| 10826 | if (ch$1 === 99 || isOctalDigit(ch$1)) { |
| 10827 | state.raise("Invalid class escape"); |
| 10828 | } |
| 10829 | state.raise("Invalid escape"); |
| 10830 | } |
| 10831 | state.pos = start; |
| 10832 | } |
| 10833 | var ch = state.current(); |
| 10834 | if (ch !== 93) { |
| 10835 | state.lastIntValue = ch; |
| 10836 | state.advance(); |
| 10837 | return true; |
| 10838 | } |
| 10839 | return false; |
| 10840 | }; |
| 10841 | pp$1.regexp_eatClassEscape = function(state) { |
| 10842 | var start = state.pos; |
| 10843 | if (state.eat( |
| 10844 | 98 |
| 10845 | /* b */ |
| 10846 | )) { |
| 10847 | state.lastIntValue = 8; |
| 10848 | return true; |
| 10849 | } |
| 10850 | if (state.switchU && state.eat( |
| 10851 | 45 |
| 10852 | /* - */ |
| 10853 | )) { |
| 10854 | state.lastIntValue = 45; |
| 10855 | return true; |
| 10856 | } |
| 10857 | if (!state.switchU && state.eat( |
| 10858 | 99 |
| 10859 | /* c */ |
| 10860 | )) { |
| 10861 | if (this.regexp_eatClassControlLetter(state)) { |
| 10862 | return true; |
| 10863 | } |
| 10864 | state.pos = start; |
| 10865 | } |
| 10866 | return this.regexp_eatCharacterClassEscape(state) || this.regexp_eatCharacterEscape(state); |
| 10867 | }; |
| 10868 | pp$1.regexp_classSetExpression = function(state) { |
| 10869 | var result = CharSetOk, subResult; |
| 10870 | if (this.regexp_eatClassSetRange(state)) ; |
| 10871 | else if (subResult = this.regexp_eatClassSetOperand(state)) { |
| 10872 | if (subResult === CharSetString) { |
| 10873 | result = CharSetString; |
| 10874 | } |
| 10875 | var start = state.pos; |
| 10876 | while (state.eatChars( |
| 10877 | [38, 38] |
| 10878 | /* && */ |
| 10879 | )) { |
| 10880 | if (state.current() !== 38 && (subResult = this.regexp_eatClassSetOperand(state))) { |
| 10881 | if (subResult !== CharSetString) { |
| 10882 | result = CharSetOk; |
| 10883 | } |
| 10884 | continue; |
| 10885 | } |
| 10886 | state.raise("Invalid character in character class"); |
| 10887 | } |
| 10888 | if (start !== state.pos) { |
| 10889 | return result; |
| 10890 | } |
| 10891 | while (state.eatChars( |
| 10892 | [45, 45] |
| 10893 | /* -- */ |
| 10894 | )) { |
| 10895 | if (this.regexp_eatClassSetOperand(state)) { |
| 10896 | continue; |
| 10897 | } |
| 10898 | state.raise("Invalid character in character class"); |
| 10899 | } |
| 10900 | if (start !== state.pos) { |
| 10901 | return result; |
| 10902 | } |
| 10903 | } else { |
| 10904 | state.raise("Invalid character in character class"); |
| 10905 | } |
| 10906 | for (; ; ) { |
| 10907 | if (this.regexp_eatClassSetRange(state)) { |
| 10908 | continue; |
| 10909 | } |
| 10910 | subResult = this.regexp_eatClassSetOperand(state); |
| 10911 | if (!subResult) { |
| 10912 | return result; |
| 10913 | } |
| 10914 | if (subResult === CharSetString) { |
| 10915 | result = CharSetString; |
| 10916 | } |
| 10917 | } |
| 10918 | }; |
| 10919 | pp$1.regexp_eatClassSetRange = function(state) { |
| 10920 | var start = state.pos; |
| 10921 | if (this.regexp_eatClassSetCharacter(state)) { |
| 10922 | var left = state.lastIntValue; |
| 10923 | if (state.eat( |
| 10924 | 45 |
| 10925 | /* - */ |
| 10926 | ) && this.regexp_eatClassSetCharacter(state)) { |
| 10927 | var right = state.lastIntValue; |
| 10928 | if (left !== -1 && right !== -1 && left > right) { |
| 10929 | state.raise("Range out of order in character class"); |
| 10930 | } |
| 10931 | return true; |
| 10932 | } |
| 10933 | state.pos = start; |
| 10934 | } |
| 10935 | return false; |
| 10936 | }; |
| 10937 | pp$1.regexp_eatClassSetOperand = function(state) { |
| 10938 | if (this.regexp_eatClassSetCharacter(state)) { |
| 10939 | return CharSetOk; |
| 10940 | } |
| 10941 | return this.regexp_eatClassStringDisjunction(state) || this.regexp_eatNestedClass(state); |
| 10942 | }; |
| 10943 | pp$1.regexp_eatNestedClass = function(state) { |
| 10944 | var start = state.pos; |
| 10945 | if (state.eat( |
| 10946 | 91 |
| 10947 | /* [ */ |
| 10948 | )) { |
| 10949 | var negate = state.eat( |
| 10950 | 94 |
| 10951 | /* ^ */ |
| 10952 | ); |
| 10953 | var result = this.regexp_classContents(state); |
| 10954 | if (state.eat( |
| 10955 | 93 |
| 10956 | /* ] */ |
| 10957 | )) { |
| 10958 | if (negate && result === CharSetString) { |
| 10959 | state.raise("Negated character class may contain strings"); |
| 10960 | } |
| 10961 | return result; |
| 10962 | } |
| 10963 | state.pos = start; |
| 10964 | } |
| 10965 | if (state.eat( |
| 10966 | 92 |
| 10967 | /* \ */ |
| 10968 | )) { |
| 10969 | var result$1 = this.regexp_eatCharacterClassEscape(state); |
| 10970 | if (result$1) { |
| 10971 | return result$1; |
| 10972 | } |
| 10973 | state.pos = start; |
| 10974 | } |
| 10975 | return null; |
| 10976 | }; |
| 10977 | pp$1.regexp_eatClassStringDisjunction = function(state) { |
| 10978 | var start = state.pos; |
| 10979 | if (state.eatChars( |
| 10980 | [92, 113] |
| 10981 | /* \q */ |
| 10982 | )) { |
| 10983 | if (state.eat( |
| 10984 | 123 |
| 10985 | /* { */ |
| 10986 | )) { |
| 10987 | var result = this.regexp_classStringDisjunctionContents(state); |
| 10988 | if (state.eat( |
| 10989 | 125 |
| 10990 | /* } */ |
| 10991 | )) { |
| 10992 | return result; |
| 10993 | } |
| 10994 | } else { |
| 10995 | state.raise("Invalid escape"); |
| 10996 | } |
| 10997 | state.pos = start; |
| 10998 | } |
| 10999 | return null; |
| 11000 | }; |
| 11001 | pp$1.regexp_classStringDisjunctionContents = function(state) { |
| 11002 | var result = this.regexp_classString(state); |
| 11003 | while (state.eat( |
| 11004 | 124 |
| 11005 | /* | */ |
| 11006 | )) { |
| 11007 | if (this.regexp_classString(state) === CharSetString) { |
| 11008 | result = CharSetString; |
| 11009 | } |
| 11010 | } |
| 11011 | return result; |
| 11012 | }; |
| 11013 | pp$1.regexp_classString = function(state) { |
| 11014 | var count = 0; |
| 11015 | while (this.regexp_eatClassSetCharacter(state)) { |
| 11016 | count++; |
| 11017 | } |
| 11018 | return count === 1 ? CharSetOk : CharSetString; |
| 11019 | }; |
| 11020 | pp$1.regexp_eatClassSetCharacter = function(state) { |
| 11021 | var start = state.pos; |
| 11022 | if (state.eat( |
| 11023 | 92 |
| 11024 | /* \ */ |
| 11025 | )) { |
| 11026 | if (this.regexp_eatCharacterEscape(state) || this.regexp_eatClassSetReservedPunctuator(state)) { |
| 11027 | return true; |
| 11028 | } |
| 11029 | if (state.eat( |
| 11030 | 98 |
| 11031 | /* b */ |
| 11032 | )) { |
| 11033 | state.lastIntValue = 8; |
| 11034 | return true; |
| 11035 | } |
| 11036 | state.pos = start; |
| 11037 | return false; |
| 11038 | } |
| 11039 | var ch = state.current(); |
| 11040 | if (ch < 0 || ch === state.lookahead() && isClassSetReservedDoublePunctuatorCharacter(ch)) { |
| 11041 | return false; |
| 11042 | } |
| 11043 | if (isClassSetSyntaxCharacter(ch)) { |
| 11044 | return false; |
| 11045 | } |
| 11046 | state.advance(); |
| 11047 | state.lastIntValue = ch; |
| 11048 | return true; |
| 11049 | }; |
| 11050 | pp$1.regexp_eatClassSetReservedPunctuator = function(state) { |
| 11051 | var ch = state.current(); |
| 11052 | if (isClassSetReservedPunctuator(ch)) { |
| 11053 | state.lastIntValue = ch; |
| 11054 | state.advance(); |
| 11055 | return true; |
| 11056 | } |
| 11057 | return false; |
| 11058 | }; |
| 11059 | pp$1.regexp_eatClassControlLetter = function(state) { |
| 11060 | var ch = state.current(); |
| 11061 | if (isDecimalDigit(ch) || ch === 95) { |
| 11062 | state.lastIntValue = ch % 32; |
| 11063 | state.advance(); |
| 11064 | return true; |
| 11065 | } |
| 11066 | return false; |
| 11067 | }; |
| 11068 | pp$1.regexp_eatHexEscapeSequence = function(state) { |
| 11069 | var start = state.pos; |
| 11070 | if (state.eat( |
| 11071 | 120 |
| 11072 | /* x */ |
| 11073 | )) { |
| 11074 | if (this.regexp_eatFixedHexDigits(state, 2)) { |
| 11075 | return true; |
| 11076 | } |
| 11077 | if (state.switchU) { |
| 11078 | state.raise("Invalid escape"); |
| 11079 | } |
| 11080 | state.pos = start; |
| 11081 | } |
| 11082 | return false; |
| 11083 | }; |
| 11084 | pp$1.regexp_eatDecimalDigits = function(state) { |
| 11085 | var start = state.pos; |
| 11086 | var ch = 0; |
| 11087 | state.lastIntValue = 0; |
| 11088 | while (isDecimalDigit(ch = state.current())) { |
| 11089 | state.lastIntValue = 10 * state.lastIntValue + (ch - 48); |
| 11090 | state.advance(); |
| 11091 | } |
| 11092 | return state.pos !== start; |
| 11093 | }; |
| 11094 | pp$1.regexp_eatHexDigits = function(state) { |
| 11095 | var start = state.pos; |
| 11096 | var ch = 0; |
| 11097 | state.lastIntValue = 0; |
| 11098 | while (isHexDigit(ch = state.current())) { |
| 11099 | state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch); |
| 11100 | state.advance(); |
| 11101 | } |
| 11102 | return state.pos !== start; |
| 11103 | }; |
| 11104 | pp$1.regexp_eatLegacyOctalEscapeSequence = function(state) { |
| 11105 | if (this.regexp_eatOctalDigit(state)) { |
| 11106 | var n1 = state.lastIntValue; |
| 11107 | if (this.regexp_eatOctalDigit(state)) { |
| 11108 | var n2 = state.lastIntValue; |
| 11109 | if (n1 <= 3 && this.regexp_eatOctalDigit(state)) { |
| 11110 | state.lastIntValue = n1 * 64 + n2 * 8 + state.lastIntValue; |
| 11111 | } else { |
| 11112 | state.lastIntValue = n1 * 8 + n2; |
| 11113 | } |
| 11114 | } else { |
| 11115 | state.lastIntValue = n1; |
| 11116 | } |
| 11117 | return true; |
| 11118 | } |
| 11119 | return false; |
| 11120 | }; |
| 11121 | pp$1.regexp_eatOctalDigit = function(state) { |
| 11122 | var ch = state.current(); |
| 11123 | if (isOctalDigit(ch)) { |
| 11124 | state.lastIntValue = ch - 48; |
| 11125 | state.advance(); |
| 11126 | return true; |
| 11127 | } |
| 11128 | state.lastIntValue = 0; |
| 11129 | return false; |
| 11130 | }; |
| 11131 | pp$1.regexp_eatFixedHexDigits = function(state, length) { |
| 11132 | var start = state.pos; |
| 11133 | state.lastIntValue = 0; |
| 11134 | for (var i2 = 0; i2 < length; ++i2) { |
| 11135 | var ch = state.current(); |
| 11136 | if (!isHexDigit(ch)) { |
| 11137 | state.pos = start; |
| 11138 | return false; |
| 11139 | } |
| 11140 | state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch); |
| 11141 | state.advance(); |
| 11142 | } |
| 11143 | return true; |
| 11144 | }; |
| 11145 | Token = function Token2(p) { |
| 11146 | this.type = p.type; |
| 11147 | this.value = p.value; |
| 11148 | this.start = p.start; |
| 11149 | this.end = p.end; |
| 11150 | if (p.options.locations) { |
| 11151 | this.loc = new SourceLocation(p, p.startLoc, p.endLoc); |
| 11152 | } |
| 11153 | if (p.options.ranges) { |
| 11154 | this.range = [p.start, p.end]; |
| 11155 | } |
| 11156 | }; |
| 11157 | pp = Parser.prototype; |
| 11158 | pp.next = function(ignoreEscapeSequenceInKeyword) { |
| 11159 | if (!ignoreEscapeSequenceInKeyword && this.type.keyword && this.containsEsc) { |
| 11160 | this.raiseRecoverable(this.start, "Escape sequence in keyword " + this.type.keyword); |
| 11161 | } |
| 11162 | if (this.options.onToken) { |
| 11163 | this.options.onToken(new Token(this)); |
| 11164 | } |
| 11165 | this.lastTokEnd = this.end; |
| 11166 | this.lastTokStart = this.start; |
| 11167 | this.lastTokEndLoc = this.endLoc; |
| 11168 | this.lastTokStartLoc = this.startLoc; |
| 11169 | this.nextToken(); |
| 11170 | }; |
| 11171 | pp.getToken = function() { |
| 11172 | this.next(); |
| 11173 | return new Token(this); |
| 11174 | }; |
| 11175 | if (typeof Symbol !== "undefined") { |
| 11176 | pp[Symbol.iterator] = function() { |
| 11177 | var this$1$1 = this; |
| 11178 | return { |
| 11179 | next: function() { |
| 11180 | var token = this$1$1.getToken(); |
| 11181 | return { |
| 11182 | done: token.type === types$1.eof, |
| 11183 | value: token |
| 11184 | }; |
| 11185 | } |
| 11186 | }; |
| 11187 | }; |
| 11188 | } |
| 11189 | pp.nextToken = function() { |
| 11190 | var curContext = this.curContext(); |
| 11191 | if (!curContext || !curContext.preserveSpace) { |
| 11192 | this.skipSpace(); |
| 11193 | } |
| 11194 | this.start = this.pos; |
| 11195 | if (this.options.locations) { |
| 11196 | this.startLoc = this.curPosition(); |
| 11197 | } |
| 11198 | if (this.pos >= this.input.length) { |
| 11199 | return this.finishToken(types$1.eof); |
| 11200 | } |
| 11201 | if (curContext.override) { |
| 11202 | return curContext.override(this); |
| 11203 | } else { |
| 11204 | this.readToken(this.fullCharCodeAtPos()); |
| 11205 | } |
| 11206 | }; |
| 11207 | pp.readToken = function(code) { |
| 11208 | if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92) { |
| 11209 | return this.readWord(); |
| 11210 | } |
| 11211 | return this.getTokenFromCode(code); |
| 11212 | }; |
| 11213 | pp.fullCharCodeAt = function(pos) { |
| 11214 | var code = this.input.charCodeAt(pos); |
| 11215 | if (code <= 55295 || code >= 56320) { |
| 11216 | return code; |
| 11217 | } |
| 11218 | var next = this.input.charCodeAt(pos + 1); |
| 11219 | return next <= 56319 || next >= 57344 ? code : (code << 10) + next - 56613888; |
| 11220 | }; |
| 11221 | pp.fullCharCodeAtPos = function() { |
| 11222 | return this.fullCharCodeAt(this.pos); |
| 11223 | }; |
| 11224 | pp.skipBlockComment = function() { |
| 11225 | var startLoc = this.options.onComment && this.curPosition(); |
| 11226 | var start = this.pos, end = this.input.indexOf("*/", this.pos += 2); |
| 11227 | if (end === -1) { |
| 11228 | this.raise(this.pos - 2, "Unterminated comment"); |
| 11229 | } |
| 11230 | this.pos = end + 2; |
| 11231 | if (this.options.locations) { |
| 11232 | for (var nextBreak = void 0, pos = start; (nextBreak = nextLineBreak(this.input, pos, this.pos)) > -1; ) { |
| 11233 | ++this.curLine; |
| 11234 | pos = this.lineStart = nextBreak; |
| 11235 | } |
| 11236 | } |
| 11237 | if (this.options.onComment) { |
| 11238 | this.options.onComment( |
| 11239 | true, |
| 11240 | this.input.slice(start + 2, end), |
| 11241 | start, |
| 11242 | this.pos, |
| 11243 | startLoc, |
| 11244 | this.curPosition() |
| 11245 | ); |
| 11246 | } |
| 11247 | }; |
| 11248 | pp.skipLineComment = function(startSkip) { |
| 11249 | var start = this.pos; |
| 11250 | var startLoc = this.options.onComment && this.curPosition(); |
| 11251 | var ch = this.input.charCodeAt(this.pos += startSkip); |
| 11252 | while (this.pos < this.input.length && !isNewLine(ch)) { |
| 11253 | ch = this.input.charCodeAt(++this.pos); |
| 11254 | } |
| 11255 | if (this.options.onComment) { |
| 11256 | this.options.onComment( |
| 11257 | false, |
| 11258 | this.input.slice(start + startSkip, this.pos), |
| 11259 | start, |
| 11260 | this.pos, |
| 11261 | startLoc, |
| 11262 | this.curPosition() |
| 11263 | ); |
| 11264 | } |
| 11265 | }; |
| 11266 | pp.skipSpace = function() { |
| 11267 | loop: while (this.pos < this.input.length) { |
| 11268 | var ch = this.input.charCodeAt(this.pos); |
| 11269 | switch (ch) { |
| 11270 | case 32: |
| 11271 | case 160: |
| 11272 | ++this.pos; |
| 11273 | break; |
| 11274 | case 13: |
| 11275 | if (this.input.charCodeAt(this.pos + 1) === 10) { |
| 11276 | ++this.pos; |
| 11277 | } |
| 11278 | case 10: |
| 11279 | case 8232: |
| 11280 | case 8233: |
| 11281 | ++this.pos; |
| 11282 | if (this.options.locations) { |
| 11283 | ++this.curLine; |
| 11284 | this.lineStart = this.pos; |
| 11285 | } |
| 11286 | break; |
| 11287 | case 47: |
| 11288 | switch (this.input.charCodeAt(this.pos + 1)) { |
| 11289 | case 42: |
| 11290 | this.skipBlockComment(); |
| 11291 | break; |
| 11292 | case 47: |
| 11293 | this.skipLineComment(2); |
| 11294 | break; |
| 11295 | default: |
| 11296 | break loop; |
| 11297 | } |
| 11298 | break; |
| 11299 | default: |
| 11300 | if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) { |
| 11301 | ++this.pos; |
| 11302 | } else { |
| 11303 | break loop; |
| 11304 | } |
| 11305 | } |
| 11306 | } |
| 11307 | }; |
| 11308 | pp.finishToken = function(type2, val) { |
| 11309 | this.end = this.pos; |
| 11310 | if (this.options.locations) { |
| 11311 | this.endLoc = this.curPosition(); |
| 11312 | } |
| 11313 | var prevType = this.type; |
| 11314 | this.type = type2; |
| 11315 | this.value = val; |
| 11316 | this.updateContext(prevType); |
| 11317 | }; |
| 11318 | pp.readToken_dot = function() { |
| 11319 | var next = this.input.charCodeAt(this.pos + 1); |
| 11320 | if (next >= 48 && next <= 57) { |
| 11321 | return this.readNumber(true); |
| 11322 | } |
| 11323 | var next2 = this.input.charCodeAt(this.pos + 2); |
| 11324 | if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { |
| 11325 | this.pos += 3; |
| 11326 | return this.finishToken(types$1.ellipsis); |
| 11327 | } else { |
| 11328 | ++this.pos; |
| 11329 | return this.finishToken(types$1.dot); |
| 11330 | } |
| 11331 | }; |
| 11332 | pp.readToken_slash = function() { |
| 11333 | var next = this.input.charCodeAt(this.pos + 1); |
| 11334 | if (this.exprAllowed) { |
| 11335 | ++this.pos; |
| 11336 | return this.readRegexp(); |
| 11337 | } |
| 11338 | if (next === 61) { |
| 11339 | return this.finishOp(types$1.assign, 2); |
| 11340 | } |
| 11341 | return this.finishOp(types$1.slash, 1); |
| 11342 | }; |
| 11343 | pp.readToken_mult_modulo_exp = function(code) { |
| 11344 | var next = this.input.charCodeAt(this.pos + 1); |
| 11345 | var size = 1; |
| 11346 | var tokentype = code === 42 ? types$1.star : types$1.modulo; |
| 11347 | if (this.options.ecmaVersion >= 7 && code === 42 && next === 42) { |
| 11348 | ++size; |
| 11349 | tokentype = types$1.starstar; |
| 11350 | next = this.input.charCodeAt(this.pos + 2); |
| 11351 | } |
| 11352 | if (next === 61) { |
| 11353 | return this.finishOp(types$1.assign, size + 1); |
| 11354 | } |
| 11355 | return this.finishOp(tokentype, size); |
| 11356 | }; |
| 11357 | pp.readToken_pipe_amp = function(code) { |
| 11358 | var next = this.input.charCodeAt(this.pos + 1); |
| 11359 | if (next === code) { |
| 11360 | if (this.options.ecmaVersion >= 12) { |
| 11361 | var next2 = this.input.charCodeAt(this.pos + 2); |
| 11362 | if (next2 === 61) { |
| 11363 | return this.finishOp(types$1.assign, 3); |
| 11364 | } |
| 11365 | } |
| 11366 | return this.finishOp(code === 124 ? types$1.logicalOR : types$1.logicalAND, 2); |
| 11367 | } |
| 11368 | if (next === 61) { |
| 11369 | return this.finishOp(types$1.assign, 2); |
| 11370 | } |
| 11371 | return this.finishOp(code === 124 ? types$1.bitwiseOR : types$1.bitwiseAND, 1); |
| 11372 | }; |
| 11373 | pp.readToken_caret = function() { |
| 11374 | var next = this.input.charCodeAt(this.pos + 1); |
| 11375 | if (next === 61) { |
| 11376 | return this.finishOp(types$1.assign, 2); |
| 11377 | } |
| 11378 | return this.finishOp(types$1.bitwiseXOR, 1); |
| 11379 | }; |
| 11380 | pp.readToken_plus_min = function(code) { |
| 11381 | var next = this.input.charCodeAt(this.pos + 1); |
| 11382 | if (next === code) { |
| 11383 | if (next === 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 62 && (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) { |
| 11384 | this.skipLineComment(3); |
| 11385 | this.skipSpace(); |
| 11386 | return this.nextToken(); |
| 11387 | } |
| 11388 | return this.finishOp(types$1.incDec, 2); |
| 11389 | } |
| 11390 | if (next === 61) { |
| 11391 | return this.finishOp(types$1.assign, 2); |
| 11392 | } |
| 11393 | return this.finishOp(types$1.plusMin, 1); |
| 11394 | }; |
| 11395 | pp.readToken_lt_gt = function(code) { |
| 11396 | var next = this.input.charCodeAt(this.pos + 1); |
| 11397 | var size = 1; |
| 11398 | if (next === code) { |
| 11399 | size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2; |
| 11400 | if (this.input.charCodeAt(this.pos + size) === 61) { |
| 11401 | return this.finishOp(types$1.assign, size + 1); |
| 11402 | } |
| 11403 | return this.finishOp(types$1.bitShift, size); |
| 11404 | } |
| 11405 | if (next === 33 && code === 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 45 && this.input.charCodeAt(this.pos + 3) === 45) { |
| 11406 | this.skipLineComment(4); |
| 11407 | this.skipSpace(); |
| 11408 | return this.nextToken(); |
| 11409 | } |
| 11410 | if (next === 61) { |
| 11411 | size = 2; |
| 11412 | } |
| 11413 | return this.finishOp(types$1.relational, size); |
| 11414 | }; |
| 11415 | pp.readToken_eq_excl = function(code) { |
| 11416 | var next = this.input.charCodeAt(this.pos + 1); |
| 11417 | if (next === 61) { |
| 11418 | return this.finishOp(types$1.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2); |
| 11419 | } |
| 11420 | if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { |
| 11421 | this.pos += 2; |
| 11422 | return this.finishToken(types$1.arrow); |
| 11423 | } |
| 11424 | return this.finishOp(code === 61 ? types$1.eq : types$1.prefix, 1); |
| 11425 | }; |
| 11426 | pp.readToken_question = function() { |
| 11427 | var ecmaVersion2 = this.options.ecmaVersion; |
| 11428 | if (ecmaVersion2 >= 11) { |
| 11429 | var next = this.input.charCodeAt(this.pos + 1); |
| 11430 | if (next === 46) { |
| 11431 | var next2 = this.input.charCodeAt(this.pos + 2); |
| 11432 | if (next2 < 48 || next2 > 57) { |
| 11433 | return this.finishOp(types$1.questionDot, 2); |
| 11434 | } |
| 11435 | } |
| 11436 | if (next === 63) { |
| 11437 | if (ecmaVersion2 >= 12) { |
| 11438 | var next2$1 = this.input.charCodeAt(this.pos + 2); |
| 11439 | if (next2$1 === 61) { |
| 11440 | return this.finishOp(types$1.assign, 3); |
| 11441 | } |
| 11442 | } |
| 11443 | return this.finishOp(types$1.coalesce, 2); |
| 11444 | } |
| 11445 | } |
| 11446 | return this.finishOp(types$1.question, 1); |
| 11447 | }; |
| 11448 | pp.readToken_numberSign = function() { |
| 11449 | var ecmaVersion2 = this.options.ecmaVersion; |
| 11450 | var code = 35; |
| 11451 | if (ecmaVersion2 >= 13) { |
| 11452 | ++this.pos; |
| 11453 | code = this.fullCharCodeAtPos(); |
| 11454 | if (isIdentifierStart(code, true) || code === 92) { |
| 11455 | return this.finishToken(types$1.privateId, this.readWord1()); |
| 11456 | } |
| 11457 | } |
| 11458 | this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'"); |
| 11459 | }; |
| 11460 | pp.getTokenFromCode = function(code) { |
| 11461 | switch (code) { |
| 11462 | // The interpretation of a dot depends on whether it is followed |
| 11463 | // by a digit or another two dots. |
| 11464 | case 46: |
| 11465 | return this.readToken_dot(); |
| 11466 | // Punctuation tokens. |
| 11467 | case 40: |
| 11468 | ++this.pos; |
| 11469 | return this.finishToken(types$1.parenL); |
| 11470 | case 41: |
| 11471 | ++this.pos; |
| 11472 | return this.finishToken(types$1.parenR); |
| 11473 | case 59: |
| 11474 | ++this.pos; |
| 11475 | return this.finishToken(types$1.semi); |
| 11476 | case 44: |
| 11477 | ++this.pos; |
| 11478 | return this.finishToken(types$1.comma); |
| 11479 | case 91: |
| 11480 | ++this.pos; |
| 11481 | return this.finishToken(types$1.bracketL); |
| 11482 | case 93: |
| 11483 | ++this.pos; |
| 11484 | return this.finishToken(types$1.bracketR); |
| 11485 | case 123: |
| 11486 | ++this.pos; |
| 11487 | return this.finishToken(types$1.braceL); |
| 11488 | case 125: |
| 11489 | ++this.pos; |
| 11490 | return this.finishToken(types$1.braceR); |
| 11491 | case 58: |
| 11492 | ++this.pos; |
| 11493 | return this.finishToken(types$1.colon); |
| 11494 | case 96: |
| 11495 | if (this.options.ecmaVersion < 6) { |
| 11496 | break; |
| 11497 | } |
| 11498 | ++this.pos; |
| 11499 | return this.finishToken(types$1.backQuote); |
| 11500 | case 48: |
| 11501 | var next = this.input.charCodeAt(this.pos + 1); |
| 11502 | if (next === 120 || next === 88) { |
| 11503 | return this.readRadixNumber(16); |
| 11504 | } |
| 11505 | if (this.options.ecmaVersion >= 6) { |
| 11506 | if (next === 111 || next === 79) { |
| 11507 | return this.readRadixNumber(8); |
| 11508 | } |
| 11509 | if (next === 98 || next === 66) { |
| 11510 | return this.readRadixNumber(2); |
| 11511 | } |
| 11512 | } |
| 11513 | // Anything else beginning with a digit is an integer, octal |
| 11514 | // number, or float. |
| 11515 | case 49: |
| 11516 | case 50: |
| 11517 | case 51: |
| 11518 | case 52: |
| 11519 | case 53: |
| 11520 | case 54: |
| 11521 | case 55: |
| 11522 | case 56: |
| 11523 | case 57: |
| 11524 | return this.readNumber(false); |
| 11525 | // Quotes produce strings. |
| 11526 | case 34: |
| 11527 | case 39: |
| 11528 | return this.readString(code); |
| 11529 | // Operators are parsed inline in tiny state machines. '=' (61) is |
| 11530 | // often referred to. `finishOp` simply skips the amount of |
| 11531 | // characters it is given as second argument, and returns a token |
| 11532 | // of the type given by its first argument. |
| 11533 | case 47: |
| 11534 | return this.readToken_slash(); |
| 11535 | case 37: |
| 11536 | case 42: |
| 11537 | return this.readToken_mult_modulo_exp(code); |
| 11538 | case 124: |
| 11539 | case 38: |
| 11540 | return this.readToken_pipe_amp(code); |
| 11541 | case 94: |
| 11542 | return this.readToken_caret(); |
| 11543 | case 43: |
| 11544 | case 45: |
| 11545 | return this.readToken_plus_min(code); |
| 11546 | case 60: |
| 11547 | case 62: |
| 11548 | return this.readToken_lt_gt(code); |
| 11549 | case 61: |
| 11550 | case 33: |
| 11551 | return this.readToken_eq_excl(code); |
| 11552 | case 63: |
| 11553 | return this.readToken_question(); |
| 11554 | case 126: |
| 11555 | return this.finishOp(types$1.prefix, 1); |
| 11556 | case 35: |
| 11557 | return this.readToken_numberSign(); |
| 11558 | } |
| 11559 | this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'"); |
| 11560 | }; |
| 11561 | pp.finishOp = function(type2, size) { |
| 11562 | var str2 = this.input.slice(this.pos, this.pos + size); |
| 11563 | this.pos += size; |
| 11564 | return this.finishToken(type2, str2); |
| 11565 | }; |
| 11566 | pp.readRegexp = function() { |
| 11567 | var escaped, inClass, start = this.pos; |
| 11568 | for (; ; ) { |
| 11569 | if (this.pos >= this.input.length) { |
| 11570 | this.raise(start, "Unterminated regular expression"); |
| 11571 | } |
| 11572 | var ch = this.input.charAt(this.pos); |
| 11573 | if (lineBreak.test(ch)) { |
| 11574 | this.raise(start, "Unterminated regular expression"); |
| 11575 | } |
| 11576 | if (!escaped) { |
| 11577 | if (ch === "[") { |
| 11578 | inClass = true; |
| 11579 | } else if (ch === "]" && inClass) { |
| 11580 | inClass = false; |
| 11581 | } else if (ch === "/" && !inClass) { |
| 11582 | break; |
| 11583 | } |
| 11584 | escaped = ch === "\\"; |
| 11585 | } else { |
| 11586 | escaped = false; |
| 11587 | } |
| 11588 | ++this.pos; |
| 11589 | } |
| 11590 | var pattern = this.input.slice(start, this.pos); |
| 11591 | ++this.pos; |
| 11592 | var flagsStart = this.pos; |
| 11593 | var flags = this.readWord1(); |
| 11594 | if (this.containsEsc) { |
| 11595 | this.unexpected(flagsStart); |
| 11596 | } |
| 11597 | var state = this.regexpState || (this.regexpState = new RegExpValidationState(this)); |
| 11598 | state.reset(start, pattern, flags); |
| 11599 | this.validateRegExpFlags(state); |
| 11600 | this.validateRegExpPattern(state); |
| 11601 | var value = null; |
| 11602 | try { |
| 11603 | value = new RegExp(pattern, flags); |
| 11604 | } catch (e) { |
| 11605 | } |
| 11606 | return this.finishToken(types$1.regexp, { pattern, flags, value }); |
| 11607 | }; |
| 11608 | pp.readInt = function(radix, len, maybeLegacyOctalNumericLiteral) { |
| 11609 | var allowSeparators = this.options.ecmaVersion >= 12 && len === void 0; |
| 11610 | var isLegacyOctalNumericLiteral = maybeLegacyOctalNumericLiteral && this.input.charCodeAt(this.pos) === 48; |
| 11611 | var start = this.pos, total = 0, lastCode = 0; |
| 11612 | for (var i2 = 0, e = len == null ? Infinity : len; i2 < e; ++i2, ++this.pos) { |
| 11613 | var code = this.input.charCodeAt(this.pos), val = void 0; |
| 11614 | if (allowSeparators && code === 95) { |
| 11615 | if (isLegacyOctalNumericLiteral) { |
| 11616 | this.raiseRecoverable(this.pos, "Numeric separator is not allowed in legacy octal numeric literals"); |
| 11617 | } |
| 11618 | if (lastCode === 95) { |
| 11619 | this.raiseRecoverable(this.pos, "Numeric separator must be exactly one underscore"); |
| 11620 | } |
| 11621 | if (i2 === 0) { |
| 11622 | this.raiseRecoverable(this.pos, "Numeric separator is not allowed at the first of digits"); |
| 11623 | } |
| 11624 | lastCode = code; |
| 11625 | continue; |
| 11626 | } |
| 11627 | if (code >= 97) { |
| 11628 | val = code - 97 + 10; |
| 11629 | } else if (code >= 65) { |
| 11630 | val = code - 65 + 10; |
| 11631 | } else if (code >= 48 && code <= 57) { |
| 11632 | val = code - 48; |
| 11633 | } else { |
| 11634 | val = Infinity; |
| 11635 | } |
| 11636 | if (val >= radix) { |
| 11637 | break; |
| 11638 | } |
| 11639 | lastCode = code; |
| 11640 | total = total * radix + val; |
| 11641 | } |
| 11642 | if (allowSeparators && lastCode === 95) { |
| 11643 | this.raiseRecoverable(this.pos - 1, "Numeric separator is not allowed at the last of digits"); |
| 11644 | } |
| 11645 | if (this.pos === start || len != null && this.pos - start !== len) { |
| 11646 | return null; |
| 11647 | } |
| 11648 | return total; |
| 11649 | }; |
| 11650 | pp.readRadixNumber = function(radix) { |
| 11651 | var start = this.pos; |
| 11652 | this.pos += 2; |
| 11653 | var val = this.readInt(radix); |
| 11654 | if (val == null) { |
| 11655 | this.raise(this.start + 2, "Expected number in radix " + radix); |
| 11656 | } |
| 11657 | if (this.options.ecmaVersion >= 11 && this.input.charCodeAt(this.pos) === 110) { |
| 11658 | val = stringToBigInt(this.input.slice(start, this.pos)); |
| 11659 | ++this.pos; |
| 11660 | } else if (isIdentifierStart(this.fullCharCodeAtPos())) { |
| 11661 | this.raise(this.pos, "Identifier directly after number"); |
| 11662 | } |
| 11663 | return this.finishToken(types$1.num, val); |
| 11664 | }; |
| 11665 | pp.readNumber = function(startsWithDot) { |
| 11666 | var start = this.pos; |
| 11667 | if (!startsWithDot && this.readInt(10, void 0, true) === null) { |
| 11668 | this.raise(start, "Invalid number"); |
| 11669 | } |
| 11670 | var octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48; |
| 11671 | if (octal && this.strict) { |
| 11672 | this.raise(start, "Invalid number"); |
| 11673 | } |
| 11674 | var next = this.input.charCodeAt(this.pos); |
| 11675 | if (!octal && !startsWithDot && this.options.ecmaVersion >= 11 && next === 110) { |
| 11676 | var val$1 = stringToBigInt(this.input.slice(start, this.pos)); |
| 11677 | ++this.pos; |
| 11678 | if (isIdentifierStart(this.fullCharCodeAtPos())) { |
| 11679 | this.raise(this.pos, "Identifier directly after number"); |
| 11680 | } |
| 11681 | return this.finishToken(types$1.num, val$1); |
| 11682 | } |
| 11683 | if (octal && /[89]/.test(this.input.slice(start, this.pos))) { |
| 11684 | octal = false; |
| 11685 | } |
| 11686 | if (next === 46 && !octal) { |
| 11687 | ++this.pos; |
| 11688 | this.readInt(10); |
| 11689 | next = this.input.charCodeAt(this.pos); |
| 11690 | } |
| 11691 | if ((next === 69 || next === 101) && !octal) { |
| 11692 | next = this.input.charCodeAt(++this.pos); |
| 11693 | if (next === 43 || next === 45) { |
| 11694 | ++this.pos; |
| 11695 | } |
| 11696 | if (this.readInt(10) === null) { |
| 11697 | this.raise(start, "Invalid number"); |
| 11698 | } |
| 11699 | } |
| 11700 | if (isIdentifierStart(this.fullCharCodeAtPos())) { |
| 11701 | this.raise(this.pos, "Identifier directly after number"); |
| 11702 | } |
| 11703 | var val = stringToNumber(this.input.slice(start, this.pos), octal); |
| 11704 | return this.finishToken(types$1.num, val); |
| 11705 | }; |
| 11706 | pp.readCodePoint = function() { |
| 11707 | var ch = this.input.charCodeAt(this.pos), code; |
| 11708 | if (ch === 123) { |
| 11709 | if (this.options.ecmaVersion < 6) { |
| 11710 | this.unexpected(); |
| 11711 | } |
| 11712 | var codePos = ++this.pos; |
| 11713 | code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos); |
| 11714 | ++this.pos; |
| 11715 | if (code > 1114111) { |
| 11716 | this.invalidStringToken(codePos, "Code point out of bounds"); |
| 11717 | } |
| 11718 | } else { |
| 11719 | code = this.readHexChar(4); |
| 11720 | } |
| 11721 | return code; |
| 11722 | }; |
| 11723 | pp.readString = function(quote) { |
| 11724 | var out = "", chunkStart = ++this.pos; |
| 11725 | for (; ; ) { |
| 11726 | if (this.pos >= this.input.length) { |
| 11727 | this.raise(this.start, "Unterminated string constant"); |
| 11728 | } |
| 11729 | var ch = this.input.charCodeAt(this.pos); |
| 11730 | if (ch === quote) { |
| 11731 | break; |
| 11732 | } |
| 11733 | if (ch === 92) { |
| 11734 | out += this.input.slice(chunkStart, this.pos); |
| 11735 | out += this.readEscapedChar(false); |
| 11736 | chunkStart = this.pos; |
| 11737 | } else if (ch === 8232 || ch === 8233) { |
| 11738 | if (this.options.ecmaVersion < 10) { |
| 11739 | this.raise(this.start, "Unterminated string constant"); |
| 11740 | } |
| 11741 | ++this.pos; |
| 11742 | if (this.options.locations) { |
| 11743 | this.curLine++; |
| 11744 | this.lineStart = this.pos; |
| 11745 | } |
| 11746 | } else { |
| 11747 | if (isNewLine(ch)) { |
| 11748 | this.raise(this.start, "Unterminated string constant"); |
| 11749 | } |
| 11750 | ++this.pos; |
| 11751 | } |
| 11752 | } |
| 11753 | out += this.input.slice(chunkStart, this.pos++); |
| 11754 | return this.finishToken(types$1.string, out); |
| 11755 | }; |
| 11756 | INVALID_TEMPLATE_ESCAPE_ERROR = {}; |
| 11757 | pp.tryReadTemplateToken = function() { |
| 11758 | this.inTemplateElement = true; |
| 11759 | try { |
| 11760 | this.readTmplToken(); |
| 11761 | } catch (err) { |
| 11762 | if (err === INVALID_TEMPLATE_ESCAPE_ERROR) { |
| 11763 | this.readInvalidTemplateToken(); |
| 11764 | } else { |
| 11765 | throw err; |
| 11766 | } |
| 11767 | } |
| 11768 | this.inTemplateElement = false; |
| 11769 | }; |
| 11770 | pp.invalidStringToken = function(position, message) { |
| 11771 | if (this.inTemplateElement && this.options.ecmaVersion >= 9) { |
| 11772 | throw INVALID_TEMPLATE_ESCAPE_ERROR; |
| 11773 | } else { |
| 11774 | this.raise(position, message); |
| 11775 | } |
| 11776 | }; |
| 11777 | pp.readTmplToken = function() { |
| 11778 | var out = "", chunkStart = this.pos; |
| 11779 | for (; ; ) { |
| 11780 | if (this.pos >= this.input.length) { |
| 11781 | this.raise(this.start, "Unterminated template"); |
| 11782 | } |
| 11783 | var ch = this.input.charCodeAt(this.pos); |
| 11784 | if (ch === 96 || ch === 36 && this.input.charCodeAt(this.pos + 1) === 123) { |
| 11785 | if (this.pos === this.start && (this.type === types$1.template || this.type === types$1.invalidTemplate)) { |
| 11786 | if (ch === 36) { |
| 11787 | this.pos += 2; |
| 11788 | return this.finishToken(types$1.dollarBraceL); |
| 11789 | } else { |
| 11790 | ++this.pos; |
| 11791 | return this.finishToken(types$1.backQuote); |
| 11792 | } |
| 11793 | } |
| 11794 | out += this.input.slice(chunkStart, this.pos); |
| 11795 | return this.finishToken(types$1.template, out); |
| 11796 | } |
| 11797 | if (ch === 92) { |
| 11798 | out += this.input.slice(chunkStart, this.pos); |
| 11799 | out += this.readEscapedChar(true); |
| 11800 | chunkStart = this.pos; |
| 11801 | } else if (isNewLine(ch)) { |
| 11802 | out += this.input.slice(chunkStart, this.pos); |
| 11803 | ++this.pos; |
| 11804 | switch (ch) { |
| 11805 | case 13: |
| 11806 | if (this.input.charCodeAt(this.pos) === 10) { |
| 11807 | ++this.pos; |
| 11808 | } |
| 11809 | case 10: |
| 11810 | out += "\n"; |
| 11811 | break; |
| 11812 | default: |
| 11813 | out += String.fromCharCode(ch); |
| 11814 | break; |
| 11815 | } |
| 11816 | if (this.options.locations) { |
| 11817 | ++this.curLine; |
| 11818 | this.lineStart = this.pos; |
| 11819 | } |
| 11820 | chunkStart = this.pos; |
| 11821 | } else { |
| 11822 | ++this.pos; |
| 11823 | } |
| 11824 | } |
| 11825 | }; |
| 11826 | pp.readInvalidTemplateToken = function() { |
| 11827 | for (; this.pos < this.input.length; this.pos++) { |
| 11828 | switch (this.input[this.pos]) { |
| 11829 | case "\\": |
| 11830 | ++this.pos; |
| 11831 | break; |
| 11832 | case "$": |
| 11833 | if (this.input[this.pos + 1] !== "{") { |
| 11834 | break; |
| 11835 | } |
| 11836 | // fall through |
| 11837 | case "`": |
| 11838 | return this.finishToken(types$1.invalidTemplate, this.input.slice(this.start, this.pos)); |
| 11839 | case "\r": |
| 11840 | if (this.input[this.pos + 1] === "\n") { |
| 11841 | ++this.pos; |
| 11842 | } |
| 11843 | // fall through |
| 11844 | case "\n": |
| 11845 | case "\u2028": |
| 11846 | case "\u2029": |
| 11847 | ++this.curLine; |
| 11848 | this.lineStart = this.pos + 1; |
| 11849 | break; |
| 11850 | } |
| 11851 | } |
| 11852 | this.raise(this.start, "Unterminated template"); |
| 11853 | }; |
| 11854 | pp.readEscapedChar = function(inTemplate) { |
| 11855 | var ch = this.input.charCodeAt(++this.pos); |
| 11856 | ++this.pos; |
| 11857 | switch (ch) { |
| 11858 | case 110: |
| 11859 | return "\n"; |
| 11860 | // 'n' -> '\n' |
| 11861 | case 114: |
| 11862 | return "\r"; |
| 11863 | // 'r' -> '\r' |
| 11864 | case 120: |
| 11865 | return String.fromCharCode(this.readHexChar(2)); |
| 11866 | // 'x' |
| 11867 | case 117: |
| 11868 | return codePointToString(this.readCodePoint()); |
| 11869 | // 'u' |
| 11870 | case 116: |
| 11871 | return " "; |
| 11872 | // 't' -> '\t' |
| 11873 | case 98: |
| 11874 | return "\b"; |
| 11875 | // 'b' -> '\b' |
| 11876 | case 118: |
| 11877 | return "\v"; |
| 11878 | // 'v' -> '\u000b' |
| 11879 | case 102: |
| 11880 | return "\f"; |
| 11881 | // 'f' -> '\f' |
| 11882 | case 13: |
| 11883 | if (this.input.charCodeAt(this.pos) === 10) { |
| 11884 | ++this.pos; |
| 11885 | } |
| 11886 | // '\r\n' |
| 11887 | case 10: |
| 11888 | if (this.options.locations) { |
| 11889 | this.lineStart = this.pos; |
| 11890 | ++this.curLine; |
| 11891 | } |
| 11892 | return ""; |
| 11893 | case 56: |
| 11894 | case 57: |
| 11895 | if (this.strict) { |
| 11896 | this.invalidStringToken( |
| 11897 | this.pos - 1, |
| 11898 | "Invalid escape sequence" |
| 11899 | ); |
| 11900 | } |
| 11901 | if (inTemplate) { |
| 11902 | var codePos = this.pos - 1; |
| 11903 | this.invalidStringToken( |
| 11904 | codePos, |
| 11905 | "Invalid escape sequence in template string" |
| 11906 | ); |
| 11907 | } |
| 11908 | default: |
| 11909 | if (ch >= 48 && ch <= 55) { |
| 11910 | var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0]; |
| 11911 | var octal = parseInt(octalStr, 8); |
| 11912 | if (octal > 255) { |
| 11913 | octalStr = octalStr.slice(0, -1); |
| 11914 | octal = parseInt(octalStr, 8); |
| 11915 | } |
| 11916 | this.pos += octalStr.length - 1; |
| 11917 | ch = this.input.charCodeAt(this.pos); |
| 11918 | if ((octalStr !== "0" || ch === 56 || ch === 57) && (this.strict || inTemplate)) { |
| 11919 | this.invalidStringToken( |
| 11920 | this.pos - 1 - octalStr.length, |
| 11921 | inTemplate ? "Octal literal in template string" : "Octal literal in strict mode" |
| 11922 | ); |
| 11923 | } |
| 11924 | return String.fromCharCode(octal); |
| 11925 | } |
| 11926 | if (isNewLine(ch)) { |
| 11927 | if (this.options.locations) { |
| 11928 | this.lineStart = this.pos; |
| 11929 | ++this.curLine; |
| 11930 | } |
| 11931 | return ""; |
| 11932 | } |
| 11933 | return String.fromCharCode(ch); |
| 11934 | } |
| 11935 | }; |
| 11936 | pp.readHexChar = function(len) { |
| 11937 | var codePos = this.pos; |
| 11938 | var n = this.readInt(16, len); |
| 11939 | if (n === null) { |
| 11940 | this.invalidStringToken(codePos, "Bad character escape sequence"); |
| 11941 | } |
| 11942 | return n; |
| 11943 | }; |
| 11944 | pp.readWord1 = function() { |
| 11945 | this.containsEsc = false; |
| 11946 | var word = "", first = true, chunkStart = this.pos; |
| 11947 | var astral = this.options.ecmaVersion >= 6; |
| 11948 | while (this.pos < this.input.length) { |
| 11949 | var ch = this.fullCharCodeAtPos(); |
| 11950 | if (isIdentifierChar(ch, astral)) { |
| 11951 | this.pos += ch <= 65535 ? 1 : 2; |
| 11952 | } else if (ch === 92) { |
| 11953 | this.containsEsc = true; |
| 11954 | word += this.input.slice(chunkStart, this.pos); |
| 11955 | var escStart = this.pos; |
| 11956 | if (this.input.charCodeAt(++this.pos) !== 117) { |
| 11957 | this.invalidStringToken(this.pos, "Expecting Unicode escape sequence \\uXXXX"); |
| 11958 | } |
| 11959 | ++this.pos; |
| 11960 | var esc = this.readCodePoint(); |
| 11961 | if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral)) { |
| 11962 | this.invalidStringToken(escStart, "Invalid Unicode escape"); |
| 11963 | } |
| 11964 | word += codePointToString(esc); |
| 11965 | chunkStart = this.pos; |
| 11966 | } else { |
| 11967 | break; |
| 11968 | } |
| 11969 | first = false; |
| 11970 | } |
| 11971 | return word + this.input.slice(chunkStart, this.pos); |
| 11972 | }; |
| 11973 | pp.readWord = function() { |
| 11974 | var word = this.readWord1(); |
| 11975 | var type2 = types$1.name; |
| 11976 | if (this.keywords.test(word)) { |
| 11977 | type2 = keywords[word]; |
| 11978 | } |
| 11979 | return this.finishToken(type2, word); |
| 11980 | }; |
| 11981 | version = "8.18.0"; |
| 11982 | Parser.acorn = { |
| 11983 | Parser, |
| 11984 | version, |
| 11985 | defaultOptions, |
| 11986 | Position, |
| 11987 | SourceLocation, |
| 11988 | getLineInfo, |
| 11989 | Node, |
| 11990 | TokenType, |
| 11991 | tokTypes: types$1, |
| 11992 | keywordTypes: keywords, |
| 11993 | TokContext, |
| 11994 | tokContexts: types2, |
| 11995 | isIdentifierChar, |
| 11996 | isIdentifierStart, |
| 11997 | Token, |
| 11998 | isNewLine, |
| 11999 | lineBreak, |
| 12000 | lineBreakG, |
| 12001 | nonASCIIwhitespace |
| 12002 | }; |
| 12003 | } |
| 12004 | }); |
| 12005 | |
| 12006 | // src/dsh/bun-closure.ts |
| 12007 | var init_bun_closure = __esm({ |
| 12008 | "src/dsh/bun-closure.ts"() { |
| 12009 | "use strict"; |
| 12010 | init_acorn(); |
| 12011 | } |
| 12012 | }); |
| 12013 | |
| 12014 | // src/dsh/resolve-hooks.ts |
| 12015 | import { fileURLToPath as fileURLToPath2, pathToFileURL as pathToFileURL2 } from "node:url"; |
| 12016 | import { resolve as resolve2, isAbsolute as isAbsolute2, dirname } from "node:path"; |
| 12017 | function keyIn(closure, path) { |
| 12018 | const canonical = insideKey(closure.canonicalRoot, path); |
| 12019 | if (canonical !== void 0) return canonical; |
| 12020 | for (const root of closure.rawRoots) { |
| 12021 | const raw = insideKey(root, path); |
| 12022 | if (raw !== void 0) return raw; |
| 12023 | } |
| 12024 | } |
| 12025 | function admitReviewedClosure(baseUrl, files) { |
| 12026 | const rawRoot = resolve2(fileURLToPath2(baseUrl)); |
| 12027 | const canonicalRoot = canonicalPath(rawRoot); |
| 12028 | const id = pathKey(canonicalRoot); |
| 12029 | const accepted = /* @__PURE__ */ Object.create(null); |
| 12030 | const keys = Object.keys(files); |
| 12031 | if (keys.length > 4096) throw new Error("reviewed composition closure exceeds its file limit"); |
| 12032 | for (const key of keys) { |
| 12033 | if (!key || key.split("/").some((part) => !part || part === "." || part === "..") || key.includes("\\") || key.includes(":") || isAbsolute2(key) || !/^[a-f0-9]{64}$/.test(files[key])) throw new Error("invalid reviewed composition closure file"); |
| 12034 | accepted[key] = files[key]; |
| 12035 | } |
| 12036 | const existing = reviewedClosures.get(id); |
| 12037 | if (existing) { |
| 12038 | if (Object.keys(existing.files).length !== keys.length || keys.some((key) => existing.files[key] !== accepted[key])) throw new Error("the same composition root carries different file receipts"); |
| 12039 | existing.refs++; |
| 12040 | existing.rawRoots.add(rawRoot); |
| 12041 | } else reviewedClosures.set(id, { files: Object.freeze(accepted), refs: 1, canonicalRoot, rawRoots: /* @__PURE__ */ new Set([rawRoot]) }); |
| 12042 | let disposed = false; |
| 12043 | return () => { |
| 12044 | if (disposed) return; |
| 12045 | disposed = true; |
| 12046 | const current2 = reviewedClosures.get(id); |
| 12047 | if (current2 && --current2.refs === 0) reviewedClosures.delete(id); |
| 12048 | }; |
| 12049 | } |
| 12050 | async function importReviewedModule(baseUrl, path) { |
| 12051 | const rawRoot = resolve2(fileURLToPath2(baseUrl)); |
| 12052 | const id = pathKey(canonicalPath(rawRoot)); |
| 12053 | const receipt = reviewedClosures.get(id); |
| 12054 | if (!receipt) throw new Error("composition module closure is no longer admitted"); |
| 12055 | const entry = resolve2(rawRoot, path); |
| 12056 | const admitted = closureAt(pathToFileURL2(entry).href); |
| 12057 | if (!admitted || admitted.root !== id || !(admitted.path in receipt.files)) throw new Error("composition module is absent from reviewed closure"); |
| 12058 | return import(pathToFileURL2(entry).href); |
| 12059 | } |
| 12060 | function closureAt(url) { |
| 12061 | if (!url?.startsWith("file:")) return; |
| 12062 | const path = resolve2(fileURLToPath2(url)); |
| 12063 | for (const [root, receipt] of reviewedClosures) { |
| 12064 | const inside = keyIn(receipt, path); |
| 12065 | if (inside !== void 0) return { root, receipt, path: inside }; |
| 12066 | } |
| 12067 | } |
| 12068 | var reviewedClosures; |
| 12069 | var init_resolve_hooks = __esm({ |
| 12070 | "src/dsh/resolve-hooks.ts"() { |
| 12071 | "use strict"; |
| 12072 | init_canonical_path(); |
| 12073 | init_runtime(); |
| 12074 | init_bun_closure(); |
| 12075 | reviewedClosures = /* @__PURE__ */ new Map(); |
| 12076 | } |
| 12077 | }); |
| 12078 | |
| 12079 | // src/shims/prompt.ts |
| 12080 | function normalizePromptSection(value) { |
| 12081 | if (typeof value !== "object" || value === null || Array.isArray(value)) { |
| 12082 | throw new TypeError("prompt section must be an object with id and text"); |
| 12083 | } |
| 12084 | if (Object.keys(value).some((key) => key !== "id" && key !== "text" && key !== "interpolate")) { |
| 12085 | throw new TypeError("prompt section supports only id and text, plus optional model-cwd interpolation"); |
| 12086 | } |
| 12087 | const { id, text: text2, interpolate: interpolate2 } = value; |
| 12088 | if (typeof id !== "string" || !SECTION_ID.test(id)) { |
| 12089 | throw new TypeError("prompt section id must be lower case, start with a letter, and use a-z, 0-9, _ or - (at most 64 characters)"); |
| 12090 | } |
| 12091 | if (typeof text2 !== "string" || text2.trim().length === 0) { |
| 12092 | throw new TypeError(`prompt section "${id}" needs non-empty text`); |
| 12093 | } |
| 12094 | if (/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f]/u.test(text2)) { |
| 12095 | throw new TypeError(`prompt section "${id}" text contains control characters`); |
| 12096 | } |
| 12097 | if (Buffer.byteLength(text2, "utf8") > MAX_PROMPT_SECTION_BYTES) { |
| 12098 | throw new RangeError(`prompt section "${id}" exceeds ${MAX_PROMPT_SECTION_BYTES} UTF-8 bytes`); |
| 12099 | } |
| 12100 | if (interpolate2 !== void 0 && interpolate2 !== "model-cwd") throw new TypeError("prompt interpolation supports only model-cwd"); |
| 12101 | if (interpolate2 !== void 0) validatePromptTemplate(text2); |
| 12102 | return Object.freeze({ id, text: text2, ...interpolate2 === void 0 ? {} : { interpolate: interpolate2 } }); |
| 12103 | } |
| 12104 | function validatePromptTemplate(text2) { |
| 12105 | for (let open = text2.indexOf("{{"); open >= 0; ) { |
| 12106 | const group = /^\{\{([^{}]*)\}\}/u.exec(text2.slice(open)); |
| 12107 | if (!group) { |
| 12108 | if (text2.indexOf("}}", open + 2) >= 0) throw new TypeError("malformed prompt variable reference"); |
| 12109 | open = text2.indexOf("{{", open + 2); |
| 12110 | continue; |
| 12111 | } |
| 12112 | if (!/^[a-z][a-z0-9_]*$/u.test(group[1])) throw new TypeError("malformed prompt variable reference"); |
| 12113 | if (group[1] !== "model" && group[1] !== "cwd") throw new TypeError(`unknown Core prompt variable "{{${group[1]}}}"; supported variables: model, cwd`); |
| 12114 | open = text2.indexOf("{{", open + group[0].length); |
| 12115 | } |
| 12116 | } |
| 12117 | var MAX_PROMPT_SECTION_BYTES, MAX_PROMPT_OWNER_BYTES, MAX_PROMPT_HOST_BYTES, SECTION_ID; |
| 12118 | var init_prompt = __esm({ |
| 12119 | "src/shims/prompt.ts"() { |
| 12120 | "use strict"; |
| 12121 | init_owned(); |
| 12122 | MAX_PROMPT_SECTION_BYTES = 4 * 1024; |
| 12123 | MAX_PROMPT_OWNER_BYTES = 32 * 1024; |
| 12124 | MAX_PROMPT_HOST_BYTES = 128 * 1024; |
| 12125 | SECTION_ID = /^[a-z][a-z0-9_-]{0,63}$/u; |
| 12126 | } |
| 12127 | }); |
| 12128 | |
| 12129 | // src/protocol.generated.ts |
| 12130 | var MAGIC_ASCII; |
| 12131 | var init_protocol_generated = __esm({ |
| 12132 | "src/protocol.generated.ts"() { |
| 12133 | "use strict"; |
| 12134 | MAGIC_ASCII = "CWX1"; |
| 12135 | } |
| 12136 | }); |
| 12137 | |
| 12138 | // src/protocol.ts |
| 12139 | var MAGIC; |
| 12140 | var init_protocol = __esm({ |
| 12141 | "src/protocol.ts"() { |
| 12142 | "use strict"; |
| 12143 | init_protocol_generated(); |
| 12144 | init_protocol_generated(); |
| 12145 | MAGIC = Buffer.from(MAGIC_ASCII, "ascii"); |
| 12146 | } |
| 12147 | }); |
| 12148 | |
| 12149 | // src/rpc.ts |
| 12150 | var init_rpc = __esm({ |
| 12151 | "src/rpc.ts"() { |
| 12152 | "use strict"; |
| 12153 | init_protocol(); |
| 12154 | } |
| 12155 | }); |
| 12156 | |
| 12157 | // src/shims/core.ts |
| 12158 | var init_core = __esm({ |
| 12159 | "src/shims/core.ts"() { |
| 12160 | "use strict"; |
| 12161 | init_protocol(); |
| 12162 | init_json(); |
| 12163 | init_rpc(); |
| 12164 | } |
| 12165 | }); |
| 12166 | |
| 12167 | // src/shims/shell-hooks.ts |
| 12168 | var init_shell_hooks2 = __esm({ |
| 12169 | "src/shims/shell-hooks.ts"() { |
| 12170 | "use strict"; |
| 12171 | } |
| 12172 | }); |
| 12173 | |
| 12174 | // src/shims/hooks.ts |
| 12175 | var init_hooks = __esm({ |
| 12176 | "src/shims/hooks.ts"() { |
| 12177 | "use strict"; |
| 12178 | init_json(); |
| 12179 | } |
| 12180 | }); |
| 12181 | |
| 12182 | // src/shims/storage.ts |
| 12183 | var STORAGE_LIMITS, MAX_RECORD_BYTES; |
| 12184 | var init_storage = __esm({ |
| 12185 | "src/shims/storage.ts"() { |
| 12186 | "use strict"; |
| 12187 | init_json(); |
| 12188 | STORAGE_LIMITS = Object.freeze({ keyBytes: 128, valueBytes: 128 * 1024, totalBytes: 4 * 1024 * 1024, keys: 1024 }); |
| 12189 | MAX_RECORD_BYTES = STORAGE_LIMITS.valueBytes + STORAGE_LIMITS.keyBytes * 6 + 128; |
| 12190 | } |
| 12191 | }); |
| 12192 | |
| 12193 | // src/tier.ts |
| 12194 | var init_tier = __esm({ |
| 12195 | "src/tier.ts"() { |
| 12196 | "use strict"; |
| 12197 | } |
| 12198 | }); |
| 12199 | |
| 12200 | // src/shims/commands.ts |
| 12201 | var NO_ATTACHMENTS; |
| 12202 | var init_commands = __esm({ |
| 12203 | "src/shims/commands.ts"() { |
| 12204 | "use strict"; |
| 12205 | NO_ATTACHMENTS = Object.freeze([]); |
| 12206 | } |
| 12207 | }); |
| 12208 | |
| 12209 | // src/root.ts |
| 12210 | import { AsyncLocalStorage } from "node:async_hooks"; |
| 12211 | var ownerStorage; |
| 12212 | var init_root = __esm({ |
| 12213 | "src/root.ts"() { |
| 12214 | "use strict"; |
| 12215 | init_composition(); |
| 12216 | init_protocol(); |
| 12217 | init_rpc(); |
| 12218 | init_resolve_hooks(); |
| 12219 | init_json(); |
| 12220 | init_core(); |
| 12221 | init_owned(); |
| 12222 | init_shell_hooks2(); |
| 12223 | init_hooks(); |
| 12224 | init_prompt(); |
| 12225 | init_storage(); |
| 12226 | init_mcp(); |
| 12227 | init_skills(); |
| 12228 | init_tier(); |
| 12229 | init_commands(); |
| 12230 | ownerStorage = new AsyncLocalStorage(); |
| 12231 | } |
| 12232 | }); |
| 12233 | |
| 12234 | // src/dsh/persona.ts |
| 12235 | function normalizePersonaConfig(value) { |
| 12236 | if (!value || typeof value !== "object" || Array.isArray(value)) throw new TypeError("persona config must be plain data"); |
| 12237 | const config = value; |
| 12238 | if (Object.keys(config).some((key) => !["prefix", "suffix", "complete", "includeRuntimeContext"].includes(key))) throw new TypeError("persona config has an unsupported field"); |
| 12239 | if (config.complete !== void 0 && config.complete !== false) throw new TypeError("persona replacement belongs to the Core prompt and cannot be imported"); |
| 12240 | if (config.includeRuntimeContext !== void 0 && config.includeRuntimeContext !== true) throw new TypeError("persona runtime-context suppression belongs to the Core prompt and cannot be imported"); |
| 12241 | if (typeof config.prefix !== "string" || config.suffix !== void 0 && typeof config.suffix !== "string") throw new TypeError("persona prefix and suffix must be text"); |
| 12242 | const result = { prefix: config.prefix, suffix: config.suffix ?? "" }; |
| 12243 | for (const [position, text2] of Object.entries(result)) { |
| 12244 | if (Buffer.byteLength(text2, "utf8") > MAX_PROMPT_SECTION_BYTES) throw new RangeError("persona text exceeds 4096 UTF-8 bytes"); |
| 12245 | if (/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f]/u.test(text2)) throw new TypeError("persona text contains control characters"); |
| 12246 | validatePromptTemplate(text2); |
| 12247 | if (text2.trim().length > 0) normalizePromptSection({ id: `persona-${position}`, text: text2, interpolate: "model-cwd" }); |
| 12248 | } |
| 12249 | return Object.freeze(result); |
| 12250 | } |
| 12251 | var PERSONA, reviewedPersonaModule; |
| 12252 | var init_persona = __esm({ |
| 12253 | "src/dsh/persona.ts"() { |
| 12254 | "use strict"; |
| 12255 | init_prompt(); |
| 12256 | init_root(); |
| 12257 | PERSONA = "@deepseek-ai/dsh-persona"; |
| 12258 | reviewedPersonaModule = Object.freeze({ |
| 12259 | name: "persona", |
| 12260 | inject: ["prompt"], |
| 12261 | apply(ctx, value) { |
| 12262 | if (!ownerStorage.getStore()?.scope) throw new Error("persona requires an exact Core-selected entry scope"); |
| 12263 | const config = normalizePersonaConfig(value); |
| 12264 | for (const [position, text2] of Object.entries(config)) { |
| 12265 | if (text2.trim().length > 0) ctx.prompt.registerSection({ id: `persona-${position}`, text: text2, interpolate: "model-cwd" }); |
| 12266 | } |
| 12267 | } |
| 12268 | }); |
| 12269 | } |
| 12270 | }); |
| 12271 | |
| 12272 | // src/dsh/upstream/agent-presets/metadata.ts |
| 12273 | import { join } from "node:path"; |
| 12274 | function text(value) { |
| 12275 | if (typeof value !== "string") return void 0; |
| 12276 | const trimmed = value.trim(); |
| 12277 | return trimmed === "" ? void 0 : trimmed; |
| 12278 | } |
| 12279 | async function readPresetMetadata(directory, readFile3) { |
| 12280 | let raw; |
| 12281 | try { |
| 12282 | raw = await readFile3(join(directory, METADATA_FILE), "utf8"); |
| 12283 | } catch { |
| 12284 | return {}; |
| 12285 | } |
| 12286 | let parsed; |
| 12287 | try { |
| 12288 | parsed = yaml.load(raw); |
| 12289 | } catch { |
| 12290 | return {}; |
| 12291 | } |
| 12292 | if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return {}; |
| 12293 | const record = parsed; |
| 12294 | const name = text(record.name); |
| 12295 | const description = text(record.description); |
| 12296 | const order = typeof record.order === "number" && Number.isFinite(record.order) ? record.order : void 0; |
| 12297 | return { |
| 12298 | ...name === void 0 ? {} : { name }, |
| 12299 | ...description === void 0 ? {} : { description }, |
| 12300 | ...order === void 0 ? {} : { order } |
| 12301 | }; |
| 12302 | } |
| 12303 | var METADATA_FILE; |
| 12304 | var init_metadata = __esm({ |
| 12305 | "src/dsh/upstream/agent-presets/metadata.ts"() { |
| 12306 | "use strict"; |
| 12307 | init_js_yaml(); |
| 12308 | METADATA_FILE = "preset.yml"; |
| 12309 | } |
| 12310 | }); |
| 12311 | |
| 12312 | // src/dsh/upstream/agent-presets/preset.ts |
| 12313 | var PRESET_ID; |
| 12314 | var init_preset = __esm({ |
| 12315 | "src/dsh/upstream/agent-presets/preset.ts"() { |
| 12316 | "use strict"; |
| 12317 | PRESET_ID = /^[a-z0-9][a-z0-9-]*$/; |
| 12318 | } |
| 12319 | }); |
| 12320 | |
| 12321 | // src/dsh/upstream/agent-presets/specifier.ts |
| 12322 | import { isAbsolute as isAbsolute3 } from "node:path"; |
| 12323 | import { pathToFileURL as pathToFileURL3 } from "node:url"; |
| 12324 | function classifyRowSpecifier(name) { |
| 12325 | if (name.startsWith("cordis:")) return { kind: "builtin", specifier: name }; |
| 12326 | if (name.startsWith(".")) return { kind: "preset", specifier: name }; |
| 12327 | if (name.startsWith("file:")) return { kind: "file", specifier: name }; |
| 12328 | if (isAbsolute3(name)) return { kind: "file", specifier: pathToFileURL3(name).href }; |
| 12329 | return { kind: "package", specifier: name }; |
| 12330 | } |
| 12331 | var init_specifier = __esm({ |
| 12332 | "src/dsh/upstream/agent-presets/specifier.ts"() { |
| 12333 | "use strict"; |
| 12334 | } |
| 12335 | }); |
| 12336 | |
| 12337 | // src/dsh/upstream/agent-presets/discovery.ts |
| 12338 | import { isBuiltin as isBuiltin2 } from "node:module"; |
| 12339 | import { join as join2, resolve as resolve3 } from "node:path"; |
| 12340 | import { fileURLToPath as fileURLToPath3, pathToFileURL as pathToFileURL4 } from "node:url"; |
| 12341 | function entryListProblem(rows, at2 = "") { |
| 12342 | if (!Array.isArray(rows)) { |
| 12343 | return at2 === "" ? "the composition must be a top-level list of plugin rows" : `group ${at2} must hold a list of plugin rows`; |
| 12344 | } |
| 12345 | for (const [index, row] of rows.entries()) { |
| 12346 | const label = at2 === "" ? `row ${String(index + 1)}` : `${at2} row ${String(index + 1)}`; |
| 12347 | if (typeof row !== "object" || row === null || Array.isArray(row)) { |
| 12348 | return `${label} is not a plugin row (expected a map with a "name")`; |
| 12349 | } |
| 12350 | const { name, group, config } = row; |
| 12351 | if (typeof name !== "string" || name === "") { |
| 12352 | return `${label} names no plugin (a "name" string is required)`; |
| 12353 | } |
| 12354 | if (group === true) { |
| 12355 | const nested = entryListProblem(config, label); |
| 12356 | if (nested !== void 0) return nested; |
| 12357 | } |
| 12358 | } |
| 12359 | return void 0; |
| 12360 | } |
| 12361 | async function rowResolves(row, presetBase, harnessBase, resolves, io) { |
| 12362 | if (row.kind === "builtin") return true; |
| 12363 | if (row.kind === "package") return isBuiltin2(row.specifier) || resolves(row.specifier, harnessBase); |
| 12364 | const url = row.kind === "file" ? new URL(row.specifier) : new URL(row.specifier, presetBase); |
| 12365 | return await isFile(fileURLToPath3(url), io); |
| 12366 | } |
| 12367 | async function unresolvableRows(rows, presetBase, harnessBase, resolves, io, at2 = "") { |
| 12368 | const found = []; |
| 12369 | for (const [index, entry] of rows.entries()) { |
| 12370 | const row = entry; |
| 12371 | if (Boolean(row.disabled)) continue; |
| 12372 | const positional = at2 === "" ? `row ${String(index + 1)}` : `${at2} row ${String(index + 1)}`; |
| 12373 | if (row.group === true) { |
| 12374 | found.push(...await unresolvableRows(row.config, presetBase, harnessBase, resolves, io, positional)); |
| 12375 | continue; |
| 12376 | } |
| 12377 | if (await rowResolves(classifyRowSpecifier(row.name), presetBase, harnessBase, resolves, io)) continue; |
| 12378 | const label = typeof row.id === "string" && row.id !== "" ? `row "${row.id}"` : positional; |
| 12379 | found.push({ label, name: row.name }); |
| 12380 | } |
| 12381 | return found; |
| 12382 | } |
| 12383 | async function compositionProblem(path, harnessBase, resolves, io) { |
| 12384 | let content; |
| 12385 | try { |
| 12386 | content = await io.readFile(path, "utf8"); |
| 12387 | } catch { |
| 12388 | return `the composition file ${COMPOSITION_FILE} cannot be read`; |
| 12389 | } |
| 12390 | let rows; |
| 12391 | try { |
| 12392 | rows = load(content, { schema: entryListSchema }); |
| 12393 | } catch (error) { |
| 12394 | const full = error instanceof Error ? error.message : String(error); |
| 12395 | return `the composition is not valid YAML: ${full.replace(/\n[\s\S]*$/, "")}`; |
| 12396 | } |
| 12397 | const shape = entryListProblem(rows); |
| 12398 | if (shape !== void 0) return shape; |
| 12399 | const presetBase = new URL(".", pathToFileURL4(path)).href; |
| 12400 | let unresolvable; |
| 12401 | try { |
| 12402 | unresolvable = await unresolvableRows(rows, presetBase, harnessBase, resolves, io); |
| 12403 | } catch (error) { |
| 12404 | const full = error instanceof Error ? error.message : String(error); |
| 12405 | return `the composition's plugins cannot be checked: ${full.replace(/\n[\s\S]*$/, "")}`; |
| 12406 | } |
| 12407 | const [first] = unresolvable; |
| 12408 | if (first === void 0) return void 0; |
| 12409 | if (unresolvable.length === 1) { |
| 12410 | return `${first.label} names a plugin that cannot be resolved: ${first.name}`; |
| 12411 | } |
| 12412 | return `${String(unresolvable.length)} rows name plugins that cannot be resolved: |
| 12413 | ` + unresolvable.map((row) => `- ${row.label}: ${row.name}`).join("\n"); |
| 12414 | } |
| 12415 | async function isFile(path, io) { |
| 12416 | try { |
| 12417 | return (await io.stat(path)).isFile(); |
| 12418 | } catch { |
| 12419 | return false; |
| 12420 | } |
| 12421 | } |
| 12422 | async function scanRoot(root, harnessBase, resolves, io) { |
| 12423 | const dir = resolve3(root.path); |
| 12424 | let children; |
| 12425 | try { |
| 12426 | children = await io.readdir(dir, { withFileTypes: true }); |
| 12427 | } catch (error) { |
| 12428 | if (error.code === "ENOENT") return []; |
| 12429 | throw new Error(`agent-presets: cannot read preset root ${dir}: ${String(error)}`, { cause: error }); |
| 12430 | } |
| 12431 | const found = []; |
| 12432 | for (const child of children) { |
| 12433 | if (!child.isDirectory() || !PRESET_ID.test(child.name)) continue; |
| 12434 | const directory = join2(dir, child.name); |
| 12435 | const path = join2(directory, COMPOSITION_FILE); |
| 12436 | const broken = await isFile(path, io) ? await compositionProblem(path, harnessBase, resolves, io) : `the composition file ${COMPOSITION_FILE} is missing — the directory still occupies the id; delete it or restore the file`; |
| 12437 | const metadata = await readPresetMetadata(directory, io.readFile); |
| 12438 | found.push({ |
| 12439 | id: child.name, |
| 12440 | trust: root.trust, |
| 12441 | path, |
| 12442 | ...metadata, |
| 12443 | ...broken === void 0 ? {} : { broken } |
| 12444 | }); |
| 12445 | } |
| 12446 | return found.sort((left, right) => { |
| 12447 | const leftOrder = left.order ?? Number.POSITIVE_INFINITY; |
| 12448 | const rightOrder = right.order ?? Number.POSITIVE_INFINITY; |
| 12449 | const byOrder = leftOrder === rightOrder ? 0 : leftOrder - rightOrder; |
| 12450 | return byOrder === 0 ? left.id.localeCompare(right.id) : byOrder; |
| 12451 | }); |
| 12452 | } |
| 12453 | async function discoverPresets(roots, harnessBase, resolves, io) { |
| 12454 | const byId = /* @__PURE__ */ new Map(); |
| 12455 | for (const root of roots) { |
| 12456 | for (const preset of await scanRoot(root, harnessBase, resolves, io)) { |
| 12457 | if (byId.has(preset.id)) continue; |
| 12458 | byId.set(preset.id, preset); |
| 12459 | } |
| 12460 | } |
| 12461 | return [...byId.values()]; |
| 12462 | } |
| 12463 | var COMPOSITION_FILE, SHIPPED_PRESET_ROOT; |
| 12464 | var init_discovery = __esm({ |
| 12465 | "src/dsh/upstream/agent-presets/discovery.ts"() { |
| 12466 | "use strict"; |
| 12467 | init_js_yaml(); |
| 12468 | init_src2(); |
| 12469 | init_metadata(); |
| 12470 | init_preset(); |
| 12471 | init_specifier(); |
| 12472 | COMPOSITION_FILE = "agent.cordis.yml"; |
| 12473 | SHIPPED_PRESET_ROOT = fileURLToPath3(new URL("../presets/", import.meta.url)); |
| 12474 | } |
| 12475 | }); |
| 12476 | |
| 12477 | // src/dsh/upstream/agent-presets/composition-inventory.ts |
| 12478 | function disabledContribution(value, evaluateExpression) { |
| 12479 | if (isJsExpr(value)) { |
| 12480 | try { |
| 12481 | return Boolean(evaluateExpression(value.__jsExpr)); |
| 12482 | } catch { |
| 12483 | return "conditional"; |
| 12484 | } |
| 12485 | } |
| 12486 | return Boolean(value); |
| 12487 | } |
| 12488 | function combineDisabled(outer, own) { |
| 12489 | if (outer === true || own === true) return true; |
| 12490 | if (outer === "conditional" || own === "conditional") return "conditional"; |
| 12491 | return false; |
| 12492 | } |
| 12493 | function flattenRows(rows, outerDisabled, evaluateExpression, found) { |
| 12494 | for (const value of rows) { |
| 12495 | const row = value; |
| 12496 | const disabled = combineDisabled(outerDisabled, disabledContribution(row.disabled, evaluateExpression)); |
| 12497 | if (row.group === true) { |
| 12498 | flattenRows(row.config, disabled, evaluateExpression, found); |
| 12499 | continue; |
| 12500 | } |
| 12501 | found.push({ |
| 12502 | entryId: typeof row.id === "string" && row.id !== "" ? row.id : null, |
| 12503 | moduleName: row.name, |
| 12504 | enabled: disabled === true ? false : disabled === "conditional" ? "conditional" : true, |
| 12505 | ...isJsExpr(row.disabled) ? { condition: row.disabled.__jsExpr } : {} |
| 12506 | }); |
| 12507 | } |
| 12508 | } |
| 12509 | async function fileComposition(path, evaluateExpression, readFile3) { |
| 12510 | let rows; |
| 12511 | try { |
| 12512 | rows = load(await readFile3(path, "utf8"), { schema: entryListSchema }); |
| 12513 | } catch (error) { |
| 12514 | return { broken: error instanceof Error ? error.message : String(error) }; |
| 12515 | } |
| 12516 | const problem = entryListProblem(rows); |
| 12517 | if (problem !== void 0) return { broken: problem }; |
| 12518 | const found = []; |
| 12519 | flattenRows(rows, false, evaluateExpression, found); |
| 12520 | return { rows: found }; |
| 12521 | } |
| 12522 | function mountedCompositionRows(tree) { |
| 12523 | const found = []; |
| 12524 | for (const entry of tree.entries()) { |
| 12525 | if (entry.options.group) continue; |
| 12526 | found.push({ |
| 12527 | entryId: entry.id, |
| 12528 | moduleName: entry.options.name, |
| 12529 | enabled: !entry.disabled, |
| 12530 | ...isJsExpr(entry.options.disabled) ? { condition: entry.options.disabled.__jsExpr } : {}, |
| 12531 | ...entry.fiber === void 0 ? {} : { fiberState: entry.fiber.state } |
| 12532 | }); |
| 12533 | } |
| 12534 | return found; |
| 12535 | } |
| 12536 | var init_composition_inventory = __esm({ |
| 12537 | "src/dsh/upstream/agent-presets/composition-inventory.ts"() { |
| 12538 | "use strict"; |
| 12539 | init_js_yaml(); |
| 12540 | init_src(); |
| 12541 | init_src2(); |
| 12542 | init_discovery(); |
| 12543 | } |
| 12544 | }); |
| 12545 | |
| 12546 | // src/dsh/agent-presets.ts |
| 12547 | import { createHash as createHash2 } from "node:crypto"; |
| 12548 | import { resolve as resolve4, relative as relative2, dirname as dirname3, sep as sep2 } from "node:path"; |
| 12549 | import { fileURLToPath as fileURLToPath4, pathToFileURL as pathToFileURL5 } from "node:url"; |
| 12550 | function plain(path) { |
| 12551 | return typeof path === "string" && path.length > 0 && path.length <= 4096 && !/[\\:\u0000-\u001f\u007f]/u.test(path) && !path.startsWith("/") && path.split("/").every((p) => p !== "" && p !== "." && p !== ".."); |
| 12552 | } |
| 12553 | function fail(message) { |
| 12554 | throw new Error(`agent-presets: ${message}`); |
| 12555 | } |
| 12556 | function containedPackageModule(name, documents, files) { |
| 12557 | if (!name || /[\\:\u0000-\u0020\u007f]/u.test(name)) return; |
| 12558 | const parts = name.split("/"); |
| 12559 | const n = name.startsWith("@") ? 2 : 1; |
| 12560 | if (parts.length < n || parts.some((p) => !p || p === "." || p === "..")) return; |
| 12561 | const pkg = parts.slice(0, n).join("/"); |
| 12562 | const packageRoot = `node_modules/${pkg}`; |
| 12563 | const source = documents.get(`${packageRoot}/package.json`); |
| 12564 | if (source === void 0) return; |
| 12565 | let data2; |
| 12566 | try { |
| 12567 | data2 = JSON.parse(source); |
| 12568 | } catch { |
| 12569 | return; |
| 12570 | } |
| 12571 | if (data2.name !== pkg || data2.type !== "module") return; |
| 12572 | const subpath = parts.length === n ? "." : `./${parts.slice(n).join("/")}`; |
| 12573 | const refused = /* @__PURE__ */ Symbol("unsupported package target"); |
| 12574 | function target(value) { |
| 12575 | if (typeof value === "string") return value; |
| 12576 | if (!value || Array.isArray(value) || typeof value !== "object") return refused; |
| 12577 | for (const [condition, child] of Object.entries(value)) { |
| 12578 | if (["node", "import", "default"].includes(condition)) { |
| 12579 | const picked = target(child); |
| 12580 | if (picked !== void 0) return picked; |
| 12581 | } |
| 12582 | } |
| 12583 | } |
| 12584 | let entry; |
| 12585 | if (data2.exports !== void 0) { |
| 12586 | const value = data2.exports; |
| 12587 | entry = value && typeof value === "object" && !Array.isArray(value) && Object.keys(value).some((k) => k.startsWith(".")) ? target(value[subpath]) : subpath === "." ? target(value) : void 0; |
| 12588 | } else if (subpath === ".") entry = typeof data2.main === "string" ? data2.main : "./index.js"; |
| 12589 | else entry = subpath; |
| 12590 | if (typeof entry !== "string" || !entry.startsWith("./") || !plain(entry.slice(2))) return; |
| 12591 | const path = `${packageRoot}/${entry.slice(2)}`; |
| 12592 | if (!/\.(mjs|js|mts)$/.test(path) || !SHA.test(files[path] ?? "")) return; |
| 12593 | return { name, path, sha256: files[path] }; |
| 12594 | } |
| 12595 | async function reviewAgentPresets(input) { |
| 12596 | const { composition } = input; |
| 12597 | const files = composition.files; |
| 12598 | if (!files || Object.keys(files).length > 4096 || !Array.isArray(input.directories) || input.directories.length > 4096) fail("invalid source inventory"); |
| 12599 | const base = resolve4("codewhale-reviewed-agent-presets"); |
| 12600 | const baseUrl = pathToFileURL5(`${base}${sep2}`).href; |
| 12601 | function key(path) { |
| 12602 | const inside = relative2(base, path).split(sep2).join("/"); |
| 12603 | if (!plain(inside)) fail("path escapes the admitted source root"); |
| 12604 | return inside; |
| 12605 | } |
| 12606 | const documents = /* @__PURE__ */ new Map(); |
| 12607 | let bytes = 0; |
| 12608 | for (const doc of input.documents) { |
| 12609 | if (!plain(doc.path) || !SHA.test(doc.sha256) || files[doc.path] !== doc.sha256 || hash(doc.source) !== doc.sha256 || documents.has(doc.path)) fail("document changed or is outside the source receipt"); |
| 12610 | bytes += Buffer.byteLength(doc.source); |
| 12611 | if (Buffer.byteLength(doc.source) > 1024 * 1024 || bytes > 4 * 1024 * 1024) fail("documents exceed their bound"); |
| 12612 | documents.set(doc.path, doc.source); |
| 12613 | } |
| 12614 | const directories = new Set(input.directories); |
| 12615 | for (const path of directories) if (!plain(path)) fail("invalid source directory"); |
| 12616 | for (const path of Object.keys(files)) if (!plain(path) || !SHA.test(files[path])) fail("invalid source file receipt"); |
| 12617 | const invalid = /* @__PURE__ */ new Set(); |
| 12618 | const parsed = /* @__PURE__ */ new Map(); |
| 12619 | const io = { |
| 12620 | async readFile(path) { |
| 12621 | const relative4 = key(path); |
| 12622 | if (invalid.has(relative4)) throw new Error("composition exceeds its data/shape bound"); |
| 12623 | const text2 = documents.get(relative4); |
| 12624 | if (text2 === void 0) throw new Error("document not admitted"); |
| 12625 | return text2; |
| 12626 | }, |
| 12627 | async stat(path) { |
| 12628 | return { isFile: () => Object.hasOwn(files, key(path)) }; |
| 12629 | }, |
| 12630 | async readdir(path) { |
| 12631 | const prefix = `${key(path)}/`; |
| 12632 | if (!directories.has(prefix.slice(0, -1))) { |
| 12633 | const e = new Error("missing root"); |
| 12634 | Object.assign(e, { code: "ENOENT" }); |
| 12635 | throw e; |
| 12636 | } |
| 12637 | return [...directories].filter((p) => p.startsWith(prefix) && !p.slice(prefix.length).includes("/")).map((p) => ({ name: p.slice(prefix.length), isDirectory: () => true })); |
| 12638 | } |
| 12639 | }; |
| 12640 | const { reviewComposition: reviewComposition2, parsePresetComposition: parsePresetComposition2, compositionRowProblem: compositionRowProblem2, hasReviewedRowBridge: hasReviewedRowBridge2 } = await Promise.resolve().then(() => (init_composition(), composition_exports)); |
| 12641 | for (const [path, source] of documents) { |
| 12642 | if (!path.endsWith("/agent.cordis.yml")) continue; |
| 12643 | try { |
| 12644 | parsed.set(path, parsePresetComposition2(source)); |
| 12645 | } catch { |
| 12646 | invalid.add(path); |
| 12647 | } |
| 12648 | } |
| 12649 | const top = reviewComposition2(composition); |
| 12650 | const rosterRows = []; |
| 12651 | function visit(rows2) { |
| 12652 | for (const row of rows2) { |
| 12653 | if (row.group === true || row.name === "cordis:group" || row.name === "@deepseek-ai/cordis-plugin-group") visit(row.config ?? []); |
| 12654 | else if (row.name === AGENT_PRESETS) rosterRows.push(row); |
| 12655 | } |
| 12656 | } |
| 12657 | visit(top.entries); |
| 12658 | if (rosterRows.length !== 1) fail("exactly one raw roster row is required"); |
| 12659 | const config = rosterRows[0].config ?? {}; |
| 12660 | if (!config || Array.isArray(config) || typeof config !== "object" || Object.keys(config).some((k) => !["default", "roots", "includeShippedRoot", "includeUserRoot"].includes(k))) fail("roster configuration must be literal upstream fields"); |
| 12661 | for (const k of ["includeShippedRoot", "includeUserRoot"]) if (config[k] !== void 0 && typeof config[k] !== "boolean") fail("root gates must be literal booleans"); |
| 12662 | if (config.default !== void 0 && (typeof config.default !== "string" || !PRESET_ID.test(config.default) || config.default.length > 64)) fail("invalid default id"); |
| 12663 | const roots = []; |
| 12664 | if (config.includeShippedRoot !== false) { |
| 12665 | const candidates = [...documents.entries()].filter(([p, text2]) => { |
| 12666 | if (p !== "package.json" && !p.endsWith("/package.json")) return false; |
| 12667 | try { |
| 12668 | return JSON.parse(text2).name === AGENT_PRESETS; |
| 12669 | } catch { |
| 12670 | return false; |
| 12671 | } |
| 12672 | }); |
| 12673 | if (candidates.length !== 1) fail("shipped root requires exactly one admitted agent-presets package"); |
| 12674 | const folder = dirname3(candidates[0][0]).split(sep2).join("/"); |
| 12675 | const root = folder === "." ? "presets" : `${folder}/presets`; |
| 12676 | if (!directories.has(root)) fail("shipped preset root was not admitted"); |
| 12677 | roots.push({ path: resolve4(base, root), trust: "system" }); |
| 12678 | } |
| 12679 | if (config.roots !== void 0 && !Array.isArray(config.roots)) fail("roots must be a literal list"); |
| 12680 | for (const root of config.roots ?? []) { |
| 12681 | if (!root || Object.keys(root).some((k) => !["path", "trust"].includes(k)) || !plain(root.path) || !["system", "user"].includes(root.trust)) fail("configured roots must stay inside the admitted package"); |
| 12682 | if (!directories.has(root.path)) fail("configured preset root was not admitted"); |
| 12683 | roots.push({ path: resolve4(base, root.path), trust: root.trust }); |
| 12684 | } |
| 12685 | if (config.includeUserRoot !== false) { |
| 12686 | if (!directories.has(".agent-presets")) fail("user root requires an admitted .agent-presets tree; ambient home discovery is refused"); |
| 12687 | roots.push({ path: resolve4(base, ".agent-presets"), trust: "user" }); |
| 12688 | } |
| 12689 | if (roots.length > 64) fail("too many roots"); |
| 12690 | const declared = new Map(composition.modules.map((m) => [m.name, m])); |
| 12691 | if (declared.size !== composition.modules.length) fail("duplicate module name receipt"); |
| 12692 | const found = await discoverPresets(roots, baseUrl, (name) => hasReviewedRowBridge2(name) || declared.has(name) || containedPackageModule(name, documents, files) !== void 0, io); |
| 12693 | if (found.length > MAX_PRESETS) fail("too many presets"); |
| 12694 | const prepared = []; |
| 12695 | const rows = []; |
| 12696 | const inventory = /* @__PURE__ */ Object.create(null); |
| 12697 | for (const preset of found) { |
| 12698 | let resolveRows2 = function(children) { |
| 12699 | for (const row of children) { |
| 12700 | if (Boolean(row.disabled) && !isJsExpr(row.disabled)) continue; |
| 12701 | if (row.group === true || row.name === "cordis:group" || row.name === "@deepseek-ai/cordis-plugin-group") { |
| 12702 | resolveRows2(row.config ?? []); |
| 12703 | continue; |
| 12704 | } |
| 12705 | const specifier = classifyRowSpecifier(row.name); |
| 12706 | if (row.name === PERSONA) normalizePersonaConfig(row.config); |
| 12707 | if (specifier.kind === "builtin" || hasReviewedRowBridge2(row.name)) continue; |
| 12708 | if (row.name === AGENT_PRESETS) fail("nested roster cannot create a second selection authority"); |
| 12709 | const problem = compositionRowProblem2(row.name); |
| 12710 | if (problem) fail(problem); |
| 12711 | let receipt; |
| 12712 | if (specifier.kind === "package") receipt = declared.get(row.name) ?? containedPackageModule(row.name, documents, files); |
| 12713 | else { |
| 12714 | const url = specifier.kind === "file" ? new URL(specifier.specifier) : new URL(specifier.specifier, pathToFileURL5(preset.path).href); |
| 12715 | const path2 = key(fileURLToPath4(url)); |
| 12716 | if (files[path2] !== void 0) receipt = { name: row.name, path: path2, sha256: files[path2] }; |
| 12717 | } |
| 12718 | if (!receipt || files[receipt.path] !== receipt.sha256) { |
| 12719 | if (isJsExpr(row.disabled)) continue; |
| 12720 | fail("row module has no exact admitted receipt"); |
| 12721 | } |
| 12722 | modules.set(row.name, receipt); |
| 12723 | } |
| 12724 | }; |
| 12725 | var resolveRows = resolveRows2; |
| 12726 | if (preset.id.length > 64 || (preset.name?.length ?? 0) > 1024 || (preset.description?.length ?? 0) > 4096) fail("preset metadata exceeds its bound"); |
| 12727 | const metadata = { |
| 12728 | id: preset.id, |
| 12729 | trust: preset.trust, |
| 12730 | is_default: preset.id === config.default, |
| 12731 | ...preset.name === void 0 ? {} : { name: preset.name }, |
| 12732 | ...preset.description === void 0 ? {} : { description: preset.description }, |
| 12733 | ...preset.order === void 0 ? {} : { order: preset.order }, |
| 12734 | ...preset.broken === void 0 ? {} : { broken: preset.broken } |
| 12735 | }; |
| 12736 | rows.push(metadata); |
| 12737 | const path = key(preset.path); |
| 12738 | inventory[preset.id] = { path, ...preset.broken !== void 0 ? { broken: preset.broken } : await fileComposition(preset.path, () => { |
| 12739 | throw new Error("conditional until mounted"); |
| 12740 | }, io.readFile) }; |
| 12741 | if (preset.broken !== void 0) continue; |
| 12742 | const source = await io.readFile(preset.path, "utf8"); |
| 12743 | const entries = parsed.get(key(preset.path)); |
| 12744 | const modules = /* @__PURE__ */ new Map(); |
| 12745 | try { |
| 12746 | resolveRows2(entries); |
| 12747 | } catch (error) { |
| 12748 | metadata.broken = error instanceof Error ? error.message : "preset preparation refused"; |
| 12749 | continue; |
| 12750 | } |
| 12751 | const layer = JSON.stringify([{ insert: entries }]); |
| 12752 | const spec = { version: 1, layers: [{ path: key(preset.path), sha256: hash(layer), source: layer }], modules: [...modules.values()], files }; |
| 12753 | reviewComposition2(spec); |
| 12754 | prepared.push({ metadata, composition: spec, source }); |
| 12755 | } |
| 12756 | if (config.default !== void 0 && !prepared.some((p) => p.metadata.id === config.default)) fail("default preset is missing or broken"); |
| 12757 | if (!prepared.length) fail("no admitted usable preset"); |
| 12758 | if (Buffer.byteLength(JSON.stringify(inventory)) > 4 * 1024 * 1024) fail("composition inventory exceeds its bound"); |
| 12759 | return { catalog: { version: 1, ...config.default === void 0 ? {} : { default: config.default }, mode_selection_enabled: true, presets: rows, inventory }, presets: prepared }; |
| 12760 | } |
| 12761 | function defineReviewedAgentPresets(mount) { |
| 12762 | return class ReviewedAgentPresets extends Service { |
| 12763 | static inject = ["loader"]; |
| 12764 | snapshot; |
| 12765 | selfCtx; |
| 12766 | constructor(ctx, config) { |
| 12767 | super(ctx, "agentPresets"); |
| 12768 | this.selfCtx = ctx; |
| 12769 | const snapshot = config?.codewhale_reviewed; |
| 12770 | if (!snapshot || snapshot.catalog?.version !== 1 || !snapshot.catalog.presets.some((p) => p.id === snapshot.selected?.metadata.id && !p.broken)) fail("raw roster needs an installer-minted preset receipt"); |
| 12771 | this.snapshot = structuredClone(snapshot); |
| 12772 | } |
| 12773 | mounting; |
| 12774 | mounted; |
| 12775 | mountSelected() { |
| 12776 | return this.mounting ??= mount(this.selfCtx, this.snapshot.base_url, this.snapshot.selected.composition).then((result) => this.mounted = result); |
| 12777 | } |
| 12778 | async list() { |
| 12779 | return this.snapshot.catalog.presets.map((row) => ({ ...structuredClone(row), path: fileURLToPath4(new URL(this.snapshot.catalog.inventory[row.id].path, this.snapshot.base_url)) })); |
| 12780 | } |
| 12781 | async remoteExportList() { |
| 12782 | return { presets: this.snapshot.catalog.presets.map(({ is_default, entry, ...row }) => ({ ...structuredClone(row), isDefault: is_default })), authorable: false, defaultId: this.defaultId, modeSelectionEnabled: this.snapshot.catalog.mode_selection_enabled }; |
| 12783 | } |
| 12784 | get defaultId() { |
| 12785 | return this.snapshot.catalog.default; |
| 12786 | } |
| 12787 | get authorable() { |
| 12788 | return false; |
| 12789 | } |
| 12790 | async resolve(id = this.defaultId) { |
| 12791 | const row = (await this.list()).find((p) => p.id === id); |
| 12792 | if (!row) fail("preset not found"); |
| 12793 | return row; |
| 12794 | } |
| 12795 | composedPreset() { |
| 12796 | return this.snapshot.selected.metadata.id; |
| 12797 | } |
| 12798 | async compositionInventory() { |
| 12799 | return this.snapshot.catalog.presets.map((row) => { |
| 12800 | const identity = { id: row.id, trust: row.trust, ...row.name === void 0 ? {} : { name: row.name }, isDefault: row.id === this.defaultId }; |
| 12801 | if (row.id === this.composedPreset() && this.mounted) return { ...identity, rows: mountedCompositionRows(this.mounted.tree) }; |
| 12802 | const read = this.snapshot.catalog.inventory[row.id]; |
| 12803 | if (row.broken || "broken" in read) return { ...identity, broken: row.broken ?? ("broken" in read ? read.broken : void 0), rows: [] }; |
| 12804 | return { ...identity, rows: structuredClone(read.rows) }; |
| 12805 | }); |
| 12806 | } |
| 12807 | async readDocument(id) { |
| 12808 | if (id !== this.composedPreset()) fail("read another preset through Core file authority"); |
| 12809 | return { agentPreset: id, trust: this.snapshot.selected.metadata.trust, content: this.snapshot.selected.source }; |
| 12810 | } |
| 12811 | select() { |
| 12812 | fail("select through Core AgentProfile/native preset selection before a turn"); |
| 12813 | } |
| 12814 | recompose() { |
| 12815 | fail("Core owns the captured agent selection and blank-session check"); |
| 12816 | } |
| 12817 | copy() { |
| 12818 | fail("copy through Core file/install/review/reload authority"); |
| 12819 | } |
| 12820 | remove() { |
| 12821 | fail("delete through Core file/install/review/reload authority"); |
| 12822 | } |
| 12823 | }; |
| 12824 | } |
| 12825 | var AGENT_PRESETS, MAX_PRESETS, hash, SHA; |
| 12826 | var init_agent_presets = __esm({ |
| 12827 | "src/dsh/agent-presets.ts"() { |
| 12828 | "use strict"; |
| 12829 | init_persona(); |
| 12830 | init_lib2(); |
| 12831 | init_discovery(); |
| 12832 | init_preset(); |
| 12833 | init_specifier(); |
| 12834 | init_composition_inventory(); |
| 12835 | init_src(); |
| 12836 | AGENT_PRESETS = "@deepseek-ai/dsh-agent-presets"; |
| 12837 | MAX_PRESETS = 64; |
| 12838 | hash = (bytes) => createHash2("sha256").update(bytes).digest("hex"); |
| 12839 | SHA = /^[a-f0-9]{64}$/; |
| 12840 | } |
| 12841 | }); |
| 12842 | |
| 12843 | // src/dsh/composition.ts |
| 12844 | var composition_exports = {}; |
| 12845 | __export(composition_exports, { |
| 12846 | ReviewedLoader: () => ReviewedLoader, |
| 12847 | compositionRowProblem: () => compositionRowProblem, |
| 12848 | hasReviewedRowBridge: () => hasReviewedRowBridge, |
| 12849 | installCompositionLoader: () => installCompositionLoader, |
| 12850 | mountReviewedComposition: () => mountReviewedComposition, |
| 12851 | mountReviewedPreset: () => mountReviewedPreset, |
| 12852 | parsePresetComposition: () => parsePresetComposition, |
| 12853 | reviewComposition: () => reviewComposition |
| 12854 | }); |
| 12855 | import { createHash as createHash3 } from "node:crypto"; |
| 12856 | import { readFile as readFile2 } from "node:fs/promises"; |
| 12857 | import { isAbsolute as isAbsolute4, relative as relative3, resolve as resolve5, sep as sep3 } from "node:path"; |
| 12858 | import { fileURLToPath as fileURLToPath5 } from "node:url"; |
| 12859 | function digest(bytes) { |
| 12860 | return createHash3("sha256").update(bytes).digest("hex"); |
| 12861 | } |
| 12862 | function plainRelative(path) { |
| 12863 | return typeof path === "string" && path.length > 0 && path.length <= 4096 && !isAbsolute4(path) && !path.startsWith("/") && !/[\\:\u0000-\u001f\u007f]/u.test(path) && path.split("/").every((part) => part !== "" && part !== "." && part !== ".."); |
| 12864 | } |
| 12865 | function boundData(root) { |
| 12866 | let nodes = 0; |
| 12867 | let bytes = 0; |
| 12868 | const ancestors = /* @__PURE__ */ new Set(); |
| 12869 | function visit(value, depth) { |
| 12870 | if (++nodes > MAX_DATA_NODES || depth > MAX_DEPTH) throw new Error("composition data exceeds its resource limit"); |
| 12871 | if (typeof value === "string") bytes += Buffer.byteLength(value); |
| 12872 | if (bytes > MAX_DATA_BYTES) throw new Error("composition expanded text exceeds 4 MiB"); |
| 12873 | if (value === null || typeof value !== "object") return; |
| 12874 | if (ancestors.has(value)) throw new Error("cyclic configuration data is unsupported"); |
| 12875 | ancestors.add(value); |
| 12876 | if (!Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) { |
| 12877 | throw new Error("composition configuration must be plain data"); |
| 12878 | } |
| 12879 | for (const [key, child] of Object.entries(value)) { |
| 12880 | bytes += Buffer.byteLength(key); |
| 12881 | visit(child, depth + 1); |
| 12882 | } |
| 12883 | ancestors.delete(value); |
| 12884 | } |
| 12885 | visit(root, 0); |
| 12886 | } |
| 12887 | function assignmentSafe(value) { |
| 12888 | if (Object.hasOwn(value, "__proto__")) throw new Error("prototype-mutating entry field is unsupported"); |
| 12889 | } |
| 12890 | function checkRows(rows, depth = 0, count = { value: 0 }) { |
| 12891 | if (depth > MAX_DEPTH) throw new Error("composition entry nesting exceeds 32 levels"); |
| 12892 | for (const row of rows) { |
| 12893 | if (++count.value > MAX_ROWS) throw new Error("composition exceeds 1024 entry rows"); |
| 12894 | if (row === null || typeof row !== "object" || Array.isArray(row)) throw new Error("entry row must be an object"); |
| 12895 | assignmentSafe(row); |
| 12896 | if (row.id !== void 0 && (typeof row.id !== "string" || row.id.length > 512)) throw new Error("entry id must be a bounded string"); |
| 12897 | if (!(row.group === true && row.name === void 0) && (typeof row.name !== "string" || row.name.length === 0 || row.name.length > 4096)) throw new Error("entry name must be a bounded string"); |
| 12898 | if ((row.group || row.name === "cordis:group" || row.name === "@deepseek-ai/cordis-plugin-group") && Array.isArray(row.config)) checkRows(row.config, depth + 1, count); |
| 12899 | } |
| 12900 | } |
| 12901 | function parsePresetComposition(source) { |
| 12902 | if (Buffer.byteLength(source) > MAX_SOURCE_BYTES) throw new Error("preset source exceeds its limit"); |
| 12903 | const rows = load(source, { schema: entryListSchema }); |
| 12904 | boundData(rows); |
| 12905 | if (!Array.isArray(rows)) throw new Error("preset composition must be an entry list"); |
| 12906 | checkRows(rows); |
| 12907 | return rows; |
| 12908 | } |
| 12909 | function reviewComposition(spec) { |
| 12910 | if (!spec || spec.version !== 1 || !Array.isArray(spec.layers) || spec.layers.length === 0 || spec.layers.length > MAX_LAYERS) { |
| 12911 | throw new Error("composition needs 1–64 reviewed layers"); |
| 12912 | } |
| 12913 | let sourceBytes = 0; |
| 12914 | const patches = []; |
| 12915 | const locations = []; |
| 12916 | const layers = []; |
| 12917 | for (const layer of spec.layers) { |
| 12918 | if (!layer || !plainRelative(layer.path) || typeof layer.source !== "string" || typeof layer.sha256 !== "string" || !SHA256.test(layer.sha256)) throw new Error("invalid reviewed layer"); |
| 12919 | sourceBytes += Buffer.byteLength(layer.source); |
| 12920 | if (sourceBytes > MAX_SOURCE_BYTES || digest(layer.source) !== layer.sha256) throw new Error("layer source changed or exceeds 1 MiB"); |
| 12921 | let parsed; |
| 12922 | try { |
| 12923 | parsed = load(layer.source, { schema: entryListSchema }); |
| 12924 | } catch { |
| 12925 | throw new Error("invalid DSH patch data"); |
| 12926 | } |
| 12927 | if (!Array.isArray(parsed)) throw new Error("DSH patch layer must be a list"); |
| 12928 | boundData(parsed); |
| 12929 | for (const patch of parsed) { |
| 12930 | if (!patch || typeof patch !== "object" || Array.isArray(patch)) throw new Error("patch must be an object"); |
| 12931 | assignmentSafe(patch); |
| 12932 | if (patch.insert !== void 0 && patch.insert !== null) { |
| 12933 | if (!Array.isArray(patch.insert)) throw new Error("patch insert must be a list"); |
| 12934 | checkRows(patch.insert); |
| 12935 | } |
| 12936 | } |
| 12937 | patches.push(...parsed); |
| 12938 | locations.push(...parsed.map((_, i2) => ({ layer: layer.path, patch: i2 + 1 }))); |
| 12939 | layers.push({ path: layer.path, sha256: layer.sha256 }); |
| 12940 | } |
| 12941 | boundData(patches); |
| 12942 | const warnings = []; |
| 12943 | const skipped = []; |
| 12944 | let entries = []; |
| 12945 | for (const [i2, patch] of patches.entries()) { |
| 12946 | entries = applyEntryPatches(entries, [patch], (message, ...args) => { |
| 12947 | let index = 0; |
| 12948 | const reason = message.replace(/%C/g, () => JSON.stringify(args[index++])); |
| 12949 | warnings.push(reason); |
| 12950 | skipped.push({ ...typeof patch.id === "string" ? { row: patch.id } : {}, ...typeof patch.name === "string" ? { package: patch.name } : {}, reason, ...locations[i2] }); |
| 12951 | }); |
| 12952 | } |
| 12953 | boundData(entries); |
| 12954 | checkRows(entries); |
| 12955 | return { version: 1, entries, warnings, skipped, layers }; |
| 12956 | } |
| 12957 | function hasReviewedRowBridge(name) { |
| 12958 | return name === "@deepseek-ai/dsh-mcp-client" || name === "@deepseek-ai/dsh-skill-filesystem" || name === "@deepseek-ai/dsh-hooks-claude-code" || name === "@deepseek-ai/dsh-hooks-codex" || name === PERSONA; |
| 12959 | } |
| 12960 | function compositionRowProblem(name) { |
| 12961 | return UNSUPPORTED_ROWS.get(name); |
| 12962 | } |
| 12963 | function installCompositionLoader(root) { |
| 12964 | if (loaders.has(root)) return; |
| 12965 | const ctx = root.isolate("loader"); |
| 12966 | const fiber = ctx.plugin(ReviewedLoader, {}); |
| 12967 | loaders.set(root, { ctx, fiber }); |
| 12968 | } |
| 12969 | function validateInventory(group) { |
| 12970 | for (const row of group.data) { |
| 12971 | const entry = group.tree.store[row.id]; |
| 12972 | if (!entry || entry.parent !== group || entry.options !== row) { |
| 12973 | throw new Error(`composition row ${JSON.stringify(row.id ?? row.name)} was not created`); |
| 12974 | } |
| 12975 | if (entry.disabled) continue; |
| 12976 | if (entry.subgroup) validateInventory(entry.subgroup); |
| 12977 | if (entry.subtree) validateInventory(entry.subtree.root); |
| 12978 | } |
| 12979 | } |
| 12980 | async function mountReviewedComposition(ctx, baseUrl, spec) { |
| 12981 | const review = reviewComposition(spec); |
| 12982 | function groups(rows) { |
| 12983 | for (const row of rows) { |
| 12984 | if (row.group === true && row.name === void 0) row.name = "cordis:group"; |
| 12985 | if (row.group === true && Array.isArray(row.config)) groups(row.config); |
| 12986 | } |
| 12987 | } |
| 12988 | groups(review.entries); |
| 12989 | const installed = loaders.get(ctx.root); |
| 12990 | if (!installed) throw new Error("composition loader was not installed by this host"); |
| 12991 | await installed.fiber.await(); |
| 12992 | const loaderCtx = ctx.extend({ |
| 12993 | baseUrl, |
| 12994 | [Context.isolate]: Object.assign(Object.create(ctx[Context.isolate]), { |
| 12995 | loader: installed.ctx[Context.isolate].loader |
| 12996 | }) |
| 12997 | }); |
| 12998 | const config = { baseUrl, spec, review, releaseClosure: admitReviewedClosure(baseUrl, spec.files) }; |
| 12999 | const carrier = loaderCtx.plugin(ReviewedCarrier, config); |
| 13000 | let disposed = false; |
| 13001 | const dispose = async () => { |
| 13002 | if (disposed) return; |
| 13003 | disposed = true; |
| 13004 | try { |
| 13005 | await mountedTrees.get(config)?.dispose(); |
| 13006 | await carrier.dispose(); |
| 13007 | } finally { |
| 13008 | config.releaseClosure(); |
| 13009 | } |
| 13010 | }; |
| 13011 | ctx.effect(() => dispose, "reviewed DSH composition teardown"); |
| 13012 | try { |
| 13013 | await carrier.await(); |
| 13014 | const mount = mountedTrees.get(config); |
| 13015 | if (!mount || carrier.state !== FiberState.ACTIVE) throw new Error("reviewed composition carrier did not activate"); |
| 13016 | return { tree: mount.tree, dispose }; |
| 13017 | } catch (error) { |
| 13018 | await dispose().catch(() => void 0); |
| 13019 | throw error; |
| 13020 | } |
| 13021 | } |
| 13022 | function leakedServices(ctx, mount) { |
| 13023 | const rootIsolate = ctx.root[Context.isolate]; |
| 13024 | const leaked = []; |
| 13025 | for (const key of Object.getOwnPropertySymbols(ctx.reflect.store)) { |
| 13026 | const impl = ctx.reflect.store[key]; |
| 13027 | if (impl === void 0) continue; |
| 13028 | let current2 = impl.fiber; |
| 13029 | while (current2 !== mount && current2.parent.fiber !== current2) current2 = current2.parent.fiber; |
| 13030 | if (current2 === mount && rootIsolate[impl.name] === key) leaked.push(impl.name); |
| 13031 | } |
| 13032 | return leaked.sort((left, right) => left.localeCompare(right)); |
| 13033 | } |
| 13034 | async function mountReviewedPreset(ctx, baseUrl, spec, catalog, selected) { |
| 13035 | if (!selected) throw new Error("agent-presets: explicit selection is required when no default is configured"); |
| 13036 | const entries = structuredClone(reviewComposition(spec).entries); |
| 13037 | let found = 0; |
| 13038 | function prepare(rows) { |
| 13039 | for (const row of rows) { |
| 13040 | if (row.group === true || row.name === "cordis:group" || row.name === "@deepseek-ai/cordis-plugin-group") { |
| 13041 | prepare(row.config); |
| 13042 | } else if (row.name === AGENT_PRESETS) { |
| 13043 | found++; |
| 13044 | row.isolate = { ...row.isolate, agentPresets: true }; |
| 13045 | row.config = { codewhale_reviewed: { catalog, selected, base_url: baseUrl } }; |
| 13046 | } |
| 13047 | } |
| 13048 | } |
| 13049 | prepare(entries); |
| 13050 | if (found !== 1) throw new Error("exactly one raw roster row is required for a selected preset"); |
| 13051 | const source = JSON.stringify([{ insert: entries }]); |
| 13052 | const top = await mountReviewedComposition(ctx, baseUrl, { ...spec, layers: [{ path: "selected-preset.json", sha256: digest(source), source }] }); |
| 13053 | try { |
| 13054 | const entry = [...top.tree.entries()].find((entry2) => entry2.options.name === AGENT_PRESETS && !entry2.disabled); |
| 13055 | const roster = entry?.ctx.get("agentPresets"); |
| 13056 | if (!roster) throw new Error("selected raw roster did not become active"); |
| 13057 | await roster.mountSelected(); |
| 13058 | return top; |
| 13059 | } catch (error) { |
| 13060 | await top.dispose(); |
| 13061 | throw error; |
| 13062 | } |
| 13063 | } |
| 13064 | var MAX_LAYERS, MAX_SOURCE_BYTES, MAX_DATA_BYTES, MAX_DATA_NODES, MAX_ROWS, MAX_DEPTH, SHA256, UNSUPPORTED_ROWS, ReviewedGroup, ReviewedLoader, loaders, ReviewedTree, mountedTrees, ReviewedCarrier; |
| 13065 | var init_composition = __esm({ |
| 13066 | "src/dsh/composition.ts"() { |
| 13067 | "use strict"; |
| 13068 | init_lib2(); |
| 13069 | init_fiber_state(); |
| 13070 | init_src(); |
| 13071 | init_src2(); |
| 13072 | init_js_yaml(); |
| 13073 | init_mcp2(); |
| 13074 | init_skill_filesystem(); |
| 13075 | init_shell_hooks(); |
| 13076 | init_resolve_hooks(); |
| 13077 | init_persona(); |
| 13078 | init_agent_presets(); |
| 13079 | MAX_LAYERS = 64; |
| 13080 | MAX_SOURCE_BYTES = 1024 * 1024; |
| 13081 | MAX_DATA_BYTES = 4 * 1024 * 1024; |
| 13082 | MAX_DATA_NODES = 1e5; |
| 13083 | MAX_ROWS = 1024; |
| 13084 | MAX_DEPTH = 32; |
| 13085 | SHA256 = /^[a-f0-9]{64}$/; |
| 13086 | UNSUPPORTED_ROWS = /* @__PURE__ */ new Map(); |
| 13087 | ReviewedGroup = class extends Group { |
| 13088 | static inject = ["loader"]; |
| 13089 | }; |
| 13090 | ReviewedLoader = class extends Loader { |
| 13091 | constructor(ctx, config) { |
| 13092 | super(ctx, config); |
| 13093 | this.builtins.group = ReviewedGroup; |
| 13094 | } |
| 13095 | }; |
| 13096 | loaders = /* @__PURE__ */ new WeakMap(); |
| 13097 | ReviewedTree = class extends EntryTree { |
| 13098 | base; |
| 13099 | modules; |
| 13100 | spec; |
| 13101 | constructor(ctx, base, spec) { |
| 13102 | super(ctx); |
| 13103 | this.base = base; |
| 13104 | this.spec = spec; |
| 13105 | const modules = /* @__PURE__ */ new Map(); |
| 13106 | if (!Array.isArray(spec.modules) || spec.modules.length > MAX_ROWS || !spec.files || Object.keys(spec.files).length > 4096) throw new Error("invalid reviewed module closure"); |
| 13107 | for (const module of spec.modules) { |
| 13108 | if (!module || typeof module.name !== "string" || module.name.length === 0 || module.name.length > 4096 || modules.has(module.name) || !plainRelative(module.path) || !SHA256.test(module.sha256) || spec.files[module.path] !== module.sha256) throw new Error("module map differs from reviewed closure"); |
| 13109 | modules.set(module.name, module); |
| 13110 | } |
| 13111 | this.modules = modules; |
| 13112 | } |
| 13113 | /** A reviewed composition is input; teardown and self-disposal never rewrite it. */ |
| 13114 | write() { |
| 13115 | } |
| 13116 | import(name) { |
| 13117 | if (name === PERSONA) return reviewedPersonaModule; |
| 13118 | if (name === AGENT_PRESETS) return defineReviewedAgentPresets(mountReviewedComposition); |
| 13119 | if (name === "cordis:group" || name === "@deepseek-ai/cordis-plugin-group") return ReviewedGroup; |
| 13120 | if (name === "@deepseek-ai/dsh-mcp-client") return reviewedMcpModule(); |
| 13121 | if (name === "@deepseek-ai/dsh-skill-filesystem") return reviewedSkillModule(); |
| 13122 | if (name === "@deepseek-ai/dsh-hooks-claude-code") return reviewedHookModule("claude-code", fileURLToPath5(this.base), this.spec.files); |
| 13123 | if (name === "@deepseek-ai/dsh-hooks-codex") return reviewedHookModule("codex", fileURLToPath5(this.base), this.spec.files); |
| 13124 | if (UNSUPPORTED_ROWS.has(name)) throw new Error(`${name}: ${UNSUPPORTED_ROWS.get(name)}`); |
| 13125 | const module = this.modules.get(name); |
| 13126 | if (!module) throw new Error(`row requires ${JSON.stringify(name)}, absent from the reviewed module closure`); |
| 13127 | return this.importReviewed(module); |
| 13128 | } |
| 13129 | async importReviewed(module) { |
| 13130 | const root = fileURLToPath5(this.base); |
| 13131 | const path = resolve5(root, module.path); |
| 13132 | const inside = relative3(root, path); |
| 13133 | if (inside.startsWith(`..${sep3}`) || inside === ".." || isAbsolute4(inside)) throw new Error("module escapes reviewed bundle"); |
| 13134 | if (this.spec.files[module.path] !== module.sha256 || digest(await readFile2(path)) !== module.sha256) throw new Error("module changed after review"); |
| 13135 | return importReviewedModule(this.base, module.path); |
| 13136 | } |
| 13137 | }; |
| 13138 | mountedTrees = /* @__PURE__ */ new WeakMap(); |
| 13139 | ReviewedCarrier = class { |
| 13140 | constructor(ctx, config) { |
| 13141 | this.ctx = ctx; |
| 13142 | this.config = config; |
| 13143 | this.tree = new ReviewedTree(ctx, config.baseUrl, config.spec); |
| 13144 | mountedTrees.set(config, { tree: this.tree, dispose: () => this.dispose() }); |
| 13145 | } |
| 13146 | ctx; |
| 13147 | config; |
| 13148 | static inject = ["loader"]; |
| 13149 | tree; |
| 13150 | disposed = false; |
| 13151 | async dispose() { |
| 13152 | if (this.disposed) return; |
| 13153 | this.disposed = true; |
| 13154 | const fibers = [...new Set([...this.tree.entries()].map((entry) => entry.fiber).filter((fiber) => fiber !== void 0))].reverse(); |
| 13155 | const pending = this.tree.getTasks(); |
| 13156 | let stopError; |
| 13157 | try { |
| 13158 | this.tree.root.stop(); |
| 13159 | } catch (error) { |
| 13160 | stopError = error; |
| 13161 | } |
| 13162 | const outcomes = await Promise.allSettled([ |
| 13163 | ...pending, |
| 13164 | ...fibers.map((fiber) => Promise.resolve().then(() => fiber.dispose())) |
| 13165 | ]); |
| 13166 | try { |
| 13167 | await this.tree.await(); |
| 13168 | if (stopError !== void 0) throw stopError; |
| 13169 | const failed = outcomes.find((outcome) => outcome.status === "rejected"); |
| 13170 | if (failed) throw failed.reason; |
| 13171 | } finally { |
| 13172 | this.config.releaseClosure(); |
| 13173 | } |
| 13174 | } |
| 13175 | async *[Service.init]() { |
| 13176 | yield () => this.dispose(); |
| 13177 | await this.tree.root.update(this.config.review.entries); |
| 13178 | await this.tree.await(); |
| 13179 | validateInventory(this.tree.root); |
| 13180 | for (const entry of this.tree.entries()) { |
| 13181 | if (entry.disabled) continue; |
| 13182 | if (!entry.fiber || entry.fiber.uid === null) throw new Error(`composition row ${JSON.stringify(entry.options.id ?? entry.options.name)} failed activation`); |
| 13183 | await entry.fiber.await(); |
| 13184 | const missing = Object.keys(entry.fiber.inject).filter((name) => entry.fiber.ctx.get(name) === void 0); |
| 13185 | if (missing.length || entry.fiber.state !== FiberState.ACTIVE) throw new Error(`composition row ${JSON.stringify(entry.options.id ?? entry.options.name)} is not active`); |
| 13186 | } |
| 13187 | const leaked = leakedServices(this.ctx, this.ctx.fiber); |
| 13188 | if (leaked.length) throw new Error(`composition published shared-root services: ${leaked.join(", ")}`); |
| 13189 | } |
| 13190 | }; |
| 13191 | } |
| 13192 | }); |
| 13193 | |
| 13194 | // src/dsh/review-main.ts |
| 13195 | init_composition(); |
| 13196 | init_agent_presets(); |
| 13197 | try { |
| 13198 | let bytes = 0; |
| 13199 | const chunks = []; |
| 13200 | for await (const chunk of process.stdin) { |
| 13201 | const part = Buffer.from(chunk); |
| 13202 | bytes += part.length; |
| 13203 | if (bytes > 8 * 1024 * 1024) throw new Error("review request exceeds 8 MiB"); |
| 13204 | chunks.push(part); |
| 13205 | } |
| 13206 | const input = JSON.parse(Buffer.concat(chunks).toString("utf8")); |
| 13207 | const output = JSON.stringify(input.kind === "agent-presets" ? await reviewAgentPresets(input) : reviewComposition(input)); |
| 13208 | if (Buffer.byteLength(output) > 8 * 1024 * 1024) throw new Error("review response exceeds 8 MiB"); |
| 13209 | process.stdout.write(output); |
| 13210 | } catch { |
| 13211 | process.stderr.write("DSH composition review refused invalid or oversized data.\n"); |
| 13212 | process.exitCode = 1; |
| 13213 | } |
| 13214 |