Skip to content

Commit 7d6100b

Browse files
committed
Merge pull request #5719 from Microsoft/typesCleanup2
Additional Types cleanup.
2 parents fc79104 + 93af2b2 commit 7d6100b

13 files changed

+72
-27
lines changed

src/compiler/binder.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ namespace ts {
196196
}
197197
if (node.name.kind === SyntaxKind.ComputedPropertyName) {
198198
const nameExpression = (<ComputedPropertyName>node.name).expression;
199-
// treat computed property names where expression is string/numeric literal as just string/numeric literal
199+
// treat computed property names where expression is string/numeric literal as just string/numeric literal
200200
if (isStringOrNumericLiteral(nameExpression.kind)) {
201201
return (<LiteralExpression>nameExpression).text;
202202
}
@@ -457,7 +457,7 @@ namespace ts {
457457

458458
/**
459459
* Returns true if node and its subnodes were successfully traversed.
460-
* Returning false means that node was not examined and caller needs to dive into the node himself.
460+
* Returning false means that node was not examined and caller needs to dive into the node himself.
461461
*/
462462
function bindReachableStatement(node: Node): void {
463463
if (checkUnreachable(node)) {
@@ -567,7 +567,7 @@ namespace ts {
567567
}
568568

569569
function bindIfStatement(n: IfStatement): void {
570-
// denotes reachability state when entering 'thenStatement' part of the if statement:
570+
// denotes reachability state when entering 'thenStatement' part of the if statement:
571571
// i.e. if condition is false then thenStatement is unreachable
572572
const ifTrueState = n.expression.kind === SyntaxKind.FalseKeyword ? Reachability.Unreachable : currentReachabilityState;
573573
// denotes reachability state when entering 'elseStatement':
@@ -1186,7 +1186,7 @@ namespace ts {
11861186
return checkStrictModePrefixUnaryExpression(<PrefixUnaryExpression>node);
11871187
case SyntaxKind.WithStatement:
11881188
return checkStrictModeWithStatement(<WithStatement>node);
1189-
case SyntaxKind.ThisKeyword:
1189+
case SyntaxKind.ThisType:
11901190
seenThisKeyword = true;
11911191
return;
11921192

@@ -1535,7 +1535,7 @@ namespace ts {
15351535

15361536
// unreachable code is reported if
15371537
// - user has explicitly asked about it AND
1538-
// - statement is in not ambient context (statements in ambient context is already an error
1538+
// - statement is in not ambient context (statements in ambient context is already an error
15391539
// so we should not report extras) AND
15401540
// - node is not variable statement OR
15411541
// - node is block scoped variable statement OR

src/compiler/checker.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4585,7 +4585,7 @@ namespace ts {
45854585
return esSymbolType;
45864586
case SyntaxKind.VoidKeyword:
45874587
return voidType;
4588-
case SyntaxKind.ThisKeyword:
4588+
case SyntaxKind.ThisType:
45894589
return getTypeFromThisTypeNode(node);
45904590
case SyntaxKind.StringLiteral:
45914591
return getTypeFromStringLiteral(<StringLiteral>node);
@@ -10208,7 +10208,7 @@ namespace ts {
1020810208
checkDestructuringAssignment(<ShorthandPropertyAssignment>p, type);
1020910209
}
1021010210
else {
10211-
// non-shorthand property assignments should always have initializers
10211+
// non-shorthand property assignments should always have initializers
1021210212
checkDestructuringAssignment((<PropertyAssignment>p).initializer, type);
1021310213
}
1021410214
}
@@ -14682,6 +14682,9 @@ namespace ts {
1468214682
const type = isExpression(node) ? checkExpression(<Expression>node) : getTypeFromTypeNode(<TypeNode>node);
1468314683
return type.symbol;
1468414684

14685+
case SyntaxKind.ThisType:
14686+
return getTypeFromTypeNode(<TypeNode>node).symbol;
14687+
1468514688
case SyntaxKind.ConstructorKeyword:
1468614689
// constructor keyword for an overload, should take us to the definition if it exist
1468714690
const constructorDeclaration = node.parent;

src/compiler/declarationEmitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ namespace ts {
378378
case SyntaxKind.BooleanKeyword:
379379
case SyntaxKind.SymbolKeyword:
380380
case SyntaxKind.VoidKeyword:
381-
case SyntaxKind.ThisKeyword:
381+
case SyntaxKind.ThisType:
382382
case SyntaxKind.StringLiteral:
383383
return writeTextOfNode(currentText, type);
384384
case SyntaxKind.ExpressionWithTypeArguments:

src/compiler/emitter.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,18 +428,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
428428
* var loop = function(x) { <code where 'arguments' is replaced witg 'arguments_1'> }
429429
* var arguments_1 = arguments
430430
* for (var x;;) loop(x);
431-
* otherwise semantics of the code will be different since 'arguments' inside converted loop body
431+
* otherwise semantics of the code will be different since 'arguments' inside converted loop body
432432
* will refer to function that holds converted loop.
433433
* This value is set on demand.
434434
*/
435435
argumentsName?: string;
436436

437437
/*
438438
* list of non-block scoped variable declarations that appear inside converted loop
439-
* such variable declarations should be moved outside the loop body
439+
* such variable declarations should be moved outside the loop body
440440
* for (let x;;) {
441441
* var y = 1;
442-
* ...
442+
* ...
443443
* }
444444
* should be converted to
445445
* var loop = function(x) {
@@ -3229,7 +3229,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
32293229
}
32303230

32313231
if (convertedLoopState && (getCombinedNodeFlags(decl) & NodeFlags.BlockScoped) === 0) {
3232-
// we are inside a converted loop - this can only happen in downlevel scenarios
3232+
// we are inside a converted loop - this can only happen in downlevel scenarios
32333233
// record names for all variable declarations
32343234
for (const varDecl of decl.declarations) {
32353235
hoistVariableDeclarationFromLoop(convertedLoopState, varDecl);
@@ -3554,7 +3554,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
35543554
write(`case "${labelMarker}": `);
35553555
// if there are no outer converted loop or outer label in question is located inside outer converted loop
35563556
// then emit labeled break\continue
3557-
// otherwise propagate pair 'label -> marker' to outer converted loop and emit 'return labelMarker' so outer loop can later decide what to do
3557+
// otherwise propagate pair 'label -> marker' to outer converted loop and emit 'return labelMarker' so outer loop can later decide what to do
35583558
if (!outerLoop || (outerLoop.labels && outerLoop.labels[labelText])) {
35593559
if (isBreak) {
35603560
write("break ");
@@ -6011,6 +6011,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
60116011
case SyntaxKind.UnionType:
60126012
case SyntaxKind.IntersectionType:
60136013
case SyntaxKind.AnyKeyword:
6014+
case SyntaxKind.ThisType:
60146015
break;
60156016

60166017
default:

src/compiler/parser.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1956,6 +1956,12 @@ namespace ts {
19561956
return finishNode(node);
19571957
}
19581958

1959+
function parseThisTypeNode(): TypeNode {
1960+
const node = <TypeNode>createNode(SyntaxKind.ThisType);
1961+
nextToken();
1962+
return finishNode(node);
1963+
}
1964+
19591965
function parseTypeQuery(): TypeQueryNode {
19601966
const node = <TypeQueryNode>createNode(SyntaxKind.TypeQuery);
19611967
parseExpected(SyntaxKind.TypeOfKeyword);
@@ -2388,8 +2394,9 @@ namespace ts {
23882394
case SyntaxKind.StringLiteral:
23892395
return <StringLiteral>parseLiteralNode(/*internName*/ true);
23902396
case SyntaxKind.VoidKeyword:
2391-
case SyntaxKind.ThisKeyword:
23922397
return parseTokenNode<TypeNode>();
2398+
case SyntaxKind.ThisKeyword:
2399+
return parseThisTypeNode();
23932400
case SyntaxKind.TypeOfKeyword:
23942401
return parseTypeQuery();
23952402
case SyntaxKind.OpenBraceToken:

src/compiler/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ namespace ts {
204204
UnionType,
205205
IntersectionType,
206206
ParenthesizedType,
207+
ThisType,
207208
// Binding patterns
208209
ObjectBindingPattern,
209210
ArrayBindingPattern,
@@ -349,7 +350,7 @@ namespace ts {
349350
FirstFutureReservedWord = ImplementsKeyword,
350351
LastFutureReservedWord = YieldKeyword,
351352
FirstTypeNode = TypePredicate,
352-
LastTypeNode = ParenthesizedType,
353+
LastTypeNode = ThisType,
353354
FirstPunctuation = OpenBraceToken,
354355
LastPunctuation = CaretEqualsToken,
355356
FirstToken = Unknown,
@@ -726,6 +727,7 @@ namespace ts {
726727
// @kind(SyntaxKind.StringKeyword)
727728
// @kind(SyntaxKind.SymbolKeyword)
728729
// @kind(SyntaxKind.VoidKeyword)
730+
// @kind(SyntaxKind.ThisType)
729731
export interface TypeNode extends Node {
730732
_typeNodeBrand: any;
731733
}
@@ -1075,7 +1077,6 @@ namespace ts {
10751077
export interface DebuggerStatement extends Statement { }
10761078

10771079
// @kind(SyntaxKind.MissingDeclaration)
1078-
// @factoryhidden("name", true)
10791080
export interface MissingDeclaration extends DeclarationStatement, ClassElement, ObjectLiteralElement, TypeElement {
10801081
name?: Identifier;
10811082
}
@@ -1232,7 +1233,6 @@ namespace ts {
12321233
export interface TypeElement extends Declaration {
12331234
_typeElementBrand: any;
12341235
name?: PropertyName;
1235-
// @factoryparam
12361236
questionToken?: Node;
12371237
}
12381238

src/services/services.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,7 +2320,7 @@ namespace ts {
23202320

23212321
return true;
23222322
}
2323-
2323+
23242324
return false;
23252325
}
23262326

@@ -2339,7 +2339,7 @@ namespace ts {
23392339
}
23402340
return false;
23412341
}
2342-
2342+
23432343
function tryConsumeDefine(): boolean {
23442344
let token = scanner.getToken();
23452345
if (token === SyntaxKind.Identifier && scanner.getTokenValue() === "define") {
@@ -2365,7 +2365,7 @@ namespace ts {
23652365
if (token !== SyntaxKind.OpenBracketToken) {
23662366
return true;
23672367
}
2368-
2368+
23692369
// skip open bracket
23702370
token = scanner.scan();
23712371
let i = 0;
@@ -2380,7 +2380,7 @@ namespace ts {
23802380
token = scanner.scan();
23812381
}
23822382
return true;
2383-
2383+
23842384
}
23852385
return false;
23862386
}
@@ -3985,7 +3985,7 @@ namespace ts {
39853985
let sourceFile = getValidSourceFile(fileName);
39863986

39873987
let entries: CompletionEntry[] = [];
3988-
3988+
39893989
if (isRightOfDot && isSourceFileJavaScript(sourceFile)) {
39903990
const uniqueNames = getCompletionEntriesFromSymbols(symbols, entries);
39913991
addRange(entries, getJavaScriptCompletionEntries(sourceFile, uniqueNames));
@@ -4604,6 +4604,7 @@ namespace ts {
46044604
case SyntaxKind.PropertyAccessExpression:
46054605
case SyntaxKind.QualifiedName:
46064606
case SyntaxKind.ThisKeyword:
4607+
case SyntaxKind.ThisType:
46074608
case SyntaxKind.SuperKeyword:
46084609
// For the identifiers/this/super etc get the type at position
46094610
let type = typeChecker.getTypeAtLocation(node);
@@ -4875,6 +4876,7 @@ namespace ts {
48754876
function getSemanticDocumentHighlights(node: Node): DocumentHighlights[] {
48764877
if (node.kind === SyntaxKind.Identifier ||
48774878
node.kind === SyntaxKind.ThisKeyword ||
4879+
node.kind === SyntaxKind.ThisType ||
48784880
node.kind === SyntaxKind.SuperKeyword ||
48794881
isLiteralNameOfPropertyDeclarationOrIndexAccess(node) ||
48804882
isNameOfExternalModuleImportOrDeclaration(node)) {
@@ -5570,7 +5572,7 @@ namespace ts {
55705572
}
55715573
}
55725574

5573-
if (node.kind === SyntaxKind.ThisKeyword) {
5575+
if (node.kind === SyntaxKind.ThisKeyword || node.kind === SyntaxKind.ThisType) {
55745576
return getReferencesForThisKeyword(node, sourceFiles);
55755577
}
55765578

@@ -6052,7 +6054,7 @@ namespace ts {
60526054
cancellationToken.throwIfCancellationRequested();
60536055

60546056
let node = getTouchingWord(sourceFile, position);
6055-
if (!node || node.kind !== SyntaxKind.ThisKeyword) {
6057+
if (!node || (node.kind !== SyntaxKind.ThisKeyword && node.kind !== SyntaxKind.ThisType)) {
60566058
return;
60576059
}
60586060

@@ -6414,7 +6416,8 @@ namespace ts {
64146416

64156417
return node.parent.kind === SyntaxKind.TypeReference ||
64166418
(node.parent.kind === SyntaxKind.ExpressionWithTypeArguments && !isExpressionWithTypeArgumentsInClassExtendsClause(<ExpressionWithTypeArguments>node.parent)) ||
6417-
node.kind === SyntaxKind.ThisKeyword && !isExpression(node);
6419+
(node.kind === SyntaxKind.ThisKeyword && !isExpression(node)) ||
6420+
node.kind === SyntaxKind.ThisType;
64186421
}
64196422

64206423
function isNamespaceReference(node: Node): boolean {
@@ -6534,6 +6537,7 @@ namespace ts {
65346537
case SyntaxKind.NullKeyword:
65356538
case SyntaxKind.SuperKeyword:
65366539
case SyntaxKind.ThisKeyword:
6540+
case SyntaxKind.ThisType:
65376541
case SyntaxKind.Identifier:
65386542
break;
65396543

tests/baselines/reference/decoratorMetadata.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ declare var decorator: any;
1212
class MyComponent {
1313
constructor(public Service: Service) {
1414
}
15+
16+
@decorator
17+
method(x: this) {
18+
}
1519
}
1620

1721
//// [service.js]
@@ -37,6 +41,14 @@ var MyComponent = (function () {
3741
function MyComponent(Service) {
3842
this.Service = Service;
3943
}
44+
MyComponent.prototype.method = function (x) {
45+
};
46+
__decorate([
47+
decorator,
48+
__metadata('design:type', Function),
49+
__metadata('design:paramtypes', [Object]),
50+
__metadata('design:returntype', void 0)
51+
], MyComponent.prototype, "method", null);
4052
MyComponent = __decorate([
4153
decorator,
4254
__metadata('design:paramtypes', [service_1.default])

tests/baselines/reference/decoratorMetadata.symbols

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,12 @@ class MyComponent {
1919
>Service : Symbol(Service, Decl(component.ts, 6, 16))
2020
>Service : Symbol(Service, Decl(component.ts, 0, 6))
2121
}
22+
23+
@decorator
24+
>decorator : Symbol(decorator, Decl(component.ts, 2, 11))
25+
26+
method(x: this) {
27+
>method : Symbol(method, Decl(component.ts, 7, 5))
28+
>x : Symbol(x, Decl(component.ts, 10, 11))
29+
}
2230
}

tests/baselines/reference/decoratorMetadata.types

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,12 @@ class MyComponent {
1919
>Service : Service
2020
>Service : Service
2121
}
22+
23+
@decorator
24+
>decorator : any
25+
26+
method(x: this) {
27+
>method : (x: this) => void
28+
>x : this
29+
}
2230
}

tests/baselines/reference/thisTypeInClasses.symbols

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ class C5 {
9292
let f1 = (x: this): this => this;
9393
>f1 : Symbol(f1, Decl(thisTypeInClasses.ts, 34, 11))
9494
>x : Symbol(x, Decl(thisTypeInClasses.ts, 34, 18))
95-
>this : Symbol(C5, Decl(thisTypeInClasses.ts, 30, 1))
9695
>this : Symbol(C5, Decl(thisTypeInClasses.ts, 30, 1))
9796

9897
let f2 = (x: this) => this;

tests/baselines/reference/thisTypeInClasses.types

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ class C5 {
9393
>f1 : (x: this) => this
9494
>(x: this): this => this : (x: this) => this
9595
>x : this
96-
>this : this
9796
>this : this
9897

9998
let f2 = (x: this) => this;

tests/cases/conformance/decorators/decoratorMetadata.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ declare var decorator: any;
1414
class MyComponent {
1515
constructor(public Service: Service) {
1616
}
17+
18+
@decorator
19+
method(x: this) {
20+
}
1721
}

0 commit comments

Comments
 (0)