-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #861 from Microsoft/unionTypesLS
Lanugage Service support for union types
- Loading branch information
Showing
12 changed files
with
395 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
///<reference path="fourslash.ts" /> | ||
|
||
////interface One { | ||
//// commonProperty: number; | ||
//// commonFunction(): number; | ||
////} | ||
//// | ||
////interface Two { | ||
//// commonProperty: string | ||
//// commonFunction(): number; | ||
////} | ||
//// | ||
////var x : One | Two; | ||
//// | ||
////x./**/ | ||
|
||
goTo.marker(); | ||
verify.memberListContains("commonProperty", "string | number", undefined, undefined, "property"); | ||
verify.memberListContains("commonFunction", "() => number", undefined, undefined, "method"); | ||
verify.memberListCount(2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
///<reference path="fourslash.ts" /> | ||
|
||
////interface One { | ||
//// commonProperty: number; | ||
//// commonFunction(): number; | ||
////} | ||
//// | ||
////interface Two { | ||
//// commonProperty: string | ||
//// commonFunction(): number; | ||
////} | ||
//// | ||
////var x : One | Two; | ||
//// | ||
////x.commonProperty./**/ | ||
|
||
goTo.marker(); | ||
verify.memberListContains("toString", "() => string", undefined, undefined, "method"); | ||
verify.memberListCount(1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
////interface One { | ||
//// /*propertyDefinition1*/commonProperty: number; | ||
//// commonFunction(): number; | ||
////} | ||
//// | ||
////interface Two { | ||
//// /*propertyDefinition2*/commonProperty: string | ||
//// commonFunction(): number; | ||
////} | ||
//// | ||
////var x : One | Two; | ||
//// | ||
////x./*propertyReference*/commonProperty; | ||
////x./*3*/commonFunction; | ||
|
||
goTo.marker("propertyReference"); | ||
goTo.definition(0); | ||
verify.caretAtMarker("propertyDefinition1"); | ||
|
||
goTo.marker("propertyReference"); | ||
goTo.definition(1); | ||
verify.caretAtMarker("propertyDefinition2"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/// <reference path='fourslash.ts' /> | ||
////interface HasAOrB { | ||
//// /*propertyDefinition1*/a: string; | ||
//// b: string; | ||
////} | ||
//// | ||
////interface One { | ||
//// common: { /*propertyDefinition2*/a : number; }; | ||
////} | ||
//// | ||
////interface Two { | ||
//// common: HasAOrB; | ||
////} | ||
//// | ||
////var x : One | Two; | ||
//// | ||
////x.common./*propertyReference*/a; | ||
|
||
goTo.marker("propertyReference"); | ||
goTo.definition(0); | ||
verify.caretAtMarker("propertyDefinition1"); | ||
|
||
goTo.marker("propertyReference"); | ||
goTo.definition(1); | ||
verify.caretAtMarker("propertyDefinition2"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/// <reference path="fourslash.ts"/> | ||
|
||
////interface One { | ||
//// commonProperty: number; | ||
//// commonFunction(): number; | ||
////} | ||
//// | ||
////interface Two { | ||
//// commonProperty: string | ||
//// commonFunction(): number; | ||
////} | ||
//// | ||
////var /*1*/x : One | Two; | ||
//// | ||
////x./*2*/commonProperty; | ||
////x./*3*/commonFunction; | ||
|
||
|
||
goTo.marker("1"); | ||
verify.quickInfoIs("One | Two", "", "x", "var"); | ||
|
||
|
||
goTo.marker("2"); | ||
verify.quickInfoIs("string | number", "", "commonProperty", "property"); | ||
|
||
goTo.marker("3"); | ||
verify.quickInfoIs("() => number", "", "commonFunction", "method"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
tests/cases/fourslash/referencesForContextuallyTypedUnionProperties.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/// <reference path='fourslash.ts'/> | ||
|
||
////interface A { | ||
//// a: number; | ||
//// common: string; | ||
////} | ||
//// | ||
////interface B { | ||
//// b: number; | ||
//// common: number; | ||
////} | ||
//// | ||
////// Assignment | ||
////var v1: A | B = { a: 0, /*1*/common: "" }; | ||
////var v2: A | B = { b: 0, /*2*/common: 3 }; | ||
//// | ||
////// Function call | ||
////function consumer(f: A | B) { } | ||
////consumer({ a: 0, b: 0, /*3*/common: 1 }); | ||
//// | ||
////// Type cast | ||
////var c = <A | B> { /*4*/common: 0, b: 0 }; | ||
//// | ||
////// Array literal | ||
////var ar: Array<A|B> = [{ a: 0, /*5*/common: "" }, { b: 0, /*6*/common: 0 }]; | ||
//// | ||
////// Nested object literal | ||
////var ob: { aorb: A|B } = { aorb: { b: 0, /*7*/common: 0 } }; | ||
//// | ||
////// Widened type | ||
////var w: A|B = { a:0, /*8*/common: undefined }; | ||
//// | ||
////// Untped -- should not be included | ||
////var u1 = { a: 0, b: 0, common: "" }; | ||
////var u2 = { b: 0, common: 0 }; | ||
|
||
test.markers().forEach((m) => { | ||
goTo.position(m.position, m.fileName); | ||
verify.referencesCountIs(10); // 8 contextually typed common, and 2 in definition (A.common, B.common) | ||
}); |
40 changes: 40 additions & 0 deletions
40
tests/cases/fourslash/referencesForContextuallyTypedUnionProperties2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/// <reference path='fourslash.ts'/> | ||
|
||
////interface A { | ||
//// a: number; | ||
//// common: string; | ||
////} | ||
//// | ||
////interface B { | ||
//// /*1*/b: number; | ||
//// common: number; | ||
////} | ||
//// | ||
////// Assignment | ||
////var v1: A | B = { a: 0, common: "" }; | ||
////var v2: A | B = { /*2*/b: 0, common: 3 }; | ||
//// | ||
////// Function call | ||
////function consumer(f: A | B) { } | ||
////consumer({ a: 0, /*3*/b: 0, common: 1 }); | ||
//// | ||
////// Type cast | ||
////var c = <A | B> { common: 0, /*4*/b: 0 }; | ||
//// | ||
////// Array literal | ||
////var ar: Array<A|B> = [{ a: 0, common: "" }, { /*5*/b: 0, common: 0 }]; | ||
//// | ||
////// Nested object literal | ||
////var ob: { aorb: A|B } = { aorb: { /*6*/b: 0, common: 0 } }; | ||
//// | ||
////// Widened type | ||
////var w: A|B = { /*7*/b:undefined, common: undefined }; | ||
//// | ||
////// Untped -- should not be included | ||
////var u1 = { a: 0, b: 0, common: "" }; | ||
////var u2 = { b: 0, common: 0 }; | ||
|
||
test.markers().forEach((m) => { | ||
goTo.position(m.position, m.fileName); | ||
verify.referencesCountIs(7); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/// <reference path='fourslash.ts'/> | ||
|
||
////interface One { | ||
//// common: { /*1*/a: number; }; | ||
////} | ||
//// | ||
////interface Base { | ||
//// /*2*/a: string; | ||
//// b: string; | ||
////} | ||
//// | ||
////interface HasAOrB extends Base { | ||
//// /*3*/a: string; | ||
//// b: string; | ||
////} | ||
//// | ||
////interface Two { | ||
//// common: HasAOrB; | ||
////} | ||
//// | ||
////var x : One | Two; | ||
//// | ||
////x.common./*4*/a; | ||
|
||
goTo.marker("1"); | ||
verify.referencesCountIs(2); // One.common.a, x.common.a | ||
|
||
goTo.marker("2"); | ||
verify.referencesCountIs(3); // Base.a, HasAOrB.a, x.common.a | ||
|
||
goTo.marker("3"); | ||
verify.referencesCountIs(3); // Base.a, HasAOrB.a, x.common.a | ||
|
||
goTo.marker("4"); | ||
verify.referencesCountIs(4); // One.common.a, Base.a, HasAOrB.a, x.common.a |