Skip to content

Commit 9e8e5ea

Browse files
committed
Merge branch 'master' into new-jsdoc-parser
2 parents 643cf30 + 3bcfb6b commit 9e8e5ea

File tree

66 files changed

+473
-1230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+473
-1230
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5378,7 +5378,7 @@ namespace ts {
53785378
while (i > 0) {
53795379
i--;
53805380
if (isSubtypeOfAny(types[i], types)) {
5381-
types.splice(i, 1);
5381+
orderedRemoveItemAt(types, i);
53825382
}
53835383
}
53845384
}
@@ -8759,7 +8759,7 @@ namespace ts {
87598759
// The location isn't a reference to the given symbol, meaning we're being asked
87608760
// a hypothetical question of what type the symbol would have if there was a reference
87618761
// to it at the given location. Since we have no control flow information for the
8762-
// hypotherical reference (control flow information is created and attached by the
8762+
// hypothetical reference (control flow information is created and attached by the
87638763
// binder), we simply return the declared type of the symbol.
87648764
return getTypeOfSymbol(symbol);
87658765
}

src/compiler/core.ts

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,21 @@ namespace ts {
566566
return result;
567567
}
568568

569+
/**
570+
* Adds the value to an array of values associated with the key, and returns the array.
571+
* Creates the array if it does not already exist.
572+
*/
573+
export function multiMapAdd<V>(map: Map<V[]>, key: string, value: V): V[] {
574+
const values = map[key];
575+
if (values) {
576+
values.push(value);
577+
return values;
578+
}
579+
else {
580+
return map[key] = [value];
581+
}
582+
}
583+
569584
/**
570585
* Tests whether a value is an array.
571586
*/
@@ -1500,20 +1515,39 @@ namespace ts {
15001515
}
15011516
}
15021517

1503-
export function copyListRemovingItem<T>(item: T, list: T[]) {
1504-
const copiedList: T[] = [];
1505-
for (const e of list) {
1506-
if (e !== item) {
1507-
copiedList.push(e);
1518+
/** Remove an item from an array, moving everything to its right one space left. */
1519+
export function orderedRemoveItemAt<T>(array: T[], index: number): void {
1520+
// This seems to be faster than either `array.splice(i, 1)` or `array.copyWithin(i, i+ 1)`.
1521+
for (let i = index; i < array.length - 1; i++) {
1522+
array[i] = array[i + 1];
1523+
}
1524+
array.pop();
1525+
}
1526+
1527+
export function unorderedRemoveItemAt<T>(array: T[], index: number): void {
1528+
// Fill in the "hole" left at `index`.
1529+
array[index] = array[array.length - 1];
1530+
array.pop();
1531+
}
1532+
1533+
/** Remove the *first* occurrence of `item` from the array. */
1534+
export function unorderedRemoveItem<T>(array: T[], item: T): void {
1535+
unorderedRemoveFirstItemWhere(array, element => element === item);
1536+
}
1537+
1538+
/** Remove the *first* element satisfying `predicate`. */
1539+
function unorderedRemoveFirstItemWhere<T>(array: T[], predicate: (element: T) => boolean): void {
1540+
for (let i = 0; i < array.length; i++) {
1541+
if (predicate(array[i])) {
1542+
unorderedRemoveItemAt(array, i);
1543+
break;
15081544
}
15091545
}
1510-
return copiedList;
15111546
}
15121547

1513-
export function createGetCanonicalFileName(useCaseSensitivefileNames: boolean): (fileName: string) => string {
1514-
return useCaseSensitivefileNames
1548+
export function createGetCanonicalFileName(useCaseSensitiveFileNames: boolean): (fileName: string) => string {
1549+
return useCaseSensitiveFileNames
15151550
? ((fileName) => fileName)
15161551
: ((fileName) => fileName.toLowerCase());
15171552
}
1518-
15191553
}

src/compiler/emitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6851,7 +6851,7 @@ const _super = (function (geti, seti) {
68516851
// export { x, y }
68526852
for (const specifier of (<ExportDeclaration>node).exportClause.elements) {
68536853
const name = (specifier.propertyName || specifier.name).text;
6854-
(exportSpecifiers[name] || (exportSpecifiers[name] = [])).push(specifier);
6854+
multiMapAdd(exportSpecifiers, name, specifier);
68556855
}
68566856
}
68576857
break;

src/compiler/sys.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ namespace ts {
267267
}
268268

269269
function addFileWatcherCallback(filePath: string, callback: FileWatcherCallback): void {
270-
(fileWatcherCallbacks[filePath] || (fileWatcherCallbacks[filePath] = [])).push(callback);
270+
multiMapAdd(fileWatcherCallbacks, filePath, callback);
271271
}
272272

273273
function addFile(fileName: string, callback: FileWatcherCallback): WatchedFile {
@@ -285,13 +285,10 @@ namespace ts {
285285
function removeFileWatcherCallback(filePath: string, callback: FileWatcherCallback) {
286286
const callbacks = fileWatcherCallbacks[filePath];
287287
if (callbacks) {
288-
const newCallbacks = copyListRemovingItem(callback, callbacks);
289-
if (newCallbacks.length === 0) {
288+
unorderedRemoveItem(callbacks, callback);
289+
if (callbacks.length === 0) {
290290
delete fileWatcherCallbacks[filePath];
291291
}
292-
else {
293-
fileWatcherCallbacks[filePath] = newCallbacks;
294-
}
295292
}
296293
}
297294

src/compiler/tsc.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,7 @@ namespace ts {
489489
sourceFile.fileWatcher.close();
490490
sourceFile.fileWatcher = undefined;
491491
if (removed) {
492-
const index = rootFileNames.indexOf(sourceFile.fileName);
493-
if (index >= 0) {
494-
rootFileNames.splice(index, 1);
495-
}
492+
unorderedRemoveItem(rootFileNames, sourceFile.fileName);
496493
}
497494
startTimerForRecompilation();
498495
}

src/compiler/utilities.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,18 @@ namespace ts {
10351035
return undefined;
10361036
}
10371037

1038+
export function isCallLikeExpression(node: Node): node is CallLikeExpression {
1039+
switch (node.kind) {
1040+
case SyntaxKind.CallExpression:
1041+
case SyntaxKind.NewExpression:
1042+
case SyntaxKind.TaggedTemplateExpression:
1043+
case SyntaxKind.Decorator:
1044+
return true;
1045+
default:
1046+
return false;
1047+
}
1048+
}
1049+
10381050
export function getInvokedExpression(node: CallLikeExpression): Expression {
10391051
if (node.kind === SyntaxKind.TaggedTemplateExpression) {
10401052
return (<TaggedTemplateExpression>node).tag;
@@ -2739,10 +2751,17 @@ namespace ts {
27392751
return token >= SyntaxKind.FirstAssignment && token <= SyntaxKind.LastAssignment;
27402752
}
27412753

2742-
export function isExpressionWithTypeArgumentsInClassExtendsClause(node: Node): boolean {
2743-
return node.kind === SyntaxKind.ExpressionWithTypeArguments &&
2754+
/** Get `C` given `N` if `N` is in the position `class C extends N` where `N` is an ExpressionWithTypeArguments. */
2755+
export function tryGetClassExtendingExpressionWithTypeArguments(node: Node): ClassLikeDeclaration | undefined {
2756+
if (node.kind === SyntaxKind.ExpressionWithTypeArguments &&
27442757
(<HeritageClause>node.parent).token === SyntaxKind.ExtendsKeyword &&
2745-
isClassLike(node.parent.parent);
2758+
isClassLike(node.parent.parent)) {
2759+
return node.parent.parent;
2760+
}
2761+
}
2762+
2763+
export function isExpressionWithTypeArgumentsInClassExtendsClause(node: Node): boolean {
2764+
return tryGetClassExtendingExpressionWithTypeArguments(node) !== undefined;
27462765
}
27472766

27482767
export function isEntityNameExpression(node: Expression): node is EntityNameExpression {

src/harness/fourslash.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,7 @@ namespace FourSlash {
15641564
public goToDefinition(definitionIndex: number) {
15651565
const definitions = this.languageService.getDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition);
15661566
if (!definitions || !definitions.length) {
1567-
this.raiseError("goToDefinition failed - expected to at least one definition location but got 0");
1567+
this.raiseError("goToDefinition failed - expected to find at least one definition location but got 0");
15681568
}
15691569

15701570
if (definitionIndex >= definitions.length) {
@@ -1579,7 +1579,7 @@ namespace FourSlash {
15791579
public goToTypeDefinition(definitionIndex: number) {
15801580
const definitions = this.languageService.getTypeDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition);
15811581
if (!definitions || !definitions.length) {
1582-
this.raiseError("goToTypeDefinition failed - expected to at least one definition location but got 0");
1582+
this.raiseError("goToTypeDefinition failed - expected to find at least one definition location but got 0");
15831583
}
15841584

15851585
if (definitionIndex >= definitions.length) {
@@ -1600,7 +1600,7 @@ namespace FourSlash {
16001600
this.raiseError(`goToDefinition - expected to 0 definition locations but got ${definitions.length}`);
16011601
}
16021602
else if (!foundDefinitions && !negative) {
1603-
this.raiseError("goToDefinition - expected to at least one definition location but got 0");
1603+
this.raiseError("goToDefinition - expected to find at least one definition location but got 0");
16041604
}
16051605
}
16061606

@@ -1649,8 +1649,7 @@ namespace FourSlash {
16491649
const result = ts.createMap<Range[]>();
16501650
for (const range of this.getRanges()) {
16511651
const text = this.rangeText(range);
1652-
const ranges = result[text] || (result[text] = []);
1653-
ranges.push(range);
1652+
ts.multiMapAdd(result, text, range);
16541653
}
16551654
return result;
16561655
}

src/harness/harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1785,7 +1785,7 @@ namespace Harness {
17851785
tsConfig.options.configFilePath = data.name;
17861786

17871787
// delete entry from the list
1788-
testUnitData.splice(i, 1);
1788+
ts.orderedRemoveItemAt(testUnitData, i);
17891789

17901790
break;
17911791
}

src/harness/unittests/services/formatting/testCode/testCode/formatting/classes.ts

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

src/harness/unittests/services/formatting/testCode/testCode/formatting/classesBaseline.ts

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

0 commit comments

Comments
 (0)