Skip to content

Doesn't handle embedded comments #1

@chocolateboy

Description

@chocolateboy

There are several issues with the regex:

  • It doesn't handle embedded comments
  • It considers functionfoo () { } to be a valid function declaration
  • Nit: \{([\w\W\s\S]*)\} is a roundabout way of saying \{(.*)\} (though I'd go with \{(.*?)\})

test

var re = require('function-regex')();

function /* 1 */ test /* 2 */ (/* 3 */ foo /* 4 */ ) /* 5 */ {
    return foo;
}

var match1 = re.exec(test.toString());
var match2 = re.exec('functionfoo(){}');

console.log("should match:", match1); // should match but doesn't
console.log("shouldn't match:", match2); // shouldn't match but does

output:

should match: null
shouldn't match: [ 'functionfoo(){}',
  'foo',
  '',
  '',
  index: 0,
  input: 'functionfoo(){}' ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions