summaryrefslogtreecommitdiff
path: root/shared/logger/node_modules/@sentry/utils/esm/buildPolyfills
diff options
context:
space:
mode:
authorrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
committerrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
commitbce557cc2dc767628bed6aac87301a1be7c5431b (patch)
treeb51a051228d01fe3306cd7626d4a96768aadb944 /shared/logger/node_modules/@sentry/utils/esm/buildPolyfills
init commit
Diffstat (limited to 'shared/logger/node_modules/@sentry/utils/esm/buildPolyfills')
-rw-r--r--shared/logger/node_modules/@sentry/utils/esm/buildPolyfills/_optionalChain.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/shared/logger/node_modules/@sentry/utils/esm/buildPolyfills/_optionalChain.js b/shared/logger/node_modules/@sentry/utils/esm/buildPolyfills/_optionalChain.js
new file mode 100644
index 0000000..6b4f012
--- /dev/null
+++ b/shared/logger/node_modules/@sentry/utils/esm/buildPolyfills/_optionalChain.js
@@ -0,0 +1,59 @@
+/**
+ * Polyfill for the optional chain operator, `?.`, given previous conversion of the expression into an array of values,
+ * descriptors, and functions.
+ *
+ * Adapted from Sucrase (https://github.com/alangpierce/sucrase)
+ * See https://github.com/alangpierce/sucrase/blob/265887868966917f3b924ce38dfad01fbab1329f/src/transformers/OptionalChainingNullishTransformer.ts#L15
+ *
+ * @param ops Array result of expression conversion
+ * @returns The value of the expression
+ */
+function _optionalChain(ops) {
+ let lastAccessLHS = undefined;
+ let value = ops[0];
+ let i = 1;
+ while (i < ops.length) {
+ const op = ops[i] ;
+ const fn = ops[i + 1] ;
+ i += 2;
+ // by checking for loose equality to `null`, we catch both `null` and `undefined`
+ if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) {
+ // really we're meaning to return `undefined` as an actual value here, but it saves bytes not to write it
+ return;
+ }
+ if (op === 'access' || op === 'optionalAccess') {
+ lastAccessLHS = value;
+ value = fn(value);
+ } else if (op === 'call' || op === 'optionalCall') {
+ value = fn((...args) => (value ).call(lastAccessLHS, ...args));
+ lastAccessLHS = undefined;
+ }
+ }
+ return value;
+}
+
+// Sucrase version
+// function _optionalChain(ops) {
+// let lastAccessLHS = undefined;
+// let value = ops[0];
+// let i = 1;
+// while (i < ops.length) {
+// const op = ops[i];
+// const fn = ops[i + 1];
+// i += 2;
+// if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) {
+// return undefined;
+// }
+// if (op === 'access' || op === 'optionalAccess') {
+// lastAccessLHS = value;
+// value = fn(value);
+// } else if (op === 'call' || op === 'optionalCall') {
+// value = fn((...args) => value.call(lastAccessLHS, ...args));
+// lastAccessLHS = undefined;
+// }
+// }
+// return value;
+// }
+
+export { _optionalChain };
+//# sourceMappingURL=_optionalChain.js.map