This repository was archived by the owner on Jan 11, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +39
-1
lines changed
Expand file tree Collapse file tree 4 files changed +39
-1
lines changed Original file line number Diff line number Diff 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" ) ,
Original file line number Diff line number Diff line change @@ -83,6 +83,10 @@ function isDojo(frame) {
8383 return getFrameUrl ( frame ) . match ( / d o j o / i) ;
8484}
8585
86+ function isPreact ( frame ) {
87+ return getFrameUrl ( frame ) . match ( / p r e a c t / i) ;
88+ }
89+
8690export 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 }
Original file line number Diff line number Diff line change 33import {
44 simplifyDisplayName ,
55 formatDisplayName ,
6- formatCopyName
6+ formatCopyName ,
7+ getLibraryFromUrl
78} from "../frame" ;
89
910const 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} ) ;
You can’t perform that action at this time.
0 commit comments