44
55// @flow
66
7- import { findBestMatchExpression } from "../utils/ast" ;
7+ import { findBestMatchExpression , findClosestClass } from "../utils/ast" ;
88import { getTokenLocation } from "../utils/editor" ;
99import { isReactComponent , isImmutable , isConsole } from "../utils/preview" ;
1010import { isGeneratedId } from "devtools-source-map" ;
@@ -17,7 +17,8 @@ import {
1717 getSelectedSource ,
1818 getSelectedFrame ,
1919 getSymbols ,
20- getCanRewind
20+ getCanRewind ,
21+ getSource
2122} from "../selectors" ;
2223
2324import { getMappedExpression } from "./expressions" ;
@@ -52,10 +53,24 @@ async function getImmutableProps(expression: string, evaluate) {
5253 } ;
5354}
5455
55- async function getExtraProps ( expression , result , evaluate ) {
56+ async function getExtraProps ( getState , expression , result , evaluate ) {
5657 const props = { } ;
5758 if ( isReactComponent ( result ) ) {
58- props . react = await getReactProps ( evaluate ) ;
59+ const selectedFrame = getSelectedFrame ( getState ( ) ) ;
60+ const source = getSource ( getState ( ) , selectedFrame . location . sourceId ) ;
61+ const symbols = getSymbols ( getState ( ) , source ) ;
62+
63+ if ( symbols && symbols . classes ) {
64+ const originalClass = findClosestClass ( symbols , selectedFrame . location ) ;
65+
66+ if ( originalClass ) {
67+ props . react = { displayName : originalClass . name } ;
68+ }
69+ }
70+
71+ if ( ! props . react ) {
72+ props . react = await getReactProps ( evaluate ) ;
73+ }
5974 }
6075
6176 if ( isImmutable ( result ) ) {
@@ -95,7 +110,7 @@ export function getExtra(
95110 selectedFrame : Frame
96111) {
97112 return async ( { dispatch, getState, client, sourceMaps } : ThunkArgs ) => {
98- const extra = await getExtraProps ( expression , result , expr =>
113+ const extra = await getExtraProps ( getState , expression , result , expr =>
99114 client . evaluateInFrame ( selectedFrame . id , expr )
100115 ) ;
101116
0 commit comments