popcode
popcode copied to clipboard
Handle multi-line statements in the console
If a student types the following into the console and presses Enter:
if (name === "Pop") {
The console should recognize that it is an incomplete statement, and allow the student to keep typing (with an expanded input area to accommodate the new line).
This seems hard—how do we distinguish between an incomplete multiline statement and a statement that is syntactically invalid for some other reason? Perhaps Esprima or one of our other linters/parsers throws a specific “unexpected end of input” type error that we can rely on.
Interesting that after typing if (name === "Pop") {
and pressing Enter
, it outputs SyntaxError: unexpected end of input
but then next input line is indented.
@alecmerdler yep although not super-surprising—the indentation behavior is almost certainly coming from built-in ACE formatting rules (which are sadly hit-or-miss in the broad scheme of things)
At minimum we should also support Shift+Enter
for entering newlines. Although this seems unnecessary since you have a full JS editor right there...
Yo this would be a sweet feature. Chrome console does this really well and it's open source so theoretically this could use a similar implementation.