Skip to content

Commit a2ff579

Browse files
author
Simon Holthausen
committed
simplify code
1 parent e4f9a85 commit a2ff579

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/preprocess.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,21 +193,20 @@ function compile_code(text, compiler, processor_options) {
193193
let ts_result;
194194
if (processor_options.typescript) {
195195
const diffs = [];
196+
let accumulated_diff = 0;
196197
const transpiled = text.replace(/<script(\s[^]*?)?>([^]*?)<\/script>/gi, (match, attributes = '', content) => {
197198
const output = processor_options.typescript.transpileModule(
198199
content,
199200
{ reportDiagnostics: false, compilerOptions: { target: processor_options.typescript.ScriptTarget.ESNext, sourceMap: true } }
200201
);
201-
const prev_diff = diffs.length ? diffs[diffs.length - 1].accumulated_diff : 0;
202202
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;
204205
diffs.push({
205206
original_start: original_start,
206-
original_end: original_start + content.length,
207207
generated_start: generated_start,
208208
generated_end: generated_start + output.outputText.length,
209209
diff: output.outputText.length - content.length,
210-
accumulated_diff: prev_diff + output.outputText.length - content.length,
211210
original_content: content,
212211
generated_content: output.outputText,
213212
map: output.sourceMapText

0 commit comments

Comments
 (0)