Skip to content

Commit 1b4a431

Browse files
Get rid of the TextDecoder, use the 1024-chunk batching trick.
1 parent 9c42104 commit 1b4a431

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/compiler/sourcemap.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ namespace ts {
44
extendedDiagnostics?: boolean;
55
}
66

7-
declare let TextDecoder: undefined | (new() => { decode(buffer: ArrayBuffer | ArrayBufferView): string });
8-
const decoder = new (typeof TextDecoder !== "undefined" ? TextDecoder : require("util").TextDecoder)();
97
let mappingsBuffer: Uint8Array;
108

119
export function createSourceMapGenerator(host: EmitHost, file: string, guessedInputLength: number, sourceRoot: string, sourcesDirectoryPath: string, generatorOptions: SourceMapGeneratorOptions): SourceMapGenerator {
@@ -304,9 +302,17 @@ namespace ts {
304302
exit();
305303
}
306304

305+
function serializeMappings(len: number): string {
306+
let mappings = "";
307+
for (let i = 0; i < len; i += 1024) {
308+
mappings += String.fromCharCode.apply(undefined, mappingsBuffer.subarray(i, Math.min(len, i + 1024)));
309+
}
310+
return mappings;
311+
}
312+
307313
function toJSON(): RawSourceMap {
308314
commitPendingMapping();
309-
const mappings = (lastMappings ??= decoder.decode(mappingsBuffer.subarray(0, mappingsPos)));
315+
const mappings = (lastMappings ??= serializeMappings(mappingsPos));
310316
return {
311317
version: 3,
312318
file,

0 commit comments

Comments
 (0)