Skip to content

Commit b156f71

Browse files
committed
Actually accept baselines
1 parent 65ff3fd commit b156f71

File tree

4 files changed

+413
-1
lines changed

4 files changed

+413
-1
lines changed

src/services/formatting/rules.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ namespace ts.formatting {
318318

319319
this.NoSpaceBeforeComma = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CommaToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
320320

321-
this.SpaceAfterCertainKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.VarKeyword, SyntaxKind.ThrowKeyword, SyntaxKind.NewKeyword, SyntaxKind.DeleteKeyword, SyntaxKind.ReturnKeyword, SyntaxKind.TypeOfKeyword, SyntaxKind.AwaitKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
321+
this.SpaceAfterCertainKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.VarKeyword, SyntaxKind.ThrowKeyword, SyntaxKind.NewKeyword, SyntaxKind.DeleteKeyword, SyntaxKind.ReturnKeyword, SyntaxKind.TypeOfKeyword, SyntaxKind.KeysOfKeyword, SyntaxKind.AwaitKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
322322
this.SpaceAfterLetConstInVariableDeclaration = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.LetKeyword, SyntaxKind.ConstKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), RuleAction.Space));
323323
this.NoSpaceBeforeOpenParenInFuncCall = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), RuleAction.Delete));
324324
this.SpaceAfterFunctionInFuncDecl = new Rule(RuleDescriptor.create3(SyntaxKind.FunctionKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext), RuleAction.Space));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//// [simpleKeysofTest.ts]
2+
// First, check that the new keyword doesn't interfere
3+
// with any other potential uses of the identifier `keysof`.
4+
namespace keysof {
5+
export type name = {};
6+
}
7+
function old(a: keysof.name) {}
8+
9+
type keysof = {a: string};
10+
function old2(a: keysof, b: keysof): keysof { return {a: ""}; }
11+
var old3 = (): keysof => ({a: ""});
12+
13+
function disambiguate1(a: keysof ({b: number})) {}
14+
function disambiguate2(): keysof ({a}) {return "a";}
15+
16+
// Then check that the `keysof` operator works as expected
17+
interface FooBar {
18+
foo: "yes";
19+
bar: "no";
20+
[index: string]: string; // Remove when the indexer is patched to passthru unions
21+
}
22+
23+
function pick(thing: FooBar, member: keysof FooBar) {
24+
return thing[member];
25+
}
26+
27+
const a = pick({foo: "yes", "bar": "no"}, "bar");
28+
29+
function pick2<T>(thing: T, member: keysof T): keysof T {
30+
return member;
31+
}
32+
const realA: "a" = "a";
33+
const x = pick2({a: "", b: 0}, realA);
34+
const xx = pick2({a: "", b: 0}, "a");
35+
const item = {0: "yes", 1: "no"};
36+
const xxx = pick2(item, "0");
37+
38+
function annotate<U, T extends keysof U>(obj: U, key: T): U & {annotation: T} {
39+
const ret = obj as U & {annotation: T};
40+
if (key === "annotation") return ret; // Already annotated
41+
ret.annotation = key;
42+
return ret;
43+
}
44+
45+
annotate({a: "things", b: "stuff"}, "b").annotation === "b";
46+
47+
48+
//// [simpleKeysofTest.js]
49+
function old(a) { }
50+
function old2(a, b) { return { a: "" }; }
51+
var old3 = function () { return ({ a: "" }); };
52+
function disambiguate1(a) { }
53+
function disambiguate2() { return "a"; }
54+
function pick(thing, member) {
55+
return thing[member];
56+
}
57+
var a = pick({ foo: "yes", "bar": "no" }, "bar");
58+
function pick2(thing, member) {
59+
return member;
60+
}
61+
var realA = "a";
62+
var x = pick2({ a: "", b: 0 }, realA);
63+
var xx = pick2({ a: "", b: 0 }, "a");
64+
var item = { 0: "yes", 1: "no" };
65+
var xxx = pick2(item, "0");
66+
function annotate(obj, key) {
67+
var ret = obj;
68+
if (key === "annotation")
69+
return ret; // Already annotated
70+
ret.annotation = key;
71+
return ret;
72+
}
73+
annotate({ a: "things", b: "stuff" }, "b").annotation === "b";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
=== tests/cases/conformance/types/keysof/simpleKeysofTest.ts ===
2+
// First, check that the new keyword doesn't interfere
3+
// with any other potential uses of the identifier `keysof`.
4+
namespace keysof {
5+
>keysof : Symbol(keysof, Decl(simpleKeysofTest.ts, 0, 0), Decl(simpleKeysofTest.ts, 5, 31))
6+
7+
export type name = {};
8+
>name : Symbol(name, Decl(simpleKeysofTest.ts, 2, 18))
9+
}
10+
function old(a: keysof.name) {}
11+
>old : Symbol(old, Decl(simpleKeysofTest.ts, 4, 1))
12+
>a : Symbol(a, Decl(simpleKeysofTest.ts, 5, 13))
13+
>keysof : Symbol(keysof, Decl(simpleKeysofTest.ts, 0, 0), Decl(simpleKeysofTest.ts, 5, 31))
14+
>name : Symbol(keysof.name, Decl(simpleKeysofTest.ts, 2, 18))
15+
16+
type keysof = {a: string};
17+
>keysof : Symbol(keysof, Decl(simpleKeysofTest.ts, 0, 0), Decl(simpleKeysofTest.ts, 5, 31))
18+
>a : Symbol(a, Decl(simpleKeysofTest.ts, 7, 15))
19+
20+
function old2(a: keysof, b: keysof): keysof { return {a: ""}; }
21+
>old2 : Symbol(old2, Decl(simpleKeysofTest.ts, 7, 26))
22+
>a : Symbol(a, Decl(simpleKeysofTest.ts, 8, 14))
23+
>keysof : Symbol(keysof, Decl(simpleKeysofTest.ts, 0, 0), Decl(simpleKeysofTest.ts, 5, 31))
24+
>b : Symbol(b, Decl(simpleKeysofTest.ts, 8, 24))
25+
>keysof : Symbol(keysof, Decl(simpleKeysofTest.ts, 0, 0), Decl(simpleKeysofTest.ts, 5, 31))
26+
>keysof : Symbol(keysof, Decl(simpleKeysofTest.ts, 0, 0), Decl(simpleKeysofTest.ts, 5, 31))
27+
>a : Symbol(a, Decl(simpleKeysofTest.ts, 8, 54))
28+
29+
var old3 = (): keysof => ({a: ""});
30+
>old3 : Symbol(old3, Decl(simpleKeysofTest.ts, 9, 3))
31+
>keysof : Symbol(keysof, Decl(simpleKeysofTest.ts, 0, 0), Decl(simpleKeysofTest.ts, 5, 31))
32+
>a : Symbol(a, Decl(simpleKeysofTest.ts, 9, 27))
33+
34+
function disambiguate1(a: keysof ({b: number})) {}
35+
>disambiguate1 : Symbol(disambiguate1, Decl(simpleKeysofTest.ts, 9, 35))
36+
>a : Symbol(a, Decl(simpleKeysofTest.ts, 11, 23))
37+
>b : Symbol(b, Decl(simpleKeysofTest.ts, 11, 35))
38+
39+
function disambiguate2(): keysof ({a}) {return "a";}
40+
>disambiguate2 : Symbol(disambiguate2, Decl(simpleKeysofTest.ts, 11, 50))
41+
>a : Symbol(a, Decl(simpleKeysofTest.ts, 12, 35))
42+
43+
// Then check that the `keysof` operator works as expected
44+
interface FooBar {
45+
>FooBar : Symbol(FooBar, Decl(simpleKeysofTest.ts, 12, 52))
46+
47+
foo: "yes";
48+
>foo : Symbol(FooBar.foo, Decl(simpleKeysofTest.ts, 15, 18))
49+
50+
bar: "no";
51+
>bar : Symbol(FooBar.bar, Decl(simpleKeysofTest.ts, 16, 15))
52+
53+
[index: string]: string; // Remove when the indexer is patched to passthru unions
54+
>index : Symbol(index, Decl(simpleKeysofTest.ts, 18, 5))
55+
}
56+
57+
function pick(thing: FooBar, member: keysof FooBar) {
58+
>pick : Symbol(pick, Decl(simpleKeysofTest.ts, 19, 1))
59+
>thing : Symbol(thing, Decl(simpleKeysofTest.ts, 21, 14))
60+
>FooBar : Symbol(FooBar, Decl(simpleKeysofTest.ts, 12, 52))
61+
>member : Symbol(member, Decl(simpleKeysofTest.ts, 21, 28))
62+
>FooBar : Symbol(FooBar, Decl(simpleKeysofTest.ts, 12, 52))
63+
64+
return thing[member];
65+
>thing : Symbol(thing, Decl(simpleKeysofTest.ts, 21, 14))
66+
>member : Symbol(member, Decl(simpleKeysofTest.ts, 21, 28))
67+
}
68+
69+
const a = pick({foo: "yes", "bar": "no"}, "bar");
70+
>a : Symbol(a, Decl(simpleKeysofTest.ts, 25, 5))
71+
>pick : Symbol(pick, Decl(simpleKeysofTest.ts, 19, 1))
72+
>foo : Symbol(foo, Decl(simpleKeysofTest.ts, 25, 16))
73+
74+
function pick2<T>(thing: T, member: keysof T): keysof T {
75+
>pick2 : Symbol(pick2, Decl(simpleKeysofTest.ts, 25, 49))
76+
>T : Symbol(T, Decl(simpleKeysofTest.ts, 27, 15))
77+
>thing : Symbol(thing, Decl(simpleKeysofTest.ts, 27, 18))
78+
>T : Symbol(T, Decl(simpleKeysofTest.ts, 27, 15))
79+
>member : Symbol(member, Decl(simpleKeysofTest.ts, 27, 27))
80+
>T : Symbol(T, Decl(simpleKeysofTest.ts, 27, 15))
81+
>T : Symbol(T, Decl(simpleKeysofTest.ts, 27, 15))
82+
83+
return member;
84+
>member : Symbol(member, Decl(simpleKeysofTest.ts, 27, 27))
85+
}
86+
const realA: "a" = "a";
87+
>realA : Symbol(realA, Decl(simpleKeysofTest.ts, 30, 5))
88+
89+
const x = pick2({a: "", b: 0}, realA);
90+
>x : Symbol(x, Decl(simpleKeysofTest.ts, 31, 5))
91+
>pick2 : Symbol(pick2, Decl(simpleKeysofTest.ts, 25, 49))
92+
>a : Symbol(a, Decl(simpleKeysofTest.ts, 31, 17))
93+
>b : Symbol(b, Decl(simpleKeysofTest.ts, 31, 23))
94+
>realA : Symbol(realA, Decl(simpleKeysofTest.ts, 30, 5))
95+
96+
const xx = pick2({a: "", b: 0}, "a");
97+
>xx : Symbol(xx, Decl(simpleKeysofTest.ts, 32, 5))
98+
>pick2 : Symbol(pick2, Decl(simpleKeysofTest.ts, 25, 49))
99+
>a : Symbol(a, Decl(simpleKeysofTest.ts, 32, 18))
100+
>b : Symbol(b, Decl(simpleKeysofTest.ts, 32, 24))
101+
102+
const item = {0: "yes", 1: "no"};
103+
>item : Symbol(item, Decl(simpleKeysofTest.ts, 33, 5))
104+
105+
const xxx = pick2(item, "0");
106+
>xxx : Symbol(xxx, Decl(simpleKeysofTest.ts, 34, 5))
107+
>pick2 : Symbol(pick2, Decl(simpleKeysofTest.ts, 25, 49))
108+
>item : Symbol(item, Decl(simpleKeysofTest.ts, 33, 5))
109+
110+
function annotate<U, T extends keysof U>(obj: U, key: T): U & {annotation: T} {
111+
>annotate : Symbol(annotate, Decl(simpleKeysofTest.ts, 34, 29))
112+
>U : Symbol(U, Decl(simpleKeysofTest.ts, 36, 18))
113+
>T : Symbol(T, Decl(simpleKeysofTest.ts, 36, 20))
114+
>U : Symbol(U, Decl(simpleKeysofTest.ts, 36, 18))
115+
>obj : Symbol(obj, Decl(simpleKeysofTest.ts, 36, 41))
116+
>U : Symbol(U, Decl(simpleKeysofTest.ts, 36, 18))
117+
>key : Symbol(key, Decl(simpleKeysofTest.ts, 36, 48))
118+
>T : Symbol(T, Decl(simpleKeysofTest.ts, 36, 20))
119+
>U : Symbol(U, Decl(simpleKeysofTest.ts, 36, 18))
120+
>annotation : Symbol(annotation, Decl(simpleKeysofTest.ts, 36, 63))
121+
>T : Symbol(T, Decl(simpleKeysofTest.ts, 36, 20))
122+
123+
const ret = obj as U & {annotation: T};
124+
>ret : Symbol(ret, Decl(simpleKeysofTest.ts, 37, 9))
125+
>obj : Symbol(obj, Decl(simpleKeysofTest.ts, 36, 41))
126+
>U : Symbol(U, Decl(simpleKeysofTest.ts, 36, 18))
127+
>annotation : Symbol(annotation, Decl(simpleKeysofTest.ts, 37, 28))
128+
>T : Symbol(T, Decl(simpleKeysofTest.ts, 36, 20))
129+
130+
if (key === "annotation") return ret; // Already annotated
131+
>key : Symbol(key, Decl(simpleKeysofTest.ts, 36, 48))
132+
>ret : Symbol(ret, Decl(simpleKeysofTest.ts, 37, 9))
133+
134+
ret.annotation = key;
135+
>ret.annotation : Symbol(annotation, Decl(simpleKeysofTest.ts, 37, 28))
136+
>ret : Symbol(ret, Decl(simpleKeysofTest.ts, 37, 9))
137+
>annotation : Symbol(annotation, Decl(simpleKeysofTest.ts, 37, 28))
138+
>key : Symbol(key, Decl(simpleKeysofTest.ts, 36, 48))
139+
140+
return ret;
141+
>ret : Symbol(ret, Decl(simpleKeysofTest.ts, 37, 9))
142+
}
143+
144+
annotate({a: "things", b: "stuff"}, "b").annotation === "b";
145+
>annotate({a: "things", b: "stuff"}, "b").annotation : Symbol(annotation, Decl(simpleKeysofTest.ts, 36, 63))
146+
>annotate : Symbol(annotate, Decl(simpleKeysofTest.ts, 34, 29))
147+
>a : Symbol(a, Decl(simpleKeysofTest.ts, 43, 10))
148+
>b : Symbol(b, Decl(simpleKeysofTest.ts, 43, 22))
149+
>annotation : Symbol(annotation, Decl(simpleKeysofTest.ts, 36, 63))
150+

0 commit comments

Comments
 (0)