Skip to content

Commit

Permalink
Support framework frames for Preact (firefox-devtools#4296)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomer Ohana authored and Johnny Khalil committed Oct 13, 2017
1 parent d3243f0 commit 764ebb8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions assets/images/Svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const svg = {
pause: require("./pause.svg"),
"pause-exceptions": require("./pause-exceptions.svg"),
plus: require("./plus.svg"),
preact: require("./preact.svg"),
prettyPrint: require("./prettyPrint.svg"),
react: require("./react.svg"),
"regex-match": require("./regex-match.svg"),
Expand Down
9 changes: 9 additions & 0 deletions assets/images/preact.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/utils/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ function isDojo(frame) {
return getFrameUrl(frame).match(/dojo/i);
}

function isPreact(frame) {
return getFrameUrl(frame).match(/preact/i);
}

export function getLibraryFromUrl(frame: Frame) {
// @TODO each of these fns calls getFrameUrl, just call it once
// (assuming there's not more complex logic to identify a lib)
Expand All @@ -95,6 +99,11 @@ export function getLibraryFromUrl(frame: Frame) {
return "jQuery";
}

// Needs to remain before "react", otherwise "react" can also match "preact"
if (isPreact(frame)) {
return "Preact";
}

if (isReact(frame)) {
return "React";
}
Expand Down
21 changes: 20 additions & 1 deletion src/utils/tests/frame.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import {
simplifyDisplayName,
formatDisplayName,
formatCopyName
formatCopyName,
getLibraryFromUrl
} from "../frame";

const cases = {
Expand Down Expand Up @@ -99,4 +100,22 @@ describe("function names", () => {
expect(formatCopyName(frame)).toEqual("child (todo-view.js#12)");
});
});

describe("getLibraryFromUrl", () => {
describe("When Preact is on the frame", () => {
it("should return Preact and not React", () => {
const frame = {
displayName: "name",
location: {
line: 12
},
source: {
url: "https://cdnjs.cloudflare.com/ajax/libs/preact/8.2.5/preact.js"
}
};

expect(getLibraryFromUrl(frame)).toEqual("Preact");
});
});
});
});

0 comments on commit 764ebb8

Please sign in to comment.