1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Replace "instanceof Array" in transformer with "[object Array]" comparison

Testing with `'[object Array]' is Object::toString.call element` allows arrays from another JS context to be properly handled. The specific use case here is to support jest, which sets up JS contexts using Node/io.js's "vm" module. This approach works in ES3 environments in contrast with ES5's `Array.isArray`.
This commit is contained in:
James Ide 2015-05-20 18:46:01 -07:00
parent 769f02ec05
commit 2087923163
2 changed files with 2 additions and 2 deletions

View file

@ -67,7 +67,7 @@
flattened = [];
for (i = 0, len1 = array.length; i < len1; i++) {
element = array[i];
if (element instanceof Array) {
if ('[object Array]' === Object.prototype.toString.call(element)) {
flattened = flattened.concat(flatten(element));
} else {
flattened.push(element);

View file

@ -49,7 +49,7 @@ extend = exports.extend = (object, properties) ->
exports.flatten = flatten = (array) ->
flattened = []
for element in array
if element instanceof Array
if '[object Array]' is Object::toString.call element
flattened = flattened.concat flatten element
else
flattened.push element