@@ -193,21 +193,20 @@ function compile_code(text, compiler, processor_options) {
193
193
let ts_result ;
194
194
if ( processor_options . typescript ) {
195
195
const diffs = [ ] ;
196
+ let accumulated_diff = 0 ;
196
197
const transpiled = text . replace ( / < s c r i p t ( \s [ ^ ] * ?) ? > ( [ ^ ] * ?) < \/ s c r i p t > / gi, ( match , attributes = '' , content ) => {
197
198
const output = processor_options . typescript . transpileModule (
198
199
content ,
199
200
{ reportDiagnostics : false , compilerOptions : { target : processor_options . typescript . ScriptTarget . ESNext , sourceMap : true } }
200
201
) ;
201
- const prev_diff = diffs . length ? diffs [ diffs . length - 1 ] . accumulated_diff : 0 ;
202
202
const original_start = text . indexOf ( content ) ;
203
- const generated_start = prev_diff + original_start ;
203
+ const generated_start = accumulated_diff + original_start ;
204
+ accumulated_diff += output . outputText . length - content . length ;
204
205
diffs . push ( {
205
206
original_start : original_start ,
206
- original_end : original_start + content . length ,
207
207
generated_start : generated_start ,
208
208
generated_end : generated_start + output . outputText . length ,
209
209
diff : output . outputText . length - content . length ,
210
- accumulated_diff : prev_diff + output . outputText . length - content . length ,
211
210
original_content : content ,
212
211
generated_content : output . outputText ,
213
212
map : output . sourceMapText
0 commit comments