Skip to content

Commit 50a0174

Browse files
authored
Merge pull request #27629 from Microsoft/sourceMapGenerator
Simplify source map generation
2 parents 2585ccb + 6927bc7 commit 50a0174

37 files changed

+1780
-1738
lines changed

scripts/build/gulp-typescript-oop/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @ts-check
22
const path = require("path");
33
const child_process = require("child_process");
4+
const fs = require("fs");
45
const tsc = require("gulp-typescript");
56
const Vinyl = require("vinyl");
67
const { Duplex, Readable } = require("stream");
@@ -42,7 +43,10 @@ function createProject(tsConfigFileName, settings, options) {
4243
getVinyl(path) { return inputs.get(path); },
4344
getSourceFile(fileName) { return sourceFiles.get(fileName); },
4445
createSourceFile(fileName, text, languageVersion) {
45-
if (text === undefined) throw new Error("File not cached.");
46+
if (text === undefined) {
47+
text = fs.readFileSync(fileName, "utf8");
48+
}
49+
4650
/** @type {protocol.SourceFile} */
4751
let file;
4852
if (options.parse) {

src/compiler/builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ namespace ts {
450450
assertSourceFileOkWithoutNextAffectedCall(state, targetSourceFile);
451451
if (!targetSourceFile) {
452452
// Emit and report any errors we ran into.
453-
let sourceMaps: SourceMapData[] = [];
453+
let sourceMaps: SourceMapEmitResult[] = [];
454454
let emitSkipped = false;
455455
let diagnostics: Diagnostic[] | undefined;
456456
let emittedFiles: string[] = [];

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3141,7 +3141,7 @@ namespace ts {
31413141
const sig = nodeBuilder.signatureToSignatureDeclaration(signature, sigOutput, enclosingDeclaration, toNodeBuilderFlags(flags) | NodeBuilderFlags.IgnoreErrors | NodeBuilderFlags.WriteTypeParametersInQualifiedName);
31423142
const printer = createPrinter({ removeComments: true, omitTrailingSemicolon: true });
31433143
const sourceFile = enclosingDeclaration && getSourceFileOfNode(enclosingDeclaration);
3144-
printer.writeNode(EmitHint.Unspecified, sig!, /*sourceFile*/ sourceFile, writer); // TODO: GH#18217
3144+
printer.writeNode(EmitHint.Unspecified, sig!, /*sourceFile*/ sourceFile, getTrailingSemicolonOmittingWriter(writer)); // TODO: GH#18217
31453145
return writer;
31463146
}
31473147
}

src/compiler/comments.ts

Lines changed: 0 additions & 431 deletions
This file was deleted.

src/compiler/core.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,10 +1061,10 @@ namespace ts {
10611061
/**
10621062
* Stable sort of an array. Elements equal to each other maintain their relative position in the array.
10631063
*/
1064-
export function stableSort<T>(array: ReadonlyArray<T>, comparer: Comparer<T>) {
1064+
export function stableSort<T>(array: ReadonlyArray<T>, comparer: Comparer<T>): SortedReadonlyArray<T> {
10651065
const indices = array.map((_, i) => i);
10661066
stableSortIndices(array, indices, comparer);
1067-
return indices.map(i => array[i]);
1067+
return indices.map(i => array[i]) as SortedArray<T> as SortedReadonlyArray<T>;
10681068
}
10691069

10701070
export function rangeEquals<T>(array1: ReadonlyArray<T>, array2: ReadonlyArray<T>, pos: number, end: number) {
@@ -1156,13 +1156,26 @@ namespace ts {
11561156
* @param offset An offset into `array` at which to start the search.
11571157
*/
11581158
export function binarySearch<T, U>(array: ReadonlyArray<T>, value: T, keySelector: (v: T) => U, keyComparer: Comparer<U>, offset?: number): number {
1159-
if (!array || array.length === 0) {
1159+
return binarySearchKey(array, keySelector(value), keySelector, keyComparer, offset);
1160+
}
1161+
1162+
/**
1163+
* Performs a binary search, finding the index at which an object with `key` occurs in `array`.
1164+
* If no such index is found, returns the 2's-complement of first index at which
1165+
* `array[index]` exceeds `key`.
1166+
* @param array A sorted array whose first element must be no larger than number
1167+
* @param key The key to be searched for in the array.
1168+
* @param keySelector A callback used to select the search key from each element of `array`.
1169+
* @param keyComparer A callback used to compare two keys in a sorted array.
1170+
* @param offset An offset into `array` at which to start the search.
1171+
*/
1172+
export function binarySearchKey<T, U>(array: ReadonlyArray<T>, key: U, keySelector: (v: T) => U, keyComparer: Comparer<U>, offset?: number): number {
1173+
if (!some(array)) {
11601174
return -1;
11611175
}
11621176

11631177
let low = offset || 0;
11641178
let high = array.length - 1;
1165-
const key = keySelector(value);
11661179
while (low <= high) {
11671180
const middle = low + ((high - low) >> 1);
11681181
const midKey = keySelector(array[middle]);

0 commit comments

Comments
 (0)