Skip to content

Commit 9da2bc3

Browse files
Also fix matching against ifs on function name
1 parent 410a645 commit 9da2bc3

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

spec/stacktrace-gps-spec.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ describe('StackTraceGPS', function() {
198198
}
199199
});
200200

201-
it('ignores special case involving class functions', function(done) {
201+
it('ignores special case interpreting control structures as the function parameter list', function(done) {
202202
var source = 'if (a) { foo(); } else if (b) { bar(); }';
203203
jasmine.Ajax.stubRequest('http://localhost:9999/file.js').andReturn({responseText: source});
204204
var originalStackFrame = new StackFrame({functionName: '@test@', args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 1, columnNumber: 0});
@@ -210,6 +210,18 @@ describe('StackTraceGPS', function() {
210210
}
211211
});
212212

213+
it('ignores special case interpreting control structures as the function name', function(done) {
214+
var source = 'functionCall()\nif (condition) {';
215+
jasmine.Ajax.stubRequest('http://localhost:9999/file.js').andReturn({responseText: source});
216+
var originalStackFrame = new StackFrame({functionName: '@test@', args: [], fileName: 'http://localhost:9999/file.js', lineNumber: 2, columnNumber: 0});
217+
new StackTraceGPS().findFunctionName(originalStackFrame).then(callback, done.fail);
218+
219+
function callback(stackframe) {
220+
expect(stackframe).toEqual(originalStackFrame);
221+
done();
222+
}
223+
});
224+
213225
it('ignores commented out function definitions', function(done) {
214226
var source = 'var foo = function() {};\n//function bar() {}\nvar baz = eval("XXX")';
215227
jasmine.Ajax.stubRequest('http://localhost:9999/file.js').andReturn({responseText: source});

stacktrace-gps.js

+1-1
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)