[CS2] Don’t require async/await support to run coffee (#4679)

* Get `coffee` command working again in Node 6, by converting the ‘await’ wrapper in the REPL to use a Promise instead of the ‘await’ keyword; add tests for REPL ‘await’ wrapper, including test to skip async tests if the runtime doesn’t support them

* Code review

* Let's support Node 6+ if we can
This commit is contained in:
Geoffrey Booth
2017-09-01 12:19:15 -07:00
committed by GitHub
parent 4a4f752204
commit 671486989f
5 changed files with 30 additions and 9 deletions

View File

@@ -26,7 +26,7 @@
}
})(),
historyMaxInputSize: 10240,
eval: async function(input, context, filename, cb) {
eval: function(input, context, filename, cb) {
var Assign, Block, Call, Code, Literal, Value, ast, err, isAsync, js, referencedVars, result, token, tokens;
// XXX: multiline hack.
input = input.replace(/\uFF00/g, '\n');
@@ -71,10 +71,11 @@
result = runInContext(js, context, filename);
// Await an async result, if necessary
if (isAsync) {
result = (await result);
if (!sawSIGINT) {
cb(null, result);
}
result.then(function(resolvedResult) {
if (!sawSIGINT) {
return cb(null, resolvedResult);
}
});
return sawSIGINT = false;
} else {
return cb(null, result);