google / google/closure-compiler
Compiler thinks nested function parameter is undefined in ECMASCRIPT6_TYPED mode
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
I'm using `v20160315` and I'm noticing the following error when I compile Closure Library code in `ADVANCED` `ECMASCRIPT6_TYPED` mode:
```
external/closure_library/closure/goog/iter/iter.js:1236: ERROR - variable index is undeclared
function getIndexFromElements(index) { return elements[index]; }
^
external/closure_library/closure/goog/iter/iter.js:1280: ERROR - variable getIndexFromElements is undeclared
(sortedIndexIterator.next()), getIndexFromElements);
^
2 error(s), 0 warning(s)
```
The params I'm using are:
```
--js_output_file=bazel-out/local-fastbuild/bin/closure/testing/test/arithmetic_module_test_bin.js
--create_source_map=bazel-out/local-fastbuild/bin/closure/testing/test/arithmetic_module_test_bin.js.map
--language_in=ECMASCRIPT6_TYPED
--language_out=ECMASCRIPT3
--compilation_level=ADVANCED
--dependency_mode=LOOSE
--warning_level=VERBOSE
--generate_exports
--js_module_root=bazel-out/local-fastbuild/bin
--source_map_location_mapping=bazel-out/local-fastbuild/bin|
--source_map_location_mapping=|/
--hide_warnings_for=.soy.js
--hide_warnings_for=external/closure_library/
--hide_warnings_for=external/soyutils_usegoog/
--formatting=PRETTY_PRINT
--debug
--entry_point=goog:arithmetic_module_test
--js=external/closure_library/closure/goog/base.js
--js=external/closure_library/closure/goog/a11y/aria/announcer.js
...
```
The code in question is:
``` javascript
/**
* Creates an iterator that returns combinations of elements from
* {@code iterable}.
*
* Combinations are obtained by taking the {@see goog.iter#permutations} of
* {@code iterable} and filtering those whose elements appear in the order they
* are encountered in {@code iterable}. For example, the 3-length combinations
* of {@code [0,1,2,3]} are {@code [[0,1,2], [0,1,3], [0,2,3], [1,2,3]]}.
* @see http://docs.python.org/2/library/itertools.html#itertools.combinations
* @param {!goog.iter.Iterator|!goog.iter.Iterable} iterable The
* iterable from which to generate combinations.
* @param {number} length The length of each combination.
* @return {!goog.iter.Iterator>} A new iterator containing
* combinations from the {@code iterable}.
* @template VALUE
*/
goog.iter.combinations = function(iterable, length) {
var elements = goog.iter.toArray(iterable);
var indexes = goog.iter.range(elements.length);
var indexIterator = goog.iter.permutations(indexes, length);
// sortedIndexIterator will now give arrays of with the given length that
// indicate what indexes into "elements" should be returned on each iteration.
var sortedIndexIterator = goog.iter.filter(
indexIterator, function(arr) { return goog.array.isSorted(arr); });
var iter = new goog.iter.Iterator();
function getIndexFromElements(index) { return elements[index]; }
iter.next = function() {
return goog.array.map(sortedIndexIterator.next(), getIndexFromElements);
};
return iter;
};
```
Contributor guide
Assessment
This issue has not been assessed yet.