Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue importing es6 lodash module #166

Closed
timshannon opened this issue Oct 5, 2015 · 7 comments
Closed

Issue importing es6 lodash module #166

timshannon opened this issue Oct 5, 2015 · 7 comments

Comments

@timshannon
Copy link

I've been using the es6 version of lodash in my project for a while and I use it like this:

import uniq from "lib/lodash/array/uniq";

It's been working fine for a while now, but I just updated rollup and now I'm getting the following error:

Cannot use indices of replaced characters as exclusion ranges
Error: Cannot use indices of replaced characters as exclusion ranges
    at source/web/node_modules/gobble-rollup/node_modules/rollup/node_modules/magic-string/src/MagicString/index.js:119:12
    at Array.map (native)
    at MagicString.indent (source/web/node_modules/gobble-rollup/node_modules/rollup/node_modules/magic-string/src/MagicString/index.js:112:28)
    at source/web/node_modules/gobble-rollup/node_modules/rollup/node_modules/magic-string/src/Bundle/index.js:155:19
    at Array.forEach (native)
    at Bundle$1.indent (source/web/node_modules/gobble-rollup/node_modules/rollup/node_modules/magic-string/src/Bundle/index.js:151:16)
    at umd (source/web/node_modules/gobble-rollup/node_modules/rollup/src/finalisers/umd.js:56:4)
    at Bundle.render (source/web/node_modules/gobble-rollup/node_modules/rollup/src/Bundle.js:179:17)
    at Object.write (source/web/node_modules/gobble-rollup/node_modules/rollup/src/rollup.js:29:32)
    at source/web/node_modules/gobble-rollup/index.js:13:17

I'll see if I can build something reproducible when I get a chance.

@Rich-Harris
Copy link
Contributor

Eek! Is that with 0.18.2 (latest version)?

@timshannon
Copy link
Author

Yep, 0.18.2.

It's very likely I'm doing something wrong. It's part of a larger project, so I need to parse this down into something simpler and reproducible to make sure.

@Rich-Harris
Copy link
Contributor

Judging by the error message it's caused by the fix for #164. Not quite sure how that's possible, but at least we know where to start looking...

@timshannon
Copy link
Author

Off the top of my head my only guess would be that it's having issues with the backticks in the comment of uniq.js. The entire file is below:

import baseCallback from '../internal/baseCallback';
import baseUniq from '../internal/baseUniq';
import isIterateeCall from '../internal/isIterateeCall';
import sortedUniq from '../internal/sortedUniq';

/**
 * Creates a duplicate-free version of an array, using
 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
 * for equality comparisons, in which only the first occurence of each element
 * is kept. Providing `true` for `isSorted` performs a faster search algorithm
 * for sorted arrays. If an iteratee function is provided it's invoked for
 * each element in the array to generate the criterion by which uniqueness
 * is computed. The `iteratee` is bound to `thisArg` and invoked with three
 * arguments: (value, index, array).
 *
 * If a property name is provided for `iteratee` the created `_.property`
 * style callback returns the property value of the given element.
 *
 * If a value is also provided for `thisArg` the created `_.matchesProperty`
 * style callback returns `true` for elements that have a matching property
 * value, else `false`.
 *
 * If an object is provided for `iteratee` the created `_.matches` style
 * callback returns `true` for elements that have the properties of the given
 * object, else `false`.
 *
 * @static
 * @memberOf _
 * @alias unique
 * @category Array
 * @param {Array} array The array to inspect.
 * @param {boolean} [isSorted] Specify the array is sorted.
 * @param {Function|Object|string} [iteratee] The function invoked per iteration.
 * @param {*} [thisArg] The `this` binding of `iteratee`.
 * @returns {Array} Returns the new duplicate-value-free array.
 * @example
 *
 * _.uniq([2, 1, 2]);
 * // => [2, 1]
 *
 * // using `isSorted`
 * _.uniq([1, 1, 2], true);
 * // => [1, 2]
 *
 * // using an iteratee function
 * _.uniq([1, 2.5, 1.5, 2], function(n) {
 *   return this.floor(n);
 * }, Math);
 * // => [1, 2.5]
 *
 * // using the `_.property` callback shorthand
 * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
 * // => [{ 'x': 1 }, { 'x': 2 }]
 */
function uniq(array, isSorted, iteratee, thisArg) {
  var length = array ? array.length : 0;
  if (!length) {
    return [];
  }
  if (isSorted != null && typeof isSorted != 'boolean') {
    thisArg = iteratee;
    iteratee = isIterateeCall(array, isSorted, thisArg) ? undefined : isSorted;
    isSorted = false;
  }
  iteratee = iteratee == null ? iteratee : baseCallback(iteratee, thisArg, 3);
  return (isSorted)
    ? sortedUniq(array, iteratee)
    : baseUniq(array, iteratee);
}

export default uniq;

@timshannon
Copy link
Author

Ok, I can reproduce it with just importing a single lodash module. You can run gobble against the repository here: https://github.com/timshannon/rollup-166 if you want to reproduce it.

It also contains my full es6 build of lodash incase I'm doing something wrong with how I'm building it.

@Rich-Harris
Copy link
Contributor

Thanks! Fixed in 0.18.3. Was happening because of a multiple var declaration block:

var argsTag = '[object Arguments]',
    arrayTag = '[object Array]',
    objectTag = '[object Object]';

Multiple declarations get separated (so we don't end up including stuff we don't need), which means screwing around with the source in such a way that the locations of the string literals got obscured. Fixed by cropping the 'exclusion ranges' (which prevent multiline strings from being indented along with source code) to exclude the enclosing quotes. Prevented non-multiline strings from being included in that set of ranges in the first place, for good measure.

@timshannon
Copy link
Author

Yep, it's working great for me now.

Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants