Skip to content

ref(utils): reorder regexpa and add tests #7505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 20, 2023
Merged

Conversation

JonasBa
Copy link
Member

@JonasBa JonasBa commented Mar 17, 2023

Reorder the regexp so that we prioritize the one more likely to match. Also adds tests and covered an edge case where input like 'at myFunction (/path/to/file.js)'; would have undefined paths.

I have generated the tests with the help of chatgpt and manually checked all of them - it got a few of them wrong or was testing impossible cases, but it did find that one edge case apparently

Comment on lines +130 to +176
if (lineMatch) {
let object: string | undefined;
let method: string | undefined;
let functionName: string | undefined;
let typeName: string | undefined;
let methodName: string | undefined;

if (lineMatch[1]) {
functionName = lineMatch[1];
if (lineMatch[1]) {
functionName = lineMatch[1];

let methodStart = functionName.lastIndexOf('.');
if (functionName[methodStart - 1] === '.') {
methodStart--;
}
let methodStart = functionName.lastIndexOf('.');
if (functionName[methodStart - 1] === '.') {
methodStart--;
}

if (methodStart > 0) {
object = functionName.slice(0, methodStart);
method = functionName.slice(methodStart + 1);
const objectEnd = object.indexOf('.Module');
if (objectEnd > 0) {
functionName = functionName.slice(objectEnd + 1);
object = object.slice(0, objectEnd);
if (methodStart > 0) {
object = functionName.slice(0, methodStart);
method = functionName.slice(methodStart + 1);
const objectEnd = object.indexOf('.Module');
if (objectEnd > 0) {
functionName = functionName.slice(objectEnd + 1);
object = object.slice(0, objectEnd);
}
}
typeName = undefined;
}
typeName = undefined;
}

if (method) {
typeName = object;
methodName = method;
}
if (method) {
typeName = object;
methodName = method;
}

if (method === '<anonymous>') {
methodName = undefined;
functionName = undefined;
}

if (method === '<anonymous>') {
methodName = undefined;
functionName = undefined;
if (functionName === undefined) {
methodName = methodName || '<anonymous>';
functionName = typeName ? `${typeName}.${methodName}` : methodName;
}

let filename = lineMatch[2] && lineMatch[2].startsWith('file://') ? lineMatch[2].slice(7) : lineMatch[2];
const isNative = lineMatch[5] === 'native';

if (!filename && lineMatch[5] && !isNative) {
filename = lineMatch[5];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an indentation change and order of operations is different - we first run the FULL_MATCH regexp which we expect to match most often and then the fallback

@AbhiPrasad AbhiPrasad merged commit b6f03bf into develop Mar 20, 2023
@AbhiPrasad AbhiPrasad deleted the jb/ref/stacktrace branch March 20, 2023 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants