diff --git a/lib/repl.js b/lib/repl.js index fe30bdd57b5e53..8bddfb5e3a8ee0 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -569,8 +569,10 @@ function REPLServer(prompt, self.wrappedCmd = true; } else { // Mitigate https://github.com/nodejs/node/issues/548 - cmd = cmd.replace(/^\s*function\s+([^(]+)/, - (_, name) => `var ${name} = function ${name}`); + cmd = cmd.replace( + /^\s*function(?:\s*(\*)\s*|\s+)([^(]+)/, + (_, genStar, name) => `var ${name} = function ${genStar || ''}${name}` + ); } // Append a \n so that it will be either // terminated, or continued onto the next expression if it's an diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 29c85e36076dbd..fd540e77c58366 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -339,6 +339,19 @@ function error_test() { // Avoid emitting stack trace { client: client_unix, send: 'a = 3.5e', expect: /^(?!\s+at\s)/gm }, + + // https://github.com/nodejs/node/issues/9850 + { client: client_unix, send: 'function* foo() {}; foo().next();', + expect: '{ value: undefined, done: true }' }, + + { client: client_unix, send: 'function *foo() {}; foo().next();', + expect: '{ value: undefined, done: true }' }, + + { client: client_unix, send: 'function*foo() {}; foo().next();', + expect: '{ value: undefined, done: true }' }, + + { client: client_unix, send: 'function * foo() {}; foo().next()', + expect: '{ value: undefined, done: true }' }, ]); }