-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
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
Labels
No labels