rspack: newTreeshaking fails at Ramda's all() utility

System Info

Using “ramda”: “0.27.1” and “@rspack/cli”: “0.4.3”

Details

Ramda library has this all utility:

import _curry2 from "./internal/_curry2.js";
import _dispatchable from "./internal/_dispatchable.js";
import _xall from "./internal/_xall.js";
/**
 * Returns `true` if all elements of the list match the predicate, `false` if
 * there are any that don't. HEH
 *
 * Dispatches to the `all` method of the second argument, if present.
 *
 * Acts as a transducer if a transformer is given in list position.
 *
 * @func
 * @memberOf R
 * @since v0.1.0
 * @category List
 * @sig (a -> Boolean) -> [a] -> Boolean
 * @param {Function} fn The predicate function.
 * @param {Array} list The array to consider.
 * @return {Boolean} `true` if the predicate is satisfied by every element, `false`
 *         otherwise.
 * @see R.any, R.none, R.transduce
 * @example
 *
 *      const equals3 = R.equals(3);
 *      R.all(equals3)([3, 3, 3, 3]); //=> true
 *      R.all(equals3)([3, 3, 1, 3]); //=> false
 */

var all =
/*#__PURE__*/
_curry2(
/*#__PURE__*/
_dispatchable(['all'], _xall, function all(fn, list) {
  var idx = 0;

  while (idx < list.length) {
    if (!fn(list[idx])) {
      return false;
    }

    idx += 1;
  }

  return true;
}));

export default all;

This is compiled down to this using Rspack with newTreeshaking and SWC:

"66364": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */var _internal_curry2_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./internal/_curry2.js */"55495");
/* harmony import */var _internal_dispatchable_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./internal/_dispatchable.js */"33478");
/* harmony import */var _internal_xall_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./internal/_xall.js */"35805");



/**
 * Returns `true` if all elements of the list match the predicate, `false` if
 * there are any that don't. HEH
 *
 * Dispatches to the `all` method of the second argument, if present.
 *
 * Acts as a transducer if a transformer is given in list position.
 *
 * @func
 * @memberOf R
 * @since v0.1.0
 * @category List
 * @sig (a -> Boolean) -> [a] -> Boolean
 * @param {Function} fn The predicate function.
 * @param {Array} list The array to consider.
 * @return {Boolean} `true` if the predicate is satisfied by every element, `false`
 *         otherwise.
 * @see R.any, R.none, R.transduce
 * @example
 *
 *      const equals3 = R.equals(3);
 *      R.all(equals3)([3, 3, 3, 3]); //=> true
 *      R.all(equals3)([3, 3, 1, 3]); //=> false
 */ var all = /*#__PURE__*/ (/* unused pure expression or super */ null && ((0, _internal_curry2_js__WEBPACK_IMPORTED_MODULE_0__.Z)(/*#__PURE__*/ (0, _internal_dispatchable_js__WEBPACK_IMPORTED_MODULE_1__.Z)([
    "all"
], , function all(fn, list) {
    var idx = 0;
    while(idx < list.length){
        if (!fn(list[idx])) return false;
        idx += 1;
    }
    return true;
}))));
var __WEBPACK_DEFAULT_EXPORT__ = (/* unused pure expression or super */ null && (all));
})

Reproduce link

No response

Reproduce Steps

When using the newTreeshaking: true, it fails with this error:

> rspack --mode production --env target=client

  × Error[javascript]: JavaScript parsing error
       ╭─[vendors-f1b574f2c20aa4ec8e59.js:43275:1]
 43275 │     "all"
 43276 │ ], , function all(fn, list) {
       ·    ┬
       ·    ╰── Expression expected
 43277 │     var idx = 0;
       ╰────

The compilation has stripped the _xall from original source code and left an empty comma expression and now it fails there.

About this issue

  • Original URL
  • State: closed
  • Created 7 months ago
  • Comments: 17 (10 by maintainers)

Most upvoted comments

I’m still unable to reproduce with a simple case but if its helpful it only occurs with newTreeshaking and optimization.splitChunks enabled in production mode.

{
    optimization: {
      splitChunks: {
        chunks: 'all',
      },
    },
    experiments: {
      rspackFuture: {
        newTreeshaking: true,
      },
    },
}

It does not occur with other splitChunks.chunks options such as async.

I noticed this comment, and I could replicate in https://github.com/web-infra-dev/rspack/issues/5595, we will fix this issue ASAP