Merge pull request #5719 from Microsoft/typesCleanup2

Additional Types cleanup.
This commit is contained in:
Ron Buckton 2015-11-19 15:32:28 -08:00
commit 7d6100bbe8
13 changed files with 72 additions and 27 deletions

View file

@ -196,7 +196,7 @@ namespace ts {
} }
if (node.name.kind === SyntaxKind.ComputedPropertyName) { if (node.name.kind === SyntaxKind.ComputedPropertyName) {
const nameExpression = (<ComputedPropertyName>node.name).expression; const nameExpression = (<ComputedPropertyName>node.name).expression;
// treat computed property names where expression is string/numeric literal as just string/numeric literal // treat computed property names where expression is string/numeric literal as just string/numeric literal
if (isStringOrNumericLiteral(nameExpression.kind)) { if (isStringOrNumericLiteral(nameExpression.kind)) {
return (<LiteralExpression>nameExpression).text; return (<LiteralExpression>nameExpression).text;
} }
@ -457,7 +457,7 @@ namespace ts {
/** /**
* Returns true if node and its subnodes were successfully traversed. * Returns true if node and its subnodes were successfully traversed.
* Returning false means that node was not examined and caller needs to dive into the node himself. * Returning false means that node was not examined and caller needs to dive into the node himself.
*/ */
function bindReachableStatement(node: Node): void { function bindReachableStatement(node: Node): void {
if (checkUnreachable(node)) { if (checkUnreachable(node)) {
@ -567,7 +567,7 @@ namespace ts {
} }
function bindIfStatement(n: IfStatement): void { function bindIfStatement(n: IfStatement): void {
// denotes reachability state when entering 'thenStatement' part of the if statement: // denotes reachability state when entering 'thenStatement' part of the if statement:
// i.e. if condition is false then thenStatement is unreachable // i.e. if condition is false then thenStatement is unreachable
const ifTrueState = n.expression.kind === SyntaxKind.FalseKeyword ? Reachability.Unreachable : currentReachabilityState; const ifTrueState = n.expression.kind === SyntaxKind.FalseKeyword ? Reachability.Unreachable : currentReachabilityState;
// denotes reachability state when entering 'elseStatement': // denotes reachability state when entering 'elseStatement':
@ -1186,7 +1186,7 @@ namespace ts {
return checkStrictModePrefixUnaryExpression(<PrefixUnaryExpression>node); return checkStrictModePrefixUnaryExpression(<PrefixUnaryExpression>node);
case SyntaxKind.WithStatement: case SyntaxKind.WithStatement:
return checkStrictModeWithStatement(<WithStatement>node); return checkStrictModeWithStatement(<WithStatement>node);
case SyntaxKind.ThisKeyword: case SyntaxKind.ThisType:
seenThisKeyword = true; seenThisKeyword = true;
return; return;
@ -1535,7 +1535,7 @@ namespace ts {
// unreachable code is reported if // unreachable code is reported if
// - user has explicitly asked about it AND // - user has explicitly asked about it AND
// - statement is in not ambient context (statements in ambient context is already an error // - statement is in not ambient context (statements in ambient context is already an error
// so we should not report extras) AND // so we should not report extras) AND
// - node is not variable statement OR // - node is not variable statement OR
// - node is block scoped variable statement OR // - node is block scoped variable statement OR

View file

@ -4585,7 +4585,7 @@ namespace ts {
return esSymbolType; return esSymbolType;
case SyntaxKind.VoidKeyword: case SyntaxKind.VoidKeyword:
return voidType; return voidType;
case SyntaxKind.ThisKeyword: case SyntaxKind.ThisType:
return getTypeFromThisTypeNode(node); return getTypeFromThisTypeNode(node);
case SyntaxKind.StringLiteral: case SyntaxKind.StringLiteral:
return getTypeFromStringLiteral(<StringLiteral>node); return getTypeFromStringLiteral(<StringLiteral>node);
@ -10208,7 +10208,7 @@ namespace ts {
checkDestructuringAssignment(<ShorthandPropertyAssignment>p, type); checkDestructuringAssignment(<ShorthandPropertyAssignment>p, type);
} }
else { else {
// non-shorthand property assignments should always have initializers // non-shorthand property assignments should always have initializers
checkDestructuringAssignment((<PropertyAssignment>p).initializer, type); checkDestructuringAssignment((<PropertyAssignment>p).initializer, type);
} }
} }
@ -14682,6 +14682,9 @@ namespace ts {
const type = isExpression(node) ? checkExpression(<Expression>node) : getTypeFromTypeNode(<TypeNode>node); const type = isExpression(node) ? checkExpression(<Expression>node) : getTypeFromTypeNode(<TypeNode>node);
return type.symbol; return type.symbol;
case SyntaxKind.ThisType:
return getTypeFromTypeNode(<TypeNode>node).symbol;
case SyntaxKind.ConstructorKeyword: case SyntaxKind.ConstructorKeyword:
// constructor keyword for an overload, should take us to the definition if it exist // constructor keyword for an overload, should take us to the definition if it exist
const constructorDeclaration = node.parent; const constructorDeclaration = node.parent;

View file

@ -378,7 +378,7 @@ namespace ts {
case SyntaxKind.BooleanKeyword: case SyntaxKind.BooleanKeyword:
case SyntaxKind.SymbolKeyword: case SyntaxKind.SymbolKeyword:
case SyntaxKind.VoidKeyword: case SyntaxKind.VoidKeyword:
case SyntaxKind.ThisKeyword: case SyntaxKind.ThisType:
case SyntaxKind.StringLiteral: case SyntaxKind.StringLiteral:
return writeTextOfNode(currentText, type); return writeTextOfNode(currentText, type);
case SyntaxKind.ExpressionWithTypeArguments: case SyntaxKind.ExpressionWithTypeArguments:

View file

@ -428,7 +428,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
* var loop = function(x) { <code where 'arguments' is replaced witg 'arguments_1'> } * var loop = function(x) { <code where 'arguments' is replaced witg 'arguments_1'> }
* var arguments_1 = arguments * var arguments_1 = arguments
* for (var x;;) loop(x); * for (var x;;) loop(x);
* otherwise semantics of the code will be different since 'arguments' inside converted loop body * otherwise semantics of the code will be different since 'arguments' inside converted loop body
* will refer to function that holds converted loop. * will refer to function that holds converted loop.
* This value is set on demand. * This value is set on demand.
*/ */
@ -436,10 +436,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
/* /*
* list of non-block scoped variable declarations that appear inside converted loop * list of non-block scoped variable declarations that appear inside converted loop
* such variable declarations should be moved outside the loop body * such variable declarations should be moved outside the loop body
* for (let x;;) { * for (let x;;) {
* var y = 1; * var y = 1;
* ... * ...
* } * }
* should be converted to * should be converted to
* var loop = function(x) { * var loop = function(x) {
@ -3229,7 +3229,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
} }
if (convertedLoopState && (getCombinedNodeFlags(decl) & NodeFlags.BlockScoped) === 0) { if (convertedLoopState && (getCombinedNodeFlags(decl) & NodeFlags.BlockScoped) === 0) {
// we are inside a converted loop - this can only happen in downlevel scenarios // we are inside a converted loop - this can only happen in downlevel scenarios
// record names for all variable declarations // record names for all variable declarations
for (const varDecl of decl.declarations) { for (const varDecl of decl.declarations) {
hoistVariableDeclarationFromLoop(convertedLoopState, varDecl); hoistVariableDeclarationFromLoop(convertedLoopState, varDecl);
@ -3554,7 +3554,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
write(`case "${labelMarker}": `); write(`case "${labelMarker}": `);
// if there are no outer converted loop or outer label in question is located inside outer converted loop // if there are no outer converted loop or outer label in question is located inside outer converted loop
// then emit labeled break\continue // then emit labeled break\continue
// otherwise propagate pair 'label -> marker' to outer converted loop and emit 'return labelMarker' so outer loop can later decide what to do // otherwise propagate pair 'label -> marker' to outer converted loop and emit 'return labelMarker' so outer loop can later decide what to do
if (!outerLoop || (outerLoop.labels && outerLoop.labels[labelText])) { if (!outerLoop || (outerLoop.labels && outerLoop.labels[labelText])) {
if (isBreak) { if (isBreak) {
write("break "); write("break ");
@ -6011,6 +6011,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
case SyntaxKind.UnionType: case SyntaxKind.UnionType:
case SyntaxKind.IntersectionType: case SyntaxKind.IntersectionType:
case SyntaxKind.AnyKeyword: case SyntaxKind.AnyKeyword:
case SyntaxKind.ThisType:
break; break;
default: default:

View file

@ -1956,6 +1956,12 @@ namespace ts {
return finishNode(node); return finishNode(node);
} }
function parseThisTypeNode(): TypeNode {
const node = <TypeNode>createNode(SyntaxKind.ThisType);
nextToken();
return finishNode(node);
}
function parseTypeQuery(): TypeQueryNode { function parseTypeQuery(): TypeQueryNode {
const node = <TypeQueryNode>createNode(SyntaxKind.TypeQuery); const node = <TypeQueryNode>createNode(SyntaxKind.TypeQuery);
parseExpected(SyntaxKind.TypeOfKeyword); parseExpected(SyntaxKind.TypeOfKeyword);
@ -2388,8 +2394,9 @@ namespace ts {
case SyntaxKind.StringLiteral: case SyntaxKind.StringLiteral:
return <StringLiteral>parseLiteralNode(/*internName*/ true); return <StringLiteral>parseLiteralNode(/*internName*/ true);
case SyntaxKind.VoidKeyword: case SyntaxKind.VoidKeyword:
case SyntaxKind.ThisKeyword:
return parseTokenNode<TypeNode>(); return parseTokenNode<TypeNode>();
case SyntaxKind.ThisKeyword:
return parseThisTypeNode();
case SyntaxKind.TypeOfKeyword: case SyntaxKind.TypeOfKeyword:
return parseTypeQuery(); return parseTypeQuery();
case SyntaxKind.OpenBraceToken: case SyntaxKind.OpenBraceToken:

View file

@ -204,6 +204,7 @@ namespace ts {
UnionType, UnionType,
IntersectionType, IntersectionType,
ParenthesizedType, ParenthesizedType,
ThisType,
// Binding patterns // Binding patterns
ObjectBindingPattern, ObjectBindingPattern,
ArrayBindingPattern, ArrayBindingPattern,
@ -349,7 +350,7 @@ namespace ts {
FirstFutureReservedWord = ImplementsKeyword, FirstFutureReservedWord = ImplementsKeyword,
LastFutureReservedWord = YieldKeyword, LastFutureReservedWord = YieldKeyword,
FirstTypeNode = TypePredicate, FirstTypeNode = TypePredicate,
LastTypeNode = ParenthesizedType, LastTypeNode = ThisType,
FirstPunctuation = OpenBraceToken, FirstPunctuation = OpenBraceToken,
LastPunctuation = CaretEqualsToken, LastPunctuation = CaretEqualsToken,
FirstToken = Unknown, FirstToken = Unknown,
@ -726,6 +727,7 @@ namespace ts {
// @kind(SyntaxKind.StringKeyword) // @kind(SyntaxKind.StringKeyword)
// @kind(SyntaxKind.SymbolKeyword) // @kind(SyntaxKind.SymbolKeyword)
// @kind(SyntaxKind.VoidKeyword) // @kind(SyntaxKind.VoidKeyword)
// @kind(SyntaxKind.ThisType)
export interface TypeNode extends Node { export interface TypeNode extends Node {
_typeNodeBrand: any; _typeNodeBrand: any;
} }
@ -1075,7 +1077,6 @@ namespace ts {
export interface DebuggerStatement extends Statement { } export interface DebuggerStatement extends Statement { }
// @kind(SyntaxKind.MissingDeclaration) // @kind(SyntaxKind.MissingDeclaration)
// @factoryhidden("name", true)
export interface MissingDeclaration extends DeclarationStatement, ClassElement, ObjectLiteralElement, TypeElement { export interface MissingDeclaration extends DeclarationStatement, ClassElement, ObjectLiteralElement, TypeElement {
name?: Identifier; name?: Identifier;
} }
@ -1232,7 +1233,6 @@ namespace ts {
export interface TypeElement extends Declaration { export interface TypeElement extends Declaration {
_typeElementBrand: any; _typeElementBrand: any;
name?: PropertyName; name?: PropertyName;
// @factoryparam
questionToken?: Node; questionToken?: Node;
} }

View file

@ -2320,7 +2320,7 @@ namespace ts {
return true; return true;
} }
return false; return false;
} }
@ -2339,7 +2339,7 @@ namespace ts {
} }
return false; return false;
} }
function tryConsumeDefine(): boolean { function tryConsumeDefine(): boolean {
let token = scanner.getToken(); let token = scanner.getToken();
if (token === SyntaxKind.Identifier && scanner.getTokenValue() === "define") { if (token === SyntaxKind.Identifier && scanner.getTokenValue() === "define") {
@ -2365,7 +2365,7 @@ namespace ts {
if (token !== SyntaxKind.OpenBracketToken) { if (token !== SyntaxKind.OpenBracketToken) {
return true; return true;
} }
// skip open bracket // skip open bracket
token = scanner.scan(); token = scanner.scan();
let i = 0; let i = 0;
@ -2380,7 +2380,7 @@ namespace ts {
token = scanner.scan(); token = scanner.scan();
} }
return true; return true;
} }
return false; return false;
} }
@ -3985,7 +3985,7 @@ namespace ts {
let sourceFile = getValidSourceFile(fileName); let sourceFile = getValidSourceFile(fileName);
let entries: CompletionEntry[] = []; let entries: CompletionEntry[] = [];
if (isRightOfDot && isSourceFileJavaScript(sourceFile)) { if (isRightOfDot && isSourceFileJavaScript(sourceFile)) {
const uniqueNames = getCompletionEntriesFromSymbols(symbols, entries); const uniqueNames = getCompletionEntriesFromSymbols(symbols, entries);
addRange(entries, getJavaScriptCompletionEntries(sourceFile, uniqueNames)); addRange(entries, getJavaScriptCompletionEntries(sourceFile, uniqueNames));
@ -4604,6 +4604,7 @@ namespace ts {
case SyntaxKind.PropertyAccessExpression: case SyntaxKind.PropertyAccessExpression:
case SyntaxKind.QualifiedName: case SyntaxKind.QualifiedName:
case SyntaxKind.ThisKeyword: case SyntaxKind.ThisKeyword:
case SyntaxKind.ThisType:
case SyntaxKind.SuperKeyword: case SyntaxKind.SuperKeyword:
// For the identifiers/this/super etc get the type at position // For the identifiers/this/super etc get the type at position
let type = typeChecker.getTypeAtLocation(node); let type = typeChecker.getTypeAtLocation(node);
@ -4875,6 +4876,7 @@ namespace ts {
function getSemanticDocumentHighlights(node: Node): DocumentHighlights[] { function getSemanticDocumentHighlights(node: Node): DocumentHighlights[] {
if (node.kind === SyntaxKind.Identifier || if (node.kind === SyntaxKind.Identifier ||
node.kind === SyntaxKind.ThisKeyword || node.kind === SyntaxKind.ThisKeyword ||
node.kind === SyntaxKind.ThisType ||
node.kind === SyntaxKind.SuperKeyword || node.kind === SyntaxKind.SuperKeyword ||
isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || isLiteralNameOfPropertyDeclarationOrIndexAccess(node) ||
isNameOfExternalModuleImportOrDeclaration(node)) { isNameOfExternalModuleImportOrDeclaration(node)) {
@ -5570,7 +5572,7 @@ namespace ts {
} }
} }
if (node.kind === SyntaxKind.ThisKeyword) { if (node.kind === SyntaxKind.ThisKeyword || node.kind === SyntaxKind.ThisType) {
return getReferencesForThisKeyword(node, sourceFiles); return getReferencesForThisKeyword(node, sourceFiles);
} }
@ -6052,7 +6054,7 @@ namespace ts {
cancellationToken.throwIfCancellationRequested(); cancellationToken.throwIfCancellationRequested();
let node = getTouchingWord(sourceFile, position); let node = getTouchingWord(sourceFile, position);
if (!node || node.kind !== SyntaxKind.ThisKeyword) { if (!node || (node.kind !== SyntaxKind.ThisKeyword && node.kind !== SyntaxKind.ThisType)) {
return; return;
} }
@ -6414,7 +6416,8 @@ namespace ts {
return node.parent.kind === SyntaxKind.TypeReference || return node.parent.kind === SyntaxKind.TypeReference ||
(node.parent.kind === SyntaxKind.ExpressionWithTypeArguments && !isExpressionWithTypeArgumentsInClassExtendsClause(<ExpressionWithTypeArguments>node.parent)) || (node.parent.kind === SyntaxKind.ExpressionWithTypeArguments && !isExpressionWithTypeArgumentsInClassExtendsClause(<ExpressionWithTypeArguments>node.parent)) ||
node.kind === SyntaxKind.ThisKeyword && !isExpression(node); (node.kind === SyntaxKind.ThisKeyword && !isExpression(node)) ||
node.kind === SyntaxKind.ThisType;
} }
function isNamespaceReference(node: Node): boolean { function isNamespaceReference(node: Node): boolean {
@ -6534,6 +6537,7 @@ namespace ts {
case SyntaxKind.NullKeyword: case SyntaxKind.NullKeyword:
case SyntaxKind.SuperKeyword: case SyntaxKind.SuperKeyword:
case SyntaxKind.ThisKeyword: case SyntaxKind.ThisKeyword:
case SyntaxKind.ThisType:
case SyntaxKind.Identifier: case SyntaxKind.Identifier:
break; break;

View file

@ -12,6 +12,10 @@ declare var decorator: any;
class MyComponent { class MyComponent {
constructor(public Service: Service) { constructor(public Service: Service) {
} }
@decorator
method(x: this) {
}
} }
//// [service.js] //// [service.js]
@ -37,6 +41,14 @@ var MyComponent = (function () {
function MyComponent(Service) { function MyComponent(Service) {
this.Service = Service; this.Service = Service;
} }
MyComponent.prototype.method = function (x) {
};
__decorate([
decorator,
__metadata('design:type', Function),
__metadata('design:paramtypes', [Object]),
__metadata('design:returntype', void 0)
], MyComponent.prototype, "method", null);
MyComponent = __decorate([ MyComponent = __decorate([
decorator, decorator,
__metadata('design:paramtypes', [service_1.default]) __metadata('design:paramtypes', [service_1.default])

View file

@ -19,4 +19,12 @@ class MyComponent {
>Service : Symbol(Service, Decl(component.ts, 6, 16)) >Service : Symbol(Service, Decl(component.ts, 6, 16))
>Service : Symbol(Service, Decl(component.ts, 0, 6)) >Service : Symbol(Service, Decl(component.ts, 0, 6))
} }
@decorator
>decorator : Symbol(decorator, Decl(component.ts, 2, 11))
method(x: this) {
>method : Symbol(method, Decl(component.ts, 7, 5))
>x : Symbol(x, Decl(component.ts, 10, 11))
}
} }

View file

@ -19,4 +19,12 @@ class MyComponent {
>Service : Service >Service : Service
>Service : Service >Service : Service
} }
@decorator
>decorator : any
method(x: this) {
>method : (x: this) => void
>x : this
}
} }

View file

@ -92,7 +92,6 @@ class C5 {
let f1 = (x: this): this => this; let f1 = (x: this): this => this;
>f1 : Symbol(f1, Decl(thisTypeInClasses.ts, 34, 11)) >f1 : Symbol(f1, Decl(thisTypeInClasses.ts, 34, 11))
>x : Symbol(x, Decl(thisTypeInClasses.ts, 34, 18)) >x : Symbol(x, Decl(thisTypeInClasses.ts, 34, 18))
>this : Symbol(C5, Decl(thisTypeInClasses.ts, 30, 1))
>this : Symbol(C5, Decl(thisTypeInClasses.ts, 30, 1)) >this : Symbol(C5, Decl(thisTypeInClasses.ts, 30, 1))
let f2 = (x: this) => this; let f2 = (x: this) => this;

View file

@ -93,7 +93,6 @@ class C5 {
>f1 : (x: this) => this >f1 : (x: this) => this
>(x: this): this => this : (x: this) => this >(x: this): this => this : (x: this) => this
>x : this >x : this
>this : this
>this : this >this : this
let f2 = (x: this) => this; let f2 = (x: this) => this;

View file

@ -14,4 +14,8 @@ declare var decorator: any;
class MyComponent { class MyComponent {
constructor(public Service: Service) { constructor(public Service: Service) {
} }
@decorator
method(x: this) {
}
} }