11import Component from "@glimmer/component" ;
2- import { inject as service } from '@ember/service' ;
3- import { tracked } from '@glimmer/tracking' ;
4- import { action } from '@ember/object' ;
2+ import { inject as service } from "@ember/service" ;
3+ import { tracked } from "@glimmer/tracking" ;
4+ import { action } from "@ember/object" ;
5+ import type RouterService from "@ember/routing/router-service" ;
56
67import gql from "graphql-tag" ;
8+ // @ts -ignore
79import { queryManager } from "ember-apollo-client" ;
810
11+ type Args = {
12+ instantiationStack : string ;
13+ } ;
14+
915const query = gql `
1016 query query($filePath: String!) {
1117 file(filePath: $filePath) {
@@ -14,65 +20,81 @@ const query = gql`
1420 }
1521` ;
1622
17- export default class InstantiationStackExplorer extends Component {
18- @service router ;
23+ export default class InstantiationStackExplorer extends Component < Args > {
24+ @service
25+ declare router : RouterService ;
26+ // @ts -ignore
1927 @queryManager apollo ;
2028
2129 @tracked selectedIndex = null ;
2230 @tracked loading = false ;
23- @tracked file = null ;
24- @tracked line = null ;
25- @tracked column = null ;
26- @tracked filePath = null ;
31+ @tracked file : string | null = null ;
32+ @tracked line : number | null = null ;
33+ @tracked column : number | null = null ;
34+ @tracked filePath : string | null = null ;
2735
2836 get instantiationStack ( ) {
2937 const fileReg = / a t ( .+ ?) \( ( \/ + .* ) : ( .+ ?) : ( .+ ?) ( \) | $ ) / m;
3038
31- const { instantiationStack } = this . args
39+ const { instantiationStack } = this . args ;
3240
33- return instantiationStack . split ( '\n' ) . map ( ( stackLine ) => {
34- if ( fileReg . exec ( stackLine ) !== null ) {
41+ return instantiationStack . split ( "\n" ) . map ( ( stackLine ) => {
42+ if ( fileReg . exec ( stackLine ) !== null ) {
3543 const match = fileReg . exec ( stackLine ) ;
3644
37- return {
38- stackLine : `at ${ match [ 1 ] } ` ,
39- filePath : match [ 2 ] ,
40- line : match [ 3 ] ,
41- column : match [ 4 ]
45+ if ( match ) {
46+ return {
47+ stackLine : `at ${ match [ 1 ] } ` ,
48+ filePath : match [ 2 ] ,
49+ line : match [ 3 ] ,
50+ column : match [ 4 ] ,
51+ } ;
4252 }
4353 }
4454
45- if ( / a t ( \/ + .* ) : ( .+ ?) : ( .+ ?) $ / m. exec ( stackLine ) !== null ) {
55+ if ( / a t ( \/ + .* ) : ( .+ ?) : ( .+ ?) $ / m. exec ( stackLine ) !== null ) {
4656 const match = / a t ( \/ + .* ) : ( .+ ?) : ( .+ ?) $ / gm. exec ( stackLine ) ;
4757
48- return {
49- stackLine : `at ${ match [ 1 ] } ` ,
50- filePath : match [ 1 ] ,
51- line : match [ 2 ] ,
52- column : match [ 3 ]
58+ if ( match ) {
59+ return {
60+ stackLine : `at ${ match [ 1 ] } ` ,
61+ filePath : match [ 1 ] ,
62+ line : match [ 2 ] ,
63+ column : match [ 3 ] ,
64+ } ;
5365 }
5466 }
5567
5668 return {
57- stackLine
58- }
69+ stackLine,
70+ } ;
5971 } ) ;
6072 }
6173
6274 @action
63- onStackClick ( filePath , line , column ) {
75+ onStackClick ( filePath : string , line : number , column : number ) {
6476 this . loading = true ;
6577
66- return this . apollo . query ( { query, variables : { filePath } } , "file" ) . then ( ( result ) => {
67- this . file = result . value ;
68- this . line = line ;
69- this . column = column ;
70- this . filePath = filePath ;
71- this . loading = false ;
78+ return this . apollo
79+ . query ( { query, variables : { filePath } } , "file" )
80+ . then ( ( result : any ) => {
81+ this . file = result . value ;
82+ this . line = line ;
83+ this . column = column ;
84+ this . filePath = filePath ;
85+ this . loading = false ;
7286
73- setTimeout ( function ( ) {
74- document . querySelector ( '.code-block' ) . scroll ( 0 , parseInt ( document . querySelector ( '.line-highlight' ) . style . top . replace ( 'px' , '' ) ) )
75- } , 200 )
76- } ) ;
87+ setTimeout ( function ( ) {
88+ document ?. querySelector ( ".code-block" ) ?. scroll (
89+ 0 ,
90+ parseInt (
91+ document
92+ ?. querySelector ( ".line-highlight" )
93+ // @ts -ignore
94+ ?. style . top . replace ( "px" , "" )
95+ )
96+ ) ;
97+ } , 200 ) ;
98+ } ) ;
7799 }
78100}
0 commit comments