Garbage output when missing semi colon
Created by: davidson16807
I love the idea for sweet.js. I made a macro to help out some work I've been doing with scalar fields. Here is a live demo when its working.
However, I noticed sweet.js has some really weird behavior when you forget a semi-colon. When I forget the first semi-colon in the example above:
ScalarField.add_field = function(field1, field2, result) {
result = result || new Float32Array(field1.length)
tensor result[i] = field1[i] + field2[i];
return result;
};
It should output something like the following:
ScalarField.add_field = function (field1_3592, field2_3593, result_3594) {
result_3594 = result_3594 || new Float32Array(field1_3592.length);
for (var i = 0, li = result_3594.length; i < li; i++) {
result_3594[i] = field1_3592[i] + field2_3593[i];
}
return result_3594;
};
Instead, sweet.js outputs the following:
ScalarField.add_field = function (field1_104, field2_105, result_106) {
result_106 = result_106 || (result_106[i] = field1_104[i] + field2_105[i]);
return result_106;
};
new Float32Array()
is obliterated and now the output is nowhere close to making sense. It took me a long while to realize the semi-colon was at fault.
This makes me have serious misgivings about using sweet.js. I want to use sweet.js because I think it can eliminate the opportunity for bugs in a bunch of long winded code. But now, if I forget a single semi-colon, even one that javascript wouldn't need to produce correct output, it's going to silently generate garbage code and its going to be very hard to track down the problem.
There needs to be some way to handle missing semi-colons. This could be done through a warning, an error, or even a reimplementation of javascript's automatic semi-colon insertion, full or partial.