Skip to content

Commit 410a645

Browse files
Fix findFunctionName regex sometimes matching if constructs
1 parent 3d05526 commit 410a645

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

spec/stacktrace-gps-spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,18 @@ describe('StackTraceGPS', function() {
198198
}
199199
});
200200

201+
it('ignores special case involving class functions', function(done) {
202+
var source = 'if (a) { foo(); } else if (b) { bar(); }';
203+
jasmine.Ajax.stubRequest('http://localhost:9999/file.js').andReturn({responseText: source});
204+
var originalStackFrame = new StackFrame({functionName: '@test@', args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 1, columnNumber: 0});
205+
new StackTraceGPS().findFunctionName(originalStackFrame).then(callback, done.fail);
206+
207+
function callback(stackframe) {
208+
expect(stackframe).toEqual(originalStackFrame);
209+
done();
210+
}
211+
});
212+
201213
it('ignores commented out function definitions', function(done) {
202214
var source = 'var foo = function() {};\n//function bar() {}\nvar baz = eval("XXX")';
203215
jasmine.Ajax.stubRequest('http://localhost:9999/file.js').andReturn({responseText: source});

stacktrace-gps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
// {name} = eval()
7272
/['"]?([$_A-Za-z][$_A-Za-z0-9]*)['"]?\s*[:=]\s*(?:eval|new Function)\b/,
7373
// fn_name() {
74-
/\b(?!(?:if|for|switch|while|with|catch)\b)(?:(?:static)\s+)?(\S+)\s*\(.*?\)\s*\{/,
74+
/\b(?!(?:if|for|switch|while|with|catch)\b)(?:(?:static)\s+)?(\S+)\s*\([^)]*\)\s*\{/,
7575
// {name} = () => {
7676
/['"]?([$_A-Za-z][$_A-Za-z0-9]*)['"]?\s*[:=]\s*\(.*?\)\s*=>/
7777
];

0 commit comments

Comments
 (0)