Open marcelaraujo opened 9 years ago
That compiles to an infinite loop:
- var n = 0
ul
while n < 20
= n++
is approximately like writing:
buf.push('<ul>');
while (n < 20) {
}
buf.push(n++);
buf.push('</ul>');
You need to indent the code within the while
statement:
- var n = 0
ul
while n < 20
= n++
This error is unfortunately impossible to statically detect in the most general case (it requires solving the halting problem). We could, however, do one of two things that would perhaps produce useful results:
while
block, at least if the condition is side effect freestart time
when rendering templates, then check current time - start time
inside any loops (for
, while
, do {...} while
etc.) so we could time out after something like 10 seconds.The first might be possible to make a non-breaking change, but it is very limited. The second option is a definite breaking change, and it makes for very slow feedback.
Owwww
Is this an old known issue?
Hummmm.. I don't think that any of given solutions would be the best choice because we don't know how long the Jade will take to complete the compile process.
Is there not any regular expression could catch this case?
This isn't an issue, the code is just misindented.
@marcelaraujo This is a known issue with all turing complete languages. Look up "The Halting Problem". It is one of the most famous computer science problems there is. It cannot be caught with a regular expression.
It would of course be possible to catch the specific case you illustrated (as I suggested in option 1) but it is not possible in the most general case. Consider the following example JavaScript program:
function foo() {
return true;
}
var i = 0;
while (i % 2 === 0) {
i++;
if (foo()) i++;
}
As a human I can prove that that program never terminates. It gets stuck in an infinite loop. The only way to know that for a computer though, is to execute the program. We may sometimes be able to do clever tricks to spot cases where it will never finish, but it is not possible in all cases.
We can apply https://github.com/ForbesLindesay/halting-problem to loops, which will catch a lot of the most common of these cases.
Hey, I found this bug when I have this template
FATAL ERROR: JS Allocation failed - process out of memory
https://gist.github.com/marcelaraujo/e4b35cb90a15699a5f8a