_asyncOptionalChainDelete.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334
  1. Object.defineProperty(exports, '__esModule', { value: true });
  2. const _asyncOptionalChain = require('./_asyncOptionalChain.js');
  3. // https://github.com/alangpierce/sucrase/tree/265887868966917f3b924ce38dfad01fbab1329f
  4. /**
  5. * Polyfill for the optional chain operator, `?.`, given previous conversion of the expression into an array of values,
  6. * descriptors, and functions, in cases where the value of the expression is to be deleted.
  7. *
  8. * Adapted from Sucrase (https://github.com/alangpierce/sucrase) See
  9. * https://github.com/alangpierce/sucrase/blob/265887868966917f3b924ce38dfad01fbab1329f/src/transformers/OptionalChainingNullishTransformer.ts#L15
  10. *
  11. * @param ops Array result of expression conversion
  12. * @returns The return value of the `delete` operator: `true`, unless the deletion target is an own, non-configurable
  13. * property (one which can't be deleted or turned into an accessor, and whose enumerability can't be changed), in which
  14. * case `false`.
  15. */
  16. async function _asyncOptionalChainDelete(ops) {
  17. const result = (await _asyncOptionalChain._asyncOptionalChain(ops)) ;
  18. // If `result` is `null`, it means we didn't get to the end of the chain and so nothing was deleted (in which case,
  19. // return `true` since that's what `delete` does when it no-ops). If it's non-null, we know the delete happened, in
  20. // which case we return whatever the `delete` returned, which will be a boolean.
  21. return result == null ? true : (result );
  22. }
  23. // Sucrase version:
  24. // async function asyncOptionalChainDelete(ops) {
  25. // const result = await ASYNC_OPTIONAL_CHAIN_NAME(ops);
  26. // return result == null ? true : result;
  27. // }
  28. exports._asyncOptionalChainDelete = _asyncOptionalChainDelete;
  29. //# sourceMappingURL=_asyncOptionalChainDelete.js.map