Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comprehensive function name lookup #1010

Merged
merged 3 commits into from
Nov 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core-js/modules/es.function.name.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var defineProperty = require('../internals/object-define-property').f;

var FunctionPrototype = Function.prototype;
var functionToString = uncurryThis(FunctionPrototype.toString);
var nameRE = /^\s*function ([^ (]*)/;
var nameRE = /function\b(?:\s|\/\*[\S\s]*?\*\/|\/\/[^\n\r]*[\n\r]+)*([^\s(/]*)/;
var regExpExec = uncurryThis(nameRE.exec);
var NAME = 'name';

Expand Down
18 changes: 18 additions & 0 deletions tests/tests/es.function.name.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,23 @@ if (DESCRIPTORS) {
return '';
};
assert.same(baz.name, '');

assert.same(function /*
multi-line comment */() { /* empty */ }.name, '');

function /*
multi-line comment */
foobar() { /* empty */ }
assert.same(foobar.name, 'foobar');

function // simple-line comment
foobaz() { /* empty */ }
assert.same(foobaz.name, 'foobaz');

function // simple-line comment
/* multi-line comment */quux/*
multi-line comment
*/() { /* empty */ }
assert.same(quux.name, 'quux');
});
}