mishoo/UglifyJS — Issue #261: recursion call is broken when the inline code has some label named same as.
Author: allex
Created: 2011-11-27 11:48:47+00:00
State: open

it's should be a bug,

please see details of the function `a` which has a label named 'a', also the function conditionally called with recursion.

when compiler these codes with uglifyjs, it's broken. for details see the second paragraph comments.

sorry for my poor english, if still has some questions, please mail to allex.wxn@gmail.com,

thanks.

// source code:
// > a.js
function a(list) {
for (var result = [], i = -1, item; item = list[++i]; ) {
if ("string" === typeof item) {

// define a label named `a`,
// NOTE: the label name `a` is same with function name
a : {
var list = nodeList, len = list.length, entity = null;
if (0 < len) {
do if (entity = list[--len], item.match(entity[0])) {
item = entity[1](item);
break a;
} while (len);
}
item = null;
}

} else if (isArray(list)) {
// recursion call this function `a`.
item = new SomeClass(a(item));
}

item && result.push(item);
}
return result;
}

// uglifyjs code:
// > uglifyjs -nc a.js
function a(a) {
for (var b = [], c = -1, d; d = a[++c]; ) {
if ("string" == typeof d) e : { // label name has been renamed to `a` -> `e`
var a = nodeList, f = a.length, g = null;
if (0 < f) do if (g = a[--f], d.match(g[0])) {
d = g[1](d);
break e;
} while (f);
d = null;
} else isArray(a) && (d = new SomeClass(e(d))); // this line is parsed unexpected, the recursion call `a` is broken to the label name `e`.
d && b.push(d);
}
return b;
};