Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 9bc5f56

Browse files
Tomer OhanajasonLaster
authored andcommitted
Support framework frames for Preact (#4296)
1 parent be8c5ed commit 9bc5f56

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

‎assets/images/Svg.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const svg = {
2828
pause: require("./pause.svg"),
2929
"pause-exceptions": require("./pause-exceptions.svg"),
3030
plus: require("./plus.svg"),
31+
preact: require("./preact.svg"),
3132
prettyPrint: require("./prettyPrint.svg"),
3233
react: require("./react.svg"),
3334
"regex-match": require("./regex-match.svg"),

‎assets/images/preact.svg‎

Lines changed: 9 additions & 0 deletions
Loading

‎src/utils/frame.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ function isDojo(frame) {
8383
return getFrameUrl(frame).match(/dojo/i);
8484
}
8585

86+
function isPreact(frame) {
87+
return getFrameUrl(frame).match(/preact/i);
88+
}
89+
8690
export function getLibraryFromUrl(frame: Frame) {
8791
// @TODO each of these fns calls getFrameUrl, just call it once
8892
// (assuming there's not more complex logic to identify a lib)
@@ -95,6 +99,11 @@ export function getLibraryFromUrl(frame: Frame) {
9599
return "jQuery";
96100
}
97101

102+
// Needs to remain before "react", otherwise "react" can also match "preact"
103+
if (isPreact(frame)) {
104+
return "Preact";
105+
}
106+
98107
if (isReact(frame)) {
99108
return "React";
100109
}

‎src/utils/tests/frame.spec.js‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import {
44
simplifyDisplayName,
55
formatDisplayName,
6-
formatCopyName
6+
formatCopyName,
7+
getLibraryFromUrl
78
} from "../frame";
89

910
const cases = {
@@ -99,4 +100,22 @@ describe("function names", () => {
99100
expect(formatCopyName(frame)).toEqual("child (todo-view.js#12)");
100101
});
101102
});
103+
104+
describe("getLibraryFromUrl", () => {
105+
describe("When Preact is on the frame", () => {
106+
it("should return Preact and not React", () => {
107+
const frame = {
108+
displayName: "name",
109+
location: {
110+
line: 12
111+
},
112+
source: {
113+
url: "https://cdnjs.cloudflare.com/ajax/libs/preact/8.2.5/preact.js"
114+
}
115+
};
116+
117+
expect(getLibraryFromUrl(frame)).toEqual("Preact");
118+
});
119+
});
120+
});
102121
});

0 commit comments

Comments
 (0)