repl: fix generator function preprocessing
Function declarations in the REPL are preprocessed into variable declarations before being evaluated. However, the preprocessing logic did not account for the star in a generator function declaration, which caused the preprocessor to output invalid syntax in some circumstances. PR-URL: https://github.com/nodejs/node/pull/9852 Fixes: https://github.com/nodejs/node/issues/9850 Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
parent
b49b496a92
commit
24a98dd810
@ -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
|
||||
|
@ -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 }' },
|
||||
]);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user