Skip to content

Commit 6695ae1

Browse files
author
Andy Hanson
committed
Merge branch 'master' into find_all_refs_primitive
2 parents 1267fd3 + 0a535f0 commit 6695ae1

File tree

201 files changed

+571
-1325
lines changed

Some content is hidden

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

201 files changed

+571
-1325
lines changed

src/compiler/checker.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4172,7 +4172,6 @@ namespace ts {
41724172
}
41734173

41744174
function getDeclaredTypeOfSymbol(symbol: Symbol): Type {
4175-
Debug.assert((symbol.flags & SymbolFlags.Instantiated) === 0);
41764175
if (symbol.flags & (SymbolFlags.Class | SymbolFlags.Interface)) {
41774176
return getDeclaredTypeOfClassOrInterface(symbol);
41784177
}

src/compiler/core.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ namespace ts {
2424
}
2525

2626
// More efficient to create a collator once and use its `compare` than to call `a.localeCompare(b)` many times.
27-
export const collator: { compare(a: string, b: string): number } = typeof Intl === "object" && typeof Intl.Collator === "function" ? new Intl.Collator() : undefined;
27+
export const collator: { compare(a: string, b: string): number } = typeof Intl === "object" && typeof Intl.Collator === "function" ? new Intl.Collator(/*locales*/ undefined, { usage: "sort", sensitivity: "accent" }) : undefined;
28+
// Intl is missing in Safari, and node 0.10 treats "a" as greater than "B".
29+
export const localeCompareIsCorrect = ts.collator && ts.collator.compare("a", "B") < 0;
2830

2931
/** Create a MapLike with good performance. */
3032
function createDictionaryObject<T>(): MapLike<T> {
@@ -1247,9 +1249,12 @@ namespace ts {
12471249
if (a === undefined) return Comparison.LessThan;
12481250
if (b === undefined) return Comparison.GreaterThan;
12491251
if (ignoreCase) {
1250-
if (collator && String.prototype.localeCompare) {
1251-
// accent means a ≠ b, a ≠ á, a = A
1252-
const result = a.localeCompare(b, /*locales*/ undefined, { usage: "sort", sensitivity: "accent" });
1252+
// Checking if "collator exists indicates that Intl is available.
1253+
// We still have to check if "collator.compare" is correct. If it is not, use "String.localeComapre"
1254+
if (collator) {
1255+
const result = localeCompareIsCorrect ?
1256+
collator.compare(a, b) :
1257+
a.localeCompare(b, /*locales*/ undefined, { usage: "sort", sensitivity: "accent" }); // accent means a ≠ b, a ≠ á, a = A
12531258
return result < 0 ? Comparison.LessThan : result > 0 ? Comparison.GreaterThan : Comparison.EqualTo;
12541259
}
12551260

src/harness/fourslash.ts

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ namespace FourSlash {
372372
}
373373

374374
// Entry points from fourslash.ts
375-
public goToMarker(name = "") {
376-
const marker = this.getMarkerByName(name);
375+
public goToMarker(name: string | Marker = "") {
376+
const marker = typeof name === "string" ? this.getMarkerByName(name) : name;
377377
if (this.activeFile.fileName !== marker.fileName) {
378378
this.openFile(marker.fileName);
379379
}
@@ -382,10 +382,37 @@ namespace FourSlash {
382382
if (marker.position === -1 || marker.position > content.length) {
383383
throw new Error(`Marker "${name}" has been invalidated by unrecoverable edits to the file.`);
384384
}
385-
this.lastKnownMarker = name;
385+
const mName = typeof name === "string" ? name : this.markerName(marker);
386+
this.lastKnownMarker = mName;
386387
this.goToPosition(marker.position);
387388
}
388389

390+
public goToEachMarker(action: () => void) {
391+
const markers = this.getMarkers();
392+
assert(markers.length);
393+
for (const marker of markers) {
394+
this.goToMarker(marker);
395+
action();
396+
}
397+
}
398+
399+
public goToEachRange(action: () => void) {
400+
const ranges = this.getRanges();
401+
assert(ranges.length);
402+
for (const range of ranges) {
403+
this.goToRangeStart(range);
404+
action();
405+
}
406+
}
407+
408+
private markerName(m: Marker): string {
409+
return ts.forEachEntry(this.testData.markerPositions, (marker, name) => {
410+
if (marker === m) {
411+
return name;
412+
}
413+
})!;
414+
}
415+
389416
public goToPosition(pos: number) {
390417
this.currentCaretPosition = pos;
391418
}
@@ -2365,6 +2392,21 @@ namespace FourSlash {
23652392
return this.languageService.getDocumentHighlights(this.activeFile.fileName, this.currentCaretPosition, filesToSearch);
23662393
}
23672394

2395+
public verifyRangesAreOccurrences(isWriteAccess?: boolean) {
2396+
const ranges = this.getRanges();
2397+
for (const r of ranges) {
2398+
this.goToRangeStart(r);
2399+
this.verifyOccurrencesAtPositionListCount(ranges.length);
2400+
for (const range of ranges) {
2401+
this.verifyOccurrencesAtPositionListContains(range.fileName, range.start, range.end, isWriteAccess);
2402+
}
2403+
}
2404+
}
2405+
2406+
public verifyRangesAreRenameLocations(findInStrings: boolean, findInComments: boolean) {
2407+
this.goToEachRange(() => this.verifyRenameLocations(findInStrings, findInComments));
2408+
}
2409+
23682410
public verifyRangesWithSameTextAreDocumentHighlights() {
23692411
this.rangesByText().forEach(ranges => this.verifyRangesAreDocumentHighlights(ranges));
23702412
}
@@ -3078,14 +3120,22 @@ namespace FourSlashInterface {
30783120
// Moves the caret to the specified marker,
30793121
// or the anonymous marker ('/**/') if no name
30803122
// is given
3081-
public marker(name?: string) {
3123+
public marker(name?: string | FourSlash.Marker) {
30823124
this.state.goToMarker(name);
30833125
}
30843126

3127+
public eachMarker(action: () => void) {
3128+
this.state.goToEachMarker(action);
3129+
}
3130+
30853131
public rangeStart(range: FourSlash.Range) {
30863132
this.state.goToRangeStart(range);
30873133
}
30883134

3135+
public eachRange(action: () => void) {
3136+
this.state.goToEachRange(action);
3137+
}
3138+
30893139
public bof() {
30903140
this.state.goToBOF();
30913141
}
@@ -3436,6 +3486,14 @@ namespace FourSlashInterface {
34363486
this.state.verifyOccurrencesAtPositionListCount(expectedCount);
34373487
}
34383488

3489+
public rangesAreOccurrences(isWriteAccess?: boolean) {
3490+
this.state.verifyRangesAreOccurrences(isWriteAccess);
3491+
}
3492+
3493+
public rangesAreRenameLocations(findInStrings = false, findInComments = false) {
3494+
this.state.verifyRangesAreRenameLocations(findInStrings, findInComments);
3495+
}
3496+
34393497
public rangesAreDocumentHighlights(ranges?: FourSlash.Range[]) {
34403498
this.state.verifyRangesAreDocumentHighlights(ranges);
34413499
}

src/services/navigationBar.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -322,34 +322,14 @@ namespace ts.NavigationBar {
322322
function compareChildren(child1: NavigationBarNode, child2: NavigationBarNode): number {
323323
const name1 = tryGetName(child1.node), name2 = tryGetName(child2.node);
324324
if (name1 && name2) {
325-
const cmp = localeCompareFix(name1, name2);
325+
const cmp = ts.compareStringsCaseInsensitive(name1, name2);
326326
return cmp !== 0 ? cmp : navigationBarNodeKind(child1) - navigationBarNodeKind(child2);
327327
}
328328
else {
329329
return name1 ? 1 : name2 ? -1 : navigationBarNodeKind(child1) - navigationBarNodeKind(child2);
330330
}
331331
}
332332

333-
// Intl is missing in Safari, and node 0.10 treats "a" as greater than "B".
334-
const localeCompareIsCorrect = ts.collator && ts.collator.compare("a", "B") < 0;
335-
const localeCompareFix: (a: string, b: string) => number = localeCompareIsCorrect ? collator.compare : function(a, b) {
336-
// This isn't perfect, but it passes all of our tests.
337-
for (let i = 0; i < Math.min(a.length, b.length); i++) {
338-
const chA = a.charAt(i), chB = b.charAt(i);
339-
if (chA === "\"" && chB === "'") {
340-
return 1;
341-
}
342-
if (chA === "'" && chB === "\"") {
343-
return -1;
344-
}
345-
const cmp = ts.compareStrings(chA.toLocaleLowerCase(), chB.toLocaleLowerCase());
346-
if (cmp !== 0) {
347-
return cmp;
348-
}
349-
}
350-
return a.length - b.length;
351-
};
352-
353333
/**
354334
* This differs from getItemName because this is just used for sorting.
355335
* We only sort nodes by name that have a more-or-less "direct" name, as opposed to `new()` and the like.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
tests/cases/compiler/test.ts(4,5): error TS2322: Type 'PassportStatic' is not assignable to type 'Passport'.
2+
Types of property 'use' are incompatible.
3+
Type '() => PassportStatic' is not assignable to type '() => this'.
4+
Type 'PassportStatic' is not assignable to type 'this'.
5+
6+
7+
==== tests/cases/compiler/passport.d.ts (0 errors) ====
8+
declare module 'passport' {
9+
namespace passport {
10+
interface Passport {
11+
use(): this;
12+
}
13+
14+
interface PassportStatic extends Passport {
15+
Passport: {new(): Passport};
16+
}
17+
}
18+
19+
const passport: passport.PassportStatic;
20+
export = passport;
21+
}
22+
23+
==== tests/cases/compiler/test.ts (1 errors) ====
24+
import * as passport from "passport";
25+
import { Passport } from "passport";
26+
27+
let p: Passport = passport.use();
28+
~
29+
!!! error TS2322: Type 'PassportStatic' is not assignable to type 'Passport'.
30+
!!! error TS2322: Types of property 'use' are incompatible.
31+
!!! error TS2322: Type '() => PassportStatic' is not assignable to type '() => this'.
32+
!!! error TS2322: Type 'PassportStatic' is not assignable to type 'this'.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//// [tests/cases/compiler/mergedDeclarations7.ts] ////
2+
3+
//// [passport.d.ts]
4+
declare module 'passport' {
5+
namespace passport {
6+
interface Passport {
7+
use(): this;
8+
}
9+
10+
interface PassportStatic extends Passport {
11+
Passport: {new(): Passport};
12+
}
13+
}
14+
15+
const passport: passport.PassportStatic;
16+
export = passport;
17+
}
18+
19+
//// [test.ts]
20+
import * as passport from "passport";
21+
import { Passport } from "passport";
22+
23+
let p: Passport = passport.use();
24+
25+
//// [test.js]
26+
"use strict";
27+
var passport = require("passport");
28+
var p = passport.use();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// @filename: passport.d.ts
2+
declare module 'passport' {
3+
namespace passport {
4+
interface Passport {
5+
use(): this;
6+
}
7+
8+
interface PassportStatic extends Passport {
9+
Passport: {new(): Passport};
10+
}
11+
}
12+
13+
const passport: passport.PassportStatic;
14+
export = passport;
15+
}
16+
17+
//@filename: test.ts
18+
import * as passport from "passport";
19+
import { Passport } from "passport";
20+
21+
let p: Passport = passport.use();

tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_Generics.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,4 @@
1111

1212
////function A</*genericName5*/
1313

14-
15-
test.markers().forEach((m) => {
16-
goTo.position(m.position, m.fileName);
17-
verify.completionListIsEmpty();
18-
});
14+
goTo.eachMarker(() => verify.completionListIsEmpty());

tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_catch.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,4 @@
66

77
//// try {} catch(a/*catchVariable2*/
88

9-
10-
test.markers().forEach((m) => {
11-
goTo.position(m.position, m.fileName);
12-
verify.completionListIsEmpty();
13-
});
9+
goTo.eachMarker(() => verify.completionListIsEmpty());

tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_classes.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,4 @@
66

77
////class a/*className2*/
88

9-
test.markers().forEach((m) => {
10-
goTo.position(m.position, m.fileName);
11-
verify.completionListIsEmpty();
12-
});
9+
goTo.eachMarker(() => verify.completionListIsEmpty());

tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_destructuring.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,4 @@
1616

1717
//// function func2({ a, b/*parameter2*/
1818

19-
test.markers().forEach(m => {
20-
goTo.position(m.position, m.fileName);
21-
verify.completionListIsEmpty();
22-
});
19+
goTo.eachMarker(() => verify.completionListIsEmpty());

tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_enumMembers.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,4 @@
44

55
////enum a { /*enumValueName1*/
66

7-
8-
test.markers().forEach((m) => {
9-
goTo.position(m.position, m.fileName);
10-
verify.completionListIsEmpty();
11-
});
7+
goTo.eachMarker(() => verify.completionListIsEmpty());

tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_enumMembers2.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,4 @@
33
////var aa = 1;
44
////enum a { foo, /*enumValueName3*/
55

6-
test.markers().forEach((m) => {
7-
goTo.position(m.position, m.fileName);
8-
verify.completionListIsEmpty();
9-
});
6+
goTo.eachMarker(() => verify.completionListIsEmpty());

tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_enums.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,4 @@
88

99
////var x = 0; enum /*enumName4*/
1010

11-
test.markers().forEach((m) => {
12-
goTo.position(m.position, m.fileName);
13-
verify.completionListIsEmpty();
14-
});
11+
goTo.eachMarker(() => verify.completionListIsEmpty());

tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_functions.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,4 @@
66

77
////function a/*functionName2*/
88

9-
10-
test.markers().forEach((m) => {
11-
goTo.position(m.position, m.fileName);
12-
verify.completionListIsEmpty();
13-
});
9+
goTo.eachMarker(() => verify.completionListIsEmpty());

tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_interfaceMembers.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,4 @@
44

55
////interface a { /*interfaceValue1*/
66

7-
test.markers().forEach((m) => {
8-
goTo.position(m.position, m.fileName);
9-
verify.completionListIsEmpty();
10-
});
7+
goTo.eachMarker(() => verify.completionListIsEmpty());

tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_interfaceMembers2.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,4 @@
44

55
////interface a { f/*interfaceValue2*/
66

7-
test.markers().forEach((m) => {
8-
goTo.position(m.position, m.fileName);
9-
verify.completionListIsEmpty();
10-
});
7+
goTo.eachMarker(() => verify.completionListIsEmpty());

tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_interfaceMembers3.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,4 @@
44

55
////interface a { f; /*interfaceValue3*/
66

7-
test.markers().forEach((m) => {
8-
goTo.position(m.position, m.fileName);
9-
verify.completionListIsEmpty();
10-
});
7+
goTo.eachMarker(() => verify.completionListIsEmpty());

tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_interfaces.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,4 @@
66

77
////interface a/*interfaceName2*/
88

9-
10-
test.markers().forEach((m) => {
11-
goTo.position(m.position, m.fileName);
12-
verify.completionListIsEmpty();
13-
});
9+
goTo.eachMarker(() => verify.completionListIsEmpty());

tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_parameters.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,4 @@
2222

2323
////class bar10{ constructor(...a/*constructorParamter6*/
2424

25-
26-
test.markers().forEach((m) => {
27-
goTo.position(m.position, m.fileName);
28-
verify.completionListIsEmpty();
29-
});
25+
goTo.eachMarker(() => verify.completionListIsEmpty());

0 commit comments

Comments
 (0)