diff --git a/lib/repl.js b/lib/repl.js index 2a101e9a171fd9..82c3b77a0f8243 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -576,8 +576,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 5564e670c8d934..4342910d5dac03 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 }' }, ]); }