@@ -53,61 +53,7 @@ function ErrorRep(props) {
5353 }
5454
5555 if ( preview . stack && props . mode !== MODE . TINY ) {
56- content . push ( "\n" ) ;
57-
58- /**
59- * Transform the stack from:
60- *
61- * semicolon@debugger eval code:1:109
62- * jkl@debugger eval code:1:63
63- * asdf@debugger eval code:1:28
64- * @debugger eval code:1:227
65- *
66- * Into a column layout:
67- *
68- * semicolon (<anonymous>:8:10)
69- * jkl (<anonymous>:5:10)
70- * asdf (<anonymous>:2:10)
71- * (<anonymous>:11:1)
72- */
73-
74- const stack = [ ] ;
75- preview . stack
76- . split ( "\n" )
77- . forEach ( ( line , index ) => {
78- if ( ! line ) {
79- // Skip any blank lines
80- return ;
81- }
82- const result = line . match ( / ^ ( .* ) @ ( .* ) $ / ) ;
83- let functionName ;
84- let location ;
85- if ( ! result || result . length !== 3 ) {
86- // This line did not match up nicely with the "function@location" pattern for
87- // some reason.
88- functionName = line ;
89- } else {
90- functionName = result [ 1 ] ;
91- location = ` (${ result [ 2 ] } )` ;
92- }
93- stack . push (
94- span (
95- { key : "fn" + index , className : "objectBox-stackTrace-fn" } ,
96- functionName
97- ) ) ;
98- stack . push (
99- span (
100- { key : "location" + index , className : "objectBox-stackTrace-location" } ,
101- location
102- ) ) ;
103- } ) ;
104-
105- content . push (
106- span (
107- { key : "stack" , className : "objectBox-stackTrace-grid" } ,
108- stack
109- )
110- ) ;
56+ content . push ( "\n" , getStacktraceElements ( preview ) ) ;
11157 }
11258
11359 return span ( {
@@ -116,6 +62,62 @@ function ErrorRep(props) {
11662 } , content ) ;
11763}
11864
65+ /**
66+ * Returns a React element reprensenting the Error stacktrace, i.e. transform error.stack
67+ * from:
68+ *
69+ * semicolon@debugger eval code:1:109
70+ * jkl@debugger eval code:1:63
71+ * asdf@debugger eval code:1:28
72+ * @debugger eval code:1:227
73+ *
74+ * Into a column layout:
75+ *
76+ * semicolon (<anonymous>:8:10)
77+ * jkl (<anonymous>:5:10)
78+ * asdf (<anonymous>:2:10)
79+ * (<anonymous>:11:1)
80+ */
81+ function getStacktraceElements ( preview ) {
82+ const stack = [ ] ;
83+ preview . stack
84+ . split ( "\n" )
85+ . forEach ( ( line , index ) => {
86+ if ( ! line ) {
87+ // Skip any blank lines
88+ return ;
89+ }
90+
91+ const result = line . match ( / ^ ( .* ) @ ( .* ) $ / ) ;
92+ let functionName ;
93+ let location ;
94+ if ( ! result || result . length !== 3 ) {
95+ // This line did not match up nicely with the "function@location" pattern for
96+ // some reason.
97+ functionName = line ;
98+ } else {
99+ functionName = result [ 1 ] ;
100+ location = ` (${ result [ 2 ] } )` ;
101+ }
102+
103+ stack . push (
104+ span ( {
105+ key : "fn" + index ,
106+ className : "objectBox-stackTrace-fn"
107+ } , functionName ) ,
108+ span ( {
109+ key : "location" + index ,
110+ className : "objectBox-stackTrace-location"
111+ } , location )
112+ ) ;
113+ } ) ;
114+
115+ return span ( {
116+ key : "stack" ,
117+ className : "objectBox-stackTrace-grid"
118+ } , stack ) ;
119+ }
120+
119121// Registration
120122function supportsObject ( object , noGrip = false ) {
121123 if ( noGrip === true || ! isGrip ( object ) ) {
0 commit comments