Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9099664

Browse filesBrowse files
not-an-aardvarkaddaleax
authored andcommitted
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: #9852 Fixes: #9850 Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent c286312 commit 9099664
Copy full SHA for 9099664

File tree

Expand file treeCollapse file tree

2 files changed

+17
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-2
lines changed
Open diff view settings
Collapse file

‎lib/repl.js‎

Copy file name to clipboardExpand all lines: lib/repl.js
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,10 @@ function REPLServer(prompt,
576576
self.wrappedCmd = true;
577577
} else {
578578
// Mitigate https://github.com/nodejs/node/issues/548
579-
cmd = cmd.replace(/^\s*function\s+([^(]+)/,
580-
(_, name) => `var ${name} = function ${name}`);
579+
cmd = cmd.replace(
580+
/^\s*function(?:\s*(\*)\s*|\s+)([^(]+)/,
581+
(_, genStar, name) => `var ${name} = function ${genStar || ''}${name}`
582+
);
581583
}
582584
// Append a \n so that it will be either
583585
// terminated, or continued onto the next expression if it's an
Collapse file

‎test/parallel/test-repl.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl.js
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,19 @@ function error_test() {
339339
// Avoid emitting stack trace
340340
{ client: client_unix, send: 'a = 3.5e',
341341
expect: /^(?!\s+at\s)/gm },
342+
343+
// https://github.com/nodejs/node/issues/9850
344+
{ client: client_unix, send: 'function* foo() {}; foo().next();',
345+
expect: '{ value: undefined, done: true }' },
346+
347+
{ client: client_unix, send: 'function *foo() {}; foo().next();',
348+
expect: '{ value: undefined, done: true }' },
349+
350+
{ client: client_unix, send: 'function*foo() {}; foo().next();',
351+
expect: '{ value: undefined, done: true }' },
352+
353+
{ client: client_unix, send: 'function * foo() {}; foo().next()',
354+
expect: '{ value: undefined, done: true }' },
342355
]);
343356
}
344357

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.