@@ -33,14 +33,15 @@ pub fn apply_source_map<G: SourceMapGetter>(
33
33
// prepareStackTrace().
34
34
let mut mappings_map: CachedMaps = HashMap :: new ( ) ;
35
35
36
- let ( script_resource_name, line_number, start_column) =
36
+ let ( script_resource_name, line_number, start_column, source_line ) =
37
37
get_maybe_orig_position (
38
38
js_error. script_resource_name . clone ( ) ,
39
39
js_error. line_number ,
40
40
// start_column is 0-based, we need 1-based here.
41
41
js_error. start_column . map ( |n| n + 1 ) ,
42
+ js_error. source_line . clone ( ) ,
42
43
& mut mappings_map,
43
- getter. clone ( ) ,
44
+ getter,
44
45
) ;
45
46
let start_column = start_column. map ( |n| n - 1 ) ;
46
47
// It is better to just move end_column to be the same distance away from
@@ -56,20 +57,6 @@ pub fn apply_source_map<G: SourceMapGetter>(
56
57
}
57
58
_ => None ,
58
59
} ;
59
- // if there is a source line that we might be different in the source file, we
60
- // will go fetch it from the getter
61
- let source_line = match line_number {
62
- Some ( ln)
63
- if js_error. source_line . is_some ( ) && script_resource_name. is_some ( ) =>
64
- {
65
- getter. get_source_line (
66
- & js_error. script_resource_name . clone ( ) . unwrap ( ) ,
67
- // Getter expects 0-based line numbers, but ours are 1-based.
68
- ln as usize - 1 ,
69
- )
70
- }
71
- _ => js_error. source_line . clone ( ) ,
72
- } ;
73
60
74
61
JsError {
75
62
message : js_error. message . clone ( ) ,
@@ -87,28 +74,43 @@ fn get_maybe_orig_position<G: SourceMapGetter>(
87
74
file_name : Option < String > ,
88
75
line_number : Option < i64 > ,
89
76
column_number : Option < i64 > ,
77
+ source_line : Option < String > ,
90
78
mappings_map : & mut CachedMaps ,
91
79
getter : Arc < G > ,
92
- ) -> ( Option < String > , Option < i64 > , Option < i64 > ) {
80
+ ) -> ( Option < String > , Option < i64 > , Option < i64 > , Option < String > ) {
93
81
match ( file_name, line_number, column_number) {
94
82
( Some ( file_name_v) , Some ( line_v) , Some ( column_v) ) => {
95
- let ( file_name, line_number, column_number) =
96
- get_orig_position ( file_name_v, line_v, column_v, mappings_map, getter) ;
97
- ( Some ( file_name) , Some ( line_number) , Some ( column_number) )
83
+ let ( file_name, line_number, column_number, source_line) =
84
+ get_orig_position (
85
+ file_name_v,
86
+ line_v,
87
+ column_v,
88
+ source_line,
89
+ mappings_map,
90
+ getter,
91
+ ) ;
92
+ (
93
+ Some ( file_name) ,
94
+ Some ( line_number) ,
95
+ Some ( column_number) ,
96
+ source_line,
97
+ )
98
98
}
99
- _ => ( None , None , None ) ,
99
+ _ => ( None , None , None , source_line ) ,
100
100
}
101
101
}
102
102
103
103
pub fn get_orig_position < G : SourceMapGetter > (
104
104
file_name : String ,
105
105
line_number : i64 ,
106
106
column_number : i64 ,
107
+ source_line : Option < String > ,
107
108
mappings_map : & mut CachedMaps ,
108
109
getter : Arc < G > ,
109
- ) -> ( String , i64 , i64 ) {
110
- let maybe_source_map = get_mappings ( & file_name, mappings_map, getter) ;
111
- let default_pos = ( file_name, line_number, column_number) ;
110
+ ) -> ( String , i64 , i64 , Option < String > ) {
111
+ let maybe_source_map = get_mappings ( & file_name, mappings_map, getter. clone ( ) ) ;
112
+ let default_pos =
113
+ ( file_name, line_number, column_number, source_line. clone ( ) ) ;
112
114
113
115
// Lookup expects 0-based line and column numbers, but ours are 1-based.
114
116
let line_number = line_number - 1 ;
@@ -121,11 +123,33 @@ pub fn get_orig_position<G: SourceMapGetter>(
121
123
None => default_pos,
122
124
Some ( token) => match token. get_source ( ) {
123
125
None => default_pos,
124
- Some ( original) => (
125
- original. to_string ( ) ,
126
- i64:: from ( token. get_src_line ( ) ) + 1 ,
127
- i64:: from ( token. get_src_col ( ) ) + 1 ,
128
- ) ,
126
+ Some ( original) => {
127
+ let maybe_source_line =
128
+ if let Some ( source_view) = token. get_source_view ( ) {
129
+ source_view. get_line ( token. get_src_line ( ) )
130
+ } else {
131
+ None
132
+ } ;
133
+
134
+ let source_line = if let Some ( source_line) = maybe_source_line {
135
+ Some ( source_line. to_string ( ) )
136
+ } else if let Some ( source_line) = getter. get_source_line (
137
+ original,
138
+ // Getter expects 0-based line numbers, but ours are 1-based.
139
+ token. get_src_line ( ) as usize ,
140
+ ) {
141
+ Some ( source_line)
142
+ } else {
143
+ source_line
144
+ } ;
145
+
146
+ (
147
+ original. to_string ( ) ,
148
+ i64:: from ( token. get_src_line ( ) ) + 1 ,
149
+ i64:: from ( token. get_src_col ( ) ) + 1 ,
150
+ source_line,
151
+ )
152
+ }
129
153
} ,
130
154
}
131
155
}
0 commit comments