From df91ef0b382464c7c05419ffb2d35b50252a3a3a Mon Sep 17 00:00:00 2001 From: zhengbli Date: Mon, 28 Mar 2016 12:37:37 -0700 Subject: [PATCH 01/61] Simple case and scoping --- src/compiler/binder.ts | 14 +++-- src/compiler/checker.ts | 24 +++++--- src/compiler/diagnosticMessages.json | 4 ++ src/compiler/parser.ts | 86 +++++++++++++++++++++++----- src/compiler/types.ts | 29 +++++++++- 5 files changed, 130 insertions(+), 27 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 6957be484f3..881ad81cb2e 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -404,6 +404,13 @@ namespace ts { // This node will now be set as the parent of all of its children as we recurse into them. parent = node; + // Binding of JsDocComment should be done before the current block scope container changes. + // because the scope of JsDocComment should not be affected by whether the current node is a + // container or not. + if (isInJavaScriptFile(node) && node.jsDocComment) { + bind(node.jsDocComment); + } + // Depending on what kind of node this is, we may have to adjust the current container // and block-container. If the current node is a container, then it is automatically // considered the current block-container as well. Also, for containers that we know @@ -468,10 +475,6 @@ namespace ts { labelStack = labelIndexMap = implicitLabels = undefined; } - if (isInJavaScriptFile(node) && node.jsDocComment) { - bind(node.jsDocComment); - } - bindReachableStatement(node); if (currentReachabilityState === Reachability.Reachable && isFunctionLikeKind(kind) && nodeIsPresent((node).body)) { @@ -857,7 +860,7 @@ namespace ts { // their container in the tree. To accomplish this, we simply add their declared // symbol to the 'locals' of the container. These symbols can then be found as // the type checker walks up the containers, checking them for matching names. - return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); + return declareSymbol(container.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes); } } @@ -1343,6 +1346,7 @@ namespace ts { return bindClassLikeDeclaration(node); case SyntaxKind.InterfaceDeclaration: return bindBlockScopedDeclaration(node, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes); + case SyntaxKind.JSDocTypedefTag: case SyntaxKind.TypeAliasDeclaration: return bindBlockScopedDeclaration(node, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes); case SyntaxKind.EnumDeclaration: diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9509c286236..ff416ec2cc5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3403,7 +3403,7 @@ namespace ts { return links.declaredType; } - function getDeclaredTypeOfTypeAlias(symbol: Symbol): Type { + function getDeclaredTypeOfTypeAlias(symbol: Symbol, node?: Node): Type { const links = getSymbolLinks(symbol); if (!links.declaredType) { // Note that we use the links object as the target here because the symbol object is used as the unique @@ -3411,8 +3411,18 @@ namespace ts { if (!pushTypeResolution(symbol, TypeSystemPropertyName.DeclaredType)) { return unknownType; } - const declaration = getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration); - let type = getTypeFromTypeNode(declaration.type); + + let typeNode: TypeNode; + let name: Identifier; + if (node && (node.flags & NodeFlags.JavaScriptFile)) { + const declaration = getDeclarationOfKind(symbol, SyntaxKind.JSDocTypedefTag); + typeNode = declaration.typeExpression.type; + } + if (!typeNode) { + const declaration = getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration); + typeNode = declaration.type; + } + let type = getTypeFromTypeNode(typeNode); if (popTypeResolution()) { links.typeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol); if (links.typeParameters) { @@ -3424,7 +3434,7 @@ namespace ts { } else { type = unknownType; - error(declaration.name, Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol)); + error(name, Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol)); } links.declaredType = type; } @@ -3462,13 +3472,13 @@ namespace ts { return links.declaredType; } - function getDeclaredTypeOfSymbol(symbol: Symbol): Type { + function getDeclaredTypeOfSymbol(symbol: Symbol, node?: Node): Type { Debug.assert((symbol.flags & SymbolFlags.Instantiated) === 0); if (symbol.flags & (SymbolFlags.Class | SymbolFlags.Interface)) { return getDeclaredTypeOfClassOrInterface(symbol); } if (symbol.flags & SymbolFlags.TypeAlias) { - return getDeclaredTypeOfTypeAlias(symbol); + return getDeclaredTypeOfTypeAlias(symbol, node); } if (symbol.flags & SymbolFlags.Enum) { return getDeclaredTypeOfEnum(symbol); @@ -4564,7 +4574,7 @@ namespace ts { // references to the type parameters of the alias. We replace those with the actual type arguments by instantiating the // declared type. Instantiations are cached using the type identities of the type arguments as the key. function getTypeFromTypeAliasReference(node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference, symbol: Symbol): Type { - const type = getDeclaredTypeOfSymbol(symbol); + const type = getDeclaredTypeOfSymbol(symbol, node); const links = getSymbolLinks(symbol); const typeParameters = links.typeParameters; if (typeParameters) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index d7c2fac2710..c887a9c7112 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -811,6 +811,10 @@ "category": "Error", "code": 1249 }, + "'{0}' tag cannot be used independently as a top level JSDoc tag.": { + "category": "Error", + "code": 1250 + }, "'with' statements are not allowed in an async function block.": { "category": "Error", "code": 1300 diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b7c011631ee..91f225931d2 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -401,6 +401,8 @@ namespace ts { return visitNode(cbNode, (node).typeExpression); case SyntaxKind.JSDocTemplateTag: return visitNodes(cbNodes, (node).typeParameters); + case SyntaxKind.JSDocTypedefTag: + return visitNode(cbNode, (node).typeExpression); } } @@ -886,7 +888,7 @@ namespace ts { /** Invokes the provided callback then unconditionally restores the parser to the state it * was in immediately prior to invoking the callback. The result of invoking the callback - * is returned from this function. + * is returned from this function. */ function lookAhead(callback: () => T): T { return speculationHelper(callback, /*isLookAhead*/ true); @@ -2068,11 +2070,11 @@ namespace ts { } function fillSignature( - returnToken: SyntaxKind, - yieldContext: boolean, - awaitContext: boolean, - requireCompleteParameterList: boolean, - signature: SignatureDeclaration): void { + returnToken: SyntaxKind, + yieldContext: boolean, + awaitContext: boolean, + requireCompleteParameterList: boolean, + signature: SignatureDeclaration): void { const returnTokenRequired = returnToken === SyntaxKind.EqualsGreaterThanToken; signature.typeParameters = parseTypeParameters(); @@ -3341,8 +3343,8 @@ namespace ts { if (sourceFile.languageVariant !== LanguageVariant.JSX) { return false; } - // We are in JSX context and the token is part of JSXElement. - // Fall through + // We are in JSX context and the token is part of JSXElement. + // Fall through default: return true; } @@ -4044,9 +4046,9 @@ namespace ts { const isAsync = !!(node.flags & NodeFlags.Async); node.name = isGenerator && isAsync ? doInYieldAndAwaitContext(parseOptionalIdentifier) : - isGenerator ? doInYieldContext(parseOptionalIdentifier) : - isAsync ? doInAwaitContext(parseOptionalIdentifier) : - parseOptionalIdentifier(); + isGenerator ? doInYieldContext(parseOptionalIdentifier) : + isAsync ? doInAwaitContext(parseOptionalIdentifier) : + parseOptionalIdentifier(); fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, node); node.body = parseFunctionBlock(/*allowYield*/ isGenerator, /*allowAwait*/ isAsync, /*ignoreMissingOpenBrace*/ false); @@ -4984,7 +4986,7 @@ namespace ts { if (token === SyntaxKind.ConstKeyword && permitInvalidConstAsModifier) { // We need to ensure that any subsequent modifiers appear on the same line - // so that when 'const' is a standalone declaration, we don't issue an error. + // so that when 'const' is a standalone declaration, we don't issue an error. if (!tryParse(nextTokenIsOnSameLineAndCanFollowModifier)) { break; } @@ -5247,7 +5249,7 @@ namespace ts { node.decorators = decorators; setModifiers(node, modifiers); if (token === SyntaxKind.GlobalKeyword) { - // parse 'global' as name of global scope augmentation + // parse 'global' as name of global scope augmentation node.name = parseIdentifier(); node.flags |= NodeFlags.GlobalAugmentation; } @@ -5829,7 +5831,7 @@ namespace ts { } function checkForEmptyTypeArgumentList(typeArguments: NodeArray) { - if (parseDiagnostics.length === 0 && typeArguments && typeArguments.length === 0) { + if (parseDiagnostics.length === 0 && typeArguments && typeArguments.length === 0) { const start = typeArguments.pos - "<".length; const end = skipTrivia(sourceText, typeArguments.end) + ">".length; return parseErrorAtPosition(start, end - start, Diagnostics.Type_argument_list_cannot_be_empty); @@ -5990,6 +5992,7 @@ namespace ts { Debug.assert(end <= content.length); let tags: NodeArray; + let currentParentJSDocDeclaration: Declaration; let result: JSDocComment; @@ -6097,6 +6100,11 @@ namespace ts { return handleTemplateTag(atToken, tagName); case "type": return handleTypeTag(atToken, tagName); + case "typedef": + return handleTypedefTag(atToken, tagName); + case "property": + case "prop": + return handlePropertyTag(atToken, tagName); } } @@ -6204,6 +6212,56 @@ namespace ts { return finishNode(result); } + function handlePropertyTag(atToken: Node, tagName: Identifier): JSDocPropertyTag { + if (!currentParentJSDocDeclaration) { + parseErrorAtPosition(tagName.pos, scanner.getTokenPos() - tagName.pos, Diagnostics._0_tag_cannot_be_used_independently_as_a_top_level_JSDoc_tag, tagName.text); + return undefined; + } + + const typeExpression = tryParseTypeExpression(); + skipWhitespace(); + const name = parseJSDocIdentifier(); + if (!name) { + parseErrorAtPosition(scanner.getStartPos(), /*length*/ 0, Diagnostics.Identifier_expected); + return undefined; + } + + const result = createNode(SyntaxKind.JSDocPropertyTag, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.name = name; + result.typeExpression = typeExpression; + return finishNode(result); + } + + function handleTypedefTag(atToken: Node, tagName: Identifier): JSDocTypedefTag { + const typeExpression = tryParseTypeExpression(); + skipWhitespace(); + const name = parseJSDocIdentifier(); + if (!name) { + parseErrorAtPosition(scanner.getStartPos(), 0, Diagnostics.Identifier_expected); + return undefined; + } + + const result = createNode(SyntaxKind.JSDocTypedefTag, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.name = name; + result.typeExpression = typeExpression; + + // if (typeExpression && typeExpression.type.kind === SyntaxKind.JSDocTypeReference) { + // const jsDocTypeReference = typeExpression.type; + // if (jsDocTypeReference.name.kind === SyntaxKind.Identifier) { + // const name = jsDocTypeReference.name; + // if (name.text === "Object") { + // currentParentJSDocDeclaration = declaration; + // } + // } + // } + + return result; + } + function handleTemplateTag(atToken: Node, tagName: Identifier): JSDocTemplateTag { if (forEach(tags, t => t.kind === SyntaxKind.JSDocTemplateTag)) { parseErrorAtPosition(tagName.pos, scanner.getTokenPos() - tagName.pos, Diagnostics._0_tag_already_specified, tagName.text); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 546d1631945..a0cc8d054e1 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -342,6 +342,10 @@ namespace ts { JSDocReturnTag, JSDocTypeTag, JSDocTemplateTag, + JSDocTypedefTag, + JSDocPropertyTag, + JSDocTypedefDeclaration, + JSDocTypeLiteral, // Synthesized list SyntaxList, @@ -1510,6 +1514,29 @@ namespace ts { typeExpression: JSDocTypeExpression; } + // @kind(SyntaxKind.JSDocTypedefTag) + export interface JSDocTypedefTag extends JSDocTag, Declaration { + name: Identifier; + typeExpression: JSDocTypeExpression; + } + + // @kind(SyntaxKind.JSDocPropertyTag) + export interface JSDocPropertyTag extends JSDocTag, TypeElement { + name: Identifier; + typeExpression: JSDocTypeExpression; + } + + // @kind(SyntaxKind.JSDocTypedefDeclaration) + export interface JSDocTypedefDeclaration extends Declaration { + name: Identifier; + type: TypeNode; + } + + // @kind(SyntaxKind.JSDocTypeLiteral) + export interface JSDocTypeLiteral extends TypeNode { + members: NodeArray; + } + // @kind(SyntaxKind.JSDocParameterTag) export interface JSDocParameterTag extends JSDocTag { preParameterName?: Identifier; @@ -2094,7 +2121,7 @@ namespace ts { jsxFlags?: JsxFlags; // flags for knowing what kind of element/attributes we're dealing with resolvedJsxType?: Type; // resolved element attributes type of a JSX openinglike element hasSuperCall?: boolean; // recorded result when we try to find super-call. We only try to find one if this flag is undefined, indicating that we haven't made an attempt. - superCall?: ExpressionStatement; // Cached first super-call found in the constructor. Used in checking whether super is called before this-accessing + superCall?: ExpressionStatement; // Cached first super-call found in the constructor. Used in checking whether super is called before this-accessing } export const enum TypeFlags { From 23bca4eda6b220a88771a6c922842f8da1c3b366 Mon Sep 17 00:00:00 2001 From: Zhengbo Li Date: Mon, 4 Apr 2016 00:44:51 -0700 Subject: [PATCH 02/61] Support the case with @property and @type --- src/compiler/binder.ts | 4 + src/compiler/checker.ts | 16 +- src/compiler/parser.ts | 142 +++++++++++++++--- src/compiler/types.ts | 19 +-- .../fourslash/server/jsdocCompletions.ts | 15 ++ 5 files changed, 160 insertions(+), 36 deletions(-) create mode 100644 tests/cases/fourslash/server/jsdocCompletions.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 881ad81cb2e..b3f163bbef1 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -744,6 +744,7 @@ namespace ts { case SyntaxKind.EnumDeclaration: case SyntaxKind.ObjectLiteralExpression: case SyntaxKind.TypeLiteral: + case SyntaxKind.JSDocTypeLiteral: case SyntaxKind.JSDocRecordType: return ContainerFlags.IsContainer; @@ -832,6 +833,7 @@ namespace ts { case SyntaxKind.ObjectLiteralExpression: case SyntaxKind.InterfaceDeclaration: case SyntaxKind.JSDocRecordType: + case SyntaxKind.JSDocTypeLiteral: // Interface/Object-types always have their children added to the 'members' of // their container. They are only accessible through an instance of their // container, and are never in scope otherwise (even inside the body of the @@ -1294,6 +1296,7 @@ namespace ts { case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: case SyntaxKind.JSDocRecordMember: + case SyntaxKind.JSDocPropertyTag: return bindPropertyOrMethodOrAccessor(node, SymbolFlags.Property | ((node).questionToken ? SymbolFlags.Optional : SymbolFlags.None), SymbolFlags.PropertyExcludes); case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: @@ -1326,6 +1329,7 @@ namespace ts { case SyntaxKind.JSDocFunctionType: return bindFunctionOrConstructorType(node); case SyntaxKind.TypeLiteral: + case SyntaxKind.JSDocTypeLiteral: case SyntaxKind.JSDocRecordType: return bindAnonymousDeclaration(node, SymbolFlags.TypeLiteral, "__type"); case SyntaxKind.ObjectLiteralExpression: diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ff416ec2cc5..e66e5e6a9d8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3412,17 +3412,14 @@ namespace ts { return unknownType; } - let typeNode: TypeNode; - let name: Identifier; + let declaration: JSDocTypedefTag | TypeAliasDeclaration; if (node && (node.flags & NodeFlags.JavaScriptFile)) { - const declaration = getDeclarationOfKind(symbol, SyntaxKind.JSDocTypedefTag); - typeNode = declaration.typeExpression.type; + declaration = getDeclarationOfKind(symbol, SyntaxKind.JSDocTypedefTag); } - if (!typeNode) { - const declaration = getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration); - typeNode = declaration.type; + if (!declaration) { + declaration = getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration); } - let type = getTypeFromTypeNode(typeNode); + let type = getTypeFromTypeNode(declaration.type); if (popTypeResolution()) { links.typeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol); if (links.typeParameters) { @@ -3434,7 +3431,7 @@ namespace ts { } else { type = unknownType; - error(name, Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol)); + error(declaration.name, Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol)); } links.declaredType = type; } @@ -5067,6 +5064,7 @@ namespace ts { case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: case SyntaxKind.TypeLiteral: + case SyntaxKind.JSDocTypeLiteral: case SyntaxKind.JSDocFunctionType: case SyntaxKind.JSDocRecordType: return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 91f225931d2..5de1369ee09 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -402,7 +402,15 @@ namespace ts { case SyntaxKind.JSDocTemplateTag: return visitNodes(cbNodes, (node).typeParameters); case SyntaxKind.JSDocTypedefTag: - return visitNode(cbNode, (node).typeExpression); + return visitNode(cbNode, (node).name) || + visitNode(cbNode, (node).typeExpression) || + visitNode(cbNode, (node).type); + case SyntaxKind.JSDocTypeLiteral: + return visitNodes(cbNodes, (node).members); + case SyntaxKind.JSDocPropertyTag: + return visitNode(cbNode, (node).name) || + visitNode(cbNode, (node).typeExpression) || + visitNode(cbNode, (node).type); } } @@ -5992,7 +6000,8 @@ namespace ts { Debug.assert(end <= content.length); let tags: NodeArray; - let currentParentJSDocDeclaration: Declaration; + let currentParentJSDocTag: JSDocParentTag; + let currentParentJSDocTagEnd: number; let result: JSDocComment; @@ -6050,6 +6059,10 @@ namespace ts { nextJSDocToken(); } + if (currentParentJSDocTag) { + finishCurrentParentTag(); + } + result = createJSDocComment(); }); @@ -6073,6 +6086,40 @@ namespace ts { } } + function finishCurrentParentTag(): void { + if (!currentParentJSDocTag) { + return; + } + + if (currentParentJSDocTag.kind === SyntaxKind.JSDocTypedefTag) { + const typedefTag = currentParentJSDocTag; + if (typedefTag.jsDocTypeTag) { + if (typedefTag.jsDocTypeTag.typeExpression.type.kind === SyntaxKind.JSDocTypeReference) { + const typeTagtype = typedefTag.jsDocTypeTag.typeExpression.type; + if ((typeTagtype.name.kind !== SyntaxKind.Identifier) || + (typeTagtype.name).text !== "Object") { + typedefTag.type = typedefTag.jsDocTypeTag.typeExpression.type; + } + } + else { + typedefTag.type = typedefTag.jsDocTypeTag.typeExpression.type; + } + } + if (!typedefTag.type) { + const tagType = createNode(SyntaxKind.JSDocTypeLiteral, currentParentJSDocTag.pos); + if (typedefTag.jsDocPropertyTags){ + tagType.members = >[]; + addRange(tagType.members, typedefTag.jsDocPropertyTags); + } + typedefTag.type = finishNode(tagType, currentParentJSDocTagEnd); + } + } + + addTag(finishNode(currentParentJSDocTag, currentParentJSDocTagEnd)); + currentParentJSDocTag = undefined; + currentParentJSDocTagEnd = undefined; + } + function parseTag(): void { Debug.assert(token === SyntaxKind.AtToken); const atToken = createNode(SyntaxKind.AtToken, scanner.getTokenPos()); @@ -6085,22 +6132,30 @@ namespace ts { } const tag = handleTag(atToken, tagName) || handleUnknownTag(atToken, tagName); - addTag(tag); + if (!currentParentJSDocTag) { + addTag(tag); + } } function handleTag(atToken: Node, tagName: Identifier): JSDocTag { if (tagName) { switch (tagName.text) { case "param": + finishCurrentParentTag(); return handleParamTag(atToken, tagName); case "return": case "returns": + finishCurrentParentTag(); return handleReturnTag(atToken, tagName); case "template": + finishCurrentParentTag(); return handleTemplateTag(atToken, tagName); case "type": + // @typedef tag is allowed to have one @type tag, therefore seeing + // a @type tag may not indicate the end of the current parent tag. return handleTypeTag(atToken, tagName); case "typedef": + finishCurrentParentTag(); return handleTypedefTag(atToken, tagName); case "property": case "prop": @@ -6130,6 +6185,25 @@ namespace ts { } } + function addToCurrentParentTag(tag: JSDocTag): void { + if (!currentParentJSDocTag) { + return; + } + switch (tag.kind) { + case SyntaxKind.JSDocPropertyTag: + if (!currentParentJSDocTag.jsDocPropertyTags) { + currentParentJSDocTag.jsDocPropertyTags = >[]; + } + currentParentJSDocTag.jsDocPropertyTags.push(tag); + break; + case SyntaxKind.JSDocTypeTag: + if (!currentParentJSDocTag.jsDocTypeTag) { + currentParentJSDocTag.jsDocTypeTag = tag; + } + break; + } + } + function tryParseTypeExpression(): JSDocTypeExpression { if (token !== SyntaxKind.OpenBraceToken) { return undefined; @@ -6205,15 +6279,33 @@ namespace ts { parseErrorAtPosition(tagName.pos, scanner.getTokenPos() - tagName.pos, Diagnostics._0_tag_already_specified, tagName.text); } - const result = createNode(SyntaxKind.JSDocTypeTag, atToken.pos); + let result = createNode(SyntaxKind.JSDocTypeTag, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.typeExpression = tryParseTypeExpression(); - return finishNode(result); + result = finishNode(result); + + let typeTagPartOfParentTag = false; + if (currentParentJSDocTag && currentParentJSDocTag.kind === SyntaxKind.JSDocTypedefTag) { + const parentTag = currentParentJSDocTag; + if (!parentTag.typeExpression && !parentTag.jsDocTypeTag) { + typeTagPartOfParentTag = true; + parentTag.jsDocTypeTag = result; + currentParentJSDocTagEnd = scanner.getStartPos(); + } + } + if (!typeTagPartOfParentTag) { + // If this @type tag is not part of the current parent tag, then + // it denotes the end of the current parent tag. + finishCurrentParentTag(); + return result; + } + + return undefined; } function handlePropertyTag(atToken: Node, tagName: Identifier): JSDocPropertyTag { - if (!currentParentJSDocDeclaration) { + if (!currentParentJSDocTag) { parseErrorAtPosition(tagName.pos, scanner.getTokenPos() - tagName.pos, Diagnostics._0_tag_cannot_be_used_independently_as_a_top_level_JSDoc_tag, tagName.text); return undefined; } @@ -6226,12 +6318,17 @@ namespace ts { return undefined; } - const result = createNode(SyntaxKind.JSDocPropertyTag, atToken.pos); + let result = createNode(SyntaxKind.JSDocPropertyTag, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.name = name; result.typeExpression = typeExpression; - return finishNode(result); + result.type = typeExpression.type; + result = finishNode(result); + + addToCurrentParentTag(result); + currentParentJSDocTagEnd = scanner.getStartPos(); + return undefined; } function handleTypedefTag(atToken: Node, tagName: Identifier): JSDocTypedefTag { @@ -6249,17 +6346,26 @@ namespace ts { result.name = name; result.typeExpression = typeExpression; - // if (typeExpression && typeExpression.type.kind === SyntaxKind.JSDocTypeReference) { - // const jsDocTypeReference = typeExpression.type; - // if (jsDocTypeReference.name.kind === SyntaxKind.Identifier) { - // const name = jsDocTypeReference.name; - // if (name.text === "Object") { - // currentParentJSDocDeclaration = declaration; - // } - // } - // } + if (typeExpression && typeExpression.type.kind === SyntaxKind.JSDocTypeReference) { + const jsDocTypeReference = typeExpression.type; + if (jsDocTypeReference.name.kind === SyntaxKind.Identifier) { + const name = jsDocTypeReference.name; + if (name.text === "Object") { + currentParentJSDocTag = result; + } + } + } + else if (!typeExpression) { + currentParentJSDocTag = result; + } - return result; + if (!currentParentJSDocTag) { + result.type = result.typeExpression.type; + return finishNode(result); + } + + currentParentJSDocTagEnd = scanner.getStartPos(); + return undefined; } function handleTemplateTag(atToken: Node, tagName: Identifier): JSDocTemplateTag { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index a0cc8d054e1..31c2c8eb068 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -344,7 +344,6 @@ namespace ts { JSDocTemplateTag, JSDocTypedefTag, JSDocPropertyTag, - JSDocTypedefDeclaration, JSDocTypeLiteral, // Synthesized list @@ -616,6 +615,7 @@ namespace ts { // SyntaxKind.PropertyAssignment // SyntaxKind.ShorthandPropertyAssignment // SyntaxKind.EnumMember + // SyntaxKind.JSDocPropertyTag export interface VariableLikeDeclaration extends Declaration { propertyName?: PropertyName; dotDotDotToken?: Node; @@ -1515,25 +1515,26 @@ namespace ts { } // @kind(SyntaxKind.JSDocTypedefTag) - export interface JSDocTypedefTag extends JSDocTag, Declaration { + export interface JSDocTypedefTag extends JSDocTag, Declaration, JSDocParentTag { name: Identifier; - typeExpression: JSDocTypeExpression; + typeExpression?: JSDocTypeExpression; + type: JSDocType; + } + + export interface JSDocParentTag extends JSDocTag { + jsDocPropertyTags?: NodeArray; + jsDocTypeTag?: JSDocTypeTag; } // @kind(SyntaxKind.JSDocPropertyTag) export interface JSDocPropertyTag extends JSDocTag, TypeElement { name: Identifier; typeExpression: JSDocTypeExpression; - } - - // @kind(SyntaxKind.JSDocTypedefDeclaration) - export interface JSDocTypedefDeclaration extends Declaration { - name: Identifier; type: TypeNode; } // @kind(SyntaxKind.JSDocTypeLiteral) - export interface JSDocTypeLiteral extends TypeNode { + export interface JSDocTypeLiteral extends JSDocType { members: NodeArray; } diff --git a/tests/cases/fourslash/server/jsdocCompletions.ts b/tests/cases/fourslash/server/jsdocCompletions.ts new file mode 100644 index 00000000000..c8dc1bbe481 --- /dev/null +++ b/tests/cases/fourslash/server/jsdocCompletions.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: jsdocCompletion_typedef.js +//// /** +//// * @typedef {Object} Person +//// * @property {string} personName +//// * @type {Person} +//// */ +//// var x1; +//// x1/**/ + +goTo.marker(); +edit.insert('.'); +verify.memberListContains('personName'); \ No newline at end of file From 9a8f6395e44ed494876f7a671b2d2750b336b929 Mon Sep 17 00:00:00 2001 From: Zhengbo Li Date: Wed, 6 Apr 2016 20:22:23 -0700 Subject: [PATCH 03/61] Support the case with variable name as @typedef type name --- src/compiler/checker.ts | 13 +++++-------- src/compiler/parser.ts | 22 +++++++++++++++++----- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e66e5e6a9d8..35ae6777fe2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3403,7 +3403,7 @@ namespace ts { return links.declaredType; } - function getDeclaredTypeOfTypeAlias(symbol: Symbol, node?: Node): Type { + function getDeclaredTypeOfTypeAlias(symbol: Symbol): Type { const links = getSymbolLinks(symbol); if (!links.declaredType) { // Note that we use the links object as the target here because the symbol object is used as the unique @@ -3412,10 +3412,7 @@ namespace ts { return unknownType; } - let declaration: JSDocTypedefTag | TypeAliasDeclaration; - if (node && (node.flags & NodeFlags.JavaScriptFile)) { - declaration = getDeclarationOfKind(symbol, SyntaxKind.JSDocTypedefTag); - } + let declaration: JSDocTypedefTag | TypeAliasDeclaration = getDeclarationOfKind(symbol, SyntaxKind.JSDocTypedefTag); if (!declaration) { declaration = getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration); } @@ -3469,13 +3466,13 @@ namespace ts { return links.declaredType; } - function getDeclaredTypeOfSymbol(symbol: Symbol, node?: Node): Type { + function getDeclaredTypeOfSymbol(symbol: Symbol): Type { Debug.assert((symbol.flags & SymbolFlags.Instantiated) === 0); if (symbol.flags & (SymbolFlags.Class | SymbolFlags.Interface)) { return getDeclaredTypeOfClassOrInterface(symbol); } if (symbol.flags & SymbolFlags.TypeAlias) { - return getDeclaredTypeOfTypeAlias(symbol, node); + return getDeclaredTypeOfTypeAlias(symbol); } if (symbol.flags & SymbolFlags.Enum) { return getDeclaredTypeOfEnum(symbol); @@ -4571,7 +4568,7 @@ namespace ts { // references to the type parameters of the alias. We replace those with the actual type arguments by instantiating the // declared type. Instantiations are cached using the type identities of the type arguments as the key. function getTypeFromTypeAliasReference(node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference, symbol: Symbol): Type { - const type = getDeclaredTypeOfSymbol(symbol, node); + const type = getDeclaredTypeOfSymbol(symbol); const links = getSymbolLinks(symbol); const typeParameters = links.typeParameters; if (typeParameters) { diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 5de1369ee09..0b4a98bd986 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -5977,7 +5977,7 @@ namespace ts { const saveParseDiagnosticsLength = parseDiagnostics.length; const saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode; - const comment = parseJSDocCommentWorker(start, length); + const comment = parseJSDocCommentWorker(start, length, parent); if (comment) { comment.parent = parent; } @@ -5989,7 +5989,7 @@ namespace ts { return comment; } - export function parseJSDocCommentWorker(start: number, length: number): JSDocComment { + export function parseJSDocCommentWorker(start: number, length: number, parentNode?: Node): JSDocComment { const content = sourceText; start = start || 0; const end = length === undefined ? content.length : start + length; @@ -6334,10 +6334,22 @@ namespace ts { function handleTypedefTag(atToken: Node, tagName: Identifier): JSDocTypedefTag { const typeExpression = tryParseTypeExpression(); skipWhitespace(); - const name = parseJSDocIdentifier(); + let name = parseJSDocIdentifier(); if (!name) { - parseErrorAtPosition(scanner.getStartPos(), 0, Diagnostics.Identifier_expected); - return undefined; + let foundNameFromParentNode = false; + if (parentNode && parentNode.kind === SyntaxKind.VariableStatement) { + if ((parentNode).declarationList.declarations.length > 0) { + const nameFromParentNode = (parentNode).declarationList.declarations[0].name; + if (nameFromParentNode.kind === SyntaxKind.Identifier) { + foundNameFromParentNode = true; + name = nameFromParentNode; + } + } + } + if (!foundNameFromParentNode) { + parseErrorAtPosition(scanner.getStartPos(), 0, Diagnostics.Identifier_expected); + return undefined; + } } const result = createNode(SyntaxKind.JSDocTypedefTag, atToken.pos); From 2945f64e3b88f8658ed7863d4d3146ad9d5c6b52 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Fri, 8 Apr 2016 20:19:39 -0700 Subject: [PATCH 04/61] Add tests for renaming and incremental parsing. Changed how the AST was hydrated with jsdocComment nodes. --- src/compiler/binder.ts | 6 +- src/compiler/checker.ts | 4 +- src/compiler/parser.ts | 44 +-- src/compiler/scanner.ts | 5 +- src/compiler/types.ts | 9 +- src/compiler/utilities.ts | 89 ++++-- src/harness/harness.ts | 22 +- src/services/services.ts | 53 +++- src/services/utilities.ts | 61 ++-- tests/cases/fourslash/commentsVariables.ts | 80 ++--- tests/cases/fourslash/doesnotwork.ts | 45 +++ .../fourslash/server/jsdocCompletions.ts | 15 - .../cases/fourslash/server/jsdocTypedefTag.ts | 64 ++++ .../server/jsdocTypedefTagGoToDefinition.ts | 29 ++ .../server/jsdocTypedefTagRename01.ts | 20 ++ .../server/jsdocTypedefTagRename02.ts | 15 + .../server/jsdocTypedefTagRename03.ts | 20 ++ .../server/jsdocTypedefTagRename04.ts | 24 ++ tests/cases/unittests/jsDocParsing.ts | 3 +- tests/webTestServer.js | 288 ++++++++++++++++++ tests/webTestServer.js.map | 1 + 21 files changed, 757 insertions(+), 140 deletions(-) create mode 100644 tests/cases/fourslash/doesnotwork.ts delete mode 100644 tests/cases/fourslash/server/jsdocCompletions.ts create mode 100644 tests/cases/fourslash/server/jsdocTypedefTag.ts create mode 100644 tests/cases/fourslash/server/jsdocTypedefTagGoToDefinition.ts create mode 100644 tests/cases/fourslash/server/jsdocTypedefTagRename01.ts create mode 100644 tests/cases/fourslash/server/jsdocTypedefTagRename02.ts create mode 100644 tests/cases/fourslash/server/jsdocTypedefTagRename03.ts create mode 100644 tests/cases/fourslash/server/jsdocTypedefTagRename04.ts create mode 100644 tests/webTestServer.js create mode 100644 tests/webTestServer.js.map diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index b3f163bbef1..45629da8adf 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -407,8 +407,10 @@ namespace ts { // Binding of JsDocComment should be done before the current block scope container changes. // because the scope of JsDocComment should not be affected by whether the current node is a // container or not. - if (isInJavaScriptFile(node) && node.jsDocComment) { - bind(node.jsDocComment); + if (isInJavaScriptFile(node) && node.jsDocComments) { + for (const jsDocComment of node.jsDocComments) { + bind(jsDocComment); + } } // Depending on what kind of node this is, we may have to adjust the current container diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 35ae6777fe2..c903696f88f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16117,7 +16117,7 @@ namespace ts { node = node.parent; } - return node.parent && node.parent.kind === SyntaxKind.TypeReference; + return node.parent && (node.parent.kind === SyntaxKind.TypeReference || node.parent.kind === SyntaxKind.JSDocTypeReference) ; } function isHeritageClauseElementIdentifier(entityName: Node): boolean { @@ -16251,7 +16251,7 @@ namespace ts { } } else if (isTypeReferenceIdentifier(entityName)) { - let meaning = entityName.parent.kind === SyntaxKind.TypeReference ? SymbolFlags.Type : SymbolFlags.Namespace; + let meaning = (entityName.parent.kind === SyntaxKind.TypeReference || entityName.parent.kind === SyntaxKind.JSDocTypeReference) ? SymbolFlags.Type : SymbolFlags.Namespace; // Include aliases in the meaning, this ensures that we do not follow aliases to where they point and instead // return the alias symbol. meaning |= SymbolFlags.Alias; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 0b4a98bd986..009a3e13fa2 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -402,15 +402,15 @@ namespace ts { case SyntaxKind.JSDocTemplateTag: return visitNodes(cbNodes, (node).typeParameters); case SyntaxKind.JSDocTypedefTag: - return visitNode(cbNode, (node).name) || - visitNode(cbNode, (node).typeExpression) || + return visitNode(cbNode, (node).typeExpression) || + visitNode(cbNode, (node).name) || visitNode(cbNode, (node).type); case SyntaxKind.JSDocTypeLiteral: return visitNodes(cbNodes, (node).members); case SyntaxKind.JSDocPropertyTag: - return visitNode(cbNode, (node).name) || - visitNode(cbNode, (node).typeExpression) || - visitNode(cbNode, (node).type); + return visitNode(cbNode, (node).typeExpression) || + visitNode(cbNode, (node).type) || + visitNode(cbNode, (node).name); } } @@ -638,9 +638,14 @@ namespace ts { if (comments) { for (const comment of comments) { const jsDocComment = JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos); - if (jsDocComment) { - node.jsDocComment = jsDocComment; + if (!jsDocComment) { + continue; } + + if (!node.jsDocComments) { + node.jsDocComments = []; + } + node.jsDocComments.push(jsDocComment); } } } @@ -6105,13 +6110,15 @@ namespace ts { typedefTag.type = typedefTag.jsDocTypeTag.typeExpression.type; } } - if (!typedefTag.type) { - const tagType = createNode(SyntaxKind.JSDocTypeLiteral, currentParentJSDocTag.pos); - if (typedefTag.jsDocPropertyTags){ - tagType.members = >[]; - addRange(tagType.members, typedefTag.jsDocPropertyTags); - } - typedefTag.type = finishNode(tagType, currentParentJSDocTagEnd); + if (!typedefTag.type && typedefTag.jsDocPropertyTags) { + const childrenTagPoses = ts.map(typedefTag.jsDocPropertyTags, tag => tag.pos); + const childrenTagEnds = ts.map(typedefTag.jsDocPropertyTags, tag => tag.end); + const pos = Math.min(...childrenTagPoses); + const end = Math.max(...childrenTagEnds); + const tagType = createNode(SyntaxKind.JSDocTypeLiteral, pos); + tagType.members = >[]; + addRange(tagType.members, typedefTag.jsDocPropertyTags); + typedefTag.type = finishNode(tagType, end); } } @@ -6545,10 +6552,6 @@ namespace ts { node._children = undefined; } - if (node.jsDocComment) { - node.jsDocComment = undefined; - } - node.pos += delta; node.end += delta; @@ -6557,6 +6560,11 @@ namespace ts { } forEachChild(node, visitNode, visitArray); + if (node.jsDocComments) { + for (const jsDocComment of node.jsDocComments) { + forEachChild(jsDocComment, visitNode, visitArray); + } + } checkNodePositions(node, aggressiveChecks); } diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 8979814a7a2..d4206749fae 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -433,7 +433,7 @@ namespace ts { } /* @internal */ - export function skipTrivia(text: string, pos: number, stopAfterLineBreak?: boolean): number { + export function skipTrivia(text: string, pos: number, stopAfterLineBreak?: boolean, stopAtComments = false): number { // Using ! with a greater than test is a fast way of testing the following conditions: // pos === undefined || pos === null || isNaN(pos) || pos < 0; if (!(pos >= 0)) { @@ -461,6 +461,9 @@ namespace ts { pos++; continue; case CharacterCodes.slash: + if (stopAtComments) { + break; + } if (text.charCodeAt(pos + 1) === CharacterCodes.slash) { pos += 2; while (pos < text.length) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 31c2c8eb068..838b5d951f2 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -374,6 +374,8 @@ namespace ts { FirstBinaryOperator = LessThanToken, LastBinaryOperator = CaretEqualsToken, FirstNode = QualifiedName, + FirstJSDocNode = JSDocTypeExpression, + LastJSDocNode = JSDocTypeLiteral } export const enum NodeFlags { @@ -447,7 +449,7 @@ namespace ts { modifiers?: ModifiersArray; // Array of modifiers /* @internal */ id?: number; // Unique id (used to look up NodeLinks) parent?: Node; // Parent node (initialized by binding - /* @internal */ jsDocComment?: JSDocComment; // JSDoc for the node, if it has any. Only for .js files. + /* @internal */ jsDocComments?: JSDocComment[]; // JSDoc for the node, if it has any. Only for .js files. /* @internal */ symbol?: Symbol; // Symbol declared by node (initialized by binding) /* @internal */ locals?: SymbolTable; // Locals associated with node (initialized by binding) /* @internal */ nextContainer?: Node; // Next container in declaration order (initialized by binding) @@ -2827,4 +2829,9 @@ namespace ts { /* @internal */ reattachFileDiagnostics(newFile: SourceFile): void; } + + // SyntaxKind.SyntaxList + export interface SyntaxList extends Node { + _children: Node[]; + } } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 4356486d3b5..fab5e9f8f8b 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -203,16 +203,54 @@ namespace ts { return !nodeIsMissing(node); } - export function getTokenPosOfNode(node: Node, sourceFile?: SourceFile): number { + export function getTokenPosOfNode(node: Node, sourceFile?: SourceFile, includeJsDocComment?: boolean): number { // With nodes that have no width (i.e. 'Missing' nodes), we actually *don't* // want to skip trivia because this will launch us forward to the next token. if (nodeIsMissing(node)) { return node.pos; } + if (isJSDocNode(node)) { + return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos, /*stopAfterLineBreak*/ false, /*stopAtComments*/ true); + } + + if (node.jsDocComments && node.jsDocComments.length > 0 && includeJsDocComment) { + return getTokenPosOfNode(node.jsDocComments[0]); + } + + if (node.kind === SyntaxKind.SyntaxList) { + const childrenPoses = ts.map((node)._children, child => getTokenPosOfNode(child, sourceFile, includeJsDocComment)); + return Math.min(...childrenPoses); + } + return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos); } + export function isJSDocNode(node: Node) { + return node.kind >= SyntaxKind.FirstJSDocNode && node.kind <= SyntaxKind.LastJSDocNode; + } + export function isJSDocType(node: Node) { + switch (node.kind) { + case SyntaxKind.JSDocAllType: + case SyntaxKind.JSDocUnknownType: + case SyntaxKind.JSDocArrayType: + case SyntaxKind.JSDocUnionType: + case SyntaxKind.JSDocTupleType: + case SyntaxKind.JSDocNullableType: + case SyntaxKind.JSDocNonNullableType: + case SyntaxKind.JSDocRecordType: + case SyntaxKind.JSDocRecordMember: + case SyntaxKind.JSDocTypeReference: + case SyntaxKind.JSDocOptionalType: + case SyntaxKind.JSDocFunctionType: + case SyntaxKind.JSDocVariadicType: + case SyntaxKind.JSDocConstructorType: + case SyntaxKind.JSDocThisType: + return true; + } + return false; + } + export function getNonDecoratorTokenPosOfNode(node: Node, sourceFile?: SourceFile): number { if (nodeIsMissing(node) || !node.decorators) { return getTokenPosOfNode(node, sourceFile); @@ -1199,26 +1237,28 @@ namespace ts { return undefined; } - const jsDocComment = getJSDocComment(node, checkParentVariableStatement); - if (!jsDocComment) { + const jsDocComments = getJSDocComments(node, checkParentVariableStatement); + if (!jsDocComments) { return undefined; } - for (const tag of jsDocComment.tags) { - if (tag.kind === kind) { - return tag; + for (const jsDocComment of jsDocComments) { + for (const tag of jsDocComment.tags) { + if (tag.kind === kind) { + return tag; + } } } } - function getJSDocComment(node: Node, checkParentVariableStatement: boolean): JSDocComment { - if (node.jsDocComment) { - return node.jsDocComment; + function getJSDocComments(node: Node, checkParentVariableStatement: boolean): JSDocComment[] { + if (node.jsDocComments) { + return node.jsDocComments; } - // Try to recognize this pattern when node is initializer of variable declaration and JSDoc comments are on containing variable statement. - // /** + // Try to recognize this pattern when node is initializer of variable declaration and JSDoc comments are on containing variable statement. + // /** // * @param {number} name - // * @returns {number} + // * @returns {number} // */ // var x = function(name) { return name.length; } if (checkParentVariableStatement) { @@ -1229,7 +1269,7 @@ namespace ts { const variableStatementNode = isInitializerOfVariableDeclarationInStatement ? node.parent.parent.parent : undefined; if (variableStatementNode) { - return variableStatementNode.jsDocComment; + return variableStatementNode.jsDocComments; } // Also recognize when the node is the RHS of an assignment expression @@ -1240,12 +1280,12 @@ namespace ts { (parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken && parent.parent.kind === SyntaxKind.ExpressionStatement; if (isSourceOfAssignmentExpressionStatement) { - return parent.parent.jsDocComment; + return parent.parent.jsDocComments; } const isPropertyAssignmentExpression = parent && parent.kind === SyntaxKind.PropertyAssignment; if (isPropertyAssignmentExpression) { - return parent.jsDocComment; + return parent.jsDocComments; } } @@ -1270,14 +1310,16 @@ namespace ts { // annotation. const parameterName = (parameter.name).text; - const jsDocComment = getJSDocComment(parameter.parent, /*checkParentVariableStatement*/ true); - if (jsDocComment) { - for (const tag of jsDocComment.tags) { - if (tag.kind === SyntaxKind.JSDocParameterTag) { - const parameterTag = tag; - const name = parameterTag.preParameterName || parameterTag.postParameterName; - if (name.text === parameterName) { - return parameterTag; + const jsDocComments = getJSDocComments(parameter.parent, /*checkParentVariableStatement*/ true); + if (jsDocComments) { + for (const jsDocComment of jsDocComments) { + for (const tag of jsDocComment.tags) { + if (tag.kind === SyntaxKind.JSDocParameterTag) { + const parameterTag = tag; + const name = parameterTag.preParameterName || parameterTag.postParameterName; + if (name.text === parameterName) { + return parameterTag; + } } } } @@ -1374,6 +1416,7 @@ namespace ts { case SyntaxKind.TypeAliasDeclaration: case SyntaxKind.TypeParameter: case SyntaxKind.VariableDeclaration: + case SyntaxKind.JSDocTypedefTag: return true; } return false; diff --git a/src/harness/harness.ts b/src/harness/harness.ts index ddaca642094..330f57cf5c9 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1,7 +1,7 @@ // // Copyright (c) Microsoft Corporation. All rights reserved. -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -217,6 +217,14 @@ namespace Utils { return k; } + if (k === (ts).SyntaxKind.FirstJSDocCommentNode || k === (ts).SyntaxKind.LastJSDocCommentNode) { + for (const kindName in (ts).SyntaxKind) { + if ((ts).SyntaxKind[kindName] === k) { + return kindName; + } + } + } + return (ts).SyntaxKind[k]; } @@ -346,7 +354,7 @@ namespace Utils { assert.equal(node1.end, node2.end, "node1.end !== node2.end"); assert.equal(node1.kind, node2.kind, "node1.kind !== node2.kind"); - // call this on both nodes to ensure all propagated flags have been set (and thus can be + // call this on both nodes to ensure all propagated flags have been set (and thus can be // compared). assert.equal(ts.containsParseError(node1), ts.containsParseError(node2)); assert.equal(node1.flags, node2.flags, "node1.flags !== node2.flags"); @@ -753,7 +761,7 @@ namespace Harness { (emittedFile: string, emittedLine: number, emittedColumn: number, sourceFile: string, sourceLine: number, sourceColumn: number, sourceName: string): void; } - // Settings + // Settings export let userSpecifiedRoot = ""; export let lightMode = false; @@ -792,7 +800,7 @@ namespace Harness { fileName: string, sourceText: string, languageVersion: ts.ScriptTarget) { - // We'll only assert invariants outside of light mode. + // We'll only assert invariants outside of light mode. const shouldAssertInvariants = !Harness.lightMode; // Only set the parent nodes if we're asserting invariants. We don't need them otherwise. @@ -887,7 +895,7 @@ namespace Harness { libFiles?: string; } - // Additional options not already in ts.optionDeclarations + // Additional options not already in ts.optionDeclarations const harnessOptionDeclarations: ts.CommandLineOption[] = [ { name: "allowNonTsExtensions", type: "boolean" }, { name: "useCaseSensitiveFileNames", type: "boolean" }, @@ -1135,7 +1143,7 @@ namespace Harness { errLines.forEach(e => outputLines.push(e)); // do not count errors from lib.d.ts here, they are computed separately as numLibraryDiagnostics - // if lib.d.ts is explicitly included in input files and there are some errors in it (i.e. because of duplicate identifiers) + // if lib.d.ts is explicitly included in input files and there are some errors in it (i.e. because of duplicate identifiers) // then they will be added twice thus triggering 'total errors' assertion with condition // 'totalErrorsReportedInNonLibraryFiles + numLibraryDiagnostics + numTest262HarnessDiagnostics, diagnostics.length @@ -1445,7 +1453,7 @@ namespace Harness { }; testUnitData.push(newTestFile2); - // unit tests always list files explicitly + // unit tests always list files explicitly const parseConfigHost: ts.ParseConfigHost = { readDirectory: (name) => [] }; diff --git a/src/services/services.ts b/src/services/services.ts index a634b2baf1a..d85d478fcbe 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -20,7 +20,7 @@ namespace ts { getChildCount(sourceFile?: SourceFile): number; getChildAt(index: number, sourceFile?: SourceFile): Node; getChildren(sourceFile?: SourceFile): Node[]; - getStart(sourceFile?: SourceFile): number; + getStart(sourceFile?: SourceFile, includeJsDocComment?: boolean): number; getFullStart(): number; getEnd(): number; getWidth(sourceFile?: SourceFile): number; @@ -170,6 +170,8 @@ namespace ts { "static", "throws", "type", + "typedef", + "property", "version" ]; let jsDocCompletionEntries: CompletionEntry[]; @@ -187,6 +189,7 @@ namespace ts { public end: number; public flags: NodeFlags; public parent: Node; + public jsDocComments: JSDocComment[]; private _children: Node[]; constructor(kind: SyntaxKind, pos: number, end: number) { @@ -201,8 +204,8 @@ namespace ts { return getSourceFileOfNode(this); } - public getStart(sourceFile?: SourceFile): number { - return getTokenPosOfNode(this, sourceFile); + public getStart(sourceFile?: SourceFile, includeJsDocComment?: boolean): number { + return getTokenPosOfNode(this, sourceFile, includeJsDocComment); } public getFullStart(): number { @@ -233,12 +236,14 @@ namespace ts { return (sourceFile || this.getSourceFile()).text.substring(this.getStart(), this.getEnd()); } - private addSyntheticNodes(nodes: Node[], pos: number, end: number): number { + private addSyntheticNodes(nodes: Node[], pos: number, end: number, useJSDocScanner?: boolean): number { scanner.setTextPos(pos); while (pos < end) { - const token = scanner.scan(); + const token = useJSDocScanner ? scanner.scanJSDocToken() : scanner.scan(); const textPos = scanner.getTextPos(); - nodes.push(createNode(token, pos, textPos, 0, this)); + if (textPos <= end) { + nodes.push(createNode(token, pos, textPos, 0, this)); + } pos = textPos; } return pos; @@ -268,20 +273,36 @@ namespace ts { scanner.setText((sourceFile || this.getSourceFile()).text); children = []; let pos = this.pos; + const isJSDocTag = + this.kind === SyntaxKind.JSDocComment || + this.kind === SyntaxKind.JSDocParameterTag || + this.kind === SyntaxKind.JSDocTag || + this.kind === SyntaxKind.JSDocParameterTag || + this.kind === SyntaxKind.JSDocReturnTag || + this.kind === SyntaxKind.JSDocTypeTag || + this.kind === SyntaxKind.JSDocTemplateTag || + this.kind === SyntaxKind.JSDocTypedefTag || + this.kind === SyntaxKind.JSDocPropertyTag; const processNode = (node: Node) => { if (pos < node.pos) { - pos = this.addSyntheticNodes(children, pos, node.pos); + pos = this.addSyntheticNodes(children, pos, node.pos, /*useJSDocScanner*/ isJSDocTag); } children.push(node); pos = node.end; }; const processNodes = (nodes: NodeArray) => { if (pos < nodes.pos) { - pos = this.addSyntheticNodes(children, pos, nodes.pos); + pos = this.addSyntheticNodes(children, pos, nodes.pos, /*useJSDocScanner*/ isJSDocTag); } children.push(this.createSyntaxList(>nodes)); pos = nodes.end; }; + // jsDocComments need to be the first children + if (this.jsDocComments) { + for (const jsDocComment of this.jsDocComments) { + processNode(jsDocComment); + } + } forEachChild(this, processNode, processNodes); if (pos < this.end) { this.addSyntheticNodes(children, pos, this.end); @@ -1883,7 +1904,7 @@ namespace ts { options.isolatedModules = true; - // transpileModule does not write anything to disk so there is no need to verify that there are no conflicts between input and output paths. + // transpileModule does not write anything to disk so there is no need to verify that there are no conflicts between input and output paths. options.suppressOutputPathCheck = true; // Filename can be non-ts file. @@ -5499,7 +5520,7 @@ namespace ts { const sourceFile = getValidSourceFile(fileName); - const node = getTouchingPropertyName(sourceFile, position); + const node = getTouchingPropertyName(sourceFile, position, /*includeJsDocComment*/ true); if (!node) { return undefined; } @@ -5808,7 +5829,8 @@ namespace ts { const sourceFile = container.getSourceFile(); const tripleSlashDirectivePrefixRegex = /^\/\/\/\s* 0) { + for (const jsDocComment of node.jsDocComments) { + forEachChild(jsDocComment, walk); + } + } } } } diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 8006fea2c07..5ea011f2226 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -260,29 +260,29 @@ namespace ts { /* Gets the token whose text has range [start, end) and * position >= start and (position < end or (position === end && token is keyword or identifier)) */ - export function getTouchingWord(sourceFile: SourceFile, position: number): Node { - return getTouchingToken(sourceFile, position, n => isWord(n.kind)); + export function getTouchingWord(sourceFile: SourceFile, position: number, includeJsDocComment = false): Node { + return getTouchingToken(sourceFile, position, n => isWord(n.kind), includeJsDocComment); } /* Gets the token whose text has range [start, end) and position >= start * and (position < end or (position === end && token is keyword or identifier or numeric/string literal)) */ - export function getTouchingPropertyName(sourceFile: SourceFile, position: number): Node { - return getTouchingToken(sourceFile, position, n => isPropertyName(n.kind)); + export function getTouchingPropertyName(sourceFile: SourceFile, position: number, includeJsDocComment = false): Node { + return getTouchingToken(sourceFile, position, n => isPropertyName(n.kind), includeJsDocComment); } /** Returns the token if position is in [start, end) or if position === end and includeItemAtEndPosition(token) === true */ - export function getTouchingToken(sourceFile: SourceFile, position: number, includeItemAtEndPosition?: (n: Node) => boolean): Node { - return getTokenAtPositionWorker(sourceFile, position, /*allowPositionInLeadingTrivia*/ false, includeItemAtEndPosition); + export function getTouchingToken(sourceFile: SourceFile, position: number, includeItemAtEndPosition?: (n: Node) => boolean, includeJsDocComment = false): Node { + return getTokenAtPositionWorker(sourceFile, position, /*allowPositionInLeadingTrivia*/ false, includeItemAtEndPosition, includeJsDocComment); } /** Returns a token if position is in [start-of-leading-trivia, end) */ - export function getTokenAtPosition(sourceFile: SourceFile, position: number): Node { - return getTokenAtPositionWorker(sourceFile, position, /*allowPositionInLeadingTrivia*/ true, /*includeItemAtEndPosition*/ undefined); + export function getTokenAtPosition(sourceFile: SourceFile, position: number, includeJsDocComment = false): Node { + return getTokenAtPositionWorker(sourceFile, position, /*allowPositionInLeadingTrivia*/ true, /*includeItemAtEndPosition*/ undefined, includeJsDocComment); } /** Get the token whose text contains the position */ - function getTokenAtPositionWorker(sourceFile: SourceFile, position: number, allowPositionInLeadingTrivia: boolean, includeItemAtEndPosition: (n: Node) => boolean): Node { + function getTokenAtPositionWorker(sourceFile: SourceFile, position: number, allowPositionInLeadingTrivia: boolean, includeItemAtEndPosition: (n: Node) => boolean, includeJsDocComment = false): Node { let current: Node = sourceFile; outer: while (true) { if (isToken(current)) { @@ -290,10 +290,34 @@ namespace ts { return current; } + if (includeJsDocComment) { + const jsDocChildren = ts.filter(current.getChildren(), isJSDocNode); + for (const jsDocChild of jsDocChildren) { + let start = allowPositionInLeadingTrivia ? jsDocChild.getFullStart() : jsDocChild.getStart(sourceFile, includeJsDocComment); + if (start <= position) { + let end = jsDocChild.getEnd(); + if (position < end || (position === end && jsDocChild.kind === SyntaxKind.EndOfFileToken)) { + current = jsDocChild; + continue outer; + } + else if (includeItemAtEndPosition && end === position) { + let previousToken = findPrecedingToken(position, sourceFile, jsDocChild); + if (previousToken && includeItemAtEndPosition(previousToken)) { + return previousToken; + } + } + } + } + } + // find the child that contains 'position' for (let i = 0, n = current.getChildCount(sourceFile); i < n; i++) { let child = current.getChildAt(i); - let start = allowPositionInLeadingTrivia ? child.getFullStart() : child.getStart(sourceFile); + // all jsDocComment nodes were already visited + if (isJSDocNode(child)) { + continue; + } + let start = allowPositionInLeadingTrivia ? child.getFullStart() : child.getStart(sourceFile, includeJsDocComment); if (start <= position) { let end = child.getEnd(); if (position < end || (position === end && child.kind === SyntaxKind.EndOfFileToken)) { @@ -308,6 +332,7 @@ namespace ts { } } } + return current; } } @@ -501,11 +526,13 @@ namespace ts { } if (node) { - let jsDocComment = node.jsDocComment; - if (jsDocComment) { - for (let tag of jsDocComment.tags) { - if (tag.pos <= position && position <= tag.end) { - return tag; + let jsDocComments = node.jsDocComments; + if (jsDocComments) { + for (const jsDocComment of jsDocComments) { + for (const tag of jsDocComment.tags) { + if (tag.pos <= position && position <= tag.end) { + return tag; + } } } } @@ -615,7 +642,7 @@ namespace ts { // [a,b,c] from: // [a, b, c] = someExpression; if (node.parent.kind === SyntaxKind.BinaryExpression && - (node.parent).left === node && + (node.parent).left === node && (node.parent).operatorToken.kind === SyntaxKind.EqualsToken) { return true; } @@ -629,7 +656,7 @@ namespace ts { // [a, b, c] of // [x, [a, b, c] ] = someExpression - // or + // or // {x, a: {a, b, c} } = someExpression if (isArrayLiteralOrObjectLiteralDestructuringPattern(node.parent.kind === SyntaxKind.PropertyAssignment ? node.parent.parent : node.parent)) { return true; diff --git a/tests/cases/fourslash/commentsVariables.ts b/tests/cases/fourslash/commentsVariables.ts index d62e1e9bee8..b2cf6c9cb9b 100644 --- a/tests/cases/fourslash/commentsVariables.ts +++ b/tests/cases/fourslash/commentsVariables.ts @@ -41,60 +41,60 @@ ////} ////var x = fo/*15*/o2; -goTo.marker('1'); -verify.quickInfoIs("var myVariable: number", "This is my variable"); +// goTo.marker('1'); +// verify.quickInfoIs("var myVariable: number", "This is my variable"); -goTo.marker('2'); -verify.completionListContains("myVariable", "var myVariable: number", "This is my variable"); +// goTo.marker('2'); +// verify.completionListContains("myVariable", "var myVariable: number", "This is my variable"); -goTo.marker('3'); -verify.completionListContains("myVariable", "var myVariable: number", "This is my variable"); -verify.completionListContains("d", "var d: number", "d variable"); +// goTo.marker('3'); +// verify.completionListContains("myVariable", "var myVariable: number", "This is my variable"); +// verify.completionListContains("d", "var d: number", "d variable"); goTo.marker('4'); verify.completionListContains("foo", "function foo(): void", "foos comment"); verify.completionListContains("fooVar", "var fooVar: () => void", "fooVar comment"); -goTo.marker('5'); -verify.currentSignatureHelpDocCommentIs("foos comment"); -goTo.marker('5q'); -verify.quickInfoIs("function foo(): void", "foos comment"); +// goTo.marker('5'); +// verify.currentSignatureHelpDocCommentIs("foos comment"); +// goTo.marker('5q'); +// verify.quickInfoIs("function foo(): void", "foos comment"); -goTo.marker('6'); -verify.currentSignatureHelpDocCommentIs(""); -goTo.marker('6q'); -verify.quickInfoIs("var fooVar: () => void", ""); +// goTo.marker('6'); +// verify.currentSignatureHelpDocCommentIs(""); +// goTo.marker('6q'); +// verify.quickInfoIs("var fooVar: () => void", ""); -goTo.marker('7'); -verify.completionListContains("foo", "function foo(): void", "foos comment"); -verify.completionListContains("fooVar", "var fooVar: () => void", "fooVar comment"); +// goTo.marker('7'); +// verify.completionListContains("foo", "function foo(): void", "foos comment"); +// verify.completionListContains("fooVar", "var fooVar: () => void", "fooVar comment"); -goTo.marker('8'); -verify.currentSignatureHelpDocCommentIs("foos comment"); -goTo.marker('8q'); -verify.quickInfoIs("function foo(): void", "foos comment"); +// goTo.marker('8'); +// verify.currentSignatureHelpDocCommentIs("foos comment"); +// goTo.marker('8q'); +// verify.quickInfoIs("function foo(): void", "foos comment"); -goTo.marker('9'); -verify.currentSignatureHelpDocCommentIs(""); -goTo.marker('9q'); -verify.quickInfoIs("var fooVar: () => void", ""); -goTo.marker('9aq'); -verify.quickInfoIs("var fooVar: () => void", "fooVar comment"); +// goTo.marker('9'); +// verify.currentSignatureHelpDocCommentIs(""); +// goTo.marker('9q'); +// verify.quickInfoIs("var fooVar: () => void", ""); +// goTo.marker('9aq'); +// verify.quickInfoIs("var fooVar: () => void", "fooVar comment"); -goTo.marker('10'); -verify.completionListContains("i", "var i: c", "instance comment"); +// goTo.marker('10'); +// verify.completionListContains("i", "var i: c", "instance comment"); -goTo.marker('11'); -verify.completionListContains("i1_i", "var i1_i: i1", "interface instance comments"); +// goTo.marker('11'); +// verify.completionListContains("i1_i", "var i1_i: i1", "interface instance comments"); -goTo.marker('12'); -verify.quickInfoIs("var fooVar: () => void", "fooVar comment"); +// goTo.marker('12'); +// verify.quickInfoIs("var fooVar: () => void", "fooVar comment"); -goTo.marker('13'); -verify.quickInfoIs("var fooVar: () => void", "fooVar comment"); +// goTo.marker('13'); +// verify.quickInfoIs("var fooVar: () => void", "fooVar comment"); -goTo.marker('14'); -verify.quickInfoIs("function foo(): void", "foos comment"); +// goTo.marker('14'); +// verify.quickInfoIs("function foo(): void", "foos comment"); -goTo.marker('15'); -verify.quickInfoIs("function foo2(a: number): void (+1 overload)", ""); +// goTo.marker('15'); +// verify.quickInfoIs("function foo2(a: number): void (+1 overload)", ""); diff --git a/tests/cases/fourslash/doesnotwork.ts b/tests/cases/fourslash/doesnotwork.ts new file mode 100644 index 00000000000..2f415563c21 --- /dev/null +++ b/tests/cases/fourslash/doesnotwork.ts @@ -0,0 +1,45 @@ +/// + +/////** This is my variable*/ +////var myVariable = 10; +//// +/////** d variable*/ +////var d = 10; +////myVariable = d; +//// +/////** foos comment*/ +////function foo() { +////} +/////** fooVar comment*/ +////var fooVar: () => void; +/////*4*/ +////foo(); +////fooVar(); +////fooVar = foo; +//// +////foo(); +////fooVar(); +////var fooVarVar = fooVar; +/////**class comment*/ +////class c { +//// /** constructor comment*/ +//// constructor() { +//// } +////} +/////**instance comment*/ +////var i = new c(); +//// +/////** interface comments*/ +////interface i1 { +////} +/////**interface instance comments*/ +////var i1_i: i1; +//// +////function foo2(a: number): void; +////function foo2(b: string): void; +////function foo2(aOrb) { +////} +////var x = foo2; + +goTo.marker('4'); +verify.completionListContains("fooVar", "var fooVar: () => void", "fooVar comment"); diff --git a/tests/cases/fourslash/server/jsdocCompletions.ts b/tests/cases/fourslash/server/jsdocCompletions.ts deleted file mode 100644 index c8dc1bbe481..00000000000 --- a/tests/cases/fourslash/server/jsdocCompletions.ts +++ /dev/null @@ -1,15 +0,0 @@ -/// - -// @allowNonTsExtensions: true -// @Filename: jsdocCompletion_typedef.js -//// /** -//// * @typedef {Object} Person -//// * @property {string} personName -//// * @type {Person} -//// */ -//// var x1; -//// x1/**/ - -goTo.marker(); -edit.insert('.'); -verify.memberListContains('personName'); \ No newline at end of file diff --git a/tests/cases/fourslash/server/jsdocTypedefTag.ts b/tests/cases/fourslash/server/jsdocTypedefTag.ts new file mode 100644 index 00000000000..e645b518020 --- /dev/null +++ b/tests/cases/fourslash/server/jsdocTypedefTag.ts @@ -0,0 +1,64 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: jsdocCompletion_typedef.js + +//// /** @typedef {(string | number)} NumberLike */ +//// +//// /** +//// * @typedef Animal +//// * @type {Object} +//// * @property {string} animalName +//// * @property {number} animalAge +//// */ +//// +//// /** +//// * @typedef {Object} Person +//// * @property {string} personName +//// * @property {number} personAge +//// */ +//// +//// /** +//// * @typedef {Object} +//// * @property {string} catName +//// * @property {number} catAge +//// */ +//// var Cat; +//// +//// /** @typedef {{ dogName: string, dogAge: number }} */ +//// var Dog; +//// +//// /** @type {NumberLike} */ +//// var numberLike; numberLike./*numberLike*/ +//// +//// /** @type {Person} */ +//// var p;p./*person*/ +//// +//// /** @type {Animal} */ +//// var a;a./*animal*/ +//// +//// /** @type {Cat} */ +//// var c;c./*cat*/ +//// +//// /** @type {Dog} */ +//// var d;d./*dog*/ + +goTo.marker('numberLike'); +verify.memberListContains('charAt'); +verify.memberListContains('toExponential'); + +goTo.marker('person'); +verify.memberListContains('personName'); +verify.memberListContains('personAge'); + +goTo.marker('animal'); +verify.memberListContains('animalName'); +verify.memberListContains('animalAge'); + +goTo.marker('dog'); +verify.memberListContains('dogName'); +verify.memberListContains('dogAge'); + +goTo.marker('cat'); +verify.memberListContains('catName'); +verify.memberListContains('catAge'); \ No newline at end of file diff --git a/tests/cases/fourslash/server/jsdocTypedefTagGoToDefinition.ts b/tests/cases/fourslash/server/jsdocTypedefTagGoToDefinition.ts new file mode 100644 index 00000000000..4db14611938 --- /dev/null +++ b/tests/cases/fourslash/server/jsdocTypedefTagGoToDefinition.ts @@ -0,0 +1,29 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: jsdocCompletion_typedef.js + +//// /** +//// * @typedef {Object} Person +//// * /*1*/@property {string} personName +//// * @property {number} personAge +//// */ +//// +//// /** +//// * @typedef {{ /*2*/animalName: string, animalAge: number }} Animal +//// */ +//// +//// /** @type {Person} */ +//// var person; person.personName/*3*/ +//// +//// /** @type {Animal} */ +//// var animal; animal.animalName/*4*/ + +goTo.file('jsdocCompletion_typedef.js'); +goTo.marker('3'); +goTo.definition(); +verify.caretAtMarker('1'); + +goTo.marker('4'); +goTo.definition(); +verify.caretAtMarker('2'); diff --git a/tests/cases/fourslash/server/jsdocTypedefTagRename01.ts b/tests/cases/fourslash/server/jsdocTypedefTagRename01.ts new file mode 100644 index 00000000000..776d0180b06 --- /dev/null +++ b/tests/cases/fourslash/server/jsdocTypedefTagRename01.ts @@ -0,0 +1,20 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: jsDocTypedef_form1.js +//// +//// /** @typedef {(string | number)} */ +//// var /*1*/[|NumberLike|]; +//// +//// /*2*/[|NumberLike|] = 10; +//// +//// /** @type {/*3*/[|NumberLike|]} */ +//// var numberLike; + +goTo.file('jsDocTypedef_form1.js') +goTo.marker('1'); +verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ true); +goTo.marker('2'); +verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ true); +goTo.marker('3'); +verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ true); \ No newline at end of file diff --git a/tests/cases/fourslash/server/jsdocTypedefTagRename02.ts b/tests/cases/fourslash/server/jsdocTypedefTagRename02.ts new file mode 100644 index 00000000000..7f1d422d971 --- /dev/null +++ b/tests/cases/fourslash/server/jsdocTypedefTagRename02.ts @@ -0,0 +1,15 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: jsDocTypedef_form2.js +//// +//// /** @typedef {(string | number)} /*1*/[|NumberLike|] */ +//// +//// /** @type {/*2*/[|NumberLike|]} */ +//// var numberLike; + +goTo.file('jsDocTypedef_form2.js') +goTo.marker('1'); +verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ true); +goTo.marker('2'); +verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ true); \ No newline at end of file diff --git a/tests/cases/fourslash/server/jsdocTypedefTagRename03.ts b/tests/cases/fourslash/server/jsdocTypedefTagRename03.ts new file mode 100644 index 00000000000..c1b38945806 --- /dev/null +++ b/tests/cases/fourslash/server/jsdocTypedefTagRename03.ts @@ -0,0 +1,20 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: jsDocTypedef_form3.js +//// +//// /** +//// * @typedef /*1*/[|Person|] +//// * @type {Object} +//// * @property {number} age +//// * @property {string} name +//// */ +//// +//// /** @type {/*2*/[|Person|]} */ +//// var person; + +goTo.file('jsDocTypedef_form3.js') +goTo.marker('1'); +verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ true); +goTo.marker('2'); +verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ true); \ No newline at end of file diff --git a/tests/cases/fourslash/server/jsdocTypedefTagRename04.ts b/tests/cases/fourslash/server/jsdocTypedefTagRename04.ts new file mode 100644 index 00000000000..b7bf220512a --- /dev/null +++ b/tests/cases/fourslash/server/jsdocTypedefTagRename04.ts @@ -0,0 +1,24 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: jsDocTypedef_form2.js +//// +//// function test1() { +//// /** @typedef {(string | number)} NumberLike */ +//// +//// /** @type {/*1*/NumberLike} */ +//// var numberLike; +//// } +//// function test2() { +//// /** @typedef {(string | number)} NumberLike2 */ +//// +//// /** @type {NumberLike2} */ +//// var n/*2*/umberLike2; +//// } + +goTo.marker('2'); +verify.quickInfoExists(); +goTo.marker('1'); +edit.insert('111'); +goTo.marker('2'); +verify.quickInfoExists(); \ No newline at end of file diff --git a/tests/cases/unittests/jsDocParsing.ts b/tests/cases/unittests/jsDocParsing.ts index 1bd7b1147ca..0540c02d135 100644 --- a/tests/cases/unittests/jsDocParsing.ts +++ b/tests/cases/unittests/jsDocParsing.ts @@ -1004,7 +1004,8 @@ module ts { if (result !== expected) { // Turn on a human-readable diff if (typeof require !== 'undefined') { - require('chai').config.showDiff = true; + const chai = require('chai'); + chai.config.showDiff = true; chai.expect(JSON.parse(result)).equal(JSON.parse(expected)); } else { diff --git a/tests/webTestServer.js b/tests/webTestServer.js new file mode 100644 index 00000000000..b47da7bfe76 --- /dev/null +++ b/tests/webTestServer.js @@ -0,0 +1,288 @@ +/// +"use strict"; +var http = require("http"); +var fs = require("fs"); +var path = require("path"); +var url = require("url"); +var child_process = require("child_process"); +var os = require("os"); +/// Command line processing /// +if (process.argv[2] == '--help') { + console.log('Runs a node server on port 8888 by default, looking for tests folder in the current directory\n'); + console.log('Syntax: node nodeServer.js [port] [typescriptEnlistmentDirectory] [tests] [--browser] [--verbose]\n'); + console.log('Examples: \n\tnode nodeServer.js 8888 .'); + console.log('\tnode nodeServer.js 3000 D:/src/typescript/public --verbose IE'); +} +function switchToForwardSlashes(path) { + return path.replace(/\\/g, "/").replace(/\/\//g, '/'); +} +var defaultPort = 8888; +var port = process.argv[2] || defaultPort; +var rootDir = switchToForwardSlashes(__dirname + '/../'); +var browser; +if (process.argv[3]) { + browser = process.argv[3]; + if (browser !== 'chrome' && browser !== 'IE') { + console.log('Invalid command line arguments. Got ' + browser + ' but expected chrome, IE or nothing.'); + } +} +var grep = process.argv[4]; +var verbose = false; +if (process.argv[5] == '--verbose') { + verbose = true; +} +else if (process.argv[5] && process.argv[5] !== '--verbose') { + console.log('Invalid command line arguments. Got ' + process.argv[5] + ' but expected --verbose or nothing.'); +} +/// Utils /// +function log(msg) { + if (verbose) { + console.log(msg); + } +} +// Copied from the compiler sources +function dir(path, spec, options) { + options = options || {}; + function filesInFolder(folder) { + var folder = switchToForwardSlashes(folder); + var paths = []; + // Everything after the current directory is relative + var baseDirectoryLength = process.cwd().length + 1; + try { + var files = fs.readdirSync(folder); + for (var i = 0; i < files.length; i++) { + var stat = fs.statSync(folder + "/" + files[i]); + if (options.recursive && stat.isDirectory()) { + paths = paths.concat(filesInFolder(folder + "/" + files[i])); + } + else if (stat.isFile() && (!spec || files[i].match(spec))) { + var relativePath = folder.substring(baseDirectoryLength); + paths.push(relativePath + "/" + files[i]); + } + } + } + catch (err) { + } + return paths; + } + return filesInFolder(path); +} +// fs.rmdirSync won't delete directories with files in it +function deleteFolderRecursive(path) { + if (fs.existsSync(path)) { + fs.readdirSync(path).forEach(function (file, index) { + var curPath = path + "/" + file; + if (fs.statSync(curPath).isDirectory()) { + deleteFolderRecursive(curPath); + } + else { + fs.unlinkSync(curPath); + } + }); + fs.rmdirSync(path); + } +} +; +function writeFile(path, data, opts) { + try { + fs.writeFileSync(path, data); + } + catch (e) { + // assume file was written to a directory that exists, if not, start recursively creating them as necessary + var parts = switchToForwardSlashes(path).split('/'); + for (var i = 0; i < parts.length; i++) { + var subDir = parts.slice(0, i).join('/'); + if (!fs.existsSync(subDir)) { + fs.mkdir(subDir); + } + } + fs.writeFileSync(path, data); + } +} +/// Request Handling /// +function handleResolutionRequest(filePath, res) { + var resolvedPath = path.resolve(filePath, ''); + resolvedPath = resolvedPath.substring(resolvedPath.indexOf('tests')); + resolvedPath = switchToForwardSlashes(resolvedPath); + send('success', res, resolvedPath); + return; +} +function send(result, res, contents, contentType) { + if (contentType === void 0) { contentType = "binary"; } + var responseCode = result === "success" ? 200 : result === "fail" ? 500 : result === 'unknown' ? 404 : parseInt(result); + res.writeHead(responseCode, { "Content-Type": contentType }); + res.end(contents); + return; +} +// Reads the data from a post request and passes it to the given callback +function processPost(req, res, callback) { + var queryData = ""; + if (typeof callback !== 'function') + return null; + if (req.method == 'POST') { + req.on('data', function (data) { + queryData += data; + if (queryData.length > 1e8) { + queryData = ""; + send("413", res, null); + console.log("ERROR: destroying connection"); + req.connection.destroy(); + } + }); + req.on('end', function () { + //res.post = url.parse(req.url).query; + callback(queryData); + }); + } + else { + send("405", res, null); + } +} +var RequestType; +(function (RequestType) { + RequestType[RequestType["GetFile"] = 0] = "GetFile"; + RequestType[RequestType["GetDir"] = 1] = "GetDir"; + RequestType[RequestType["ResolveFile"] = 2] = "ResolveFile"; + RequestType[RequestType["WriteFile"] = 3] = "WriteFile"; + RequestType[RequestType["DeleteFile"] = 4] = "DeleteFile"; + RequestType[RequestType["WriteDir"] = 5] = "WriteDir"; + RequestType[RequestType["DeleteDir"] = 6] = "DeleteDir"; + RequestType[RequestType["AppendFile"] = 7] = "AppendFile"; + RequestType[RequestType["Unknown"] = 8] = "Unknown"; +})(RequestType || (RequestType = {})); +function getRequestOperation(req, filename) { + if (req.method === 'GET' && req.url.indexOf('?') === -1) { + if (req.url.indexOf('.') !== -1) + return RequestType.GetFile; + else + return RequestType.GetDir; + } + else { + var queryData = url.parse(req.url, true).query; + if (req.method === 'GET' && queryData.resolve !== undefined) + return RequestType.ResolveFile; + // mocha uses ?grep= query string as equivalent to the --grep command line option used to filter tests + if (req.method === 'GET' && queryData.grep !== undefined) + return RequestType.GetFile; + if (req.method === 'POST' && queryData.action) { + var path = req.url.substr(0, req.url.lastIndexOf('?')); + var isFile = path.substring(path.lastIndexOf('/')).indexOf('.') !== -1; + switch (queryData.action.toUpperCase()) { + case 'WRITE': + return isFile ? RequestType.WriteFile : RequestType.WriteDir; + case 'DELETE': + return isFile ? RequestType.DeleteFile : RequestType.DeleteDir; + case 'APPEND': + return isFile ? RequestType.AppendFile : RequestType.Unknown; + } + } + return RequestType.Unknown; + } +} +function handleRequestOperation(req, res, operation, reqPath) { + switch (operation) { + case RequestType.GetDir: + var filesInFolder = dir(reqPath, "", { recursive: true }); + send('success', res, filesInFolder.join(',')); + break; + case RequestType.GetFile: + fs.readFile(reqPath, function (err, file) { + var ext = reqPath.substr(reqPath.lastIndexOf('.')); + var contentType = 'binary'; + if (ext === '.js') + contentType = 'text/javascript'; + else if (ext === '.css') + contentType = 'text/javascript'; + else if (ext === '.html') + contentType = 'text/html'; + err + ? send('fail', res, err.message, contentType) + : send('success', res, file, contentType); + }); + break; + case RequestType.ResolveFile: + var resolveRequest = req.url.match(/(.*)\?resolve/); + handleResolutionRequest(resolveRequest[1], res); + break; + case RequestType.WriteFile: + processPost(req, res, function (data) { + writeFile(reqPath, data, { recursive: true }); + }); + send('success', res, null); + break; + case RequestType.WriteDir: + fs.mkdirSync(reqPath); + send('success', res, null); + break; + case RequestType.DeleteFile: + if (fs.existsSync(reqPath)) { + fs.unlinkSync(reqPath); + } + send('success', res, null); + break; + case RequestType.DeleteDir: + if (fs.existsSync(reqPath)) { + fs.rmdirSync(reqPath); + } + send('success', res, null); + break; + case RequestType.AppendFile: + processPost(req, res, function (data) { + fs.appendFileSync(reqPath, data); + }); + send('success', res, null); + break; + case RequestType.Unknown: + default: + send('unknown', res, null); + break; + } +} +console.log("Static file server running at\n => http://localhost:" + port + "/\nCTRL + C to shutdown"); +http.createServer(function (req, res) { + log(req.method + ' ' + req.url); + var uri = url.parse(req.url).pathname; + var reqPath = path.join(process.cwd(), uri); + var operation = getRequestOperation(req, reqPath); + handleRequestOperation(req, res, operation, reqPath); +}).listen(8888); +var browserPath; +if ((browser && browser === 'chrome')) { + var defaultChromePath = ""; + switch (os.platform()) { + case "win32": + case "win64": + defaultChromePath = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"; + break; + case "darwin": + defaultChromePath = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"; + break; + case "linux": + defaultChromePath = "/opt/google/chrome/chrome"; + break; + default: + console.log("default Chrome location is unknown for platform '" + os.platform() + "'"); + break; + } + if (fs.existsSync(defaultChromePath)) { + browserPath = defaultChromePath; + } + else { + browserPath = browser; + } +} +else { + var defaultIEPath = 'C:/Program Files/Internet Explorer/iexplore.exe'; + if (fs.existsSync(defaultIEPath)) { + browserPath = defaultIEPath; + } + else { + browserPath = browser; + } +} +console.log('Using browser: ' + browserPath); +var queryString = grep ? "?grep=" + grep : ''; +child_process.spawn(browserPath, ['http://localhost:' + port + '/tests/webTestResults.html' + queryString], { + stdio: 'inherit' +}); +//# sourceMappingURL=file:///C:/Users/lizhe/Documents/github/TypeScript/tests/webTestServer.js.map \ No newline at end of file diff --git a/tests/webTestServer.js.map b/tests/webTestServer.js.map new file mode 100644 index 00000000000..1c924a872f4 --- /dev/null +++ b/tests/webTestServer.js.map @@ -0,0 +1 @@ +{"version":3,"file":"webTestServer.js","sourceRoot":"","sources":["file:///C:/Users/lizhe/Documents/github/TypeScript/tests/webTestServer.ts"],"names":[],"mappings":"AAAA,yDAAyD;;AAEzD,IAAO,IAAI,WAAW,MAAM,CAAC,CAAC;AAC9B,IAAO,EAAE,WAAW,IAAI,CAAC,CAAC;AAC1B,IAAO,IAAI,WAAW,MAAM,CAAC,CAAC;AAC9B,IAAO,GAAG,WAAW,KAAK,CAAC,CAAC;AAC5B,IAAO,aAAa,WAAW,eAAe,CAAC,CAAC;AAChD,IAAO,EAAE,WAAW,IAAI,CAAC,CAAC;AAE1B,+BAA+B;AAE/B,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC;IAC9B,OAAO,CAAC,GAAG,CAAC,iGAAiG,CAAC,CAAC;IAC/G,OAAO,CAAC,GAAG,CAAC,qGAAqG,CAAC,CAAC;IACnH,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;IACvD,OAAO,CAAC,GAAG,CAAC,iEAAiE,CAAC,CAAC;AACnF,CAAC;AAED,gCAAgC,IAAY;IACxC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AAC1D,CAAC;AAED,IAAI,WAAW,GAAG,IAAI,CAAC;AACvB,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC;AAC1C,IAAI,OAAO,GAAG,sBAAsB,CAAC,SAAS,GAAG,MAAM,CAAC,CAAC;AAEzD,IAAI,OAAe,CAAC;AACpB,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClB,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1B,EAAE,CAAC,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,sCAAsC,GAAG,OAAO,GAAG,sCAAsC,CAAC,CAAC;IAC3G,CAAC;AACL,CAAC;AAED,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAE3B,IAAI,OAAO,GAAG,KAAK,CAAC;AACpB,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC;IACjC,OAAO,GAAG,IAAI,CAAC;AACnB,CAAC;AAAC,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC;IAC5D,OAAO,CAAC,GAAG,CAAC,sCAAsC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,qCAAqC,CAAC,CAAC;AAClH,CAAC;AAED,aAAa;AACb,aAAa,GAAW;IACpB,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;QACV,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;AACL,CAAC;AAED,mCAAmC;AACnC,aAAa,IAAY,EAAE,IAAa,EAAE,OAAa;IACnD,OAAO,GAAG,OAAO,IAA8B,EAAE,CAAC;IAElD,uBAAuB,MAAc;QACjC,IAAI,MAAM,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;QAC5C,IAAI,KAAK,GAAa,EAAE,CAAC;QACzB,qDAAqD;QACrD,IAAI,mBAAmB,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;QAEnD,IAAI,CAAC;YACD,IAAI,KAAK,GAAG,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YACnC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBACpC,IAAI,IAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,MAAM,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAChD,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;oBAC1C,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACjE,CAAC;gBAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;oBAC1D,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;oBACzD,KAAK,CAAC,IAAI,CAAC,YAAY,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC9C,CAAC;YACL,CAAC;QACL,CAAE;QAAA,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAEf,CAAC;QACD,MAAM,CAAC,KAAK,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC;AAED,yDAAyD;AACzD,+BAA+B,IAAY;IACvC,EAAE,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACtB,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,KAAK;YAC9C,IAAI,OAAO,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC;YAChC,EAAE,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;gBACrC,qBAAqB,CAAC,OAAO,CAAC,CAAC;YACnC,CAAC;YAAC,IAAI,CAAC,CAAC;gBACJ,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YAC3B,CAAC;QACL,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;AACL,CAAC;AAAA,CAAC;AAEF,mBAAmB,IAAY,EAAE,IAAS,EAAE,IAA4B;IACpE,IAAI,CAAC;QACD,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACjC,CAAE;IAAA,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACT,2GAA2G;QAC3G,IAAI,KAAK,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACpD,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACpC,IAAI,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACzC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACzB,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YACrB,CAAC;QACL,CAAC;QACD,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;AACL,CAAC;AAED,wBAAwB;AAExB,iCAAiC,QAAgB,EAAE,GAAwB;IACvE,IAAI,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAC9C,YAAY,GAAG,YAAY,CAAC,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IACrE,YAAY,GAAG,sBAAsB,CAAC,YAAY,CAAC,CAAC;IACpD,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC;IACnC,MAAM,CAAC;AACX,CAAC;AAMD,cAAc,MAAc,EAAE,GAAwB,EAAE,QAAgB,EAAE,WAAsB;IAAtB,2BAAsB,GAAtB,sBAAsB;IAC5F,IAAI,YAAY,GAAG,MAAM,KAAK,SAAS,GAAG,GAAG,GAAG,MAAM,KAAK,MAAM,GAAG,GAAG,GAAG,MAAM,KAAK,SAAS,GAAG,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IACxH,GAAG,CAAC,SAAS,CAAC,YAAY,EAAE,EAAE,cAAc,EAAE,WAAW,EAAE,CAAC,CAAC;IAC7D,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAClB,MAAM,CAAC;AACX,CAAC;AAED,yEAAyE;AACzE,qBAAqB,GAAuB,EAAE,GAAwB,EAAE,QAA+B;IACnG,IAAI,SAAS,GAAG,EAAE,CAAC;IACnB,EAAE,CAAC,CAAC,OAAO,QAAQ,KAAK,UAAU,CAAC;QAAC,MAAM,CAAC,IAAI,CAAC;IAEhD,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC;QACvB,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,IAAY;YACjC,SAAS,IAAI,IAAI,CAAC;YAClB,EAAE,CAAC,CAAC,SAAS,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC;gBACzB,SAAS,GAAG,EAAE,CAAC;gBACf,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;gBACvB,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;gBAC5C,GAAG,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;YAC7B,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE;YACV,sCAAsC;YACtC,QAAQ,CAAC,SAAS,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;IAEP,CAAC;IAAC,IAAI,CAAC,CAAC;QACJ,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IAC3B,CAAC;AACL,CAAC;AAED,IAAK,WAUJ;AAVD,WAAK,WAAW;IACZ,mDAAO,CAAA;IACP,iDAAM,CAAA;IACN,2DAAW,CAAA;IACX,uDAAS,CAAA;IACT,yDAAU,CAAA;IACV,qDAAQ,CAAA;IACR,uDAAS,CAAA;IACT,yDAAU,CAAA;IACV,mDAAO,CAAA;AACX,CAAC,EAVI,WAAW,KAAX,WAAW,QAUf;AAED,6BAA6B,GAAuB,EAAE,QAAgB;IAClE,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,KAAK,KAAK,IAAI,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACtD,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;YAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC;QAC5D,IAAI;YAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC;IACnC,CAAC;IACD,IAAI,CAAC,CAAC;QACF,IAAI,SAAS,GAAQ,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC;QACpD,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,KAAK,KAAK,IAAI,SAAS,CAAC,OAAO,KAAK,SAAS,CAAC;YAAC,MAAM,CAAC,WAAW,CAAC,WAAW,CAAA;QAC3F,8GAA8G;QAC9G,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,KAAK,KAAK,IAAI,SAAS,CAAC,IAAI,KAAK,SAAS,CAAC;YAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAA;QACpF,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,KAAK,MAAM,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;YAC5C,IAAI,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;YACvD,IAAI,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;YACvE,MAAM,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;gBACrC,KAAK,OAAO;oBACR,MAAM,CAAC,MAAM,GAAG,WAAW,CAAC,SAAS,GAAG,WAAW,CAAC,QAAQ,CAAC;gBACjE,KAAK,QAAQ;oBACT,MAAM,CAAC,MAAM,GAAG,WAAW,CAAC,UAAU,GAAG,WAAW,CAAC,SAAS,CAAC;gBACnE,KAAK,QAAQ;oBACT,MAAM,CAAC,MAAM,GAAG,WAAW,CAAC,UAAU,GAAG,WAAW,CAAC,OAAO,CAAC;YACrE,CAAC;QACL,CAAC;QACD,MAAM,CAAC,WAAW,CAAC,OAAO,CAAA;IAC9B,CAAC;AACL,CAAC;AAED,gCAAgC,GAAuB,EAAE,GAAwB,EAAE,SAAsB,EAAE,OAAe;IACtH,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;QAChB,KAAK,WAAW,CAAC,MAAM;YACnB,IAAI,aAAa,GAAG,GAAG,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC1D,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YAC9C,KAAK,CAAC;QACV,KAAK,WAAW,CAAC,OAAO;YACpB,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,EAAE,IAAI;gBACpC,IAAI,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;gBACnD,IAAI,WAAW,GAAG,QAAQ,CAAC;gBAC3B,EAAE,CAAC,CAAC,GAAG,KAAK,KAAK,CAAC;oBAAC,WAAW,GAAG,iBAAiB,CAAA;gBAClD,IAAI,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,MAAM,CAAC;oBAAC,WAAW,GAAG,iBAAiB,CAAA;gBACxD,IAAI,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,OAAO,CAAC;oBAAC,WAAW,GAAG,WAAW,CAAA;gBACnD,GAAG;sBACD,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC;sBAC3C,IAAI,CAAC,SAAS,EAAE,GAAG,EAAQ,IAAK,EAAE,WAAW,CAAC,CAAC;YACrD,CAAC,CAAC,CAAC;YACH,KAAK,CAAC;QACV,KAAK,WAAW,CAAC,WAAW;YACxB,IAAI,cAAc,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;YACpD,uBAAuB,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YAChD,KAAK,CAAC;QACV,KAAK,WAAW,CAAC,SAAS;YACtB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,UAAC,IAAI;gBACvB,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAClD,CAAC,CAAC,CAAC;YACH,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YAC3B,KAAK,CAAC;QACV,KAAK,WAAW,CAAC,QAAQ;YACrB,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YACtB,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YAC3B,KAAK,CAAC;QACV,KAAK,WAAW,CAAC,UAAU;YACvB,EAAE,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;gBACzB,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YAC3B,CAAC;YACD,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YAC3B,KAAK,CAAC;QACV,KAAK,WAAW,CAAC,SAAS;YACtB,EAAE,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;gBACzB,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YAC1B,CAAC;YACD,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YAC3B,KAAK,CAAC;QACV,KAAK,WAAW,CAAC,UAAU;YACvB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,UAAC,IAAI;gBACvB,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YACrC,CAAC,CAAC,CAAC;YACH,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YAC3B,KAAK,CAAC;QACV,KAAK,WAAW,CAAC,OAAO,CAAC;QACzB;YACI,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YAC3B,KAAK,CAAC;IACd,CAAC;AACL,CAAC;AAED,OAAO,CAAC,GAAG,CAAC,uDAAuD,GAAG,IAAI,GAAG,yBAAyB,CAAC,CAAC;AAExG,IAAI,CAAC,YAAY,CAAC,UAAU,GAAuB,EAAE,GAAwB;IACzE,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IAChC,IAAI,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAA;IACrC,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC;IAC5C,IAAI,SAAS,GAAG,mBAAmB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAClD,sBAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AACzD,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAEhB,IAAI,WAAmB,CAAC;AACxB,EAAE,CAAC,CAAC,CAAC,OAAO,IAAI,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC;IACpC,IAAI,iBAAiB,GAAG,EAAE,CAAC;IAC3B,MAAM,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QACpB,KAAK,OAAO,CAAC;QACb,KAAK,OAAO;YACR,iBAAiB,GAAG,6DAA6D,CAAC;YAClF,KAAK,CAAC;QACV,KAAK,QAAQ;YACT,iBAAiB,GAAG,8DAA8D,CAAC;YACnF,KAAK,CAAC;QACV,KAAK,OAAO;YACR,iBAAiB,GAAG,2BAA2B,CAAA;YAC/C,KAAK,CAAC;QACV;YACI,OAAO,CAAC,GAAG,CAAC,sDAAoD,EAAE,CAAC,QAAQ,EAAE,MAAG,CAAC,CAAC;YAClF,KAAK,CAAC;IACd,CAAC;IACD,EAAE,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;QACnC,WAAW,GAAG,iBAAiB,CAAC;IACpC,CAAC;IAAC,IAAI,CAAC,CAAC;QACJ,WAAW,GAAG,OAAO,CAAC;IAC1B,CAAC;AACL,CAAC;AAAC,IAAI,CAAC,CAAC;IACJ,IAAI,aAAa,GAAG,iDAAiD,CAAC;IACtE,EAAE,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;QAC/B,WAAW,GAAG,aAAa,CAAC;IAChC,CAAC;IAAC,IAAI,CAAC,CAAC;QACJ,WAAW,GAAG,OAAO,CAAC;IAC1B,CAAC;AACL,CAAC;AAED,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,WAAW,CAAC,CAAC;AAE7C,IAAI,WAAW,GAAG,IAAI,GAAG,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAC;AAC9C,aAAa,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,mBAAmB,GAAG,IAAI,GAAG,4BAA4B,GAAG,WAAW,CAAC,EAAE;IACxG,KAAK,EAAE,SAAS;CACnB,CAAC,CAAC"} \ No newline at end of file From 0dddcf4b84ee3eba1413a1591984605ef4940708 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Thu, 14 Apr 2016 16:51:22 -0700 Subject: [PATCH 05/61] code clean up --- src/compiler/parser.ts | 38 ++- src/compiler/types.ts | 2 + src/compiler/utilities.ts | 32 +-- src/harness/harness.ts | 4 +- src/services/services.ts | 9 +- tests/cases/fourslash/commentsVariables.ts | 80 +++--- tests/cases/fourslash/doesnotwork.ts | 45 ---- tests/webTestServer.js | 288 --------------------- tests/webTestServer.js.map | 1 - 9 files changed, 72 insertions(+), 427 deletions(-) delete mode 100644 tests/cases/fourslash/doesnotwork.ts delete mode 100644 tests/webTestServer.js delete mode 100644 tests/webTestServer.js.map diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 058098eff1d..3a1c3c62f41 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -409,7 +409,6 @@ namespace ts { return visitNodes(cbNodes, (node).members); case SyntaxKind.JSDocPropertyTag: return visitNode(cbNode, (node).typeExpression) || - visitNode(cbNode, (node).type) || visitNode(cbNode, (node).name); } } @@ -4063,9 +4062,9 @@ namespace ts { const isAsync = !!(node.flags & NodeFlags.Async); node.name = isGenerator && isAsync ? doInYieldAndAwaitContext(parseOptionalIdentifier) : - isGenerator ? doInYieldContext(parseOptionalIdentifier) : - isAsync ? doInAwaitContext(parseOptionalIdentifier) : - parseOptionalIdentifier(); + isGenerator ? doInYieldContext(parseOptionalIdentifier) : + isAsync ? doInAwaitContext(parseOptionalIdentifier) : + parseOptionalIdentifier(); fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, node); node.body = parseFunctionBlock(/*allowYield*/ isGenerator, /*allowAwait*/ isAsync, /*ignoreMissingOpenBrace*/ false); @@ -6121,15 +6120,13 @@ namespace ts { typedefTag.type = typedefTag.jsDocTypeTag.typeExpression.type; } } - if (!typedefTag.type && typedefTag.jsDocPropertyTags) { - const childrenTagPoses = ts.map(typedefTag.jsDocPropertyTags, tag => tag.pos); - const childrenTagEnds = ts.map(typedefTag.jsDocPropertyTags, tag => tag.end); - const pos = Math.min(...childrenTagPoses); - const end = Math.max(...childrenTagEnds); - const tagType = createNode(SyntaxKind.JSDocTypeLiteral, pos); - tagType.members = >[]; - addRange(tagType.members, typedefTag.jsDocPropertyTags); - typedefTag.type = finishNode(tagType, end); + if (!typedefTag.type && typedefTag.jsDocPropertyTags && typedefTag.jsDocPropertyTags.length > 0) { + const pos = typedefTag.jsDocPropertyTags[0].pos; + const end = typedefTag.jsDocPropertyTags[typedefTag.jsDocPropertyTags.length - 1].end; + const jsdocTypeLiteral = createNode(SyntaxKind.JSDocTypeLiteral, pos); + jsdocTypeLiteral.members = >[]; + addRange(jsdocTypeLiteral.members, typedefTag.jsDocPropertyTags); + typedefTag.type = finishNode(jsdocTypeLiteral, end); } } @@ -6303,23 +6300,18 @@ namespace ts { result.typeExpression = tryParseTypeExpression(); result = finishNode(result); - let typeTagPartOfParentTag = false; if (currentParentJSDocTag && currentParentJSDocTag.kind === SyntaxKind.JSDocTypedefTag) { const parentTag = currentParentJSDocTag; if (!parentTag.typeExpression && !parentTag.jsDocTypeTag) { - typeTagPartOfParentTag = true; parentTag.jsDocTypeTag = result; currentParentJSDocTagEnd = scanner.getStartPos(); + return result; } } - if (!typeTagPartOfParentTag) { - // If this @type tag is not part of the current parent tag, then - // it denotes the end of the current parent tag. - finishCurrentParentTag(); - return result; - } - - return undefined; + // If this @type tag is not part of the current parent tag, then + // it denotes the end of the current parent tag. + finishCurrentParentTag(); + return result; } function handlePropertyTag(atToken: Node, tagName: Identifier): JSDocPropertyTag { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 7743f7c35de..91ce1f1022f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1533,6 +1533,8 @@ namespace ts { export interface JSDocPropertyTag extends JSDocTag, TypeElement { name: Identifier; typeExpression: JSDocTypeExpression; + // Add a "type" property here to make the interface compatible + // with the "VariableLikeDeclaration" definition type: TypeNode; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index ebf6b42581a..2f29e477d69 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -279,13 +279,16 @@ namespace ts { return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos, /*stopAfterLineBreak*/ false, /*stopAtComments*/ true); } - if (node.jsDocComments && node.jsDocComments.length > 0 && includeJsDocComment) { + if (includeJsDocComment && node.jsDocComments && node.jsDocComments.length > 0) { return getTokenPosOfNode(node.jsDocComments[0]); } - if (node.kind === SyntaxKind.SyntaxList) { - const childrenPoses = ts.map((node)._children, child => getTokenPosOfNode(child, sourceFile, includeJsDocComment)); - return Math.min(...childrenPoses); + // For a syntax list, it is possible that one of its children has JSDocComment nodes, while + // the syntax list itself considers them as normal trivia. Therefore if we simply skip + // trivia for the list, we may have skipped the JSDocComment as well. So we should process its + // first child to determine the actual position of its first token. + if (node.kind === SyntaxKind.SyntaxList && (node)._children.length > 0) { + return getTokenPosOfNode((node)._children[0], sourceFile, includeJsDocComment); } return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos); @@ -294,27 +297,6 @@ namespace ts { export function isJSDocNode(node: Node) { return node.kind >= SyntaxKind.FirstJSDocNode && node.kind <= SyntaxKind.LastJSDocNode; } - export function isJSDocType(node: Node) { - switch (node.kind) { - case SyntaxKind.JSDocAllType: - case SyntaxKind.JSDocUnknownType: - case SyntaxKind.JSDocArrayType: - case SyntaxKind.JSDocUnionType: - case SyntaxKind.JSDocTupleType: - case SyntaxKind.JSDocNullableType: - case SyntaxKind.JSDocNonNullableType: - case SyntaxKind.JSDocRecordType: - case SyntaxKind.JSDocRecordMember: - case SyntaxKind.JSDocTypeReference: - case SyntaxKind.JSDocOptionalType: - case SyntaxKind.JSDocFunctionType: - case SyntaxKind.JSDocVariadicType: - case SyntaxKind.JSDocConstructorType: - case SyntaxKind.JSDocThisType: - return true; - } - return false; - } export function getNonDecoratorTokenPosOfNode(node: Node, sourceFile?: SourceFile): number { if (nodeIsMissing(node) || !node.decorators) { diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 790ecebb75f..e07fe60ba86 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -222,7 +222,9 @@ namespace Utils { return k; } - if (k === (ts).SyntaxKind.FirstJSDocCommentNode || k === (ts).SyntaxKind.LastJSDocCommentNode) { + // For some markers in SyntaxKind, we should print its original syntax name instead of + // the marker name in tests. + if (k === (ts).SyntaxKind.FirstJSDocNode || k === (ts).SyntaxKind.LastJSDocNode) { for (const kindName in (ts).SyntaxKind) { if ((ts).SyntaxKind[kindName] === k) { return kindName; diff --git a/src/services/services.ts b/src/services/services.ts index f2906aaa8b4..ffbb174fe8c 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -173,6 +173,7 @@ namespace ts { "type", "typedef", "property", + "prop", "version" ]; let jsDocCompletionEntries: CompletionEntry[]; @@ -274,7 +275,7 @@ namespace ts { scanner.setText((sourceFile || this.getSourceFile()).text); children = []; let pos = this.pos; - const isJSDocTag = + const useJSDocScanner = this.kind === SyntaxKind.JSDocComment || this.kind === SyntaxKind.JSDocParameterTag || this.kind === SyntaxKind.JSDocTag || @@ -286,14 +287,14 @@ namespace ts { this.kind === SyntaxKind.JSDocPropertyTag; const processNode = (node: Node) => { if (pos < node.pos) { - pos = this.addSyntheticNodes(children, pos, node.pos, /*useJSDocScanner*/ isJSDocTag); + pos = this.addSyntheticNodes(children, pos, node.pos, useJSDocScanner); } children.push(node); pos = node.end; }; const processNodes = (nodes: NodeArray) => { if (pos < nodes.pos) { - pos = this.addSyntheticNodes(children, pos, nodes.pos, /*useJSDocScanner*/ isJSDocTag); + pos = this.addSyntheticNodes(children, pos, nodes.pos, useJSDocScanner); } children.push(this.createSyntaxList(>nodes)); pos = nodes.end; @@ -7803,7 +7804,7 @@ namespace ts { break; default: forEachChild(node, walk); - if (node.jsDocComments && node.jsDocComments.length > 0) { + if (node.jsDocComments) { for (const jsDocComment of node.jsDocComments) { forEachChild(jsDocComment, walk); } diff --git a/tests/cases/fourslash/commentsVariables.ts b/tests/cases/fourslash/commentsVariables.ts index b2cf6c9cb9b..d62e1e9bee8 100644 --- a/tests/cases/fourslash/commentsVariables.ts +++ b/tests/cases/fourslash/commentsVariables.ts @@ -41,60 +41,60 @@ ////} ////var x = fo/*15*/o2; -// goTo.marker('1'); -// verify.quickInfoIs("var myVariable: number", "This is my variable"); +goTo.marker('1'); +verify.quickInfoIs("var myVariable: number", "This is my variable"); -// goTo.marker('2'); -// verify.completionListContains("myVariable", "var myVariable: number", "This is my variable"); +goTo.marker('2'); +verify.completionListContains("myVariable", "var myVariable: number", "This is my variable"); -// goTo.marker('3'); -// verify.completionListContains("myVariable", "var myVariable: number", "This is my variable"); -// verify.completionListContains("d", "var d: number", "d variable"); +goTo.marker('3'); +verify.completionListContains("myVariable", "var myVariable: number", "This is my variable"); +verify.completionListContains("d", "var d: number", "d variable"); goTo.marker('4'); verify.completionListContains("foo", "function foo(): void", "foos comment"); verify.completionListContains("fooVar", "var fooVar: () => void", "fooVar comment"); -// goTo.marker('5'); -// verify.currentSignatureHelpDocCommentIs("foos comment"); -// goTo.marker('5q'); -// verify.quickInfoIs("function foo(): void", "foos comment"); +goTo.marker('5'); +verify.currentSignatureHelpDocCommentIs("foos comment"); +goTo.marker('5q'); +verify.quickInfoIs("function foo(): void", "foos comment"); -// goTo.marker('6'); -// verify.currentSignatureHelpDocCommentIs(""); -// goTo.marker('6q'); -// verify.quickInfoIs("var fooVar: () => void", ""); +goTo.marker('6'); +verify.currentSignatureHelpDocCommentIs(""); +goTo.marker('6q'); +verify.quickInfoIs("var fooVar: () => void", ""); -// goTo.marker('7'); -// verify.completionListContains("foo", "function foo(): void", "foos comment"); -// verify.completionListContains("fooVar", "var fooVar: () => void", "fooVar comment"); +goTo.marker('7'); +verify.completionListContains("foo", "function foo(): void", "foos comment"); +verify.completionListContains("fooVar", "var fooVar: () => void", "fooVar comment"); -// goTo.marker('8'); -// verify.currentSignatureHelpDocCommentIs("foos comment"); -// goTo.marker('8q'); -// verify.quickInfoIs("function foo(): void", "foos comment"); +goTo.marker('8'); +verify.currentSignatureHelpDocCommentIs("foos comment"); +goTo.marker('8q'); +verify.quickInfoIs("function foo(): void", "foos comment"); -// goTo.marker('9'); -// verify.currentSignatureHelpDocCommentIs(""); -// goTo.marker('9q'); -// verify.quickInfoIs("var fooVar: () => void", ""); -// goTo.marker('9aq'); -// verify.quickInfoIs("var fooVar: () => void", "fooVar comment"); +goTo.marker('9'); +verify.currentSignatureHelpDocCommentIs(""); +goTo.marker('9q'); +verify.quickInfoIs("var fooVar: () => void", ""); +goTo.marker('9aq'); +verify.quickInfoIs("var fooVar: () => void", "fooVar comment"); -// goTo.marker('10'); -// verify.completionListContains("i", "var i: c", "instance comment"); +goTo.marker('10'); +verify.completionListContains("i", "var i: c", "instance comment"); -// goTo.marker('11'); -// verify.completionListContains("i1_i", "var i1_i: i1", "interface instance comments"); +goTo.marker('11'); +verify.completionListContains("i1_i", "var i1_i: i1", "interface instance comments"); -// goTo.marker('12'); -// verify.quickInfoIs("var fooVar: () => void", "fooVar comment"); +goTo.marker('12'); +verify.quickInfoIs("var fooVar: () => void", "fooVar comment"); -// goTo.marker('13'); -// verify.quickInfoIs("var fooVar: () => void", "fooVar comment"); +goTo.marker('13'); +verify.quickInfoIs("var fooVar: () => void", "fooVar comment"); -// goTo.marker('14'); -// verify.quickInfoIs("function foo(): void", "foos comment"); +goTo.marker('14'); +verify.quickInfoIs("function foo(): void", "foos comment"); -// goTo.marker('15'); -// verify.quickInfoIs("function foo2(a: number): void (+1 overload)", ""); +goTo.marker('15'); +verify.quickInfoIs("function foo2(a: number): void (+1 overload)", ""); diff --git a/tests/cases/fourslash/doesnotwork.ts b/tests/cases/fourslash/doesnotwork.ts deleted file mode 100644 index 2f415563c21..00000000000 --- a/tests/cases/fourslash/doesnotwork.ts +++ /dev/null @@ -1,45 +0,0 @@ -/// - -/////** This is my variable*/ -////var myVariable = 10; -//// -/////** d variable*/ -////var d = 10; -////myVariable = d; -//// -/////** foos comment*/ -////function foo() { -////} -/////** fooVar comment*/ -////var fooVar: () => void; -/////*4*/ -////foo(); -////fooVar(); -////fooVar = foo; -//// -////foo(); -////fooVar(); -////var fooVarVar = fooVar; -/////**class comment*/ -////class c { -//// /** constructor comment*/ -//// constructor() { -//// } -////} -/////**instance comment*/ -////var i = new c(); -//// -/////** interface comments*/ -////interface i1 { -////} -/////**interface instance comments*/ -////var i1_i: i1; -//// -////function foo2(a: number): void; -////function foo2(b: string): void; -////function foo2(aOrb) { -////} -////var x = foo2; - -goTo.marker('4'); -verify.completionListContains("fooVar", "var fooVar: () => void", "fooVar comment"); diff --git a/tests/webTestServer.js b/tests/webTestServer.js deleted file mode 100644 index b47da7bfe76..00000000000 --- a/tests/webTestServer.js +++ /dev/null @@ -1,288 +0,0 @@ -/// -"use strict"; -var http = require("http"); -var fs = require("fs"); -var path = require("path"); -var url = require("url"); -var child_process = require("child_process"); -var os = require("os"); -/// Command line processing /// -if (process.argv[2] == '--help') { - console.log('Runs a node server on port 8888 by default, looking for tests folder in the current directory\n'); - console.log('Syntax: node nodeServer.js [port] [typescriptEnlistmentDirectory] [tests] [--browser] [--verbose]\n'); - console.log('Examples: \n\tnode nodeServer.js 8888 .'); - console.log('\tnode nodeServer.js 3000 D:/src/typescript/public --verbose IE'); -} -function switchToForwardSlashes(path) { - return path.replace(/\\/g, "/").replace(/\/\//g, '/'); -} -var defaultPort = 8888; -var port = process.argv[2] || defaultPort; -var rootDir = switchToForwardSlashes(__dirname + '/../'); -var browser; -if (process.argv[3]) { - browser = process.argv[3]; - if (browser !== 'chrome' && browser !== 'IE') { - console.log('Invalid command line arguments. Got ' + browser + ' but expected chrome, IE or nothing.'); - } -} -var grep = process.argv[4]; -var verbose = false; -if (process.argv[5] == '--verbose') { - verbose = true; -} -else if (process.argv[5] && process.argv[5] !== '--verbose') { - console.log('Invalid command line arguments. Got ' + process.argv[5] + ' but expected --verbose or nothing.'); -} -/// Utils /// -function log(msg) { - if (verbose) { - console.log(msg); - } -} -// Copied from the compiler sources -function dir(path, spec, options) { - options = options || {}; - function filesInFolder(folder) { - var folder = switchToForwardSlashes(folder); - var paths = []; - // Everything after the current directory is relative - var baseDirectoryLength = process.cwd().length + 1; - try { - var files = fs.readdirSync(folder); - for (var i = 0; i < files.length; i++) { - var stat = fs.statSync(folder + "/" + files[i]); - if (options.recursive && stat.isDirectory()) { - paths = paths.concat(filesInFolder(folder + "/" + files[i])); - } - else if (stat.isFile() && (!spec || files[i].match(spec))) { - var relativePath = folder.substring(baseDirectoryLength); - paths.push(relativePath + "/" + files[i]); - } - } - } - catch (err) { - } - return paths; - } - return filesInFolder(path); -} -// fs.rmdirSync won't delete directories with files in it -function deleteFolderRecursive(path) { - if (fs.existsSync(path)) { - fs.readdirSync(path).forEach(function (file, index) { - var curPath = path + "/" + file; - if (fs.statSync(curPath).isDirectory()) { - deleteFolderRecursive(curPath); - } - else { - fs.unlinkSync(curPath); - } - }); - fs.rmdirSync(path); - } -} -; -function writeFile(path, data, opts) { - try { - fs.writeFileSync(path, data); - } - catch (e) { - // assume file was written to a directory that exists, if not, start recursively creating them as necessary - var parts = switchToForwardSlashes(path).split('/'); - for (var i = 0; i < parts.length; i++) { - var subDir = parts.slice(0, i).join('/'); - if (!fs.existsSync(subDir)) { - fs.mkdir(subDir); - } - } - fs.writeFileSync(path, data); - } -} -/// Request Handling /// -function handleResolutionRequest(filePath, res) { - var resolvedPath = path.resolve(filePath, ''); - resolvedPath = resolvedPath.substring(resolvedPath.indexOf('tests')); - resolvedPath = switchToForwardSlashes(resolvedPath); - send('success', res, resolvedPath); - return; -} -function send(result, res, contents, contentType) { - if (contentType === void 0) { contentType = "binary"; } - var responseCode = result === "success" ? 200 : result === "fail" ? 500 : result === 'unknown' ? 404 : parseInt(result); - res.writeHead(responseCode, { "Content-Type": contentType }); - res.end(contents); - return; -} -// Reads the data from a post request and passes it to the given callback -function processPost(req, res, callback) { - var queryData = ""; - if (typeof callback !== 'function') - return null; - if (req.method == 'POST') { - req.on('data', function (data) { - queryData += data; - if (queryData.length > 1e8) { - queryData = ""; - send("413", res, null); - console.log("ERROR: destroying connection"); - req.connection.destroy(); - } - }); - req.on('end', function () { - //res.post = url.parse(req.url).query; - callback(queryData); - }); - } - else { - send("405", res, null); - } -} -var RequestType; -(function (RequestType) { - RequestType[RequestType["GetFile"] = 0] = "GetFile"; - RequestType[RequestType["GetDir"] = 1] = "GetDir"; - RequestType[RequestType["ResolveFile"] = 2] = "ResolveFile"; - RequestType[RequestType["WriteFile"] = 3] = "WriteFile"; - RequestType[RequestType["DeleteFile"] = 4] = "DeleteFile"; - RequestType[RequestType["WriteDir"] = 5] = "WriteDir"; - RequestType[RequestType["DeleteDir"] = 6] = "DeleteDir"; - RequestType[RequestType["AppendFile"] = 7] = "AppendFile"; - RequestType[RequestType["Unknown"] = 8] = "Unknown"; -})(RequestType || (RequestType = {})); -function getRequestOperation(req, filename) { - if (req.method === 'GET' && req.url.indexOf('?') === -1) { - if (req.url.indexOf('.') !== -1) - return RequestType.GetFile; - else - return RequestType.GetDir; - } - else { - var queryData = url.parse(req.url, true).query; - if (req.method === 'GET' && queryData.resolve !== undefined) - return RequestType.ResolveFile; - // mocha uses ?grep= query string as equivalent to the --grep command line option used to filter tests - if (req.method === 'GET' && queryData.grep !== undefined) - return RequestType.GetFile; - if (req.method === 'POST' && queryData.action) { - var path = req.url.substr(0, req.url.lastIndexOf('?')); - var isFile = path.substring(path.lastIndexOf('/')).indexOf('.') !== -1; - switch (queryData.action.toUpperCase()) { - case 'WRITE': - return isFile ? RequestType.WriteFile : RequestType.WriteDir; - case 'DELETE': - return isFile ? RequestType.DeleteFile : RequestType.DeleteDir; - case 'APPEND': - return isFile ? RequestType.AppendFile : RequestType.Unknown; - } - } - return RequestType.Unknown; - } -} -function handleRequestOperation(req, res, operation, reqPath) { - switch (operation) { - case RequestType.GetDir: - var filesInFolder = dir(reqPath, "", { recursive: true }); - send('success', res, filesInFolder.join(',')); - break; - case RequestType.GetFile: - fs.readFile(reqPath, function (err, file) { - var ext = reqPath.substr(reqPath.lastIndexOf('.')); - var contentType = 'binary'; - if (ext === '.js') - contentType = 'text/javascript'; - else if (ext === '.css') - contentType = 'text/javascript'; - else if (ext === '.html') - contentType = 'text/html'; - err - ? send('fail', res, err.message, contentType) - : send('success', res, file, contentType); - }); - break; - case RequestType.ResolveFile: - var resolveRequest = req.url.match(/(.*)\?resolve/); - handleResolutionRequest(resolveRequest[1], res); - break; - case RequestType.WriteFile: - processPost(req, res, function (data) { - writeFile(reqPath, data, { recursive: true }); - }); - send('success', res, null); - break; - case RequestType.WriteDir: - fs.mkdirSync(reqPath); - send('success', res, null); - break; - case RequestType.DeleteFile: - if (fs.existsSync(reqPath)) { - fs.unlinkSync(reqPath); - } - send('success', res, null); - break; - case RequestType.DeleteDir: - if (fs.existsSync(reqPath)) { - fs.rmdirSync(reqPath); - } - send('success', res, null); - break; - case RequestType.AppendFile: - processPost(req, res, function (data) { - fs.appendFileSync(reqPath, data); - }); - send('success', res, null); - break; - case RequestType.Unknown: - default: - send('unknown', res, null); - break; - } -} -console.log("Static file server running at\n => http://localhost:" + port + "/\nCTRL + C to shutdown"); -http.createServer(function (req, res) { - log(req.method + ' ' + req.url); - var uri = url.parse(req.url).pathname; - var reqPath = path.join(process.cwd(), uri); - var operation = getRequestOperation(req, reqPath); - handleRequestOperation(req, res, operation, reqPath); -}).listen(8888); -var browserPath; -if ((browser && browser === 'chrome')) { - var defaultChromePath = ""; - switch (os.platform()) { - case "win32": - case "win64": - defaultChromePath = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"; - break; - case "darwin": - defaultChromePath = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"; - break; - case "linux": - defaultChromePath = "/opt/google/chrome/chrome"; - break; - default: - console.log("default Chrome location is unknown for platform '" + os.platform() + "'"); - break; - } - if (fs.existsSync(defaultChromePath)) { - browserPath = defaultChromePath; - } - else { - browserPath = browser; - } -} -else { - var defaultIEPath = 'C:/Program Files/Internet Explorer/iexplore.exe'; - if (fs.existsSync(defaultIEPath)) { - browserPath = defaultIEPath; - } - else { - browserPath = browser; - } -} -console.log('Using browser: ' + browserPath); -var queryString = grep ? "?grep=" + grep : ''; -child_process.spawn(browserPath, ['http://localhost:' + port + '/tests/webTestResults.html' + queryString], { - stdio: 'inherit' -}); -//# sourceMappingURL=file:///C:/Users/lizhe/Documents/github/TypeScript/tests/webTestServer.js.map \ No newline at end of file diff --git a/tests/webTestServer.js.map b/tests/webTestServer.js.map deleted file mode 100644 index 1c924a872f4..00000000000 --- a/tests/webTestServer.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"webTestServer.js","sourceRoot":"","sources":["file:///C:/Users/lizhe/Documents/github/TypeScript/tests/webTestServer.ts"],"names":[],"mappings":"AAAA,yDAAyD;;AAEzD,IAAO,IAAI,WAAW,MAAM,CAAC,CAAC;AAC9B,IAAO,EAAE,WAAW,IAAI,CAAC,CAAC;AAC1B,IAAO,IAAI,WAAW,MAAM,CAAC,CAAC;AAC9B,IAAO,GAAG,WAAW,KAAK,CAAC,CAAC;AAC5B,IAAO,aAAa,WAAW,eAAe,CAAC,CAAC;AAChD,IAAO,EAAE,WAAW,IAAI,CAAC,CAAC;AAE1B,+BAA+B;AAE/B,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC;IAC9B,OAAO,CAAC,GAAG,CAAC,iGAAiG,CAAC,CAAC;IAC/G,OAAO,CAAC,GAAG,CAAC,qGAAqG,CAAC,CAAC;IACnH,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;IACvD,OAAO,CAAC,GAAG,CAAC,iEAAiE,CAAC,CAAC;AACnF,CAAC;AAED,gCAAgC,IAAY;IACxC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AAC1D,CAAC;AAED,IAAI,WAAW,GAAG,IAAI,CAAC;AACvB,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC;AAC1C,IAAI,OAAO,GAAG,sBAAsB,CAAC,SAAS,GAAG,MAAM,CAAC,CAAC;AAEzD,IAAI,OAAe,CAAC;AACpB,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClB,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1B,EAAE,CAAC,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,sCAAsC,GAAG,OAAO,GAAG,sCAAsC,CAAC,CAAC;IAC3G,CAAC;AACL,CAAC;AAED,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAE3B,IAAI,OAAO,GAAG,KAAK,CAAC;AACpB,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC;IACjC,OAAO,GAAG,IAAI,CAAC;AACnB,CAAC;AAAC,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC;IAC5D,OAAO,CAAC,GAAG,CAAC,sCAAsC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,qCAAqC,CAAC,CAAC;AAClH,CAAC;AAED,aAAa;AACb,aAAa,GAAW;IACpB,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;QACV,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;AACL,CAAC;AAED,mCAAmC;AACnC,aAAa,IAAY,EAAE,IAAa,EAAE,OAAa;IACnD,OAAO,GAAG,OAAO,IAA8B,EAAE,CAAC;IAElD,uBAAuB,MAAc;QACjC,IAAI,MAAM,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;QAC5C,IAAI,KAAK,GAAa,EAAE,CAAC;QACzB,qDAAqD;QACrD,IAAI,mBAAmB,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;QAEnD,IAAI,CAAC;YACD,IAAI,KAAK,GAAG,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YACnC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBACpC,IAAI,IAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,MAAM,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAChD,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;oBAC1C,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACjE,CAAC;gBAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;oBAC1D,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;oBACzD,KAAK,CAAC,IAAI,CAAC,YAAY,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC9C,CAAC;YACL,CAAC;QACL,CAAE;QAAA,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAEf,CAAC;QACD,MAAM,CAAC,KAAK,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC;AAED,yDAAyD;AACzD,+BAA+B,IAAY;IACvC,EAAE,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACtB,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,KAAK;YAC9C,IAAI,OAAO,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC;YAChC,EAAE,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;gBACrC,qBAAqB,CAAC,OAAO,CAAC,CAAC;YACnC,CAAC;YAAC,IAAI,CAAC,CAAC;gBACJ,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YAC3B,CAAC;QACL,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;AACL,CAAC;AAAA,CAAC;AAEF,mBAAmB,IAAY,EAAE,IAAS,EAAE,IAA4B;IACpE,IAAI,CAAC;QACD,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACjC,CAAE;IAAA,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACT,2GAA2G;QAC3G,IAAI,KAAK,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACpD,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACpC,IAAI,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACzC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACzB,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YACrB,CAAC;QACL,CAAC;QACD,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;AACL,CAAC;AAED,wBAAwB;AAExB,iCAAiC,QAAgB,EAAE,GAAwB;IACvE,IAAI,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAC9C,YAAY,GAAG,YAAY,CAAC,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IACrE,YAAY,GAAG,sBAAsB,CAAC,YAAY,CAAC,CAAC;IACpD,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC;IACnC,MAAM,CAAC;AACX,CAAC;AAMD,cAAc,MAAc,EAAE,GAAwB,EAAE,QAAgB,EAAE,WAAsB;IAAtB,2BAAsB,GAAtB,sBAAsB;IAC5F,IAAI,YAAY,GAAG,MAAM,KAAK,SAAS,GAAG,GAAG,GAAG,MAAM,KAAK,MAAM,GAAG,GAAG,GAAG,MAAM,KAAK,SAAS,GAAG,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IACxH,GAAG,CAAC,SAAS,CAAC,YAAY,EAAE,EAAE,cAAc,EAAE,WAAW,EAAE,CAAC,CAAC;IAC7D,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAClB,MAAM,CAAC;AACX,CAAC;AAED,yEAAyE;AACzE,qBAAqB,GAAuB,EAAE,GAAwB,EAAE,QAA+B;IACnG,IAAI,SAAS,GAAG,EAAE,CAAC;IACnB,EAAE,CAAC,CAAC,OAAO,QAAQ,KAAK,UAAU,CAAC;QAAC,MAAM,CAAC,IAAI,CAAC;IAEhD,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC;QACvB,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,IAAY;YACjC,SAAS,IAAI,IAAI,CAAC;YAClB,EAAE,CAAC,CAAC,SAAS,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC;gBACzB,SAAS,GAAG,EAAE,CAAC;gBACf,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;gBACvB,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;gBAC5C,GAAG,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;YAC7B,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE;YACV,sCAAsC;YACtC,QAAQ,CAAC,SAAS,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;IAEP,CAAC;IAAC,IAAI,CAAC,CAAC;QACJ,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IAC3B,CAAC;AACL,CAAC;AAED,IAAK,WAUJ;AAVD,WAAK,WAAW;IACZ,mDAAO,CAAA;IACP,iDAAM,CAAA;IACN,2DAAW,CAAA;IACX,uDAAS,CAAA;IACT,yDAAU,CAAA;IACV,qDAAQ,CAAA;IACR,uDAAS,CAAA;IACT,yDAAU,CAAA;IACV,mDAAO,CAAA;AACX,CAAC,EAVI,WAAW,KAAX,WAAW,QAUf;AAED,6BAA6B,GAAuB,EAAE,QAAgB;IAClE,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,KAAK,KAAK,IAAI,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACtD,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;YAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC;QAC5D,IAAI;YAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC;IACnC,CAAC;IACD,IAAI,CAAC,CAAC;QACF,IAAI,SAAS,GAAQ,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC;QACpD,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,KAAK,KAAK,IAAI,SAAS,CAAC,OAAO,KAAK,SAAS,CAAC;YAAC,MAAM,CAAC,WAAW,CAAC,WAAW,CAAA;QAC3F,8GAA8G;QAC9G,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,KAAK,KAAK,IAAI,SAAS,CAAC,IAAI,KAAK,SAAS,CAAC;YAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAA;QACpF,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,KAAK,MAAM,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;YAC5C,IAAI,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;YACvD,IAAI,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;YACvE,MAAM,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;gBACrC,KAAK,OAAO;oBACR,MAAM,CAAC,MAAM,GAAG,WAAW,CAAC,SAAS,GAAG,WAAW,CAAC,QAAQ,CAAC;gBACjE,KAAK,QAAQ;oBACT,MAAM,CAAC,MAAM,GAAG,WAAW,CAAC,UAAU,GAAG,WAAW,CAAC,SAAS,CAAC;gBACnE,KAAK,QAAQ;oBACT,MAAM,CAAC,MAAM,GAAG,WAAW,CAAC,UAAU,GAAG,WAAW,CAAC,OAAO,CAAC;YACrE,CAAC;QACL,CAAC;QACD,MAAM,CAAC,WAAW,CAAC,OAAO,CAAA;IAC9B,CAAC;AACL,CAAC;AAED,gCAAgC,GAAuB,EAAE,GAAwB,EAAE,SAAsB,EAAE,OAAe;IACtH,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;QAChB,KAAK,WAAW,CAAC,MAAM;YACnB,IAAI,aAAa,GAAG,GAAG,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC1D,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YAC9C,KAAK,CAAC;QACV,KAAK,WAAW,CAAC,OAAO;YACpB,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,EAAE,IAAI;gBACpC,IAAI,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;gBACnD,IAAI,WAAW,GAAG,QAAQ,CAAC;gBAC3B,EAAE,CAAC,CAAC,GAAG,KAAK,KAAK,CAAC;oBAAC,WAAW,GAAG,iBAAiB,CAAA;gBAClD,IAAI,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,MAAM,CAAC;oBAAC,WAAW,GAAG,iBAAiB,CAAA;gBACxD,IAAI,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,OAAO,CAAC;oBAAC,WAAW,GAAG,WAAW,CAAA;gBACnD,GAAG;sBACD,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC;sBAC3C,IAAI,CAAC,SAAS,EAAE,GAAG,EAAQ,IAAK,EAAE,WAAW,CAAC,CAAC;YACrD,CAAC,CAAC,CAAC;YACH,KAAK,CAAC;QACV,KAAK,WAAW,CAAC,WAAW;YACxB,IAAI,cAAc,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;YACpD,uBAAuB,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YAChD,KAAK,CAAC;QACV,KAAK,WAAW,CAAC,SAAS;YACtB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,UAAC,IAAI;gBACvB,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAClD,CAAC,CAAC,CAAC;YACH,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YAC3B,KAAK,CAAC;QACV,KAAK,WAAW,CAAC,QAAQ;YACrB,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YACtB,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YAC3B,KAAK,CAAC;QACV,KAAK,WAAW,CAAC,UAAU;YACvB,EAAE,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;gBACzB,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YAC3B,CAAC;YACD,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YAC3B,KAAK,CAAC;QACV,KAAK,WAAW,CAAC,SAAS;YACtB,EAAE,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;gBACzB,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YAC1B,CAAC;YACD,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YAC3B,KAAK,CAAC;QACV,KAAK,WAAW,CAAC,UAAU;YACvB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,UAAC,IAAI;gBACvB,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YACrC,CAAC,CAAC,CAAC;YACH,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YAC3B,KAAK,CAAC;QACV,KAAK,WAAW,CAAC,OAAO,CAAC;QACzB;YACI,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YAC3B,KAAK,CAAC;IACd,CAAC;AACL,CAAC;AAED,OAAO,CAAC,GAAG,CAAC,uDAAuD,GAAG,IAAI,GAAG,yBAAyB,CAAC,CAAC;AAExG,IAAI,CAAC,YAAY,CAAC,UAAU,GAAuB,EAAE,GAAwB;IACzE,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IAChC,IAAI,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAA;IACrC,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC;IAC5C,IAAI,SAAS,GAAG,mBAAmB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAClD,sBAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AACzD,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAEhB,IAAI,WAAmB,CAAC;AACxB,EAAE,CAAC,CAAC,CAAC,OAAO,IAAI,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC;IACpC,IAAI,iBAAiB,GAAG,EAAE,CAAC;IAC3B,MAAM,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QACpB,KAAK,OAAO,CAAC;QACb,KAAK,OAAO;YACR,iBAAiB,GAAG,6DAA6D,CAAC;YAClF,KAAK,CAAC;QACV,KAAK,QAAQ;YACT,iBAAiB,GAAG,8DAA8D,CAAC;YACnF,KAAK,CAAC;QACV,KAAK,OAAO;YACR,iBAAiB,GAAG,2BAA2B,CAAA;YAC/C,KAAK,CAAC;QACV;YACI,OAAO,CAAC,GAAG,CAAC,sDAAoD,EAAE,CAAC,QAAQ,EAAE,MAAG,CAAC,CAAC;YAClF,KAAK,CAAC;IACd,CAAC;IACD,EAAE,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;QACnC,WAAW,GAAG,iBAAiB,CAAC;IACpC,CAAC;IAAC,IAAI,CAAC,CAAC;QACJ,WAAW,GAAG,OAAO,CAAC;IAC1B,CAAC;AACL,CAAC;AAAC,IAAI,CAAC,CAAC;IACJ,IAAI,aAAa,GAAG,iDAAiD,CAAC;IACtE,EAAE,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;QAC/B,WAAW,GAAG,aAAa,CAAC;IAChC,CAAC;IAAC,IAAI,CAAC,CAAC;QACJ,WAAW,GAAG,OAAO,CAAC;IAC1B,CAAC;AACL,CAAC;AAED,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,WAAW,CAAC,CAAC;AAE7C,IAAI,WAAW,GAAG,IAAI,GAAG,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAC;AAC9C,aAAa,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,mBAAmB,GAAG,IAAI,GAAG,4BAA4B,GAAG,WAAW,CAAC,EAAE;IACxG,KAAK,EAAE,SAAS;CACnB,CAAC,CAAC"} \ No newline at end of file From 15cbb0216202eec3e9fa5f04c124607d4bf8c020 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Fri, 22 Apr 2016 14:26:30 -0700 Subject: [PATCH 06/61] refactor --- src/compiler/types.ts | 2 +- src/services/utilities.ts | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 91ce1f1022f..f40237ba47e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -450,7 +450,7 @@ namespace ts { modifiers?: ModifiersArray; // Array of modifiers /* @internal */ id?: number; // Unique id (used to look up NodeLinks) parent?: Node; // Parent node (initialized by binding - /* @internal */ jsDocComments?: JSDocComment[]; // JSDoc for the node, if it has any. Only for .js files. + /* @internal */ jsDocComments?: JSDocComment[]; // JSDoc for the node, if it has any. Only for .js files. /* @internal */ symbol?: Symbol; // Symbol declared by node (initialized by binding) /* @internal */ locals?: SymbolTable; // Locals associated with node (initialized by binding) /* @internal */ nextContainer?: Node; // Next container in declaration order (initialized by binding) diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 73ac43911b5..0230195b0cc 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -267,7 +267,7 @@ namespace ts { if (includeJsDocComment) { const jsDocChildren = ts.filter(current.getChildren(), isJSDocNode); for (const jsDocChild of jsDocChildren) { - let start = allowPositionInLeadingTrivia ? jsDocChild.getFullStart() : jsDocChild.getStart(sourceFile, includeJsDocComment); + const start = allowPositionInLeadingTrivia ? jsDocChild.getFullStart() : jsDocChild.getStart(sourceFile, includeJsDocComment); if (start <= position) { let end = jsDocChild.getEnd(); if (position < end || (position === end && jsDocChild.kind === SyntaxKind.EndOfFileToken)) { @@ -500,9 +500,8 @@ namespace ts { } if (node) { - let jsDocComments = node.jsDocComments; - if (jsDocComments) { - for (const jsDocComment of jsDocComments) { + if (node.jsDocComments) { + for (const jsDocComment of node.jsDocComments) { for (const tag of jsDocComment.tags) { if (tag.pos <= position && position <= tag.end) { return tag; From d568d79b495d256e93907b28c3aeec912b41594f Mon Sep 17 00:00:00 2001 From: zhengbli Date: Fri, 22 Apr 2016 15:19:57 -0700 Subject: [PATCH 07/61] resolve build error --- src/compiler/parser.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b9662126e65..612602f5658 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -6322,7 +6322,7 @@ namespace ts { const typeExpression = tryParseTypeExpression(); skipWhitespace(); - const name = parseJSDocIdentifier(); + const name = parseJSDocIdentifierName(); if (!name) { parseErrorAtPosition(scanner.getStartPos(), /*length*/ 0, Diagnostics.Identifier_expected); return undefined; @@ -6344,7 +6344,7 @@ namespace ts { function handleTypedefTag(atToken: Node, tagName: Identifier): JSDocTypedefTag { const typeExpression = tryParseTypeExpression(); skipWhitespace(); - let name = parseJSDocIdentifier(); + let name = parseJSDocIdentifierName(); if (!name) { let foundNameFromParentNode = false; if (parentNode && parentNode.kind === SyntaxKind.VariableStatement) { From 79bb4ba5b42d58c2f8ff8955f26f58a9ef24cddb Mon Sep 17 00:00:00 2001 From: Zhengbo Li Date: Mon, 25 Apr 2016 11:56:16 -0700 Subject: [PATCH 08/61] Fix broken test --- src/services/utilities.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/services/utilities.ts b/src/services/utilities.ts index bf90a023c14..12baca1af54 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -445,6 +445,10 @@ namespace ts { return false; } + if (token.kind === SyntaxKind.JsxText) { + return true; + } + //
Hello |
if (token.kind === SyntaxKind.LessThanToken && token.parent.kind === SyntaxKind.JsxText) { return true; @@ -455,7 +459,7 @@ namespace ts { return true; } - //
{ + //
{ // | // } < /div> if (token && token.kind === SyntaxKind.CloseBraceToken && token.parent.kind === SyntaxKind.JsxExpression) { From cd97270721b9d5fddde74980526218dc97ad81e0 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 23 May 2016 15:11:03 -0700 Subject: [PATCH 09/61] Add test case --- ...peParameterExplicitlyExtendsAny.errors.txt | 34 ++++++++++---- .../typeParameterExplicitlyExtendsAny.js | 44 +++++++++++++++++-- .../typeParameterExplicitlyExtendsAny.ts | 25 ++++++++++- 3 files changed, 89 insertions(+), 14 deletions(-) diff --git a/tests/baselines/reference/typeParameterExplicitlyExtendsAny.errors.txt b/tests/baselines/reference/typeParameterExplicitlyExtendsAny.errors.txt index 24f40e967da..27d1738fcbc 100644 --- a/tests/baselines/reference/typeParameterExplicitlyExtendsAny.errors.txt +++ b/tests/baselines/reference/typeParameterExplicitlyExtendsAny.errors.txt @@ -1,9 +1,7 @@ tests/cases/compiler/typeParameterExplicitlyExtendsAny.ts(3,7): error TS2339: Property 'blah' does not exist on type 'T'. -tests/cases/compiler/typeParameterExplicitlyExtendsAny.ts(9,7): error TS2339: Property 'blah' does not exist on type 'T'. -tests/cases/compiler/typeParameterExplicitlyExtendsAny.ts(10,7): error TS2339: Property 'toString' does not exist on type 'T'. -==== tests/cases/compiler/typeParameterExplicitlyExtendsAny.ts (3 errors) ==== +==== tests/cases/compiler/typeParameterExplicitlyExtendsAny.ts (1 errors) ==== function fee() { var t: T; t.blah; // Error @@ -14,10 +12,28 @@ tests/cases/compiler/typeParameterExplicitlyExtendsAny.ts(10,7): error TS2339: P function fee2() { var t: T; - t.blah; // Error - ~~~~ -!!! error TS2339: Property 'blah' does not exist on type 'T'. + t.blah; // ok t.toString; // ok - ~~~~~~~~ -!!! error TS2339: Property 'toString' does not exist on type 'T'. - } \ No newline at end of file + } + + function f(x: T) { + x.children; + x(); + new x(); + x[100]; + x['hello']; + } + + + // Generic Tree structure + type Tree = T & { + children?: Tree[]; + } + + class MyClass { + public static displayTree1>(tree: T) { + // error "Property 'children' does not exist on type 'T'" + tree.children; + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeParameterExplicitlyExtendsAny.js b/tests/baselines/reference/typeParameterExplicitlyExtendsAny.js index 5a1775d44ae..3c2ec6c5977 100644 --- a/tests/baselines/reference/typeParameterExplicitlyExtendsAny.js +++ b/tests/baselines/reference/typeParameterExplicitlyExtendsAny.js @@ -7,9 +7,31 @@ function fee() { function fee2() { var t: T; - t.blah; // Error + t.blah; // ok t.toString; // ok -} +} + +function f(x: T) { + x.children; + x(); + new x(); + x[100]; + x['hello']; +} + + +// Generic Tree structure +type Tree = T & { + children?: Tree[]; +} + +class MyClass { + public static displayTree1>(tree: T) { + // error "Property 'children' does not exist on type 'T'" + tree.children; + } +} + //// [typeParameterExplicitlyExtendsAny.js] function fee() { @@ -19,6 +41,22 @@ function fee() { } function fee2() { var t; - t.blah; // Error + t.blah; // ok t.toString; // ok } +function f(x) { + x.children; + x(); + new x(); + x[100]; + x['hello']; +} +var MyClass = (function () { + function MyClass() { + } + MyClass.displayTree1 = function (tree) { + // error "Property 'children' does not exist on type 'T'" + tree.children; + }; + return MyClass; +}()); diff --git a/tests/cases/compiler/typeParameterExplicitlyExtendsAny.ts b/tests/cases/compiler/typeParameterExplicitlyExtendsAny.ts index f004bf84c5e..1ff14373dcb 100644 --- a/tests/cases/compiler/typeParameterExplicitlyExtendsAny.ts +++ b/tests/cases/compiler/typeParameterExplicitlyExtendsAny.ts @@ -6,6 +6,27 @@ function fee() { function fee2() { var t: T; - t.blah; // Error + t.blah; // ok t.toString; // ok -} \ No newline at end of file +} + +function f(x: T) { + x.children; + x(); + new x(); + x[100]; + x['hello']; +} + + +// Generic Tree structure +type Tree = T & { + children?: Tree[]; +} + +class MyClass { + public static displayTree1>(tree: T) { + // error "Property 'children' does not exist on type 'T'" + tree.children; + } +} From f69ecb5b90746ad6e87c6cff8044eb02f7e1b7ca Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 23 May 2016 16:00:56 -0700 Subject: [PATCH 10/61] run tests in parallel by equally dividing them between workers --- Jakefile.js | 99 +++++++++++++++++-------- src/harness/compilerRunner.ts | 12 +++- src/harness/fourslashRunner.ts | 12 +++- src/harness/projectsRunner.ts | 12 +++- src/harness/runner.ts | 127 ++++++++++++++++++++++++++++++--- src/harness/runnerbase.ts | 11 ++- src/harness/rwcRunner.ts | 10 ++- src/harness/test262Runner.ts | 12 +++- 8 files changed, 246 insertions(+), 49 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index 5112a8db597..73bfdfdaedf 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -680,9 +680,9 @@ function cleanTestDirs() { } // used to pass data from jake command line directly to run.js -function writeTestConfigFile(tests, light, testConfigFile) { - console.log('Running test(s): ' + tests); - var testConfigContents = JSON.stringify({ test: [tests], light: light }); +function writeTestConfigFile(tests, light, taskConfigsFolder, workerCount, testConfigFile) { + var testConfigContents = JSON.stringify({ test: tests ? [tests] : undefined, light: light, workerCount: workerCount, taskConfigsFolder: taskConfigsFolder }); + console.log('Running tests with config: ' + testConfigContents); fs.writeFileSync('test.config', testConfigContents); } @@ -692,7 +692,7 @@ function deleteTemporaryProjectOutput() { } } -function runConsoleTests(defaultReporter, defaultSubsets) { +function runConsoleTests(defaultReporter, runInParallel) { cleanTestDirs(); var debug = process.env.debug || process.env.d; tests = process.env.test || process.env.tests || process.env.t; @@ -701,9 +701,22 @@ function runConsoleTests(defaultReporter, defaultSubsets) { if(fs.existsSync(testConfigFile)) { fs.unlinkSync(testConfigFile); } + var workerCount, taskConfigsFolder; + if (runInParallel) { + // generate name to store task configuration files + var prefix = os.tmpdir() + "/ts-tests"; + var i = 1; + do { + taskConfigsFolder = prefix + i; + i++; + } while (fs.existsSync(taskConfigsFolder)); + fs.mkdirSync(taskConfigsFolder); - if (tests || light) { - writeTestConfigFile(tests, light, testConfigFile); + workerCount = process.env.workerCount || os.cpus().length; + } + + if (tests || light || taskConfigsFolder) { + writeTestConfigFile(tests, light, taskConfigsFolder, workerCount, testConfigFile); } if (tests && tests.toLocaleLowerCase() === "rwc") { @@ -717,45 +730,71 @@ function runConsoleTests(defaultReporter, defaultSubsets) { // timeout normally isn't necessary but Travis-CI has been timing out on compiler baselines occasionally // default timeout is 2sec which really should be enough, but maybe we just need a small amount longer - var subsetRegexes; - if(defaultSubsets.length === 0) { - subsetRegexes = [tests]; - } - else { - var subsets = tests ? tests.split("|") : defaultSubsets; - subsetRegexes = subsets.map(function (sub) { return "^" + sub + ".*$"; }); - subsetRegexes.push("^(?!" + subsets.join("|") + ").*$"); - } - subsetRegexes.forEach(function (subsetRegex, i) { - tests = subsetRegex ? ' -g "' + subsetRegex + '"' : ''; + if(!runInParallel) { + tests = tests ? ' -g "' + tests + '"' : ''; var cmd = "mocha" + (debug ? " --debug-brk" : "") + " -R " + reporter + tests + colors + ' -t ' + testTimeout + ' ' + run; console.log(cmd); - function finish() { - deleteTemporaryProjectOutput(); - complete(); - } exec(cmd, function () { - if (lintFlag && i === 0) { - var lint = jake.Task['lint']; - lint.addListener('complete', function () { - complete(); - }); - lint.invoke(); + if (i === 0) { + runLinter(); } finish(); }, finish); - }); + + } + else { + // run task to load all tests and partition then between workers + var cmd = "mocha " + " -R min " + colors + run; + console.log(cmd); + exec(cmd, function() { + // read all configuration files and spawn a worker for every config + var configFiles = fs.readdirSync(taskConfigsFolder); + var counter = configFiles.length; + // schedule work for chunks + configFiles.forEach(function (f) { + var configPath = path.join(taskConfigsFolder, f); + var workerCmd = "mocha" + " -t " + testTimeout + " -R " + reporter + " " + colors + " " + run + " --config='" + configPath + "'"; + console.log(workerCmd); + exec(workerCmd, finishWorker, finishWorker) + }); + + function finishWorker() { + counter--; + if (counter === 0) { + // last worker clean everything and runs linter + runLinter(); + deleteTemporaryProjectOutput(); + jake.rmRf(taskConfigsFolder); + } + complete(); + } + }); + } + function finish() { + deleteTemporaryProjectOutput(); + complete(); + } + function runLinter() { + if (!lintFlag) { + return; + } + var lint = jake.Task['lint']; + lint.addListener('complete', function () { + complete(); + }); + lint.invoke(); + } } var testTimeout = 20000; desc("Runs all the tests in parallel using the built run.js file. Optional arguments are: t[ests]=category1|category2|... d[ebug]=true."); task("runtests-parallel", ["build-rules", "tests", builtLocalDirectory], function() { - runConsoleTests('min', ['compiler', 'conformance', 'Projects', 'fourslash']); + runConsoleTests('min', /*runInParallel*/ true); }, {async: true}); desc("Runs the tests using the built run.js file. Optional arguments are: t[ests]=regex r[eporter]=[list|spec|json|] d[ebug]=true color[s]=false lint=true."); task("runtests", ["build-rules", "tests", builtLocalDirectory], function() { - runConsoleTests('mocha-fivemat-progress-reporter', []); + runConsoleTests('mocha-fivemat-progress-reporter', /*runInParallel*/ false); }, {async: true}); desc("Generates code coverage data via instanbul"); diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index 1ddbd1ea331..fefea00b807 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -11,7 +11,7 @@ const enum CompilerTestType { class CompilerBaselineRunner extends RunnerBase { private basePath = "tests/cases"; - private testSuiteName: string; + private testSuiteName: TestRunnerKind; private errors: boolean; private emit: boolean; private decl: boolean; @@ -40,6 +40,14 @@ class CompilerBaselineRunner extends RunnerBase { this.basePath += "/" + this.testSuiteName; } + public kind() { + return this.testSuiteName; + } + + public enumerateTestFiles() { + return this.enumerateFiles(this.basePath, /\.tsx?$/, { recursive: true }); + } + private makeUnitName(name: string, root: string) { return ts.isRootedDiskPath(name) ? name : ts.combinePaths(root, name); }; @@ -390,7 +398,7 @@ class CompilerBaselineRunner extends RunnerBase { // this will set up a series of describe/it blocks to run between the setup and cleanup phases if (this.tests.length === 0) { - const testFiles = this.enumerateFiles(this.basePath, /\.tsx?$/, { recursive: true }); + const testFiles = this.enumerateTestFiles(); testFiles.forEach(fn => { fn = fn.replace(/\\/g, "/"); this.checkTestCodeOutput(fn); diff --git a/src/harness/fourslashRunner.ts b/src/harness/fourslashRunner.ts index 386bd9e340c..a6174342acd 100644 --- a/src/harness/fourslashRunner.ts +++ b/src/harness/fourslashRunner.ts @@ -12,7 +12,7 @@ const enum FourSlashTestType { class FourSlashRunner extends RunnerBase { protected basePath: string; - protected testSuiteName: string; + protected testSuiteName: TestRunnerKind; constructor(private testType: FourSlashTestType) { super(); @@ -36,9 +36,17 @@ class FourSlashRunner extends RunnerBase { } } + public enumerateTestFiles() { + return this.enumerateFiles(this.basePath, /\.ts/i, { recursive: false }); + } + + public kind() { + return this.testSuiteName; + } + public initializeTests() { if (this.tests.length === 0) { - this.tests = this.enumerateFiles(this.basePath, /\.ts/i, { recursive: false }); + this.tests = this.enumerateTestFiles(); } describe(this.testSuiteName + " tests", () => { diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 9ee4359d8d3..777ef63145d 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -37,11 +37,19 @@ interface BatchCompileProjectTestCaseResult extends CompileProjectFilesResult { } class ProjectRunner extends RunnerBase { + + public enumerateTestFiles() { + return this.enumerateFiles("tests/cases/project", /\.json$/, { recursive: true }); + } + + public kind(): TestRunnerKind { + return "project"; + } + public initializeTests() { if (this.tests.length === 0) { - const testFiles = this.enumerateFiles("tests/cases/project", /\.json$/, { recursive: true }); + const testFiles = this.enumerateTestFiles(); testFiles.forEach(fn => { - fn = fn.replace(/\\/g, "/"); this.runProjectTestCase(fn); }); } diff --git a/src/harness/runner.ts b/src/harness/runner.ts index bb3cafea0a8..07723913040 100644 --- a/src/harness/runner.ts +++ b/src/harness/runner.ts @@ -33,18 +33,90 @@ function runTests(runners: RunnerBase[]) { } } -// users can define tests to run in mytest.config that will override cmd line args, otherwise use cmd line args (test.config), otherwise no options -let mytestconfig = "mytest.config"; -let testconfig = "test.config"; -let testConfigFile = - Harness.IO.fileExists(mytestconfig) ? Harness.IO.readFile(mytestconfig) : - (Harness.IO.fileExists(testconfig) ? Harness.IO.readFile(testconfig) : ""); +function tryGetConfig(args: string[]) { + const prefix = "--config="; + const configPath = ts.forEach(args, arg => arg.lastIndexOf(prefix, 0) === 0 && arg.substr(prefix.length)); + // strip leading and trailing quotes from the path (necessary on Windows since shell does not do it automatically) + return configPath && configPath.replace(/(^[\"'])|([\"']$)/g, ""); +} -if (testConfigFile !== "") { - const testConfig = JSON.parse(testConfigFile); +function createRunner(kind: TestRunnerKind): RunnerBase { + switch (kind) { + case "conformance": + return new CompilerBaselineRunner(CompilerTestType.Conformance); + case "compiler": + return new CompilerBaselineRunner(CompilerTestType.Regressions); + case "fourslash": + return new FourSlashRunner(FourSlashTestType.Native); + case "fourslash-shims": + return new FourSlashRunner(FourSlashTestType.Shims); + case "fourslash-shims-pp": + return new FourSlashRunner(FourSlashTestType.ShimsWithPreprocess); + case "fourslash-server": + return new FourSlashRunner(FourSlashTestType.Server); + case "project": + return new ProjectRunner(); + case "rwc": + return new RWCRunner(); + case "test262": + return new Test262BaselineRunner(); + } +} + +// users can define tests to run in mytest.config that will override cmd line args, otherwise use cmd line args (test.config), otherwise no options + +const mytestconfigFileName = "mytest.config"; +const testconfigFileName = "test.config"; + +const customConfig = tryGetConfig(Harness.IO.args()); +let testConfigContent = + customConfig && Harness.IO.fileExists(customConfig) + ? Harness.IO.readFile(customConfig) + : Harness.IO.fileExists(mytestconfigFileName) + ? Harness.IO.readFile(mytestconfigFileName) + : Harness.IO.fileExists(testconfigFileName) ? Harness.IO.readFile(testconfigFileName) : ""; + +let taskConfigsFolder: string; +let workerCount: number; +let runUnitTests = true; + +interface TestConfig { + light?: boolean; + taskConfigsFolder?: string; + workerCount?: number; + tasks?: TaskSet[]; + test?: string[]; + runUnitTests?: boolean; +} + +interface TaskSet { + runner: TestRunnerKind; + files: string[]; +} + +if (testConfigContent !== "") { + const testConfig = JSON.parse(testConfigContent); if (testConfig.light) { Harness.lightMode = true; } + if (testConfig.taskConfigsFolder) { + taskConfigsFolder = testConfig.taskConfigsFolder; + } + if (testConfig.runUnitTests !== undefined) { + runUnitTests = testConfig.runUnitTests; + } + if (testConfig.workerCount) { + workerCount = testConfig.workerCount; + } + if (testConfig.tasks) { + for (const taskSet of testConfig.tasks) { + const runner = createRunner(taskSet.runner); + for (const file of taskSet.files) { + runner.addTest(file); + } + runners.push(runner); + } + } if (testConfig.test && testConfig.test.length > 0) { for (const option of testConfig.test) { @@ -108,4 +180,41 @@ if (runners.length === 0) { // runners.push(new GeneratedFourslashRunner()); } -runTests(runners); +if (taskConfigsFolder) { + // this instance of mocha should only partition work but not run actual tests + runUnitTests = false; + const workerConfigs: TestConfig[] = []; + for (let i = 0; i < workerCount; i++) { + // pass light mode settings to workers + workerConfigs.push({ light: Harness.lightMode, tasks: [] }); + } + + for (const runner of runners) { + const files = runner.enumerateTestFiles(); + const chunkSize = Math.floor(files.length / workerCount) + 1; // add extra 1 to prevent missing tests due to rounding + for (let i = 0; i < workerCount; i++) { + const startPos = i * chunkSize; + const len = Math.min(chunkSize, files.length - startPos); + if (len !== 0) { + workerConfigs[i].tasks.push({ + runner: runner.kind(), + files: files.slice(startPos, startPos + len) + }); + } + } + } + + for (let i = 0; i < workerCount; i++) { + const config = workerConfigs[i]; + // use last worker to run unit tests + config.runUnitTests = i === workerCount - 1; + Harness.IO.writeFile(ts.combinePaths(taskConfigsFolder, `task-config${i}.json`), JSON.stringify(workerConfigs[i])); + } +} +else { + runTests(runners); +} +if (!runUnitTests) { + // patch `describe` to skip unit tests + describe = describe.skip; +} \ No newline at end of file diff --git a/src/harness/runnerbase.ts b/src/harness/runnerbase.ts index a114e8c3201..81da0907714 100644 --- a/src/harness/runnerbase.ts +++ b/src/harness/runnerbase.ts @@ -1,5 +1,10 @@ /// + +type TestRunnerKind = CompilerTestKind | FourslashTestKind | "project" | "rwc" | "test262"; +type CompilerTestKind = "conformance" | "compiler"; +type FourslashTestKind = "fourslash" | "fourslash-shims" | "fourslash-shims-pp" | "fourslash-server"; + abstract class RunnerBase { constructor() { } @@ -12,9 +17,13 @@ abstract class RunnerBase { } public enumerateFiles(folder: string, regex?: RegExp, options?: { recursive: boolean }): string[] { - return Harness.IO.listFiles(Harness.userSpecifiedRoot + folder, regex, { recursive: (options ? options.recursive : false) }); + return ts.map(Harness.IO.listFiles(Harness.userSpecifiedRoot + folder, regex, { recursive: (options ? options.recursive : false) }), ts.normalizeSlashes); } + abstract kind(): TestRunnerKind; + + abstract enumerateTestFiles(): string[]; + /** Setup the runner's tests so that they are ready to be executed by the harness * The first test should be a describe/it block that sets up the harness's compiler instance appropriately */ diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index 39231435bf5..ff1623b9051 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -223,12 +223,20 @@ namespace RWC { class RWCRunner extends RunnerBase { private static sourcePath = "internal/cases/rwc/"; + public enumerateTestFiles() { + return Harness.IO.listFiles(RWCRunner.sourcePath, /.+\.json$/); + } + + public kind(): TestRunnerKind { + return "rwc"; + } + /** Setup the runner's tests so that they are ready to be executed by the harness * The first test should be a describe/it block that sets up the harness's compiler instance appropriately */ public initializeTests(): void { // Read in and evaluate the test list - const testList = Harness.IO.listFiles(RWCRunner.sourcePath, /.+\.json$/); + const testList = this.enumerateTestFiles(); for (let i = 0; i < testList.length; i++) { this.runTest(testList[i]); } diff --git a/src/harness/test262Runner.ts b/src/harness/test262Runner.ts index cc9957c1fac..a3276cc65b3 100644 --- a/src/harness/test262Runner.ts +++ b/src/harness/test262Runner.ts @@ -97,12 +97,20 @@ class Test262BaselineRunner extends RunnerBase { }); } + public kind(): TestRunnerKind { + return "test262"; + } + + public enumerateTestFiles() { + return ts.map(this.enumerateFiles(Test262BaselineRunner.basePath, Test262BaselineRunner.testFileExtensionRegex, { recursive: true }), ts.normalizePath); + } + public initializeTests() { // this will set up a series of describe/it blocks to run between the setup and cleanup phases if (this.tests.length === 0) { - const testFiles = this.enumerateFiles(Test262BaselineRunner.basePath, Test262BaselineRunner.testFileExtensionRegex, { recursive: true }); + const testFiles = this.enumerateTestFiles(); testFiles.forEach(fn => { - this.runTest(ts.normalizePath(fn)); + this.runTest(fn); }); } else { From bc36f8c5ca3abb9c972053fa92ea089dfdb136d1 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 23 May 2016 16:04:22 -0700 Subject: [PATCH 11/61] Apparent members for type params constrained by any --- src/compiler/checker.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e80be0bfe45..722c223a842 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9927,9 +9927,9 @@ namespace ts { } const apparentType = getApparentType(getWidenedType(type)); - if (apparentType === unknownType) { - // handle cases when type is Type parameter with invalid constraint - return unknownType; + if (apparentType === unknownType || (type.flags & TypeFlags.TypeParameter && isTypeAny(apparentType))) { + // handle cases when type is Type parameter with invalid or any constraint + return apparentType; } const prop = getPropertyOfType(apparentType, right.text); if (!prop) { @@ -11120,7 +11120,9 @@ namespace ts { // types are provided for the argument expressions, and the result is always of type Any. // We exclude union types because we may have a union of function types that happen to have // no common signatures. - if (isTypeAny(funcType) || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) { + if (isTypeAny(funcType) || + (isTypeAny(apparentType) && funcType.flags & TypeFlags.TypeParameter) || + (!callSignatures.length && !constructSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) { // The unknownType indicates that an error already occurred (and was reported). No // need to report another error in this case. if (funcType !== unknownType && node.typeArguments) { From b8b38f3b86882d2f7ba94ce53be09cedd821a238 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 24 May 2016 12:11:15 -0700 Subject: [PATCH 12/61] Do not resolve alias when getting symbol of import equal's right hand side Fixes #5501 --- src/compiler/checker.ts | 22 ++++++++----------- .../reference/acceptableAlias1.symbols | 2 +- .../amdImportNotAsPrimaryExpression.symbols | 2 +- .../reference/chainedImportAlias.symbols | 2 +- ...mmonJSImportNotAsPrimaryExpression.symbols | 2 +- .../declFileForExportedImport.symbols | 2 +- ...lFileImportChainInExportAssignment.symbols | 2 +- .../declarationEmit_nameConflicts.symbols | 2 +- .../dependencyViaImportAlias.symbols | 2 +- ...edImportInIndirectExportAssignment.symbols | 2 +- ...alModuleReferenceDoubleUnderscore1.symbols | 2 +- ...ternalModuleInsideAnInternalModule.symbols | 2 +- .../import_reference-exported-alias.symbols | 4 ++-- .../import_reference-to-type-alias.symbols | 2 +- .../importedAliasesInTypePositions.symbols | 2 +- .../reference/tsxPreserveEmit1.symbols | 2 +- tests/cases/fourslash/renameAlias.ts | 11 ++++++++++ tests/cases/fourslash/renameAlias2.ts | 11 ++++++++++ tests/cases/fourslash/renameAlias3.ts | 11 ++++++++++ .../fourslash/renameAliasExternalModule.ts | 16 ++++++++++++++ .../fourslash/renameAliasExternalModule2.ts | 16 ++++++++++++++ .../fourslash/renameAliasExternalModule3.ts | 16 ++++++++++++++ 22 files changed, 106 insertions(+), 29 deletions(-) create mode 100644 tests/cases/fourslash/renameAlias.ts create mode 100644 tests/cases/fourslash/renameAlias2.ts create mode 100644 tests/cases/fourslash/renameAlias3.ts create mode 100644 tests/cases/fourslash/renameAliasExternalModule.ts create mode 100644 tests/cases/fourslash/renameAliasExternalModule2.ts create mode 100644 tests/cases/fourslash/renameAliasExternalModule3.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6a42dc43d51..8a510825673 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1154,11 +1154,7 @@ namespace ts { } // This function is only for imports with entity names - function getSymbolOfPartOfRightHandSideOfImportEquals(entityName: EntityName, importDeclaration?: ImportEqualsDeclaration): Symbol { - if (!importDeclaration) { - importDeclaration = getAncestor(entityName, SyntaxKind.ImportEqualsDeclaration); - Debug.assert(importDeclaration !== undefined); - } + function getSymbolOfPartOfRightHandSideOfImportEquals(entityName: EntityName, importDeclaration: ImportEqualsDeclaration, dontResolveAlias?: boolean): Symbol { // There are three things we might try to look for. In the following examples, // the search term is enclosed in |...|: // @@ -1170,13 +1166,13 @@ namespace ts { } // Check for case 1 and 3 in the above example if (entityName.kind === SyntaxKind.Identifier || entityName.parent.kind === SyntaxKind.QualifiedName) { - return resolveEntityName(entityName, SymbolFlags.Namespace); + return resolveEntityName(entityName, SymbolFlags.Namespace, /*ignoreErrors*/ false, dontResolveAlias); } else { // Case 2 in above example // entityName.kind could be a QualifiedName or a Missing identifier Debug.assert(entityName.parent.kind === SyntaxKind.ImportEqualsDeclaration); - return resolveEntityName(entityName, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace); + return resolveEntityName(entityName, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, /*ignoreErrors*/ false, dontResolveAlias); } } @@ -1185,7 +1181,7 @@ namespace ts { } // Resolves a qualified name and any involved aliases - function resolveEntityName(name: EntityName | Expression, meaning: SymbolFlags, ignoreErrors?: boolean): Symbol { + function resolveEntityName(name: EntityName | Expression, meaning: SymbolFlags, ignoreErrors?: boolean, dontResolveAlias?: boolean): Symbol { if (nodeIsMissing(name)) { return undefined; } @@ -1219,7 +1215,7 @@ namespace ts { Debug.fail("Unknown entity name kind."); } Debug.assert((symbol.flags & SymbolFlags.Instantiated) === 0, "Should never get an instantiated symbol here."); - return symbol.flags & meaning ? symbol : resolveAlias(symbol); + return (symbol.flags & meaning) || dontResolveAlias ? symbol : resolveAlias(symbol); } function resolveExternalModuleName(location: Node, moduleReferenceExpression: Expression): Symbol { @@ -16441,7 +16437,9 @@ namespace ts { if (entityName.kind !== SyntaxKind.PropertyAccessExpression) { if (isInRightSideOfImportOrExportAssignment(entityName)) { // Since we already checked for ExportAssignment, this really could only be an Import - return getSymbolOfPartOfRightHandSideOfImportEquals(entityName); + const importEqualsDeclaration = getAncestor(entityName, SyntaxKind.ImportEqualsDeclaration); + Debug.assert(importEqualsDeclaration !== undefined); + return getSymbolOfPartOfRightHandSideOfImportEquals(entityName, importEqualsDeclaration, /*dontResolveAlias*/ true); } } @@ -16531,9 +16529,7 @@ namespace ts { if (node.kind === SyntaxKind.Identifier) { if (isInRightSideOfImportOrExportAssignment(node)) { - return node.parent.kind === SyntaxKind.ExportAssignment - ? getSymbolOfEntityNameOrPropertyAccessExpression(node) - : getSymbolOfPartOfRightHandSideOfImportEquals(node); + return getSymbolOfEntityNameOrPropertyAccessExpression(node); } else if (node.parent.kind === SyntaxKind.BindingElement && node.parent.parent.kind === SyntaxKind.ObjectBindingPattern && diff --git a/tests/baselines/reference/acceptableAlias1.symbols b/tests/baselines/reference/acceptableAlias1.symbols index cffbc70290f..31679fb6a52 100644 --- a/tests/baselines/reference/acceptableAlias1.symbols +++ b/tests/baselines/reference/acceptableAlias1.symbols @@ -13,5 +13,5 @@ module M { import r = M.X; >r : Symbol(r, Decl(acceptableAlias1.ts, 4, 1)) >M : Symbol(M, Decl(acceptableAlias1.ts, 0, 0)) ->X : Symbol(r, Decl(acceptableAlias1.ts, 0, 10)) +>X : Symbol(M.X, Decl(acceptableAlias1.ts, 2, 5)) diff --git a/tests/baselines/reference/amdImportNotAsPrimaryExpression.symbols b/tests/baselines/reference/amdImportNotAsPrimaryExpression.symbols index ae67c0a3175..a04bd7077c1 100644 --- a/tests/baselines/reference/amdImportNotAsPrimaryExpression.symbols +++ b/tests/baselines/reference/amdImportNotAsPrimaryExpression.symbols @@ -5,7 +5,7 @@ import foo = require("./foo_0"); // None of the below should cause a runtime dependency on foo_0 import f = foo.M1; >f : Symbol(f, Decl(foo_1.ts, 0, 32)) ->foo : Symbol(foo, Decl(foo_0.ts, 0, 0)) +>foo : Symbol(foo, Decl(foo_1.ts, 0, 0)) >M1 : Symbol(foo.M1, Decl(foo_0.ts, 8, 1)) var i: f.I2; diff --git a/tests/baselines/reference/chainedImportAlias.symbols b/tests/baselines/reference/chainedImportAlias.symbols index 0f374305aeb..d10e22af119 100644 --- a/tests/baselines/reference/chainedImportAlias.symbols +++ b/tests/baselines/reference/chainedImportAlias.symbols @@ -4,7 +4,7 @@ import x = require('./chainedImportAlias_file0'); import y = x; >y : Symbol(y, Decl(chainedImportAlias_file1.ts, 0, 49)) ->x : Symbol(x, Decl(chainedImportAlias_file0.ts, 0, 0)) +>x : Symbol(x, Decl(chainedImportAlias_file1.ts, 0, 0)) y.m.foo(); >y.m.foo : Symbol(x.m.foo, Decl(chainedImportAlias_file0.ts, 0, 17)) diff --git a/tests/baselines/reference/commonJSImportNotAsPrimaryExpression.symbols b/tests/baselines/reference/commonJSImportNotAsPrimaryExpression.symbols index ae67c0a3175..a04bd7077c1 100644 --- a/tests/baselines/reference/commonJSImportNotAsPrimaryExpression.symbols +++ b/tests/baselines/reference/commonJSImportNotAsPrimaryExpression.symbols @@ -5,7 +5,7 @@ import foo = require("./foo_0"); // None of the below should cause a runtime dependency on foo_0 import f = foo.M1; >f : Symbol(f, Decl(foo_1.ts, 0, 32)) ->foo : Symbol(foo, Decl(foo_0.ts, 0, 0)) +>foo : Symbol(foo, Decl(foo_1.ts, 0, 0)) >M1 : Symbol(foo.M1, Decl(foo_0.ts, 8, 1)) var i: f.I2; diff --git a/tests/baselines/reference/declFileForExportedImport.symbols b/tests/baselines/reference/declFileForExportedImport.symbols index fe14836199c..c9c36796826 100644 --- a/tests/baselines/reference/declFileForExportedImport.symbols +++ b/tests/baselines/reference/declFileForExportedImport.symbols @@ -11,7 +11,7 @@ var y = a.x; export import b = a; >b : Symbol(b, Decl(declFileForExportedImport_1.ts, 2, 12)) ->a : Symbol(a, Decl(declFileForExportedImport_0.ts, 0, 0)) +>a : Symbol(a, Decl(declFileForExportedImport_1.ts, 0, 0)) var z = b.x; >z : Symbol(z, Decl(declFileForExportedImport_1.ts, 5, 3)) diff --git a/tests/baselines/reference/declFileImportChainInExportAssignment.symbols b/tests/baselines/reference/declFileImportChainInExportAssignment.symbols index 12e05bed75a..a47db44a02e 100644 --- a/tests/baselines/reference/declFileImportChainInExportAssignment.symbols +++ b/tests/baselines/reference/declFileImportChainInExportAssignment.symbols @@ -17,7 +17,7 @@ import a = m.c; import b = a; >b : Symbol(b, Decl(declFileImportChainInExportAssignment.ts, 6, 15)) ->a : Symbol(a, Decl(declFileImportChainInExportAssignment.ts, 0, 10)) +>a : Symbol(a, Decl(declFileImportChainInExportAssignment.ts, 5, 1)) export = b; >b : Symbol(b, Decl(declFileImportChainInExportAssignment.ts, 6, 15)) diff --git a/tests/baselines/reference/declarationEmit_nameConflicts.symbols b/tests/baselines/reference/declarationEmit_nameConflicts.symbols index 1c5bb35b756..43657e85baf 100644 --- a/tests/baselines/reference/declarationEmit_nameConflicts.symbols +++ b/tests/baselines/reference/declarationEmit_nameConflicts.symbols @@ -37,7 +37,7 @@ export module M { export import d = im; >d : Symbol(d, Decl(declarationEmit_nameConflicts_0.ts, 11, 24)) ->im : Symbol(d, Decl(declarationEmit_nameConflicts_1.ts, 0, 0)) +>im : Symbol(im, Decl(declarationEmit_nameConflicts_0.ts, 0, 0)) } export module M.P { diff --git a/tests/baselines/reference/dependencyViaImportAlias.symbols b/tests/baselines/reference/dependencyViaImportAlias.symbols index 8855b8d6451..04c0a9a1a13 100644 --- a/tests/baselines/reference/dependencyViaImportAlias.symbols +++ b/tests/baselines/reference/dependencyViaImportAlias.symbols @@ -4,7 +4,7 @@ import a = require('A'); import A = a.A; >A : Symbol(A, Decl(B.ts, 0, 24)) ->a : Symbol(a, Decl(A.ts, 0, 0)) +>a : Symbol(a, Decl(B.ts, 0, 0)) >A : Symbol(a.A, Decl(A.ts, 0, 0)) export = A; diff --git a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.symbols b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.symbols index 24eab96f54b..77b93c3ef00 100644 --- a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.symbols +++ b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.symbols @@ -14,7 +14,7 @@ import { a } from "./es6ImportNamedImportInIndirectExportAssignment_0"; import x = a; >x : Symbol(x, Decl(es6ImportNamedImportInIndirectExportAssignment_1.ts, 0, 71)) ->a : Symbol(a, Decl(es6ImportNamedImportInIndirectExportAssignment_0.ts, 0, 0)) +>a : Symbol(a, Decl(es6ImportNamedImportInIndirectExportAssignment_1.ts, 0, 8)) export = x; >x : Symbol(x, Decl(es6ImportNamedImportInIndirectExportAssignment_1.ts, 0, 71)) diff --git a/tests/baselines/reference/externalModuleReferenceDoubleUnderscore1.symbols b/tests/baselines/reference/externalModuleReferenceDoubleUnderscore1.symbols index 02e5e6cfc5a..d4b995af6b2 100644 --- a/tests/baselines/reference/externalModuleReferenceDoubleUnderscore1.symbols +++ b/tests/baselines/reference/externalModuleReferenceDoubleUnderscore1.symbols @@ -5,7 +5,7 @@ declare module 'timezonecomplete' { export import TimeUnit = basics.TimeUnit; >TimeUnit : Symbol(TimeUnit, Decl(externalModuleReferenceDoubleUnderscore1.ts, 1, 57)) ->basics : Symbol(basics, Decl(externalModuleReferenceDoubleUnderscore1.ts, 3, 1)) +>basics : Symbol(basics, Decl(externalModuleReferenceDoubleUnderscore1.ts, 0, 35)) >TimeUnit : Symbol(basics.TimeUnit, Decl(externalModuleReferenceDoubleUnderscore1.ts, 5, 44)) } diff --git a/tests/baselines/reference/importAliasAnExternalModuleInsideAnInternalModule.symbols b/tests/baselines/reference/importAliasAnExternalModuleInsideAnInternalModule.symbols index ffaca4a0ec5..ecc81c727e1 100644 --- a/tests/baselines/reference/importAliasAnExternalModuleInsideAnInternalModule.symbols +++ b/tests/baselines/reference/importAliasAnExternalModuleInsideAnInternalModule.symbols @@ -8,7 +8,7 @@ module m_private { //import r2 = require('m'); // would be error export import C = r; // no error >C : Symbol(C, Decl(importAliasAnExternalModuleInsideAnInternalModule_file1.ts, 1, 18)) ->r : Symbol(C, Decl(importAliasAnExternalModuleInsideAnInternalModule_file0.ts, 0, 0)) +>r : Symbol(r, Decl(importAliasAnExternalModuleInsideAnInternalModule_file1.ts, 0, 0)) C.m.foo(); >C.m.foo : Symbol(C.m.foo, Decl(importAliasAnExternalModuleInsideAnInternalModule_file0.ts, 0, 17)) diff --git a/tests/baselines/reference/import_reference-exported-alias.symbols b/tests/baselines/reference/import_reference-exported-alias.symbols index 5a7e8b8c5c7..10ccb7a9256 100644 --- a/tests/baselines/reference/import_reference-exported-alias.symbols +++ b/tests/baselines/reference/import_reference-exported-alias.symbols @@ -4,12 +4,12 @@ import appJs = require("file1"); import Services = appJs.Services; >Services : Symbol(Services, Decl(file2.ts, 0, 32)) ->appJs : Symbol(appJs, Decl(file1.ts, 0, 0)) +>appJs : Symbol(appJs, Decl(file2.ts, 0, 0)) >Services : Symbol(appJs.Services, Decl(file1.ts, 0, 12)) import UserServices = Services.UserServices; >UserServices : Symbol(UserServices, Decl(file2.ts, 1, 33)) ->Services : Symbol(appJs.Services, Decl(file1.ts, 0, 12)) +>Services : Symbol(Services, Decl(file2.ts, 0, 32)) >UserServices : Symbol(Services.UserServices, Decl(file1.ts, 1, 28)) var x = new UserServices().getUserName(); diff --git a/tests/baselines/reference/import_reference-to-type-alias.symbols b/tests/baselines/reference/import_reference-to-type-alias.symbols index 6d096c1cba3..996cf05be71 100644 --- a/tests/baselines/reference/import_reference-to-type-alias.symbols +++ b/tests/baselines/reference/import_reference-to-type-alias.symbols @@ -4,7 +4,7 @@ import appJs = require("file1"); import Services = appJs.App.Services; >Services : Symbol(Services, Decl(file2.ts, 0, 32)) ->appJs : Symbol(appJs, Decl(file1.ts, 0, 0)) +>appJs : Symbol(appJs, Decl(file2.ts, 0, 0)) >App : Symbol(appJs.App, Decl(file1.ts, 0, 0)) >Services : Symbol(Services, Decl(file1.ts, 0, 19)) diff --git a/tests/baselines/reference/importedAliasesInTypePositions.symbols b/tests/baselines/reference/importedAliasesInTypePositions.symbols index 1d28900c22f..1ad3c4254f8 100644 --- a/tests/baselines/reference/importedAliasesInTypePositions.symbols +++ b/tests/baselines/reference/importedAliasesInTypePositions.symbols @@ -4,7 +4,7 @@ import RT_ALIAS = require("file1"); import ReferredTo = RT_ALIAS.elaborate.nested.mod.name.ReferredTo; >ReferredTo : Symbol(ReferredTo, Decl(file2.ts, 0, 35)) ->RT_ALIAS : Symbol(RT_ALIAS, Decl(file1.ts, 0, 0)) +>RT_ALIAS : Symbol(RT_ALIAS, Decl(file2.ts, 0, 0)) >elaborate : Symbol(RT_ALIAS.elaborate, Decl(file1.ts, 0, 0)) >nested : Symbol(RT_ALIAS.elaborate.nested, Decl(file1.ts, 0, 24)) >mod : Symbol(RT_ALIAS.elaborate.nested.mod, Decl(file1.ts, 0, 31)) diff --git a/tests/baselines/reference/tsxPreserveEmit1.symbols b/tests/baselines/reference/tsxPreserveEmit1.symbols index 53707b86104..b5651d7c38e 100644 --- a/tests/baselines/reference/tsxPreserveEmit1.symbols +++ b/tests/baselines/reference/tsxPreserveEmit1.symbols @@ -8,7 +8,7 @@ import ReactRouter = require('react-router'); import Route = ReactRouter.Route; >Route : Symbol(Route, Decl(test.tsx, 2, 45)) ->ReactRouter : Symbol(ReactRouter, Decl(react.d.ts, 4, 1)) +>ReactRouter : Symbol(ReactRouter, Decl(test.tsx, 1, 32)) >Route : Symbol(ReactRouter.Route, Decl(react.d.ts, 7, 4)) var routes1 = ; diff --git a/tests/cases/fourslash/renameAlias.ts b/tests/cases/fourslash/renameAlias.ts new file mode 100644 index 00000000000..e3f57ac7b41 --- /dev/null +++ b/tests/cases/fourslash/renameAlias.ts @@ -0,0 +1,11 @@ +/// + +////module SomeModule { export class SomeClass { } } +////import [|M|] = SomeModule; +////import C = [|M|].SomeClass; + +let ranges = test.ranges() +for (let range of ranges) { + goTo.position(range.start); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} \ No newline at end of file diff --git a/tests/cases/fourslash/renameAlias2.ts b/tests/cases/fourslash/renameAlias2.ts new file mode 100644 index 00000000000..da1bcf8248d --- /dev/null +++ b/tests/cases/fourslash/renameAlias2.ts @@ -0,0 +1,11 @@ +/// + +////module [|SomeModule|] { export class SomeClass { } } +////import M = [|SomeModule|]; +////import C = M.SomeClass; + +let ranges = test.ranges() +for (let range of ranges) { + goTo.position(range.start); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} \ No newline at end of file diff --git a/tests/cases/fourslash/renameAlias3.ts b/tests/cases/fourslash/renameAlias3.ts new file mode 100644 index 00000000000..9172f052abb --- /dev/null +++ b/tests/cases/fourslash/renameAlias3.ts @@ -0,0 +1,11 @@ +/// + +////module SomeModule { export class [|SomeClass|] { } } +////import M = SomeModule; +////import C = M.[|SomeClass|]; + +let ranges = test.ranges() +for (let range of ranges) { + goTo.position(range.start); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} \ No newline at end of file diff --git a/tests/cases/fourslash/renameAliasExternalModule.ts b/tests/cases/fourslash/renameAliasExternalModule.ts new file mode 100644 index 00000000000..54277fd6e64 --- /dev/null +++ b/tests/cases/fourslash/renameAliasExternalModule.ts @@ -0,0 +1,16 @@ +/// + +// @Filename: a.ts +////module SomeModule { export class SomeClass { } } +////export = SomeModule; + +// @Filename: b.ts +////import [|M|] = require("./a"); +////import C = [|M|].SomeClass; + +let ranges = test.ranges() +for (let range of ranges) { + goTo.file(range.fileName); + goTo.position(range.start); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} \ No newline at end of file diff --git a/tests/cases/fourslash/renameAliasExternalModule2.ts b/tests/cases/fourslash/renameAliasExternalModule2.ts new file mode 100644 index 00000000000..2d9d07efb68 --- /dev/null +++ b/tests/cases/fourslash/renameAliasExternalModule2.ts @@ -0,0 +1,16 @@ +/// + +// @Filename: a.ts +////module [|SomeModule|] { export class SomeClass { } } +////export = [|SomeModule|]; + +// @Filename: b.ts +////import M = require("./a"); +////import C = M.SomeClass; + +let ranges = test.ranges() +for (let range of ranges) { + goTo.file(range.fileName); + goTo.position(range.start); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} \ No newline at end of file diff --git a/tests/cases/fourslash/renameAliasExternalModule3.ts b/tests/cases/fourslash/renameAliasExternalModule3.ts new file mode 100644 index 00000000000..acff9371c77 --- /dev/null +++ b/tests/cases/fourslash/renameAliasExternalModule3.ts @@ -0,0 +1,16 @@ +/// + +// @Filename: a.ts +////module SomeModule { export class [|SomeClass|] { } } +////export = SomeModule; + +// @Filename: b.ts +////import M = require("./a"); +////import C = M.[|SomeClass|]; + +let ranges = test.ranges() +for (let range of ranges) { + goTo.file(range.fileName); + goTo.position(range.start); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} \ No newline at end of file From 5f7bbbf8fdb949c32e1d68e2dc1efb45a59f4a1e Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 24 May 2016 14:29:52 -0700 Subject: [PATCH 13/61] unconditionnaly use linter for non-parallel run --- Jakefile.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index 73bfdfdaedf..7be070bc492 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -735,9 +735,7 @@ function runConsoleTests(defaultReporter, runInParallel) { var cmd = "mocha" + (debug ? " --debug-brk" : "") + " -R " + reporter + tests + colors + ' -t ' + testTimeout + ' ' + run; console.log(cmd); exec(cmd, function () { - if (i === 0) { - runLinter(); - } + runLinter(); finish(); }, finish); From 699dc4f9bb452646b72883378bc7401e013ae390 Mon Sep 17 00:00:00 2001 From: Rado Kirov Date: Thu, 19 May 2016 17:15:26 -0700 Subject: [PATCH 14/61] do not emit double assigment of class expressions. Closure compiler ES6 support rejects expressions of the form `let A = B = class {}` With a small rewriting of the emitted code the case of decorated and staticly referenced classes, TypeScript ES6 emit satisfies this requirement. Before: let C_1; let C = C_1 = class C {}; After: let C_1 = class C {}; let C_1 = C; --- src/compiler/emitter.ts | 46 +++++++++++-------- .../reference/decoratorOnClass5.es6.js | 4 +- .../reference/decoratorOnClass6.es6.js | 4 +- .../reference/decoratorOnClass7.es6.js | 4 +- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index f27557a9136..f225b4cacf8 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5359,17 +5359,17 @@ const _super = (function (geti, seti) { // // TypeScript | Javascript // --------------------------------|------------------------------------ - // @dec | let C_1; - // class C { | let C = C_1 = class C { - // static x() { return C.y; } | static x() { return C_1.y; } - // static y = 1; | } + // @dec | let C_1 = class C { + // class C { | static x() { return C_1.y; } + // static x() { return C.y; } | } + // static y = 1; | let C = C_1; // } | C.y = 1; // | C = C_1 = __decorate([dec], C); // --------------------------------|------------------------------------ - // @dec | let C_1; - // export class C { | export let C = C_1 = class C { - // static x() { return C.y; } | static x() { return C_1.y; } - // static y = 1; | } + // @dec | let C_1 = class C { + // export class C { | static x() { return C_1.y; } + // static x() { return C.y; } | } + // static y = 1; | export let C = C_1; // } | C.y = 1; // | C = C_1 = __decorate([dec], C); // --------------------------------------------------------------------- @@ -5398,10 +5398,10 @@ const _super = (function (geti, seti) { // // TypeScript | Javascript // --------------------------------|------------------------------------ - // @dec | let C_1; - // export default class C { | let C = C_1 = class C { - // static x() { return C.y; } | static x() { return C_1.y; } - // static y = 1; | } + // @dec | let C_1 = class C { + // export default class C { | static x() { return C_1.y; } + // static x() { return C.y; } | }; + // static y = 1; | let C = C_1; // } | C.y = 1; // | C = C_1 = __decorate([dec], C); // | export default C; @@ -5410,25 +5410,25 @@ const _super = (function (geti, seti) { // // NOTE: we reuse the same rewriting logic for cases when targeting ES6 and module kind is System. - // Because of hoisting top level class declaration need to be emitted as class expressions. + // Because of hoisting top level class declaration need to be emitted as class expressions. // Double bind case is only required if node is decorated. if (isDecorated && resolver.getNodeCheckFlags(node) & NodeCheckFlags.ClassWithBodyScopedClassBinding) { decoratedClassAlias = unescapeIdentifier(makeUniqueName(node.name ? node.name.text : "default")); decoratedClassAliases[getNodeId(node)] = decoratedClassAlias; - write(`let ${decoratedClassAlias};`); - writeLine(); } - if (isES6ExportedDeclaration(node) && !(node.flags & NodeFlags.Default)) { + if (isES6ExportedDeclaration(node) && !(node.flags & NodeFlags.Default) && decoratedClassAlias === undefined) { write("export "); } if (!isHoistedDeclarationInSystemModule) { write("let "); } - emitDeclarationName(node); if (decoratedClassAlias !== undefined) { - write(` = ${decoratedClassAlias}`); + write(`${decoratedClassAlias}`); + } + else { + emitDeclarationName(node); } write(" = "); @@ -5490,6 +5490,16 @@ const _super = (function (geti, seti) { emitToken(SyntaxKind.CloseBraceToken, node.members.end); if (rewriteAsClassExpression) { + if (decoratedClassAlias !== undefined) { + write(";"); + writeLine(); + if (isES6ExportedDeclaration(node) && !(node.flags & NodeFlags.Default)) { + write("export "); + } + write("let "); + emitDeclarationName(node); + write(` = ${decoratedClassAlias}`); + } decoratedClassAliases[getNodeId(node)] = undefined; write(";"); } diff --git a/tests/baselines/reference/decoratorOnClass5.es6.js b/tests/baselines/reference/decoratorOnClass5.es6.js index 58c5f0d4f29..e34740d6517 100644 --- a/tests/baselines/reference/decoratorOnClass5.es6.js +++ b/tests/baselines/reference/decoratorOnClass5.es6.js @@ -16,10 +16,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; -let C_1; -let C = C_1 = class C { +let C_1 = class C { static x() { return C_1.y; } }; +let C = C_1; C.y = 1; C = C_1 = __decorate([ dec diff --git a/tests/baselines/reference/decoratorOnClass6.es6.js b/tests/baselines/reference/decoratorOnClass6.es6.js index 03b8ace2b5b..0861774bfc0 100644 --- a/tests/baselines/reference/decoratorOnClass6.es6.js +++ b/tests/baselines/reference/decoratorOnClass6.es6.js @@ -16,10 +16,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; -let C_1; -export let C = C_1 = class C { +let C_1 = class C { static x() { return C_1.y; } }; +export let C = C_1; C.y = 1; C = C_1 = __decorate([ dec diff --git a/tests/baselines/reference/decoratorOnClass7.es6.js b/tests/baselines/reference/decoratorOnClass7.es6.js index 3ffd0f1574f..7f111ea4abf 100644 --- a/tests/baselines/reference/decoratorOnClass7.es6.js +++ b/tests/baselines/reference/decoratorOnClass7.es6.js @@ -16,10 +16,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; -let C_1; -let C = C_1 = class C { +let C_1 = class C { static x() { return C_1.y; } }; +let C = C_1; C.y = 1; C = C_1 = __decorate([ dec From 7cb2db7f9efd9d6e3efe1a7fe8e221cdbd6375fd Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 24 May 2016 20:09:15 -0700 Subject: [PATCH 15/61] Fix #8795: make properties defined in optional constructor paramters optional --- src/compiler/binder.ts | 2 +- .../assignmentCompatability10.errors.txt | 17 ---------- .../optionalParameterProperty.errors.txt | 23 +++++++++++++ .../reference/optionalParameterProperty.js | 32 +++++++++++++++++++ ...opertyParameterWithQuestionMark.errors.txt | 25 ++++++--------- .../propertyParameterWithQuestionMark.js | 16 +++++----- .../compiler/optionalParameterProperty.ts | 11 +++++++ .../propertyParameterWithQuestionMark.ts | 8 ++--- 8 files changed, 89 insertions(+), 45 deletions(-) delete mode 100644 tests/baselines/reference/assignmentCompatability10.errors.txt create mode 100644 tests/baselines/reference/optionalParameterProperty.errors.txt create mode 100644 tests/baselines/reference/optionalParameterProperty.js create mode 100644 tests/cases/compiler/optionalParameterProperty.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 304e77271a7..d05b6c9f82c 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2027,7 +2027,7 @@ namespace ts { // containing class. if (isParameterPropertyDeclaration(node)) { const classDeclaration = node.parent.parent; - declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, SymbolFlags.Property | (node.questionToken ? SymbolFlags.Optional : SymbolFlags.None), SymbolFlags.PropertyExcludes); } } diff --git a/tests/baselines/reference/assignmentCompatability10.errors.txt b/tests/baselines/reference/assignmentCompatability10.errors.txt deleted file mode 100644 index 883bf1c277c..00000000000 --- a/tests/baselines/reference/assignmentCompatability10.errors.txt +++ /dev/null @@ -1,17 +0,0 @@ -tests/cases/compiler/assignmentCompatability10.ts(9,1): error TS2322: Type 'interfaceWithPublicAndOptional' is not assignable to type 'classWithPublicAndOptional'. - Property 'two' is optional in type 'interfaceWithPublicAndOptional' but required in type 'classWithPublicAndOptional'. - - -==== tests/cases/compiler/assignmentCompatability10.ts (1 errors) ==== - module __test1__ { - export interface interfaceWithPublicAndOptional { one: T; two?: U; }; var obj4: interfaceWithPublicAndOptional = { one: 1 };; - export var __val__obj4 = obj4; - } - module __test2__ { - export class classWithPublicAndOptional { constructor(public one: T, public two?: U) {} } var x4 = new classWithPublicAndOptional(1);; - export var __val__x4 = x4; - } - __test2__.__val__x4 = __test1__.__val__obj4 - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type 'interfaceWithPublicAndOptional' is not assignable to type 'classWithPublicAndOptional'. -!!! error TS2322: Property 'two' is optional in type 'interfaceWithPublicAndOptional' but required in type 'classWithPublicAndOptional'. \ No newline at end of file diff --git a/tests/baselines/reference/optionalParameterProperty.errors.txt b/tests/baselines/reference/optionalParameterProperty.errors.txt new file mode 100644 index 00000000000..d585ff6964d --- /dev/null +++ b/tests/baselines/reference/optionalParameterProperty.errors.txt @@ -0,0 +1,23 @@ +tests/cases/compiler/optionalParameterProperty.ts(6,7): error TS2415: Class 'D' incorrectly extends base class 'C'. + Types of property 'p' are incompatible. + Type 'number | undefined' is not assignable to type 'number'. + Type 'undefined' is not assignable to type 'number'. + + +==== tests/cases/compiler/optionalParameterProperty.ts (1 errors) ==== + + class C { + p: number; + } + + class D extends C { + ~ +!!! error TS2415: Class 'D' incorrectly extends base class 'C'. +!!! error TS2415: Types of property 'p' are incompatible. +!!! error TS2415: Type 'number | undefined' is not assignable to type 'number'. +!!! error TS2415: Type 'undefined' is not assignable to type 'number'. + constructor(public p?: number) { + super(); + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/optionalParameterProperty.js b/tests/baselines/reference/optionalParameterProperty.js new file mode 100644 index 00000000000..48cefeef22c --- /dev/null +++ b/tests/baselines/reference/optionalParameterProperty.js @@ -0,0 +1,32 @@ +//// [optionalParameterProperty.ts] + +class C { + p: number; +} + +class D extends C { + constructor(public p?: number) { + super(); + } +} + + +//// [optionalParameterProperty.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var C = (function () { + function C() { + } + return C; +}()); +var D = (function (_super) { + __extends(D, _super); + function D(p) { + _super.call(this); + this.p = p; + } + return D; +}(C)); diff --git a/tests/baselines/reference/propertyParameterWithQuestionMark.errors.txt b/tests/baselines/reference/propertyParameterWithQuestionMark.errors.txt index b3970c216eb..76dfb503e52 100644 --- a/tests/baselines/reference/propertyParameterWithQuestionMark.errors.txt +++ b/tests/baselines/reference/propertyParameterWithQuestionMark.errors.txt @@ -1,22 +1,17 @@ -tests/cases/compiler/propertyParameterWithQuestionMark.ts(6,5): error TS2322: Type '{}' is not assignable to type 'C'. - Property 'x' is missing in type '{}'. -tests/cases/compiler/propertyParameterWithQuestionMark.ts(8,1): error TS2322: Type '{ x?: any; }' is not assignable to type 'C'. - Property 'x' is optional in type '{ x?: any; }' but required in type 'C'. +tests/cases/compiler/propertyParameterWithQuestionMark.ts(9,5): error TS2322: Type 'C' is not assignable to type '{ x: any; }'. + Property 'x' is optional in type 'C' but required in type '{ x: any; }'. -==== tests/cases/compiler/propertyParameterWithQuestionMark.ts (2 errors) ==== +==== tests/cases/compiler/propertyParameterWithQuestionMark.ts (1 errors) ==== class C { constructor(public x?) { } } - // x should not be an optional property - var v: C = {}; // Should fail - ~ -!!! error TS2322: Type '{}' is not assignable to type 'C'. -!!! error TS2322: Property 'x' is missing in type '{}'. + // x should be an optional property + var v: C = {}; // Should succeed var v2: { x? } - v = v2; // Should fail - ~ -!!! error TS2322: Type '{ x?: any; }' is not assignable to type 'C'. -!!! error TS2322: Property 'x' is optional in type '{ x?: any; }' but required in type 'C'. - var v3: { x } = new C; // Should succeed \ No newline at end of file + v = v2; // Should succeed + var v3: { x } = new C; // Should fail + ~~ +!!! error TS2322: Type 'C' is not assignable to type '{ x: any; }'. +!!! error TS2322: Property 'x' is optional in type 'C' but required in type '{ x: any; }'. \ No newline at end of file diff --git a/tests/baselines/reference/propertyParameterWithQuestionMark.js b/tests/baselines/reference/propertyParameterWithQuestionMark.js index 511062663e8..b72638387dd 100644 --- a/tests/baselines/reference/propertyParameterWithQuestionMark.js +++ b/tests/baselines/reference/propertyParameterWithQuestionMark.js @@ -3,11 +3,11 @@ class C { constructor(public x?) { } } -// x should not be an optional property -var v: C = {}; // Should fail +// x should be an optional property +var v: C = {}; // Should succeed var v2: { x? } -v = v2; // Should fail -var v3: { x } = new C; // Should succeed +v = v2; // Should succeed +var v3: { x } = new C; // Should fail //// [propertyParameterWithQuestionMark.js] var C = (function () { @@ -16,8 +16,8 @@ var C = (function () { } return C; }()); -// x should not be an optional property -var v = {}; // Should fail +// x should be an optional property +var v = {}; // Should succeed var v2; -v = v2; // Should fail -var v3 = new C; // Should succeed +v = v2; // Should succeed +var v3 = new C; // Should fail diff --git a/tests/cases/compiler/optionalParameterProperty.ts b/tests/cases/compiler/optionalParameterProperty.ts new file mode 100644 index 00000000000..1f547d4af26 --- /dev/null +++ b/tests/cases/compiler/optionalParameterProperty.ts @@ -0,0 +1,11 @@ +// @strictNullChecks: true + +class C { + p: number; +} + +class D extends C { + constructor(public p?: number) { + super(); + } +} diff --git a/tests/cases/compiler/propertyParameterWithQuestionMark.ts b/tests/cases/compiler/propertyParameterWithQuestionMark.ts index 1a0eedb799e..ce2d88669c3 100644 --- a/tests/cases/compiler/propertyParameterWithQuestionMark.ts +++ b/tests/cases/compiler/propertyParameterWithQuestionMark.ts @@ -2,8 +2,8 @@ class C { constructor(public x?) { } } -// x should not be an optional property -var v: C = {}; // Should fail +// x should be an optional property +var v: C = {}; // Should succeed var v2: { x? } -v = v2; // Should fail -var v3: { x } = new C; // Should succeed \ No newline at end of file +v = v2; // Should succeed +var v3: { x } = new C; // Should fail \ No newline at end of file From dbd30542a6a7ecdb3b6a2594a353bb91d0bbcdd7 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 25 May 2016 07:16:23 -0700 Subject: [PATCH 16/61] Include classes as childItems in navigation bar --- src/services/navigationBar.ts | 3 +++ tests/cases/fourslash/navbar_contains-no-duplicates.ts | 4 ++-- .../navigationBarItemsBindingPatternsInConstructor.ts | 2 +- .../cases/fourslash/navigationBarItemsEmptyConstructors.ts | 2 +- .../navigationBarItemsInsideMethodsAndConstructors.ts | 2 +- tests/cases/fourslash/navigationBarItemsItems.ts | 4 ++-- .../fourslash/navigationBarItemsItemsExternalModules.ts | 4 ++-- .../fourslash/navigationBarItemsItemsExternalModules2.ts | 4 ++-- .../fourslash/navigationBarItemsItemsExternalModules3.ts | 4 ++-- tests/cases/fourslash/navigationBarItemsMissingName1.ts | 6 +++--- .../navigationBarItemsMultilineStringIdentifiers.ts | 4 ++-- .../navigationBarItemsPropertiesDefinedInConstructors.ts | 2 +- tests/cases/fourslash/navigationBarItemsSymbols1.ts | 5 +++-- tests/cases/fourslash/server/navbar01.ts | 4 ++-- 14 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index cb81c398cb8..f05f3f3a6e6 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -330,6 +330,9 @@ namespace ts.NavigationBar { case SyntaxKind.PropertySignature: return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.memberVariableElement); + case SyntaxKind.ClassDeclaration: + return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.classElement); + case SyntaxKind.FunctionDeclaration: return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.functionElement); diff --git a/tests/cases/fourslash/navbar_contains-no-duplicates.ts b/tests/cases/fourslash/navbar_contains-no-duplicates.ts index ec86e4b2f20..a698e5b0f0e 100644 --- a/tests/cases/fourslash/navbar_contains-no-duplicates.ts +++ b/tests/cases/fourslash/navbar_contains-no-duplicates.ts @@ -2,7 +2,7 @@ //// {| "itemName": "Windows", "kind": "module", "parentName": "" |}declare module Windows { //// {| "itemName": "Foundation", "kind": "module", "parentName": "" |}export module Foundation { //// export var {| "itemName": "A", "kind": "var" |}A; -//// {| "itemName": "Test", "kind": "class" |}export class Test { +//// {| "itemName": "Test", "kind": "class", "parentName": "Foundation" |}export class Test { //// {| "itemName": "wow", "kind": "method" |}public wow(); //// } //// } @@ -38,4 +38,4 @@ test.markers().forEach(marker => { marker.position); } }); -verify.navigationBarCount(12); \ No newline at end of file +verify.navigationBarCount(15); \ No newline at end of file diff --git a/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts b/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts index 84c1d09efe7..24979e141e5 100644 --- a/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts +++ b/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts @@ -11,4 +11,4 @@ //// } ////} -verify.navigationBarCount(6); // 2x(class + field + constructor) +verify.navigationBarCount(9); // global + 2 children + 2x(class + field + constructor) diff --git a/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts b/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts index 2255d29e293..a80f4c596d4 100644 --- a/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts +++ b/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts @@ -9,4 +9,4 @@ verify.navigationBarContains("Test", "class"); verify.navigationBarContains("constructor", "constructor"); // no other items -verify.navigationBarCount(2); \ No newline at end of file +verify.navigationBarCount(4); // global + 1 child, Test + 1 child \ No newline at end of file diff --git a/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts b/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts index 89b05dc6b07..3d2c026d360 100644 --- a/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts +++ b/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts @@ -39,4 +39,4 @@ test.markers().forEach((marker) => { }); // no other items -verify.navigationBarCount(19); +verify.navigationBarCount(21); diff --git a/tests/cases/fourslash/navigationBarItemsItems.ts b/tests/cases/fourslash/navigationBarItemsItems.ts index 5cae68b1194..95fdecd369c 100644 --- a/tests/cases/fourslash/navigationBarItemsItems.ts +++ b/tests/cases/fourslash/navigationBarItemsItems.ts @@ -13,7 +13,7 @@ ////{| "itemName": "Shapes", "kind": "module", "parentName": "" |}module Shapes { //// //// // Class -//// {| "itemName": "Point", "kind": "class", "parentName": "" |}export class Point implements IPoint { +//// {| "itemName": "Point", "kind": "class", "parentName": "Shapes" |}export class Point implements IPoint { //// {| "itemName": "constructor", "kind": "constructor", "parentName": "Point" |}constructor (public x: number, public y: number) { } //// //// // Instance member @@ -49,4 +49,4 @@ test.markers().forEach((marker) => { } }); -verify.navigationBarCount(24); +verify.navigationBarCount(25); diff --git a/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts index 64a595cafb1..7b2e0def4bf 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts @@ -1,6 +1,6 @@ /// -////{| "itemName": "Bar", "kind": "class" |}export class Bar { +////{| "itemName": "Bar", "kind": "class", "parentName": "\"navigationBarItemsItemsExternalModules\"" |}export class Bar { //// {| "itemName": "s", "kind": "property", "parentName": "Bar" |}public s: string; ////} @@ -8,4 +8,4 @@ test.markers().forEach((marker) => { verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); }); -verify.navigationBarCount(2); // external module node + class + property +verify.navigationBarCount(4); // external module node + class + property diff --git a/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts index 7c1c32cff76..9087493b298 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts @@ -1,7 +1,7 @@ /// // @Filename: test/file.ts -////{| "itemName": "Bar", "kind": "class" |}export class Bar { +////{| "itemName": "Bar", "kind": "class", "parentName": "\"file\"" |}export class Bar { //// {| "itemName": "s", "kind": "property", "parentName": "Bar" |}public s: string; ////} ////{| "itemName": "\"file\"", "kind": "module" |} @@ -12,4 +12,4 @@ test.markers().forEach((marker) => { verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); }); -verify.navigationBarCount(4); // external module node + variable in module + class + property +verify.navigationBarCount(5); // external module node + variable in module + class + property diff --git a/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts index 6e6dc9871cc..a00b3a131dd 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts @@ -1,7 +1,7 @@ /// // @Filename: test/my fil"e.ts -////{| "itemName": "Bar", "kind": "class" |}export class Bar { +////{| "itemName": "Bar", "kind": "class", "parentName": "\"my fil\\\"e\"" |}export class Bar { //// {| "itemName": "s", "kind": "property", "parentName": "Bar" |}public s: string; ////} ////{| "itemName": "\"my fil\\\"e\"", "kind": "module" |} @@ -12,4 +12,4 @@ test.markers().forEach((marker) => { verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); }); -verify.navigationBarCount(4); // external module node + variable in module + class + property +verify.navigationBarCount(5); // external module node + 2 children + class + property diff --git a/tests/cases/fourslash/navigationBarItemsMissingName1.ts b/tests/cases/fourslash/navigationBarItemsMissingName1.ts index 98321039c5a..59f2911f3aa 100644 --- a/tests/cases/fourslash/navigationBarItemsMissingName1.ts +++ b/tests/cases/fourslash/navigationBarItemsMissingName1.ts @@ -2,7 +2,7 @@ /////** //// * This is a class. //// */ -////{| "itemName": "C", "kind": "class" |} class C { +////{| "itemName": "C", "kind": "class", "parentName": "\"navigationBarItemsMissingName1\"" |} class C { //// {| "itemName": "foo", "kind": "method" |} foo() { //// } ////} @@ -12,5 +12,5 @@ test.markers().forEach((marker) => { verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); }); -/// Only have two named elements. -verify.navigationBarCount(2); +/// Root + 1 child, class + 1 child +verify.navigationBarCount(4); diff --git a/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts b/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts index 8856c4c044a..54524436d40 100644 --- a/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts +++ b/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts @@ -20,7 +20,7 @@ //// b"(): Foo; ////} //// -////{| "itemName": "Bar", "kind": "class" |} +////{| "itemName": "Bar", "kind": "class", "parentName": "" |} ////class Bar implements Foo { //// {| "itemName": "'a1\\\\\\r\\nb'", "kind": "property", "parentName": "Bar" |} //// 'a1\\\r\nb': Foo; @@ -38,4 +38,4 @@ test.markers().forEach((marker) => { verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); }); -verify.navigationBarCount(9); // interface w/ 2 properties, class w/ 2 properties, 3 modules \ No newline at end of file +verify.navigationBarCount(11); // global + 1 child, interface w/ 2 properties, class w/ 2 properties, 3 modules \ No newline at end of file diff --git a/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts b/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts index 9b3f4aacd9c..8e1981f6101 100644 --- a/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts +++ b/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts @@ -12,4 +12,4 @@ verify.navigationBarContains("a", "property"); verify.navigationBarContains("b", "property"); // no other items -verify.navigationBarCount(4); \ No newline at end of file +verify.navigationBarCount(6); \ No newline at end of file diff --git a/tests/cases/fourslash/navigationBarItemsSymbols1.ts b/tests/cases/fourslash/navigationBarItemsSymbols1.ts index c9df85b3ece..6d55812fa0e 100644 --- a/tests/cases/fourslash/navigationBarItemsSymbols1.ts +++ b/tests/cases/fourslash/navigationBarItemsSymbols1.ts @@ -1,6 +1,6 @@ /// -////{| "itemName": "C", "kind": "class", "parentName": "" |} +////{| "itemName": "C", "kind": "class", "parentName": "" |} ////class C { //// {| "itemName": "[Symbol.isRegExp]", "kind": "property", "parentName": "C" |} //// [Symbol.isRegExp] = 0; @@ -14,4 +14,5 @@ test.markers().forEach(marker => { verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); }); -verify.navigationBarCount(test.markers().length); \ No newline at end of file +// 2 lack markers: and its child +verify.navigationBarCount(2 + test.markers().length); \ No newline at end of file diff --git a/tests/cases/fourslash/server/navbar01.ts b/tests/cases/fourslash/server/navbar01.ts index e4e2b699be5..ead4cafe0c8 100644 --- a/tests/cases/fourslash/server/navbar01.ts +++ b/tests/cases/fourslash/server/navbar01.ts @@ -13,7 +13,7 @@ ////{| "itemName": "Shapes", "kind": "module", "parentName": "" |}module Shapes { //// //// // Class -//// {| "itemName": "Point", "kind": "class", "parentName": "" |}export class Point implements IPoint { +//// {| "itemName": "Point", "kind": "class", "parentName": "Shapes" |}export class Point implements IPoint { //// {| "itemName": "constructor", "kind": "constructor", "parentName": "Point" |}constructor (public x: number, public y: number) { } //// //// // Instance member @@ -49,4 +49,4 @@ test.markers().forEach((marker) => { } }); -verify.navigationBarCount(24); +verify.navigationBarCount(25); From 109c05863ee95c19afabb1340006cca66c1828d4 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 25 May 2016 07:49:56 -0700 Subject: [PATCH 17/61] Include modules as childItems in navigation bar --- src/services/navigationBar.ts | 44 ++++++++++--------- .../navbar_contains-no-duplicates.ts | 12 ++--- .../fourslash/navigationBarItemsItems.ts | 4 +- .../fourslash/navigationBarItemsItems2.ts | 2 +- .../navigationBarItemsItemsModuleVariables.ts | 4 +- .../fourslash/navigationBarItemsModules.ts | 19 ++++---- ...ationBarItemsMultilineStringIdentifiers.ts | 8 ++-- tests/cases/fourslash/server/navbar01.ts | 4 +- 8 files changed, 51 insertions(+), 46 deletions(-) diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index cb81c398cb8..53b1ca0b02c 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -320,6 +320,10 @@ namespace ts.NavigationBar { case SyntaxKind.EnumMember: return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.memberVariableElement); + //move? + case SyntaxKind.ModuleDeclaration: + return createItem(node, getModuleName(node), ts.ScriptElementKind.moduleElement); + case SyntaxKind.CallSignature: return createItem(node, "()", ts.ScriptElementKind.callSignatureElement); @@ -433,26 +437,6 @@ namespace ts.NavigationBar { return undefined; - function getModuleName(moduleDeclaration: ModuleDeclaration): string { - // We want to maintain quotation marks. - if (isAmbientModule(moduleDeclaration)) { - return getTextOfNode(moduleDeclaration.name); - } - - // Otherwise, we need to aggregate each identifier to build up the qualified name. - const result: string[] = []; - - result.push(moduleDeclaration.name.text); - - while (moduleDeclaration.body && moduleDeclaration.body.kind === SyntaxKind.ModuleDeclaration) { - moduleDeclaration = moduleDeclaration.body; - - result.push(moduleDeclaration.name.text); - } - - return result.join("."); - } - function createModuleItem(node: ModuleDeclaration): NavigationBarItem { const moduleName = getModuleName(node); @@ -587,6 +571,26 @@ namespace ts.NavigationBar { } } + function getModuleName(moduleDeclaration: ModuleDeclaration): string { + // We want to maintain quotation marks. + if (isAmbientModule(moduleDeclaration)) { + return getTextOfNode(moduleDeclaration.name); + } + + // Otherwise, we need to aggregate each identifier to build up the qualified name. + const result: string[] = []; + + result.push(moduleDeclaration.name.text); + + while (moduleDeclaration.body && moduleDeclaration.body.kind === SyntaxKind.ModuleDeclaration) { + moduleDeclaration = moduleDeclaration.body; + + result.push(moduleDeclaration.name.text); + } + + return result.join("."); + } + function removeComputedProperties(node: EnumDeclaration): Declaration[] { return filter(node.members, member => member.name === undefined || member.name.kind !== SyntaxKind.ComputedPropertyName); } diff --git a/tests/cases/fourslash/navbar_contains-no-duplicates.ts b/tests/cases/fourslash/navbar_contains-no-duplicates.ts index ec86e4b2f20..380b9be04f0 100644 --- a/tests/cases/fourslash/navbar_contains-no-duplicates.ts +++ b/tests/cases/fourslash/navbar_contains-no-duplicates.ts @@ -1,6 +1,6 @@ /// -//// {| "itemName": "Windows", "kind": "module", "parentName": "" |}declare module Windows { -//// {| "itemName": "Foundation", "kind": "module", "parentName": "" |}export module Foundation { +//// {| "itemName": "Windows", "kind": "module", "parentName": "" |}declare module Windows { +//// {| "itemName": "Foundation", "kind": "module", "parentName": "Windows" |}export module Foundation { //// export var {| "itemName": "A", "kind": "var" |}A; //// {| "itemName": "Test", "kind": "class" |}export class Test { //// {| "itemName": "wow", "kind": "method" |}public wow(); @@ -8,8 +8,8 @@ //// } //// } //// -//// {| "itemName": "Windows", "kind": "module", "parentName": "", "isAdditionalRange": true |}declare module Windows { -//// {| "itemName": "Foundation", "kind": "module", "parentName": "", "isAdditionalRange": true |}export module Foundation { +//// {| "itemName": "Windows", "kind": "module", "parentName": "", "isAdditionalRange": true |}declare module Windows { +//// {| "itemName": "Foundation", "kind": "module", "parentName": "Windows", "isAdditionalRange": true |}export module Foundation { //// export var {| "itemName": "B", "kind": "var" |}B; //// {| "itemName": "Test", "kind": "module" |}export module Test { //// {| "itemName": "Boom", "kind": "function" |}export function Boom(): number; @@ -23,7 +23,7 @@ //// } //// } //// -//// {| "itemName": "ABC", "kind": "module", "parentName": "" |}module ABC { +//// {| "itemName": "ABC", "kind": "module", "parentName": "" |}module ABC { //// export var {| "itemName": "x", "kind": "var" |}x = 3; //// } @@ -38,4 +38,4 @@ test.markers().forEach(marker => { marker.position); } }); -verify.navigationBarCount(12); \ No newline at end of file +verify.navigationBarCount(17); \ No newline at end of file diff --git a/tests/cases/fourslash/navigationBarItemsItems.ts b/tests/cases/fourslash/navigationBarItemsItems.ts index 5cae68b1194..582aad019b9 100644 --- a/tests/cases/fourslash/navigationBarItemsItems.ts +++ b/tests/cases/fourslash/navigationBarItemsItems.ts @@ -10,7 +10,7 @@ ////} //// /////// Module -////{| "itemName": "Shapes", "kind": "module", "parentName": "" |}module Shapes { +////{| "itemName": "Shapes", "kind": "module", "parentName": "" |}module Shapes { //// //// // Class //// {| "itemName": "Point", "kind": "class", "parentName": "" |}export class Point implements IPoint { @@ -49,4 +49,4 @@ test.markers().forEach((marker) => { } }); -verify.navigationBarCount(24); +verify.navigationBarCount(25); diff --git a/tests/cases/fourslash/navigationBarItemsItems2.ts b/tests/cases/fourslash/navigationBarItemsItems2.ts index d4ffde54051..013f27b4d71 100644 --- a/tests/cases/fourslash/navigationBarItemsItems2.ts +++ b/tests/cases/fourslash/navigationBarItemsItems2.ts @@ -8,5 +8,5 @@ edit.insertLine("module A"); edit.insert("export class "); // should not crash -verify.navigationBarCount(2); +verify.navigationBarCount(4); diff --git a/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts b/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts index afc1acfb9cb..5429011888c 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts @@ -22,9 +22,9 @@ goTo.marker("file1"); verify.navigationBarContains("Module1", "module"); verify.navigationBarContains("x", "var"); // nothing else should show up -verify.navigationBarCount(2); +verify.navigationBarCount(4); // , its child, Module1, its child goTo.marker("file2"); verify.navigationBarContains("Module1.SubModule", "module"); verify.navigationBarContains("y", "var"); -verify.navigationBarCount(2); +verify.navigationBarCount(4); diff --git a/tests/cases/fourslash/navigationBarItemsModules.ts b/tests/cases/fourslash/navigationBarItemsModules.ts index 895a9e23a06..237ec8eb275 100644 --- a/tests/cases/fourslash/navigationBarItemsModules.ts +++ b/tests/cases/fourslash/navigationBarItemsModules.ts @@ -1,35 +1,36 @@ +/// -////{| "itemName": "\"X.Y.Z\"", "kind": "module" |} +////{| "itemName": "\"X.Y.Z\"", "kind": "module", "parentName": "" |} ////declare module "X.Y.Z" { ////} //// -////{| "itemName": "'X2.Y2.Z2'", "kind": "module" |} +////{| "itemName": "'X2.Y2.Z2'", "kind": "module", "parentName": "" |} ////declare module 'X2.Y2.Z2' { ////} //// -////{| "itemName": "A.B.C", "kind": "module" |} +////{| "itemName": "A.B.C", "kind": "module", "parentName": "" |} ////module A.B.C { //// {| "itemName": "x", "kind": "var", "parentName": "A.B.C" |} //// export var x; ////} //// -////{| "itemName": "A.B", "kind": "module" |} +////{| "itemName": "A.B", "kind": "module", "parentName": "" |} ////module A.B { //// {| "itemName": "y", "kind": "var", "parentName": "A.B" |} //// export var y; ////} //// -////{| "itemName": "A", "kind": "module" |} +////{| "itemName": "A", "kind": "module", "parentName": "" |} ////module A { //// {| "itemName": "z", "kind": "var", "parentName": "A" |} //// export var z; ////} //// -////{| "itemName": "A", "kind": "module" |} +////{| "itemName": "A", "kind": "module", "parentName": "" |} ////module A { -//// {| "itemName": "B", "kind": "module", "parentName": "" |} +//// {| "itemName": "B", "kind": "module", "parentName": "A" |} //// module B { -//// {| "itemName": "C", "kind": "module", "parentName": "" |} +//// {| "itemName": "C", "kind": "module", "parentName": "B" |} //// module C { //// {| "itemName": "x", "kind": "var", "parentName": "C" |} //// declare var x; @@ -45,4 +46,4 @@ test.markers().forEach((marker) => { /// We have 8 module keywords, and 4 var keywords. /// The declarations of A.B.C.x do not get merged, so the 4 vars are independent. /// The two 'A' modules, however, do get merged, so in reality we have 7 modules. -verify.navigationBarCount(11); +verify.navigationBarCount(19); diff --git a/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts b/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts index 8856c4c044a..fc6eeb4dcec 100644 --- a/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts +++ b/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts @@ -1,13 +1,13 @@ -////{| "itemName": "\"Multiline\\r\\nMadness\"", "kind": "module" |} +////{| "itemName": "\"Multiline\\r\\nMadness\"", "kind": "module", "parentName": "" |} ////declare module "Multiline\r\nMadness" { ////} //// -////{| "itemName": "\"Multiline\\\nMadness\"", "kind": "module" |} +////{| "itemName": "\"Multiline\\\nMadness\"", "kind": "module", "parentName": "" |} ////declare module "Multiline\ ////Madness" { ////} -////{| "itemName": "\"MultilineMadness\"", "kind": "module" |} +////{| "itemName": "\"MultilineMadness\"", "kind": "module", "parentName": "" |} ////declare module "MultilineMadness" {} //// ////{| "itemName": "Foo", "kind": "interface" |} @@ -38,4 +38,4 @@ test.markers().forEach((marker) => { verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); }); -verify.navigationBarCount(9); // interface w/ 2 properties, class w/ 2 properties, 3 modules \ No newline at end of file +verify.navigationBarCount(13); \ No newline at end of file diff --git a/tests/cases/fourslash/server/navbar01.ts b/tests/cases/fourslash/server/navbar01.ts index e4e2b699be5..79b0dd3c1ab 100644 --- a/tests/cases/fourslash/server/navbar01.ts +++ b/tests/cases/fourslash/server/navbar01.ts @@ -10,7 +10,7 @@ ////} //// /////// Module -////{| "itemName": "Shapes", "kind": "module", "parentName": "" |}module Shapes { +////{| "itemName": "Shapes", "kind": "module", "parentName": "" |}module Shapes { //// //// // Class //// {| "itemName": "Point", "kind": "class", "parentName": "" |}export class Point implements IPoint { @@ -49,4 +49,4 @@ test.markers().forEach((marker) => { } }); -verify.navigationBarCount(24); +verify.navigationBarCount(25); From 642d6d540717e1ae8e5cd9650ac7ed48e883a21a Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 25 May 2016 10:12:16 -0700 Subject: [PATCH 18/61] Only allow excess numeric properties w/numeric indexers Previously, having a numeric indexer on a target type meant that excess object property checking would allow any property. Now only numeric properties are allowed. --- src/compiler/checker.ts | 9 ++++++--- .../objectLiteralExcessProperties.errors.txt | 16 +++++++++++++++- .../reference/objectLiteralExcessProperties.js | 6 ++++++ .../compiler/objectLiteralExcessProperties.ts | 4 ++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3e8066865ac..70db18b0f29 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6034,11 +6034,14 @@ namespace ts { function isKnownProperty(type: Type, name: string): boolean { if (type.flags & TypeFlags.ObjectType) { const resolved = resolveStructuredTypeMembers(type); - if ((relation === assignableRelation || relation === comparableRelation) && - (type === globalObjectType || isEmptyObjectType(resolved)) || - resolved.stringIndexInfo || resolved.numberIndexInfo || getPropertyOfType(type, name)) { + if ((relation === assignableRelation || relation === comparableRelation) && (type === globalObjectType || isEmptyObjectType(resolved)) || + resolved.stringIndexInfo || + getPropertyOfType(type, name)) { return true; } + if (resolved.numberIndexInfo) { + return isNumericLiteralName(name); + } } else if (type.flags & TypeFlags.UnionOrIntersection) { for (const t of (type).types) { diff --git a/tests/baselines/reference/objectLiteralExcessProperties.errors.txt b/tests/baselines/reference/objectLiteralExcessProperties.errors.txt index 84f635bf947..cfae572d6d2 100644 --- a/tests/baselines/reference/objectLiteralExcessProperties.errors.txt +++ b/tests/baselines/reference/objectLiteralExcessProperties.errors.txt @@ -15,9 +15,13 @@ tests/cases/compiler/objectLiteralExcessProperties.ts(19,57): error TS2322: Type Object literal may only specify known properties, and 'price' does not exist in type 'Book & Cover'. tests/cases/compiler/objectLiteralExcessProperties.ts(21,43): error TS2322: Type '{ foreword: string; price: number; }' is not assignable to type 'Book & number'. Object literal may only specify known properties, and 'price' does not exist in type 'Book & number'. +tests/cases/compiler/objectLiteralExcessProperties.ts(23,29): error TS2322: Type '{ couleur: string; }' is not assignable to type 'Cover | Cover[]'. + Object literal may only specify known properties, and 'couleur' does not exist in type 'Cover | Cover[]'. +tests/cases/compiler/objectLiteralExcessProperties.ts(25,27): error TS2322: Type '{ forewarned: string; }' is not assignable to type 'Book | Book[]'. + Object literal may only specify known properties, and 'forewarned' does not exist in type 'Book | Book[]'. -==== tests/cases/compiler/objectLiteralExcessProperties.ts (7 errors) ==== +==== tests/cases/compiler/objectLiteralExcessProperties.ts (9 errors) ==== interface Book { foreword: string; } @@ -63,4 +67,14 @@ tests/cases/compiler/objectLiteralExcessProperties.ts(21,43): error TS2322: Type ~~~~~~~~~~~~ !!! error TS2322: Type '{ foreword: string; price: number; }' is not assignable to type 'Book & number'. !!! error TS2322: Object literal may only specify known properties, and 'price' does not exist in type 'Book & number'. + + var b8: Cover | Cover[] = { couleur : "non" }; + ~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ couleur: string; }' is not assignable to type 'Cover | Cover[]'. +!!! error TS2322: Object literal may only specify known properties, and 'couleur' does not exist in type 'Cover | Cover[]'. + + var b9: Book | Book[] = { forewarned: "still no" }; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ forewarned: string; }' is not assignable to type 'Book | Book[]'. +!!! error TS2322: Object literal may only specify known properties, and 'forewarned' does not exist in type 'Book | Book[]'. \ No newline at end of file diff --git a/tests/baselines/reference/objectLiteralExcessProperties.js b/tests/baselines/reference/objectLiteralExcessProperties.js index 747928ccb20..3515723b5f1 100644 --- a/tests/baselines/reference/objectLiteralExcessProperties.js +++ b/tests/baselines/reference/objectLiteralExcessProperties.js @@ -20,6 +20,10 @@ var b5: Book & Cover = { foreward: "hi", color: "blue" }; var b6: Book & Cover = { foreword: "hi", color: "blue", price: 10.99 }; var b7: Book & number = { foreword: "hi", price: 10.99 }; + +var b8: Cover | Cover[] = { couleur : "non" }; + +var b9: Book | Book[] = { forewarned: "still no" }; //// [objectLiteralExcessProperties.js] @@ -30,3 +34,5 @@ var b4 = { foreword: "hi", colour: "blue" }; var b5 = { foreward: "hi", color: "blue" }; var b6 = { foreword: "hi", color: "blue", price: 10.99 }; var b7 = { foreword: "hi", price: 10.99 }; +var b8 = { couleur: "non" }; +var b9 = { forewarned: "still no" }; diff --git a/tests/cases/compiler/objectLiteralExcessProperties.ts b/tests/cases/compiler/objectLiteralExcessProperties.ts index 0aa81703c33..7ed64d2d42c 100644 --- a/tests/cases/compiler/objectLiteralExcessProperties.ts +++ b/tests/cases/compiler/objectLiteralExcessProperties.ts @@ -19,3 +19,7 @@ var b5: Book & Cover = { foreward: "hi", color: "blue" }; var b6: Book & Cover = { foreword: "hi", color: "blue", price: 10.99 }; var b7: Book & number = { foreword: "hi", price: 10.99 }; + +var b8: Cover | Cover[] = { couleur : "non" }; + +var b9: Book | Book[] = { forewarned: "still no" }; From 5bfdf69fbf3a2bc6d026f59a8eae8e98d8d95dfa Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 25 May 2016 10:17:59 -0700 Subject: [PATCH 19/61] Remove comment --- src/services/navigationBar.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 53b1ca0b02c..8b5a7c5849e 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -320,7 +320,6 @@ namespace ts.NavigationBar { case SyntaxKind.EnumMember: return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.memberVariableElement); - //move? case SyntaxKind.ModuleDeclaration: return createItem(node, getModuleName(node), ts.ScriptElementKind.moduleElement); From 89fb304eeede783031f15ea298cd4289bd533977 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 25 May 2016 10:18:49 -0700 Subject: [PATCH 20/61] Add test case for excess checking of numeric properties --- .../objectLiteralExcessProperties.errors.txt | 19 ++++++++++++++++++- .../objectLiteralExcessProperties.js | 10 ++++++++++ .../compiler/objectLiteralExcessProperties.ts | 8 ++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/tests/baselines/reference/objectLiteralExcessProperties.errors.txt b/tests/baselines/reference/objectLiteralExcessProperties.errors.txt index cfae572d6d2..b96b9b0c542 100644 --- a/tests/baselines/reference/objectLiteralExcessProperties.errors.txt +++ b/tests/baselines/reference/objectLiteralExcessProperties.errors.txt @@ -19,9 +19,13 @@ tests/cases/compiler/objectLiteralExcessProperties.ts(23,29): error TS2322: Type Object literal may only specify known properties, and 'couleur' does not exist in type 'Cover | Cover[]'. tests/cases/compiler/objectLiteralExcessProperties.ts(25,27): error TS2322: Type '{ forewarned: string; }' is not assignable to type 'Book | Book[]'. Object literal may only specify known properties, and 'forewarned' does not exist in type 'Book | Book[]'. +tests/cases/compiler/objectLiteralExcessProperties.ts(33,27): error TS2322: Type '{ 0: { colour: string; }; }' is not assignable to type 'Indexed'. + Property '0' is incompatible with index signature. + Type '{ colour: string; }' is not assignable to type 'Cover'. + Object literal may only specify known properties, and 'colour' does not exist in type 'Cover'. -==== tests/cases/compiler/objectLiteralExcessProperties.ts (9 errors) ==== +==== tests/cases/compiler/objectLiteralExcessProperties.ts (10 errors) ==== interface Book { foreword: string; } @@ -77,4 +81,17 @@ tests/cases/compiler/objectLiteralExcessProperties.ts(25,27): error TS2322: Type ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2322: Type '{ forewarned: string; }' is not assignable to type 'Book | Book[]'. !!! error TS2322: Object literal may only specify known properties, and 'forewarned' does not exist in type 'Book | Book[]'. + + interface Indexed { + [n: number]: Cover; + } + + var b10: Indexed = { 0: { }, '1': { } }; // ok + + var b11: Indexed = { 0: { colour: "blue" } }; // nested object literal still errors + ~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ 0: { colour: string; }; }' is not assignable to type 'Indexed'. +!!! error TS2322: Property '0' is incompatible with index signature. +!!! error TS2322: Type '{ colour: string; }' is not assignable to type 'Cover'. +!!! error TS2322: Object literal may only specify known properties, and 'colour' does not exist in type 'Cover'. \ No newline at end of file diff --git a/tests/baselines/reference/objectLiteralExcessProperties.js b/tests/baselines/reference/objectLiteralExcessProperties.js index 3515723b5f1..38186b19bf7 100644 --- a/tests/baselines/reference/objectLiteralExcessProperties.js +++ b/tests/baselines/reference/objectLiteralExcessProperties.js @@ -24,6 +24,14 @@ var b7: Book & number = { foreword: "hi", price: 10.99 }; var b8: Cover | Cover[] = { couleur : "non" }; var b9: Book | Book[] = { forewarned: "still no" }; + +interface Indexed { + [n: number]: Cover; +} + +var b10: Indexed = { 0: { }, '1': { } }; // ok + +var b11: Indexed = { 0: { colour: "blue" } }; // nested object literal still errors //// [objectLiteralExcessProperties.js] @@ -36,3 +44,5 @@ var b6 = { foreword: "hi", color: "blue", price: 10.99 }; var b7 = { foreword: "hi", price: 10.99 }; var b8 = { couleur: "non" }; var b9 = { forewarned: "still no" }; +var b10 = { 0: {}, '1': {} }; // ok +var b11 = { 0: { colour: "blue" } }; // nested object literal still errors diff --git a/tests/cases/compiler/objectLiteralExcessProperties.ts b/tests/cases/compiler/objectLiteralExcessProperties.ts index 7ed64d2d42c..ca681b7b28e 100644 --- a/tests/cases/compiler/objectLiteralExcessProperties.ts +++ b/tests/cases/compiler/objectLiteralExcessProperties.ts @@ -23,3 +23,11 @@ var b7: Book & number = { foreword: "hi", price: 10.99 }; var b8: Cover | Cover[] = { couleur : "non" }; var b9: Book | Book[] = { forewarned: "still no" }; + +interface Indexed { + [n: number]: Cover; +} + +var b10: Indexed = { 0: { }, '1': { } }; // ok + +var b11: Indexed = { 0: { colour: "blue" } }; // nested object literal still errors From 5138e8be8ea21317b62b082ca345695d37445502 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 25 May 2016 11:37:10 -0700 Subject: [PATCH 21/61] Correct tests and update baselines. A lot of tests used non-numeric property names for object literals that are contextually typed only by a numeric indexer. --- ...computedPropertyNamesContextualType7_ES5.js | 7 ++++--- ...tedPropertyNamesContextualType7_ES5.symbols | 5 ++--- ...putedPropertyNamesContextualType7_ES5.types | 8 ++++---- ...computedPropertyNamesContextualType7_ES6.js | 7 ++++--- ...tedPropertyNamesContextualType7_ES6.symbols | 5 ++--- ...putedPropertyNamesContextualType7_ES6.types | 8 ++++---- .../indexSignaturesInferentialTyping.js | 10 ++++------ .../indexSignaturesInferentialTyping.symbols | 16 +++++----------- .../indexSignaturesInferentialTyping.types | 18 ++++-------------- ...erConstrainsPropertyDeclarations.errors.txt | 12 +++++------- ...rConstrainsPropertyDeclarations2.errors.txt | 12 +++++------- .../reference/numericIndexerConstraint4.js | 5 +++-- .../numericIndexerConstraint4.symbols | 3 +-- .../reference/numericIndexerConstraint4.types | 5 ++--- .../objectLitIndexerContextualType.errors.txt | 12 +++++++++--- .../objectLitIndexerContextualType.js | 5 +++-- .../objectTypesIdentityWithNumericIndexers1.js | 4 ++-- ...ctTypesIdentityWithNumericIndexers1.symbols | 9 ++++----- ...jectTypesIdentityWithNumericIndexers1.types | 5 ++--- .../objectTypesIdentityWithNumericIndexers2.js | 4 ++-- ...ctTypesIdentityWithNumericIndexers2.symbols | 9 ++++----- ...jectTypesIdentityWithNumericIndexers2.types | 5 ++--- .../objectTypesIdentityWithNumericIndexers3.js | 4 ++-- ...ctTypesIdentityWithNumericIndexers3.symbols | 9 ++++----- ...jectTypesIdentityWithNumericIndexers3.types | 5 ++--- .../reference/propertyAccess.errors.txt | 7 ++++++- .../indexSignaturesInferentialTyping.ts | 5 ++--- .../compiler/numericIndexerConstraint4.ts | 2 +- .../compiler/objectLitIndexerContextualType.ts | 4 ++-- ...computedPropertyNamesContextualType7_ES5.ts | 4 ++-- ...computedPropertyNamesContextualType7_ES6.ts | 4 ++-- .../objectTypesIdentityWithNumericIndexers1.ts | 2 +- .../objectTypesIdentityWithNumericIndexers2.ts | 2 +- .../objectTypesIdentityWithNumericIndexers3.ts | 2 +- 34 files changed, 103 insertions(+), 121 deletions(-) diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js index 9ca7e826aa7..65cc057fa81 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js @@ -6,16 +6,17 @@ interface I { declare function foo(obj: I): T foo({ - p: "", + 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0] -}); +}); + //// [computedPropertyNamesContextualType7_ES5.js] foo((_a = { - p: "", + 101: "", 0: function () { } }, _a["hi" + "bye"] = true, diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.symbols b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.symbols index 22e4cf2b45b..562b238cdac 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.symbols +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.symbols @@ -19,11 +19,10 @@ declare function foo(obj: I): T foo({ >foo : Symbol(foo, Decl(computedPropertyNamesContextualType7_ES5.ts, 2, 1)) - p: "", ->p : Symbol(p, Decl(computedPropertyNamesContextualType7_ES5.ts, 6, 5)) - + 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0] }); + diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types index 083388ba975..53c8f805c57 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types @@ -17,12 +17,11 @@ declare function foo(obj: I): T >T : T foo({ ->foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : (() => void) | number | number[] +>foo({ 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | (() => void) | number | number[] >foo : (obj: I) => T ->{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | (() => void) | boolean | number | number[]; [x: number]: (() => void) | number | number[]; 0: () => void; p: string; } +>{ 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | (() => void) | boolean | number | number[]; [x: number]: string | (() => void) | number | number[]; 0: () => void; 101: string; } - p: "", ->p : string + 101: "", >"" : string 0: () => { }, @@ -47,3 +46,4 @@ foo({ >0 : number }); + diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.js b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.js index 185ccd72ead..0b515dba7ca 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.js @@ -6,16 +6,17 @@ interface I { declare function foo(obj: I): T foo({ - p: "", + 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0] -}); +}); + //// [computedPropertyNamesContextualType7_ES6.js] foo({ - p: "", + 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.symbols b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.symbols index 7f33ebf58ad..ca0c2f12a80 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.symbols +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.symbols @@ -19,11 +19,10 @@ declare function foo(obj: I): T foo({ >foo : Symbol(foo, Decl(computedPropertyNamesContextualType7_ES6.ts, 2, 1)) - p: "", ->p : Symbol(p, Decl(computedPropertyNamesContextualType7_ES6.ts, 6, 5)) - + 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0] }); + diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types index bc6ae72fb4f..f2eefe7405e 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types @@ -17,12 +17,11 @@ declare function foo(obj: I): T >T : T foo({ ->foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : (() => void) | number | number[] +>foo({ 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | (() => void) | number | number[] >foo : (obj: I) => T ->{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | (() => void) | boolean | number | number[]; [x: number]: (() => void) | number | number[]; 0: () => void; p: string; } +>{ 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | (() => void) | boolean | number | number[]; [x: number]: string | (() => void) | number | number[]; 0: () => void; 101: string; } - p: "", ->p : string + 101: "", >"" : string 0: () => { }, @@ -47,3 +46,4 @@ foo({ >0 : number }); + diff --git a/tests/baselines/reference/indexSignaturesInferentialTyping.js b/tests/baselines/reference/indexSignaturesInferentialTyping.js index 53636be716c..b5255861a10 100644 --- a/tests/baselines/reference/indexSignaturesInferentialTyping.js +++ b/tests/baselines/reference/indexSignaturesInferentialTyping.js @@ -3,15 +3,13 @@ function foo(items: { [index: number]: T }): T { return undefined; } function bar(items: { [index: string]: T }): T { return undefined; } var x1 = foo({ 0: 0, 1: 1 }); // type should be number -var x2 = foo({ zero: 0, one: 1 }); -var x3 = bar({ 0: 0, 1: 1 }); -var x4 = bar({ zero: 0, one: 1 }); // type should be number +var x2 = bar({ 0: 0, 1: 1 }); +var x3 = bar({ zero: 0, one: 1 }); // type should be number //// [indexSignaturesInferentialTyping.js] function foo(items) { return undefined; } function bar(items) { return undefined; } var x1 = foo({ 0: 0, 1: 1 }); // type should be number -var x2 = foo({ zero: 0, one: 1 }); -var x3 = bar({ 0: 0, 1: 1 }); -var x4 = bar({ zero: 0, one: 1 }); // type should be number +var x2 = bar({ 0: 0, 1: 1 }); +var x3 = bar({ zero: 0, one: 1 }); // type should be number diff --git a/tests/baselines/reference/indexSignaturesInferentialTyping.symbols b/tests/baselines/reference/indexSignaturesInferentialTyping.symbols index a34aa7a5cd1..754fe0390a4 100644 --- a/tests/baselines/reference/indexSignaturesInferentialTyping.symbols +++ b/tests/baselines/reference/indexSignaturesInferentialTyping.symbols @@ -21,19 +21,13 @@ var x1 = foo({ 0: 0, 1: 1 }); // type should be number >x1 : Symbol(x1, Decl(indexSignaturesInferentialTyping.ts, 3, 3)) >foo : Symbol(foo, Decl(indexSignaturesInferentialTyping.ts, 0, 0)) -var x2 = foo({ zero: 0, one: 1 }); +var x2 = bar({ 0: 0, 1: 1 }); >x2 : Symbol(x2, Decl(indexSignaturesInferentialTyping.ts, 4, 3)) ->foo : Symbol(foo, Decl(indexSignaturesInferentialTyping.ts, 0, 0)) ->zero : Symbol(zero, Decl(indexSignaturesInferentialTyping.ts, 4, 14)) ->one : Symbol(one, Decl(indexSignaturesInferentialTyping.ts, 4, 23)) +>bar : Symbol(bar, Decl(indexSignaturesInferentialTyping.ts, 0, 71)) -var x3 = bar({ 0: 0, 1: 1 }); +var x3 = bar({ zero: 0, one: 1 }); // type should be number >x3 : Symbol(x3, Decl(indexSignaturesInferentialTyping.ts, 5, 3)) >bar : Symbol(bar, Decl(indexSignaturesInferentialTyping.ts, 0, 71)) - -var x4 = bar({ zero: 0, one: 1 }); // type should be number ->x4 : Symbol(x4, Decl(indexSignaturesInferentialTyping.ts, 6, 3)) ->bar : Symbol(bar, Decl(indexSignaturesInferentialTyping.ts, 0, 71)) ->zero : Symbol(zero, Decl(indexSignaturesInferentialTyping.ts, 6, 14)) ->one : Symbol(one, Decl(indexSignaturesInferentialTyping.ts, 6, 23)) +>zero : Symbol(zero, Decl(indexSignaturesInferentialTyping.ts, 5, 14)) +>one : Symbol(one, Decl(indexSignaturesInferentialTyping.ts, 5, 23)) diff --git a/tests/baselines/reference/indexSignaturesInferentialTyping.types b/tests/baselines/reference/indexSignaturesInferentialTyping.types index 8545a7d4ca9..47c7aa21388 100644 --- a/tests/baselines/reference/indexSignaturesInferentialTyping.types +++ b/tests/baselines/reference/indexSignaturesInferentialTyping.types @@ -25,26 +25,16 @@ var x1 = foo({ 0: 0, 1: 1 }); // type should be number >0 : number >1 : number -var x2 = foo({ zero: 0, one: 1 }); ->x2 : {} ->foo({ zero: 0, one: 1 }) : {} ->foo : (items: { [index: number]: T; }) => T ->{ zero: 0, one: 1 } : { zero: number; one: number; } ->zero : number ->0 : number ->one : number ->1 : number - -var x3 = bar({ 0: 0, 1: 1 }); ->x3 : number +var x2 = bar({ 0: 0, 1: 1 }); +>x2 : number >bar({ 0: 0, 1: 1 }) : number >bar : (items: { [index: string]: T; }) => T >{ 0: 0, 1: 1 } : { 0: number; 1: number; } >0 : number >1 : number -var x4 = bar({ zero: 0, one: 1 }); // type should be number ->x4 : number +var x3 = bar({ zero: 0, one: 1 }); // type should be number +>x3 : number >bar({ zero: 0, one: 1 }) : number >bar : (items: { [index: string]: T; }) => T >{ zero: 0, one: 1 } : { zero: number; one: number; } diff --git a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt index bb01b2fe125..ec0f330f1a3 100644 --- a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt @@ -5,9 +5,8 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(36,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(50,5): error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(68,5): error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo(): string; }' is not assignable to type '{ [x: number]: string; }'. - Property '2.0' is incompatible with index signature. - Type 'number' is not assignable to type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(79,5): error TS2322: Type '{ 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo(): string; }' is not assignable to type '{ [x: number]: string; }'. + Object literal may only specify known properties, and 'a' does not exist in type '{ [x: number]: string; }'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(88,9): error TS2304: Cannot find name 'Myn'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(90,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(93,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. @@ -106,11 +105,10 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo // error var b: { [x: number]: string; } = { - ~ -!!! error TS2322: Type '{ 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo(): string; }' is not assignable to type '{ [x: number]: string; }'. -!!! error TS2322: Property '2.0' is incompatible with index signature. -!!! error TS2322: Type 'number' is not assignable to type 'string'. a: '', + ~~~~~ +!!! error TS2322: Type '{ 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo(): string; }' is not assignable to type '{ [x: number]: string; }'. +!!! error TS2322: Object literal may only specify known properties, and 'a' does not exist in type '{ [x: number]: string; }'. b: 1, c: () => { }, "d": '', diff --git a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt index 332b356c732..e6d22ff0712 100644 --- a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt +++ b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt @@ -1,9 +1,8 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(16,5): error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(25,5): error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(34,5): error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(39,5): error TS2322: Type '{ 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }'. - Property '3.0' is incompatible with index signature. - Type 'number' is not assignable to type 'A'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(44,5): error TS2322: Type '{ 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }'. + Object literal may only specify known properties, and '"4.0"' does not exist in type '{ [x: number]: A; }'. ==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts (4 errors) ==== @@ -52,13 +51,12 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo // error var b: { [x: number]: A } = { - ~ -!!! error TS2322: Type '{ 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }'. -!!! error TS2322: Property '3.0' is incompatible with index signature. -!!! error TS2322: Type 'number' is not assignable to type 'A'. 1.0: new A(), 2.0: new B(), "2.5": new B(), 3.0: 1, "4.0": '' + ~~~~~~~~~ +!!! error TS2322: Type '{ 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }'. +!!! error TS2322: Object literal may only specify known properties, and '"4.0"' does not exist in type '{ [x: number]: A; }'. } \ No newline at end of file diff --git a/tests/baselines/reference/numericIndexerConstraint4.js b/tests/baselines/reference/numericIndexerConstraint4.js index 245569cb62e..a9eace23833 100644 --- a/tests/baselines/reference/numericIndexerConstraint4.js +++ b/tests/baselines/reference/numericIndexerConstraint4.js @@ -9,7 +9,8 @@ class B extends A { var x: { [idx: number]: A; -} = { data: new B() } +} = { 0: new B() } + //// [numericIndexerConstraint4.js] var __extends = (this && this.__extends) || function (d, b) { @@ -29,4 +30,4 @@ var B = (function (_super) { } return B; }(A)); -var x = { data: new B() }; +var x = { 0: new B() }; diff --git a/tests/baselines/reference/numericIndexerConstraint4.symbols b/tests/baselines/reference/numericIndexerConstraint4.symbols index 46301a6787b..8edf7d0f6fe 100644 --- a/tests/baselines/reference/numericIndexerConstraint4.symbols +++ b/tests/baselines/reference/numericIndexerConstraint4.symbols @@ -21,7 +21,6 @@ var x: { >idx : Symbol(idx, Decl(numericIndexerConstraint4.ts, 9, 5)) >A : Symbol(A, Decl(numericIndexerConstraint4.ts, 0, 0)) -} = { data: new B() } ->data : Symbol(data, Decl(numericIndexerConstraint4.ts, 10, 5)) +} = { 0: new B() } >B : Symbol(B, Decl(numericIndexerConstraint4.ts, 2, 1)) diff --git a/tests/baselines/reference/numericIndexerConstraint4.types b/tests/baselines/reference/numericIndexerConstraint4.types index c8af4d54a9a..c8cda0e6be2 100644 --- a/tests/baselines/reference/numericIndexerConstraint4.types +++ b/tests/baselines/reference/numericIndexerConstraint4.types @@ -21,9 +21,8 @@ var x: { >idx : number >A : A -} = { data: new B() } ->{ data: new B() } : { data: B; } ->data : B +} = { 0: new B() } +>{ 0: new B() } : { 0: B; } >new B() : B >B : typeof B diff --git a/tests/baselines/reference/objectLitIndexerContextualType.errors.txt b/tests/baselines/reference/objectLitIndexerContextualType.errors.txt index ca65ee5a5be..5012dc11728 100644 --- a/tests/baselines/reference/objectLitIndexerContextualType.errors.txt +++ b/tests/baselines/reference/objectLitIndexerContextualType.errors.txt @@ -2,11 +2,13 @@ tests/cases/compiler/objectLitIndexerContextualType.ts(12,13): error TS2362: The tests/cases/compiler/objectLitIndexerContextualType.ts(12,17): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/compiler/objectLitIndexerContextualType.ts(15,13): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/compiler/objectLitIndexerContextualType.ts(15,17): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/compiler/objectLitIndexerContextualType.ts(18,5): error TS2322: Type '{ s: (t: any) => number; }' is not assignable to type 'J'. + Object literal may only specify known properties, and 's' does not exist in type 'J'. tests/cases/compiler/objectLitIndexerContextualType.ts(21,13): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/compiler/objectLitIndexerContextualType.ts(21,17): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -==== tests/cases/compiler/objectLitIndexerContextualType.ts (6 errors) ==== +==== tests/cases/compiler/objectLitIndexerContextualType.ts (7 errors) ==== interface I { [s: string]: (s: string) => number; } @@ -32,7 +34,10 @@ tests/cases/compiler/objectLitIndexerContextualType.ts(21,17): error TS2363: The !!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. }; y = { - s: t => t * t, // Should not error + s: t => t * t, // Should error + ~~~~~~~~~~~~~ +!!! error TS2322: Type '{ s: (t: any) => number; }' is not assignable to type 'J'. +!!! error TS2322: Object literal may only specify known properties, and 's' does not exist in type 'J'. }; y = { 0: t => t * t, // Should error @@ -40,4 +45,5 @@ tests/cases/compiler/objectLitIndexerContextualType.ts(21,17): error TS2363: The !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. ~ !!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - }; \ No newline at end of file + }; + \ No newline at end of file diff --git a/tests/baselines/reference/objectLitIndexerContextualType.js b/tests/baselines/reference/objectLitIndexerContextualType.js index f0cf90724b3..601462d8751 100644 --- a/tests/baselines/reference/objectLitIndexerContextualType.js +++ b/tests/baselines/reference/objectLitIndexerContextualType.js @@ -16,11 +16,12 @@ x = { 0: t => t * t, // Should error }; y = { - s: t => t * t, // Should not error + s: t => t * t, // Should error }; y = { 0: t => t * t, // Should error -}; +}; + //// [objectLitIndexerContextualType.js] var x; diff --git a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.js b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.js index c0bd423cd79..29781229b5a 100644 --- a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.js +++ b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.js @@ -26,7 +26,7 @@ class PB extends B { var a: { [x: number]: string; } -var b: { [x: number]: string; } = { foo: '' }; +var b: { [x: number]: string; } = { 0: '' }; function foo1(x: A); function foo1(x: A); // error @@ -159,7 +159,7 @@ var PB = (function (_super) { return PB; }(B)); var a; -var b = { foo: '' }; +var b = { 0: '' }; function foo1(x) { } function foo1b(x) { } function foo1c(x) { } diff --git a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.symbols b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.symbols index 4a2eb1ab2a1..798fb5c3c57 100644 --- a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.symbols +++ b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.symbols @@ -47,23 +47,22 @@ var a: { [x: number]: string; >x : Symbol(x, Decl(objectTypesIdentityWithNumericIndexers1.ts, 25, 5)) } -var b: { [x: number]: string; } = { foo: '' }; +var b: { [x: number]: string; } = { 0: '' }; >b : Symbol(b, Decl(objectTypesIdentityWithNumericIndexers1.ts, 27, 3)) >x : Symbol(x, Decl(objectTypesIdentityWithNumericIndexers1.ts, 27, 10)) ->foo : Symbol(foo, Decl(objectTypesIdentityWithNumericIndexers1.ts, 27, 35)) function foo1(x: A); ->foo1 : Symbol(foo1, Decl(objectTypesIdentityWithNumericIndexers1.ts, 27, 46), Decl(objectTypesIdentityWithNumericIndexers1.ts, 29, 20), Decl(objectTypesIdentityWithNumericIndexers1.ts, 30, 20)) +>foo1 : Symbol(foo1, Decl(objectTypesIdentityWithNumericIndexers1.ts, 27, 44), Decl(objectTypesIdentityWithNumericIndexers1.ts, 29, 20), Decl(objectTypesIdentityWithNumericIndexers1.ts, 30, 20)) >x : Symbol(x, Decl(objectTypesIdentityWithNumericIndexers1.ts, 29, 14)) >A : Symbol(A, Decl(objectTypesIdentityWithNumericIndexers1.ts, 0, 0)) function foo1(x: A); // error ->foo1 : Symbol(foo1, Decl(objectTypesIdentityWithNumericIndexers1.ts, 27, 46), Decl(objectTypesIdentityWithNumericIndexers1.ts, 29, 20), Decl(objectTypesIdentityWithNumericIndexers1.ts, 30, 20)) +>foo1 : Symbol(foo1, Decl(objectTypesIdentityWithNumericIndexers1.ts, 27, 44), Decl(objectTypesIdentityWithNumericIndexers1.ts, 29, 20), Decl(objectTypesIdentityWithNumericIndexers1.ts, 30, 20)) >x : Symbol(x, Decl(objectTypesIdentityWithNumericIndexers1.ts, 30, 14)) >A : Symbol(A, Decl(objectTypesIdentityWithNumericIndexers1.ts, 0, 0)) function foo1(x: any) { } ->foo1 : Symbol(foo1, Decl(objectTypesIdentityWithNumericIndexers1.ts, 27, 46), Decl(objectTypesIdentityWithNumericIndexers1.ts, 29, 20), Decl(objectTypesIdentityWithNumericIndexers1.ts, 30, 20)) +>foo1 : Symbol(foo1, Decl(objectTypesIdentityWithNumericIndexers1.ts, 27, 44), Decl(objectTypesIdentityWithNumericIndexers1.ts, 29, 20), Decl(objectTypesIdentityWithNumericIndexers1.ts, 30, 20)) >x : Symbol(x, Decl(objectTypesIdentityWithNumericIndexers1.ts, 31, 14)) function foo1b(x: B); diff --git a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.types b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.types index c5de5c7b9b4..78c69f0cdd3 100644 --- a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.types +++ b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.types @@ -47,11 +47,10 @@ var a: { [x: number]: string; >x : number } -var b: { [x: number]: string; } = { foo: '' }; +var b: { [x: number]: string; } = { 0: '' }; >b : { [x: number]: string; } >x : number ->{ foo: '' } : { foo: string; } ->foo : string +>{ 0: '' } : { 0: string; } >'' : string function foo1(x: A); diff --git a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.js b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.js index 98c29e96a86..7ecb597a2d9 100644 --- a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.js +++ b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.js @@ -29,7 +29,7 @@ class PB extends B { var a: { [x: number]: Base; } -var b: { [x: number]: Derived; } = { foo: null }; +var b: { [x: number]: Derived; } = { 0: null }; function foo1(x: A); function foo1(x: A); // error @@ -174,7 +174,7 @@ var PB = (function (_super) { return PB; }(B)); var a; -var b = { foo: null }; +var b = { 0: null }; function foo1(x) { } function foo1b(x) { } function foo1c(x) { } diff --git a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.symbols b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.symbols index 5fde90941ef..b4ad1857748 100644 --- a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.symbols +++ b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.symbols @@ -60,25 +60,24 @@ var a: { >x : Symbol(x, Decl(objectTypesIdentityWithNumericIndexers2.ts, 28, 5)) >Base : Symbol(Base, Decl(objectTypesIdentityWithNumericIndexers2.ts, 0, 0)) } -var b: { [x: number]: Derived; } = { foo: null }; +var b: { [x: number]: Derived; } = { 0: null }; >b : Symbol(b, Decl(objectTypesIdentityWithNumericIndexers2.ts, 30, 3)) >x : Symbol(x, Decl(objectTypesIdentityWithNumericIndexers2.ts, 30, 10)) >Derived : Symbol(Derived, Decl(objectTypesIdentityWithNumericIndexers2.ts, 2, 27)) ->foo : Symbol(foo, Decl(objectTypesIdentityWithNumericIndexers2.ts, 30, 36)) >Derived : Symbol(Derived, Decl(objectTypesIdentityWithNumericIndexers2.ts, 2, 27)) function foo1(x: A); ->foo1 : Symbol(foo1, Decl(objectTypesIdentityWithNumericIndexers2.ts, 30, 58), Decl(objectTypesIdentityWithNumericIndexers2.ts, 32, 20), Decl(objectTypesIdentityWithNumericIndexers2.ts, 33, 20)) +>foo1 : Symbol(foo1, Decl(objectTypesIdentityWithNumericIndexers2.ts, 30, 56), Decl(objectTypesIdentityWithNumericIndexers2.ts, 32, 20), Decl(objectTypesIdentityWithNumericIndexers2.ts, 33, 20)) >x : Symbol(x, Decl(objectTypesIdentityWithNumericIndexers2.ts, 32, 14)) >A : Symbol(A, Decl(objectTypesIdentityWithNumericIndexers2.ts, 3, 43)) function foo1(x: A); // error ->foo1 : Symbol(foo1, Decl(objectTypesIdentityWithNumericIndexers2.ts, 30, 58), Decl(objectTypesIdentityWithNumericIndexers2.ts, 32, 20), Decl(objectTypesIdentityWithNumericIndexers2.ts, 33, 20)) +>foo1 : Symbol(foo1, Decl(objectTypesIdentityWithNumericIndexers2.ts, 30, 56), Decl(objectTypesIdentityWithNumericIndexers2.ts, 32, 20), Decl(objectTypesIdentityWithNumericIndexers2.ts, 33, 20)) >x : Symbol(x, Decl(objectTypesIdentityWithNumericIndexers2.ts, 33, 14)) >A : Symbol(A, Decl(objectTypesIdentityWithNumericIndexers2.ts, 3, 43)) function foo1(x: any) { } ->foo1 : Symbol(foo1, Decl(objectTypesIdentityWithNumericIndexers2.ts, 30, 58), Decl(objectTypesIdentityWithNumericIndexers2.ts, 32, 20), Decl(objectTypesIdentityWithNumericIndexers2.ts, 33, 20)) +>foo1 : Symbol(foo1, Decl(objectTypesIdentityWithNumericIndexers2.ts, 30, 56), Decl(objectTypesIdentityWithNumericIndexers2.ts, 32, 20), Decl(objectTypesIdentityWithNumericIndexers2.ts, 33, 20)) >x : Symbol(x, Decl(objectTypesIdentityWithNumericIndexers2.ts, 34, 14)) function foo1b(x: B); diff --git a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.types b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.types index 17fc6a07a00..ce38d95174b 100644 --- a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.types +++ b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.types @@ -60,12 +60,11 @@ var a: { >x : number >Base : Base } -var b: { [x: number]: Derived; } = { foo: null }; +var b: { [x: number]: Derived; } = { 0: null }; >b : { [x: number]: Derived; } >x : number >Derived : Derived ->{ foo: null } : { foo: Derived; } ->foo : Derived +>{ 0: null } : { 0: Derived; } >null : Derived >Derived : Derived >null : null diff --git a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.js b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.js index ea85b8b3c67..9710afe700d 100644 --- a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.js +++ b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.js @@ -26,7 +26,7 @@ class PB extends B { var a: { [x: string]: string; } -var b: { [x: number]: string; } = { foo: '' }; +var b: { [x: number]: string; } = { 0: '' }; function foo1(x: A); function foo1(x: A); // error @@ -159,7 +159,7 @@ var PB = (function (_super) { return PB; }(B)); var a; -var b = { foo: '' }; +var b = { 0: '' }; function foo1(x) { } function foo1b(x) { } function foo1c(x) { } diff --git a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.symbols b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.symbols index c0bc1b5cf60..ed95b3a7025 100644 --- a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.symbols +++ b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.symbols @@ -47,23 +47,22 @@ var a: { [x: string]: string; >x : Symbol(x, Decl(objectTypesIdentityWithNumericIndexers3.ts, 25, 5)) } -var b: { [x: number]: string; } = { foo: '' }; +var b: { [x: number]: string; } = { 0: '' }; >b : Symbol(b, Decl(objectTypesIdentityWithNumericIndexers3.ts, 27, 3)) >x : Symbol(x, Decl(objectTypesIdentityWithNumericIndexers3.ts, 27, 10)) ->foo : Symbol(foo, Decl(objectTypesIdentityWithNumericIndexers3.ts, 27, 35)) function foo1(x: A); ->foo1 : Symbol(foo1, Decl(objectTypesIdentityWithNumericIndexers3.ts, 27, 46), Decl(objectTypesIdentityWithNumericIndexers3.ts, 29, 20), Decl(objectTypesIdentityWithNumericIndexers3.ts, 30, 20)) +>foo1 : Symbol(foo1, Decl(objectTypesIdentityWithNumericIndexers3.ts, 27, 44), Decl(objectTypesIdentityWithNumericIndexers3.ts, 29, 20), Decl(objectTypesIdentityWithNumericIndexers3.ts, 30, 20)) >x : Symbol(x, Decl(objectTypesIdentityWithNumericIndexers3.ts, 29, 14)) >A : Symbol(A, Decl(objectTypesIdentityWithNumericIndexers3.ts, 0, 0)) function foo1(x: A); // error ->foo1 : Symbol(foo1, Decl(objectTypesIdentityWithNumericIndexers3.ts, 27, 46), Decl(objectTypesIdentityWithNumericIndexers3.ts, 29, 20), Decl(objectTypesIdentityWithNumericIndexers3.ts, 30, 20)) +>foo1 : Symbol(foo1, Decl(objectTypesIdentityWithNumericIndexers3.ts, 27, 44), Decl(objectTypesIdentityWithNumericIndexers3.ts, 29, 20), Decl(objectTypesIdentityWithNumericIndexers3.ts, 30, 20)) >x : Symbol(x, Decl(objectTypesIdentityWithNumericIndexers3.ts, 30, 14)) >A : Symbol(A, Decl(objectTypesIdentityWithNumericIndexers3.ts, 0, 0)) function foo1(x: any) { } ->foo1 : Symbol(foo1, Decl(objectTypesIdentityWithNumericIndexers3.ts, 27, 46), Decl(objectTypesIdentityWithNumericIndexers3.ts, 29, 20), Decl(objectTypesIdentityWithNumericIndexers3.ts, 30, 20)) +>foo1 : Symbol(foo1, Decl(objectTypesIdentityWithNumericIndexers3.ts, 27, 44), Decl(objectTypesIdentityWithNumericIndexers3.ts, 29, 20), Decl(objectTypesIdentityWithNumericIndexers3.ts, 30, 20)) >x : Symbol(x, Decl(objectTypesIdentityWithNumericIndexers3.ts, 31, 14)) function foo1b(x: B); diff --git a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.types b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.types index 99e6b8c8632..a6ea5a292e5 100644 --- a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.types +++ b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.types @@ -47,11 +47,10 @@ var a: { [x: string]: string; >x : string } -var b: { [x: number]: string; } = { foo: '' }; +var b: { [x: number]: string; } = { 0: '' }; >b : { [x: number]: string; } >x : number ->{ foo: '' } : { foo: string; } ->foo : string +>{ 0: '' } : { 0: string; } >'' : string function foo1(x: A); diff --git a/tests/baselines/reference/propertyAccess.errors.txt b/tests/baselines/reference/propertyAccess.errors.txt index 7d496f87751..b3244956174 100644 --- a/tests/baselines/reference/propertyAccess.errors.txt +++ b/tests/baselines/reference/propertyAccess.errors.txt @@ -1,10 +1,12 @@ +tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(11,55): error TS2322: Type '{ 3: string; 'three': string; }' is not assignable to type '{ [n: number]: string; }'. + Object literal may only specify known properties, and ''three'' does not exist in type '{ [n: number]: string; }'. tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(45,14): error TS2339: Property 'qqq' does not exist on type '{ 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }'. tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(80,10): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(117,10): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(140,12): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. -==== tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts (4 errors) ==== +==== tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts (5 errors) ==== class A { a: number; } @@ -16,6 +18,9 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(140,12): er } var numIndex: { [n: number]: string } = { 3: 'three', 'three': 'three' }; + ~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ 3: string; 'three': string; }' is not assignable to type '{ [n: number]: string; }'. +!!! error TS2322: Object literal may only specify known properties, and ''three'' does not exist in type '{ [n: number]: string; }'. var strIndex: { [n: string]: Compass } = { 'N': Compass.North, 'E': Compass.East }; var bothIndex: { diff --git a/tests/cases/compiler/indexSignaturesInferentialTyping.ts b/tests/cases/compiler/indexSignaturesInferentialTyping.ts index e40f32a799b..b47293a77e5 100644 --- a/tests/cases/compiler/indexSignaturesInferentialTyping.ts +++ b/tests/cases/compiler/indexSignaturesInferentialTyping.ts @@ -2,6 +2,5 @@ function foo(items: { [index: number]: T }): T { return undefined; } function bar(items: { [index: string]: T }): T { return undefined; } var x1 = foo({ 0: 0, 1: 1 }); // type should be number -var x2 = foo({ zero: 0, one: 1 }); -var x3 = bar({ 0: 0, 1: 1 }); -var x4 = bar({ zero: 0, one: 1 }); // type should be number +var x2 = bar({ 0: 0, 1: 1 }); +var x3 = bar({ zero: 0, one: 1 }); // type should be number diff --git a/tests/cases/compiler/numericIndexerConstraint4.ts b/tests/cases/compiler/numericIndexerConstraint4.ts index abdfac0fc9c..7e890168558 100644 --- a/tests/cases/compiler/numericIndexerConstraint4.ts +++ b/tests/cases/compiler/numericIndexerConstraint4.ts @@ -8,4 +8,4 @@ class B extends A { var x: { [idx: number]: A; -} = { data: new B() } \ No newline at end of file +} = { 0: new B() } diff --git a/tests/cases/compiler/objectLitIndexerContextualType.ts b/tests/cases/compiler/objectLitIndexerContextualType.ts index 2b07d995183..b687e226cfc 100644 --- a/tests/cases/compiler/objectLitIndexerContextualType.ts +++ b/tests/cases/compiler/objectLitIndexerContextualType.ts @@ -15,8 +15,8 @@ x = { 0: t => t * t, // Should error }; y = { - s: t => t * t, // Should not error + s: t => t * t, // Should error }; y = { 0: t => t * t, // Should error -}; \ No newline at end of file +}; diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7_ES5.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7_ES5.ts index 722891c2f6a..4f124ece6d2 100644 --- a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7_ES5.ts +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7_ES5.ts @@ -6,9 +6,9 @@ interface I { declare function foo(obj: I): T foo({ - p: "", + 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0] -}); \ No newline at end of file +}); diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7_ES6.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7_ES6.ts index 1ddb966488d..2a7a476ca7a 100644 --- a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7_ES6.ts +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7_ES6.ts @@ -6,9 +6,9 @@ interface I { declare function foo(obj: I): T foo({ - p: "", + 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0] -}); \ No newline at end of file +}); diff --git a/tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers1.ts b/tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers1.ts index 7092fab6c31..867199d9051 100644 --- a/tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers1.ts +++ b/tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers1.ts @@ -25,7 +25,7 @@ class PB extends B { var a: { [x: number]: string; } -var b: { [x: number]: string; } = { foo: '' }; +var b: { [x: number]: string; } = { 0: '' }; function foo1(x: A); function foo1(x: A); // error diff --git a/tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers2.ts b/tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers2.ts index b5c0f4c1615..ea9d7d04ee2 100644 --- a/tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers2.ts +++ b/tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers2.ts @@ -28,7 +28,7 @@ class PB extends B { var a: { [x: number]: Base; } -var b: { [x: number]: Derived; } = { foo: null }; +var b: { [x: number]: Derived; } = { 0: null }; function foo1(x: A); function foo1(x: A); // error diff --git a/tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers3.ts b/tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers3.ts index ae64acedcec..d3f22604c44 100644 --- a/tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers3.ts +++ b/tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithNumericIndexers3.ts @@ -25,7 +25,7 @@ class PB extends B { var a: { [x: string]: string; } -var b: { [x: number]: string; } = { foo: '' }; +var b: { [x: number]: string; } = { 0: '' }; function foo1(x: A); function foo1(x: A); // error From 58c8d345bc56b53a63f6b5f516484153fbbac5fe Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 25 May 2016 12:17:57 -0700 Subject: [PATCH 22/61] Update LKG --- lib/lib.d.ts | 24 +- lib/lib.es5.d.ts | 24 +- lib/lib.es6.d.ts | 24 +- lib/tsc.js | 365 ++++++++++++++++------- lib/tsserver.js | 431 ++++++++++++++++++--------- lib/tsserverlibrary.d.ts | 48 +++- lib/tsserverlibrary.js | 431 ++++++++++++++++++--------- lib/typescript.d.ts | 40 ++- lib/typescript.js | 560 ++++++++++++++++++++++++------------ lib/typescriptServices.d.ts | 40 ++- lib/typescriptServices.js | 560 ++++++++++++++++++++++++------------ 11 files changed, 1726 insertions(+), 821 deletions(-) diff --git a/lib/lib.d.ts b/lib/lib.d.ts index 6bded7a1135..15745c5d533 100644 --- a/lib/lib.d.ts +++ b/lib/lib.d.ts @@ -965,38 +965,22 @@ interface JSON { * If a member contains nested objects, the nested objects are transformed before the parent object is. */ parse(text: string, reviver?: (key: any, value: any) => any): any; - /** - * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. - * @param value A JavaScript value, usually an object or array, to be converted. - */ - stringify(value: any): string; - /** - * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. - * @param value A JavaScript value, usually an object or array, to be converted. - * @param replacer A function that transforms the results. - */ - stringify(value: any, replacer: (key: string, value: any) => any): string; - /** - * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. - * @param value A JavaScript value, usually an object or array, to be converted. - * @param replacer Array that transforms the results. - */ - stringify(value: any, replacer: any[]): string; /** * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. * @param value A JavaScript value, usually an object or array, to be converted. * @param replacer A function that transforms the results. * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. */ - stringify(value: any, replacer: (key: string, value: any) => any, space: string | number): string; + stringify(value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; /** * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. * @param value A JavaScript value, usually an object or array, to be converted. - * @param replacer Array that transforms the results. + * @param replacer An array of strings and numbers that acts as a white list for selecting the object properties that will be stringified. * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. */ - stringify(value: any, replacer: any[], space: string | number): string; + stringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string; } + /** * An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format. */ diff --git a/lib/lib.es5.d.ts b/lib/lib.es5.d.ts index 3a0f73f3cc7..e4e0334e0cb 100644 --- a/lib/lib.es5.d.ts +++ b/lib/lib.es5.d.ts @@ -965,38 +965,22 @@ interface JSON { * If a member contains nested objects, the nested objects are transformed before the parent object is. */ parse(text: string, reviver?: (key: any, value: any) => any): any; - /** - * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. - * @param value A JavaScript value, usually an object or array, to be converted. - */ - stringify(value: any): string; - /** - * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. - * @param value A JavaScript value, usually an object or array, to be converted. - * @param replacer A function that transforms the results. - */ - stringify(value: any, replacer: (key: string, value: any) => any): string; - /** - * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. - * @param value A JavaScript value, usually an object or array, to be converted. - * @param replacer Array that transforms the results. - */ - stringify(value: any, replacer: any[]): string; /** * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. * @param value A JavaScript value, usually an object or array, to be converted. * @param replacer A function that transforms the results. * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. */ - stringify(value: any, replacer: (key: string, value: any) => any, space: string | number): string; + stringify(value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; /** * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. * @param value A JavaScript value, usually an object or array, to be converted. - * @param replacer Array that transforms the results. + * @param replacer An array of strings and numbers that acts as a white list for selecting the object properties that will be stringified. * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. */ - stringify(value: any, replacer: any[], space: string | number): string; + stringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string; } + /** * An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format. */ diff --git a/lib/lib.es6.d.ts b/lib/lib.es6.d.ts index 6ed743d739a..ae54e8e8570 100644 --- a/lib/lib.es6.d.ts +++ b/lib/lib.es6.d.ts @@ -965,38 +965,22 @@ interface JSON { * If a member contains nested objects, the nested objects are transformed before the parent object is. */ parse(text: string, reviver?: (key: any, value: any) => any): any; - /** - * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. - * @param value A JavaScript value, usually an object or array, to be converted. - */ - stringify(value: any): string; - /** - * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. - * @param value A JavaScript value, usually an object or array, to be converted. - * @param replacer A function that transforms the results. - */ - stringify(value: any, replacer: (key: string, value: any) => any): string; - /** - * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. - * @param value A JavaScript value, usually an object or array, to be converted. - * @param replacer Array that transforms the results. - */ - stringify(value: any, replacer: any[]): string; /** * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. * @param value A JavaScript value, usually an object or array, to be converted. * @param replacer A function that transforms the results. * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. */ - stringify(value: any, replacer: (key: string, value: any) => any, space: string | number): string; + stringify(value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; /** * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. * @param value A JavaScript value, usually an object or array, to be converted. - * @param replacer Array that transforms the results. + * @param replacer An array of strings and numbers that acts as a white list for selecting the object properties that will be stringified. * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. */ - stringify(value: any, replacer: any[], space: string | number): string; + stringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string; } + /** * An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format. */ diff --git a/lib/tsc.js b/lib/tsc.js index 8dba7a921dc..00c758c0446 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -913,6 +913,10 @@ var ts; } return result.sort(); } + function getDirectories(path) { + var folder = fso.GetFolder(path); + return getNames(folder.subfolders); + } function readDirectory(path, extension, exclude) { var result = []; exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); @@ -967,6 +971,7 @@ var ts; getCurrentDirectory: function () { return new ActiveXObject("WScript.Shell").CurrentDirectory; }, + getDirectories: getDirectories, readDirectory: readDirectory, exit: function (exitCode) { try { @@ -1114,6 +1119,9 @@ var ts; function directoryExists(path) { return fileSystemEntryExists(path, 1); } + function getDirectories(path) { + return ts.filter(_fs.readdirSync(path), function (p) { return fileSystemEntryExists(ts.combinePaths(path, p), 1); }); + } function readDirectory(path, extension, exclude) { var result = []; exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); @@ -1206,6 +1214,7 @@ var ts; getCurrentDirectory: function () { return process.cwd(); }, + getDirectories: getDirectories, readDirectory: readDirectory, getModifiedTime: function (path) { try { @@ -1256,6 +1265,7 @@ var ts; createDirectory: ChakraHost.createDirectory, getExecutingFilePath: function () { return ChakraHost.executingFile; }, getCurrentDirectory: function () { return ChakraHost.currentDirectory; }, + getDirectories: ChakraHost.getDirectories, readDirectory: ChakraHost.readDirectory, exit: ChakraHost.quit, realpath: realpath @@ -1389,7 +1399,7 @@ var ts; or_expected: { code: 1144, category: ts.DiagnosticCategory.Error, key: "or_expected_1144", message: "'{' or ';' expected." }, Declaration_expected: { code: 1146, category: ts.DiagnosticCategory.Error, key: "Declaration_expected_1146", message: "Declaration expected." }, Import_declarations_in_a_namespace_cannot_reference_a_module: { code: 1147, category: ts.DiagnosticCategory.Error, key: "Import_declarations_in_a_namespace_cannot_reference_a_module_1147", message: "Import declarations in a namespace cannot reference a module." }, - Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting__1148", message: "Cannot compile modules unless the '--module' flag is provided with a valid module type. Consider setting the 'module' compiler option in a 'tsconfig.json' file." }, + Cannot_use_imports_exports_or_module_augmentations_when_module_is_none: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot_use_imports_exports_or_module_augmentations_when_module_is_none_1148", message: "Cannot use imports, exports, or module augmentations when '--module' is 'none'." }, File_name_0_differs_from_already_included_file_name_1_only_in_casing: { code: 1149, category: ts.DiagnosticCategory.Error, key: "File_name_0_differs_from_already_included_file_name_1_only_in_casing_1149", message: "File name '{0}' differs from already included file name '{1}' only in casing" }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: ts.DiagnosticCategory.Error, key: "new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead_1150", message: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, const_declarations_must_be_initialized: { code: 1155, category: ts.DiagnosticCategory.Error, key: "const_declarations_must_be_initialized_1155", message: "'const' declarations must be initialized" }, @@ -1759,6 +1769,8 @@ var ts; this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation: { code: 2683, category: ts.DiagnosticCategory.Error, key: "this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_2683", message: "'this' implicitly has type 'any' because it does not have a type annotation." }, The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1: { code: 2684, category: ts.DiagnosticCategory.Error, key: "The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1_2684", message: "The 'this' context of type '{0}' is not assignable to method's 'this' of type '{1}'." }, The_this_types_of_each_signature_are_incompatible: { code: 2685, category: ts.DiagnosticCategory.Error, key: "The_this_types_of_each_signature_are_incompatible_2685", message: "The 'this' types of each signature are incompatible." }, + Identifier_0_must_be_imported_from_a_module: { code: 2686, category: ts.DiagnosticCategory.Error, key: "Identifier_0_must_be_imported_from_a_module_2686", message: "Identifier '{0}' must be imported from a module" }, + All_declarations_of_0_must_have_identical_modifiers: { code: 2687, category: ts.DiagnosticCategory.Error, key: "All_declarations_of_0_must_have_identical_modifiers_2687", message: "All declarations of '{0}' must have identical modifiers." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import_declaration_0_is_using_private_name_1_4000", message: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: ts.DiagnosticCategory.Error, key: "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", message: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: ts.DiagnosticCategory.Error, key: "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", message: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -1852,7 +1864,7 @@ var ts; Option_paths_cannot_be_used_without_specifying_baseUrl_option: { code: 5060, category: ts.DiagnosticCategory.Error, key: "Option_paths_cannot_be_used_without_specifying_baseUrl_option_5060", message: "Option 'paths' cannot be used without specifying '--baseUrl' option." }, Pattern_0_can_have_at_most_one_Asterisk_character: { code: 5061, category: ts.DiagnosticCategory.Error, key: "Pattern_0_can_have_at_most_one_Asterisk_character_5061", message: "Pattern '{0}' can have at most one '*' character" }, Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character: { code: 5062, category: ts.DiagnosticCategory.Error, key: "Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character_5062", message: "Substitution '{0}' in pattern '{1}' in can have at most one '*' character" }, - Substututions_for_pattern_0_should_be_an_array: { code: 5063, category: ts.DiagnosticCategory.Error, key: "Substututions_for_pattern_0_should_be_an_array_5063", message: "Substututions for pattern '{0}' should be an array." }, + Substitutions_for_pattern_0_should_be_an_array: { code: 5063, category: ts.DiagnosticCategory.Error, key: "Substitutions_for_pattern_0_should_be_an_array_5063", message: "Substitutions for pattern '{0}' should be an array." }, Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2: { code: 5064, category: ts.DiagnosticCategory.Error, key: "Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2_5064", message: "Substitution '{0}' for pattern '{1}' has incorrect type, expected 'string', got '{2}'." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: ts.DiagnosticCategory.Message, key: "Concatenate_and_emit_output_to_single_file_6001", message: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: ts.DiagnosticCategory.Message, key: "Generates_corresponding_d_ts_file_6002", message: "Generates corresponding '.d.ts' file." }, @@ -1865,6 +1877,7 @@ var ts; Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do_not_emit_comments_to_output_6009", message: "Do not emit comments to output." }, Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do_not_emit_outputs_6010", message: "Do not emit outputs." }, Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking: { code: 6011, category: ts.DiagnosticCategory.Message, key: "Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typech_6011", message: "Allow default imports from modules with no default export. This does not affect code emit, just typechecking." }, + Skip_type_checking_of_declaration_files: { code: 6012, category: ts.DiagnosticCategory.Message, key: "Skip_type_checking_of_declaration_files_6012", message: "Skip type checking of declaration files." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015_6015", message: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015'" }, Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015: { code: 6016, category: ts.DiagnosticCategory.Message, key: "Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015_6016", message: "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'" }, Print_this_message: { code: 6017, category: ts.DiagnosticCategory.Message, key: "Print_this_message_6017", message: "Print this message." }, @@ -1966,6 +1979,7 @@ var ts; Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set: { code: 6128, category: ts.DiagnosticCategory.Message, key: "Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set_6128", message: "======== Resolving type reference directive '{0}', containing file not set, root directory not set. ========" }, The_config_file_0_found_doesn_t_contain_any_source_files: { code: 6129, category: ts.DiagnosticCategory.Error, key: "The_config_file_0_found_doesn_t_contain_any_source_files_6129", message: "The config file '{0}' found doesn't contain any source files." }, Resolving_real_path_for_0_result_1: { code: 6130, category: ts.DiagnosticCategory.Message, key: "Resolving_real_path_for_0_result_1_6130", message: "Resolving real path for '{0}', result '{1}'" }, + Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { code: 6131, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system_6131", message: "Cannot compile modules using option '{0}' unless the '--module' flag is 'amd' or 'system'." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable_0_implicitly_has_an_1_type_7005", message: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter_0_implicitly_has_an_1_type_7006", message: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member_0_implicitly_has_an_1_type_7008", message: "Member '{0}' implicitly has an '{1}' type." }, @@ -5004,7 +5018,7 @@ var ts; } ts.isWellKnownSymbolSyntactically = isWellKnownSymbolSyntactically; function getPropertyNameForPropertyNameNode(name) { - if (name.kind === 69 || name.kind === 9 || name.kind === 8) { + if (name.kind === 69 || name.kind === 9 || name.kind === 8 || name.kind === 142) { return name.text; } if (name.kind === 140) { @@ -12050,10 +12064,10 @@ var ts; case 145: case 144: case 266: - return bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 107455); + return bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 0); case 253: case 254: - return bindPropertyOrMethodOrAccessor(node, 4, 107455); + return bindPropertyOrMethodOrAccessor(node, 4, 0); case 255: return bindPropertyOrMethodOrAccessor(node, 8, 107455); case 247: @@ -12065,7 +12079,7 @@ var ts; return declareSymbolAndAddToSymbolTable(node, 131072, 0); case 147: case 146: - return bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 107455 : 99263); + return bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 0 : 99263); case 220: return bindFunctionDeclaration(node); case 148: @@ -12108,7 +12122,7 @@ var ts; case 238: return declareSymbolAndAddToSymbolTable(node, 8388608, 8388608); case 228: - return bindGlobalModuleExportDeclaration(node); + return bindNamespaceExportDeclaration(node); case 231: return bindImportClause(node); case 236: @@ -12144,13 +12158,13 @@ var ts; bindAnonymousDeclaration(node, 8388608, getDeclarationName(node)); } else if (boundExpression.kind === 69 && node.kind === 235) { - declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 107455 | 8388608); + declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 0 | 8388608); } else { - declareSymbol(container.symbol.exports, container.symbol, node, 4, 107455 | 8388608); + declareSymbol(container.symbol.exports, container.symbol, node, 4, 0 | 8388608); } } - function bindGlobalModuleExportDeclaration(node) { + function bindNamespaceExportDeclaration(node) { if (node.modifiers && node.modifiers.length) { file.bindDiagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.Modifiers_cannot_appear_here)); } @@ -12202,7 +12216,7 @@ var ts; function bindThisPropertyAssignment(node) { if (container.kind === 179 || container.kind === 220) { container.symbol.members = container.symbol.members || {}; - declareSymbol(container.symbol.members, container.symbol, node, 4, 107455 & ~4); + declareSymbol(container.symbol.members, container.symbol, node, 4, 0 & ~4); } } function bindPrototypePropertyAssignment(node) { @@ -12219,7 +12233,7 @@ var ts; if (!funcSymbol.members) { funcSymbol.members = {}; } - declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, 4, 107455); + declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, 4, 0); } function bindCallExpression(node) { if (!file.commonJsModuleIndicator && ts.isRequireCall(node, false)) { @@ -12295,7 +12309,7 @@ var ts; } if (ts.isParameterPropertyDeclaration(node)) { var classDeclaration = node.parent.parent; - declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 107455); + declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 0); } } function bindFunctionDeclaration(node) { @@ -12595,7 +12609,7 @@ var ts; if (flags & 1) result |= 107454; if (flags & 4) - result |= 107455; + result |= 0; if (flags & 8) result |= 107455; if (flags & 16) @@ -12851,6 +12865,7 @@ var ts; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; + var isInExternalModule = false; loop: while (location) { if (location.locals && !isGlobalSourceFile(location)) { if (result = getSymbol(location.locals, name, meaning)) { @@ -12882,6 +12897,7 @@ var ts; case 256: if (!ts.isExternalOrCommonJsModule(location)) break; + isInExternalModule = true; case 225: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 256 || ts.isAmbientModule(location)) { @@ -13005,6 +13021,12 @@ var ts; checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation); } } + if (result && isInExternalModule) { + var decls = result.declarations; + if (decls && decls.length === 1 && decls[0].kind === 228) { + error(errorLocation, ts.Diagnostics.Identifier_0_must_be_imported_from_a_module, name); + } + } } return result; } @@ -14480,7 +14502,7 @@ var ts; } function getTypeForBindingElementParent(node) { var symbol = getSymbolOfNode(node); - return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node); + return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, false); } function getTextOfPropertyName(name) { switch (name.kind) { @@ -14585,7 +14607,7 @@ var ts; function addOptionality(type, optional) { return strictNullChecks && optional ? addNullableKind(type, 32) : type; } - function getTypeForVariableLikeDeclaration(declaration) { + function getTypeForVariableLikeDeclaration(declaration, includeOptionality) { if (declaration.flags & 134217728) { var type = getTypeForVariableLikeDeclarationFromJSDocComment(declaration); if (type && type !== unknownType) { @@ -14602,7 +14624,7 @@ var ts; return getTypeForBindingElement(declaration); } if (declaration.type) { - return addOptionality(getTypeFromTypeNode(declaration.type), !!declaration.questionToken); + return addOptionality(getTypeFromTypeNode(declaration.type), declaration.questionToken && includeOptionality); } if (declaration.kind === 142) { var func = declaration.parent; @@ -14621,11 +14643,11 @@ var ts; ? getContextuallyTypedThisType(func) : getContextuallyTypedParameterType(declaration); if (type) { - return addOptionality(type, !!declaration.questionToken); + return addOptionality(type, declaration.questionToken && includeOptionality); } } if (declaration.initializer) { - return addOptionality(checkExpressionCached(declaration.initializer), !!declaration.questionToken); + return addOptionality(checkExpressionCached(declaration.initializer), declaration.questionToken && includeOptionality); } if (declaration.kind === 254) { return checkIdentifier(declaration.name); @@ -14693,7 +14715,7 @@ var ts; : getTypeFromArrayBindingPattern(pattern, includePatternInType); } function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) { - var type = getTypeForVariableLikeDeclaration(declaration); + var type = getTypeForVariableLikeDeclaration(declaration, true); if (type) { if (reportErrors) { reportErrorsFromWidening(declaration, type); @@ -17010,7 +17032,7 @@ var ts; return isIdenticalTo(source, target); } if (!(target.flags & 134217728)) { - if (target.flags & 1) + if (target.flags & 1 || source.flags & 134217728) return -1; if (source.flags & 32) { if (!strictNullChecks || target.flags & (32 | 16) || source === emptyArrayElementType) @@ -17030,7 +17052,7 @@ var ts; if (source.flags & 256 && target === stringType) return -1; if (relation === assignableRelation || relation === comparableRelation) { - if (source.flags & (1 | 134217728)) + if (source.flags & 1) return -1; if (source === numberType && target.flags & 128) return -1; @@ -17807,41 +17829,47 @@ var ts; getSignaturesOfType(type, 0).length === 0 && getSignaturesOfType(type, 1).length === 0; } + function createTransientSymbol(source, type) { + var symbol = createSymbol(source.flags | 67108864, source.name); + symbol.declarations = source.declarations; + symbol.parent = source.parent; + symbol.type = type; + symbol.target = source; + if (source.valueDeclaration) { + symbol.valueDeclaration = source.valueDeclaration; + } + return symbol; + } + function transformTypeOfMembers(type, f) { + var members = {}; + for (var _i = 0, _a = getPropertiesOfObjectType(type); _i < _a.length; _i++) { + var property = _a[_i]; + var original = getTypeOfSymbol(property); + var updated = f(original); + members[property.name] = updated === original ? property : createTransientSymbol(property, updated); + } + ; + return members; + } function getRegularTypeOfObjectLiteral(type) { - if (type.flags & 1048576) { - var regularType = type.regularType; - if (!regularType) { - regularType = createType(type.flags & ~1048576); - regularType.symbol = type.symbol; - regularType.members = type.members; - regularType.properties = type.properties; - regularType.callSignatures = type.callSignatures; - regularType.constructSignatures = type.constructSignatures; - regularType.stringIndexInfo = type.stringIndexInfo; - regularType.numberIndexInfo = type.numberIndexInfo; - type.regularType = regularType; - } + if (!(type.flags & 1048576)) { + return type; + } + var regularType = type.regularType; + if (regularType) { return regularType; } - return type; + var resolved = type; + var members = transformTypeOfMembers(type, getRegularTypeOfObjectLiteral); + var regularNew = createAnonymousType(resolved.symbol, members, resolved.callSignatures, resolved.constructSignatures, resolved.stringIndexInfo, resolved.numberIndexInfo); + regularNew.flags = resolved.flags & ~1048576; + type.regularType = regularNew; + return regularNew; } function getWidenedTypeOfObjectLiteral(type) { - var properties = getPropertiesOfObjectType(type); - var members = {}; - ts.forEach(properties, function (p) { - var propType = getTypeOfSymbol(p); - var widenedType = getWidenedType(propType); - if (propType !== widenedType) { - var symbol = createSymbol(p.flags | 67108864, p.name); - symbol.declarations = p.declarations; - symbol.parent = p.parent; - symbol.type = widenedType; - symbol.target = p; - if (p.valueDeclaration) - symbol.valueDeclaration = p.valueDeclaration; - p = symbol; - } - members[p.name] = p; + var members = transformTypeOfMembers(type, function (prop) { + var widened = getWidenedType(prop); + return prop === widened ? prop : widened; }); var stringIndexInfo = getIndexInfoOfType(type, 0); var numberIndexInfo = getIndexInfoOfType(type, 1); @@ -19134,7 +19162,7 @@ var ts; } return nodeCheckFlag === 512 ? getBaseConstructorTypeOfClass(classType) - : baseClassType; + : getTypeWithThisArgument(baseClassType, classType.thisType); function isLegalUsageOfSuperExpression(container) { if (!container) { return false; @@ -21182,7 +21210,7 @@ var ts; var types = void 0; var funcIsGenerator = !!func.asteriskToken; if (funcIsGenerator) { - types = checkAndAggregateYieldOperandTypes(func.body, contextualMapper); + types = checkAndAggregateYieldOperandTypes(func, contextualMapper); if (types.length === 0) { var iterableIteratorAny = createIterableIteratorType(anyType); if (compilerOptions.noImplicitAny) { @@ -21192,8 +21220,7 @@ var ts; } } else { - var hasImplicitReturn = !!(func.flags & 32768); - types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper, isAsync, hasImplicitReturn); + types = checkAndAggregateReturnExpressionTypes(func, contextualMapper); if (!types) { return neverType; } @@ -21240,9 +21267,9 @@ var ts; return widenedType; } } - function checkAndAggregateYieldOperandTypes(body, contextualMapper) { + function checkAndAggregateYieldOperandTypes(func, contextualMapper) { var aggregatedTypes = []; - ts.forEachYieldExpression(body, function (yieldExpression) { + ts.forEachYieldExpression(func.body, function (yieldExpression) { var expr = yieldExpression.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); @@ -21256,28 +21283,34 @@ var ts; }); return aggregatedTypes; } - function checkAndAggregateReturnExpressionTypes(body, contextualMapper, isAsync, hasImplicitReturn) { + function checkAndAggregateReturnExpressionTypes(func, contextualMapper) { + var isAsync = ts.isAsyncFunctionLike(func); var aggregatedTypes = []; - var hasOmittedExpressions = false; - ts.forEachReturnStatement(body, function (returnStatement) { + var hasReturnWithNoExpression = !!(func.flags & 32768); + var hasReturnOfTypeNever = false; + ts.forEachReturnStatement(func.body, function (returnStatement) { var expr = returnStatement.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); if (isAsync) { - type = checkAwaitedType(type, body.parent, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); + type = checkAwaitedType(type, func, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); } - if (type !== neverType && !ts.contains(aggregatedTypes, type)) { + if (type === neverType) { + hasReturnOfTypeNever = true; + } + else if (!ts.contains(aggregatedTypes, type)) { aggregatedTypes.push(type); } } else { - hasOmittedExpressions = true; + hasReturnWithNoExpression = true; } }); - if (aggregatedTypes.length === 0 && !hasOmittedExpressions && !hasImplicitReturn) { + if (aggregatedTypes.length === 0 && !hasReturnWithNoExpression && (hasReturnOfTypeNever || + func.kind === 179 || func.kind === 180)) { return undefined; } - if (strictNullChecks && aggregatedTypes.length && (hasOmittedExpressions || hasImplicitReturn)) { + if (strictNullChecks && aggregatedTypes.length && hasReturnWithNoExpression) { if (!ts.contains(aggregatedTypes, undefinedType)) { aggregatedTypes.push(undefinedType); } @@ -21407,7 +21440,9 @@ var ts; (expr.kind === 172 || expr.kind === 173) && expr.expression.kind === 97) { var func = ts.getContainingFunction(expr); - return !(func && func.kind === 148 && func.parent === symbol.valueDeclaration.parent); + if (!(func && func.kind === 148)) + return true; + return !(func.parent === symbol.valueDeclaration.parent || func === symbol.valueDeclaration.parent); } return true; } @@ -22231,6 +22266,79 @@ var ts; } } } + function checkClassForDuplicateDeclarations(node) { + var getter = 1, setter = 2, property = getter | setter; + var instanceNames = {}; + var staticNames = {}; + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind === 148) { + for (var _b = 0, _c = member.parameters; _b < _c.length; _b++) { + var param = _c[_b]; + if (ts.isParameterPropertyDeclaration(param)) { + addName(instanceNames, param.name, param.name.text, property); + } + } + } + else { + var static = ts.forEach(member.modifiers, function (m) { return m.kind === 113; }); + var names = static ? staticNames : instanceNames; + var memberName = member.name && ts.getPropertyNameForPropertyNameNode(member.name); + if (memberName) { + switch (member.kind) { + case 149: + addName(names, member.name, memberName, getter); + break; + case 150: + addName(names, member.name, memberName, setter); + break; + case 145: + addName(names, member.name, memberName, property); + break; + } + } + } + } + function addName(names, location, name, meaning) { + if (ts.hasProperty(names, name)) { + var prev = names[name]; + if (prev & meaning) { + error(location, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(location)); + } + else { + names[name] = prev | meaning; + } + } + else { + names[name] = meaning; + } + } + } + function checkObjectTypeForDuplicateDeclarations(node) { + var names = {}; + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind == 144) { + var memberName = void 0; + switch (member.name.kind) { + case 9: + case 8: + case 69: + memberName = member.name.text; + break; + default: + continue; + } + if (ts.hasProperty(names, memberName)) { + error(member.symbol.valueDeclaration.name, ts.Diagnostics.Duplicate_identifier_0, memberName); + error(member.name, ts.Diagnostics.Duplicate_identifier_0, memberName); + } + else { + names[memberName] = true; + } + } + } + } function checkTypeForDuplicateIndexSignatures(node) { if (node.kind === 222) { var nodeSymbol = getSymbolOfNode(node); @@ -22449,6 +22557,7 @@ var ts; var type = getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); checkIndexConstraints(type); checkTypeForDuplicateIndexSignatures(node); + checkObjectTypeForDuplicateDeclarations(node); } } function checkArrayType(node) { @@ -23208,6 +23317,10 @@ var ts; if (node.initializer) { checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, undefined); } + if (!areDeclarationFlagsIdentical(node, symbol.valueDeclaration)) { + error(symbol.valueDeclaration.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); + error(node.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); + } } if (node.kind !== 145 && node.kind !== 144) { checkExportsOnMergedDeclarations(node); @@ -23220,6 +23333,18 @@ var ts; checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } } + function areDeclarationFlagsIdentical(left, right) { + if (ts.hasQuestionToken(left) !== ts.hasQuestionToken(right)) { + return false; + } + var interestingFlags = 8 | + 16 | + 256 | + 128 | + 64 | + 32; + return (left.flags & interestingFlags) === (right.flags & interestingFlags); + } function checkVariableDeclaration(node) { checkGrammarVariableDeclaration(node); return checkVariableLikeDeclaration(node); @@ -23770,6 +23895,7 @@ var ts; var typeWithThis = getTypeWithThisArgument(type); var staticType = getTypeOfSymbol(symbol); checkTypeParameterListsIdentical(node, symbol); + checkClassForDuplicateDeclarations(node); var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); if (baseTypeNode) { var baseTypes = getBaseTypes(type); @@ -23981,6 +24107,7 @@ var ts; checkIndexConstraints(type); } } + checkObjectTypeForDuplicateDeclarations(node); } ts.forEach(ts.getInterfaceBaseTypeNodes(node), function (heritageElement) { if (!ts.isSupportedExpressionWithTypeArguments(heritageElement)) { @@ -24735,10 +24862,8 @@ var ts; function checkSourceFileWorker(node) { var links = getNodeLinks(node); if (!(links.flags & 1)) { - if (compilerOptions.skipDefaultLibCheck) { - if (node.hasNoDefaultLib) { - return; - } + if (compilerOptions.skipLibCheck && node.isDeclarationFile || compilerOptions.skipDefaultLibCheck && node.hasNoDefaultLib) { + return; } checkGrammarSourceFile(node); potentialThisCollisions.length = 0; @@ -25107,7 +25232,7 @@ var ts; return symbol && getTypeOfSymbol(symbol); } if (ts.isBindingPattern(node)) { - return getTypeForVariableLikeDeclaration(node.parent); + return getTypeForVariableLikeDeclaration(node.parent, true); } if (isInRightSideOfImportOrExportAssignment(node)) { var symbol = getSymbolAtLocation(node); @@ -25546,7 +25671,7 @@ var ts; if (file.moduleAugmentations.length) { (augmentations || (augmentations = [])).push(file.moduleAugmentations); } - if (file.wasReferenced && file.symbol && file.symbol.globalExports) { + if (file.symbol && file.symbol.globalExports) { mergeSymbolTable(globals, file.symbol.globalExports); } }); @@ -26116,7 +26241,6 @@ var ts; if (prop.kind === 193 || name_20.kind === 140) { checkGrammarComputedPropertyName(name_20); - return "continue"; } if (prop.kind === 254 && !inDestructuring && prop.objectAssignmentInitializer) { return { value: grammarErrorOnNode(prop.equalsToken, ts.Diagnostics.can_only_be_used_in_an_object_literal_property_inside_a_destructuring_assignment) }; @@ -26146,17 +26270,21 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_20.text)) { - seen[name_20.text] = currentKind; + var effectiveName = ts.getPropertyNameForPropertyNameNode(name_20); + if (effectiveName === undefined) { + return "continue"; + } + if (!ts.hasProperty(seen, effectiveName)) { + seen[effectiveName] = currentKind; } else { - var existingKind = seen[name_20.text]; + var existingKind = seen[effectiveName]; if (currentKind === Property && existingKind === Property) { - return "continue"; + grammarErrorOnNode(name_20, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name_20)); } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_20.text] = currentKind | existingKind; + seen[effectiveName] = currentKind | existingKind; } else { return { value: grammarErrorOnNode(name_20, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name) }; @@ -34613,7 +34741,7 @@ var ts; skipTsx: true, traceEnabled: traceEnabled }; - var rootDir = options.typesRoot || (options.configFilePath ? ts.getDirectoryPath(options.configFilePath) : undefined); + var rootDir = options.typesRoot || (options.configFilePath ? ts.getDirectoryPath(options.configFilePath) : (host.getCurrentDirectory && host.getCurrentDirectory())); if (traceEnabled) { if (containingFile === undefined) { if (rootDir === undefined) { @@ -35116,12 +35244,25 @@ var ts; } } } + function getDefaultTypeDirectiveNames(rootPath) { + var localTypes = ts.combinePaths(rootPath, "types"); + var npmTypes = ts.combinePaths(rootPath, "node_modules/@types"); + var result = []; + if (ts.sys.directoryExists(localTypes)) { + result = result.concat(ts.sys.getDirectories(localTypes)); + } + if (ts.sys.directoryExists(npmTypes)) { + result = result.concat(ts.sys.getDirectories(npmTypes)); + } + return result; + } function getDefaultLibLocation() { return ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())); } var newLine = ts.getNewLineCharacter(options); var realpath = ts.sys.realpath && (function (path) { return ts.sys.realpath(path); }); return { + getDefaultTypeDirectiveNames: getDefaultTypeDirectiveNames, getSourceFile: getSourceFile, getDefaultLibLocation: getDefaultLibLocation, getDefaultLibFileName: function (options) { return ts.combinePaths(getDefaultLibLocation(), ts.getDefaultLibFileName(options)); }, @@ -35189,6 +35330,19 @@ var ts; } return resolutions; } + function getDefaultTypeDirectiveNames(options, rootFiles, host) { + if (options.types) { + return options.types; + } + if (host && host.getDefaultTypeDirectiveNames) { + var commonRoot = computeCommonSourceDirectoryOfFilenames(rootFiles, host.getCurrentDirectory(), function (f) { return host.getCanonicalFileName(f); }); + if (commonRoot) { + return host.getDefaultTypeDirectiveNames(commonRoot); + } + } + return undefined; + } + ts.getDefaultTypeDirectiveNames = getDefaultTypeDirectiveNames; function createProgram(rootNames, options, host, oldProgram) { var program; var files = []; @@ -35224,13 +35378,14 @@ var ts; var filesByName = ts.createFileMap(); var filesByNameIgnoreCase = host.useCaseSensitiveFileNames() ? ts.createFileMap(function (fileName) { return fileName.toLowerCase(); }) : undefined; if (!tryReuseStructureFromOldProgram()) { - if (options.types && options.types.length) { - var resolutions = resolveTypeReferenceDirectiveNamesWorker(options.types, undefined); - for (var i = 0; i < options.types.length; i++) { - processTypeReferenceDirective(options.types[i], resolutions[i]); + ts.forEach(rootNames, function (name) { return processRootFile(name, false); }); + var typeReferences = getDefaultTypeDirectiveNames(options, rootNames, host); + if (typeReferences) { + var resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, undefined); + for (var i = 0; i < typeReferences.length; i++) { + processTypeReferenceDirective(typeReferences[i], resolutions[i]); } } - ts.forEach(rootNames, function (name) { return processRootFile(name, false); }); if (!skipDefaultLib) { if (!options.lib) { processRootFile(host.getDefaultLibFileName(options), true); @@ -35807,9 +35962,6 @@ var ts; if (file_1 && options.forceConsistentCasingInFileNames && ts.getNormalizedAbsolutePath(file_1.fileName, currentDirectory) !== ts.getNormalizedAbsolutePath(fileName, currentDirectory)) { reportFileNamesDifferOnlyInCasingError(fileName, file_1.fileName, refFile, refPos, refEnd); } - if (file_1) { - file_1.wasReferenced = file_1.wasReferenced || isReference; - } return file_1; } var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { @@ -35822,7 +35974,6 @@ var ts; }); filesByName.set(path, file); if (file) { - file.wasReferenced = file.wasReferenced || isReference; file.path = path; if (host.useCaseSensitiveFileNames()) { var existingFile = filesByNameIgnoreCase.get(path); @@ -35923,17 +36074,7 @@ var ts; !options.noResolve && i < file.imports.length; if (shouldAddFile) { - var importedFile = findSourceFile(resolution.resolvedFileName, ts.toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), false, false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); - if (importedFile && resolution.isExternalLibraryImport) { - if (!ts.isExternalModule(importedFile) && importedFile.statements.length) { - var start_5 = ts.getTokenPosOfNode(file.imports[i], file); - fileProcessingDiagnostics.add(ts.createFileDiagnostic(file, start_5, file.imports[i].end - start_5, ts.Diagnostics.Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition, importedFile.fileName)); - } - else if (importedFile.referencedFiles.length) { - var firstRef = importedFile.referencedFiles[0]; - fileProcessingDiagnostics.add(ts.createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, ts.Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition)); - } - } + findSourceFile(resolution.resolvedFileName, ts.toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), false, false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); } } } @@ -36018,7 +36159,7 @@ var ts; } } else { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Substututions_for_pattern_0_should_be_an_array, key)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Substitutions_for_pattern_0_should_be_an_array, key)); } } } @@ -36067,13 +36208,19 @@ var ts; } else if (firstExternalModuleSourceFile && languageVersion < 2 && options.module === ts.ModuleKind.None) { var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file)); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none)); } if (options.module === ts.ModuleKind.ES6 && languageVersion < 2) { programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_es2015_when_targeting_ES5_or_lower)); } - if (outFile && options.module && !(options.module === ts.ModuleKind.AMD || options.module === ts.ModuleKind.System)) { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); + if (outFile) { + if (options.module && !(options.module === ts.ModuleKind.AMD || options.module === ts.ModuleKind.System)) { + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); + } + else if (options.module === undefined && firstExternalModuleSourceFile) { + var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system, options.out ? "out" : "outFile")); + } } if (options.outDir || options.sourceRoot || @@ -36156,6 +36303,11 @@ var ts; type: "boolean", description: ts.Diagnostics.Print_this_message }, + { + name: "help", + shortName: "?", + type: "boolean" + }, { name: "init", type: "boolean", @@ -36258,6 +36410,11 @@ var ts; name: "skipDefaultLibCheck", type: "boolean" }, + { + name: "skipLibCheck", + type: "boolean", + description: ts.Diagnostics.Skip_type_checking_of_declaration_files + }, { name: "out", type: "string", diff --git a/lib/tsserver.js b/lib/tsserver.js index ecb7bfb5509..7eb744a77d3 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -918,6 +918,10 @@ var ts; } return result.sort(); } + function getDirectories(path) { + var folder = fso.GetFolder(path); + return getNames(folder.subfolders); + } function readDirectory(path, extension, exclude) { var result = []; exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); @@ -972,6 +976,7 @@ var ts; getCurrentDirectory: function () { return new ActiveXObject("WScript.Shell").CurrentDirectory; }, + getDirectories: getDirectories, readDirectory: readDirectory, exit: function (exitCode) { try { @@ -1119,6 +1124,9 @@ var ts; function directoryExists(path) { return fileSystemEntryExists(path, 1); } + function getDirectories(path) { + return ts.filter(_fs.readdirSync(path), function (p) { return fileSystemEntryExists(ts.combinePaths(path, p), 1); }); + } function readDirectory(path, extension, exclude) { var result = []; exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); @@ -1211,6 +1219,7 @@ var ts; getCurrentDirectory: function () { return process.cwd(); }, + getDirectories: getDirectories, readDirectory: readDirectory, getModifiedTime: function (path) { try { @@ -1261,6 +1270,7 @@ var ts; createDirectory: ChakraHost.createDirectory, getExecutingFilePath: function () { return ChakraHost.executingFile; }, getCurrentDirectory: function () { return ChakraHost.currentDirectory; }, + getDirectories: ChakraHost.getDirectories, readDirectory: ChakraHost.readDirectory, exit: ChakraHost.quit, realpath: realpath @@ -1394,7 +1404,7 @@ var ts; or_expected: { code: 1144, category: ts.DiagnosticCategory.Error, key: "or_expected_1144", message: "'{' or ';' expected." }, Declaration_expected: { code: 1146, category: ts.DiagnosticCategory.Error, key: "Declaration_expected_1146", message: "Declaration expected." }, Import_declarations_in_a_namespace_cannot_reference_a_module: { code: 1147, category: ts.DiagnosticCategory.Error, key: "Import_declarations_in_a_namespace_cannot_reference_a_module_1147", message: "Import declarations in a namespace cannot reference a module." }, - Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting__1148", message: "Cannot compile modules unless the '--module' flag is provided with a valid module type. Consider setting the 'module' compiler option in a 'tsconfig.json' file." }, + Cannot_use_imports_exports_or_module_augmentations_when_module_is_none: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot_use_imports_exports_or_module_augmentations_when_module_is_none_1148", message: "Cannot use imports, exports, or module augmentations when '--module' is 'none'." }, File_name_0_differs_from_already_included_file_name_1_only_in_casing: { code: 1149, category: ts.DiagnosticCategory.Error, key: "File_name_0_differs_from_already_included_file_name_1_only_in_casing_1149", message: "File name '{0}' differs from already included file name '{1}' only in casing" }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: ts.DiagnosticCategory.Error, key: "new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead_1150", message: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, const_declarations_must_be_initialized: { code: 1155, category: ts.DiagnosticCategory.Error, key: "const_declarations_must_be_initialized_1155", message: "'const' declarations must be initialized" }, @@ -1764,6 +1774,8 @@ var ts; this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation: { code: 2683, category: ts.DiagnosticCategory.Error, key: "this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_2683", message: "'this' implicitly has type 'any' because it does not have a type annotation." }, The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1: { code: 2684, category: ts.DiagnosticCategory.Error, key: "The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1_2684", message: "The 'this' context of type '{0}' is not assignable to method's 'this' of type '{1}'." }, The_this_types_of_each_signature_are_incompatible: { code: 2685, category: ts.DiagnosticCategory.Error, key: "The_this_types_of_each_signature_are_incompatible_2685", message: "The 'this' types of each signature are incompatible." }, + Identifier_0_must_be_imported_from_a_module: { code: 2686, category: ts.DiagnosticCategory.Error, key: "Identifier_0_must_be_imported_from_a_module_2686", message: "Identifier '{0}' must be imported from a module" }, + All_declarations_of_0_must_have_identical_modifiers: { code: 2687, category: ts.DiagnosticCategory.Error, key: "All_declarations_of_0_must_have_identical_modifiers_2687", message: "All declarations of '{0}' must have identical modifiers." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import_declaration_0_is_using_private_name_1_4000", message: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: ts.DiagnosticCategory.Error, key: "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", message: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: ts.DiagnosticCategory.Error, key: "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", message: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -1857,7 +1869,7 @@ var ts; Option_paths_cannot_be_used_without_specifying_baseUrl_option: { code: 5060, category: ts.DiagnosticCategory.Error, key: "Option_paths_cannot_be_used_without_specifying_baseUrl_option_5060", message: "Option 'paths' cannot be used without specifying '--baseUrl' option." }, Pattern_0_can_have_at_most_one_Asterisk_character: { code: 5061, category: ts.DiagnosticCategory.Error, key: "Pattern_0_can_have_at_most_one_Asterisk_character_5061", message: "Pattern '{0}' can have at most one '*' character" }, Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character: { code: 5062, category: ts.DiagnosticCategory.Error, key: "Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character_5062", message: "Substitution '{0}' in pattern '{1}' in can have at most one '*' character" }, - Substututions_for_pattern_0_should_be_an_array: { code: 5063, category: ts.DiagnosticCategory.Error, key: "Substututions_for_pattern_0_should_be_an_array_5063", message: "Substututions for pattern '{0}' should be an array." }, + Substitutions_for_pattern_0_should_be_an_array: { code: 5063, category: ts.DiagnosticCategory.Error, key: "Substitutions_for_pattern_0_should_be_an_array_5063", message: "Substitutions for pattern '{0}' should be an array." }, Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2: { code: 5064, category: ts.DiagnosticCategory.Error, key: "Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2_5064", message: "Substitution '{0}' for pattern '{1}' has incorrect type, expected 'string', got '{2}'." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: ts.DiagnosticCategory.Message, key: "Concatenate_and_emit_output_to_single_file_6001", message: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: ts.DiagnosticCategory.Message, key: "Generates_corresponding_d_ts_file_6002", message: "Generates corresponding '.d.ts' file." }, @@ -1870,6 +1882,7 @@ var ts; Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do_not_emit_comments_to_output_6009", message: "Do not emit comments to output." }, Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do_not_emit_outputs_6010", message: "Do not emit outputs." }, Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking: { code: 6011, category: ts.DiagnosticCategory.Message, key: "Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typech_6011", message: "Allow default imports from modules with no default export. This does not affect code emit, just typechecking." }, + Skip_type_checking_of_declaration_files: { code: 6012, category: ts.DiagnosticCategory.Message, key: "Skip_type_checking_of_declaration_files_6012", message: "Skip type checking of declaration files." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015_6015", message: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015'" }, Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015: { code: 6016, category: ts.DiagnosticCategory.Message, key: "Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015_6016", message: "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'" }, Print_this_message: { code: 6017, category: ts.DiagnosticCategory.Message, key: "Print_this_message_6017", message: "Print this message." }, @@ -1971,6 +1984,7 @@ var ts; Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set: { code: 6128, category: ts.DiagnosticCategory.Message, key: "Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set_6128", message: "======== Resolving type reference directive '{0}', containing file not set, root directory not set. ========" }, The_config_file_0_found_doesn_t_contain_any_source_files: { code: 6129, category: ts.DiagnosticCategory.Error, key: "The_config_file_0_found_doesn_t_contain_any_source_files_6129", message: "The config file '{0}' found doesn't contain any source files." }, Resolving_real_path_for_0_result_1: { code: 6130, category: ts.DiagnosticCategory.Message, key: "Resolving_real_path_for_0_result_1_6130", message: "Resolving real path for '{0}', result '{1}'" }, + Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { code: 6131, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system_6131", message: "Cannot compile modules using option '{0}' unless the '--module' flag is 'amd' or 'system'." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable_0_implicitly_has_an_1_type_7005", message: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter_0_implicitly_has_an_1_type_7006", message: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member_0_implicitly_has_an_1_type_7008", message: "Member '{0}' implicitly has an '{1}' type." }, @@ -3537,6 +3551,11 @@ var ts; type: "boolean", description: ts.Diagnostics.Print_this_message }, + { + name: "help", + shortName: "?", + type: "boolean" + }, { name: "init", type: "boolean", @@ -3639,6 +3658,11 @@ var ts; name: "skipDefaultLibCheck", type: "boolean" }, + { + name: "skipLibCheck", + type: "boolean", + description: ts.Diagnostics.Skip_type_checking_of_declaration_files + }, { name: "out", type: "string", @@ -5758,7 +5782,7 @@ var ts; } ts.isWellKnownSymbolSyntactically = isWellKnownSymbolSyntactically; function getPropertyNameForPropertyNameNode(name) { - if (name.kind === 69 || name.kind === 9 || name.kind === 8) { + if (name.kind === 69 || name.kind === 9 || name.kind === 8 || name.kind === 142) { return name.text; } if (name.kind === 140) { @@ -12804,10 +12828,10 @@ var ts; case 145: case 144: case 266: - return bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 107455); + return bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 0); case 253: case 254: - return bindPropertyOrMethodOrAccessor(node, 4, 107455); + return bindPropertyOrMethodOrAccessor(node, 4, 0); case 255: return bindPropertyOrMethodOrAccessor(node, 8, 107455); case 247: @@ -12819,7 +12843,7 @@ var ts; return declareSymbolAndAddToSymbolTable(node, 131072, 0); case 147: case 146: - return bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 107455 : 99263); + return bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 0 : 99263); case 220: return bindFunctionDeclaration(node); case 148: @@ -12862,7 +12886,7 @@ var ts; case 238: return declareSymbolAndAddToSymbolTable(node, 8388608, 8388608); case 228: - return bindGlobalModuleExportDeclaration(node); + return bindNamespaceExportDeclaration(node); case 231: return bindImportClause(node); case 236: @@ -12898,13 +12922,13 @@ var ts; bindAnonymousDeclaration(node, 8388608, getDeclarationName(node)); } else if (boundExpression.kind === 69 && node.kind === 235) { - declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 107455 | 8388608); + declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 0 | 8388608); } else { - declareSymbol(container.symbol.exports, container.symbol, node, 4, 107455 | 8388608); + declareSymbol(container.symbol.exports, container.symbol, node, 4, 0 | 8388608); } } - function bindGlobalModuleExportDeclaration(node) { + function bindNamespaceExportDeclaration(node) { if (node.modifiers && node.modifiers.length) { file.bindDiagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.Modifiers_cannot_appear_here)); } @@ -12956,7 +12980,7 @@ var ts; function bindThisPropertyAssignment(node) { if (container.kind === 179 || container.kind === 220) { container.symbol.members = container.symbol.members || {}; - declareSymbol(container.symbol.members, container.symbol, node, 4, 107455 & ~4); + declareSymbol(container.symbol.members, container.symbol, node, 4, 0 & ~4); } } function bindPrototypePropertyAssignment(node) { @@ -12973,7 +12997,7 @@ var ts; if (!funcSymbol.members) { funcSymbol.members = {}; } - declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, 4, 107455); + declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, 4, 0); } function bindCallExpression(node) { if (!file.commonJsModuleIndicator && ts.isRequireCall(node, false)) { @@ -13049,7 +13073,7 @@ var ts; } if (ts.isParameterPropertyDeclaration(node)) { var classDeclaration = node.parent.parent; - declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 107455); + declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 0); } } function bindFunctionDeclaration(node) { @@ -13349,7 +13373,7 @@ var ts; if (flags & 1) result |= 107454; if (flags & 4) - result |= 107455; + result |= 0; if (flags & 8) result |= 107455; if (flags & 16) @@ -13605,6 +13629,7 @@ var ts; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; + var isInExternalModule = false; loop: while (location) { if (location.locals && !isGlobalSourceFile(location)) { if (result = getSymbol(location.locals, name, meaning)) { @@ -13636,6 +13661,7 @@ var ts; case 256: if (!ts.isExternalOrCommonJsModule(location)) break; + isInExternalModule = true; case 225: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 256 || ts.isAmbientModule(location)) { @@ -13759,6 +13785,12 @@ var ts; checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation); } } + if (result && isInExternalModule) { + var decls = result.declarations; + if (decls && decls.length === 1 && decls[0].kind === 228) { + error(errorLocation, ts.Diagnostics.Identifier_0_must_be_imported_from_a_module, name); + } + } } return result; } @@ -15234,7 +15266,7 @@ var ts; } function getTypeForBindingElementParent(node) { var symbol = getSymbolOfNode(node); - return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node); + return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, false); } function getTextOfPropertyName(name) { switch (name.kind) { @@ -15339,7 +15371,7 @@ var ts; function addOptionality(type, optional) { return strictNullChecks && optional ? addNullableKind(type, 32) : type; } - function getTypeForVariableLikeDeclaration(declaration) { + function getTypeForVariableLikeDeclaration(declaration, includeOptionality) { if (declaration.flags & 134217728) { var type = getTypeForVariableLikeDeclarationFromJSDocComment(declaration); if (type && type !== unknownType) { @@ -15356,7 +15388,7 @@ var ts; return getTypeForBindingElement(declaration); } if (declaration.type) { - return addOptionality(getTypeFromTypeNode(declaration.type), !!declaration.questionToken); + return addOptionality(getTypeFromTypeNode(declaration.type), declaration.questionToken && includeOptionality); } if (declaration.kind === 142) { var func = declaration.parent; @@ -15375,11 +15407,11 @@ var ts; ? getContextuallyTypedThisType(func) : getContextuallyTypedParameterType(declaration); if (type) { - return addOptionality(type, !!declaration.questionToken); + return addOptionality(type, declaration.questionToken && includeOptionality); } } if (declaration.initializer) { - return addOptionality(checkExpressionCached(declaration.initializer), !!declaration.questionToken); + return addOptionality(checkExpressionCached(declaration.initializer), declaration.questionToken && includeOptionality); } if (declaration.kind === 254) { return checkIdentifier(declaration.name); @@ -15447,7 +15479,7 @@ var ts; : getTypeFromArrayBindingPattern(pattern, includePatternInType); } function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) { - var type = getTypeForVariableLikeDeclaration(declaration); + var type = getTypeForVariableLikeDeclaration(declaration, true); if (type) { if (reportErrors) { reportErrorsFromWidening(declaration, type); @@ -17764,7 +17796,7 @@ var ts; return isIdenticalTo(source, target); } if (!(target.flags & 134217728)) { - if (target.flags & 1) + if (target.flags & 1 || source.flags & 134217728) return -1; if (source.flags & 32) { if (!strictNullChecks || target.flags & (32 | 16) || source === emptyArrayElementType) @@ -17784,7 +17816,7 @@ var ts; if (source.flags & 256 && target === stringType) return -1; if (relation === assignableRelation || relation === comparableRelation) { - if (source.flags & (1 | 134217728)) + if (source.flags & 1) return -1; if (source === numberType && target.flags & 128) return -1; @@ -18561,41 +18593,47 @@ var ts; getSignaturesOfType(type, 0).length === 0 && getSignaturesOfType(type, 1).length === 0; } + function createTransientSymbol(source, type) { + var symbol = createSymbol(source.flags | 67108864, source.name); + symbol.declarations = source.declarations; + symbol.parent = source.parent; + symbol.type = type; + symbol.target = source; + if (source.valueDeclaration) { + symbol.valueDeclaration = source.valueDeclaration; + } + return symbol; + } + function transformTypeOfMembers(type, f) { + var members = {}; + for (var _i = 0, _a = getPropertiesOfObjectType(type); _i < _a.length; _i++) { + var property = _a[_i]; + var original = getTypeOfSymbol(property); + var updated = f(original); + members[property.name] = updated === original ? property : createTransientSymbol(property, updated); + } + ; + return members; + } function getRegularTypeOfObjectLiteral(type) { - if (type.flags & 1048576) { - var regularType = type.regularType; - if (!regularType) { - regularType = createType(type.flags & ~1048576); - regularType.symbol = type.symbol; - regularType.members = type.members; - regularType.properties = type.properties; - regularType.callSignatures = type.callSignatures; - regularType.constructSignatures = type.constructSignatures; - regularType.stringIndexInfo = type.stringIndexInfo; - regularType.numberIndexInfo = type.numberIndexInfo; - type.regularType = regularType; - } + if (!(type.flags & 1048576)) { + return type; + } + var regularType = type.regularType; + if (regularType) { return regularType; } - return type; + var resolved = type; + var members = transformTypeOfMembers(type, getRegularTypeOfObjectLiteral); + var regularNew = createAnonymousType(resolved.symbol, members, resolved.callSignatures, resolved.constructSignatures, resolved.stringIndexInfo, resolved.numberIndexInfo); + regularNew.flags = resolved.flags & ~1048576; + type.regularType = regularNew; + return regularNew; } function getWidenedTypeOfObjectLiteral(type) { - var properties = getPropertiesOfObjectType(type); - var members = {}; - ts.forEach(properties, function (p) { - var propType = getTypeOfSymbol(p); - var widenedType = getWidenedType(propType); - if (propType !== widenedType) { - var symbol = createSymbol(p.flags | 67108864, p.name); - symbol.declarations = p.declarations; - symbol.parent = p.parent; - symbol.type = widenedType; - symbol.target = p; - if (p.valueDeclaration) - symbol.valueDeclaration = p.valueDeclaration; - p = symbol; - } - members[p.name] = p; + var members = transformTypeOfMembers(type, function (prop) { + var widened = getWidenedType(prop); + return prop === widened ? prop : widened; }); var stringIndexInfo = getIndexInfoOfType(type, 0); var numberIndexInfo = getIndexInfoOfType(type, 1); @@ -19888,7 +19926,7 @@ var ts; } return nodeCheckFlag === 512 ? getBaseConstructorTypeOfClass(classType) - : baseClassType; + : getTypeWithThisArgument(baseClassType, classType.thisType); function isLegalUsageOfSuperExpression(container) { if (!container) { return false; @@ -21936,7 +21974,7 @@ var ts; var types = void 0; var funcIsGenerator = !!func.asteriskToken; if (funcIsGenerator) { - types = checkAndAggregateYieldOperandTypes(func.body, contextualMapper); + types = checkAndAggregateYieldOperandTypes(func, contextualMapper); if (types.length === 0) { var iterableIteratorAny = createIterableIteratorType(anyType); if (compilerOptions.noImplicitAny) { @@ -21946,8 +21984,7 @@ var ts; } } else { - var hasImplicitReturn = !!(func.flags & 32768); - types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper, isAsync, hasImplicitReturn); + types = checkAndAggregateReturnExpressionTypes(func, contextualMapper); if (!types) { return neverType; } @@ -21994,9 +22031,9 @@ var ts; return widenedType; } } - function checkAndAggregateYieldOperandTypes(body, contextualMapper) { + function checkAndAggregateYieldOperandTypes(func, contextualMapper) { var aggregatedTypes = []; - ts.forEachYieldExpression(body, function (yieldExpression) { + ts.forEachYieldExpression(func.body, function (yieldExpression) { var expr = yieldExpression.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); @@ -22010,28 +22047,34 @@ var ts; }); return aggregatedTypes; } - function checkAndAggregateReturnExpressionTypes(body, contextualMapper, isAsync, hasImplicitReturn) { + function checkAndAggregateReturnExpressionTypes(func, contextualMapper) { + var isAsync = ts.isAsyncFunctionLike(func); var aggregatedTypes = []; - var hasOmittedExpressions = false; - ts.forEachReturnStatement(body, function (returnStatement) { + var hasReturnWithNoExpression = !!(func.flags & 32768); + var hasReturnOfTypeNever = false; + ts.forEachReturnStatement(func.body, function (returnStatement) { var expr = returnStatement.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); if (isAsync) { - type = checkAwaitedType(type, body.parent, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); + type = checkAwaitedType(type, func, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); } - if (type !== neverType && !ts.contains(aggregatedTypes, type)) { + if (type === neverType) { + hasReturnOfTypeNever = true; + } + else if (!ts.contains(aggregatedTypes, type)) { aggregatedTypes.push(type); } } else { - hasOmittedExpressions = true; + hasReturnWithNoExpression = true; } }); - if (aggregatedTypes.length === 0 && !hasOmittedExpressions && !hasImplicitReturn) { + if (aggregatedTypes.length === 0 && !hasReturnWithNoExpression && (hasReturnOfTypeNever || + func.kind === 179 || func.kind === 180)) { return undefined; } - if (strictNullChecks && aggregatedTypes.length && (hasOmittedExpressions || hasImplicitReturn)) { + if (strictNullChecks && aggregatedTypes.length && hasReturnWithNoExpression) { if (!ts.contains(aggregatedTypes, undefinedType)) { aggregatedTypes.push(undefinedType); } @@ -22161,7 +22204,9 @@ var ts; (expr.kind === 172 || expr.kind === 173) && expr.expression.kind === 97) { var func = ts.getContainingFunction(expr); - return !(func && func.kind === 148 && func.parent === symbol.valueDeclaration.parent); + if (!(func && func.kind === 148)) + return true; + return !(func.parent === symbol.valueDeclaration.parent || func === symbol.valueDeclaration.parent); } return true; } @@ -22985,6 +23030,79 @@ var ts; } } } + function checkClassForDuplicateDeclarations(node) { + var getter = 1, setter = 2, property = getter | setter; + var instanceNames = {}; + var staticNames = {}; + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind === 148) { + for (var _b = 0, _c = member.parameters; _b < _c.length; _b++) { + var param = _c[_b]; + if (ts.isParameterPropertyDeclaration(param)) { + addName(instanceNames, param.name, param.name.text, property); + } + } + } + else { + var static = ts.forEach(member.modifiers, function (m) { return m.kind === 113; }); + var names = static ? staticNames : instanceNames; + var memberName = member.name && ts.getPropertyNameForPropertyNameNode(member.name); + if (memberName) { + switch (member.kind) { + case 149: + addName(names, member.name, memberName, getter); + break; + case 150: + addName(names, member.name, memberName, setter); + break; + case 145: + addName(names, member.name, memberName, property); + break; + } + } + } + } + function addName(names, location, name, meaning) { + if (ts.hasProperty(names, name)) { + var prev = names[name]; + if (prev & meaning) { + error(location, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(location)); + } + else { + names[name] = prev | meaning; + } + } + else { + names[name] = meaning; + } + } + } + function checkObjectTypeForDuplicateDeclarations(node) { + var names = {}; + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind == 144) { + var memberName = void 0; + switch (member.name.kind) { + case 9: + case 8: + case 69: + memberName = member.name.text; + break; + default: + continue; + } + if (ts.hasProperty(names, memberName)) { + error(member.symbol.valueDeclaration.name, ts.Diagnostics.Duplicate_identifier_0, memberName); + error(member.name, ts.Diagnostics.Duplicate_identifier_0, memberName); + } + else { + names[memberName] = true; + } + } + } + } function checkTypeForDuplicateIndexSignatures(node) { if (node.kind === 222) { var nodeSymbol = getSymbolOfNode(node); @@ -23203,6 +23321,7 @@ var ts; var type = getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); checkIndexConstraints(type); checkTypeForDuplicateIndexSignatures(node); + checkObjectTypeForDuplicateDeclarations(node); } } function checkArrayType(node) { @@ -23962,6 +24081,10 @@ var ts; if (node.initializer) { checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, undefined); } + if (!areDeclarationFlagsIdentical(node, symbol.valueDeclaration)) { + error(symbol.valueDeclaration.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); + error(node.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); + } } if (node.kind !== 145 && node.kind !== 144) { checkExportsOnMergedDeclarations(node); @@ -23974,6 +24097,18 @@ var ts; checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } } + function areDeclarationFlagsIdentical(left, right) { + if (ts.hasQuestionToken(left) !== ts.hasQuestionToken(right)) { + return false; + } + var interestingFlags = 8 | + 16 | + 256 | + 128 | + 64 | + 32; + return (left.flags & interestingFlags) === (right.flags & interestingFlags); + } function checkVariableDeclaration(node) { checkGrammarVariableDeclaration(node); return checkVariableLikeDeclaration(node); @@ -24524,6 +24659,7 @@ var ts; var typeWithThis = getTypeWithThisArgument(type); var staticType = getTypeOfSymbol(symbol); checkTypeParameterListsIdentical(node, symbol); + checkClassForDuplicateDeclarations(node); var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); if (baseTypeNode) { var baseTypes = getBaseTypes(type); @@ -24735,6 +24871,7 @@ var ts; checkIndexConstraints(type); } } + checkObjectTypeForDuplicateDeclarations(node); } ts.forEach(ts.getInterfaceBaseTypeNodes(node), function (heritageElement) { if (!ts.isSupportedExpressionWithTypeArguments(heritageElement)) { @@ -25489,10 +25626,8 @@ var ts; function checkSourceFileWorker(node) { var links = getNodeLinks(node); if (!(links.flags & 1)) { - if (compilerOptions.skipDefaultLibCheck) { - if (node.hasNoDefaultLib) { - return; - } + if (compilerOptions.skipLibCheck && node.isDeclarationFile || compilerOptions.skipDefaultLibCheck && node.hasNoDefaultLib) { + return; } checkGrammarSourceFile(node); potentialThisCollisions.length = 0; @@ -25861,7 +25996,7 @@ var ts; return symbol && getTypeOfSymbol(symbol); } if (ts.isBindingPattern(node)) { - return getTypeForVariableLikeDeclaration(node.parent); + return getTypeForVariableLikeDeclaration(node.parent, true); } if (isInRightSideOfImportOrExportAssignment(node)) { var symbol = getSymbolAtLocation(node); @@ -26300,7 +26435,7 @@ var ts; if (file.moduleAugmentations.length) { (augmentations || (augmentations = [])).push(file.moduleAugmentations); } - if (file.wasReferenced && file.symbol && file.symbol.globalExports) { + if (file.symbol && file.symbol.globalExports) { mergeSymbolTable(globals, file.symbol.globalExports); } }); @@ -26870,7 +27005,6 @@ var ts; if (prop.kind === 193 || name_20.kind === 140) { checkGrammarComputedPropertyName(name_20); - return "continue"; } if (prop.kind === 254 && !inDestructuring && prop.objectAssignmentInitializer) { return { value: grammarErrorOnNode(prop.equalsToken, ts.Diagnostics.can_only_be_used_in_an_object_literal_property_inside_a_destructuring_assignment) }; @@ -26900,17 +27034,21 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_20.text)) { - seen[name_20.text] = currentKind; + var effectiveName = ts.getPropertyNameForPropertyNameNode(name_20); + if (effectiveName === undefined) { + return "continue"; + } + if (!ts.hasProperty(seen, effectiveName)) { + seen[effectiveName] = currentKind; } else { - var existingKind = seen[name_20.text]; + var existingKind = seen[effectiveName]; if (currentKind === Property && existingKind === Property) { - return "continue"; + grammarErrorOnNode(name_20, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name_20)); } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_20.text] = currentKind | existingKind; + seen[effectiveName] = currentKind | existingKind; } else { return { value: grammarErrorOnNode(name_20, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name) }; @@ -35367,7 +35505,7 @@ var ts; skipTsx: true, traceEnabled: traceEnabled }; - var rootDir = options.typesRoot || (options.configFilePath ? ts.getDirectoryPath(options.configFilePath) : undefined); + var rootDir = options.typesRoot || (options.configFilePath ? ts.getDirectoryPath(options.configFilePath) : (host.getCurrentDirectory && host.getCurrentDirectory())); if (traceEnabled) { if (containingFile === undefined) { if (rootDir === undefined) { @@ -35870,12 +36008,25 @@ var ts; } } } + function getDefaultTypeDirectiveNames(rootPath) { + var localTypes = ts.combinePaths(rootPath, "types"); + var npmTypes = ts.combinePaths(rootPath, "node_modules/@types"); + var result = []; + if (ts.sys.directoryExists(localTypes)) { + result = result.concat(ts.sys.getDirectories(localTypes)); + } + if (ts.sys.directoryExists(npmTypes)) { + result = result.concat(ts.sys.getDirectories(npmTypes)); + } + return result; + } function getDefaultLibLocation() { return ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())); } var newLine = ts.getNewLineCharacter(options); var realpath = ts.sys.realpath && (function (path) { return ts.sys.realpath(path); }); return { + getDefaultTypeDirectiveNames: getDefaultTypeDirectiveNames, getSourceFile: getSourceFile, getDefaultLibLocation: getDefaultLibLocation, getDefaultLibFileName: function (options) { return ts.combinePaths(getDefaultLibLocation(), ts.getDefaultLibFileName(options)); }, @@ -35943,6 +36094,19 @@ var ts; } return resolutions; } + function getDefaultTypeDirectiveNames(options, rootFiles, host) { + if (options.types) { + return options.types; + } + if (host && host.getDefaultTypeDirectiveNames) { + var commonRoot = computeCommonSourceDirectoryOfFilenames(rootFiles, host.getCurrentDirectory(), function (f) { return host.getCanonicalFileName(f); }); + if (commonRoot) { + return host.getDefaultTypeDirectiveNames(commonRoot); + } + } + return undefined; + } + ts.getDefaultTypeDirectiveNames = getDefaultTypeDirectiveNames; function createProgram(rootNames, options, host, oldProgram) { var program; var files = []; @@ -35978,13 +36142,14 @@ var ts; var filesByName = ts.createFileMap(); var filesByNameIgnoreCase = host.useCaseSensitiveFileNames() ? ts.createFileMap(function (fileName) { return fileName.toLowerCase(); }) : undefined; if (!tryReuseStructureFromOldProgram()) { - if (options.types && options.types.length) { - var resolutions = resolveTypeReferenceDirectiveNamesWorker(options.types, undefined); - for (var i = 0; i < options.types.length; i++) { - processTypeReferenceDirective(options.types[i], resolutions[i]); + ts.forEach(rootNames, function (name) { return processRootFile(name, false); }); + var typeReferences = getDefaultTypeDirectiveNames(options, rootNames, host); + if (typeReferences) { + var resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, undefined); + for (var i = 0; i < typeReferences.length; i++) { + processTypeReferenceDirective(typeReferences[i], resolutions[i]); } } - ts.forEach(rootNames, function (name) { return processRootFile(name, false); }); if (!skipDefaultLib) { if (!options.lib) { processRootFile(host.getDefaultLibFileName(options), true); @@ -36561,9 +36726,6 @@ var ts; if (file_1 && options.forceConsistentCasingInFileNames && ts.getNormalizedAbsolutePath(file_1.fileName, currentDirectory) !== ts.getNormalizedAbsolutePath(fileName, currentDirectory)) { reportFileNamesDifferOnlyInCasingError(fileName, file_1.fileName, refFile, refPos, refEnd); } - if (file_1) { - file_1.wasReferenced = file_1.wasReferenced || isReference; - } return file_1; } var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { @@ -36576,7 +36738,6 @@ var ts; }); filesByName.set(path, file); if (file) { - file.wasReferenced = file.wasReferenced || isReference; file.path = path; if (host.useCaseSensitiveFileNames()) { var existingFile = filesByNameIgnoreCase.get(path); @@ -36677,17 +36838,7 @@ var ts; !options.noResolve && i < file.imports.length; if (shouldAddFile) { - var importedFile = findSourceFile(resolution.resolvedFileName, ts.toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), false, false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); - if (importedFile && resolution.isExternalLibraryImport) { - if (!ts.isExternalModule(importedFile) && importedFile.statements.length) { - var start_5 = ts.getTokenPosOfNode(file.imports[i], file); - fileProcessingDiagnostics.add(ts.createFileDiagnostic(file, start_5, file.imports[i].end - start_5, ts.Diagnostics.Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition, importedFile.fileName)); - } - else if (importedFile.referencedFiles.length) { - var firstRef = importedFile.referencedFiles[0]; - fileProcessingDiagnostics.add(ts.createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, ts.Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition)); - } - } + findSourceFile(resolution.resolvedFileName, ts.toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), false, false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); } } } @@ -36772,7 +36923,7 @@ var ts; } } else { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Substututions_for_pattern_0_should_be_an_array, key)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Substitutions_for_pattern_0_should_be_an_array, key)); } } } @@ -36821,13 +36972,19 @@ var ts; } else if (firstExternalModuleSourceFile && languageVersion < 2 && options.module === ts.ModuleKind.None) { var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file)); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none)); } if (options.module === ts.ModuleKind.ES6 && languageVersion < 2) { programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_es2015_when_targeting_ES5_or_lower)); } - if (outFile && options.module && !(options.module === ts.ModuleKind.AMD || options.module === ts.ModuleKind.System)) { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); + if (outFile) { + if (options.module && !(options.module === ts.ModuleKind.AMD || options.module === ts.ModuleKind.System)) { + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); + } + else if (options.module === undefined && firstExternalModuleSourceFile) { + var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system, options.out ? "out" : "outFile")); + } } if (options.outDir || options.sourceRoot || @@ -37517,7 +37674,7 @@ var ts; (function (ts) { var NavigateTo; (function (NavigateTo) { - function getNavigateToItems(program, cancellationToken, searchValue, maxResultCount) { + function getNavigateToItems(program, checker, cancellationToken, searchValue, maxResultCount) { var patternMatcher = ts.createPatternMatcher(searchValue); var rawItems = []; var baseSensitivity = { sensitivity: "base" }; @@ -37550,6 +37707,17 @@ var ts; } } }); + rawItems = ts.filter(rawItems, function (item) { + var decl = item.declaration; + if (decl.kind === 231 || decl.kind === 234 || decl.kind === 229) { + var importer = checker.getSymbolAtLocation(decl.name); + var imported = checker.getAliasedSymbol(importer); + return importer.name !== imported.name; + } + else { + return true; + } + }); rawItems.sort(compareNavigateToItems); if (maxResultCount !== undefined) { rawItems = rawItems.slice(0, maxResultCount); @@ -37892,8 +38060,12 @@ var ts; return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberSetAccessorElement); case 153: return createItem(node, "[]", ts.ScriptElementKind.indexSignatureElement); + case 224: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.enumElement); case 255: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); + case 222: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.interfaceElement); case 151: return createItem(node, "()", ts.ScriptElementKind.callSignatureElement); case 152: @@ -39263,7 +39435,7 @@ var ts; } } function findRightmostChildNodeWithTokens(children, exclusiveStartPosition) { - for (var i = exclusiveStartPosition - 1; i >= 0; --i) { + for (var i = exclusiveStartPosition - 1; i >= 0; i--) { if (nodeHasTokens(children[i])) { return children[i]; } @@ -39889,18 +40061,17 @@ var ts; if (!isStarted) { scanner.scan(); } - var t; var pos = scanner.getStartPos(); while (pos < endPos) { - var t_1 = scanner.getToken(); - if (!ts.isTrivia(t_1)) { + var t = scanner.getToken(); + if (!ts.isTrivia(t)) { break; } scanner.scan(); var item = { pos: pos, end: scanner.getStartPos(), - kind: t_1 + kind: t }; pos = scanner.getStartPos(); if (!leadingTrivia) { @@ -41550,7 +41721,7 @@ var ts; else { parts = []; var startPos = commentRange.pos; - for (var line = startLine; line < endLine; ++line) { + for (var line = startLine; line < endLine; line++) { var endOfLine = ts.getEndLinePosition(line, sourceFile); parts.push({ pos: startPos, end: endOfLine }); startPos = ts.getStartPositionOfLine(line + 1, sourceFile); @@ -41568,7 +41739,7 @@ var ts; startLine++; } var delta = indentation - nonWhitespaceColumnInFirstPart.column; - for (var i = startIndex, len = parts.length; i < len; ++i, ++startLine) { + for (var i = startIndex, len = parts.length; i < len; i++, startLine++) { var startLinePos_1 = ts.getStartPositionOfLine(startLine, sourceFile); var nonWhitespaceCharacterAndColumn = i === 0 ? nonWhitespaceColumnInFirstPart @@ -41584,7 +41755,7 @@ var ts; } } function trimTrailingWhitespacesForLines(line1, line2, range) { - for (var line = line1; line < line2; ++line) { + for (var line = line1; line < line2; line++) { var lineStartPosition = ts.getStartPositionOfLine(line, sourceFile); var lineEndPosition = ts.getEndLinePosition(line, sourceFile); if (range && (ts.isComment(range.kind) || ts.isStringOrRegularExpressionOrTemplateLiteral(range.kind)) && range.pos <= lineEndPosition && range.end > lineEndPosition) { @@ -41627,7 +41798,6 @@ var ts; } } function applyRuleEdits(rule, previousRange, previousStartLine, currentRange, currentStartLine) { - var between; switch (rule.Operation.Action) { case 1: return; @@ -41657,14 +41827,6 @@ var ts; } } } - function isSomeBlock(kind) { - switch (kind) { - case 199: - case 226: - return true; - } - return false; - } function getOpenTokenForList(node, list) { switch (node.kind) { case 148: @@ -41722,7 +41884,7 @@ var ts; internedTabsIndentation = []; } if (internedTabsIndentation[tabs] === undefined) { - internedTabsIndentation[tabs] = tabString = repeat('\t', tabs); + internedTabsIndentation[tabs] = tabString = repeat("\t", tabs); } else { tabString = internedTabsIndentation[tabs]; @@ -41747,7 +41909,7 @@ var ts; } function repeat(value, count) { var s = ""; - for (var i = 0; i < count; ++i) { + for (var i = 0; i < count; i++) { s += value; } return s; @@ -42015,7 +42177,7 @@ var ts; ts.Debug.assert(index >= 0 && index < list.length); var node = list[index]; var lineAndCharacter = getStartLineAndCharacterForNode(node, sourceFile); - for (var i = index - 1; i >= 0; --i) { + for (var i = index - 1; i >= 0; i--) { if (list[i].kind === 24) { continue; } @@ -42034,7 +42196,7 @@ var ts; function findFirstNonWhitespaceCharacterAndColumn(startPos, endPos, sourceFile, options) { var character = 0; var column = 0; - for (var pos = startPos; pos < endPos; ++pos) { + for (var pos = startPos; pos < endPos; pos++) { var ch = sourceFile.text.charCodeAt(pos); if (!ts.isWhiteSpace(ch)) { break; @@ -44005,9 +44167,9 @@ var ts; log("getCompletionData: Get previous token 1: " + (new Date().getTime() - start)); var contextToken = previousToken; if (contextToken && position <= contextToken.end && ts.isWord(contextToken.kind)) { - var start_6 = new Date().getTime(); + var start_5 = new Date().getTime(); contextToken = ts.findPrecedingToken(contextToken.getFullStart(), sourceFile); - log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_6)); + log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_5)); } var node = currentToken; var isRightOfDot = false; @@ -44234,9 +44396,9 @@ var ts; || contextToken.kind === 166 || contextToken.kind === 10 || ts.isTemplateLiteralKind(contextToken.kind)) { - var start_7 = contextToken.getStart(); + var start_6 = contextToken.getStart(); var end = contextToken.getEnd(); - if (start_7 < position && position < end) { + if (start_6 < position && position < end) { return true; } if (position === end) { @@ -45314,8 +45476,7 @@ var ts; } function getDocumentHighlights(fileName, position, filesToSearch) { synchronizeHostData(); - filesToSearch = ts.map(filesToSearch, ts.normalizeSlashes); - var sourceFilesToSearch = ts.filter(program.getSourceFiles(), function (f) { return ts.contains(filesToSearch, f.fileName); }); + var sourceFilesToSearch = ts.map(filesToSearch, function (f) { return program.getSourceFile(f); }); var sourceFile = getValidSourceFile(fileName); var node = ts.getTouchingWord(sourceFile, position); if (!node) { @@ -46498,7 +46659,8 @@ var ts; } function getNavigateToItems(searchValue, maxResultCount) { synchronizeHostData(); - return ts.NavigateTo.getNavigateToItems(program, cancellationToken, searchValue, maxResultCount); + var checker = getProgram().getTypeChecker(); + return ts.NavigateTo.getNavigateToItems(program, checker, cancellationToken, searchValue, maxResultCount); } function getEmitOutput(fileName) { synchronizeHostData(); @@ -51195,6 +51357,9 @@ var ts; LanguageServiceShimHostAdapter.prototype.getCurrentDirectory = function () { return this.shimHost.getCurrentDirectory(); }; + LanguageServiceShimHostAdapter.prototype.getDirectories = function (path) { + return this.shimHost.getDirectories(path); + }; LanguageServiceShimHostAdapter.prototype.getDefaultLibFileName = function (options) { return this.shimHost.getDefaultLibFileName(JSON.stringify(options)); }; diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts index 0629ad983a3..76b66dda93b 100644 --- a/lib/tsserverlibrary.d.ts +++ b/lib/tsserverlibrary.d.ts @@ -247,7 +247,7 @@ declare namespace ts { ModuleDeclaration = 225, ModuleBlock = 226, CaseBlock = 227, - GlobalModuleExportDeclaration = 228, + NamespaceExportDeclaration = 228, ImportEqualsDeclaration = 229, ImportDeclaration = 230, ImportClause = 231, @@ -925,7 +925,7 @@ declare namespace ts { interface NamespaceImport extends Declaration { name: Identifier; } - interface GlobalModuleExportDeclaration extends DeclarationStatement { + interface NamespaceExportDeclaration extends DeclarationStatement { name: Identifier; moduleReference: LiteralLikeNode; } @@ -1087,7 +1087,6 @@ declare namespace ts { scriptKind: ScriptKind; externalModuleIndicator: Node; commonJsModuleIndicator: Node; - wasReferenced?: boolean; identifiers: Map; nodeCount: number; identifierCount: number; @@ -1381,7 +1380,7 @@ declare namespace ts { FunctionScopedVariableExcludes = 107454, BlockScopedVariableExcludes = 107455, ParameterExcludes = 107455, - PropertyExcludes = 107455, + PropertyExcludes = 0, EnumMemberExcludes = 107455, FunctionExcludes = 106927, ClassExcludes = 899519, @@ -1735,6 +1734,7 @@ declare namespace ts { allowJs?: boolean; noImplicitUseStrict?: boolean; strictNullChecks?: boolean; + skipLibCheck?: boolean; listEmittedFiles?: boolean; lib?: string[]; stripInternal?: boolean; @@ -1967,6 +1967,7 @@ declare namespace ts { trace?(s: string): void; directoryExists?(directoryName: string): boolean; realpath?(path: string): string; + getCurrentDirectory?(): string; } interface ResolvedModule { resolvedFileName: string; @@ -1990,6 +1991,7 @@ declare namespace ts { getCancellationToken?(): CancellationToken; getDefaultLibFileName(options: CompilerOptions): string; getDefaultLibLocation?(): string; + getDefaultTypeDirectiveNames?(rootPath: string): string[]; writeFile: WriteFileCallback; getCurrentDirectory(): string; getCanonicalFileName(fileName: string): string; @@ -2136,6 +2138,7 @@ declare namespace ts { createDirectory(path: string): void; getExecutingFilePath(): string; getCurrentDirectory(): string; + getDirectories(path: string): string[]; readDirectory(path: string, extension?: string, exclude?: string[]): string[]; getModifiedTime?(path: string): Date; createHash?(data: string): string; @@ -2820,7 +2823,7 @@ declare namespace ts { key: string; message: string; }; - Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file: { + Cannot_use_imports_exports_or_module_augmentations_when_module_is_none: { code: number; category: DiagnosticCategory; key: string; @@ -5040,6 +5043,18 @@ declare namespace ts { key: string; message: string; }; + Identifier_0_must_be_imported_from_a_module: { + code: number; + category: DiagnosticCategory; + key: string; + message: string; + }; + All_declarations_of_0_must_have_identical_modifiers: { + code: number; + category: DiagnosticCategory; + key: string; + message: string; + }; Import_declaration_0_is_using_private_name_1: { code: number; category: DiagnosticCategory; @@ -5598,7 +5613,7 @@ declare namespace ts { key: string; message: string; }; - Substututions_for_pattern_0_should_be_an_array: { + Substitutions_for_pattern_0_should_be_an_array: { code: number; category: DiagnosticCategory; key: string; @@ -5676,6 +5691,12 @@ declare namespace ts { key: string; message: string; }; + Skip_type_checking_of_declaration_files: { + code: number; + category: DiagnosticCategory; + key: string; + message: string; + }; Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015: { code: number; category: DiagnosticCategory; @@ -6282,6 +6303,12 @@ declare namespace ts { key: string; message: string; }; + Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { + code: number; + category: DiagnosticCategory; + key: string; + message: string; + }; Variable_0_implicitly_has_an_1_type: { code: number; category: DiagnosticCategory; @@ -7024,6 +7051,7 @@ declare namespace ts { function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; + function getDefaultTypeDirectiveNames(options: CompilerOptions, rootFiles: string[], host: CompilerHost): string[]; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program): Program; } declare namespace ts.BreakpointResolver { @@ -7033,7 +7061,7 @@ declare namespace ts.OutliningElementsCollector { function collectElements(sourceFile: SourceFile): OutliningSpan[]; } declare namespace ts.NavigateTo { - function getNavigateToItems(program: Program, cancellationToken: CancellationToken, searchValue: string, maxResultCount: number): NavigateToItem[]; + function getNavigateToItems(program: Program, checker: TypeChecker, cancellationToken: CancellationToken, searchValue: string, maxResultCount: number): NavigateToItem[]; } declare namespace ts.NavigationBar { function getNavigationBarItems(sourceFile: SourceFile, compilerOptions: CompilerOptions): ts.NavigationBarItem[]; @@ -7431,7 +7459,7 @@ declare namespace ts.formatting { } } declare namespace ts.formatting { - module Shared { + namespace Shared { interface ITokenAccess { GetTokens(): SyntaxKind[]; Contains(token: SyntaxKind): boolean; @@ -7516,7 +7544,7 @@ declare namespace ts.formatting { function getIndentationString(indentation: number, options: FormatCodeOptions): string; } declare namespace ts.formatting { - module SmartIndenter { + namespace SmartIndenter { function getIndentation(position: number, sourceFile: SourceFile, options: EditorOptions): number; function getIndentationForNode(n: Node, ignoreActualIndentationRange: TextRange, sourceFile: SourceFile, options: FormatCodeOptions): number; function childStartsOnTheSameLineWithElseInIfStatement(parent: Node, child: TextRangeWithKind, childStartLine: number, sourceFile: SourceFile): boolean; @@ -8487,6 +8515,7 @@ declare namespace ts { getLocalizedDiagnosticMessages(): string; getCancellationToken(): HostCancellationToken; getCurrentDirectory(): string; + getDirectories(path: string): string[]; getDefaultLibFileName(options: string): string; getNewLine?(): string; getProjectVersion?(): string; @@ -8582,6 +8611,7 @@ declare namespace ts { getLocalizedDiagnosticMessages(): any; getCancellationToken(): HostCancellationToken; getCurrentDirectory(): string; + getDirectories(path: string): string[]; getDefaultLibFileName(options: CompilerOptions): string; } class CoreServicesShimHostAdapter implements ParseConfigHost, ModuleResolutionHost { diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 050d9ca265d..902bfcf610e 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -918,6 +918,10 @@ var ts; } return result.sort(); } + function getDirectories(path) { + var folder = fso.GetFolder(path); + return getNames(folder.subfolders); + } function readDirectory(path, extension, exclude) { var result = []; exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); @@ -972,6 +976,7 @@ var ts; getCurrentDirectory: function () { return new ActiveXObject("WScript.Shell").CurrentDirectory; }, + getDirectories: getDirectories, readDirectory: readDirectory, exit: function (exitCode) { try { @@ -1119,6 +1124,9 @@ var ts; function directoryExists(path) { return fileSystemEntryExists(path, 1); } + function getDirectories(path) { + return ts.filter(_fs.readdirSync(path), function (p) { return fileSystemEntryExists(ts.combinePaths(path, p), 1); }); + } function readDirectory(path, extension, exclude) { var result = []; exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); @@ -1211,6 +1219,7 @@ var ts; getCurrentDirectory: function () { return process.cwd(); }, + getDirectories: getDirectories, readDirectory: readDirectory, getModifiedTime: function (path) { try { @@ -1261,6 +1270,7 @@ var ts; createDirectory: ChakraHost.createDirectory, getExecutingFilePath: function () { return ChakraHost.executingFile; }, getCurrentDirectory: function () { return ChakraHost.currentDirectory; }, + getDirectories: ChakraHost.getDirectories, readDirectory: ChakraHost.readDirectory, exit: ChakraHost.quit, realpath: realpath @@ -1394,7 +1404,7 @@ var ts; or_expected: { code: 1144, category: ts.DiagnosticCategory.Error, key: "or_expected_1144", message: "'{' or ';' expected." }, Declaration_expected: { code: 1146, category: ts.DiagnosticCategory.Error, key: "Declaration_expected_1146", message: "Declaration expected." }, Import_declarations_in_a_namespace_cannot_reference_a_module: { code: 1147, category: ts.DiagnosticCategory.Error, key: "Import_declarations_in_a_namespace_cannot_reference_a_module_1147", message: "Import declarations in a namespace cannot reference a module." }, - Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting__1148", message: "Cannot compile modules unless the '--module' flag is provided with a valid module type. Consider setting the 'module' compiler option in a 'tsconfig.json' file." }, + Cannot_use_imports_exports_or_module_augmentations_when_module_is_none: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot_use_imports_exports_or_module_augmentations_when_module_is_none_1148", message: "Cannot use imports, exports, or module augmentations when '--module' is 'none'." }, File_name_0_differs_from_already_included_file_name_1_only_in_casing: { code: 1149, category: ts.DiagnosticCategory.Error, key: "File_name_0_differs_from_already_included_file_name_1_only_in_casing_1149", message: "File name '{0}' differs from already included file name '{1}' only in casing" }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: ts.DiagnosticCategory.Error, key: "new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead_1150", message: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, const_declarations_must_be_initialized: { code: 1155, category: ts.DiagnosticCategory.Error, key: "const_declarations_must_be_initialized_1155", message: "'const' declarations must be initialized" }, @@ -1764,6 +1774,8 @@ var ts; this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation: { code: 2683, category: ts.DiagnosticCategory.Error, key: "this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_2683", message: "'this' implicitly has type 'any' because it does not have a type annotation." }, The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1: { code: 2684, category: ts.DiagnosticCategory.Error, key: "The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1_2684", message: "The 'this' context of type '{0}' is not assignable to method's 'this' of type '{1}'." }, The_this_types_of_each_signature_are_incompatible: { code: 2685, category: ts.DiagnosticCategory.Error, key: "The_this_types_of_each_signature_are_incompatible_2685", message: "The 'this' types of each signature are incompatible." }, + Identifier_0_must_be_imported_from_a_module: { code: 2686, category: ts.DiagnosticCategory.Error, key: "Identifier_0_must_be_imported_from_a_module_2686", message: "Identifier '{0}' must be imported from a module" }, + All_declarations_of_0_must_have_identical_modifiers: { code: 2687, category: ts.DiagnosticCategory.Error, key: "All_declarations_of_0_must_have_identical_modifiers_2687", message: "All declarations of '{0}' must have identical modifiers." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import_declaration_0_is_using_private_name_1_4000", message: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: ts.DiagnosticCategory.Error, key: "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", message: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: ts.DiagnosticCategory.Error, key: "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", message: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -1857,7 +1869,7 @@ var ts; Option_paths_cannot_be_used_without_specifying_baseUrl_option: { code: 5060, category: ts.DiagnosticCategory.Error, key: "Option_paths_cannot_be_used_without_specifying_baseUrl_option_5060", message: "Option 'paths' cannot be used without specifying '--baseUrl' option." }, Pattern_0_can_have_at_most_one_Asterisk_character: { code: 5061, category: ts.DiagnosticCategory.Error, key: "Pattern_0_can_have_at_most_one_Asterisk_character_5061", message: "Pattern '{0}' can have at most one '*' character" }, Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character: { code: 5062, category: ts.DiagnosticCategory.Error, key: "Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character_5062", message: "Substitution '{0}' in pattern '{1}' in can have at most one '*' character" }, - Substututions_for_pattern_0_should_be_an_array: { code: 5063, category: ts.DiagnosticCategory.Error, key: "Substututions_for_pattern_0_should_be_an_array_5063", message: "Substututions for pattern '{0}' should be an array." }, + Substitutions_for_pattern_0_should_be_an_array: { code: 5063, category: ts.DiagnosticCategory.Error, key: "Substitutions_for_pattern_0_should_be_an_array_5063", message: "Substitutions for pattern '{0}' should be an array." }, Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2: { code: 5064, category: ts.DiagnosticCategory.Error, key: "Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2_5064", message: "Substitution '{0}' for pattern '{1}' has incorrect type, expected 'string', got '{2}'." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: ts.DiagnosticCategory.Message, key: "Concatenate_and_emit_output_to_single_file_6001", message: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: ts.DiagnosticCategory.Message, key: "Generates_corresponding_d_ts_file_6002", message: "Generates corresponding '.d.ts' file." }, @@ -1870,6 +1882,7 @@ var ts; Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do_not_emit_comments_to_output_6009", message: "Do not emit comments to output." }, Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do_not_emit_outputs_6010", message: "Do not emit outputs." }, Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking: { code: 6011, category: ts.DiagnosticCategory.Message, key: "Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typech_6011", message: "Allow default imports from modules with no default export. This does not affect code emit, just typechecking." }, + Skip_type_checking_of_declaration_files: { code: 6012, category: ts.DiagnosticCategory.Message, key: "Skip_type_checking_of_declaration_files_6012", message: "Skip type checking of declaration files." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015_6015", message: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015'" }, Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015: { code: 6016, category: ts.DiagnosticCategory.Message, key: "Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015_6016", message: "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'" }, Print_this_message: { code: 6017, category: ts.DiagnosticCategory.Message, key: "Print_this_message_6017", message: "Print this message." }, @@ -1971,6 +1984,7 @@ var ts; Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set: { code: 6128, category: ts.DiagnosticCategory.Message, key: "Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set_6128", message: "======== Resolving type reference directive '{0}', containing file not set, root directory not set. ========" }, The_config_file_0_found_doesn_t_contain_any_source_files: { code: 6129, category: ts.DiagnosticCategory.Error, key: "The_config_file_0_found_doesn_t_contain_any_source_files_6129", message: "The config file '{0}' found doesn't contain any source files." }, Resolving_real_path_for_0_result_1: { code: 6130, category: ts.DiagnosticCategory.Message, key: "Resolving_real_path_for_0_result_1_6130", message: "Resolving real path for '{0}', result '{1}'" }, + Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { code: 6131, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system_6131", message: "Cannot compile modules using option '{0}' unless the '--module' flag is 'amd' or 'system'." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable_0_implicitly_has_an_1_type_7005", message: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter_0_implicitly_has_an_1_type_7006", message: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member_0_implicitly_has_an_1_type_7008", message: "Member '{0}' implicitly has an '{1}' type." }, @@ -3537,6 +3551,11 @@ var ts; type: "boolean", description: ts.Diagnostics.Print_this_message }, + { + name: "help", + shortName: "?", + type: "boolean" + }, { name: "init", type: "boolean", @@ -3639,6 +3658,11 @@ var ts; name: "skipDefaultLibCheck", type: "boolean" }, + { + name: "skipLibCheck", + type: "boolean", + description: ts.Diagnostics.Skip_type_checking_of_declaration_files + }, { name: "out", type: "string", @@ -5758,7 +5782,7 @@ var ts; } ts.isWellKnownSymbolSyntactically = isWellKnownSymbolSyntactically; function getPropertyNameForPropertyNameNode(name) { - if (name.kind === 69 || name.kind === 9 || name.kind === 8) { + if (name.kind === 69 || name.kind === 9 || name.kind === 8 || name.kind === 142) { return name.text; } if (name.kind === 140) { @@ -12804,10 +12828,10 @@ var ts; case 145: case 144: case 266: - return bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 107455); + return bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 0); case 253: case 254: - return bindPropertyOrMethodOrAccessor(node, 4, 107455); + return bindPropertyOrMethodOrAccessor(node, 4, 0); case 255: return bindPropertyOrMethodOrAccessor(node, 8, 107455); case 247: @@ -12819,7 +12843,7 @@ var ts; return declareSymbolAndAddToSymbolTable(node, 131072, 0); case 147: case 146: - return bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 107455 : 99263); + return bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 0 : 99263); case 220: return bindFunctionDeclaration(node); case 148: @@ -12862,7 +12886,7 @@ var ts; case 238: return declareSymbolAndAddToSymbolTable(node, 8388608, 8388608); case 228: - return bindGlobalModuleExportDeclaration(node); + return bindNamespaceExportDeclaration(node); case 231: return bindImportClause(node); case 236: @@ -12898,13 +12922,13 @@ var ts; bindAnonymousDeclaration(node, 8388608, getDeclarationName(node)); } else if (boundExpression.kind === 69 && node.kind === 235) { - declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 107455 | 8388608); + declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 0 | 8388608); } else { - declareSymbol(container.symbol.exports, container.symbol, node, 4, 107455 | 8388608); + declareSymbol(container.symbol.exports, container.symbol, node, 4, 0 | 8388608); } } - function bindGlobalModuleExportDeclaration(node) { + function bindNamespaceExportDeclaration(node) { if (node.modifiers && node.modifiers.length) { file.bindDiagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.Modifiers_cannot_appear_here)); } @@ -12956,7 +12980,7 @@ var ts; function bindThisPropertyAssignment(node) { if (container.kind === 179 || container.kind === 220) { container.symbol.members = container.symbol.members || {}; - declareSymbol(container.symbol.members, container.symbol, node, 4, 107455 & ~4); + declareSymbol(container.symbol.members, container.symbol, node, 4, 0 & ~4); } } function bindPrototypePropertyAssignment(node) { @@ -12973,7 +12997,7 @@ var ts; if (!funcSymbol.members) { funcSymbol.members = {}; } - declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, 4, 107455); + declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, 4, 0); } function bindCallExpression(node) { if (!file.commonJsModuleIndicator && ts.isRequireCall(node, false)) { @@ -13049,7 +13073,7 @@ var ts; } if (ts.isParameterPropertyDeclaration(node)) { var classDeclaration = node.parent.parent; - declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 107455); + declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 0); } } function bindFunctionDeclaration(node) { @@ -13349,7 +13373,7 @@ var ts; if (flags & 1) result |= 107454; if (flags & 4) - result |= 107455; + result |= 0; if (flags & 8) result |= 107455; if (flags & 16) @@ -13605,6 +13629,7 @@ var ts; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; + var isInExternalModule = false; loop: while (location) { if (location.locals && !isGlobalSourceFile(location)) { if (result = getSymbol(location.locals, name, meaning)) { @@ -13636,6 +13661,7 @@ var ts; case 256: if (!ts.isExternalOrCommonJsModule(location)) break; + isInExternalModule = true; case 225: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 256 || ts.isAmbientModule(location)) { @@ -13759,6 +13785,12 @@ var ts; checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation); } } + if (result && isInExternalModule) { + var decls = result.declarations; + if (decls && decls.length === 1 && decls[0].kind === 228) { + error(errorLocation, ts.Diagnostics.Identifier_0_must_be_imported_from_a_module, name); + } + } } return result; } @@ -15234,7 +15266,7 @@ var ts; } function getTypeForBindingElementParent(node) { var symbol = getSymbolOfNode(node); - return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node); + return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, false); } function getTextOfPropertyName(name) { switch (name.kind) { @@ -15339,7 +15371,7 @@ var ts; function addOptionality(type, optional) { return strictNullChecks && optional ? addNullableKind(type, 32) : type; } - function getTypeForVariableLikeDeclaration(declaration) { + function getTypeForVariableLikeDeclaration(declaration, includeOptionality) { if (declaration.flags & 134217728) { var type = getTypeForVariableLikeDeclarationFromJSDocComment(declaration); if (type && type !== unknownType) { @@ -15356,7 +15388,7 @@ var ts; return getTypeForBindingElement(declaration); } if (declaration.type) { - return addOptionality(getTypeFromTypeNode(declaration.type), !!declaration.questionToken); + return addOptionality(getTypeFromTypeNode(declaration.type), declaration.questionToken && includeOptionality); } if (declaration.kind === 142) { var func = declaration.parent; @@ -15375,11 +15407,11 @@ var ts; ? getContextuallyTypedThisType(func) : getContextuallyTypedParameterType(declaration); if (type) { - return addOptionality(type, !!declaration.questionToken); + return addOptionality(type, declaration.questionToken && includeOptionality); } } if (declaration.initializer) { - return addOptionality(checkExpressionCached(declaration.initializer), !!declaration.questionToken); + return addOptionality(checkExpressionCached(declaration.initializer), declaration.questionToken && includeOptionality); } if (declaration.kind === 254) { return checkIdentifier(declaration.name); @@ -15447,7 +15479,7 @@ var ts; : getTypeFromArrayBindingPattern(pattern, includePatternInType); } function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) { - var type = getTypeForVariableLikeDeclaration(declaration); + var type = getTypeForVariableLikeDeclaration(declaration, true); if (type) { if (reportErrors) { reportErrorsFromWidening(declaration, type); @@ -17764,7 +17796,7 @@ var ts; return isIdenticalTo(source, target); } if (!(target.flags & 134217728)) { - if (target.flags & 1) + if (target.flags & 1 || source.flags & 134217728) return -1; if (source.flags & 32) { if (!strictNullChecks || target.flags & (32 | 16) || source === emptyArrayElementType) @@ -17784,7 +17816,7 @@ var ts; if (source.flags & 256 && target === stringType) return -1; if (relation === assignableRelation || relation === comparableRelation) { - if (source.flags & (1 | 134217728)) + if (source.flags & 1) return -1; if (source === numberType && target.flags & 128) return -1; @@ -18561,41 +18593,47 @@ var ts; getSignaturesOfType(type, 0).length === 0 && getSignaturesOfType(type, 1).length === 0; } + function createTransientSymbol(source, type) { + var symbol = createSymbol(source.flags | 67108864, source.name); + symbol.declarations = source.declarations; + symbol.parent = source.parent; + symbol.type = type; + symbol.target = source; + if (source.valueDeclaration) { + symbol.valueDeclaration = source.valueDeclaration; + } + return symbol; + } + function transformTypeOfMembers(type, f) { + var members = {}; + for (var _i = 0, _a = getPropertiesOfObjectType(type); _i < _a.length; _i++) { + var property = _a[_i]; + var original = getTypeOfSymbol(property); + var updated = f(original); + members[property.name] = updated === original ? property : createTransientSymbol(property, updated); + } + ; + return members; + } function getRegularTypeOfObjectLiteral(type) { - if (type.flags & 1048576) { - var regularType = type.regularType; - if (!regularType) { - regularType = createType(type.flags & ~1048576); - regularType.symbol = type.symbol; - regularType.members = type.members; - regularType.properties = type.properties; - regularType.callSignatures = type.callSignatures; - regularType.constructSignatures = type.constructSignatures; - regularType.stringIndexInfo = type.stringIndexInfo; - regularType.numberIndexInfo = type.numberIndexInfo; - type.regularType = regularType; - } + if (!(type.flags & 1048576)) { + return type; + } + var regularType = type.regularType; + if (regularType) { return regularType; } - return type; + var resolved = type; + var members = transformTypeOfMembers(type, getRegularTypeOfObjectLiteral); + var regularNew = createAnonymousType(resolved.symbol, members, resolved.callSignatures, resolved.constructSignatures, resolved.stringIndexInfo, resolved.numberIndexInfo); + regularNew.flags = resolved.flags & ~1048576; + type.regularType = regularNew; + return regularNew; } function getWidenedTypeOfObjectLiteral(type) { - var properties = getPropertiesOfObjectType(type); - var members = {}; - ts.forEach(properties, function (p) { - var propType = getTypeOfSymbol(p); - var widenedType = getWidenedType(propType); - if (propType !== widenedType) { - var symbol = createSymbol(p.flags | 67108864, p.name); - symbol.declarations = p.declarations; - symbol.parent = p.parent; - symbol.type = widenedType; - symbol.target = p; - if (p.valueDeclaration) - symbol.valueDeclaration = p.valueDeclaration; - p = symbol; - } - members[p.name] = p; + var members = transformTypeOfMembers(type, function (prop) { + var widened = getWidenedType(prop); + return prop === widened ? prop : widened; }); var stringIndexInfo = getIndexInfoOfType(type, 0); var numberIndexInfo = getIndexInfoOfType(type, 1); @@ -19888,7 +19926,7 @@ var ts; } return nodeCheckFlag === 512 ? getBaseConstructorTypeOfClass(classType) - : baseClassType; + : getTypeWithThisArgument(baseClassType, classType.thisType); function isLegalUsageOfSuperExpression(container) { if (!container) { return false; @@ -21936,7 +21974,7 @@ var ts; var types = void 0; var funcIsGenerator = !!func.asteriskToken; if (funcIsGenerator) { - types = checkAndAggregateYieldOperandTypes(func.body, contextualMapper); + types = checkAndAggregateYieldOperandTypes(func, contextualMapper); if (types.length === 0) { var iterableIteratorAny = createIterableIteratorType(anyType); if (compilerOptions.noImplicitAny) { @@ -21946,8 +21984,7 @@ var ts; } } else { - var hasImplicitReturn = !!(func.flags & 32768); - types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper, isAsync, hasImplicitReturn); + types = checkAndAggregateReturnExpressionTypes(func, contextualMapper); if (!types) { return neverType; } @@ -21994,9 +22031,9 @@ var ts; return widenedType; } } - function checkAndAggregateYieldOperandTypes(body, contextualMapper) { + function checkAndAggregateYieldOperandTypes(func, contextualMapper) { var aggregatedTypes = []; - ts.forEachYieldExpression(body, function (yieldExpression) { + ts.forEachYieldExpression(func.body, function (yieldExpression) { var expr = yieldExpression.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); @@ -22010,28 +22047,34 @@ var ts; }); return aggregatedTypes; } - function checkAndAggregateReturnExpressionTypes(body, contextualMapper, isAsync, hasImplicitReturn) { + function checkAndAggregateReturnExpressionTypes(func, contextualMapper) { + var isAsync = ts.isAsyncFunctionLike(func); var aggregatedTypes = []; - var hasOmittedExpressions = false; - ts.forEachReturnStatement(body, function (returnStatement) { + var hasReturnWithNoExpression = !!(func.flags & 32768); + var hasReturnOfTypeNever = false; + ts.forEachReturnStatement(func.body, function (returnStatement) { var expr = returnStatement.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); if (isAsync) { - type = checkAwaitedType(type, body.parent, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); + type = checkAwaitedType(type, func, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); } - if (type !== neverType && !ts.contains(aggregatedTypes, type)) { + if (type === neverType) { + hasReturnOfTypeNever = true; + } + else if (!ts.contains(aggregatedTypes, type)) { aggregatedTypes.push(type); } } else { - hasOmittedExpressions = true; + hasReturnWithNoExpression = true; } }); - if (aggregatedTypes.length === 0 && !hasOmittedExpressions && !hasImplicitReturn) { + if (aggregatedTypes.length === 0 && !hasReturnWithNoExpression && (hasReturnOfTypeNever || + func.kind === 179 || func.kind === 180)) { return undefined; } - if (strictNullChecks && aggregatedTypes.length && (hasOmittedExpressions || hasImplicitReturn)) { + if (strictNullChecks && aggregatedTypes.length && hasReturnWithNoExpression) { if (!ts.contains(aggregatedTypes, undefinedType)) { aggregatedTypes.push(undefinedType); } @@ -22161,7 +22204,9 @@ var ts; (expr.kind === 172 || expr.kind === 173) && expr.expression.kind === 97) { var func = ts.getContainingFunction(expr); - return !(func && func.kind === 148 && func.parent === symbol.valueDeclaration.parent); + if (!(func && func.kind === 148)) + return true; + return !(func.parent === symbol.valueDeclaration.parent || func === symbol.valueDeclaration.parent); } return true; } @@ -22985,6 +23030,79 @@ var ts; } } } + function checkClassForDuplicateDeclarations(node) { + var getter = 1, setter = 2, property = getter | setter; + var instanceNames = {}; + var staticNames = {}; + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind === 148) { + for (var _b = 0, _c = member.parameters; _b < _c.length; _b++) { + var param = _c[_b]; + if (ts.isParameterPropertyDeclaration(param)) { + addName(instanceNames, param.name, param.name.text, property); + } + } + } + else { + var static = ts.forEach(member.modifiers, function (m) { return m.kind === 113; }); + var names = static ? staticNames : instanceNames; + var memberName = member.name && ts.getPropertyNameForPropertyNameNode(member.name); + if (memberName) { + switch (member.kind) { + case 149: + addName(names, member.name, memberName, getter); + break; + case 150: + addName(names, member.name, memberName, setter); + break; + case 145: + addName(names, member.name, memberName, property); + break; + } + } + } + } + function addName(names, location, name, meaning) { + if (ts.hasProperty(names, name)) { + var prev = names[name]; + if (prev & meaning) { + error(location, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(location)); + } + else { + names[name] = prev | meaning; + } + } + else { + names[name] = meaning; + } + } + } + function checkObjectTypeForDuplicateDeclarations(node) { + var names = {}; + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind == 144) { + var memberName = void 0; + switch (member.name.kind) { + case 9: + case 8: + case 69: + memberName = member.name.text; + break; + default: + continue; + } + if (ts.hasProperty(names, memberName)) { + error(member.symbol.valueDeclaration.name, ts.Diagnostics.Duplicate_identifier_0, memberName); + error(member.name, ts.Diagnostics.Duplicate_identifier_0, memberName); + } + else { + names[memberName] = true; + } + } + } + } function checkTypeForDuplicateIndexSignatures(node) { if (node.kind === 222) { var nodeSymbol = getSymbolOfNode(node); @@ -23203,6 +23321,7 @@ var ts; var type = getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); checkIndexConstraints(type); checkTypeForDuplicateIndexSignatures(node); + checkObjectTypeForDuplicateDeclarations(node); } } function checkArrayType(node) { @@ -23962,6 +24081,10 @@ var ts; if (node.initializer) { checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, undefined); } + if (!areDeclarationFlagsIdentical(node, symbol.valueDeclaration)) { + error(symbol.valueDeclaration.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); + error(node.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); + } } if (node.kind !== 145 && node.kind !== 144) { checkExportsOnMergedDeclarations(node); @@ -23974,6 +24097,18 @@ var ts; checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } } + function areDeclarationFlagsIdentical(left, right) { + if (ts.hasQuestionToken(left) !== ts.hasQuestionToken(right)) { + return false; + } + var interestingFlags = 8 | + 16 | + 256 | + 128 | + 64 | + 32; + return (left.flags & interestingFlags) === (right.flags & interestingFlags); + } function checkVariableDeclaration(node) { checkGrammarVariableDeclaration(node); return checkVariableLikeDeclaration(node); @@ -24524,6 +24659,7 @@ var ts; var typeWithThis = getTypeWithThisArgument(type); var staticType = getTypeOfSymbol(symbol); checkTypeParameterListsIdentical(node, symbol); + checkClassForDuplicateDeclarations(node); var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); if (baseTypeNode) { var baseTypes = getBaseTypes(type); @@ -24735,6 +24871,7 @@ var ts; checkIndexConstraints(type); } } + checkObjectTypeForDuplicateDeclarations(node); } ts.forEach(ts.getInterfaceBaseTypeNodes(node), function (heritageElement) { if (!ts.isSupportedExpressionWithTypeArguments(heritageElement)) { @@ -25489,10 +25626,8 @@ var ts; function checkSourceFileWorker(node) { var links = getNodeLinks(node); if (!(links.flags & 1)) { - if (compilerOptions.skipDefaultLibCheck) { - if (node.hasNoDefaultLib) { - return; - } + if (compilerOptions.skipLibCheck && node.isDeclarationFile || compilerOptions.skipDefaultLibCheck && node.hasNoDefaultLib) { + return; } checkGrammarSourceFile(node); potentialThisCollisions.length = 0; @@ -25861,7 +25996,7 @@ var ts; return symbol && getTypeOfSymbol(symbol); } if (ts.isBindingPattern(node)) { - return getTypeForVariableLikeDeclaration(node.parent); + return getTypeForVariableLikeDeclaration(node.parent, true); } if (isInRightSideOfImportOrExportAssignment(node)) { var symbol = getSymbolAtLocation(node); @@ -26300,7 +26435,7 @@ var ts; if (file.moduleAugmentations.length) { (augmentations || (augmentations = [])).push(file.moduleAugmentations); } - if (file.wasReferenced && file.symbol && file.symbol.globalExports) { + if (file.symbol && file.symbol.globalExports) { mergeSymbolTable(globals, file.symbol.globalExports); } }); @@ -26870,7 +27005,6 @@ var ts; if (prop.kind === 193 || name_20.kind === 140) { checkGrammarComputedPropertyName(name_20); - return "continue"; } if (prop.kind === 254 && !inDestructuring && prop.objectAssignmentInitializer) { return { value: grammarErrorOnNode(prop.equalsToken, ts.Diagnostics.can_only_be_used_in_an_object_literal_property_inside_a_destructuring_assignment) }; @@ -26900,17 +27034,21 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_20.text)) { - seen[name_20.text] = currentKind; + var effectiveName = ts.getPropertyNameForPropertyNameNode(name_20); + if (effectiveName === undefined) { + return "continue"; + } + if (!ts.hasProperty(seen, effectiveName)) { + seen[effectiveName] = currentKind; } else { - var existingKind = seen[name_20.text]; + var existingKind = seen[effectiveName]; if (currentKind === Property && existingKind === Property) { - return "continue"; + grammarErrorOnNode(name_20, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name_20)); } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_20.text] = currentKind | existingKind; + seen[effectiveName] = currentKind | existingKind; } else { return { value: grammarErrorOnNode(name_20, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name) }; @@ -35367,7 +35505,7 @@ var ts; skipTsx: true, traceEnabled: traceEnabled }; - var rootDir = options.typesRoot || (options.configFilePath ? ts.getDirectoryPath(options.configFilePath) : undefined); + var rootDir = options.typesRoot || (options.configFilePath ? ts.getDirectoryPath(options.configFilePath) : (host.getCurrentDirectory && host.getCurrentDirectory())); if (traceEnabled) { if (containingFile === undefined) { if (rootDir === undefined) { @@ -35870,12 +36008,25 @@ var ts; } } } + function getDefaultTypeDirectiveNames(rootPath) { + var localTypes = ts.combinePaths(rootPath, "types"); + var npmTypes = ts.combinePaths(rootPath, "node_modules/@types"); + var result = []; + if (ts.sys.directoryExists(localTypes)) { + result = result.concat(ts.sys.getDirectories(localTypes)); + } + if (ts.sys.directoryExists(npmTypes)) { + result = result.concat(ts.sys.getDirectories(npmTypes)); + } + return result; + } function getDefaultLibLocation() { return ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())); } var newLine = ts.getNewLineCharacter(options); var realpath = ts.sys.realpath && (function (path) { return ts.sys.realpath(path); }); return { + getDefaultTypeDirectiveNames: getDefaultTypeDirectiveNames, getSourceFile: getSourceFile, getDefaultLibLocation: getDefaultLibLocation, getDefaultLibFileName: function (options) { return ts.combinePaths(getDefaultLibLocation(), ts.getDefaultLibFileName(options)); }, @@ -35943,6 +36094,19 @@ var ts; } return resolutions; } + function getDefaultTypeDirectiveNames(options, rootFiles, host) { + if (options.types) { + return options.types; + } + if (host && host.getDefaultTypeDirectiveNames) { + var commonRoot = computeCommonSourceDirectoryOfFilenames(rootFiles, host.getCurrentDirectory(), function (f) { return host.getCanonicalFileName(f); }); + if (commonRoot) { + return host.getDefaultTypeDirectiveNames(commonRoot); + } + } + return undefined; + } + ts.getDefaultTypeDirectiveNames = getDefaultTypeDirectiveNames; function createProgram(rootNames, options, host, oldProgram) { var program; var files = []; @@ -35978,13 +36142,14 @@ var ts; var filesByName = ts.createFileMap(); var filesByNameIgnoreCase = host.useCaseSensitiveFileNames() ? ts.createFileMap(function (fileName) { return fileName.toLowerCase(); }) : undefined; if (!tryReuseStructureFromOldProgram()) { - if (options.types && options.types.length) { - var resolutions = resolveTypeReferenceDirectiveNamesWorker(options.types, undefined); - for (var i = 0; i < options.types.length; i++) { - processTypeReferenceDirective(options.types[i], resolutions[i]); + ts.forEach(rootNames, function (name) { return processRootFile(name, false); }); + var typeReferences = getDefaultTypeDirectiveNames(options, rootNames, host); + if (typeReferences) { + var resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, undefined); + for (var i = 0; i < typeReferences.length; i++) { + processTypeReferenceDirective(typeReferences[i], resolutions[i]); } } - ts.forEach(rootNames, function (name) { return processRootFile(name, false); }); if (!skipDefaultLib) { if (!options.lib) { processRootFile(host.getDefaultLibFileName(options), true); @@ -36561,9 +36726,6 @@ var ts; if (file_1 && options.forceConsistentCasingInFileNames && ts.getNormalizedAbsolutePath(file_1.fileName, currentDirectory) !== ts.getNormalizedAbsolutePath(fileName, currentDirectory)) { reportFileNamesDifferOnlyInCasingError(fileName, file_1.fileName, refFile, refPos, refEnd); } - if (file_1) { - file_1.wasReferenced = file_1.wasReferenced || isReference; - } return file_1; } var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { @@ -36576,7 +36738,6 @@ var ts; }); filesByName.set(path, file); if (file) { - file.wasReferenced = file.wasReferenced || isReference; file.path = path; if (host.useCaseSensitiveFileNames()) { var existingFile = filesByNameIgnoreCase.get(path); @@ -36677,17 +36838,7 @@ var ts; !options.noResolve && i < file.imports.length; if (shouldAddFile) { - var importedFile = findSourceFile(resolution.resolvedFileName, ts.toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), false, false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); - if (importedFile && resolution.isExternalLibraryImport) { - if (!ts.isExternalModule(importedFile) && importedFile.statements.length) { - var start_5 = ts.getTokenPosOfNode(file.imports[i], file); - fileProcessingDiagnostics.add(ts.createFileDiagnostic(file, start_5, file.imports[i].end - start_5, ts.Diagnostics.Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition, importedFile.fileName)); - } - else if (importedFile.referencedFiles.length) { - var firstRef = importedFile.referencedFiles[0]; - fileProcessingDiagnostics.add(ts.createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, ts.Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition)); - } - } + findSourceFile(resolution.resolvedFileName, ts.toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), false, false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); } } } @@ -36772,7 +36923,7 @@ var ts; } } else { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Substututions_for_pattern_0_should_be_an_array, key)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Substitutions_for_pattern_0_should_be_an_array, key)); } } } @@ -36821,13 +36972,19 @@ var ts; } else if (firstExternalModuleSourceFile && languageVersion < 2 && options.module === ts.ModuleKind.None) { var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file)); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none)); } if (options.module === ts.ModuleKind.ES6 && languageVersion < 2) { programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_es2015_when_targeting_ES5_or_lower)); } - if (outFile && options.module && !(options.module === ts.ModuleKind.AMD || options.module === ts.ModuleKind.System)) { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); + if (outFile) { + if (options.module && !(options.module === ts.ModuleKind.AMD || options.module === ts.ModuleKind.System)) { + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); + } + else if (options.module === undefined && firstExternalModuleSourceFile) { + var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system, options.out ? "out" : "outFile")); + } } if (options.outDir || options.sourceRoot || @@ -37517,7 +37674,7 @@ var ts; (function (ts) { var NavigateTo; (function (NavigateTo) { - function getNavigateToItems(program, cancellationToken, searchValue, maxResultCount) { + function getNavigateToItems(program, checker, cancellationToken, searchValue, maxResultCount) { var patternMatcher = ts.createPatternMatcher(searchValue); var rawItems = []; var baseSensitivity = { sensitivity: "base" }; @@ -37550,6 +37707,17 @@ var ts; } } }); + rawItems = ts.filter(rawItems, function (item) { + var decl = item.declaration; + if (decl.kind === 231 || decl.kind === 234 || decl.kind === 229) { + var importer = checker.getSymbolAtLocation(decl.name); + var imported = checker.getAliasedSymbol(importer); + return importer.name !== imported.name; + } + else { + return true; + } + }); rawItems.sort(compareNavigateToItems); if (maxResultCount !== undefined) { rawItems = rawItems.slice(0, maxResultCount); @@ -37892,8 +38060,12 @@ var ts; return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberSetAccessorElement); case 153: return createItem(node, "[]", ts.ScriptElementKind.indexSignatureElement); + case 224: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.enumElement); case 255: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); + case 222: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.interfaceElement); case 151: return createItem(node, "()", ts.ScriptElementKind.callSignatureElement); case 152: @@ -39263,7 +39435,7 @@ var ts; } } function findRightmostChildNodeWithTokens(children, exclusiveStartPosition) { - for (var i = exclusiveStartPosition - 1; i >= 0; --i) { + for (var i = exclusiveStartPosition - 1; i >= 0; i--) { if (nodeHasTokens(children[i])) { return children[i]; } @@ -39889,18 +40061,17 @@ var ts; if (!isStarted) { scanner.scan(); } - var t; var pos = scanner.getStartPos(); while (pos < endPos) { - var t_1 = scanner.getToken(); - if (!ts.isTrivia(t_1)) { + var t = scanner.getToken(); + if (!ts.isTrivia(t)) { break; } scanner.scan(); var item = { pos: pos, end: scanner.getStartPos(), - kind: t_1 + kind: t }; pos = scanner.getStartPos(); if (!leadingTrivia) { @@ -41550,7 +41721,7 @@ var ts; else { parts = []; var startPos = commentRange.pos; - for (var line = startLine; line < endLine; ++line) { + for (var line = startLine; line < endLine; line++) { var endOfLine = ts.getEndLinePosition(line, sourceFile); parts.push({ pos: startPos, end: endOfLine }); startPos = ts.getStartPositionOfLine(line + 1, sourceFile); @@ -41568,7 +41739,7 @@ var ts; startLine++; } var delta = indentation - nonWhitespaceColumnInFirstPart.column; - for (var i = startIndex, len = parts.length; i < len; ++i, ++startLine) { + for (var i = startIndex, len = parts.length; i < len; i++, startLine++) { var startLinePos_1 = ts.getStartPositionOfLine(startLine, sourceFile); var nonWhitespaceCharacterAndColumn = i === 0 ? nonWhitespaceColumnInFirstPart @@ -41584,7 +41755,7 @@ var ts; } } function trimTrailingWhitespacesForLines(line1, line2, range) { - for (var line = line1; line < line2; ++line) { + for (var line = line1; line < line2; line++) { var lineStartPosition = ts.getStartPositionOfLine(line, sourceFile); var lineEndPosition = ts.getEndLinePosition(line, sourceFile); if (range && (ts.isComment(range.kind) || ts.isStringOrRegularExpressionOrTemplateLiteral(range.kind)) && range.pos <= lineEndPosition && range.end > lineEndPosition) { @@ -41627,7 +41798,6 @@ var ts; } } function applyRuleEdits(rule, previousRange, previousStartLine, currentRange, currentStartLine) { - var between; switch (rule.Operation.Action) { case 1: return; @@ -41657,14 +41827,6 @@ var ts; } } } - function isSomeBlock(kind) { - switch (kind) { - case 199: - case 226: - return true; - } - return false; - } function getOpenTokenForList(node, list) { switch (node.kind) { case 148: @@ -41722,7 +41884,7 @@ var ts; internedTabsIndentation = []; } if (internedTabsIndentation[tabs] === undefined) { - internedTabsIndentation[tabs] = tabString = repeat('\t', tabs); + internedTabsIndentation[tabs] = tabString = repeat("\t", tabs); } else { tabString = internedTabsIndentation[tabs]; @@ -41747,7 +41909,7 @@ var ts; } function repeat(value, count) { var s = ""; - for (var i = 0; i < count; ++i) { + for (var i = 0; i < count; i++) { s += value; } return s; @@ -42015,7 +42177,7 @@ var ts; ts.Debug.assert(index >= 0 && index < list.length); var node = list[index]; var lineAndCharacter = getStartLineAndCharacterForNode(node, sourceFile); - for (var i = index - 1; i >= 0; --i) { + for (var i = index - 1; i >= 0; i--) { if (list[i].kind === 24) { continue; } @@ -42034,7 +42196,7 @@ var ts; function findFirstNonWhitespaceCharacterAndColumn(startPos, endPos, sourceFile, options) { var character = 0; var column = 0; - for (var pos = startPos; pos < endPos; ++pos) { + for (var pos = startPos; pos < endPos; pos++) { var ch = sourceFile.text.charCodeAt(pos); if (!ts.isWhiteSpace(ch)) { break; @@ -44005,9 +44167,9 @@ var ts; log("getCompletionData: Get previous token 1: " + (new Date().getTime() - start)); var contextToken = previousToken; if (contextToken && position <= contextToken.end && ts.isWord(contextToken.kind)) { - var start_6 = new Date().getTime(); + var start_5 = new Date().getTime(); contextToken = ts.findPrecedingToken(contextToken.getFullStart(), sourceFile); - log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_6)); + log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_5)); } var node = currentToken; var isRightOfDot = false; @@ -44234,9 +44396,9 @@ var ts; || contextToken.kind === 166 || contextToken.kind === 10 || ts.isTemplateLiteralKind(contextToken.kind)) { - var start_7 = contextToken.getStart(); + var start_6 = contextToken.getStart(); var end = contextToken.getEnd(); - if (start_7 < position && position < end) { + if (start_6 < position && position < end) { return true; } if (position === end) { @@ -45314,8 +45476,7 @@ var ts; } function getDocumentHighlights(fileName, position, filesToSearch) { synchronizeHostData(); - filesToSearch = ts.map(filesToSearch, ts.normalizeSlashes); - var sourceFilesToSearch = ts.filter(program.getSourceFiles(), function (f) { return ts.contains(filesToSearch, f.fileName); }); + var sourceFilesToSearch = ts.map(filesToSearch, function (f) { return program.getSourceFile(f); }); var sourceFile = getValidSourceFile(fileName); var node = ts.getTouchingWord(sourceFile, position); if (!node) { @@ -46498,7 +46659,8 @@ var ts; } function getNavigateToItems(searchValue, maxResultCount) { synchronizeHostData(); - return ts.NavigateTo.getNavigateToItems(program, cancellationToken, searchValue, maxResultCount); + var checker = getProgram().getTypeChecker(); + return ts.NavigateTo.getNavigateToItems(program, checker, cancellationToken, searchValue, maxResultCount); } function getEmitOutput(fileName) { synchronizeHostData(); @@ -50961,6 +51123,9 @@ var ts; LanguageServiceShimHostAdapter.prototype.getCurrentDirectory = function () { return this.shimHost.getCurrentDirectory(); }; + LanguageServiceShimHostAdapter.prototype.getDirectories = function (path) { + return this.shimHost.getDirectories(path); + }; LanguageServiceShimHostAdapter.prototype.getDefaultLibFileName = function (options) { return this.shimHost.getDefaultLibFileName(JSON.stringify(options)); }; diff --git a/lib/typescript.d.ts b/lib/typescript.d.ts index 84a06001d14..1ac624055d7 100644 --- a/lib/typescript.d.ts +++ b/lib/typescript.d.ts @@ -261,7 +261,7 @@ declare namespace ts { ModuleDeclaration = 225, ModuleBlock = 226, CaseBlock = 227, - GlobalModuleExportDeclaration = 228, + NamespaceExportDeclaration = 228, ImportEqualsDeclaration = 229, ImportDeclaration = 230, ImportClause = 231, @@ -934,7 +934,7 @@ declare namespace ts { interface NamespaceImport extends Declaration { name: Identifier; } - interface GlobalModuleExportDeclaration extends DeclarationStatement { + interface NamespaceExportDeclaration extends DeclarationStatement { name: Identifier; moduleReference: LiteralLikeNode; } @@ -1329,7 +1329,7 @@ declare namespace ts { FunctionScopedVariableExcludes = 107454, BlockScopedVariableExcludes = 107455, ParameterExcludes = 107455, - PropertyExcludes = 107455, + PropertyExcludes = 0, EnumMemberExcludes = 107455, FunctionExcludes = 106927, ClassExcludes = 899519, @@ -1554,6 +1554,7 @@ declare namespace ts { allowJs?: boolean; noImplicitUseStrict?: boolean; strictNullChecks?: boolean; + skipLibCheck?: boolean; listEmittedFiles?: boolean; lib?: string[]; types?: string[]; @@ -1627,6 +1628,7 @@ declare namespace ts { trace?(s: string): void; directoryExists?(directoryName: string): boolean; realpath?(path: string): string; + getCurrentDirectory?(): string; } interface ResolvedModule { resolvedFileName: string; @@ -1650,6 +1652,7 @@ declare namespace ts { getCancellationToken?(): CancellationToken; getDefaultLibFileName(options: CompilerOptions): string; getDefaultLibLocation?(): string; + getDefaultTypeDirectiveNames?(rootPath: string): string[]; writeFile: WriteFileCallback; getCurrentDirectory(): string; getCanonicalFileName(fileName: string): string; @@ -1693,6 +1696,7 @@ declare namespace ts { createDirectory(path: string): void; getExecutingFilePath(): string; getCurrentDirectory(): string; + getDirectories(path: string): string[]; readDirectory(path: string, extension?: string, exclude?: string[]): string[]; getModifiedTime?(path: string): Date; createHash?(data: string): string; @@ -1812,6 +1816,7 @@ declare namespace ts { function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; + function getDefaultTypeDirectiveNames(options: CompilerOptions, rootFiles: string[], host: CompilerHost): string[]; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program): Program; } declare namespace ts { @@ -2345,26 +2350,55 @@ declare namespace ts { namespace ScriptElementKind { const unknown: string; const warning: string; + /** predefined type (void) or keyword (class) */ const keyword: string; + /** top level script node */ const scriptElement: string; + /** module foo {} */ const moduleElement: string; + /** class X {} */ const classElement: string; + /** var x = class X {} */ const localClassElement: string; + /** interface Y {} */ const interfaceElement: string; + /** type T = ... */ const typeElement: string; + /** enum E */ const enumElement: string; + /** + * Inside module and script only + * const v = .. + */ const variableElement: string; + /** Inside function */ const localVariableElement: string; + /** + * Inside module and script only + * function f() { } + */ const functionElement: string; + /** Inside function */ const localFunctionElement: string; + /** class X { [public|private]* foo() {} } */ const memberFunctionElement: string; + /** class X { [public|private]* [get|set] foo:number; } */ const memberGetAccessorElement: string; const memberSetAccessorElement: string; + /** + * class X { [public|private]* foo:number; } + * interface Y { foo:number; } + */ const memberVariableElement: string; + /** class X { constructor() { } } */ const constructorImplementationElement: string; + /** interface Y { ():number; } */ const callSignatureElement: string; + /** interface Y { []:number; } */ const indexSignatureElement: string; + /** interface Y { new():Y; } */ const constructSignatureElement: string; + /** function foo(*Y*: string) */ const parameterElement: string; const typeParameterElement: string; const primitiveType: string; diff --git a/lib/typescript.js b/lib/typescript.js index e78eda7b0bb..19fffd35501 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -271,7 +271,7 @@ var ts; SyntaxKind[SyntaxKind["ModuleDeclaration"] = 225] = "ModuleDeclaration"; SyntaxKind[SyntaxKind["ModuleBlock"] = 226] = "ModuleBlock"; SyntaxKind[SyntaxKind["CaseBlock"] = 227] = "CaseBlock"; - SyntaxKind[SyntaxKind["GlobalModuleExportDeclaration"] = 228] = "GlobalModuleExportDeclaration"; + SyntaxKind[SyntaxKind["NamespaceExportDeclaration"] = 228] = "NamespaceExportDeclaration"; SyntaxKind[SyntaxKind["ImportEqualsDeclaration"] = 229] = "ImportEqualsDeclaration"; SyntaxKind[SyntaxKind["ImportDeclaration"] = 230] = "ImportDeclaration"; SyntaxKind[SyntaxKind["ImportClause"] = 231] = "ImportClause"; @@ -561,7 +561,7 @@ var ts; // they can not merge with anything in the value space SymbolFlags[SymbolFlags["BlockScopedVariableExcludes"] = 107455] = "BlockScopedVariableExcludes"; SymbolFlags[SymbolFlags["ParameterExcludes"] = 107455] = "ParameterExcludes"; - SymbolFlags[SymbolFlags["PropertyExcludes"] = 107455] = "PropertyExcludes"; + SymbolFlags[SymbolFlags["PropertyExcludes"] = 0] = "PropertyExcludes"; SymbolFlags[SymbolFlags["EnumMemberExcludes"] = 107455] = "EnumMemberExcludes"; SymbolFlags[SymbolFlags["FunctionExcludes"] = 106927] = "FunctionExcludes"; SymbolFlags[SymbolFlags["ClassExcludes"] = 899519] = "ClassExcludes"; @@ -1841,6 +1841,10 @@ var ts; } return result.sort(); } + function getDirectories(path) { + var folder = fso.GetFolder(path); + return getNames(folder.subfolders); + } function readDirectory(path, extension, exclude) { var result = []; exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); @@ -1895,6 +1899,7 @@ var ts; getCurrentDirectory: function () { return new ActiveXObject("WScript.Shell").CurrentDirectory; }, + getDirectories: getDirectories, readDirectory: readDirectory, exit: function (exitCode) { try { @@ -2057,6 +2062,9 @@ var ts; function directoryExists(path) { return fileSystemEntryExists(path, 1 /* Directory */); } + function getDirectories(path) { + return ts.filter(_fs.readdirSync(path), function (p) { return fileSystemEntryExists(ts.combinePaths(path, p), 1 /* Directory */); }); + } function readDirectory(path, extension, exclude) { var result = []; exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); @@ -2157,6 +2165,7 @@ var ts; getCurrentDirectory: function () { return process.cwd(); }, + getDirectories: getDirectories, readDirectory: readDirectory, getModifiedTime: function (path) { try { @@ -2209,6 +2218,7 @@ var ts; createDirectory: ChakraHost.createDirectory, getExecutingFilePath: function () { return ChakraHost.executingFile; }, getCurrentDirectory: function () { return ChakraHost.currentDirectory; }, + getDirectories: ChakraHost.getDirectories, readDirectory: ChakraHost.readDirectory, exit: ChakraHost.quit, realpath: realpath @@ -2347,7 +2357,7 @@ var ts; or_expected: { code: 1144, category: ts.DiagnosticCategory.Error, key: "or_expected_1144", message: "'{' or ';' expected." }, Declaration_expected: { code: 1146, category: ts.DiagnosticCategory.Error, key: "Declaration_expected_1146", message: "Declaration expected." }, Import_declarations_in_a_namespace_cannot_reference_a_module: { code: 1147, category: ts.DiagnosticCategory.Error, key: "Import_declarations_in_a_namespace_cannot_reference_a_module_1147", message: "Import declarations in a namespace cannot reference a module." }, - Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting__1148", message: "Cannot compile modules unless the '--module' flag is provided with a valid module type. Consider setting the 'module' compiler option in a 'tsconfig.json' file." }, + Cannot_use_imports_exports_or_module_augmentations_when_module_is_none: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot_use_imports_exports_or_module_augmentations_when_module_is_none_1148", message: "Cannot use imports, exports, or module augmentations when '--module' is 'none'." }, File_name_0_differs_from_already_included_file_name_1_only_in_casing: { code: 1149, category: ts.DiagnosticCategory.Error, key: "File_name_0_differs_from_already_included_file_name_1_only_in_casing_1149", message: "File name '{0}' differs from already included file name '{1}' only in casing" }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: ts.DiagnosticCategory.Error, key: "new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead_1150", message: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, const_declarations_must_be_initialized: { code: 1155, category: ts.DiagnosticCategory.Error, key: "const_declarations_must_be_initialized_1155", message: "'const' declarations must be initialized" }, @@ -2717,6 +2727,8 @@ var ts; this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation: { code: 2683, category: ts.DiagnosticCategory.Error, key: "this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_2683", message: "'this' implicitly has type 'any' because it does not have a type annotation." }, The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1: { code: 2684, category: ts.DiagnosticCategory.Error, key: "The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1_2684", message: "The 'this' context of type '{0}' is not assignable to method's 'this' of type '{1}'." }, The_this_types_of_each_signature_are_incompatible: { code: 2685, category: ts.DiagnosticCategory.Error, key: "The_this_types_of_each_signature_are_incompatible_2685", message: "The 'this' types of each signature are incompatible." }, + Identifier_0_must_be_imported_from_a_module: { code: 2686, category: ts.DiagnosticCategory.Error, key: "Identifier_0_must_be_imported_from_a_module_2686", message: "Identifier '{0}' must be imported from a module" }, + All_declarations_of_0_must_have_identical_modifiers: { code: 2687, category: ts.DiagnosticCategory.Error, key: "All_declarations_of_0_must_have_identical_modifiers_2687", message: "All declarations of '{0}' must have identical modifiers." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import_declaration_0_is_using_private_name_1_4000", message: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: ts.DiagnosticCategory.Error, key: "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", message: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: ts.DiagnosticCategory.Error, key: "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", message: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -2810,7 +2822,7 @@ var ts; Option_paths_cannot_be_used_without_specifying_baseUrl_option: { code: 5060, category: ts.DiagnosticCategory.Error, key: "Option_paths_cannot_be_used_without_specifying_baseUrl_option_5060", message: "Option 'paths' cannot be used without specifying '--baseUrl' option." }, Pattern_0_can_have_at_most_one_Asterisk_character: { code: 5061, category: ts.DiagnosticCategory.Error, key: "Pattern_0_can_have_at_most_one_Asterisk_character_5061", message: "Pattern '{0}' can have at most one '*' character" }, Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character: { code: 5062, category: ts.DiagnosticCategory.Error, key: "Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character_5062", message: "Substitution '{0}' in pattern '{1}' in can have at most one '*' character" }, - Substututions_for_pattern_0_should_be_an_array: { code: 5063, category: ts.DiagnosticCategory.Error, key: "Substututions_for_pattern_0_should_be_an_array_5063", message: "Substututions for pattern '{0}' should be an array." }, + Substitutions_for_pattern_0_should_be_an_array: { code: 5063, category: ts.DiagnosticCategory.Error, key: "Substitutions_for_pattern_0_should_be_an_array_5063", message: "Substitutions for pattern '{0}' should be an array." }, Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2: { code: 5064, category: ts.DiagnosticCategory.Error, key: "Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2_5064", message: "Substitution '{0}' for pattern '{1}' has incorrect type, expected 'string', got '{2}'." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: ts.DiagnosticCategory.Message, key: "Concatenate_and_emit_output_to_single_file_6001", message: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: ts.DiagnosticCategory.Message, key: "Generates_corresponding_d_ts_file_6002", message: "Generates corresponding '.d.ts' file." }, @@ -2823,6 +2835,7 @@ var ts; Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do_not_emit_comments_to_output_6009", message: "Do not emit comments to output." }, Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do_not_emit_outputs_6010", message: "Do not emit outputs." }, Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking: { code: 6011, category: ts.DiagnosticCategory.Message, key: "Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typech_6011", message: "Allow default imports from modules with no default export. This does not affect code emit, just typechecking." }, + Skip_type_checking_of_declaration_files: { code: 6012, category: ts.DiagnosticCategory.Message, key: "Skip_type_checking_of_declaration_files_6012", message: "Skip type checking of declaration files." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015_6015", message: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015'" }, Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015: { code: 6016, category: ts.DiagnosticCategory.Message, key: "Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015_6016", message: "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'" }, Print_this_message: { code: 6017, category: ts.DiagnosticCategory.Message, key: "Print_this_message_6017", message: "Print this message." }, @@ -2924,6 +2937,7 @@ var ts; Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set: { code: 6128, category: ts.DiagnosticCategory.Message, key: "Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set_6128", message: "======== Resolving type reference directive '{0}', containing file not set, root directory not set. ========" }, The_config_file_0_found_doesn_t_contain_any_source_files: { code: 6129, category: ts.DiagnosticCategory.Error, key: "The_config_file_0_found_doesn_t_contain_any_source_files_6129", message: "The config file '{0}' found doesn't contain any source files." }, Resolving_real_path_for_0_result_1: { code: 6130, category: ts.DiagnosticCategory.Message, key: "Resolving_real_path_for_0_result_1_6130", message: "Resolving real path for '{0}', result '{1}'" }, + Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { code: 6131, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system_6131", message: "Cannot compile modules using option '{0}' unless the '--module' flag is 'amd' or 'system'." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable_0_implicitly_has_an_1_type_7005", message: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter_0_implicitly_has_an_1_type_7006", message: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member_0_implicitly_has_an_1_type_7008", message: "Member '{0}' implicitly has an '{1}' type." }, @@ -6172,7 +6186,7 @@ var ts; // export default ... function isAliasSymbolDeclaration(node) { return node.kind === 229 /* ImportEqualsDeclaration */ || - node.kind === 228 /* GlobalModuleExportDeclaration */ || + node.kind === 228 /* NamespaceExportDeclaration */ || node.kind === 231 /* ImportClause */ && !!node.name || node.kind === 232 /* NamespaceImport */ || node.kind === 234 /* ImportSpecifier */ || @@ -6301,7 +6315,7 @@ var ts; } ts.isWellKnownSymbolSyntactically = isWellKnownSymbolSyntactically; function getPropertyNameForPropertyNameNode(name) { - if (name.kind === 69 /* Identifier */ || name.kind === 9 /* StringLiteral */ || name.kind === 8 /* NumericLiteral */) { + if (name.kind === 69 /* Identifier */ || name.kind === 9 /* StringLiteral */ || name.kind === 8 /* NumericLiteral */ || name.kind === 142 /* Parameter */) { return name.text; } if (name.kind === 140 /* ComputedPropertyName */) { @@ -7773,7 +7787,7 @@ var ts; case 231 /* ImportClause */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.namedBindings); - case 228 /* GlobalModuleExportDeclaration */: + case 228 /* NamespaceExportDeclaration */: return visitNode(cbNode, node.name); case 232 /* NamespaceImport */: return visitNode(cbNode, node.name); @@ -12182,7 +12196,7 @@ var ts; return nextToken() === 39 /* SlashToken */; } function parseGlobalModuleExportDeclaration(fullStart, decorators, modifiers) { - var exportDeclaration = createNode(228 /* GlobalModuleExportDeclaration */, fullStart); + var exportDeclaration = createNode(228 /* NamespaceExportDeclaration */, fullStart); exportDeclaration.decorators = decorators; exportDeclaration.modifiers = modifiers; parseExpected(116 /* AsKeyword */); @@ -15018,10 +15032,10 @@ var ts; case 145 /* PropertyDeclaration */: case 144 /* PropertySignature */: case 266 /* JSDocRecordMember */: - return bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 107455 /* PropertyExcludes */); + return bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 0 /* PropertyExcludes */); case 253 /* PropertyAssignment */: case 254 /* ShorthandPropertyAssignment */: - return bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 107455 /* PropertyExcludes */); + return bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 0 /* PropertyExcludes */); case 255 /* EnumMember */: return bindPropertyOrMethodOrAccessor(node, 8 /* EnumMember */, 107455 /* EnumMemberExcludes */); case 247 /* JsxSpreadAttribute */: @@ -15037,7 +15051,7 @@ var ts; // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes // so that it will conflict with any other object literal members with the same // name. - return bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), ts.isObjectLiteralMethod(node) ? 107455 /* PropertyExcludes */ : 99263 /* MethodExcludes */); + return bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), ts.isObjectLiteralMethod(node) ? 0 /* PropertyExcludes */ : 99263 /* MethodExcludes */); case 220 /* FunctionDeclaration */: return bindFunctionDeclaration(node); case 148 /* Constructor */: @@ -15081,8 +15095,8 @@ var ts; case 234 /* ImportSpecifier */: case 238 /* ExportSpecifier */: return declareSymbolAndAddToSymbolTable(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */); - case 228 /* GlobalModuleExportDeclaration */: - return bindGlobalModuleExportDeclaration(node); + case 228 /* NamespaceExportDeclaration */: + return bindNamespaceExportDeclaration(node); case 231 /* ImportClause */: return bindImportClause(node); case 236 /* ExportDeclaration */: @@ -15120,14 +15134,14 @@ var ts; } else if (boundExpression.kind === 69 /* Identifier */ && node.kind === 235 /* ExportAssignment */) { // An export default clause with an identifier exports all meanings of that identifier - declareSymbol(container.symbol.exports, container.symbol, node, 8388608 /* Alias */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); + declareSymbol(container.symbol.exports, container.symbol, node, 8388608 /* Alias */, 0 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); } else { // An export default clause with an expression exports a value - declareSymbol(container.symbol.exports, container.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); + declareSymbol(container.symbol.exports, container.symbol, node, 4 /* Property */, 0 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); } } - function bindGlobalModuleExportDeclaration(node) { + function bindNamespaceExportDeclaration(node) { if (node.modifiers && node.modifiers.length) { file.bindDiagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.Modifiers_cannot_appear_here)); } @@ -15186,7 +15200,7 @@ var ts; if (container.kind === 179 /* FunctionExpression */ || container.kind === 220 /* FunctionDeclaration */) { container.symbol.members = container.symbol.members || {}; // It's acceptable for multiple 'this' assignments of the same identifier to occur - declareSymbol(container.symbol.members, container.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */ & ~4 /* Property */); + declareSymbol(container.symbol.members, container.symbol, node, 4 /* Property */, 0 /* PropertyExcludes */ & ~4 /* Property */); } } function bindPrototypePropertyAssignment(node) { @@ -15209,7 +15223,7 @@ var ts; funcSymbol.members = {}; } // Declare the method/property - declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, 4 /* Property */, 107455 /* PropertyExcludes */); + declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, 4 /* Property */, 0 /* PropertyExcludes */); } function bindCallExpression(node) { // We're only inspecting call expressions to detect CommonJS modules, so we can skip @@ -15310,7 +15324,7 @@ var ts; // containing class. if (ts.isParameterPropertyDeclaration(node)) { var classDeclaration = node.parent.parent; - declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */); + declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */, 0 /* PropertyExcludes */); } } function bindFunctionDeclaration(node) { @@ -15696,7 +15710,7 @@ var ts; if (flags & 1 /* FunctionScopedVariable */) result |= 107454 /* FunctionScopedVariableExcludes */; if (flags & 4 /* Property */) - result |= 107455 /* PropertyExcludes */; + result |= 0 /* PropertyExcludes */; if (flags & 8 /* EnumMember */) result |= 107455 /* EnumMemberExcludes */; if (flags & 16 /* Function */) @@ -15982,6 +15996,7 @@ var ts; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; + var isInExternalModule = false; loop: while (location) { // Locals of a source file are not in scope (because they get merged into the global symbol table) if (location.locals && !isGlobalSourceFile(location)) { @@ -16024,6 +16039,7 @@ var ts; case 256 /* SourceFile */: if (!ts.isExternalOrCommonJsModule(location)) break; + isInExternalModule = true; case 225 /* ModuleDeclaration */: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 256 /* SourceFile */ || ts.isAmbientModule(location)) { @@ -16207,6 +16223,13 @@ var ts; checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation); } } + // If we're in an external module, we can't reference symbols created from UMD export declarations + if (result && isInExternalModule) { + var decls = result.declarations; + if (decls && decls.length === 1 && decls[0].kind === 228 /* NamespaceExportDeclaration */) { + error(errorLocation, ts.Diagnostics.Identifier_0_must_be_imported_from_a_module, name); + } + } } return result; } @@ -16409,7 +16432,7 @@ var ts; return getTargetOfExportSpecifier(node); case 235 /* ExportAssignment */: return getTargetOfExportAssignment(node); - case 228 /* GlobalModuleExportDeclaration */: + case 228 /* NamespaceExportDeclaration */: return getTargetOfGlobalModuleExportDeclaration(node); } } @@ -17883,7 +17906,7 @@ var ts; // assigned by contextual typing. function getTypeForBindingElementParent(node) { var symbol = getSymbolOfNode(node); - return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node); + return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ false); } function getTextOfPropertyName(name) { switch (name.kind) { @@ -18009,7 +18032,7 @@ var ts; return strictNullChecks && optional ? addNullableKind(type, 32 /* Undefined */) : type; } // Return the inferred type for a variable, parameter, or property declaration - function getTypeForVariableLikeDeclaration(declaration) { + function getTypeForVariableLikeDeclaration(declaration, includeOptionality) { if (declaration.flags & 134217728 /* JavaScriptFile */) { // If this is a variable in a JavaScript file, then use the JSDoc type (if it has // one as its type), otherwise fallback to the below standard TS codepaths to @@ -18035,7 +18058,7 @@ var ts; } // Use type from type annotation if one is present if (declaration.type) { - return addOptionality(getTypeFromTypeNode(declaration.type), /*optional*/ !!declaration.questionToken); + return addOptionality(getTypeFromTypeNode(declaration.type), /*optional*/ declaration.questionToken && includeOptionality); } if (declaration.kind === 142 /* Parameter */) { var func = declaration.parent; @@ -18056,12 +18079,12 @@ var ts; ? getContextuallyTypedThisType(func) : getContextuallyTypedParameterType(declaration); if (type) { - return addOptionality(type, /*optional*/ !!declaration.questionToken); + return addOptionality(type, /*optional*/ declaration.questionToken && includeOptionality); } } // Use the type of the initializer expression if one is present if (declaration.initializer) { - return addOptionality(checkExpressionCached(declaration.initializer), /*optional*/ !!declaration.questionToken); + return addOptionality(checkExpressionCached(declaration.initializer), /*optional*/ declaration.questionToken && includeOptionality); } // If it is a short-hand property assignment, use the type of the identifier if (declaration.kind === 254 /* ShorthandPropertyAssignment */) { @@ -18155,7 +18178,7 @@ var ts; // binding pattern [x, s = ""]. Because the contextual type is a tuple type, the resulting type of [1, "one"] is the // tuple type [number, string]. Thus, the type inferred for 'x' is number and the type inferred for 's' is string. function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) { - var type = getTypeForVariableLikeDeclaration(declaration); + var type = getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true); if (type) { if (reportErrors) { reportErrorsFromWidening(declaration, type); @@ -20719,7 +20742,7 @@ var ts; return isIdenticalTo(source, target); } if (!(target.flags & 134217728 /* Never */)) { - if (target.flags & 1 /* Any */) + if (target.flags & 1 /* Any */ || source.flags & 134217728 /* Never */) return -1 /* True */; if (source.flags & 32 /* Undefined */) { if (!strictNullChecks || target.flags & (32 /* Undefined */ | 16 /* Void */) || source === emptyArrayElementType) @@ -20739,7 +20762,7 @@ var ts; if (source.flags & 256 /* StringLiteral */ && target === stringType) return -1 /* True */; if (relation === assignableRelation || relation === comparableRelation) { - if (source.flags & (1 /* Any */ | 134217728 /* Never */)) + if (source.flags & 1 /* Any */) return -1 /* True */; if (source === numberType && target.flags & 128 /* Enum */) return -1 /* True */; @@ -21634,41 +21657,52 @@ var ts; getSignaturesOfType(type, 0 /* Call */).length === 0 && getSignaturesOfType(type, 1 /* Construct */).length === 0; } + function createTransientSymbol(source, type) { + var symbol = createSymbol(source.flags | 67108864 /* Transient */, source.name); + symbol.declarations = source.declarations; + symbol.parent = source.parent; + symbol.type = type; + symbol.target = source; + if (source.valueDeclaration) { + symbol.valueDeclaration = source.valueDeclaration; + } + return symbol; + } + function transformTypeOfMembers(type, f) { + var members = {}; + for (var _i = 0, _a = getPropertiesOfObjectType(type); _i < _a.length; _i++) { + var property = _a[_i]; + var original = getTypeOfSymbol(property); + var updated = f(original); + members[property.name] = updated === original ? property : createTransientSymbol(property, updated); + } + ; + return members; + } + /** + * If the the provided object literal is subject to the excess properties check, + * create a new that is exempt. Recursively mark object literal members as exempt. + * Leave signatures alone since they are not subject to the check. + */ function getRegularTypeOfObjectLiteral(type) { - if (type.flags & 1048576 /* FreshObjectLiteral */) { - var regularType = type.regularType; - if (!regularType) { - regularType = createType(type.flags & ~1048576 /* FreshObjectLiteral */); - regularType.symbol = type.symbol; - regularType.members = type.members; - regularType.properties = type.properties; - regularType.callSignatures = type.callSignatures; - regularType.constructSignatures = type.constructSignatures; - regularType.stringIndexInfo = type.stringIndexInfo; - regularType.numberIndexInfo = type.numberIndexInfo; - type.regularType = regularType; - } + if (!(type.flags & 1048576 /* FreshObjectLiteral */)) { + return type; + } + var regularType = type.regularType; + if (regularType) { return regularType; } - return type; + var resolved = type; + var members = transformTypeOfMembers(type, getRegularTypeOfObjectLiteral); + var regularNew = createAnonymousType(resolved.symbol, members, resolved.callSignatures, resolved.constructSignatures, resolved.stringIndexInfo, resolved.numberIndexInfo); + regularNew.flags = resolved.flags & ~1048576 /* FreshObjectLiteral */; + type.regularType = regularNew; + return regularNew; } function getWidenedTypeOfObjectLiteral(type) { - var properties = getPropertiesOfObjectType(type); - var members = {}; - ts.forEach(properties, function (p) { - var propType = getTypeOfSymbol(p); - var widenedType = getWidenedType(propType); - if (propType !== widenedType) { - var symbol = createSymbol(p.flags | 67108864 /* Transient */, p.name); - symbol.declarations = p.declarations; - symbol.parent = p.parent; - symbol.type = widenedType; - symbol.target = p; - if (p.valueDeclaration) - symbol.valueDeclaration = p.valueDeclaration; - p = symbol; - } - members[p.name] = p; + var members = transformTypeOfMembers(type, function (prop) { + var widened = getWidenedType(prop); + return prop === widened ? prop : widened; }); var stringIndexInfo = getIndexInfoOfType(type, 0 /* String */); var numberIndexInfo = getIndexInfoOfType(type, 1 /* Number */); @@ -23224,7 +23258,7 @@ var ts; } return nodeCheckFlag === 512 /* SuperStatic */ ? getBaseConstructorTypeOfClass(classType) - : baseClassType; + : getTypeWithThisArgument(baseClassType, classType.thisType); function isLegalUsageOfSuperExpression(container) { if (!container) { return false; @@ -25936,7 +25970,7 @@ var ts; var types = void 0; var funcIsGenerator = !!func.asteriskToken; if (funcIsGenerator) { - types = checkAndAggregateYieldOperandTypes(func.body, contextualMapper); + types = checkAndAggregateYieldOperandTypes(func, contextualMapper); if (types.length === 0) { var iterableIteratorAny = createIterableIteratorType(anyType); if (compilerOptions.noImplicitAny) { @@ -25946,8 +25980,7 @@ var ts; } } else { - var hasImplicitReturn = !!(func.flags & 32768 /* HasImplicitReturn */); - types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper, isAsync, hasImplicitReturn); + types = checkAndAggregateReturnExpressionTypes(func, contextualMapper); if (!types) { return neverType; } @@ -26001,9 +26034,9 @@ var ts; return widenedType; } } - function checkAndAggregateYieldOperandTypes(body, contextualMapper) { + function checkAndAggregateYieldOperandTypes(func, contextualMapper) { var aggregatedTypes = []; - ts.forEachYieldExpression(body, function (yieldExpression) { + ts.forEachYieldExpression(func.body, function (yieldExpression) { var expr = yieldExpression.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); @@ -26018,10 +26051,12 @@ var ts; }); return aggregatedTypes; } - function checkAndAggregateReturnExpressionTypes(body, contextualMapper, isAsync, hasImplicitReturn) { + function checkAndAggregateReturnExpressionTypes(func, contextualMapper) { + var isAsync = ts.isAsyncFunctionLike(func); var aggregatedTypes = []; - var hasOmittedExpressions = false; - ts.forEachReturnStatement(body, function (returnStatement) { + var hasReturnWithNoExpression = !!(func.flags & 32768 /* HasImplicitReturn */); + var hasReturnOfTypeNever = false; + ts.forEachReturnStatement(func.body, function (returnStatement) { var expr = returnStatement.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); @@ -26030,20 +26065,24 @@ var ts; // Promise/A+ compatible implementation will always assimilate any foreign promise, so the // return type of the body should be unwrapped to its awaited type, which should be wrapped in // the native Promise type by the caller. - type = checkAwaitedType(type, body.parent, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); + type = checkAwaitedType(type, func, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); } - if (type !== neverType && !ts.contains(aggregatedTypes, type)) { + if (type === neverType) { + hasReturnOfTypeNever = true; + } + else if (!ts.contains(aggregatedTypes, type)) { aggregatedTypes.push(type); } } else { - hasOmittedExpressions = true; + hasReturnWithNoExpression = true; } }); - if (aggregatedTypes.length === 0 && !hasOmittedExpressions && !hasImplicitReturn) { + if (aggregatedTypes.length === 0 && !hasReturnWithNoExpression && (hasReturnOfTypeNever || + func.kind === 179 /* FunctionExpression */ || func.kind === 180 /* ArrowFunction */)) { return undefined; } - if (strictNullChecks && aggregatedTypes.length && (hasOmittedExpressions || hasImplicitReturn)) { + if (strictNullChecks && aggregatedTypes.length && hasReturnWithNoExpression) { if (!ts.contains(aggregatedTypes, undefinedType)) { aggregatedTypes.push(undefinedType); } @@ -26215,8 +26254,14 @@ var ts; if (symbol.flags & 4 /* Property */ && (expr.kind === 172 /* PropertyAccessExpression */ || expr.kind === 173 /* ElementAccessExpression */) && expr.expression.kind === 97 /* ThisKeyword */) { + // Look for if this is the constructor for the class that `symbol` is a property of. var func = ts.getContainingFunction(expr); - return !(func && func.kind === 148 /* Constructor */ && func.parent === symbol.valueDeclaration.parent); + if (!(func && func.kind === 148 /* Constructor */)) + return true; + // If func.parent is a class and symbol is a (readonly) property of that class, or + // if func is a constructor and symbol is a (readonly) parameter property declared in it, + // then symbol is writeable here. + return !(func.parent === symbol.valueDeclaration.parent || func === symbol.valueDeclaration.parent); } return true; } @@ -27148,6 +27193,79 @@ var ts; } } } + function checkClassForDuplicateDeclarations(node) { + var getter = 1, setter = 2, property = getter | setter; + var instanceNames = {}; + var staticNames = {}; + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind === 148 /* Constructor */) { + for (var _b = 0, _c = member.parameters; _b < _c.length; _b++) { + var param = _c[_b]; + if (ts.isParameterPropertyDeclaration(param)) { + addName(instanceNames, param.name, param.name.text, property); + } + } + } + else { + var static = ts.forEach(member.modifiers, function (m) { return m.kind === 113 /* StaticKeyword */; }); + var names = static ? staticNames : instanceNames; + var memberName = member.name && ts.getPropertyNameForPropertyNameNode(member.name); + if (memberName) { + switch (member.kind) { + case 149 /* GetAccessor */: + addName(names, member.name, memberName, getter); + break; + case 150 /* SetAccessor */: + addName(names, member.name, memberName, setter); + break; + case 145 /* PropertyDeclaration */: + addName(names, member.name, memberName, property); + break; + } + } + } + } + function addName(names, location, name, meaning) { + if (ts.hasProperty(names, name)) { + var prev = names[name]; + if (prev & meaning) { + error(location, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(location)); + } + else { + names[name] = prev | meaning; + } + } + else { + names[name] = meaning; + } + } + } + function checkObjectTypeForDuplicateDeclarations(node) { + var names = {}; + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind == 144 /* PropertySignature */) { + var memberName = void 0; + switch (member.name.kind) { + case 9 /* StringLiteral */: + case 8 /* NumericLiteral */: + case 69 /* Identifier */: + memberName = member.name.text; + break; + default: + continue; + } + if (ts.hasProperty(names, memberName)) { + error(member.symbol.valueDeclaration.name, ts.Diagnostics.Duplicate_identifier_0, memberName); + error(member.name, ts.Diagnostics.Duplicate_identifier_0, memberName); + } + else { + names[memberName] = true; + } + } + } + } function checkTypeForDuplicateIndexSignatures(node) { if (node.kind === 222 /* InterfaceDeclaration */) { var nodeSymbol = getSymbolOfNode(node); @@ -27399,6 +27517,7 @@ var ts; var type = getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); checkIndexConstraints(type); checkTypeForDuplicateIndexSignatures(node); + checkObjectTypeForDuplicateDeclarations(node); } } function checkArrayType(node) { @@ -28444,6 +28563,10 @@ var ts; if (node.initializer) { checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, /*headMessage*/ undefined); } + if (!areDeclarationFlagsIdentical(node, symbol.valueDeclaration)) { + error(symbol.valueDeclaration.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); + error(node.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); + } } if (node.kind !== 145 /* PropertyDeclaration */ && node.kind !== 144 /* PropertySignature */) { // We know we don't have a binding pattern or computed name here @@ -28457,6 +28580,18 @@ var ts; checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } } + function areDeclarationFlagsIdentical(left, right) { + if (ts.hasQuestionToken(left) !== ts.hasQuestionToken(right)) { + return false; + } + var interestingFlags = 8 /* Private */ | + 16 /* Protected */ | + 256 /* Async */ | + 128 /* Abstract */ | + 64 /* Readonly */ | + 32 /* Static */; + return (left.flags & interestingFlags) === (right.flags & interestingFlags); + } function checkVariableDeclaration(node) { checkGrammarVariableDeclaration(node); return checkVariableLikeDeclaration(node); @@ -29150,6 +29285,7 @@ var ts; var typeWithThis = getTypeWithThisArgument(type); var staticType = getTypeOfSymbol(symbol); checkTypeParameterListsIdentical(node, symbol); + checkClassForDuplicateDeclarations(node); var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); if (baseTypeNode) { var baseTypes = getBaseTypes(type); @@ -29398,6 +29534,7 @@ var ts; checkIndexConstraints(type); } } + checkObjectTypeForDuplicateDeclarations(node); } ts.forEach(ts.getInterfaceBaseTypeNodes(node), function (heritageElement) { if (!ts.isSupportedExpressionWithTypeArguments(heritageElement)) { @@ -30241,14 +30378,11 @@ var ts; function checkSourceFileWorker(node) { var links = getNodeLinks(node); if (!(links.flags & 1 /* TypeChecked */)) { - // Check whether the file has declared it is the default lib, - // and whether the user has specifically chosen to avoid checking it. - if (compilerOptions.skipDefaultLibCheck) { - // If the user specified '--noLib' and a file has a '/// ', - // then we should treat that file as a default lib. - if (node.hasNoDefaultLib) { - return; - } + // If skipLibCheck is enabled, skip type checking if file is a declaration file. + // If skipDefaultLibCheck is enabled, skip type checking if file contains a + // '/// ' directive. + if (compilerOptions.skipLibCheck && node.isDeclarationFile || compilerOptions.skipDefaultLibCheck && node.hasNoDefaultLib) { + return; } // Grammar checking checkGrammarSourceFile(node); @@ -30665,7 +30799,7 @@ var ts; return symbol && getTypeOfSymbol(symbol); } if (ts.isBindingPattern(node)) { - return getTypeForVariableLikeDeclaration(node.parent); + return getTypeForVariableLikeDeclaration(node.parent, /*includeOptionality*/ true); } if (isInRightSideOfImportOrExportAssignment(node)) { var symbol = getSymbolAtLocation(node); @@ -31204,7 +31338,7 @@ var ts; if (file.moduleAugmentations.length) { (augmentations || (augmentations = [])).push(file.moduleAugmentations); } - if (file.wasReferenced && file.symbol && file.symbol.globalExports) { + if (file.symbol && file.symbol.globalExports) { mergeSymbolTable(globals, file.symbol.globalExports); } }); @@ -31787,7 +31921,6 @@ var ts; name_20.kind === 140 /* ComputedPropertyName */) { // If the name is not a ComputedPropertyName, the grammar checking will skip it checkGrammarComputedPropertyName(name_20); - return "continue"; } if (prop.kind === 254 /* ShorthandPropertyAssignment */ && !inDestructuring && prop.objectAssignmentInitializer) { // having objectAssignmentInitializer is only valid in ObjectAssignmentPattern @@ -31829,17 +31962,21 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_20.text)) { - seen[name_20.text] = currentKind; + var effectiveName = ts.getPropertyNameForPropertyNameNode(name_20); + if (effectiveName === undefined) { + return "continue"; + } + if (!ts.hasProperty(seen, effectiveName)) { + seen[effectiveName] = currentKind; } else { - var existingKind = seen[name_20.text]; + var existingKind = seen[effectiveName]; if (currentKind === Property && existingKind === Property) { - return "continue"; + grammarErrorOnNode(name_20, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name_20)); } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_20.text] = currentKind | existingKind; + seen[effectiveName] = currentKind | existingKind; } else { return { value: grammarErrorOnNode(name_20, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name) }; @@ -41638,8 +41775,8 @@ var ts; skipTsx: true, traceEnabled: traceEnabled }; - // use typesRoot and fallback to directory that contains tsconfig if typesRoot is not set - var rootDir = options.typesRoot || (options.configFilePath ? ts.getDirectoryPath(options.configFilePath) : undefined); + // use typesRoot and fallback to directory that contains tsconfig or current directory if typesRoot is not set + var rootDir = options.typesRoot || (options.configFilePath ? ts.getDirectoryPath(options.configFilePath) : (host.getCurrentDirectory && host.getCurrentDirectory())); if (traceEnabled) { if (containingFile === undefined) { if (rootDir === undefined) { @@ -42229,12 +42366,25 @@ var ts; } } } + function getDefaultTypeDirectiveNames(rootPath) { + var localTypes = ts.combinePaths(rootPath, "types"); + var npmTypes = ts.combinePaths(rootPath, "node_modules/@types"); + var result = []; + if (ts.sys.directoryExists(localTypes)) { + result = result.concat(ts.sys.getDirectories(localTypes)); + } + if (ts.sys.directoryExists(npmTypes)) { + result = result.concat(ts.sys.getDirectories(npmTypes)); + } + return result; + } function getDefaultLibLocation() { return ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())); } var newLine = ts.getNewLineCharacter(options); var realpath = ts.sys.realpath && (function (path) { return ts.sys.realpath(path); }); return { + getDefaultTypeDirectiveNames: getDefaultTypeDirectiveNames, getSourceFile: getSourceFile, getDefaultLibLocation: getDefaultLibLocation, getDefaultLibFileName: function (options) { return ts.combinePaths(getDefaultLibLocation(), ts.getDefaultLibFileName(options)); }, @@ -42302,6 +42452,21 @@ var ts; } return resolutions; } + function getDefaultTypeDirectiveNames(options, rootFiles, host) { + // Use explicit type list from tsconfig.json + if (options.types) { + return options.types; + } + // or load all types from the automatic type import fields + if (host && host.getDefaultTypeDirectiveNames) { + var commonRoot = computeCommonSourceDirectoryOfFilenames(rootFiles, host.getCurrentDirectory(), function (f) { return host.getCanonicalFileName(f); }); + if (commonRoot) { + return host.getDefaultTypeDirectiveNames(commonRoot); + } + } + return undefined; + } + ts.getDefaultTypeDirectiveNames = getDefaultTypeDirectiveNames; function createProgram(rootNames, options, host, oldProgram) { var program; var files = []; @@ -42340,14 +42505,15 @@ var ts; // used to track cases when two file names differ only in casing var filesByNameIgnoreCase = host.useCaseSensitiveFileNames() ? ts.createFileMap(function (fileName) { return fileName.toLowerCase(); }) : undefined; if (!tryReuseStructureFromOldProgram()) { + ts.forEach(rootNames, function (name) { return processRootFile(name, /*isDefaultLib*/ false); }); // load type declarations specified via 'types' argument - if (options.types && options.types.length) { - var resolutions = resolveTypeReferenceDirectiveNamesWorker(options.types, /*containingFile*/ undefined); - for (var i = 0; i < options.types.length; i++) { - processTypeReferenceDirective(options.types[i], resolutions[i]); + var typeReferences = getDefaultTypeDirectiveNames(options, rootNames, host); + if (typeReferences) { + var resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, /*containingFile*/ undefined); + for (var i = 0; i < typeReferences.length; i++) { + processTypeReferenceDirective(typeReferences[i], resolutions[i]); } } - ts.forEach(rootNames, function (name) { return processRootFile(name, /*isDefaultLib*/ false); }); // Do not process the default library if: // - The '--noLib' flag is used. // - A 'no-default-lib' reference comment is encountered in @@ -42999,9 +43165,6 @@ var ts; if (file_1 && options.forceConsistentCasingInFileNames && ts.getNormalizedAbsolutePath(file_1.fileName, currentDirectory) !== ts.getNormalizedAbsolutePath(fileName, currentDirectory)) { reportFileNamesDifferOnlyInCasingError(fileName, file_1.fileName, refFile, refPos, refEnd); } - if (file_1) { - file_1.wasReferenced = file_1.wasReferenced || isReference; - } return file_1; } // We haven't looked for this file, do so now and cache result @@ -43015,7 +43178,6 @@ var ts; }); filesByName.set(path, file); if (file) { - file.wasReferenced = file.wasReferenced || isReference; file.path = path; if (host.useCaseSensitiveFileNames()) { // for case-sensitive file systems check if we've already seen some file with similar filename ignoring case @@ -43129,19 +43291,7 @@ var ts; !options.noResolve && i < file.imports.length; if (shouldAddFile) { - var importedFile = findSourceFile(resolution.resolvedFileName, ts.toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), /*isDefaultLib*/ false, /*isReference*/ false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); - if (importedFile && resolution.isExternalLibraryImport) { - // Since currently irrespective of allowJs, we only look for supportedTypeScript extension external module files, - // this check is ok. Otherwise this would be never true for javascript file - if (!ts.isExternalModule(importedFile) && importedFile.statements.length) { - var start_5 = ts.getTokenPosOfNode(file.imports[i], file); - fileProcessingDiagnostics.add(ts.createFileDiagnostic(file, start_5, file.imports[i].end - start_5, ts.Diagnostics.Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition, importedFile.fileName)); - } - else if (importedFile.referencedFiles.length) { - var firstRef = importedFile.referencedFiles[0]; - fileProcessingDiagnostics.add(ts.createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, ts.Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition)); - } - } + findSourceFile(resolution.resolvedFileName, ts.toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), /*isDefaultLib*/ false, /*isReference*/ false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); } } } @@ -43227,7 +43377,7 @@ var ts; } } else { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Substututions_for_pattern_0_should_be_an_array, key)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Substitutions_for_pattern_0_should_be_an_array, key)); } } } @@ -43278,15 +43428,21 @@ var ts; else if (firstExternalModuleSourceFile && languageVersion < 2 /* ES6 */ && options.module === ts.ModuleKind.None) { // We cannot use createDiagnosticFromNode because nodes do not have parents yet var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file)); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none)); } // Cannot specify module gen target of es6 when below es6 if (options.module === ts.ModuleKind.ES6 && languageVersion < 2 /* ES6 */) { programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_es2015_when_targeting_ES5_or_lower)); } // Cannot specify module gen that isn't amd or system with --out - if (outFile && options.module && !(options.module === ts.ModuleKind.AMD || options.module === ts.ModuleKind.System)) { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); + if (outFile) { + if (options.module && !(options.module === ts.ModuleKind.AMD || options.module === ts.ModuleKind.System)) { + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); + } + else if (options.module === undefined && firstExternalModuleSourceFile) { + var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system, options.out ? "out" : "outFile")); + } } // there has to be common source directory if user specified --outdir || --sourceRoot // if user specified --mapRoot, there needs to be common source directory if there would be multiple files being emitted @@ -43384,6 +43540,11 @@ var ts; type: "boolean", description: ts.Diagnostics.Print_this_message }, + { + name: "help", + shortName: "?", + type: "boolean" + }, { name: "init", type: "boolean", @@ -43486,6 +43647,11 @@ var ts; name: "skipDefaultLibCheck", type: "boolean" }, + { + name: "skipLibCheck", + type: "boolean", + description: ts.Diagnostics.Skip_type_checking_of_declaration_files + }, { name: "out", type: "string", @@ -44315,7 +44481,7 @@ var ts; (function (ts) { var NavigateTo; (function (NavigateTo) { - function getNavigateToItems(program, cancellationToken, searchValue, maxResultCount) { + function getNavigateToItems(program, checker, cancellationToken, searchValue, maxResultCount) { var patternMatcher = ts.createPatternMatcher(searchValue); var rawItems = []; // This means "compare in a case insensitive manner." @@ -44354,6 +44520,18 @@ var ts; } } }); + // Remove imports when the imported declaration is already in the list and has the same name. + rawItems = ts.filter(rawItems, function (item) { + var decl = item.declaration; + if (decl.kind === 231 /* ImportClause */ || decl.kind === 234 /* ImportSpecifier */ || decl.kind === 229 /* ImportEqualsDeclaration */) { + var importer = checker.getSymbolAtLocation(decl.name); + var imported = checker.getAliasedSymbol(importer); + return importer.name !== imported.name; + } + else { + return true; + } + }); rawItems.sort(compareNavigateToItems); if (maxResultCount !== undefined) { rawItems = rawItems.slice(0, maxResultCount); @@ -44752,8 +44930,12 @@ var ts; return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberSetAccessorElement); case 153 /* IndexSignature */: return createItem(node, "[]", ts.ScriptElementKind.indexSignatureElement); + case 224 /* EnumDeclaration */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.enumElement); case 255 /* EnumMember */: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); + case 222 /* InterfaceDeclaration */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.interfaceElement); case 151 /* CallSignature */: return createItem(node, "()", ts.ScriptElementKind.callSignatureElement); case 152 /* ConstructSignature */: @@ -45714,7 +45896,7 @@ var ts; // To do this, the method will back parse the expression starting at the position required. it will try to parse the current expression as a generic type expression, if it did succeed it // will return the generic identifier that started the expression (e.g. "foo" in "foo= 0; --i) { + for (var i = exclusiveStartPosition - 1; i >= 0; i--) { if (nodeHasTokens(children[i])) { return children[i]; } @@ -47337,12 +47519,11 @@ var ts; if (!isStarted) { scanner.scan(); } - var t; var pos = scanner.getStartPos(); // Read leading trivia and token while (pos < endPos) { - var t_1 = scanner.getToken(); - if (!ts.isTrivia(t_1)) { + var t = scanner.getToken(); + if (!ts.isTrivia(t)) { break; } // consume leading trivia @@ -47350,7 +47531,7 @@ var ts; var item = { pos: pos, end: scanner.getStartPos(), - kind: t_1 + kind: t }; pos = scanner.getStartPos(); if (!leadingTrivia) { @@ -47690,6 +47871,7 @@ var ts; })(formatting = ts.formatting || (ts.formatting = {})); })(ts || (ts = {})); /// +/* tslint:disable:no-null-keyword */ /* @internal */ var ts; (function (ts) { @@ -47951,7 +48133,7 @@ var ts; this.SpaceAfterKeywordInControl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Keywords, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsControlDeclContext), 2 /* Space */)); this.NoSpaceAfterKeywordInControl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Keywords, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsControlDeclContext), 8 /* Delete */)); // Open Brace braces after function - //TypeScript: Function can have return types, which can be made of tons of different token kinds + // TypeScript: Function can have return types, which can be made of tons of different token kinds this.NewLineBeforeOpenBraceInFunction = new formatting.Rule(formatting.RuleDescriptor.create2(this.FunctionOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext, Rules.IsBeforeMultilineBlockContext), 4 /* NewLine */), 1 /* CanDeleteNewLines */); // Open Brace braces after TypeScript module/class/interface this.NewLineBeforeOpenBraceInTypeScriptDeclWithBlock = new formatting.Rule(formatting.RuleDescriptor.create2(this.TypeScriptOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsTypeScriptDeclWithBlockContext, Rules.IsBeforeMultilineBlockContext), 4 /* NewLine */), 1 /* CanDeleteNewLines */); @@ -48092,17 +48274,17 @@ var ts; case 220 /* FunctionDeclaration */: case 147 /* MethodDeclaration */: case 146 /* MethodSignature */: - //case SyntaxKind.MemberFunctionDeclaration: + // case SyntaxKind.MemberFunctionDeclaration: case 149 /* GetAccessor */: case 150 /* SetAccessor */: - ///case SyntaxKind.MethodSignature: + // case SyntaxKind.MethodSignature: case 151 /* CallSignature */: case 179 /* FunctionExpression */: case 148 /* Constructor */: case 180 /* ArrowFunction */: - //case SyntaxKind.ConstructorDeclaration: - //case SyntaxKind.SimpleArrowFunctionExpression: - //case SyntaxKind.ParenthesizedArrowFunctionExpression: + // case SyntaxKind.ConstructorDeclaration: + // case SyntaxKind.SimpleArrowFunctionExpression: + // case SyntaxKind.ParenthesizedArrowFunctionExpression: case 222 /* InterfaceDeclaration */: return true; } @@ -48254,6 +48436,7 @@ var ts; })(formatting = ts.formatting || (ts.formatting = {})); })(ts || (ts = {})); /// +/* tslint:disable:no-null-keyword */ /* @internal */ var ts; (function (ts) { @@ -48271,9 +48454,9 @@ var ts; }; RulesMap.prototype.Initialize = function (rules) { this.mapRowLength = 138 /* LastToken */ + 1; - this.map = new Array(this.mapRowLength * this.mapRowLength); //new Array(this.mapRowLength * this.mapRowLength); + this.map = new Array(this.mapRowLength * this.mapRowLength); // new Array(this.mapRowLength * this.mapRowLength); // This array is used only during construction of the rulesbucket in the map - var rulesBucketConstructionStateList = new Array(this.map.length); //new Array(this.map.length); + var rulesBucketConstructionStateList = new Array(this.map.length); // new Array(this.map.length); this.FillRules(rules, rulesBucketConstructionStateList); return this.map; }; @@ -48285,7 +48468,7 @@ var ts; }; RulesMap.prototype.GetRuleBucketIndex = function (row, column) { var rulesBucketIndex = (row * this.mapRowLength) + column; - //Debug.Assert(rulesBucketIndex < this.map.Length, "Trying to access an index outside the array."); + // Debug.Assert(rulesBucketIndex < this.map.Length, "Trying to access an index outside the array."); return rulesBucketIndex; }; RulesMap.prototype.FillRule = function (rule, rulesBucketConstructionStateList) { @@ -48537,6 +48720,7 @@ var ts; /// /// /// +/* tslint:disable:no-null-keyword */ /* @internal */ var ts; (function (ts) { @@ -49058,7 +49242,7 @@ var ts; // if there are any tokens that logically belong to node and interleave child nodes // such tokens will be consumed in processChildNode for for the child that follows them ts.forEachChild(node, function (child) { - processChildNode(child, /*inheritedIndentation*/ -1 /* Unknown */, node, nodeDynamicIndentation, nodeStartLine, undecoratedNodeStartLine, /*isListElement*/ false); + processChildNode(child, /*inheritedIndentation*/ -1 /* Unknown */, node, nodeDynamicIndentation, nodeStartLine, undecoratedNodeStartLine, /*isListItem*/ false); }, function (nodes) { processChildNodes(nodes, node, nodeStartLine, nodeDynamicIndentation); }); @@ -49149,7 +49333,7 @@ var ts; var inheritedIndentation = -1 /* Unknown */; for (var i = 0; i < nodes.length; i++) { var child = nodes[i]; - inheritedIndentation = processChildNode(child, inheritedIndentation, node, listDynamicIndentation, startLine, startLine, /*isListElement*/ true, /*isFirstListItem*/ i === 0); + inheritedIndentation = processChildNode(child, inheritedIndentation, node, listDynamicIndentation, startLine, startLine, /*isListItem*/ true, /*isFirstListItem*/ i === 0); } if (listEndToken !== 0 /* Unknown */) { if (formattingScanner.isOnToken()) { @@ -49279,7 +49463,7 @@ var ts; // Handle the case where the next line is moved to be the end of this line. // In this case we don't indent the next line in the next pass. if (currentParent.getStart(sourceFile) === currentItem.pos) { - dynamicIndentation.recomputeIndentation(/*lineAdded*/ false); + dynamicIndentation.recomputeIndentation(/*lineAddedByFormatting*/ false); } } else if (rule.Operation.Action & 4 /* NewLine */ && currentStartLine === previousStartLine) { @@ -49288,7 +49472,7 @@ var ts; // In this case we indent token2 in the next pass but we set // sameLineIndent flag to notify the indenter that the indentation is within the line. if (currentParent.getStart(sourceFile) === currentItem.pos) { - dynamicIndentation.recomputeIndentation(/*lineAdded*/ true); + dynamicIndentation.recomputeIndentation(/*lineAddedByFormatting*/ true); } } // We need to trim trailing whitespace between the tokens if they were on different lines, and no rule was applied to put them on the same line @@ -49336,7 +49520,7 @@ var ts; else { parts = []; var startPos = commentRange.pos; - for (var line = startLine; line < endLine; ++line) { + for (var line = startLine; line < endLine; line++) { var endOfLine = ts.getEndLinePosition(line, sourceFile); parts.push({ pos: startPos, end: endOfLine }); startPos = ts.getStartPositionOfLine(line + 1, sourceFile); @@ -49355,7 +49539,7 @@ var ts; } // shift all parts on the delta size var delta = indentation - nonWhitespaceColumnInFirstPart.column; - for (var i = startIndex, len = parts.length; i < len; ++i, ++startLine) { + for (var i = startIndex, len = parts.length; i < len; i++, startLine++) { var startLinePos_1 = ts.getStartPositionOfLine(startLine, sourceFile); var nonWhitespaceCharacterAndColumn = i === 0 ? nonWhitespaceColumnInFirstPart @@ -49371,7 +49555,7 @@ var ts; } } function trimTrailingWhitespacesForLines(line1, line2, range) { - for (var line = line1; line < line2; ++line) { + for (var line = line1; line < line2; line++) { var lineStartPosition = ts.getStartPositionOfLine(line, sourceFile); var lineEndPosition = ts.getEndLinePosition(line, sourceFile); // do not trim whitespaces in comments or template expression @@ -49422,7 +49606,6 @@ var ts; } } function applyRuleEdits(rule, previousRange, previousStartLine, currentRange, currentStartLine) { - var between; switch (rule.Operation.Action) { case 1 /* Ignore */: // no action required @@ -49459,14 +49642,6 @@ var ts; } } } - function isSomeBlock(kind) { - switch (kind) { - case 199 /* Block */: - case 226 /* ModuleBlock */: - return true; - } - return false; - } function getOpenTokenForList(node, list) { switch (node.kind) { case 148 /* Constructor */: @@ -49525,7 +49700,7 @@ var ts; internedTabsIndentation = []; } if (internedTabsIndentation[tabs] === undefined) { - internedTabsIndentation[tabs] = tabString = repeat('\t', tabs); + internedTabsIndentation[tabs] = tabString = repeat("\t", tabs); } else { tabString = internedTabsIndentation[tabs]; @@ -49550,7 +49725,7 @@ var ts; } function repeat(value, count) { var s = ""; - for (var i = 0; i < count; ++i) { + for (var i = 0; i < count; i++) { s += value; } return s; @@ -49866,7 +50041,7 @@ var ts; // walk toward the start of the list starting from current node and check if the line is the same for all items. // if end line for item [i - 1] differs from the start line for item [i] - find column of the first non-whitespace character on the line of item [i] var lineAndCharacter = getStartLineAndCharacterForNode(node, sourceFile); - for (var i = index - 1; i >= 0; --i) { + for (var i = index - 1; i >= 0; i--) { if (list[i].kind === 24 /* CommaToken */) { continue; } @@ -49893,7 +50068,7 @@ var ts; function findFirstNonWhitespaceCharacterAndColumn(startPos, endPos, sourceFile, options) { var character = 0; var column = 0; - for (var pos = startPos; pos < endPos; ++pos) { + for (var pos = startPos; pos < endPos; pos++) { var ch = sourceFile.text.charCodeAt(pos); if (!ts.isWhiteSpace(ch)) { break; @@ -49987,7 +50162,7 @@ var ts; Function returns true when the parent node should indent the given child by an explicit rule */ function shouldIndentChildNode(parent, child) { - return nodeContentIsAlwaysIndented(parent.kind) || nodeWillIndentChild(parent, child, false); + return nodeContentIsAlwaysIndented(parent.kind) || nodeWillIndentChild(parent, child, /*indentByDefault*/ false); } SmartIndenter.shouldIndentChildNode = shouldIndentChildNode; })(SmartIndenter = formatting.SmartIndenter || (formatting.SmartIndenter = {})); @@ -50809,49 +50984,55 @@ var ts; (function (ScriptElementKind) { ScriptElementKind.unknown = ""; ScriptElementKind.warning = "warning"; - // predefined type (void) or keyword (class) + /** predefined type (void) or keyword (class) */ ScriptElementKind.keyword = "keyword"; - // top level script node + /** top level script node */ ScriptElementKind.scriptElement = "script"; - // module foo {} + /** module foo {} */ ScriptElementKind.moduleElement = "module"; - // class X {} + /** class X {} */ ScriptElementKind.classElement = "class"; - // var x = class X {} + /** var x = class X {} */ ScriptElementKind.localClassElement = "local class"; - // interface Y {} + /** interface Y {} */ ScriptElementKind.interfaceElement = "interface"; - // type T = ... + /** type T = ... */ ScriptElementKind.typeElement = "type"; - // enum E + /** enum E */ ScriptElementKind.enumElement = "enum"; - // Inside module and script only - // const v = .. + /** + * Inside module and script only + * const v = .. + */ ScriptElementKind.variableElement = "var"; - // Inside function + /** Inside function */ ScriptElementKind.localVariableElement = "local var"; - // Inside module and script only - // function f() { } + /** + * Inside module and script only + * function f() { } + */ ScriptElementKind.functionElement = "function"; - // Inside function + /** Inside function */ ScriptElementKind.localFunctionElement = "local function"; - // class X { [public|private]* foo() {} } + /** class X { [public|private]* foo() {} } */ ScriptElementKind.memberFunctionElement = "method"; - // class X { [public|private]* [get|set] foo:number; } + /** class X { [public|private]* [get|set] foo:number; } */ ScriptElementKind.memberGetAccessorElement = "getter"; ScriptElementKind.memberSetAccessorElement = "setter"; - // class X { [public|private]* foo:number; } - // interface Y { foo:number; } + /** + * class X { [public|private]* foo:number; } + * interface Y { foo:number; } + */ ScriptElementKind.memberVariableElement = "property"; - // class X { constructor() { } } + /** class X { constructor() { } } */ ScriptElementKind.constructorImplementationElement = "constructor"; - // interface Y { ():number; } + /** interface Y { ():number; } */ ScriptElementKind.callSignatureElement = "call"; - // interface Y { []:number; } + /** interface Y { []:number; } */ ScriptElementKind.indexSignatureElement = "index"; - // interface Y { new():Y; } + /** interface Y { new():Y; } */ ScriptElementKind.constructSignatureElement = "construct"; - // function foo(*Y*: string) + /** function foo(*Y*: string) */ ScriptElementKind.parameterElement = "parameter"; ScriptElementKind.typeParameterElement = "type parameter"; ScriptElementKind.primitiveType = "primitive type"; @@ -52236,9 +52417,9 @@ var ts; // Check if the caret is at the end of an identifier; this is a partial identifier that we want to complete: e.g. a.toS| // Skip this partial identifier and adjust the contextToken to the token that precedes it. if (contextToken && position <= contextToken.end && ts.isWord(contextToken.kind)) { - var start_6 = new Date().getTime(); + var start_5 = new Date().getTime(); contextToken = ts.findPrecedingToken(contextToken.getFullStart(), sourceFile); - log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_6)); + log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_5)); } // Find the node where completion is requested on. // Also determine whether we are trying to complete with members of that node @@ -52518,13 +52699,13 @@ var ts; || contextToken.kind === 166 /* StringLiteralType */ || contextToken.kind === 10 /* RegularExpressionLiteral */ || ts.isTemplateLiteralKind(contextToken.kind)) { - var start_7 = contextToken.getStart(); + var start_6 = contextToken.getStart(); var end = contextToken.getEnd(); // To be "in" one of these literals, the position has to be: // 1. entirely within the token text. // 2. at the end position of an unterminated token. // 3. at the end of a regular expression (due to trailing flags like '/foo/g'). - if (start_7 < position && position < end) { + if (start_6 < position && position < end) { return true; } if (position === end) { @@ -53759,8 +53940,7 @@ var ts; } function getDocumentHighlights(fileName, position, filesToSearch) { synchronizeHostData(); - filesToSearch = ts.map(filesToSearch, ts.normalizeSlashes); - var sourceFilesToSearch = ts.filter(program.getSourceFiles(), function (f) { return ts.contains(filesToSearch, f.fileName); }); + var sourceFilesToSearch = ts.map(filesToSearch, function (f) { return program.getSourceFile(f); }); var sourceFile = getValidSourceFile(fileName); var node = ts.getTouchingWord(sourceFile, position); if (!node) { @@ -55150,7 +55330,8 @@ var ts; /// NavigateTo function getNavigateToItems(searchValue, maxResultCount) { synchronizeHostData(); - return ts.NavigateTo.getNavigateToItems(program, cancellationToken, searchValue, maxResultCount); + var checker = getProgram().getTypeChecker(); + return ts.NavigateTo.getNavigateToItems(program, checker, cancellationToken, searchValue, maxResultCount); } function getEmitOutput(fileName) { synchronizeHostData(); @@ -57559,6 +57740,9 @@ var ts; LanguageServiceShimHostAdapter.prototype.getCurrentDirectory = function () { return this.shimHost.getCurrentDirectory(); }; + LanguageServiceShimHostAdapter.prototype.getDirectories = function (path) { + return this.shimHost.getDirectories(path); + }; LanguageServiceShimHostAdapter.prototype.getDefaultLibFileName = function (options) { return this.shimHost.getDefaultLibFileName(JSON.stringify(options)); }; diff --git a/lib/typescriptServices.d.ts b/lib/typescriptServices.d.ts index cd459201d8b..67530e211bc 100644 --- a/lib/typescriptServices.d.ts +++ b/lib/typescriptServices.d.ts @@ -261,7 +261,7 @@ declare namespace ts { ModuleDeclaration = 225, ModuleBlock = 226, CaseBlock = 227, - GlobalModuleExportDeclaration = 228, + NamespaceExportDeclaration = 228, ImportEqualsDeclaration = 229, ImportDeclaration = 230, ImportClause = 231, @@ -934,7 +934,7 @@ declare namespace ts { interface NamespaceImport extends Declaration { name: Identifier; } - interface GlobalModuleExportDeclaration extends DeclarationStatement { + interface NamespaceExportDeclaration extends DeclarationStatement { name: Identifier; moduleReference: LiteralLikeNode; } @@ -1329,7 +1329,7 @@ declare namespace ts { FunctionScopedVariableExcludes = 107454, BlockScopedVariableExcludes = 107455, ParameterExcludes = 107455, - PropertyExcludes = 107455, + PropertyExcludes = 0, EnumMemberExcludes = 107455, FunctionExcludes = 106927, ClassExcludes = 899519, @@ -1554,6 +1554,7 @@ declare namespace ts { allowJs?: boolean; noImplicitUseStrict?: boolean; strictNullChecks?: boolean; + skipLibCheck?: boolean; listEmittedFiles?: boolean; lib?: string[]; types?: string[]; @@ -1627,6 +1628,7 @@ declare namespace ts { trace?(s: string): void; directoryExists?(directoryName: string): boolean; realpath?(path: string): string; + getCurrentDirectory?(): string; } interface ResolvedModule { resolvedFileName: string; @@ -1650,6 +1652,7 @@ declare namespace ts { getCancellationToken?(): CancellationToken; getDefaultLibFileName(options: CompilerOptions): string; getDefaultLibLocation?(): string; + getDefaultTypeDirectiveNames?(rootPath: string): string[]; writeFile: WriteFileCallback; getCurrentDirectory(): string; getCanonicalFileName(fileName: string): string; @@ -1693,6 +1696,7 @@ declare namespace ts { createDirectory(path: string): void; getExecutingFilePath(): string; getCurrentDirectory(): string; + getDirectories(path: string): string[]; readDirectory(path: string, extension?: string, exclude?: string[]): string[]; getModifiedTime?(path: string): Date; createHash?(data: string): string; @@ -1812,6 +1816,7 @@ declare namespace ts { function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; + function getDefaultTypeDirectiveNames(options: CompilerOptions, rootFiles: string[], host: CompilerHost): string[]; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program): Program; } declare namespace ts { @@ -2345,26 +2350,55 @@ declare namespace ts { namespace ScriptElementKind { const unknown: string; const warning: string; + /** predefined type (void) or keyword (class) */ const keyword: string; + /** top level script node */ const scriptElement: string; + /** module foo {} */ const moduleElement: string; + /** class X {} */ const classElement: string; + /** var x = class X {} */ const localClassElement: string; + /** interface Y {} */ const interfaceElement: string; + /** type T = ... */ const typeElement: string; + /** enum E */ const enumElement: string; + /** + * Inside module and script only + * const v = .. + */ const variableElement: string; + /** Inside function */ const localVariableElement: string; + /** + * Inside module and script only + * function f() { } + */ const functionElement: string; + /** Inside function */ const localFunctionElement: string; + /** class X { [public|private]* foo() {} } */ const memberFunctionElement: string; + /** class X { [public|private]* [get|set] foo:number; } */ const memberGetAccessorElement: string; const memberSetAccessorElement: string; + /** + * class X { [public|private]* foo:number; } + * interface Y { foo:number; } + */ const memberVariableElement: string; + /** class X { constructor() { } } */ const constructorImplementationElement: string; + /** interface Y { ():number; } */ const callSignatureElement: string; + /** interface Y { []:number; } */ const indexSignatureElement: string; + /** interface Y { new():Y; } */ const constructSignatureElement: string; + /** function foo(*Y*: string) */ const parameterElement: string; const typeParameterElement: string; const primitiveType: string; diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index e78eda7b0bb..19fffd35501 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -271,7 +271,7 @@ var ts; SyntaxKind[SyntaxKind["ModuleDeclaration"] = 225] = "ModuleDeclaration"; SyntaxKind[SyntaxKind["ModuleBlock"] = 226] = "ModuleBlock"; SyntaxKind[SyntaxKind["CaseBlock"] = 227] = "CaseBlock"; - SyntaxKind[SyntaxKind["GlobalModuleExportDeclaration"] = 228] = "GlobalModuleExportDeclaration"; + SyntaxKind[SyntaxKind["NamespaceExportDeclaration"] = 228] = "NamespaceExportDeclaration"; SyntaxKind[SyntaxKind["ImportEqualsDeclaration"] = 229] = "ImportEqualsDeclaration"; SyntaxKind[SyntaxKind["ImportDeclaration"] = 230] = "ImportDeclaration"; SyntaxKind[SyntaxKind["ImportClause"] = 231] = "ImportClause"; @@ -561,7 +561,7 @@ var ts; // they can not merge with anything in the value space SymbolFlags[SymbolFlags["BlockScopedVariableExcludes"] = 107455] = "BlockScopedVariableExcludes"; SymbolFlags[SymbolFlags["ParameterExcludes"] = 107455] = "ParameterExcludes"; - SymbolFlags[SymbolFlags["PropertyExcludes"] = 107455] = "PropertyExcludes"; + SymbolFlags[SymbolFlags["PropertyExcludes"] = 0] = "PropertyExcludes"; SymbolFlags[SymbolFlags["EnumMemberExcludes"] = 107455] = "EnumMemberExcludes"; SymbolFlags[SymbolFlags["FunctionExcludes"] = 106927] = "FunctionExcludes"; SymbolFlags[SymbolFlags["ClassExcludes"] = 899519] = "ClassExcludes"; @@ -1841,6 +1841,10 @@ var ts; } return result.sort(); } + function getDirectories(path) { + var folder = fso.GetFolder(path); + return getNames(folder.subfolders); + } function readDirectory(path, extension, exclude) { var result = []; exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); @@ -1895,6 +1899,7 @@ var ts; getCurrentDirectory: function () { return new ActiveXObject("WScript.Shell").CurrentDirectory; }, + getDirectories: getDirectories, readDirectory: readDirectory, exit: function (exitCode) { try { @@ -2057,6 +2062,9 @@ var ts; function directoryExists(path) { return fileSystemEntryExists(path, 1 /* Directory */); } + function getDirectories(path) { + return ts.filter(_fs.readdirSync(path), function (p) { return fileSystemEntryExists(ts.combinePaths(path, p), 1 /* Directory */); }); + } function readDirectory(path, extension, exclude) { var result = []; exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); @@ -2157,6 +2165,7 @@ var ts; getCurrentDirectory: function () { return process.cwd(); }, + getDirectories: getDirectories, readDirectory: readDirectory, getModifiedTime: function (path) { try { @@ -2209,6 +2218,7 @@ var ts; createDirectory: ChakraHost.createDirectory, getExecutingFilePath: function () { return ChakraHost.executingFile; }, getCurrentDirectory: function () { return ChakraHost.currentDirectory; }, + getDirectories: ChakraHost.getDirectories, readDirectory: ChakraHost.readDirectory, exit: ChakraHost.quit, realpath: realpath @@ -2347,7 +2357,7 @@ var ts; or_expected: { code: 1144, category: ts.DiagnosticCategory.Error, key: "or_expected_1144", message: "'{' or ';' expected." }, Declaration_expected: { code: 1146, category: ts.DiagnosticCategory.Error, key: "Declaration_expected_1146", message: "Declaration expected." }, Import_declarations_in_a_namespace_cannot_reference_a_module: { code: 1147, category: ts.DiagnosticCategory.Error, key: "Import_declarations_in_a_namespace_cannot_reference_a_module_1147", message: "Import declarations in a namespace cannot reference a module." }, - Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting__1148", message: "Cannot compile modules unless the '--module' flag is provided with a valid module type. Consider setting the 'module' compiler option in a 'tsconfig.json' file." }, + Cannot_use_imports_exports_or_module_augmentations_when_module_is_none: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot_use_imports_exports_or_module_augmentations_when_module_is_none_1148", message: "Cannot use imports, exports, or module augmentations when '--module' is 'none'." }, File_name_0_differs_from_already_included_file_name_1_only_in_casing: { code: 1149, category: ts.DiagnosticCategory.Error, key: "File_name_0_differs_from_already_included_file_name_1_only_in_casing_1149", message: "File name '{0}' differs from already included file name '{1}' only in casing" }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: ts.DiagnosticCategory.Error, key: "new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead_1150", message: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, const_declarations_must_be_initialized: { code: 1155, category: ts.DiagnosticCategory.Error, key: "const_declarations_must_be_initialized_1155", message: "'const' declarations must be initialized" }, @@ -2717,6 +2727,8 @@ var ts; this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation: { code: 2683, category: ts.DiagnosticCategory.Error, key: "this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_2683", message: "'this' implicitly has type 'any' because it does not have a type annotation." }, The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1: { code: 2684, category: ts.DiagnosticCategory.Error, key: "The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1_2684", message: "The 'this' context of type '{0}' is not assignable to method's 'this' of type '{1}'." }, The_this_types_of_each_signature_are_incompatible: { code: 2685, category: ts.DiagnosticCategory.Error, key: "The_this_types_of_each_signature_are_incompatible_2685", message: "The 'this' types of each signature are incompatible." }, + Identifier_0_must_be_imported_from_a_module: { code: 2686, category: ts.DiagnosticCategory.Error, key: "Identifier_0_must_be_imported_from_a_module_2686", message: "Identifier '{0}' must be imported from a module" }, + All_declarations_of_0_must_have_identical_modifiers: { code: 2687, category: ts.DiagnosticCategory.Error, key: "All_declarations_of_0_must_have_identical_modifiers_2687", message: "All declarations of '{0}' must have identical modifiers." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import_declaration_0_is_using_private_name_1_4000", message: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: ts.DiagnosticCategory.Error, key: "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", message: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: ts.DiagnosticCategory.Error, key: "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", message: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -2810,7 +2822,7 @@ var ts; Option_paths_cannot_be_used_without_specifying_baseUrl_option: { code: 5060, category: ts.DiagnosticCategory.Error, key: "Option_paths_cannot_be_used_without_specifying_baseUrl_option_5060", message: "Option 'paths' cannot be used without specifying '--baseUrl' option." }, Pattern_0_can_have_at_most_one_Asterisk_character: { code: 5061, category: ts.DiagnosticCategory.Error, key: "Pattern_0_can_have_at_most_one_Asterisk_character_5061", message: "Pattern '{0}' can have at most one '*' character" }, Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character: { code: 5062, category: ts.DiagnosticCategory.Error, key: "Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character_5062", message: "Substitution '{0}' in pattern '{1}' in can have at most one '*' character" }, - Substututions_for_pattern_0_should_be_an_array: { code: 5063, category: ts.DiagnosticCategory.Error, key: "Substututions_for_pattern_0_should_be_an_array_5063", message: "Substututions for pattern '{0}' should be an array." }, + Substitutions_for_pattern_0_should_be_an_array: { code: 5063, category: ts.DiagnosticCategory.Error, key: "Substitutions_for_pattern_0_should_be_an_array_5063", message: "Substitutions for pattern '{0}' should be an array." }, Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2: { code: 5064, category: ts.DiagnosticCategory.Error, key: "Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2_5064", message: "Substitution '{0}' for pattern '{1}' has incorrect type, expected 'string', got '{2}'." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: ts.DiagnosticCategory.Message, key: "Concatenate_and_emit_output_to_single_file_6001", message: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: ts.DiagnosticCategory.Message, key: "Generates_corresponding_d_ts_file_6002", message: "Generates corresponding '.d.ts' file." }, @@ -2823,6 +2835,7 @@ var ts; Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do_not_emit_comments_to_output_6009", message: "Do not emit comments to output." }, Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do_not_emit_outputs_6010", message: "Do not emit outputs." }, Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking: { code: 6011, category: ts.DiagnosticCategory.Message, key: "Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typech_6011", message: "Allow default imports from modules with no default export. This does not affect code emit, just typechecking." }, + Skip_type_checking_of_declaration_files: { code: 6012, category: ts.DiagnosticCategory.Message, key: "Skip_type_checking_of_declaration_files_6012", message: "Skip type checking of declaration files." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015_6015", message: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015'" }, Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015: { code: 6016, category: ts.DiagnosticCategory.Message, key: "Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015_6016", message: "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'" }, Print_this_message: { code: 6017, category: ts.DiagnosticCategory.Message, key: "Print_this_message_6017", message: "Print this message." }, @@ -2924,6 +2937,7 @@ var ts; Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set: { code: 6128, category: ts.DiagnosticCategory.Message, key: "Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set_6128", message: "======== Resolving type reference directive '{0}', containing file not set, root directory not set. ========" }, The_config_file_0_found_doesn_t_contain_any_source_files: { code: 6129, category: ts.DiagnosticCategory.Error, key: "The_config_file_0_found_doesn_t_contain_any_source_files_6129", message: "The config file '{0}' found doesn't contain any source files." }, Resolving_real_path_for_0_result_1: { code: 6130, category: ts.DiagnosticCategory.Message, key: "Resolving_real_path_for_0_result_1_6130", message: "Resolving real path for '{0}', result '{1}'" }, + Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { code: 6131, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system_6131", message: "Cannot compile modules using option '{0}' unless the '--module' flag is 'amd' or 'system'." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable_0_implicitly_has_an_1_type_7005", message: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter_0_implicitly_has_an_1_type_7006", message: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member_0_implicitly_has_an_1_type_7008", message: "Member '{0}' implicitly has an '{1}' type." }, @@ -6172,7 +6186,7 @@ var ts; // export default ... function isAliasSymbolDeclaration(node) { return node.kind === 229 /* ImportEqualsDeclaration */ || - node.kind === 228 /* GlobalModuleExportDeclaration */ || + node.kind === 228 /* NamespaceExportDeclaration */ || node.kind === 231 /* ImportClause */ && !!node.name || node.kind === 232 /* NamespaceImport */ || node.kind === 234 /* ImportSpecifier */ || @@ -6301,7 +6315,7 @@ var ts; } ts.isWellKnownSymbolSyntactically = isWellKnownSymbolSyntactically; function getPropertyNameForPropertyNameNode(name) { - if (name.kind === 69 /* Identifier */ || name.kind === 9 /* StringLiteral */ || name.kind === 8 /* NumericLiteral */) { + if (name.kind === 69 /* Identifier */ || name.kind === 9 /* StringLiteral */ || name.kind === 8 /* NumericLiteral */ || name.kind === 142 /* Parameter */) { return name.text; } if (name.kind === 140 /* ComputedPropertyName */) { @@ -7773,7 +7787,7 @@ var ts; case 231 /* ImportClause */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.namedBindings); - case 228 /* GlobalModuleExportDeclaration */: + case 228 /* NamespaceExportDeclaration */: return visitNode(cbNode, node.name); case 232 /* NamespaceImport */: return visitNode(cbNode, node.name); @@ -12182,7 +12196,7 @@ var ts; return nextToken() === 39 /* SlashToken */; } function parseGlobalModuleExportDeclaration(fullStart, decorators, modifiers) { - var exportDeclaration = createNode(228 /* GlobalModuleExportDeclaration */, fullStart); + var exportDeclaration = createNode(228 /* NamespaceExportDeclaration */, fullStart); exportDeclaration.decorators = decorators; exportDeclaration.modifiers = modifiers; parseExpected(116 /* AsKeyword */); @@ -15018,10 +15032,10 @@ var ts; case 145 /* PropertyDeclaration */: case 144 /* PropertySignature */: case 266 /* JSDocRecordMember */: - return bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 107455 /* PropertyExcludes */); + return bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 0 /* PropertyExcludes */); case 253 /* PropertyAssignment */: case 254 /* ShorthandPropertyAssignment */: - return bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 107455 /* PropertyExcludes */); + return bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 0 /* PropertyExcludes */); case 255 /* EnumMember */: return bindPropertyOrMethodOrAccessor(node, 8 /* EnumMember */, 107455 /* EnumMemberExcludes */); case 247 /* JsxSpreadAttribute */: @@ -15037,7 +15051,7 @@ var ts; // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes // so that it will conflict with any other object literal members with the same // name. - return bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), ts.isObjectLiteralMethod(node) ? 107455 /* PropertyExcludes */ : 99263 /* MethodExcludes */); + return bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), ts.isObjectLiteralMethod(node) ? 0 /* PropertyExcludes */ : 99263 /* MethodExcludes */); case 220 /* FunctionDeclaration */: return bindFunctionDeclaration(node); case 148 /* Constructor */: @@ -15081,8 +15095,8 @@ var ts; case 234 /* ImportSpecifier */: case 238 /* ExportSpecifier */: return declareSymbolAndAddToSymbolTable(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */); - case 228 /* GlobalModuleExportDeclaration */: - return bindGlobalModuleExportDeclaration(node); + case 228 /* NamespaceExportDeclaration */: + return bindNamespaceExportDeclaration(node); case 231 /* ImportClause */: return bindImportClause(node); case 236 /* ExportDeclaration */: @@ -15120,14 +15134,14 @@ var ts; } else if (boundExpression.kind === 69 /* Identifier */ && node.kind === 235 /* ExportAssignment */) { // An export default clause with an identifier exports all meanings of that identifier - declareSymbol(container.symbol.exports, container.symbol, node, 8388608 /* Alias */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); + declareSymbol(container.symbol.exports, container.symbol, node, 8388608 /* Alias */, 0 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); } else { // An export default clause with an expression exports a value - declareSymbol(container.symbol.exports, container.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); + declareSymbol(container.symbol.exports, container.symbol, node, 4 /* Property */, 0 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); } } - function bindGlobalModuleExportDeclaration(node) { + function bindNamespaceExportDeclaration(node) { if (node.modifiers && node.modifiers.length) { file.bindDiagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.Modifiers_cannot_appear_here)); } @@ -15186,7 +15200,7 @@ var ts; if (container.kind === 179 /* FunctionExpression */ || container.kind === 220 /* FunctionDeclaration */) { container.symbol.members = container.symbol.members || {}; // It's acceptable for multiple 'this' assignments of the same identifier to occur - declareSymbol(container.symbol.members, container.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */ & ~4 /* Property */); + declareSymbol(container.symbol.members, container.symbol, node, 4 /* Property */, 0 /* PropertyExcludes */ & ~4 /* Property */); } } function bindPrototypePropertyAssignment(node) { @@ -15209,7 +15223,7 @@ var ts; funcSymbol.members = {}; } // Declare the method/property - declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, 4 /* Property */, 107455 /* PropertyExcludes */); + declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, 4 /* Property */, 0 /* PropertyExcludes */); } function bindCallExpression(node) { // We're only inspecting call expressions to detect CommonJS modules, so we can skip @@ -15310,7 +15324,7 @@ var ts; // containing class. if (ts.isParameterPropertyDeclaration(node)) { var classDeclaration = node.parent.parent; - declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */); + declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */, 0 /* PropertyExcludes */); } } function bindFunctionDeclaration(node) { @@ -15696,7 +15710,7 @@ var ts; if (flags & 1 /* FunctionScopedVariable */) result |= 107454 /* FunctionScopedVariableExcludes */; if (flags & 4 /* Property */) - result |= 107455 /* PropertyExcludes */; + result |= 0 /* PropertyExcludes */; if (flags & 8 /* EnumMember */) result |= 107455 /* EnumMemberExcludes */; if (flags & 16 /* Function */) @@ -15982,6 +15996,7 @@ var ts; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; + var isInExternalModule = false; loop: while (location) { // Locals of a source file are not in scope (because they get merged into the global symbol table) if (location.locals && !isGlobalSourceFile(location)) { @@ -16024,6 +16039,7 @@ var ts; case 256 /* SourceFile */: if (!ts.isExternalOrCommonJsModule(location)) break; + isInExternalModule = true; case 225 /* ModuleDeclaration */: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 256 /* SourceFile */ || ts.isAmbientModule(location)) { @@ -16207,6 +16223,13 @@ var ts; checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation); } } + // If we're in an external module, we can't reference symbols created from UMD export declarations + if (result && isInExternalModule) { + var decls = result.declarations; + if (decls && decls.length === 1 && decls[0].kind === 228 /* NamespaceExportDeclaration */) { + error(errorLocation, ts.Diagnostics.Identifier_0_must_be_imported_from_a_module, name); + } + } } return result; } @@ -16409,7 +16432,7 @@ var ts; return getTargetOfExportSpecifier(node); case 235 /* ExportAssignment */: return getTargetOfExportAssignment(node); - case 228 /* GlobalModuleExportDeclaration */: + case 228 /* NamespaceExportDeclaration */: return getTargetOfGlobalModuleExportDeclaration(node); } } @@ -17883,7 +17906,7 @@ var ts; // assigned by contextual typing. function getTypeForBindingElementParent(node) { var symbol = getSymbolOfNode(node); - return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node); + return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ false); } function getTextOfPropertyName(name) { switch (name.kind) { @@ -18009,7 +18032,7 @@ var ts; return strictNullChecks && optional ? addNullableKind(type, 32 /* Undefined */) : type; } // Return the inferred type for a variable, parameter, or property declaration - function getTypeForVariableLikeDeclaration(declaration) { + function getTypeForVariableLikeDeclaration(declaration, includeOptionality) { if (declaration.flags & 134217728 /* JavaScriptFile */) { // If this is a variable in a JavaScript file, then use the JSDoc type (if it has // one as its type), otherwise fallback to the below standard TS codepaths to @@ -18035,7 +18058,7 @@ var ts; } // Use type from type annotation if one is present if (declaration.type) { - return addOptionality(getTypeFromTypeNode(declaration.type), /*optional*/ !!declaration.questionToken); + return addOptionality(getTypeFromTypeNode(declaration.type), /*optional*/ declaration.questionToken && includeOptionality); } if (declaration.kind === 142 /* Parameter */) { var func = declaration.parent; @@ -18056,12 +18079,12 @@ var ts; ? getContextuallyTypedThisType(func) : getContextuallyTypedParameterType(declaration); if (type) { - return addOptionality(type, /*optional*/ !!declaration.questionToken); + return addOptionality(type, /*optional*/ declaration.questionToken && includeOptionality); } } // Use the type of the initializer expression if one is present if (declaration.initializer) { - return addOptionality(checkExpressionCached(declaration.initializer), /*optional*/ !!declaration.questionToken); + return addOptionality(checkExpressionCached(declaration.initializer), /*optional*/ declaration.questionToken && includeOptionality); } // If it is a short-hand property assignment, use the type of the identifier if (declaration.kind === 254 /* ShorthandPropertyAssignment */) { @@ -18155,7 +18178,7 @@ var ts; // binding pattern [x, s = ""]. Because the contextual type is a tuple type, the resulting type of [1, "one"] is the // tuple type [number, string]. Thus, the type inferred for 'x' is number and the type inferred for 's' is string. function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) { - var type = getTypeForVariableLikeDeclaration(declaration); + var type = getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true); if (type) { if (reportErrors) { reportErrorsFromWidening(declaration, type); @@ -20719,7 +20742,7 @@ var ts; return isIdenticalTo(source, target); } if (!(target.flags & 134217728 /* Never */)) { - if (target.flags & 1 /* Any */) + if (target.flags & 1 /* Any */ || source.flags & 134217728 /* Never */) return -1 /* True */; if (source.flags & 32 /* Undefined */) { if (!strictNullChecks || target.flags & (32 /* Undefined */ | 16 /* Void */) || source === emptyArrayElementType) @@ -20739,7 +20762,7 @@ var ts; if (source.flags & 256 /* StringLiteral */ && target === stringType) return -1 /* True */; if (relation === assignableRelation || relation === comparableRelation) { - if (source.flags & (1 /* Any */ | 134217728 /* Never */)) + if (source.flags & 1 /* Any */) return -1 /* True */; if (source === numberType && target.flags & 128 /* Enum */) return -1 /* True */; @@ -21634,41 +21657,52 @@ var ts; getSignaturesOfType(type, 0 /* Call */).length === 0 && getSignaturesOfType(type, 1 /* Construct */).length === 0; } + function createTransientSymbol(source, type) { + var symbol = createSymbol(source.flags | 67108864 /* Transient */, source.name); + symbol.declarations = source.declarations; + symbol.parent = source.parent; + symbol.type = type; + symbol.target = source; + if (source.valueDeclaration) { + symbol.valueDeclaration = source.valueDeclaration; + } + return symbol; + } + function transformTypeOfMembers(type, f) { + var members = {}; + for (var _i = 0, _a = getPropertiesOfObjectType(type); _i < _a.length; _i++) { + var property = _a[_i]; + var original = getTypeOfSymbol(property); + var updated = f(original); + members[property.name] = updated === original ? property : createTransientSymbol(property, updated); + } + ; + return members; + } + /** + * If the the provided object literal is subject to the excess properties check, + * create a new that is exempt. Recursively mark object literal members as exempt. + * Leave signatures alone since they are not subject to the check. + */ function getRegularTypeOfObjectLiteral(type) { - if (type.flags & 1048576 /* FreshObjectLiteral */) { - var regularType = type.regularType; - if (!regularType) { - regularType = createType(type.flags & ~1048576 /* FreshObjectLiteral */); - regularType.symbol = type.symbol; - regularType.members = type.members; - regularType.properties = type.properties; - regularType.callSignatures = type.callSignatures; - regularType.constructSignatures = type.constructSignatures; - regularType.stringIndexInfo = type.stringIndexInfo; - regularType.numberIndexInfo = type.numberIndexInfo; - type.regularType = regularType; - } + if (!(type.flags & 1048576 /* FreshObjectLiteral */)) { + return type; + } + var regularType = type.regularType; + if (regularType) { return regularType; } - return type; + var resolved = type; + var members = transformTypeOfMembers(type, getRegularTypeOfObjectLiteral); + var regularNew = createAnonymousType(resolved.symbol, members, resolved.callSignatures, resolved.constructSignatures, resolved.stringIndexInfo, resolved.numberIndexInfo); + regularNew.flags = resolved.flags & ~1048576 /* FreshObjectLiteral */; + type.regularType = regularNew; + return regularNew; } function getWidenedTypeOfObjectLiteral(type) { - var properties = getPropertiesOfObjectType(type); - var members = {}; - ts.forEach(properties, function (p) { - var propType = getTypeOfSymbol(p); - var widenedType = getWidenedType(propType); - if (propType !== widenedType) { - var symbol = createSymbol(p.flags | 67108864 /* Transient */, p.name); - symbol.declarations = p.declarations; - symbol.parent = p.parent; - symbol.type = widenedType; - symbol.target = p; - if (p.valueDeclaration) - symbol.valueDeclaration = p.valueDeclaration; - p = symbol; - } - members[p.name] = p; + var members = transformTypeOfMembers(type, function (prop) { + var widened = getWidenedType(prop); + return prop === widened ? prop : widened; }); var stringIndexInfo = getIndexInfoOfType(type, 0 /* String */); var numberIndexInfo = getIndexInfoOfType(type, 1 /* Number */); @@ -23224,7 +23258,7 @@ var ts; } return nodeCheckFlag === 512 /* SuperStatic */ ? getBaseConstructorTypeOfClass(classType) - : baseClassType; + : getTypeWithThisArgument(baseClassType, classType.thisType); function isLegalUsageOfSuperExpression(container) { if (!container) { return false; @@ -25936,7 +25970,7 @@ var ts; var types = void 0; var funcIsGenerator = !!func.asteriskToken; if (funcIsGenerator) { - types = checkAndAggregateYieldOperandTypes(func.body, contextualMapper); + types = checkAndAggregateYieldOperandTypes(func, contextualMapper); if (types.length === 0) { var iterableIteratorAny = createIterableIteratorType(anyType); if (compilerOptions.noImplicitAny) { @@ -25946,8 +25980,7 @@ var ts; } } else { - var hasImplicitReturn = !!(func.flags & 32768 /* HasImplicitReturn */); - types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper, isAsync, hasImplicitReturn); + types = checkAndAggregateReturnExpressionTypes(func, contextualMapper); if (!types) { return neverType; } @@ -26001,9 +26034,9 @@ var ts; return widenedType; } } - function checkAndAggregateYieldOperandTypes(body, contextualMapper) { + function checkAndAggregateYieldOperandTypes(func, contextualMapper) { var aggregatedTypes = []; - ts.forEachYieldExpression(body, function (yieldExpression) { + ts.forEachYieldExpression(func.body, function (yieldExpression) { var expr = yieldExpression.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); @@ -26018,10 +26051,12 @@ var ts; }); return aggregatedTypes; } - function checkAndAggregateReturnExpressionTypes(body, contextualMapper, isAsync, hasImplicitReturn) { + function checkAndAggregateReturnExpressionTypes(func, contextualMapper) { + var isAsync = ts.isAsyncFunctionLike(func); var aggregatedTypes = []; - var hasOmittedExpressions = false; - ts.forEachReturnStatement(body, function (returnStatement) { + var hasReturnWithNoExpression = !!(func.flags & 32768 /* HasImplicitReturn */); + var hasReturnOfTypeNever = false; + ts.forEachReturnStatement(func.body, function (returnStatement) { var expr = returnStatement.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); @@ -26030,20 +26065,24 @@ var ts; // Promise/A+ compatible implementation will always assimilate any foreign promise, so the // return type of the body should be unwrapped to its awaited type, which should be wrapped in // the native Promise type by the caller. - type = checkAwaitedType(type, body.parent, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); + type = checkAwaitedType(type, func, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); } - if (type !== neverType && !ts.contains(aggregatedTypes, type)) { + if (type === neverType) { + hasReturnOfTypeNever = true; + } + else if (!ts.contains(aggregatedTypes, type)) { aggregatedTypes.push(type); } } else { - hasOmittedExpressions = true; + hasReturnWithNoExpression = true; } }); - if (aggregatedTypes.length === 0 && !hasOmittedExpressions && !hasImplicitReturn) { + if (aggregatedTypes.length === 0 && !hasReturnWithNoExpression && (hasReturnOfTypeNever || + func.kind === 179 /* FunctionExpression */ || func.kind === 180 /* ArrowFunction */)) { return undefined; } - if (strictNullChecks && aggregatedTypes.length && (hasOmittedExpressions || hasImplicitReturn)) { + if (strictNullChecks && aggregatedTypes.length && hasReturnWithNoExpression) { if (!ts.contains(aggregatedTypes, undefinedType)) { aggregatedTypes.push(undefinedType); } @@ -26215,8 +26254,14 @@ var ts; if (symbol.flags & 4 /* Property */ && (expr.kind === 172 /* PropertyAccessExpression */ || expr.kind === 173 /* ElementAccessExpression */) && expr.expression.kind === 97 /* ThisKeyword */) { + // Look for if this is the constructor for the class that `symbol` is a property of. var func = ts.getContainingFunction(expr); - return !(func && func.kind === 148 /* Constructor */ && func.parent === symbol.valueDeclaration.parent); + if (!(func && func.kind === 148 /* Constructor */)) + return true; + // If func.parent is a class and symbol is a (readonly) property of that class, or + // if func is a constructor and symbol is a (readonly) parameter property declared in it, + // then symbol is writeable here. + return !(func.parent === symbol.valueDeclaration.parent || func === symbol.valueDeclaration.parent); } return true; } @@ -27148,6 +27193,79 @@ var ts; } } } + function checkClassForDuplicateDeclarations(node) { + var getter = 1, setter = 2, property = getter | setter; + var instanceNames = {}; + var staticNames = {}; + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind === 148 /* Constructor */) { + for (var _b = 0, _c = member.parameters; _b < _c.length; _b++) { + var param = _c[_b]; + if (ts.isParameterPropertyDeclaration(param)) { + addName(instanceNames, param.name, param.name.text, property); + } + } + } + else { + var static = ts.forEach(member.modifiers, function (m) { return m.kind === 113 /* StaticKeyword */; }); + var names = static ? staticNames : instanceNames; + var memberName = member.name && ts.getPropertyNameForPropertyNameNode(member.name); + if (memberName) { + switch (member.kind) { + case 149 /* GetAccessor */: + addName(names, member.name, memberName, getter); + break; + case 150 /* SetAccessor */: + addName(names, member.name, memberName, setter); + break; + case 145 /* PropertyDeclaration */: + addName(names, member.name, memberName, property); + break; + } + } + } + } + function addName(names, location, name, meaning) { + if (ts.hasProperty(names, name)) { + var prev = names[name]; + if (prev & meaning) { + error(location, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(location)); + } + else { + names[name] = prev | meaning; + } + } + else { + names[name] = meaning; + } + } + } + function checkObjectTypeForDuplicateDeclarations(node) { + var names = {}; + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind == 144 /* PropertySignature */) { + var memberName = void 0; + switch (member.name.kind) { + case 9 /* StringLiteral */: + case 8 /* NumericLiteral */: + case 69 /* Identifier */: + memberName = member.name.text; + break; + default: + continue; + } + if (ts.hasProperty(names, memberName)) { + error(member.symbol.valueDeclaration.name, ts.Diagnostics.Duplicate_identifier_0, memberName); + error(member.name, ts.Diagnostics.Duplicate_identifier_0, memberName); + } + else { + names[memberName] = true; + } + } + } + } function checkTypeForDuplicateIndexSignatures(node) { if (node.kind === 222 /* InterfaceDeclaration */) { var nodeSymbol = getSymbolOfNode(node); @@ -27399,6 +27517,7 @@ var ts; var type = getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); checkIndexConstraints(type); checkTypeForDuplicateIndexSignatures(node); + checkObjectTypeForDuplicateDeclarations(node); } } function checkArrayType(node) { @@ -28444,6 +28563,10 @@ var ts; if (node.initializer) { checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, /*headMessage*/ undefined); } + if (!areDeclarationFlagsIdentical(node, symbol.valueDeclaration)) { + error(symbol.valueDeclaration.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); + error(node.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); + } } if (node.kind !== 145 /* PropertyDeclaration */ && node.kind !== 144 /* PropertySignature */) { // We know we don't have a binding pattern or computed name here @@ -28457,6 +28580,18 @@ var ts; checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } } + function areDeclarationFlagsIdentical(left, right) { + if (ts.hasQuestionToken(left) !== ts.hasQuestionToken(right)) { + return false; + } + var interestingFlags = 8 /* Private */ | + 16 /* Protected */ | + 256 /* Async */ | + 128 /* Abstract */ | + 64 /* Readonly */ | + 32 /* Static */; + return (left.flags & interestingFlags) === (right.flags & interestingFlags); + } function checkVariableDeclaration(node) { checkGrammarVariableDeclaration(node); return checkVariableLikeDeclaration(node); @@ -29150,6 +29285,7 @@ var ts; var typeWithThis = getTypeWithThisArgument(type); var staticType = getTypeOfSymbol(symbol); checkTypeParameterListsIdentical(node, symbol); + checkClassForDuplicateDeclarations(node); var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); if (baseTypeNode) { var baseTypes = getBaseTypes(type); @@ -29398,6 +29534,7 @@ var ts; checkIndexConstraints(type); } } + checkObjectTypeForDuplicateDeclarations(node); } ts.forEach(ts.getInterfaceBaseTypeNodes(node), function (heritageElement) { if (!ts.isSupportedExpressionWithTypeArguments(heritageElement)) { @@ -30241,14 +30378,11 @@ var ts; function checkSourceFileWorker(node) { var links = getNodeLinks(node); if (!(links.flags & 1 /* TypeChecked */)) { - // Check whether the file has declared it is the default lib, - // and whether the user has specifically chosen to avoid checking it. - if (compilerOptions.skipDefaultLibCheck) { - // If the user specified '--noLib' and a file has a '/// ', - // then we should treat that file as a default lib. - if (node.hasNoDefaultLib) { - return; - } + // If skipLibCheck is enabled, skip type checking if file is a declaration file. + // If skipDefaultLibCheck is enabled, skip type checking if file contains a + // '/// ' directive. + if (compilerOptions.skipLibCheck && node.isDeclarationFile || compilerOptions.skipDefaultLibCheck && node.hasNoDefaultLib) { + return; } // Grammar checking checkGrammarSourceFile(node); @@ -30665,7 +30799,7 @@ var ts; return symbol && getTypeOfSymbol(symbol); } if (ts.isBindingPattern(node)) { - return getTypeForVariableLikeDeclaration(node.parent); + return getTypeForVariableLikeDeclaration(node.parent, /*includeOptionality*/ true); } if (isInRightSideOfImportOrExportAssignment(node)) { var symbol = getSymbolAtLocation(node); @@ -31204,7 +31338,7 @@ var ts; if (file.moduleAugmentations.length) { (augmentations || (augmentations = [])).push(file.moduleAugmentations); } - if (file.wasReferenced && file.symbol && file.symbol.globalExports) { + if (file.symbol && file.symbol.globalExports) { mergeSymbolTable(globals, file.symbol.globalExports); } }); @@ -31787,7 +31921,6 @@ var ts; name_20.kind === 140 /* ComputedPropertyName */) { // If the name is not a ComputedPropertyName, the grammar checking will skip it checkGrammarComputedPropertyName(name_20); - return "continue"; } if (prop.kind === 254 /* ShorthandPropertyAssignment */ && !inDestructuring && prop.objectAssignmentInitializer) { // having objectAssignmentInitializer is only valid in ObjectAssignmentPattern @@ -31829,17 +31962,21 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_20.text)) { - seen[name_20.text] = currentKind; + var effectiveName = ts.getPropertyNameForPropertyNameNode(name_20); + if (effectiveName === undefined) { + return "continue"; + } + if (!ts.hasProperty(seen, effectiveName)) { + seen[effectiveName] = currentKind; } else { - var existingKind = seen[name_20.text]; + var existingKind = seen[effectiveName]; if (currentKind === Property && existingKind === Property) { - return "continue"; + grammarErrorOnNode(name_20, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name_20)); } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_20.text] = currentKind | existingKind; + seen[effectiveName] = currentKind | existingKind; } else { return { value: grammarErrorOnNode(name_20, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name) }; @@ -41638,8 +41775,8 @@ var ts; skipTsx: true, traceEnabled: traceEnabled }; - // use typesRoot and fallback to directory that contains tsconfig if typesRoot is not set - var rootDir = options.typesRoot || (options.configFilePath ? ts.getDirectoryPath(options.configFilePath) : undefined); + // use typesRoot and fallback to directory that contains tsconfig or current directory if typesRoot is not set + var rootDir = options.typesRoot || (options.configFilePath ? ts.getDirectoryPath(options.configFilePath) : (host.getCurrentDirectory && host.getCurrentDirectory())); if (traceEnabled) { if (containingFile === undefined) { if (rootDir === undefined) { @@ -42229,12 +42366,25 @@ var ts; } } } + function getDefaultTypeDirectiveNames(rootPath) { + var localTypes = ts.combinePaths(rootPath, "types"); + var npmTypes = ts.combinePaths(rootPath, "node_modules/@types"); + var result = []; + if (ts.sys.directoryExists(localTypes)) { + result = result.concat(ts.sys.getDirectories(localTypes)); + } + if (ts.sys.directoryExists(npmTypes)) { + result = result.concat(ts.sys.getDirectories(npmTypes)); + } + return result; + } function getDefaultLibLocation() { return ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())); } var newLine = ts.getNewLineCharacter(options); var realpath = ts.sys.realpath && (function (path) { return ts.sys.realpath(path); }); return { + getDefaultTypeDirectiveNames: getDefaultTypeDirectiveNames, getSourceFile: getSourceFile, getDefaultLibLocation: getDefaultLibLocation, getDefaultLibFileName: function (options) { return ts.combinePaths(getDefaultLibLocation(), ts.getDefaultLibFileName(options)); }, @@ -42302,6 +42452,21 @@ var ts; } return resolutions; } + function getDefaultTypeDirectiveNames(options, rootFiles, host) { + // Use explicit type list from tsconfig.json + if (options.types) { + return options.types; + } + // or load all types from the automatic type import fields + if (host && host.getDefaultTypeDirectiveNames) { + var commonRoot = computeCommonSourceDirectoryOfFilenames(rootFiles, host.getCurrentDirectory(), function (f) { return host.getCanonicalFileName(f); }); + if (commonRoot) { + return host.getDefaultTypeDirectiveNames(commonRoot); + } + } + return undefined; + } + ts.getDefaultTypeDirectiveNames = getDefaultTypeDirectiveNames; function createProgram(rootNames, options, host, oldProgram) { var program; var files = []; @@ -42340,14 +42505,15 @@ var ts; // used to track cases when two file names differ only in casing var filesByNameIgnoreCase = host.useCaseSensitiveFileNames() ? ts.createFileMap(function (fileName) { return fileName.toLowerCase(); }) : undefined; if (!tryReuseStructureFromOldProgram()) { + ts.forEach(rootNames, function (name) { return processRootFile(name, /*isDefaultLib*/ false); }); // load type declarations specified via 'types' argument - if (options.types && options.types.length) { - var resolutions = resolveTypeReferenceDirectiveNamesWorker(options.types, /*containingFile*/ undefined); - for (var i = 0; i < options.types.length; i++) { - processTypeReferenceDirective(options.types[i], resolutions[i]); + var typeReferences = getDefaultTypeDirectiveNames(options, rootNames, host); + if (typeReferences) { + var resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, /*containingFile*/ undefined); + for (var i = 0; i < typeReferences.length; i++) { + processTypeReferenceDirective(typeReferences[i], resolutions[i]); } } - ts.forEach(rootNames, function (name) { return processRootFile(name, /*isDefaultLib*/ false); }); // Do not process the default library if: // - The '--noLib' flag is used. // - A 'no-default-lib' reference comment is encountered in @@ -42999,9 +43165,6 @@ var ts; if (file_1 && options.forceConsistentCasingInFileNames && ts.getNormalizedAbsolutePath(file_1.fileName, currentDirectory) !== ts.getNormalizedAbsolutePath(fileName, currentDirectory)) { reportFileNamesDifferOnlyInCasingError(fileName, file_1.fileName, refFile, refPos, refEnd); } - if (file_1) { - file_1.wasReferenced = file_1.wasReferenced || isReference; - } return file_1; } // We haven't looked for this file, do so now and cache result @@ -43015,7 +43178,6 @@ var ts; }); filesByName.set(path, file); if (file) { - file.wasReferenced = file.wasReferenced || isReference; file.path = path; if (host.useCaseSensitiveFileNames()) { // for case-sensitive file systems check if we've already seen some file with similar filename ignoring case @@ -43129,19 +43291,7 @@ var ts; !options.noResolve && i < file.imports.length; if (shouldAddFile) { - var importedFile = findSourceFile(resolution.resolvedFileName, ts.toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), /*isDefaultLib*/ false, /*isReference*/ false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); - if (importedFile && resolution.isExternalLibraryImport) { - // Since currently irrespective of allowJs, we only look for supportedTypeScript extension external module files, - // this check is ok. Otherwise this would be never true for javascript file - if (!ts.isExternalModule(importedFile) && importedFile.statements.length) { - var start_5 = ts.getTokenPosOfNode(file.imports[i], file); - fileProcessingDiagnostics.add(ts.createFileDiagnostic(file, start_5, file.imports[i].end - start_5, ts.Diagnostics.Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition, importedFile.fileName)); - } - else if (importedFile.referencedFiles.length) { - var firstRef = importedFile.referencedFiles[0]; - fileProcessingDiagnostics.add(ts.createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, ts.Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition)); - } - } + findSourceFile(resolution.resolvedFileName, ts.toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), /*isDefaultLib*/ false, /*isReference*/ false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); } } } @@ -43227,7 +43377,7 @@ var ts; } } else { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Substututions_for_pattern_0_should_be_an_array, key)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Substitutions_for_pattern_0_should_be_an_array, key)); } } } @@ -43278,15 +43428,21 @@ var ts; else if (firstExternalModuleSourceFile && languageVersion < 2 /* ES6 */ && options.module === ts.ModuleKind.None) { // We cannot use createDiagnosticFromNode because nodes do not have parents yet var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file)); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none)); } // Cannot specify module gen target of es6 when below es6 if (options.module === ts.ModuleKind.ES6 && languageVersion < 2 /* ES6 */) { programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_es2015_when_targeting_ES5_or_lower)); } // Cannot specify module gen that isn't amd or system with --out - if (outFile && options.module && !(options.module === ts.ModuleKind.AMD || options.module === ts.ModuleKind.System)) { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); + if (outFile) { + if (options.module && !(options.module === ts.ModuleKind.AMD || options.module === ts.ModuleKind.System)) { + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); + } + else if (options.module === undefined && firstExternalModuleSourceFile) { + var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system, options.out ? "out" : "outFile")); + } } // there has to be common source directory if user specified --outdir || --sourceRoot // if user specified --mapRoot, there needs to be common source directory if there would be multiple files being emitted @@ -43384,6 +43540,11 @@ var ts; type: "boolean", description: ts.Diagnostics.Print_this_message }, + { + name: "help", + shortName: "?", + type: "boolean" + }, { name: "init", type: "boolean", @@ -43486,6 +43647,11 @@ var ts; name: "skipDefaultLibCheck", type: "boolean" }, + { + name: "skipLibCheck", + type: "boolean", + description: ts.Diagnostics.Skip_type_checking_of_declaration_files + }, { name: "out", type: "string", @@ -44315,7 +44481,7 @@ var ts; (function (ts) { var NavigateTo; (function (NavigateTo) { - function getNavigateToItems(program, cancellationToken, searchValue, maxResultCount) { + function getNavigateToItems(program, checker, cancellationToken, searchValue, maxResultCount) { var patternMatcher = ts.createPatternMatcher(searchValue); var rawItems = []; // This means "compare in a case insensitive manner." @@ -44354,6 +44520,18 @@ var ts; } } }); + // Remove imports when the imported declaration is already in the list and has the same name. + rawItems = ts.filter(rawItems, function (item) { + var decl = item.declaration; + if (decl.kind === 231 /* ImportClause */ || decl.kind === 234 /* ImportSpecifier */ || decl.kind === 229 /* ImportEqualsDeclaration */) { + var importer = checker.getSymbolAtLocation(decl.name); + var imported = checker.getAliasedSymbol(importer); + return importer.name !== imported.name; + } + else { + return true; + } + }); rawItems.sort(compareNavigateToItems); if (maxResultCount !== undefined) { rawItems = rawItems.slice(0, maxResultCount); @@ -44752,8 +44930,12 @@ var ts; return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberSetAccessorElement); case 153 /* IndexSignature */: return createItem(node, "[]", ts.ScriptElementKind.indexSignatureElement); + case 224 /* EnumDeclaration */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.enumElement); case 255 /* EnumMember */: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); + case 222 /* InterfaceDeclaration */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.interfaceElement); case 151 /* CallSignature */: return createItem(node, "()", ts.ScriptElementKind.callSignatureElement); case 152 /* ConstructSignature */: @@ -45714,7 +45896,7 @@ var ts; // To do this, the method will back parse the expression starting at the position required. it will try to parse the current expression as a generic type expression, if it did succeed it // will return the generic identifier that started the expression (e.g. "foo" in "foo= 0; --i) { + for (var i = exclusiveStartPosition - 1; i >= 0; i--) { if (nodeHasTokens(children[i])) { return children[i]; } @@ -47337,12 +47519,11 @@ var ts; if (!isStarted) { scanner.scan(); } - var t; var pos = scanner.getStartPos(); // Read leading trivia and token while (pos < endPos) { - var t_1 = scanner.getToken(); - if (!ts.isTrivia(t_1)) { + var t = scanner.getToken(); + if (!ts.isTrivia(t)) { break; } // consume leading trivia @@ -47350,7 +47531,7 @@ var ts; var item = { pos: pos, end: scanner.getStartPos(), - kind: t_1 + kind: t }; pos = scanner.getStartPos(); if (!leadingTrivia) { @@ -47690,6 +47871,7 @@ var ts; })(formatting = ts.formatting || (ts.formatting = {})); })(ts || (ts = {})); /// +/* tslint:disable:no-null-keyword */ /* @internal */ var ts; (function (ts) { @@ -47951,7 +48133,7 @@ var ts; this.SpaceAfterKeywordInControl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Keywords, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsControlDeclContext), 2 /* Space */)); this.NoSpaceAfterKeywordInControl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Keywords, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsControlDeclContext), 8 /* Delete */)); // Open Brace braces after function - //TypeScript: Function can have return types, which can be made of tons of different token kinds + // TypeScript: Function can have return types, which can be made of tons of different token kinds this.NewLineBeforeOpenBraceInFunction = new formatting.Rule(formatting.RuleDescriptor.create2(this.FunctionOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext, Rules.IsBeforeMultilineBlockContext), 4 /* NewLine */), 1 /* CanDeleteNewLines */); // Open Brace braces after TypeScript module/class/interface this.NewLineBeforeOpenBraceInTypeScriptDeclWithBlock = new formatting.Rule(formatting.RuleDescriptor.create2(this.TypeScriptOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsTypeScriptDeclWithBlockContext, Rules.IsBeforeMultilineBlockContext), 4 /* NewLine */), 1 /* CanDeleteNewLines */); @@ -48092,17 +48274,17 @@ var ts; case 220 /* FunctionDeclaration */: case 147 /* MethodDeclaration */: case 146 /* MethodSignature */: - //case SyntaxKind.MemberFunctionDeclaration: + // case SyntaxKind.MemberFunctionDeclaration: case 149 /* GetAccessor */: case 150 /* SetAccessor */: - ///case SyntaxKind.MethodSignature: + // case SyntaxKind.MethodSignature: case 151 /* CallSignature */: case 179 /* FunctionExpression */: case 148 /* Constructor */: case 180 /* ArrowFunction */: - //case SyntaxKind.ConstructorDeclaration: - //case SyntaxKind.SimpleArrowFunctionExpression: - //case SyntaxKind.ParenthesizedArrowFunctionExpression: + // case SyntaxKind.ConstructorDeclaration: + // case SyntaxKind.SimpleArrowFunctionExpression: + // case SyntaxKind.ParenthesizedArrowFunctionExpression: case 222 /* InterfaceDeclaration */: return true; } @@ -48254,6 +48436,7 @@ var ts; })(formatting = ts.formatting || (ts.formatting = {})); })(ts || (ts = {})); /// +/* tslint:disable:no-null-keyword */ /* @internal */ var ts; (function (ts) { @@ -48271,9 +48454,9 @@ var ts; }; RulesMap.prototype.Initialize = function (rules) { this.mapRowLength = 138 /* LastToken */ + 1; - this.map = new Array(this.mapRowLength * this.mapRowLength); //new Array(this.mapRowLength * this.mapRowLength); + this.map = new Array(this.mapRowLength * this.mapRowLength); // new Array(this.mapRowLength * this.mapRowLength); // This array is used only during construction of the rulesbucket in the map - var rulesBucketConstructionStateList = new Array(this.map.length); //new Array(this.map.length); + var rulesBucketConstructionStateList = new Array(this.map.length); // new Array(this.map.length); this.FillRules(rules, rulesBucketConstructionStateList); return this.map; }; @@ -48285,7 +48468,7 @@ var ts; }; RulesMap.prototype.GetRuleBucketIndex = function (row, column) { var rulesBucketIndex = (row * this.mapRowLength) + column; - //Debug.Assert(rulesBucketIndex < this.map.Length, "Trying to access an index outside the array."); + // Debug.Assert(rulesBucketIndex < this.map.Length, "Trying to access an index outside the array."); return rulesBucketIndex; }; RulesMap.prototype.FillRule = function (rule, rulesBucketConstructionStateList) { @@ -48537,6 +48720,7 @@ var ts; /// /// /// +/* tslint:disable:no-null-keyword */ /* @internal */ var ts; (function (ts) { @@ -49058,7 +49242,7 @@ var ts; // if there are any tokens that logically belong to node and interleave child nodes // such tokens will be consumed in processChildNode for for the child that follows them ts.forEachChild(node, function (child) { - processChildNode(child, /*inheritedIndentation*/ -1 /* Unknown */, node, nodeDynamicIndentation, nodeStartLine, undecoratedNodeStartLine, /*isListElement*/ false); + processChildNode(child, /*inheritedIndentation*/ -1 /* Unknown */, node, nodeDynamicIndentation, nodeStartLine, undecoratedNodeStartLine, /*isListItem*/ false); }, function (nodes) { processChildNodes(nodes, node, nodeStartLine, nodeDynamicIndentation); }); @@ -49149,7 +49333,7 @@ var ts; var inheritedIndentation = -1 /* Unknown */; for (var i = 0; i < nodes.length; i++) { var child = nodes[i]; - inheritedIndentation = processChildNode(child, inheritedIndentation, node, listDynamicIndentation, startLine, startLine, /*isListElement*/ true, /*isFirstListItem*/ i === 0); + inheritedIndentation = processChildNode(child, inheritedIndentation, node, listDynamicIndentation, startLine, startLine, /*isListItem*/ true, /*isFirstListItem*/ i === 0); } if (listEndToken !== 0 /* Unknown */) { if (formattingScanner.isOnToken()) { @@ -49279,7 +49463,7 @@ var ts; // Handle the case where the next line is moved to be the end of this line. // In this case we don't indent the next line in the next pass. if (currentParent.getStart(sourceFile) === currentItem.pos) { - dynamicIndentation.recomputeIndentation(/*lineAdded*/ false); + dynamicIndentation.recomputeIndentation(/*lineAddedByFormatting*/ false); } } else if (rule.Operation.Action & 4 /* NewLine */ && currentStartLine === previousStartLine) { @@ -49288,7 +49472,7 @@ var ts; // In this case we indent token2 in the next pass but we set // sameLineIndent flag to notify the indenter that the indentation is within the line. if (currentParent.getStart(sourceFile) === currentItem.pos) { - dynamicIndentation.recomputeIndentation(/*lineAdded*/ true); + dynamicIndentation.recomputeIndentation(/*lineAddedByFormatting*/ true); } } // We need to trim trailing whitespace between the tokens if they were on different lines, and no rule was applied to put them on the same line @@ -49336,7 +49520,7 @@ var ts; else { parts = []; var startPos = commentRange.pos; - for (var line = startLine; line < endLine; ++line) { + for (var line = startLine; line < endLine; line++) { var endOfLine = ts.getEndLinePosition(line, sourceFile); parts.push({ pos: startPos, end: endOfLine }); startPos = ts.getStartPositionOfLine(line + 1, sourceFile); @@ -49355,7 +49539,7 @@ var ts; } // shift all parts on the delta size var delta = indentation - nonWhitespaceColumnInFirstPart.column; - for (var i = startIndex, len = parts.length; i < len; ++i, ++startLine) { + for (var i = startIndex, len = parts.length; i < len; i++, startLine++) { var startLinePos_1 = ts.getStartPositionOfLine(startLine, sourceFile); var nonWhitespaceCharacterAndColumn = i === 0 ? nonWhitespaceColumnInFirstPart @@ -49371,7 +49555,7 @@ var ts; } } function trimTrailingWhitespacesForLines(line1, line2, range) { - for (var line = line1; line < line2; ++line) { + for (var line = line1; line < line2; line++) { var lineStartPosition = ts.getStartPositionOfLine(line, sourceFile); var lineEndPosition = ts.getEndLinePosition(line, sourceFile); // do not trim whitespaces in comments or template expression @@ -49422,7 +49606,6 @@ var ts; } } function applyRuleEdits(rule, previousRange, previousStartLine, currentRange, currentStartLine) { - var between; switch (rule.Operation.Action) { case 1 /* Ignore */: // no action required @@ -49459,14 +49642,6 @@ var ts; } } } - function isSomeBlock(kind) { - switch (kind) { - case 199 /* Block */: - case 226 /* ModuleBlock */: - return true; - } - return false; - } function getOpenTokenForList(node, list) { switch (node.kind) { case 148 /* Constructor */: @@ -49525,7 +49700,7 @@ var ts; internedTabsIndentation = []; } if (internedTabsIndentation[tabs] === undefined) { - internedTabsIndentation[tabs] = tabString = repeat('\t', tabs); + internedTabsIndentation[tabs] = tabString = repeat("\t", tabs); } else { tabString = internedTabsIndentation[tabs]; @@ -49550,7 +49725,7 @@ var ts; } function repeat(value, count) { var s = ""; - for (var i = 0; i < count; ++i) { + for (var i = 0; i < count; i++) { s += value; } return s; @@ -49866,7 +50041,7 @@ var ts; // walk toward the start of the list starting from current node and check if the line is the same for all items. // if end line for item [i - 1] differs from the start line for item [i] - find column of the first non-whitespace character on the line of item [i] var lineAndCharacter = getStartLineAndCharacterForNode(node, sourceFile); - for (var i = index - 1; i >= 0; --i) { + for (var i = index - 1; i >= 0; i--) { if (list[i].kind === 24 /* CommaToken */) { continue; } @@ -49893,7 +50068,7 @@ var ts; function findFirstNonWhitespaceCharacterAndColumn(startPos, endPos, sourceFile, options) { var character = 0; var column = 0; - for (var pos = startPos; pos < endPos; ++pos) { + for (var pos = startPos; pos < endPos; pos++) { var ch = sourceFile.text.charCodeAt(pos); if (!ts.isWhiteSpace(ch)) { break; @@ -49987,7 +50162,7 @@ var ts; Function returns true when the parent node should indent the given child by an explicit rule */ function shouldIndentChildNode(parent, child) { - return nodeContentIsAlwaysIndented(parent.kind) || nodeWillIndentChild(parent, child, false); + return nodeContentIsAlwaysIndented(parent.kind) || nodeWillIndentChild(parent, child, /*indentByDefault*/ false); } SmartIndenter.shouldIndentChildNode = shouldIndentChildNode; })(SmartIndenter = formatting.SmartIndenter || (formatting.SmartIndenter = {})); @@ -50809,49 +50984,55 @@ var ts; (function (ScriptElementKind) { ScriptElementKind.unknown = ""; ScriptElementKind.warning = "warning"; - // predefined type (void) or keyword (class) + /** predefined type (void) or keyword (class) */ ScriptElementKind.keyword = "keyword"; - // top level script node + /** top level script node */ ScriptElementKind.scriptElement = "script"; - // module foo {} + /** module foo {} */ ScriptElementKind.moduleElement = "module"; - // class X {} + /** class X {} */ ScriptElementKind.classElement = "class"; - // var x = class X {} + /** var x = class X {} */ ScriptElementKind.localClassElement = "local class"; - // interface Y {} + /** interface Y {} */ ScriptElementKind.interfaceElement = "interface"; - // type T = ... + /** type T = ... */ ScriptElementKind.typeElement = "type"; - // enum E + /** enum E */ ScriptElementKind.enumElement = "enum"; - // Inside module and script only - // const v = .. + /** + * Inside module and script only + * const v = .. + */ ScriptElementKind.variableElement = "var"; - // Inside function + /** Inside function */ ScriptElementKind.localVariableElement = "local var"; - // Inside module and script only - // function f() { } + /** + * Inside module and script only + * function f() { } + */ ScriptElementKind.functionElement = "function"; - // Inside function + /** Inside function */ ScriptElementKind.localFunctionElement = "local function"; - // class X { [public|private]* foo() {} } + /** class X { [public|private]* foo() {} } */ ScriptElementKind.memberFunctionElement = "method"; - // class X { [public|private]* [get|set] foo:number; } + /** class X { [public|private]* [get|set] foo:number; } */ ScriptElementKind.memberGetAccessorElement = "getter"; ScriptElementKind.memberSetAccessorElement = "setter"; - // class X { [public|private]* foo:number; } - // interface Y { foo:number; } + /** + * class X { [public|private]* foo:number; } + * interface Y { foo:number; } + */ ScriptElementKind.memberVariableElement = "property"; - // class X { constructor() { } } + /** class X { constructor() { } } */ ScriptElementKind.constructorImplementationElement = "constructor"; - // interface Y { ():number; } + /** interface Y { ():number; } */ ScriptElementKind.callSignatureElement = "call"; - // interface Y { []:number; } + /** interface Y { []:number; } */ ScriptElementKind.indexSignatureElement = "index"; - // interface Y { new():Y; } + /** interface Y { new():Y; } */ ScriptElementKind.constructSignatureElement = "construct"; - // function foo(*Y*: string) + /** function foo(*Y*: string) */ ScriptElementKind.parameterElement = "parameter"; ScriptElementKind.typeParameterElement = "type parameter"; ScriptElementKind.primitiveType = "primitive type"; @@ -52236,9 +52417,9 @@ var ts; // Check if the caret is at the end of an identifier; this is a partial identifier that we want to complete: e.g. a.toS| // Skip this partial identifier and adjust the contextToken to the token that precedes it. if (contextToken && position <= contextToken.end && ts.isWord(contextToken.kind)) { - var start_6 = new Date().getTime(); + var start_5 = new Date().getTime(); contextToken = ts.findPrecedingToken(contextToken.getFullStart(), sourceFile); - log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_6)); + log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_5)); } // Find the node where completion is requested on. // Also determine whether we are trying to complete with members of that node @@ -52518,13 +52699,13 @@ var ts; || contextToken.kind === 166 /* StringLiteralType */ || contextToken.kind === 10 /* RegularExpressionLiteral */ || ts.isTemplateLiteralKind(contextToken.kind)) { - var start_7 = contextToken.getStart(); + var start_6 = contextToken.getStart(); var end = contextToken.getEnd(); // To be "in" one of these literals, the position has to be: // 1. entirely within the token text. // 2. at the end position of an unterminated token. // 3. at the end of a regular expression (due to trailing flags like '/foo/g'). - if (start_7 < position && position < end) { + if (start_6 < position && position < end) { return true; } if (position === end) { @@ -53759,8 +53940,7 @@ var ts; } function getDocumentHighlights(fileName, position, filesToSearch) { synchronizeHostData(); - filesToSearch = ts.map(filesToSearch, ts.normalizeSlashes); - var sourceFilesToSearch = ts.filter(program.getSourceFiles(), function (f) { return ts.contains(filesToSearch, f.fileName); }); + var sourceFilesToSearch = ts.map(filesToSearch, function (f) { return program.getSourceFile(f); }); var sourceFile = getValidSourceFile(fileName); var node = ts.getTouchingWord(sourceFile, position); if (!node) { @@ -55150,7 +55330,8 @@ var ts; /// NavigateTo function getNavigateToItems(searchValue, maxResultCount) { synchronizeHostData(); - return ts.NavigateTo.getNavigateToItems(program, cancellationToken, searchValue, maxResultCount); + var checker = getProgram().getTypeChecker(); + return ts.NavigateTo.getNavigateToItems(program, checker, cancellationToken, searchValue, maxResultCount); } function getEmitOutput(fileName) { synchronizeHostData(); @@ -57559,6 +57740,9 @@ var ts; LanguageServiceShimHostAdapter.prototype.getCurrentDirectory = function () { return this.shimHost.getCurrentDirectory(); }; + LanguageServiceShimHostAdapter.prototype.getDirectories = function (path) { + return this.shimHost.getDirectories(path); + }; LanguageServiceShimHostAdapter.prototype.getDefaultLibFileName = function (options) { return this.shimHost.getDefaultLibFileName(JSON.stringify(options)); }; From b3531b01584d5ff47278f1569ff449cf3a472c72 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 25 May 2016 12:25:53 -0700 Subject: [PATCH 23/61] add a extra check to avoid rescans --- scripts/tslint/booleanTriviaRule.ts | 2 +- src/services/utilities.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/tslint/booleanTriviaRule.ts b/scripts/tslint/booleanTriviaRule.ts index 756728a1a11..b626b7560a6 100644 --- a/scripts/tslint/booleanTriviaRule.ts +++ b/scripts/tslint/booleanTriviaRule.ts @@ -18,7 +18,7 @@ class BooleanTriviaWalker extends Lint.RuleWalker { visitCallExpression(node: ts.CallExpression) { super.visitCallExpression(node); - if (node.arguments) { + if (node.arguments && node.arguments.some(arg => arg.kind === ts.SyntaxKind.TrueKeyword || arg.kind === ts.SyntaxKind.FalseKeyword)) { const targetCallSignature = this.checker.getResolvedSignature(node); if (!!targetCallSignature) { const targetParameters = targetCallSignature.getParameters(); diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 34ae39c02d4..f4617395c43 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -267,6 +267,9 @@ namespace ts { // find the child that contains 'position' for (let i = 0, n = current.getChildCount(sourceFile); i < n; i++) { const child = current.getChildAt(i); + if (position < child.getFullStart() || position > child.getEnd()) { + continue; + } const start = allowPositionInLeadingTrivia ? child.getFullStart() : child.getStart(sourceFile); if (start <= position) { const end = child.getEnd(); From 1e41af30fee7fbdb1b7e2bb1130ae183abd0a7ab Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 25 May 2016 12:27:29 -0700 Subject: [PATCH 24/61] Update LKG --- lib/tsc.js | 2 +- lib/tsserver.js | 2 +- lib/tsserverlibrary.js | 2 +- lib/typescript.js | 9 ++++----- lib/typescriptServices.js | 9 ++++----- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/tsc.js b/lib/tsc.js index 00c758c0446..ca303c49f7b 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -18090,7 +18090,7 @@ var ts; inferFromTypes(source, t); } } - if (target.flags & 16384 && typeParameterCount === 1) { + if (typeParameterCount === 1) { inferiority++; inferFromTypes(source, typeParameter); inferiority--; diff --git a/lib/tsserver.js b/lib/tsserver.js index 7eb744a77d3..dcf76693225 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -18854,7 +18854,7 @@ var ts; inferFromTypes(source, t); } } - if (target.flags & 16384 && typeParameterCount === 1) { + if (typeParameterCount === 1) { inferiority++; inferFromTypes(source, typeParameter); inferiority--; diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 902bfcf610e..f16d02e472c 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -18854,7 +18854,7 @@ var ts; inferFromTypes(source, t); } } - if (target.flags & 16384 && typeParameterCount === 1) { + if (typeParameterCount === 1) { inferiority++; inferFromTypes(source, typeParameter); inferiority--; diff --git a/lib/typescript.js b/lib/typescript.js index 19fffd35501..cf982a3ede9 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -21958,11 +21958,10 @@ var ts; inferFromTypes(source, t); } } - // Next, if target is a union type containing a single naked type parameter, make a - // secondary inference to that type parameter. We don't do this for intersection types - // because in a target type like Foo & T we don't know how which parts of the source type - // should be matched by Foo and which should be inferred to T. - if (target.flags & 16384 /* Union */ && typeParameterCount === 1) { + // Next, if target containings a single naked type parameter, make a secondary inference to that type + // parameter. This gives meaningful results for union types in co-variant positions and intersection + // types in contra-variant positions (such as callback parameters). + if (typeParameterCount === 1) { inferiority++; inferFromTypes(source, typeParameter); inferiority--; diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 19fffd35501..cf982a3ede9 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -21958,11 +21958,10 @@ var ts; inferFromTypes(source, t); } } - // Next, if target is a union type containing a single naked type parameter, make a - // secondary inference to that type parameter. We don't do this for intersection types - // because in a target type like Foo & T we don't know how which parts of the source type - // should be matched by Foo and which should be inferred to T. - if (target.flags & 16384 /* Union */ && typeParameterCount === 1) { + // Next, if target containings a single naked type parameter, make a secondary inference to that type + // parameter. This gives meaningful results for union types in co-variant positions and intersection + // types in contra-variant positions (such as callback parameters). + if (typeParameterCount === 1) { inferiority++; inferFromTypes(source, typeParameter); inferiority--; From 7ddb1631bc923c79d6c3f1b6bd10797f6aeac6be Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 25 May 2016 13:38:53 -0700 Subject: [PATCH 25/61] Remove many uses of 'null' in harness. Remaining uses should be commented. --- src/harness/compilerRunner.ts | 1 + src/harness/external/chai.d.ts | 3 +- src/harness/fourslash.ts | 43 +++++++++++++-------------- src/harness/fourslashRunner.ts | 1 - src/harness/harness.ts | 39 ++++++++++++------------ src/harness/harnessLanguageService.ts | 2 +- src/harness/loggedIO.ts | 6 ++-- src/harness/projectsRunner.ts | 3 +- src/harness/runner.ts | 2 -- src/harness/rwcRunner.ts | 5 ++-- src/harness/test262Runner.ts | 1 + 11 files changed, 51 insertions(+), 55 deletions(-) diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index d368293bd65..1a83f8c4582 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -1,6 +1,7 @@ /// /// /// +// In harness baselines, null is different than undefined. See `generateActual` in `harness.ts`. /* tslint:disable:no-null-keyword */ const enum CompilerTestType { diff --git a/src/harness/external/chai.d.ts b/src/harness/external/chai.d.ts index 814de75e7b2..59cf2834b27 100644 --- a/src/harness/external/chai.d.ts +++ b/src/harness/external/chai.d.ts @@ -169,7 +169,6 @@ declare module chai { function notEqual(actual: any, expected: any, message?: string): void; function isTrue(value: any, message?: string): void; function isFalse(value: any, message?: string): void; - function isNull(value: any, message?: string): void; - function isNotNull(value: any, message?: string): void; + function isOk(actual: any, message?: string): void; } } \ No newline at end of file diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 4fd3161d1dc..0f11d12097d 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -18,7 +18,6 @@ /// /// /// -/* tslint:disable:no-null-keyword */ namespace FourSlash { ts.disableIncrementalParsing = false; @@ -198,7 +197,7 @@ namespace FourSlash { public lastKnownMarker: string = ""; // The file that's currently 'opened' - public activeFile: FourSlashFile = null; + public activeFile: FourSlashFile; // Whether or not we should format on keystrokes public enableFormatting = true; @@ -922,7 +921,7 @@ namespace FourSlash { public verifyCurrentParameterIsletiable(isVariable: boolean) { const signature = this.getActiveSignatureHelpItem(); - assert.isNotNull(signature); + assert.isOk(signature); assert.equal(isVariable, signature.isVariadic); } @@ -1911,7 +1910,7 @@ namespace FourSlash { public verifyNavigationItemsCount(expected: number, searchValue: string, matchKind?: string) { const items = this.languageService.getNavigateToItems(searchValue); let actual = 0; - let item: ts.NavigateToItem = null; + let item: ts.NavigateToItem; // Count only the match that match the same MatchKind for (let i = 0; i < items.length; i++) { @@ -2183,7 +2182,7 @@ namespace FourSlash { } private findFile(indexOrName: any) { - let result: FourSlashFile = null; + let result: FourSlashFile; if (typeof indexOrName === "number") { const index = indexOrName; if (index >= this.testData.files.length) { @@ -2352,9 +2351,15 @@ ${code} const ranges: Range[] = []; // Stuff related to the subfile we're parsing - let currentFileContent: string = null; + let currentFileContent: string = undefined; let currentFileName = fileName; let currentFileOptions: { [s: string]: string } = {}; + + function resetLocalData() { + currentFileContent = undefined; + currentFileOptions = {}; + currentFileName = fileName; + } for (let i = 0; i < lines.length; i++) { let line = lines[i]; @@ -2368,7 +2373,7 @@ ${code} // Subfile content line // Append to the current subfile content, inserting a newline needed - if (currentFileContent === null) { + if (currentFileContent === undefined) { currentFileContent = ""; } else { @@ -2400,10 +2405,7 @@ ${code} // Store result file files.push(file); - // Reset local data - currentFileContent = null; - currentFileOptions = {}; - currentFileName = fileName; + resetLocalData(); } currentFileName = basePath + "/" + match[2]; @@ -2430,10 +2432,7 @@ ${code} // Store result file files.push(file); - // Reset local data - currentFileContent = null; - currentFileOptions = {}; - currentFileName = fileName; + resetLocalData(); } } } @@ -2498,7 +2497,7 @@ ${code} if (markerValue === undefined) { reportError(fileName, location.sourceLine, location.sourceColumn, "Object markers can not be empty"); - return null; + return undefined; } const marker: Marker = { @@ -2527,7 +2526,7 @@ ${code} if (markerMap[name] !== undefined) { const message = "Marker '" + name + "' is duplicated in the source file contents."; reportError(marker.fileName, location.sourceLine, location.sourceColumn, message); - return null; + return undefined; } else { markerMap[name] = marker; @@ -2546,7 +2545,7 @@ ${code} let output = ""; /// The current marker (or maybe multi-line comment?) we're parsing, possibly - let openMarker: LocationInformation = null; + let openMarker: LocationInformation = undefined; /// A stack of the open range markers that are still unclosed const openRanges: RangeLocationInformation[] = []; @@ -2654,7 +2653,7 @@ ${code} difference += i + 1 - openMarker.sourcePosition; // Reset the state - openMarker = null; + openMarker = undefined; state = State.none; } break; @@ -2676,7 +2675,7 @@ ${code} difference += i + 1 - openMarker.sourcePosition; // Reset the state - openMarker = null; + openMarker = undefined; state = State.none; } else if (validMarkerChars.indexOf(currentChar) < 0) { @@ -2688,7 +2687,7 @@ ${code} // Bail out the text we've gathered so far back into the output flush(i); lastNormalCharPosition = i; - openMarker = null; + openMarker = undefined; state = State.none; } @@ -2719,7 +2718,7 @@ ${code} reportError(fileName, openRange.sourceLine, openRange.sourceColumn, "Unterminated range."); } - if (openMarker !== null) { + if (openMarker) { reportError(fileName, openMarker.sourceLine, openMarker.sourceColumn, "Unterminated marker."); } diff --git a/src/harness/fourslashRunner.ts b/src/harness/fourslashRunner.ts index 386bd9e340c..0047e851fc1 100644 --- a/src/harness/fourslashRunner.ts +++ b/src/harness/fourslashRunner.ts @@ -1,7 +1,6 @@ /// /// /// -/* tslint:disable:no-null-keyword */ const enum FourSlashTestType { Native, diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 5b26829cf4a..d6959c2a54f 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -23,7 +23,6 @@ /// /// /// -/* tslint:disable:no-null-keyword */ // Block scoped definitions work poorly for global variables, temporarily enable var /* tslint:disable:no-var-keyword */ @@ -32,7 +31,7 @@ var _chai: typeof chai = require("chai"); var assert: typeof _chai.assert = _chai.assert; declare var __dirname: string; // Node-specific -var global = Function("return this").call(null); +var global = Function("return this").call(undefined); /* tslint:enable:no-var-keyword */ namespace Utils { @@ -558,15 +557,9 @@ namespace Harness { } export function directoryName(path: string) { - let dirPath = pathModule.dirname(path); - + const dirPath = pathModule.dirname(path); // Node will just continue to repeat the root path, rather than return null - if (dirPath === path) { - dirPath = null; - } - else { - return dirPath; - } + return dirPath === path ? undefined : dirPath; } export let listFiles: typeof IO.listFiles = (path, spec?, options?) => { @@ -634,7 +627,7 @@ namespace Harness { xhr.send(); } catch (e) { - return { status: 404, responseText: null }; + return { status: 404, responseText: undefined }; } return waitForXHR(xhr); @@ -651,7 +644,7 @@ namespace Harness { } catch (e) { log(`XHR Error: ${e}`); - return { status: 500, responseText: null }; + return { status: 500, responseText: undefined }; } return waitForXHR(xhr); @@ -663,7 +656,7 @@ namespace Harness { } export function deleteFile(path: string) { - Http.writeToServerSync(serverRoot + path, "DELETE", null); + Http.writeToServerSync(serverRoot + path, "DELETE"); } export function directoryExists(path: string): boolean { @@ -674,7 +667,7 @@ namespace Harness { let dirPath = path; // root of the server if (dirPath.match(/localhost:\d+$/) || dirPath.match(/localhost:\d+\/$/)) { - dirPath = null; + dirPath = undefined; // path + fileName } else if (dirPath.indexOf(".") === -1) { @@ -722,7 +715,7 @@ namespace Harness { return response.responseText; } else { - return null; + return undefined; } } @@ -1418,7 +1411,9 @@ namespace Harness { const opts: CompilerSettings = {}; let match: RegExpExecArray; - while ((match = optionRegex.exec(content)) != null) { + /* tslint:disable:no-null-keyword */ + while ((match = optionRegex.exec(content)) !== null) { + /* tslint:enable:no-null-keyword */ opts[match[1]] = match[2]; } @@ -1435,9 +1430,9 @@ namespace Harness { const lines = Utils.splitContentByNewlines(code); // Stuff related to the subfile we're parsing - let currentFileContent: string = null; + let currentFileContent: string = undefined; let currentFileOptions: any = {}; - let currentFileName: any = null; + let currentFileName: any = undefined; let refs: string[] = []; for (let i = 0; i < lines.length; i++) { @@ -1465,7 +1460,7 @@ namespace Harness { testUnitData.push(newTestFile); // Reset local data - currentFileContent = null; + currentFileContent = undefined; currentFileOptions = {}; currentFileName = testMetaData[2]; refs = []; @@ -1478,7 +1473,7 @@ namespace Harness { else { // Subfile content line // Append to the current subfile content, inserting a newline needed - if (currentFileContent === null) { + if (currentFileContent === undefined) { currentFileContent = ""; } else { @@ -1601,7 +1596,9 @@ namespace Harness { // Store the content in the 'local' folder so we // can accept it later (manually) + /* tslint:disable:no-null-keyword */ if (actual !== null) { + /* tslint:enable:no-null-keyword */ IO.writeFile(actualFileName, actual); } @@ -1618,7 +1615,9 @@ namespace Harness { const refFileName = referencePath(relativeFileName, opts && opts.Baselinefolder, opts && opts.Subfolder); + /* tslint:disable:no-null-keyword */ if (actual === null) { + /* tslint:enable:no-null-keyword */ actual = ""; } diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index bd370b3601b..b3478e40609 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -172,7 +172,7 @@ namespace Harness.LanguageService { */ public positionToLineAndCharacter(fileName: string, position: number): ts.LineAndCharacter { const script: ScriptInfo = this.fileNameToScript[fileName]; - assert.isNotNull(script); + assert.isOk(script); return ts.computeLineAndCharacterOfPosition(script.getLineMap(), position); } diff --git a/src/harness/loggedIO.ts b/src/harness/loggedIO.ts index d468b371fbe..1c399b30a1d 100644 --- a/src/harness/loggedIO.ts +++ b/src/harness/loggedIO.ts @@ -1,7 +1,6 @@ /// /// /// -/* tslint:disable:no-null-keyword */ interface FileInformation { contents: string; @@ -94,7 +93,7 @@ namespace Playback { return lookup[s] = func(s); }); run.reset = () => { - lookup = null; + lookup = undefined; }; return run; @@ -170,7 +169,8 @@ namespace Playback { path => callAndRecord(underlying.fileExists(path), recordLog.fileExists, { path }), memoize(path => { // If we read from the file, it must exist - if (findResultByPath(wrapper, replayLog.filesRead, path, null) !== null) { + const noResult = {}; + if (findResultByPath(wrapper, replayLog.filesRead, path, noResult) !== noResult) { return true; } else { diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 9ee4359d8d3..d4e91d43efe 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -1,6 +1,5 @@ /// /// -/* tslint:disable:no-null-keyword */ // Test case is json of below type in tests/cases/project/ interface ProjectRunnerTestCase { @@ -53,7 +52,7 @@ class ProjectRunner extends RunnerBase { private runProjectTestCase(testCaseFileName: string) { let testCase: ProjectRunnerTestCase & ts.CompilerOptions; - let testFileText: string = null; + let testFileText: string; try { testFileText = Harness.IO.readFile(testCaseFileName); } diff --git a/src/harness/runner.ts b/src/harness/runner.ts index bb3cafea0a8..b56959d7e5d 100644 --- a/src/harness/runner.ts +++ b/src/harness/runner.ts @@ -20,8 +20,6 @@ /// /// -/* tslint:disable:no-null-keyword */ - let runners: RunnerBase[] = []; let iterations = 1; diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index 39231435bf5..99b1ce8cc88 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -2,6 +2,7 @@ /// /// /// +// In harness baselines, null is different than undefined. See `generateActual` in `harness.ts`. /* tslint:disable:no-null-keyword */ namespace RWC { @@ -123,7 +124,7 @@ namespace RWC { opts.options.noLib = true; // Emit the results - compilerOptions = null; + compilerOptions = undefined; const output = Harness.Compiler.compileFiles( inputFiles, otherFiles, @@ -139,7 +140,7 @@ namespace RWC { function getHarnessCompilerInputUnit(fileName: string): Harness.Compiler.TestFile { const unitName = ts.normalizeSlashes(Harness.IO.resolvePath(fileName)); - let content: string = null; + let content: string; try { content = Harness.IO.readFile(unitName); } diff --git a/src/harness/test262Runner.ts b/src/harness/test262Runner.ts index cc9957c1fac..241af5f3d00 100644 --- a/src/harness/test262Runner.ts +++ b/src/harness/test262Runner.ts @@ -1,5 +1,6 @@ /// /// +// In harness baselines, null is different than undefined. See `generateActual` in `harness.ts`. /* tslint:disable:no-null-keyword */ class Test262BaselineRunner extends RunnerBase { From 6ab389174ce8b6513d8040370042c2730549b449 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 25 May 2016 16:46:20 -0700 Subject: [PATCH 26/61] Accept baselines --- .../assignmentCompatability10.symbols | 46 +++++++++++++++++ .../reference/assignmentCompatability10.types | 51 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 tests/baselines/reference/assignmentCompatability10.symbols create mode 100644 tests/baselines/reference/assignmentCompatability10.types diff --git a/tests/baselines/reference/assignmentCompatability10.symbols b/tests/baselines/reference/assignmentCompatability10.symbols new file mode 100644 index 00000000000..d4fdcd73241 --- /dev/null +++ b/tests/baselines/reference/assignmentCompatability10.symbols @@ -0,0 +1,46 @@ +=== tests/cases/compiler/assignmentCompatability10.ts === +module __test1__ { +>__test1__ : Symbol(__test1__, Decl(assignmentCompatability10.ts, 0, 0)) + + export interface interfaceWithPublicAndOptional { one: T; two?: U; }; var obj4: interfaceWithPublicAndOptional = { one: 1 };; +>interfaceWithPublicAndOptional : Symbol(interfaceWithPublicAndOptional, Decl(assignmentCompatability10.ts, 0, 18)) +>T : Symbol(T, Decl(assignmentCompatability10.ts, 1, 52)) +>U : Symbol(U, Decl(assignmentCompatability10.ts, 1, 54)) +>one : Symbol(interfaceWithPublicAndOptional.one, Decl(assignmentCompatability10.ts, 1, 58)) +>T : Symbol(T, Decl(assignmentCompatability10.ts, 1, 52)) +>two : Symbol(interfaceWithPublicAndOptional.two, Decl(assignmentCompatability10.ts, 1, 66)) +>U : Symbol(U, Decl(assignmentCompatability10.ts, 1, 54)) +>obj4 : Symbol(obj4, Decl(assignmentCompatability10.ts, 1, 83)) +>interfaceWithPublicAndOptional : Symbol(interfaceWithPublicAndOptional, Decl(assignmentCompatability10.ts, 0, 18)) +>one : Symbol(one, Decl(assignmentCompatability10.ts, 1, 139)) + + export var __val__obj4 = obj4; +>__val__obj4 : Symbol(__val__obj4, Decl(assignmentCompatability10.ts, 2, 14)) +>obj4 : Symbol(obj4, Decl(assignmentCompatability10.ts, 1, 83)) +} +module __test2__ { +>__test2__ : Symbol(__test2__, Decl(assignmentCompatability10.ts, 3, 1)) + + export class classWithPublicAndOptional { constructor(public one: T, public two?: U) {} } var x4 = new classWithPublicAndOptional(1);; +>classWithPublicAndOptional : Symbol(classWithPublicAndOptional, Decl(assignmentCompatability10.ts, 4, 18)) +>T : Symbol(T, Decl(assignmentCompatability10.ts, 5, 44)) +>U : Symbol(U, Decl(assignmentCompatability10.ts, 5, 46)) +>one : Symbol(classWithPublicAndOptional.one, Decl(assignmentCompatability10.ts, 5, 63)) +>T : Symbol(T, Decl(assignmentCompatability10.ts, 5, 44)) +>two : Symbol(classWithPublicAndOptional.two, Decl(assignmentCompatability10.ts, 5, 77)) +>U : Symbol(U, Decl(assignmentCompatability10.ts, 5, 46)) +>x4 : Symbol(x4, Decl(assignmentCompatability10.ts, 5, 104)) +>classWithPublicAndOptional : Symbol(classWithPublicAndOptional, Decl(assignmentCompatability10.ts, 4, 18)) + + export var __val__x4 = x4; +>__val__x4 : Symbol(__val__x4, Decl(assignmentCompatability10.ts, 6, 14)) +>x4 : Symbol(x4, Decl(assignmentCompatability10.ts, 5, 104)) +} +__test2__.__val__x4 = __test1__.__val__obj4 +>__test2__.__val__x4 : Symbol(__test2__.__val__x4, Decl(assignmentCompatability10.ts, 6, 14)) +>__test2__ : Symbol(__test2__, Decl(assignmentCompatability10.ts, 3, 1)) +>__val__x4 : Symbol(__test2__.__val__x4, Decl(assignmentCompatability10.ts, 6, 14)) +>__test1__.__val__obj4 : Symbol(__test1__.__val__obj4, Decl(assignmentCompatability10.ts, 2, 14)) +>__test1__ : Symbol(__test1__, Decl(assignmentCompatability10.ts, 0, 0)) +>__val__obj4 : Symbol(__test1__.__val__obj4, Decl(assignmentCompatability10.ts, 2, 14)) + diff --git a/tests/baselines/reference/assignmentCompatability10.types b/tests/baselines/reference/assignmentCompatability10.types new file mode 100644 index 00000000000..f4c2bba451d --- /dev/null +++ b/tests/baselines/reference/assignmentCompatability10.types @@ -0,0 +1,51 @@ +=== tests/cases/compiler/assignmentCompatability10.ts === +module __test1__ { +>__test1__ : typeof __test1__ + + export interface interfaceWithPublicAndOptional { one: T; two?: U; }; var obj4: interfaceWithPublicAndOptional = { one: 1 };; +>interfaceWithPublicAndOptional : interfaceWithPublicAndOptional +>T : T +>U : U +>one : T +>T : T +>two : U +>U : U +>obj4 : interfaceWithPublicAndOptional +>interfaceWithPublicAndOptional : interfaceWithPublicAndOptional +>{ one: 1 } : { one: number; } +>one : number +>1 : number + + export var __val__obj4 = obj4; +>__val__obj4 : interfaceWithPublicAndOptional +>obj4 : interfaceWithPublicAndOptional +} +module __test2__ { +>__test2__ : typeof __test2__ + + export class classWithPublicAndOptional { constructor(public one: T, public two?: U) {} } var x4 = new classWithPublicAndOptional(1);; +>classWithPublicAndOptional : classWithPublicAndOptional +>T : T +>U : U +>one : T +>T : T +>two : U +>U : U +>x4 : classWithPublicAndOptional +>new classWithPublicAndOptional(1) : classWithPublicAndOptional +>classWithPublicAndOptional : typeof classWithPublicAndOptional +>1 : number + + export var __val__x4 = x4; +>__val__x4 : classWithPublicAndOptional +>x4 : classWithPublicAndOptional +} +__test2__.__val__x4 = __test1__.__val__obj4 +>__test2__.__val__x4 = __test1__.__val__obj4 : __test1__.interfaceWithPublicAndOptional +>__test2__.__val__x4 : __test2__.classWithPublicAndOptional +>__test2__ : typeof __test2__ +>__val__x4 : __test2__.classWithPublicAndOptional +>__test1__.__val__obj4 : __test1__.interfaceWithPublicAndOptional +>__test1__ : typeof __test1__ +>__val__obj4 : __test1__.interfaceWithPublicAndOptional + From 42c17e194e77e4e5f32eacef1784d1407df41fe2 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 25 May 2016 17:03:33 -0700 Subject: [PATCH 27/61] Address PR comments --- src/compiler/checker.ts | 4 +- ...omputedPropertyNamesContextualType7_ES5.js | 13 +++++-- ...edPropertyNamesContextualType7_ES5.symbols | 39 ++++++++++++++----- ...utedPropertyNamesContextualType7_ES5.types | 38 +++++++++++++----- ...omputedPropertyNamesContextualType7_ES6.js | 13 +++++-- ...edPropertyNamesContextualType7_ES6.symbols | 39 ++++++++++++++----- ...utedPropertyNamesContextualType7_ES6.types | 38 +++++++++++++----- ...omputedPropertyNamesContextualType7_ES5.ts | 11 ++++-- ...omputedPropertyNamesContextualType7_ES6.ts | 11 ++++-- 9 files changed, 151 insertions(+), 55 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4768a357d2b..40998d9a633 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6036,12 +6036,10 @@ namespace ts { const resolved = resolveStructuredTypeMembers(type); if ((relation === assignableRelation || relation === comparableRelation) && (type === globalObjectType || isEmptyObjectType(resolved)) || resolved.stringIndexInfo || + (resolved.numberIndexInfo && isNumericLiteralName(name)) || getPropertyOfType(type, name)) { return true; } - if (resolved.numberIndexInfo) { - return isNumericLiteralName(name); - } } else if (type.flags & TypeFlags.UnionOrIntersection) { for (const t of (type).types) { diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js index 65cc057fa81..bc8966520f6 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js @@ -1,22 +1,26 @@ //// [computedPropertyNamesContextualType7_ES5.ts] interface I { - [s: number]: T; + [n: number]: T; +} +interface J { + [s: string]: T; } -declare function foo(obj: I): T +declare function foo(obj: I): T; +declare function g(obj: J): T; foo({ - 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0] }); + +g({ p: "" }); //// [computedPropertyNamesContextualType7_ES5.js] foo((_a = { - 101: "", 0: function () { } }, _a["hi" + "bye"] = true, @@ -24,4 +28,5 @@ foo((_a = { _a[+"hi"] = [0], _a )); +g({ p: "" }); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.symbols b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.symbols index 562b238cdac..d6889f9912d 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.symbols +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.symbols @@ -3,26 +3,45 @@ interface I { >I : Symbol(I, Decl(computedPropertyNamesContextualType7_ES5.ts, 0, 0)) >T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 0, 12)) - [s: number]: T; ->s : Symbol(s, Decl(computedPropertyNamesContextualType7_ES5.ts, 1, 5)) + [n: number]: T; +>n : Symbol(n, Decl(computedPropertyNamesContextualType7_ES5.ts, 1, 5)) >T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 0, 12)) } +interface J { +>J : Symbol(J, Decl(computedPropertyNamesContextualType7_ES5.ts, 2, 1)) +>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 3, 12)) -declare function foo(obj: I): T ->foo : Symbol(foo, Decl(computedPropertyNamesContextualType7_ES5.ts, 2, 1)) ->T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 4, 21)) ->obj : Symbol(obj, Decl(computedPropertyNamesContextualType7_ES5.ts, 4, 24)) + [s: string]: T; +>s : Symbol(s, Decl(computedPropertyNamesContextualType7_ES5.ts, 4, 5)) +>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 3, 12)) +} + +declare function foo(obj: I): T; +>foo : Symbol(foo, Decl(computedPropertyNamesContextualType7_ES5.ts, 5, 1)) +>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 7, 21)) +>obj : Symbol(obj, Decl(computedPropertyNamesContextualType7_ES5.ts, 7, 24)) >I : Symbol(I, Decl(computedPropertyNamesContextualType7_ES5.ts, 0, 0)) ->T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 4, 21)) ->T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 4, 21)) +>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 7, 21)) +>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 7, 21)) + +declare function g(obj: J): T; +>g : Symbol(g, Decl(computedPropertyNamesContextualType7_ES5.ts, 7, 38)) +>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 8, 19)) +>obj : Symbol(obj, Decl(computedPropertyNamesContextualType7_ES5.ts, 8, 22)) +>J : Symbol(J, Decl(computedPropertyNamesContextualType7_ES5.ts, 2, 1)) +>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 8, 19)) +>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 8, 19)) foo({ ->foo : Symbol(foo, Decl(computedPropertyNamesContextualType7_ES5.ts, 2, 1)) +>foo : Symbol(foo, Decl(computedPropertyNamesContextualType7_ES5.ts, 5, 1)) - 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0] }); +g({ p: "" }); +>g : Symbol(g, Decl(computedPropertyNamesContextualType7_ES5.ts, 7, 38)) +>p : Symbol(p, Decl(computedPropertyNamesContextualType7_ES5.ts, 17, 3)) + diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types index 53c8f805c57..64367864881 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types @@ -3,12 +3,20 @@ interface I { >I : I >T : T - [s: number]: T; ->s : number + [n: number]: T; +>n : number +>T : T +} +interface J { +>J : J +>T : T + + [s: string]: T; +>s : string >T : T } -declare function foo(obj: I): T +declare function foo(obj: I): T; >foo : (obj: I) => T >T : T >obj : I @@ -16,13 +24,18 @@ declare function foo(obj: I): T >T : T >T : T -foo({ ->foo({ 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | (() => void) | number | number[] ->foo : (obj: I) => T ->{ 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | (() => void) | boolean | number | number[]; [x: number]: string | (() => void) | number | number[]; 0: () => void; 101: string; } +declare function g(obj: J): T; +>g : (obj: J) => T +>T : T +>obj : J +>J : J +>T : T +>T : T - 101: "", ->"" : string +foo({ +>foo({ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : (() => void) | number | number[] +>foo : (obj: I) => T +>{ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: (() => void) | boolean | number | number[]; [x: number]: (() => void) | number | number[]; 0: () => void; } 0: () => { }, >() => { } : () => void @@ -47,3 +60,10 @@ foo({ }); +g({ p: "" }); +>g({ p: "" }) : string +>g : (obj: J) => T +>{ p: "" } : { p: string; } +>p : string +>"" : string + diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.js b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.js index 0b515dba7ca..273c15018b6 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.js @@ -1,24 +1,29 @@ //// [computedPropertyNamesContextualType7_ES6.ts] interface I { - [s: number]: T; + [n: number]: T; +} +interface J { + [s: string]: T; } -declare function foo(obj: I): T +declare function foo(obj: I): T; +declare function g(obj: J): T; foo({ - 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0] }); + +g({ p: "" }); //// [computedPropertyNamesContextualType7_ES6.js] foo({ - 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0] }); +g({ p: "" }); diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.symbols b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.symbols index ca0c2f12a80..d04c8f913bd 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.symbols +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.symbols @@ -3,26 +3,45 @@ interface I { >I : Symbol(I, Decl(computedPropertyNamesContextualType7_ES6.ts, 0, 0)) >T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 0, 12)) - [s: number]: T; ->s : Symbol(s, Decl(computedPropertyNamesContextualType7_ES6.ts, 1, 5)) + [n: number]: T; +>n : Symbol(n, Decl(computedPropertyNamesContextualType7_ES6.ts, 1, 5)) >T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 0, 12)) } +interface J { +>J : Symbol(J, Decl(computedPropertyNamesContextualType7_ES6.ts, 2, 1)) +>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 3, 12)) -declare function foo(obj: I): T ->foo : Symbol(foo, Decl(computedPropertyNamesContextualType7_ES6.ts, 2, 1)) ->T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 4, 21)) ->obj : Symbol(obj, Decl(computedPropertyNamesContextualType7_ES6.ts, 4, 24)) + [s: string]: T; +>s : Symbol(s, Decl(computedPropertyNamesContextualType7_ES6.ts, 4, 5)) +>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 3, 12)) +} + +declare function foo(obj: I): T; +>foo : Symbol(foo, Decl(computedPropertyNamesContextualType7_ES6.ts, 5, 1)) +>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 7, 21)) +>obj : Symbol(obj, Decl(computedPropertyNamesContextualType7_ES6.ts, 7, 24)) >I : Symbol(I, Decl(computedPropertyNamesContextualType7_ES6.ts, 0, 0)) ->T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 4, 21)) ->T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 4, 21)) +>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 7, 21)) +>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 7, 21)) + +declare function g(obj: J): T; +>g : Symbol(g, Decl(computedPropertyNamesContextualType7_ES6.ts, 7, 38)) +>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 8, 19)) +>obj : Symbol(obj, Decl(computedPropertyNamesContextualType7_ES6.ts, 8, 22)) +>J : Symbol(J, Decl(computedPropertyNamesContextualType7_ES6.ts, 2, 1)) +>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 8, 19)) +>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 8, 19)) foo({ ->foo : Symbol(foo, Decl(computedPropertyNamesContextualType7_ES6.ts, 2, 1)) +>foo : Symbol(foo, Decl(computedPropertyNamesContextualType7_ES6.ts, 5, 1)) - 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0] }); +g({ p: "" }); +>g : Symbol(g, Decl(computedPropertyNamesContextualType7_ES6.ts, 7, 38)) +>p : Symbol(p, Decl(computedPropertyNamesContextualType7_ES6.ts, 17, 3)) + diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types index f2eefe7405e..07aeda807b0 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types @@ -3,12 +3,20 @@ interface I { >I : I >T : T - [s: number]: T; ->s : number + [n: number]: T; +>n : number +>T : T +} +interface J { +>J : J +>T : T + + [s: string]: T; +>s : string >T : T } -declare function foo(obj: I): T +declare function foo(obj: I): T; >foo : (obj: I) => T >T : T >obj : I @@ -16,13 +24,18 @@ declare function foo(obj: I): T >T : T >T : T -foo({ ->foo({ 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | (() => void) | number | number[] ->foo : (obj: I) => T ->{ 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | (() => void) | boolean | number | number[]; [x: number]: string | (() => void) | number | number[]; 0: () => void; 101: string; } +declare function g(obj: J): T; +>g : (obj: J) => T +>T : T +>obj : J +>J : J +>T : T +>T : T - 101: "", ->"" : string +foo({ +>foo({ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : (() => void) | number | number[] +>foo : (obj: I) => T +>{ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: (() => void) | boolean | number | number[]; [x: number]: (() => void) | number | number[]; 0: () => void; } 0: () => { }, >() => { } : () => void @@ -47,3 +60,10 @@ foo({ }); +g({ p: "" }); +>g({ p: "" }) : string +>g : (obj: J) => T +>{ p: "" } : { p: string; } +>p : string +>"" : string + diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7_ES5.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7_ES5.ts index 4f124ece6d2..6d98092b968 100644 --- a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7_ES5.ts +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7_ES5.ts @@ -1,14 +1,19 @@ // @target: es5 interface I { - [s: number]: T; + [n: number]: T; +} +interface J { + [s: string]: T; } -declare function foo(obj: I): T +declare function foo(obj: I): T; +declare function g(obj: J): T; foo({ - 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0] }); + +g({ p: "" }); diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7_ES6.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7_ES6.ts index 2a7a476ca7a..459ce1471b4 100644 --- a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7_ES6.ts +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7_ES6.ts @@ -1,14 +1,19 @@ // @target: es6 interface I { - [s: number]: T; + [n: number]: T; +} +interface J { + [s: string]: T; } -declare function foo(obj: I): T +declare function foo(obj: I): T; +declare function g(obj: J): T; foo({ - 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0] }); + +g({ p: "" }); From 5a627ad1761218066bdcb2771c40750eac7d4a0b Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 26 May 2016 06:01:20 -0700 Subject: [PATCH 28/61] Fix trailing whitespace --- src/harness/fourslash.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 0f11d12097d..3bce13820d7 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2354,7 +2354,7 @@ ${code} let currentFileContent: string = undefined; let currentFileName = fileName; let currentFileOptions: { [s: string]: string } = {}; - + function resetLocalData() { currentFileContent = undefined; currentFileOptions = {}; From 5c23b3bc20ea043e2022487a211364bfa7d320c2 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 26 May 2016 06:04:42 -0700 Subject: [PATCH 29/61] Fix more tests --- tests/cases/fourslash/getNavigationBarItems.ts | 2 +- .../fourslash/navigationBarItemsMultilineStringIdentifiers.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cases/fourslash/getNavigationBarItems.ts b/tests/cases/fourslash/getNavigationBarItems.ts index 8e9b8de5b05..cd09f61011e 100644 --- a/tests/cases/fourslash/getNavigationBarItems.ts +++ b/tests/cases/fourslash/getNavigationBarItems.ts @@ -5,7 +5,7 @@ //// ["bar"]: string; ////} -verify.navigationBarCount(3); +verify.navigationBarCount(5); verify.navigationBarContains("C", "class"); verify.navigationBarChildItem("C", "[\"bar\"]", "property"); verify.navigationBarChildItem("C", "foo", "property"); diff --git a/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts b/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts index 681039d174a..4e7c715e6cd 100644 --- a/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts +++ b/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts @@ -38,4 +38,4 @@ test.markers().forEach((marker) => { verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); }); -verify.navigationBarCount(11); // global + 1 child, interface w/ 2 properties, class w/ 2 properties, 3 modules +verify.navigationBarCount(12); // global + 1 child, interface w/ 2 properties, class w/ 2 properties, 3 modules From fe77f541f600492025680e82b58895f3f3ceedd4 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 25 May 2016 07:24:14 -0700 Subject: [PATCH 30/61] Always include a root node in the navigation bar. This lets us change the navigation bar counting algorithm to traverse from the root only, so it never has duplicate nodes. --- src/harness/fourslash.ts | 19 +++++++++---------- src/services/navigationBar.ts | 13 +------------ 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 3bce13820d7..048beb21e09 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1961,23 +1961,22 @@ namespace FourSlash { public verifyNavigationBarCount(expected: number) { const items = this.languageService.getNavigationBarItems(this.activeFile.fileName); - const actual = this.getNavigationBarItemsCount(items); + const actual = this.getNavigationBarItemsCount(items[0]); if (expected !== actual) { this.raiseError(`verifyNavigationBarCount failed - found: ${actual} navigation items, expected: ${expected}.`); } } - private getNavigationBarItemsCount(items: ts.NavigationBarItem[]) { - let result = 0; - if (items) { - for (let i = 0, n = items.length; i < n; i++) { - result++; - result += this.getNavigationBarItemsCount(items[i].childItems); - } + private getNavigationBarItemsCount(root: ts.NavigationBarItem) { + ts.Debug.assert(root.kind === ts.ScriptElementKind.moduleElement); + function recur(item: ts.NavigationBarItem) { + let count = 1; + for (const child of item.childItems) + count += recur(child); + return count; } - - return result; + return recur(root); } public verifyNavigationBarContains(name: string, kind: string, fileName?: string, parentName?: string, isAdditionalSpan?: boolean, markerPosition?: number) { diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index bcf0726ffd5..f6f7b741a56 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -9,16 +9,10 @@ namespace ts.NavigationBar { return getJsNavigationBarItems(sourceFile, compilerOptions); } - // If the source file has any child items, then it included in the tree - // and takes lexical ownership of all other top-level items. - let hasGlobalNode = false; - return getItemsWorker(getTopLevelNodes(sourceFile), createTopLevelItem); function getIndent(node: Node): number { - // If we have a global node in the tree, - // then it adds an extra layer of depth to all subnodes. - let indent = hasGlobalNode ? 1 : 0; + let indent = 1; // Global node is the only one with indent 0. let current = node.parent; while (current) { @@ -508,11 +502,6 @@ namespace ts.NavigationBar { function createSourceFileItem(node: SourceFile): ts.NavigationBarItem { const childItems = getItemsWorker(getChildNodes(node.statements), createChildItem); - if (childItems === undefined || childItems.length === 0) { - return undefined; - } - - hasGlobalNode = true; const rootName = isExternalModule(node) ? "\"" + escapeString(getBaseFileName(removeFileExtension(normalizePath(node.fileName)))) + "\"" : ""; From fe970abc81e04cfc21b01db6138289fccbfbeef8 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 26 May 2016 07:30:31 -0700 Subject: [PATCH 31/61] Change tests to use the full JSON output of the navigation bar. This reduces the confusion of verify.navigationBarCount() counting duplicate items. --- src/harness/fourslash.ts | 113 ++++------- .../fourslash/deleteClassWithEnumPresent.ts | 33 +++- tests/cases/fourslash/fourslash.ts | 4 +- .../cases/fourslash/getNavigationBarItems.ts | 32 +++- tests/cases/fourslash/navbar_const.ts | 24 ++- .../navbar_contains-no-duplicates.ts | 152 ++++++++++++--- tests/cases/fourslash/navbar_exportDefault.ts | 97 ++++++++-- tests/cases/fourslash/navbar_let.ts | 24 ++- .../navigationBarItemsBindingPatterns.ts | 66 +++++-- ...ionBarItemsBindingPatternsInConstructor.ts | 48 ++++- .../navigationBarItemsEmptyConstructors.ts | 29 ++- .../fourslash/navigationBarItemsExports.ts | 33 +++- .../fourslash/navigationBarItemsFunctions.ts | 60 ++++-- .../navigationBarItemsFunctionsBroken.ts | 25 ++- .../navigationBarItemsFunctionsBroken2.ts | 25 ++- .../fourslash/navigationBarItemsImports.ts | 60 ++++-- ...ionBarItemsInsideMethodsAndConstructors.ts | 159 +++++++++++++--- .../fourslash/navigationBarItemsItems.ts | 174 ++++++++++++++--- .../fourslash/navigationBarItemsItems2.ts | 29 ++- ...rItemsItemsContainsNoAnonymousFunctions.ts | 58 +++++- .../navigationBarItemsItemsExternalModules.ts | 36 +++- ...navigationBarItemsItemsExternalModules2.ts | 43 ++++- ...navigationBarItemsItemsExternalModules3.ts | 43 ++++- .../navigationBarItemsItemsModuleVariables.ts | 56 +++++- .../navigationBarItemsMissingName1.ts | 39 ++-- .../navigationBarItemsMissingName2.ts | 26 ++- .../fourslash/navigationBarItemsModules.ts | 138 +++++++++++--- ...ationBarItemsMultilineStringIdentifiers.ts | 98 ++++++++-- ...BarItemsPropertiesDefinedInConstructors.ts | 41 +++- .../fourslash/navigationBarItemsSymbols1.ts | 42 ++++- .../fourslash/navigationBarItemsSymbols2.ts | 37 +++- .../fourslash/navigationBarItemsSymbols3.ts | 25 ++- .../fourslash/navigationBarItemsTypeAlias.ts | 16 +- tests/cases/fourslash/server/navbar01.ts | 175 +++++++++++++++--- .../shims-pp/getNavigationBarItems.ts | 22 ++- .../fourslash/shims/getNavigationBarItems.ts | 22 ++- 36 files changed, 1656 insertions(+), 448 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 048beb21e09..c33c9107ad7 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1959,70 +1959,42 @@ namespace FourSlash { } } - public verifyNavigationBarCount(expected: number) { - const items = this.languageService.getNavigationBarItems(this.activeFile.fileName); - const actual = this.getNavigationBarItemsCount(items[0]); - - if (expected !== actual) { - this.raiseError(`verifyNavigationBarCount failed - found: ${actual} navigation items, expected: ${expected}.`); + public verifyNavigationBar(json: any) { + let items = this.languageService.getNavigationBarItems(this.activeFile.fileName); + items = this.simplifyNavigationBar(items); + if (JSON.stringify(items) !== JSON.stringify(json)) { + this.raiseError(`verifyNavigationBar failed - expected: ${JSON.stringify(json, undefined, 2)}, got: ${JSON.stringify(items, undefined, 2)}`) } } - private getNavigationBarItemsCount(root: ts.NavigationBarItem) { - ts.Debug.assert(root.kind === ts.ScriptElementKind.moduleElement); - function recur(item: ts.NavigationBarItem) { - let count = 1; - for (const child of item.childItems) - count += recur(child); - return count; - } - return recur(root); - } - - public verifyNavigationBarContains(name: string, kind: string, fileName?: string, parentName?: string, isAdditionalSpan?: boolean, markerPosition?: number) { - fileName = fileName || this.activeFile.fileName; - const items = this.languageService.getNavigationBarItems(fileName); - - if (!items || items.length === 0) { - this.raiseError("verifyNavigationBarContains failed - found 0 navigation items, expected at least one."); - } - - if (this.navigationBarItemsContains(items, name, kind, parentName)) { - return; - } - - const missingItem = { name, kind, parentName }; - this.raiseError(`verifyNavigationBarContains failed - could not find the item: ${JSON.stringify(missingItem, undefined, 2)} in the returned list: (${JSON.stringify(items, undefined, 2)})`); - } - - private navigationBarItemsContains(items: ts.NavigationBarItem[], name: string, kind: string, parentName?: string) { - function recur(items: ts.NavigationBarItem[], curParentName: string) { - for (let i = 0; i < items.length; i++) { - const item = items[i]; - if (item && item.text === name && item.kind === kind && (!parentName || curParentName === parentName)) { - return true; - } - if (recur(item.childItems, item.text)) { - return true; - } - } - return false; - } - return recur(items, ""); - } - - public verifyNavigationBarChildItem(parent: string, name: string, kind: string) { - const items = this.languageService.getNavigationBarItems(this.activeFile.fileName); - - for (let i = 0; i < items.length; i++) { - const item = items[i]; - if (item.text === parent) { - if (this.navigationBarItemsContains(item.childItems, name, kind)) - return; - const missingItem = { name, kind }; - this.raiseError(`verifyNavigationBarChildItem failed - could not find the item: ${JSON.stringify(missingItem)} in the children list: (${JSON.stringify(item.childItems, undefined, 2)})`); - } - } + // Remove any properties that tend to all have the same value so that test data is easier to read. + private simplifyNavigationBar(items: ts.NavigationBarItem[]): any { + return items.map(item => { + item = ts.clone(item); + if (item.kindModifiers === "") + delete item.kindModifiers; + delete item.spans; + item.childItems = item.childItems.map(child => { + child = ts.clone(child); + ts.Debug.assert(child.childItems.length === 0); + ts.Debug.assert(child.indent === 0); + ts.Debug.assert(child.bolded === false); + ts.Debug.assert(child.grayed === false); + delete child.childItems; + delete child.indent; + delete child.bolded; + delete child.grayed; + delete child.spans; + if (child.kindModifiers === "") + delete child.kindModifiers; + return child; + }); + if (item.bolded === false) + delete item.bolded; + if (item.grayed === false) + delete item.grayed; + return item; + }) } public printNavigationItems(searchValue: string) { @@ -3041,23 +3013,8 @@ namespace FourSlashInterface { this.DocCommentTemplate(/*expectedText*/ undefined, /*expectedOffset*/ undefined, /*empty*/ true); } - public navigationBarCount(count: number) { - this.state.verifyNavigationBarCount(count); - } - - // TODO: figure out what to do with the unused arguments. - public navigationBarContains( - name: string, - kind: string, - fileName?: string, - parentName?: string, - isAdditionalSpan?: boolean, - markerPosition?: number) { - this.state.verifyNavigationBarContains(name, kind, fileName, parentName, isAdditionalSpan, markerPosition); - } - - public navigationBarChildItem(parent: string, name: string, kind: string) { - this.state.verifyNavigationBarChildItem(parent, name, kind); + public navigationBar(json: any) { + this.state.verifyNavigationBar(json); } public navigationItemsListCount(count: number, searchValue: string, matchKind?: string) { diff --git a/tests/cases/fourslash/deleteClassWithEnumPresent.ts b/tests/cases/fourslash/deleteClassWithEnumPresent.ts index 29f7c61e259..d8d4478afe7 100644 --- a/tests/cases/fourslash/deleteClassWithEnumPresent.ts +++ b/tests/cases/fourslash/deleteClassWithEnumPresent.ts @@ -5,4 +5,35 @@ goTo.marker(); edit.deleteAtCaret('class Bar { }'.length); -verify.navigationBarContains('Foo', 'enum', 'tests/cases/fourslash/deleteClassWithEnumPresent.ts', ''); \ No newline at end of file +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "Foo", + "kind": "enum" + } + ], + "indent": 0 + }, + { + "text": "Foo", + "kind": "enum", + "childItems": [ + { + "text": "a", + "kind": "property" + }, + { + "text": "b", + "kind": "property" + }, + { + "text": "c", + "kind": "property" + } + ], + "indent": 1 + } +]); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 08883f163f2..8a0d2d36364 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -175,9 +175,7 @@ declare namespace FourSlashInterface { DocCommentTemplate(expectedText: string, expectedOffset: number, empty?: boolean): void; noDocCommentTemplate(): void; - navigationBarCount(count: number): void; - navigationBarContains(name: string, kind: string, fileName?: string, parentName?: string, isAdditionalSpan?: boolean, markerPosition?: number): void; - navigationBarChildItem(parent: string, text: string, kind: string): void; + navigationBar(json: any): void; navigationItemsListCount(count: number, searchValue: string, matchKind?: string): void; navigationItemsListContains(name: string, kind: string, searchValue: string, matchKind: string, fileName?: string, parentName?: string): void; occurrencesAtPositionContains(range: Range, isWriteAccess?: boolean): void; diff --git a/tests/cases/fourslash/getNavigationBarItems.ts b/tests/cases/fourslash/getNavigationBarItems.ts index cd09f61011e..a2b0492514a 100644 --- a/tests/cases/fourslash/getNavigationBarItems.ts +++ b/tests/cases/fourslash/getNavigationBarItems.ts @@ -5,7 +5,31 @@ //// ["bar"]: string; ////} -verify.navigationBarCount(5); -verify.navigationBarContains("C", "class"); -verify.navigationBarChildItem("C", "[\"bar\"]", "property"); -verify.navigationBarChildItem("C", "foo", "property"); +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "C", + "kind": "class" + } + ], + "indent": 0 + }, + { + "text": "C", + "kind": "class", + "childItems": [ + { + "text": "[\"bar\"]", + "kind": "property" + }, + { + "text": "foo", + "kind": "property" + } + ], + "indent": 1 + } +]) diff --git a/tests/cases/fourslash/navbar_const.ts b/tests/cases/fourslash/navbar_const.ts index 5d8b42607c8..02a10f46a74 100644 --- a/tests/cases/fourslash/navbar_const.ts +++ b/tests/cases/fourslash/navbar_const.ts @@ -1,13 +1,17 @@ /// -//// {| "itemName": "c", "kind": "const", "parentName": "" |}const c = 0; +//// const c = 0; -test.markers().forEach(marker => { - verify.navigationBarContains( - marker.data.itemName, - marker.data.kind, - marker.fileName, - marker.data.parentName, - marker.data.isAdditionalRange, - marker.position); -}); \ No newline at end of file +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "c", + "kind": "const" + } + ], + "indent": 0 + } +]); diff --git a/tests/cases/fourslash/navbar_contains-no-duplicates.ts b/tests/cases/fourslash/navbar_contains-no-duplicates.ts index 42b33a722ad..333130ff795 100644 --- a/tests/cases/fourslash/navbar_contains-no-duplicates.ts +++ b/tests/cases/fourslash/navbar_contains-no-duplicates.ts @@ -1,42 +1,142 @@ /// -//// {| "itemName": "Windows", "kind": "module", "parentName": "" |}declare module Windows { -//// {| "itemName": "Foundation", "kind": "module", "parentName": "Windows" |}export module Foundation { -//// export var {| "itemName": "A", "kind": "var" |}A; -//// {| "itemName": "Test", "kind": "class", "parentName": "Foundation" |}export class Test { -//// {| "itemName": "wow", "kind": "method" |}public wow(); +//// declare module Windows { +//// export module Foundation { +//// export var A; +//// export class Test { +//// public wow(); //// } //// } //// } //// -//// {| "itemName": "Windows", "kind": "module", "parentName": "", "isAdditionalRange": true |}declare module Windows { -//// {| "itemName": "Foundation", "kind": "module", "parentName": "Windows", "isAdditionalRange": true |}export module Foundation { -//// export var {| "itemName": "B", "kind": "var" |}B; -//// {| "itemName": "Test", "kind": "module" |}export module Test { -//// {| "itemName": "Boom", "kind": "function" |}export function Boom(): number; +//// declare module Windows { +//// export module Foundation { +//// export var B; +//// export module Test { +//// export function Boom(): number; //// } //// } //// } //// -//// {| "itemName": "ABC", "kind": "class", "parentName": "" |}class ABC { -//// {| "itemName": "foo", "kind": "method" |}public foo() { +//// class ABC { +//// public foo() { //// return 3; //// } //// } //// -//// {| "itemName": "ABC", "kind": "module", "parentName": "" |}module ABC { -//// export var {| "itemName": "x", "kind": "var" |}x = 3; +//// module ABC { +//// export var x = 3; //// } -test.markers().forEach(marker => { - if (marker.data) { - verify.navigationBarContains( - marker.data.itemName, - marker.data.kind, - marker.fileName, - marker.data.parentName, - marker.data.isAdditionalRange, - marker.position); +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "ABC", + "kind": "class" + }, + { + "text": "ABC", + "kind": "module" + }, + { + "text": "Windows", + "kind": "module", + "kindModifiers": "declare" + } + ], + "indent": 0 + }, + { + "text": "ABC", + "kind": "class", + "childItems": [ + { + "text": "foo", + "kind": "method", + "kindModifiers": "public" + } + ], + "indent": 1 + }, + { + "text": "ABC", + "kind": "module", + "childItems": [ + { + "text": "x", + "kind": "var", + "kindModifiers": "export" + } + ], + "indent": 1 + }, + { + "text": "Windows", + "kind": "module", + "kindModifiers": "declare", + "childItems": [ + { + "text": "Foundation", + "kind": "module", + "kindModifiers": "export,declare" + } + ], + "indent": 1 + }, + { + "text": "Foundation", + "kind": "module", + "kindModifiers": "export,declare", + "childItems": [ + { + "text": "A", + "kind": "var", + "kindModifiers": "export,declare" + }, + { + "text": "Test", + "kind": "class", + "kindModifiers": "export,declare" + }, + { + "text": "B", + "kind": "var", + "kindModifiers": "export,declare" + }, + { + "text": "Test", + "kind": "module", + "kindModifiers": "export,declare" + } + ], + "indent": 2 + }, + { + "text": "Test", + "kind": "class", + "kindModifiers": "export,declare", + "childItems": [ + { + "text": "wow", + "kind": "method", + "kindModifiers": "public,declare" + } + ], + "indent": 3 + }, + { + "text": "Test", + "kind": "module", + "kindModifiers": "export,declare", + "childItems": [ + { + "text": "Boom", + "kind": "function", + "kindModifiers": "export,declare" + } + ], + "indent": 3 } -}); - -verify.navigationBarCount(19); +]); diff --git a/tests/cases/fourslash/navbar_exportDefault.ts b/tests/cases/fourslash/navbar_exportDefault.ts index a56eeb8b226..7c666589f12 100644 --- a/tests/cases/fourslash/navbar_exportDefault.ts +++ b/tests/cases/fourslash/navbar_exportDefault.ts @@ -1,24 +1,93 @@ /// // @Filename: a.ts -//// {| "itemName": "default", "kind": "class", "parentName": "" |}export default class { } +////export default class { } // @Filename: b.ts -//// {| "itemName": "C", "kind": "class", "parentName": "" |}export default class C { } +////export default class C { } // @Filename: c.ts -//// {| "itemName": "default", "kind": "function", "parentName": "" |}export default function { } +////export default function { } // @Filename: d.ts -//// {| "itemName": "Func", "kind": "function", "parentName": "" |}export default function Func { } +////export default function Func { } -test.markers().forEach(marker => { - goTo.file(marker.fileName); - verify.navigationBarContains( - marker.data.itemName, - marker.data.kind, - marker.fileName, - marker.data.parentName, - marker.data.isAdditionalRange, - marker.position); -}); \ No newline at end of file +goTo.file("a.ts"); +verify.navigationBar([ + { + "text": "\"a\"", + "kind": "module", + "childItems": [], + "indent": 0 + }, + { + "text": "default", + "kind": "class", + "kindModifiers": "export", + "childItems": [], + "indent": 1 + } +]); + +goTo.file("b.ts"); +verify.navigationBar([ + { + "text": "\"b\"", + "kind": "module", + "childItems": [ + { + "text": "C", + "kind": "class", + "kindModifiers": "export" + } + ], + "indent": 0 + }, + { + "text": "C", + "kind": "class", + "kindModifiers": "export", + "childItems": [], + "indent": 1 + } +]); + +goTo.file("c.ts"); +verify.navigationBar([ + { + "text": "\"c\"", + "kind": "module", + "childItems": [], + "indent": 0 + }, + { + "text": "default", + "kind": "function", + "kindModifiers": "export", + "childItems": [], + "indent": 1 + } +]); + +goTo.file("d.ts"); +verify.navigationBar([ + { + "text": "\"d\"", + "kind": "module", + "childItems": [ + { + "text": "Func", + "kind": "function", + "kindModifiers": "export" + } + ], + "indent": 0 + }, + { + "text": "Func", + "kind": "function", + "kindModifiers": "export", + "childItems": [], + "indent": 1 + } +]); diff --git a/tests/cases/fourslash/navbar_let.ts b/tests/cases/fourslash/navbar_let.ts index c3b125526ef..dc9d9c07857 100644 --- a/tests/cases/fourslash/navbar_let.ts +++ b/tests/cases/fourslash/navbar_let.ts @@ -1,13 +1,17 @@ /// -//// {| "itemName": "c", "kind": "let", "parentName": "" |}let c = 0; +////let c = 0; -test.markers().forEach(marker => { - verify.navigationBarContains( - marker.data.itemName, - marker.data.kind, - marker.fileName, - marker.data.parentName, - marker.data.isAdditionalRange, - marker.position); -}); \ No newline at end of file +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "c", + "kind": "let" + } + ], + "indent": 0 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsBindingPatterns.ts b/tests/cases/fourslash/navigationBarItemsBindingPatterns.ts index afac15daacc..007a9c9b804 100644 --- a/tests/cases/fourslash/navigationBarItemsBindingPatterns.ts +++ b/tests/cases/fourslash/navigationBarItemsBindingPatterns.ts @@ -6,16 +6,56 @@ ////const bar1, [c, d] ////var {e, x: [f, g]} = {a:1, x:[]}; -verify.navigationBarCount(12); // global (1) + variable declarations (4) + binding patterns (7) -verify.navigationBarContains("foo", "var"); -verify.navigationBarContains("bar", "var"); -verify.navigationBarContains("foo1", "let") -verify.navigationBarContains("a", "let"); -verify.navigationBarContains("b", "let"); -verify.navigationBarContains("bar1", "const"); -verify.navigationBarContains("c", "const"); -verify.navigationBarContains("d", "const"); -verify.navigationBarContains("e", "var"); -verify.navigationBarContains("f", "var"); -verify.navigationBarContains("g", "var"); - +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "a", + "kind": "let" + }, + { + "text": "b", + "kind": "let" + }, + { + "text": "bar", + "kind": "var" + }, + { + "text": "bar1", + "kind": "const" + }, + { + "text": "c", + "kind": "const" + }, + { + "text": "d", + "kind": "const" + }, + { + "text": "e", + "kind": "var" + }, + { + "text": "f", + "kind": "var" + }, + { + "text": "foo", + "kind": "var" + }, + { + "text": "foo1", + "kind": "let" + }, + { + "text": "g", + "kind": "var" + } + ], + "indent": 0 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts b/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts index 24979e141e5..41751f5c74b 100644 --- a/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts +++ b/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts @@ -11,4 +11,50 @@ //// } ////} -verify.navigationBarCount(9); // global + 2 children + 2x(class + field + constructor) +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "A", + "kind": "class" + }, + { + "text": "B", + "kind": "class" + } + ], + "indent": 0 + }, + { + "text": "A", + "kind": "class", + "childItems": [ + { + "text": "constructor", + "kind": "constructor" + }, + { + "text": "x", + "kind": "property" + } + ], + "indent": 1 + }, + { + "text": "B", + "kind": "class", + "childItems": [ + { + "text": "constructor", + "kind": "constructor" + }, + { + "text": "x", + "kind": "property" + } + ], + "indent": 1 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts b/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts index a80f4c596d4..27c33f6afb2 100644 --- a/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts +++ b/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts @@ -5,8 +5,27 @@ //// } ////} -verify.navigationBarContains("Test", "class"); -verify.navigationBarContains("constructor", "constructor"); - -// no other items -verify.navigationBarCount(4); // global + 1 child, Test + 1 child \ No newline at end of file +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "Test", + "kind": "class" + } + ], + "indent": 0 + }, + { + "text": "Test", + "kind": "class", + "childItems": [ + { + "text": "constructor", + "kind": "constructor" + } + ], + "indent": 1 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsExports.ts b/tests/cases/fourslash/navigationBarItemsExports.ts index b88b60d0efb..79422f96274 100644 --- a/tests/cases/fourslash/navigationBarItemsExports.ts +++ b/tests/cases/fourslash/navigationBarItemsExports.ts @@ -1,18 +1,33 @@ /// -////export { {| "itemName": "a", "kind": "alias", "parentName": "" |}a } from "a"; +////export { a } from "a"; //// -////export { {| "itemName": "B", "kind": "alias", "parentName": "" |}b as B } from "a" +////export { b as B } from "a" //// -////{| "itemName": "e", "kind": "alias", "parentName": "" |} export import e = require("a"); +////export import e = require("a"); //// ////export * from "a"; // no bindings here -test.markers().forEach((marker) => { - if (marker.data) { - verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); +verify.navigationBar([ + { + "text": "\"navigationBarItemsExports\"", + "kind": "module", + "childItems": [ + { + "text": "a", + "kind": "alias" + }, + { + "text": "B", + "kind": "alias" + }, + { + "text": "e", + "kind": "alias", + "kindModifiers": "export" + } + ], + "indent": 0 } -}); - -verify.navigationBarCount(4); +]); diff --git a/tests/cases/fourslash/navigationBarItemsFunctions.ts b/tests/cases/fourslash/navigationBarItemsFunctions.ts index 0948923c046..e2260f2ff2b 100644 --- a/tests/cases/fourslash/navigationBarItemsFunctions.ts +++ b/tests/cases/fourslash/navigationBarItemsFunctions.ts @@ -1,23 +1,61 @@ /// -////{| "itemName": "", "kind": "module" |} -//// -////{| "itemName": "foo", "kind": "function" |}function foo() { +////function foo() { //// var x = 10; -//// {| "itemName": "bar", "kind": "function", "parentName": "foo" |}function bar() { +//// function bar() { //// var y = 10; -//// {| "itemName": "biz", "kind": "function", "parentName": "bar" |}function biz() { +//// function biz() { //// var z = 10; //// } //// } ////} //// -////{| "itemName": "baz", "kind": "function", "parentName": "" |}function baz() { +////function baz() { //// var v = 10; ////} -test.markers().forEach((marker) => { - verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); -}); - -verify.navigationBarCount(8); // 4 functions + global. Note: there are 8 because of the functions show up at the top level and as child items. +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "baz", + "kind": "function" + }, + { + "text": "foo", + "kind": "function" + } + ], + "indent": 0 + }, + { + "text": "baz", + "kind": "function", + "childItems": [], + "indent": 1 + }, + { + "text": "foo", + "kind": "function", + "childItems": [ + { + "text": "bar", + "kind": "function" + } + ], + "indent": 1 + }, + { + "text": "bar", + "kind": "function", + "childItems": [ + { + "text": "biz", + "kind": "function" + } + ], + "indent": 2 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsFunctionsBroken.ts b/tests/cases/fourslash/navigationBarItemsFunctionsBroken.ts index e8bf1d33fc3..dc84b50ff30 100644 --- a/tests/cases/fourslash/navigationBarItemsFunctionsBroken.ts +++ b/tests/cases/fourslash/navigationBarItemsFunctionsBroken.ts @@ -1,12 +1,25 @@ /// -////{| "itemName": "f", "kind": "function" |} ////function f() { //// function; ////} -test.markers().forEach((marker) => { - verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); -}); - -verify.navigationBarCount(3); // and 'f'. \ No newline at end of file +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "f", + "kind": "function" + } + ], + "indent": 0 + }, + { + "text": "f", + "kind": "function", + "childItems": [], + "indent": 1 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsFunctionsBroken2.ts b/tests/cases/fourslash/navigationBarItemsFunctionsBroken2.ts index 9576d4dd789..b4612efcac0 100644 --- a/tests/cases/fourslash/navigationBarItemsFunctionsBroken2.ts +++ b/tests/cases/fourslash/navigationBarItemsFunctionsBroken2.ts @@ -1,13 +1,26 @@ /// ////function; -////{| "itemName": "f", "kind": "function" |} ////function f() { //// function; ////} -test.markers().forEach((marker) => { - verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); -}); - -verify.navigationBarCount(3); // and 'f' \ No newline at end of file +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "f", + "kind": "function" + } + ], + "indent": 0 + }, + { + "text": "f", + "kind": "function", + "childItems": [], + "indent": 1 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsImports.ts b/tests/cases/fourslash/navigationBarItemsImports.ts index 53619da310a..d6526a7a68c 100644 --- a/tests/cases/fourslash/navigationBarItemsImports.ts +++ b/tests/cases/fourslash/navigationBarItemsImports.ts @@ -1,25 +1,57 @@ /// -////import {| "itemName": "d1", "kind": "alias", "parentName": "" |}d1 from "a"; +////import d1 from "a"; //// -////import { {| "itemName": "a", "kind": "alias", "parentName": "" |}a } from "a"; +////import { a } from "a"; //// -////import { {| "itemName": "B", "kind": "alias", "parentName": "" |}b as B } from "a" +////import { b as B } from "a" //// -////import {| "itemName": "d2", "kind": "alias", "parentName": "" |}d2, -//// { {| "itemName": "c", "kind": "alias", "parentName": "" |}c, -//// {| "itemName": "D", "kind": "alias", "parentName": "" |} d as D } from "a" +////import d2, { c, d as D } from "a" //// -////{| "itemName": "e", "kind": "alias", "parentName": "" |}import e = require("a"); +////import e = require("a"); //// -////import {| "itemName": "ns", "kind": "alias", "parentName": "" |}* as ns from "a"; +////import * as ns from "a"; -test.markers().forEach((marker) => { - if (marker.data) { - verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); +verify.navigationBar([ + { + "text": "\"navigationBarItemsImports\"", + "kind": "module", + "childItems": [ + { + "text": "a", + "kind": "alias" + }, + { + "text": "B", + "kind": "alias" + }, + { + "text": "c", + "kind": "alias" + }, + { + "text": "D", + "kind": "alias" + }, + { + "text": "d1", + "kind": "alias" + }, + { + "text": "d2", + "kind": "alias" + }, + { + "text": "e", + "kind": "alias" + }, + { + "text": "ns", + "kind": "alias" + } + ], + "indent": 0 } -}); - -verify.navigationBarCount(9); +]); diff --git a/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts b/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts index 8d93d241ae1..7d2fb4ed127 100644 --- a/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts +++ b/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts @@ -2,41 +2,140 @@ ////class Class { //// constructor() { -//// {| "itemName": "LocalFunctionInConstructor", "kind": "function", "parentName": "constructor"|}function LocalFunctionInConstructor() { -//// -//// } -//// -//// {| "itemName": "LocalInterfaceInConstrcutor", "kind": "interface", "parentName": "constructor"|}interface LocalInterfaceInConstrcutor { -//// } -//// -//// {| "itemName": "LocalEnumInConstructor", "kind": "enum", "parentName": "constructor"|}enum LocalEnumInConstructor { -//// {| "itemName": "LocalEnumMemberInConstructor", "kind": "property", "parentName": "LocalEnumInConstructor"|}LocalEnumMemberInConstructor, -//// } +//// function LocalFunctionInConstructor() {} +//// interface LocalInterfaceInConstrcutor {} +//// enum LocalEnumInConstructor { LocalEnumMemberInConstructor } //// } //// //// method() { -//// {| "itemName": "LocalFunctionInMethod", "kind": "function", "parentName": "method"|}function LocalFunctionInMethod() { -//// {| "itemName": "LocalFunctionInLocalFunctionInMethod", "kind": "function", "parentName": "LocalFunctionInMethod"|}function LocalFunctionInLocalFunctionInMethod() { -//// -//// } -//// } -//// -//// {| "itemName": "LocalInterfaceInMethod", "kind": "interface", "parentName": "method"|}interface LocalInterfaceInMethod { -//// } -//// -//// {| "itemName": "LocalEnumInMethod", "kind": "enum", "parentName": "method"|}enum LocalEnumInMethod { -//// {| "itemName": "LocalEnumMemberInMethod", "kind": "property", "parentName": "LocalEnumInMethod"|}LocalEnumMemberInMethod, +//// function LocalFunctionInMethod() { +//// function LocalFunctionInLocalFunctionInMethod() {} //// } +//// interface LocalInterfaceInMethod {} +//// enum LocalEnumInMethod { LocalEnumMemberInMethod } //// } //// -//// emptyMethod() { // Non child functions method should not be duplicated -//// -//// } +//// emptyMethod() { } // Non child functions method should not be duplicated ////} -test.markers().forEach((marker) => { - verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); -}); - -// no other items -verify.navigationBarCount(23); +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "Class", + "kind": "class" + } + ], + "indent": 0 + }, + { + "text": "Class", + "kind": "class", + "childItems": [ + { + "text": "constructor", + "kind": "constructor" + }, + { + "text": "emptyMethod", + "kind": "method" + }, + { + "text": "method", + "kind": "method" + } + ], + "indent": 1 + }, + { + "text": "constructor", + "kind": "constructor", + "childItems": [ + { + "text": "LocalEnumInConstructor", + "kind": "enum" + }, + { + "text": "LocalFunctionInConstructor", + "kind": "function" + }, + { + "text": "LocalInterfaceInConstrcutor", + "kind": "interface" + } + ], + "indent": 2 + }, + { + "text": "LocalEnumInConstructor", + "kind": "enum", + "childItems": [ + { + "text": "LocalEnumMemberInConstructor", + "kind": "property" + } + ], + "indent": 2 + }, + { + "text": "LocalFunctionInConstructor", + "kind": "function", + "childItems": [], + "indent": 2 + }, + { + "text": "LocalInterfaceInConstrcutor", + "kind": "interface", + "childItems": [], + "indent": 2 + }, + { + "text": "method", + "kind": "method", + "childItems": [ + { + "text": "LocalEnumInMethod", + "kind": "enum" + }, + { + "text": "LocalFunctionInMethod", + "kind": "function" + }, + { + "text": "LocalInterfaceInMethod", + "kind": "interface" + } + ], + "indent": 2 + }, + { + "text": "LocalEnumInMethod", + "kind": "enum", + "childItems": [ + { + "text": "LocalEnumMemberInMethod", + "kind": "property" + } + ], + "indent": 2 + }, + { + "text": "LocalFunctionInMethod", + "kind": "function", + "childItems": [ + { + "text": "LocalFunctionInLocalFunctionInMethod", + "kind": "function" + } + ], + "indent": 2 + }, + { + "text": "LocalInterfaceInMethod", + "kind": "interface", + "childItems": [], + "indent": 2 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsItems.ts b/tests/cases/fourslash/navigationBarItemsItems.ts index e8e9fd40824..013d28cd402 100644 --- a/tests/cases/fourslash/navigationBarItemsItems.ts +++ b/tests/cases/fourslash/navigationBarItemsItems.ts @@ -1,52 +1,172 @@ /// ////// Interface -////{| "itemName": "IPoint", "kind": "interface", "parentName": "" |}interface IPoint { -//// {| "itemName": "getDist", "kind": "method", "parentName": "IPoint" |}getDist(): number; -//// {| "itemName": "new()", "kind": "construct", "parentName": "IPoint" |}new(): IPoint; -//// {| "itemName": "()", "kind": "call", "parentName": "IPoint" |}(): any; -//// {| "itemName": "[]", "kind": "index", "parentName": "IPoint" |}[x:string]: number; -//// {| "itemName": "prop", "kind": "property", "parentName": "IPoint" |}prop: string; +////interface IPoint { +//// getDist(): number; +//// new(): IPoint; +//// (): any; +//// [x:string]: number; +//// prop: string; ////} //// /////// Module -////{| "itemName": "Shapes", "kind": "module", "parentName": "" |}module Shapes { +////module Shapes { //// //// // Class -//// {| "itemName": "Point", "kind": "class", "parentName": "Shapes" |}export class Point implements IPoint { -//// {| "itemName": "constructor", "kind": "constructor", "parentName": "Point" |}constructor (public x: number, public y: number) { } +//// export class Point implements IPoint { +//// constructor (public x: number, public y: number) { } //// //// // Instance member -//// {| "itemName": "getDist", "kind": "method", "parentName": "Point" |}getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); } +//// getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); } //// //// // Getter -//// {| "itemName": "value", "kind": "getter", "parentName": "Point" |}get value(): number { return 0; } +//// get value(): number { return 0; } //// //// // Setter -//// {| "itemName": "value", "kind": "setter", "parentName": "Point" |}set value(newValue: number) { return; } +//// set value(newValue: number) { return; } //// //// // Static member -//// {| "itemName": "origin", "kind": "property", "parentName": "Point" |}static origin = new Point(0, 0); +//// static origin = new Point(0, 0); //// //// // Static method -//// {| "itemName": "getOrigin", "kind": "method", "parentName": "Point" |}private static getOrigin() { return Point.origin;} +//// private static getOrigin() { return Point.origin; } //// } //// -//// {| "itemName": "Values", "kind": "enum", "parentName": "Shapes" |}enum Values { -//// value1, -//// {| "itemName": "value2", "kind": "property", "parentName": "Values" |}value2, -//// value3, -//// } +//// enum Values { value1, value2, value3 } ////} //// ////// Local variables -////{| "itemName": "p", "kind": "var", "parentName": "" |}var p: IPoint = new Shapes.Point(3, 4); -////{| "itemName": "dist", "kind": "var", "parentName": "" |}var dist = p.getDist(); +////var p: IPoint = new Shapes.Point(3, 4); +////var dist = p.getDist(); -test.markers().forEach((marker) => { - if (marker.data) { - verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "dist", + "kind": "var" + }, + { + "text": "IPoint", + "kind": "interface" + }, + { + "text": "p", + "kind": "var" + }, + { + "text": "Shapes", + "kind": "module" + } + ], + "indent": 0 + }, + { + "text": "IPoint", + "kind": "interface", + "childItems": [ + { + "text": "()", + "kind": "call" + }, + { + "text": "new()", + "kind": "construct" + }, + { + "text": "[]", + "kind": "index" + }, + { + "text": "getDist", + "kind": "method" + }, + { + "text": "prop", + "kind": "property" + } + ], + "indent": 1 + }, + { + "text": "Shapes", + "kind": "module", + "childItems": [ + { + "text": "Point", + "kind": "class", + "kindModifiers": "export" + }, + { + "text": "Values", + "kind": "enum" + } + ], + "indent": 1 + }, + { + "text": "Point", + "kind": "class", + "kindModifiers": "export", + "childItems": [ + { + "text": "constructor", + "kind": "constructor" + }, + { + "text": "getDist", + "kind": "method" + }, + { + "text": "getOrigin", + "kind": "method", + "kindModifiers": "private,static" + }, + { + "text": "origin", + "kind": "property", + "kindModifiers": "static" + }, + { + "text": "value", + "kind": "getter" + }, + { + "text": "value", + "kind": "setter" + }, + { + "text": "x", + "kind": "property", + "kindModifiers": "public" + }, + { + "text": "y", + "kind": "property", + "kindModifiers": "public" + } + ], + "indent": 2 + }, + { + "text": "Values", + "kind": "enum", + "childItems": [ + { + "text": "value1", + "kind": "property" + }, + { + "text": "value2", + "kind": "property" + }, + { + "text": "value3", + "kind": "property" + } + ], + "indent": 2 } -}); - -verify.navigationBarCount(27); +]); diff --git a/tests/cases/fourslash/navigationBarItemsItems2.ts b/tests/cases/fourslash/navigationBarItemsItems2.ts index 013f27b4d71..27c32531d6b 100644 --- a/tests/cases/fourslash/navigationBarItemsItems2.ts +++ b/tests/cases/fourslash/navigationBarItemsItems2.ts @@ -1,6 +1,5 @@ /// - /////**/ goTo.marker(); @@ -8,5 +7,29 @@ edit.insertLine("module A"); edit.insert("export class "); // should not crash -verify.navigationBarCount(4); - +verify.navigationBar([ + { + "text": "\"navigationBarItemsItems2\"", + "kind": "module", + "childItems": [ + { + "text": "A", + "kind": "module" + } + ], + "indent": 0 + }, + { + "text": "default", + "kind": "class", + "kindModifiers": "export", + "childItems": [], + "indent": 1 + }, + { + "text": "A", + "kind": "module", + "childItems": [], + "indent": 1 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsItemsContainsNoAnonymousFunctions.ts b/tests/cases/fourslash/navigationBarItemsItemsContainsNoAnonymousFunctions.ts index dac6e96ab93..34e4a1c0c89 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsContainsNoAnonymousFunctions.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsContainsNoAnonymousFunctions.ts @@ -30,15 +30,57 @@ ////} goTo.marker("file1"); -verify.navigationBarCount(0); +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [], + "indent": 0 + } +]); goTo.marker("file2"); -verify.navigationBarContains("", "module"); -verify.navigationBarContains("x", "var"); -verify.navigationBarCount(2); +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "x", + "kind": "var" + } + ], + "indent": 0 + } +]); goTo.marker("file3"); -verify.navigationBarContains("", "module"); -verify.navigationBarContains("foo", "function"); -verify.navigationBarContains("bar", "function"); -verify.navigationBarCount(5); \ No newline at end of file +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "bar", + "kind": "function" + }, + { + "text": "foo", + "kind": "function" + } + ], + "indent": 0 + }, + { + "text": "bar", + "kind": "function", + "childItems": [], + "indent": 1 + }, + { + "text": "foo", + "kind": "function", + "childItems": [], + "indent": 1 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts index 7b2e0def4bf..f2df772fb19 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts @@ -1,11 +1,33 @@ /// -////{| "itemName": "Bar", "kind": "class", "parentName": "\"navigationBarItemsItemsExternalModules\"" |}export class Bar { -//// {| "itemName": "s", "kind": "property", "parentName": "Bar" |}public s: string; +////export class Bar { +//// public s: string; ////} -test.markers().forEach((marker) => { - verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); -}); - -verify.navigationBarCount(4); // external module node + class + property +verify.navigationBar([ + { + "text": "\"navigationBarItemsItemsExternalModules\"", + "kind": "module", + "childItems": [ + { + "text": "Bar", + "kind": "class", + "kindModifiers": "export" + } + ], + "indent": 0 + }, + { + "text": "Bar", + "kind": "class", + "kindModifiers": "export", + "childItems": [ + { + "text": "s", + "kind": "property", + "kindModifiers": "public" + } + ], + "indent": 1 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts index 9087493b298..54d4759afe6 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts @@ -1,15 +1,40 @@ /// // @Filename: test/file.ts -////{| "itemName": "Bar", "kind": "class", "parentName": "\"file\"" |}export class Bar { -//// {| "itemName": "s", "kind": "property", "parentName": "Bar" |}public s: string; +////export class Bar { +//// public s: string; ////} -////{| "itemName": "\"file\"", "kind": "module" |} -////{| "itemName": "x", "kind": "var", "parentName": "\"file\"" |} ////export var x: number; -test.markers().forEach((marker) => { - verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); -}); - -verify.navigationBarCount(5); // external module node + variable in module + class + property +verify.navigationBar([ + { + "text": "\"file\"", + "kind": "module", + "childItems": [ + { + "text": "Bar", + "kind": "class", + "kindModifiers": "export" + }, + { + "text": "x", + "kind": "var", + "kindModifiers": "export" + } + ], + "indent": 0 + }, + { + "text": "Bar", + "kind": "class", + "kindModifiers": "export", + "childItems": [ + { + "text": "s", + "kind": "property", + "kindModifiers": "public" + } + ], + "indent": 1 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts index a00b3a131dd..2db04c980d2 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts @@ -1,15 +1,40 @@ /// // @Filename: test/my fil"e.ts -////{| "itemName": "Bar", "kind": "class", "parentName": "\"my fil\\\"e\"" |}export class Bar { -//// {| "itemName": "s", "kind": "property", "parentName": "Bar" |}public s: string; +////export class Bar { +//// public s: string; ////} -////{| "itemName": "\"my fil\\\"e\"", "kind": "module" |} -////{| "itemName": "x", "kind": "var", "parentName": "\"my fil\\\"e\"" |} ////export var x: number; -test.markers().forEach((marker) => { - verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); -}); - -verify.navigationBarCount(5); // external module node + 2 children + class + property +verify.navigationBar([ + { + "text": "\"my fil\\\"e\"", + "kind": "module", + "childItems": [ + { + "text": "Bar", + "kind": "class", + "kindModifiers": "export" + }, + { + "text": "x", + "kind": "var", + "kindModifiers": "export" + } + ], + "indent": 0 + }, + { + "text": "Bar", + "kind": "class", + "kindModifiers": "export", + "childItems": [ + { + "text": "s", + "kind": "property", + "kindModifiers": "public" + } + ], + "indent": 1 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts b/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts index 5429011888c..ef4022ce046 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts @@ -19,12 +19,56 @@ //// export var z = 0; ////} goTo.marker("file1"); -verify.navigationBarContains("Module1", "module"); -verify.navigationBarContains("x", "var"); // nothing else should show up -verify.navigationBarCount(4); // , its child, Module1, its child +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "Module1", + "kind": "module" + } + ], + "indent": 0 + }, + { + "text": "Module1", + "kind": "module", + "childItems": [ + { + "text": "x", + "kind": "var", + "kindModifiers": "export" + } + ], + "indent": 1 + } +]); goTo.marker("file2"); -verify.navigationBarContains("Module1.SubModule", "module"); -verify.navigationBarContains("y", "var"); -verify.navigationBarCount(4); +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "Module1.SubModule", + "kind": "module" + } + ], + "indent": 0 + }, + { + "text": "Module1.SubModule", + "kind": "module", + "childItems": [ + { + "text": "y", + "kind": "var", + "kindModifiers": "export" + } + ], + "indent": 1 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsMissingName1.ts b/tests/cases/fourslash/navigationBarItemsMissingName1.ts index 59f2911f3aa..4738cc45063 100644 --- a/tests/cases/fourslash/navigationBarItemsMissingName1.ts +++ b/tests/cases/fourslash/navigationBarItemsMissingName1.ts @@ -1,16 +1,29 @@ ////export function -/////** -//// * This is a class. -//// */ -////{| "itemName": "C", "kind": "class", "parentName": "\"navigationBarItemsMissingName1\"" |} class C { -//// {| "itemName": "foo", "kind": "method" |} foo() { -//// } +////class C { +//// foo() {} ////} - -test.markers().forEach((marker) => { - verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); -}); - -/// Root + 1 child, class + 1 child -verify.navigationBarCount(4); +verify.navigationBar([ + { + "text": "\"navigationBarItemsMissingName1\"", + "kind": "module", + "childItems": [ + { + "text": "C", + "kind": "class" + } + ], + "indent": 0 + }, + { + "text": "C", + "kind": "class", + "childItems": [ + { + "text": "foo", + "kind": "method" + } + ], + "indent": 1 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsMissingName2.ts b/tests/cases/fourslash/navigationBarItemsMissingName2.ts index d26aa0b553d..f4a37cf1154 100644 --- a/tests/cases/fourslash/navigationBarItemsMissingName2.ts +++ b/tests/cases/fourslash/navigationBarItemsMissingName2.ts @@ -2,10 +2,26 @@ //// * This is a class. //// */ ////class /* But it has no name! */ { -//// foo() { -//// } +//// foo() {} ////} - -// The class is unnamed, so its method is not included either. -verify.navigationBarCount(2); +// Anonymous classes are still included. +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [], + "indent": 0 + }, + { + "text": "default", + "kind": "class", + "childItems": [ + { + "text": "foo", + "kind": "method" + } + ], + "indent": 1 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsModules.ts b/tests/cases/fourslash/navigationBarItemsModules.ts index 237ec8eb275..c3b8aef08eb 100644 --- a/tests/cases/fourslash/navigationBarItemsModules.ts +++ b/tests/cases/fourslash/navigationBarItemsModules.ts @@ -1,49 +1,137 @@ /// -////{| "itemName": "\"X.Y.Z\"", "kind": "module", "parentName": "" |} -////declare module "X.Y.Z" { -////} +////declare module "X.Y.Z" {} //// -////{| "itemName": "'X2.Y2.Z2'", "kind": "module", "parentName": "" |} -////declare module 'X2.Y2.Z2' { -////} +////declare module 'X2.Y2.Z2' {} //// -////{| "itemName": "A.B.C", "kind": "module", "parentName": "" |} ////module A.B.C { -//// {| "itemName": "x", "kind": "var", "parentName": "A.B.C" |} //// export var x; ////} //// -////{| "itemName": "A.B", "kind": "module", "parentName": "" |} ////module A.B { -//// {| "itemName": "y", "kind": "var", "parentName": "A.B" |} //// export var y; ////} //// -////{| "itemName": "A", "kind": "module", "parentName": "" |} ////module A { -//// {| "itemName": "z", "kind": "var", "parentName": "A" |} //// export var z; ////} //// -////{| "itemName": "A", "kind": "module", "parentName": "" |} ////module A { -//// {| "itemName": "B", "kind": "module", "parentName": "A" |} //// module B { -//// {| "itemName": "C", "kind": "module", "parentName": "B" |} //// module C { -//// {| "itemName": "x", "kind": "var", "parentName": "C" |} //// declare var x; //// } //// } ////} - -test.markers().forEach((marker) => { - verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); -}); - -/// We have 8 module keywords, and 4 var keywords. -/// The declarations of A.B.C.x do not get merged, so the 4 vars are independent. -/// The two 'A' modules, however, do get merged, so in reality we have 7 modules. -verify.navigationBarCount(19); +//We have 8 module keywords, and 4 var keywords. +//The declarations of A.B.C.x do not get merged, so the 4 vars are independent. +//The two 'A' modules, however, do get merged, so in reality we have 7 modules. +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "A.B.C", + "kind": "module" + }, + { + "text": "A.B", + "kind": "module" + }, + { + "text": "A", + "kind": "module" + }, + { + "text": "\"X.Y.Z\"", + "kind": "module", + "kindModifiers": "declare" + }, + { + "text": "'X2.Y2.Z2'", + "kind": "module", + "kindModifiers": "declare" + } + ], + "indent": 0 + }, + { + "text": "A.B.C", + "kind": "module", + "childItems": [ + { + "text": "x", + "kind": "var", + "kindModifiers": "export" + } + ], + "indent": 1 + }, + { + "text": "A.B", + "kind": "module", + "childItems": [ + { + "text": "y", + "kind": "var", + "kindModifiers": "export" + } + ], + "indent": 1 + }, + { + "text": "A", + "kind": "module", + "childItems": [ + { + "text": "z", + "kind": "var", + "kindModifiers": "export" + }, + { + "text": "B", + "kind": "module" + } + ], + "indent": 1 + }, + { + "text": "B", + "kind": "module", + "childItems": [ + { + "text": "C", + "kind": "module" + } + ], + "indent": 2 + }, + { + "text": "C", + "kind": "module", + "childItems": [ + { + "text": "x", + "kind": "var", + "kindModifiers": "declare" + } + ], + "indent": 3 + }, + { + "text": "\"X.Y.Z\"", + "kind": "module", + "kindModifiers": "declare", + "childItems": [], + "indent": 1 + }, + { + "text": "'X2.Y2.Z2'", + "kind": "module", + "kindModifiers": "declare", + "childItems": [], + "indent": 1 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts b/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts index 6bd3d799171..c2e43f5f7b7 100644 --- a/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts +++ b/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts @@ -1,31 +1,22 @@ -////{| "itemName": "\"Multiline\\r\\nMadness\"", "kind": "module", "parentName": "" |} ////declare module "Multiline\r\nMadness" { ////} //// -////{| "itemName": "\"Multiline\\\nMadness\"", "kind": "module", "parentName": "" |} ////declare module "Multiline\ ////Madness" { ////} -////{| "itemName": "\"MultilineMadness\"", "kind": "module", "parentName": "" |} ////declare module "MultilineMadness" {} //// -////{| "itemName": "Foo", "kind": "interface", "parentName": "" |} ////interface Foo { -//// {| "itemName": "\"a1\\\\\\r\\nb\"", "kind": "property", "parentName": "Foo" |} //// "a1\\\r\nb"; -//// {| "itemName": "\"a2\\\n \\\n b\"", "kind": "method", "parentName": "Foo" |} //// "a2\ //// \ //// b"(): Foo; ////} //// -////{| "itemName": "Bar", "kind": "class", "parentName": "" |} ////class Bar implements Foo { -//// {| "itemName": "'a1\\\\\\r\\nb'", "kind": "property", "parentName": "Bar" |} //// 'a1\\\r\nb': Foo; //// -//// {| "itemName": "'a2\\\n \\\n b'", "kind": "method", "parentName": "Bar" |} //// 'a2\ //// \ //// b'(): Foo { @@ -33,9 +24,86 @@ //// } ////} - -test.markers().forEach((marker) => { - verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); -}); - -verify.navigationBarCount(15); +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "Bar", + "kind": "class" + }, + { + "text": "Foo", + "kind": "interface" + }, + { + "text": "\"Multiline\\r\\nMadness\"", + "kind": "module", + "kindModifiers": "declare" + }, + { + "text": "\"Multiline\\\nMadness\"", + "kind": "module", + "kindModifiers": "declare" + }, + { + "text": "\"MultilineMadness\"", + "kind": "module", + "kindModifiers": "declare" + } + ], + "indent": 0 + }, + { + "text": "Bar", + "kind": "class", + "childItems": [ + { + "text": "'a1\\\\\\r\\nb'", + "kind": "property" + }, + { + "text": "'a2\\\n \\\n b'", + "kind": "method" + } + ], + "indent": 1 + }, + { + "text": "Foo", + "kind": "interface", + "childItems": [ + { + "text": "\"a1\\\\\\r\\nb\"", + "kind": "property" + }, + { + "text": "\"a2\\\n \\\n b\"", + "kind": "method" + } + ], + "indent": 1 + }, + { + "text": "\"Multiline\\r\\nMadness\"", + "kind": "module", + "kindModifiers": "declare", + "childItems": [], + "indent": 1 + }, + { + "text": "\"Multiline\\\nMadness\"", + "kind": "module", + "kindModifiers": "declare", + "childItems": [], + "indent": 1 + }, + { + "text": "\"MultilineMadness\"", + "kind": "module", + "kindModifiers": "declare", + "childItems": [], + "indent": 1 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts b/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts index 8e1981f6101..d99d3bce9eb 100644 --- a/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts +++ b/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts @@ -6,10 +6,37 @@ //// } ////} -verify.navigationBarContains("List", "class"); -verify.navigationBarContains("constructor", "constructor"); -verify.navigationBarContains("a", "property"); -verify.navigationBarContains("b", "property"); - -// no other items -verify.navigationBarCount(6); \ No newline at end of file +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "List", + "kind": "class" + } + ], + "indent": 0 + }, + { + "text": "List", + "kind": "class", + "childItems": [ + { + "text": "constructor", + "kind": "constructor" + }, + { + "text": "a", + "kind": "property", + "kindModifiers": "public" + }, + { + "text": "b", + "kind": "property", + "kindModifiers": "public" + } + ], + "indent": 1 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsSymbols1.ts b/tests/cases/fourslash/navigationBarItemsSymbols1.ts index 6d55812fa0e..8c565447c19 100644 --- a/tests/cases/fourslash/navigationBarItemsSymbols1.ts +++ b/tests/cases/fourslash/navigationBarItemsSymbols1.ts @@ -1,18 +1,40 @@ /// -////{| "itemName": "C", "kind": "class", "parentName": "" |} ////class C { -//// {| "itemName": "[Symbol.isRegExp]", "kind": "property", "parentName": "C" |} //// [Symbol.isRegExp] = 0; -//// {| "itemName": "[Symbol.iterator]", "kind": "method", "parentName": "C" |} //// [Symbol.iterator]() { } -//// {| "itemName": "[Symbol.isConcatSpreadable]", "kind": "getter", "parentName": "C" |} //// get [Symbol.isConcatSpreadable]() { } ////} -test.markers().forEach(marker => { - verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); -}); - -// 2 lack markers: and its child -verify.navigationBarCount(2 + test.markers().length); \ No newline at end of file +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "C", + "kind": "class" + } + ], + "indent": 0 + }, + { + "text": "C", + "kind": "class", + "childItems": [ + { + "text": "[Symbol.isConcatSpreadable]", + "kind": "getter" + }, + { + "text": "[Symbol.isRegExp]", + "kind": "property" + }, + { + "text": "[Symbol.iterator]", + "kind": "method" + } + ], + "indent": 1 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsSymbols2.ts b/tests/cases/fourslash/navigationBarItemsSymbols2.ts index 5c398f77bbd..d747b5dadaa 100644 --- a/tests/cases/fourslash/navigationBarItemsSymbols2.ts +++ b/tests/cases/fourslash/navigationBarItemsSymbols2.ts @@ -1,16 +1,35 @@ /// -////{| "itemName": "I", "kind": "interface", "parentName": "" |} ////interface I { -//// {| "itemName": "[Symbol.isRegExp]", "kind": "property", "parentName": "I" |} //// [Symbol.isRegExp]: string; -//// {| "itemName": "[Symbol.iterator]", "kind": "method", "parentName": "I" |} //// [Symbol.iterator](): string; ////} -test.markers().forEach(marker => { - verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); -}); - -// 2 are not marked: and its child. -verify.navigationBarCount(2 + test.markers().length); \ No newline at end of file +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "I", + "kind": "interface" + } + ], + "indent": 0 + }, + { + "text": "I", + "kind": "interface", + "childItems": [ + { + "text": "[Symbol.isRegExp]", + "kind": "property" + }, + { + "text": "[Symbol.iterator]", + "kind": "method" + } + ], + "indent": 1 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsSymbols3.ts b/tests/cases/fourslash/navigationBarItemsSymbols3.ts index 23451588ecd..29ff9f277a3 100644 --- a/tests/cases/fourslash/navigationBarItemsSymbols3.ts +++ b/tests/cases/fourslash/navigationBarItemsSymbols3.ts @@ -1,13 +1,26 @@ /// -////{| "itemName": "E", "kind": "enum", "parentName": "" |} ////enum E { //// // No nav bar entry for this //// [Symbol.isRegExp] = 0 ////} -test.markers().forEach(marker => { - verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); -}); - -verify.navigationBarCount(3); // and E appearing both toplevel and under \ No newline at end of file +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "E", + "kind": "enum" + } + ], + "indent": 0 + }, + { + "text": "E", + "kind": "enum", + "childItems": [], + "indent": 1 + } +]); diff --git a/tests/cases/fourslash/navigationBarItemsTypeAlias.ts b/tests/cases/fourslash/navigationBarItemsTypeAlias.ts index 50923256533..8a422651bf3 100644 --- a/tests/cases/fourslash/navigationBarItemsTypeAlias.ts +++ b/tests/cases/fourslash/navigationBarItemsTypeAlias.ts @@ -2,5 +2,17 @@ ////type T = number | string; -verify.navigationBarCount(1); -verify.navigationBarContains("T", "type"); +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [], + "indent": 0 + }, + { + "text": "T", + "kind": "type", + "childItems": [], + "indent": 1 + } +]); diff --git a/tests/cases/fourslash/server/navbar01.ts b/tests/cases/fourslash/server/navbar01.ts index fea424317db..ed8ed2d8563 100644 --- a/tests/cases/fourslash/server/navbar01.ts +++ b/tests/cases/fourslash/server/navbar01.ts @@ -1,52 +1,171 @@ /// ////// Interface -////{| "itemName": "IPoint", "kind": "interface", "parentName": "" |}interface IPoint { -//// {| "itemName": "getDist", "kind": "method", "parentName": "IPoint" |}getDist(): number; -//// {| "itemName": "new()", "kind": "construct", "parentName": "IPoint" |}new(): IPoint; -//// {| "itemName": "()", "kind": "call", "parentName": "IPoint" |}(): any; -//// {| "itemName": "[]", "kind": "index", "parentName": "IPoint" |}[x:string]: number; -//// {| "itemName": "prop", "kind": "property", "parentName": "IPoint" |}prop: string; +////interface IPoint { +//// getDist(): number; +//// new(): IPoint; +//// (): any; +//// [x:string]: number; +//// prop: string; ////} //// /////// Module -////{| "itemName": "Shapes", "kind": "module", "parentName": "" |}module Shapes { -//// +////module Shapes { //// // Class -//// {| "itemName": "Point", "kind": "class", "parentName": "Shapes" |}export class Point implements IPoint { -//// {| "itemName": "constructor", "kind": "constructor", "parentName": "Point" |}constructor (public x: number, public y: number) { } +//// export class Point implements IPoint { +//// constructor (public x: number, public y: number) { } //// //// // Instance member -//// {| "itemName": "getDist", "kind": "method", "parentName": "Point" |}getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); } +//// getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); } //// //// // Getter -//// {| "itemName": "value", "kind": "getter", "parentName": "Point" |}get value(): number { return 0; } +//// get value(): number { return 0; } //// //// // Setter -//// {| "itemName": "value", "kind": "setter", "parentName": "Point" |}set value(newValue: number) { return; } +//// set value(newValue: number) { return; } //// //// // Static member -//// {| "itemName": "origin", "kind": "property", "parentName": "Point" |}static origin = new Point(0, 0); +//// static origin = new Point(0, 0); //// //// // Static method -//// {| "itemName": "getOrigin", "kind": "method", "parentName": "Point" |}private static getOrigin() { return Point.origin;} +//// private static getOrigin() { return Point.origin;} //// } //// -//// {| "itemName": "Values", "kind": "enum", "parentName": "Shapes" |}enum Values { -//// value1, -//// {| "itemName": "value2", "kind": "property", "parentName": "Values" |}value2, -//// value3, -//// } +//// enum Values { value1, value2, value3 } ////} //// ////// Local variables -////{| "itemName": "p", "kind": "var", "parentName": "" |}var p: IPoint = new Shapes.Point(3, 4); -////{| "itemName": "dist", "kind": "var", "parentName": "" |}var dist = p.getDist(); +////var p: IPoint = new Shapes.Point(3, 4); +////var dist = p.getDist(); -test.markers().forEach((marker) => { - if (marker.data) { - verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName); +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "dist", + "kind": "var" + }, + { + "text": "IPoint", + "kind": "interface" + }, + { + "text": "p", + "kind": "var" + }, + { + "text": "Shapes", + "kind": "module" + } + ], + "indent": 0 + }, + { + "text": "IPoint", + "kind": "interface", + "childItems": [ + { + "text": "()", + "kind": "call" + }, + { + "text": "new()", + "kind": "construct" + }, + { + "text": "[]", + "kind": "index" + }, + { + "text": "getDist", + "kind": "method" + }, + { + "text": "prop", + "kind": "property" + } + ], + "indent": 0 + }, + { + "text": "Shapes", + "kind": "module", + "childItems": [ + { + "text": "Point", + "kind": "class", + "kindModifiers": "export" + }, + { + "text": "Values", + "kind": "enum" + } + ], + "indent": 0 + }, + { + "text": "Point", + "kind": "class", + "kindModifiers": "export", + "childItems": [ + { + "text": "constructor", + "kind": "constructor" + }, + { + "text": "getDist", + "kind": "method" + }, + { + "text": "getOrigin", + "kind": "method", + "kindModifiers": "private,static" + }, + { + "text": "origin", + "kind": "property", + "kindModifiers": "static" + }, + { + "text": "value", + "kind": "getter" + }, + { + "text": "value", + "kind": "setter" + }, + { + "text": "x", + "kind": "property", + "kindModifiers": "public" + }, + { + "text": "y", + "kind": "property", + "kindModifiers": "public" + } + ], + "indent": 0 + }, + { + "text": "Values", + "kind": "enum", + "childItems": [ + { + "text": "value1", + "kind": "property" + }, + { + "text": "value2", + "kind": "property" + }, + { + "text": "value3", + "kind": "property" + } + ], + "indent": 0 } -}); - -verify.navigationBarCount(27); +]); diff --git a/tests/cases/fourslash/shims-pp/getNavigationBarItems.ts b/tests/cases/fourslash/shims-pp/getNavigationBarItems.ts index a2cdb80baef..fe852e03a28 100644 --- a/tests/cases/fourslash/shims-pp/getNavigationBarItems.ts +++ b/tests/cases/fourslash/shims-pp/getNavigationBarItems.ts @@ -2,12 +2,16 @@ //// {| "itemName": "c", "kind": "const", "parentName": "" |}const c = 0; -test.markers().forEach(marker => { - verify.navigationBarContains( - marker.data.itemName, - marker.data.kind, - marker.fileName, - marker.data.parentName, - marker.data.isAdditionalRange, - marker.position); -}); \ No newline at end of file +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "c", + "kind": "const" + } + ], + "indent": 0 + } +]); diff --git a/tests/cases/fourslash/shims/getNavigationBarItems.ts b/tests/cases/fourslash/shims/getNavigationBarItems.ts index a2cdb80baef..fe852e03a28 100644 --- a/tests/cases/fourslash/shims/getNavigationBarItems.ts +++ b/tests/cases/fourslash/shims/getNavigationBarItems.ts @@ -2,12 +2,16 @@ //// {| "itemName": "c", "kind": "const", "parentName": "" |}const c = 0; -test.markers().forEach(marker => { - verify.navigationBarContains( - marker.data.itemName, - marker.data.kind, - marker.fileName, - marker.data.parentName, - marker.data.isAdditionalRange, - marker.position); -}); \ No newline at end of file +verify.navigationBar([ + { + "text": "", + "kind": "module", + "childItems": [ + { + "text": "c", + "kind": "const" + } + ], + "indent": 0 + } +]); From 12914eacc5300c5cd9a0aa44df4bef85591288be Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 26 May 2016 09:01:56 -0700 Subject: [PATCH 32/61] Fix lint errors --- src/harness/fourslash.ts | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index c33c9107ad7..53aaa8c7d6e 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1963,7 +1963,7 @@ namespace FourSlash { let items = this.languageService.getNavigationBarItems(this.activeFile.fileName); items = this.simplifyNavigationBar(items); if (JSON.stringify(items) !== JSON.stringify(json)) { - this.raiseError(`verifyNavigationBar failed - expected: ${JSON.stringify(json, undefined, 2)}, got: ${JSON.stringify(items, undefined, 2)}`) + this.raiseError(`verifyNavigationBar failed - expected: ${JSON.stringify(json, undefined, 2)}, got: ${JSON.stringify(items, undefined, 2)}`); } } @@ -1971,30 +1971,35 @@ namespace FourSlash { private simplifyNavigationBar(items: ts.NavigationBarItem[]): any { return items.map(item => { item = ts.clone(item); - if (item.kindModifiers === "") + if (item.kindModifiers === "") { delete item.kindModifiers; + } + // We won't check this. delete item.spans; item.childItems = item.childItems.map(child => { child = ts.clone(child); - ts.Debug.assert(child.childItems.length === 0); - ts.Debug.assert(child.indent === 0); - ts.Debug.assert(child.bolded === false); - ts.Debug.assert(child.grayed === false); - delete child.childItems; - delete child.indent; - delete child.bolded; - delete child.grayed; delete child.spans; - if (child.kindModifiers === "") + ts.Debug.assert(child.childItems.length === 0); + delete child.childItems; + ts.Debug.assert(child.indent === 0); + delete child.indent; + ts.Debug.assert(child.bolded === false); + delete child.bolded; + ts.Debug.assert(child.grayed === false); + delete child.grayed; + if (child.kindModifiers === "") { delete child.kindModifiers; + } return child; }); - if (item.bolded === false) + if (item.bolded === false) { delete item.bolded; - if (item.grayed === false) + } + if (item.grayed === false) { delete item.grayed; + } return item; - }) + }); } public printNavigationItems(searchValue: string) { From cc5b103b2ee59a61241cd8cc942497f048f7012b Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 26 May 2016 09:45:40 -0700 Subject: [PATCH 33/61] Fix localeCompare differences in node versions --- src/services/navigationBar.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index bcf0726ffd5..1c3dcb0a585 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -140,7 +140,7 @@ namespace ts.NavigationBar { function sortNodes(nodes: Node[]): Node[] { return nodes.slice(0).sort((n1: Declaration, n2: Declaration) => { if (n1.name && n2.name) { - return getPropertyNameForPropertyNameNode(n1.name).localeCompare(getPropertyNameForPropertyNameNode(n2.name)); + return localeCompareFix(getPropertyNameForPropertyNameNode(n1.name), getPropertyNameForPropertyNameNode(n2.name)); } else if (n1.name) { return 1; @@ -152,6 +152,16 @@ namespace ts.NavigationBar { return n1.kind - n2.kind; } }); + + // node 0.10 treats "a" as greater than "B". + // For consistency, sort alphabetically, falling back to which is lower-case. + function localeCompareFix(a: string, b: string) { + const cmp = a.toLowerCase().localeCompare(b.toLowerCase()); + if (cmp !== 0) + return cmp; + // Return the *opposite* of the `<` operator, which works the same in node 0.10 and 6.0. + return a < b ? 1 : a > b ? -1 : 0; + } } function addTopLevelNodes(nodes: Node[], topLevelNodes: Node[]): void { From f012159220edaa716bf39c297b334486c687d354 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 26 May 2016 09:59:45 -0700 Subject: [PATCH 34/61] Revert previous commit --- src/services/navigationBar.ts | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 1c3dcb0a585..bcf0726ffd5 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -140,7 +140,7 @@ namespace ts.NavigationBar { function sortNodes(nodes: Node[]): Node[] { return nodes.slice(0).sort((n1: Declaration, n2: Declaration) => { if (n1.name && n2.name) { - return localeCompareFix(getPropertyNameForPropertyNameNode(n1.name), getPropertyNameForPropertyNameNode(n2.name)); + return getPropertyNameForPropertyNameNode(n1.name).localeCompare(getPropertyNameForPropertyNameNode(n2.name)); } else if (n1.name) { return 1; @@ -152,16 +152,6 @@ namespace ts.NavigationBar { return n1.kind - n2.kind; } }); - - // node 0.10 treats "a" as greater than "B". - // For consistency, sort alphabetically, falling back to which is lower-case. - function localeCompareFix(a: string, b: string) { - const cmp = a.toLowerCase().localeCompare(b.toLowerCase()); - if (cmp !== 0) - return cmp; - // Return the *opposite* of the `<` operator, which works the same in node 0.10 and 6.0. - return a < b ? 1 : a > b ? -1 : 0; - } } function addTopLevelNodes(nodes: Node[], topLevelNodes: Node[]): void { From 58d69cda6447b626ad269c946f2f7ec8e8aba758 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 26 May 2016 10:03:07 -0700 Subject: [PATCH 35/61] Fix localeCompare differences between node versions node 6.2.0: "a".localeCompare("A") is -1. node 0.10.45: "a".localeCompare("A") is 32. --- src/services/navigationBar.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index f6f7b741a56..8db95584eb4 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -134,7 +134,7 @@ namespace ts.NavigationBar { function sortNodes(nodes: Node[]): Node[] { return nodes.slice(0).sort((n1: Declaration, n2: Declaration) => { if (n1.name && n2.name) { - return getPropertyNameForPropertyNameNode(n1.name).localeCompare(getPropertyNameForPropertyNameNode(n2.name)); + return localeCompareFix(getPropertyNameForPropertyNameNode(n1.name), getPropertyNameForPropertyNameNode(n2.name)); } else if (n1.name) { return 1; @@ -146,6 +146,16 @@ namespace ts.NavigationBar { return n1.kind - n2.kind; } }); + + // node 0.10 treats "a" as greater than "B". + // For consistency, sort alphabetically, falling back to which is lower-case. + function localeCompareFix(a: string, b: string) { + const cmp = a.toLowerCase().localeCompare(b.toLowerCase()); + if (cmp !== 0) + return cmp; + // Return the *opposite* of the `<` operator, which works the same in node 0.10 and 6.0. + return a < b ? 1 : a > b ? -1 : 0; + } } function addTopLevelNodes(nodes: Node[], topLevelNodes: Node[]): void { From fdd5c06b630287c03bbd0c5508eb96cea4834240 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 26 May 2016 12:18:19 -0700 Subject: [PATCH 36/61] Include type aliases as childItems in navigation bar --- src/services/navigationBar.ts | 3 +++ tests/cases/fourslash/navigationBarItemsTypeAlias.ts | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index bcf0726ffd5..0cb431de668 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -104,6 +104,7 @@ namespace ts.NavigationBar { case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.ImportSpecifier: case SyntaxKind.ExportSpecifier: + case SyntaxKind.TypeAliasDeclaration: childNodes.push(node); break; } @@ -326,6 +327,8 @@ namespace ts.NavigationBar { case SyntaxKind.InterfaceDeclaration: return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.interfaceElement); + case SyntaxKind.TypeAliasDeclaration: + return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.typeElement); case SyntaxKind.CallSignature: return createItem(node, "()", ts.ScriptElementKind.callSignatureElement); diff --git a/tests/cases/fourslash/navigationBarItemsTypeAlias.ts b/tests/cases/fourslash/navigationBarItemsTypeAlias.ts index 50923256533..448a959380f 100644 --- a/tests/cases/fourslash/navigationBarItemsTypeAlias.ts +++ b/tests/cases/fourslash/navigationBarItemsTypeAlias.ts @@ -2,5 +2,6 @@ ////type T = number | string; -verify.navigationBarCount(1); +verify.navigationBarCount(3); verify.navigationBarContains("T", "type"); +verify.navigationBarChildItem("", "T", "type"); From abfcdd2cfdbc7abc149496c43f49e43e910eb8ea Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 26 May 2016 12:42:35 -0700 Subject: [PATCH 37/61] Symbol for property assignments in Salsa/ES6 constructors Previously no symbol at all was created, meaning that Salsa didn't track properties in ES6 code. --- src/compiler/binder.ts | 18 +++++++++++++----- .../cases/fourslash/renameJsThisProperty03.ts | 14 ++++++++++++++ .../cases/fourslash/renameJsThisProperty04.ts | 14 ++++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 tests/cases/fourslash/renameJsThisProperty03.ts create mode 100644 tests/cases/fourslash/renameJsThisProperty04.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 19fdf79a24a..6f0f1ac7863 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1880,12 +1880,20 @@ namespace ts { } function bindThisPropertyAssignment(node: BinaryExpression) { - // Declare a 'member' in case it turns out the container was an ES5 class - if (container.kind === SyntaxKind.FunctionExpression || container.kind === SyntaxKind.FunctionDeclaration) { - container.symbol.members = container.symbol.members || {}; - // It's acceptable for multiple 'this' assignments of the same identifier to occur - declareSymbol(container.symbol.members, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property); + // Declare a 'member' in case it turns out the container was an ES5 class or ES6 constructor + let assignee: Node; + if (container.kind === SyntaxKind.FunctionDeclaration || container.kind === SyntaxKind.FunctionDeclaration) { + assignee = container; } + else if (container.kind === SyntaxKind.Constructor) { + assignee = container.parent; + } + else { + return; + } + assignee.symbol.members = assignee.symbol.members || {}; + // It's acceptable for multiple 'this' assignments of the same identifier to occur + declareSymbol(assignee.symbol.members, assignee.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property); } function bindPrototypePropertyAssignment(node: BinaryExpression) { diff --git a/tests/cases/fourslash/renameJsThisProperty03.ts b/tests/cases/fourslash/renameJsThisProperty03.ts new file mode 100644 index 00000000000..f2176538578 --- /dev/null +++ b/tests/cases/fourslash/renameJsThisProperty03.ts @@ -0,0 +1,14 @@ +/// + +// @allowJs: true +// @Filename: a.js +////class C { +//// constructor(y) { +//// this./**/[|x|] = y; +//// } +////} +////var t = new C(12); +////t.[|x|] = 11; + +goTo.marker(); +verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false); diff --git a/tests/cases/fourslash/renameJsThisProperty04.ts b/tests/cases/fourslash/renameJsThisProperty04.ts new file mode 100644 index 00000000000..e307022c66f --- /dev/null +++ b/tests/cases/fourslash/renameJsThisProperty04.ts @@ -0,0 +1,14 @@ +/// + +// @allowJs: true +// @Filename: a.js +////class C { +//// constructor(y) { +//// this.[|x|] = y; +//// } +////} +////var t = new C(12); +////t./**/[|x|] = 11; + +goTo.marker(); +verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false); From 5e49b57fea08e913b222ec7a30dd24f7706173af Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 26 May 2016 13:00:38 -0700 Subject: [PATCH 38/61] Fix #8834: exclude paramters and variables from flag checks --- src/compiler/checker.ts | 6 ++++++ .../optionalParamterAndVariableDeclaration.js | 15 +++++++++++++++ ...ptionalParamterAndVariableDeclaration.symbols | 13 +++++++++++++ .../optionalParamterAndVariableDeclaration.types | 16 ++++++++++++++++ ...nalParamterAndVariableDeclaration2.errors.txt | 13 +++++++++++++ .../optionalParamterAndVariableDeclaration2.js | 16 ++++++++++++++++ .../optionalParamterAndVariableDeclaration.ts | 5 +++++ .../optionalParamterAndVariableDeclaration2.ts | 7 +++++++ 8 files changed, 91 insertions(+) create mode 100644 tests/baselines/reference/optionalParamterAndVariableDeclaration.js create mode 100644 tests/baselines/reference/optionalParamterAndVariableDeclaration.symbols create mode 100644 tests/baselines/reference/optionalParamterAndVariableDeclaration.types create mode 100644 tests/baselines/reference/optionalParamterAndVariableDeclaration2.errors.txt create mode 100644 tests/baselines/reference/optionalParamterAndVariableDeclaration2.js create mode 100644 tests/cases/compiler/optionalParamterAndVariableDeclaration.ts create mode 100644 tests/cases/compiler/optionalParamterAndVariableDeclaration2.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5a7c6fa29e5..db996d26131 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14527,6 +14527,12 @@ namespace ts { } function areDeclarationFlagsIdentical(left: Declaration, right: Declaration) { + if ((left.kind === SyntaxKind.Parameter && right.kind === SyntaxKind.VariableDeclaration) || + (left.kind === SyntaxKind.VariableDeclaration && right.kind === SyntaxKind.Parameter)) { + // Diffrences in optionality between paramters and variables are allowed. + return true; + } + if (hasQuestionToken(left) !== hasQuestionToken(right)) { return false; } diff --git a/tests/baselines/reference/optionalParamterAndVariableDeclaration.js b/tests/baselines/reference/optionalParamterAndVariableDeclaration.js new file mode 100644 index 00000000000..ae672b15d54 --- /dev/null +++ b/tests/baselines/reference/optionalParamterAndVariableDeclaration.js @@ -0,0 +1,15 @@ +//// [optionalParamterAndVariableDeclaration.ts] +class C { + constructor(options?: number) { + var options = (options || 0); + } +} + + +//// [optionalParamterAndVariableDeclaration.js] +var C = (function () { + function C(options) { + var options = (options || 0); + } + return C; +}()); diff --git a/tests/baselines/reference/optionalParamterAndVariableDeclaration.symbols b/tests/baselines/reference/optionalParamterAndVariableDeclaration.symbols new file mode 100644 index 00000000000..0a761182e02 --- /dev/null +++ b/tests/baselines/reference/optionalParamterAndVariableDeclaration.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/optionalParamterAndVariableDeclaration.ts === +class C { +>C : Symbol(C, Decl(optionalParamterAndVariableDeclaration.ts, 0, 0)) + + constructor(options?: number) { +>options : Symbol(options, Decl(optionalParamterAndVariableDeclaration.ts, 1, 16), Decl(optionalParamterAndVariableDeclaration.ts, 2, 11)) + + var options = (options || 0); +>options : Symbol(options, Decl(optionalParamterAndVariableDeclaration.ts, 1, 16), Decl(optionalParamterAndVariableDeclaration.ts, 2, 11)) +>options : Symbol(options, Decl(optionalParamterAndVariableDeclaration.ts, 1, 16), Decl(optionalParamterAndVariableDeclaration.ts, 2, 11)) + } +} + diff --git a/tests/baselines/reference/optionalParamterAndVariableDeclaration.types b/tests/baselines/reference/optionalParamterAndVariableDeclaration.types new file mode 100644 index 00000000000..36c74bf00b9 --- /dev/null +++ b/tests/baselines/reference/optionalParamterAndVariableDeclaration.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/optionalParamterAndVariableDeclaration.ts === +class C { +>C : C + + constructor(options?: number) { +>options : number + + var options = (options || 0); +>options : number +>(options || 0) : number +>options || 0 : number +>options : number +>0 : number + } +} + diff --git a/tests/baselines/reference/optionalParamterAndVariableDeclaration2.errors.txt b/tests/baselines/reference/optionalParamterAndVariableDeclaration2.errors.txt new file mode 100644 index 00000000000..0d309327531 --- /dev/null +++ b/tests/baselines/reference/optionalParamterAndVariableDeclaration2.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/optionalParamterAndVariableDeclaration2.ts(4,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'options' must be of type 'number | undefined', but here has type 'number'. + + +==== tests/cases/compiler/optionalParamterAndVariableDeclaration2.ts (1 errors) ==== + + class C { + constructor(options?: number) { + var options = (options || 0); + ~~~~~~~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'options' must be of type 'number | undefined', but here has type 'number'. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/optionalParamterAndVariableDeclaration2.js b/tests/baselines/reference/optionalParamterAndVariableDeclaration2.js new file mode 100644 index 00000000000..a4ffc9f382d --- /dev/null +++ b/tests/baselines/reference/optionalParamterAndVariableDeclaration2.js @@ -0,0 +1,16 @@ +//// [optionalParamterAndVariableDeclaration2.ts] + +class C { + constructor(options?: number) { + var options = (options || 0); + } +} + + +//// [optionalParamterAndVariableDeclaration2.js] +var C = (function () { + function C(options) { + var options = (options || 0); + } + return C; +}()); diff --git a/tests/cases/compiler/optionalParamterAndVariableDeclaration.ts b/tests/cases/compiler/optionalParamterAndVariableDeclaration.ts new file mode 100644 index 00000000000..d9c1d407dca --- /dev/null +++ b/tests/cases/compiler/optionalParamterAndVariableDeclaration.ts @@ -0,0 +1,5 @@ +class C { + constructor(options?: number) { + var options = (options || 0); + } +} diff --git a/tests/cases/compiler/optionalParamterAndVariableDeclaration2.ts b/tests/cases/compiler/optionalParamterAndVariableDeclaration2.ts new file mode 100644 index 00000000000..7bdb0ab89c2 --- /dev/null +++ b/tests/cases/compiler/optionalParamterAndVariableDeclaration2.ts @@ -0,0 +1,7 @@ +// @strictNullChecks: true + +class C { + constructor(options?: number) { + var options = (options || 0); + } +} From 04d6e9167f031e045958010f7705d7377c77597a Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 26 May 2016 14:11:06 -0700 Subject: [PATCH 39/61] Fix typos --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index db996d26131..2e701bd56bf 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14529,7 +14529,7 @@ namespace ts { function areDeclarationFlagsIdentical(left: Declaration, right: Declaration) { if ((left.kind === SyntaxKind.Parameter && right.kind === SyntaxKind.VariableDeclaration) || (left.kind === SyntaxKind.VariableDeclaration && right.kind === SyntaxKind.Parameter)) { - // Diffrences in optionality between paramters and variables are allowed. + // Differences in optionality between parameters and variables are allowed. return true; } From 81ce532cde1f4ffd88e8c507b19432712723401f Mon Sep 17 00:00:00 2001 From: zhengbli Date: Wed, 25 May 2016 23:05:20 -0700 Subject: [PATCH 40/61] Change how typedef tag is parsed --- src/compiler/binder.ts | 7 +- src/compiler/parser.ts | 215 ++++++++++++++++++----------------------- src/compiler/types.ts | 13 +-- 3 files changed, 103 insertions(+), 132 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 9b421ed34cb..377c5d3f465 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1702,8 +1702,9 @@ namespace ts { case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: case SyntaxKind.JSDocRecordMember: - case SyntaxKind.JSDocPropertyTag: return bindPropertyOrMethodOrAccessor(node, SymbolFlags.Property | ((node).questionToken ? SymbolFlags.Optional : SymbolFlags.None), SymbolFlags.PropertyExcludes); + case SyntaxKind.JSDocPropertyTag: + return bindJSDocProperty(node); case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: return bindPropertyOrMethodOrAccessor(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); @@ -2085,6 +2086,10 @@ namespace ts { : declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes); } + function bindJSDocProperty(node: JSDocPropertyTag) { + return declareSymbolAndAddToSymbolTable(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + } + // reachability checks function shouldReportErrorOnModuleDeclaration(node: ModuleDeclaration): boolean { diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 9c26fdeb179..07509d0afcc 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -406,7 +406,7 @@ namespace ts { visitNode(cbNode, (node).name) || visitNode(cbNode, (node).type); case SyntaxKind.JSDocTypeLiteral: - return visitNodes(cbNodes, (node).members); + return visitNodes(cbNodes, (node).jsDocPropertyTags); case SyntaxKind.JSDocPropertyTag: return visitNode(cbNode, (node).typeExpression) || visitNode(cbNode, (node).name); @@ -4113,9 +4113,9 @@ namespace ts { const isAsync = !!(node.flags & NodeFlags.Async); node.name = isGenerator && isAsync ? doInYieldAndAwaitContext(parseOptionalIdentifier) : - isGenerator ? doInYieldContext(parseOptionalIdentifier) : - isAsync ? doInAwaitContext(parseOptionalIdentifier) : - parseOptionalIdentifier(); + isGenerator ? doInYieldContext(parseOptionalIdentifier) : + isAsync ? doInAwaitContext(parseOptionalIdentifier) : + parseOptionalIdentifier(); fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, node); node.body = parseFunctionBlock(/*allowYield*/ isGenerator, /*allowAwait*/ isAsync, /*ignoreMissingOpenBrace*/ false); @@ -6066,9 +6066,6 @@ namespace ts { Debug.assert(end <= content.length); let tags: NodeArray; - let currentParentJSDocTag: JSDocParentTag; - let currentParentJSDocTagEnd: number; - let result: JSDocComment; // Check for /** (JSDoc opening part) @@ -6125,10 +6122,6 @@ namespace ts { nextJSDocToken(); } - if (currentParentJSDocTag) { - finishCurrentParentTag(); - } - result = createJSDocComment(); }); @@ -6152,40 +6145,6 @@ namespace ts { } } - function finishCurrentParentTag(): void { - if (!currentParentJSDocTag) { - return; - } - - if (currentParentJSDocTag.kind === SyntaxKind.JSDocTypedefTag) { - const typedefTag = currentParentJSDocTag; - if (typedefTag.jsDocTypeTag) { - if (typedefTag.jsDocTypeTag.typeExpression.type.kind === SyntaxKind.JSDocTypeReference) { - const typeTagtype = typedefTag.jsDocTypeTag.typeExpression.type; - if ((typeTagtype.name.kind !== SyntaxKind.Identifier) || - (typeTagtype.name).text !== "Object") { - typedefTag.type = typedefTag.jsDocTypeTag.typeExpression.type; - } - } - else { - typedefTag.type = typedefTag.jsDocTypeTag.typeExpression.type; - } - } - if (!typedefTag.type && typedefTag.jsDocPropertyTags && typedefTag.jsDocPropertyTags.length > 0) { - const pos = typedefTag.jsDocPropertyTags[0].pos; - const end = typedefTag.jsDocPropertyTags[typedefTag.jsDocPropertyTags.length - 1].end; - const jsdocTypeLiteral = createNode(SyntaxKind.JSDocTypeLiteral, pos); - jsdocTypeLiteral.members = >[]; - addRange(jsdocTypeLiteral.members, typedefTag.jsDocPropertyTags); - typedefTag.type = finishNode(jsdocTypeLiteral, end); - } - } - - addTag(finishNode(currentParentJSDocTag, currentParentJSDocTagEnd)); - currentParentJSDocTag = undefined; - currentParentJSDocTagEnd = undefined; - } - function parseTag(): void { Debug.assert(token === SyntaxKind.AtToken); const atToken = createNode(SyntaxKind.AtToken, scanner.getTokenPos()); @@ -6198,34 +6157,23 @@ namespace ts { } const tag = handleTag(atToken, tagName) || handleUnknownTag(atToken, tagName); - if (!currentParentJSDocTag) { - addTag(tag); - } + addTag(tag); } function handleTag(atToken: Node, tagName: Identifier): JSDocTag { if (tagName) { switch (tagName.text) { case "param": - finishCurrentParentTag(); return handleParamTag(atToken, tagName); case "return": case "returns": - finishCurrentParentTag(); return handleReturnTag(atToken, tagName); case "template": - finishCurrentParentTag(); return handleTemplateTag(atToken, tagName); case "type": - // @typedef tag is allowed to have one @type tag, therefore seeing - // a @type tag may not indicate the end of the current parent tag. return handleTypeTag(atToken, tagName); case "typedef": - finishCurrentParentTag(); return handleTypedefTag(atToken, tagName); - case "property": - case "prop": - return handlePropertyTag(atToken, tagName); } } @@ -6251,25 +6199,6 @@ namespace ts { } } - function addToCurrentParentTag(tag: JSDocTag): void { - if (!currentParentJSDocTag) { - return; - } - switch (tag.kind) { - case SyntaxKind.JSDocPropertyTag: - if (!currentParentJSDocTag.jsDocPropertyTags) { - currentParentJSDocTag.jsDocPropertyTags = >[]; - } - currentParentJSDocTag.jsDocPropertyTags.push(tag); - break; - case SyntaxKind.JSDocTypeTag: - if (!currentParentJSDocTag.jsDocTypeTag) { - currentParentJSDocTag.jsDocTypeTag = tag; - } - break; - } - } - function tryParseTypeExpression(): JSDocTypeExpression { if (token !== SyntaxKind.OpenBraceToken) { return undefined; @@ -6345,32 +6274,14 @@ namespace ts { parseErrorAtPosition(tagName.pos, scanner.getTokenPos() - tagName.pos, Diagnostics._0_tag_already_specified, tagName.text); } - let result = createNode(SyntaxKind.JSDocTypeTag, atToken.pos); + const result = createNode(SyntaxKind.JSDocTypeTag, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.typeExpression = tryParseTypeExpression(); - result = finishNode(result); - - if (currentParentJSDocTag && currentParentJSDocTag.kind === SyntaxKind.JSDocTypedefTag) { - const parentTag = currentParentJSDocTag; - if (!parentTag.typeExpression && !parentTag.jsDocTypeTag) { - parentTag.jsDocTypeTag = result; - currentParentJSDocTagEnd = scanner.getStartPos(); - return result; - } - } - // If this @type tag is not part of the current parent tag, then - // it denotes the end of the current parent tag. - finishCurrentParentTag(); - return result; + return finishNode(result); } function handlePropertyTag(atToken: Node, tagName: Identifier): JSDocPropertyTag { - if (!currentParentJSDocTag) { - parseErrorAtPosition(tagName.pos, scanner.getTokenPos() - tagName.pos, Diagnostics._0_tag_cannot_be_used_independently_as_a_top_level_JSDoc_tag, tagName.text); - return undefined; - } - const typeExpression = tryParseTypeExpression(); skipWhitespace(); const name = parseJSDocIdentifierName(); @@ -6379,17 +6290,12 @@ namespace ts { return undefined; } - let result = createNode(SyntaxKind.JSDocPropertyTag, atToken.pos); + const result = createNode(SyntaxKind.JSDocPropertyTag, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.name = name; result.typeExpression = typeExpression; - result.type = typeExpression.type; - result = finishNode(result); - - addToCurrentParentTag(result); - currentParentJSDocTagEnd = scanner.getStartPos(); - return undefined; + return finishNode(result); } function handleTypedefTag(atToken: Node, tagName: Identifier): JSDocTypedefTag { @@ -6413,32 +6319,99 @@ namespace ts { } } - const result = createNode(SyntaxKind.JSDocTypedefTag, atToken.pos); - result.atToken = atToken; - result.tagName = tagName; - result.name = name; - result.typeExpression = typeExpression; + const typedefTag = createNode(SyntaxKind.JSDocTypedefTag, atToken.pos); + typedefTag.atToken = atToken; + typedefTag.tagName = tagName; + typedefTag.name = name; + typedefTag.typeExpression = typeExpression; - if (typeExpression && typeExpression.type.kind === SyntaxKind.JSDocTypeReference) { - const jsDocTypeReference = typeExpression.type; - if (jsDocTypeReference.name.kind === SyntaxKind.Identifier) { - const name = jsDocTypeReference.name; - if (name.text === "Object") { - currentParentJSDocTag = result; + if (typeExpression) { + if (typeExpression.type.kind === SyntaxKind.JSDocTypeReference) { + const jsDocTypeReference = typeExpression.type; + if (jsDocTypeReference.name.kind === SyntaxKind.Identifier) { + const name = jsDocTypeReference.name; + if (name.text === "Object") { + typedefTag.type = scanChildTags(); + } } } + if (!typedefTag.type) { + typedefTag.type = typeExpression.type; + } } - else if (!typeExpression) { - currentParentJSDocTag = result; + else { + typedefTag.type = scanChildTags(); } - if (!currentParentJSDocTag) { - result.type = result.typeExpression.type; - return finishNode(result); + return finishNode(typedefTag); + + function scanChildTags(): JSDocTypeLiteral { + const jsDocTypeLiteral = createNode(SyntaxKind.JSDocTypeLiteral, scanner.getStartPos()); + let resumePos = scanner.getStartPos(); + let canParseTag = true; + let seenAsterisk = false; + let parentTagTerminated = false; + + while (token !== SyntaxKind.EndOfFileToken && !parentTagTerminated) { + nextJSDocToken(); + switch (token) { + case SyntaxKind.AtToken: + if (canParseTag) { + parentTagTerminated = !tryParseChildTag(jsDocTypeLiteral); + } + seenAsterisk = false; + break; + case SyntaxKind.NewLineTrivia: + resumePos = scanner.getStartPos() - 1; + canParseTag = true; + seenAsterisk = false; + break; + case SyntaxKind.AsteriskToken: + if (seenAsterisk) { + canParseTag = false; + } + seenAsterisk = true; + break; + case SyntaxKind.Identifier: + canParseTag = false; + case SyntaxKind.EndOfFileToken: + break; + } + } + scanner.setTextPos(resumePos); + return finishNode(jsDocTypeLiteral); + } + } + + function tryParseChildTag(parentTag: JSDocTypeLiteral): boolean { + Debug.assert(token === SyntaxKind.AtToken); + const atToken = createNode(SyntaxKind.AtToken, scanner.getStartPos()); + atToken.end = scanner.getTextPos(); + nextJSDocToken(); + + const tagName = parseJSDocIdentifierName(); + if (!tagName) { + return false; } - currentParentJSDocTagEnd = scanner.getStartPos(); - return undefined; + switch (tagName.text) { + case "type": + if (parentTag.jsDocTypeTag) { + // already has a @type tag, terminate the parent tag now. + return false; + } + parentTag.jsDocTypeTag = handleTypeTag(atToken, tagName); + return true; + case "prop": + case "property": + if (!parentTag.jsDocPropertyTags) { + parentTag.jsDocPropertyTags = >[]; + } + const propertyTag = handlePropertyTag(atToken, tagName); + parentTag.jsDocPropertyTags.push(propertyTag); + return true; + } + return false; } function handleTemplateTag(atToken: Node, tagName: Identifier): JSDocTemplateTag { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b472aa92e62..1b9af02a8d5 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1517,29 +1517,22 @@ namespace ts { } // @kind(SyntaxKind.JSDocTypedefTag) - export interface JSDocTypedefTag extends JSDocTag, Declaration, JSDocParentTag { + export interface JSDocTypedefTag extends JSDocTag, Declaration { name: Identifier; typeExpression?: JSDocTypeExpression; type: JSDocType; } - export interface JSDocParentTag extends JSDocTag { - jsDocPropertyTags?: NodeArray; - jsDocTypeTag?: JSDocTypeTag; - } - // @kind(SyntaxKind.JSDocPropertyTag) export interface JSDocPropertyTag extends JSDocTag, TypeElement { name: Identifier; typeExpression: JSDocTypeExpression; - // Add a "type" property here to make the interface compatible - // with the "VariableLikeDeclaration" definition - type: TypeNode; } // @kind(SyntaxKind.JSDocTypeLiteral) export interface JSDocTypeLiteral extends JSDocType { - members: NodeArray; + jsDocPropertyTags?: NodeArray; + jsDocTypeTag?: JSDocTypeTag; } // @kind(SyntaxKind.JSDocParameterTag) From 3b5c72c4bc033f5bf4d38931b2eed0bf0bf7e5e9 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 26 May 2016 15:30:31 -0700 Subject: [PATCH 41/61] Include outer function expressions in control flow analysis --- src/compiler/binder.ts | 24 ++++++++++++++++- src/compiler/checker.ts | 57 +++++++++++++++++++++++++++++++++-------- src/compiler/types.ts | 7 +++++ 3 files changed, 77 insertions(+), 11 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index a7cb0d12758..2476709b501 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -472,6 +472,9 @@ namespace ts { hasExplicitReturn = false; currentFlow = { flags: FlowFlags.Start }; + if (kind === SyntaxKind.FunctionExpression || kind === SyntaxKind.ArrowFunction) { + (currentFlow).container = node; + } currentBreakTarget = undefined; currentContinueTarget = undefined; activeLabels = undefined; @@ -589,6 +592,9 @@ namespace ts { case SyntaxKind.VariableDeclaration: bindVariableDeclarationFlow(node); break; + case SyntaxKind.CallExpression: + bindCallExpressionFlow(node); + break; default: forEachChild(node, bind); break; @@ -1098,6 +1104,20 @@ namespace ts { } } + function bindCallExpressionFlow(node: CallExpression) { + forEachChild(node, bind); + // If the target of the call expression is a function expression or arrow function we have + // an immediately invoked function expression (IIFE). Initialize the flowNode property to + // the current control flow (which includes evaluation of the IIFE arguments). + let expr: Expression = node.expression; + while (expr.kind === SyntaxKind.ParenthesizedExpression) { + expr = (expr).expression; + } + if (expr.kind === SyntaxKind.FunctionExpression || expr.kind === SyntaxKind.ArrowFunction) { + node.flowNode = currentFlow; + } + } + function getContainerFlags(node: Node): ContainerFlags { switch (node.kind) { case SyntaxKind.ClassExpression: @@ -2054,7 +2074,9 @@ namespace ts { hasAsyncFunctions = true; } } - + if (currentFlow) { + node.flowNode = currentFlow; + } checkStrictModeFunctionName(node); const bindingName = (node).name ? (node).name.text : "__function"; return bindAnonymousDeclaration(node, SymbolFlags.Function, bindingName); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5a7c6fa29e5..c14a7e26add 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7648,7 +7648,7 @@ namespace ts { getInitialTypeOfBindingElement(node); } - function getFlowTypeOfReference(reference: Node, declaredType: Type, assumeInitialized: boolean) { + function getFlowTypeOfReference(reference: Node, declaredType: Type, assumeInitialized: boolean, includeOuterFunctions: boolean) { let key: string; if (!reference.flowNode || assumeInitialized && !(declaredType.flags & TypeFlags.Narrowable)) { return declaredType; @@ -7694,15 +7694,30 @@ namespace ts { getTypeAtFlowBranchLabel(flow) : getTypeAtFlowLoopLabel(flow); } - else if (flow.flags & FlowFlags.Unreachable) { + else if (flow.flags & FlowFlags.Start) { + let container = (flow).container; + if (container) { + // If container is an IIFE continue with the control flow associated with the + // call expression node. + let iife = getImmediatelyInvokedFunctionExpression(container); + if (iife && iife.flowNode) { + flow = iife.flowNode; + continue; + } + // Check if we should continue with the control flow of the containing function. + if (includeOuterFunctions && container.flowNode) { + flow = container.flowNode; + continue; + } + } + // At the top of the flow we have the initial type. + type = initialType; + } + else { // Unreachable code errors are reported in the binding phase. Here we // simply return the declared type to reduce follow-on errors. type = declaredType; } - else { - // At the top of the flow we have the initial type. - type = initialType; - } if (flow.flags & FlowFlags.Shared) { // Record visited node and the associated type in the cache. visitedFlowNodes[visitedFlowCount] = flow; @@ -8071,6 +8086,27 @@ namespace ts { return expression; } + function getControlFlowContainer(node: Identifier, declarationContainer: Node, skipFunctionExpressions: boolean) { + let container = getContainingFunctionOrModule(node); + while (container !== declarationContainer && + (container.kind === SyntaxKind.FunctionExpression || container.kind === SyntaxKind.ArrowFunction) && + (skipFunctionExpressions || getImmediatelyInvokedFunctionExpression(container))) { + container = getContainingFunctionOrModule(container); + } + return container; + } + + function isDeclarationIncludedInFlow(reference: Node, declaration: Declaration, includeOuterFunctions: boolean) { + const declarationContainer = getContainingFunctionOrModule(declaration); + let container = getContainingFunctionOrModule(reference); + while (container !== declarationContainer && + (container.kind === SyntaxKind.FunctionExpression || container.kind === SyntaxKind.ArrowFunction) && + (includeOuterFunctions || getImmediatelyInvokedFunctionExpression(container))) { + container = getContainingFunctionOrModule(container); + } + return container === declarationContainer; + } + function checkIdentifier(node: Identifier): Type { const symbol = getResolvedSymbol(node); @@ -8127,10 +8163,11 @@ namespace ts { return type; } const declaration = localOrExportSymbol.valueDeclaration; + const includeOuterFunctions = isReadonlySymbol(localOrExportSymbol); const assumeInitialized = !strictNullChecks || (type.flags & TypeFlags.Any) !== 0 || !declaration || getRootDeclaration(declaration).kind === SyntaxKind.Parameter || isInAmbientContext(declaration) || - getContainingFunctionOrModule(declaration) !== getContainingFunctionOrModule(node); - const flowType = getFlowTypeOfReference(node, type, assumeInitialized); + !isDeclarationIncludedInFlow(node, declaration, includeOuterFunctions); + const flowType = getFlowTypeOfReference(node, type, assumeInitialized, includeOuterFunctions); if (!assumeInitialized && !(getNullableKind(type) & TypeFlags.Undefined) && getNullableKind(flowType) & TypeFlags.Undefined) { error(node, Diagnostics.Variable_0_is_used_before_being_assigned, symbolToString(symbol)); // Return the declared type to reduce follow-on errors @@ -8379,7 +8416,7 @@ namespace ts { if (isClassLike(container.parent)) { const symbol = getSymbolOfNode(container.parent); const type = container.flags & NodeFlags.Static ? getTypeOfSymbol(symbol) : (getDeclaredTypeOfSymbol(symbol)).thisType; - return getFlowTypeOfReference(node, type, /*assumeInitialized*/ true); + return getFlowTypeOfReference(node, type, /*assumeInitialized*/ true, /*includeOuterFunctions*/ true); } if (isInJavaScriptFile(node)) { @@ -9991,7 +10028,7 @@ namespace ts { return propType; } } - return getFlowTypeOfReference(node, propType, /*assumeInitialized*/ true); + return getFlowTypeOfReference(node, propType, /*assumeInitialized*/ true, /*includeOuterFunctions*/ false); } function isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 7613c489920..762d710d504 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1537,6 +1537,13 @@ namespace ts { id?: number; // Node id used by flow type cache in checker } + // FlowStart represents the start of a control flow. For a function expression or arrow + // function, the container property references the function (which in turn has a flowNode + // property for the containing control flow). + export interface FlowStart extends FlowNode { + container?: FunctionExpression | ArrowFunction; + } + // FlowLabel represents a junction with multiple possible preceding control flows. export interface FlowLabel extends FlowNode { antecedents: FlowNode[]; From d20664aa69b54cb05b427fb357c72a384100d131 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 26 May 2016 16:26:30 -0700 Subject: [PATCH 42/61] Fix test --- .../typeGuardsInFunctionAndModuleBlock.js | 4 +-- ...typeGuardsInFunctionAndModuleBlock.symbols | 18 +++++----- .../typeGuardsInFunctionAndModuleBlock.types | 34 +++++++++---------- .../typeGuardsInFunctionAndModuleBlock.ts | 2 +- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.js b/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.js index 91443a9ae78..8ec45de814e 100644 --- a/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.js +++ b/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.js @@ -41,7 +41,7 @@ function foo4(x: number | string | boolean) { : x.toString(); // number })(x); // x here is narrowed to number | boolean } -// Type guards affect nested function expressions and nested function declarations +// Type guards do not affect nested function declarations function foo5(x: number | string | boolean) { if (typeof x === "string") { var y = x; // string; @@ -121,7 +121,7 @@ function foo4(x) { : x.toString(); // number })(x); // x here is narrowed to number | boolean } -// Type guards affect nested function expressions and nested function declarations +// Type guards do not affect nested function declarations function foo5(x) { if (typeof x === "string") { var y = x; // string; diff --git a/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.symbols b/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.symbols index bf21641624e..56eeb22bf9f 100644 --- a/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.symbols +++ b/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.symbols @@ -27,9 +27,9 @@ function foo(x: number | string | boolean) { >toString : Symbol(Object.toString, Decl(lib.d.ts, --, --)) : x.toString(); // number ->x.toString : Symbol(toString, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>x.toString : Symbol(Number.toString, Decl(lib.d.ts, --, --)) >x : Symbol(x, Decl(typeGuardsInFunctionAndModuleBlock.ts, 2, 13)) ->toString : Symbol(toString, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, --, --)) } (); } @@ -60,9 +60,9 @@ function foo2(x: number | string | boolean) { >toString : Symbol(Object.toString, Decl(lib.d.ts, --, --)) : x.toString(); // number ->x.toString : Symbol(toString, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>x.toString : Symbol(Number.toString, Decl(lib.d.ts, --, --)) >x : Symbol(x, Decl(typeGuardsInFunctionAndModuleBlock.ts, 12, 14)) ->toString : Symbol(toString, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, --, --)) } (x); // x here is narrowed to number | boolean >x : Symbol(x, Decl(typeGuardsInFunctionAndModuleBlock.ts, 12, 14)) @@ -91,9 +91,9 @@ function foo3(x: number | string | boolean) { >toString : Symbol(Object.toString, Decl(lib.d.ts, --, --)) : x.toString(); // number ->x.toString : Symbol(toString, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>x.toString : Symbol(Number.toString, Decl(lib.d.ts, --, --)) >x : Symbol(x, Decl(typeGuardsInFunctionAndModuleBlock.ts, 22, 14)) ->toString : Symbol(toString, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, --, --)) })(); } @@ -123,14 +123,14 @@ function foo4(x: number | string | boolean) { >toString : Symbol(Object.toString, Decl(lib.d.ts, --, --)) : x.toString(); // number ->x.toString : Symbol(toString, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>x.toString : Symbol(Number.toString, Decl(lib.d.ts, --, --)) >x : Symbol(x, Decl(typeGuardsInFunctionAndModuleBlock.ts, 32, 14)) ->toString : Symbol(toString, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, --, --)) })(x); // x here is narrowed to number | boolean >x : Symbol(x, Decl(typeGuardsInFunctionAndModuleBlock.ts, 32, 14)) } -// Type guards affect nested function expressions and nested function declarations +// Type guards do not affect nested function declarations function foo5(x: number | string | boolean) { >foo5 : Symbol(foo5, Decl(typeGuardsInFunctionAndModuleBlock.ts, 41, 1)) >x : Symbol(x, Decl(typeGuardsInFunctionAndModuleBlock.ts, 43, 14)) diff --git a/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.types b/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.types index 67d1816cfc3..cc9553b9767 100644 --- a/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.types +++ b/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.types @@ -21,14 +21,14 @@ function foo(x: number | string | boolean) { >f : () => string var b = x; // number | boolean ->b : number | string | boolean ->x : number | string | boolean +>b : number | boolean +>x : number | boolean return typeof x === "boolean" >typeof x === "boolean" ? x.toString() // boolean : x.toString() : string >typeof x === "boolean" : boolean >typeof x : string ->x : number | string | boolean +>x : number | boolean >"boolean" : string ? x.toString() // boolean @@ -40,7 +40,7 @@ function foo(x: number | string | boolean) { : x.toString(); // number >x.toString() : string >x.toString : (radix?: number) => string ->x : number | string +>x : number >toString : (radix?: number) => string } (); @@ -66,14 +66,14 @@ function foo2(x: number | string | boolean) { >a : number | boolean var b = x; // new scope - number | boolean ->b : number | string | boolean ->x : number | string | boolean +>b : number | boolean +>x : number | boolean return typeof x === "boolean" >typeof x === "boolean" ? x.toString() // boolean : x.toString() : string >typeof x === "boolean" : boolean >typeof x : string ->x : number | string | boolean +>x : number | boolean >"boolean" : string ? x.toString() // boolean @@ -85,7 +85,7 @@ function foo2(x: number | string | boolean) { : x.toString(); // number >x.toString() : string >x.toString : (radix?: number) => string ->x : number | string +>x : number >toString : (radix?: number) => string } (x); // x here is narrowed to number | boolean @@ -111,14 +111,14 @@ function foo3(x: number | string | boolean) { >() => { var b = x; // new scope - number | boolean return typeof x === "boolean" ? x.toString() // boolean : x.toString(); // number } : () => string var b = x; // new scope - number | boolean ->b : number | string | boolean ->x : number | string | boolean +>b : number | boolean +>x : number | boolean return typeof x === "boolean" >typeof x === "boolean" ? x.toString() // boolean : x.toString() : string >typeof x === "boolean" : boolean >typeof x : string ->x : number | string | boolean +>x : number | boolean >"boolean" : string ? x.toString() // boolean @@ -130,7 +130,7 @@ function foo3(x: number | string | boolean) { : x.toString(); // number >x.toString() : string >x.toString : (radix?: number) => string ->x : number | string +>x : number >toString : (radix?: number) => string })(); @@ -156,14 +156,14 @@ function foo4(x: number | string | boolean) { >a : number | boolean var b = x; // new scope - number | boolean ->b : number | string | boolean ->x : number | string | boolean +>b : number | boolean +>x : number | boolean return typeof x === "boolean" >typeof x === "boolean" ? x.toString() // boolean : x.toString() : string >typeof x === "boolean" : boolean >typeof x : string ->x : number | string | boolean +>x : number | boolean >"boolean" : string ? x.toString() // boolean @@ -175,13 +175,13 @@ function foo4(x: number | string | boolean) { : x.toString(); // number >x.toString() : string >x.toString : (radix?: number) => string ->x : number | string +>x : number >toString : (radix?: number) => string })(x); // x here is narrowed to number | boolean >x : number | boolean } -// Type guards affect nested function expressions and nested function declarations +// Type guards do not affect nested function declarations function foo5(x: number | string | boolean) { >foo5 : (x: number | string | boolean) => void >x : number | string | boolean diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardsInFunctionAndModuleBlock.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardsInFunctionAndModuleBlock.ts index 5dbc925d04b..f1ba854394b 100644 --- a/tests/cases/conformance/expressions/typeGuards/typeGuardsInFunctionAndModuleBlock.ts +++ b/tests/cases/conformance/expressions/typeGuards/typeGuardsInFunctionAndModuleBlock.ts @@ -40,7 +40,7 @@ function foo4(x: number | string | boolean) { : x.toString(); // number })(x); // x here is narrowed to number | boolean } -// Type guards affect nested function expressions and nested function declarations +// Type guards do not affect nested function declarations function foo5(x: number | string | boolean) { if (typeof x === "string") { var y = x; // string; From e5e21f9b5e34f1c999289a9ba7cbd9adbde67290 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 26 May 2016 16:26:40 -0700 Subject: [PATCH 43/61] Add new tests --- .../constLocalsInFunctionExpressions.js | 73 +++++++++ .../constLocalsInFunctionExpressions.symbols | 95 +++++++++++ .../constLocalsInFunctionExpressions.types | 121 ++++++++++++++ tests/baselines/reference/controlFlowIIFE.js | 87 ++++++++++ .../reference/controlFlowIIFE.symbols | 108 +++++++++++++ .../baselines/reference/controlFlowIIFE.types | 149 ++++++++++++++++++ .../constLocalsInFunctionExpressions.ts | 38 +++++ .../controlFlow/controlFlowIIFE.ts | 47 ++++++ 8 files changed, 718 insertions(+) create mode 100644 tests/baselines/reference/constLocalsInFunctionExpressions.js create mode 100644 tests/baselines/reference/constLocalsInFunctionExpressions.symbols create mode 100644 tests/baselines/reference/constLocalsInFunctionExpressions.types create mode 100644 tests/baselines/reference/controlFlowIIFE.js create mode 100644 tests/baselines/reference/controlFlowIIFE.symbols create mode 100644 tests/baselines/reference/controlFlowIIFE.types create mode 100644 tests/cases/conformance/controlFlow/constLocalsInFunctionExpressions.ts create mode 100644 tests/cases/conformance/controlFlow/controlFlowIIFE.ts diff --git a/tests/baselines/reference/constLocalsInFunctionExpressions.js b/tests/baselines/reference/constLocalsInFunctionExpressions.js new file mode 100644 index 00000000000..473de3b1a6c --- /dev/null +++ b/tests/baselines/reference/constLocalsInFunctionExpressions.js @@ -0,0 +1,73 @@ +//// [constLocalsInFunctionExpressions.ts] +declare function getStringOrNumber(): string | number; + +function f1() { + const x = getStringOrNumber(); + if (typeof x === "string") { + const f = () => x.length; + } +} + +function f2() { + const x = getStringOrNumber(); + if (typeof x !== "string") { + return; + } + const f = () => x.length; +} + +function f3() { + const x = getStringOrNumber(); + if (typeof x === "string") { + const f = function() { return x.length; }; + } +} + +function f4() { + const x = getStringOrNumber(); + if (typeof x !== "string") { + return; + } + const f = function() { return x.length; }; +} + +function f5() { + const x = getStringOrNumber(); + if (typeof x === "string") { + const f = () => () => x.length; + } +} + +//// [constLocalsInFunctionExpressions.js] +function f1() { + var x = getStringOrNumber(); + if (typeof x === "string") { + var f = function () { return x.length; }; + } +} +function f2() { + var x = getStringOrNumber(); + if (typeof x !== "string") { + return; + } + var f = function () { return x.length; }; +} +function f3() { + var x = getStringOrNumber(); + if (typeof x === "string") { + var f = function () { return x.length; }; + } +} +function f4() { + var x = getStringOrNumber(); + if (typeof x !== "string") { + return; + } + var f = function () { return x.length; }; +} +function f5() { + var x = getStringOrNumber(); + if (typeof x === "string") { + var f = function () { return function () { return x.length; }; }; + } +} diff --git a/tests/baselines/reference/constLocalsInFunctionExpressions.symbols b/tests/baselines/reference/constLocalsInFunctionExpressions.symbols new file mode 100644 index 00000000000..d9465a118aa --- /dev/null +++ b/tests/baselines/reference/constLocalsInFunctionExpressions.symbols @@ -0,0 +1,95 @@ +=== tests/cases/conformance/controlFlow/constLocalsInFunctionExpressions.ts === +declare function getStringOrNumber(): string | number; +>getStringOrNumber : Symbol(getStringOrNumber, Decl(constLocalsInFunctionExpressions.ts, 0, 0)) + +function f1() { +>f1 : Symbol(f1, Decl(constLocalsInFunctionExpressions.ts, 0, 54)) + + const x = getStringOrNumber(); +>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 3, 9)) +>getStringOrNumber : Symbol(getStringOrNumber, Decl(constLocalsInFunctionExpressions.ts, 0, 0)) + + if (typeof x === "string") { +>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 3, 9)) + + const f = () => x.length; +>f : Symbol(f, Decl(constLocalsInFunctionExpressions.ts, 5, 13)) +>x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 3, 9)) +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) + } +} + +function f2() { +>f2 : Symbol(f2, Decl(constLocalsInFunctionExpressions.ts, 7, 1)) + + const x = getStringOrNumber(); +>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 10, 9)) +>getStringOrNumber : Symbol(getStringOrNumber, Decl(constLocalsInFunctionExpressions.ts, 0, 0)) + + if (typeof x !== "string") { +>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 10, 9)) + + return; + } + const f = () => x.length; +>f : Symbol(f, Decl(constLocalsInFunctionExpressions.ts, 14, 9)) +>x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 10, 9)) +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) +} + +function f3() { +>f3 : Symbol(f3, Decl(constLocalsInFunctionExpressions.ts, 15, 1)) + + const x = getStringOrNumber(); +>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 18, 9)) +>getStringOrNumber : Symbol(getStringOrNumber, Decl(constLocalsInFunctionExpressions.ts, 0, 0)) + + if (typeof x === "string") { +>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 18, 9)) + + const f = function() { return x.length; }; +>f : Symbol(f, Decl(constLocalsInFunctionExpressions.ts, 20, 13)) +>x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 18, 9)) +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) + } +} + +function f4() { +>f4 : Symbol(f4, Decl(constLocalsInFunctionExpressions.ts, 22, 1)) + + const x = getStringOrNumber(); +>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 25, 9)) +>getStringOrNumber : Symbol(getStringOrNumber, Decl(constLocalsInFunctionExpressions.ts, 0, 0)) + + if (typeof x !== "string") { +>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 25, 9)) + + return; + } + const f = function() { return x.length; }; +>f : Symbol(f, Decl(constLocalsInFunctionExpressions.ts, 29, 9)) +>x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 25, 9)) +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) +} + +function f5() { +>f5 : Symbol(f5, Decl(constLocalsInFunctionExpressions.ts, 30, 1)) + + const x = getStringOrNumber(); +>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 33, 9)) +>getStringOrNumber : Symbol(getStringOrNumber, Decl(constLocalsInFunctionExpressions.ts, 0, 0)) + + if (typeof x === "string") { +>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 33, 9)) + + const f = () => () => x.length; +>f : Symbol(f, Decl(constLocalsInFunctionExpressions.ts, 35, 13)) +>x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(constLocalsInFunctionExpressions.ts, 33, 9)) +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) + } +} diff --git a/tests/baselines/reference/constLocalsInFunctionExpressions.types b/tests/baselines/reference/constLocalsInFunctionExpressions.types new file mode 100644 index 00000000000..e9f0086f6b1 --- /dev/null +++ b/tests/baselines/reference/constLocalsInFunctionExpressions.types @@ -0,0 +1,121 @@ +=== tests/cases/conformance/controlFlow/constLocalsInFunctionExpressions.ts === +declare function getStringOrNumber(): string | number; +>getStringOrNumber : () => string | number + +function f1() { +>f1 : () => void + + const x = getStringOrNumber(); +>x : string | number +>getStringOrNumber() : string | number +>getStringOrNumber : () => string | number + + if (typeof x === "string") { +>typeof x === "string" : boolean +>typeof x : string +>x : string | number +>"string" : string + + const f = () => x.length; +>f : () => number +>() => x.length : () => number +>x.length : number +>x : string +>length : number + } +} + +function f2() { +>f2 : () => void + + const x = getStringOrNumber(); +>x : string | number +>getStringOrNumber() : string | number +>getStringOrNumber : () => string | number + + if (typeof x !== "string") { +>typeof x !== "string" : boolean +>typeof x : string +>x : string | number +>"string" : string + + return; + } + const f = () => x.length; +>f : () => number +>() => x.length : () => number +>x.length : number +>x : string +>length : number +} + +function f3() { +>f3 : () => void + + const x = getStringOrNumber(); +>x : string | number +>getStringOrNumber() : string | number +>getStringOrNumber : () => string | number + + if (typeof x === "string") { +>typeof x === "string" : boolean +>typeof x : string +>x : string | number +>"string" : string + + const f = function() { return x.length; }; +>f : () => number +>function() { return x.length; } : () => number +>x.length : number +>x : string +>length : number + } +} + +function f4() { +>f4 : () => void + + const x = getStringOrNumber(); +>x : string | number +>getStringOrNumber() : string | number +>getStringOrNumber : () => string | number + + if (typeof x !== "string") { +>typeof x !== "string" : boolean +>typeof x : string +>x : string | number +>"string" : string + + return; + } + const f = function() { return x.length; }; +>f : () => number +>function() { return x.length; } : () => number +>x.length : number +>x : string +>length : number +} + +function f5() { +>f5 : () => void + + const x = getStringOrNumber(); +>x : string | number +>getStringOrNumber() : string | number +>getStringOrNumber : () => string | number + + if (typeof x === "string") { +>typeof x === "string" : boolean +>typeof x : string +>x : string | number +>"string" : string + + const f = () => () => x.length; +>f : () => () => number +>() => () => x.length : () => () => number +>() => x.length : () => number +>x.length : number +>x : string +>length : number + } +} diff --git a/tests/baselines/reference/controlFlowIIFE.js b/tests/baselines/reference/controlFlowIIFE.js new file mode 100644 index 00000000000..6454d1117db --- /dev/null +++ b/tests/baselines/reference/controlFlowIIFE.js @@ -0,0 +1,87 @@ +//// [controlFlowIIFE.ts] + +declare function getStringOrNumber(): string | number; + +function f1() { + let x = getStringOrNumber(); + if (typeof x === "string") { + let n = function() { + return x.length; + }(); + } +} + +function f2() { + let x = getStringOrNumber(); + if (typeof x === "string") { + let n = (function() { + return x.length; + })(); + } +} + +function f3() { + let x = getStringOrNumber(); + let y: number; + if (typeof x === "string") { + let n = (z => x.length + y + z)(y = 1); + } +} + +// Repros from #8381 + +let maybeNumber: number | undefined; +(function () { + maybeNumber = 1; +})(); +if (maybeNumber !== undefined) { + maybeNumber++; +} + +let test: string | undefined; +if (!test) { + throw new Error('Test is not defined'); +} +(() => { + test.slice(1); // No error +})(); + +//// [controlFlowIIFE.js] +function f1() { + var x = getStringOrNumber(); + if (typeof x === "string") { + var n = function () { + return x.length; + }(); + } +} +function f2() { + var x = getStringOrNumber(); + if (typeof x === "string") { + var n = (function () { + return x.length; + })(); + } +} +function f3() { + var x = getStringOrNumber(); + var y; + if (typeof x === "string") { + var n = (function (z) { return x.length + y + z; })(y = 1); + } +} +// Repros from #8381 +var maybeNumber; +(function () { + maybeNumber = 1; +})(); +if (maybeNumber !== undefined) { + maybeNumber++; +} +var test; +if (!test) { + throw new Error('Test is not defined'); +} +(function () { + test.slice(1); // No error +})(); diff --git a/tests/baselines/reference/controlFlowIIFE.symbols b/tests/baselines/reference/controlFlowIIFE.symbols new file mode 100644 index 00000000000..2a03bb3ff2b --- /dev/null +++ b/tests/baselines/reference/controlFlowIIFE.symbols @@ -0,0 +1,108 @@ +=== tests/cases/conformance/controlFlow/controlFlowIIFE.ts === + +declare function getStringOrNumber(): string | number; +>getStringOrNumber : Symbol(getStringOrNumber, Decl(controlFlowIIFE.ts, 0, 0)) + +function f1() { +>f1 : Symbol(f1, Decl(controlFlowIIFE.ts, 1, 54)) + + let x = getStringOrNumber(); +>x : Symbol(x, Decl(controlFlowIIFE.ts, 4, 7)) +>getStringOrNumber : Symbol(getStringOrNumber, Decl(controlFlowIIFE.ts, 0, 0)) + + if (typeof x === "string") { +>x : Symbol(x, Decl(controlFlowIIFE.ts, 4, 7)) + + let n = function() { +>n : Symbol(n, Decl(controlFlowIIFE.ts, 6, 11)) + + return x.length; +>x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(controlFlowIIFE.ts, 4, 7)) +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) + + }(); + } +} + +function f2() { +>f2 : Symbol(f2, Decl(controlFlowIIFE.ts, 10, 1)) + + let x = getStringOrNumber(); +>x : Symbol(x, Decl(controlFlowIIFE.ts, 13, 7)) +>getStringOrNumber : Symbol(getStringOrNumber, Decl(controlFlowIIFE.ts, 0, 0)) + + if (typeof x === "string") { +>x : Symbol(x, Decl(controlFlowIIFE.ts, 13, 7)) + + let n = (function() { +>n : Symbol(n, Decl(controlFlowIIFE.ts, 15, 11)) + + return x.length; +>x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(controlFlowIIFE.ts, 13, 7)) +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) + + })(); + } +} + +function f3() { +>f3 : Symbol(f3, Decl(controlFlowIIFE.ts, 19, 1)) + + let x = getStringOrNumber(); +>x : Symbol(x, Decl(controlFlowIIFE.ts, 22, 7)) +>getStringOrNumber : Symbol(getStringOrNumber, Decl(controlFlowIIFE.ts, 0, 0)) + + let y: number; +>y : Symbol(y, Decl(controlFlowIIFE.ts, 23, 7)) + + if (typeof x === "string") { +>x : Symbol(x, Decl(controlFlowIIFE.ts, 22, 7)) + + let n = (z => x.length + y + z)(y = 1); +>n : Symbol(n, Decl(controlFlowIIFE.ts, 25, 11)) +>z : Symbol(z, Decl(controlFlowIIFE.ts, 25, 17)) +>x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(controlFlowIIFE.ts, 22, 7)) +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>y : Symbol(y, Decl(controlFlowIIFE.ts, 23, 7)) +>z : Symbol(z, Decl(controlFlowIIFE.ts, 25, 17)) +>y : Symbol(y, Decl(controlFlowIIFE.ts, 23, 7)) + } +} + +// Repros from #8381 + +let maybeNumber: number | undefined; +>maybeNumber : Symbol(maybeNumber, Decl(controlFlowIIFE.ts, 31, 3)) + +(function () { + maybeNumber = 1; +>maybeNumber : Symbol(maybeNumber, Decl(controlFlowIIFE.ts, 31, 3)) + +})(); +if (maybeNumber !== undefined) { +>maybeNumber : Symbol(maybeNumber, Decl(controlFlowIIFE.ts, 31, 3)) +>undefined : Symbol(undefined) + + maybeNumber++; +>maybeNumber : Symbol(maybeNumber, Decl(controlFlowIIFE.ts, 31, 3)) +} + +let test: string | undefined; +>test : Symbol(test, Decl(controlFlowIIFE.ts, 39, 3)) + +if (!test) { +>test : Symbol(test, Decl(controlFlowIIFE.ts, 39, 3)) + + throw new Error('Test is not defined'); +>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +} +(() => { + test.slice(1); // No error +>test.slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) +>test : Symbol(test, Decl(controlFlowIIFE.ts, 39, 3)) +>slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) + +})(); diff --git a/tests/baselines/reference/controlFlowIIFE.types b/tests/baselines/reference/controlFlowIIFE.types new file mode 100644 index 00000000000..0a6ad5da02f --- /dev/null +++ b/tests/baselines/reference/controlFlowIIFE.types @@ -0,0 +1,149 @@ +=== tests/cases/conformance/controlFlow/controlFlowIIFE.ts === + +declare function getStringOrNumber(): string | number; +>getStringOrNumber : () => string | number + +function f1() { +>f1 : () => void + + let x = getStringOrNumber(); +>x : string | number +>getStringOrNumber() : string | number +>getStringOrNumber : () => string | number + + if (typeof x === "string") { +>typeof x === "string" : boolean +>typeof x : string +>x : string | number +>"string" : string + + let n = function() { +>n : number +>function() { return x.length; }() : number +>function() { return x.length; } : () => number + + return x.length; +>x.length : number +>x : string +>length : number + + }(); + } +} + +function f2() { +>f2 : () => void + + let x = getStringOrNumber(); +>x : string | number +>getStringOrNumber() : string | number +>getStringOrNumber : () => string | number + + if (typeof x === "string") { +>typeof x === "string" : boolean +>typeof x : string +>x : string | number +>"string" : string + + let n = (function() { +>n : number +>(function() { return x.length; })() : number +>(function() { return x.length; }) : () => number +>function() { return x.length; } : () => number + + return x.length; +>x.length : number +>x : string +>length : number + + })(); + } +} + +function f3() { +>f3 : () => void + + let x = getStringOrNumber(); +>x : string | number +>getStringOrNumber() : string | number +>getStringOrNumber : () => string | number + + let y: number; +>y : number + + if (typeof x === "string") { +>typeof x === "string" : boolean +>typeof x : string +>x : string | number +>"string" : string + + let n = (z => x.length + y + z)(y = 1); +>n : number +>(z => x.length + y + z)(y = 1) : number +>(z => x.length + y + z) : (z: number) => number +>z => x.length + y + z : (z: number) => number +>z : number +>x.length + y + z : number +>x.length + y : number +>x.length : number +>x : string +>length : number +>y : number +>z : number +>y = 1 : number +>y : number +>1 : number + } +} + +// Repros from #8381 + +let maybeNumber: number | undefined; +>maybeNumber : number | undefined + +(function () { +>(function () { maybeNumber = 1;})() : void +>(function () { maybeNumber = 1;}) : () => void +>function () { maybeNumber = 1;} : () => void + + maybeNumber = 1; +>maybeNumber = 1 : number +>maybeNumber : number | undefined +>1 : number + +})(); +if (maybeNumber !== undefined) { +>maybeNumber !== undefined : boolean +>maybeNumber : number | undefined +>undefined : undefined + + maybeNumber++; +>maybeNumber++ : number +>maybeNumber : number +} + +let test: string | undefined; +>test : string | undefined + +if (!test) { +>!test : boolean +>test : string | undefined + + throw new Error('Test is not defined'); +>new Error('Test is not defined') : Error +>Error : ErrorConstructor +>'Test is not defined' : string +} +(() => { +>(() => { test.slice(1); // No error})() : void +>(() => { test.slice(1); // No error}) : () => void +>() => { test.slice(1); // No error} : () => void + + test.slice(1); // No error +>test.slice(1) : string +>test.slice : (start?: number | undefined, end?: number | undefined) => string +>test : string +>slice : (start?: number | undefined, end?: number | undefined) => string +>1 : number + +})(); diff --git a/tests/cases/conformance/controlFlow/constLocalsInFunctionExpressions.ts b/tests/cases/conformance/controlFlow/constLocalsInFunctionExpressions.ts new file mode 100644 index 00000000000..69b19fcb307 --- /dev/null +++ b/tests/cases/conformance/controlFlow/constLocalsInFunctionExpressions.ts @@ -0,0 +1,38 @@ +declare function getStringOrNumber(): string | number; + +function f1() { + const x = getStringOrNumber(); + if (typeof x === "string") { + const f = () => x.length; + } +} + +function f2() { + const x = getStringOrNumber(); + if (typeof x !== "string") { + return; + } + const f = () => x.length; +} + +function f3() { + const x = getStringOrNumber(); + if (typeof x === "string") { + const f = function() { return x.length; }; + } +} + +function f4() { + const x = getStringOrNumber(); + if (typeof x !== "string") { + return; + } + const f = function() { return x.length; }; +} + +function f5() { + const x = getStringOrNumber(); + if (typeof x === "string") { + const f = () => () => x.length; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/controlFlow/controlFlowIIFE.ts b/tests/cases/conformance/controlFlow/controlFlowIIFE.ts new file mode 100644 index 00000000000..e703fb2fdff --- /dev/null +++ b/tests/cases/conformance/controlFlow/controlFlowIIFE.ts @@ -0,0 +1,47 @@ +// @strictNullChecks: true + +declare function getStringOrNumber(): string | number; + +function f1() { + let x = getStringOrNumber(); + if (typeof x === "string") { + let n = function() { + return x.length; + }(); + } +} + +function f2() { + let x = getStringOrNumber(); + if (typeof x === "string") { + let n = (function() { + return x.length; + })(); + } +} + +function f3() { + let x = getStringOrNumber(); + let y: number; + if (typeof x === "string") { + let n = (z => x.length + y + z)(y = 1); + } +} + +// Repros from #8381 + +let maybeNumber: number | undefined; +(function () { + maybeNumber = 1; +})(); +if (maybeNumber !== undefined) { + maybeNumber++; +} + +let test: string | undefined; +if (!test) { + throw new Error('Test is not defined'); +} +(() => { + test.slice(1); // No error +})(); \ No newline at end of file From 1647d20d90e0cc68a2714abeb7a1e81bb32c2b17 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 26 May 2016 16:50:36 -0700 Subject: [PATCH 44/61] Fix linting errors --- src/compiler/checker.ts | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c14a7e26add..58aaae9f72b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7695,11 +7695,11 @@ namespace ts { getTypeAtFlowLoopLabel(flow); } else if (flow.flags & FlowFlags.Start) { - let container = (flow).container; + const container = (flow).container; if (container) { // If container is an IIFE continue with the control flow associated with the // call expression node. - let iife = getImmediatelyInvokedFunctionExpression(container); + const iife = getImmediatelyInvokedFunctionExpression(container); if (iife && iife.flowNode) { flow = iife.flowNode; continue; @@ -8086,16 +8086,6 @@ namespace ts { return expression; } - function getControlFlowContainer(node: Identifier, declarationContainer: Node, skipFunctionExpressions: boolean) { - let container = getContainingFunctionOrModule(node); - while (container !== declarationContainer && - (container.kind === SyntaxKind.FunctionExpression || container.kind === SyntaxKind.ArrowFunction) && - (skipFunctionExpressions || getImmediatelyInvokedFunctionExpression(container))) { - container = getContainingFunctionOrModule(container); - } - return container; - } - function isDeclarationIncludedInFlow(reference: Node, declaration: Declaration, includeOuterFunctions: boolean) { const declarationContainer = getContainingFunctionOrModule(declaration); let container = getContainingFunctionOrModule(reference); From b2664e7f842fe838e4a96564651b0fab723207ee Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Fri, 27 May 2016 06:12:10 -0700 Subject: [PATCH 45/61] Use a JSON.stringify replacer function instead of changing the value beforehand --- src/harness/fourslash.ts | 52 ++++++------------- .../fourslash/deleteClassWithEnumPresent.ts | 3 +- .../cases/fourslash/getNavigationBarItems.ts | 3 +- tests/cases/fourslash/navbar_const.ts | 3 +- .../navbar_contains-no-duplicates.ts | 3 +- tests/cases/fourslash/navbar_exportDefault.ts | 16 ++---- tests/cases/fourslash/navbar_let.ts | 3 +- .../navigationBarItemsBindingPatterns.ts | 3 +- ...ionBarItemsBindingPatternsInConstructor.ts | 3 +- .../navigationBarItemsEmptyConstructors.ts | 3 +- .../fourslash/navigationBarItemsExports.ts | 3 +- .../fourslash/navigationBarItemsFunctions.ts | 4 +- .../navigationBarItemsFunctionsBroken.ts | 4 +- .../navigationBarItemsFunctionsBroken2.ts | 4 +- .../fourslash/navigationBarItemsImports.ts | 3 +- ...ionBarItemsInsideMethodsAndConstructors.ts | 6 +-- .../fourslash/navigationBarItemsItems.ts | 3 +- .../fourslash/navigationBarItemsItems2.ts | 5 +- ...rItemsItemsContainsNoAnonymousFunctions.ts | 12 ++--- .../navigationBarItemsItemsExternalModules.ts | 3 +- ...navigationBarItemsItemsExternalModules2.ts | 3 +- ...navigationBarItemsItemsExternalModules3.ts | 3 +- .../navigationBarItemsItemsModuleVariables.ts | 6 +-- .../navigationBarItemsMissingName1.ts | 3 +- .../navigationBarItemsMissingName2.ts | 4 +- .../fourslash/navigationBarItemsModules.ts | 5 +- ...ationBarItemsMultilineStringIdentifiers.ts | 6 +-- ...BarItemsPropertiesDefinedInConstructors.ts | 3 +- .../fourslash/navigationBarItemsSymbols1.ts | 3 +- .../fourslash/navigationBarItemsSymbols2.ts | 3 +- .../fourslash/navigationBarItemsSymbols3.ts | 4 +- .../fourslash/navigationBarItemsTypeAlias.ts | 4 +- tests/cases/fourslash/server/navbar01.ts | 15 ++---- .../shims-pp/getNavigationBarItems.ts | 3 +- .../fourslash/shims/getNavigationBarItems.ts | 3 +- 35 files changed, 58 insertions(+), 149 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 53aaa8c7d6e..4a756ab3b1e 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1960,46 +1960,24 @@ namespace FourSlash { } public verifyNavigationBar(json: any) { - let items = this.languageService.getNavigationBarItems(this.activeFile.fileName); - items = this.simplifyNavigationBar(items); - if (JSON.stringify(items) !== JSON.stringify(json)) { - this.raiseError(`verifyNavigationBar failed - expected: ${JSON.stringify(json, undefined, 2)}, got: ${JSON.stringify(items, undefined, 2)}`); + const items = this.languageService.getNavigationBarItems(this.activeFile.fileName); + if (JSON.stringify(items, replacer) !== JSON.stringify(json)) { + this.raiseError(`verifyNavigationBar failed - expected: ${JSON.stringify(json, undefined, 2)}, got: ${JSON.stringify(items, replacer, 2)}`); } - } - // Remove any properties that tend to all have the same value so that test data is easier to read. - private simplifyNavigationBar(items: ts.NavigationBarItem[]): any { - return items.map(item => { - item = ts.clone(item); - if (item.kindModifiers === "") { - delete item.kindModifiers; + // Make the data easier to read. + function replacer(key: string, value: any) { + switch (key) { + case "spans": + // We won't ever check this. + return undefined; + case "childItems": + return value.length === 0 ? undefined : value; + default: + // Omit falsy values, those are presumed to be the default. + return value || undefined; } - // We won't check this. - delete item.spans; - item.childItems = item.childItems.map(child => { - child = ts.clone(child); - delete child.spans; - ts.Debug.assert(child.childItems.length === 0); - delete child.childItems; - ts.Debug.assert(child.indent === 0); - delete child.indent; - ts.Debug.assert(child.bolded === false); - delete child.bolded; - ts.Debug.assert(child.grayed === false); - delete child.grayed; - if (child.kindModifiers === "") { - delete child.kindModifiers; - } - return child; - }); - if (item.bolded === false) { - delete item.bolded; - } - if (item.grayed === false) { - delete item.grayed; - } - return item; - }); + } } public printNavigationItems(searchValue: string) { diff --git a/tests/cases/fourslash/deleteClassWithEnumPresent.ts b/tests/cases/fourslash/deleteClassWithEnumPresent.ts index d8d4478afe7..17d2adae0b1 100644 --- a/tests/cases/fourslash/deleteClassWithEnumPresent.ts +++ b/tests/cases/fourslash/deleteClassWithEnumPresent.ts @@ -14,8 +14,7 @@ verify.navigationBar([ "text": "Foo", "kind": "enum" } - ], - "indent": 0 + ] }, { "text": "Foo", diff --git a/tests/cases/fourslash/getNavigationBarItems.ts b/tests/cases/fourslash/getNavigationBarItems.ts index a2b0492514a..c3b519fe114 100644 --- a/tests/cases/fourslash/getNavigationBarItems.ts +++ b/tests/cases/fourslash/getNavigationBarItems.ts @@ -14,8 +14,7 @@ verify.navigationBar([ "text": "C", "kind": "class" } - ], - "indent": 0 + ] }, { "text": "C", diff --git a/tests/cases/fourslash/navbar_const.ts b/tests/cases/fourslash/navbar_const.ts index 02a10f46a74..6ec594a2873 100644 --- a/tests/cases/fourslash/navbar_const.ts +++ b/tests/cases/fourslash/navbar_const.ts @@ -11,7 +11,6 @@ verify.navigationBar([ "text": "c", "kind": "const" } - ], - "indent": 0 + ] } ]); diff --git a/tests/cases/fourslash/navbar_contains-no-duplicates.ts b/tests/cases/fourslash/navbar_contains-no-duplicates.ts index 333130ff795..e259a7bef90 100644 --- a/tests/cases/fourslash/navbar_contains-no-duplicates.ts +++ b/tests/cases/fourslash/navbar_contains-no-duplicates.ts @@ -45,8 +45,7 @@ verify.navigationBar([ "kind": "module", "kindModifiers": "declare" } - ], - "indent": 0 + ] }, { "text": "ABC", diff --git a/tests/cases/fourslash/navbar_exportDefault.ts b/tests/cases/fourslash/navbar_exportDefault.ts index 7c666589f12..dc99cff7d64 100644 --- a/tests/cases/fourslash/navbar_exportDefault.ts +++ b/tests/cases/fourslash/navbar_exportDefault.ts @@ -16,15 +16,12 @@ goTo.file("a.ts"); verify.navigationBar([ { "text": "\"a\"", - "kind": "module", - "childItems": [], - "indent": 0 + "kind": "module" }, { "text": "default", "kind": "class", "kindModifiers": "export", - "childItems": [], "indent": 1 } ]); @@ -40,14 +37,12 @@ verify.navigationBar([ "kind": "class", "kindModifiers": "export" } - ], - "indent": 0 + ] }, { "text": "C", "kind": "class", "kindModifiers": "export", - "childItems": [], "indent": 1 } ]); @@ -57,14 +52,11 @@ verify.navigationBar([ { "text": "\"c\"", "kind": "module", - "childItems": [], - "indent": 0 }, { "text": "default", "kind": "function", "kindModifiers": "export", - "childItems": [], "indent": 1 } ]); @@ -80,14 +72,12 @@ verify.navigationBar([ "kind": "function", "kindModifiers": "export" } - ], - "indent": 0 + ] }, { "text": "Func", "kind": "function", "kindModifiers": "export", - "childItems": [], "indent": 1 } ]); diff --git a/tests/cases/fourslash/navbar_let.ts b/tests/cases/fourslash/navbar_let.ts index dc9d9c07857..7ccd61cdfd6 100644 --- a/tests/cases/fourslash/navbar_let.ts +++ b/tests/cases/fourslash/navbar_let.ts @@ -11,7 +11,6 @@ verify.navigationBar([ "text": "c", "kind": "let" } - ], - "indent": 0 + ] } ]); diff --git a/tests/cases/fourslash/navigationBarItemsBindingPatterns.ts b/tests/cases/fourslash/navigationBarItemsBindingPatterns.ts index 007a9c9b804..849f918f473 100644 --- a/tests/cases/fourslash/navigationBarItemsBindingPatterns.ts +++ b/tests/cases/fourslash/navigationBarItemsBindingPatterns.ts @@ -55,7 +55,6 @@ verify.navigationBar([ "text": "g", "kind": "var" } - ], - "indent": 0 + ] } ]); diff --git a/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts b/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts index 41751f5c74b..0ae3e692aa1 100644 --- a/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts +++ b/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts @@ -24,8 +24,7 @@ verify.navigationBar([ "text": "B", "kind": "class" } - ], - "indent": 0 + ] }, { "text": "A", diff --git a/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts b/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts index 27c33f6afb2..fd534f4c6db 100644 --- a/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts +++ b/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts @@ -14,8 +14,7 @@ verify.navigationBar([ "text": "Test", "kind": "class" } - ], - "indent": 0 + ] }, { "text": "Test", diff --git a/tests/cases/fourslash/navigationBarItemsExports.ts b/tests/cases/fourslash/navigationBarItemsExports.ts index 79422f96274..3ec9b0a7138 100644 --- a/tests/cases/fourslash/navigationBarItemsExports.ts +++ b/tests/cases/fourslash/navigationBarItemsExports.ts @@ -27,7 +27,6 @@ verify.navigationBar([ "kind": "alias", "kindModifiers": "export" } - ], - "indent": 0 + ] } ]); diff --git a/tests/cases/fourslash/navigationBarItemsFunctions.ts b/tests/cases/fourslash/navigationBarItemsFunctions.ts index e2260f2ff2b..91546462a25 100644 --- a/tests/cases/fourslash/navigationBarItemsFunctions.ts +++ b/tests/cases/fourslash/navigationBarItemsFunctions.ts @@ -27,13 +27,11 @@ verify.navigationBar([ "text": "foo", "kind": "function" } - ], - "indent": 0 + ] }, { "text": "baz", "kind": "function", - "childItems": [], "indent": 1 }, { diff --git a/tests/cases/fourslash/navigationBarItemsFunctionsBroken.ts b/tests/cases/fourslash/navigationBarItemsFunctionsBroken.ts index dc84b50ff30..96dcbb944ae 100644 --- a/tests/cases/fourslash/navigationBarItemsFunctionsBroken.ts +++ b/tests/cases/fourslash/navigationBarItemsFunctionsBroken.ts @@ -13,13 +13,11 @@ verify.navigationBar([ "text": "f", "kind": "function" } - ], - "indent": 0 + ] }, { "text": "f", "kind": "function", - "childItems": [], "indent": 1 } ]); diff --git a/tests/cases/fourslash/navigationBarItemsFunctionsBroken2.ts b/tests/cases/fourslash/navigationBarItemsFunctionsBroken2.ts index b4612efcac0..127bde8c9e7 100644 --- a/tests/cases/fourslash/navigationBarItemsFunctionsBroken2.ts +++ b/tests/cases/fourslash/navigationBarItemsFunctionsBroken2.ts @@ -14,13 +14,11 @@ verify.navigationBar([ "text": "f", "kind": "function" } - ], - "indent": 0 + ] }, { "text": "f", "kind": "function", - "childItems": [], "indent": 1 } ]); diff --git a/tests/cases/fourslash/navigationBarItemsImports.ts b/tests/cases/fourslash/navigationBarItemsImports.ts index d6526a7a68c..ed398ec7f1d 100644 --- a/tests/cases/fourslash/navigationBarItemsImports.ts +++ b/tests/cases/fourslash/navigationBarItemsImports.ts @@ -51,7 +51,6 @@ verify.navigationBar([ "text": "ns", "kind": "alias" } - ], - "indent": 0 + ] } ]); diff --git a/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts b/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts index 7d2fb4ed127..28ec25c6f1d 100644 --- a/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts +++ b/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts @@ -27,8 +27,7 @@ verify.navigationBar([ "text": "Class", "kind": "class" } - ], - "indent": 0 + ] }, { "text": "Class", @@ -82,13 +81,11 @@ verify.navigationBar([ { "text": "LocalFunctionInConstructor", "kind": "function", - "childItems": [], "indent": 2 }, { "text": "LocalInterfaceInConstrcutor", "kind": "interface", - "childItems": [], "indent": 2 }, { @@ -135,7 +132,6 @@ verify.navigationBar([ { "text": "LocalInterfaceInMethod", "kind": "interface", - "childItems": [], "indent": 2 } ]); diff --git a/tests/cases/fourslash/navigationBarItemsItems.ts b/tests/cases/fourslash/navigationBarItemsItems.ts index 013d28cd402..87da8581734 100644 --- a/tests/cases/fourslash/navigationBarItemsItems.ts +++ b/tests/cases/fourslash/navigationBarItemsItems.ts @@ -60,8 +60,7 @@ verify.navigationBar([ "text": "Shapes", "kind": "module" } - ], - "indent": 0 + ] }, { "text": "IPoint", diff --git a/tests/cases/fourslash/navigationBarItemsItems2.ts b/tests/cases/fourslash/navigationBarItemsItems2.ts index 27c32531d6b..762531d8778 100644 --- a/tests/cases/fourslash/navigationBarItemsItems2.ts +++ b/tests/cases/fourslash/navigationBarItemsItems2.ts @@ -16,20 +16,17 @@ verify.navigationBar([ "text": "A", "kind": "module" } - ], - "indent": 0 + ] }, { "text": "default", "kind": "class", "kindModifiers": "export", - "childItems": [], "indent": 1 }, { "text": "A", "kind": "module", - "childItems": [], "indent": 1 } ]); diff --git a/tests/cases/fourslash/navigationBarItemsItemsContainsNoAnonymousFunctions.ts b/tests/cases/fourslash/navigationBarItemsItemsContainsNoAnonymousFunctions.ts index 34e4a1c0c89..276e19624c9 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsContainsNoAnonymousFunctions.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsContainsNoAnonymousFunctions.ts @@ -33,9 +33,7 @@ goTo.marker("file1"); verify.navigationBar([ { "text": "", - "kind": "module", - "childItems": [], - "indent": 0 + "kind": "module" } ]); @@ -49,8 +47,7 @@ verify.navigationBar([ "text": "x", "kind": "var" } - ], - "indent": 0 + ] } ]); @@ -68,19 +65,16 @@ verify.navigationBar([ "text": "foo", "kind": "function" } - ], - "indent": 0 + ] }, { "text": "bar", "kind": "function", - "childItems": [], "indent": 1 }, { "text": "foo", "kind": "function", - "childItems": [], "indent": 1 } ]); diff --git a/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts index f2df772fb19..04091185dd0 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts @@ -14,8 +14,7 @@ verify.navigationBar([ "kind": "class", "kindModifiers": "export" } - ], - "indent": 0 + ] }, { "text": "Bar", diff --git a/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts index 54d4759afe6..4939091d944 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts @@ -21,8 +21,7 @@ verify.navigationBar([ "kind": "var", "kindModifiers": "export" } - ], - "indent": 0 + ] }, { "text": "Bar", diff --git a/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts index 2db04c980d2..5ee760fabc6 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts @@ -21,8 +21,7 @@ verify.navigationBar([ "kind": "var", "kindModifiers": "export" } - ], - "indent": 0 + ] }, { "text": "Bar", diff --git a/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts b/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts index ef4022ce046..6b85d481612 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts @@ -29,8 +29,7 @@ verify.navigationBar([ "text": "Module1", "kind": "module" } - ], - "indent": 0 + ] }, { "text": "Module1", @@ -56,8 +55,7 @@ verify.navigationBar([ "text": "Module1.SubModule", "kind": "module" } - ], - "indent": 0 + ] }, { "text": "Module1.SubModule", diff --git a/tests/cases/fourslash/navigationBarItemsMissingName1.ts b/tests/cases/fourslash/navigationBarItemsMissingName1.ts index 4738cc45063..af0e89683bc 100644 --- a/tests/cases/fourslash/navigationBarItemsMissingName1.ts +++ b/tests/cases/fourslash/navigationBarItemsMissingName1.ts @@ -12,8 +12,7 @@ verify.navigationBar([ "text": "C", "kind": "class" } - ], - "indent": 0 + ] }, { "text": "C", diff --git a/tests/cases/fourslash/navigationBarItemsMissingName2.ts b/tests/cases/fourslash/navigationBarItemsMissingName2.ts index f4a37cf1154..2eda3b07855 100644 --- a/tests/cases/fourslash/navigationBarItemsMissingName2.ts +++ b/tests/cases/fourslash/navigationBarItemsMissingName2.ts @@ -9,9 +9,7 @@ verify.navigationBar([ { "text": "", - "kind": "module", - "childItems": [], - "indent": 0 + "kind": "module" }, { "text": "default", diff --git a/tests/cases/fourslash/navigationBarItemsModules.ts b/tests/cases/fourslash/navigationBarItemsModules.ts index c3b8aef08eb..979f22084e5 100644 --- a/tests/cases/fourslash/navigationBarItemsModules.ts +++ b/tests/cases/fourslash/navigationBarItemsModules.ts @@ -54,8 +54,7 @@ verify.navigationBar([ "kind": "module", "kindModifiers": "declare" } - ], - "indent": 0 + ] }, { "text": "A.B.C", @@ -124,14 +123,12 @@ verify.navigationBar([ "text": "\"X.Y.Z\"", "kind": "module", "kindModifiers": "declare", - "childItems": [], "indent": 1 }, { "text": "'X2.Y2.Z2'", "kind": "module", "kindModifiers": "declare", - "childItems": [], "indent": 1 } ]); diff --git a/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts b/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts index c2e43f5f7b7..2ee4c93a2f1 100644 --- a/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts +++ b/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts @@ -52,8 +52,7 @@ verify.navigationBar([ "kind": "module", "kindModifiers": "declare" } - ], - "indent": 0 + ] }, { "text": "Bar", @@ -89,21 +88,18 @@ verify.navigationBar([ "text": "\"Multiline\\r\\nMadness\"", "kind": "module", "kindModifiers": "declare", - "childItems": [], "indent": 1 }, { "text": "\"Multiline\\\nMadness\"", "kind": "module", "kindModifiers": "declare", - "childItems": [], "indent": 1 }, { "text": "\"MultilineMadness\"", "kind": "module", "kindModifiers": "declare", - "childItems": [], "indent": 1 } ]); diff --git a/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts b/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts index d99d3bce9eb..9e5a48370c1 100644 --- a/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts +++ b/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts @@ -15,8 +15,7 @@ verify.navigationBar([ "text": "List", "kind": "class" } - ], - "indent": 0 + ] }, { "text": "List", diff --git a/tests/cases/fourslash/navigationBarItemsSymbols1.ts b/tests/cases/fourslash/navigationBarItemsSymbols1.ts index 8c565447c19..53f4c7af445 100644 --- a/tests/cases/fourslash/navigationBarItemsSymbols1.ts +++ b/tests/cases/fourslash/navigationBarItemsSymbols1.ts @@ -15,8 +15,7 @@ verify.navigationBar([ "text": "C", "kind": "class" } - ], - "indent": 0 + ] }, { "text": "C", diff --git a/tests/cases/fourslash/navigationBarItemsSymbols2.ts b/tests/cases/fourslash/navigationBarItemsSymbols2.ts index d747b5dadaa..2674047f9c0 100644 --- a/tests/cases/fourslash/navigationBarItemsSymbols2.ts +++ b/tests/cases/fourslash/navigationBarItemsSymbols2.ts @@ -14,8 +14,7 @@ verify.navigationBar([ "text": "I", "kind": "interface" } - ], - "indent": 0 + ] }, { "text": "I", diff --git a/tests/cases/fourslash/navigationBarItemsSymbols3.ts b/tests/cases/fourslash/navigationBarItemsSymbols3.ts index 29ff9f277a3..9564c496dd8 100644 --- a/tests/cases/fourslash/navigationBarItemsSymbols3.ts +++ b/tests/cases/fourslash/navigationBarItemsSymbols3.ts @@ -14,13 +14,11 @@ verify.navigationBar([ "text": "E", "kind": "enum" } - ], - "indent": 0 + ] }, { "text": "E", "kind": "enum", - "childItems": [], "indent": 1 } ]); diff --git a/tests/cases/fourslash/navigationBarItemsTypeAlias.ts b/tests/cases/fourslash/navigationBarItemsTypeAlias.ts index 4973e84b2ed..8ff9854ac16 100644 --- a/tests/cases/fourslash/navigationBarItemsTypeAlias.ts +++ b/tests/cases/fourslash/navigationBarItemsTypeAlias.ts @@ -11,13 +11,11 @@ verify.navigationBar([ "text": "T", "kind": "type" } - ], - "indent": 0 + ] }, { "text": "T", "kind": "type", - "childItems": [], "indent": 1 } ]); diff --git a/tests/cases/fourslash/server/navbar01.ts b/tests/cases/fourslash/server/navbar01.ts index ed8ed2d8563..7f2229fcb81 100644 --- a/tests/cases/fourslash/server/navbar01.ts +++ b/tests/cases/fourslash/server/navbar01.ts @@ -59,8 +59,7 @@ verify.navigationBar([ "text": "Shapes", "kind": "module" } - ], - "indent": 0 + ] }, { "text": "IPoint", @@ -86,8 +85,7 @@ verify.navigationBar([ "text": "prop", "kind": "property" } - ], - "indent": 0 + ] }, { "text": "Shapes", @@ -102,8 +100,7 @@ verify.navigationBar([ "text": "Values", "kind": "enum" } - ], - "indent": 0 + ] }, { "text": "Point", @@ -146,8 +143,7 @@ verify.navigationBar([ "kind": "property", "kindModifiers": "public" } - ], - "indent": 0 + ] }, { "text": "Values", @@ -165,7 +161,6 @@ verify.navigationBar([ "text": "value3", "kind": "property" } - ], - "indent": 0 + ] } ]); diff --git a/tests/cases/fourslash/shims-pp/getNavigationBarItems.ts b/tests/cases/fourslash/shims-pp/getNavigationBarItems.ts index fe852e03a28..b06d782d8bf 100644 --- a/tests/cases/fourslash/shims-pp/getNavigationBarItems.ts +++ b/tests/cases/fourslash/shims-pp/getNavigationBarItems.ts @@ -11,7 +11,6 @@ verify.navigationBar([ "text": "c", "kind": "const" } - ], - "indent": 0 + ] } ]); diff --git a/tests/cases/fourslash/shims/getNavigationBarItems.ts b/tests/cases/fourslash/shims/getNavigationBarItems.ts index fe852e03a28..b06d782d8bf 100644 --- a/tests/cases/fourslash/shims/getNavigationBarItems.ts +++ b/tests/cases/fourslash/shims/getNavigationBarItems.ts @@ -11,7 +11,6 @@ verify.navigationBar([ "text": "c", "kind": "const" } - ], - "indent": 0 + ] } ]); From eab25119898cde36f1e7c1bc8e35a1aa52696b5c Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 27 May 2016 09:51:30 -0700 Subject: [PATCH 46/61] update signature of finishWorker --- Jakefile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jakefile.js b/Jakefile.js index f0415635956..474303a9722 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -759,7 +759,7 @@ function runConsoleTests(defaultReporter, runInParallel) { exec(workerCmd, finishWorker, finishWorker) }); - function finishWorker(errorStatus) { + function finishWorker(e, errorStatus) { counter--; if (firstErrorStatus === undefined && errorStatus !== undefined) { firstErrorStatus = errorStatus; From f3d1b46dcba63bf70900c9ca607bb1aabf0047dd Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Fri, 27 May 2016 10:40:28 -0700 Subject: [PATCH 47/61] Add tests for private and readonly parameter properties in navbar --- .../navigationBarItemsPropertiesDefinedInConstructors.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts b/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts index 9e5a48370c1..0ea7a0745c2 100644 --- a/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts +++ b/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts @@ -1,7 +1,7 @@ /// ////class List { -//// constructor(public a: boolean, public b: T, c: number) { +//// constructor(public a: boolean, private b: T, readonly c: string, d: number) { //// var local = 0; //// } ////} @@ -33,7 +33,11 @@ verify.navigationBar([ { "text": "b", "kind": "property", - "kindModifiers": "public" + "kindModifiers": "private" + }, + { + "text": "c", + "kind": "property" } ], "indent": 1 From 92938cd8df88dd89b2cd0791084e0b7fb871a4c9 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 27 May 2016 15:38:59 -0700 Subject: [PATCH 48/61] check that default clause is non-empty in reachability checks --- src/compiler/binder.ts | 4 ++-- .../reachabilityCheckWithEmptyDefault.js | 18 +++++++++++++++ .../reachabilityCheckWithEmptyDefault.symbols | 18 +++++++++++++++ .../reachabilityCheckWithEmptyDefault.types | 22 +++++++++++++++++++ .../reachabilityCheckWithEmptyDefault.ts | 8 +++++++ 5 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/reachabilityCheckWithEmptyDefault.js create mode 100644 tests/baselines/reference/reachabilityCheckWithEmptyDefault.symbols create mode 100644 tests/baselines/reference/reachabilityCheckWithEmptyDefault.types create mode 100644 tests/cases/compiler/reachabilityCheckWithEmptyDefault.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 6f0f1ac7863..fef23770475 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -912,8 +912,8 @@ namespace ts { preSwitchCaseFlow = currentFlow; bind(node.caseBlock); addAntecedent(postSwitchLabel, currentFlow); - const hasDefault = forEach(node.caseBlock.clauses, c => c.kind === SyntaxKind.DefaultClause); - if (!hasDefault) { + const hasNonEmptyDefault = forEach(node.caseBlock.clauses, c => c.kind === SyntaxKind.DefaultClause && c.statements.length); + if (!hasNonEmptyDefault) { addAntecedent(postSwitchLabel, preSwitchCaseFlow); } currentBreakTarget = saveBreakTarget; diff --git a/tests/baselines/reference/reachabilityCheckWithEmptyDefault.js b/tests/baselines/reference/reachabilityCheckWithEmptyDefault.js new file mode 100644 index 00000000000..0096d2d2f9a --- /dev/null +++ b/tests/baselines/reference/reachabilityCheckWithEmptyDefault.js @@ -0,0 +1,18 @@ +//// [reachabilityCheckWithEmptyDefault.ts] +declare function print(s: string): void; +function foo(x: any) { + switch(x) { + case 1: return; + default: + } + print('1'); +} + +//// [reachabilityCheckWithEmptyDefault.js] +function foo(x) { + switch (x) { + case 1: return; + default: + } + print('1'); +} diff --git a/tests/baselines/reference/reachabilityCheckWithEmptyDefault.symbols b/tests/baselines/reference/reachabilityCheckWithEmptyDefault.symbols new file mode 100644 index 00000000000..d3123c0e8ba --- /dev/null +++ b/tests/baselines/reference/reachabilityCheckWithEmptyDefault.symbols @@ -0,0 +1,18 @@ +=== tests/cases/compiler/reachabilityCheckWithEmptyDefault.ts === +declare function print(s: string): void; +>print : Symbol(print, Decl(reachabilityCheckWithEmptyDefault.ts, 0, 0)) +>s : Symbol(s, Decl(reachabilityCheckWithEmptyDefault.ts, 0, 23)) + +function foo(x: any) { +>foo : Symbol(foo, Decl(reachabilityCheckWithEmptyDefault.ts, 0, 40)) +>x : Symbol(x, Decl(reachabilityCheckWithEmptyDefault.ts, 1, 13)) + + switch(x) { +>x : Symbol(x, Decl(reachabilityCheckWithEmptyDefault.ts, 1, 13)) + + case 1: return; + default: + } + print('1'); +>print : Symbol(print, Decl(reachabilityCheckWithEmptyDefault.ts, 0, 0)) +} diff --git a/tests/baselines/reference/reachabilityCheckWithEmptyDefault.types b/tests/baselines/reference/reachabilityCheckWithEmptyDefault.types new file mode 100644 index 00000000000..3d01b876473 --- /dev/null +++ b/tests/baselines/reference/reachabilityCheckWithEmptyDefault.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/reachabilityCheckWithEmptyDefault.ts === +declare function print(s: string): void; +>print : (s: string) => void +>s : string + +function foo(x: any) { +>foo : (x: any) => void +>x : any + + switch(x) { +>x : any + + case 1: return; +>1 : number + + default: + } + print('1'); +>print('1') : void +>print : (s: string) => void +>'1' : string +} diff --git a/tests/cases/compiler/reachabilityCheckWithEmptyDefault.ts b/tests/cases/compiler/reachabilityCheckWithEmptyDefault.ts new file mode 100644 index 00000000000..6429528a0da --- /dev/null +++ b/tests/cases/compiler/reachabilityCheckWithEmptyDefault.ts @@ -0,0 +1,8 @@ +declare function print(s: string): void; +function foo(x: any) { + switch(x) { + case 1: return; + default: + } + print('1'); +} \ No newline at end of file From e8ecf0e615ca552b7355740cd91cae6f8ed7b74e Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 28 May 2016 06:43:28 -0700 Subject: [PATCH 49/61] Track return statements in IIFE using a flow label --- src/compiler/binder.ts | 83 +++++++++++++++++++++++++-------------- src/compiler/checker.ts | 63 ++++++++++------------------- src/compiler/types.ts | 1 + src/compiler/utilities.ts | 14 +++++++ 4 files changed, 89 insertions(+), 72 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 2476709b501..93417493fa7 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -104,14 +104,15 @@ namespace ts { let seenThisKeyword: boolean; // state used by reachability checks - let hasExplicitReturn: boolean; let currentFlow: FlowNode; let currentBreakTarget: FlowLabel; let currentContinueTarget: FlowLabel; + let currentReturnTarget: FlowLabel; let currentTrueTarget: FlowLabel; let currentFalseTarget: FlowLabel; let preSwitchCaseFlow: FlowNode; let activeLabels: ActiveLabel[]; + let hasExplicitReturn: boolean; // state used for emit helpers let hasClassExtends: boolean; @@ -156,13 +157,14 @@ namespace ts { blockScopeContainer = undefined; lastContainer = undefined; seenThisKeyword = false; - hasExplicitReturn = false; currentFlow = undefined; currentBreakTarget = undefined; currentContinueTarget = undefined; + currentReturnTarget = undefined; currentTrueTarget = undefined; currentFalseTarget = undefined; activeLabels = undefined; + hasExplicitReturn = false; hasClassExtends = false; hasAsyncFunctions = false; hasDecorators = false; @@ -443,20 +445,20 @@ namespace ts { blockScopeContainer.locals = undefined; } - let savedHasExplicitReturn: boolean; - let savedCurrentFlow: FlowNode; - let savedBreakTarget: FlowLabel; - let savedContinueTarget: FlowLabel; - let savedActiveLabels: ActiveLabel[]; + let saveCurrentFlow: FlowNode; + let saveBreakTarget: FlowLabel; + let saveContinueTarget: FlowLabel; + let saveReturnTarget: FlowLabel; + let saveActiveLabels: ActiveLabel[]; + let saveHasExplicitReturn: boolean; + let isIIFE: boolean; const kind = node.kind; let flags = node.flags; - // reset all reachability check related flags on node (for incremental scenarios) - flags &= ~NodeFlags.ReachabilityCheckFlags; - - // reset all emit helper flags on node (for incremental scenarios) - flags &= ~NodeFlags.EmitHelperFlags; + // Reset all reachability check related flags on node (for incremental scenarios) + // Reset all emit helper flags on node (for incremental scenarios) + flags &= ~NodeFlags.ReachabilityAndEmitFlags; if (kind === SyntaxKind.InterfaceDeclaration) { seenThisKeyword = false; @@ -464,23 +466,30 @@ namespace ts { const saveState = kind === SyntaxKind.SourceFile || kind === SyntaxKind.ModuleBlock || isFunctionLikeKind(kind); if (saveState) { - savedHasExplicitReturn = hasExplicitReturn; - savedCurrentFlow = currentFlow; - savedBreakTarget = currentBreakTarget; - savedContinueTarget = currentContinueTarget; - savedActiveLabels = activeLabels; - - hasExplicitReturn = false; - currentFlow = { flags: FlowFlags.Start }; - if (kind === SyntaxKind.FunctionExpression || kind === SyntaxKind.ArrowFunction) { - (currentFlow).container = node; + saveCurrentFlow = currentFlow; + saveBreakTarget = currentBreakTarget; + saveContinueTarget = currentContinueTarget; + saveReturnTarget = currentReturnTarget; + saveActiveLabels = activeLabels; + saveHasExplicitReturn = hasExplicitReturn; + isIIFE = (kind === SyntaxKind.FunctionExpression || kind === SyntaxKind.ArrowFunction) && !!getImmediatelyInvokedFunctionExpression(node); + if (isIIFE) { + currentReturnTarget = createBranchLabel(); + } + else { + currentFlow = { flags: FlowFlags.Start }; + if (kind === SyntaxKind.FunctionExpression || kind === SyntaxKind.ArrowFunction) { + (currentFlow).container = node; + } + currentReturnTarget = undefined; } currentBreakTarget = undefined; currentContinueTarget = undefined; activeLabels = undefined; + hasExplicitReturn = false; } - if (isInJavaScriptFile(node) && node.jsDocComment) { + if (node.flags & NodeFlags.JavaScriptFile && node.jsDocComment) { bind(node.jsDocComment); } @@ -518,11 +527,18 @@ namespace ts { node.flags = flags; if (saveState) { - hasExplicitReturn = savedHasExplicitReturn; - currentFlow = savedCurrentFlow; - currentBreakTarget = savedBreakTarget; - currentContinueTarget = savedContinueTarget; - activeLabels = savedActiveLabels; + if (isIIFE) { + addAntecedent(currentReturnTarget, currentFlow); + currentFlow = finishFlowLabel(currentReturnTarget); + } + else { + currentFlow = saveCurrentFlow; + } + currentBreakTarget = saveBreakTarget; + currentContinueTarget = saveContinueTarget; + currentReturnTarget = saveReturnTarget; + activeLabels = saveActiveLabels; + hasExplicitReturn = saveHasExplicitReturn; } container = saveContainer; @@ -854,6 +870,9 @@ namespace ts { bind(node.expression); if (node.kind === SyntaxKind.ReturnStatement) { hasExplicitReturn = true; + if (currentReturnTarget) { + addAntecedent(currentReturnTarget, currentFlow); + } } currentFlow = unreachableFlow; } @@ -1105,7 +1124,6 @@ namespace ts { } function bindCallExpressionFlow(node: CallExpression) { - forEachChild(node, bind); // If the target of the call expression is a function expression or arrow function we have // an immediately invoked function expression (IIFE). Initialize the flowNode property to // the current control flow (which includes evaluation of the IIFE arguments). @@ -1114,7 +1132,12 @@ namespace ts { expr = (expr).expression; } if (expr.kind === SyntaxKind.FunctionExpression || expr.kind === SyntaxKind.ArrowFunction) { - node.flowNode = currentFlow; + forEach(node.typeArguments, bind); + forEach(node.arguments, bind); + bind(node.expression); + } + else { + forEachChild(node, bind); } } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 58aaae9f72b..037ab78413a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7695,20 +7695,11 @@ namespace ts { getTypeAtFlowLoopLabel(flow); } else if (flow.flags & FlowFlags.Start) { + // Check if we should continue with the control flow of the containing function. const container = (flow).container; - if (container) { - // If container is an IIFE continue with the control flow associated with the - // call expression node. - const iife = getImmediatelyInvokedFunctionExpression(container); - if (iife && iife.flowNode) { - flow = iife.flowNode; - continue; - } - // Check if we should continue with the control flow of the containing function. - if (includeOuterFunctions && container.flowNode) { - flow = container.flowNode; - continue; - } + if (container && includeOuterFunctions) { + flow = container.flowNode; + continue; } // At the top of the flow we have the initial type. type = initialType; @@ -8652,23 +8643,25 @@ namespace ts { function getContextuallyTypedParameterType(parameter: ParameterDeclaration): Type { const func = parameter.parent; if (isContextSensitiveFunctionOrObjectLiteralMethod(func)) { - const iife = getImmediatelyInvokedFunctionExpression(func); - if (iife) { - const indexOfParameter = indexOf(func.parameters, parameter); - if (iife.arguments && indexOfParameter < iife.arguments.length) { - if (parameter.dotDotDotToken) { - const restTypes: Type[] = []; - for (let i = indexOfParameter; i < iife.arguments.length; i++) { - restTypes.push(getTypeOfExpression(iife.arguments[i])); + if (func.kind === SyntaxKind.FunctionExpression || func.kind === SyntaxKind.ArrowFunction) { + const iife = getImmediatelyInvokedFunctionExpression(func); + if (iife) { + const indexOfParameter = indexOf(func.parameters, parameter); + if (iife.arguments && indexOfParameter < iife.arguments.length) { + if (parameter.dotDotDotToken) { + const restTypes: Type[] = []; + for (let i = indexOfParameter; i < iife.arguments.length; i++) { + restTypes.push(getTypeOfExpression(iife.arguments[i])); + } + return createArrayType(getUnionType(restTypes)); } - return createArrayType(getUnionType(restTypes)); + const links = getNodeLinks(iife); + const cached = links.resolvedSignature; + links.resolvedSignature = anySignature; + const type = checkExpression(iife.arguments[indexOfParameter]); + links.resolvedSignature = cached; + return type; } - const links = getNodeLinks(iife); - const cached = links.resolvedSignature; - links.resolvedSignature = anySignature; - const type = checkExpression(iife.arguments[indexOfParameter]); - links.resolvedSignature = cached; - return type; } } const contextualSignature = getContextualSignature(func); @@ -8691,20 +8684,6 @@ namespace ts { return undefined; } - function getImmediatelyInvokedFunctionExpression(func: FunctionExpression | MethodDeclaration) { - if (isFunctionExpressionOrArrowFunction(func)) { - let prev: Node = func; - let parent: Node = func.parent; - while (parent.kind === SyntaxKind.ParenthesizedExpression) { - prev = parent; - parent = parent.parent; - } - if (parent.kind === SyntaxKind.CallExpression && (parent as CallExpression).expression === prev) { - return parent as CallExpression; - } - } - } - // In a variable, parameter or property declaration with a type annotation, // the contextual type of an initializer expression is the type of the variable, parameter or property. // Otherwise, in a parameter declaration of a contextually typed function expression, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 762d710d504..4e55956fa7c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -416,6 +416,7 @@ namespace ts { ReachabilityCheckFlags = HasImplicitReturn | HasExplicitReturn, EmitHelperFlags = HasClassExtends | HasDecorators | HasParamDecorators | HasAsyncFunctions, + ReachabilityAndEmitFlags = ReachabilityCheckFlags | EmitHelperFlags, // Parsing context flags ContextFlags = DisallowInContext | YieldContext | DecoratorContext | AwaitContext | JavaScriptFile, diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 7969389d788..500fa722dda 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -987,6 +987,20 @@ namespace ts { } } + export function getImmediatelyInvokedFunctionExpression(func: Node): CallExpression { + if (func.kind === SyntaxKind.FunctionExpression || func.kind === SyntaxKind.ArrowFunction) { + let prev = func; + let parent = func.parent; + while (parent.kind === SyntaxKind.ParenthesizedExpression) { + prev = parent; + parent = parent.parent; + } + if (parent.kind === SyntaxKind.CallExpression && (parent as CallExpression).expression === prev) { + return parent as CallExpression; + } + } + } + /** * Determines whether a node is a property or element access expression for super. */ From 4d730a5c6a6cda260f5e382fa2c4b8cf92cb578c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 28 May 2016 06:45:10 -0700 Subject: [PATCH 50/61] Update test --- tests/baselines/reference/controlFlowIIFE.js | 2 ++ tests/baselines/reference/controlFlowIIFE.symbols | 9 ++++++--- tests/baselines/reference/controlFlowIIFE.types | 6 +++++- tests/cases/conformance/controlFlow/controlFlowIIFE.ts | 1 + 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/baselines/reference/controlFlowIIFE.js b/tests/baselines/reference/controlFlowIIFE.js index 6454d1117db..5d295b57315 100644 --- a/tests/baselines/reference/controlFlowIIFE.js +++ b/tests/baselines/reference/controlFlowIIFE.js @@ -34,6 +34,7 @@ let maybeNumber: number | undefined; (function () { maybeNumber = 1; })(); +maybeNumber++; if (maybeNumber !== undefined) { maybeNumber++; } @@ -75,6 +76,7 @@ var maybeNumber; (function () { maybeNumber = 1; })(); +maybeNumber++; if (maybeNumber !== undefined) { maybeNumber++; } diff --git a/tests/baselines/reference/controlFlowIIFE.symbols b/tests/baselines/reference/controlFlowIIFE.symbols index 2a03bb3ff2b..b1b2b741158 100644 --- a/tests/baselines/reference/controlFlowIIFE.symbols +++ b/tests/baselines/reference/controlFlowIIFE.symbols @@ -82,6 +82,9 @@ let maybeNumber: number | undefined; >maybeNumber : Symbol(maybeNumber, Decl(controlFlowIIFE.ts, 31, 3)) })(); +maybeNumber++; +>maybeNumber : Symbol(maybeNumber, Decl(controlFlowIIFE.ts, 31, 3)) + if (maybeNumber !== undefined) { >maybeNumber : Symbol(maybeNumber, Decl(controlFlowIIFE.ts, 31, 3)) >undefined : Symbol(undefined) @@ -91,10 +94,10 @@ if (maybeNumber !== undefined) { } let test: string | undefined; ->test : Symbol(test, Decl(controlFlowIIFE.ts, 39, 3)) +>test : Symbol(test, Decl(controlFlowIIFE.ts, 40, 3)) if (!test) { ->test : Symbol(test, Decl(controlFlowIIFE.ts, 39, 3)) +>test : Symbol(test, Decl(controlFlowIIFE.ts, 40, 3)) throw new Error('Test is not defined'); >Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) @@ -102,7 +105,7 @@ if (!test) { (() => { test.slice(1); // No error >test.slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) ->test : Symbol(test, Decl(controlFlowIIFE.ts, 39, 3)) +>test : Symbol(test, Decl(controlFlowIIFE.ts, 40, 3)) >slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) })(); diff --git a/tests/baselines/reference/controlFlowIIFE.types b/tests/baselines/reference/controlFlowIIFE.types index 0a6ad5da02f..c041de04bc7 100644 --- a/tests/baselines/reference/controlFlowIIFE.types +++ b/tests/baselines/reference/controlFlowIIFE.types @@ -112,9 +112,13 @@ let maybeNumber: number | undefined; >1 : number })(); +maybeNumber++; +>maybeNumber++ : number +>maybeNumber : number + if (maybeNumber !== undefined) { >maybeNumber !== undefined : boolean ->maybeNumber : number | undefined +>maybeNumber : number >undefined : undefined maybeNumber++; diff --git a/tests/cases/conformance/controlFlow/controlFlowIIFE.ts b/tests/cases/conformance/controlFlow/controlFlowIIFE.ts index e703fb2fdff..c72f038c1ec 100644 --- a/tests/cases/conformance/controlFlow/controlFlowIIFE.ts +++ b/tests/cases/conformance/controlFlow/controlFlowIIFE.ts @@ -34,6 +34,7 @@ let maybeNumber: number | undefined; (function () { maybeNumber = 1; })(); +maybeNumber++; if (maybeNumber !== undefined) { maybeNumber++; } From 66e9f7dc214dc13c936e3cec2a27d3fef56777be Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 28 May 2016 16:00:31 -0700 Subject: [PATCH 51/61] Optimize critical code paths in binder --- src/compiler/binder.ts | 213 +++++++++++++++++------------------------ 1 file changed, 87 insertions(+), 126 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 93417493fa7..4f24458f08d 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -77,12 +77,14 @@ namespace ts { // Blocks (when not parented by functions), Catch clauses, For/For-in/For-of statements... IsBlockScopedContainer = 1 << 1, - HasLocals = 1 << 2, + // The current node is the container of a control flow path. The current control flow should + // be saved and restored, and a new control flow initialized within the container. + IsControlFlowContainer = 1 << 2, - // If the current node is a container that also container that also contains locals. Examples: - // - // Functions, Methods, Modules, Source-files. - IsContainerWithLocals = IsContainer | HasLocals + IsFunctionLike = 1 << 3, + IsFunctionExpression = 1 << 4, + HasLocals = 1 << 5, + IsInterface = 1 << 6, } const binder = createBinder(); @@ -103,7 +105,7 @@ namespace ts { let lastContainer: Node; let seenThisKeyword: boolean; - // state used by reachability checks + // state used by control flow analysis let currentFlow: FlowNode; let currentBreakTarget: FlowLabel; let currentContinueTarget: FlowLabel; @@ -115,11 +117,7 @@ namespace ts { let hasExplicitReturn: boolean; // state used for emit helpers - let hasClassExtends: boolean; - let hasAsyncFunctions: boolean; - let hasDecorators: boolean; - let hasParameterDecorators: boolean; - let hasJsxSpreadAttribute: boolean; + let emitFlags: NodeFlags; // If this file is an external module, then it is automatically in strict-mode according to // ES6. If it is not an external module, then we'll determine if it is in strict mode or @@ -165,11 +163,7 @@ namespace ts { currentFalseTarget = undefined; activeLabels = undefined; hasExplicitReturn = false; - hasClassExtends = false; - hasAsyncFunctions = false; - hasDecorators = false; - hasParameterDecorators = false; - hasJsxSpreadAttribute = false; + emitFlags = NodeFlags.None; } return bindSourceFile; @@ -402,17 +396,12 @@ namespace ts { // All container nodes are kept on a linked list in declaration order. This list is used by // the getLocalNameOfContainer function in the type checker to validate that the local name // used for a container is unique. - function bindChildren(node: Node) { + function bindContainer(node: Node, containerFlags: ContainerFlags) { // Before we recurse into a node's children, we first save the existing parent, container // and block-container. Then after we pop out of processing the children, we restore // these saved values. - const saveParent = parent; const saveContainer = container; const savedBlockScopeContainer = blockScopeContainer; - - // This node will now be set as the parent of all of its children as we recurse into them. - parent = node; - // Depending on what kind of node this is, we may have to adjust the current container // and block-container. If the current node is a container, then it is automatically // considered the current block-container as well. Also, for containers that we know @@ -430,55 +419,33 @@ namespace ts { // reusing a node from a previous compilation, that node may have had 'locals' created // for it. We must clear this so we don't accidentally move any stale data forward from // a previous compilation. - const containerFlags = getContainerFlags(node); if (containerFlags & ContainerFlags.IsContainer) { container = blockScopeContainer = node; - if (containerFlags & ContainerFlags.HasLocals) { container.locals = {}; } - addToContainerChain(container); } else if (containerFlags & ContainerFlags.IsBlockScopedContainer) { blockScopeContainer = node; blockScopeContainer.locals = undefined; } - - let saveCurrentFlow: FlowNode; - let saveBreakTarget: FlowLabel; - let saveContinueTarget: FlowLabel; - let saveReturnTarget: FlowLabel; - let saveActiveLabels: ActiveLabel[]; - let saveHasExplicitReturn: boolean; - let isIIFE: boolean; - - const kind = node.kind; - let flags = node.flags; - - // Reset all reachability check related flags on node (for incremental scenarios) - // Reset all emit helper flags on node (for incremental scenarios) - flags &= ~NodeFlags.ReachabilityAndEmitFlags; - - if (kind === SyntaxKind.InterfaceDeclaration) { - seenThisKeyword = false; - } - - const saveState = kind === SyntaxKind.SourceFile || kind === SyntaxKind.ModuleBlock || isFunctionLikeKind(kind); - if (saveState) { - saveCurrentFlow = currentFlow; - saveBreakTarget = currentBreakTarget; - saveContinueTarget = currentContinueTarget; - saveReturnTarget = currentReturnTarget; - saveActiveLabels = activeLabels; - saveHasExplicitReturn = hasExplicitReturn; - isIIFE = (kind === SyntaxKind.FunctionExpression || kind === SyntaxKind.ArrowFunction) && !!getImmediatelyInvokedFunctionExpression(node); + if (containerFlags & ContainerFlags.IsControlFlowContainer) { + const saveCurrentFlow = currentFlow; + const saveBreakTarget = currentBreakTarget; + const saveContinueTarget = currentContinueTarget; + const saveReturnTarget = currentReturnTarget; + const saveActiveLabels = activeLabels; + const saveHasExplicitReturn = hasExplicitReturn; + const isIIFE = containerFlags & ContainerFlags.IsFunctionExpression && !!getImmediatelyInvokedFunctionExpression(node); + // An IIFE is considered part of the containing control flow. Return statements behave + // similarly to break statements that exit to a label just past the statement body. if (isIIFE) { currentReturnTarget = createBranchLabel(); } else { currentFlow = { flags: FlowFlags.Start }; - if (kind === SyntaxKind.FunctionExpression || kind === SyntaxKind.ArrowFunction) { + if (containerFlags & ContainerFlags.IsFunctionExpression) { (currentFlow).container = node; } currentReturnTarget = undefined; @@ -487,46 +454,17 @@ namespace ts { currentContinueTarget = undefined; activeLabels = undefined; hasExplicitReturn = false; - } - - if (node.flags & NodeFlags.JavaScriptFile && node.jsDocComment) { - bind(node.jsDocComment); - } - - bindReachableStatement(node); - - if (!(currentFlow.flags & FlowFlags.Unreachable) && isFunctionLikeKind(kind) && nodeIsPresent((node).body)) { - flags |= NodeFlags.HasImplicitReturn; - if (hasExplicitReturn) { - flags |= NodeFlags.HasExplicitReturn; + bindChildren(node); + // Reset all reachability check related flags on node (for incremental scenarios) + // Reset all emit helper flags on node (for incremental scenarios) + node.flags &= ~NodeFlags.ReachabilityAndEmitFlags; + if (!(currentFlow.flags & FlowFlags.Unreachable) && containerFlags & ContainerFlags.IsFunctionLike && nodeIsPresent((node).body)) { + node.flags |= NodeFlags.HasImplicitReturn; + if (hasExplicitReturn) node.flags |= NodeFlags.HasExplicitReturn; } - } - - if (kind === SyntaxKind.InterfaceDeclaration) { - flags = seenThisKeyword ? flags | NodeFlags.ContainsThis : flags & ~NodeFlags.ContainsThis; - } - - if (kind === SyntaxKind.SourceFile) { - if (hasClassExtends) { - flags |= NodeFlags.HasClassExtends; + if (node.kind === SyntaxKind.SourceFile) { + node.flags |= emitFlags; } - if (hasDecorators) { - flags |= NodeFlags.HasDecorators; - } - if (hasParameterDecorators) { - flags |= NodeFlags.HasParamDecorators; - } - if (hasAsyncFunctions) { - flags |= NodeFlags.HasAsyncFunctions; - } - if (hasJsxSpreadAttribute) { - flags |= NodeFlags.HasJsxSpreadAttribute; - } - } - - node.flags = flags; - - if (saveState) { if (isIIFE) { addAntecedent(currentReturnTarget, currentFlow); currentFlow = finishFlowLabel(currentReturnTarget); @@ -540,22 +478,26 @@ namespace ts { activeLabels = saveActiveLabels; hasExplicitReturn = saveHasExplicitReturn; } - + else if (containerFlags & ContainerFlags.IsInterface) { + seenThisKeyword = false; + bindChildren(node); + node.flags = seenThisKeyword ? node.flags | NodeFlags.ContainsThis : node.flags & ~NodeFlags.ContainsThis; + } + else { + bindChildren(node); + } container = saveContainer; - parent = saveParent; blockScopeContainer = savedBlockScopeContainer; } - /** - * 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. - */ - function bindReachableStatement(node: Node): void { + function bindChildren(node: Node): void { + if (node.flags & NodeFlags.JavaScriptFile && node.jsDocComment) { + bind(node.jsDocComment); + } if (checkUnreachable(node)) { forEachChild(node, bind); return; } - switch (node.kind) { case SyntaxKind.WhileStatement: bindWhileStatement(node); @@ -1145,31 +1087,42 @@ namespace ts { switch (node.kind) { case SyntaxKind.ClassExpression: case SyntaxKind.ClassDeclaration: - case SyntaxKind.InterfaceDeclaration: case SyntaxKind.EnumDeclaration: case SyntaxKind.ObjectLiteralExpression: case SyntaxKind.TypeLiteral: case SyntaxKind.JSDocRecordType: return ContainerFlags.IsContainer; + case SyntaxKind.InterfaceDeclaration: + return ContainerFlags.IsContainer | ContainerFlags.IsInterface; + + case SyntaxKind.JSDocFunctionType: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.TypeAliasDeclaration: + return ContainerFlags.IsContainer | ContainerFlags.HasLocals; + + case SyntaxKind.SourceFile: + return ContainerFlags.IsContainer | ContainerFlags.IsControlFlowContainer | ContainerFlags.HasLocals; + + case SyntaxKind.Constructor: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.Constructor: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: case SyntaxKind.FunctionType: - case SyntaxKind.JSDocFunctionType: case SyntaxKind.ConstructorType: + return ContainerFlags.IsContainer | ContainerFlags.IsControlFlowContainer | ContainerFlags.HasLocals | ContainerFlags.IsFunctionLike; + case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - case SyntaxKind.ModuleDeclaration: - case SyntaxKind.SourceFile: - case SyntaxKind.TypeAliasDeclaration: - return ContainerFlags.IsContainerWithLocals; + return ContainerFlags.IsContainer | ContainerFlags.IsControlFlowContainer | ContainerFlags.HasLocals | ContainerFlags.IsFunctionLike | ContainerFlags.IsFunctionExpression; + + case SyntaxKind.ModuleBlock: + return ContainerFlags.IsControlFlowContainer; case SyntaxKind.CatchClause: case SyntaxKind.ForStatement: @@ -1606,8 +1559,8 @@ namespace ts { node.parent = parent; - const savedInStrictMode = inStrictMode; - if (!savedInStrictMode) { + const saveInStrictMode = inStrictMode; + if (!saveInStrictMode) { updateStrictMode(node); } @@ -1627,9 +1580,18 @@ namespace ts { // symbols we do specialized work when we recurse. For example, we'll keep track of // the current 'container' node when it changes. This helps us know which symbol table // a local should go into for example. - bindChildren(node); + const saveParent = parent; + parent = node; + const containerFlags = getContainerFlags(node); + if (containerFlags === ContainerFlags.None) { + bindChildren(node); + } + else { + bindContainer(node, containerFlags); + } + parent = saveParent; - inStrictMode = savedInStrictMode; + inStrictMode = saveInStrictMode; } function updateStrictMode(node: Node) { @@ -1746,7 +1708,7 @@ namespace ts { return bindPropertyOrMethodOrAccessor(node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes); case SyntaxKind.JsxSpreadAttribute: - hasJsxSpreadAttribute = true; + emitFlags |= NodeFlags.HasJsxSpreadAttribute; return; case SyntaxKind.CallSignature: @@ -1970,10 +1932,10 @@ namespace ts { function bindClassLikeDeclaration(node: ClassLikeDeclaration) { if (!isDeclarationFile(file) && !isInAmbientContext(node)) { if (getClassExtendsHeritageClauseElement(node) !== undefined) { - hasClassExtends = true; + emitFlags |= NodeFlags.HasClassExtends; } if (nodeIsDecorated(node)) { - hasDecorators = true; + emitFlags |= NodeFlags.HasDecorators; } } @@ -2049,8 +2011,7 @@ namespace ts { if (!isDeclarationFile(file) && !isInAmbientContext(node) && nodeIsDecorated(node)) { - hasDecorators = true; - hasParameterDecorators = true; + emitFlags |= (NodeFlags.HasDecorators | NodeFlags.HasParamDecorators); } if (inStrictMode) { @@ -2077,7 +2038,7 @@ namespace ts { function bindFunctionDeclaration(node: FunctionDeclaration) { if (!isDeclarationFile(file) && !isInAmbientContext(node)) { if (isAsyncFunctionLike(node)) { - hasAsyncFunctions = true; + emitFlags |= NodeFlags.HasAsyncFunctions; } } @@ -2094,7 +2055,7 @@ namespace ts { function bindFunctionExpression(node: FunctionExpression) { if (!isDeclarationFile(file) && !isInAmbientContext(node)) { if (isAsyncFunctionLike(node)) { - hasAsyncFunctions = true; + emitFlags |= NodeFlags.HasAsyncFunctions; } } if (currentFlow) { @@ -2108,10 +2069,10 @@ namespace ts { function bindPropertyOrMethodOrAccessor(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) { if (!isDeclarationFile(file) && !isInAmbientContext(node)) { if (isAsyncFunctionLike(node)) { - hasAsyncFunctions = true; + emitFlags |= NodeFlags.HasAsyncFunctions; } if (nodeIsDecorated(node)) { - hasDecorators = true; + emitFlags |= NodeFlags.HasDecorators; } } From 5b4dffc2d72f9c1b99fdf6fa3d2f090fc735066c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 29 May 2016 16:04:34 -0700 Subject: [PATCH 52/61] More critical path optimization in binder --- src/compiler/binder.ts | 86 ++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 49 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 4f24458f08d..af304e5f0a2 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1556,15 +1556,9 @@ namespace ts { if (!node) { return; } - node.parent = parent; - const saveInStrictMode = inStrictMode; - if (!saveInStrictMode) { - updateStrictMode(node); - } - - // First we bind declaration nodes to a symbol if possible. We'll both create a symbol + // First we bind declaration nodes to a symbol if possible. We'll both create a symbol // and then potentially add the symbol to an appropriate symbol table. Possible // destination symbol tables are: // @@ -1572,56 +1566,40 @@ namespace ts { // 2) The 'members' table of the current container's symbol. // 3) The 'locals' table of the current container. // - // However, not all symbols will end up in any of these tables. 'Anonymous' symbols + // However, not all symbols will end up in any of these tables. 'Anonymous' symbols // (like TypeLiterals for example) will not be put in any table. bindWorker(node); - - // Then we recurse into the children of the node to bind them as well. For certain - // symbols we do specialized work when we recurse. For example, we'll keep track of - // the current 'container' node when it changes. This helps us know which symbol table - // a local should go into for example. - const saveParent = parent; - parent = node; - const containerFlags = getContainerFlags(node); - if (containerFlags === ContainerFlags.None) { - bindChildren(node); + // Then we recurse into the children of the node to bind them as well. For certain + // symbols we do specialized work when we recurse. For example, we'll keep track of + // the current 'container' node when it changes. This helps us know which symbol table + // a local should go into for example. Since terminal nodes are known not to have + // children, as an optimization we don't process those. + if (node.kind > SyntaxKind.LastToken) { + const saveParent = parent; + parent = node; + const containerFlags = getContainerFlags(node); + if (containerFlags === ContainerFlags.None) { + bindChildren(node); + } + else { + bindContainer(node, containerFlags); + } + parent = saveParent; } - else { - bindContainer(node, containerFlags); - } - parent = saveParent; - inStrictMode = saveInStrictMode; } - function updateStrictMode(node: Node) { - switch (node.kind) { - case SyntaxKind.SourceFile: - case SyntaxKind.ModuleBlock: - updateStrictModeStatementList((node).statements); - return; - case SyntaxKind.Block: - if (isFunctionLike(node.parent)) { - updateStrictModeStatementList((node).statements); - } - return; - case SyntaxKind.ClassDeclaration: - case SyntaxKind.ClassExpression: - // All classes are automatically in strict mode in ES6. - inStrictMode = true; - return; - } - } - function updateStrictModeStatementList(statements: NodeArray) { - for (const statement of statements) { - if (!isPrologueDirective(statement)) { - return; - } + if (!inStrictMode) { + for (const statement of statements) { + if (!isPrologueDirective(statement)) { + return; + } - if (isUseStrictPrologueDirective(statement)) { - inStrictMode = true; - return; + if (isUseStrictPrologueDirective(statement)) { + inStrictMode = true; + return; + } } } } @@ -1753,6 +1731,8 @@ namespace ts { // Members of classes, interfaces, and modules case SyntaxKind.ClassExpression: case SyntaxKind.ClassDeclaration: + // All classes are automatically in strict mode in ES6. + inStrictMode = true; return bindClassLikeDeclaration(node); case SyntaxKind.InterfaceDeclaration: return bindBlockScopedDeclaration(node, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes); @@ -1778,7 +1758,15 @@ namespace ts { case SyntaxKind.ExportAssignment: return bindExportAssignment(node); case SyntaxKind.SourceFile: + updateStrictModeStatementList((node).statements); return bindSourceFileIfExternalModule(); + case SyntaxKind.Block: + if (!isFunctionLike(node.parent)) { + return; + } + // Fall through + case SyntaxKind.ModuleBlock: + return updateStrictModeStatementList((node).statements); } } From 18ee4b0a1ee1e326b5bbcdc0104466ac9c3d13d2 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Mon, 30 May 2016 22:11:43 -0700 Subject: [PATCH 53/61] cr feedback --- src/compiler/binder.ts | 12 ++++++++++++ src/compiler/checker.ts | 16 +++++++++++++--- src/compiler/parser.ts | 29 ++++++----------------------- src/compiler/types.ts | 8 +++++--- src/services/navigationBar.ts | 6 ++++++ src/services/services.ts | 11 +---------- 6 files changed, 43 insertions(+), 39 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 756be48ed94..3d3a86f20fd 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -267,6 +267,18 @@ namespace ts { let functionType = node.parent; let index = indexOf(functionType.parameters, node); return "p" + index; + case SyntaxKind.JSDocTypedefTag: + const parentNode = node.parent && node.parent.parent; + let nameFromParentNode: string; + if (parentNode && parentNode.kind === SyntaxKind.VariableStatement) { + if ((parentNode).declarationList.declarations.length > 0) { + const nameIdentifier = (parentNode).declarationList.declarations[0].name; + if (nameIdentifier.kind === SyntaxKind.Identifier) { + nameFromParentNode = (nameIdentifier).text; + } + } + } + return nameFromParentNode; } } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 42af34c0659..e8b23822593 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3586,11 +3586,21 @@ namespace ts { return unknownType; } + let type: Type; let declaration: JSDocTypedefTag | TypeAliasDeclaration = getDeclarationOfKind(symbol, SyntaxKind.JSDocTypedefTag); - if (!declaration) { - declaration = getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration); + if (declaration) { + if (declaration.jsDocTypeLiteral) { + type = getTypeFromTypeNode(declaration.jsDocTypeLiteral); + } + else { + type = getTypeFromTypeNode(declaration.typeExpression.type); + } } - let type = getTypeFromTypeNode(declaration.type); + else { + declaration = getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration); + type = getTypeFromTypeNode(declaration.type); + } + if (popTypeResolution()) { links.typeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol); if (links.typeParameters) { diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 07509d0afcc..c61b4b836ea 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -404,7 +404,7 @@ namespace ts { case SyntaxKind.JSDocTypedefTag: return visitNode(cbNode, (node).typeExpression) || visitNode(cbNode, (node).name) || - visitNode(cbNode, (node).type); + visitNode(cbNode, (node).jsDocTypeLiteral); case SyntaxKind.JSDocTypeLiteral: return visitNodes(cbNodes, (node).jsDocPropertyTags); case SyntaxKind.JSDocPropertyTag: @@ -6301,28 +6301,11 @@ namespace ts { function handleTypedefTag(atToken: Node, tagName: Identifier): JSDocTypedefTag { const typeExpression = tryParseTypeExpression(); skipWhitespace(); - let name = parseJSDocIdentifierName(); - if (!name) { - let foundNameFromParentNode = false; - if (parentNode && parentNode.kind === SyntaxKind.VariableStatement) { - if ((parentNode).declarationList.declarations.length > 0) { - const nameFromParentNode = (parentNode).declarationList.declarations[0].name; - if (nameFromParentNode.kind === SyntaxKind.Identifier) { - foundNameFromParentNode = true; - name = nameFromParentNode; - } - } - } - if (!foundNameFromParentNode) { - parseErrorAtPosition(scanner.getStartPos(), 0, Diagnostics.Identifier_expected); - return undefined; - } - } const typedefTag = createNode(SyntaxKind.JSDocTypedefTag, atToken.pos); typedefTag.atToken = atToken; typedefTag.tagName = tagName; - typedefTag.name = name; + typedefTag.name = parseJSDocIdentifierName(); typedefTag.typeExpression = typeExpression; if (typeExpression) { @@ -6331,16 +6314,16 @@ namespace ts { if (jsDocTypeReference.name.kind === SyntaxKind.Identifier) { const name = jsDocTypeReference.name; if (name.text === "Object") { - typedefTag.type = scanChildTags(); + typedefTag.jsDocTypeLiteral = scanChildTags(); } } } - if (!typedefTag.type) { - typedefTag.type = typeExpression.type; + if (!typedefTag.jsDocTypeLiteral) { + typedefTag.jsDocTypeLiteral = typeExpression.type; } } else { - typedefTag.type = scanChildTags(); + typedefTag.jsDocTypeLiteral = scanChildTags(); } return finishNode(typedefTag); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1b9af02a8d5..f23b52b35d7 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -376,7 +376,9 @@ namespace ts { LastBinaryOperator = CaretEqualsToken, FirstNode = QualifiedName, FirstJSDocNode = JSDocTypeExpression, - LastJSDocNode = JSDocTypeLiteral + LastJSDocNode = JSDocTypeLiteral, + FirstJSDocTagNode = JSDocComment, + LastJSDocTagNode = JSDocTypeLiteral } export const enum NodeFlags { @@ -1518,9 +1520,9 @@ namespace ts { // @kind(SyntaxKind.JSDocTypedefTag) export interface JSDocTypedefTag extends JSDocTag, Declaration { - name: Identifier; + name?: Identifier; typeExpression?: JSDocTypeExpression; - type: JSDocType; + jsDocTypeLiteral?: JSDocTypeLiteral; } // @kind(SyntaxKind.JSDocPropertyTag) diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 0cb431de668..5515356a259 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -653,6 +653,12 @@ namespace ts.NavigationBar { topItem.childItems.push(newItem); } + if (node.jsDocComments && node.jsDocComments.length > 0) { + for (const jsDocComment of node.jsDocComments) { + visitNode(jsDocComment); + } + } + // Add a level if traversing into a container if (newItem && (isFunctionLike(node) || isClassLike(node))) { const lastTop = topItem; diff --git a/src/services/services.ts b/src/services/services.ts index 8fef753f2e8..90740b257c6 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -276,16 +276,7 @@ namespace ts { scanner.setText((sourceFile || this.getSourceFile()).text); children = []; let pos = this.pos; - const useJSDocScanner = - this.kind === SyntaxKind.JSDocComment || - this.kind === SyntaxKind.JSDocParameterTag || - this.kind === SyntaxKind.JSDocTag || - this.kind === SyntaxKind.JSDocParameterTag || - this.kind === SyntaxKind.JSDocReturnTag || - this.kind === SyntaxKind.JSDocTypeTag || - this.kind === SyntaxKind.JSDocTemplateTag || - this.kind === SyntaxKind.JSDocTypedefTag || - this.kind === SyntaxKind.JSDocPropertyTag; + const useJSDocScanner = this.kind >= SyntaxKind.FirstJSDocTagNode && this.kind <= SyntaxKind.LastJSDocTagNode; const processNode = (node: Node) => { if (pos < node.pos) { pos = this.addSyntheticNodes(children, pos, node.pos, useJSDocScanner); From 59b188d4cae7c9d0c4d39a6ec839506c1170a519 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Tue, 31 May 2016 02:05:26 -0700 Subject: [PATCH 54/61] Add navigationTo test for jsdoc typedef --- src/compiler/parser.ts | 7 ++++++ src/harness/harness.ts | 5 +++- src/services/navigationBar.ts | 23 ++++++++++++++++++- .../server/jsdocTypedefTagNavigateTo.ts | 16 +++++++++++++ tests/cases/unittests/jsDocParsing.ts | 3 ++- 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/server/jsdocTypedefTagNavigateTo.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index c61b4b836ea..20f3d927e71 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -672,6 +672,13 @@ namespace ts { const saveParent = parent; parent = n; forEachChild(n, visitNode); + if (n.jsDocComments) { + for (const jsDocComment of n.jsDocComments) { + jsDocComment.parent = n; + parent = jsDocComment; + forEachChild(jsDocComment, visitNode); + } + } parent = saveParent; } } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index e1c90cee80c..5fe5b84ac91 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -223,7 +223,10 @@ namespace Utils { // For some markers in SyntaxKind, we should print its original syntax name instead of // the marker name in tests. - if (k === (ts).SyntaxKind.FirstJSDocNode || k === (ts).SyntaxKind.LastJSDocNode) { + if (k === (ts).SyntaxKind.FirstJSDocNode || + k === (ts).SyntaxKind.LastJSDocNode || + k === (ts).SyntaxKind.FirstJSDocTagNode || + k === (ts).SyntaxKind.LastJSDocTagNode) { for (const kindName in (ts).SyntaxKind) { if ((ts).SyntaxKind[kindName] === k) { return kindName; diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 5515356a259..3adc5563d71 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -738,6 +738,27 @@ namespace ts.NavigationBar { } const declName = declarationNameToString(decl.name); return getNavBarItem(declName, ScriptElementKind.constElement, [getNodeSpan(node)]); + case SyntaxKind.JSDocTypedefTag: + if ((node).name) { + return getNavBarItem( + (node).name.text, + ScriptElementKind.typeElement, + [getNodeSpan(node)]); + } + else { + const parentNode = node.parent && node.parent.parent; + if (parentNode && parentNode.kind === SyntaxKind.VariableStatement) { + if ((parentNode).declarationList.declarations.length > 0) { + const nameIdentifier = (parentNode).declarationList.declarations[0].name; + if (nameIdentifier.kind === SyntaxKind.Identifier) { + return getNavBarItem( + (nameIdentifier).text, + ScriptElementKind.typeElement, + [getNodeSpan(node)]); + } + } + } + } default: return undefined; } @@ -808,7 +829,7 @@ namespace ts.NavigationBar { } function getNodeSpan(node: Node) { - return node.kind === SyntaxKind.SourceFile + return node.kind === SyntaxKind.SourceFile ? createTextSpanFromBounds(node.getFullStart(), node.getEnd()) : createTextSpanFromBounds(node.getStart(), node.getEnd()); } diff --git a/tests/cases/fourslash/server/jsdocTypedefTagNavigateTo.ts b/tests/cases/fourslash/server/jsdocTypedefTagNavigateTo.ts new file mode 100644 index 00000000000..1d1c1ac27ca --- /dev/null +++ b/tests/cases/fourslash/server/jsdocTypedefTagNavigateTo.ts @@ -0,0 +1,16 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: jsDocTypedef_form2.js +//// +//// /** @typedef {(string | number)} NumberLike */ +//// /** @typedef {(string | number | string[])} */ +//// var NumberLike2; +//// +//// /** @type {/*1*/NumberLike} */ +//// var numberLike; + +verify.navigationBarContains("NumberLike", "type"); +verify.navigationBarContains("NumberLike2", "type"); +verify.navigationBarContains("NumberLike2", "var"); +verify.navigationBarContains("numberLike", "var"); \ No newline at end of file diff --git a/tests/cases/unittests/jsDocParsing.ts b/tests/cases/unittests/jsDocParsing.ts index 8afad08909c..fb75b4d4940 100644 --- a/tests/cases/unittests/jsDocParsing.ts +++ b/tests/cases/unittests/jsDocParsing.ts @@ -1004,7 +1004,8 @@ namespace ts { if (result !== expected) { // Turn on a human-readable diff if (typeof require !== "undefined") { - require("chai").config.showDiff = true; + const chai = require("chai"); + chai.config.showDiff = true; chai.expect(JSON.parse(result)).equal(JSON.parse(expected)); } else { From e4ca76898f6ae52496c6c84ddb24c9199c77b702 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 31 May 2016 10:17:45 -0700 Subject: [PATCH 55/61] Remove redundant parameter to `writeTestConfigFile` It allowed a new parameter to silently succeed, causing runtests-browser to run zero files. --- Jakefile.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index 474303a9722..2f0ce4aa399 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -680,7 +680,7 @@ function cleanTestDirs() { } // used to pass data from jake command line directly to run.js -function writeTestConfigFile(tests, light, taskConfigsFolder, workerCount, testConfigFile) { +function writeTestConfigFile(tests, light, taskConfigsFolder, workerCount) { var testConfigContents = JSON.stringify({ test: tests ? [tests] : undefined, light: light, workerCount: workerCount, taskConfigsFolder: taskConfigsFolder }); console.log('Running tests with config: ' + testConfigContents); fs.writeFileSync('test.config', testConfigContents); @@ -716,7 +716,7 @@ function runConsoleTests(defaultReporter, runInParallel) { } if (tests || light || taskConfigsFolder) { - writeTestConfigFile(tests, light, taskConfigsFolder, workerCount, testConfigFile); + writeTestConfigFile(tests, light, taskConfigsFolder, workerCount); } if (tests && tests.toLocaleLowerCase() === "rwc") { @@ -850,7 +850,7 @@ task("runtests-browser", ["tests", "browserify", builtLocalDirectory, servicesFi fs.unlinkSync(testConfigFile); } if(tests || light) { - writeTestConfigFile(tests, light, testConfigFile); + writeTestConfigFile(tests, light); } tests = tests ? tests : ''; From e93f9df95506a8cf3daa99b18a05331960c9f726 Mon Sep 17 00:00:00 2001 From: Zhengbo Li Date: Tue, 31 May 2016 10:48:25 -0700 Subject: [PATCH 56/61] Fix broken test --- .../server/jsdocTypedefTagNavigateTo.ts | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/cases/fourslash/server/jsdocTypedefTagNavigateTo.ts b/tests/cases/fourslash/server/jsdocTypedefTagNavigateTo.ts index 1d1c1ac27ca..77cd75aa44c 100644 --- a/tests/cases/fourslash/server/jsdocTypedefTagNavigateTo.ts +++ b/tests/cases/fourslash/server/jsdocTypedefTagNavigateTo.ts @@ -10,7 +10,21 @@ //// /** @type {/*1*/NumberLike} */ //// var numberLike; -verify.navigationBarContains("NumberLike", "type"); -verify.navigationBarContains("NumberLike2", "type"); -verify.navigationBarContains("NumberLike2", "var"); -verify.navigationBarContains("numberLike", "var"); \ No newline at end of file +verify.navigationBar([ + { + "text": "NumberLike", + "kind": "type" + }, + { + "text": "NumberLike2", + "kind": "type" + }, + { + "text": "NumberLike2", + "kind": "var" + }, + { + "text": "numberLike", + "kind": "var" + } +]); \ No newline at end of file From 35b8b42b554d2b98230320b727b452d0abe9aaae Mon Sep 17 00:00:00 2001 From: Yui Date: Tue, 31 May 2016 11:16:56 -0700 Subject: [PATCH 57/61] Only check if the extensions match (#8870) --- src/harness/loggedIO.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/harness/loggedIO.ts b/src/harness/loggedIO.ts index 1c399b30a1d..3535decf121 100644 --- a/src/harness/loggedIO.ts +++ b/src/harness/loggedIO.ts @@ -226,13 +226,7 @@ namespace Playback { (path, extension, exclude) => findResultByPath(wrapper, replayLog.directoriesRead.filter( d => { - if (d.extension === extension) { - if (d.exclude) { - return ts.arrayIsEqualTo(d.exclude, exclude); - } - return true; - } - return false; + return d.extension === extension; } ), path)); From 3433a7800a01e045486e48bc06fffc551295086f Mon Sep 17 00:00:00 2001 From: zhengbli Date: Tue, 31 May 2016 12:35:12 -0700 Subject: [PATCH 58/61] Fix formatOnEnter for double newlines --- src/harness/fourslash.ts | 10 ++++++++++ src/services/formatting/formatting.ts | 6 ++++++ tests/cases/fourslash/formatOnEnter.ts | 17 +++++++++++++++++ tests/cases/fourslash/fourslash.ts | 1 + 4 files changed, 34 insertions(+) create mode 100644 tests/cases/fourslash/formatOnEnter.ts diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 4a756ab3b1e..bd556c659c7 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1486,6 +1486,12 @@ namespace FourSlash { this.fixCaretPosition(); } + public formatOnType(pos: number, key: string) { + const edits = this.languageService.getFormattingEditsAfterKeystroke(this.activeFile.fileName, pos, key, this.formatCodeOptions); + this.currentCaretPosition += this.applyEdits(this.activeFile.fileName, edits, /*isFormattingEdit*/ true); + this.fixCaretPosition(); + } + private updateMarkersForEdit(fileName: string, minChar: number, limChar: number, text: string) { for (let i = 0; i < this.testData.markers.length; i++) { const marker = this.testData.markers[i]; @@ -3223,6 +3229,10 @@ namespace FourSlashInterface { this.state.formatSelection(this.state.getMarkerByName(startMarker).position, this.state.getMarkerByName(endMarker).position); } + public onType(posMarker: string, key: string) { + this.state.formatOnType(this.state.getMarkerByName(posMarker).position, key); + } + public setOption(name: string, value: number): void; public setOption(name: string, value: string): void; public setOption(name: string, value: boolean): void; diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 2f5f10752f4..7127eb98006 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -81,6 +81,12 @@ namespace ts.formatting { while (isWhiteSpace(sourceFile.text.charCodeAt(endOfFormatSpan)) && !isLineBreak(sourceFile.text.charCodeAt(endOfFormatSpan))) { endOfFormatSpan--; } + // if the character at the end of the span is a line break, we shouldn't include it, because it indicates we don't want to + // touch the current line at all. Also, on some OSes the line break consists of two characters (\r\n), we should test if the + // previous character before the end of format span is line break character as well. + while (isLineBreak(sourceFile.text.charCodeAt(endOfFormatSpan))) { + endOfFormatSpan--; + } const span = { // get start position for the previous line pos: getStartPositionOfLine(line - 1, sourceFile), diff --git a/tests/cases/fourslash/formatOnEnter.ts b/tests/cases/fourslash/formatOnEnter.ts new file mode 100644 index 00000000000..f505cf6cec7 --- /dev/null +++ b/tests/cases/fourslash/formatOnEnter.ts @@ -0,0 +1,17 @@ +/// + +/////*3*/function listAPIFiles (path : string): string[] { +//// /*1*/ +//// /*2*/ +////} + +goTo.marker("1"); +format.onType("1", "\n"); +verify.currentLineContentIs(" "); + +goTo.marker("2"); +format.onType("2", "\n"); +verify.currentLineContentIs(" "); + +goTo.marker("3"); +verify.currentLineContentIs("function listAPIFiles(path: string): string[] {"); \ No newline at end of file diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 8a0d2d36364..71e1c3cc5d7 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -246,6 +246,7 @@ declare namespace FourSlashInterface { copyFormatOptions(): FormatCodeOptions; setFormatOptions(options: FormatCodeOptions): any; selection(startMarker: string, endMarker: string): void; + onType(posMarker: string, key: string): void; setOption(name: string, value: number): any; setOption(name: string, value: string): any; setOption(name: string, value: boolean): any; From 58fdd011df74f226f1909a2155896e43fc5c2042 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Tue, 31 May 2016 14:08:48 -0700 Subject: [PATCH 59/61] avoid eating all preceding empty lines --- src/services/formatting/formatting.ts | 2 +- tests/cases/fourslash/{ => server}/formatOnEnter.ts | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/cases/fourslash/{ => server}/formatOnEnter.ts (100%) diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 7127eb98006..ef8fddcfb3a 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -84,7 +84,7 @@ namespace ts.formatting { // if the character at the end of the span is a line break, we shouldn't include it, because it indicates we don't want to // touch the current line at all. Also, on some OSes the line break consists of two characters (\r\n), we should test if the // previous character before the end of format span is line break character as well. - while (isLineBreak(sourceFile.text.charCodeAt(endOfFormatSpan))) { + if (isLineBreak(sourceFile.text.charCodeAt(endOfFormatSpan))) { endOfFormatSpan--; } const span = { diff --git a/tests/cases/fourslash/formatOnEnter.ts b/tests/cases/fourslash/server/formatOnEnter.ts similarity index 100% rename from tests/cases/fourslash/formatOnEnter.ts rename to tests/cases/fourslash/server/formatOnEnter.ts From 41446fe4c27820e5668e6a37ba7a2934d6dfa7ad Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 31 May 2016 14:33:00 -0700 Subject: [PATCH 60/61] Address CR feedback --- src/compiler/checker.ts | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 037ab78413a..caaabdc96cd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8643,25 +8643,23 @@ namespace ts { function getContextuallyTypedParameterType(parameter: ParameterDeclaration): Type { const func = parameter.parent; if (isContextSensitiveFunctionOrObjectLiteralMethod(func)) { - if (func.kind === SyntaxKind.FunctionExpression || func.kind === SyntaxKind.ArrowFunction) { - const iife = getImmediatelyInvokedFunctionExpression(func); - if (iife) { - const indexOfParameter = indexOf(func.parameters, parameter); - if (iife.arguments && indexOfParameter < iife.arguments.length) { - if (parameter.dotDotDotToken) { - const restTypes: Type[] = []; - for (let i = indexOfParameter; i < iife.arguments.length; i++) { - restTypes.push(getTypeOfExpression(iife.arguments[i])); - } - return createArrayType(getUnionType(restTypes)); + const iife = getImmediatelyInvokedFunctionExpression(func); + if (iife) { + const indexOfParameter = indexOf(func.parameters, parameter); + if (iife.arguments && indexOfParameter < iife.arguments.length) { + if (parameter.dotDotDotToken) { + const restTypes: Type[] = []; + for (let i = indexOfParameter; i < iife.arguments.length; i++) { + restTypes.push(getTypeOfExpression(iife.arguments[i])); } - const links = getNodeLinks(iife); - const cached = links.resolvedSignature; - links.resolvedSignature = anySignature; - const type = checkExpression(iife.arguments[indexOfParameter]); - links.resolvedSignature = cached; - return type; + return createArrayType(getUnionType(restTypes)); } + const links = getNodeLinks(iife); + const cached = links.resolvedSignature; + links.resolvedSignature = anySignature; + const type = checkExpression(iife.arguments[indexOfParameter]); + links.resolvedSignature = cached; + return type; } } const contextualSignature = getContextualSignature(func); From eb0f035c78219ed920052094351326c5b35e1fe3 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Tue, 31 May 2016 16:08:12 -0700 Subject: [PATCH 61/61] Remove unused parameter --- src/compiler/parser.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 20f3d927e71..6f042627c6b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2725,7 +2725,7 @@ namespace ts { // 1) async[no LineTerminator here]AsyncArrowBindingIdentifier[?Yield][no LineTerminator here]=>AsyncConciseBody[?In] // 2) CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await][no LineTerminator here]=>AsyncConciseBody[?In] // Production (1) of AsyncArrowFunctionExpression is parsed in "tryParseAsyncSimpleArrowFunctionExpression". - // And production (2) is parsed in "tryParseParenthesizedArrowFunctionExpression". + // And production (2) is parsed in "tryParseParenthesizedArrowFunctionExpression". // // If we do successfully parse arrow-function, we must *not* recurse for productions 1, 2 or 3. An ArrowFunction is // not a LeftHandSideExpression, nor does it start a ConditionalExpression. So we are done @@ -6050,7 +6050,7 @@ namespace ts { const saveParseDiagnosticsLength = parseDiagnostics.length; const saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode; - const comment = parseJSDocCommentWorker(start, length, parent); + const comment = parseJSDocCommentWorker(start, length); if (comment) { comment.parent = parent; } @@ -6062,7 +6062,7 @@ namespace ts { return comment; } - export function parseJSDocCommentWorker(start: number, length: number, parentNode?: Node): JSDocComment { + export function parseJSDocCommentWorker(start: number, length: number): JSDocComment { const content = sourceText; start = start || 0; const end = length === undefined ? content.length : start + length;