@volter/tabnode 0.2.14-volter.88

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (429) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +78 -0
  3. package/THIRD-PARTY-NOTICES.md +12 -0
  4. package/dist/__sw__.js +526 -0
  5. package/dist/assets/runtime-worker-4MKaHFVb.js +75221 -0
  6. package/dist/assets/runtime-worker-4MKaHFVb.js.map +1 -0
  7. package/dist/code-transforms.d.ts +21 -0
  8. package/dist/code-transforms.d.ts.map +1 -0
  9. package/dist/config/cdn.d.ts +12 -0
  10. package/dist/config/cdn.d.ts.map +1 -0
  11. package/dist/create-runtime.d.ts +22 -0
  12. package/dist/create-runtime.d.ts.map +1 -0
  13. package/dist/host-globals.d.ts +62 -0
  14. package/dist/host-globals.d.ts.map +1 -0
  15. package/dist/index.cjs +36021 -0
  16. package/dist/index.cjs.map +1 -0
  17. package/dist/index.d.ts +127 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.mjs +36020 -0
  20. package/dist/index.mjs.map +1 -0
  21. package/dist/node-internals.d.ts +68 -0
  22. package/dist/node-internals.d.ts.map +1 -0
  23. package/dist/node-lib/binding/blob.d.ts +12 -0
  24. package/dist/node-lib/binding/blob.d.ts.map +1 -0
  25. package/dist/node-lib/binding/buffer.d.ts +144 -0
  26. package/dist/node-lib/binding/buffer.d.ts.map +1 -0
  27. package/dist/node-lib/binding/cares_wrap.d.ts +14 -0
  28. package/dist/node-lib/binding/cares_wrap.d.ts.map +1 -0
  29. package/dist/node-lib/binding/fds.d.ts +30 -0
  30. package/dist/node-lib/binding/fds.d.ts.map +1 -0
  31. package/dist/node-lib/binding/fs.d.ts +157 -0
  32. package/dist/node-lib/binding/fs.d.ts.map +1 -0
  33. package/dist/node-lib/binding/handles.d.ts +81 -0
  34. package/dist/node-lib/binding/handles.d.ts.map +1 -0
  35. package/dist/node-lib/binding/http_parser.d.ts +122 -0
  36. package/dist/node-lib/binding/http_parser.d.ts.map +1 -0
  37. package/dist/node-lib/binding/index.d.ts +3 -0
  38. package/dist/node-lib/binding/index.d.ts.map +1 -0
  39. package/dist/node-lib/binding/llhttp-wasm.d.ts +22 -0
  40. package/dist/node-lib/binding/llhttp-wasm.d.ts.map +1 -0
  41. package/dist/node-lib/binding/misc.d.ts +123 -0
  42. package/dist/node-lib/binding/misc.d.ts.map +1 -0
  43. package/dist/node-lib/binding/pipe_wrap.d.ts +84 -0
  44. package/dist/node-lib/binding/pipe_wrap.d.ts.map +1 -0
  45. package/dist/node-lib/binding/process_wrap.d.ts +173 -0
  46. package/dist/node-lib/binding/process_wrap.d.ts.map +1 -0
  47. package/dist/node-lib/binding/spawn_sync.d.ts +30 -0
  48. package/dist/node-lib/binding/spawn_sync.d.ts.map +1 -0
  49. package/dist/node-lib/binding/stream_wrap.d.ts +191 -0
  50. package/dist/node-lib/binding/stream_wrap.d.ts.map +1 -0
  51. package/dist/node-lib/binding/stubs.d.ts +23 -0
  52. package/dist/node-lib/binding/stubs.d.ts.map +1 -0
  53. package/dist/node-lib/binding/tcp_wrap.d.ts +98 -0
  54. package/dist/node-lib/binding/tcp_wrap.d.ts.map +1 -0
  55. package/dist/node-lib/binding/tty_wrap.d.ts +36 -0
  56. package/dist/node-lib/binding/tty_wrap.d.ts.map +1 -0
  57. package/dist/node-lib/binding/util.d.ts +126 -0
  58. package/dist/node-lib/binding/util.d.ts.map +1 -0
  59. package/dist/node-lib/binding/uv.d.ts +32 -0
  60. package/dist/node-lib/binding/uv.d.ts.map +1 -0
  61. package/dist/node-lib/binding/zlib-pako.d.ts +22 -0
  62. package/dist/node-lib/binding/zlib-pako.d.ts.map +1 -0
  63. package/dist/node-lib/binding/zlib.d.ts +38 -0
  64. package/dist/node-lib/binding/zlib.d.ts.map +1 -0
  65. package/dist/node-lib/buffer-module.d.ts +51 -0
  66. package/dist/node-lib/buffer-module.d.ts.map +1 -0
  67. package/dist/node-lib/child-process-module.d.ts +26 -0
  68. package/dist/node-lib/child-process-module.d.ts.map +1 -0
  69. package/dist/node-lib/events-module.d.ts +58 -0
  70. package/dist/node-lib/events-module.d.ts.map +1 -0
  71. package/dist/node-lib/fs-module.d.ts +5 -0
  72. package/dist/node-lib/fs-module.d.ts.map +1 -0
  73. package/dist/node-lib/http-bridge.d.ts +43 -0
  74. package/dist/node-lib/http-bridge.d.ts.map +1 -0
  75. package/dist/node-lib/http-module.d.ts +35 -0
  76. package/dist/node-lib/http-module.d.ts.map +1 -0
  77. package/dist/node-lib/internals/addresses.d.ts +40 -0
  78. package/dist/node-lib/internals/addresses.d.ts.map +1 -0
  79. package/dist/node-lib/internals/buffer-and-streams.d.ts +96 -0
  80. package/dist/node-lib/internals/buffer-and-streams.d.ts.map +1 -0
  81. package/dist/node-lib/internals/child-process.d.ts +27 -0
  82. package/dist/node-lib/internals/child-process.d.ts.map +1 -0
  83. package/dist/node-lib/internals/events-util.d.ts +83 -0
  84. package/dist/node-lib/internals/events-util.d.ts.map +1 -0
  85. package/dist/node-lib/internals/index.d.ts +2 -0
  86. package/dist/node-lib/internals/index.d.ts.map +1 -0
  87. package/dist/node-lib/internals/modules.d.ts +67 -0
  88. package/dist/node-lib/internals/modules.d.ts.map +1 -0
  89. package/dist/node-lib/internals/readline-access.d.ts +2 -0
  90. package/dist/node-lib/internals/readline-access.d.ts.map +1 -0
  91. package/dist/node-lib/internals/runtime.d.ts +150 -0
  92. package/dist/node-lib/internals/runtime.d.ts.map +1 -0
  93. package/dist/node-lib/internals/util.d.ts +33 -0
  94. package/dist/node-lib/internals/util.d.ts.map +1 -0
  95. package/dist/node-lib/lazy.d.ts +31 -0
  96. package/dist/node-lib/lazy.d.ts.map +1 -0
  97. package/dist/node-lib/load.d.ts +27 -0
  98. package/dist/node-lib/load.d.ts.map +1 -0
  99. package/dist/node-lib/module-hooks.d.ts +89 -0
  100. package/dist/node-lib/module-hooks.d.ts.map +1 -0
  101. package/dist/node-lib/net-module.d.ts +181 -0
  102. package/dist/node-lib/net-module.d.ts.map +1 -0
  103. package/dist/node-lib/node-versions.d.ts +27 -0
  104. package/dist/node-lib/node-versions.d.ts.map +1 -0
  105. package/dist/node-lib/public-modules.d.ts +2 -0
  106. package/dist/node-lib/public-modules.d.ts.map +1 -0
  107. package/dist/node-lib/require-hook.d.ts +15 -0
  108. package/dist/node-lib/require-hook.d.ts.map +1 -0
  109. package/dist/node-lib/small-modules.d.ts +16 -0
  110. package/dist/node-lib/small-modules.d.ts.map +1 -0
  111. package/dist/node-lib/sources.d.ts +4 -0
  112. package/dist/node-lib/sources.d.ts.map +1 -0
  113. package/dist/node-lib/stream-module.d.ts +77 -0
  114. package/dist/node-lib/stream-module.d.ts.map +1 -0
  115. package/dist/node-lib/timers.d.ts +19 -0
  116. package/dist/node-lib/timers.d.ts.map +1 -0
  117. package/dist/node-lib/util-module.d.ts +76 -0
  118. package/dist/node-lib/util-module.d.ts.map +1 -0
  119. package/dist/node-resolution.d.ts +50 -0
  120. package/dist/node-resolution.d.ts.map +1 -0
  121. package/dist/node-resolver.d.ts +7 -0
  122. package/dist/node-resolver.d.ts.map +1 -0
  123. package/dist/npm/index.d.ts +73 -0
  124. package/dist/npm/index.d.ts.map +1 -0
  125. package/dist/npm/registry.d.ts +111 -0
  126. package/dist/npm/registry.d.ts.map +1 -0
  127. package/dist/npm/resolver.d.ts +79 -0
  128. package/dist/npm/resolver.d.ts.map +1 -0
  129. package/dist/npm/tarball.d.ts +28 -0
  130. package/dist/npm/tarball.d.ts.map +1 -0
  131. package/dist/process-tokens.d.ts +77 -0
  132. package/dist/process-tokens.d.ts.map +1 -0
  133. package/dist/punycode-source.d.ts +3 -0
  134. package/dist/punycode-source.d.ts.map +1 -0
  135. package/dist/runtime-interface.d.ts +74 -0
  136. package/dist/runtime-interface.d.ts.map +1 -0
  137. package/dist/runtime.d.ts +144 -0
  138. package/dist/runtime.d.ts.map +1 -0
  139. package/dist/server-bridge.d.ts +147 -0
  140. package/dist/server-bridge.d.ts.map +1 -0
  141. package/dist/shims/async_hooks.d.ts +50 -0
  142. package/dist/shims/async_hooks.d.ts.map +1 -0
  143. package/dist/shims/child_process.d.ts +104 -0
  144. package/dist/shims/child_process.d.ts.map +1 -0
  145. package/dist/shims/cluster.d.ts +52 -0
  146. package/dist/shims/cluster.d.ts.map +1 -0
  147. package/dist/shims/command-line.d.ts +43 -0
  148. package/dist/shims/command-line.d.ts.map +1 -0
  149. package/dist/shims/constants.d.ts +222 -0
  150. package/dist/shims/constants.d.ts.map +1 -0
  151. package/dist/shims/crypto-constants.d.ts +12 -0
  152. package/dist/shims/crypto-constants.d.ts.map +1 -0
  153. package/dist/shims/crypto.d.ts +144 -0
  154. package/dist/shims/crypto.d.ts.map +1 -0
  155. package/dist/shims/dgram.d.ts +34 -0
  156. package/dist/shims/dgram.d.ts.map +1 -0
  157. package/dist/shims/dns.d.ts +91 -0
  158. package/dist/shims/dns.d.ts.map +1 -0
  159. package/dist/shims/domain.d.ts +25 -0
  160. package/dist/shims/domain.d.ts.map +1 -0
  161. package/dist/shims/esbuild.d.ts +205 -0
  162. package/dist/shims/esbuild.d.ts.map +1 -0
  163. package/dist/shims/fs.d.ts +25 -0
  164. package/dist/shims/fs.d.ts.map +1 -0
  165. package/dist/shims/http2.d.ts +81 -0
  166. package/dist/shims/http2.d.ts.map +1 -0
  167. package/dist/shims/inspector.d.ts +25 -0
  168. package/dist/shims/inspector.d.ts.map +1 -0
  169. package/dist/shims/module.d.ts +22 -0
  170. package/dist/shims/module.d.ts.map +1 -0
  171. package/dist/shims/os.d.ts +159 -0
  172. package/dist/shims/os.d.ts.map +1 -0
  173. package/dist/shims/path.d.ts +52 -0
  174. package/dist/shims/path.d.ts.map +1 -0
  175. package/dist/shims/perf_hooks.d.ts +50 -0
  176. package/dist/shims/perf_hooks.d.ts.map +1 -0
  177. package/dist/shims/process.d.ts +226 -0
  178. package/dist/shims/process.d.ts.map +1 -0
  179. package/dist/shims/rollup.d.ts +71 -0
  180. package/dist/shims/rollup.d.ts.map +1 -0
  181. package/dist/shims/string_decoder.d.ts +41 -0
  182. package/dist/shims/string_decoder.d.ts.map +1 -0
  183. package/dist/shims/sync-child.d.ts +64 -0
  184. package/dist/shims/sync-child.d.ts.map +1 -0
  185. package/dist/shims/tls.d.ts +53 -0
  186. package/dist/shims/tls.d.ts.map +1 -0
  187. package/dist/shims/url.d.ts +84 -0
  188. package/dist/shims/url.d.ts.map +1 -0
  189. package/dist/shims/v8.d.ts +73 -0
  190. package/dist/shims/v8.d.ts.map +1 -0
  191. package/dist/shims/vfs-adapter.d.ts +126 -0
  192. package/dist/shims/vfs-adapter.d.ts.map +1 -0
  193. package/dist/shims/vm.d.ts +52 -0
  194. package/dist/shims/vm.d.ts.map +1 -0
  195. package/dist/shims/wasi.d.ts +78 -0
  196. package/dist/shims/wasi.d.ts.map +1 -0
  197. package/dist/shims/worker_threads.d.ts +66 -0
  198. package/dist/shims/worker_threads.d.ts.map +1 -0
  199. package/dist/shims/zlib-constants.d.ts +66 -0
  200. package/dist/shims/zlib-constants.d.ts.map +1 -0
  201. package/dist/shims/zlib.d.ts +102 -0
  202. package/dist/shims/zlib.d.ts.map +1 -0
  203. package/dist/transform.d.ts +24 -0
  204. package/dist/transform.d.ts.map +1 -0
  205. package/dist/types/package-json.d.ts +18 -0
  206. package/dist/types/package-json.d.ts.map +1 -0
  207. package/dist/utils/binary-encoding.d.ts +13 -0
  208. package/dist/utils/binary-encoding.d.ts.map +1 -0
  209. package/dist/utils/glob.d.ts +19 -0
  210. package/dist/utils/glob.d.ts.map +1 -0
  211. package/dist/utils/hash.d.ts +6 -0
  212. package/dist/utils/hash.d.ts.map +1 -0
  213. package/dist/virtual-fs.d.ts +259 -0
  214. package/dist/virtual-fs.d.ts.map +1 -0
  215. package/dist/vite-plugin.cjs +50 -0
  216. package/dist/vite-plugin.cjs.map +1 -0
  217. package/dist/vite-plugin.d.ts +36 -0
  218. package/dist/vite-plugin.d.ts.map +1 -0
  219. package/dist/vite-plugin.mjs +31 -0
  220. package/dist/vite-plugin.mjs.map +1 -0
  221. package/dist/worker/runtime-worker.d.ts +8 -0
  222. package/dist/worker/runtime-worker.d.ts.map +1 -0
  223. package/dist/worker-runtime.d.ts +50 -0
  224. package/dist/worker-runtime.d.ts.map +1 -0
  225. package/package.json +88 -0
  226. package/src/code-transforms.ts +560 -0
  227. package/src/config/cdn.ts +13 -0
  228. package/src/create-runtime.ts +89 -0
  229. package/src/host-globals.ts +121 -0
  230. package/src/index.ts +235 -0
  231. package/src/node-internals.ts +283 -0
  232. package/src/node-lib/LICENSE +47 -0
  233. package/src/node-lib/_http_agent.js +547 -0
  234. package/src/node-lib/_http_client.js +996 -0
  235. package/src/node-lib/_http_common.js +269 -0
  236. package/src/node-lib/_http_incoming.js +453 -0
  237. package/src/node-lib/_http_outgoing.js +1262 -0
  238. package/src/node-lib/_http_server.js +1230 -0
  239. package/src/node-lib/assert/strict.js +3 -0
  240. package/src/node-lib/assert.js +844 -0
  241. package/src/node-lib/binding/blob.ts +35 -0
  242. package/src/node-lib/binding/buffer.ts +465 -0
  243. package/src/node-lib/binding/cares_wrap.ts +57 -0
  244. package/src/node-lib/binding/fds.ts +80 -0
  245. package/src/node-lib/binding/fs.ts +857 -0
  246. package/src/node-lib/binding/handles.ts +187 -0
  247. package/src/node-lib/binding/http_parser.ts +536 -0
  248. package/src/node-lib/binding/index.ts +77 -0
  249. package/src/node-lib/binding/llhttp-wasm.ts +670 -0
  250. package/src/node-lib/binding/misc.ts +252 -0
  251. package/src/node-lib/binding/pipe_wrap.ts +166 -0
  252. package/src/node-lib/binding/process_wrap.ts +371 -0
  253. package/src/node-lib/binding/spawn_sync.ts +141 -0
  254. package/src/node-lib/binding/stream_wrap.ts +413 -0
  255. package/src/node-lib/binding/stubs.ts +19 -0
  256. package/src/node-lib/binding/tcp_wrap.ts +254 -0
  257. package/src/node-lib/binding/tty_wrap.ts +56 -0
  258. package/src/node-lib/binding/util.ts +274 -0
  259. package/src/node-lib/binding/uv.ts +102 -0
  260. package/src/node-lib/binding/zlib-pako.ts +50 -0
  261. package/src/node-lib/binding/zlib.ts +259 -0
  262. package/src/node-lib/buffer-module.ts +70 -0
  263. package/src/node-lib/buffer.js +1373 -0
  264. package/src/node-lib/child-process-module.ts +58 -0
  265. package/src/node-lib/child_process.js +1046 -0
  266. package/src/node-lib/constants.js +41 -0
  267. package/src/node-lib/diagnostics_channel.js +438 -0
  268. package/src/node-lib/events-module.ts +80 -0
  269. package/src/node-lib/events.js +1223 -0
  270. package/src/node-lib/fs-module.ts +43 -0
  271. package/src/node-lib/fs.js +3377 -0
  272. package/src/node-lib/http-bridge.ts +299 -0
  273. package/src/node-lib/http-module.ts +53 -0
  274. package/src/node-lib/http.js +198 -0
  275. package/src/node-lib/https.js +429 -0
  276. package/src/node-lib/internal/assert/assertion_error.js +417 -0
  277. package/src/node-lib/internal/assert/calltracker.js +153 -0
  278. package/src/node-lib/internal/assert/myers_diff.js +177 -0
  279. package/src/node-lib/internal/assert/utils.js +278 -0
  280. package/src/node-lib/internal/buffer.js +1120 -0
  281. package/src/node-lib/internal/child_process/serialization.js +169 -0
  282. package/src/node-lib/internal/child_process.js +1135 -0
  283. package/src/node-lib/internal/constants.js +56 -0
  284. package/src/node-lib/internal/deps/minimatch/index.js +1628 -0
  285. package/src/node-lib/internal/errors.js +1912 -0
  286. package/src/node-lib/internal/events/abort_listener.js +54 -0
  287. package/src/node-lib/internal/events/symbols.js +11 -0
  288. package/src/node-lib/internal/fixed_queue.js +119 -0
  289. package/src/node-lib/internal/freelist.js +30 -0
  290. package/src/node-lib/internal/fs/cp/cp-sync.js +242 -0
  291. package/src/node-lib/internal/fs/cp/cp.js +382 -0
  292. package/src/node-lib/internal/fs/dir.js +369 -0
  293. package/src/node-lib/internal/fs/glob.js +763 -0
  294. package/src/node-lib/internal/fs/promises.js +1312 -0
  295. package/src/node-lib/internal/fs/read/context.js +129 -0
  296. package/src/node-lib/internal/fs/recursive_watch.js +275 -0
  297. package/src/node-lib/internal/fs/rimraf.js +311 -0
  298. package/src/node-lib/internal/fs/streams.js +571 -0
  299. package/src/node-lib/internal/fs/sync_write_stream.js +49 -0
  300. package/src/node-lib/internal/fs/utils.js +987 -0
  301. package/src/node-lib/internal/fs/watchers.js +418 -0
  302. package/src/node-lib/internal/http.js +62 -0
  303. package/src/node-lib/internal/mime.js +389 -0
  304. package/src/node-lib/internal/modules/customization_hooks.js +406 -0
  305. package/src/node-lib/internal/net.js +95 -0
  306. package/src/node-lib/internal/querystring.js +119 -0
  307. package/src/node-lib/internal/readline/callbacks.js +132 -0
  308. package/src/node-lib/internal/readline/emitKeypressEvents.js +99 -0
  309. package/src/node-lib/internal/readline/interface.js +1418 -0
  310. package/src/node-lib/internal/readline/promises.js +144 -0
  311. package/src/node-lib/internal/readline/utils.js +405 -0
  312. package/src/node-lib/internal/socket_list.js +108 -0
  313. package/src/node-lib/internal/stream_base_commons.js +280 -0
  314. package/src/node-lib/internal/streams/add-abort-signal.js +60 -0
  315. package/src/node-lib/internal/streams/compose.js +257 -0
  316. package/src/node-lib/internal/streams/destroy.js +361 -0
  317. package/src/node-lib/internal/streams/duplex.js +203 -0
  318. package/src/node-lib/internal/streams/duplexify.js +379 -0
  319. package/src/node-lib/internal/streams/duplexpair.js +62 -0
  320. package/src/node-lib/internal/streams/end-of-stream.js +331 -0
  321. package/src/node-lib/internal/streams/from.js +208 -0
  322. package/src/node-lib/internal/streams/lazy_transform.js +57 -0
  323. package/src/node-lib/internal/streams/legacy.js +125 -0
  324. package/src/node-lib/internal/streams/operators.js +436 -0
  325. package/src/node-lib/internal/streams/passthrough.js +47 -0
  326. package/src/node-lib/internal/streams/pipeline.js +465 -0
  327. package/src/node-lib/internal/streams/readable.js +1762 -0
  328. package/src/node-lib/internal/streams/state.js +51 -0
  329. package/src/node-lib/internal/streams/transform.js +204 -0
  330. package/src/node-lib/internal/streams/utils.js +363 -0
  331. package/src/node-lib/internal/streams/writable.js +1163 -0
  332. package/src/node-lib/internal/tty.js +260 -0
  333. package/src/node-lib/internal/util/colors.js +40 -0
  334. package/src/node-lib/internal/util/comparisons.js +1028 -0
  335. package/src/node-lib/internal/util/debuglog.js +524 -0
  336. package/src/node-lib/internal/util/inspect.js +2535 -0
  337. package/src/node-lib/internal/util/parse_args/parse_args.js +412 -0
  338. package/src/node-lib/internal/util/parse_args/utils.js +197 -0
  339. package/src/node-lib/internal/util.js +1003 -0
  340. package/src/node-lib/internal/validators.js +654 -0
  341. package/src/node-lib/internals/addresses.ts +159 -0
  342. package/src/node-lib/internals/buffer-and-streams.ts +224 -0
  343. package/src/node-lib/internals/child-process.ts +64 -0
  344. package/src/node-lib/internals/events-util.ts +105 -0
  345. package/src/node-lib/internals/index.ts +66 -0
  346. package/src/node-lib/internals/modules.ts +117 -0
  347. package/src/node-lib/internals/readline-access.ts +16 -0
  348. package/src/node-lib/internals/runtime.ts +277 -0
  349. package/src/node-lib/internals/util.ts +98 -0
  350. package/src/node-lib/lazy.ts +158 -0
  351. package/src/node-lib/load.ts +390 -0
  352. package/src/node-lib/module-hooks.ts +281 -0
  353. package/src/node-lib/net-module.ts +248 -0
  354. package/src/node-lib/net.js +2540 -0
  355. package/src/node-lib/node-versions.ts +34 -0
  356. package/src/node-lib/os.js +356 -0
  357. package/src/node-lib/path.js +1694 -0
  358. package/src/node-lib/primordials.js +743 -0
  359. package/src/node-lib/public-modules.ts +109 -0
  360. package/src/node-lib/punycode.js +455 -0
  361. package/src/node-lib/querystring.js +484 -0
  362. package/src/node-lib/readline/promises.js +73 -0
  363. package/src/node-lib/readline.js +523 -0
  364. package/src/node-lib/require-hook.ts +27 -0
  365. package/src/node-lib/small-modules.ts +35 -0
  366. package/src/node-lib/sources.ts +200 -0
  367. package/src/node-lib/stream/promises.js +44 -0
  368. package/src/node-lib/stream-module.ts +101 -0
  369. package/src/node-lib/stream.js +152 -0
  370. package/src/node-lib/timers.ts +33 -0
  371. package/src/node-lib/tty.js +168 -0
  372. package/src/node-lib/util-module.ts +104 -0
  373. package/src/node-lib/util.js +689 -0
  374. package/src/node-lib/wasi.js +179 -0
  375. package/src/node-lib/zlib.js +1036 -0
  376. package/src/node-resolution.ts +241 -0
  377. package/src/node-resolver.ts +33 -0
  378. package/src/npm/index.ts +425 -0
  379. package/src/npm/registry.ts +235 -0
  380. package/src/npm/resolver.ts +589 -0
  381. package/src/npm/tarball.ts +246 -0
  382. package/src/process-tokens.ts +156 -0
  383. package/src/punycode-source.ts +6 -0
  384. package/src/runtime-interface.ts +85 -0
  385. package/src/runtime.ts +3073 -0
  386. package/src/server-bridge.ts +971 -0
  387. package/src/shims/async_hooks.ts +181 -0
  388. package/src/shims/child_process.ts +1591 -0
  389. package/src/shims/cluster.ts +79 -0
  390. package/src/shims/command-line.ts +79 -0
  391. package/src/shims/constants.ts +68 -0
  392. package/src/shims/crypto-constants.ts +11 -0
  393. package/src/shims/crypto.ts +1061 -0
  394. package/src/shims/dgram.ts +47 -0
  395. package/src/shims/dns.ts +185 -0
  396. package/src/shims/domain.ts +58 -0
  397. package/src/shims/esbuild.ts +1638 -0
  398. package/src/shims/fs.ts +82 -0
  399. package/src/shims/http2.ts +96 -0
  400. package/src/shims/inspector.ts +30 -0
  401. package/src/shims/module.ts +86 -0
  402. package/src/shims/os.ts +195 -0
  403. package/src/shims/path.ts +246 -0
  404. package/src/shims/perf_hooks.ts +92 -0
  405. package/src/shims/process.ts +804 -0
  406. package/src/shims/rollup.ts +149 -0
  407. package/src/shims/string_decoder.ts +396 -0
  408. package/src/shims/sync-child.ts +469 -0
  409. package/src/shims/tls.ts +94 -0
  410. package/src/shims/url.ts +217 -0
  411. package/src/shims/v8.ts +113 -0
  412. package/src/shims/vfs-adapter.ts +408 -0
  413. package/src/shims/vm.ts +132 -0
  414. package/src/shims/wasi.ts +1440 -0
  415. package/src/shims/worker_threads.ts +114 -0
  416. package/src/shims/zlib-constants.ts +65 -0
  417. package/src/shims/zlib.ts +228 -0
  418. package/src/transform.ts +324 -0
  419. package/src/types/external.d.ts +55 -0
  420. package/src/types/package-json.ts +17 -0
  421. package/src/types/pako-zlib.d.ts +30 -0
  422. package/src/types/sha.js.d.ts +14 -0
  423. package/src/utils/binary-encoding.ts +43 -0
  424. package/src/utils/glob.ts +54 -0
  425. package/src/utils/hash.ts +12 -0
  426. package/src/virtual-fs.ts +1048 -0
  427. package/src/vite-plugin.ts +76 -0
  428. package/src/worker/runtime-worker.ts +128 -0
  429. package/src/worker-runtime.ts +145 -0
@@ -0,0 +1,2535 @@
1
+ 'use strict';
2
+
3
+ const {
4
+ Array,
5
+ ArrayBuffer,
6
+ ArrayBufferPrototype,
7
+ ArrayIsArray,
8
+ ArrayPrototype,
9
+ ArrayPrototypeFilter,
10
+ ArrayPrototypeForEach,
11
+ ArrayPrototypeIncludes,
12
+ ArrayPrototypeIndexOf,
13
+ ArrayPrototypeJoin,
14
+ ArrayPrototypeMap,
15
+ ArrayPrototypePop,
16
+ ArrayPrototypePush,
17
+ ArrayPrototypePushApply,
18
+ ArrayPrototypeSlice,
19
+ ArrayPrototypeSort,
20
+ ArrayPrototypeSplice,
21
+ ArrayPrototypeUnshift,
22
+ BigIntPrototypeValueOf,
23
+ Boolean,
24
+ BooleanPrototype,
25
+ BooleanPrototypeValueOf,
26
+ DataView,
27
+ DataViewPrototype,
28
+ Date,
29
+ DatePrototype,
30
+ DatePrototypeGetTime,
31
+ DatePrototypeToISOString,
32
+ DatePrototypeToString,
33
+ Error,
34
+ ErrorPrototype,
35
+ ErrorPrototypeToString,
36
+ Function,
37
+ FunctionPrototype,
38
+ FunctionPrototypeBind,
39
+ FunctionPrototypeCall,
40
+ FunctionPrototypeSymbolHasInstance,
41
+ FunctionPrototypeToString,
42
+ JSONStringify,
43
+ Map,
44
+ MapPrototype,
45
+ MapPrototypeEntries,
46
+ MapPrototypeGetSize,
47
+ MathFloor,
48
+ MathMax,
49
+ MathMin,
50
+ MathRound,
51
+ MathSqrt,
52
+ MathTrunc,
53
+ Number,
54
+ NumberIsFinite,
55
+ NumberIsNaN,
56
+ NumberParseFloat,
57
+ NumberParseInt,
58
+ NumberPrototype,
59
+ NumberPrototypeToString,
60
+ NumberPrototypeValueOf,
61
+ Object,
62
+ ObjectAssign,
63
+ ObjectDefineProperty,
64
+ ObjectGetOwnPropertyDescriptor,
65
+ ObjectGetOwnPropertyNames,
66
+ ObjectGetOwnPropertySymbols,
67
+ ObjectGetPrototypeOf,
68
+ ObjectIs,
69
+ ObjectKeys,
70
+ ObjectPrototype,
71
+ ObjectPrototypeHasOwnProperty,
72
+ ObjectPrototypePropertyIsEnumerable,
73
+ ObjectSeal,
74
+ ObjectSetPrototypeOf,
75
+ Promise,
76
+ PromisePrototype,
77
+ ReflectApply,
78
+ ReflectOwnKeys,
79
+ RegExp,
80
+ RegExpPrototype,
81
+ RegExpPrototypeExec,
82
+ RegExpPrototypeSymbolReplace,
83
+ RegExpPrototypeSymbolSplit,
84
+ RegExpPrototypeToString,
85
+ SafeMap,
86
+ SafeSet,
87
+ SafeStringIterator,
88
+ Set,
89
+ SetPrototype,
90
+ SetPrototypeGetSize,
91
+ SetPrototypeValues,
92
+ String,
93
+ StringPrototype,
94
+ StringPrototypeCharCodeAt,
95
+ StringPrototypeCodePointAt,
96
+ StringPrototypeEndsWith,
97
+ StringPrototypeIncludes,
98
+ StringPrototypeIndexOf,
99
+ StringPrototypeLastIndexOf,
100
+ StringPrototypeNormalize,
101
+ StringPrototypePadEnd,
102
+ StringPrototypePadStart,
103
+ StringPrototypeRepeat,
104
+ StringPrototypeReplace,
105
+ StringPrototypeReplaceAll,
106
+ StringPrototypeSlice,
107
+ StringPrototypeSplit,
108
+ StringPrototypeStartsWith,
109
+ StringPrototypeToLowerCase,
110
+ StringPrototypeTrim,
111
+ StringPrototypeValueOf,
112
+ SymbolIterator,
113
+ SymbolPrototypeToString,
114
+ SymbolPrototypeValueOf,
115
+ SymbolToPrimitive,
116
+ SymbolToStringTag,
117
+ TypedArray,
118
+ TypedArrayPrototype,
119
+ TypedArrayPrototypeGetLength,
120
+ TypedArrayPrototypeGetSymbolToStringTag,
121
+ Uint8Array,
122
+ WeakMap,
123
+ WeakMapPrototype,
124
+ WeakSet,
125
+ WeakSetPrototype,
126
+ globalThis,
127
+ uncurryThis,
128
+ } = primordials;
129
+
130
+ const {
131
+ constants: {
132
+ ALL_PROPERTIES,
133
+ ONLY_ENUMERABLE,
134
+ kPending,
135
+ kRejected,
136
+ },
137
+ getOwnNonIndexProperties,
138
+ getPromiseDetails,
139
+ getProxyDetails,
140
+ previewEntries,
141
+ getConstructorName: internalGetConstructorName,
142
+ getExternalValue,
143
+ } = internalBinding('util');
144
+
145
+ const {
146
+ customInspectSymbol,
147
+ isError,
148
+ join,
149
+ removeColors,
150
+ } = require('internal/util');
151
+
152
+ const {
153
+ isStackOverflowError,
154
+ } = require('internal/errors');
155
+
156
+ const {
157
+ isAsyncFunction,
158
+ isGeneratorFunction,
159
+ isAnyArrayBuffer,
160
+ isArrayBuffer,
161
+ isArgumentsObject,
162
+ isBoxedPrimitive,
163
+ isDataView,
164
+ isExternal,
165
+ isMap,
166
+ isMapIterator,
167
+ isModuleNamespaceObject,
168
+ isNativeError,
169
+ isPromise,
170
+ isSet,
171
+ isSetIterator,
172
+ isWeakMap,
173
+ isWeakSet,
174
+ isRegExp,
175
+ isDate,
176
+ isTypedArray,
177
+ isStringObject,
178
+ isNumberObject,
179
+ isBooleanObject,
180
+ isBigIntObject,
181
+ } = require('internal/util/types');
182
+
183
+ const assert = require('internal/assert');
184
+
185
+ const { BuiltinModule } = require('internal/bootstrap/realm');
186
+ const {
187
+ validateObject,
188
+ validateString,
189
+ kValidateObjectAllowArray,
190
+ } = require('internal/validators');
191
+
192
+ let hexSlice;
193
+ let internalUrl;
194
+
195
+ function pathToFileUrlHref(filepath) {
196
+ internalUrl ??= require('internal/url');
197
+ return internalUrl.pathToFileURL(filepath).href;
198
+ }
199
+
200
+ function isURL(value) {
201
+ internalUrl ??= require('internal/url');
202
+ return typeof value.href === 'string' && value instanceof internalUrl.URL;
203
+ }
204
+
205
+ const builtInObjects = new SafeSet(
206
+ ArrayPrototypeFilter(
207
+ ObjectGetOwnPropertyNames(globalThis),
208
+ (e) => RegExpPrototypeExec(/^[A-Z][a-zA-Z0-9]+$/, e) !== null,
209
+ ),
210
+ );
211
+
212
+ // https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot
213
+ const isUndetectableObject = (v) => typeof v === 'undefined' && v !== undefined;
214
+
215
+ // These options must stay in sync with `getUserOptions`. So if any option will
216
+ // be added or removed, `getUserOptions` must also be updated accordingly.
217
+ const inspectDefaultOptions = ObjectSeal({
218
+ showHidden: false,
219
+ depth: 2,
220
+ colors: false,
221
+ customInspect: true,
222
+ showProxy: false,
223
+ maxArrayLength: 100,
224
+ maxStringLength: 10000,
225
+ breakLength: 80,
226
+ compact: 3,
227
+ sorted: false,
228
+ getters: false,
229
+ numericSeparator: false,
230
+ });
231
+
232
+ const kObjectType = 0;
233
+ const kArrayType = 1;
234
+ const kArrayExtrasType = 2;
235
+
236
+ /* eslint-disable no-control-regex */
237
+ const strEscapeSequencesRegExp = /[\x00-\x1f\x27\x5c\x7f-\x9f]|[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/;
238
+ const strEscapeSequencesReplacer = /[\x00-\x1f\x27\x5c\x7f-\x9f]|[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/g;
239
+ const strEscapeSequencesRegExpSingle = /[\x00-\x1f\x5c\x7f-\x9f]|[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/;
240
+ const strEscapeSequencesReplacerSingle = /[\x00-\x1f\x5c\x7f-\x9f]|[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/g;
241
+ /* eslint-enable no-control-regex */
242
+
243
+ const keyStrRegExp = /^[a-zA-Z_][a-zA-Z_0-9]*$/;
244
+ const numberRegExp = /^(0|[1-9][0-9]*)$/;
245
+
246
+ const coreModuleRegExp = /^ {4}at (?:[^/\\(]+ \(|)node:(.+):\d+:\d+\)?$/;
247
+ const nodeModulesRegExp = /[/\\]node_modules[/\\](.+?)(?=[/\\])/g;
248
+
249
+ const classRegExp = /^(\s+[^(]*?)\s*{/;
250
+ // eslint-disable-next-line node-core/no-unescaped-regexp-dot
251
+ const stripCommentsRegExp = /(\/\/.*?\n)|(\/\*(.|\n)*?\*\/)/g;
252
+
253
+ const kMinLineLength = 16;
254
+
255
+ // Constants to map the iterator state.
256
+ const kWeak = 0;
257
+ const kIterator = 1;
258
+ const kMapEntries = 2;
259
+
260
+ // Escaped control characters (plus the single quote and the backslash). Use
261
+ // empty strings to fill up unused entries.
262
+ const meta = [
263
+ '\\x00', '\\x01', '\\x02', '\\x03', '\\x04', '\\x05', '\\x06', '\\x07', // x07
264
+ '\\b', '\\t', '\\n', '\\x0B', '\\f', '\\r', '\\x0E', '\\x0F', // x0F
265
+ '\\x10', '\\x11', '\\x12', '\\x13', '\\x14', '\\x15', '\\x16', '\\x17', // x17
266
+ '\\x18', '\\x19', '\\x1A', '\\x1B', '\\x1C', '\\x1D', '\\x1E', '\\x1F', // x1F
267
+ '', '', '', '', '', '', '', "\\'", '', '', '', '', '', '', '', '', // x2F
268
+ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', // x3F
269
+ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', // x4F
270
+ '', '', '', '', '', '', '', '', '', '', '', '', '\\\\', '', '', '', // x5F
271
+ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', // x6F
272
+ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '\\x7F', // x7F
273
+ '\\x80', '\\x81', '\\x82', '\\x83', '\\x84', '\\x85', '\\x86', '\\x87', // x87
274
+ '\\x88', '\\x89', '\\x8A', '\\x8B', '\\x8C', '\\x8D', '\\x8E', '\\x8F', // x8F
275
+ '\\x90', '\\x91', '\\x92', '\\x93', '\\x94', '\\x95', '\\x96', '\\x97', // x97
276
+ '\\x98', '\\x99', '\\x9A', '\\x9B', '\\x9C', '\\x9D', '\\x9E', '\\x9F', // x9F
277
+ ];
278
+
279
+ // Regex used for ansi escape code splitting
280
+ // Ref: https://github.com/chalk/ansi-regex/blob/f338e1814144efb950276aac84135ff86b72dc8e/index.js
281
+ // License: MIT by Sindre Sorhus <sindresorhus@gmail.com>
282
+ // Matches all ansi escape code sequences in a string
283
+ const ansi = new RegExp(
284
+ '[\\u001B\\u009B][[\\]()#;?]*' +
285
+ '(?:(?:(?:(?:;[-a-zA-Z\\d\\/\\#&.:=?%@~_]+)*' +
286
+ '|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/\\#&.:=?%@~_]*)*)?' +
287
+ '(?:\\u0007|\\u001B\\u005C|\\u009C))' +
288
+ '|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?' +
289
+ '[\\dA-PR-TZcf-nq-uy=><~]))', 'g',
290
+ );
291
+
292
+ let getStringWidth;
293
+
294
+ function getUserOptions(ctx, isCrossContext) {
295
+ const ret = {
296
+ stylize: ctx.stylize,
297
+ showHidden: ctx.showHidden,
298
+ depth: ctx.depth,
299
+ colors: ctx.colors,
300
+ customInspect: ctx.customInspect,
301
+ showProxy: ctx.showProxy,
302
+ maxArrayLength: ctx.maxArrayLength,
303
+ maxStringLength: ctx.maxStringLength,
304
+ breakLength: ctx.breakLength,
305
+ compact: ctx.compact,
306
+ sorted: ctx.sorted,
307
+ getters: ctx.getters,
308
+ numericSeparator: ctx.numericSeparator,
309
+ ...ctx.userOptions,
310
+ };
311
+
312
+ // Typically, the target value will be an instance of `Object`. If that is
313
+ // *not* the case, the object may come from another vm.Context, and we want
314
+ // to avoid passing it objects from this Context in that case, so we remove
315
+ // the prototype from the returned object itself + the `stylize()` function,
316
+ // and remove all other non-primitives, including non-primitive user options.
317
+ if (isCrossContext) {
318
+ ObjectSetPrototypeOf(ret, null);
319
+ for (const key of ObjectKeys(ret)) {
320
+ if ((typeof ret[key] === 'object' || typeof ret[key] === 'function') &&
321
+ ret[key] !== null) {
322
+ delete ret[key];
323
+ }
324
+ }
325
+ ret.stylize = ObjectSetPrototypeOf((value, flavour) => {
326
+ let stylized;
327
+ try {
328
+ stylized = `${ctx.stylize(value, flavour)}`;
329
+ } catch {
330
+ // Continue regardless of error.
331
+ }
332
+
333
+ if (typeof stylized !== 'string') return value;
334
+ // `stylized` is a string as it should be, which is safe to pass along.
335
+ return stylized;
336
+ }, null);
337
+ }
338
+
339
+ return ret;
340
+ }
341
+
342
+ /**
343
+ * Echos the value of any input. Tries to print the value out
344
+ * in the best way possible given the different types.
345
+ * @param {any} value The value to print out.
346
+ * @param {object} opts Optional options object that alters the output.
347
+ */
348
+ /* Legacy: value, showHidden, depth, colors */
349
+ function inspect(value, opts) {
350
+ // Default options
351
+ const ctx = {
352
+ budget: {},
353
+ indentationLvl: 0,
354
+ seen: [],
355
+ currentDepth: 0,
356
+ stylize: stylizeNoColor,
357
+ showHidden: inspectDefaultOptions.showHidden,
358
+ depth: inspectDefaultOptions.depth,
359
+ colors: inspectDefaultOptions.colors,
360
+ customInspect: inspectDefaultOptions.customInspect,
361
+ showProxy: inspectDefaultOptions.showProxy,
362
+ maxArrayLength: inspectDefaultOptions.maxArrayLength,
363
+ maxStringLength: inspectDefaultOptions.maxStringLength,
364
+ breakLength: inspectDefaultOptions.breakLength,
365
+ compact: inspectDefaultOptions.compact,
366
+ sorted: inspectDefaultOptions.sorted,
367
+ getters: inspectDefaultOptions.getters,
368
+ numericSeparator: inspectDefaultOptions.numericSeparator,
369
+ };
370
+ if (arguments.length > 1) {
371
+ // Legacy...
372
+ if (arguments.length > 2) {
373
+ if (arguments[2] !== undefined) {
374
+ ctx.depth = arguments[2];
375
+ }
376
+ if (arguments.length > 3 && arguments[3] !== undefined) {
377
+ ctx.colors = arguments[3];
378
+ }
379
+ }
380
+ // Set user-specified options
381
+ if (typeof opts === 'boolean') {
382
+ ctx.showHidden = opts;
383
+ } else if (opts) {
384
+ const optKeys = ObjectKeys(opts);
385
+ for (let i = 0; i < optKeys.length; ++i) {
386
+ const key = optKeys[i];
387
+ // TODO(BridgeAR): Find a solution what to do about stylize. Either make
388
+ // this function public or add a new API with a similar or better
389
+ // functionality.
390
+ if (
391
+ ObjectPrototypeHasOwnProperty(inspectDefaultOptions, key) ||
392
+ key === 'stylize') {
393
+ ctx[key] = opts[key];
394
+ } else if (ctx.userOptions === undefined) {
395
+ // This is required to pass through the actual user input.
396
+ ctx.userOptions = opts;
397
+ }
398
+ }
399
+ }
400
+ }
401
+ if (ctx.colors) ctx.stylize = stylizeWithColor;
402
+ if (ctx.maxArrayLength === null) ctx.maxArrayLength = Infinity;
403
+ if (ctx.maxStringLength === null) ctx.maxStringLength = Infinity;
404
+ return formatValue(ctx, value, 0);
405
+ }
406
+ inspect.custom = customInspectSymbol;
407
+
408
+ ObjectDefineProperty(inspect, 'defaultOptions', {
409
+ __proto__: null,
410
+ get() {
411
+ return inspectDefaultOptions;
412
+ },
413
+ set(options) {
414
+ validateObject(options, 'options');
415
+ return ObjectAssign(inspectDefaultOptions, options);
416
+ },
417
+ });
418
+
419
+ // Set Graphics Rendition https://en.wikipedia.org/wiki/ANSI_escape_code#graphics
420
+ // Each color consists of an array with the color code as first entry and the
421
+ // reset code as second entry.
422
+ const defaultFG = 39;
423
+ const defaultBG = 49;
424
+ inspect.colors = {
425
+ __proto__: null,
426
+ reset: [0, 0],
427
+ bold: [1, 22],
428
+ dim: [2, 22], // Alias: faint
429
+ italic: [3, 23],
430
+ underline: [4, 24],
431
+ blink: [5, 25],
432
+ // Swap foreground and background colors
433
+ inverse: [7, 27], // Alias: swapcolors, swapColors
434
+ hidden: [8, 28], // Alias: conceal
435
+ strikethrough: [9, 29], // Alias: strikeThrough, crossedout, crossedOut
436
+ doubleunderline: [21, 24], // Alias: doubleUnderline
437
+ black: [30, defaultFG],
438
+ red: [31, defaultFG],
439
+ green: [32, defaultFG],
440
+ yellow: [33, defaultFG],
441
+ blue: [34, defaultFG],
442
+ magenta: [35, defaultFG],
443
+ cyan: [36, defaultFG],
444
+ white: [37, defaultFG],
445
+ bgBlack: [40, defaultBG],
446
+ bgRed: [41, defaultBG],
447
+ bgGreen: [42, defaultBG],
448
+ bgYellow: [43, defaultBG],
449
+ bgBlue: [44, defaultBG],
450
+ bgMagenta: [45, defaultBG],
451
+ bgCyan: [46, defaultBG],
452
+ bgWhite: [47, defaultBG],
453
+ framed: [51, 54],
454
+ overlined: [53, 55],
455
+ gray: [90, defaultFG], // Alias: grey, blackBright
456
+ redBright: [91, defaultFG],
457
+ greenBright: [92, defaultFG],
458
+ yellowBright: [93, defaultFG],
459
+ blueBright: [94, defaultFG],
460
+ magentaBright: [95, defaultFG],
461
+ cyanBright: [96, defaultFG],
462
+ whiteBright: [97, defaultFG],
463
+ bgGray: [100, defaultBG], // Alias: bgGrey, bgBlackBright
464
+ bgRedBright: [101, defaultBG],
465
+ bgGreenBright: [102, defaultBG],
466
+ bgYellowBright: [103, defaultBG],
467
+ bgBlueBright: [104, defaultBG],
468
+ bgMagentaBright: [105, defaultBG],
469
+ bgCyanBright: [106, defaultBG],
470
+ bgWhiteBright: [107, defaultBG],
471
+ };
472
+
473
+ function defineColorAlias(target, alias) {
474
+ ObjectDefineProperty(inspect.colors, alias, {
475
+ __proto__: null,
476
+ get() {
477
+ return this[target];
478
+ },
479
+ set(value) {
480
+ this[target] = value;
481
+ },
482
+ configurable: true,
483
+ enumerable: false,
484
+ });
485
+ }
486
+
487
+ defineColorAlias('gray', 'grey');
488
+ defineColorAlias('gray', 'blackBright');
489
+ defineColorAlias('bgGray', 'bgGrey');
490
+ defineColorAlias('bgGray', 'bgBlackBright');
491
+ defineColorAlias('dim', 'faint');
492
+ defineColorAlias('strikethrough', 'crossedout');
493
+ defineColorAlias('strikethrough', 'strikeThrough');
494
+ defineColorAlias('strikethrough', 'crossedOut');
495
+ defineColorAlias('hidden', 'conceal');
496
+ defineColorAlias('inverse', 'swapColors');
497
+ defineColorAlias('inverse', 'swapcolors');
498
+ defineColorAlias('doubleunderline', 'doubleUnderline');
499
+
500
+ // TODO(BridgeAR): Add function style support for more complex styles.
501
+ // Don't use 'blue' not visible on cmd.exe
502
+ inspect.styles = ObjectAssign({ __proto__: null }, {
503
+ special: 'cyan',
504
+ number: 'yellow',
505
+ bigint: 'yellow',
506
+ boolean: 'yellow',
507
+ undefined: 'grey',
508
+ null: 'bold',
509
+ string: 'green',
510
+ symbol: 'green',
511
+ date: 'magenta',
512
+ // "name": intentionally not styling
513
+ // TODO(BridgeAR): Highlight regular expressions properly.
514
+ regexp: 'red',
515
+ module: 'underline',
516
+ });
517
+
518
+ function addQuotes(str, quotes) {
519
+ if (quotes === -1) {
520
+ return `"${str}"`;
521
+ }
522
+ if (quotes === -2) {
523
+ return `\`${str}\``;
524
+ }
525
+ return `'${str}'`;
526
+ }
527
+
528
+ function escapeFn(str) {
529
+ const charCode = StringPrototypeCharCodeAt(str);
530
+ return meta.length > charCode ? meta[charCode] : `\\u${NumberPrototypeToString(charCode, 16)}`;
531
+ }
532
+
533
+ // Escape control characters, single quotes and the backslash.
534
+ // This is similar to JSON stringify escaping.
535
+ function strEscape(str) {
536
+ let escapeTest = strEscapeSequencesRegExp;
537
+ let escapeReplace = strEscapeSequencesReplacer;
538
+ let singleQuote = 39;
539
+
540
+ // Check for double quotes. If not present, do not escape single quotes and
541
+ // instead wrap the text in double quotes. If double quotes exist, check for
542
+ // backticks. If they do not exist, use those as fallback instead of the
543
+ // double quotes.
544
+ if (StringPrototypeIncludes(str, "'")) {
545
+ // This invalidates the charCode and therefore can not be matched for
546
+ // anymore.
547
+ if (!StringPrototypeIncludes(str, '"')) {
548
+ singleQuote = -1;
549
+ } else if (!StringPrototypeIncludes(str, '`') &&
550
+ !StringPrototypeIncludes(str, '${')) {
551
+ singleQuote = -2;
552
+ }
553
+ if (singleQuote !== 39) {
554
+ escapeTest = strEscapeSequencesRegExpSingle;
555
+ escapeReplace = strEscapeSequencesReplacerSingle;
556
+ }
557
+ }
558
+
559
+ // Some magic numbers that worked out fine while benchmarking with v8 6.0
560
+ if (str.length < 5000 && RegExpPrototypeExec(escapeTest, str) === null)
561
+ return addQuotes(str, singleQuote);
562
+ if (str.length > 100) {
563
+ str = RegExpPrototypeSymbolReplace(escapeReplace, str, escapeFn);
564
+ return addQuotes(str, singleQuote);
565
+ }
566
+
567
+ let result = '';
568
+ let last = 0;
569
+ for (let i = 0; i < str.length; i++) {
570
+ const point = StringPrototypeCharCodeAt(str, i);
571
+ if (point === singleQuote ||
572
+ point === 92 ||
573
+ point < 32 ||
574
+ (point > 126 && point < 160)) {
575
+ if (last === i) {
576
+ result += meta[point];
577
+ } else {
578
+ result += `${StringPrototypeSlice(str, last, i)}${meta[point]}`;
579
+ }
580
+ last = i + 1;
581
+ } else if (point >= 0xd800 && point <= 0xdfff) {
582
+ if (point <= 0xdbff && i + 1 < str.length) {
583
+ const point = StringPrototypeCharCodeAt(str, i + 1);
584
+ if (point >= 0xdc00 && point <= 0xdfff) {
585
+ i++;
586
+ continue;
587
+ }
588
+ }
589
+ result += `${StringPrototypeSlice(str, last, i)}\\u${NumberPrototypeToString(point, 16)}`;
590
+ last = i + 1;
591
+ }
592
+ }
593
+
594
+ if (last !== str.length) {
595
+ result += StringPrototypeSlice(str, last);
596
+ }
597
+ return addQuotes(result, singleQuote);
598
+ }
599
+
600
+ function stylizeWithColor(str, styleType) {
601
+ const style = inspect.styles[styleType];
602
+ if (style !== undefined) {
603
+ const color = inspect.colors[style];
604
+ if (color !== undefined)
605
+ return `\u001b[${color[0]}m${str}\u001b[${color[1]}m`;
606
+ }
607
+ return str;
608
+ }
609
+
610
+ function stylizeNoColor(str) {
611
+ return str;
612
+ }
613
+
614
+ // Return a new empty array to push in the results of the default formatter.
615
+ function getEmptyFormatArray() {
616
+ return [];
617
+ }
618
+
619
+ function isInstanceof(object, proto) {
620
+ try {
621
+ return object instanceof proto;
622
+ } catch {
623
+ return false;
624
+ }
625
+ }
626
+
627
+ // Special-case for some builtin prototypes in case their `constructor` property has been tampered.
628
+ const wellKnownPrototypes = new SafeMap()
629
+ .set(ArrayPrototype, { name: 'Array', constructor: Array })
630
+ .set(ArrayBufferPrototype, { name: 'ArrayBuffer', constructor: ArrayBuffer })
631
+ .set(FunctionPrototype, { name: 'Function', constructor: Function })
632
+ .set(MapPrototype, { name: 'Map', constructor: Map })
633
+ .set(SetPrototype, { name: 'Set', constructor: Set })
634
+ .set(ObjectPrototype, { name: 'Object', constructor: Object })
635
+ .set(TypedArrayPrototype, { name: 'TypedArray', constructor: TypedArray })
636
+ .set(RegExpPrototype, { name: 'RegExp', constructor: RegExp })
637
+ .set(DatePrototype, { name: 'Date', constructor: Date })
638
+ .set(DataViewPrototype, { name: 'DataView', constructor: DataView })
639
+ .set(ErrorPrototype, { name: 'Error', constructor: Error })
640
+ .set(BooleanPrototype, { name: 'Boolean', constructor: Boolean })
641
+ .set(NumberPrototype, { name: 'Number', constructor: Number })
642
+ .set(StringPrototype, { name: 'String', constructor: String })
643
+ .set(PromisePrototype, { name: 'Promise', constructor: Promise })
644
+ .set(WeakMapPrototype, { name: 'WeakMap', constructor: WeakMap })
645
+ .set(WeakSetPrototype, { name: 'WeakSet', constructor: WeakSet });
646
+
647
+ function getConstructorName(obj, ctx, recurseTimes, protoProps) {
648
+ let firstProto;
649
+ const tmp = obj;
650
+ while (obj || isUndetectableObject(obj)) {
651
+ const wellKnownPrototypeNameAndConstructor = wellKnownPrototypes.get(obj);
652
+ if (wellKnownPrototypeNameAndConstructor !== undefined) {
653
+ const { name, constructor } = wellKnownPrototypeNameAndConstructor;
654
+ if (FunctionPrototypeSymbolHasInstance(constructor, tmp)) {
655
+ if (protoProps !== undefined && firstProto !== obj) {
656
+ addPrototypeProperties(
657
+ ctx, tmp, firstProto || tmp, recurseTimes, protoProps);
658
+ }
659
+ return name;
660
+ }
661
+ }
662
+ const descriptor = ObjectGetOwnPropertyDescriptor(obj, 'constructor');
663
+ if (descriptor !== undefined &&
664
+ typeof descriptor.value === 'function' &&
665
+ descriptor.value.name !== '' &&
666
+ isInstanceof(tmp, descriptor.value)) {
667
+ if (protoProps !== undefined &&
668
+ (firstProto !== obj ||
669
+ !builtInObjects.has(descriptor.value.name))) {
670
+ addPrototypeProperties(
671
+ ctx, tmp, firstProto || tmp, recurseTimes, protoProps);
672
+ }
673
+ return String(descriptor.value.name);
674
+ }
675
+
676
+ obj = ObjectGetPrototypeOf(obj);
677
+ if (firstProto === undefined) {
678
+ firstProto = obj;
679
+ }
680
+ }
681
+
682
+ if (firstProto === null) {
683
+ return null;
684
+ }
685
+
686
+ const res = internalGetConstructorName(tmp);
687
+
688
+ if (recurseTimes > ctx.depth && ctx.depth !== null) {
689
+ return `${res} <Complex prototype>`;
690
+ }
691
+
692
+ const protoConstr = getConstructorName(
693
+ firstProto, ctx, recurseTimes + 1, protoProps);
694
+
695
+ if (protoConstr === null) {
696
+ return `${res} <${inspect(firstProto, {
697
+ ...ctx,
698
+ customInspect: false,
699
+ depth: -1,
700
+ })}>`;
701
+ }
702
+
703
+ return `${res} <${protoConstr}>`;
704
+ }
705
+
706
+ // This function has the side effect of adding prototype properties to the
707
+ // `output` argument (which is an array). This is intended to highlight user
708
+ // defined prototype properties.
709
+ function addPrototypeProperties(ctx, main, obj, recurseTimes, output) {
710
+ let depth = 0;
711
+ let keys;
712
+ let keySet;
713
+ do {
714
+ if (depth !== 0 || main === obj) {
715
+ obj = ObjectGetPrototypeOf(obj);
716
+ // Stop as soon as a null prototype is encountered.
717
+ if (obj === null) {
718
+ return;
719
+ }
720
+ // Stop as soon as a built-in object type is detected.
721
+ const descriptor = ObjectGetOwnPropertyDescriptor(obj, 'constructor');
722
+ if (descriptor !== undefined &&
723
+ typeof descriptor.value === 'function' &&
724
+ builtInObjects.has(descriptor.value.name)) {
725
+ return;
726
+ }
727
+ }
728
+
729
+ if (depth === 0) {
730
+ keySet = new SafeSet();
731
+ } else {
732
+ ArrayPrototypeForEach(keys, (key) => keySet.add(key));
733
+ }
734
+ // Get all own property names and symbols.
735
+ keys = ReflectOwnKeys(obj);
736
+ ArrayPrototypePush(ctx.seen, main);
737
+ for (const key of keys) {
738
+ // Ignore the `constructor` property and keys that exist on layers above.
739
+ if (key === 'constructor' ||
740
+ ObjectPrototypeHasOwnProperty(main, key) ||
741
+ (depth !== 0 && keySet.has(key))) {
742
+ continue;
743
+ }
744
+ const desc = ObjectGetOwnPropertyDescriptor(obj, key);
745
+ if (typeof desc.value === 'function') {
746
+ continue;
747
+ }
748
+ const value = formatProperty(
749
+ ctx, obj, recurseTimes, key, kObjectType, desc, main);
750
+ if (ctx.colors) {
751
+ // Faint!
752
+ ArrayPrototypePush(output, `\u001b[2m${value}\u001b[22m`);
753
+ } else {
754
+ ArrayPrototypePush(output, value);
755
+ }
756
+ }
757
+ ArrayPrototypePop(ctx.seen);
758
+ // Limit the inspection to up to three prototype layers. Using `recurseTimes`
759
+ // is not a good choice here, because it's as if the properties are declared
760
+ // on the current object from the users perspective.
761
+ } while (++depth !== 3);
762
+ }
763
+
764
+ /** @type {(constructor: string, tag: string, fallback: string, size?: string) => string} */
765
+ function getPrefix(constructor, tag, fallback, size = '') {
766
+ if (constructor === null) {
767
+ if (tag !== '' && fallback !== tag) {
768
+ return `[${fallback}${size}: null prototype] [${tag}] `;
769
+ }
770
+ return `[${fallback}${size}: null prototype] `;
771
+ }
772
+
773
+ if (tag !== '' && constructor !== tag) {
774
+ return `${constructor}${size} [${tag}] `;
775
+ }
776
+ return `${constructor}${size} `;
777
+ }
778
+
779
+ // Look up the keys of the object.
780
+ function getKeys(value, showHidden) {
781
+ let keys;
782
+ const symbols = ObjectGetOwnPropertySymbols(value);
783
+ if (showHidden) {
784
+ keys = ObjectGetOwnPropertyNames(value);
785
+ if (symbols.length !== 0)
786
+ ArrayPrototypePushApply(keys, symbols);
787
+ } else {
788
+ // This might throw if `value` is a Module Namespace Object from an
789
+ // unevaluated module, but we don't want to perform the actual type
790
+ // check because it's expensive.
791
+ // TODO(devsnek): track https://github.com/tc39/ecma262/issues/1209
792
+ // and modify this logic as needed.
793
+ try {
794
+ keys = ObjectKeys(value);
795
+ } catch (err) {
796
+ assert(isNativeError(err) && err.name === 'ReferenceError' &&
797
+ isModuleNamespaceObject(value));
798
+ keys = ObjectGetOwnPropertyNames(value);
799
+ }
800
+ if (symbols.length !== 0) {
801
+ const filter = (key) => ObjectPrototypePropertyIsEnumerable(value, key);
802
+ ArrayPrototypePushApply(keys, ArrayPrototypeFilter(symbols, filter));
803
+ }
804
+ }
805
+ return keys;
806
+ }
807
+
808
+ function getCtxStyle(value, constructor, tag) {
809
+ let fallback = '';
810
+ if (constructor === null) {
811
+ fallback = internalGetConstructorName(value);
812
+ if (fallback === tag) {
813
+ fallback = 'Object';
814
+ }
815
+ }
816
+ return getPrefix(constructor, tag, fallback);
817
+ }
818
+
819
+ function formatProxy(ctx, proxy, recurseTimes) {
820
+ if (recurseTimes > ctx.depth && ctx.depth !== null) {
821
+ return ctx.stylize('Proxy [Array]', 'special');
822
+ }
823
+ recurseTimes += 1;
824
+ ctx.indentationLvl += 2;
825
+ const res = [
826
+ formatValue(ctx, proxy[0], recurseTimes),
827
+ formatValue(ctx, proxy[1], recurseTimes),
828
+ ];
829
+ ctx.indentationLvl -= 2;
830
+ return reduceToSingleString(
831
+ ctx, res, '', ['Proxy [', ']'], kArrayExtrasType, recurseTimes);
832
+ }
833
+
834
+ // Note: using `formatValue` directly requires the indentation level to be
835
+ // corrected by setting `ctx.indentationLvL += diff` and then to decrease the
836
+ // value afterwards again.
837
+ function formatValue(ctx, value, recurseTimes, typedArray) {
838
+ // Primitive types cannot have properties.
839
+ if (typeof value !== 'object' &&
840
+ typeof value !== 'function' &&
841
+ !isUndetectableObject(value)) {
842
+ return formatPrimitive(ctx.stylize, value, ctx);
843
+ }
844
+ if (value === null) {
845
+ return ctx.stylize('null', 'null');
846
+ }
847
+
848
+ // Memorize the context for custom inspection on proxies.
849
+ const context = value;
850
+ // Always check for proxies to prevent side effects and to prevent triggering
851
+ // any proxy handlers.
852
+ const proxy = getProxyDetails(value, !!ctx.showProxy);
853
+ if (proxy !== undefined) {
854
+ if (proxy === null || proxy[0] === null) {
855
+ return ctx.stylize('<Revoked Proxy>', 'special');
856
+ }
857
+ if (ctx.showProxy) {
858
+ return formatProxy(ctx, proxy, recurseTimes);
859
+ }
860
+ value = proxy;
861
+ }
862
+
863
+ // Provide a hook for user-specified inspect functions.
864
+ // Check that value is an object with an inspect function on it.
865
+ if (ctx.customInspect) {
866
+ const maybeCustom = value[customInspectSymbol];
867
+ if (typeof maybeCustom === 'function' &&
868
+ // Filter out the util module, its inspect function is special.
869
+ maybeCustom !== inspect &&
870
+ // Also filter out any prototype objects using the circular check.
871
+ ObjectGetOwnPropertyDescriptor(value, 'constructor')?.value?.prototype !== value) {
872
+ // This makes sure the recurseTimes are reported as before while using
873
+ // a counter internally.
874
+ const depth = ctx.depth === null ? null : ctx.depth - recurseTimes;
875
+ const isCrossContext =
876
+ proxy !== undefined || !FunctionPrototypeSymbolHasInstance(Object, context);
877
+ const ret = FunctionPrototypeCall(
878
+ maybeCustom,
879
+ context,
880
+ depth,
881
+ getUserOptions(ctx, isCrossContext),
882
+ inspect,
883
+ );
884
+ // If the custom inspection method returned `this`, don't go into
885
+ // infinite recursion.
886
+ if (ret !== context) {
887
+ if (typeof ret !== 'string') {
888
+ return formatValue(ctx, ret, recurseTimes);
889
+ }
890
+ return StringPrototypeReplaceAll(ret, '\n', `\n${StringPrototypeRepeat(' ', ctx.indentationLvl)}`);
891
+ }
892
+ }
893
+ }
894
+
895
+ // Using an array here is actually better for the average case than using
896
+ // a Set. `seen` will only check for the depth and will never grow too large.
897
+ if (ctx.seen.includes(value)) {
898
+ let index = 1;
899
+ if (ctx.circular === undefined) {
900
+ ctx.circular = new SafeMap();
901
+ ctx.circular.set(value, index);
902
+ } else {
903
+ index = ctx.circular.get(value);
904
+ if (index === undefined) {
905
+ index = ctx.circular.size + 1;
906
+ ctx.circular.set(value, index);
907
+ }
908
+ }
909
+ return ctx.stylize(`[Circular *${index}]`, 'special');
910
+ }
911
+
912
+ return formatRaw(ctx, value, recurseTimes, typedArray);
913
+ }
914
+
915
+ function formatRaw(ctx, value, recurseTimes, typedArray) {
916
+ let keys;
917
+ let protoProps;
918
+ if (ctx.showHidden && (recurseTimes <= ctx.depth || ctx.depth === null)) {
919
+ protoProps = [];
920
+ }
921
+
922
+ const constructor = getConstructorName(value, ctx, recurseTimes, protoProps);
923
+ // Reset the variable to check for this later on.
924
+ if (protoProps !== undefined && protoProps.length === 0) {
925
+ protoProps = undefined;
926
+ }
927
+
928
+ let tag = value[SymbolToStringTag];
929
+ // Only list the tag in case it's non-enumerable / not an own property.
930
+ // Otherwise we'd print this twice.
931
+ if (typeof tag !== 'string' ||
932
+ (tag !== '' &&
933
+ (ctx.showHidden ?
934
+ ObjectPrototypeHasOwnProperty :
935
+ ObjectPrototypePropertyIsEnumerable)(
936
+ value, SymbolToStringTag,
937
+ ))) {
938
+ tag = '';
939
+ }
940
+ let base = '';
941
+ let formatter = getEmptyFormatArray;
942
+ let braces;
943
+ let noIterator = true;
944
+ let i = 0;
945
+ const filter = ctx.showHidden ? ALL_PROPERTIES : ONLY_ENUMERABLE;
946
+
947
+ let extrasType = kObjectType;
948
+
949
+ // Iterators and the rest are split to reduce checks.
950
+ // We have to check all values in case the constructor is set to null.
951
+ // Otherwise it would not possible to identify all types properly.
952
+ if (SymbolIterator in value || constructor === null) {
953
+ noIterator = false;
954
+ if (ArrayIsArray(value)) {
955
+ // Only set the constructor for non ordinary ("Array [...]") arrays.
956
+ const prefix = (constructor !== 'Array' || tag !== '') ?
957
+ getPrefix(constructor, tag, 'Array', `(${value.length})`) :
958
+ '';
959
+ keys = getOwnNonIndexProperties(value, filter);
960
+ braces = [`${prefix}[`, ']'];
961
+ if (value.length === 0 && keys.length === 0 && protoProps === undefined)
962
+ return `${braces[0]}]`;
963
+ extrasType = kArrayExtrasType;
964
+ formatter = formatArray;
965
+ } else if (isSet(value)) {
966
+ const size = SetPrototypeGetSize(value);
967
+ const prefix = getPrefix(constructor, tag, 'Set', `(${size})`);
968
+ keys = getKeys(value, ctx.showHidden);
969
+ formatter = constructor !== null ?
970
+ FunctionPrototypeBind(formatSet, null, value) :
971
+ FunctionPrototypeBind(formatSet, null, SetPrototypeValues(value));
972
+ if (size === 0 && keys.length === 0 && protoProps === undefined)
973
+ return `${prefix}{}`;
974
+ braces = [`${prefix}{`, '}'];
975
+ } else if (isMap(value)) {
976
+ const size = MapPrototypeGetSize(value);
977
+ const prefix = getPrefix(constructor, tag, 'Map', `(${size})`);
978
+ keys = getKeys(value, ctx.showHidden);
979
+ formatter = constructor !== null ?
980
+ FunctionPrototypeBind(formatMap, null, value) :
981
+ FunctionPrototypeBind(formatMap, null, MapPrototypeEntries(value));
982
+ if (size === 0 && keys.length === 0 && protoProps === undefined)
983
+ return `${prefix}{}`;
984
+ braces = [`${prefix}{`, '}'];
985
+ } else if (isTypedArray(value)) {
986
+ keys = getOwnNonIndexProperties(value, filter);
987
+ let bound = value;
988
+ let fallback = '';
989
+ if (constructor === null) {
990
+ fallback = TypedArrayPrototypeGetSymbolToStringTag(value);
991
+ // Reconstruct the array information.
992
+ bound = new primordials[fallback](value);
993
+ }
994
+ const size = TypedArrayPrototypeGetLength(value);
995
+ const prefix = getPrefix(constructor, tag, fallback, `(${size})`);
996
+ braces = [`${prefix}[`, ']'];
997
+ if (value.length === 0 && keys.length === 0 && !ctx.showHidden)
998
+ return `${braces[0]}]`;
999
+ // Special handle the value. The original value is required below. The
1000
+ // bound function is required to reconstruct missing information.
1001
+ formatter = FunctionPrototypeBind(formatTypedArray, null, bound, size);
1002
+ extrasType = kArrayExtrasType;
1003
+ } else if (isMapIterator(value)) {
1004
+ keys = getKeys(value, ctx.showHidden);
1005
+ braces = getIteratorBraces('Map', tag);
1006
+ // Add braces to the formatter parameters.
1007
+ formatter = FunctionPrototypeBind(formatIterator, null, braces);
1008
+ } else if (isSetIterator(value)) {
1009
+ keys = getKeys(value, ctx.showHidden);
1010
+ braces = getIteratorBraces('Set', tag);
1011
+ // Add braces to the formatter parameters.
1012
+ formatter = FunctionPrototypeBind(formatIterator, null, braces);
1013
+ } else {
1014
+ noIterator = true;
1015
+ }
1016
+ }
1017
+ if (noIterator) {
1018
+ keys = getKeys(value, ctx.showHidden);
1019
+ braces = ['{', '}'];
1020
+ if (typeof value === 'function') {
1021
+ base = getFunctionBase(ctx, value, constructor, tag);
1022
+ if (keys.length === 0 && protoProps === undefined)
1023
+ return ctx.stylize(base, 'special');
1024
+ } else if (constructor === 'Object') {
1025
+ if (isArgumentsObject(value)) {
1026
+ braces[0] = '[Arguments] {';
1027
+ } else if (tag !== '') {
1028
+ braces[0] = `${getPrefix(constructor, tag, 'Object')}{`;
1029
+ }
1030
+ if (keys.length === 0 && protoProps === undefined) {
1031
+ return `${braces[0]}}`;
1032
+ }
1033
+ } else if (isRegExp(value)) {
1034
+ // Make RegExps say that they are RegExps
1035
+ base = RegExpPrototypeToString(
1036
+ constructor !== null ? value : new RegExp(value),
1037
+ );
1038
+ const prefix = getPrefix(constructor, tag, 'RegExp');
1039
+ if (prefix !== 'RegExp ')
1040
+ base = `${prefix}${base}`;
1041
+ if ((keys.length === 0 && protoProps === undefined) ||
1042
+ (recurseTimes > ctx.depth && ctx.depth !== null)) {
1043
+ return ctx.stylize(base, 'regexp');
1044
+ }
1045
+ } else if (isDate(value)) {
1046
+ // Make dates with properties first say the date
1047
+ base = NumberIsNaN(DatePrototypeGetTime(value)) ?
1048
+ DatePrototypeToString(value) :
1049
+ DatePrototypeToISOString(value);
1050
+ const prefix = getPrefix(constructor, tag, 'Date');
1051
+ if (prefix !== 'Date ')
1052
+ base = `${prefix}${base}`;
1053
+ if (keys.length === 0 && protoProps === undefined) {
1054
+ return ctx.stylize(base, 'date');
1055
+ }
1056
+ } else if (isError(value)) {
1057
+ base = formatError(value, constructor, tag, ctx, keys);
1058
+ if (keys.length === 0 && protoProps === undefined)
1059
+ return base;
1060
+ } else if (isAnyArrayBuffer(value)) {
1061
+ // Fast path for ArrayBuffer and SharedArrayBuffer.
1062
+ // Can't do the same for DataView because it has a non-primitive
1063
+ // .buffer property that we need to recurse for.
1064
+ const arrayType = isArrayBuffer(value) ? 'ArrayBuffer' :
1065
+ 'SharedArrayBuffer';
1066
+ const prefix = getPrefix(constructor, tag, arrayType);
1067
+ if (typedArray === undefined) {
1068
+ formatter = formatArrayBuffer;
1069
+ } else if (keys.length === 0 && protoProps === undefined) {
1070
+ return prefix +
1071
+ `{ byteLength: ${formatNumber(ctx.stylize, value.byteLength, false)} }`;
1072
+ }
1073
+ braces[0] = `${prefix}{`;
1074
+ ArrayPrototypeUnshift(keys, 'byteLength');
1075
+ } else if (isDataView(value)) {
1076
+ braces[0] = `${getPrefix(constructor, tag, 'DataView')}{`;
1077
+ // .buffer goes last, it's not a primitive like the others.
1078
+ ArrayPrototypeUnshift(keys, 'byteLength', 'byteOffset', 'buffer');
1079
+ } else if (isPromise(value)) {
1080
+ braces[0] = `${getPrefix(constructor, tag, 'Promise')}{`;
1081
+ formatter = formatPromise;
1082
+ } else if (isWeakSet(value)) {
1083
+ braces[0] = `${getPrefix(constructor, tag, 'WeakSet')}{`;
1084
+ formatter = ctx.showHidden ? formatWeakSet : formatWeakCollection;
1085
+ } else if (isWeakMap(value)) {
1086
+ braces[0] = `${getPrefix(constructor, tag, 'WeakMap')}{`;
1087
+ formatter = ctx.showHidden ? formatWeakMap : formatWeakCollection;
1088
+ } else if (isModuleNamespaceObject(value)) {
1089
+ braces[0] = `${getPrefix(constructor, tag, 'Module')}{`;
1090
+ // Special handle keys for namespace objects.
1091
+ formatter = formatNamespaceObject.bind(null, keys);
1092
+ } else if (isBoxedPrimitive(value)) {
1093
+ base = getBoxedBase(value, ctx, keys, constructor, tag);
1094
+ if (keys.length === 0 && protoProps === undefined) {
1095
+ return base;
1096
+ }
1097
+ } else if (isURL(value) && !(recurseTimes > ctx.depth && ctx.depth !== null)) {
1098
+ base = value.href;
1099
+ if (keys.length === 0 && protoProps === undefined) {
1100
+ return base;
1101
+ }
1102
+ } else {
1103
+ if (keys.length === 0 && protoProps === undefined) {
1104
+ if (isExternal(value)) {
1105
+ const address = getExternalValue(value).toString(16);
1106
+ return ctx.stylize(`[External: ${address}]`, 'special');
1107
+ }
1108
+ return `${getCtxStyle(value, constructor, tag)}{}`;
1109
+ }
1110
+ braces[0] = `${getCtxStyle(value, constructor, tag)}{`;
1111
+ }
1112
+ }
1113
+
1114
+ if (recurseTimes > ctx.depth && ctx.depth !== null) {
1115
+ let constructorName = StringPrototypeSlice(getCtxStyle(value, constructor, tag), 0, -1);
1116
+ if (constructor !== null)
1117
+ constructorName = `[${constructorName}]`;
1118
+ return ctx.stylize(constructorName, 'special');
1119
+ }
1120
+ recurseTimes += 1;
1121
+
1122
+ ctx.seen.push(value);
1123
+ ctx.currentDepth = recurseTimes;
1124
+ let output;
1125
+ const indentationLvl = ctx.indentationLvl;
1126
+ try {
1127
+ output = formatter(ctx, value, recurseTimes);
1128
+ for (i = 0; i < keys.length; i++) {
1129
+ ArrayPrototypePush(
1130
+ output,
1131
+ formatProperty(ctx, value, recurseTimes, keys[i], extrasType),
1132
+ );
1133
+ }
1134
+ if (protoProps !== undefined) {
1135
+ ArrayPrototypePushApply(output, protoProps);
1136
+ }
1137
+ } catch (err) {
1138
+ if (!isStackOverflowError(err)) throw err;
1139
+ const constructorName = StringPrototypeSlice(getCtxStyle(value, constructor, tag), 0, -1);
1140
+ return handleMaxCallStackSize(ctx, err, constructorName, indentationLvl);
1141
+ }
1142
+ if (ctx.circular !== undefined) {
1143
+ const index = ctx.circular.get(value);
1144
+ if (index !== undefined) {
1145
+ const reference = ctx.stylize(`<ref *${index}>`, 'special');
1146
+ // Add reference always to the very beginning of the output.
1147
+ if (ctx.compact !== true) {
1148
+ base = base === '' ? reference : `${reference} ${base}`;
1149
+ } else {
1150
+ braces[0] = `${reference} ${braces[0]}`;
1151
+ }
1152
+ }
1153
+ }
1154
+ ctx.seen.pop();
1155
+
1156
+ if (ctx.sorted) {
1157
+ const comparator = ctx.sorted === true ? undefined : ctx.sorted;
1158
+ if (extrasType === kObjectType) {
1159
+ ArrayPrototypeSort(output, comparator);
1160
+ } else if (keys.length > 1) {
1161
+ const sorted = ArrayPrototypeSort(ArrayPrototypeSlice(output, output.length - keys.length), comparator);
1162
+ ArrayPrototypeUnshift(sorted, output, output.length - keys.length, keys.length);
1163
+ ReflectApply(ArrayPrototypeSplice, null, sorted);
1164
+ }
1165
+ }
1166
+
1167
+ const res = reduceToSingleString(
1168
+ ctx, output, base, braces, extrasType, recurseTimes, value);
1169
+ const budget = ctx.budget[ctx.indentationLvl] || 0;
1170
+ const newLength = budget + res.length;
1171
+ ctx.budget[ctx.indentationLvl] = newLength;
1172
+ // If any indentationLvl exceeds this limit, limit further inspecting to the
1173
+ // minimum. Otherwise the recursive algorithm might continue inspecting the
1174
+ // object even though the maximum string size (~2 ** 28 on 32 bit systems and
1175
+ // ~2 ** 30 on 64 bit systems) exceeded. The actual output is not limited at
1176
+ // exactly 2 ** 27 but a bit higher. This depends on the object shape.
1177
+ // This limit also makes sure that huge objects don't block the event loop
1178
+ // significantly.
1179
+ if (newLength > 2 ** 27) {
1180
+ ctx.depth = -1;
1181
+ }
1182
+ return res;
1183
+ }
1184
+
1185
+ function getIteratorBraces(type, tag) {
1186
+ if (tag !== `${type} Iterator`) {
1187
+ if (tag !== '')
1188
+ tag += '] [';
1189
+ tag += `${type} Iterator`;
1190
+ }
1191
+ return [`[${tag}] {`, '}'];
1192
+ }
1193
+
1194
+ function getBoxedBase(value, ctx, keys, constructor, tag) {
1195
+ let fn;
1196
+ let type;
1197
+ if (isNumberObject(value)) {
1198
+ fn = NumberPrototypeValueOf;
1199
+ type = 'Number';
1200
+ } else if (isStringObject(value)) {
1201
+ fn = StringPrototypeValueOf;
1202
+ type = 'String';
1203
+ // For boxed Strings, we have to remove the 0-n indexed entries,
1204
+ // since they just noisy up the output and are redundant
1205
+ // Make boxed primitive Strings look like such
1206
+ keys.splice(0, value.length);
1207
+ } else if (isBooleanObject(value)) {
1208
+ fn = BooleanPrototypeValueOf;
1209
+ type = 'Boolean';
1210
+ } else if (isBigIntObject(value)) {
1211
+ fn = BigIntPrototypeValueOf;
1212
+ type = 'BigInt';
1213
+ } else {
1214
+ fn = SymbolPrototypeValueOf;
1215
+ type = 'Symbol';
1216
+ }
1217
+ let base = `[${type}`;
1218
+ if (type !== constructor) {
1219
+ if (constructor === null) {
1220
+ base += ' (null prototype)';
1221
+ } else {
1222
+ base += ` (${constructor})`;
1223
+ }
1224
+ }
1225
+ base += `: ${formatPrimitive(stylizeNoColor, fn(value), ctx)}]`;
1226
+ if (tag !== '' && tag !== constructor) {
1227
+ base += ` [${tag}]`;
1228
+ }
1229
+ if (keys.length !== 0 || ctx.stylize === stylizeNoColor)
1230
+ return base;
1231
+ return ctx.stylize(base, StringPrototypeToLowerCase(type));
1232
+ }
1233
+
1234
+ function getClassBase(value, constructor, tag) {
1235
+ const hasName = ObjectPrototypeHasOwnProperty(value, 'name');
1236
+ const name = (hasName && value.name) || '(anonymous)';
1237
+ let base = `class ${name}`;
1238
+ if (constructor !== 'Function' && constructor !== null) {
1239
+ base += ` [${constructor}]`;
1240
+ }
1241
+ if (tag !== '' && constructor !== tag) {
1242
+ base += ` [${tag}]`;
1243
+ }
1244
+ if (constructor !== null) {
1245
+ const superName = ObjectGetPrototypeOf(value).name;
1246
+ if (superName) {
1247
+ base += ` extends ${superName}`;
1248
+ }
1249
+ } else {
1250
+ base += ' extends [null prototype]';
1251
+ }
1252
+ return `[${base}]`;
1253
+ }
1254
+
1255
+ function getFunctionBase(ctx, value, constructor, tag) {
1256
+ const stringified = FunctionPrototypeToString(value);
1257
+ if (StringPrototypeStartsWith(stringified, 'class') && stringified[stringified.length - 1] === '}') {
1258
+ const slice = StringPrototypeSlice(stringified, 5, -1);
1259
+ const bracketIndex = StringPrototypeIndexOf(slice, '{');
1260
+ if (bracketIndex !== -1 &&
1261
+ (!StringPrototypeIncludes(StringPrototypeSlice(slice, 0, bracketIndex), '(') ||
1262
+ // Slow path to guarantee that it's indeed a class.
1263
+ RegExpPrototypeExec(classRegExp, RegExpPrototypeSymbolReplace(stripCommentsRegExp, slice)) !== null)
1264
+ ) {
1265
+ return getClassBase(value, constructor, tag);
1266
+ }
1267
+ }
1268
+ let type = 'Function';
1269
+ if (isGeneratorFunction(value)) {
1270
+ type = `Generator${type}`;
1271
+ }
1272
+ if (isAsyncFunction(value)) {
1273
+ type = `Async${type}`;
1274
+ }
1275
+ let base = `[${type}`;
1276
+ if (constructor === null) {
1277
+ base += ' (null prototype)';
1278
+ }
1279
+ if (value.name === '') {
1280
+ base += ' (anonymous)';
1281
+ } else {
1282
+ base += `: ${typeof value.name === 'string' ? value.name : formatValue(ctx, value.name)}`;
1283
+ }
1284
+ base += ']';
1285
+ if (constructor !== type && constructor !== null) {
1286
+ base += ` ${constructor}`;
1287
+ }
1288
+ if (tag !== '' && constructor !== tag) {
1289
+ base += ` [${tag}]`;
1290
+ }
1291
+ return base;
1292
+ }
1293
+
1294
+ function identicalSequenceRange(a, b) {
1295
+ for (let i = 0; i < a.length - 3; i++) {
1296
+ // Find the first entry of b that matches the current entry of a.
1297
+ const pos = ArrayPrototypeIndexOf(b, a[i]);
1298
+ if (pos !== -1) {
1299
+ const rest = b.length - pos;
1300
+ if (rest > 3) {
1301
+ let len = 1;
1302
+ const maxLen = MathMin(a.length - i, rest);
1303
+ // Count the number of consecutive entries.
1304
+ while (maxLen > len && a[i + len] === b[pos + len]) {
1305
+ len++;
1306
+ }
1307
+ if (len > 3) {
1308
+ return { len, offset: i };
1309
+ }
1310
+ }
1311
+ }
1312
+ }
1313
+
1314
+ return { len: 0, offset: 0 };
1315
+ }
1316
+
1317
+ function getStackString(ctx, error) {
1318
+ if (error.stack) {
1319
+ if (typeof error.stack === 'string') {
1320
+ return error.stack;
1321
+ }
1322
+ ctx.seen.push(error);
1323
+ ctx.indentationLvl += 4;
1324
+ const result = formatValue(ctx, error.stack);
1325
+ ctx.indentationLvl -= 4;
1326
+ ctx.seen.pop();
1327
+ return `${ErrorPrototypeToString(error)}\n ${result}`;
1328
+ }
1329
+ return ErrorPrototypeToString(error);
1330
+ }
1331
+
1332
+ function getStackFrames(ctx, err, stack) {
1333
+ const frames = StringPrototypeSplit(stack, '\n');
1334
+
1335
+ let cause;
1336
+ try {
1337
+ ({ cause } = err);
1338
+ } catch {
1339
+ // If 'cause' is a getter that throws, ignore it.
1340
+ }
1341
+
1342
+ // Remove stack frames identical to frames in cause.
1343
+ if (cause != null && isError(cause)) {
1344
+ const causeStack = getStackString(ctx, cause);
1345
+ const causeStackStart = StringPrototypeIndexOf(causeStack, '\n at');
1346
+ if (causeStackStart !== -1) {
1347
+ const causeFrames = StringPrototypeSplit(StringPrototypeSlice(causeStack, causeStackStart + 1), '\n');
1348
+ const { len, offset } = identicalSequenceRange(frames, causeFrames);
1349
+ if (len > 0) {
1350
+ const skipped = len - 2;
1351
+ const msg = ` ... ${skipped} lines matching cause stack trace ...`;
1352
+ frames.splice(offset + 1, skipped, ctx.stylize(msg, 'undefined'));
1353
+ }
1354
+ }
1355
+ }
1356
+ return frames;
1357
+ }
1358
+
1359
+ /** @type {(stack: string, constructor: string | null, name: unknown, tag: string) => string} */
1360
+ function improveStack(stack, constructor, name, tag) {
1361
+ // A stack trace may contain arbitrary data. Only manipulate the output
1362
+ // for "regular errors" (errors that "look normal") for now.
1363
+ let len = name.length;
1364
+
1365
+ if (typeof name !== 'string') {
1366
+ stack = StringPrototypeReplace(
1367
+ stack,
1368
+ `${name}`,
1369
+ `${name} [${StringPrototypeSlice(getPrefix(constructor, tag, 'Error'), 0, -1)}]`,
1370
+ );
1371
+ }
1372
+
1373
+ if (constructor === null ||
1374
+ (StringPrototypeEndsWith(name, 'Error') &&
1375
+ StringPrototypeStartsWith(stack, name) &&
1376
+ (stack.length === len || stack[len] === ':' || stack[len] === '\n'))) {
1377
+ let fallback = 'Error';
1378
+ if (constructor === null) {
1379
+ const start = RegExpPrototypeExec(/^([A-Z][a-z_ A-Z0-9[\]()-]+)(?::|\n {4}at)/, stack) ||
1380
+ RegExpPrototypeExec(/^([a-z_A-Z0-9-]*Error)$/, stack);
1381
+ fallback = (start?.[1]) || '';
1382
+ len = fallback.length;
1383
+ fallback ||= 'Error';
1384
+ }
1385
+ const prefix = StringPrototypeSlice(getPrefix(constructor, tag, fallback), 0, -1);
1386
+ if (name !== prefix) {
1387
+ if (StringPrototypeIncludes(prefix, name)) {
1388
+ if (len === 0) {
1389
+ stack = `${prefix}: ${stack}`;
1390
+ } else {
1391
+ stack = `${prefix}${StringPrototypeSlice(stack, len)}`;
1392
+ }
1393
+ } else {
1394
+ stack = `${prefix} [${name}]${StringPrototypeSlice(stack, len)}`;
1395
+ }
1396
+ }
1397
+ }
1398
+ return stack;
1399
+ }
1400
+
1401
+ function removeDuplicateErrorKeys(ctx, keys, err, stack) {
1402
+ if (!ctx.showHidden && keys.length !== 0) {
1403
+ for (const name of ['name', 'message', 'stack']) {
1404
+ const index = ArrayPrototypeIndexOf(keys, name);
1405
+ // Only hide the property if it's a string and if it's part of the original stack
1406
+ if (index !== -1 && (typeof err[name] !== 'string' || StringPrototypeIncludes(stack, err[name]))) {
1407
+ ArrayPrototypeSplice(keys, index, 1);
1408
+ }
1409
+ }
1410
+ }
1411
+ }
1412
+
1413
+ function markNodeModules(ctx, line) {
1414
+ let tempLine = '';
1415
+ let nodeModule;
1416
+ let pos = 0;
1417
+ while ((nodeModule = nodeModulesRegExp.exec(line)) !== null) {
1418
+ // '/node_modules/'.length === 14
1419
+ tempLine += StringPrototypeSlice(line, pos, nodeModule.index + 14);
1420
+ tempLine += ctx.stylize(nodeModule[1], 'module');
1421
+ pos = nodeModule.index + nodeModule[0].length;
1422
+ }
1423
+ if (pos !== 0) {
1424
+ line = tempLine + StringPrototypeSlice(line, pos);
1425
+ }
1426
+ return line;
1427
+ }
1428
+
1429
+ function markCwd(ctx, line, workingDirectory) {
1430
+ let cwdStartPos = StringPrototypeIndexOf(line, workingDirectory);
1431
+ let tempLine = '';
1432
+ let cwdLength = workingDirectory.length;
1433
+ if (cwdStartPos !== -1) {
1434
+ if (StringPrototypeSlice(line, cwdStartPos - 7, cwdStartPos) === 'file://') {
1435
+ cwdLength += 7;
1436
+ cwdStartPos -= 7;
1437
+ }
1438
+ const start = line[cwdStartPos - 1] === '(' ? cwdStartPos - 1 : cwdStartPos;
1439
+ const end = start !== cwdStartPos && StringPrototypeEndsWith(line, ')') ? -1 : line.length;
1440
+ const workingDirectoryEndPos = cwdStartPos + cwdLength + 1;
1441
+ const cwdSlice = StringPrototypeSlice(line, start, workingDirectoryEndPos);
1442
+
1443
+ tempLine += StringPrototypeSlice(line, 0, start);
1444
+ tempLine += ctx.stylize(cwdSlice, 'undefined');
1445
+ tempLine += StringPrototypeSlice(line, workingDirectoryEndPos, end);
1446
+ if (end === -1) {
1447
+ tempLine += ctx.stylize(')', 'undefined');
1448
+ }
1449
+ } else {
1450
+ tempLine += line;
1451
+ }
1452
+ return tempLine;
1453
+ }
1454
+
1455
+ function safeGetCWD() {
1456
+ let workingDirectory;
1457
+ try {
1458
+ workingDirectory = process.cwd();
1459
+ } catch {
1460
+ return;
1461
+ }
1462
+ return workingDirectory;
1463
+ }
1464
+
1465
+ function formatError(err, constructor, tag, ctx, keys) {
1466
+ const name = err.name != null ? err.name : 'Error';
1467
+ let stack = getStackString(ctx, err);
1468
+
1469
+ removeDuplicateErrorKeys(ctx, keys, err, stack);
1470
+
1471
+ if ('cause' in err &&
1472
+ (keys.length === 0 || !ArrayPrototypeIncludes(keys, 'cause'))) {
1473
+ ArrayPrototypePush(keys, 'cause');
1474
+ }
1475
+
1476
+ // Print errors aggregated into AggregateError
1477
+ if (ArrayIsArray(err.errors) &&
1478
+ (keys.length === 0 || !ArrayPrototypeIncludes(keys, 'errors'))) {
1479
+ ArrayPrototypePush(keys, 'errors');
1480
+ }
1481
+
1482
+ stack = improveStack(stack, constructor, name, tag);
1483
+
1484
+ // Ignore the error message if it's contained in the stack.
1485
+ let pos = (err.message && StringPrototypeIndexOf(stack, err.message)) || -1;
1486
+ if (pos !== -1)
1487
+ pos += err.message.length;
1488
+ // Wrap the error in brackets in case it has no stack trace.
1489
+ const stackStart = StringPrototypeIndexOf(stack, '\n at', pos);
1490
+ if (stackStart === -1) {
1491
+ stack = `[${stack}]`;
1492
+ } else {
1493
+ let newStack = StringPrototypeSlice(stack, 0, stackStart);
1494
+ const stackFramePart = StringPrototypeSlice(stack, stackStart + 1);
1495
+ const lines = getStackFrames(ctx, err, stackFramePart);
1496
+ if (ctx.colors) {
1497
+ // Highlight userland code and node modules.
1498
+ const workingDirectory = safeGetCWD();
1499
+ let esmWorkingDirectory;
1500
+ for (let line of lines) {
1501
+ const core = RegExpPrototypeExec(coreModuleRegExp, line);
1502
+ if (core !== null && BuiltinModule.exists(core[1])) {
1503
+ newStack += `\n${ctx.stylize(line, 'undefined')}`;
1504
+ } else {
1505
+ newStack += '\n';
1506
+
1507
+ line = markNodeModules(ctx, line);
1508
+ if (workingDirectory !== undefined) {
1509
+ let newLine = markCwd(ctx, line, workingDirectory);
1510
+ if (newLine === line) {
1511
+ esmWorkingDirectory ??= pathToFileUrlHref(workingDirectory);
1512
+ newLine = markCwd(ctx, line, esmWorkingDirectory);
1513
+ }
1514
+ line = newLine;
1515
+ }
1516
+
1517
+ newStack += line;
1518
+ }
1519
+ }
1520
+ } else {
1521
+ newStack += `\n${ArrayPrototypeJoin(lines, '\n')}`;
1522
+ }
1523
+ stack = newStack;
1524
+ }
1525
+ // The message and the stack have to be indented as well!
1526
+ if (ctx.indentationLvl !== 0) {
1527
+ const indentation = StringPrototypeRepeat(' ', ctx.indentationLvl);
1528
+ stack = StringPrototypeReplaceAll(stack, '\n', `\n${indentation}`);
1529
+ }
1530
+ return stack;
1531
+ }
1532
+
1533
+ function groupArrayElements(ctx, output, value) {
1534
+ let totalLength = 0;
1535
+ let maxLength = 0;
1536
+ let i = 0;
1537
+ let outputLength = output.length;
1538
+ if (ctx.maxArrayLength < output.length) {
1539
+ // This makes sure the "... n more items" part is not taken into account.
1540
+ outputLength--;
1541
+ }
1542
+ const separatorSpace = 2; // Add 1 for the space and 1 for the separator.
1543
+ const dataLen = new Array(outputLength);
1544
+ // Calculate the total length of all output entries and the individual max
1545
+ // entries length of all output entries. We have to remove colors first,
1546
+ // otherwise the length would not be calculated properly.
1547
+ for (; i < outputLength; i++) {
1548
+ const len = getStringWidth(output[i], ctx.colors);
1549
+ dataLen[i] = len;
1550
+ totalLength += len + separatorSpace;
1551
+ if (maxLength < len)
1552
+ maxLength = len;
1553
+ }
1554
+ // Add two to `maxLength` as we add a single whitespace character plus a comma
1555
+ // in-between two entries.
1556
+ const actualMax = maxLength + separatorSpace;
1557
+ // Check if at least three entries fit next to each other and prevent grouping
1558
+ // of arrays that contains entries of very different length (i.e., if a single
1559
+ // entry is longer than 1/5 of all other entries combined). Otherwise the
1560
+ // space in-between small entries would be enormous.
1561
+ if (actualMax * 3 + ctx.indentationLvl < ctx.breakLength &&
1562
+ (totalLength / actualMax > 5 || maxLength <= 6)) {
1563
+
1564
+ const approxCharHeights = 2.5;
1565
+ const averageBias = MathSqrt(actualMax - totalLength / output.length);
1566
+ const biasedMax = MathMax(actualMax - 3 - averageBias, 1);
1567
+ // Dynamically check how many columns seem possible.
1568
+ const columns = MathMin(
1569
+ // Ideally a square should be drawn. We expect a character to be about 2.5
1570
+ // times as high as wide. This is the area formula to calculate a square
1571
+ // which contains n rectangles of size `actualMax * approxCharHeights`.
1572
+ // Divide that by `actualMax` to receive the correct number of columns.
1573
+ // The added bias increases the columns for short entries.
1574
+ MathRound(
1575
+ MathSqrt(
1576
+ approxCharHeights * biasedMax * outputLength,
1577
+ ) / biasedMax,
1578
+ ),
1579
+ // Do not exceed the breakLength.
1580
+ MathFloor((ctx.breakLength - ctx.indentationLvl) / actualMax),
1581
+ // Limit array grouping for small `compact` modes as the user requested
1582
+ // minimal grouping.
1583
+ ctx.compact * 4,
1584
+ // Limit the columns to a maximum of fifteen.
1585
+ 15,
1586
+ );
1587
+ // Return with the original output if no grouping should happen.
1588
+ if (columns <= 1) {
1589
+ return output;
1590
+ }
1591
+ const tmp = [];
1592
+ const maxLineLength = [];
1593
+ for (let i = 0; i < columns; i++) {
1594
+ let lineMaxLength = 0;
1595
+ for (let j = i; j < output.length; j += columns) {
1596
+ if (dataLen[j] > lineMaxLength)
1597
+ lineMaxLength = dataLen[j];
1598
+ }
1599
+ lineMaxLength += separatorSpace;
1600
+ maxLineLength[i] = lineMaxLength;
1601
+ }
1602
+ let order = StringPrototypePadStart;
1603
+ if (value !== undefined) {
1604
+ for (let i = 0; i < output.length; i++) {
1605
+ if (typeof value[i] !== 'number' && typeof value[i] !== 'bigint') {
1606
+ order = StringPrototypePadEnd;
1607
+ break;
1608
+ }
1609
+ }
1610
+ }
1611
+ // Each iteration creates a single line of grouped entries.
1612
+ for (let i = 0; i < outputLength; i += columns) {
1613
+ // The last lines may contain less entries than columns.
1614
+ const max = MathMin(i + columns, outputLength);
1615
+ let str = '';
1616
+ let j = i;
1617
+ for (; j < max - 1; j++) {
1618
+ // Calculate extra color padding in case it's active. This has to be
1619
+ // done line by line as some lines might contain more colors than
1620
+ // others.
1621
+ const padding = maxLineLength[j - i] + output[j].length - dataLen[j];
1622
+ str += order(`${output[j]}, `, padding, ' ');
1623
+ }
1624
+ if (order === StringPrototypePadStart) {
1625
+ const padding = maxLineLength[j - i] +
1626
+ output[j].length -
1627
+ dataLen[j] -
1628
+ separatorSpace;
1629
+ str += StringPrototypePadStart(output[j], padding, ' ');
1630
+ } else {
1631
+ str += output[j];
1632
+ }
1633
+ ArrayPrototypePush(tmp, str);
1634
+ }
1635
+ if (ctx.maxArrayLength < output.length) {
1636
+ ArrayPrototypePush(tmp, output[outputLength]);
1637
+ }
1638
+ output = tmp;
1639
+ }
1640
+ return output;
1641
+ }
1642
+
1643
+ function handleMaxCallStackSize(ctx, err, constructorName, indentationLvl) {
1644
+ ctx.seen.pop();
1645
+ ctx.indentationLvl = indentationLvl;
1646
+ return ctx.stylize(
1647
+ `[${constructorName}: Inspection interrupted ` +
1648
+ 'prematurely. Maximum call stack size exceeded.]',
1649
+ 'special',
1650
+ );
1651
+ }
1652
+
1653
+ function addNumericSeparator(integerString) {
1654
+ let result = '';
1655
+ let i = integerString.length;
1656
+ assert(i !== 0);
1657
+ const start = integerString[0] === '-' ? 1 : 0;
1658
+ for (; i >= start + 4; i -= 3) {
1659
+ result = `_${StringPrototypeSlice(integerString, i - 3, i)}${result}`;
1660
+ }
1661
+ return i === integerString.length ?
1662
+ integerString :
1663
+ `${StringPrototypeSlice(integerString, 0, i)}${result}`;
1664
+ }
1665
+
1666
+ function addNumericSeparatorEnd(integerString) {
1667
+ let result = '';
1668
+ let i = 0;
1669
+ for (; i < integerString.length - 3; i += 3) {
1670
+ result += `${StringPrototypeSlice(integerString, i, i + 3)}_`;
1671
+ }
1672
+ return i === 0 ?
1673
+ integerString :
1674
+ `${result}${StringPrototypeSlice(integerString, i)}`;
1675
+ }
1676
+
1677
+ const remainingText = (remaining) => `... ${remaining} more item${remaining > 1 ? 's' : ''}`;
1678
+
1679
+ function formatNumber(fn, number, numericSeparator) {
1680
+ if (!numericSeparator) {
1681
+ // Format -0 as '-0'. Checking `number === -0` won't distinguish 0 from -0.
1682
+ if (ObjectIs(number, -0)) {
1683
+ return fn('-0', 'number');
1684
+ }
1685
+ return fn(`${number}`, 'number');
1686
+ }
1687
+ const integer = MathTrunc(number);
1688
+ const string = String(integer);
1689
+ if (integer === number) {
1690
+ if (!NumberIsFinite(number) || StringPrototypeIncludes(string, 'e')) {
1691
+ return fn(string, 'number');
1692
+ }
1693
+ return fn(`${addNumericSeparator(string)}`, 'number');
1694
+ }
1695
+ if (NumberIsNaN(number)) {
1696
+ return fn(string, 'number');
1697
+ }
1698
+ return fn(`${
1699
+ addNumericSeparator(string)
1700
+ }.${
1701
+ addNumericSeparatorEnd(
1702
+ StringPrototypeSlice(String(number), string.length + 1),
1703
+ )
1704
+ }`, 'number');
1705
+ }
1706
+
1707
+ function formatBigInt(fn, bigint, numericSeparator) {
1708
+ const string = String(bigint);
1709
+ if (!numericSeparator) {
1710
+ return fn(`${string}n`, 'bigint');
1711
+ }
1712
+ return fn(`${addNumericSeparator(string)}n`, 'bigint');
1713
+ }
1714
+
1715
+ function formatPrimitive(fn, value, ctx) {
1716
+ if (typeof value === 'string') {
1717
+ let trailer = '';
1718
+ if (value.length > ctx.maxStringLength) {
1719
+ const remaining = value.length - ctx.maxStringLength;
1720
+ value = StringPrototypeSlice(value, 0, ctx.maxStringLength);
1721
+ trailer = `... ${remaining} more character${remaining > 1 ? 's' : ''}`;
1722
+ }
1723
+ if (ctx.compact !== true &&
1724
+ // We do not support handling unicode characters width with
1725
+ // the readline getStringWidth function as there are
1726
+ // performance implications.
1727
+ value.length > kMinLineLength &&
1728
+ value.length > ctx.breakLength - ctx.indentationLvl - 4) {
1729
+ return ArrayPrototypeJoin(
1730
+ ArrayPrototypeMap(
1731
+ RegExpPrototypeSymbolSplit(/(?<=\n)/, value),
1732
+ (line) => fn(strEscape(line), 'string'),
1733
+ ),
1734
+ ` +\n${StringPrototypeRepeat(' ', ctx.indentationLvl + 2)}`,
1735
+ ) + trailer;
1736
+ }
1737
+ return fn(strEscape(value), 'string') + trailer;
1738
+ }
1739
+ if (typeof value === 'number')
1740
+ return formatNumber(fn, value, ctx.numericSeparator);
1741
+ if (typeof value === 'bigint')
1742
+ return formatBigInt(fn, value, ctx.numericSeparator);
1743
+ if (typeof value === 'boolean')
1744
+ return fn(`${value}`, 'boolean');
1745
+ if (typeof value === 'undefined')
1746
+ return fn('undefined', 'undefined');
1747
+ // es6 symbol primitive
1748
+ return fn(SymbolPrototypeToString(value), 'symbol');
1749
+ }
1750
+
1751
+ function formatNamespaceObject(keys, ctx, value, recurseTimes) {
1752
+ const output = new Array(keys.length);
1753
+ for (let i = 0; i < keys.length; i++) {
1754
+ try {
1755
+ output[i] = formatProperty(ctx, value, recurseTimes, keys[i],
1756
+ kObjectType);
1757
+ } catch (err) {
1758
+ assert(isNativeError(err) && err.name === 'ReferenceError');
1759
+ // Use the existing functionality. This makes sure the indentation and
1760
+ // line breaks are always correct. Otherwise it is very difficult to keep
1761
+ // this aligned, even though this is a hacky way of dealing with this.
1762
+ const tmp = { [keys[i]]: '' };
1763
+ output[i] = formatProperty(ctx, tmp, recurseTimes, keys[i], kObjectType);
1764
+ const pos = StringPrototypeLastIndexOf(output[i], ' ');
1765
+ // We have to find the last whitespace and have to replace that value as
1766
+ // it will be visualized as a regular string.
1767
+ output[i] = StringPrototypeSlice(output[i], 0, pos + 1) +
1768
+ ctx.stylize('<uninitialized>', 'special');
1769
+ }
1770
+ }
1771
+ // Reset the keys to an empty array. This prevents duplicated inspection.
1772
+ keys.length = 0;
1773
+ return output;
1774
+ }
1775
+
1776
+ // The array is sparse and/or has extra keys
1777
+ function formatSpecialArray(ctx, value, recurseTimes, maxLength, output, i) {
1778
+ const keys = ObjectKeys(value);
1779
+ let index = i;
1780
+ for (; i < keys.length && output.length < maxLength; i++) {
1781
+ const key = keys[i];
1782
+ const tmp = +key;
1783
+ // Arrays can only have up to 2^32 - 1 entries
1784
+ if (tmp > 2 ** 32 - 2) {
1785
+ break;
1786
+ }
1787
+ if (`${index}` !== key) {
1788
+ if (RegExpPrototypeExec(numberRegExp, key) === null) {
1789
+ break;
1790
+ }
1791
+ const emptyItems = tmp - index;
1792
+ const ending = emptyItems > 1 ? 's' : '';
1793
+ const message = `<${emptyItems} empty item${ending}>`;
1794
+ ArrayPrototypePush(output, ctx.stylize(message, 'undefined'));
1795
+ index = tmp;
1796
+ if (output.length === maxLength) {
1797
+ break;
1798
+ }
1799
+ }
1800
+ ArrayPrototypePush(output, formatProperty(ctx, value, recurseTimes, key, kArrayType));
1801
+ index++;
1802
+ }
1803
+ const remaining = value.length - index;
1804
+ if (output.length !== maxLength) {
1805
+ if (remaining > 0) {
1806
+ const ending = remaining > 1 ? 's' : '';
1807
+ const message = `<${remaining} empty item${ending}>`;
1808
+ ArrayPrototypePush(output, ctx.stylize(message, 'undefined'));
1809
+ }
1810
+ } else if (remaining > 0) {
1811
+ ArrayPrototypePush(output, remainingText(remaining));
1812
+ }
1813
+ return output;
1814
+ }
1815
+
1816
+ function formatArrayBuffer(ctx, value) {
1817
+ let buffer;
1818
+ try {
1819
+ buffer = new Uint8Array(value);
1820
+ } catch {
1821
+ return [ctx.stylize('(detached)', 'special')];
1822
+ }
1823
+ if (hexSlice === undefined)
1824
+ hexSlice = uncurryThis(require('buffer').Buffer.prototype.hexSlice);
1825
+ let str = StringPrototypeTrim(RegExpPrototypeSymbolReplace(
1826
+ /(.{2})/g,
1827
+ hexSlice(buffer, 0, MathMin(ctx.maxArrayLength, buffer.length)),
1828
+ '$1 ',
1829
+ ));
1830
+ const remaining = buffer.length - ctx.maxArrayLength;
1831
+ if (remaining > 0)
1832
+ str += ` ... ${remaining} more byte${remaining > 1 ? 's' : ''}`;
1833
+ return [`${ctx.stylize('[Uint8Contents]', 'special')}: <${str}>`];
1834
+ }
1835
+
1836
+ function formatArray(ctx, value, recurseTimes) {
1837
+ const valLen = value.length;
1838
+ const len = MathMin(MathMax(0, ctx.maxArrayLength), valLen);
1839
+
1840
+ const remaining = valLen - len;
1841
+ const output = [];
1842
+ for (let i = 0; i < len; i++) {
1843
+ // Special handle sparse arrays.
1844
+ if (!ObjectPrototypeHasOwnProperty(value, i)) {
1845
+ return formatSpecialArray(ctx, value, recurseTimes, len, output, i);
1846
+ }
1847
+ ArrayPrototypePush(output, formatProperty(ctx, value, recurseTimes, i, kArrayType));
1848
+ }
1849
+ if (remaining > 0) {
1850
+ ArrayPrototypePush(output, remainingText(remaining));
1851
+ }
1852
+ return output;
1853
+ }
1854
+
1855
+ function formatTypedArray(value, length, ctx, ignored, recurseTimes) {
1856
+ const maxLength = MathMin(MathMax(0, ctx.maxArrayLength), length);
1857
+ const remaining = value.length - maxLength;
1858
+ const output = new Array(maxLength);
1859
+ const elementFormatter = value.length > 0 && typeof value[0] === 'number' ?
1860
+ formatNumber :
1861
+ formatBigInt;
1862
+ for (let i = 0; i < maxLength; ++i) {
1863
+ output[i] = elementFormatter(ctx.stylize, value[i], ctx.numericSeparator);
1864
+ }
1865
+ if (remaining > 0) {
1866
+ output[maxLength] = remainingText(remaining);
1867
+ }
1868
+ if (ctx.showHidden) {
1869
+ // .buffer goes last, it's not a primitive like the others.
1870
+ // All besides `BYTES_PER_ELEMENT` are actually getters.
1871
+ ctx.indentationLvl += 2;
1872
+ for (const key of [
1873
+ 'BYTES_PER_ELEMENT',
1874
+ 'length',
1875
+ 'byteLength',
1876
+ 'byteOffset',
1877
+ 'buffer',
1878
+ ]) {
1879
+ const str = formatValue(ctx, value[key], recurseTimes, true);
1880
+ ArrayPrototypePush(output, `[${key}]: ${str}`);
1881
+ }
1882
+ ctx.indentationLvl -= 2;
1883
+ }
1884
+ return output;
1885
+ }
1886
+
1887
+ function formatSet(value, ctx, ignored, recurseTimes) {
1888
+ const length = value.size;
1889
+ const maxLength = MathMin(MathMax(0, ctx.maxArrayLength), length);
1890
+ const remaining = length - maxLength;
1891
+ const output = [];
1892
+ ctx.indentationLvl += 2;
1893
+ let i = 0;
1894
+ for (const v of value) {
1895
+ if (i >= maxLength) break;
1896
+ ArrayPrototypePush(output, formatValue(ctx, v, recurseTimes));
1897
+ i++;
1898
+ }
1899
+ if (remaining > 0) {
1900
+ ArrayPrototypePush(output, remainingText(remaining));
1901
+ }
1902
+ ctx.indentationLvl -= 2;
1903
+ return output;
1904
+ }
1905
+
1906
+ function formatMap(value, ctx, ignored, recurseTimes) {
1907
+ const length = value.size;
1908
+ const maxLength = MathMin(MathMax(0, ctx.maxArrayLength), length);
1909
+ const remaining = length - maxLength;
1910
+ const output = [];
1911
+ ctx.indentationLvl += 2;
1912
+ let i = 0;
1913
+ for (const { 0: k, 1: v } of value) {
1914
+ if (i >= maxLength) break;
1915
+ ArrayPrototypePush(
1916
+ output,
1917
+ `${formatValue(ctx, k, recurseTimes)} => ${formatValue(ctx, v, recurseTimes)}`,
1918
+ );
1919
+ i++;
1920
+ }
1921
+ if (remaining > 0) {
1922
+ ArrayPrototypePush(output, remainingText(remaining));
1923
+ }
1924
+ ctx.indentationLvl -= 2;
1925
+ return output;
1926
+ }
1927
+
1928
+ function formatSetIterInner(ctx, recurseTimes, entries, state) {
1929
+ const maxArrayLength = MathMax(ctx.maxArrayLength, 0);
1930
+ const maxLength = MathMin(maxArrayLength, entries.length);
1931
+ const output = new Array(maxLength);
1932
+ ctx.indentationLvl += 2;
1933
+ for (let i = 0; i < maxLength; i++) {
1934
+ output[i] = formatValue(ctx, entries[i], recurseTimes);
1935
+ }
1936
+ ctx.indentationLvl -= 2;
1937
+ if (state === kWeak && !ctx.sorted) {
1938
+ // Sort all entries to have a halfway reliable output (if more entries than
1939
+ // retrieved ones exist, we can not reliably return the same output) if the
1940
+ // output is not sorted anyway.
1941
+ ArrayPrototypeSort(output);
1942
+ }
1943
+ const remaining = entries.length - maxLength;
1944
+ if (remaining > 0) {
1945
+ ArrayPrototypePush(output, remainingText(remaining));
1946
+ }
1947
+ return output;
1948
+ }
1949
+
1950
+ function formatMapIterInner(ctx, recurseTimes, entries, state) {
1951
+ const maxArrayLength = MathMax(ctx.maxArrayLength, 0);
1952
+ // Entries exist as [key1, val1, key2, val2, ...]
1953
+ const len = entries.length / 2;
1954
+ const remaining = len - maxArrayLength;
1955
+ const maxLength = MathMin(maxArrayLength, len);
1956
+ const output = new Array(maxLength);
1957
+ let i = 0;
1958
+ ctx.indentationLvl += 2;
1959
+ if (state === kWeak) {
1960
+ for (; i < maxLength; i++) {
1961
+ const pos = i * 2;
1962
+ output[i] =
1963
+ `${formatValue(ctx, entries[pos], recurseTimes)} => ${formatValue(ctx, entries[pos + 1], recurseTimes)}`;
1964
+ }
1965
+ // Sort all entries to have a halfway reliable output (if more entries than
1966
+ // retrieved ones exist, we can not reliably return the same output) if the
1967
+ // output is not sorted anyway.
1968
+ if (!ctx.sorted)
1969
+ ArrayPrototypeSort(output);
1970
+ } else {
1971
+ for (; i < maxLength; i++) {
1972
+ const pos = i * 2;
1973
+ const res = [
1974
+ formatValue(ctx, entries[pos], recurseTimes),
1975
+ formatValue(ctx, entries[pos + 1], recurseTimes),
1976
+ ];
1977
+ output[i] = reduceToSingleString(
1978
+ ctx, res, '', ['[', ']'], kArrayExtrasType, recurseTimes);
1979
+ }
1980
+ }
1981
+ ctx.indentationLvl -= 2;
1982
+ if (remaining > 0) {
1983
+ ArrayPrototypePush(output, remainingText(remaining));
1984
+ }
1985
+ return output;
1986
+ }
1987
+
1988
+ function formatWeakCollection(ctx) {
1989
+ return [ctx.stylize('<items unknown>', 'special')];
1990
+ }
1991
+
1992
+ function formatWeakSet(ctx, value, recurseTimes) {
1993
+ const entries = previewEntries(value);
1994
+ return formatSetIterInner(ctx, recurseTimes, entries, kWeak);
1995
+ }
1996
+
1997
+ function formatWeakMap(ctx, value, recurseTimes) {
1998
+ const entries = previewEntries(value);
1999
+ return formatMapIterInner(ctx, recurseTimes, entries, kWeak);
2000
+ }
2001
+
2002
+ function formatIterator(braces, ctx, value, recurseTimes) {
2003
+ const { 0: entries, 1: isKeyValue } = previewEntries(value, true);
2004
+ if (isKeyValue) {
2005
+ // Mark entry iterators as such.
2006
+ braces[0] = RegExpPrototypeSymbolReplace(/ Iterator] {$/, braces[0], ' Entries] {');
2007
+ return formatMapIterInner(ctx, recurseTimes, entries, kMapEntries);
2008
+ }
2009
+
2010
+ return formatSetIterInner(ctx, recurseTimes, entries, kIterator);
2011
+ }
2012
+
2013
+ function formatPromise(ctx, value, recurseTimes) {
2014
+ let output;
2015
+ const { 0: state, 1: result } = getPromiseDetails(value);
2016
+ if (state === kPending) {
2017
+ output = [ctx.stylize('<pending>', 'special')];
2018
+ } else {
2019
+ ctx.indentationLvl += 2;
2020
+ const str = formatValue(ctx, result, recurseTimes);
2021
+ ctx.indentationLvl -= 2;
2022
+ output = [
2023
+ state === kRejected ?
2024
+ `${ctx.stylize('<rejected>', 'special')} ${str}` :
2025
+ str,
2026
+ ];
2027
+ }
2028
+ return output;
2029
+ }
2030
+
2031
+ function formatProperty(ctx, value, recurseTimes, key, type, desc,
2032
+ original = value) {
2033
+ let name, str;
2034
+ let extra = ' ';
2035
+ desc ||= ObjectGetOwnPropertyDescriptor(value, key) ||
2036
+ { value: value[key], enumerable: true };
2037
+ if (desc.value !== undefined) {
2038
+ const diff = (ctx.compact !== true || type !== kObjectType) ? 2 : 3;
2039
+ ctx.indentationLvl += diff;
2040
+ str = formatValue(ctx, desc.value, recurseTimes);
2041
+ if (diff === 3 && ctx.breakLength < getStringWidth(str, ctx.colors)) {
2042
+ extra = `\n${StringPrototypeRepeat(' ', ctx.indentationLvl)}`;
2043
+ }
2044
+ ctx.indentationLvl -= diff;
2045
+ } else if (desc.get !== undefined) {
2046
+ const label = desc.set !== undefined ? 'Getter/Setter' : 'Getter';
2047
+ const s = ctx.stylize;
2048
+ const sp = 'special';
2049
+ if (ctx.getters && (ctx.getters === true ||
2050
+ (ctx.getters === 'get' && desc.set === undefined) ||
2051
+ (ctx.getters === 'set' && desc.set !== undefined))) {
2052
+ try {
2053
+ const tmp = FunctionPrototypeCall(desc.get, original);
2054
+ ctx.indentationLvl += 2;
2055
+ if (tmp === null) {
2056
+ str = `${s(`[${label}:`, sp)} ${s('null', 'null')}${s(']', sp)}`;
2057
+ } else if (typeof tmp === 'object') {
2058
+ str = `${s(`[${label}]`, sp)} ${formatValue(ctx, tmp, recurseTimes)}`;
2059
+ } else {
2060
+ const primitive = formatPrimitive(s, tmp, ctx);
2061
+ str = `${s(`[${label}:`, sp)} ${primitive}${s(']', sp)}`;
2062
+ }
2063
+ ctx.indentationLvl -= 2;
2064
+ } catch (err) {
2065
+ const message = `<Inspection threw (${err.message})>`;
2066
+ str = `${s(`[${label}:`, sp)} ${message}${s(']', sp)}`;
2067
+ }
2068
+ } else {
2069
+ str = ctx.stylize(`[${label}]`, sp);
2070
+ }
2071
+ } else if (desc.set !== undefined) {
2072
+ str = ctx.stylize('[Setter]', 'special');
2073
+ } else {
2074
+ str = ctx.stylize('undefined', 'undefined');
2075
+ }
2076
+ if (type === kArrayType) {
2077
+ return str;
2078
+ }
2079
+ if (typeof key === 'symbol') {
2080
+ const tmp = RegExpPrototypeSymbolReplace(
2081
+ strEscapeSequencesReplacer,
2082
+ SymbolPrototypeToString(key),
2083
+ escapeFn,
2084
+ );
2085
+ name = `[${ctx.stylize(tmp, 'symbol')}]`;
2086
+ } else if (key === '__proto__') {
2087
+ name = "['__proto__']";
2088
+ } else if (desc.enumerable === false) {
2089
+ const tmp = RegExpPrototypeSymbolReplace(
2090
+ strEscapeSequencesReplacer,
2091
+ key,
2092
+ escapeFn,
2093
+ );
2094
+ name = `[${tmp}]`;
2095
+ } else if (RegExpPrototypeExec(keyStrRegExp, key) !== null) {
2096
+ name = ctx.stylize(key, 'name');
2097
+ } else {
2098
+ name = ctx.stylize(strEscape(key), 'string');
2099
+ }
2100
+ return `${name}:${extra}${str}`;
2101
+ }
2102
+
2103
+ function isBelowBreakLength(ctx, output, start, base) {
2104
+ // Each entry is separated by at least a comma. Thus, we start with a total
2105
+ // length of at least `output.length`. In addition, some cases have a
2106
+ // whitespace in-between each other that is added to the total as well.
2107
+ // TODO(BridgeAR): Add unicode support. Use the readline getStringWidth
2108
+ // function. Check the performance overhead and make it an opt-in in case it's
2109
+ // significant.
2110
+ let totalLength = output.length + start;
2111
+ if (totalLength + output.length > ctx.breakLength)
2112
+ return false;
2113
+ for (let i = 0; i < output.length; i++) {
2114
+ if (ctx.colors) {
2115
+ totalLength += removeColors(output[i]).length;
2116
+ } else {
2117
+ totalLength += output[i].length;
2118
+ }
2119
+ if (totalLength > ctx.breakLength) {
2120
+ return false;
2121
+ }
2122
+ }
2123
+ // Do not line up properties on the same line if `base` contains line breaks.
2124
+ return base === '' || !StringPrototypeIncludes(base, '\n');
2125
+ }
2126
+
2127
+ function reduceToSingleString(
2128
+ ctx, output, base, braces, extrasType, recurseTimes, value) {
2129
+ if (ctx.compact !== true) {
2130
+ if (typeof ctx.compact === 'number' && ctx.compact >= 1) {
2131
+ // Memorize the original output length. In case the output is grouped,
2132
+ // prevent lining up the entries on a single line.
2133
+ const entries = output.length;
2134
+ // Group array elements together if the array contains at least six
2135
+ // separate entries.
2136
+ if (extrasType === kArrayExtrasType && entries > 6) {
2137
+ output = groupArrayElements(ctx, output, value);
2138
+ }
2139
+ // `ctx.currentDepth` is set to the most inner depth of the currently
2140
+ // inspected object part while `recurseTimes` is the actual current depth
2141
+ // that is inspected.
2142
+ //
2143
+ // Example:
2144
+ //
2145
+ // const a = { first: [ 1, 2, 3 ], second: { inner: [ 1, 2, 3 ] } }
2146
+ //
2147
+ // The deepest depth of `a` is 2 (a.second.inner) and `a.first` has a max
2148
+ // depth of 1.
2149
+ //
2150
+ // Consolidate all entries of the local most inner depth up to
2151
+ // `ctx.compact`, as long as the properties are smaller than
2152
+ // `ctx.breakLength`.
2153
+ if (ctx.currentDepth - recurseTimes < ctx.compact &&
2154
+ entries === output.length) {
2155
+ // Line up all entries on a single line in case the entries do not
2156
+ // exceed `breakLength`. Add 10 as constant to start next to all other
2157
+ // factors that may reduce `breakLength`.
2158
+ const start = output.length + ctx.indentationLvl +
2159
+ braces[0].length + base.length + 10;
2160
+ if (isBelowBreakLength(ctx, output, start, base)) {
2161
+ const joinedOutput = join(output, ', ');
2162
+ if (!StringPrototypeIncludes(joinedOutput, '\n')) {
2163
+ return `${base ? `${base} ` : ''}${braces[0]} ${joinedOutput}` +
2164
+ ` ${braces[1]}`;
2165
+ }
2166
+ }
2167
+ }
2168
+ }
2169
+ // Line up each entry on an individual line.
2170
+ const indentation = `\n${StringPrototypeRepeat(' ', ctx.indentationLvl)}`;
2171
+ return `${base ? `${base} ` : ''}${braces[0]}${indentation} ` +
2172
+ `${join(output, `,${indentation} `)}${indentation}${braces[1]}`;
2173
+ }
2174
+ // Line up all entries on a single line in case the entries do not exceed
2175
+ // `breakLength`.
2176
+ if (isBelowBreakLength(ctx, output, 0, base)) {
2177
+ return `${braces[0]}${base ? ` ${base}` : ''} ${join(output, ', ')} ` +
2178
+ braces[1];
2179
+ }
2180
+ const indentation = StringPrototypeRepeat(' ', ctx.indentationLvl);
2181
+ // If the opening "brace" is too large, like in the case of "Set {",
2182
+ // we need to force the first item to be on the next line or the
2183
+ // items will not line up correctly.
2184
+ const ln = base === '' && braces[0].length === 1 ?
2185
+ ' ' : `${base ? ` ${base}` : ''}\n${indentation} `;
2186
+ // Line up each entry on an individual line.
2187
+ return `${braces[0]}${ln}${join(output, `,\n${indentation} `)} ${braces[1]}`;
2188
+ }
2189
+
2190
+ function hasBuiltInToString(value) {
2191
+ // Prevent triggering proxy traps.
2192
+ const getFullProxy = false;
2193
+ const proxyTarget = getProxyDetails(value, getFullProxy);
2194
+ if (proxyTarget !== undefined) {
2195
+ if (proxyTarget === null) {
2196
+ return true;
2197
+ }
2198
+ value = proxyTarget;
2199
+ }
2200
+
2201
+ let hasOwnToString = ObjectPrototypeHasOwnProperty;
2202
+ let hasOwnToPrimitive = ObjectPrototypeHasOwnProperty;
2203
+
2204
+ // Count objects without `toString` and `Symbol.toPrimitive` function as built-in.
2205
+ if (typeof value.toString !== 'function') {
2206
+ if (typeof value[SymbolToPrimitive] !== 'function') {
2207
+ return true;
2208
+ } else if (ObjectPrototypeHasOwnProperty(value, SymbolToPrimitive)) {
2209
+ return false;
2210
+ }
2211
+ hasOwnToString = returnFalse;
2212
+ } else if (ObjectPrototypeHasOwnProperty(value, 'toString')) {
2213
+ return false;
2214
+ } else if (typeof value[SymbolToPrimitive] !== 'function') {
2215
+ hasOwnToPrimitive = returnFalse;
2216
+ } else if (ObjectPrototypeHasOwnProperty(value, SymbolToPrimitive)) {
2217
+ return false;
2218
+ }
2219
+
2220
+ // Find the object that has the `toString` property or `Symbol.toPrimitive` property
2221
+ // as own property in the prototype chain.
2222
+ let pointer = value;
2223
+ do {
2224
+ pointer = ObjectGetPrototypeOf(pointer);
2225
+ } while (!hasOwnToString(pointer, 'toString') &&
2226
+ !hasOwnToPrimitive(pointer, SymbolToPrimitive));
2227
+
2228
+ // Check closer if the object is a built-in.
2229
+ const descriptor = ObjectGetOwnPropertyDescriptor(pointer, 'constructor');
2230
+ return descriptor !== undefined &&
2231
+ typeof descriptor.value === 'function' &&
2232
+ builtInObjects.has(descriptor.value.name);
2233
+ }
2234
+
2235
+ function returnFalse() {
2236
+ return false;
2237
+ }
2238
+
2239
+ const firstErrorLine = (error) => StringPrototypeSplit(error.message, '\n', 1)[0];
2240
+ let CIRCULAR_ERROR_MESSAGE;
2241
+ function tryStringify(arg) {
2242
+ try {
2243
+ return JSONStringify(arg);
2244
+ } catch (err) {
2245
+ // Populate the circular error message lazily
2246
+ if (!CIRCULAR_ERROR_MESSAGE) {
2247
+ try {
2248
+ const a = {};
2249
+ a.a = a;
2250
+ JSONStringify(a);
2251
+ } catch (circularError) {
2252
+ CIRCULAR_ERROR_MESSAGE = firstErrorLine(circularError);
2253
+ }
2254
+ }
2255
+ if (err.name === 'TypeError' &&
2256
+ firstErrorLine(err) === CIRCULAR_ERROR_MESSAGE) {
2257
+ return '[Circular]';
2258
+ }
2259
+ throw err;
2260
+ }
2261
+ }
2262
+
2263
+ function format(...args) {
2264
+ return formatWithOptionsInternal(undefined, args);
2265
+ }
2266
+
2267
+ function formatWithOptions(inspectOptions, ...args) {
2268
+ validateObject(inspectOptions, 'inspectOptions', kValidateObjectAllowArray);
2269
+ return formatWithOptionsInternal(inspectOptions, args);
2270
+ }
2271
+
2272
+ function formatNumberNoColor(number, options) {
2273
+ return formatNumber(
2274
+ stylizeNoColor,
2275
+ number,
2276
+ options?.numericSeparator ?? inspectDefaultOptions.numericSeparator,
2277
+ );
2278
+ }
2279
+
2280
+ function formatBigIntNoColor(bigint, options) {
2281
+ return formatBigInt(
2282
+ stylizeNoColor,
2283
+ bigint,
2284
+ options?.numericSeparator ?? inspectDefaultOptions.numericSeparator,
2285
+ );
2286
+ }
2287
+
2288
+ function formatWithOptionsInternal(inspectOptions, args) {
2289
+ const first = args[0];
2290
+ let a = 0;
2291
+ let str = '';
2292
+ let join = '';
2293
+
2294
+ if (typeof first === 'string') {
2295
+ if (args.length === 1) {
2296
+ return first;
2297
+ }
2298
+ let tempStr;
2299
+ let lastPos = 0;
2300
+
2301
+ for (let i = 0; i < first.length - 1; i++) {
2302
+ if (StringPrototypeCharCodeAt(first, i) === 37) { // '%'
2303
+ const nextChar = StringPrototypeCharCodeAt(first, ++i);
2304
+ if (a + 1 !== args.length) {
2305
+ switch (nextChar) {
2306
+ case 115: { // 's'
2307
+ const tempArg = args[++a];
2308
+ if (typeof tempArg === 'number') {
2309
+ tempStr = formatNumberNoColor(tempArg, inspectOptions);
2310
+ } else if (typeof tempArg === 'bigint') {
2311
+ tempStr = formatBigIntNoColor(tempArg, inspectOptions);
2312
+ } else if (typeof tempArg !== 'object' ||
2313
+ tempArg === null ||
2314
+ !hasBuiltInToString(tempArg)) {
2315
+ tempStr = String(tempArg);
2316
+ } else {
2317
+ tempStr = inspect(tempArg, {
2318
+ ...inspectOptions,
2319
+ compact: 3,
2320
+ colors: false,
2321
+ depth: 0,
2322
+ });
2323
+ }
2324
+ break;
2325
+ }
2326
+ case 106: // 'j'
2327
+ tempStr = tryStringify(args[++a]);
2328
+ break;
2329
+ case 100: { // 'd'
2330
+ const tempNum = args[++a];
2331
+ if (typeof tempNum === 'bigint') {
2332
+ tempStr = formatBigIntNoColor(tempNum, inspectOptions);
2333
+ } else if (typeof tempNum === 'symbol') {
2334
+ tempStr = 'NaN';
2335
+ } else {
2336
+ tempStr = formatNumberNoColor(Number(tempNum), inspectOptions);
2337
+ }
2338
+ break;
2339
+ }
2340
+ case 79: // 'O'
2341
+ tempStr = inspect(args[++a], inspectOptions);
2342
+ break;
2343
+ case 111: // 'o'
2344
+ tempStr = inspect(args[++a], {
2345
+ ...inspectOptions,
2346
+ showHidden: true,
2347
+ showProxy: true,
2348
+ depth: 4,
2349
+ });
2350
+ break;
2351
+ case 105: { // 'i'
2352
+ const tempInteger = args[++a];
2353
+ if (typeof tempInteger === 'bigint') {
2354
+ tempStr = formatBigIntNoColor(tempInteger, inspectOptions);
2355
+ } else if (typeof tempInteger === 'symbol') {
2356
+ tempStr = 'NaN';
2357
+ } else {
2358
+ tempStr = formatNumberNoColor(
2359
+ NumberParseInt(tempInteger), inspectOptions);
2360
+ }
2361
+ break;
2362
+ }
2363
+ case 102: { // 'f'
2364
+ const tempFloat = args[++a];
2365
+ if (typeof tempFloat === 'symbol') {
2366
+ tempStr = 'NaN';
2367
+ } else {
2368
+ tempStr = formatNumberNoColor(
2369
+ NumberParseFloat(tempFloat), inspectOptions);
2370
+ }
2371
+ break;
2372
+ }
2373
+ case 99: // 'c'
2374
+ a += 1;
2375
+ tempStr = '';
2376
+ break;
2377
+ case 37: // '%'
2378
+ str += StringPrototypeSlice(first, lastPos, i);
2379
+ lastPos = i + 1;
2380
+ continue;
2381
+ default: // Any other character is not a correct placeholder
2382
+ continue;
2383
+ }
2384
+ if (lastPos !== i - 1) {
2385
+ str += StringPrototypeSlice(first, lastPos, i - 1);
2386
+ }
2387
+ str += tempStr;
2388
+ lastPos = i + 1;
2389
+ } else if (nextChar === 37) {
2390
+ str += StringPrototypeSlice(first, lastPos, i);
2391
+ lastPos = i + 1;
2392
+ }
2393
+ }
2394
+ }
2395
+ if (lastPos !== 0) {
2396
+ a++;
2397
+ join = ' ';
2398
+ if (lastPos < first.length) {
2399
+ str += StringPrototypeSlice(first, lastPos);
2400
+ }
2401
+ }
2402
+ }
2403
+
2404
+ while (a < args.length) {
2405
+ const value = args[a];
2406
+ str += join;
2407
+ str += typeof value !== 'string' ? inspect(value, inspectOptions) : value;
2408
+ join = ' ';
2409
+ a++;
2410
+ }
2411
+ return str;
2412
+ }
2413
+
2414
+ function isZeroWidthCodePoint(code) {
2415
+ return code <= 0x1F || // C0 control codes
2416
+ (code >= 0x7F && code <= 0x9F) || // C1 control codes
2417
+ (code >= 0x300 && code <= 0x36F) || // Combining Diacritical Marks
2418
+ (code >= 0x200B && code <= 0x200F) || // Modifying Invisible Characters
2419
+ // Combining Diacritical Marks for Symbols
2420
+ (code >= 0x20D0 && code <= 0x20FF) ||
2421
+ (code >= 0xFE00 && code <= 0xFE0F) || // Variation Selectors
2422
+ (code >= 0xFE20 && code <= 0xFE2F) || // Combining Half Marks
2423
+ (code >= 0xE0100 && code <= 0xE01EF); // Variation Selectors
2424
+ }
2425
+
2426
+ if (internalBinding('config').hasIntl) {
2427
+ const icu = internalBinding('icu');
2428
+ // icu.getStringWidth(string, ambiguousAsFullWidth, expandEmojiSequence)
2429
+ // Defaults: ambiguousAsFullWidth = false; expandEmojiSequence = true;
2430
+ // TODO(BridgeAR): Expose the options to the user. That is probably the
2431
+ // best thing possible at the moment, since it's difficult to know what
2432
+ // the receiving end supports.
2433
+ getStringWidth = function getStringWidth(str, removeControlChars = true) {
2434
+ let width = 0;
2435
+
2436
+ if (removeControlChars) {
2437
+ str = stripVTControlCharacters(str);
2438
+ }
2439
+ for (let i = 0; i < str.length; i++) {
2440
+ // Try to avoid calling into C++ by first handling the ASCII portion of
2441
+ // the string. If it is fully ASCII, we skip the C++ part.
2442
+ const code = str.charCodeAt(i);
2443
+ if (code >= 127) {
2444
+ width += icu.getStringWidth(StringPrototypeNormalize(StringPrototypeSlice(str, i), 'NFC'));
2445
+ break;
2446
+ }
2447
+ width += code >= 32 ? 1 : 0;
2448
+ }
2449
+ return width;
2450
+ };
2451
+ } else {
2452
+ /**
2453
+ * Returns the number of columns required to display the given string.
2454
+ */
2455
+ getStringWidth = function getStringWidth(str, removeControlChars = true) {
2456
+ let width = 0;
2457
+
2458
+ if (removeControlChars)
2459
+ str = stripVTControlCharacters(str);
2460
+ str = StringPrototypeNormalize(str, 'NFC');
2461
+ for (const char of new SafeStringIterator(str)) {
2462
+ const code = StringPrototypeCodePointAt(char, 0);
2463
+ if (isFullWidthCodePoint(code)) {
2464
+ width += 2;
2465
+ } else if (!isZeroWidthCodePoint(code)) {
2466
+ width++;
2467
+ }
2468
+ }
2469
+
2470
+ return width;
2471
+ };
2472
+
2473
+ /**
2474
+ * Returns true if the character represented by a given
2475
+ * Unicode code point is full-width. Otherwise returns false.
2476
+ */
2477
+ const isFullWidthCodePoint = (code) => {
2478
+ // Code points are partially derived from:
2479
+ // https://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt
2480
+ return code >= 0x1100 && (
2481
+ code <= 0x115f || // Hangul Jamo
2482
+ code === 0x2329 || // LEFT-POINTING ANGLE BRACKET
2483
+ code === 0x232a || // RIGHT-POINTING ANGLE BRACKET
2484
+ // CJK Radicals Supplement .. Enclosed CJK Letters and Months
2485
+ (code >= 0x2e80 && code <= 0x3247 && code !== 0x303f) ||
2486
+ // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
2487
+ (code >= 0x3250 && code <= 0x4dbf) ||
2488
+ // CJK Unified Ideographs .. Yi Radicals
2489
+ (code >= 0x4e00 && code <= 0xa4c6) ||
2490
+ // Hangul Jamo Extended-A
2491
+ (code >= 0xa960 && code <= 0xa97c) ||
2492
+ // Hangul Syllables
2493
+ (code >= 0xac00 && code <= 0xd7a3) ||
2494
+ // CJK Compatibility Ideographs
2495
+ (code >= 0xf900 && code <= 0xfaff) ||
2496
+ // Vertical Forms
2497
+ (code >= 0xfe10 && code <= 0xfe19) ||
2498
+ // CJK Compatibility Forms .. Small Form Variants
2499
+ (code >= 0xfe30 && code <= 0xfe6b) ||
2500
+ // Halfwidth and Fullwidth Forms
2501
+ (code >= 0xff01 && code <= 0xff60) ||
2502
+ (code >= 0xffe0 && code <= 0xffe6) ||
2503
+ // Kana Supplement
2504
+ (code >= 0x1b000 && code <= 0x1b001) ||
2505
+ // Enclosed Ideographic Supplement
2506
+ (code >= 0x1f200 && code <= 0x1f251) ||
2507
+ // Miscellaneous Symbols and Pictographs 0x1f300 - 0x1f5ff
2508
+ // Emoticons 0x1f600 - 0x1f64f
2509
+ (code >= 0x1f300 && code <= 0x1f64f) ||
2510
+ // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
2511
+ (code >= 0x20000 && code <= 0x3fffd)
2512
+ );
2513
+ };
2514
+
2515
+ }
2516
+
2517
+ /**
2518
+ * Remove all VT control characters. Use to estimate displayed string width.
2519
+ */
2520
+ function stripVTControlCharacters(str) {
2521
+ validateString(str, 'str');
2522
+
2523
+ return RegExpPrototypeSymbolReplace(ansi, str, '');
2524
+ }
2525
+
2526
+ module.exports = {
2527
+ identicalSequenceRange,
2528
+ inspect,
2529
+ inspectDefaultOptions,
2530
+ format,
2531
+ formatWithOptions,
2532
+ getStringWidth,
2533
+ stripVTControlCharacters,
2534
+ isZeroWidthCodePoint,
2535
+ };