_optionalChainDelete.js 1.6 KB

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