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

Function name regex can get incorrect name for annoymous function #6

Copy link
Copy link
@bengourley

Description

@bengourley
Issue body actions

Given the function source:

function () {
  // set the script that called this function
  updateLastScript(script)
  // immediately unset it
  _setTimeout(function () { updateLastScript(null) }, 0)
  cb.apply(this, arguments)
}

this Regex will incorrectly name the function updateLastScript which is an unfortunate sequence of a comment ending in function followed by a function call.

if (/function(?:\s+([\w$]+))+\s*\(/.test(curr.toString())) {

a nested function definition can also trip it up:

function () {
  function jim() {
    // inner
  }
  more()
  statements()
}

The following update fixes these scenarios, correctly returning null for these two annonymous functions:

- if (/function(?:\s+([\w$]+))+\s*\(/.test(curr.toString())) { 
+ if (/^\s*function(?:\s+([\w$]+))+\s*\(/.test(curr.toString())) { 

I'm not sure if the "any preceding whitespace" part is strictly necessary but I don't think it hurts to permit that.

I can put together a PR for this including tests but I wanted to post it up as an issue before I get around to that while I work around it.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

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