diff --git a/Jakefile.js b/Jakefile.js index beb16d2886..288472a697 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -924,7 +924,8 @@ function lintFileAsync(options, path, cb) { var lintTargets = compilerSources .concat(harnessCoreSources) .concat(serverCoreSources) - .concat(scriptSources); + .concat(scriptSources) + .concat([path.join(servicesDirectory, "services.ts")]); desc("Runs tslint on the compiler sources"); task("lint", ["build-rules"], function() { diff --git a/doc/README.md b/doc/README.md new file mode 100644 index 0000000000..164fb69ee2 --- /dev/null +++ b/doc/README.md @@ -0,0 +1,7 @@ +This directory contains miscellaneous documentation such as the TypeScript language specification and logo. +If you are looking for more introductory material, you might want to take a look at the [TypeScript Handbook](https://github.com/Microsoft/TypeScript-Handbook). + +# Spec Contributions + +The specification is first authored as a Microsoft Word (docx) file and then generated into Markdown and PDF formats. +Due to the binary format of docx files, and the merging difficulties that may come with it, it is preferred that any suggestions or problems found in the spec should be [filed as issues](https://github.com/Microsoft/TypeScript/issues/new) rather than sent as pull requests. \ No newline at end of file diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index a399efc842..f7108c5d2d 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1499,10 +1499,7 @@ namespace ts { // If this is a property-parameter, then also declare the property symbol into the // containing class. - if (node.flags & NodeFlags.AccessibilityModifier && - node.parent.kind === SyntaxKind.Constructor && - isClassLike(node.parent.parent)) { - + if (isParameterPropertyDeclaration(node)) { const classDeclaration = node.parent.parent; declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1fdac127c5..5d57e9d202 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -67,6 +67,7 @@ namespace ts { // The language service will always care about the narrowed type of a symbol, because that is // the type the language says the symbol should have. getTypeOfSymbolAtLocation: getNarrowedTypeOfSymbol, + getSymbolsOfParameterPropertyDeclaration, getDeclaredTypeOfSymbol, getPropertiesOfType, getPropertyOfType, @@ -430,6 +431,26 @@ namespace ts { // return undefined if we can't find a symbol. } + /** + * Get symbols that represent parameter-property-declaration as parameter and as property declaration + * @param parameter a parameterDeclaration node + * @param parameterName a name of the parameter to get the symbols for. + * @return a tuple of two symbols + */ + function getSymbolsOfParameterPropertyDeclaration(parameter: ParameterDeclaration, parameterName: string): [Symbol, Symbol] { + const constructoDeclaration = parameter.parent; + const classDeclaration = parameter.parent.parent; + + const parameterSymbol = getSymbol(constructoDeclaration.locals, parameterName, SymbolFlags.Value); + const propertySymbol = getSymbol(classDeclaration.symbol.members, parameterName, SymbolFlags.Value); + + if (parameterSymbol && propertySymbol) { + return [parameterSymbol, propertySymbol]; + } + + Debug.fail("There should exist two symbols, one as property declaration and one as parameter declaration"); + } + function isBlockScopedNameDeclaredBeforeUse(declaration: Declaration, usage: Node): boolean { const declarationFile = getSourceFileOfNode(declaration); const useFile = getSourceFileOfNode(usage); @@ -819,15 +840,6 @@ namespace ts { return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier); } - function getMemberOfModuleVariable(moduleSymbol: Symbol, name: string): Symbol { - if (moduleSymbol.flags & SymbolFlags.Variable) { - const typeAnnotation = (moduleSymbol.valueDeclaration).type; - if (typeAnnotation) { - return getPropertyOfType(getTypeFromTypeNode(typeAnnotation), name); - } - } - } - // This function creates a synthetic symbol that combines the value side of one symbol with the // type/namespace side of another symbol. Consider this example: // @@ -1063,7 +1075,6 @@ namespace ts { } const moduleReferenceLiteral = moduleReferenceExpression; - const searchPath = getDirectoryPath(getSourceFile(location).fileName); // Module names are escaped in our symbol table. However, string literal values aren't. // Escape the name in the "require(...)" clause to ensure we find the right symbol. @@ -2183,65 +2194,15 @@ namespace ts { } function isDeclarationVisible(node: Declaration): boolean { - function getContainingExternalModule(node: Node) { - for (; node; node = node.parent) { - if (node.kind === SyntaxKind.ModuleDeclaration) { - if ((node).name.kind === SyntaxKind.StringLiteral) { - return node; - } - } - else if (node.kind === SyntaxKind.SourceFile) { - return isExternalOrCommonJsModule(node) ? node : undefined; - } + if (node) { + const links = getNodeLinks(node); + if (links.isVisible === undefined) { + links.isVisible = !!determineIfDeclarationIsVisible(); } - Debug.fail("getContainingModule cant reach here"); + return links.isVisible; } - function isUsedInExportAssignment(node: Node) { - // Get source File and see if it is external module and has export assigned symbol - const externalModule = getContainingExternalModule(node); - let exportAssignmentSymbol: Symbol; - let resolvedExportSymbol: Symbol; - if (externalModule) { - // This is export assigned symbol node - const externalModuleSymbol = getSymbolOfNode(externalModule); - exportAssignmentSymbol = getExportAssignmentSymbol(externalModuleSymbol); - const symbolOfNode = getSymbolOfNode(node); - if (isSymbolUsedInExportAssignment(symbolOfNode)) { - return true; - } - - // if symbolOfNode is alias declaration, resolve the symbol declaration and check - if (symbolOfNode.flags & SymbolFlags.Alias) { - return isSymbolUsedInExportAssignment(resolveAlias(symbolOfNode)); - } - } - - // Check if the symbol is used in export assignment - function isSymbolUsedInExportAssignment(symbol: Symbol) { - if (exportAssignmentSymbol === symbol) { - return true; - } - - if (exportAssignmentSymbol && !!(exportAssignmentSymbol.flags & SymbolFlags.Alias)) { - // if export assigned symbol is alias declaration, resolve the alias - resolvedExportSymbol = resolvedExportSymbol || resolveAlias(exportAssignmentSymbol); - if (resolvedExportSymbol === symbol) { - return true; - } - - // Container of resolvedExportSymbol is visible - return forEach(resolvedExportSymbol.declarations, (current: Node) => { - while (current) { - if (current === node) { - return true; - } - current = current.parent; - } - }); - } - } - } + return false; function determineIfDeclarationIsVisible() { switch (node.kind) { @@ -2320,14 +2281,6 @@ namespace ts { Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + node.kind); } } - - if (node) { - const links = getNodeLinks(node); - if (links.isVisible === undefined) { - links.isVisible = !!determineIfDeclarationIsVisible(); - } - return links.isVisible; - } } function collectLinkedAliases(node: Identifier): Node[] { @@ -3373,14 +3326,6 @@ namespace ts { } } - function addInheritedSignatures(signatures: Signature[], baseSignatures: Signature[]) { - if (baseSignatures) { - for (const signature of baseSignatures) { - signatures.push(signature); - } - } - } - function resolveDeclaredMembers(type: InterfaceType): InterfaceTypeWithDeclaredMembers { if (!(type).declaredProperties) { const symbol = type.symbol; @@ -3507,7 +3452,7 @@ namespace ts { function findMatchingSignature(signatureList: Signature[], signature: Signature, partialMatch: boolean, ignoreReturnTypes: boolean): Signature { for (const s of signatureList) { - if (compareSignatures(s, signature, partialMatch, ignoreReturnTypes, compareTypes)) { + if (compareSignaturesIdentical(s, signature, partialMatch, ignoreReturnTypes, compareTypesIdentical)) { return s; } } @@ -3768,11 +3713,14 @@ namespace ts { function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: string): Symbol { const types = containingType.types; let props: Symbol[]; + // Flags we want to propagate to the result if they exist in all source symbols + let commonFlags = (containingType.flags & TypeFlags.Intersection) ? SymbolFlags.Optional : SymbolFlags.None; for (const current of types) { const type = getApparentType(current); if (type !== unknownType) { const prop = getPropertyOfType(type, name); if (prop && !(getDeclarationFlagsFromSymbol(prop) & (NodeFlags.Private | NodeFlags.Protected))) { + commonFlags &= prop.flags; if (!props) { props = [prop]; } @@ -3800,7 +3748,12 @@ namespace ts { } propTypes.push(getTypeOfSymbol(prop)); } - const result = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | SymbolFlags.SyntheticProperty, name); + const result = createSymbol( + SymbolFlags.Property | + SymbolFlags.Transient | + SymbolFlags.SyntheticProperty | + commonFlags, + name); result.containingType = containingType; result.declarations = declarations; result.type = containingType.flags & TypeFlags.Union ? getUnionType(propTypes) : getIntersectionType(propTypes); @@ -3861,25 +3814,6 @@ namespace ts { function getSignaturesOfType(type: Type, kind: SignatureKind): Signature[] { return getSignaturesOfStructuredType(getApparentType(type), kind); } - - function typeHasConstructSignatures(type: Type): boolean { - const apparentType = getApparentType(type); - if (apparentType.flags & (TypeFlags.ObjectType | TypeFlags.Union)) { - const resolved = resolveStructuredTypeMembers(type); - return resolved.constructSignatures.length > 0; - } - return false; - } - - function typeHasCallOrConstructSignatures(type: Type): boolean { - const apparentType = getApparentType(type); - if (apparentType.flags & TypeFlags.StructuredType) { - const resolved = resolveStructuredTypeMembers(type); - return resolved.callSignatures.length > 0 || resolved.constructSignatures.length > 0; - } - return false; - } - function getIndexTypeOfStructuredType(type: Type, kind: IndexKind): Type { if (type.flags & TypeFlags.StructuredType) { const resolved = resolveStructuredTypeMembers(type); @@ -4381,10 +4315,6 @@ namespace ts { return getTypeOfGlobalSymbol(getGlobalTypeSymbol(name), arity); } - function tryGetGlobalType(name: string, arity = 0): ObjectType { - return getTypeOfGlobalSymbol(getGlobalSymbol(name, SymbolFlags.Type, /*diagnostic*/ undefined), arity); - } - /** * Returns a type that is inside a namespace at the global scope, e.g. * getExportedTypeFromNamespace('JSX', 'Element') returns the JSX.Element type @@ -4959,7 +4889,7 @@ namespace ts { return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined); } - function compareTypes(source: Type, target: Type): Ternary { + function compareTypesIdentical(source: Type, target: Type): Ternary { return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined) ? Ternary.True : Ternary.False; } @@ -4979,10 +4909,96 @@ namespace ts { return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage, containingMessageChain); } - function isSignatureAssignableTo(source: Signature, target: Signature): boolean { - const sourceType = getOrCreateTypeFromSignature(source); - const targetType = getOrCreateTypeFromSignature(target); - return checkTypeRelatedTo(sourceType, targetType, assignableRelation, /*errorNode*/ undefined); + /** + * See signatureRelatedTo, compareSignaturesIdentical + */ + function isSignatureAssignableTo(source: Signature, target: Signature, ignoreReturnTypes: boolean): boolean { + // TODO (drosen): De-duplicate code between related functions. + if (source === target) { + return true; + } + if (!target.hasRestParameter && source.minArgumentCount > target.parameters.length) { + return false; + } + + // Spec 1.0 Section 3.8.3 & 3.8.4: + // M and N (the signatures) are instantiated using type Any as the type argument for all type parameters declared by M and N + source = getErasedSignature(source); + target = getErasedSignature(target); + + const sourceMax = getNumNonRestParameters(source); + const targetMax = getNumNonRestParameters(target); + const checkCount = getNumParametersToCheckForSignatureRelatability(source, sourceMax, target, targetMax); + for (let i = 0; i < checkCount; i++) { + const s = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source); + const t = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target); + const related = isTypeAssignableTo(t, s) || isTypeAssignableTo(s, t); + if (!related) { + return false; + } + } + + if (!ignoreReturnTypes) { + const targetReturnType = getReturnTypeOfSignature(target); + if (targetReturnType === voidType) { + return true; + } + const sourceReturnType = getReturnTypeOfSignature(source); + + // The following block preserves behavior forbidding boolean returning functions from being assignable to type guard returning functions + if (targetReturnType.flags & TypeFlags.PredicateType && (targetReturnType as PredicateType).predicate.kind === TypePredicateKind.Identifier) { + if (!(sourceReturnType.flags & TypeFlags.PredicateType)) { + return false; + } + } + + return isTypeAssignableTo(sourceReturnType, targetReturnType); + } + + return true; + } + + function isImplementationCompatibleWithOverload(implementation: Signature, overload: Signature): boolean { + const erasedSource = getErasedSignature(implementation); + const erasedTarget = getErasedSignature(overload); + + // First see if the return types are compatible in either direction. + const sourceReturnType = getReturnTypeOfSignature(erasedSource); + const targetReturnType = getReturnTypeOfSignature(erasedTarget); + if (targetReturnType === voidType + || checkTypeRelatedTo(targetReturnType, sourceReturnType, assignableRelation, /*errorNode*/ undefined) + || checkTypeRelatedTo(sourceReturnType, targetReturnType, assignableRelation, /*errorNode*/ undefined)) { + + return isSignatureAssignableTo(erasedSource, erasedTarget, /*ignoreReturnTypes*/ true); + } + + return false; + } + + function getNumNonRestParameters(signature: Signature) { + const numParams = signature.parameters.length; + return signature.hasRestParameter ? + numParams - 1 : + numParams; + } + + function getNumParametersToCheckForSignatureRelatability(source: Signature, sourceNonRestParamCount: number, target: Signature, targetNonRestParamCount: number) { + if (source.hasRestParameter === target.hasRestParameter) { + if (source.hasRestParameter) { + // If both have rest parameters, get the max and add 1 to + // compensate for the rest parameter. + return Math.max(sourceNonRestParamCount, targetNonRestParamCount) + 1; + } + else { + return Math.min(sourceNonRestParamCount, targetNonRestParamCount); + } + } + else { + // Return the count for whichever signature doesn't have rest parameters. + return source.hasRestParameter ? + targetNonRestParamCount : + sourceNonRestParamCount; + } } /** @@ -5066,6 +5082,11 @@ namespace ts { if (source === undefinedType) return Ternary.True; if (source === nullType && target !== undefinedType) return Ternary.True; if (source.flags & TypeFlags.Enum && target === numberType) return Ternary.True; + if (source.flags & TypeFlags.Enum && target.flags & TypeFlags.Enum) { + if (result = enumRelatedTo(source, target)) { + return result; + } + } if (source.flags & TypeFlags.StringLiteral && target === stringType) return Ternary.True; if (relation === assignableRelation) { if (isTypeAny(source)) return Ternary.True; @@ -5528,32 +5549,24 @@ namespace ts { if (target === anyFunctionType || source === anyFunctionType) { return Ternary.True; } + const sourceSignatures = getSignaturesOfType(source, kind); const targetSignatures = getSignaturesOfType(target, kind); + if (kind === SignatureKind.Construct && sourceSignatures.length && targetSignatures.length && + isAbstractConstructorType(source) && !isAbstractConstructorType(target)) { + // An abstract constructor type is not assignable to a non-abstract constructor type + // as it would otherwise be possible to new an abstract class. Note that the assignablity + // check we perform for an extends clause excludes construct signatures from the target, + // so this check never proceeds. + if (reportErrors) { + reportError(Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type); + } + return Ternary.False; + } + let result = Ternary.True; const saveErrorInfo = errorInfo; - - - if (kind === SignatureKind.Construct) { - // Only want to compare the construct signatures for abstractness guarantees. - - // Because the "abstractness" of a class is the same across all construct signatures - // (internally we are checking the corresponding declaration), it is enough to perform - // the check and report an error once over all pairs of source and target construct signatures. - // - // sourceSig and targetSig are (possibly) undefined. - // - // Note that in an extends-clause, targetSignatures is stripped, so the check never proceeds. - const sourceSig = sourceSignatures[0]; - const targetSig = targetSignatures[0]; - - result &= abstractSignatureRelatedTo(source, sourceSig, target, targetSig); - if (result !== Ternary.True) { - return result; - } - } - outer: for (const t of targetSignatures) { if (!t.hasStringLiterals || target.flags & TypeFlags.FromSignature) { // Only elaborate errors from the first failure @@ -5569,7 +5582,7 @@ namespace ts { shouldElaborateErrors = false; } } - // don't elaborate the primitive apparent types (like Number) + // don't elaborate the primitive apparent types (like Number) // because the actual primitives will have already been reported. if (shouldElaborateErrors && !isPrimitiveApparentType(source)) { reportError(Diagnostics.Type_0_provides_no_match_for_the_signature_1, @@ -5580,43 +5593,13 @@ namespace ts { } } return result; - - function abstractSignatureRelatedTo(source: Type, sourceSig: Signature, target: Type, targetSig: Signature) { - if (sourceSig && targetSig) { - - const sourceDecl = source.symbol && getClassLikeDeclarationOfSymbol(source.symbol); - const targetDecl = target.symbol && getClassLikeDeclarationOfSymbol(target.symbol); - - if (!sourceDecl) { - // If the source object isn't itself a class declaration, it can be freely assigned, regardless - // of whether the constructed object is abstract or not. - return Ternary.True; - } - - const sourceErasedSignature = getErasedSignature(sourceSig); - const targetErasedSignature = getErasedSignature(targetSig); - - const sourceReturnType = sourceErasedSignature && getReturnTypeOfSignature(sourceErasedSignature); - const targetReturnType = targetErasedSignature && getReturnTypeOfSignature(targetErasedSignature); - - const sourceReturnDecl = sourceReturnType && sourceReturnType.symbol && getClassLikeDeclarationOfSymbol(sourceReturnType.symbol); - const targetReturnDecl = targetReturnType && targetReturnType.symbol && getClassLikeDeclarationOfSymbol(targetReturnType.symbol); - const sourceIsAbstract = sourceReturnDecl && sourceReturnDecl.flags & NodeFlags.Abstract; - const targetIsAbstract = targetReturnDecl && targetReturnDecl.flags & NodeFlags.Abstract; - - if (sourceIsAbstract && !(targetIsAbstract && targetDecl)) { - // if target isn't a class-declaration type, then it can be new'd, so we forbid the assignment. - if (reportErrors) { - reportError(Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type); - } - return Ternary.False; - } - } - return Ternary.True; - } } + /** + * See signatureAssignableTo, signatureAssignableTo + */ function signatureRelatedTo(source: Signature, target: Signature, reportErrors: boolean): Ternary { + // TODO (drosen): De-duplicate code between related functions. if (source === target) { return Ternary.True; } @@ -5668,10 +5651,12 @@ namespace ts { } const targetReturnType = getReturnTypeOfSignature(target); - if (targetReturnType === voidType) return result; + if (targetReturnType === voidType) { + return result; + } const sourceReturnType = getReturnTypeOfSignature(source); - // The follow block preserves old behavior forbidding boolean returning functions from being assignable to type guard returning functions + // The following block preserves behavior forbidding boolean returning functions from being assignable to type guard returning functions if (targetReturnType.flags & TypeFlags.PredicateType && (targetReturnType as PredicateType).predicate.kind === TypePredicateKind.Identifier) { if (!(sourceReturnType.flags & TypeFlags.PredicateType)) { if (reportErrors) { @@ -5692,7 +5677,7 @@ namespace ts { } let result = Ternary.True; for (let i = 0, len = sourceSignatures.length; i < len; ++i) { - const related = compareSignatures(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreReturnTypes*/ false, isRelatedTo); + const related = compareSignaturesIdentical(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreReturnTypes*/ false, isRelatedTo); if (!related) { return Ternary.False; } @@ -5780,6 +5765,41 @@ namespace ts { } return Ternary.False; } + + function enumRelatedTo(source: Type, target: Type) { + if (source.symbol.name !== target.symbol.name || + source.symbol.flags & SymbolFlags.ConstEnum || + target.symbol.flags & SymbolFlags.ConstEnum) { + return Ternary.False; + } + const targetEnumType = getTypeOfSymbol(target.symbol); + for (const property of getPropertiesOfType(getTypeOfSymbol(source.symbol))) { + if (property.flags & SymbolFlags.EnumMember) { + const targetProperty = getPropertyOfType(targetEnumType, property.name); + if (!targetProperty || !(targetProperty.flags & SymbolFlags.EnumMember)) { + reportError(Diagnostics.Property_0_is_missing_in_type_1, + property.name, + typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType)); + return Ternary.False; + } + } + } + return Ternary.True; + } + } + + // Return true if the given type is the constructor type for an abstract class + function isAbstractConstructorType(type: Type) { + if (type.flags & TypeFlags.Anonymous) { + const symbol = type.symbol; + if (symbol && symbol.flags & SymbolFlags.Class) { + const declaration = getClassLikeDeclarationOfSymbol(symbol); + if (declaration && declaration.flags & NodeFlags.Abstract) { + return true; + } + } + } + return false; } // Return true if the given type is part of a deeply nested chain of generic instantiations. We consider this to be the case @@ -5804,7 +5824,7 @@ namespace ts { } function isPropertyIdenticalTo(sourceProp: Symbol, targetProp: Symbol): boolean { - return compareProperties(sourceProp, targetProp, compareTypes) !== Ternary.False; + return compareProperties(sourceProp, targetProp, compareTypesIdentical) !== Ternary.False; } function compareProperties(sourceProp: Symbol, targetProp: Symbol, compareTypes: (source: Type, target: Type) => Ternary): Ternary { @@ -5851,7 +5871,11 @@ namespace ts { return false; } - function compareSignatures(source: Signature, target: Signature, partialMatch: boolean, ignoreReturnTypes: boolean, compareTypes: (s: Type, t: Type) => Ternary): Ternary { + /** + * See signatureRelatedTo, compareSignaturesIdentical + */ + function compareSignaturesIdentical(source: Signature, target: Signature, partialMatch: boolean, ignoreReturnTypes: boolean, compareTypes: (s: Type, t: Type) => Ternary): Ternary { + // TODO (drosen): De-duplicate code between related functions. if (source === target) { return Ternary.True; } @@ -6148,12 +6172,8 @@ namespace ts { } function createInferenceContext(typeParameters: TypeParameter[], inferUnionTypes: boolean): InferenceContext { - const inferences: TypeInferences[] = []; - for (const unused of typeParameters) { - inferences.push({ - primary: undefined, secondary: undefined, isFixed: false - }); - } + const inferences = map(typeParameters, createTypeInferencesObject); + return { typeParameters, inferUnionTypes, @@ -6162,6 +6182,14 @@ namespace ts { }; } + function createTypeInferencesObject(): TypeInferences { + return { + primary: undefined, + secondary: undefined, + isFixed: false, + }; + } + function inferTypes(context: InferenceContext, source: Type, target: Type) { let sourceStack: Type[]; let targetStack: Type[]; @@ -6432,10 +6460,6 @@ namespace ts { return context.inferredTypes; } - function hasAncestor(node: Node, kind: SyntaxKind): boolean { - return getAncestor(node, kind) !== undefined; - } - // EXPRESSION TYPE CHECKING function getResolvedSymbol(node: Identifier): Symbol { @@ -7058,17 +7082,14 @@ namespace ts { function checkSuperExpression(node: Node): Type { const isCallExpression = node.parent.kind === SyntaxKind.CallExpression && (node.parent).expression === node; - const classDeclaration = getContainingClass(node); - const classType = classDeclaration && getDeclaredTypeOfSymbol(getSymbolOfNode(classDeclaration)); - const baseClassType = classType && getBaseTypes(classType)[0]; - let container = getSuperContainer(node, /*includeFunctions*/ true); + let container = getSuperContainer(node, /*stopOnFunctions*/ true); let needToCaptureLexicalThis = false; if (!isCallExpression) { // adjust the container reference in case if super is used inside arrow functions with arbitrary deep nesting while (container && container.kind === SyntaxKind.ArrowFunction) { - container = getSuperContainer(container, /*includeFunctions*/ true); + container = getSuperContainer(container, /*stopOnFunctions*/ true); needToCaptureLexicalThis = languageVersion < ScriptTarget.ES6; } } @@ -7076,43 +7097,66 @@ namespace ts { const canUseSuperExpression = isLegalUsageOfSuperExpression(container); let nodeCheckFlag: NodeCheckFlags = 0; - // always set NodeCheckFlags for 'super' expression node - if (canUseSuperExpression) { - if ((container.flags & NodeFlags.Static) || isCallExpression) { - nodeCheckFlag = NodeCheckFlags.SuperStatic; - } - else { - nodeCheckFlag = NodeCheckFlags.SuperInstance; - } - - getNodeLinks(node).flags |= nodeCheckFlag; - - if (needToCaptureLexicalThis) { - // call expressions are allowed only in constructors so they should always capture correct 'this' - // super property access expressions can also appear in arrow functions - - // in this case they should also use correct lexical this - captureLexicalThis(node.parent, container); - } - } - - if (!baseClassType) { - if (!classDeclaration || !getClassExtendsHeritageClauseElement(classDeclaration)) { - error(node, Diagnostics.super_can_only_be_referenced_in_a_derived_class); - } - return unknownType; - } - if (!canUseSuperExpression) { - if (container && container.kind === SyntaxKind.ComputedPropertyName) { + // issue more specific error if super is used in computed property name + // class A { foo() { return "1" }} + // class B { + // [super.foo()]() {} + // } + let current = node; + while (current && current !== container && current.kind !== SyntaxKind.ComputedPropertyName) { + current = current.parent; + } + if (current && current.kind === SyntaxKind.ComputedPropertyName) { error(node, Diagnostics.super_cannot_be_referenced_in_a_computed_property_name); } else if (isCallExpression) { error(node, Diagnostics.Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors); } + else if (!container || !container.parent || !(isClassLike(container.parent) || container.parent.kind === SyntaxKind.ObjectLiteralExpression)) { + error(node, Diagnostics.super_can_only_be_referenced_in_members_of_derived_classes_or_object_literal_expressions); + } else { error(node, Diagnostics.super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class); } + return unknownType; + } + if ((container.flags & NodeFlags.Static) || isCallExpression) { + nodeCheckFlag = NodeCheckFlags.SuperStatic; + } + else { + nodeCheckFlag = NodeCheckFlags.SuperInstance; + } + + getNodeLinks(node).flags |= nodeCheckFlag; + + if (needToCaptureLexicalThis) { + // call expressions are allowed only in constructors so they should always capture correct 'this' + // super property access expressions can also appear in arrow functions - + // in this case they should also use correct lexical this + captureLexicalThis(node.parent, container); + } + + if (container.parent.kind === SyntaxKind.ObjectLiteralExpression) { + if (languageVersion < ScriptTarget.ES6) { + error(node, Diagnostics.super_is_only_allowed_in_members_of_object_literal_expressions_when_option_target_is_ES2015_or_higher); + return unknownType; + } + else { + // for object literal assume that type of 'super' is 'any' + return anyType; + } + } + + // at this point the only legal case for parent is ClassLikeDeclaration + const classLikeDeclaration = container.parent; + const classType = getDeclaredTypeOfSymbol(getSymbolOfNode(classLikeDeclaration)); + const baseClassType = classType && getBaseTypes(classType)[0]; + if (!baseClassType) { + if (!getClassExtendsHeritageClauseElement(classLikeDeclaration)) { + error(node, Diagnostics.super_can_only_be_referenced_in_a_derived_class); + } return unknownType; } @@ -7142,8 +7186,8 @@ namespace ts { // - In a constructor, instance member function, instance member accessor, or instance member variable initializer where this references a derived class instance // - In a static member function or static member accessor - // topmost container must be something that is directly nested in the class declaration - if (container && isClassLike(container.parent)) { + // topmost container must be something that is directly nested in the class declaration\object literal expression + if (isClassLike(container.parent) || container.parent.kind === SyntaxKind.ObjectLiteralExpression) { if (container.flags & NodeFlags.Static) { return container.kind === SyntaxKind.MethodDeclaration || container.kind === SyntaxKind.MethodSignature || @@ -7559,7 +7603,7 @@ namespace ts { // This signature will contribute to contextual union signature signatureList = [signature]; } - else if (!compareSignatures(signatureList[0], signature, /*partialMatch*/ false, /*ignoreReturnTypes*/ true, compareTypes)) { + else if (!compareSignaturesIdentical(signatureList[0], signature, /*partialMatch*/ false, /*ignoreReturnTypes*/ true, compareTypesIdentical)) { // Signatures aren't identical, do not use return undefined; } @@ -8035,7 +8079,6 @@ namespace ts { /// type or factory function. /// Otherwise, returns unknownSymbol. function getJsxElementTagSymbol(node: JsxOpeningLikeElement | JsxClosingElement): Symbol { - const flags: JsxFlags = JsxFlags.UnknownElement; const links = getNodeLinks(node); if (!links.resolvedSymbol) { if (isJsxIntrinsicIdentifier(node.tagName)) { @@ -8234,9 +8277,9 @@ namespace ts { // Props is of type 'any' or unknown return links.resolvedJsxType = attributesType; } - else if (!(attributesType.flags & TypeFlags.ObjectType)) { - // Props is not an object type - error(node.tagName, Diagnostics.JSX_element_attributes_type_0_must_be_an_object_type, typeToString(attributesType)); + else if (attributesType.flags & TypeFlags.Union) { + // Props cannot be a union type + error(node.tagName, Diagnostics.JSX_element_attributes_type_0_may_not_be_a_union_type, typeToString(attributesType)); return links.resolvedJsxType = anyType; } else { @@ -11580,7 +11623,7 @@ namespace ts { } for (const otherSignature of signaturesToCheck) { - if (!otherSignature.hasStringLiterals && isSignatureAssignableTo(signature, otherSignature)) { + if (!otherSignature.hasStringLiterals && isSignatureAssignableTo(signature, otherSignature, /*ignoreReturnTypes*/ false)) { return; } } @@ -11827,7 +11870,7 @@ namespace ts { // // The implementation is completely unrelated to the specialized signature, yet we do not check this. for (const signature of signatures) { - if (!signature.hasStringLiterals && !isSignatureAssignableTo(bodySignature, signature)) { + if (!signature.hasStringLiterals && !isImplementationCompatibleWithOverload(bodySignature, signature)) { error(signature.declaration, Diagnostics.Overload_signature_is_not_compatible_with_function_implementation); break; } @@ -14308,16 +14351,6 @@ namespace ts { } } - function getModuleStatements(node: Declaration): Statement[] { - if (node.kind === SyntaxKind.SourceFile) { - return (node).statements; - } - if (node.kind === SyntaxKind.ModuleDeclaration && (node).body.kind === SyntaxKind.ModuleBlock) { - return ((node).body).statements; - } - return emptyArray; - } - function hasExportedMembers(moduleSymbol: Symbol) { for (var id in moduleSymbol.exports) { if (id !== "export=") { @@ -15396,20 +15429,6 @@ namespace ts { return symbol && getExportSymbolOfValueSymbolIfExported(symbol).valueDeclaration; } - function instantiateSingleCallFunctionType(functionType: Type, typeArguments: Type[]): Type { - if (functionType === unknownType) { - return unknownType; - } - - const signature = getSingleCallSignature(functionType); - if (!signature) { - return unknownType; - } - - const instantiatedSignature = getSignatureInstantiation(signature, typeArguments); - return getOrCreateTypeFromSignature(instantiatedSignature); - } - function createResolver(): EmitResolver { return { getReferencedExportContainer, @@ -15544,7 +15563,12 @@ namespace ts { return false; } if (!nodeCanBeDecorated(node)) { - return grammarErrorOnFirstToken(node, Diagnostics.Decorators_are_not_valid_here); + if (node.kind === SyntaxKind.MethodDeclaration && !ts.nodeIsPresent((node).body)) { + return grammarErrorOnFirstToken(node, Diagnostics.A_decorator_can_only_decorate_a_method_implementation_not_an_overload); + } + else { + return grammarErrorOnFirstToken(node, Diagnostics.Decorators_are_not_valid_here); + } } else if (node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor) { const accessors = getAllAccessorDeclarations((node.parent).members, node); @@ -16458,25 +16482,6 @@ namespace ts { } } - function isIntegerLiteral(expression: Expression): boolean { - if (expression.kind === SyntaxKind.PrefixUnaryExpression) { - const unaryExpression = expression; - if (unaryExpression.operator === SyntaxKind.PlusToken || unaryExpression.operator === SyntaxKind.MinusToken) { - expression = unaryExpression.operand; - } - } - if (expression.kind === SyntaxKind.NumericLiteral) { - // Allows for scientific notation since literalExpression.text was formed by - // coercing a number to a string. Sometimes this coercion can yield a string - // in scientific notation. - // We also don't need special logic for hex because a hex integer is converted - // to decimal when it is coerced. - return /^[0-9]+([eE]\+?[0-9]+)?$/.test((expression).text); - } - - return false; - } - function hasParseDiagnostics(sourceFile: SourceFile): boolean { return sourceFile.parseDiagnostics.length > 0; } @@ -16505,11 +16510,6 @@ namespace ts { } } - function isEvalOrArgumentsIdentifier(node: Node): boolean { - return node.kind === SyntaxKind.Identifier && - ((node).text === "eval" || (node).text === "arguments"); - } - function checkGrammarConstructorTypeParameters(node: ConstructorDeclaration) { if (node.typeParameters) { return grammarErrorAtPos(getSourceFileOfNode(node), node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration); diff --git a/src/compiler/core.ts b/src/compiler/core.ts index cae7bd8210..ad434d4cfa 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -794,23 +794,6 @@ namespace ts { return path; } - const backslashOrDoubleQuote = /[\"\\]/g; - const escapedCharsRegExp = /[\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g; - const escapedCharsMap: Map = { - "\0": "\\0", - "\t": "\\t", - "\v": "\\v", - "\f": "\\f", - "\b": "\\b", - "\r": "\\r", - "\n": "\\n", - "\\": "\\\\", - "\"": "\\\"", - "\u2028": "\\u2028", // lineSeparator - "\u2029": "\\u2029", // paragraphSeparator - "\u0085": "\\u0085" // nextLine - }; - export interface ObjectAllocator { getNodeConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Node; getSourceFileConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => SourceFile; diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 3348b51dff..d0c5cbff48 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -1534,14 +1534,6 @@ namespace ts { } function emitBindingElement(bindingElement: BindingElement) { - function getBindingElementTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - const diagnosticMessage = getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult); - return diagnosticMessage !== undefined ? { - diagnosticMessage, - errorNode: bindingElement, - typeName: bindingElement.name - } : undefined; - } if (bindingElement.kind === SyntaxKind.OmittedExpression) { // If bindingElement is an omittedExpression (i.e. containing elision), diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 5412380893..a43f3534df 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -795,6 +795,10 @@ "category": "Error", "code": 1248 }, + "A decorator can only decorate a method implementation, not an overload.": { + "category": "Error", + "code": 1249 + }, "'with' statements are not allowed in an async function block.": { "category": "Error", "code": 1300 @@ -1691,7 +1695,7 @@ "category": "Error", "code": 2528 }, - "JSX element attributes type '{0}' must be an object type.": { + "JSX element attributes type '{0}' may not be a union type.": { "category": "Error", "code": 2600 }, @@ -1759,6 +1763,14 @@ "category": "Error", "code": 2658 }, + "'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher.": { + "category": "Error", + "code": 2659 + }, + "'super' can only be referenced in members of derived classes or object literal expressions.": { + "category": "Error", + "code": 2660 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index cc5a865923..3924312d1e 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -781,12 +781,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } } - function emitTrailingCommaIfPresent(nodeList: NodeArray): void { - if (nodeList.hasTrailingComma) { - write(","); - } - } - function emitLinePreservingList(parent: Node, nodes: NodeArray, allowTrailingComma: boolean, spacesBetweenBraces: boolean) { Debug.assert(nodes.length > 0); @@ -2452,7 +2446,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitPrefixUnaryExpression(node: PrefixUnaryExpression) { - const exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); + const exportChanged = (node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) && + isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); if (exportChanged) { // emit @@ -3238,10 +3233,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } } - function emitDownLevelForOfStatement(node: ForOfStatement) { - emitLoop(node, emitDownLevelForOfStatementWorker); - } - function emitDownLevelForOfStatementWorker(node: ForOfStatement, loop: ConvertedLoop) { // The following ES6 code: // @@ -4310,22 +4301,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // TODO (yuisu) : we should not have special cases to condition emitting comments // but have one place to fix check for these conditions. - if (node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature && - node.parent && node.parent.kind !== SyntaxKind.PropertyAssignment && - node.parent.kind !== SyntaxKind.CallExpression) { - // 1. Methods will emit the comments as part of emitting method declaration - + const { kind, parent } = node; + if (kind !== SyntaxKind.MethodDeclaration && + kind !== SyntaxKind.MethodSignature && + parent && + parent.kind !== SyntaxKind.PropertyAssignment && + parent.kind !== SyntaxKind.CallExpression && + parent.kind !== SyntaxKind.ArrayLiteralExpression) { + // 1. Methods will emit comments at their assignment declaration sites. + // // 2. If the function is a property of object literal, emitting leading-comments - // is done by emitNodeWithoutSourceMap which then call this function. - // In particular, we would like to avoid emit comments twice in following case: - // For example: + // is done by emitNodeWithoutSourceMap which then call this function. + // In particular, we would like to avoid emit comments twice in following case: + // // var obj = { // id: // /*comment*/ () => void // } - + // // 3. If the function is an argument in call expression, emitting of comments will be - // taken care of in emit list of arguments inside of emitCallexpression + // taken care of in emit list of arguments inside of 'emitCallExpression'. + // + // 4. If the function is in an array literal, 'emitLinePreservingList' will take care + // of leading comments. emitLeadingComments(node); } @@ -4352,12 +4350,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } emitSignatureAndBody(node); - if (modulekind !== ModuleKind.ES6 && node.kind === SyntaxKind.FunctionDeclaration && node.parent === currentSourceFile && node.name) { + if (modulekind !== ModuleKind.ES6 && kind === SyntaxKind.FunctionDeclaration && parent === currentSourceFile && node.name) { emitExportMemberAssignments((node).name); } emitEnd(node); - if (node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) { + if (kind !== SyntaxKind.MethodDeclaration && kind !== SyntaxKind.MethodSignature) { emitTrailingComments(node); } } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 62d9833710..7f5d052a7e 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -771,10 +771,6 @@ namespace ts { return doInsideOfContext(ParserContextFlags.Yield, func); } - function doOutsideOfYieldContext(func: () => T): T { - return doOutsideOfContext(ParserContextFlags.Yield, func); - } - function doInDecoratorContext(func: () => T): T { return doInsideOfContext(ParserContextFlags.Decorator, func); } @@ -791,10 +787,6 @@ namespace ts { return doInsideOfContext(ParserContextFlags.Yield | ParserContextFlags.Await, func); } - function doOutsideOfYieldAndAwaitContext(func: () => T): T { - return doOutsideOfContext(ParserContextFlags.Yield | ParserContextFlags.Await, func); - } - function inContext(flags: ParserContextFlags) { return (contextFlags & flags) !== 0; } @@ -851,10 +843,6 @@ namespace ts { return token = scanner.scan(); } - function getTokenPos(pos: number): number { - return skipTrivia(sourceText, pos); - } - function reScanGreaterToken(): SyntaxKind { return token = scanner.reScanGreaterToken(); } @@ -2644,10 +2632,6 @@ namespace ts { isStartOfExpression(); } - function allowInAndParseExpression(): Expression { - return allowInAnd(parseExpression); - } - function parseExpression(): Expression { // Expression[in]: // AssignmentExpression[in] @@ -3962,7 +3946,6 @@ namespace ts { const asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); const tokenIsIdentifier = isIdentifier(); - const nameToken = token; const propertyName = parsePropertyName(); // Disallowing of optional property assignments happens in the grammar checker. @@ -5104,10 +5087,6 @@ namespace ts { return undefined; } - function parseHeritageClausesWorker() { - return parseList(ParsingContext.HeritageClauses, parseHeritageClause); - } - function parseHeritageClause() { if (token === SyntaxKind.ExtendsKeyword || token === SyntaxKind.ImplementsKeyword) { const node = createNode(SyntaxKind.HeritageClause); @@ -5253,12 +5232,6 @@ namespace ts { return nextToken() === SyntaxKind.SlashToken; } - function nextTokenIsCommaOrFromKeyword() { - nextToken(); - return token === SyntaxKind.CommaToken || - token === SyntaxKind.FromKeyword; - } - function parseImportDeclarationOrImportEqualsDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportDeclaration { parseExpected(SyntaxKind.ImportKeyword); const afterImportPos = scanner.getStartPos(); @@ -5751,13 +5724,6 @@ namespace ts { return finishNode(parameter); } - function parseJSDocOptionalType(type: JSDocType): JSDocOptionalType { - const result = createNode(SyntaxKind.JSDocOptionalType, type.pos); - nextToken(); - result.type = type; - return finishNode(result); - } - function parseJSDocTypeReference(): JSDocTypeReference { const result = createNode(SyntaxKind.JSDocTypeReference); result.name = parseSimplePropertyName(); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index da6f7ab0ee..d5c8b9f913 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -573,8 +573,11 @@ namespace ts { // If the noEmitOnError flag is set, then check if we have any errors so far. If so, // immediately bail out. Note that we pass 'undefined' for 'sourceFile' so that we // get any preEmit diagnostics, not just the ones - if (options.noEmitOnError && getPreEmitDiagnostics(program, /*sourceFile:*/ undefined, cancellationToken).length > 0) { - return { diagnostics: [], sourceMaps: undefined, emitSkipped: true }; + if (options.noEmitOnError) { + const preEmitDiagnostics = getPreEmitDiagnostics(program, /*sourceFile:*/ undefined, cancellationToken); + if (preEmitDiagnostics.length > 0) { + return { diagnostics: preEmitDiagnostics, sourceMaps: undefined, emitSkipped: true }; + } } // Create the emit resolver outside of the "emitTime" tracking code below. That way diff --git a/src/compiler/sourcemap.ts b/src/compiler/sourcemap.ts index 0e90cee1fb..8abf1432b0 100644 --- a/src/compiler/sourcemap.ts +++ b/src/compiler/sourcemap.ts @@ -15,7 +15,6 @@ namespace ts { reset(): void; } - const nop = <(...args: any[]) => any>Function.prototype; let nullSourceMapWriter: SourceMapWriter; export function getNullSourceMapWriter(): SourceMapWriter { diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 836b2daeab..c99c28bc0d 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -218,7 +218,6 @@ namespace ts { const _fs = require("fs"); const _path = require("path"); const _os = require("os"); - const _tty = require("tty"); // average async stat takes about 30 microseconds // set chunk size to do 30 files in < 1 millisecond @@ -313,10 +312,6 @@ namespace ts { // time dynamically to match the large reference set? const watchedFileSet = createWatchedFileSet(); - function isNode4OrLater(): Boolean { - return parseInt(process.version.charAt(1)) >= 4; - } - const platform: string = _os.platform(); // win32\win64 are case insensitive platforms, MacOS (darwin) by default is also case insensitive const useCaseSensitiveFileNames = platform !== "win32" && platform !== "win64" && platform !== "darwin"; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index f0810ef5f5..24f70373a8 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1195,7 +1195,7 @@ namespace ts { // @kind(SyntaxKind.CaseClause) export interface CaseClause extends Node { - expression?: Expression; + expression: Expression; statements: NodeArray; } @@ -1723,6 +1723,7 @@ namespace ts { getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[]; getSymbolAtLocation(node: Node): Symbol; + getSymbolsOfParameterPropertyDeclaration(parameter: ParameterDeclaration, parameterName: string): Symbol[]; getShorthandAssignmentValueSymbol(location: Node): Symbol; getTypeAtLocation(node: Node): Type; typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 462bb623a2..c5a31992a8 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -775,26 +775,38 @@ namespace ts { } } - export function getSuperContainer(node: Node, includeFunctions: boolean): Node { + /** + * Given an super call\property node returns a closest node where either + * - super call\property is legal in the node and not legal in the parent node the node. + * i.e. super call is legal in constructor but not legal in the class body. + * - node is arrow function (so caller might need to call getSuperContainer in case if he needs to climb higher) + * - super call\property is definitely illegal in the node (but might be legal in some subnode) + * i.e. super property access is illegal in function declaration but can be legal in the statement list + */ + export function getSuperContainer(node: Node, stopOnFunctions: boolean): Node { while (true) { node = node.parent; - if (!node) return node; + if (!node) { + return node; + } switch (node.kind) { case SyntaxKind.ComputedPropertyName: - // If the grandparent node is an object literal (as opposed to a class), - // then the computed property is not a 'super' container. - // A computed property name in a class needs to be a super container - // so that we can error on it. - if (isClassLike(node.parent.parent)) { - return node; - } - // If this is a computed property, then the parent should not - // make it a super container. The parent might be a property - // in an object literal, like a method or accessor. But in order for - // such a parent to be a super container, the reference must be in - // the *body* of the container. node = node.parent; break; + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + if (!stopOnFunctions) { + continue; + } + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.Constructor: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + return node; case SyntaxKind.Decorator: // Decorators are always applied outside of the body of a class or method. if (node.parent.kind === SyntaxKind.Parameter && isClassElement(node.parent.parent)) { @@ -808,20 +820,6 @@ namespace ts { node = node.parent; } break; - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.FunctionExpression: - case SyntaxKind.ArrowFunction: - if (!includeFunctions) { - continue; - } - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.PropertySignature: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - case SyntaxKind.Constructor: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - return node; } } } @@ -2748,4 +2746,8 @@ namespace ts { } } } + + export function isParameterPropertyDeclaration(node: ParameterDeclaration): boolean { + return node.flags & NodeFlags.AccessibilityModifier && node.parent.kind === SyntaxKind.Constructor && isClassLike(node.parent.parent); + } } diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index 8ee287b263..d1566c05d4 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -251,7 +251,6 @@ class CompilerBaselineRunner extends RunnerBase { const allFiles = toBeCompiled.concat(otherFiles).filter(file => !!program.getSourceFile(file.unitName)); const fullWalker = new TypeWriterWalker(program, /*fullTypeCheck*/ true); - const pullWalker = new TypeWriterWalker(program, /*fullTypeCheck*/ false); const fullResults: ts.Map = {}; const pullResults: ts.Map = {}; diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 118a430cb4..ab1a605cd3 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -321,11 +321,6 @@ namespace FourSlash { PlaceOpenBraceOnNewLineForControlBlocks: false, }; - this.testData.files.forEach(file => { - const fileName = file.fileName.replace(Harness.IO.directoryName(file.fileName), "").substr(1); - const fileNameWithoutExtension = fileName.substr(0, fileName.lastIndexOf(".")); - }); - // Open the first file by default this.openFile(0); } @@ -762,10 +757,6 @@ namespace FourSlash { return this.languageService.getReferencesAtPosition(this.activeFile.fileName, this.currentCaretPosition); } - private assertionMessage(name: string, actualValue: any, expectedValue: any) { - return "\nActual " + name + ":\n\t" + actualValue + "\nExpected value:\n\t" + expectedValue; - } - public getSyntacticDiagnostics(expected: string) { const diagnostics = this.languageService.getSyntacticDiagnostics(this.activeFile.fileName); this.testDiagnostics(expected, diagnostics); @@ -910,7 +901,6 @@ namespace FourSlash { } public verifyCurrentParameterSpanIs(parameter: string) { - const activeSignature = this.getActiveSignatureHelpItem(); const activeParameter = this.getActiveParameter(); assert.equal(ts.displayPartsToString(activeParameter.displayParts), parameter); } @@ -2195,9 +2185,6 @@ namespace FourSlash { } } - // TOOD: should these just use the Harness's stdout/stderr? - const fsOutput = new Harness.Compiler.WriterAggregator(); - const fsErrors = new Harness.Compiler.WriterAggregator(); export function runFourSlashTest(basePath: string, testType: FourSlashTestType, fileName: string) { const content = Harness.IO.readFile(fileName); runFourSlashTestContent(basePath, testType, content, fileName); @@ -2788,6 +2775,10 @@ namespace FourSlashInterface { this.state.verifyCompletionListItemsCountIsGreaterThan(count, this.negative); } + public assertHasRanges(ranges: FourSlash.Range[]) { + assert(ranges.length !== 0, "Array of ranges is expected to be non-empty"); + } + public completionListIsEmpty() { this.state.verifyCompletionListIsEmpty(this.negative); } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 15f3813e54..7fd8197317 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -31,7 +31,6 @@ // this will work in the browser via browserify var _chai: typeof chai = require("chai"); var assert: typeof _chai.assert = _chai.assert; -var expect: typeof _chai.expect = _chai.expect; declare var __dirname: string; // Node-specific var global = Function("return this").call(null); /* tslint:enable:no-var-keyword */ @@ -513,7 +512,6 @@ namespace Harness { } const folder: any = fso.GetFolder(path); - const paths: string[] = []; return filesInFolder(folder, path); }; @@ -617,7 +615,6 @@ namespace Harness { export const getExecutingFilePath = () => ""; export const exit = (exitCode: number) => {}; - const supportsCodePage = () => false; export let log = (s: string) => console.log(s); namespace Http { @@ -627,18 +624,6 @@ namespace Harness { } /// Ask the server to use node's path.resolve to resolve the given path - function getResolvedPathFromServer(path: string) { - const xhr = new XMLHttpRequest(); - try { - xhr.open("GET", path + "?resolve", /*async*/ false); - xhr.send(); - } - catch (e) { - return { status: 404, responseText: null }; - } - - return waitForXHR(xhr); - } export interface XHRResponse { status: number; diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 3c7814df56..fb5b6ce92a 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -315,13 +315,6 @@ namespace Harness.LanguageService { class LanguageServiceShimProxy implements ts.LanguageService { constructor(private shim: ts.LanguageServiceShim) { } - private unwrappJSONCallResult(result: string): any { - const parsedResult = JSON.parse(result); - if (parsedResult.error) { - throw new Error("Language Service Shim Error: " + JSON.stringify(parsedResult.error)); - } - return parsedResult.result; - } cleanupSemanticCache(): void { this.shim.cleanupSemanticCache(); } diff --git a/src/harness/loggedIO.ts b/src/harness/loggedIO.ts index 0bae91f797..3d51682f74 100644 --- a/src/harness/loggedIO.ts +++ b/src/harness/loggedIO.ts @@ -305,25 +305,6 @@ namespace Playback { } } - const pathEquivCache: any = {}; - function pathsAreEquivalent(left: string, right: string, wrapper: { resolvePath(s: string): string }) { - const key = left + "-~~-" + right; - function areSame(a: string, b: string) { - return ts.normalizeSlashes(a).toLowerCase() === ts.normalizeSlashes(b).toLowerCase(); - } - function check() { - if (Harness.Path.getFileName(left).toLowerCase() === Harness.Path.getFileName(right).toLowerCase()) { - return areSame(left, right) || areSame(wrapper.resolvePath(left), right) || areSame(left, wrapper.resolvePath(right)) || areSame(wrapper.resolvePath(left), wrapper.resolvePath(right)); - } - } - if (pathEquivCache.hasOwnProperty(key)) { - return pathEquivCache[key]; - } - else { - return pathEquivCache[key] = check(); - } - } - function noOpReplay(name: string) { // console.log("Swallowed write operation during replay: " + name); } diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 0305b7595c..5a1c85fc13 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -263,13 +263,11 @@ namespace ts.server { } resolvePath(path: string): string { - const start = new Date().getTime(); const result = this.host.resolvePath(path); return result; } fileExists(path: string): boolean { - const start = new Date().getTime(); const result = this.host.fileExists(path); return result; } @@ -325,32 +323,6 @@ namespace ts.server { } } - // assumes normalized paths - function getAbsolutePath(filename: string, directory: string) { - const rootLength = ts.getRootLength(filename); - if (rootLength > 0) { - return filename; - } - else { - const splitFilename = filename.split("/"); - const splitDir = directory.split("/"); - let i = 0; - let dirTail = 0; - const sflen = splitFilename.length; - while ((i < sflen) && (splitFilename[i].charAt(0) == ".")) { - const dots = splitFilename[i]; - if (dots == "..") { - dirTail++; - } - else if (dots != ".") { - return undefined; - } - i++; - } - return splitDir.slice(0, splitDir.length - dirTail).concat(splitFilename.slice(i)).join("/"); - } - } - export interface ProjectOptions { // these fields can be present in the project file files?: string[]; @@ -514,7 +486,7 @@ namespace ts.server { // number becomes 0 for a watcher, then we should close it. directoryWatchersRefCount: ts.Map = {}; hostConfiguration: HostConfiguration; - timerForDetectingProjectFilelistChanges: Map = {}; + timerForDetectingProjectFileListChanges: Map = {}; constructor(public host: ServerHost, public psLogger: Logger, public eventHandler?: ProjectServiceEventHandler) { // ts.disableIncrementalParsing = true; @@ -569,21 +541,22 @@ namespace ts.server { } this.log("Detected source file changes: " + fileName); - this.startTimerForDetectingProjectFilelistChanges(project); + this.startTimerForDetectingProjectFileListChanges(project); } - startTimerForDetectingProjectFilelistChanges(project: Project) { - if (this.timerForDetectingProjectFilelistChanges[project.projectFilename]) { - clearTimeout(this.timerForDetectingProjectFilelistChanges[project.projectFilename]); + startTimerForDetectingProjectFileListChanges(project: Project) { + if (this.timerForDetectingProjectFileListChanges[project.projectFilename]) { + clearTimeout(this.timerForDetectingProjectFileListChanges[project.projectFilename]); } - this.timerForDetectingProjectFilelistChanges[project.projectFilename] = setTimeout( - () => this.handleProjectFilelistChanges(project), + this.timerForDetectingProjectFileListChanges[project.projectFilename] = setTimeout( + () => this.handleProjectFileListChanges(project), 250 ); } - handleProjectFilelistChanges(project: Project) { - const { succeeded, projectOptions, error } = this.configFileToProjectOptions(project.projectFilename); + handleProjectFileListChanges(project: Project) { + const { projectOptions } = this.configFileToProjectOptions(project.projectFilename); + const newRootFiles = projectOptions.files.map((f => this.getCanonicalFileName(f))); const currentRootFiles = project.getRootFiles().map((f => this.getCanonicalFileName(f))); @@ -611,7 +584,8 @@ namespace ts.server { this.log("Detected newly added tsconfig file: " + fileName); - const { succeeded, projectOptions, error } = this.configFileToProjectOptions(fileName); + const { projectOptions } = this.configFileToProjectOptions(fileName); + const rootFilesInTsconfig = projectOptions.files.map(f => this.getCanonicalFileName(f)); const openFileRoots = this.openFileRoots.map(s => this.getCanonicalFileName(s.fileName)); @@ -1109,7 +1083,6 @@ namespace ts.server { * Close file whose contents is managed by the client * @param filename is absolute pathname */ - closeClientFile(filename: string) { const info = ts.lookUp(this.filenameToScriptInfo, filename); if (info) { @@ -1765,9 +1738,9 @@ namespace ts.server { } getLineMapper() { - return ((line: number) => { + return (line: number) => { return this.index.lineNumberToInfo(line).offset; - }); + }; } getTextChangeRangeSinceVersion(scriptVersion: number) { diff --git a/src/server/server.ts b/src/server/server.ts index e29e79ac6e..d9f078ac0e 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -4,9 +4,7 @@ /* tslint:disable:no-null */ namespace ts.server { - const nodeproto: typeof NodeJS._debugger = require("_debugger"); const readline: NodeJS.ReadLine = require("readline"); - const path: NodeJS.Path = require("path"); const fs: typeof NodeJS.fs = require("fs"); const rl = readline.createInterface({ diff --git a/src/server/session.ts b/src/server/session.ts index dae2384ce5..78686b7911 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -129,9 +129,6 @@ namespace ts.server { export class Session { protected projectService: ProjectService; - private pendingOperation = false; - private fileHash: ts.Map = {}; - private nextFileId = 1; private errorTimer: any; /*NodeJS.Timer | number*/ private immediateId: any; private changeSeq = 0; @@ -239,11 +236,6 @@ namespace ts.server { } } - private errorCheck(file: string, project: Project) { - this.syntacticCheck(file, project); - this.semanticCheck(file, project); - } - private reloadProjects() { this.projectService.reloadProjects(); } @@ -901,7 +893,7 @@ namespace ts.server { } getDiagnosticsForProject(delay: number, fileName: string) { - const { configFileName, fileNames } = this.getProjectInfo(fileName, /*needFileNameList*/ true); + const { fileNames } = this.getProjectInfo(fileName, /*needFileNameList*/ true); // No need to analyze lib.d.ts let fileNamesInProject = fileNames.filter((value, index, array) => value.indexOf("lib.d.ts") < 0); diff --git a/src/services/services.ts b/src/services/services.ts index a9dda549ea..0ffd1138cb 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -12,7 +12,7 @@ namespace ts { /** The version of the language service API */ - export let servicesVersion = "0.4" + export const servicesVersion = "0.4"; export interface Node { getSourceFile(): SourceFile; @@ -48,7 +48,7 @@ namespace ts { getConstructSignatures(): Signature[]; getStringIndexType(): Type; getNumberIndexType(): Type; - getBaseTypes(): ObjectType[] + getBaseTypes(): ObjectType[]; } export interface Signature { @@ -97,7 +97,7 @@ namespace ts { dispose?(): void; } - export module ScriptSnapshot { + export namespace ScriptSnapshot { class StringScriptSnapshot implements IScriptSnapshot { constructor(private text: string) { @@ -126,12 +126,12 @@ namespace ts { referencedFiles: FileReference[]; importedFiles: FileReference[]; ambientExternalModules: string[]; - isLibFile: boolean + isLibFile: boolean; } - let scanner: Scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ true); + const scanner: Scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ true); - let emptyArray: any[] = []; + const emptyArray: any[] = []; const jsDocTagNames = [ "augments", @@ -174,7 +174,7 @@ namespace ts { let jsDocCompletionEntries: CompletionEntry[]; function createNode(kind: SyntaxKind, pos: number, end: number, flags: NodeFlags, parent?: Node): NodeObject { - let node = new NodeObject(kind, pos, end); + const node = new NodeObject(kind, pos, end); node.flags = flags; node.parent = parent; return node; @@ -235,8 +235,8 @@ namespace ts { private addSyntheticNodes(nodes: Node[], pos: number, end: number): number { scanner.setTextPos(pos); while (pos < end) { - let token = scanner.scan(); - let textPos = scanner.getTextPos(); + const token = scanner.scan(); + const textPos = scanner.getTextPos(); nodes.push(createNode(token, pos, textPos, NodeFlags.Synthetic, this)); pos = textPos; } @@ -244,13 +244,11 @@ namespace ts { } private createSyntaxList(nodes: NodeArray): Node { - let list = createNode(SyntaxKind.SyntaxList, nodes.pos, nodes.end, NodeFlags.Synthetic, this); + const list = createNode(SyntaxKind.SyntaxList, nodes.pos, nodes.end, NodeFlags.Synthetic, this); list._children = []; let pos = nodes.pos; - - - for (let node of nodes) { + for (const node of nodes) { if (pos < node.pos) { pos = this.addSyntheticNodes(list._children, pos, node.pos); } @@ -269,14 +267,14 @@ namespace ts { scanner.setText((sourceFile || this.getSourceFile()).text); children = []; let pos = this.pos; - let processNode = (node: Node) => { + const processNode = (node: Node) => { if (pos < node.pos) { pos = this.addSyntheticNodes(children, pos, node.pos); } children.push(node); pos = node.end; }; - let processNodes = (nodes: NodeArray) => { + const processNodes = (nodes: NodeArray) => { if (pos < nodes.pos) { pos = this.addSyntheticNodes(children, pos, nodes.pos); } @@ -308,20 +306,20 @@ namespace ts { } public getFirstToken(sourceFile?: SourceFile): Node { - let children = this.getChildren(sourceFile); + const children = this.getChildren(sourceFile); if (!children.length) { return undefined; } - let child = children[0]; + const child = children[0]; return child.kind < SyntaxKind.FirstNode ? child : child.getFirstToken(sourceFile); } public getLastToken(sourceFile?: SourceFile): Node { - let children = this.getChildren(sourceFile); + const children = this.getChildren(sourceFile); - let child = lastOrUndefined(children); + const child = lastOrUndefined(children); if (!child) { return undefined; } @@ -366,8 +364,8 @@ namespace ts { } function getJsDocCommentsFromDeclarations(declarations: Declaration[], name: string, canUseParsedParamTagComments: boolean) { - let documentationComment = []; - let docComments = getJsDocCommentsSeparatedByNewLines(); + const documentationComment = []; + const docComments = getJsDocCommentsSeparatedByNewLines(); ts.forEach(docComments, docComment => { if (documentationComment.length) { documentationComment.push(lineBreakPart()); @@ -378,22 +376,22 @@ namespace ts { return documentationComment; function getJsDocCommentsSeparatedByNewLines() { - let paramTag = "@param"; - let jsDocCommentParts: SymbolDisplayPart[] = []; + const paramTag = "@param"; + const jsDocCommentParts: SymbolDisplayPart[] = []; ts.forEach(declarations, (declaration, indexOfDeclaration) => { // Make sure we are collecting doc comment from declaration once, // In case of union property there might be same declaration multiple times // which only varies in type parameter - // Eg. let a: Array | Array; a.length + // Eg. const a: Array | Array; a.length // The property length will have two declarations of property length coming // from Array - Array and Array if (indexOf(declarations, declaration) === indexOfDeclaration) { - let sourceFileOfDeclaration = getSourceFileOfNode(declaration); + const sourceFileOfDeclaration = getSourceFileOfNode(declaration); // If it is parameter - try and get the jsDoc comment with @param tag from function declaration's jsDoc comments if (canUseParsedParamTagComments && declaration.kind === SyntaxKind.Parameter) { ts.forEach(getJsDocCommentTextRange(declaration.parent, sourceFileOfDeclaration), jsDocCommentTextRange => { - let cleanedParamJsDocComment = getCleanedParamJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); + const cleanedParamJsDocComment = getCleanedParamJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); if (cleanedParamJsDocComment) { addRange(jsDocCommentParts, cleanedParamJsDocComment); } @@ -413,7 +411,7 @@ namespace ts { // Get the cleaned js doc comment text from the declaration ts.forEach(getJsDocCommentTextRange( declaration.kind === SyntaxKind.VariableDeclaration ? declaration.parent.parent : declaration, sourceFileOfDeclaration), jsDocCommentTextRange => { - let cleanedJsDocComment = getCleanedJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); + const cleanedJsDocComment = getCleanedJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); if (cleanedJsDocComment) { addRange(jsDocCommentParts, cleanedJsDocComment); } @@ -439,7 +437,7 @@ namespace ts { } for (; pos < end; pos++) { - let ch = sourceFile.text.charCodeAt(pos); + const ch = sourceFile.text.charCodeAt(pos); if (!isWhiteSpace(ch) || isLineBreak(ch)) { // Either found lineBreak or non whiteSpace return pos; @@ -480,7 +478,7 @@ namespace ts { function getCleanedJsDocComment(pos: number, end: number, sourceFile: SourceFile) { let spacesToRemoveAfterAsterisk: number; - let docComments: SymbolDisplayPart[] = []; + const docComments: SymbolDisplayPart[] = []; let blankLineCount = 0; let isInParamTag = false; @@ -491,7 +489,7 @@ namespace ts { // If the comment starts with '*' consume the spaces on this line if (pos < end && sourceFile.text.charCodeAt(pos) === CharacterCodes.asterisk) { - let lineStartPos = pos + 1; + const lineStartPos = pos + 1; pos = consumeWhiteSpacesOnTheLine(pos + 1, end, sourceFile, spacesToRemoveAfterAsterisk); // Set the spaces to remove after asterisk as margin if not already set @@ -505,7 +503,7 @@ namespace ts { // Analyse text on this line while (pos < end && !isLineBreak(sourceFile.text.charCodeAt(pos))) { - let ch = sourceFile.text.charAt(pos); + const ch = sourceFile.text.charAt(pos); if (ch === "@") { // If it is @param tag if (isParamTag(pos, end, sourceFile)) { @@ -544,7 +542,7 @@ namespace ts { function getCleanedParamJsDocComment(pos: number, end: number, sourceFile: SourceFile) { let paramHelpStringMargin: number; - let paramDocComments: SymbolDisplayPart[] = []; + const paramDocComments: SymbolDisplayPart[] = []; while (pos < end) { if (isParamTag(pos, end, sourceFile)) { let blankLineCount = 0; @@ -559,7 +557,7 @@ namespace ts { if (sourceFile.text.charCodeAt(pos) === CharacterCodes.openBrace) { pos++; for (let curlies = 1; pos < end; pos++) { - let charCode = sourceFile.text.charCodeAt(pos); + const charCode = sourceFile.text.charCodeAt(pos); // { character means we need to find another } to match the found one if (charCode === CharacterCodes.openBrace) { @@ -603,9 +601,9 @@ namespace ts { } let paramHelpString = ""; - let firstLineParamHelpStringPos = pos; + const firstLineParamHelpStringPos = pos; while (pos < end) { - let ch = sourceFile.text.charCodeAt(pos); + const ch = sourceFile.text.charCodeAt(pos); // at line break, set this comment line text and go to next line if (isLineBreak(ch)) { @@ -674,15 +672,15 @@ namespace ts { } // Now consume white spaces max - let startOfLinePos = pos; + const startOfLinePos = pos; pos = consumeWhiteSpacesOnTheLine(pos, end, sourceFile, paramHelpStringMargin); if (pos >= end) { return; } - let consumedSpaces = pos - startOfLinePos; + const consumedSpaces = pos - startOfLinePos; if (consumedSpaces < paramHelpStringMargin) { - let ch = sourceFile.text.charCodeAt(pos); + const ch = sourceFile.text.charCodeAt(pos); if (ch === CharacterCodes.asterisk) { // Consume more spaces after asterisk pos = consumeWhiteSpacesOnTheLine(pos + 1, end, sourceFile, paramHelpStringMargin - consumedSpaces - 1); @@ -815,7 +813,7 @@ namespace ts { private namedDeclarations: Map; constructor(kind: SyntaxKind, pos: number, end: number) { - super(kind, pos, end) + super(kind, pos, end); } public update(newText: string, textChangeRange: TextChangeRange): SourceFile { @@ -843,16 +841,16 @@ namespace ts { } private computeNamedDeclarations(): Map { - let result: Map = {}; + const result: Map = {}; forEachChild(this, visit); return result; function addDeclaration(declaration: Declaration) { - let name = getDeclarationName(declaration); + const name = getDeclarationName(declaration); if (name) { - let declarations = getDeclarations(name); + const declarations = getDeclarations(name); declarations.push(declaration); } } @@ -863,13 +861,13 @@ namespace ts { function getDeclarationName(declaration: Declaration) { if (declaration.name) { - let result = getTextOfIdentifierOrLiteral(declaration.name); + const result = getTextOfIdentifierOrLiteral(declaration.name); if (result !== undefined) { return result; } if (declaration.name.kind === SyntaxKind.ComputedPropertyName) { - let expr = (declaration.name).expression; + const expr = (declaration.name).expression; if (expr.kind === SyntaxKind.PropertyAccessExpression) { return (expr).name.text; } @@ -899,12 +897,12 @@ namespace ts { case SyntaxKind.FunctionDeclaration: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: - let functionDeclaration = node; - let declarationName = getDeclarationName(functionDeclaration); + const functionDeclaration = node; + const declarationName = getDeclarationName(functionDeclaration); if (declarationName) { - let declarations = getDeclarations(declarationName); - let lastDeclaration = lastOrUndefined(declarations); + const declarations = getDeclarations(declarationName); + const lastDeclaration = lastOrUndefined(declarations); // Check whether this declaration belongs to an "overload group". if (lastDeclaration && functionDeclaration.parent === lastDeclaration.parent && functionDeclaration.symbol === lastDeclaration.symbol) { @@ -980,7 +978,7 @@ namespace ts { break; case SyntaxKind.ImportDeclaration: - let importClause = (node).importClause; + const importClause = (node).importClause; if (importClause) { // Handle default import case e.g.: // import d from "mod"; @@ -1113,8 +1111,8 @@ namespace ts { } export interface Classifications { - spans: number[], - endOfLineState: EndOfLineState + spans: number[]; + endOfLineState: EndOfLineState; } export interface ClassifiedSpan { @@ -1171,7 +1169,7 @@ namespace ts { highlightSpans: HighlightSpan[]; } - export module HighlightSpanKind { + export namespace HighlightSpanKind { export const none = "none"; export const definition = "definition"; export const reference = "reference"; @@ -1220,7 +1218,7 @@ namespace ts { InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: boolean; PlaceOpenBraceOnNewLineForFunctions: boolean; PlaceOpenBraceOnNewLineForControlBlocks: boolean; - [s: string]: boolean | number| string; + [s: string]: boolean | number | string; } export interface DefinitionInfo { @@ -1500,7 +1498,7 @@ namespace ts { } // TODO: move these to enums - export module ScriptElementKind { + export namespace ScriptElementKind { export const unknown = ""; export const warning = "warning"; @@ -1529,7 +1527,7 @@ namespace ts { export const enumElement = "enum"; // Inside module and script only - // let v = .. + // const v = .. export const variableElement = "var"; // Inside function @@ -1581,7 +1579,7 @@ namespace ts { export const letElement = "let"; } - export module ScriptElementKindModifier { + export namespace ScriptElementKindModifier { export const none = ""; export const publicMemberModifier = "public"; export const privateMemberModifier = "private"; @@ -1723,8 +1721,8 @@ namespace ts { this.fileNameToEntry = createFileMap(); // Initialize the list with the root file names - let rootFileNames = host.getScriptFileNames(); - for (let fileName of rootFileNames) { + const rootFileNames = host.getScriptFileNames(); + for (const fileName of rootFileNames) { this.createEntry(fileName, toPath(fileName, this.currentDirectory, getCanonicalFileName)); } @@ -1738,7 +1736,7 @@ namespace ts { private createEntry(fileName: string, path: Path) { let entry: HostFileInformation; - let scriptSnapshot = this.host.getScriptSnapshot(fileName); + const scriptSnapshot = this.host.getScriptSnapshot(fileName); if (scriptSnapshot) { entry = { hostFileName: fileName, @@ -1760,7 +1758,7 @@ namespace ts { } public getOrCreateEntry(fileName: string): HostFileInformation { - let path = toPath(fileName, this.currentDirectory, this.getCanonicalFileName) + const path = toPath(fileName, this.currentDirectory, this.getCanonicalFileName); if (this.contains(path)) { return this.getEntry(path); } @@ -1769,7 +1767,7 @@ namespace ts { } public getRootFileNames(): string[] { - let fileNames: string[] = []; + const fileNames: string[] = []; this.fileNameToEntry.forEachValue((path, value) => { if (value) { @@ -1781,12 +1779,12 @@ namespace ts { } public getVersion(path: Path): string { - let file = this.getEntry(path); + const file = this.getEntry(path); return file && file.version; } public getScriptSnapshot(path: Path): IScriptSnapshot { - let file = this.getEntry(path); + const file = this.getEntry(path); return file && file.scriptSnapshot; } } @@ -1803,22 +1801,22 @@ namespace ts { } public getCurrentSourceFile(fileName: string): SourceFile { - let scriptSnapshot = this.host.getScriptSnapshot(fileName); + const scriptSnapshot = this.host.getScriptSnapshot(fileName); if (!scriptSnapshot) { // The host does not know about this file. throw new Error("Could not find file: '" + fileName + "'."); } - let version = this.host.getScriptVersion(fileName); + const version = this.host.getScriptVersion(fileName); let sourceFile: SourceFile; if (this.currentFileName !== fileName) { // This is a new file, just parse it - sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, ScriptTarget.Latest, version, /*setNodeParents:*/ true); + sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, ScriptTarget.Latest, version, /*setNodeParents*/ true); } else if (this.currentFileVersion !== version) { // This is the same file, just a newer version. Incrementally parse the file. - let editRange = scriptSnapshot.getChangeRange(this.currentFileScriptSnapshot); + const editRange = scriptSnapshot.getChangeRange(this.currentFileScriptSnapshot); sourceFile = updateLanguageServiceSourceFile(this.currentSourceFile, scriptSnapshot, version, editRange); } @@ -1863,7 +1861,7 @@ namespace ts { * - noResolve = true */ export function transpileModule(input: string, transpileOptions: TranspileOptions): TranspileOutput { - let options = transpileOptions.compilerOptions ? clone(transpileOptions.compilerOptions) : getDefaultCompilerOptions(); + const options = transpileOptions.compilerOptions ? clone(transpileOptions.compilerOptions) : getDefaultCompilerOptions(); options.isolatedModules = true; @@ -1879,21 +1877,22 @@ namespace ts { options.noResolve = true; // if jsx is specified then treat file as .tsx - let inputFileName = transpileOptions.fileName || (options.jsx ? "module.tsx" : "module.ts"); - let sourceFile = createSourceFile(inputFileName, input, options.target); + const inputFileName = transpileOptions.fileName || (options.jsx ? "module.tsx" : "module.ts"); + const sourceFile = createSourceFile(inputFileName, input, options.target); if (transpileOptions.moduleName) { sourceFile.moduleName = transpileOptions.moduleName; } sourceFile.renamedDependencies = transpileOptions.renamedDependencies; - let newLine = getNewLineCharacter(options); + const newLine = getNewLineCharacter(options); // Output let outputText: string; let sourceMapText: string; + // Create a compilerHost object to allow the compiler to read and write files - let compilerHost: CompilerHost = { + const compilerHost: CompilerHost = { getSourceFile: (fileName, target) => fileName === normalizeSlashes(inputFileName) ? sourceFile : undefined, writeFile: (name, text, writeByteOrderMark) => { if (fileExtensionIs(name, ".map")) { @@ -1914,7 +1913,7 @@ namespace ts { readFile: (fileName): string => "" }; - let program = createProgram([inputFileName], options, compilerHost); + const program = createProgram([inputFileName], options, compilerHost); let diagnostics: Diagnostic[]; if (transpileOptions.reportDiagnostics) { @@ -1934,15 +1933,15 @@ namespace ts { * This is a shortcut function for transpileModule - it accepts transpileOptions as parameters and returns only outputText part of the result. */ export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[], moduleName?: string): string { - let output = transpileModule(input, { compilerOptions, fileName, reportDiagnostics: !!diagnostics, moduleName }); + const output = transpileModule(input, { compilerOptions, fileName, reportDiagnostics: !!diagnostics, moduleName }); // addRange correctly handles cases when wither 'from' or 'to' argument is missing addRange(diagnostics, output.diagnostics); return output.outputText; } export function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile { - let text = scriptSnapshot.getText(0, scriptSnapshot.getLength()); - let sourceFile = createSourceFile(fileName, text, scriptTarget, setNodeParents); + const text = scriptSnapshot.getText(0, scriptSnapshot.getLength()); + const sourceFile = createSourceFile(fileName, text, scriptTarget, setNodeParents); setSourceFileFields(sourceFile, scriptSnapshot, version); // after full parsing we can use table with interned strings as name table sourceFile.nameTable = sourceFile.identifiers; @@ -1961,12 +1960,12 @@ namespace ts { let newText: string; // grab the fragment from the beginning of the original text to the beginning of the span - let prefix = textChangeRange.span.start !== 0 + const prefix = textChangeRange.span.start !== 0 ? sourceFile.text.substr(0, textChangeRange.span.start) : ""; // grab the fragment from the end of the span till the end of the original text - let suffix = textSpanEnd(textChangeRange.span) !== sourceFile.text.length + const suffix = textSpanEnd(textChangeRange.span) !== sourceFile.text.length ? sourceFile.text.substr(textSpanEnd(textChangeRange.span)) : ""; @@ -1976,7 +1975,7 @@ namespace ts { } else { // it was actual edit, fetch the fragment of new text that correspond to new span - let changedText = scriptSnapshot.getText(textChangeRange.span.start, textChangeRange.span.start + textChangeRange.newLength); + const changedText = scriptSnapshot.getText(textChangeRange.span.start, textChangeRange.span.start + textChangeRange.newLength); // combine prefix, changed text and suffix newText = prefix && suffix ? prefix + changedText + suffix @@ -1985,7 +1984,7 @@ namespace ts { : (changedText + suffix); } - let newSourceFile = updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks); + const newSourceFile = updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks); setSourceFileFields(newSourceFile, scriptSnapshot, version); // after incremental parsing nameTable might not be up-to-date // drop it so it can be lazily recreated later @@ -2006,7 +2005,7 @@ namespace ts { } // Otherwise, just create a new source file. - return createLanguageServiceSourceFile(sourceFile.fileName, scriptSnapshot, sourceFile.languageVersion, version, /*setNodeParents:*/ true); + return createLanguageServiceSourceFile(sourceFile.fileName, scriptSnapshot, sourceFile.languageVersion, version, /*setNodeParents*/ true); } export function createGetCanonicalFileName(useCaseSensitivefileNames: boolean): (fileName: string) => string { @@ -2019,15 +2018,15 @@ namespace ts { export function createDocumentRegistry(useCaseSensitiveFileNames?: boolean, currentDirectory = ""): DocumentRegistry { // Maps from compiler setting target (ES3, ES5, etc.) to all the cached documents we have // for those settings. - let buckets: Map> = {}; - let getCanonicalFileName = createGetCanonicalFileName(!!useCaseSensitiveFileNames); + const buckets: Map> = {}; + const getCanonicalFileName = createGetCanonicalFileName(!!useCaseSensitiveFileNames); function getKeyFromCompilationSettings(settings: CompilerOptions): string { return "_" + settings.target + "|" + settings.module + "|" + settings.noResolve + "|" + settings.jsx + +"|" + settings.allowJs; } function getBucketForCompilationSettings(settings: CompilerOptions, createIfMissing: boolean): FileMap { - let key = getKeyFromCompilationSettings(settings); + const key = getKeyFromCompilationSettings(settings); let bucket = lookUp(buckets, key); if (!bucket && createIfMissing) { buckets[key] = bucket = createFileMap(); @@ -2036,9 +2035,9 @@ namespace ts { } function reportStats() { - let bucketInfoArray = Object.keys(buckets).filter(name => name && name.charAt(0) === '_').map(name => { - let entries = lookUp(buckets, name); - let sourceFiles: { name: string; refCount: number; references: string[]; }[] = []; + const bucketInfoArray = Object.keys(buckets).filter(name => name && name.charAt(0) === "_").map(name => { + const entries = lookUp(buckets, name); + const sourceFiles: { name: string; refCount: number; references: string[]; }[] = []; entries.forEachValue((key, entry) => { sourceFiles.push({ name: key, @@ -2052,15 +2051,15 @@ namespace ts { sourceFiles }; }); - return JSON.stringify(bucketInfoArray, null, 2); + return JSON.stringify(bucketInfoArray, undefined, 2); } function acquireDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile { - return acquireOrUpdateDocument(fileName, compilationSettings, scriptSnapshot, version, /*acquiring:*/ true); + return acquireOrUpdateDocument(fileName, compilationSettings, scriptSnapshot, version, /*acquiring*/ true); } function updateDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile { - return acquireOrUpdateDocument(fileName, compilationSettings, scriptSnapshot, version, /*acquiring:*/ false); + return acquireOrUpdateDocument(fileName, compilationSettings, scriptSnapshot, version, /*acquiring*/ false); } function acquireOrUpdateDocument( @@ -2070,14 +2069,14 @@ namespace ts { version: string, acquiring: boolean): SourceFile { - let bucket = getBucketForCompilationSettings(compilationSettings, /*createIfMissing*/ true); - let path = toPath(fileName, currentDirectory, getCanonicalFileName); + const bucket = getBucketForCompilationSettings(compilationSettings, /*createIfMissing*/ true); + const path = toPath(fileName, currentDirectory, getCanonicalFileName); let entry = bucket.get(path); if (!entry) { Debug.assert(acquiring, "How could we be trying to update a document that the registry doesn't have?"); // Have never seen this file with these settings. Create a new source file for it. - let sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, compilationSettings.target, version, /*setNodeParents:*/ false); + const sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, compilationSettings.target, version, /*setNodeParents*/ false); entry = { sourceFile: sourceFile, @@ -2109,12 +2108,12 @@ namespace ts { } function releaseDocument(fileName: string, compilationSettings: CompilerOptions): void { - let bucket = getBucketForCompilationSettings(compilationSettings, false); + const bucket = getBucketForCompilationSettings(compilationSettings, /*createIfMissing*/false); Debug.assert(bucket !== undefined); - let path = toPath(fileName, currentDirectory, getCanonicalFileName); + const path = toPath(fileName, currentDirectory, getCanonicalFileName); - let entry = bucket.get(path); + const entry = bucket.get(path); entry.languageServiceRefCount--; Debug.assert(entry.languageServiceRefCount >= 0); @@ -2132,19 +2131,19 @@ namespace ts { } export function preProcessFile(sourceText: string, readImportFiles = true, detectJavaScriptImports = false): PreProcessedFileInfo { - let referencedFiles: FileReference[] = []; - let importedFiles: FileReference[] = []; + const referencedFiles: FileReference[] = []; + const importedFiles: FileReference[] = []; let ambientExternalModules: string[]; let isNoDefaultLib = false; function processTripleSlashDirectives(): void { - let commentRanges = getLeadingCommentRanges(sourceText, 0); + const commentRanges = getLeadingCommentRanges(sourceText, 0); forEach(commentRanges, commentRange => { - let comment = sourceText.substring(commentRange.pos, commentRange.end); - let referencePathMatchResult = getFileReferenceFromReferencePath(comment, commentRange); + const comment = sourceText.substring(commentRange.pos, commentRange.end); + const referencePathMatchResult = getFileReferenceFromReferencePath(comment, commentRange); if (referencePathMatchResult) { isNoDefaultLib = referencePathMatchResult.isNoDefaultLib; - let fileReference = referencePathMatchResult.fileReference; + const fileReference = referencePathMatchResult.fileReference; if (fileReference) { referencedFiles.push(fileReference); } @@ -2160,8 +2159,8 @@ namespace ts { } function recordModuleName() { - let importPath = scanner.getTokenValue(); - let pos = scanner.getTokenPos(); + const importPath = scanner.getTokenValue(); + const pos = scanner.getTokenPos(); importedFiles.push({ fileName: importPath, pos: pos, @@ -2213,7 +2212,7 @@ namespace ts { } } else if (token === SyntaxKind.EqualsToken) { - if (tryConsumeRequireCall(/* skipCurrentToken */ true)) { + if (tryConsumeRequireCall(/*skipCurrentToken*/ true)) { return true; } } @@ -2311,7 +2310,7 @@ namespace ts { if (token === SyntaxKind.Identifier || isKeyword(token)) { token = scanner.scan(); if (token === SyntaxKind.EqualsToken) { - if (tryConsumeRequireCall(/* skipCurrentToken */ true)) { + if (tryConsumeRequireCall(/*skipCurrentToken*/ true)) { return true; } } @@ -2410,7 +2409,7 @@ namespace ts { if (tryConsumeDeclare() || tryConsumeImport() || tryConsumeExport() || - (detectJavaScriptImports && (tryConsumeRequireCall(/* skipCurrentToken */ false) || tryConsumeDefine()))) { + (detectJavaScriptImports && (tryConsumeRequireCall(/*skipCurrentToken*/ false) || tryConsumeDefine()))) { continue; } else { @@ -2550,8 +2549,8 @@ namespace ts { return true; } else if (position === comment.end) { - let text = sourceFile.text; - let width = comment.end - comment.pos; + const text = sourceFile.text; + const width = comment.end - comment.pos; // is single line comment or just /* if (width <= 2 || text.charCodeAt(comment.pos + 1) === CharacterCodes.slash) { return true; @@ -2583,7 +2582,7 @@ namespace ts { } // A cache of completion entries for keywords, these do not change between sessions - let keywordCompletions: CompletionEntry[] = []; + const keywordCompletions: CompletionEntry[] = []; for (let i = SyntaxKind.FirstKeyword; i <= SyntaxKind.LastKeyword; i++) { keywordCompletions.push({ name: tokenToString(i), @@ -2673,15 +2672,15 @@ namespace ts { export function createLanguageService(host: LanguageServiceHost, documentRegistry: DocumentRegistry = createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames(), host.getCurrentDirectory())): LanguageService { - let syntaxTreeCache: SyntaxTreeCache = new SyntaxTreeCache(host); + const syntaxTreeCache: SyntaxTreeCache = new SyntaxTreeCache(host); let ruleProvider: formatting.RulesProvider; let program: Program; let lastProjectVersion: string; - let useCaseSensitivefileNames = false; - let cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken()); + const useCaseSensitivefileNames = false; + const cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken()); - let currentDirectory = host.getCurrentDirectory(); + const currentDirectory = host.getCurrentDirectory(); // Check if the localized messages json is set, otherwise query the host for it if (!localizedDiagnosticMessages && host.getLocalizedDiagnosticMessages) { localizedDiagnosticMessages = host.getLocalizedDiagnosticMessages(); @@ -2693,10 +2692,10 @@ namespace ts { } } - let getCanonicalFileName = createGetCanonicalFileName(useCaseSensitivefileNames); + const getCanonicalFileName = createGetCanonicalFileName(useCaseSensitivefileNames); function getValidSourceFile(fileName: string): SourceFile { - let sourceFile = program.getSourceFile(fileName); + const sourceFile = program.getSourceFile(fileName); if (!sourceFile) { throw new Error("Could not find file: '" + fileName + "'."); } @@ -2716,7 +2715,7 @@ namespace ts { function synchronizeHostData(): void { // perform fast check if host supports it if (host.getProjectVersion) { - let hostProjectVersion = host.getProjectVersion(); + const hostProjectVersion = host.getProjectVersion(); if (hostProjectVersion) { if (lastProjectVersion === hostProjectVersion) { return; @@ -2740,17 +2739,17 @@ namespace ts { // the program points to old source files that have been invalidated because of // incremental parsing. - let oldSettings = program && program.getCompilerOptions(); - let newSettings = hostCache.compilationSettings(); - let changesInCompilationSettingsAffectSyntax = oldSettings && + const oldSettings = program && program.getCompilerOptions(); + const newSettings = hostCache.compilationSettings(); + const changesInCompilationSettingsAffectSyntax = oldSettings && (oldSettings.target !== newSettings.target || oldSettings.module !== newSettings.module || oldSettings.noResolve !== newSettings.noResolve || - oldSettings.jsx !== newSettings.jsx || + oldSettings.jsx !== newSettings.jsx || oldSettings.allowJs !== newSettings.allowJs); // Now create a new compiler - let compilerHost: CompilerHost = { + const compilerHost: CompilerHost = { getSourceFile: getOrCreateSourceFile, getCancellationToken: () => cancellationToken, getCanonicalFileName, @@ -2766,22 +2765,22 @@ namespace ts { }, readFile: (fileName): string => { // stub missing host functionality - let entry = hostCache.getOrCreateEntry(fileName); + const entry = hostCache.getOrCreateEntry(fileName); return entry && entry.scriptSnapshot.getText(0, entry.scriptSnapshot.getLength()); } }; if (host.resolveModuleNames) { - compilerHost.resolveModuleNames = (moduleNames, containingFile) => host.resolveModuleNames(moduleNames, containingFile) + compilerHost.resolveModuleNames = (moduleNames, containingFile) => host.resolveModuleNames(moduleNames, containingFile); } - let newProgram = createProgram(hostCache.getRootFileNames(), newSettings, compilerHost, program); + const newProgram = createProgram(hostCache.getRootFileNames(), newSettings, compilerHost, program); // Release any files we have acquired in the old program but are // not part of the new program. if (program) { - let oldSourceFiles = program.getSourceFiles(); - for (let oldSourceFile of oldSourceFiles) { + const oldSourceFiles = program.getSourceFiles(); + for (const oldSourceFile of oldSourceFiles) { if (!newProgram.getSourceFile(oldSourceFile.fileName) || changesInCompilationSettingsAffectSyntax) { documentRegistry.releaseDocument(oldSourceFile.fileName, oldSettings); } @@ -2804,7 +2803,7 @@ namespace ts { // The program is asking for this file, check first if the host can locate it. // If the host can not locate the file, then it does not exist. return undefined // to the program to allow reporting of errors for missing files. - let hostFileInformation = hostCache.getOrCreateEntry(fileName); + const hostFileInformation = hostCache.getOrCreateEntry(fileName); if (!hostFileInformation) { return undefined; } @@ -2814,7 +2813,7 @@ namespace ts { // can not be reused. we have to dump all syntax trees and create new ones. if (!changesInCompilationSettingsAffectSyntax) { // Check if the old program had this file already - let oldSourceFile = program && program.getSourceFile(fileName); + const oldSourceFile = program && program.getSourceFile(fileName); if (oldSourceFile) { // We already had a source file for this file name. Go to the registry to // ensure that we get the right up to date version of it. We need this to @@ -2851,7 +2850,7 @@ namespace ts { if (!sourceFile) { return false; } - let path = sourceFile.path || toPath(sourceFile.fileName, currentDirectory, getCanonicalFileName); + const path = sourceFile.path || toPath(sourceFile.fileName, currentDirectory, getCanonicalFileName); return sourceFile.version === hostCache.getVersion(path); } @@ -2862,13 +2861,13 @@ namespace ts { } // If number of files in the program do not match, it is not up-to-date - let rootFileNames = hostCache.getRootFileNames(); + const rootFileNames = hostCache.getRootFileNames(); if (program.getSourceFiles().length !== rootFileNames.length) { return false; } // If any file is not up-to-date, then the whole program is not up-to-date - for (let fileName of rootFileNames) { + for (const fileName of rootFileNames) { if (!sourceFileUpToDate(program.getSourceFile(fileName))) { return false; } @@ -2910,18 +2909,18 @@ namespace ts { function getSemanticDiagnostics(fileName: string): Diagnostic[] { synchronizeHostData(); - let targetSourceFile = getValidSourceFile(fileName); + const targetSourceFile = getValidSourceFile(fileName); // Only perform the action per file regardless of '-out' flag as LanguageServiceHost is expected to call this function per file. // Therefore only get diagnostics for given file. - let semanticDiagnostics = program.getSemanticDiagnostics(targetSourceFile, cancellationToken); + const semanticDiagnostics = program.getSemanticDiagnostics(targetSourceFile, cancellationToken); if (!program.getCompilerOptions().declaration) { return semanticDiagnostics; } // If '-d' is enabled, check for emitter error. One example of emitter error is export class implements non-export interface - let declarationDiagnostics = program.getDeclarationDiagnostics(targetSourceFile, cancellationToken); + const declarationDiagnostics = program.getDeclarationDiagnostics(targetSourceFile, cancellationToken); return concatenate(semanticDiagnostics, declarationDiagnostics); } @@ -2937,14 +2936,14 @@ namespace ts { * @return undefined if the name is of external module otherwise a name with striped of any quote */ function getCompletionEntryDisplayNameForSymbol(symbol: Symbol, target: ScriptTarget, performCharacterChecks: boolean, location: Node): string { - let displayName: string = getDeclaredName(program.getTypeChecker(), symbol, location); + const displayName: string = getDeclaredName(program.getTypeChecker(), symbol, location); if (displayName) { - let firstCharCode = displayName.charCodeAt(0); + const firstCharCode = displayName.charCodeAt(0); // First check of the displayName is not external module; if it is an external module, it is not valid entry if ((symbol.flags & SymbolFlags.Namespace) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) { // If the symbol is external module, don't show it in the completion list - // (i.e declare module "http" { let x; } | // <= request completion here, "http" should not be there) + // (i.e declare module "http" { const x; } | // <= request completion here, "http" should not be there) return undefined; } } @@ -2987,20 +2986,19 @@ namespace ts { } function getCompletionData(fileName: string, position: number) { - let typeChecker = program.getTypeChecker(); - let syntacticStart = new Date().getTime(); - let sourceFile = getValidSourceFile(fileName); - let isJavaScriptFile = isSourceFileJavaScript(sourceFile); + const typeChecker = program.getTypeChecker(); + const sourceFile = getValidSourceFile(fileName); + const isJavaScriptFile = isSourceFileJavaScript(sourceFile); let isJsDocTagName = false; let start = new Date().getTime(); - let currentToken = getTokenAtPosition(sourceFile, position); + const currentToken = getTokenAtPosition(sourceFile, position); log("getCompletionData: Get current token: " + (new Date().getTime() - start)); start = new Date().getTime(); // Completion not allowed inside comments, bail out if this is the case - let insideComment = isInsideComment(sourceFile, currentToken, position); + const insideComment = isInsideComment(sourceFile, currentToken, position); log("getCompletionData: Is inside comment: " + (new Date().getTime() - start)); if (insideComment) { @@ -3014,7 +3012,7 @@ namespace ts { // /** @type {number | string} */ // Completion should work in the brackets let insideJsDocTagExpression = false; - let tag = getJsDocTagAtPosition(sourceFile, position); + const tag = getJsDocTagAtPosition(sourceFile, position); if (tag) { if (tag.tagName.pos <= position && position <= tag.tagName.end) { isJsDocTagName = true; @@ -3024,7 +3022,7 @@ namespace ts { case SyntaxKind.JSDocTypeTag: case SyntaxKind.JSDocParameterTag: case SyntaxKind.JSDocReturnTag: - let tagWithExpression = tag; + const tagWithExpression = tag; if (tagWithExpression.typeExpression) { insideJsDocTagExpression = tagWithExpression.typeExpression.pos < position && position < tagWithExpression.typeExpression.end; } @@ -3045,7 +3043,7 @@ namespace ts { } start = new Date().getTime(); - let previousToken = findPrecedingToken(position, sourceFile); + const previousToken = findPrecedingToken(position, sourceFile); log("getCompletionData: Get previous token 1: " + (new Date().getTime() - start)); // The decision to provide completion depends on the contextToken, which is determined through the previousToken. @@ -3055,7 +3053,7 @@ namespace 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 && isWord(contextToken.kind)) { - let start = new Date().getTime(); + const start = new Date().getTime(); contextToken = findPrecedingToken(contextToken.getFullStart(), sourceFile); log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start)); } @@ -3076,7 +3074,7 @@ namespace ts { return undefined; } - let { parent, kind } = contextToken; + const { parent, kind } = contextToken; if (kind === SyntaxKind.DotToken) { if (parent.kind === SyntaxKind.PropertyAccessExpression) { node = (contextToken.parent).expression; @@ -3103,7 +3101,7 @@ namespace ts { } } - let semanticStart = new Date().getTime(); + const semanticStart = new Date().getTime(); let isMemberCompletion: boolean; let isNewIdentifierLocation: boolean; let symbols: Symbol[] = []; @@ -3112,7 +3110,7 @@ namespace ts { getTypeScriptMemberSymbols(); } else if (isRightOfOpenTag) { - let tagSymbols = typeChecker.getJsxIntrinsicTagNames(); + const tagSymbols = typeChecker.getJsxIntrinsicTagNames(); if (tryGetGlobalSymbols()) { symbols = tagSymbols.concat(symbols.filter(s => !!(s.flags & SymbolFlags.Value))); } @@ -3123,7 +3121,7 @@ namespace ts { isNewIdentifierLocation = false; } else if (isStartingCloseTag) { - let tagName = (contextToken.parent.parent).openingElement.tagName; + const tagName = (contextToken.parent.parent).openingElement.tagName; symbols = [typeChecker.getSymbolAtLocation(tagName)]; isMemberCompletion = true; @@ -3157,7 +3155,7 @@ namespace ts { if (symbol && symbol.flags & SymbolFlags.HasExports) { // Extract module or enum members - let exportedSymbols = typeChecker.getExportsOfModule(symbol); + const exportedSymbols = typeChecker.getExportsOfModule(symbol); forEach(exportedSymbols, symbol => { if (typeChecker.isValidPropertyAccess((node.parent), symbol.name)) { symbols.push(symbol); @@ -3166,14 +3164,14 @@ namespace ts { } } - let type = typeChecker.getTypeAtLocation(node); + const type = typeChecker.getTypeAtLocation(node); addTypeProperties(type); } function addTypeProperties(type: Type) { if (type) { // Filter private properties - for (let symbol of type.getApparentProperties()) { + for (const symbol of type.getApparentProperties()) { if (typeChecker.isValidPropertyAccess((node.parent), symbol.name)) { symbols.push(symbol); } @@ -3185,8 +3183,8 @@ namespace ts { // each individual type has. This is because we're going to add all identifiers // anyways. So we might as well elevate the members that were at least part // of the individual types to a higher status since we know what they are. - let unionType = type; - for (let elementType of unionType.types) { + const unionType = type; + for (const elementType of unionType.types) { addTypeProperties(elementType); } } @@ -3256,14 +3254,14 @@ namespace ts { // - 'contextToken' was adjusted to the token prior to 'previousToken' // because we were at the end of an identifier. // - 'previousToken' is defined. - let adjustedPosition = previousToken !== contextToken ? + const adjustedPosition = previousToken !== contextToken ? previousToken.getStart() : position; - let scopeNode = getScopeNode(contextToken, adjustedPosition, sourceFile) || sourceFile; + const scopeNode = getScopeNode(contextToken, adjustedPosition, sourceFile) || sourceFile; /// TODO filter meaning based on the current context - let symbolMeanings = SymbolFlags.Type | SymbolFlags.Value | SymbolFlags.Namespace | SymbolFlags.Alias; + const symbolMeanings = SymbolFlags.Type | SymbolFlags.Value | SymbolFlags.Namespace | SymbolFlags.Alias; symbols = typeChecker.getSymbolsInScope(scopeNode, symbolMeanings); return true; @@ -3282,8 +3280,8 @@ namespace ts { } function isCompletionListBlocker(contextToken: Node): boolean { - let start = new Date().getTime(); - let result = isInStringOrRegularExpressionOrTemplateLiteral(contextToken) || + const start = new Date().getTime(); + const result = isInStringOrRegularExpressionOrTemplateLiteral(contextToken) || isSolelyIdentifierDefinitionLocation(contextToken) || isDotOfNumericLiteral(contextToken) || isInJsxText(contextToken); @@ -3310,27 +3308,27 @@ namespace ts { function isNewIdentifierDefinitionLocation(previousToken: Node): boolean { if (previousToken) { - let containingNodeKind = previousToken.parent.kind; + const containingNodeKind = previousToken.parent.kind; switch (previousToken.kind) { case SyntaxKind.CommaToken: return containingNodeKind === SyntaxKind.CallExpression // func( a, | || containingNodeKind === SyntaxKind.Constructor // constructor( a, | /* public, protected, private keywords are allowed here, so show completion */ || containingNodeKind === SyntaxKind.NewExpression // new C(a, | || containingNodeKind === SyntaxKind.ArrayLiteralExpression // [a, | - || containingNodeKind === SyntaxKind.BinaryExpression // let x = (a, | + || containingNodeKind === SyntaxKind.BinaryExpression // const x = (a, | || containingNodeKind === SyntaxKind.FunctionType; // var x: (s: string, list| case SyntaxKind.OpenParenToken: return containingNodeKind === SyntaxKind.CallExpression // func( | || containingNodeKind === SyntaxKind.Constructor // constructor( | || containingNodeKind === SyntaxKind.NewExpression // new C(a| - || containingNodeKind === SyntaxKind.ParenthesizedExpression // let x = (a| + || containingNodeKind === SyntaxKind.ParenthesizedExpression // const x = (a| || containingNodeKind === SyntaxKind.ParenthesizedType; // function F(pred: (a| /* this can become an arrow function, where 'a' is the argument */ case SyntaxKind.OpenBracketToken: return containingNodeKind === SyntaxKind.ArrayLiteralExpression // [ | || containingNodeKind === SyntaxKind.IndexSignature // [ | : string ] - || containingNodeKind === SyntaxKind.ComputedPropertyName // [ | /* this can become an index signature */ + || containingNodeKind === SyntaxKind.ComputedPropertyName; // [ | /* this can become an index signature */ case SyntaxKind.ModuleKeyword: // module | case SyntaxKind.NamespaceKeyword: // namespace | @@ -3343,7 +3341,7 @@ namespace ts { return containingNodeKind === SyntaxKind.ClassDeclaration; // class A{ | case SyntaxKind.EqualsToken: - return containingNodeKind === SyntaxKind.VariableDeclaration // let x = a| + return containingNodeKind === SyntaxKind.VariableDeclaration // const x = a| || containingNodeKind === SyntaxKind.BinaryExpression; // x = a| case SyntaxKind.TemplateHead: @@ -3375,8 +3373,8 @@ namespace ts { || contextToken.kind === SyntaxKind.StringLiteralType || contextToken.kind === SyntaxKind.RegularExpressionLiteral || isTemplateLiteralKind(contextToken.kind)) { - let start = contextToken.getStart(); - let end = contextToken.getEnd(); + const start = contextToken.getStart(); + const end = contextToken.getEnd(); // To be "in" one of these literals, the position has to be: // 1. entirely within the token text. @@ -3420,7 +3418,7 @@ namespace ts { // We are *only* completing on properties from the type being destructured. isNewIdentifierLocation = false; - let rootDeclaration = getRootDeclaration(objectLikeContainer.parent); + const rootDeclaration = getRootDeclaration(objectLikeContainer.parent); if (isVariableLike(rootDeclaration)) { // We don't want to complete using the type acquired by the shape // of the binding pattern; we are only interested in types acquired @@ -3431,7 +3429,7 @@ namespace ts { } } else { - Debug.fail("Root declaration is not variable-like.") + Debug.fail("Root declaration is not variable-like."); } } else { @@ -3442,7 +3440,7 @@ namespace ts { return false; } - let typeMembers = typeChecker.getPropertiesOfType(typeForObject); + const typeMembers = typeChecker.getPropertiesOfType(typeForObject); if (typeMembers && typeMembers.length > 0) { // Add filtered items to the completion list symbols = filterObjectMembersList(typeMembers, existingMembers); @@ -3466,11 +3464,11 @@ namespace ts { * @returns true if 'symbols' was successfully populated; false otherwise. */ function tryGetImportOrExportClauseCompletionSymbols(namedImportsOrExports: NamedImportsOrExports): boolean { - let declarationKind = namedImportsOrExports.kind === SyntaxKind.NamedImports ? + const declarationKind = namedImportsOrExports.kind === SyntaxKind.NamedImports ? SyntaxKind.ImportDeclaration : SyntaxKind.ExportDeclaration; - let importOrExportDeclaration = getAncestor(namedImportsOrExports, declarationKind); - let moduleSpecifier = importOrExportDeclaration.moduleSpecifier; + const importOrExportDeclaration = getAncestor(namedImportsOrExports, declarationKind); + const moduleSpecifier = importOrExportDeclaration.moduleSpecifier; if (!moduleSpecifier) { return false; @@ -3480,7 +3478,7 @@ namespace ts { isNewIdentifierLocation = false; let exports: Symbol[]; - let moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(importOrExportDeclaration.moduleSpecifier); + const moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(importOrExportDeclaration.moduleSpecifier); if (moduleSpecifierSymbol) { exports = typeChecker.getExportsOfModule(moduleSpecifierSymbol); } @@ -3497,9 +3495,9 @@ namespace ts { function tryGetObjectLikeCompletionContainer(contextToken: Node): ObjectLiteralExpression | BindingPattern { if (contextToken) { switch (contextToken.kind) { - case SyntaxKind.OpenBraceToken: // let x = { | - case SyntaxKind.CommaToken: // let x = { a: 0, | - let parent = contextToken.parent; + case SyntaxKind.OpenBraceToken: // const x = { | + case SyntaxKind.CommaToken: // const x = { a: 0, | + const parent = contextToken.parent; if (parent && (parent.kind === SyntaxKind.ObjectLiteralExpression || parent.kind === SyntaxKind.ObjectBindingPattern)) { return parent; } @@ -3532,8 +3530,8 @@ namespace ts { function tryGetContainingJsxElement(contextToken: Node): JsxOpeningLikeElement { if (contextToken) { - let parent = contextToken.parent; - switch(contextToken.kind) { + const parent = contextToken.parent; + switch (contextToken.kind) { case SyntaxKind.LessThanSlashToken: case SyntaxKind.SlashToken: case SyntaxKind.Identifier: @@ -3596,7 +3594,7 @@ namespace ts { * @returns true if we are certain that the currently edited location must define a new location; false otherwise. */ function isSolelyIdentifierDefinitionLocation(contextToken: Node): boolean { - let containingNodeKind = contextToken.parent.kind; + const containingNodeKind = contextToken.parent.kind; switch (contextToken.kind) { case SyntaxKind.CommaToken: return containingNodeKind === SyntaxKind.VariableDeclaration || @@ -3626,13 +3624,13 @@ namespace ts { case SyntaxKind.OpenBraceToken: return containingNodeKind === SyntaxKind.EnumDeclaration || // enum a { | containingNodeKind === SyntaxKind.InterfaceDeclaration || // interface a { | - containingNodeKind === SyntaxKind.TypeLiteral; // let x : { | + containingNodeKind === SyntaxKind.TypeLiteral; // const x : { | case SyntaxKind.SemicolonToken: return containingNodeKind === SyntaxKind.PropertySignature && contextToken.parent && contextToken.parent.parent && (contextToken.parent.parent.kind === SyntaxKind.InterfaceDeclaration || // interface a { f; | - contextToken.parent.parent.kind === SyntaxKind.TypeLiteral); // let x : { a; | + contextToken.parent.parent.kind === SyntaxKind.TypeLiteral); // const x : { a; | case SyntaxKind.LessThanToken: return containingNodeKind === SyntaxKind.ClassDeclaration || // class A< | @@ -3699,7 +3697,7 @@ namespace ts { function isDotOfNumericLiteral(contextToken: Node): boolean { if (contextToken.kind === SyntaxKind.NumericLiteral) { - let text = contextToken.getFullText(); + const text = contextToken.getFullText(); return text.charAt(text.length - 1) === "."; } @@ -3716,15 +3714,15 @@ namespace ts { * do not occur at the current position and have not otherwise been typed. */ function filterNamedImportOrExportCompletionItems(exportsOfModule: Symbol[], namedImportsOrExports: ImportOrExportSpecifier[]): Symbol[] { - let exisingImportsOrExports: Map = {}; + const exisingImportsOrExports: Map = {}; - for (let element of namedImportsOrExports) { + for (const element of namedImportsOrExports) { // If this is the current item we are editing right now, do not filter it out if (element.getStart() <= position && position <= element.getEnd()) { continue; } - let name = element.propertyName || element.name; + const name = element.propertyName || element.name; exisingImportsOrExports[name.text] = true; } @@ -3746,8 +3744,8 @@ namespace ts { return contextualMemberSymbols; } - let existingMemberNames: Map = {}; - for (let m of existingMembers) { + const existingMemberNames: Map = {}; + for (const m of existingMembers) { // Ignore omitted expressions for missing members if (m.kind !== SyntaxKind.PropertyAssignment && m.kind !== SyntaxKind.ShorthandPropertyAssignment && @@ -3766,7 +3764,7 @@ namespace ts { if (m.kind === SyntaxKind.BindingElement && (m).propertyName) { // include only identifiers in completion list if ((m).propertyName.kind === SyntaxKind.Identifier) { - existingName = ((m).propertyName).text + existingName = ((m).propertyName).text; } } else { @@ -3789,8 +3787,8 @@ namespace ts { * do not occur at the current position and have not otherwise been typed. */ function filterJsxAttributes(symbols: Symbol[], attributes: NodeArray): Symbol[] { - let seenNames: Map = {}; - for (let attr of attributes) { + const seenNames: Map = {}; + for (const attr of attributes) { // If this is the current item we are editing right now, do not filter it out if (attr.getStart() <= position && position <= attr.getEnd()) { continue; @@ -3809,21 +3807,21 @@ namespace ts { function getCompletionsAtPosition(fileName: string, position: number): CompletionInfo { synchronizeHostData(); - let completionData = getCompletionData(fileName, position); + const completionData = getCompletionData(fileName, position); if (!completionData) { return undefined; } - let { symbols, isMemberCompletion, isNewIdentifierLocation, location, isRightOfDot, isJsDocTagName } = completionData; + const { symbols, isMemberCompletion, isNewIdentifierLocation, location, isRightOfDot, isJsDocTagName } = completionData; if (isJsDocTagName) { // If the current position is a jsDoc tag name, only tag names should be provided for completion return { isMemberCompletion: false, isNewIdentifierLocation: false, entries: getAllJsDocCompletionEntries() }; } - let sourceFile = getValidSourceFile(fileName); + const sourceFile = getValidSourceFile(fileName); - let entries: CompletionEntry[] = []; + const entries: CompletionEntry[] = []; if (isRightOfDot && isSourceFileJavaScript(sourceFile)) { const uniqueNames = getCompletionEntriesFromSymbols(symbols, entries); @@ -3845,16 +3843,16 @@ namespace ts { return { isMemberCompletion, isNewIdentifierLocation, entries }; function getJavaScriptCompletionEntries(sourceFile: SourceFile, uniqueNames: Map): CompletionEntry[] { - let entries: CompletionEntry[] = []; - let target = program.getCompilerOptions().target; + const entries: CompletionEntry[] = []; + const target = program.getCompilerOptions().target; - let nameTable = getNameTable(sourceFile); - for (let name in nameTable) { + const nameTable = getNameTable(sourceFile); + for (const name in nameTable) { if (!uniqueNames[name]) { uniqueNames[name] = name; - let displayName = getCompletionEntryDisplayName(name, target, /*performCharacterChecks:*/ true); + const displayName = getCompletionEntryDisplayName(name, target, /*performCharacterChecks*/ true); if (displayName) { - let entry = { + const entry = { name: displayName, kind: ScriptElementKind.warning, kindModifiers: "", @@ -3875,7 +3873,7 @@ namespace ts { kind: ScriptElementKind.keyword, kindModifiers: "", sortText: "0", - } + }; })); } @@ -3883,7 +3881,7 @@ namespace ts { // Try to get a valid display name for this symbol, if we could not find one, then ignore it. // We would like to only show things that can be added after a dot, so for instance numeric properties can // not be accessed with a dot (a.1 <- invalid) - let displayName = getCompletionEntryDisplayNameForSymbol(symbol, program.getCompilerOptions().target, /*performCharacterChecks:*/ true, location); + const displayName = getCompletionEntryDisplayNameForSymbol(symbol, program.getCompilerOptions().target, /*performCharacterChecks*/ true, location); if (!displayName) { return undefined; } @@ -3905,13 +3903,13 @@ namespace ts { } function getCompletionEntriesFromSymbols(symbols: Symbol[], entries: CompletionEntry[]): Map { - let start = new Date().getTime(); - let uniqueNames: Map = {}; + const start = new Date().getTime(); + const uniqueNames: Map = {}; if (symbols) { - for (let symbol of symbols) { - let entry = createCompletionEntry(symbol, location); + for (const symbol of symbols) { + const entry = createCompletionEntry(symbol, location); if (entry) { - let id = escapeIdentifier(entry.name); + const id = escapeIdentifier(entry.name); if (!lookUp(uniqueNames, id)) { entries.push(entry); uniqueNames[id] = id; @@ -3929,19 +3927,19 @@ namespace ts { synchronizeHostData(); // Compute all the completion symbols again. - let completionData = getCompletionData(fileName, position); + const completionData = getCompletionData(fileName, position); if (completionData) { - let { symbols, location } = completionData; + const { symbols, location } = completionData; // Find the symbol with the matching entry name. - let target = program.getCompilerOptions().target; + const target = program.getCompilerOptions().target; // We don't need to perform character checks here because we're only comparing the // name against 'entryName' (which is known to be good), not building a new // completion entry. - let symbol = forEach(symbols, s => getCompletionEntryDisplayNameForSymbol(s, target, /*performCharacterChecks:*/ false, location) === entryName ? s : undefined); + const symbol = forEach(symbols, s => getCompletionEntryDisplayNameForSymbol(s, target, /*performCharacterChecks*/ false, location) === entryName ? s : undefined); if (symbol) { - let { displayParts, documentation, symbolKind } = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getValidSourceFile(fileName), location, location, SemanticMeaning.All); + const { displayParts, documentation, symbolKind } = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getValidSourceFile(fileName), location, location, SemanticMeaning.All); return { name: entryName, kindModifiers: getSymbolModifiers(symbol), @@ -3953,7 +3951,7 @@ namespace ts { } // Didn't find a symbol with this name. See if we can find a keyword instead. - let keywordCompletion = forEach(keywordCompletions, c => c.name === entryName); + const keywordCompletion = forEach(keywordCompletions, c => c.name === entryName); if (keywordCompletion) { return { name: entryName, @@ -3969,7 +3967,7 @@ namespace ts { // TODO(drosen): use contextual SemanticMeaning. function getSymbolKind(symbol: Symbol, location: Node): string { - let flags = symbol.getFlags(); + const flags = symbol.getFlags(); if (flags & SymbolFlags.Class) return getDeclarationOfKind(symbol, SyntaxKind.ClassExpression) ? ScriptElementKind.localClassElement : ScriptElementKind.classElement; @@ -3978,7 +3976,7 @@ namespace ts { if (flags & SymbolFlags.Interface) return ScriptElementKind.interfaceElement; if (flags & SymbolFlags.TypeParameter) return ScriptElementKind.typeParameterElement; - let result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags, location); + const result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags, location); if (result === ScriptElementKind.unknown) { if (flags & SymbolFlags.TypeParameter) return ScriptElementKind.typeParameterElement; if (flags & SymbolFlags.EnumMember) return ScriptElementKind.variableElement; @@ -3990,7 +3988,7 @@ namespace ts { } function getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol: Symbol, flags: SymbolFlags, location: Node) { - let typeChecker = program.getTypeChecker(); + const typeChecker = program.getTypeChecker(); if (typeChecker.isUndefinedSymbol(symbol)) { return ScriptElementKind.variableElement; @@ -4019,8 +4017,8 @@ namespace ts { if (flags & SymbolFlags.Property) { if (flags & SymbolFlags.SyntheticProperty) { // If union property is result of union of non method (property/accessors/variables), it is labeled as property - let unionPropertyKind = forEach(typeChecker.getRootSymbols(symbol), rootSymbol => { - let rootSymbolFlags = rootSymbol.getFlags(); + const unionPropertyKind = forEach(typeChecker.getRootSymbols(symbol), rootSymbol => { + const rootSymbolFlags = rootSymbol.getFlags(); if (rootSymbolFlags & (SymbolFlags.PropertyOrAccessor | SymbolFlags.Variable)) { return ScriptElementKind.memberVariableElement; } @@ -4028,8 +4026,8 @@ namespace ts { }); if (!unionPropertyKind) { // If this was union of all methods, - //make sure it has call signatures before we can label it as method - let typeOfUnionProperty = typeChecker.getTypeOfSymbolAtLocation(symbol, location); + // make sure it has call signatures before we can label it as method + const typeOfUnionProperty = typeChecker.getTypeOfSymbolAtLocation(symbol, location); if (typeOfUnionProperty.getCallSignatures().length) { return ScriptElementKind.memberFunctionElement; } @@ -4053,11 +4051,11 @@ namespace ts { function getSymbolDisplayPartsDocumentationAndSymbolKind(symbol: Symbol, sourceFile: SourceFile, enclosingDeclaration: Node, location: Node, semanticMeaning = getMeaningFromLocation(location)) { - let typeChecker = program.getTypeChecker(); + const typeChecker = program.getTypeChecker(); - let displayParts: SymbolDisplayPart[] = []; + const displayParts: SymbolDisplayPart[] = []; let documentation: SymbolDisplayPart[]; - let symbolFlags = symbol.flags; + const symbolFlags = symbol.flags; let symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, symbolFlags, location); let hasAddedSymbolInfo: boolean; let type: Type; @@ -4073,7 +4071,7 @@ namespace ts { type = typeChecker.getTypeOfSymbolAtLocation(symbol, location); if (type) { if (location.parent && location.parent.kind === SyntaxKind.PropertyAccessExpression) { - let right = (location.parent).name; + const right = (location.parent).name; // Either the location is on the right of a property access, or on the left and the right is missing if (right === location || (right && right.getFullWidth() === 0)) { location = location.parent; @@ -4090,15 +4088,15 @@ namespace ts { } if (callExpression) { - let candidateSignatures: Signature[] = []; + const candidateSignatures: Signature[] = []; signature = typeChecker.getResolvedSignature(callExpression, candidateSignatures); if (!signature && candidateSignatures.length) { // Use the first candidate: signature = candidateSignatures[0]; } - let useConstructSignatures = callExpression.kind === SyntaxKind.NewExpression || callExpression.expression.kind === SyntaxKind.SuperKeyword; - let allSignatures = useConstructSignatures ? type.getConstructSignatures() : type.getCallSignatures(); + const useConstructSignatures = callExpression.kind === SyntaxKind.NewExpression || callExpression.expression.kind === SyntaxKind.SuperKeyword; + const allSignatures = useConstructSignatures ? type.getConstructSignatures() : type.getCallSignatures(); if (!contains(allSignatures, signature.target) && !contains(allSignatures, signature)) { // Get the first signature if there is one -- allSignatures may contain @@ -4156,8 +4154,8 @@ namespace ts { else if ((isNameOfFunctionDeclaration(location) && !(symbol.flags & SymbolFlags.Accessor)) || // name of function declaration (location.kind === SyntaxKind.ConstructorKeyword && location.parent.kind === SyntaxKind.Constructor)) { // At constructor keyword of constructor declaration // get the signature from the declaration and write it - let functionDeclaration = location.parent; - let allSignatures = functionDeclaration.kind === SyntaxKind.Constructor ? type.getConstructSignatures() : type.getCallSignatures(); + const functionDeclaration = location.parent; + const allSignatures = functionDeclaration.kind === SyntaxKind.Constructor ? type.getConstructSignatures() : type.getCallSignatures(); if (!typeChecker.isImplementationOfOverload(functionDeclaration)) { signature = typeChecker.getSignatureFromDeclaration(functionDeclaration); } @@ -4226,8 +4224,8 @@ namespace ts { } if (symbolFlags & SymbolFlags.Module) { addNewLineIfDisplayPartsExist(); - let declaration = getDeclarationOfKind(symbol, SyntaxKind.ModuleDeclaration); - let isNamespace = declaration && declaration.name && declaration.name.kind === SyntaxKind.Identifier; + const declaration = getDeclarationOfKind(symbol, SyntaxKind.ModuleDeclaration); + const isNamespace = declaration && declaration.name && declaration.name.kind === SyntaxKind.Identifier; displayParts.push(keywordPart(isNamespace ? SyntaxKind.NamespaceKeyword : SyntaxKind.ModuleKeyword)); displayParts.push(spacePart()); addFullSymbolName(symbol); @@ -4279,9 +4277,9 @@ namespace ts { } if (symbolFlags & SymbolFlags.EnumMember) { addPrefixForAnyFunctionOrVar(symbol, "enum member"); - let declaration = symbol.declarations[0]; + const declaration = symbol.declarations[0]; if (declaration.kind === SyntaxKind.EnumMember) { - let constantValue = typeChecker.getConstantValue(declaration); + const constantValue = typeChecker.getConstantValue(declaration); if (constantValue !== undefined) { displayParts.push(spacePart()); displayParts.push(operatorPart(SyntaxKind.EqualsToken)); @@ -4297,7 +4295,7 @@ namespace ts { addFullSymbolName(symbol); ts.forEach(symbol.declarations, declaration => { if (declaration.kind === SyntaxKind.ImportEqualsDeclaration) { - let importEqualsDeclaration = declaration; + const importEqualsDeclaration = declaration; if (isExternalModuleImportEqualsDeclaration(importEqualsDeclaration)) { displayParts.push(spacePart()); displayParts.push(operatorPart(SyntaxKind.EqualsToken)); @@ -4308,7 +4306,7 @@ namespace ts { displayParts.push(punctuationPart(SyntaxKind.CloseParenToken)); } else { - let internalAliasSymbol = typeChecker.getSymbolAtLocation(importEqualsDeclaration.moduleReference); + const internalAliasSymbol = typeChecker.getSymbolAtLocation(importEqualsDeclaration.moduleReference); if (internalAliasSymbol) { displayParts.push(spacePart()); displayParts.push(operatorPart(SyntaxKind.EqualsToken)); @@ -4332,7 +4330,7 @@ namespace ts { displayParts.push(spacePart()); // If the type is type parameter, format it specially if (type.symbol && type.symbol.flags & SymbolFlags.TypeParameter) { - let typeParameterParts = mapToDisplayParts(writer => { + const typeParameterParts = mapToDisplayParts(writer => { typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplay(type, writer, enclosingDeclaration); }); addRange(displayParts, typeParameterParts); @@ -4347,7 +4345,7 @@ namespace ts { symbolFlags & SymbolFlags.Signature || symbolFlags & SymbolFlags.Accessor || symbolKind === ScriptElementKind.memberFunctionElement) { - let allSignatures = type.getCallSignatures(); + const allSignatures = type.getCallSignatures(); addSignatureDisplayParts(allSignatures[0], allSignatures); } } @@ -4370,7 +4368,7 @@ namespace ts { } function addFullSymbolName(symbol: Symbol, enclosingDeclaration?: Node) { - let fullSymbolDisplayParts = symbolToDisplayParts(typeChecker, symbol, enclosingDeclaration || sourceFile, /*meaning*/ undefined, + const fullSymbolDisplayParts = symbolToDisplayParts(typeChecker, symbol, enclosingDeclaration || sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments | SymbolFormatFlags.UseOnlyExternalAliasing); addRange(displayParts, fullSymbolDisplayParts); } @@ -4416,7 +4414,7 @@ namespace ts { } function writeTypeParametersOfSymbol(symbol: Symbol, enclosingDeclaration: Node) { - let typeParameterParts = mapToDisplayParts(writer => { + const typeParameterParts = mapToDisplayParts(writer => { typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaration); }); addRange(displayParts, typeParameterParts); @@ -4426,8 +4424,8 @@ namespace ts { function getQuickInfoAtPosition(fileName: string, position: number): QuickInfo { synchronizeHostData(); - let sourceFile = getValidSourceFile(fileName); - let node = getTouchingPropertyName(sourceFile, position); + const sourceFile = getValidSourceFile(fileName); + const node = getTouchingPropertyName(sourceFile, position); if (!node) { return undefined; } @@ -4436,8 +4434,8 @@ namespace ts { return undefined; } - let typeChecker = program.getTypeChecker(); - let symbol = typeChecker.getSymbolAtLocation(node); + const typeChecker = program.getTypeChecker(); + const symbol = typeChecker.getSymbolAtLocation(node); if (!symbol) { // Try getting just type at this position and show @@ -4449,7 +4447,7 @@ namespace ts { case SyntaxKind.ThisType: case SyntaxKind.SuperKeyword: // For the identifiers/this/super etc get the type at position - let type = typeChecker.getTypeAtLocation(node); + const type = typeChecker.getTypeAtLocation(node); if (type) { return { kind: ScriptElementKind.unknown, @@ -4464,7 +4462,7 @@ namespace ts { return undefined; } - let displayPartsDocumentationsAndKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, sourceFile, getContainerNode(node), node); + const displayPartsDocumentationsAndKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, sourceFile, getContainerNode(node), node); return { kind: displayPartsDocumentationsAndKind.symbolKind, kindModifiers: getSymbolModifiers(symbol), @@ -4486,13 +4484,13 @@ namespace ts { } function getDefinitionFromSymbol(symbol: Symbol, node: Node): DefinitionInfo[] { - let typeChecker = program.getTypeChecker(); - let result: DefinitionInfo[] = []; - let declarations = symbol.getDeclarations(); - let symbolName = typeChecker.symbolToString(symbol); // Do not get scoped name, just the name of the symbol - let symbolKind = getSymbolKind(symbol, node); - let containerSymbol = symbol.parent; - let containerName = containerSymbol ? typeChecker.symbolToString(containerSymbol, node) : ""; + const typeChecker = program.getTypeChecker(); + const result: DefinitionInfo[] = []; + const declarations = symbol.getDeclarations(); + const symbolName = typeChecker.symbolToString(symbol); // Do not get scoped name, just the name of the symbol + const symbolKind = getSymbolKind(symbol, node); + const containerSymbol = symbol.parent; + const containerName = containerSymbol ? typeChecker.symbolToString(containerSymbol, node) : ""; if (!tryAddConstructSignature(symbol, node, symbolKind, symbolName, containerName, result) && !tryAddCallSignature(symbol, node, symbolKind, symbolName, containerName, result)) { @@ -4510,7 +4508,7 @@ namespace ts { if (isNewExpressionTarget(location) || location.kind === SyntaxKind.ConstructorKeyword) { if (symbol.flags & SymbolFlags.Class) { // Find the first class-like declaration and try to get the construct signature. - for (let declaration of symbol.getDeclarations()) { + for (const declaration of symbol.getDeclarations()) { if (isClassLike(declaration)) { return tryAddSignature(declaration.members, /*selectConstructors*/ true, @@ -4535,7 +4533,7 @@ namespace ts { } function tryAddSignature(signatureDeclarations: Declaration[], selectConstructors: boolean, symbolKind: string, symbolName: string, containerName: string, result: DefinitionInfo[]) { - let declarations: Declaration[] = []; + const declarations: Declaration[] = []; let definition: Declaration; forEach(signatureDeclarations, d => { @@ -4563,24 +4561,24 @@ namespace ts { function getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[] { synchronizeHostData(); - let sourceFile = getValidSourceFile(fileName); + const sourceFile = getValidSourceFile(fileName); - let node = getTouchingPropertyName(sourceFile, position); + const node = getTouchingPropertyName(sourceFile, position); if (!node) { return undefined; } // Labels if (isJumpStatementTarget(node)) { - let labelName = (node).text; - let label = getTargetLabel((node.parent), (node).text); + const labelName = (node).text; + const label = getTargetLabel((node.parent), (node).text); return label ? [createDefinitionInfo(label, ScriptElementKind.label, labelName, /*containerName*/ undefined)] : undefined; } /// Triple slash reference comments - let comment = forEach(sourceFile.referencedFiles, r => (r.pos <= position && position < r.end) ? r : undefined); + const comment = forEach(sourceFile.referencedFiles, r => (r.pos <= position && position < r.end) ? r : undefined); if (comment) { - let referenceFile = tryResolveScriptReference(program, sourceFile, comment); + const referenceFile = tryResolveScriptReference(program, sourceFile, comment); if (referenceFile) { return [{ fileName: referenceFile.fileName, @@ -4594,7 +4592,7 @@ namespace ts { return undefined; } - let typeChecker = program.getTypeChecker(); + const typeChecker = program.getTypeChecker(); let symbol = typeChecker.getSymbolAtLocation(node); // Could not find a symbol e.g. node is string or number keyword, @@ -4608,7 +4606,7 @@ namespace ts { // import {A, B} from "mod"; // to jump to the implementation directly. if (symbol.flags & SymbolFlags.Alias) { - let declaration = symbol.declarations[0]; + const declaration = symbol.declarations[0]; if (node.kind === SyntaxKind.Identifier && node.parent === declaration) { symbol = typeChecker.getAliasedSymbol(symbol); } @@ -4620,15 +4618,15 @@ namespace ts { // is performed at the location of property access, we would like to go to definition of the property in the short-hand // assignment. This case and others are handled by the following code. if (node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) { - let shorthandSymbol = typeChecker.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); + const shorthandSymbol = typeChecker.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); if (!shorthandSymbol) { return []; } - let shorthandDeclarations = shorthandSymbol.getDeclarations(); - let shorthandSymbolKind = getSymbolKind(shorthandSymbol, node); - let shorthandSymbolName = typeChecker.symbolToString(shorthandSymbol); - let shorthandContainerName = typeChecker.symbolToString(symbol.parent, node); + const shorthandDeclarations = shorthandSymbol.getDeclarations(); + const shorthandSymbolKind = getSymbolKind(shorthandSymbol, node); + const shorthandSymbolName = typeChecker.symbolToString(shorthandSymbol); + const shorthandContainerName = typeChecker.symbolToString(symbol.parent, node); return map(shorthandDeclarations, declaration => createDefinitionInfo(declaration, shorthandSymbolKind, shorthandSymbolName, shorthandContainerName)); } @@ -4640,27 +4638,27 @@ namespace ts { function getTypeDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[] { synchronizeHostData(); - let sourceFile = getValidSourceFile(fileName); + const sourceFile = getValidSourceFile(fileName); - let node = getTouchingPropertyName(sourceFile, position); + const node = getTouchingPropertyName(sourceFile, position); if (!node) { return undefined; } - let typeChecker = program.getTypeChecker(); + const typeChecker = program.getTypeChecker(); - let symbol = typeChecker.getSymbolAtLocation(node); + const symbol = typeChecker.getSymbolAtLocation(node); if (!symbol) { return undefined; } - let type = typeChecker.getTypeOfSymbolAtLocation(symbol, node); + const type = typeChecker.getTypeOfSymbolAtLocation(symbol, node); if (!type) { return undefined; } if (type.flags & TypeFlags.Union) { - let result: DefinitionInfo[] = []; + const result: DefinitionInfo[] = []; forEach((type).types, t => { if (t.symbol) { addRange(/*to*/ result, /*from*/ getDefinitionFromSymbol(t.symbol, node)); @@ -4680,7 +4678,7 @@ namespace ts { let results = getOccurrencesAtPositionCore(fileName, position); if (results) { - let sourceFile = getCanonicalFileName(normalizeSlashes(fileName)); + const sourceFile = getCanonicalFileName(normalizeSlashes(fileName)); // Get occurrences only supports reporting occurrences for the file queried. So // filter down to that list. @@ -4694,10 +4692,10 @@ namespace ts { synchronizeHostData(); filesToSearch = map(filesToSearch, normalizeSlashes); - let sourceFilesToSearch = filter(program.getSourceFiles(), f => contains(filesToSearch, f.fileName)); - let sourceFile = getValidSourceFile(fileName); + const sourceFilesToSearch = filter(program.getSourceFiles(), f => contains(filesToSearch, f.fileName)); + const sourceFile = getValidSourceFile(fileName); - let node = getTouchingWord(sourceFile, position); + const node = getTouchingWord(sourceFile, position); if (!node) { return undefined; } @@ -4705,8 +4703,8 @@ namespace ts { return getSemanticDocumentHighlights(node) || getSyntacticDocumentHighlights(node); function getHighlightSpanForNode(node: Node): HighlightSpan { - let start = node.getStart(); - let end = node.getEnd(); + const start = node.getStart(); + const end = node.getEnd(); return { fileName: sourceFile.fileName, @@ -4723,7 +4721,7 @@ namespace ts { isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || isNameOfExternalModuleImportOrDeclaration(node)) { - let referencedSymbols = getReferencedSymbolsForNode(node, sourceFilesToSearch, /*findInStrings:*/ false, /*findInComments:*/ false); + const referencedSymbols = getReferencedSymbolsForNode(node, sourceFilesToSearch, /*findInStrings*/ false, /*findInComments*/ false); return convertReferencedSymbols(referencedSymbols); } @@ -4734,11 +4732,11 @@ namespace ts { return undefined; } - let fileNameToDocumentHighlights: Map = {}; - let result: DocumentHighlights[] = []; - for (let referencedSymbol of referencedSymbols) { - for (let referenceEntry of referencedSymbol.references) { - let fileName = referenceEntry.fileName; + const fileNameToDocumentHighlights: Map = {}; + const result: DocumentHighlights[] = []; + for (const referencedSymbol of referencedSymbols) { + for (const referenceEntry of referencedSymbol.references) { + const fileName = referenceEntry.fileName; let documentHighlights = getProperty(fileNameToDocumentHighlights, fileName); if (!documentHighlights) { documentHighlights = { fileName, highlightSpans: [] }; @@ -4759,9 +4757,9 @@ namespace ts { } function getSyntacticDocumentHighlights(node: Node): DocumentHighlights[] { - let fileName = sourceFile.fileName; + const fileName = sourceFile.fileName; - let highlightSpans = getHighlightSpans(node); + const highlightSpans = getHighlightSpans(node); if (!highlightSpans || highlightSpans.length === 0) { return undefined; } @@ -4865,7 +4863,7 @@ namespace ts { * into function boundaries and try-blocks with catch-clauses. */ function aggregateOwnedThrowStatements(node: Node): ThrowStatement[] { - let statementAccumulator: ThrowStatement[] = [] + const statementAccumulator: ThrowStatement[] = []; aggregate(node); return statementAccumulator; @@ -4874,7 +4872,7 @@ namespace ts { statementAccumulator.push(node); } else if (node.kind === SyntaxKind.TryStatement) { - let tryStatement = node; + const tryStatement = node; if (tryStatement.catchClause) { aggregate(tryStatement.catchClause); @@ -4905,7 +4903,7 @@ namespace ts { let child: Node = throwStatement; while (child.parent) { - let parent = child.parent; + const parent = child.parent; if (isFunctionBlock(parent) || parent.kind === SyntaxKind.SourceFile) { return parent; @@ -4914,7 +4912,7 @@ namespace ts { // A throw-statement is only owned by a try-statement if the try-statement has // a catch clause, and if the throw-statement occurs within the try block. if (parent.kind === SyntaxKind.TryStatement) { - let tryStatement = parent; + const tryStatement = parent; if (tryStatement.tryBlock === child && tryStatement.catchClause) { return child; @@ -4928,7 +4926,7 @@ namespace ts { } function aggregateAllBreakAndContinueStatements(node: Node): BreakOrContinueStatement[] { - let statementAccumulator: BreakOrContinueStatement[] = [] + const statementAccumulator: BreakOrContinueStatement[] = []; aggregate(node); return statementAccumulator; @@ -4944,7 +4942,7 @@ namespace ts { } function ownsBreakOrContinueStatement(owner: Node, statement: BreakOrContinueStatement): boolean { - let actualOwner = getBreakOrContinueOwner(statement); + const actualOwner = getBreakOrContinueOwner(statement); return actualOwner && actualOwner === owner; } @@ -4979,7 +4977,7 @@ namespace ts { } function getModifierOccurrences(modifier: SyntaxKind, declaration: Node): HighlightSpan[] { - let container = declaration.parent; + const container = declaration.parent; // Make sure we only highlight the keyword when it makes sense to do so. if (isAccessibilityModifier(modifier)) { @@ -5009,8 +5007,8 @@ namespace ts { return undefined; } - let keywords: Node[] = []; - let modifierFlag: NodeFlags = getFlagFromModifier(modifier); + const keywords: Node[] = []; + const modifierFlag: NodeFlags = getFlagFromModifier(modifier); let nodes: Node[]; switch (container.kind) { @@ -5035,7 +5033,7 @@ namespace ts { // If we're an accessibility modifier, we're in an instance member and should search // the constructor's parameter list for instance members as well. if (modifierFlag & NodeFlags.AccessibilityModifier) { - let constructor = forEach((container).members, member => { + const constructor = forEach((container).members, member => { return member.kind === SyntaxKind.Constructor && member; }); @@ -5048,7 +5046,7 @@ namespace ts { } break; default: - Debug.fail("Invalid container kind.") + Debug.fail("Invalid container kind."); } forEach(nodes, node => { @@ -5091,7 +5089,7 @@ namespace ts { } function getGetAndSetOccurrences(accessorDeclaration: AccessorDeclaration): HighlightSpan[] { - let keywords: Node[] = []; + const keywords: Node[] = []; tryPushAccessorKeyword(accessorDeclaration.symbol, SyntaxKind.GetAccessor); tryPushAccessorKeyword(accessorDeclaration.symbol, SyntaxKind.SetAccessor); @@ -5099,7 +5097,7 @@ namespace ts { return map(keywords, getHighlightSpanForNode); function tryPushAccessorKeyword(accessorSymbol: Symbol, accessorKind: SyntaxKind): void { - let accessor = getDeclarationOfKind(accessorSymbol, accessorKind); + const accessor = getDeclarationOfKind(accessorSymbol, accessorKind); if (accessor) { forEach(accessor.getChildren(), child => pushKeywordIf(keywords, child, SyntaxKind.GetKeyword, SyntaxKind.SetKeyword)); @@ -5108,9 +5106,9 @@ namespace ts { } function getConstructorOccurrences(constructorDeclaration: ConstructorDeclaration): HighlightSpan[] { - let declarations = constructorDeclaration.symbol.getDeclarations() + const declarations = constructorDeclaration.symbol.getDeclarations(); - let keywords: Node[] = []; + const keywords: Node[] = []; forEach(declarations, declaration => { forEach(declaration.getChildren(), token => { @@ -5122,12 +5120,12 @@ namespace ts { } function getLoopBreakContinueOccurrences(loopNode: IterationStatement): HighlightSpan[] { - let keywords: Node[] = []; + const keywords: Node[] = []; if (pushKeywordIf(keywords, loopNode.getFirstToken(), SyntaxKind.ForKeyword, SyntaxKind.WhileKeyword, SyntaxKind.DoKeyword)) { // If we succeeded and got a do-while loop, then start looking for a 'while' keyword. if (loopNode.kind === SyntaxKind.DoStatement) { - let loopTokens = loopNode.getChildren(); + const loopTokens = loopNode.getChildren(); for (let i = loopTokens.length - 1; i >= 0; i--) { if (pushKeywordIf(keywords, loopTokens[i], SyntaxKind.WhileKeyword)) { @@ -5137,7 +5135,7 @@ namespace ts { } } - let breaksAndContinues = aggregateAllBreakAndContinueStatements(loopNode.statement); + const breaksAndContinues = aggregateAllBreakAndContinueStatements(loopNode.statement); forEach(breaksAndContinues, statement => { if (ownsBreakOrContinueStatement(loopNode, statement)) { @@ -5149,7 +5147,7 @@ namespace ts { } function getBreakOrContinueStatementOccurrences(breakOrContinueStatement: BreakOrContinueStatement): HighlightSpan[] { - let owner = getBreakOrContinueOwner(breakOrContinueStatement); + const owner = getBreakOrContinueOwner(breakOrContinueStatement); if (owner) { switch (owner.kind) { @@ -5158,7 +5156,7 @@ namespace ts { case SyntaxKind.ForOfStatement: case SyntaxKind.DoStatement: case SyntaxKind.WhileStatement: - return getLoopBreakContinueOccurrences(owner) + return getLoopBreakContinueOccurrences(owner); case SyntaxKind.SwitchStatement: return getSwitchCaseDefaultOccurrences(owner); @@ -5169,7 +5167,7 @@ namespace ts { } function getSwitchCaseDefaultOccurrences(switchStatement: SwitchStatement): HighlightSpan[] { - let keywords: Node[] = []; + const keywords: Node[] = []; pushKeywordIf(keywords, switchStatement.getFirstToken(), SyntaxKind.SwitchKeyword); @@ -5177,7 +5175,7 @@ namespace ts { forEach(switchStatement.caseBlock.clauses, clause => { pushKeywordIf(keywords, clause.getFirstToken(), SyntaxKind.CaseKeyword, SyntaxKind.DefaultKeyword); - let breaksAndContinues = aggregateAllBreakAndContinueStatements(clause); + const breaksAndContinues = aggregateAllBreakAndContinueStatements(clause); forEach(breaksAndContinues, statement => { if (ownsBreakOrContinueStatement(switchStatement, statement)) { @@ -5190,7 +5188,7 @@ namespace ts { } function getTryCatchFinallyOccurrences(tryStatement: TryStatement): HighlightSpan[] { - let keywords: Node[] = []; + const keywords: Node[] = []; pushKeywordIf(keywords, tryStatement.getFirstToken(), SyntaxKind.TryKeyword); @@ -5199,7 +5197,7 @@ namespace ts { } if (tryStatement.finallyBlock) { - let finallyKeyword = findChildOfKind(tryStatement, SyntaxKind.FinallyKeyword, sourceFile); + const finallyKeyword = findChildOfKind(tryStatement, SyntaxKind.FinallyKeyword, sourceFile); pushKeywordIf(keywords, finallyKeyword, SyntaxKind.FinallyKeyword); } @@ -5207,13 +5205,13 @@ namespace ts { } function getThrowOccurrences(throwStatement: ThrowStatement): HighlightSpan[] { - let owner = getThrowStatementOwner(throwStatement); + const owner = getThrowStatementOwner(throwStatement); if (!owner) { return undefined; } - let keywords: Node[] = []; + const keywords: Node[] = []; forEach(aggregateOwnedThrowStatements(owner), throwStatement => { pushKeywordIf(keywords, throwStatement.getFirstToken(), SyntaxKind.ThrowKeyword); @@ -5231,14 +5229,14 @@ namespace ts { } function getReturnOccurrences(returnStatement: ReturnStatement): HighlightSpan[] { - let func = getContainingFunction(returnStatement); + const func = getContainingFunction(returnStatement); // If we didn't find a containing function with a block body, bail out. if (!(func && hasKind(func.body, SyntaxKind.Block))) { return undefined; } - let keywords: Node[] = [] + const keywords: Node[] = []; forEachReturnStatement(func.body, returnStatement => { pushKeywordIf(keywords, returnStatement.getFirstToken(), SyntaxKind.ReturnKeyword); }); @@ -5252,7 +5250,7 @@ namespace ts { } function getIfElseOccurrences(ifStatement: IfStatement): HighlightSpan[] { - let keywords: Node[] = []; + const keywords: Node[] = []; // Traverse upwards through all parent if-statements linked by their else-branches. while (hasKind(ifStatement.parent, SyntaxKind.IfStatement) && (ifStatement.parent).elseStatement === ifStatement) { @@ -5261,7 +5259,7 @@ namespace ts { // Now traverse back down through the else branches, aggregating if/else keywords of if-statements. while (ifStatement) { - let children = ifStatement.getChildren(); + const children = ifStatement.getChildren(); pushKeywordIf(keywords, children[0], SyntaxKind.IfKeyword); // Generally the 'else' keyword is second-to-last, so we traverse backwards. @@ -5272,20 +5270,20 @@ namespace ts { } if (!hasKind(ifStatement.elseStatement, SyntaxKind.IfStatement)) { - break + break; } ifStatement = ifStatement.elseStatement; } - let result: HighlightSpan[] = []; + const result: HighlightSpan[] = []; // We'd like to highlight else/ifs together if they are only separated by whitespace // (i.e. the keywords are separated by no comments, no newlines). for (let i = 0; i < keywords.length; i++) { if (keywords[i].kind === SyntaxKind.ElseKeyword && i < keywords.length - 1) { - let elseKeyword = keywords[i]; - let ifKeyword = keywords[i + 1]; // this *should* always be an 'if' keyword. + const elseKeyword = keywords[i]; + const ifKeyword = keywords[i + 1]; // this *should* always be an 'if' keyword. let shouldCombindElseAndIf = true; @@ -5328,9 +5326,9 @@ namespace ts { return undefined; } - let result: ReferenceEntry[] = []; - for (let entry of documentHighlights) { - for (let highlightSpan of entry.highlightSpans) { + const result: ReferenceEntry[] = []; + for (const entry of documentHighlights) { + for (const highlightSpan of entry.highlightSpans) { result.push({ fileName: entry.fileName, textSpan: highlightSpan.textSpan, @@ -5348,9 +5346,9 @@ namespace ts { return undefined; } - let referenceEntries: ReferenceEntry[] = []; + const referenceEntries: ReferenceEntry[] = []; - for (let referenceSymbol of referenceSymbols) { + for (const referenceSymbol of referenceSymbols) { addRange(referenceEntries, referenceSymbol.references); } @@ -5358,17 +5356,17 @@ namespace ts { } function findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): RenameLocation[] { - let referencedSymbols = findReferencedSymbols(fileName, position, findInStrings, findInComments); + const referencedSymbols = findReferencedSymbols(fileName, position, findInStrings, findInComments); return convertReferences(referencedSymbols); } function getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[] { - let referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings:*/ false, /*findInComments:*/ false); + const referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings*/ false, /*findInComments*/ false); return convertReferences(referencedSymbols); } - function findReferences(fileName: string, position: number): ReferencedSymbol[]{ - let referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings:*/ false, /*findInComments:*/ false); + function findReferences(fileName: string, position: number): ReferencedSymbol[] { + const referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings*/ false, /*findInComments*/ false); // Only include referenced symbols that have a valid definition. return filter(referencedSymbols, rs => !!rs.definition); @@ -5377,17 +5375,17 @@ namespace ts { function findReferencedSymbols(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): ReferencedSymbol[] { synchronizeHostData(); - let sourceFile = getValidSourceFile(fileName); + const sourceFile = getValidSourceFile(fileName); - let node = getTouchingPropertyName(sourceFile, position); + const node = getTouchingPropertyName(sourceFile, position); if (!node) { return undefined; } if (node.kind !== SyntaxKind.Identifier && // TODO (drosen): This should be enabled in a later release - currently breaks rename. - //node.kind !== SyntaxKind.ThisKeyword && - //node.kind !== SyntaxKind.SuperKeyword && + // node.kind !== SyntaxKind.ThisKeyword && + // node.kind !== SyntaxKind.SuperKeyword && !isLiteralNameOfPropertyDeclarationOrIndexAccess(node) && !isNameOfExternalModuleImportOrDeclaration(node)) { return undefined; @@ -5398,12 +5396,12 @@ namespace ts { } function getReferencedSymbolsForNode(node: Node, sourceFiles: SourceFile[], findInStrings: boolean, findInComments: boolean): ReferencedSymbol[] { - let typeChecker = program.getTypeChecker(); + const typeChecker = program.getTypeChecker(); // Labels if (isLabelName(node)) { if (isJumpStatementTarget(node)) { - let labelDefinition = getTargetLabel((node.parent), (node).text); + const labelDefinition = getTargetLabel((node.parent), (node).text); // if we have a label definition, look within its statement for references, if not, then // the label is undefined and we have no results.. return labelDefinition ? getLabelReferencesInNode(labelDefinition.parent, labelDefinition) : undefined; @@ -5422,7 +5420,7 @@ namespace ts { return getReferencesForSuperKeyword(node); } - let symbol = typeChecker.getSymbolAtLocation(node); + const symbol = typeChecker.getSymbolAtLocation(node); // Could not find a symbol e.g. unknown identifier if (!symbol) { @@ -5430,7 +5428,7 @@ namespace ts { return undefined; } - let declarations = symbol.declarations; + const declarations = symbol.declarations; // The symbol was an internal symbol and does not have a declaration e.g. undefined symbol if (!declarations || !declarations.length) { @@ -5440,29 +5438,29 @@ namespace ts { let result: ReferencedSymbol[]; // Compute the meaning from the location and the symbol it references - let searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), declarations); + const searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), declarations); // Get the text to search for. // Note: if this is an external module symbol, the name doesn't include quotes. - let declaredName = stripQuotes(getDeclaredName(typeChecker, symbol, node)); + const declaredName = stripQuotes(getDeclaredName(typeChecker, symbol, node)); // Try to get the smallest valid scope that we can limit our search to; // otherwise we'll need to search globally (i.e. include each file). - let scope = getSymbolScope(symbol); + const scope = getSymbolScope(symbol); // Maps from a symbol ID to the ReferencedSymbol entry in 'result'. - let symbolToIndex: number[] = []; + const symbolToIndex: number[] = []; if (scope) { result = []; getReferencesInNode(scope, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result, symbolToIndex); } else { - let internedName = getInternedName(symbol, node, declarations) - for (let sourceFile of sourceFiles) { + const internedName = getInternedName(symbol, node, declarations); + for (const sourceFile of sourceFiles) { cancellationToken.throwIfCancellationRequested(); - let nameTable = getNameTable(sourceFile); + const nameTable = getNameTable(sourceFile); if (lookUp(nameTable, internedName)) { result = result || []; @@ -5474,9 +5472,9 @@ namespace ts { return result; function getDefinition(symbol: Symbol): DefinitionInfo { - let info = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, node.getSourceFile(), getContainerNode(node), node); - let name = map(info.displayParts, p => p.text).join(""); - let declarations = symbol.declarations; + const info = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, node.getSourceFile(), getContainerNode(node), node); + const name = map(info.displayParts, p => p.text).join(""); + const declarations = symbol.declarations; if (!declarations || declarations.length === 0) { return undefined; } @@ -5506,7 +5504,7 @@ namespace ts { // Try to get the local symbol if we're dealing with an 'export default' // since that symbol has the "true" name. - let localExportDefaultSymbol = getLocalSymbolForExportDefault(symbol); + const localExportDefaultSymbol = getLocalSymbolForExportDefault(symbol); symbol = localExportDefaultSymbol || symbol; return stripQuotes(symbol.name); @@ -5523,14 +5521,14 @@ namespace ts { function getSymbolScope(symbol: Symbol): Node { // If this is the symbol of a named function expression or named class expression, // then named references are limited to its own scope. - let valueDeclaration = symbol.valueDeclaration; + const valueDeclaration = symbol.valueDeclaration; if (valueDeclaration && (valueDeclaration.kind === SyntaxKind.FunctionExpression || valueDeclaration.kind === SyntaxKind.ClassExpression)) { return valueDeclaration; } // If this is private property or method, the scope is the containing class if (symbol.flags & (SymbolFlags.Property | SymbolFlags.Method)) { - let privateDeclaration = forEach(symbol.getDeclarations(), d => (d.flags & NodeFlags.Private) ? d : undefined); + const privateDeclaration = forEach(symbol.getDeclarations(), d => (d.flags & NodeFlags.Private) ? d : undefined); if (privateDeclaration) { return getAncestor(privateDeclaration, SyntaxKind.ClassDeclaration); } @@ -5548,12 +5546,12 @@ namespace ts { return undefined; } - let scope: Node = undefined; + let scope: Node; - let declarations = symbol.getDeclarations(); + const declarations = symbol.getDeclarations(); if (declarations) { - for (let declaration of declarations) { - let container = getContainerNode(declaration); + for (const declaration of declarations) { + const container = getContainerNode(declaration); if (!container) { return undefined; @@ -5579,7 +5577,7 @@ namespace ts { } function getPossibleSymbolReferencePositions(sourceFile: SourceFile, symbolName: string, start: number, end: number): number[] { - let positions: number[] = []; + const positions: number[] = []; /// TODO: Cache symbol existence for files to save text search // Also, need to make this work for unicode escapes. @@ -5589,9 +5587,9 @@ namespace ts { return positions; } - let text = sourceFile.text; - let sourceLength = text.length; - let symbolNameLength = symbolName.length; + const text = sourceFile.text; + const sourceLength = text.length; + const symbolNameLength = symbolName.length; let position = text.indexOf(symbolName, start); while (position >= 0) { @@ -5602,7 +5600,7 @@ namespace ts { // We found a match. Make sure it's not part of a larger word (i.e. the char // before and after it have to be a non-identifier char). - let endPosition = position + symbolNameLength; + const endPosition = position + symbolNameLength; if ((position === 0 || !isIdentifierPart(text.charCodeAt(position - 1), ScriptTarget.Latest)) && (endPosition === sourceLength || !isIdentifierPart(text.charCodeAt(endPosition), ScriptTarget.Latest))) { @@ -5616,14 +5614,14 @@ namespace ts { } function getLabelReferencesInNode(container: Node, targetLabel: Identifier): ReferencedSymbol[] { - let references: ReferenceEntry[] = []; - let sourceFile = container.getSourceFile(); - let labelName = targetLabel.text; - let possiblePositions = getPossibleSymbolReferencePositions(sourceFile, labelName, container.getStart(), container.getEnd()); + const references: ReferenceEntry[] = []; + const sourceFile = container.getSourceFile(); + const labelName = targetLabel.text; + const possiblePositions = getPossibleSymbolReferencePositions(sourceFile, labelName, container.getStart(), container.getEnd()); forEach(possiblePositions, position => { cancellationToken.throwIfCancellationRequested(); - let node = getTouchingWord(sourceFile, position); + const node = getTouchingWord(sourceFile, position); if (!node || node.getWidth() !== labelName.length) { return; } @@ -5635,14 +5633,14 @@ namespace ts { } }); - let definition: DefinitionInfo = { + const definition: DefinitionInfo = { containerKind: "", containerName: "", fileName: targetLabel.getSourceFile().fileName, kind: ScriptElementKind.label, name: labelName, textSpan: createTextSpanFromBounds(targetLabel.getStart(), targetLabel.getEnd()) - } + }; return [{ definition, references }]; } @@ -5687,19 +5685,19 @@ namespace ts { result: ReferencedSymbol[], symbolToIndex: number[]): void { - let sourceFile = container.getSourceFile(); - let tripleSlashDirectivePrefixRegex = /^\/\/\/\s* { cancellationToken.throwIfCancellationRequested(); - let referenceLocation = getTouchingPropertyName(sourceFile, position); + const referenceLocation = getTouchingPropertyName(sourceFile, position); if (!isValidReferencePosition(referenceLocation, searchText)) { // This wasn't the start of a token. Check to see if it might be a // match in a comment or string if that's what the caller is asking @@ -5727,14 +5725,14 @@ namespace ts { return; } - let referenceSymbol = typeChecker.getSymbolAtLocation(referenceLocation); + const referenceSymbol = typeChecker.getSymbolAtLocation(referenceLocation); if (referenceSymbol) { - let referenceSymbolDeclaration = referenceSymbol.valueDeclaration; - let shorthandValueSymbol = typeChecker.getShorthandAssignmentValueSymbol(referenceSymbolDeclaration); - let relatedSymbol = getRelatedSymbol(searchSymbols, referenceSymbol, referenceLocation); + const referenceSymbolDeclaration = referenceSymbol.valueDeclaration; + const shorthandValueSymbol = typeChecker.getShorthandAssignmentValueSymbol(referenceSymbolDeclaration); + const relatedSymbol = getRelatedSymbol(searchSymbols, referenceSymbol, referenceLocation); if (relatedSymbol) { - let referencedSymbol = getReferencedSymbol(relatedSymbol); + const referencedSymbol = getReferencedSymbol(relatedSymbol); referencedSymbol.references.push(getReferenceEntryFromNode(referenceLocation)); } /* Because in short-hand property assignment, an identifier which stored as name of the short-hand property assignment @@ -5744,7 +5742,7 @@ namespace ts { * position of property accessing, the referenceEntry of such position will be handled in the first case. */ else if (!(referenceSymbol.flags & SymbolFlags.Transient) && searchSymbols.indexOf(shorthandValueSymbol) >= 0) { - let referencedSymbol = getReferencedSymbol(shorthandValueSymbol); + const referencedSymbol = getReferencedSymbol(shorthandValueSymbol); referencedSymbol.references.push(getReferenceEntryFromNode(referenceSymbolDeclaration.name)); } } @@ -5754,7 +5752,7 @@ namespace ts { return; function getReferencedSymbol(symbol: Symbol): ReferencedSymbol { - let symbolId = getSymbolId(symbol); + const symbolId = getSymbolId(symbol); let index = symbolToIndex[symbolId]; if (index === undefined) { index = result.length; @@ -5773,14 +5771,14 @@ namespace ts { return isInCommentHelper(sourceFile, position, isNonReferenceComment); function isNonReferenceComment(c: CommentRange): boolean { - let commentText = sourceFile.text.substring(c.pos, c.end); + const commentText = sourceFile.text.substring(c.pos, c.end); return !tripleSlashDirectivePrefixRegex.test(commentText); } } } function getReferencesForSuperKeyword(superKeyword: Node): ReferencedSymbol[] { - let searchSpaceNode = getSuperContainer(superKeyword, /*includeFunctions*/ false); + let searchSpaceNode = getSuperContainer(superKeyword, /*stopOnFunctions*/ false); if (!searchSpaceNode) { return undefined; } @@ -5802,20 +5800,20 @@ namespace ts { return undefined; } - let references: ReferenceEntry[] = []; + const references: ReferenceEntry[] = []; - let sourceFile = searchSpaceNode.getSourceFile(); - let possiblePositions = getPossibleSymbolReferencePositions(sourceFile, "super", searchSpaceNode.getStart(), searchSpaceNode.getEnd()); + const sourceFile = searchSpaceNode.getSourceFile(); + const possiblePositions = getPossibleSymbolReferencePositions(sourceFile, "super", searchSpaceNode.getStart(), searchSpaceNode.getEnd()); forEach(possiblePositions, position => { cancellationToken.throwIfCancellationRequested(); - let node = getTouchingWord(sourceFile, position); + const node = getTouchingWord(sourceFile, position); if (!node || node.kind !== SyntaxKind.SuperKeyword) { return; } - let container = getSuperContainer(node, /*includeFunctions*/ false); + const container = getSuperContainer(node, /*stopOnFunctions*/ false); // If we have a 'super' container, we must have an enclosing class. // Now make sure the owning class is the same as the search-space @@ -5825,7 +5823,7 @@ namespace ts { } }); - let definition = getDefinition(searchSpaceNode.symbol); + const definition = getDefinition(searchSpaceNode.symbol); return [{ definition, references }]; } @@ -5847,7 +5845,7 @@ namespace ts { case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: - staticFlag &= searchSpaceNode.flags + staticFlag &= searchSpaceNode.flags; searchSpaceNode = searchSpaceNode.parent; // re-assign to be the owning class break; case SyntaxKind.SourceFile: @@ -5864,7 +5862,7 @@ namespace ts { return undefined; } - let references: ReferenceEntry[] = []; + const references: ReferenceEntry[] = []; let possiblePositions: number[]; if (searchSpaceNode.kind === SyntaxKind.SourceFile) { @@ -5874,7 +5872,7 @@ namespace ts { }); } else { - let sourceFile = searchSpaceNode.getSourceFile(); + const sourceFile = searchSpaceNode.getSourceFile(); possiblePositions = getPossibleSymbolReferencePositions(sourceFile, "this", searchSpaceNode.getStart(), searchSpaceNode.getEnd()); getThisReferencesInFile(sourceFile, searchSpaceNode, possiblePositions, references); } @@ -5895,12 +5893,12 @@ namespace ts { forEach(possiblePositions, position => { cancellationToken.throwIfCancellationRequested(); - let node = getTouchingWord(sourceFile, position); + const node = getTouchingWord(sourceFile, position); if (!node || (node.kind !== SyntaxKind.ThisKeyword && node.kind !== SyntaxKind.ThisType)) { return; } - let container = getThisContainer(node, /* includeArrowFunctions */ false); + const container = getThisContainer(node, /* includeArrowFunctions */ false); switch (searchSpaceNode.kind) { case SyntaxKind.FunctionExpression: @@ -5955,18 +5953,27 @@ namespace ts { * property name and variable declaration of the identifier. * Like in below example, when querying for all references for an identifier 'name', of the property assignment, the language service * should show both 'name' in 'obj' and 'name' in variable declaration - * let name = "Foo"; - * let obj = { name }; + * const name = "Foo"; + * const obj = { name }; * In order to do that, we will populate the search set with the value symbol of the identifier as a value of the property assignment * so that when matching with potential reference symbol, both symbols from property declaration and variable declaration * will be included correctly. */ - let shorthandValueSymbol = typeChecker.getShorthandAssignmentValueSymbol(location.parent); + const shorthandValueSymbol = typeChecker.getShorthandAssignmentValueSymbol(location.parent); if (shorthandValueSymbol) { result.push(shorthandValueSymbol); } } + // If the symbol.valueDeclaration is a property parameter declaration, + // we should include both parameter declaration symbol and property declaration symbol + // Parameter Declaration symbol is only visible within function scope, so the symbol is stored in contructor.locals. + // Property Declaration symbol is a member of the class, so the symbol is stored in its class Declaration.symbol.members + if (symbol.valueDeclaration && symbol.valueDeclaration.kind === SyntaxKind.Parameter && + isParameterPropertyDeclaration(symbol.valueDeclaration)) { + result = result.concat(typeChecker.getSymbolsOfParameterPropertyDeclaration(symbol.valueDeclaration, symbol.name)); + } + // If this is a union property, add all the symbols from all its source symbols in all unioned types. // If the symbol is an instantiation from a another symbol (e.g. widened symbol) , add the root the list forEach(typeChecker.getRootSymbols(symbol), rootSymbol => { @@ -5999,9 +6006,9 @@ namespace ts { function getPropertySymbolFromTypeReference(typeReference: ExpressionWithTypeArguments) { if (typeReference) { - let type = typeChecker.getTypeAtLocation(typeReference); + const type = typeChecker.getTypeAtLocation(typeReference); if (type) { - let propertySymbol = typeChecker.getPropertyOfType(type, propertyName); + const propertySymbol = typeChecker.getPropertyOfType(type, propertyName); if (propertySymbol) { result.push(propertySymbol); } @@ -6021,7 +6028,7 @@ namespace ts { // If the reference symbol is an alias, check if what it is aliasing is one of the search // symbols. if (isImportOrExportSpecifierImportSymbol(referenceSymbol)) { - let aliasedSymbol = typeChecker.getAliasedSymbol(referenceSymbol); + const aliasedSymbol = typeChecker.getAliasedSymbol(referenceSymbol); if (searchSymbols.indexOf(aliasedSymbol) >= 0) { return aliasedSymbol; } @@ -6047,7 +6054,7 @@ namespace ts { // Finally, try all properties with the same name in any type the containing type extended or implemented, and // see if any is in the list if (rootSymbol.parent && rootSymbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) { - let result: Symbol[] = []; + const result: Symbol[] = []; getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result); return forEach(result, s => searchSymbols.indexOf(s) >= 0 ? s : undefined); } @@ -6058,21 +6065,21 @@ namespace ts { function getPropertySymbolsFromContextualType(node: Node): Symbol[] { if (isNameOfPropertyAssignment(node)) { - let objectLiteral = node.parent.parent; - let contextualType = typeChecker.getContextualType(objectLiteral); - let name = (node).text; + const objectLiteral = node.parent.parent; + const contextualType = typeChecker.getContextualType(objectLiteral); + const name = (node).text; if (contextualType) { if (contextualType.flags & TypeFlags.Union) { // This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types) // if not, search the constituent types for the property - let unionProperty = contextualType.getProperty(name) + const unionProperty = contextualType.getProperty(name); if (unionProperty) { return [unionProperty]; } else { - let result: Symbol[] = []; + const result: Symbol[] = []; forEach((contextualType).types, t => { - let symbol = t.getProperty(name); + const symbol = t.getProperty(name); if (symbol) { result.push(symbol); } @@ -6081,7 +6088,7 @@ namespace ts { } } else { - let symbol = contextualType.getProperty(name); + const symbol = contextualType.getProperty(name); if (symbol) { return [symbol]; } @@ -6110,8 +6117,8 @@ namespace ts { // Remember the last meaning lastIterationMeaning = meaning; - for (let declaration of declarations) { - let declarationMeaning = getMeaningFromDeclaration(declaration); + for (const declaration of declarations) { + const declarationMeaning = getMeaningFromDeclaration(declaration); if (declarationMeaning & meaning) { meaning |= declarationMeaning; @@ -6146,13 +6153,13 @@ namespace ts { return true; } - let parent = node.parent; + const parent = node.parent; if (parent) { if (parent.kind === SyntaxKind.PostfixUnaryExpression || parent.kind === SyntaxKind.PrefixUnaryExpression) { return true; } else if (parent.kind === SyntaxKind.BinaryExpression && (parent).left === node) { - let operator = (parent).operatorToken.kind; + const operator = (parent).operatorToken.kind; return SyntaxKind.FirstAssignment <= operator && operator <= SyntaxKind.LastAssignment; } } @@ -6167,15 +6174,11 @@ namespace ts { return ts.NavigateTo.getNavigateToItems(program, cancellationToken, searchValue, maxResultCount); } - function containErrors(diagnostics: Diagnostic[]): boolean { - return forEach(diagnostics, diagnostic => diagnostic.category === DiagnosticCategory.Error); - } - function getEmitOutput(fileName: string): EmitOutput { synchronizeHostData(); - let sourceFile = getValidSourceFile(fileName); - let outputFiles: OutputFile[] = []; + const sourceFile = getValidSourceFile(fileName); + const outputFiles: OutputFile[] = []; function writeFile(fileName: string, data: string, writeByteOrderMark: boolean) { outputFiles.push({ @@ -6185,7 +6188,7 @@ namespace ts { }); } - let emitOutput = program.emit(sourceFile, writeFile, cancellationToken); + const emitOutput = program.emit(sourceFile, writeFile, cancellationToken); return { outputFiles, @@ -6278,7 +6281,7 @@ namespace ts { } if (!isLastClause && root.parent.kind === SyntaxKind.ExpressionWithTypeArguments && root.parent.parent.kind === SyntaxKind.HeritageClause) { - let decl = root.parent.parent.parent; + const decl = root.parent.parent.parent; return (decl.kind === SyntaxKind.ClassDeclaration && (root.parent.parent).token === SyntaxKind.ImplementsKeyword) || (decl.kind === SyntaxKind.InterfaceDeclaration && (root.parent.parent).token === SyntaxKind.ExtendsKeyword); } @@ -6350,7 +6353,7 @@ namespace ts { function getSignatureHelpItems(fileName: string, position: number): SignatureHelpItems { synchronizeHostData(); - let sourceFile = getValidSourceFile(fileName); + const sourceFile = getValidSourceFile(fileName); return SignatureHelp.getSignatureHelpItems(program, sourceFile, position, cancellationToken); } @@ -6361,10 +6364,10 @@ namespace ts { } function getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): TextSpan { - let sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); + const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); // Get node at the location - let node = getTouchingPropertyName(sourceFile, startPos); + const node = getTouchingPropertyName(sourceFile, startPos); if (!node) { return; @@ -6420,13 +6423,13 @@ namespace ts { function getBreakpointStatementAtPosition(fileName: string, position: number) { // doesn't use compiler - no need to synchronize with host - let sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); + const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); return BreakpointResolver.spanInSourceFileAtLocation(sourceFile, position); } function getNavigationBarItems(fileName: string): NavigationBarItem[] { - let sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); + const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); return NavigationBar.getNavigationBarItems(sourceFile, host.getCompilationSettings()); } @@ -6458,11 +6461,11 @@ namespace ts { function getEncodedSemanticClassifications(fileName: string, span: TextSpan): Classifications { synchronizeHostData(); - let sourceFile = getValidSourceFile(fileName); - let typeChecker = program.getTypeChecker(); + const sourceFile = getValidSourceFile(fileName); + const typeChecker = program.getTypeChecker(); - let result: number[] = []; - let classifiableNames = program.getClassifiableNames(); + const result: number[] = []; + const classifiableNames = program.getClassifiableNames(); processNode(sourceFile); return { spans: result, endOfLineState: EndOfLineState.None }; @@ -6474,7 +6477,7 @@ namespace ts { } function classifySymbol(symbol: Symbol, meaningAtPosition: SemanticMeaning): ClassificationType { - let flags = symbol.getFlags(); + const flags = symbol.getFlags(); if ((flags & SymbolFlags.Classifiable) === SymbolFlags.None) { return; } @@ -6522,19 +6525,19 @@ namespace ts { function processNode(node: Node) { // Only walk into nodes that intersect the requested span. if (node && textSpanIntersectsWith(span, node.getFullStart(), node.getFullWidth())) { - let kind = node.kind; + const kind = node.kind; checkForClassificationCancellation(kind); if (kind === SyntaxKind.Identifier && !nodeIsMissing(node)) { - let identifier = node; + const identifier = node; // Only bother calling into the typechecker if this is an identifier that // could possibly resolve to a type name. This makes classification run // in a third of the time it would normally take. if (classifiableNames[identifier.text]) { - let symbol = typeChecker.getSymbolAtLocation(node); + const symbol = typeChecker.getSymbolAtLocation(node); if (symbol) { - let type = classifySymbol(symbol, getMeaningFromLocation(node)); + const type = classifySymbol(symbol, getMeaningFromLocation(node)); if (type) { pushClassification(node.getStart(), node.getWidth(), type); } @@ -6574,8 +6577,8 @@ namespace ts { function convertClassifications(classifications: Classifications): ClassifiedSpan[] { Debug.assert(classifications.spans.length % 3 === 0); - let dense = classifications.spans; - let result: ClassifiedSpan[] = []; + const dense = classifications.spans; + const result: ClassifiedSpan[] = []; for (let i = 0, n = dense.length; i < n; i += 3) { result.push({ textSpan: createTextSpan(dense[i], dense[i + 1]), @@ -6592,15 +6595,15 @@ namespace ts { function getEncodedSyntacticClassifications(fileName: string, span: TextSpan): Classifications { // doesn't use compiler - no need to synchronize with host - let sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); - let spanStart = span.start; - let spanLength = span.length; + const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); + const spanStart = span.start; + const spanLength = span.length; // Make a scanner we can get trivia from. - let triviaScanner = createScanner(ScriptTarget.Latest, /*skipTrivia:*/ false, sourceFile.languageVariant, sourceFile.text); - let mergeConflictScanner = createScanner(ScriptTarget.Latest, /*skipTrivia:*/ false, sourceFile.languageVariant, sourceFile.text); + const triviaScanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ false, sourceFile.languageVariant, sourceFile.text); + const mergeConflictScanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ false, sourceFile.languageVariant, sourceFile.text); - let result: number[] = []; + const result: number[] = []; processElement(sourceFile); return { spans: result, endOfLineState: EndOfLineState.None }; @@ -6614,15 +6617,15 @@ namespace ts { function classifyLeadingTriviaAndGetTokenStart(token: Node): number { triviaScanner.setTextPos(token.pos); while (true) { - let start = triviaScanner.getTextPos(); + const start = triviaScanner.getTextPos(); // only bother scanning if we have something that could be trivia. if (!couldStartTrivia(sourceFile.text, start)) { return start; } - let kind = triviaScanner.scan(); - let end = triviaScanner.getTextPos(); - let width = end - start; + const kind = triviaScanner.scan(); + const end = triviaScanner.getTextPos(); + const width = end - start; // The moment we get something that isn't trivia, then stop processing. if (!isTrivia(kind)) { @@ -6646,8 +6649,8 @@ namespace ts { } if (kind === SyntaxKind.ConflictMarkerTrivia) { - let text = sourceFile.text; - let ch = text.charCodeAt(start); + const text = sourceFile.text; + const ch = text.charCodeAt(start); // for the <<<<<<< and >>>>>>> markers, we just add them in as comments // in the classification stream. @@ -6668,7 +6671,7 @@ namespace ts { if (kind === SyntaxKind.MultiLineCommentTrivia) { // See if this is a doc comment. If so, we'll classify certain portions of it // specially. - let docCommentAndDiagnostics = parseIsolatedJSDocComment(sourceFile.text, start, width); + const docCommentAndDiagnostics = parseIsolatedJSDocComment(sourceFile.text, start, width); if (docCommentAndDiagnostics && docCommentAndDiagnostics.jsDocComment) { docCommentAndDiagnostics.jsDocComment.parent = token; classifyJSDocComment(docCommentAndDiagnostics.jsDocComment); @@ -6687,7 +6690,7 @@ namespace ts { function classifyJSDocComment(docComment: JSDocComment) { let pos = docComment.pos; - for (let tag of docComment.tags) { + for (const tag of docComment.tags) { // As we walk through each tag, classify the portion of text from the end of // the last tag (or the start of the entire doc comment) as 'comment'. if (tag.pos !== pos) { @@ -6745,7 +6748,7 @@ namespace ts { } function processJSDocTemplateTag(tag: JSDocTemplateTag) { - for (let child of tag.getChildren()) { + for (const child of tag.getChildren()) { processElement(child); } } @@ -6767,11 +6770,11 @@ namespace ts { } function classifyDisabledCodeToken() { - let start = mergeConflictScanner.getTextPos(); - let tokenKind = mergeConflictScanner.scan(); - let end = mergeConflictScanner.getTextPos(); + const start = mergeConflictScanner.getTextPos(); + const tokenKind = mergeConflictScanner.scan(); + const end = mergeConflictScanner.getTextPos(); - let type = classifyTokenType(tokenKind); + const type = classifyTokenType(tokenKind); if (type) { pushClassification(start, end - start, type); } @@ -6782,12 +6785,12 @@ namespace ts { return; } - let tokenStart = classifyLeadingTriviaAndGetTokenStart(token); + const tokenStart = classifyLeadingTriviaAndGetTokenStart(token); - let tokenWidth = token.end - tokenStart; + const tokenWidth = token.end - tokenStart; Debug.assert(tokenWidth >= 0); if (tokenWidth > 0) { - let type = classifyTokenType(token.kind, token); + const type = classifyTokenType(token.kind, token); if (type) { pushClassification(tokenStart, tokenWidth, type); } @@ -6914,9 +6917,9 @@ namespace ts { if (decodedTextSpanIntersectsWith(spanStart, spanLength, element.pos, element.getFullWidth())) { checkForClassificationCancellation(element.kind); - let children = element.getChildren(sourceFile); + const children = element.getChildren(sourceFile); for (let i = 0, n = children.length; i < n; i++) { - let child = children[i]; + const child = children[i]; if (isToken(child)) { classifyToken(child); } @@ -6931,28 +6934,28 @@ namespace ts { function getOutliningSpans(fileName: string): OutliningSpan[] { // doesn't use compiler - no need to synchronize with host - let sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); + const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); return OutliningElementsCollector.collectElements(sourceFile); } function getBraceMatchingAtPosition(fileName: string, position: number) { - let sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); - let result: TextSpan[] = []; + const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); + const result: TextSpan[] = []; - let token = getTouchingToken(sourceFile, position); + const token = getTouchingToken(sourceFile, position); if (token.getStart(sourceFile) === position) { - let matchKind = getMatchingTokenKind(token); + const matchKind = getMatchingTokenKind(token); // Ensure that there is a corresponding token to match ours. if (matchKind) { - let parentElement = token.parent; + const parentElement = token.parent; - let childNodes = parentElement.getChildren(sourceFile); - for (let current of childNodes) { + const childNodes = parentElement.getChildren(sourceFile); + for (const current of childNodes) { if (current.kind === matchKind) { - let range1 = createTextSpan(token.getStart(sourceFile), token.getWidth(sourceFile)); - let range2 = createTextSpan(current.getStart(sourceFile), current.getWidth(sourceFile)); + const range1 = createTextSpan(token.getStart(sourceFile), token.getWidth(sourceFile)); + const range2 = createTextSpan(current.getStart(sourceFile), current.getWidth(sourceFile)); // We want to order the braces when we return the result. if (range1.start < range2.start) { @@ -6972,11 +6975,11 @@ namespace ts { function getMatchingTokenKind(token: Node): ts.SyntaxKind { switch (token.kind) { - case ts.SyntaxKind.OpenBraceToken: return ts.SyntaxKind.CloseBraceToken + case ts.SyntaxKind.OpenBraceToken: return ts.SyntaxKind.CloseBraceToken; case ts.SyntaxKind.OpenParenToken: return ts.SyntaxKind.CloseParenToken; case ts.SyntaxKind.OpenBracketToken: return ts.SyntaxKind.CloseBracketToken; case ts.SyntaxKind.LessThanToken: return ts.SyntaxKind.GreaterThanToken; - case ts.SyntaxKind.CloseBraceToken: return ts.SyntaxKind.OpenBraceToken + case ts.SyntaxKind.CloseBraceToken: return ts.SyntaxKind.OpenBraceToken; case ts.SyntaxKind.CloseParenToken: return ts.SyntaxKind.OpenParenToken; case ts.SyntaxKind.CloseBracketToken: return ts.SyntaxKind.OpenBracketToken; case ts.SyntaxKind.GreaterThanToken: return ts.SyntaxKind.LessThanToken; @@ -6988,29 +6991,29 @@ namespace ts { function getIndentationAtPosition(fileName: string, position: number, editorOptions: EditorOptions) { let start = new Date().getTime(); - let sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); + const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); log("getIndentationAtPosition: getCurrentSourceFile: " + (new Date().getTime() - start)); start = new Date().getTime(); - let result = formatting.SmartIndenter.getIndentation(position, sourceFile, editorOptions); + const result = formatting.SmartIndenter.getIndentation(position, sourceFile, editorOptions); log("getIndentationAtPosition: computeIndentation : " + (new Date().getTime() - start)); return result; } function getFormattingEditsForRange(fileName: string, start: number, end: number, options: FormatCodeOptions): TextChange[] { - let sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); + const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); return formatting.formatSelection(start, end, sourceFile, getRuleProvider(options), options); } function getFormattingEditsForDocument(fileName: string, options: FormatCodeOptions): TextChange[] { - let sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); + const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); return formatting.formatDocument(sourceFile, getRuleProvider(options), options); } function getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): TextChange[] { - let sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); + const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); if (key === "}") { return formatting.formatOnClosingCurly(position, sourceFile, getRuleProvider(options), options); @@ -7046,16 +7049,15 @@ namespace ts { * be performed. */ function getDocCommentTemplateAtPosition(fileName: string, position: number): TextInsertion { - let start = new Date().getTime(); - let sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); + const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); // Check if in a context where we don't want to perform any insertion if (isInString(sourceFile, position) || isInComment(sourceFile, position) || hasDocComment(sourceFile, position)) { return undefined; } - let tokenAtPos = getTokenAtPosition(sourceFile, position); - let tokenStart = tokenAtPos.getStart() + const tokenAtPos = getTokenAtPosition(sourceFile, position); + const tokenStart = tokenAtPos.getStart(); if (!tokenAtPos || tokenStart < position) { return undefined; } @@ -7091,11 +7093,11 @@ namespace ts { return undefined; } - let parameters = getParametersForJsDocOwningNode(commentOwner); - let posLineAndChar = sourceFile.getLineAndCharacterOfPosition(position); - let lineStart = sourceFile.getLineStarts()[posLineAndChar.line]; + const parameters = getParametersForJsDocOwningNode(commentOwner); + const posLineAndChar = sourceFile.getLineAndCharacterOfPosition(position); + const lineStart = sourceFile.getLineStarts()[posLineAndChar.line]; - let indentationStr = sourceFile.text.substr(lineStart, posLineAndChar.character); + const indentationStr = sourceFile.text.substr(lineStart, posLineAndChar.character); // TODO: call a helper method instead once PR #4133 gets merged in. const newLine = host.getNewLine ? host.getNewLine() : "\r\n"; @@ -7119,7 +7121,7 @@ namespace ts { // * if the caret was directly in front of the object, then we add an extra line and indentation. const preamble = "/**" + newLine + indentationStr + " * "; - let result = + const result = preamble + newLine + docParams + indentationStr + " */" + @@ -7163,7 +7165,7 @@ namespace ts { case SyntaxKind.ArrowFunction: return (rightHandSide).parameters; case SyntaxKind.ClassExpression: - for (let member of (rightHandSide).members) { + for (const member of (rightHandSide).members) { if (member.kind === SyntaxKind.Constructor) { return (member).parameters; } @@ -7183,15 +7185,15 @@ namespace ts { // anything away. synchronizeHostData(); - let sourceFile = getValidSourceFile(fileName); + const sourceFile = getValidSourceFile(fileName); cancellationToken.throwIfCancellationRequested(); - let fileContents = sourceFile.text; - let result: TodoComment[] = []; + const fileContents = sourceFile.text; + const result: TodoComment[] = []; if (descriptors.length > 0) { - let regExp = getTodoCommentsRegExp(); + const regExp = getTodoCommentsRegExp(); let matchArray: RegExpExecArray; while (matchArray = regExp.exec(fileContents)) { @@ -7214,15 +7216,15 @@ namespace ts { // // i.e. 'undefined' in position 3 above means TODO(jason) didn't match. // "hack" in position 4 means HACK did match. - let firstDescriptorCaptureIndex = 3; + const firstDescriptorCaptureIndex = 3; Debug.assert(matchArray.length === descriptors.length + firstDescriptorCaptureIndex); - let preamble = matchArray[1]; - let matchPosition = matchArray.index + preamble.length; + const preamble = matchArray[1]; + const matchPosition = matchArray.index + preamble.length; // OK, we have found a match in the file. This is only an acceptable match if // it is contained within a comment. - let token = getTokenAtPosition(sourceFile, matchPosition); + const token = getTokenAtPosition(sourceFile, matchPosition); if (!isInsideComment(sourceFile, token, matchPosition)) { continue; } @@ -7241,7 +7243,7 @@ namespace ts { continue; } - let message = matchArray[2]; + const message = matchArray[2]; result.push({ descriptor: descriptor, message: message, @@ -7272,14 +7274,14 @@ namespace ts { // // The following three regexps are used to match the start of the text up to the TODO // comment portion. - let singleLineCommentStart = /(?:\/\/+\s*)/.source; - let multiLineCommentStart = /(?:\/\*+\s*)/.source; - let anyNumberOfSpacesAndAsterixesAtStartOfLine = /(?:^(?:\s|\*)*)/.source; + const singleLineCommentStart = /(?:\/\/+\s*)/.source; + const multiLineCommentStart = /(?:\/\*+\s*)/.source; + const anyNumberOfSpacesAndAsterixesAtStartOfLine = /(?:^(?:\s|\*)*)/.source; // Match any of the above three TODO comment start regexps. // Note that the outermost group *is* a capture group. We want to capture the preamble // so that we can determine the starting position of the TODO comment match. - let preamble = "(" + anyNumberOfSpacesAndAsterixesAtStartOfLine + "|" + singleLineCommentStart + "|" + multiLineCommentStart + ")"; + const preamble = "(" + anyNumberOfSpacesAndAsterixesAtStartOfLine + "|" + singleLineCommentStart + "|" + multiLineCommentStart + ")"; // Takes the descriptors and forms a regexp that matches them as if they were literals. // For example, if the descriptors are "TODO(jason)" and "HACK", then this will be: @@ -7289,17 +7291,17 @@ namespace ts { // Note that the outermost group is *not* a capture group, but the innermost groups // *are* capture groups. By capturing the inner literals we can determine after // matching which descriptor we are dealing with. - let literals = "(?:" + map(descriptors, d => "(" + escapeRegExp(d.text) + ")").join("|") + ")"; + const literals = "(?:" + map(descriptors, d => "(" + escapeRegExp(d.text) + ")").join("|") + ")"; // After matching a descriptor literal, the following regexp matches the rest of the // text up to the end of the line (or */). - let endOfLineOrEndOfComment = /(?:$|\*\/)/.source - let messageRemainder = /(?:.*?)/.source + const endOfLineOrEndOfComment = /(?:$|\*\/)/.source; + const messageRemainder = /(?:.*?)/.source; // This is the portion of the match we'll return as part of the TODO comment result. We // match the literal portion up to the end of the line or end of comment. - let messagePortion = "(" + literals + messageRemainder + ")"; - let regExpString = preamble + messagePortion + endOfLineOrEndOfComment; + const messagePortion = "(" + literals + messageRemainder + ")"; + const regExpString = preamble + messagePortion + endOfLineOrEndOfComment; // The final regexp will look like this: // /((?:\/\/+\s*)|(?:\/\*+\s*)|(?:^(?:\s|\*)*))((?:(TODO\(jason\))|(HACK))(?:.*?))(?:$|\*\/)/gim @@ -7325,40 +7327,46 @@ namespace ts { function getRenameInfo(fileName: string, position: number): RenameInfo { synchronizeHostData(); - let sourceFile = getValidSourceFile(fileName); - let typeChecker = program.getTypeChecker(); + const sourceFile = getValidSourceFile(fileName); + const typeChecker = program.getTypeChecker(); - let node = getTouchingWord(sourceFile, position); + const node = getTouchingWord(sourceFile, position); // Can only rename an identifier. if (node && node.kind === SyntaxKind.Identifier) { - let symbol = typeChecker.getSymbolAtLocation(node); + const symbol = typeChecker.getSymbolAtLocation(node); // Only allow a symbol to be renamed if it actually has at least one declaration. if (symbol) { - let declarations = symbol.getDeclarations(); + const declarations = symbol.getDeclarations(); if (declarations && declarations.length > 0) { // Disallow rename for elements that are defined in the standard TypeScript library. - let defaultLibFileName = host.getDefaultLibFileName(host.getCompilationSettings()); + const defaultLibFileName = host.getDefaultLibFileName(host.getCompilationSettings()); + const canonicalDefaultLibName = getCanonicalFileName(ts.normalizePath(defaultLibFileName)); if (defaultLibFileName) { - for (let current of declarations) { - let sourceFile = current.getSourceFile(); - var canonicalName = getCanonicalFileName(ts.normalizePath(sourceFile.fileName)); - if (sourceFile && getCanonicalFileName(ts.normalizePath(sourceFile.fileName)) === getCanonicalFileName(ts.normalizePath(defaultLibFileName))) { + for (const current of declarations) { + const sourceFile = current.getSourceFile(); + // TODO (drosen): When is there no source file? + if (!sourceFile) { + continue; + } + + const canonicalName = getCanonicalFileName(ts.normalizePath(sourceFile.fileName)); + if (canonicalName === canonicalDefaultLibName) { return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library)); } } } - let displayName = stripQuotes(getDeclaredName(typeChecker, symbol, node)); - let kind = getSymbolKind(symbol, node); + const displayName = stripQuotes(getDeclaredName(typeChecker, symbol, node)); + const kind = getSymbolKind(symbol, node); if (kind) { return { canRename: true, - localizedErrorMessage: undefined, + kind, displayName, + localizedErrorMessage: undefined, fullDisplayName: typeChecker.getFullyQualifiedName(symbol), - kind: kind, kindModifiers: getSymbolModifiers(symbol), triggerSpan: createTextSpan(node.getStart(), node.getWidth()) }; @@ -7425,14 +7433,14 @@ namespace ts { /* @internal */ export function getNameTable(sourceFile: SourceFile): Map { if (!sourceFile.nameTable) { - initializeNameTable(sourceFile) + initializeNameTable(sourceFile); } return sourceFile.nameTable; } function initializeNameTable(sourceFile: SourceFile): void { - let nameTable: Map = {}; + const nameTable: Map = {}; walk(sourceFile); sourceFile.nameTable = nameTable; @@ -7470,13 +7478,13 @@ namespace ts { /// Classifier export function createClassifier(): Classifier { - let scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ false); + const scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ false); /// We do not have a full parser support to know when we should parse a regex or not /// If we consider every slash token to be a regex, we could be missing cases like "1/2/3", where /// we have a series of divide operator. this list allows us to be more accurate by ruling out /// locations where a regexp cannot exist. - let noRegexTable: boolean[] = []; + const noRegexTable: boolean[] = []; noRegexTable[SyntaxKind.Identifier] = true; noRegexTable[SyntaxKind.StringLiteral] = true; noRegexTable[SyntaxKind.NumericLiteral] = true; @@ -7510,7 +7518,7 @@ namespace ts { // // Where on the second line, you will get the 'return' keyword, // a string literal, and a template end consisting of '} } `'. - let templateStack: SyntaxKind[] = []; + const templateStack: SyntaxKind[] = []; /** Returns true if 'keyword2' can legally follow 'keyword1' in any language construct. */ function canFollow(keyword1: SyntaxKind, keyword2: SyntaxKind) { @@ -7536,18 +7544,18 @@ namespace ts { } function convertClassifications(classifications: Classifications, text: string): ClassificationResult { - let entries: ClassificationInfo[] = []; - let dense = classifications.spans; + const entries: ClassificationInfo[] = []; + const dense = classifications.spans; let lastEnd = 0; for (let i = 0, n = dense.length; i < n; i += 3) { - let start = dense[i]; - let length = dense[i + 1]; - let type = dense[i + 2]; + const start = dense[i]; + const length = dense[i + 1]; + const type = dense[i + 2]; // Make a whitespace entry between the last item and this one. if (lastEnd >= 0) { - let whitespaceLength = start - lastEnd; + const whitespaceLength = start - lastEnd; if (whitespaceLength > 0) { entries.push({ length: whitespaceLength, classification: TokenClass.Whitespace }); } @@ -7557,7 +7565,7 @@ namespace ts { lastEnd = start + length; } - let whitespaceLength = text.length - lastEnd; + const whitespaceLength = text.length - lastEnd; if (whitespaceLength > 0) { entries.push({ length: whitespaceLength, classification: TokenClass.Whitespace }); } @@ -7611,7 +7619,7 @@ namespace ts { // (and a newline). That way when we lex we'll think we're still in a multiline comment. switch (lexState) { case EndOfLineState.InDoubleQuoteStringLiteral: - text = '"\\\n' + text; + text = "\"\\\n" + text; offset = 3; break; case EndOfLineState.InSingleQuoteStringLiteral: @@ -7637,7 +7645,7 @@ namespace ts { scanner.setText(text); - let result: Classifications = { + const result: Classifications = { endOfLineState: EndOfLineState.None, spans: [] }; @@ -7719,7 +7727,7 @@ namespace ts { // If we don't have anything on the template stack, // then we aren't trying to keep track of a previously scanned template head. if (templateStack.length > 0) { - let lastTemplateStackToken = lastOrUndefined(templateStack); + const lastTemplateStackToken = lastOrUndefined(templateStack); if (lastTemplateStackToken === SyntaxKind.TemplateHead) { token = scanner.reScanTemplateToken(); @@ -7749,17 +7757,17 @@ namespace ts { return result; function processToken(): void { - let start = scanner.getTokenPos(); - let end = scanner.getTextPos(); + const start = scanner.getTokenPos(); + const end = scanner.getTextPos(); addResult(start, end, classFromKind(token)); if (end >= text.length) { if (token === SyntaxKind.StringLiteral || token === SyntaxKind.StringLiteralType) { // Check to see if we finished up on a multiline string literal. - let tokenText = scanner.getTokenText(); + const tokenText = scanner.getTokenText(); if (scanner.isUnterminated()) { - let lastCharIndex = tokenText.length - 1; + const lastCharIndex = tokenText.length - 1; let numBackslashes = 0; while (tokenText.charCodeAt(lastCharIndex - numBackslashes) === CharacterCodes.backslash) { @@ -7768,7 +7776,7 @@ namespace ts { // If we have an odd number of backslashes, then the multiline string is unclosed if (numBackslashes & 1) { - let quoteChar = tokenText.charCodeAt(0); + const quoteChar = tokenText.charCodeAt(0); result.endOfLineState = quoteChar === CharacterCodes.doubleQuote ? EndOfLineState.InDoubleQuoteStringLiteral : EndOfLineState.InSingleQuoteStringLiteral; @@ -7817,7 +7825,7 @@ namespace ts { // relative to the original text. start -= offset; end -= offset; - let length = end - start; + const length = end - start; if (length > 0) { result.spans.push(start); @@ -7932,7 +7940,7 @@ namespace ts { } /// getDefaultLibraryFilePath - declare let __dirname: string; + declare const __dirname: string; /** * Get the path of the default library files (lib.d.ts) as distributed with the typescript diff --git a/tests/baselines/reference/DeclarationErrorsNoEmitOnError.errors.txt b/tests/baselines/reference/DeclarationErrorsNoEmitOnError.errors.txt new file mode 100644 index 0000000000..1f442e98d1 --- /dev/null +++ b/tests/baselines/reference/DeclarationErrorsNoEmitOnError.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/DeclarationErrorsNoEmitOnError.ts(4,8): error TS4033: Property 'f' of exported interface has or is using private name 'T'. + + +==== tests/cases/compiler/DeclarationErrorsNoEmitOnError.ts (1 errors) ==== + + type T = { x : number } + export interface I { + f: T; + ~ +!!! error TS4033: Property 'f' of exported interface has or is using private name 'T'. + } \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiteralComments.js b/tests/baselines/reference/arrayLiteralComments.js new file mode 100644 index 0000000000..4f13df1c82 --- /dev/null +++ b/tests/baselines/reference/arrayLiteralComments.js @@ -0,0 +1,31 @@ +//// [arrayLiteralComments.ts] +var testArrayWithFunc = [ + // Function comment + function() { + let x = 1; + }, + // String comment + '1', + // Numeric comment + 2, + // Object comment + { a: 1 }, + // Array comment + [1, 2, 3] +] + +//// [arrayLiteralComments.js] +var testArrayWithFunc = [ + // Function comment + function () { + var x = 1; + }, + // String comment + '1', + // Numeric comment + 2, + // Object comment + { a: 1 }, + // Array comment + [1, 2, 3] +]; diff --git a/tests/baselines/reference/arrayLiteralComments.symbols b/tests/baselines/reference/arrayLiteralComments.symbols new file mode 100644 index 0000000000..c1c173d741 --- /dev/null +++ b/tests/baselines/reference/arrayLiteralComments.symbols @@ -0,0 +1,21 @@ +=== tests/cases/compiler/arrayLiteralComments.ts === +var testArrayWithFunc = [ +>testArrayWithFunc : Symbol(testArrayWithFunc, Decl(arrayLiteralComments.ts, 0, 3)) + + // Function comment + function() { + let x = 1; +>x : Symbol(x, Decl(arrayLiteralComments.ts, 3, 11)) + + }, + // String comment + '1', + // Numeric comment + 2, + // Object comment + { a: 1 }, +>a : Symbol(a, Decl(arrayLiteralComments.ts, 10, 5)) + + // Array comment + [1, 2, 3] +] diff --git a/tests/baselines/reference/arrayLiteralComments.types b/tests/baselines/reference/arrayLiteralComments.types new file mode 100644 index 0000000000..a8c32b48e4 --- /dev/null +++ b/tests/baselines/reference/arrayLiteralComments.types @@ -0,0 +1,36 @@ +=== tests/cases/compiler/arrayLiteralComments.ts === +var testArrayWithFunc = [ +>testArrayWithFunc : ((() => void) | string | number | { a: number; } | number[])[] +>[ // Function comment function() { let x = 1; }, // String comment '1', // Numeric comment 2, // Object comment { a: 1 }, // Array comment [1, 2, 3]] : ((() => void) | string | number | { a: number; } | number[])[] + + // Function comment + function() { +>function() { let x = 1; } : () => void + + let x = 1; +>x : number +>1 : number + + }, + // String comment + '1', +>'1' : string + + // Numeric comment + 2, +>2 : number + + // Object comment + { a: 1 }, +>{ a: 1 } : { a: number; } +>a : number +>1 : number + + // Array comment + [1, 2, 3] +>[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number + +] diff --git a/tests/baselines/reference/computedPropertyNames30_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames30_ES5.errors.txt index deb80dbcca..e64b83f609 100644 --- a/tests/baselines/reference/computedPropertyNames30_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames30_ES5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES5.ts(11,19): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. +tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES5.ts(11,19): error TS2466: 'super' cannot be referenced in a computed property name. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES5.ts (1 errors) ==== @@ -14,7 +14,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES5.ts(11 //treatment of other similar violations. [(super(), "prop")]() { } ~~~~~ -!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. +!!! error TS2466: 'super' cannot be referenced in a computed property name. }; } } diff --git a/tests/baselines/reference/computedPropertyNames30_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames30_ES6.errors.txt index b10d184f79..a5771629ac 100644 --- a/tests/baselines/reference/computedPropertyNames30_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames30_ES6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES6.ts(11,19): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. +tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES6.ts(11,19): error TS2466: 'super' cannot be referenced in a computed property name. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES6.ts (1 errors) ==== @@ -14,7 +14,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames30_ES6.ts(11 //treatment of other similar violations. [(super(), "prop")]() { } ~~~~~ -!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. +!!! error TS2466: 'super' cannot be referenced in a computed property name. }; } } diff --git a/tests/baselines/reference/conformanceFunctionOverloads.js b/tests/baselines/reference/conformanceFunctionOverloads.js deleted file mode 100644 index b245f6a2c9..0000000000 --- a/tests/baselines/reference/conformanceFunctionOverloads.js +++ /dev/null @@ -1,37 +0,0 @@ -//// [conformanceFunctionOverloads.ts] -// Function overloads do not emit code - -// Function overload signature with optional parameter - -// Function overload signature with optional parameter - -// Function overloads with generic and non-generic overloads - -// Function overloads whose only difference is returning different unconstrained generic parameters - -// Function overloads whose only difference is returning different constrained generic parameters - -// Function overloads that differ only by type parameter constraints - -// Function overloads with matching accessibility - -// Function overloads with matching export - -// Function overloads with more params than implementation signature - -// Function overloads where return types are same infinitely recursive type reference - - - -//// [conformanceFunctionOverloads.js] -// Function overloads do not emit code -// Function overload signature with optional parameter -// Function overload signature with optional parameter -// Function overloads with generic and non-generic overloads -// Function overloads whose only difference is returning different unconstrained generic parameters -// Function overloads whose only difference is returning different constrained generic parameters -// Function overloads that differ only by type parameter constraints -// Function overloads with matching accessibility -// Function overloads with matching export -// Function overloads with more params than implementation signature -// Function overloads where return types are same infinitely recursive type reference diff --git a/tests/baselines/reference/conformanceFunctionOverloads.symbols b/tests/baselines/reference/conformanceFunctionOverloads.symbols deleted file mode 100644 index a80814ea93..0000000000 --- a/tests/baselines/reference/conformanceFunctionOverloads.symbols +++ /dev/null @@ -1,25 +0,0 @@ -=== tests/cases/conformance/functions/conformanceFunctionOverloads.ts === -// Function overloads do not emit code -No type information for this code. -No type information for this code.// Function overload signature with optional parameter -No type information for this code. -No type information for this code.// Function overload signature with optional parameter -No type information for this code. -No type information for this code.// Function overloads with generic and non-generic overloads -No type information for this code. -No type information for this code.// Function overloads whose only difference is returning different unconstrained generic parameters -No type information for this code. -No type information for this code.// Function overloads whose only difference is returning different constrained generic parameters -No type information for this code. -No type information for this code.// Function overloads that differ only by type parameter constraints -No type information for this code. -No type information for this code.// Function overloads with matching accessibility -No type information for this code. -No type information for this code.// Function overloads with matching export -No type information for this code. -No type information for this code.// Function overloads with more params than implementation signature -No type information for this code. -No type information for this code.// Function overloads where return types are same infinitely recursive type reference -No type information for this code. -No type information for this code. -No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/conformanceFunctionOverloads.types b/tests/baselines/reference/conformanceFunctionOverloads.types deleted file mode 100644 index a80814ea93..0000000000 --- a/tests/baselines/reference/conformanceFunctionOverloads.types +++ /dev/null @@ -1,25 +0,0 @@ -=== tests/cases/conformance/functions/conformanceFunctionOverloads.ts === -// Function overloads do not emit code -No type information for this code. -No type information for this code.// Function overload signature with optional parameter -No type information for this code. -No type information for this code.// Function overload signature with optional parameter -No type information for this code. -No type information for this code.// Function overloads with generic and non-generic overloads -No type information for this code. -No type information for this code.// Function overloads whose only difference is returning different unconstrained generic parameters -No type information for this code. -No type information for this code.// Function overloads whose only difference is returning different constrained generic parameters -No type information for this code. -No type information for this code.// Function overloads that differ only by type parameter constraints -No type information for this code. -No type information for this code.// Function overloads with matching accessibility -No type information for this code. -No type information for this code.// Function overloads with matching export -No type information for this code. -No type information for this code.// Function overloads with more params than implementation signature -No type information for this code. -No type information for this code.// Function overloads where return types are same infinitely recursive type reference -No type information for this code. -No type information for this code. -No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassMethod12.errors.txt b/tests/baselines/reference/decoratorOnClassMethod12.errors.txt index 3ad3cabebe..c285d5f12c 100644 --- a/tests/baselines/reference/decoratorOnClassMethod12.errors.txt +++ b/tests/baselines/reference/decoratorOnClassMethod12.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod12.ts(6,10): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod12.ts(6,10): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. ==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod12.ts (1 errors) ==== @@ -9,7 +9,7 @@ tests/cases/conformance/decorators/class/method/decoratorOnClassMethod12.ts(6,10 class C extends S { @super.decorator ~~~~~ -!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. method() { } } } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassMethodOverload1.errors.txt b/tests/baselines/reference/decoratorOnClassMethodOverload1.errors.txt new file mode 100644 index 0000000000..d1670bd6bb --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethodOverload1.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/decorators/class/method/decoratorOnClassMethodOverload1.ts(4,5): error TS1249: A decorator can only decorate a method implementation, not an overload. + + +==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethodOverload1.ts (1 errors) ==== + declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + + class C { + @dec + ~ +!!! error TS1249: A decorator can only decorate a method implementation, not an overload. + method() + method() { } + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassMethodOverload1.js b/tests/baselines/reference/decoratorOnClassMethodOverload1.js new file mode 100644 index 0000000000..cb2e29b3d0 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethodOverload1.js @@ -0,0 +1,16 @@ +//// [decoratorOnClassMethodOverload1.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + @dec + method() + method() { } +} + +//// [decoratorOnClassMethodOverload1.js] +var C = (function () { + function C() { + } + C.prototype.method = function () { }; + return C; +}()); diff --git a/tests/baselines/reference/decoratorOnClassMethodOverload2.js b/tests/baselines/reference/decoratorOnClassMethodOverload2.js new file mode 100644 index 0000000000..eafa5da711 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethodOverload2.js @@ -0,0 +1,25 @@ +//// [decoratorOnClassMethodOverload2.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + method() + @dec + method() { } +} + +//// [decoratorOnClassMethodOverload2.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + 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; +}; +var C = (function () { + function C() { + } + C.prototype.method = function () { }; + __decorate([ + dec + ], C.prototype, "method", null); + return C; +}()); diff --git a/tests/baselines/reference/decoratorOnClassMethodOverload2.symbols b/tests/baselines/reference/decoratorOnClassMethodOverload2.symbols new file mode 100644 index 0000000000..f05dd62434 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethodOverload2.symbols @@ -0,0 +1,24 @@ +=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethodOverload2.ts === +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; +>dec : Symbol(dec, Decl(decoratorOnClassMethodOverload2.ts, 0, 0)) +>T : Symbol(T, Decl(decoratorOnClassMethodOverload2.ts, 0, 21)) +>target : Symbol(target, Decl(decoratorOnClassMethodOverload2.ts, 0, 24)) +>propertyKey : Symbol(propertyKey, Decl(decoratorOnClassMethodOverload2.ts, 0, 36)) +>descriptor : Symbol(descriptor, Decl(decoratorOnClassMethodOverload2.ts, 0, 57)) +>TypedPropertyDescriptor : Symbol(TypedPropertyDescriptor, Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(decoratorOnClassMethodOverload2.ts, 0, 21)) +>TypedPropertyDescriptor : Symbol(TypedPropertyDescriptor, Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(decoratorOnClassMethodOverload2.ts, 0, 21)) + +class C { +>C : Symbol(C, Decl(decoratorOnClassMethodOverload2.ts, 0, 126)) + + method() +>method : Symbol(method, Decl(decoratorOnClassMethodOverload2.ts, 2, 9), Decl(decoratorOnClassMethodOverload2.ts, 3, 12)) + + @dec +>dec : Symbol(dec, Decl(decoratorOnClassMethodOverload2.ts, 0, 0)) + + method() { } +>method : Symbol(method, Decl(decoratorOnClassMethodOverload2.ts, 2, 9), Decl(decoratorOnClassMethodOverload2.ts, 3, 12)) +} diff --git a/tests/baselines/reference/decoratorOnClassMethodOverload2.types b/tests/baselines/reference/decoratorOnClassMethodOverload2.types new file mode 100644 index 0000000000..7002d74a82 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethodOverload2.types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethodOverload2.ts === +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; +>dec : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + method() +>method : () => any + + @dec +>dec : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor + + method() { } +>method : () => any +} diff --git a/tests/baselines/reference/emitThisInSuperMethodCall.errors.txt b/tests/baselines/reference/emitThisInSuperMethodCall.errors.txt index 06211ef771..c8d694c856 100644 --- a/tests/baselines/reference/emitThisInSuperMethodCall.errors.txt +++ b/tests/baselines/reference/emitThisInSuperMethodCall.errors.txt @@ -1,6 +1,6 @@ -tests/cases/compiler/emitThisInSuperMethodCall.ts(10,17): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. -tests/cases/compiler/emitThisInSuperMethodCall.ts(17,17): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. -tests/cases/compiler/emitThisInSuperMethodCall.ts(23,13): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. +tests/cases/compiler/emitThisInSuperMethodCall.ts(10,17): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/compiler/emitThisInSuperMethodCall.ts(17,17): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/compiler/emitThisInSuperMethodCall.ts(23,13): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. ==== tests/cases/compiler/emitThisInSuperMethodCall.ts (3 errors) ==== @@ -15,7 +15,7 @@ tests/cases/compiler/emitThisInSuperMethodCall.ts(23,13): error TS2338: 'super' function inner() { super.sayHello(); ~~~~~ -!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. } }; } @@ -24,7 +24,7 @@ tests/cases/compiler/emitThisInSuperMethodCall.ts(23,13): error TS2338: 'super' () => { super.sayHello(); ~~~~~ -!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. } } } @@ -32,7 +32,7 @@ tests/cases/compiler/emitThisInSuperMethodCall.ts(23,13): error TS2338: 'super' function inner() { super.sayHello(); ~~~~~ -!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. } } } diff --git a/tests/baselines/reference/enumAssignmentCompat3.errors.txt b/tests/baselines/reference/enumAssignmentCompat3.errors.txt new file mode 100644 index 0000000000..02cb431477 --- /dev/null +++ b/tests/baselines/reference/enumAssignmentCompat3.errors.txt @@ -0,0 +1,129 @@ +tests/cases/compiler/enumAssignmentCompat3.ts(68,1): error TS2322: Type 'Abcd.E' is not assignable to type 'First.E'. + Property 'd' is missing in type 'First.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(70,1): error TS2322: Type 'Cd.E' is not assignable to type 'First.E'. + Property 'd' is missing in type 'First.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(71,1): error TS2322: Type 'Nope' is not assignable to type 'E'. +tests/cases/compiler/enumAssignmentCompat3.ts(75,1): error TS2322: Type 'First.E' is not assignable to type 'Ab.E'. + Property 'c' is missing in type 'Ab.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(76,1): error TS2322: Type 'First.E' is not assignable to type 'Cd.E'. + Property 'a' is missing in type 'Cd.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(77,1): error TS2322: Type 'E' is not assignable to type 'Nope'. +tests/cases/compiler/enumAssignmentCompat3.ts(82,1): error TS2322: Type 'Const.E' is not assignable to type 'First.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(83,1): error TS2322: Type 'First.E' is not assignable to type 'Const.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(86,1): error TS2322: Type 'Merged.E' is not assignable to type 'First.E'. + Property 'd' is missing in type 'First.E'. + + +==== tests/cases/compiler/enumAssignmentCompat3.ts (9 errors) ==== + namespace First { + export enum E { + a, b, c, + } + } + namespace Abc { + export enum E { + a, b, c, + } + export enum Nope { + a, b, c, + } + } + namespace Abcd { + export enum E { + a, b, c, d, + } + } + namespace Ab { + export enum E { + a, b, + } + } + namespace Cd { + export enum E { + c, d, + } + } + namespace Const { + export const enum E { + a, b, c, + } + } + namespace Decl { + export declare enum E { + a, b, c = 3, + } + } + namespace Merged { + export enum E { + a, b, + } + export enum E { + c = 3, d, + } + } + + namespace Merged2 { + export enum E { + a, b, c + } + export module E { + export let d = 5; + } + } + + var abc: First.E; + var secondAbc: Abc.E; + var secondAbcd: Abcd.E; + var secondAb: Ab.E; + var secondCd: Cd.E; + var nope: Abc.Nope; + var k: Const.E; + var decl: Decl.E; + var merged: Merged.E; + var merged2: Merged2.E; + abc = secondAbc; // ok + abc = secondAbcd; // missing 'd' + ~~~ +!!! error TS2322: Type 'Abcd.E' is not assignable to type 'First.E'. +!!! error TS2322: Property 'd' is missing in type 'First.E'. + abc = secondAb; // ok + abc = secondCd; // missing 'd' + ~~~ +!!! error TS2322: Type 'Cd.E' is not assignable to type 'First.E'. +!!! error TS2322: Property 'd' is missing in type 'First.E'. + abc = nope; // nope! + ~~~ +!!! error TS2322: Type 'Nope' is not assignable to type 'E'. + abc = decl; // ok + secondAbc = abc; // ok + secondAbcd = abc; // ok + secondAb = abc; // missing 'c' + ~~~~~~~~ +!!! error TS2322: Type 'First.E' is not assignable to type 'Ab.E'. +!!! error TS2322: Property 'c' is missing in type 'Ab.E'. + secondCd = abc; // missing 'a' and 'b' + ~~~~~~~~ +!!! error TS2322: Type 'First.E' is not assignable to type 'Cd.E'. +!!! error TS2322: Property 'a' is missing in type 'Cd.E'. + nope = abc; // nope! + ~~~~ +!!! error TS2322: Type 'E' is not assignable to type 'Nope'. + decl = abc; // ok + + // const is only assignable to itself + k = k; + abc = k; // error + ~~~ +!!! error TS2322: Type 'Const.E' is not assignable to type 'First.E'. + k = abc; + ~ +!!! error TS2322: Type 'First.E' is not assignable to type 'Const.E'. + + // merged enums compare all their members + abc = merged; // missing 'd' + ~~~ +!!! error TS2322: Type 'Merged.E' is not assignable to type 'First.E'. +!!! error TS2322: Property 'd' is missing in type 'First.E'. + merged = abc; // ok + abc = merged2; // ok + merged2 = abc; // ok \ No newline at end of file diff --git a/tests/baselines/reference/enumAssignmentCompat3.js b/tests/baselines/reference/enumAssignmentCompat3.js new file mode 100644 index 0000000000..74f74ab165 --- /dev/null +++ b/tests/baselines/reference/enumAssignmentCompat3.js @@ -0,0 +1,202 @@ +//// [enumAssignmentCompat3.ts] +namespace First { + export enum E { + a, b, c, + } +} +namespace Abc { + export enum E { + a, b, c, + } + export enum Nope { + a, b, c, + } +} +namespace Abcd { + export enum E { + a, b, c, d, + } +} +namespace Ab { + export enum E { + a, b, + } +} +namespace Cd { + export enum E { + c, d, + } +} +namespace Const { + export const enum E { + a, b, c, + } +} +namespace Decl { + export declare enum E { + a, b, c = 3, + } +} +namespace Merged { + export enum E { + a, b, + } + export enum E { + c = 3, d, + } +} + +namespace Merged2 { + export enum E { + a, b, c + } + export module E { + export let d = 5; + } +} + +var abc: First.E; +var secondAbc: Abc.E; +var secondAbcd: Abcd.E; +var secondAb: Ab.E; +var secondCd: Cd.E; +var nope: Abc.Nope; +var k: Const.E; +var decl: Decl.E; +var merged: Merged.E; +var merged2: Merged2.E; +abc = secondAbc; // ok +abc = secondAbcd; // missing 'd' +abc = secondAb; // ok +abc = secondCd; // missing 'd' +abc = nope; // nope! +abc = decl; // ok +secondAbc = abc; // ok +secondAbcd = abc; // ok +secondAb = abc; // missing 'c' +secondCd = abc; // missing 'a' and 'b' +nope = abc; // nope! +decl = abc; // ok + +// const is only assignable to itself +k = k; +abc = k; // error +k = abc; + +// merged enums compare all their members +abc = merged; // missing 'd' +merged = abc; // ok +abc = merged2; // ok +merged2 = abc; // ok + +//// [enumAssignmentCompat3.js] +var First; +(function (First) { + (function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; + E[E["c"] = 2] = "c"; + })(First.E || (First.E = {})); + var E = First.E; +})(First || (First = {})); +var Abc; +(function (Abc) { + (function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; + E[E["c"] = 2] = "c"; + })(Abc.E || (Abc.E = {})); + var E = Abc.E; + (function (Nope) { + Nope[Nope["a"] = 0] = "a"; + Nope[Nope["b"] = 1] = "b"; + Nope[Nope["c"] = 2] = "c"; + })(Abc.Nope || (Abc.Nope = {})); + var Nope = Abc.Nope; +})(Abc || (Abc = {})); +var Abcd; +(function (Abcd) { + (function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; + E[E["c"] = 2] = "c"; + E[E["d"] = 3] = "d"; + })(Abcd.E || (Abcd.E = {})); + var E = Abcd.E; +})(Abcd || (Abcd = {})); +var Ab; +(function (Ab) { + (function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; + })(Ab.E || (Ab.E = {})); + var E = Ab.E; +})(Ab || (Ab = {})); +var Cd; +(function (Cd) { + (function (E) { + E[E["c"] = 0] = "c"; + E[E["d"] = 1] = "d"; + })(Cd.E || (Cd.E = {})); + var E = Cd.E; +})(Cd || (Cd = {})); +var Decl; +(function (Decl) { +})(Decl || (Decl = {})); +var Merged; +(function (Merged) { + (function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; + })(Merged.E || (Merged.E = {})); + var E = Merged.E; + (function (E) { + E[E["c"] = 3] = "c"; + E[E["d"] = 4] = "d"; + })(Merged.E || (Merged.E = {})); + var E = Merged.E; +})(Merged || (Merged = {})); +var Merged2; +(function (Merged2) { + (function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; + E[E["c"] = 2] = "c"; + })(Merged2.E || (Merged2.E = {})); + var E = Merged2.E; + var E; + (function (E) { + E.d = 5; + })(E = Merged2.E || (Merged2.E = {})); +})(Merged2 || (Merged2 = {})); +var abc; +var secondAbc; +var secondAbcd; +var secondAb; +var secondCd; +var nope; +var k; +var decl; +var merged; +var merged2; +abc = secondAbc; // ok +abc = secondAbcd; // missing 'd' +abc = secondAb; // ok +abc = secondCd; // missing 'd' +abc = nope; // nope! +abc = decl; // ok +secondAbc = abc; // ok +secondAbcd = abc; // ok +secondAb = abc; // missing 'c' +secondCd = abc; // missing 'a' and 'b' +nope = abc; // nope! +decl = abc; // ok +// const is only assignable to itself +k = k; +abc = k; // error +k = abc; +// merged enums compare all their members +abc = merged; // missing 'd' +merged = abc; // ok +abc = merged2; // ok +merged2 = abc; // ok diff --git a/tests/baselines/reference/errorSuperCalls.errors.txt b/tests/baselines/reference/errorSuperCalls.errors.txt index 9ecc7a1565..49bcb4b4d4 100644 --- a/tests/baselines/reference/errorSuperCalls.errors.txt +++ b/tests/baselines/reference/errorSuperCalls.errors.txt @@ -1,12 +1,12 @@ tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(4,9): error TS2335: 'super' can only be referenced in a derived class. -tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(9,9): error TS2335: 'super' can only be referenced in a derived class. -tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(14,9): error TS2335: 'super' can only be referenced in a derived class. -tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(18,9): error TS2335: 'super' can only be referenced in a derived class. -tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(22,9): error TS2335: 'super' can only be referenced in a derived class. -tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(26,9): error TS2335: 'super' can only be referenced in a derived class. -tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(30,16): error TS2335: 'super' can only be referenced in a derived class. -tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(34,9): error TS2335: 'super' can only be referenced in a derived class. -tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(38,9): error TS2335: 'super' can only be referenced in a derived class. +tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(9,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. +tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(14,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. +tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(18,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. +tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(22,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. +tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(26,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. +tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(30,16): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. +tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(34,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. +tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(38,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(46,14): error TS1034: 'super' must be followed by an argument list or member access. tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(58,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(62,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. @@ -27,50 +27,50 @@ tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(71,9): error T fn() { super(); ~~~~~ -!!! error TS2335: 'super' can only be referenced in a derived class. +!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. } //super call in class accessor (get and set) with no base type get foo() { super(); ~~~~~ -!!! error TS2335: 'super' can only be referenced in a derived class. +!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. return null; } set foo(v) { super(); ~~~~~ -!!! error TS2335: 'super' can only be referenced in a derived class. +!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. } //super call in class member initializer with no base type p = super(); ~~~~~ -!!! error TS2335: 'super' can only be referenced in a derived class. +!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. //super call in static class member function with no base type static fn() { super(); ~~~~~ -!!! error TS2335: 'super' can only be referenced in a derived class. +!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. } //super call in static class member initializer with no base type static k = super(); ~~~~~ -!!! error TS2335: 'super' can only be referenced in a derived class. +!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. //super call in static class accessor (get and set) with no base type static get q() { super(); ~~~~~ -!!! error TS2335: 'super' can only be referenced in a derived class. +!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. return null; } static set q(n) { super(); ~~~~~ -!!! error TS2335: 'super' can only be referenced in a derived class. +!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. } } diff --git a/tests/baselines/reference/errorSuperPropertyAccess.errors.txt b/tests/baselines/reference/errorSuperPropertyAccess.errors.txt index c34ed91204..c54ace99f1 100644 --- a/tests/baselines/reference/errorSuperPropertyAccess.errors.txt +++ b/tests/baselines/reference/errorSuperPropertyAccess.errors.txt @@ -15,8 +15,8 @@ tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(65,23): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(68,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(69,19): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. -tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(73,13): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. -tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(76,40): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. +tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(73,13): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(76,40): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(87,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(91,23): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(94,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. @@ -34,8 +34,8 @@ tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(120,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(121,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(122,9): error TS2341: Property 'privateStaticFunc' is private and only accessible within class 'SomeBase'. -tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(127,16): error TS2335: 'super' can only be referenced in a derived class. -tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(127,30): error TS2335: 'super' can only be referenced in a derived class. +tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(127,16): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(127,30): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. ==== tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts (38 errors) ==== @@ -147,12 +147,12 @@ tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess function inner() { super.publicFunc(); ~~~~~ -!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. } var x = { test: function () { return super.publicFunc(); } ~~~~~ -!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. } } } @@ -239,7 +239,7 @@ tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess // In object literal var obj = { n: super.wat, p: super.foo() }; ~~~~~ -!!! error TS2335: 'super' can only be referenced in a derived class. +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. ~~~~~ -!!! error TS2335: 'super' can only be referenced in a derived class. +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. \ No newline at end of file diff --git a/tests/baselines/reference/functionOverloadCompatibilityWithVoid01.errors.txt b/tests/baselines/reference/functionOverloadCompatibilityWithVoid01.errors.txt new file mode 100644 index 0000000000..56951e380e --- /dev/null +++ b/tests/baselines/reference/functionOverloadCompatibilityWithVoid01.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid01.ts(1,10): error TS2394: Overload signature is not compatible with function implementation. + + +==== tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid01.ts (1 errors) ==== + function f(x: string): number; + ~ +!!! error TS2394: Overload signature is not compatible with function implementation. + function f(x: string): void { + return; + } \ No newline at end of file diff --git a/tests/baselines/reference/functionOverloadCompatibilityWithVoid01.js b/tests/baselines/reference/functionOverloadCompatibilityWithVoid01.js new file mode 100644 index 0000000000..b2d7e64d58 --- /dev/null +++ b/tests/baselines/reference/functionOverloadCompatibilityWithVoid01.js @@ -0,0 +1,10 @@ +//// [functionOverloadCompatibilityWithVoid01.ts] +function f(x: string): number; +function f(x: string): void { + return; +} + +//// [functionOverloadCompatibilityWithVoid01.js] +function f(x) { + return; +} diff --git a/tests/baselines/reference/functionOverloadCompatibilityWithVoid02.js b/tests/baselines/reference/functionOverloadCompatibilityWithVoid02.js new file mode 100644 index 0000000000..4f53be1f9c --- /dev/null +++ b/tests/baselines/reference/functionOverloadCompatibilityWithVoid02.js @@ -0,0 +1,10 @@ +//// [functionOverloadCompatibilityWithVoid02.ts] +function f(x: string): void; +function f(x: string): number { + return 0; +} + +//// [functionOverloadCompatibilityWithVoid02.js] +function f(x) { + return 0; +} diff --git a/tests/baselines/reference/functionOverloadCompatibilityWithVoid02.symbols b/tests/baselines/reference/functionOverloadCompatibilityWithVoid02.symbols new file mode 100644 index 0000000000..210f7e3e4e --- /dev/null +++ b/tests/baselines/reference/functionOverloadCompatibilityWithVoid02.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid02.ts === +function f(x: string): void; +>f : Symbol(f, Decl(functionOverloadCompatibilityWithVoid02.ts, 0, 0), Decl(functionOverloadCompatibilityWithVoid02.ts, 0, 28)) +>x : Symbol(x, Decl(functionOverloadCompatibilityWithVoid02.ts, 0, 11)) + +function f(x: string): number { +>f : Symbol(f, Decl(functionOverloadCompatibilityWithVoid02.ts, 0, 0), Decl(functionOverloadCompatibilityWithVoid02.ts, 0, 28)) +>x : Symbol(x, Decl(functionOverloadCompatibilityWithVoid02.ts, 1, 11)) + + return 0; +} diff --git a/tests/baselines/reference/functionOverloadCompatibilityWithVoid02.types b/tests/baselines/reference/functionOverloadCompatibilityWithVoid02.types new file mode 100644 index 0000000000..aa6fda7222 --- /dev/null +++ b/tests/baselines/reference/functionOverloadCompatibilityWithVoid02.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid02.ts === +function f(x: string): void; +>f : (x: string) => void +>x : string + +function f(x: string): number { +>f : (x: string) => void +>x : string + + return 0; +>0 : number +} diff --git a/tests/baselines/reference/functionOverloadCompatibilityWithVoid03.js b/tests/baselines/reference/functionOverloadCompatibilityWithVoid03.js new file mode 100644 index 0000000000..b83939442c --- /dev/null +++ b/tests/baselines/reference/functionOverloadCompatibilityWithVoid03.js @@ -0,0 +1,10 @@ +//// [functionOverloadCompatibilityWithVoid03.ts] +function f(x: string): void; +function f(x: string): void { + return; +} + +//// [functionOverloadCompatibilityWithVoid03.js] +function f(x) { + return; +} diff --git a/tests/baselines/reference/functionOverloadCompatibilityWithVoid03.symbols b/tests/baselines/reference/functionOverloadCompatibilityWithVoid03.symbols new file mode 100644 index 0000000000..57fe6006ce --- /dev/null +++ b/tests/baselines/reference/functionOverloadCompatibilityWithVoid03.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid03.ts === +function f(x: string): void; +>f : Symbol(f, Decl(functionOverloadCompatibilityWithVoid03.ts, 0, 0), Decl(functionOverloadCompatibilityWithVoid03.ts, 0, 28)) +>x : Symbol(x, Decl(functionOverloadCompatibilityWithVoid03.ts, 0, 11)) + +function f(x: string): void { +>f : Symbol(f, Decl(functionOverloadCompatibilityWithVoid03.ts, 0, 0), Decl(functionOverloadCompatibilityWithVoid03.ts, 0, 28)) +>x : Symbol(x, Decl(functionOverloadCompatibilityWithVoid03.ts, 1, 11)) + + return; +} diff --git a/tests/baselines/reference/functionOverloadCompatibilityWithVoid03.types b/tests/baselines/reference/functionOverloadCompatibilityWithVoid03.types new file mode 100644 index 0000000000..74dfa28c14 --- /dev/null +++ b/tests/baselines/reference/functionOverloadCompatibilityWithVoid03.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid03.ts === +function f(x: string): void; +>f : (x: string) => void +>x : string + +function f(x: string): void { +>f : (x: string) => void +>x : string + + return; +} diff --git a/tests/baselines/reference/functionOverloads22.errors.txt b/tests/baselines/reference/functionOverloads22.errors.txt deleted file mode 100644 index c9fc8aa2b2..0000000000 --- a/tests/baselines/reference/functionOverloads22.errors.txt +++ /dev/null @@ -1,10 +0,0 @@ -tests/cases/compiler/functionOverloads22.ts(2,10): error TS2394: Overload signature is not compatible with function implementation. - - -==== tests/cases/compiler/functionOverloads22.ts (1 errors) ==== - function foo(bar:number):{a:number;}[]; - function foo(bar:string):{a:number; b:string;}[]; - ~~~ -!!! error TS2394: Overload signature is not compatible with function implementation. - function foo(bar:any):{a:any;b?:any;}[] { return [{a:""}] } - \ No newline at end of file diff --git a/tests/baselines/reference/functionOverloads22.symbols b/tests/baselines/reference/functionOverloads22.symbols new file mode 100644 index 0000000000..7924da073b --- /dev/null +++ b/tests/baselines/reference/functionOverloads22.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/functionOverloads22.ts === +function foo(bar:number):{a:number;}[]; +>foo : Symbol(foo, Decl(functionOverloads22.ts, 0, 0), Decl(functionOverloads22.ts, 0, 39), Decl(functionOverloads22.ts, 1, 49)) +>bar : Symbol(bar, Decl(functionOverloads22.ts, 0, 13)) +>a : Symbol(a, Decl(functionOverloads22.ts, 0, 26)) + +function foo(bar:string):{a:number; b:string;}[]; +>foo : Symbol(foo, Decl(functionOverloads22.ts, 0, 0), Decl(functionOverloads22.ts, 0, 39), Decl(functionOverloads22.ts, 1, 49)) +>bar : Symbol(bar, Decl(functionOverloads22.ts, 1, 13)) +>a : Symbol(a, Decl(functionOverloads22.ts, 1, 26)) +>b : Symbol(b, Decl(functionOverloads22.ts, 1, 35)) + +function foo(bar:any):{a:any;b?:any;}[] { return [{a:""}] } +>foo : Symbol(foo, Decl(functionOverloads22.ts, 0, 0), Decl(functionOverloads22.ts, 0, 39), Decl(functionOverloads22.ts, 1, 49)) +>bar : Symbol(bar, Decl(functionOverloads22.ts, 2, 13)) +>a : Symbol(a, Decl(functionOverloads22.ts, 2, 23)) +>b : Symbol(b, Decl(functionOverloads22.ts, 2, 29)) +>a : Symbol(a, Decl(functionOverloads22.ts, 2, 51)) + diff --git a/tests/baselines/reference/functionOverloads22.types b/tests/baselines/reference/functionOverloads22.types new file mode 100644 index 0000000000..7557b1c049 --- /dev/null +++ b/tests/baselines/reference/functionOverloads22.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/functionOverloads22.ts === +function foo(bar:number):{a:number;}[]; +>foo : { (bar: number): { a: number; }[]; (bar: string): { a: number; b: string; }[]; } +>bar : number +>a : number + +function foo(bar:string):{a:number; b:string;}[]; +>foo : { (bar: number): { a: number; }[]; (bar: string): { a: number; b: string; }[]; } +>bar : string +>a : number +>b : string + +function foo(bar:any):{a:any;b?:any;}[] { return [{a:""}] } +>foo : { (bar: number): { a: number; }[]; (bar: string): { a: number; b: string; }[]; } +>bar : any +>a : any +>b : any +>[{a:""}] : { a: string; }[] +>{a:""} : { a: string; } +>a : string +>"" : string + diff --git a/tests/baselines/reference/functionOverloads43.js b/tests/baselines/reference/functionOverloads43.js new file mode 100644 index 0000000000..2bb4b61af1 --- /dev/null +++ b/tests/baselines/reference/functionOverloads43.js @@ -0,0 +1,24 @@ +//// [functionOverloads43.ts] +function foo(bar: { a:number }[]): number; +function foo(bar: { a:string }[]): string; +function foo([x]: { a:number | string }[]): string | number { + if (x) { + return x.a; + } + + return undefined; +} + +var x = foo([{a: "str"}]); +var y = foo([{a: 100}]); + +//// [functionOverloads43.js] +function foo(_a) { + var x = _a[0]; + if (x) { + return x.a; + } + return undefined; +} +var x = foo([{ a: "str" }]); +var y = foo([{ a: 100 }]); diff --git a/tests/baselines/reference/functionOverloads43.symbols b/tests/baselines/reference/functionOverloads43.symbols new file mode 100644 index 0000000000..179ba3e3fe --- /dev/null +++ b/tests/baselines/reference/functionOverloads43.symbols @@ -0,0 +1,39 @@ +=== tests/cases/compiler/functionOverloads43.ts === +function foo(bar: { a:number }[]): number; +>foo : Symbol(foo, Decl(functionOverloads43.ts, 0, 0), Decl(functionOverloads43.ts, 0, 42), Decl(functionOverloads43.ts, 1, 42)) +>bar : Symbol(bar, Decl(functionOverloads43.ts, 0, 13)) +>a : Symbol(a, Decl(functionOverloads43.ts, 0, 19)) + +function foo(bar: { a:string }[]): string; +>foo : Symbol(foo, Decl(functionOverloads43.ts, 0, 0), Decl(functionOverloads43.ts, 0, 42), Decl(functionOverloads43.ts, 1, 42)) +>bar : Symbol(bar, Decl(functionOverloads43.ts, 1, 13)) +>a : Symbol(a, Decl(functionOverloads43.ts, 1, 19)) + +function foo([x]: { a:number | string }[]): string | number { +>foo : Symbol(foo, Decl(functionOverloads43.ts, 0, 0), Decl(functionOverloads43.ts, 0, 42), Decl(functionOverloads43.ts, 1, 42)) +>x : Symbol(x, Decl(functionOverloads43.ts, 2, 14)) +>a : Symbol(a, Decl(functionOverloads43.ts, 2, 19)) + + if (x) { +>x : Symbol(x, Decl(functionOverloads43.ts, 2, 14)) + + return x.a; +>x.a : Symbol(a, Decl(functionOverloads43.ts, 2, 19)) +>x : Symbol(x, Decl(functionOverloads43.ts, 2, 14)) +>a : Symbol(a, Decl(functionOverloads43.ts, 2, 19)) + } + + return undefined; +>undefined : Symbol(undefined) +} + +var x = foo([{a: "str"}]); +>x : Symbol(x, Decl(functionOverloads43.ts, 10, 3)) +>foo : Symbol(foo, Decl(functionOverloads43.ts, 0, 0), Decl(functionOverloads43.ts, 0, 42), Decl(functionOverloads43.ts, 1, 42)) +>a : Symbol(a, Decl(functionOverloads43.ts, 10, 14)) + +var y = foo([{a: 100}]); +>y : Symbol(y, Decl(functionOverloads43.ts, 11, 3)) +>foo : Symbol(foo, Decl(functionOverloads43.ts, 0, 0), Decl(functionOverloads43.ts, 0, 42), Decl(functionOverloads43.ts, 1, 42)) +>a : Symbol(a, Decl(functionOverloads43.ts, 11, 14)) + diff --git a/tests/baselines/reference/functionOverloads43.types b/tests/baselines/reference/functionOverloads43.types new file mode 100644 index 0000000000..7c0fa8eb81 --- /dev/null +++ b/tests/baselines/reference/functionOverloads43.types @@ -0,0 +1,47 @@ +=== tests/cases/compiler/functionOverloads43.ts === +function foo(bar: { a:number }[]): number; +>foo : { (bar: { a: number; }[]): number; (bar: { a: string; }[]): string; } +>bar : { a: number; }[] +>a : number + +function foo(bar: { a:string }[]): string; +>foo : { (bar: { a: number; }[]): number; (bar: { a: string; }[]): string; } +>bar : { a: string; }[] +>a : string + +function foo([x]: { a:number | string }[]): string | number { +>foo : { (bar: { a: number; }[]): number; (bar: { a: string; }[]): string; } +>x : { a: number | string; } +>a : number | string + + if (x) { +>x : { a: number | string; } + + return x.a; +>x.a : number | string +>x : { a: number | string; } +>a : number | string + } + + return undefined; +>undefined : undefined +} + +var x = foo([{a: "str"}]); +>x : string +>foo([{a: "str"}]) : string +>foo : { (bar: { a: number; }[]): number; (bar: { a: string; }[]): string; } +>[{a: "str"}] : { a: string; }[] +>{a: "str"} : { a: string; } +>a : string +>"str" : string + +var y = foo([{a: 100}]); +>y : number +>foo([{a: 100}]) : number +>foo : { (bar: { a: number; }[]): number; (bar: { a: string; }[]): string; } +>[{a: 100}] : { a: number; }[] +>{a: 100} : { a: number; } +>a : number +>100 : number + diff --git a/tests/baselines/reference/functionOverloads44.js b/tests/baselines/reference/functionOverloads44.js new file mode 100644 index 0000000000..916204d123 --- /dev/null +++ b/tests/baselines/reference/functionOverloads44.js @@ -0,0 +1,37 @@ +//// [functionOverloads44.ts] +interface Animal { animal } +interface Dog extends Animal { dog } +interface Cat extends Animal { cat } + +function foo1(bar: { a:number }[]): Dog; +function foo1(bar: { a:string }[]): Animal; +function foo1([x]: { a:number | string }[]): Dog { + return undefined; +} + +function foo2(bar: { a:number }[]): Cat; +function foo2(bar: { a:string }[]): Cat | Dog; +function foo2([x]: { a:number | string }[]): Cat { + return undefined; +} + + +var x1 = foo1([{a: "str"}]); +var y1 = foo1([{a: 100}]); + +var x2 = foo2([{a: "str"}]); +var y2 = foo2([{a: 100}]); + +//// [functionOverloads44.js] +function foo1(_a) { + var x = _a[0]; + return undefined; +} +function foo2(_a) { + var x = _a[0]; + return undefined; +} +var x1 = foo1([{ a: "str" }]); +var y1 = foo1([{ a: 100 }]); +var x2 = foo2([{ a: "str" }]); +var y2 = foo2([{ a: 100 }]); diff --git a/tests/baselines/reference/functionOverloads44.symbols b/tests/baselines/reference/functionOverloads44.symbols new file mode 100644 index 0000000000..3520777a83 --- /dev/null +++ b/tests/baselines/reference/functionOverloads44.symbols @@ -0,0 +1,81 @@ +=== tests/cases/compiler/functionOverloads44.ts === +interface Animal { animal } +>Animal : Symbol(Animal, Decl(functionOverloads44.ts, 0, 0)) +>animal : Symbol(animal, Decl(functionOverloads44.ts, 0, 18)) + +interface Dog extends Animal { dog } +>Dog : Symbol(Dog, Decl(functionOverloads44.ts, 0, 27)) +>Animal : Symbol(Animal, Decl(functionOverloads44.ts, 0, 0)) +>dog : Symbol(dog, Decl(functionOverloads44.ts, 1, 30)) + +interface Cat extends Animal { cat } +>Cat : Symbol(Cat, Decl(functionOverloads44.ts, 1, 36)) +>Animal : Symbol(Animal, Decl(functionOverloads44.ts, 0, 0)) +>cat : Symbol(cat, Decl(functionOverloads44.ts, 2, 30)) + +function foo1(bar: { a:number }[]): Dog; +>foo1 : Symbol(foo1, Decl(functionOverloads44.ts, 2, 36), Decl(functionOverloads44.ts, 4, 40), Decl(functionOverloads44.ts, 5, 43)) +>bar : Symbol(bar, Decl(functionOverloads44.ts, 4, 14)) +>a : Symbol(a, Decl(functionOverloads44.ts, 4, 20)) +>Dog : Symbol(Dog, Decl(functionOverloads44.ts, 0, 27)) + +function foo1(bar: { a:string }[]): Animal; +>foo1 : Symbol(foo1, Decl(functionOverloads44.ts, 2, 36), Decl(functionOverloads44.ts, 4, 40), Decl(functionOverloads44.ts, 5, 43)) +>bar : Symbol(bar, Decl(functionOverloads44.ts, 5, 14)) +>a : Symbol(a, Decl(functionOverloads44.ts, 5, 20)) +>Animal : Symbol(Animal, Decl(functionOverloads44.ts, 0, 0)) + +function foo1([x]: { a:number | string }[]): Dog { +>foo1 : Symbol(foo1, Decl(functionOverloads44.ts, 2, 36), Decl(functionOverloads44.ts, 4, 40), Decl(functionOverloads44.ts, 5, 43)) +>x : Symbol(x, Decl(functionOverloads44.ts, 6, 15)) +>a : Symbol(a, Decl(functionOverloads44.ts, 6, 20)) +>Dog : Symbol(Dog, Decl(functionOverloads44.ts, 0, 27)) + + return undefined; +>undefined : Symbol(undefined) +} + +function foo2(bar: { a:number }[]): Cat; +>foo2 : Symbol(foo2, Decl(functionOverloads44.ts, 8, 1), Decl(functionOverloads44.ts, 10, 40), Decl(functionOverloads44.ts, 11, 46)) +>bar : Symbol(bar, Decl(functionOverloads44.ts, 10, 14)) +>a : Symbol(a, Decl(functionOverloads44.ts, 10, 20)) +>Cat : Symbol(Cat, Decl(functionOverloads44.ts, 1, 36)) + +function foo2(bar: { a:string }[]): Cat | Dog; +>foo2 : Symbol(foo2, Decl(functionOverloads44.ts, 8, 1), Decl(functionOverloads44.ts, 10, 40), Decl(functionOverloads44.ts, 11, 46)) +>bar : Symbol(bar, Decl(functionOverloads44.ts, 11, 14)) +>a : Symbol(a, Decl(functionOverloads44.ts, 11, 20)) +>Cat : Symbol(Cat, Decl(functionOverloads44.ts, 1, 36)) +>Dog : Symbol(Dog, Decl(functionOverloads44.ts, 0, 27)) + +function foo2([x]: { a:number | string }[]): Cat { +>foo2 : Symbol(foo2, Decl(functionOverloads44.ts, 8, 1), Decl(functionOverloads44.ts, 10, 40), Decl(functionOverloads44.ts, 11, 46)) +>x : Symbol(x, Decl(functionOverloads44.ts, 12, 15)) +>a : Symbol(a, Decl(functionOverloads44.ts, 12, 20)) +>Cat : Symbol(Cat, Decl(functionOverloads44.ts, 1, 36)) + + return undefined; +>undefined : Symbol(undefined) +} + + +var x1 = foo1([{a: "str"}]); +>x1 : Symbol(x1, Decl(functionOverloads44.ts, 17, 3)) +>foo1 : Symbol(foo1, Decl(functionOverloads44.ts, 2, 36), Decl(functionOverloads44.ts, 4, 40), Decl(functionOverloads44.ts, 5, 43)) +>a : Symbol(a, Decl(functionOverloads44.ts, 17, 16)) + +var y1 = foo1([{a: 100}]); +>y1 : Symbol(y1, Decl(functionOverloads44.ts, 18, 3)) +>foo1 : Symbol(foo1, Decl(functionOverloads44.ts, 2, 36), Decl(functionOverloads44.ts, 4, 40), Decl(functionOverloads44.ts, 5, 43)) +>a : Symbol(a, Decl(functionOverloads44.ts, 18, 16)) + +var x2 = foo2([{a: "str"}]); +>x2 : Symbol(x2, Decl(functionOverloads44.ts, 20, 3)) +>foo2 : Symbol(foo2, Decl(functionOverloads44.ts, 8, 1), Decl(functionOverloads44.ts, 10, 40), Decl(functionOverloads44.ts, 11, 46)) +>a : Symbol(a, Decl(functionOverloads44.ts, 20, 16)) + +var y2 = foo2([{a: 100}]); +>y2 : Symbol(y2, Decl(functionOverloads44.ts, 21, 3)) +>foo2 : Symbol(foo2, Decl(functionOverloads44.ts, 8, 1), Decl(functionOverloads44.ts, 10, 40), Decl(functionOverloads44.ts, 11, 46)) +>a : Symbol(a, Decl(functionOverloads44.ts, 21, 16)) + diff --git a/tests/baselines/reference/functionOverloads44.types b/tests/baselines/reference/functionOverloads44.types new file mode 100644 index 0000000000..56cad09b47 --- /dev/null +++ b/tests/baselines/reference/functionOverloads44.types @@ -0,0 +1,97 @@ +=== tests/cases/compiler/functionOverloads44.ts === +interface Animal { animal } +>Animal : Animal +>animal : any + +interface Dog extends Animal { dog } +>Dog : Dog +>Animal : Animal +>dog : any + +interface Cat extends Animal { cat } +>Cat : Cat +>Animal : Animal +>cat : any + +function foo1(bar: { a:number }[]): Dog; +>foo1 : { (bar: { a: number; }[]): Dog; (bar: { a: string; }[]): Animal; } +>bar : { a: number; }[] +>a : number +>Dog : Dog + +function foo1(bar: { a:string }[]): Animal; +>foo1 : { (bar: { a: number; }[]): Dog; (bar: { a: string; }[]): Animal; } +>bar : { a: string; }[] +>a : string +>Animal : Animal + +function foo1([x]: { a:number | string }[]): Dog { +>foo1 : { (bar: { a: number; }[]): Dog; (bar: { a: string; }[]): Animal; } +>x : { a: number | string; } +>a : number | string +>Dog : Dog + + return undefined; +>undefined : undefined +} + +function foo2(bar: { a:number }[]): Cat; +>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Cat | Dog; } +>bar : { a: number; }[] +>a : number +>Cat : Cat + +function foo2(bar: { a:string }[]): Cat | Dog; +>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Cat | Dog; } +>bar : { a: string; }[] +>a : string +>Cat : Cat +>Dog : Dog + +function foo2([x]: { a:number | string }[]): Cat { +>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Cat | Dog; } +>x : { a: number | string; } +>a : number | string +>Cat : Cat + + return undefined; +>undefined : undefined +} + + +var x1 = foo1([{a: "str"}]); +>x1 : Animal +>foo1([{a: "str"}]) : Animal +>foo1 : { (bar: { a: number; }[]): Dog; (bar: { a: string; }[]): Animal; } +>[{a: "str"}] : { a: string; }[] +>{a: "str"} : { a: string; } +>a : string +>"str" : string + +var y1 = foo1([{a: 100}]); +>y1 : Dog +>foo1([{a: 100}]) : Dog +>foo1 : { (bar: { a: number; }[]): Dog; (bar: { a: string; }[]): Animal; } +>[{a: 100}] : { a: number; }[] +>{a: 100} : { a: number; } +>a : number +>100 : number + +var x2 = foo2([{a: "str"}]); +>x2 : Cat | Dog +>foo2([{a: "str"}]) : Cat | Dog +>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Cat | Dog; } +>[{a: "str"}] : { a: string; }[] +>{a: "str"} : { a: string; } +>a : string +>"str" : string + +var y2 = foo2([{a: 100}]); +>y2 : Cat +>foo2([{a: 100}]) : Cat +>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Cat | Dog; } +>[{a: 100}] : { a: number; }[] +>{a: 100} : { a: number; } +>a : number +>100 : number + diff --git a/tests/baselines/reference/functionOverloads45.js b/tests/baselines/reference/functionOverloads45.js new file mode 100644 index 0000000000..89bf41893c --- /dev/null +++ b/tests/baselines/reference/functionOverloads45.js @@ -0,0 +1,37 @@ +//// [functionOverloads45.ts] +interface Animal { animal } +interface Dog extends Animal { dog } +interface Cat extends Animal { cat } + +function foo1(bar: { a:number }[]): Cat; +function foo1(bar: { a:string }[]): Dog; +function foo1([x]: { a:number | string }[]): Animal { + return undefined; +} + +function foo2(bar: { a:number }[]): Cat; +function foo2(bar: { a:string }[]): Dog; +function foo2([x]: { a:number | string }[]): Cat | Dog { + return undefined; +} + + +var x1 = foo1([{a: "str"}]); +var y1 = foo1([{a: 100}]); + +var x2 = foo2([{a: "str"}]); +var y2 = foo2([{a: 100}]); + +//// [functionOverloads45.js] +function foo1(_a) { + var x = _a[0]; + return undefined; +} +function foo2(_a) { + var x = _a[0]; + return undefined; +} +var x1 = foo1([{ a: "str" }]); +var y1 = foo1([{ a: 100 }]); +var x2 = foo2([{ a: "str" }]); +var y2 = foo2([{ a: 100 }]); diff --git a/tests/baselines/reference/functionOverloads45.symbols b/tests/baselines/reference/functionOverloads45.symbols new file mode 100644 index 0000000000..2859933909 --- /dev/null +++ b/tests/baselines/reference/functionOverloads45.symbols @@ -0,0 +1,81 @@ +=== tests/cases/compiler/functionOverloads45.ts === +interface Animal { animal } +>Animal : Symbol(Animal, Decl(functionOverloads45.ts, 0, 0)) +>animal : Symbol(animal, Decl(functionOverloads45.ts, 0, 18)) + +interface Dog extends Animal { dog } +>Dog : Symbol(Dog, Decl(functionOverloads45.ts, 0, 27)) +>Animal : Symbol(Animal, Decl(functionOverloads45.ts, 0, 0)) +>dog : Symbol(dog, Decl(functionOverloads45.ts, 1, 30)) + +interface Cat extends Animal { cat } +>Cat : Symbol(Cat, Decl(functionOverloads45.ts, 1, 36)) +>Animal : Symbol(Animal, Decl(functionOverloads45.ts, 0, 0)) +>cat : Symbol(cat, Decl(functionOverloads45.ts, 2, 30)) + +function foo1(bar: { a:number }[]): Cat; +>foo1 : Symbol(foo1, Decl(functionOverloads45.ts, 2, 36), Decl(functionOverloads45.ts, 4, 40), Decl(functionOverloads45.ts, 5, 40)) +>bar : Symbol(bar, Decl(functionOverloads45.ts, 4, 14)) +>a : Symbol(a, Decl(functionOverloads45.ts, 4, 20)) +>Cat : Symbol(Cat, Decl(functionOverloads45.ts, 1, 36)) + +function foo1(bar: { a:string }[]): Dog; +>foo1 : Symbol(foo1, Decl(functionOverloads45.ts, 2, 36), Decl(functionOverloads45.ts, 4, 40), Decl(functionOverloads45.ts, 5, 40)) +>bar : Symbol(bar, Decl(functionOverloads45.ts, 5, 14)) +>a : Symbol(a, Decl(functionOverloads45.ts, 5, 20)) +>Dog : Symbol(Dog, Decl(functionOverloads45.ts, 0, 27)) + +function foo1([x]: { a:number | string }[]): Animal { +>foo1 : Symbol(foo1, Decl(functionOverloads45.ts, 2, 36), Decl(functionOverloads45.ts, 4, 40), Decl(functionOverloads45.ts, 5, 40)) +>x : Symbol(x, Decl(functionOverloads45.ts, 6, 15)) +>a : Symbol(a, Decl(functionOverloads45.ts, 6, 20)) +>Animal : Symbol(Animal, Decl(functionOverloads45.ts, 0, 0)) + + return undefined; +>undefined : Symbol(undefined) +} + +function foo2(bar: { a:number }[]): Cat; +>foo2 : Symbol(foo2, Decl(functionOverloads45.ts, 8, 1), Decl(functionOverloads45.ts, 10, 40), Decl(functionOverloads45.ts, 11, 40)) +>bar : Symbol(bar, Decl(functionOverloads45.ts, 10, 14)) +>a : Symbol(a, Decl(functionOverloads45.ts, 10, 20)) +>Cat : Symbol(Cat, Decl(functionOverloads45.ts, 1, 36)) + +function foo2(bar: { a:string }[]): Dog; +>foo2 : Symbol(foo2, Decl(functionOverloads45.ts, 8, 1), Decl(functionOverloads45.ts, 10, 40), Decl(functionOverloads45.ts, 11, 40)) +>bar : Symbol(bar, Decl(functionOverloads45.ts, 11, 14)) +>a : Symbol(a, Decl(functionOverloads45.ts, 11, 20)) +>Dog : Symbol(Dog, Decl(functionOverloads45.ts, 0, 27)) + +function foo2([x]: { a:number | string }[]): Cat | Dog { +>foo2 : Symbol(foo2, Decl(functionOverloads45.ts, 8, 1), Decl(functionOverloads45.ts, 10, 40), Decl(functionOverloads45.ts, 11, 40)) +>x : Symbol(x, Decl(functionOverloads45.ts, 12, 15)) +>a : Symbol(a, Decl(functionOverloads45.ts, 12, 20)) +>Cat : Symbol(Cat, Decl(functionOverloads45.ts, 1, 36)) +>Dog : Symbol(Dog, Decl(functionOverloads45.ts, 0, 27)) + + return undefined; +>undefined : Symbol(undefined) +} + + +var x1 = foo1([{a: "str"}]); +>x1 : Symbol(x1, Decl(functionOverloads45.ts, 17, 3)) +>foo1 : Symbol(foo1, Decl(functionOverloads45.ts, 2, 36), Decl(functionOverloads45.ts, 4, 40), Decl(functionOverloads45.ts, 5, 40)) +>a : Symbol(a, Decl(functionOverloads45.ts, 17, 16)) + +var y1 = foo1([{a: 100}]); +>y1 : Symbol(y1, Decl(functionOverloads45.ts, 18, 3)) +>foo1 : Symbol(foo1, Decl(functionOverloads45.ts, 2, 36), Decl(functionOverloads45.ts, 4, 40), Decl(functionOverloads45.ts, 5, 40)) +>a : Symbol(a, Decl(functionOverloads45.ts, 18, 16)) + +var x2 = foo2([{a: "str"}]); +>x2 : Symbol(x2, Decl(functionOverloads45.ts, 20, 3)) +>foo2 : Symbol(foo2, Decl(functionOverloads45.ts, 8, 1), Decl(functionOverloads45.ts, 10, 40), Decl(functionOverloads45.ts, 11, 40)) +>a : Symbol(a, Decl(functionOverloads45.ts, 20, 16)) + +var y2 = foo2([{a: 100}]); +>y2 : Symbol(y2, Decl(functionOverloads45.ts, 21, 3)) +>foo2 : Symbol(foo2, Decl(functionOverloads45.ts, 8, 1), Decl(functionOverloads45.ts, 10, 40), Decl(functionOverloads45.ts, 11, 40)) +>a : Symbol(a, Decl(functionOverloads45.ts, 21, 16)) + diff --git a/tests/baselines/reference/functionOverloads45.types b/tests/baselines/reference/functionOverloads45.types new file mode 100644 index 0000000000..257a615e33 --- /dev/null +++ b/tests/baselines/reference/functionOverloads45.types @@ -0,0 +1,97 @@ +=== tests/cases/compiler/functionOverloads45.ts === +interface Animal { animal } +>Animal : Animal +>animal : any + +interface Dog extends Animal { dog } +>Dog : Dog +>Animal : Animal +>dog : any + +interface Cat extends Animal { cat } +>Cat : Cat +>Animal : Animal +>cat : any + +function foo1(bar: { a:number }[]): Cat; +>foo1 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; } +>bar : { a: number; }[] +>a : number +>Cat : Cat + +function foo1(bar: { a:string }[]): Dog; +>foo1 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; } +>bar : { a: string; }[] +>a : string +>Dog : Dog + +function foo1([x]: { a:number | string }[]): Animal { +>foo1 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; } +>x : { a: number | string; } +>a : number | string +>Animal : Animal + + return undefined; +>undefined : undefined +} + +function foo2(bar: { a:number }[]): Cat; +>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; } +>bar : { a: number; }[] +>a : number +>Cat : Cat + +function foo2(bar: { a:string }[]): Dog; +>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; } +>bar : { a: string; }[] +>a : string +>Dog : Dog + +function foo2([x]: { a:number | string }[]): Cat | Dog { +>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; } +>x : { a: number | string; } +>a : number | string +>Cat : Cat +>Dog : Dog + + return undefined; +>undefined : undefined +} + + +var x1 = foo1([{a: "str"}]); +>x1 : Dog +>foo1([{a: "str"}]) : Dog +>foo1 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; } +>[{a: "str"}] : { a: string; }[] +>{a: "str"} : { a: string; } +>a : string +>"str" : string + +var y1 = foo1([{a: 100}]); +>y1 : Cat +>foo1([{a: 100}]) : Cat +>foo1 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; } +>[{a: 100}] : { a: number; }[] +>{a: 100} : { a: number; } +>a : number +>100 : number + +var x2 = foo2([{a: "str"}]); +>x2 : Dog +>foo2([{a: "str"}]) : Dog +>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; } +>[{a: "str"}] : { a: string; }[] +>{a: "str"} : { a: string; } +>a : string +>"str" : string + +var y2 = foo2([{a: 100}]); +>y2 : Cat +>foo2([{a: 100}]) : Cat +>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; } +>[{a: 100}] : { a: number; }[] +>{a: 100} : { a: number; } +>a : number +>100 : number + diff --git a/tests/baselines/reference/overloadOnConstConstraintChecks4.errors.txt b/tests/baselines/reference/overloadOnConstConstraintChecks4.errors.txt deleted file mode 100644 index 7a8037b3dd..0000000000 --- a/tests/baselines/reference/overloadOnConstConstraintChecks4.errors.txt +++ /dev/null @@ -1,19 +0,0 @@ -tests/cases/compiler/overloadOnConstConstraintChecks4.ts(9,10): error TS2394: Overload signature is not compatible with function implementation. - - -==== tests/cases/compiler/overloadOnConstConstraintChecks4.ts (1 errors) ==== - class Z { } - class A extends Z { private x = 1 } - class B extends A {} - class C extends A { - public foo() { } - } - function foo(name: 'hi'): B; - function foo(name: 'bye'): C; - function foo(name: string): A; // error - ~~~ -!!! error TS2394: Overload signature is not compatible with function implementation. - function foo(name: any): Z { - return null; - } - \ No newline at end of file diff --git a/tests/baselines/reference/overloadOnConstConstraintChecks4.js b/tests/baselines/reference/overloadOnConstConstraintChecks4.js index 10733fa8ea..d73c59863a 100644 --- a/tests/baselines/reference/overloadOnConstConstraintChecks4.js +++ b/tests/baselines/reference/overloadOnConstConstraintChecks4.js @@ -7,7 +7,7 @@ class C extends A { } function foo(name: 'hi'): B; function foo(name: 'bye'): C; -function foo(name: string): A; // error +function foo(name: string): A; function foo(name: any): Z { return null; } diff --git a/tests/baselines/reference/overloadOnConstConstraintChecks4.symbols b/tests/baselines/reference/overloadOnConstConstraintChecks4.symbols new file mode 100644 index 0000000000..6e2a34b55e --- /dev/null +++ b/tests/baselines/reference/overloadOnConstConstraintChecks4.symbols @@ -0,0 +1,43 @@ +=== tests/cases/compiler/overloadOnConstConstraintChecks4.ts === +class Z { } +>Z : Symbol(Z, Decl(overloadOnConstConstraintChecks4.ts, 0, 0)) + +class A extends Z { private x = 1 } +>A : Symbol(A, Decl(overloadOnConstConstraintChecks4.ts, 0, 11)) +>Z : Symbol(Z, Decl(overloadOnConstConstraintChecks4.ts, 0, 0)) +>x : Symbol(x, Decl(overloadOnConstConstraintChecks4.ts, 1, 19)) + +class B extends A {} +>B : Symbol(B, Decl(overloadOnConstConstraintChecks4.ts, 1, 35)) +>A : Symbol(A, Decl(overloadOnConstConstraintChecks4.ts, 0, 11)) + +class C extends A { +>C : Symbol(C, Decl(overloadOnConstConstraintChecks4.ts, 2, 20)) +>A : Symbol(A, Decl(overloadOnConstConstraintChecks4.ts, 0, 11)) + + public foo() { } +>foo : Symbol(foo, Decl(overloadOnConstConstraintChecks4.ts, 3, 19)) +} +function foo(name: 'hi'): B; +>foo : Symbol(foo, Decl(overloadOnConstConstraintChecks4.ts, 5, 1), Decl(overloadOnConstConstraintChecks4.ts, 6, 28), Decl(overloadOnConstConstraintChecks4.ts, 7, 29), Decl(overloadOnConstConstraintChecks4.ts, 8, 30)) +>name : Symbol(name, Decl(overloadOnConstConstraintChecks4.ts, 6, 13)) +>B : Symbol(B, Decl(overloadOnConstConstraintChecks4.ts, 1, 35)) + +function foo(name: 'bye'): C; +>foo : Symbol(foo, Decl(overloadOnConstConstraintChecks4.ts, 5, 1), Decl(overloadOnConstConstraintChecks4.ts, 6, 28), Decl(overloadOnConstConstraintChecks4.ts, 7, 29), Decl(overloadOnConstConstraintChecks4.ts, 8, 30)) +>name : Symbol(name, Decl(overloadOnConstConstraintChecks4.ts, 7, 13)) +>C : Symbol(C, Decl(overloadOnConstConstraintChecks4.ts, 2, 20)) + +function foo(name: string): A; +>foo : Symbol(foo, Decl(overloadOnConstConstraintChecks4.ts, 5, 1), Decl(overloadOnConstConstraintChecks4.ts, 6, 28), Decl(overloadOnConstConstraintChecks4.ts, 7, 29), Decl(overloadOnConstConstraintChecks4.ts, 8, 30)) +>name : Symbol(name, Decl(overloadOnConstConstraintChecks4.ts, 8, 13)) +>A : Symbol(A, Decl(overloadOnConstConstraintChecks4.ts, 0, 11)) + +function foo(name: any): Z { +>foo : Symbol(foo, Decl(overloadOnConstConstraintChecks4.ts, 5, 1), Decl(overloadOnConstConstraintChecks4.ts, 6, 28), Decl(overloadOnConstConstraintChecks4.ts, 7, 29), Decl(overloadOnConstConstraintChecks4.ts, 8, 30)) +>name : Symbol(name, Decl(overloadOnConstConstraintChecks4.ts, 9, 13)) +>Z : Symbol(Z, Decl(overloadOnConstConstraintChecks4.ts, 0, 0)) + + return null; +} + diff --git a/tests/baselines/reference/overloadOnConstConstraintChecks4.types b/tests/baselines/reference/overloadOnConstConstraintChecks4.types new file mode 100644 index 0000000000..6ca7288ead --- /dev/null +++ b/tests/baselines/reference/overloadOnConstConstraintChecks4.types @@ -0,0 +1,45 @@ +=== tests/cases/compiler/overloadOnConstConstraintChecks4.ts === +class Z { } +>Z : Z + +class A extends Z { private x = 1 } +>A : A +>Z : Z +>x : number +>1 : number + +class B extends A {} +>B : B +>A : A + +class C extends A { +>C : C +>A : A + + public foo() { } +>foo : () => void +} +function foo(name: 'hi'): B; +>foo : { (name: "hi"): B; (name: "bye"): C; (name: string): A; } +>name : "hi" +>B : B + +function foo(name: 'bye'): C; +>foo : { (name: "hi"): B; (name: "bye"): C; (name: string): A; } +>name : "bye" +>C : C + +function foo(name: string): A; +>foo : { (name: "hi"): B; (name: "bye"): C; (name: string): A; } +>name : string +>A : A + +function foo(name: any): Z { +>foo : { (name: "hi"): B; (name: "bye"): C; (name: string): A; } +>name : any +>Z : Z + + return null; +>null : null +} + diff --git a/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.js b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.js new file mode 100644 index 0000000000..5d414c97d0 --- /dev/null +++ b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.js @@ -0,0 +1,58 @@ +//// [prefixUnaryOperatorsOnExportedVariables.ts] + +export var x = false; +export var y = 1; +if (!x) { + +} + +if (+x) { + +} + +if (-x) { + +} + +if (~x) { + +} + +if (void x) { + +} + +if (typeof x) { + +} + +if (++y) { + +} + +//// [prefixUnaryOperatorsOnExportedVariables.js] +System.register([], function(exports_1) { + "use strict"; + var x, y; + return { + setters:[], + execute: function() { + exports_1("x", x = false); + exports_1("y", y = 1); + if (!x) { + } + if (+x) { + } + if (-x) { + } + if (~x) { + } + if (void x) { + } + if (typeof x) { + } + if (exports_1("y", ++y)) { + } + } + } +}); diff --git a/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.symbols b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.symbols new file mode 100644 index 0000000000..c8293ef190 --- /dev/null +++ b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.symbols @@ -0,0 +1,42 @@ +=== tests/cases/compiler/prefixUnaryOperatorsOnExportedVariables.ts === + +export var x = false; +>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10)) + +export var y = 1; +>y : Symbol(y, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 2, 10)) + +if (!x) { +>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10)) + +} + +if (+x) { +>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10)) + +} + +if (-x) { +>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10)) + +} + +if (~x) { +>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10)) + +} + +if (void x) { +>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10)) + +} + +if (typeof x) { +>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10)) + +} + +if (++y) { +>y : Symbol(y, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 2, 10)) + +} diff --git a/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.types b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.types new file mode 100644 index 0000000000..c75ba492c3 --- /dev/null +++ b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.types @@ -0,0 +1,51 @@ +=== tests/cases/compiler/prefixUnaryOperatorsOnExportedVariables.ts === + +export var x = false; +>x : boolean +>false : boolean + +export var y = 1; +>y : number +>1 : number + +if (!x) { +>!x : boolean +>x : boolean + +} + +if (+x) { +>+x : number +>x : boolean + +} + +if (-x) { +>-x : number +>x : boolean + +} + +if (~x) { +>~x : number +>x : boolean + +} + +if (void x) { +>void x : undefined +>x : boolean + +} + +if (typeof x) { +>typeof x : string +>x : boolean + +} + +if (++y) { +>++y : number +>y : number + +} diff --git a/tests/baselines/reference/stringLiteralTypesAsTags01.js b/tests/baselines/reference/stringLiteralTypesAsTags01.js index 3fe33ace48..b7b3872ce6 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTags01.js +++ b/tests/baselines/reference/stringLiteralTypesAsTags01.js @@ -20,7 +20,7 @@ function hasKind(entity: Entity, kind: "A"): entity is A; function hasKind(entity: Entity, kind: "B"): entity is B; function hasKind(entity: Entity, kind: Kind): entity is Entity; function hasKind(entity: Entity, kind: Kind): boolean { - return kind === is; + return entity.kind === kind; } let x: A = { @@ -44,7 +44,7 @@ else { //// [stringLiteralTypesAsTags01.js] function hasKind(entity, kind) { - return kind === is; + return entity.kind === kind; } var x = { kind: "A", diff --git a/tests/baselines/reference/stringLiteralTypesAsTags01.symbols b/tests/baselines/reference/stringLiteralTypesAsTags01.symbols new file mode 100644 index 0000000000..afdeeff71a --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesAsTags01.symbols @@ -0,0 +1,112 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts === + +type Kind = "A" | "B" +>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags01.ts, 0, 0)) + +interface Entity { +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags01.ts, 1, 21)) + + kind: Kind; +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags01.ts, 3, 18)) +>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags01.ts, 0, 0)) +} + +interface A extends Entity { +>A : Symbol(A, Decl(stringLiteralTypesAsTags01.ts, 5, 1)) +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags01.ts, 1, 21)) + + kind: "A"; +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags01.ts, 7, 28)) + + a: number; +>a : Symbol(a, Decl(stringLiteralTypesAsTags01.ts, 8, 14)) +} + +interface B extends Entity { +>B : Symbol(B, Decl(stringLiteralTypesAsTags01.ts, 10, 1)) +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags01.ts, 1, 21)) + + kind: "B"; +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags01.ts, 12, 28)) + + b: string; +>b : Symbol(b, Decl(stringLiteralTypesAsTags01.ts, 13, 14)) +} + +function hasKind(entity: Entity, kind: "A"): entity is A; +>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags01.ts, 15, 1), Decl(stringLiteralTypesAsTags01.ts, 17, 57), Decl(stringLiteralTypesAsTags01.ts, 18, 57), Decl(stringLiteralTypesAsTags01.ts, 19, 63)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags01.ts, 17, 17)) +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags01.ts, 1, 21)) +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags01.ts, 17, 32)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags01.ts, 17, 17)) +>A : Symbol(A, Decl(stringLiteralTypesAsTags01.ts, 5, 1)) + +function hasKind(entity: Entity, kind: "B"): entity is B; +>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags01.ts, 15, 1), Decl(stringLiteralTypesAsTags01.ts, 17, 57), Decl(stringLiteralTypesAsTags01.ts, 18, 57), Decl(stringLiteralTypesAsTags01.ts, 19, 63)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags01.ts, 18, 17)) +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags01.ts, 1, 21)) +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags01.ts, 18, 32)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags01.ts, 18, 17)) +>B : Symbol(B, Decl(stringLiteralTypesAsTags01.ts, 10, 1)) + +function hasKind(entity: Entity, kind: Kind): entity is Entity; +>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags01.ts, 15, 1), Decl(stringLiteralTypesAsTags01.ts, 17, 57), Decl(stringLiteralTypesAsTags01.ts, 18, 57), Decl(stringLiteralTypesAsTags01.ts, 19, 63)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags01.ts, 19, 17)) +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags01.ts, 1, 21)) +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags01.ts, 19, 32)) +>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags01.ts, 0, 0)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags01.ts, 19, 17)) +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags01.ts, 1, 21)) + +function hasKind(entity: Entity, kind: Kind): boolean { +>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags01.ts, 15, 1), Decl(stringLiteralTypesAsTags01.ts, 17, 57), Decl(stringLiteralTypesAsTags01.ts, 18, 57), Decl(stringLiteralTypesAsTags01.ts, 19, 63)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags01.ts, 20, 17)) +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags01.ts, 1, 21)) +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags01.ts, 20, 32)) +>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags01.ts, 0, 0)) + + return entity.kind === kind; +>entity.kind : Symbol(Entity.kind, Decl(stringLiteralTypesAsTags01.ts, 3, 18)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags01.ts, 20, 17)) +>kind : Symbol(Entity.kind, Decl(stringLiteralTypesAsTags01.ts, 3, 18)) +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags01.ts, 20, 32)) +} + +let x: A = { +>x : Symbol(x, Decl(stringLiteralTypesAsTags01.ts, 24, 3)) +>A : Symbol(A, Decl(stringLiteralTypesAsTags01.ts, 5, 1)) + + kind: "A", +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags01.ts, 24, 12)) + + a: 100, +>a : Symbol(a, Decl(stringLiteralTypesAsTags01.ts, 25, 14)) +} + +if (hasKind(x, "A")) { +>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags01.ts, 15, 1), Decl(stringLiteralTypesAsTags01.ts, 17, 57), Decl(stringLiteralTypesAsTags01.ts, 18, 57), Decl(stringLiteralTypesAsTags01.ts, 19, 63)) +>x : Symbol(x, Decl(stringLiteralTypesAsTags01.ts, 24, 3)) + + let a = x; +>a : Symbol(a, Decl(stringLiteralTypesAsTags01.ts, 30, 7)) +>x : Symbol(x, Decl(stringLiteralTypesAsTags01.ts, 24, 3)) +} +else { + let b = x; +>b : Symbol(b, Decl(stringLiteralTypesAsTags01.ts, 33, 7)) +>x : Symbol(x, Decl(stringLiteralTypesAsTags01.ts, 24, 3)) +} + +if (!hasKind(x, "B")) { +>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags01.ts, 15, 1), Decl(stringLiteralTypesAsTags01.ts, 17, 57), Decl(stringLiteralTypesAsTags01.ts, 18, 57), Decl(stringLiteralTypesAsTags01.ts, 19, 63)) +>x : Symbol(x, Decl(stringLiteralTypesAsTags01.ts, 24, 3)) + + let c = x; +>c : Symbol(c, Decl(stringLiteralTypesAsTags01.ts, 37, 7)) +>x : Symbol(x, Decl(stringLiteralTypesAsTags01.ts, 24, 3)) +} +else { + let d = x; +>d : Symbol(d, Decl(stringLiteralTypesAsTags01.ts, 40, 7)) +>x : Symbol(x, Decl(stringLiteralTypesAsTags01.ts, 24, 3)) +} diff --git a/tests/baselines/reference/stringLiteralTypesAsTags01.types b/tests/baselines/reference/stringLiteralTypesAsTags01.types new file mode 100644 index 0000000000..6966ede548 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesAsTags01.types @@ -0,0 +1,121 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts === + +type Kind = "A" | "B" +>Kind : "A" | "B" + +interface Entity { +>Entity : Entity + + kind: Kind; +>kind : "A" | "B" +>Kind : "A" | "B" +} + +interface A extends Entity { +>A : A +>Entity : Entity + + kind: "A"; +>kind : "A" + + a: number; +>a : number +} + +interface B extends Entity { +>B : B +>Entity : Entity + + kind: "B"; +>kind : "B" + + b: string; +>b : string +} + +function hasKind(entity: Entity, kind: "A"): entity is A; +>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: "A" | "B"): entity is Entity; } +>entity : Entity +>Entity : Entity +>kind : "A" +>entity : any +>A : A + +function hasKind(entity: Entity, kind: "B"): entity is B; +>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: "A" | "B"): entity is Entity; } +>entity : Entity +>Entity : Entity +>kind : "B" +>entity : any +>B : B + +function hasKind(entity: Entity, kind: Kind): entity is Entity; +>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: "A" | "B"): entity is Entity; } +>entity : Entity +>Entity : Entity +>kind : "A" | "B" +>Kind : "A" | "B" +>entity : any +>Entity : Entity + +function hasKind(entity: Entity, kind: Kind): boolean { +>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: "A" | "B"): entity is Entity; } +>entity : Entity +>Entity : Entity +>kind : "A" | "B" +>Kind : "A" | "B" + + return entity.kind === kind; +>entity.kind === kind : boolean +>entity.kind : "A" | "B" +>entity : Entity +>kind : "A" | "B" +>kind : "A" | "B" +} + +let x: A = { +>x : A +>A : A +>{ kind: "A", a: 100,} : { kind: "A"; a: number; } + + kind: "A", +>kind : "A" +>"A" : "A" + + a: 100, +>a : number +>100 : number +} + +if (hasKind(x, "A")) { +>hasKind(x, "A") : entity is A +>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: "A" | "B"): entity is Entity; } +>x : A +>"A" : "A" + + let a = x; +>a : A +>x : A +} +else { + let b = x; +>b : A +>x : A +} + +if (!hasKind(x, "B")) { +>!hasKind(x, "B") : boolean +>hasKind(x, "B") : entity is B +>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: "A" | "B"): entity is Entity; } +>x : A +>"B" : "B" + + let c = x; +>c : A +>x : A +} +else { + let d = x; +>d : A +>x : A +} diff --git a/tests/baselines/reference/stringLiteralTypesAsTags01.errors.txt b/tests/baselines/reference/stringLiteralTypesAsTags02.errors.txt similarity index 56% rename from tests/baselines/reference/stringLiteralTypesAsTags01.errors.txt rename to tests/baselines/reference/stringLiteralTypesAsTags02.errors.txt index 90c8c3efdf..077113632d 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTags01.errors.txt +++ b/tests/baselines/reference/stringLiteralTypesAsTags02.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(20,10): error TS2394: Overload signature is not compatible with function implementation. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(22,21): error TS2304: Cannot find name 'is'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags02.ts(18,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags02.ts(19,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts (2 errors) ==== +==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags02.ts (2 errors) ==== type Kind = "A" | "B" @@ -21,14 +21,13 @@ tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts(22,21) } function hasKind(entity: Entity, kind: "A"): entity is A; - function hasKind(entity: Entity, kind: "B"): entity is B; - function hasKind(entity: Entity, kind: Kind): entity is Entity; ~~~~~~~ -!!! error TS2394: Overload signature is not compatible with function implementation. - function hasKind(entity: Entity, kind: Kind): boolean { - return kind === is; - ~~ -!!! error TS2304: Cannot find name 'is'. +!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. + function hasKind(entity: Entity, kind: "B"): entity is B; + ~~~~~~~ +!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. + function hasKind(entity: Entity, kind: Kind): entity is (A | B) { + return entity.kind === kind; } let x: A = { diff --git a/tests/baselines/reference/stringLiteralTypesAsTags02.js b/tests/baselines/reference/stringLiteralTypesAsTags02.js new file mode 100644 index 0000000000..e83f1ad46e --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesAsTags02.js @@ -0,0 +1,81 @@ +//// [stringLiteralTypesAsTags02.ts] + +type Kind = "A" | "B" + +interface Entity { + kind: Kind; +} + +interface A extends Entity { + kind: "A"; + a: number; +} + +interface B extends Entity { + kind: "B"; + b: string; +} + +function hasKind(entity: Entity, kind: "A"): entity is A; +function hasKind(entity: Entity, kind: "B"): entity is B; +function hasKind(entity: Entity, kind: Kind): entity is (A | B) { + return entity.kind === kind; +} + +let x: A = { + kind: "A", + a: 100, +} + +if (hasKind(x, "A")) { + let a = x; +} +else { + let b = x; +} + +if (!hasKind(x, "B")) { + let c = x; +} +else { + let d = x; +} + +//// [stringLiteralTypesAsTags02.js] +function hasKind(entity, kind) { + return entity.kind === kind; +} +var x = { + kind: "A", + a: 100 +}; +if (hasKind(x, "A")) { + var a = x; +} +else { + var b = x; +} +if (!hasKind(x, "B")) { + var c = x; +} +else { + var d = x; +} + + +//// [stringLiteralTypesAsTags02.d.ts] +declare type Kind = "A" | "B"; +interface Entity { + kind: Kind; +} +interface A extends Entity { + kind: "A"; + a: number; +} +interface B extends Entity { + kind: "B"; + b: string; +} +declare function hasKind(entity: Entity, kind: "A"): entity is A; +declare function hasKind(entity: Entity, kind: "B"): entity is B; +declare let x: A; diff --git a/tests/baselines/reference/stringLiteralTypesAsTags03.js b/tests/baselines/reference/stringLiteralTypesAsTags03.js new file mode 100644 index 0000000000..bb2ed56040 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesAsTags03.js @@ -0,0 +1,85 @@ +//// [stringLiteralTypesAsTags03.ts] + +type Kind = "A" | "B" + +interface Entity { + kind: Kind; +} + +interface A extends Entity { + kind: "A"; + a: number; +} + +interface B extends Entity { + kind: "B"; + b: string; +} + +// Currently (2015-12-14), we write '"A" | "A"' and '"B" | "B"' to avoid +// interpreting respective overloads as "specialized" signatures. +// That way, we can avoid the need to look for a compatible overload +// signature and simply check compatibility with the implementation. +function hasKind(entity: Entity, kind: "A" | "A"): entity is A; +function hasKind(entity: Entity, kind: "B" | "B"): entity is B; +function hasKind(entity: Entity, kind: Kind): entity is Entity { + return entity.kind === kind; +} + +let x: A = { + kind: "A", + a: 100, +} + +if (hasKind(x, "A")) { + let a = x; +} +else { + let b = x; +} + +if (!hasKind(x, "B")) { + let c = x; +} +else { + let d = x; +} + +//// [stringLiteralTypesAsTags03.js] +function hasKind(entity, kind) { + return entity.kind === kind; +} +var x = { + kind: "A", + a: 100 +}; +if (hasKind(x, "A")) { + var a = x; +} +else { + var b = x; +} +if (!hasKind(x, "B")) { + var c = x; +} +else { + var d = x; +} + + +//// [stringLiteralTypesAsTags03.d.ts] +declare type Kind = "A" | "B"; +interface Entity { + kind: Kind; +} +interface A extends Entity { + kind: "A"; + a: number; +} +interface B extends Entity { + kind: "B"; + b: string; +} +declare function hasKind(entity: Entity, kind: "A" | "A"): entity is A; +declare function hasKind(entity: Entity, kind: "B" | "B"): entity is B; +declare let x: A; diff --git a/tests/baselines/reference/stringLiteralTypesAsTags03.symbols b/tests/baselines/reference/stringLiteralTypesAsTags03.symbols new file mode 100644 index 0000000000..3694daf8e0 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesAsTags03.symbols @@ -0,0 +1,109 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags03.ts === + +type Kind = "A" | "B" +>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags03.ts, 0, 0)) + +interface Entity { +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21)) + + kind: Kind; +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 3, 18)) +>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags03.ts, 0, 0)) +} + +interface A extends Entity { +>A : Symbol(A, Decl(stringLiteralTypesAsTags03.ts, 5, 1)) +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21)) + + kind: "A"; +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 7, 28)) + + a: number; +>a : Symbol(a, Decl(stringLiteralTypesAsTags03.ts, 8, 14)) +} + +interface B extends Entity { +>B : Symbol(B, Decl(stringLiteralTypesAsTags03.ts, 10, 1)) +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21)) + + kind: "B"; +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 12, 28)) + + b: string; +>b : Symbol(b, Decl(stringLiteralTypesAsTags03.ts, 13, 14)) +} + +// Currently (2015-12-14), we write '"A" | "A"' and '"B" | "B"' to avoid +// interpreting respective overloads as "specialized" signatures. +// That way, we can avoid the need to look for a compatible overload +// signature and simply check compatibility with the implementation. +function hasKind(entity: Entity, kind: "A" | "A"): entity is A; +>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags03.ts, 15, 1), Decl(stringLiteralTypesAsTags03.ts, 21, 63), Decl(stringLiteralTypesAsTags03.ts, 22, 63)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 21, 17)) +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21)) +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 21, 32)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 21, 17)) +>A : Symbol(A, Decl(stringLiteralTypesAsTags03.ts, 5, 1)) + +function hasKind(entity: Entity, kind: "B" | "B"): entity is B; +>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags03.ts, 15, 1), Decl(stringLiteralTypesAsTags03.ts, 21, 63), Decl(stringLiteralTypesAsTags03.ts, 22, 63)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 22, 17)) +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21)) +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 22, 32)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 22, 17)) +>B : Symbol(B, Decl(stringLiteralTypesAsTags03.ts, 10, 1)) + +function hasKind(entity: Entity, kind: Kind): entity is Entity { +>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags03.ts, 15, 1), Decl(stringLiteralTypesAsTags03.ts, 21, 63), Decl(stringLiteralTypesAsTags03.ts, 22, 63)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 23, 17)) +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21)) +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 23, 32)) +>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags03.ts, 0, 0)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 23, 17)) +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21)) + + return entity.kind === kind; +>entity.kind : Symbol(Entity.kind, Decl(stringLiteralTypesAsTags03.ts, 3, 18)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 23, 17)) +>kind : Symbol(Entity.kind, Decl(stringLiteralTypesAsTags03.ts, 3, 18)) +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 23, 32)) +} + +let x: A = { +>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3)) +>A : Symbol(A, Decl(stringLiteralTypesAsTags03.ts, 5, 1)) + + kind: "A", +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 27, 12)) + + a: 100, +>a : Symbol(a, Decl(stringLiteralTypesAsTags03.ts, 28, 14)) +} + +if (hasKind(x, "A")) { +>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags03.ts, 15, 1), Decl(stringLiteralTypesAsTags03.ts, 21, 63), Decl(stringLiteralTypesAsTags03.ts, 22, 63)) +>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3)) + + let a = x; +>a : Symbol(a, Decl(stringLiteralTypesAsTags03.ts, 33, 7)) +>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3)) +} +else { + let b = x; +>b : Symbol(b, Decl(stringLiteralTypesAsTags03.ts, 36, 7)) +>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3)) +} + +if (!hasKind(x, "B")) { +>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags03.ts, 15, 1), Decl(stringLiteralTypesAsTags03.ts, 21, 63), Decl(stringLiteralTypesAsTags03.ts, 22, 63)) +>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3)) + + let c = x; +>c : Symbol(c, Decl(stringLiteralTypesAsTags03.ts, 40, 7)) +>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3)) +} +else { + let d = x; +>d : Symbol(d, Decl(stringLiteralTypesAsTags03.ts, 43, 7)) +>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3)) +} diff --git a/tests/baselines/reference/stringLiteralTypesAsTags03.types b/tests/baselines/reference/stringLiteralTypesAsTags03.types new file mode 100644 index 0000000000..a1d83a1c05 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesAsTags03.types @@ -0,0 +1,118 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags03.ts === + +type Kind = "A" | "B" +>Kind : "A" | "B" + +interface Entity { +>Entity : Entity + + kind: Kind; +>kind : "A" | "B" +>Kind : "A" | "B" +} + +interface A extends Entity { +>A : A +>Entity : Entity + + kind: "A"; +>kind : "A" + + a: number; +>a : number +} + +interface B extends Entity { +>B : B +>Entity : Entity + + kind: "B"; +>kind : "B" + + b: string; +>b : string +} + +// Currently (2015-12-14), we write '"A" | "A"' and '"B" | "B"' to avoid +// interpreting respective overloads as "specialized" signatures. +// That way, we can avoid the need to look for a compatible overload +// signature and simply check compatibility with the implementation. +function hasKind(entity: Entity, kind: "A" | "A"): entity is A; +>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; } +>entity : Entity +>Entity : Entity +>kind : "A" +>entity : any +>A : A + +function hasKind(entity: Entity, kind: "B" | "B"): entity is B; +>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; } +>entity : Entity +>Entity : Entity +>kind : "B" +>entity : any +>B : B + +function hasKind(entity: Entity, kind: Kind): entity is Entity { +>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; } +>entity : Entity +>Entity : Entity +>kind : "A" | "B" +>Kind : "A" | "B" +>entity : any +>Entity : Entity + + return entity.kind === kind; +>entity.kind === kind : boolean +>entity.kind : "A" | "B" +>entity : Entity +>kind : "A" | "B" +>kind : "A" | "B" +} + +let x: A = { +>x : A +>A : A +>{ kind: "A", a: 100,} : { kind: "A"; a: number; } + + kind: "A", +>kind : "A" +>"A" : "A" + + a: 100, +>a : number +>100 : number +} + +if (hasKind(x, "A")) { +>hasKind(x, "A") : entity is A +>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; } +>x : A +>"A" : "A" + + let a = x; +>a : A +>x : A +} +else { + let b = x; +>b : A +>x : A +} + +if (!hasKind(x, "B")) { +>!hasKind(x, "B") : boolean +>hasKind(x, "B") : entity is B +>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; } +>x : A +>"B" : "B" + + let c = x; +>c : A +>x : A +} +else { + let d = x; +>d : A +>x : A +} diff --git a/tests/baselines/reference/stringLiteralTypesOverloads01.errors.txt b/tests/baselines/reference/stringLiteralTypesOverloads01.errors.txt deleted file mode 100644 index 1592427208..0000000000 --- a/tests/baselines/reference/stringLiteralTypesOverloads01.errors.txt +++ /dev/null @@ -1,59 +0,0 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts(11,10): error TS2354: No best common type exists among return expressions. - - -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts (1 errors) ==== - - type PrimitiveName = 'string' | 'number' | 'boolean'; - - function getFalsyPrimitive(x: "string"): string; - function getFalsyPrimitive(x: "number"): number; - function getFalsyPrimitive(x: "boolean"): boolean; - function getFalsyPrimitive(x: "boolean" | "string"): boolean | string; - function getFalsyPrimitive(x: "boolean" | "number"): boolean | number; - function getFalsyPrimitive(x: "number" | "string"): number | string; - function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean; - function getFalsyPrimitive(x: PrimitiveName) { - ~~~~~~~~~~~~~~~~~ -!!! error TS2354: No best common type exists among return expressions. - if (x === "string") { - return ""; - } - if (x === "number") { - return 0; - } - if (x === "boolean") { - return false; - } - - // Should be unreachable. - throw "Invalid value"; - } - - namespace Consts1 { - const EMPTY_STRING = getFalsyPrimitive("string"); - const ZERO = getFalsyPrimitive('number'); - const FALSE = getFalsyPrimitive("boolean"); - } - - const string: "string" = "string" - const number: "number" = "number" - const boolean: "boolean" = "boolean" - - const stringOrNumber = string || number; - const stringOrBoolean = string || boolean; - const booleanOrNumber = number || boolean; - const stringOrBooleanOrNumber = stringOrBoolean || number; - - namespace Consts2 { - const EMPTY_STRING = getFalsyPrimitive(string); - const ZERO = getFalsyPrimitive(number); - const FALSE = getFalsyPrimitive(boolean); - - const a = getFalsyPrimitive(stringOrNumber); - const b = getFalsyPrimitive(stringOrBoolean); - const c = getFalsyPrimitive(booleanOrNumber); - const d = getFalsyPrimitive(stringOrBooleanOrNumber); - } - - - \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralTypesOverloads01.js b/tests/baselines/reference/stringLiteralTypesOverloads01.js index 73dabd26fa..f3331c9f71 100644 --- a/tests/baselines/reference/stringLiteralTypesOverloads01.js +++ b/tests/baselines/reference/stringLiteralTypesOverloads01.js @@ -9,7 +9,7 @@ function getFalsyPrimitive(x: "boolean" | "string"): boolean | string; function getFalsyPrimitive(x: "boolean" | "number"): boolean | number; function getFalsyPrimitive(x: "number" | "string"): number | string; function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean; -function getFalsyPrimitive(x: PrimitiveName) { +function getFalsyPrimitive(x: PrimitiveName): number | string | boolean { if (x === "string") { return ""; } diff --git a/tests/baselines/reference/stringLiteralTypesOverloads01.symbols b/tests/baselines/reference/stringLiteralTypesOverloads01.symbols new file mode 100644 index 0000000000..c92fe13407 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesOverloads01.symbols @@ -0,0 +1,144 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts === + +type PrimitiveName = 'string' | 'number' | 'boolean'; +>PrimitiveName : Symbol(PrimitiveName, Decl(stringLiteralTypesOverloads01.ts, 0, 0)) + +function getFalsyPrimitive(x: "string"): string; +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90)) +>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 3, 27)) + +function getFalsyPrimitive(x: "number"): number; +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90)) +>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 4, 27)) + +function getFalsyPrimitive(x: "boolean"): boolean; +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90)) +>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 5, 27)) + +function getFalsyPrimitive(x: "boolean" | "string"): boolean | string; +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90)) +>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 6, 27)) + +function getFalsyPrimitive(x: "boolean" | "number"): boolean | number; +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90)) +>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 7, 27)) + +function getFalsyPrimitive(x: "number" | "string"): number | string; +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90)) +>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 8, 27)) + +function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean; +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90)) +>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 9, 27)) + +function getFalsyPrimitive(x: PrimitiveName): number | string | boolean { +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90)) +>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 10, 27)) +>PrimitiveName : Symbol(PrimitiveName, Decl(stringLiteralTypesOverloads01.ts, 0, 0)) + + if (x === "string") { +>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 10, 27)) + + return ""; + } + if (x === "number") { +>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 10, 27)) + + return 0; + } + if (x === "boolean") { +>x : Symbol(x, Decl(stringLiteralTypesOverloads01.ts, 10, 27)) + + return false; + } + + // Should be unreachable. + throw "Invalid value"; +} + +namespace Consts1 { +>Consts1 : Symbol(Consts1, Decl(stringLiteralTypesOverloads01.ts, 23, 1)) + + const EMPTY_STRING = getFalsyPrimitive("string"); +>EMPTY_STRING : Symbol(EMPTY_STRING, Decl(stringLiteralTypesOverloads01.ts, 26, 9)) +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90)) + + const ZERO = getFalsyPrimitive('number'); +>ZERO : Symbol(ZERO, Decl(stringLiteralTypesOverloads01.ts, 27, 9)) +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90)) + + const FALSE = getFalsyPrimitive("boolean"); +>FALSE : Symbol(FALSE, Decl(stringLiteralTypesOverloads01.ts, 28, 9)) +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90)) +} + +const string: "string" = "string" +>string : Symbol(string, Decl(stringLiteralTypesOverloads01.ts, 31, 5)) + +const number: "number" = "number" +>number : Symbol(number, Decl(stringLiteralTypesOverloads01.ts, 32, 5)) + +const boolean: "boolean" = "boolean" +>boolean : Symbol(boolean, Decl(stringLiteralTypesOverloads01.ts, 33, 5)) + +const stringOrNumber = string || number; +>stringOrNumber : Symbol(stringOrNumber, Decl(stringLiteralTypesOverloads01.ts, 35, 5)) +>string : Symbol(string, Decl(stringLiteralTypesOverloads01.ts, 31, 5)) +>number : Symbol(number, Decl(stringLiteralTypesOverloads01.ts, 32, 5)) + +const stringOrBoolean = string || boolean; +>stringOrBoolean : Symbol(stringOrBoolean, Decl(stringLiteralTypesOverloads01.ts, 36, 5)) +>string : Symbol(string, Decl(stringLiteralTypesOverloads01.ts, 31, 5)) +>boolean : Symbol(boolean, Decl(stringLiteralTypesOverloads01.ts, 33, 5)) + +const booleanOrNumber = number || boolean; +>booleanOrNumber : Symbol(booleanOrNumber, Decl(stringLiteralTypesOverloads01.ts, 37, 5)) +>number : Symbol(number, Decl(stringLiteralTypesOverloads01.ts, 32, 5)) +>boolean : Symbol(boolean, Decl(stringLiteralTypesOverloads01.ts, 33, 5)) + +const stringOrBooleanOrNumber = stringOrBoolean || number; +>stringOrBooleanOrNumber : Symbol(stringOrBooleanOrNumber, Decl(stringLiteralTypesOverloads01.ts, 38, 5)) +>stringOrBoolean : Symbol(stringOrBoolean, Decl(stringLiteralTypesOverloads01.ts, 36, 5)) +>number : Symbol(number, Decl(stringLiteralTypesOverloads01.ts, 32, 5)) + +namespace Consts2 { +>Consts2 : Symbol(Consts2, Decl(stringLiteralTypesOverloads01.ts, 38, 58)) + + const EMPTY_STRING = getFalsyPrimitive(string); +>EMPTY_STRING : Symbol(EMPTY_STRING, Decl(stringLiteralTypesOverloads01.ts, 41, 9)) +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90)) +>string : Symbol(string, Decl(stringLiteralTypesOverloads01.ts, 31, 5)) + + const ZERO = getFalsyPrimitive(number); +>ZERO : Symbol(ZERO, Decl(stringLiteralTypesOverloads01.ts, 42, 9)) +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90)) +>number : Symbol(number, Decl(stringLiteralTypesOverloads01.ts, 32, 5)) + + const FALSE = getFalsyPrimitive(boolean); +>FALSE : Symbol(FALSE, Decl(stringLiteralTypesOverloads01.ts, 43, 9)) +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90)) +>boolean : Symbol(boolean, Decl(stringLiteralTypesOverloads01.ts, 33, 5)) + + const a = getFalsyPrimitive(stringOrNumber); +>a : Symbol(a, Decl(stringLiteralTypesOverloads01.ts, 45, 9)) +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90)) +>stringOrNumber : Symbol(stringOrNumber, Decl(stringLiteralTypesOverloads01.ts, 35, 5)) + + const b = getFalsyPrimitive(stringOrBoolean); +>b : Symbol(b, Decl(stringLiteralTypesOverloads01.ts, 46, 9)) +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90)) +>stringOrBoolean : Symbol(stringOrBoolean, Decl(stringLiteralTypesOverloads01.ts, 36, 5)) + + const c = getFalsyPrimitive(booleanOrNumber); +>c : Symbol(c, Decl(stringLiteralTypesOverloads01.ts, 47, 9)) +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90)) +>booleanOrNumber : Symbol(booleanOrNumber, Decl(stringLiteralTypesOverloads01.ts, 37, 5)) + + const d = getFalsyPrimitive(stringOrBooleanOrNumber); +>d : Symbol(d, Decl(stringLiteralTypesOverloads01.ts, 48, 9)) +>getFalsyPrimitive : Symbol(getFalsyPrimitive, Decl(stringLiteralTypesOverloads01.ts, 1, 53), Decl(stringLiteralTypesOverloads01.ts, 3, 48), Decl(stringLiteralTypesOverloads01.ts, 4, 48), Decl(stringLiteralTypesOverloads01.ts, 5, 50), Decl(stringLiteralTypesOverloads01.ts, 6, 70), Decl(stringLiteralTypesOverloads01.ts, 7, 70), Decl(stringLiteralTypesOverloads01.ts, 8, 68), Decl(stringLiteralTypesOverloads01.ts, 9, 90)) +>stringOrBooleanOrNumber : Symbol(stringOrBooleanOrNumber, Decl(stringLiteralTypesOverloads01.ts, 38, 5)) +} + + + diff --git a/tests/baselines/reference/stringLiteralTypesOverloads01.types b/tests/baselines/reference/stringLiteralTypesOverloads01.types new file mode 100644 index 0000000000..6ba8d48211 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesOverloads01.types @@ -0,0 +1,174 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts === + +type PrimitiveName = 'string' | 'number' | 'boolean'; +>PrimitiveName : "string" | "number" | "boolean" + +function getFalsyPrimitive(x: "string"): string; +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>x : "string" + +function getFalsyPrimitive(x: "number"): number; +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>x : "number" + +function getFalsyPrimitive(x: "boolean"): boolean; +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>x : "boolean" + +function getFalsyPrimitive(x: "boolean" | "string"): boolean | string; +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>x : "boolean" | "string" + +function getFalsyPrimitive(x: "boolean" | "number"): boolean | number; +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>x : "boolean" | "number" + +function getFalsyPrimitive(x: "number" | "string"): number | string; +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>x : "number" | "string" + +function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean; +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>x : "number" | "string" | "boolean" + +function getFalsyPrimitive(x: PrimitiveName): number | string | boolean { +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>x : "string" | "number" | "boolean" +>PrimitiveName : "string" | "number" | "boolean" + + if (x === "string") { +>x === "string" : boolean +>x : "string" | "number" | "boolean" +>"string" : string + + return ""; +>"" : string + } + if (x === "number") { +>x === "number" : boolean +>x : "string" | "number" | "boolean" +>"number" : string + + return 0; +>0 : number + } + if (x === "boolean") { +>x === "boolean" : boolean +>x : "string" | "number" | "boolean" +>"boolean" : string + + return false; +>false : boolean + } + + // Should be unreachable. + throw "Invalid value"; +>"Invalid value" : string +} + +namespace Consts1 { +>Consts1 : typeof Consts1 + + const EMPTY_STRING = getFalsyPrimitive("string"); +>EMPTY_STRING : string +>getFalsyPrimitive("string") : string +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>"string" : "string" + + const ZERO = getFalsyPrimitive('number'); +>ZERO : number +>getFalsyPrimitive('number') : number +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>'number' : "number" + + const FALSE = getFalsyPrimitive("boolean"); +>FALSE : boolean +>getFalsyPrimitive("boolean") : boolean +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>"boolean" : "boolean" +} + +const string: "string" = "string" +>string : "string" +>"string" : "string" + +const number: "number" = "number" +>number : "number" +>"number" : "number" + +const boolean: "boolean" = "boolean" +>boolean : "boolean" +>"boolean" : "boolean" + +const stringOrNumber = string || number; +>stringOrNumber : "string" | "number" +>string || number : "string" | "number" +>string : "string" +>number : "number" + +const stringOrBoolean = string || boolean; +>stringOrBoolean : "string" | "boolean" +>string || boolean : "string" | "boolean" +>string : "string" +>boolean : "boolean" + +const booleanOrNumber = number || boolean; +>booleanOrNumber : "number" | "boolean" +>number || boolean : "number" | "boolean" +>number : "number" +>boolean : "boolean" + +const stringOrBooleanOrNumber = stringOrBoolean || number; +>stringOrBooleanOrNumber : "string" | "boolean" | "number" +>stringOrBoolean || number : "string" | "boolean" | "number" +>stringOrBoolean : "string" | "boolean" +>number : "number" + +namespace Consts2 { +>Consts2 : typeof Consts2 + + const EMPTY_STRING = getFalsyPrimitive(string); +>EMPTY_STRING : string +>getFalsyPrimitive(string) : string +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>string : "string" + + const ZERO = getFalsyPrimitive(number); +>ZERO : number +>getFalsyPrimitive(number) : number +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>number : "number" + + const FALSE = getFalsyPrimitive(boolean); +>FALSE : boolean +>getFalsyPrimitive(boolean) : boolean +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>boolean : "boolean" + + const a = getFalsyPrimitive(stringOrNumber); +>a : number | string +>getFalsyPrimitive(stringOrNumber) : number | string +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>stringOrNumber : "string" | "number" + + const b = getFalsyPrimitive(stringOrBoolean); +>b : boolean | string +>getFalsyPrimitive(stringOrBoolean) : boolean | string +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>stringOrBoolean : "string" | "boolean" + + const c = getFalsyPrimitive(booleanOrNumber); +>c : boolean | number +>getFalsyPrimitive(booleanOrNumber) : boolean | number +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>booleanOrNumber : "number" | "boolean" + + const d = getFalsyPrimitive(stringOrBooleanOrNumber); +>d : number | string | boolean +>getFalsyPrimitive(stringOrBooleanOrNumber) : number | string | boolean +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>stringOrBooleanOrNumber : "string" | "boolean" | "number" +} + + + diff --git a/tests/baselines/reference/superCallFromFunction1.errors.txt b/tests/baselines/reference/superCallFromFunction1.errors.txt index 374a3aeb16..b993d9f125 100644 --- a/tests/baselines/reference/superCallFromFunction1.errors.txt +++ b/tests/baselines/reference/superCallFromFunction1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/superCallFromFunction1.ts(3,5): error TS2335: 'super' can only be referenced in a derived class. +tests/cases/compiler/superCallFromFunction1.ts(3,5): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. ==== tests/cases/compiler/superCallFromFunction1.ts (1 errors) ==== @@ -6,5 +6,5 @@ tests/cases/compiler/superCallFromFunction1.ts(3,5): error TS2335: 'super' can o function foo() { super(value => String(value)); ~~~~~ -!!! error TS2335: 'super' can only be referenced in a derived class. +!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. } \ No newline at end of file diff --git a/tests/baselines/reference/superErrors.errors.txt b/tests/baselines/reference/superErrors.errors.txt index 26e0ba3a6c..5c6d7365a6 100644 --- a/tests/baselines/reference/superErrors.errors.txt +++ b/tests/baselines/reference/superErrors.errors.txt @@ -1,15 +1,15 @@ -tests/cases/compiler/superErrors.ts(3,13): error TS2335: 'super' can only be referenced in a derived class. +tests/cases/compiler/superErrors.ts(3,13): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. tests/cases/compiler/superErrors.ts(3,18): error TS1034: 'super' must be followed by an argument list or member access. -tests/cases/compiler/superErrors.ts(4,19): error TS2335: 'super' can only be referenced in a derived class. +tests/cases/compiler/superErrors.ts(4,19): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. tests/cases/compiler/superErrors.ts(4,24): error TS1034: 'super' must be followed by an argument list or member access. -tests/cases/compiler/superErrors.ts(5,31): error TS2335: 'super' can only be referenced in a derived class. +tests/cases/compiler/superErrors.ts(5,31): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. tests/cases/compiler/superErrors.ts(5,36): error TS1034: 'super' must be followed by an argument list or member access. -tests/cases/compiler/superErrors.ts(22,13): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. -tests/cases/compiler/superErrors.ts(27,27): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. -tests/cases/compiler/superErrors.ts(31,36): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. +tests/cases/compiler/superErrors.ts(22,13): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/compiler/superErrors.ts(27,27): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/compiler/superErrors.ts(31,36): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. tests/cases/compiler/superErrors.ts(31,41): error TS1034: 'super' must be followed by an argument list or member access. -tests/cases/compiler/superErrors.ts(39,27): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. -tests/cases/compiler/superErrors.ts(43,36): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. +tests/cases/compiler/superErrors.ts(39,27): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/compiler/superErrors.ts(43,36): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. tests/cases/compiler/superErrors.ts(43,41): error TS1034: 'super' must be followed by an argument list or member access. tests/cases/compiler/superErrors.ts(47,22): error TS1034: 'super' must be followed by an argument list or member access. tests/cases/compiler/superErrors.ts(48,28): error TS1034: 'super' must be followed by an argument list or member access. @@ -21,17 +21,17 @@ tests/cases/compiler/superErrors.ts(49,40): error TS1034: 'super' must be follow // super in a non class context var x = super; ~~~~~ -!!! error TS2335: 'super' can only be referenced in a derived class. +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. ~ !!! error TS1034: 'super' must be followed by an argument list or member access. var y = () => super; ~~~~~ -!!! error TS2335: 'super' can only be referenced in a derived class. +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. ~ !!! error TS1034: 'super' must be followed by an argument list or member access. var z = () => () => () => super; ~~~~~ -!!! error TS2335: 'super' can only be referenced in a derived class. +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. ~ !!! error TS1034: 'super' must be followed by an argument list or member access. } @@ -52,20 +52,20 @@ tests/cases/compiler/superErrors.ts(49,40): error TS1034: 'super' must be follow function inner() { super.sayHello(); ~~~~~ -!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. } // super call in a lambda in an inner function in a constructor function inner2() { var x = () => super.sayHello(); ~~~~~ -!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. } // super call in a lambda in a function expression in a constructor (function() { return () => super; })(); ~~~~~ -!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. ~ !!! error TS1034: 'super' must be followed by an argument list or member access. } @@ -77,13 +77,13 @@ tests/cases/compiler/superErrors.ts(49,40): error TS1034: 'super' must be follow function inner() { var x = () => super.sayHello(); ~~~~~ -!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. } // super call in a lambda in a function expression in a constructor (function() { return () => super; })(); ~~~~~ -!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. ~ !!! error TS1034: 'super' must be followed by an argument list or member access. } diff --git a/tests/baselines/reference/superInObjectLiterals_ES5.errors.txt b/tests/baselines/reference/superInObjectLiterals_ES5.errors.txt new file mode 100644 index 0000000000..a3149ce8cd --- /dev/null +++ b/tests/baselines/reference/superInObjectLiterals_ES5.errors.txt @@ -0,0 +1,95 @@ +tests/cases/compiler/superInObjectLiterals_ES5.ts(7,9): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. +tests/cases/compiler/superInObjectLiterals_ES5.ts(10,9): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. +tests/cases/compiler/superInObjectLiterals_ES5.ts(14,9): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. +tests/cases/compiler/superInObjectLiterals_ES5.ts(17,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/compiler/superInObjectLiterals_ES5.ts(20,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/compiler/superInObjectLiterals_ES5.ts(23,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/compiler/superInObjectLiterals_ES5.ts(39,17): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. +tests/cases/compiler/superInObjectLiterals_ES5.ts(42,17): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. +tests/cases/compiler/superInObjectLiterals_ES5.ts(46,17): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. +tests/cases/compiler/superInObjectLiterals_ES5.ts(49,17): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/compiler/superInObjectLiterals_ES5.ts(52,17): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. + + +==== tests/cases/compiler/superInObjectLiterals_ES5.ts (11 errors) ==== + var obj = { + __proto__: { + method() { + } + }, + method() { + super.method(); + ~~~~~ +!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. + }, + get prop() { + super.method(); + ~~~~~ +!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. + return 10; + }, + set prop(value) { + super.method(); + ~~~~~ +!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. + }, + p1: function () { + super.method(); + ~~~~~ +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. + }, + p2: function f() { + super.method(); + ~~~~~ +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. + }, + p3: () => { + super.method(); + ~~~~~ +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. + } + }; + + class A { + method() { } + } + + class B extends A { + f() { + var obj = { + __proto__: { + method() { + } + }, + method() { + super.method(); + ~~~~~ +!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. + }, + get prop() { + super.method(); + ~~~~~ +!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. + return 10; + }, + set prop(value) { + super.method(); + ~~~~~ +!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. + }, + p1: function () { + super.method(); + ~~~~~ +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. + }, + p2: function f() { + super.method(); + ~~~~~ +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. + }, + p3: () => { + super.method(); + } + }; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/superInObjectLiterals_ES5.js b/tests/baselines/reference/superInObjectLiterals_ES5.js new file mode 100644 index 0000000000..f701ca7df7 --- /dev/null +++ b/tests/baselines/reference/superInObjectLiterals_ES5.js @@ -0,0 +1,133 @@ +//// [superInObjectLiterals_ES5.ts] +var obj = { + __proto__: { + method() { + } + }, + method() { + super.method(); + }, + get prop() { + super.method(); + return 10; + }, + set prop(value) { + super.method(); + }, + p1: function () { + super.method(); + }, + p2: function f() { + super.method(); + }, + p3: () => { + super.method(); + } +}; + +class A { + method() { } +} + +class B extends A { + f() { + var obj = { + __proto__: { + method() { + } + }, + method() { + super.method(); + }, + get prop() { + super.method(); + return 10; + }, + set prop(value) { + super.method(); + }, + p1: function () { + super.method(); + }, + p2: function f() { + super.method(); + }, + p3: () => { + super.method(); + } + }; + } +} + +//// [superInObjectLiterals_ES5.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 obj = { + __proto__: { + method: function () { + } + }, + method: function () { + _super.prototype.method.call(this); + }, + get prop() { + _super.prototype.method.call(this); + return 10; + }, + set prop(value) { + _super.prototype.method.call(this); + }, + p1: function () { + _super.method.call(this); + }, + p2: function f() { + _super.method.call(this); + }, + p3: function () { + _super.method.call(this); + } +}; +var A = (function () { + function A() { + } + A.prototype.method = function () { }; + return A; +}()); +var B = (function (_super) { + __extends(B, _super); + function B() { + _super.apply(this, arguments); + } + B.prototype.f = function () { + var _this = this; + var obj = { + __proto__: { + method: function () { + } + }, + method: function () { + _super.prototype.method.call(this); + }, + get prop() { + _super.prototype.method.call(this); + return 10; + }, + set prop(value) { + _super.prototype.method.call(this); + }, + p1: function () { + _super.method.call(this); + }, + p2: function f() { + _super.method.call(this); + }, + p3: function () { + _super.prototype.method.call(_this); + } + }; + }; + return B; +}(A)); diff --git a/tests/baselines/reference/superInObjectLiterals_ES6.errors.txt b/tests/baselines/reference/superInObjectLiterals_ES6.errors.txt new file mode 100644 index 0000000000..dcd9692f5e --- /dev/null +++ b/tests/baselines/reference/superInObjectLiterals_ES6.errors.txt @@ -0,0 +1,77 @@ +tests/cases/compiler/superInObjectLiterals_ES6.ts(17,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/compiler/superInObjectLiterals_ES6.ts(20,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/compiler/superInObjectLiterals_ES6.ts(23,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/compiler/superInObjectLiterals_ES6.ts(49,17): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/compiler/superInObjectLiterals_ES6.ts(52,17): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. + + +==== tests/cases/compiler/superInObjectLiterals_ES6.ts (5 errors) ==== + var obj = { + __proto__: { + method() { + } + }, + method() { + super.method(); + }, + get prop() { + super.method(); + return 10; + }, + set prop(value) { + super.method(); + }, + p1: function () { + super.method(); + ~~~~~ +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. + }, + p2: function f() { + super.method(); + ~~~~~ +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. + }, + p3: () => { + super.method(); + ~~~~~ +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. + } + }; + + class A { + method() { } + } + + class B extends A { + f() { + var obj = { + __proto__: { + method() { + } + }, + method() { + super.method(); + }, + get prop() { + super.method(); + return 10; + }, + set prop(value) { + super.method(); + }, + p1: function () { + super.method(); + ~~~~~ +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. + }, + p2: function f() { + super.method(); + ~~~~~ +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. + }, + p3: () => { + super.method(); + } + }; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/superInObjectLiterals_ES6.js b/tests/baselines/reference/superInObjectLiterals_ES6.js new file mode 100644 index 0000000000..4cd62e6894 --- /dev/null +++ b/tests/baselines/reference/superInObjectLiterals_ES6.js @@ -0,0 +1,119 @@ +//// [superInObjectLiterals_ES6.ts] +var obj = { + __proto__: { + method() { + } + }, + method() { + super.method(); + }, + get prop() { + super.method(); + return 10; + }, + set prop(value) { + super.method(); + }, + p1: function () { + super.method(); + }, + p2: function f() { + super.method(); + }, + p3: () => { + super.method(); + } +}; + +class A { + method() { } +} + +class B extends A { + f() { + var obj = { + __proto__: { + method() { + } + }, + method() { + super.method(); + }, + get prop() { + super.method(); + return 10; + }, + set prop(value) { + super.method(); + }, + p1: function () { + super.method(); + }, + p2: function f() { + super.method(); + }, + p3: () => { + super.method(); + } + }; + } +} + +//// [superInObjectLiterals_ES6.js] +var obj = { + __proto__: { + method() { + } + }, + method() { + super.method(); + }, + get prop() { + super.method(); + return 10; + }, + set prop(value) { + super.method(); + }, + p1: function () { + super.method(); + }, + p2: function f() { + super.method(); + }, + p3: () => { + super.method(); + } +}; +class A { + method() { } +} +class B extends A { + f() { + var obj = { + __proto__: { + method() { + } + }, + method() { + super.method(); + }, + get prop() { + super.method(); + return 10; + }, + set prop(value) { + super.method(); + }, + p1: function () { + super.method(); + }, + p2: function f() { + super.method(); + }, + p3: () => { + super.method(); + } + }; + } +} diff --git a/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES5.js b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES5.js new file mode 100644 index 0000000000..a91dfc76e3 --- /dev/null +++ b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES5.js @@ -0,0 +1,46 @@ +//// [superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts] +class A { + foo() { return 1; } +} + +class B extends A { + foo() { return 2; } + bar() { + return class { + [super.foo()]() { + return 100; + } + } + } +} + +//// [superPropertyAccessInComputedPropertiesOfNestedType_ES5.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 A = (function () { + function A() { + } + A.prototype.foo = function () { return 1; }; + return A; +}()); +var B = (function (_super) { + __extends(B, _super); + function B() { + _super.apply(this, arguments); + } + B.prototype.foo = function () { return 2; }; + B.prototype.bar = function () { + return (function () { + function class_1() { + } + class_1.prototype[_super.prototype.foo.call(this)] = function () { + return 100; + }; + return class_1; + }()); + }; + return B; +}(A)); diff --git a/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES5.symbols b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES5.symbols new file mode 100644 index 0000000000..1379d50179 --- /dev/null +++ b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES5.symbols @@ -0,0 +1,29 @@ +=== tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts === +class A { +>A : Symbol(A, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 0, 0)) + + foo() { return 1; } +>foo : Symbol(foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 0, 9)) +} + +class B extends A { +>B : Symbol(B, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 2, 1)) +>A : Symbol(A, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 0, 0)) + + foo() { return 2; } +>foo : Symbol(foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 4, 19)) + + bar() { +>bar : Symbol(bar, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 5, 23)) + + return class { + [super.foo()]() { +>super.foo : Symbol(A.foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 0, 9)) +>super : Symbol(A, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 0, 0)) +>foo : Symbol(A.foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts, 0, 9)) + + return 100; + } + } + } +} diff --git a/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES5.types b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES5.types new file mode 100644 index 0000000000..d435bff69b --- /dev/null +++ b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES5.types @@ -0,0 +1,35 @@ +=== tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts === +class A { +>A : A + + foo() { return 1; } +>foo : () => number +>1 : number +} + +class B extends A { +>B : B +>A : A + + foo() { return 2; } +>foo : () => number +>2 : number + + bar() { +>bar : () => typeof (Anonymous class) + + return class { +>class { [super.foo()]() { return 100; } } : typeof (Anonymous class) + + [super.foo()]() { +>super.foo() : number +>super.foo : () => number +>super : A +>foo : () => number + + return 100; +>100 : number + } + } + } +} diff --git a/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES6.js b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES6.js new file mode 100644 index 0000000000..825fa7682e --- /dev/null +++ b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES6.js @@ -0,0 +1,31 @@ +//// [superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts] +class A { + foo() { return 1; } +} + +class B extends A { + foo() { return 2; } + bar() { + return class { + [super.foo()]() { + return 100; + } + } + } +} + +//// [superPropertyAccessInComputedPropertiesOfNestedType_ES6.js] +class A { + foo() { return 1; } +} +class B extends A { + foo() { return 2; } + bar() { + return class { + [super.foo()]() { + return 100; + } + } + ; + } +} diff --git a/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES6.symbols b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES6.symbols new file mode 100644 index 0000000000..12446259f3 --- /dev/null +++ b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES6.symbols @@ -0,0 +1,29 @@ +=== tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts === +class A { +>A : Symbol(A, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 0, 0)) + + foo() { return 1; } +>foo : Symbol(foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 0, 9)) +} + +class B extends A { +>B : Symbol(B, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 2, 1)) +>A : Symbol(A, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 0, 0)) + + foo() { return 2; } +>foo : Symbol(foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 4, 19)) + + bar() { +>bar : Symbol(bar, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 5, 23)) + + return class { + [super.foo()]() { +>super.foo : Symbol(A.foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 0, 9)) +>super : Symbol(A, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 0, 0)) +>foo : Symbol(A.foo, Decl(superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts, 0, 9)) + + return 100; + } + } + } +} diff --git a/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES6.types b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES6.types new file mode 100644 index 0000000000..817e3b73ba --- /dev/null +++ b/tests/baselines/reference/superPropertyAccessInComputedPropertiesOfNestedType_ES6.types @@ -0,0 +1,35 @@ +=== tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts === +class A { +>A : A + + foo() { return 1; } +>foo : () => number +>1 : number +} + +class B extends A { +>B : B +>A : A + + foo() { return 2; } +>foo : () => number +>2 : number + + bar() { +>bar : () => typeof (Anonymous class) + + return class { +>class { [super.foo()]() { return 100; } } : typeof (Anonymous class) + + [super.foo()]() { +>super.foo() : number +>super.foo : () => number +>super : A +>foo : () => number + + return 100; +>100 : number + } + } + } +} diff --git a/tests/baselines/reference/super_inside-object-literal-getters-and-setters.errors.txt b/tests/baselines/reference/super_inside-object-literal-getters-and-setters.errors.txt index 4f1faf78a7..5fe7fa59ff 100644 --- a/tests/baselines/reference/super_inside-object-literal-getters-and-setters.errors.txt +++ b/tests/baselines/reference/super_inside-object-literal-getters-and-setters.errors.txt @@ -1,10 +1,10 @@ tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(4,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(5,20): error TS2335: 'super' can only be referenced in a derived class. +tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(5,20): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(7,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(8,13): error TS2335: 'super' can only be referenced in a derived class. -tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(11,20): error TS2335: 'super' can only be referenced in a derived class. +tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(8,13): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. +tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(11,20): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(20,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(21,24): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. +tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(21,24): error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. ==== tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts (7 errors) ==== @@ -16,19 +16,19 @@ tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(21,24): !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. return super._foo; ~~~~~ -!!! error TS2335: 'super' can only be referenced in a derived class. +!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. }, set foo(value: string) { ~~~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. super._foo = value; ~~~~~ -!!! error TS2335: 'super' can only be referenced in a derived class. +!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. }, test: function () { return super._foo; ~~~~~ -!!! error TS2335: 'super' can only be referenced in a derived class. +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. } } } @@ -42,7 +42,7 @@ tests/cases/compiler/super_inside-object-literal-getters-and-setters.ts(21,24): !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. return super.test(); ~~~~~ -!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. +!!! error TS2659: 'super' is only allowed in members of object literal expressions when option 'target' is 'ES2015' or higher. } }; } diff --git a/tests/baselines/reference/super_inside-object-literal-getters-and-setters.js b/tests/baselines/reference/super_inside-object-literal-getters-and-setters.js index be70ee3318..db6db37ac8 100644 --- a/tests/baselines/reference/super_inside-object-literal-getters-and-setters.js +++ b/tests/baselines/reference/super_inside-object-literal-getters-and-setters.js @@ -38,10 +38,10 @@ var ObjectLiteral; var ThisInObjectLiteral = { _foo: '1', get foo() { - return _super._foo; + return _super.prototype._foo; }, set foo(value) { - _super._foo = value; + _super.prototype._foo = value; }, test: function () { return _super._foo; @@ -62,7 +62,7 @@ var SuperObjectTest = (function (_super) { SuperObjectTest.prototype.testing = function () { var test = { get F() { - return _super.test.call(this); + return _super.prototype.test.call(this); } }; }; diff --git a/tests/baselines/reference/tsxAttributeResolution11.errors.txt b/tests/baselines/reference/tsxAttributeResolution11.errors.txt new file mode 100644 index 0000000000..b043897d50 --- /dev/null +++ b/tests/baselines/reference/tsxAttributeResolution11.errors.txt @@ -0,0 +1,33 @@ +tests/cases/conformance/jsx/file.tsx(11,22): error TS2339: Property 'bar' does not exist on type 'IntrinsicAttributes & { ref?: string; }'. + + +==== tests/cases/conformance/jsx/react.d.ts (0 errors) ==== + + declare module JSX { + interface Element { } + interface IntrinsicElements { + } + interface ElementAttributesProperty { + props; + } + interface IntrinsicAttributes { + ref?: string; + } + } + +==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== + class MyComponent { + render() { + } + + props: { + ref?: string; + } + } + + // Should be an OK + var x = ; + ~~~ +!!! error TS2339: Property 'bar' does not exist on type 'IntrinsicAttributes & { ref?: string; }'. + + \ No newline at end of file diff --git a/tests/baselines/reference/tsxAttributeResolution11.js b/tests/baselines/reference/tsxAttributeResolution11.js new file mode 100644 index 0000000000..03b843c209 --- /dev/null +++ b/tests/baselines/reference/tsxAttributeResolution11.js @@ -0,0 +1,41 @@ +//// [tests/cases/conformance/jsx/tsxAttributeResolution11.tsx] //// + +//// [react.d.ts] + +declare module JSX { + interface Element { } + interface IntrinsicElements { + } + interface ElementAttributesProperty { + props; + } + interface IntrinsicAttributes { + ref?: string; + } +} + +//// [file.tsx] +class MyComponent { + render() { + } + + props: { + ref?: string; + } +} + +// Should be an OK +var x = ; + + + +//// [file.jsx] +var MyComponent = (function () { + function MyComponent() { + } + MyComponent.prototype.render = function () { + }; + return MyComponent; +}()); +// Should be an OK +var x = ; diff --git a/tests/cases/compiler/DeclarationErrorsNoEmitOnError.ts b/tests/cases/compiler/DeclarationErrorsNoEmitOnError.ts new file mode 100644 index 0000000000..ef8711e711 --- /dev/null +++ b/tests/cases/compiler/DeclarationErrorsNoEmitOnError.ts @@ -0,0 +1,8 @@ +// @module: commonjs +// @declaration: true +// @noEmitOnError: true + +type T = { x : number } +export interface I { + f: T; +} \ No newline at end of file diff --git a/tests/cases/compiler/arrayLiteralComments.ts b/tests/cases/compiler/arrayLiteralComments.ts new file mode 100644 index 0000000000..131cecc1d9 --- /dev/null +++ b/tests/cases/compiler/arrayLiteralComments.ts @@ -0,0 +1,14 @@ +var testArrayWithFunc = [ + // Function comment + function() { + let x = 1; + }, + // String comment + '1', + // Numeric comment + 2, + // Object comment + { a: 1 }, + // Array comment + [1, 2, 3] +] \ No newline at end of file diff --git a/tests/cases/compiler/enumAssignmentCompat3.ts b/tests/cases/compiler/enumAssignmentCompat3.ts new file mode 100644 index 0000000000..97a136468e --- /dev/null +++ b/tests/cases/compiler/enumAssignmentCompat3.ts @@ -0,0 +1,89 @@ +namespace First { + export enum E { + a, b, c, + } +} +namespace Abc { + export enum E { + a, b, c, + } + export enum Nope { + a, b, c, + } +} +namespace Abcd { + export enum E { + a, b, c, d, + } +} +namespace Ab { + export enum E { + a, b, + } +} +namespace Cd { + export enum E { + c, d, + } +} +namespace Const { + export const enum E { + a, b, c, + } +} +namespace Decl { + export declare enum E { + a, b, c = 3, + } +} +namespace Merged { + export enum E { + a, b, + } + export enum E { + c = 3, d, + } +} + +namespace Merged2 { + export enum E { + a, b, c + } + export module E { + export let d = 5; + } +} + +var abc: First.E; +var secondAbc: Abc.E; +var secondAbcd: Abcd.E; +var secondAb: Ab.E; +var secondCd: Cd.E; +var nope: Abc.Nope; +var k: Const.E; +var decl: Decl.E; +var merged: Merged.E; +var merged2: Merged2.E; +abc = secondAbc; // ok +abc = secondAbcd; // missing 'd' +abc = secondAb; // ok +abc = secondCd; // missing 'd' +abc = nope; // nope! +abc = decl; // ok +secondAbc = abc; // ok +secondAbcd = abc; // ok +secondAb = abc; // missing 'c' +secondCd = abc; // missing 'a' and 'b' +nope = abc; // nope! +decl = abc; // ok + +// const is only assignable to itself +k = k; +abc = k; // error +k = abc; + +// merged enums compare all their members +abc = merged; // missing 'd' +merged = abc; // ok +abc = merged2; // ok +merged2 = abc; // ok \ No newline at end of file diff --git a/tests/cases/compiler/functionOverloads43.ts b/tests/cases/compiler/functionOverloads43.ts new file mode 100644 index 0000000000..8822fd86c1 --- /dev/null +++ b/tests/cases/compiler/functionOverloads43.ts @@ -0,0 +1,12 @@ +function foo(bar: { a:number }[]): number; +function foo(bar: { a:string }[]): string; +function foo([x]: { a:number | string }[]): string | number { + if (x) { + return x.a; + } + + return undefined; +} + +var x = foo([{a: "str"}]); +var y = foo([{a: 100}]); \ No newline at end of file diff --git a/tests/cases/compiler/functionOverloads44.ts b/tests/cases/compiler/functionOverloads44.ts new file mode 100644 index 0000000000..20a7ed540f --- /dev/null +++ b/tests/cases/compiler/functionOverloads44.ts @@ -0,0 +1,22 @@ +interface Animal { animal } +interface Dog extends Animal { dog } +interface Cat extends Animal { cat } + +function foo1(bar: { a:number }[]): Dog; +function foo1(bar: { a:string }[]): Animal; +function foo1([x]: { a:number | string }[]): Dog { + return undefined; +} + +function foo2(bar: { a:number }[]): Cat; +function foo2(bar: { a:string }[]): Cat | Dog; +function foo2([x]: { a:number | string }[]): Cat { + return undefined; +} + + +var x1 = foo1([{a: "str"}]); +var y1 = foo1([{a: 100}]); + +var x2 = foo2([{a: "str"}]); +var y2 = foo2([{a: 100}]); \ No newline at end of file diff --git a/tests/cases/compiler/functionOverloads45.ts b/tests/cases/compiler/functionOverloads45.ts new file mode 100644 index 0000000000..6210bd1342 --- /dev/null +++ b/tests/cases/compiler/functionOverloads45.ts @@ -0,0 +1,22 @@ +interface Animal { animal } +interface Dog extends Animal { dog } +interface Cat extends Animal { cat } + +function foo1(bar: { a:number }[]): Cat; +function foo1(bar: { a:string }[]): Dog; +function foo1([x]: { a:number | string }[]): Animal { + return undefined; +} + +function foo2(bar: { a:number }[]): Cat; +function foo2(bar: { a:string }[]): Dog; +function foo2([x]: { a:number | string }[]): Cat | Dog { + return undefined; +} + + +var x1 = foo1([{a: "str"}]); +var y1 = foo1([{a: 100}]); + +var x2 = foo2([{a: "str"}]); +var y2 = foo2([{a: 100}]); \ No newline at end of file diff --git a/tests/cases/compiler/overloadOnConstConstraintChecks4.ts b/tests/cases/compiler/overloadOnConstConstraintChecks4.ts index f63c5b4634..55425f6339 100644 --- a/tests/cases/compiler/overloadOnConstConstraintChecks4.ts +++ b/tests/cases/compiler/overloadOnConstConstraintChecks4.ts @@ -6,7 +6,7 @@ class C extends A { } function foo(name: 'hi'): B; function foo(name: 'bye'): C; -function foo(name: string): A; // error +function foo(name: string): A; function foo(name: any): Z { return null; } diff --git a/tests/cases/compiler/prefixUnaryOperatorsOnExportedVariables.ts b/tests/cases/compiler/prefixUnaryOperatorsOnExportedVariables.ts new file mode 100644 index 0000000000..58b05bb513 --- /dev/null +++ b/tests/cases/compiler/prefixUnaryOperatorsOnExportedVariables.ts @@ -0,0 +1,32 @@ +// @target: ES5 +// @module: system + +export var x = false; +export var y = 1; +if (!x) { + +} + +if (+x) { + +} + +if (-x) { + +} + +if (~x) { + +} + +if (void x) { + +} + +if (typeof x) { + +} + +if (++y) { + +} \ No newline at end of file diff --git a/tests/cases/compiler/superInObjectLiterals_ES5.ts b/tests/cases/compiler/superInObjectLiterals_ES5.ts new file mode 100644 index 0000000000..96cdfaa5b7 --- /dev/null +++ b/tests/cases/compiler/superInObjectLiterals_ES5.ts @@ -0,0 +1,60 @@ +// @target: ES5 +var obj = { + __proto__: { + method() { + } + }, + method() { + super.method(); + }, + get prop() { + super.method(); + return 10; + }, + set prop(value) { + super.method(); + }, + p1: function () { + super.method(); + }, + p2: function f() { + super.method(); + }, + p3: () => { + super.method(); + } +}; + +class A { + method() { } +} + +class B extends A { + f() { + var obj = { + __proto__: { + method() { + } + }, + method() { + super.method(); + }, + get prop() { + super.method(); + return 10; + }, + set prop(value) { + super.method(); + }, + p1: function () { + super.method(); + }, + p2: function f() { + super.method(); + }, + p3: () => { + super.method(); + } + }; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/superInObjectLiterals_ES6.ts b/tests/cases/compiler/superInObjectLiterals_ES6.ts new file mode 100644 index 0000000000..05b2853a90 --- /dev/null +++ b/tests/cases/compiler/superInObjectLiterals_ES6.ts @@ -0,0 +1,60 @@ +// @target: ES6 +var obj = { + __proto__: { + method() { + } + }, + method() { + super.method(); + }, + get prop() { + super.method(); + return 10; + }, + set prop(value) { + super.method(); + }, + p1: function () { + super.method(); + }, + p2: function f() { + super.method(); + }, + p3: () => { + super.method(); + } +}; + +class A { + method() { } +} + +class B extends A { + f() { + var obj = { + __proto__: { + method() { + } + }, + method() { + super.method(); + }, + get prop() { + super.method(); + return 10; + }, + set prop(value) { + super.method(); + }, + p1: function () { + super.method(); + }, + p2: function f() { + super.method(); + }, + p3: () => { + super.method(); + } + }; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts b/tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts new file mode 100644 index 0000000000..9c7d28f96a --- /dev/null +++ b/tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES5.ts @@ -0,0 +1,15 @@ +// @target: ES5 +class A { + foo() { return 1; } +} + +class B extends A { + foo() { return 2; } + bar() { + return class { + [super.foo()]() { + return 100; + } + } + } +} \ No newline at end of file diff --git a/tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts b/tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts new file mode 100644 index 0000000000..6a8c2e1a7d --- /dev/null +++ b/tests/cases/compiler/superPropertyAccessInComputedPropertiesOfNestedType_ES6.ts @@ -0,0 +1,15 @@ +// @target: ES6 +class A { + foo() { return 1; } +} + +class B extends A { + foo() { return 2; } + bar() { + return class { + [super.foo()]() { + return 100; + } + } + } +} \ No newline at end of file diff --git a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethodOverload1.ts b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethodOverload1.ts new file mode 100644 index 0000000000..722463b33d --- /dev/null +++ b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethodOverload1.ts @@ -0,0 +1,9 @@ +// @target: ES5 +// @experimentaldecorators: true +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + @dec + method() + method() { } +} \ No newline at end of file diff --git a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethodOverload2.ts b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethodOverload2.ts new file mode 100644 index 0000000000..ee5a3f33bf --- /dev/null +++ b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethodOverload2.ts @@ -0,0 +1,9 @@ +// @target: ES5 +// @experimentaldecorators: true +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + method() + @dec + method() { } +} \ No newline at end of file diff --git a/tests/cases/conformance/functions/conformanceFunctionOverloads.ts b/tests/cases/conformance/functions/conformanceFunctionOverloads.ts deleted file mode 100644 index f1e08782a5..0000000000 --- a/tests/cases/conformance/functions/conformanceFunctionOverloads.ts +++ /dev/null @@ -1,22 +0,0 @@ -// Function overloads do not emit code - -// Function overload signature with optional parameter - -// Function overload signature with optional parameter - -// Function overloads with generic and non-generic overloads - -// Function overloads whose only difference is returning different unconstrained generic parameters - -// Function overloads whose only difference is returning different constrained generic parameters - -// Function overloads that differ only by type parameter constraints - -// Function overloads with matching accessibility - -// Function overloads with matching export - -// Function overloads with more params than implementation signature - -// Function overloads where return types are same infinitely recursive type reference - diff --git a/tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid01.ts b/tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid01.ts new file mode 100644 index 0000000000..d973c946bb --- /dev/null +++ b/tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid01.ts @@ -0,0 +1,4 @@ +function f(x: string): number; +function f(x: string): void { + return; +} \ No newline at end of file diff --git a/tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid02.ts b/tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid02.ts new file mode 100644 index 0000000000..ef89d790ff --- /dev/null +++ b/tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid02.ts @@ -0,0 +1,4 @@ +function f(x: string): void; +function f(x: string): number { + return 0; +} \ No newline at end of file diff --git a/tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid03.ts b/tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid03.ts new file mode 100644 index 0000000000..5f0a2327d7 --- /dev/null +++ b/tests/cases/conformance/functions/functionOverloadCompatibilityWithVoid03.ts @@ -0,0 +1,4 @@ +function f(x: string): void; +function f(x: string): void { + return; +} \ No newline at end of file diff --git a/tests/cases/conformance/jsx/tsxAttributeResolution11.tsx b/tests/cases/conformance/jsx/tsxAttributeResolution11.tsx new file mode 100644 index 0000000000..fdff3c36fc --- /dev/null +++ b/tests/cases/conformance/jsx/tsxAttributeResolution11.tsx @@ -0,0 +1,29 @@ +//@jsx: preserve +//@module: amd + +//@filename: react.d.ts +declare module JSX { + interface Element { } + interface IntrinsicElements { + } + interface ElementAttributesProperty { + props; + } + interface IntrinsicAttributes { + ref?: string; + } +} + +//@filename: file.tsx +class MyComponent { + render() { + } + + props: { + ref?: string; + } +} + +// Should be an OK +var x = ; + diff --git a/tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts index cea04f0818..ba18940653 100644 --- a/tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts @@ -20,7 +20,7 @@ function hasKind(entity: Entity, kind: "A"): entity is A; function hasKind(entity: Entity, kind: "B"): entity is B; function hasKind(entity: Entity, kind: Kind): entity is Entity; function hasKind(entity: Entity, kind: Kind): boolean { - return kind === is; + return entity.kind === kind; } let x: A = { diff --git a/tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags02.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags02.ts new file mode 100644 index 0000000000..9fdc942a3f --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags02.ts @@ -0,0 +1,42 @@ +// @declaration: true + +type Kind = "A" | "B" + +interface Entity { + kind: Kind; +} + +interface A extends Entity { + kind: "A"; + a: number; +} + +interface B extends Entity { + kind: "B"; + b: string; +} + +function hasKind(entity: Entity, kind: "A"): entity is A; +function hasKind(entity: Entity, kind: "B"): entity is B; +function hasKind(entity: Entity, kind: Kind): entity is (A | B) { + return entity.kind === kind; +} + +let x: A = { + kind: "A", + a: 100, +} + +if (hasKind(x, "A")) { + let a = x; +} +else { + let b = x; +} + +if (!hasKind(x, "B")) { + let c = x; +} +else { + let d = x; +} \ No newline at end of file diff --git a/tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags03.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags03.ts new file mode 100644 index 0000000000..96011d2725 --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags03.ts @@ -0,0 +1,46 @@ +// @declaration: true + +type Kind = "A" | "B" + +interface Entity { + kind: Kind; +} + +interface A extends Entity { + kind: "A"; + a: number; +} + +interface B extends Entity { + kind: "B"; + b: string; +} + +// Currently (2015-12-14), we write '"A" | "A"' and '"B" | "B"' to avoid +// interpreting respective overloads as "specialized" signatures. +// That way, we can avoid the need to look for a compatible overload +// signature and simply check compatibility with the implementation. +function hasKind(entity: Entity, kind: "A" | "A"): entity is A; +function hasKind(entity: Entity, kind: "B" | "B"): entity is B; +function hasKind(entity: Entity, kind: Kind): entity is Entity { + return entity.kind === kind; +} + +let x: A = { + kind: "A", + a: 100, +} + +if (hasKind(x, "A")) { + let a = x; +} +else { + let b = x; +} + +if (!hasKind(x, "B")) { + let c = x; +} +else { + let d = x; +} \ No newline at end of file diff --git a/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts index d88167eaef..0044113440 100644 --- a/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts @@ -9,7 +9,7 @@ function getFalsyPrimitive(x: "boolean" | "string"): boolean | string; function getFalsyPrimitive(x: "boolean" | "number"): boolean | number; function getFalsyPrimitive(x: "number" | "string"): number | string; function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean; -function getFalsyPrimitive(x: PrimitiveName) { +function getFalsyPrimitive(x: PrimitiveName): number | string | boolean { if (x === "string") { return ""; } diff --git a/tests/cases/fourslash/documentHighlightAtParameterPropertyDeclaration1.ts b/tests/cases/fourslash/documentHighlightAtParameterPropertyDeclaration1.ts new file mode 100644 index 0000000000..aeccd252fe --- /dev/null +++ b/tests/cases/fourslash/documentHighlightAtParameterPropertyDeclaration1.ts @@ -0,0 +1,24 @@ +/// + +// @Filename: file1.ts +//// class Foo { +//// constructor(private /*0*/privateParam: number, +//// public /*1*/publicParam: string, +//// protected /*2*/protectedParam: boolean) { +//// +//// let localPrivate = /*3*/privateParam; +//// this./*4*/privateParam += 10; +//// +//// let localPublic = /*5*/publicParam; +//// this./*6*/publicParam += " Hello!"; +//// +//// let localProtected = /*7*/protectedParam; +//// this./*8*/protectedParam = false; +//// } +//// } + +let markers = test.markers() +for (let marker of markers) { + goTo.position(marker.position); + verify.documentHighlightsAtPositionCount(3, ["file1.ts"]); +} \ No newline at end of file diff --git a/tests/cases/fourslash/documentHighlightAtParameterPropertyDeclaration2.ts b/tests/cases/fourslash/documentHighlightAtParameterPropertyDeclaration2.ts new file mode 100644 index 0000000000..f5d6764205 --- /dev/null +++ b/tests/cases/fourslash/documentHighlightAtParameterPropertyDeclaration2.ts @@ -0,0 +1,24 @@ +/// + +// @Filename: file1.ts +//// class Foo { +//// constructor(private {/*0*/privateParam}: number, +//// public {/*1*/publicParam}: string, +//// protected {/*2*/protectedParam}: boolean) { +//// +//// let localPrivate = /*3*/privateParam; +//// this.privateParam += 10; // this is not valid syntax +//// +//// let localPublic = /*4*/publicParam; +//// this.publicParam += " Hello!"; // this is not valid syntax +//// +//// let localProtected = /*5*/protectedParam; +//// this.protectedParam = false; // this is not valid syntax +//// } +//// } + +let markers = test.markers() +for (let marker of markers) { + goTo.position(marker.position); + verify.documentHighlightsAtPositionCount(2, ["file1.ts"]); +} \ No newline at end of file diff --git a/tests/cases/fourslash/documentHighlightAtParameterPropertyDeclaration3.ts b/tests/cases/fourslash/documentHighlightAtParameterPropertyDeclaration3.ts new file mode 100644 index 0000000000..958e3bb45c --- /dev/null +++ b/tests/cases/fourslash/documentHighlightAtParameterPropertyDeclaration3.ts @@ -0,0 +1,24 @@ +/// + +// @Filename: file1.ts +//// class Foo { +//// constructor(private [/*0*/privateParam]: number, +//// public [/*1*/publicParam]: string, +//// protected [/*2*/protectedParam]: boolean) { +//// +//// let localPrivate = /*3*/privateParam; +//// this.privateParam += 10; // this is not valid syntax +//// +//// let localPublic = /*4*/publicParam; +//// this.publicParam += " Hello!"; // this is not valid syntax +//// +//// let localProtected = /*5*/protectedParam; +//// this.protectedParam = false; // this is not valid syntax +//// } +//// } + +let markers = test.markers() +for (let marker of markers) { + goTo.position(marker.position); + verify.documentHighlightsAtPositionCount(2, ["file1.ts"]); +} \ No newline at end of file diff --git a/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration1.ts b/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration1.ts new file mode 100644 index 0000000000..4018698f4e --- /dev/null +++ b/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration1.ts @@ -0,0 +1,21 @@ +/// + +//// class Foo { +//// constructor(private [|privateParam|]: number) { +//// let localPrivate = [|privateParam|]; +//// this.[|privateParam|] += 10; +//// } +//// } + +const ranges = test.ranges(); +verify.assertHasRanges(ranges); +for (const range of ranges) { + goTo.position(range.start); + + if (ranges.length) { + verify.referencesCountIs(ranges.length); + for (const expectedRange of ranges) { + verify.referencesAtPositionContains(expectedRange); + } + } +} \ No newline at end of file diff --git a/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration2.ts b/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration2.ts new file mode 100644 index 0000000000..a450a77e2d --- /dev/null +++ b/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration2.ts @@ -0,0 +1,19 @@ +/// + +//// class Foo { +//// constructor(public [|publicParam|]: number) { +//// let localPublic = [|publicParam|]; +//// this.[|publicParam|] += 10; +//// } +//// } + +let ranges = test.ranges(); +verify.assertHasRanges(ranges); +for (let range of ranges) { + goTo.position(range.start); + + verify.referencesCountIs(ranges.length); + for (let expectedRange of ranges) { + verify.referencesAtPositionContains(expectedRange); + } +} \ No newline at end of file diff --git a/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration3.ts b/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration3.ts new file mode 100644 index 0000000000..82fd67dfc9 --- /dev/null +++ b/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration3.ts @@ -0,0 +1,19 @@ +/// + +//// class Foo { +//// constructor(protected [|protectedParam|]: number) { +//// let localProtected = [|protectedParam|]; +//// this.[|protectedParam|] += 10; +//// } +//// } + +const ranges = test.ranges(); +verify.assertHasRanges(ranges); +for (const range of ranges) { + goTo.position(range.start); + + verify.referencesCountIs(ranges.length); + for (const expectedRange of ranges) { + verify.referencesAtPositionContains(expectedRange); + } +} \ No newline at end of file diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index b9b379bd46..dd443e942c 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -137,6 +137,7 @@ declare namespace FourSlashInterface { verifyDefinitionsName(name: string, containerName: string): void; } class verify extends verifyNegatable { + assertHasRanges(ranges: FourSlash.Range[]): void; caretAtMarker(markerName?: string): void; indentationIs(numberOfSpaces: number): void; indentationAtPositionIs(fileName: string, position: number, numberOfSpaces: number, indentStyle?: ts.IndentStyle): void; diff --git a/tests/cases/fourslash/getOccurrencesSuper3.ts b/tests/cases/fourslash/getOccurrencesSuper3.ts new file mode 100644 index 0000000000..bceac02a39 --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesSuper3.ts @@ -0,0 +1,34 @@ +/// + +////let x = { +//// a() { +//// return [|s/**/uper|].b(); +//// }, +//// b() { +//// return [|super|].a(); +//// }, +//// c: function () { +//// return [|super|].a(); +//// } +//// d: () => [|super|].b(); +////} + +function checkRange(r: FourSlashInterface.Range, expectedOccurences: FourSlashInterface.Range[]): void { + goTo.position(r.start); + if (expectedOccurences.length) { + for (const expected of expectedOccurences) { + verify.occurrencesAtPositionContains(expected); + } + } + else { + verify.occurrencesAtPositionCount(0); + } +} + +let [r0, r1, r2, r3] = test.ranges(); + +checkRange(r0, [r0, r1]); +checkRange(r1, [r0, r1]); +checkRange(r0, [r0, r1]); +checkRange(r2, []); +checkRange(r3, []); \ No newline at end of file diff --git a/tests/cases/fourslash/referenceInParameterPropertyDeclaration.ts b/tests/cases/fourslash/referenceInParameterPropertyDeclaration.ts new file mode 100644 index 0000000000..4e86e7a491 --- /dev/null +++ b/tests/cases/fourslash/referenceInParameterPropertyDeclaration.ts @@ -0,0 +1,24 @@ +/// + +// @Filename: file1.ts +//// class Foo { +//// constructor(private /*0*/privateParam: number, +//// public /*1*/publicParam: string, +//// protected /*2*/protectedParam: boolean) { +//// +//// let localPrivate = /*3*/privateParam; +//// this./*4*/privateParam += 10; +//// +//// let localPublic = /*5*/publicParam; +//// this./*6*/publicParam += " Hello!"; +//// +//// let localProtected = /*7*/protectedParam; +//// this./*8*/protectedParam = false; +//// } +//// } + +let markers = test.markers() +for (let marker of markers) { + goTo.position(marker.position); + verify.referencesCountIs(3); +} \ No newline at end of file diff --git a/tests/cases/fourslash/renameParameterPropertyDeclaration1.ts b/tests/cases/fourslash/renameParameterPropertyDeclaration1.ts new file mode 100644 index 0000000000..42bfbf63a4 --- /dev/null +++ b/tests/cases/fourslash/renameParameterPropertyDeclaration1.ts @@ -0,0 +1,15 @@ +/// + +//// class Foo { +//// constructor(private [|privateParam|]: number) { +//// let localPrivate = [|privateParam|]; +//// this.[|privateParam|] += 10; +//// } +//// } + +let ranges = test.ranges(); +verify.assertHasRanges(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/renameParameterPropertyDeclaration2.ts b/tests/cases/fourslash/renameParameterPropertyDeclaration2.ts new file mode 100644 index 0000000000..e7ef9d1c1a --- /dev/null +++ b/tests/cases/fourslash/renameParameterPropertyDeclaration2.ts @@ -0,0 +1,15 @@ +/// + +//// class Foo { +//// constructor(public [|publicParam|]: number) { +//// let publicParam = [|publicParam|]; +//// this.[|publicParam|] += 10; +//// } +//// } + +let ranges = test.ranges(); +verify.assertHasRanges(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/renameParameterPropertyDeclaration3.ts b/tests/cases/fourslash/renameParameterPropertyDeclaration3.ts new file mode 100644 index 0000000000..9446e2aeb7 --- /dev/null +++ b/tests/cases/fourslash/renameParameterPropertyDeclaration3.ts @@ -0,0 +1,15 @@ +/// + +//// class Foo { +//// constructor(protected [|protectedParam|]: number) { +//// let protectedParam = [|protectedParam|]; +//// this.[|protectedParam|] += 10; +//// } +//// } + +let ranges = test.ranges(); +verify.assertHasRanges(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/renameParameterPropertyDeclaration4.ts b/tests/cases/fourslash/renameParameterPropertyDeclaration4.ts new file mode 100644 index 0000000000..7fb4b8c757 --- /dev/null +++ b/tests/cases/fourslash/renameParameterPropertyDeclaration4.ts @@ -0,0 +1,14 @@ +/// + +//// class Foo { +//// constructor(protected { [|protectedParam|] }) { +//// let myProtectedParam = [|protectedParam|]; +//// } +//// } + +let ranges = test.ranges(); +verify.assertHasRanges(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/renameParameterPropertyDeclaration5.ts b/tests/cases/fourslash/renameParameterPropertyDeclaration5.ts new file mode 100644 index 0000000000..b7c47a4c0d --- /dev/null +++ b/tests/cases/fourslash/renameParameterPropertyDeclaration5.ts @@ -0,0 +1,14 @@ +/// + +//// class Foo { +//// constructor(protected [ [|protectedParam|] ]) { +//// let myProtectedParam = [|protectedParam|]; +//// } +//// } + +let ranges = test.ranges(); +verify.assertHasRanges(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/unittests/session.ts b/tests/cases/unittests/session.ts index c1dfd50894..41f4bc599f 100644 --- a/tests/cases/unittests/session.ts +++ b/tests/cases/unittests/session.ts @@ -1,5 +1,7 @@ /// +const expect: typeof _chai.expect = _chai.expect; + namespace ts.server { let lastWrittenToHost: string; const mockHost: ServerHost = { @@ -28,7 +30,7 @@ namespace ts.server { endGroup(): void {}, msg(s: string, type?: string): void {}, }; - + describe("the Session class", () => { let session: Session; let lastSent: protocol.Message; @@ -204,7 +206,7 @@ namespace ts.server { .to.throw(`Protocol handler already exists for command "${command}"`); }); }); - + describe("event", () => { it("can format event responses and send them", () => { const evt = "notify-test"; @@ -315,7 +317,7 @@ namespace ts.server { responseRequired: true })); } - + send(msg: protocol.Message) { this.client.handle(msg); } @@ -323,7 +325,7 @@ namespace ts.server { enqueue(msg: protocol.Request) { this.queue.unshift(msg); } - + handleRequest(msg: protocol.Request) { let response: protocol.Response; try { @@ -345,7 +347,7 @@ namespace ts.server { } } } - + class InProcClient { private server: InProcSession; private seq = 0; @@ -379,7 +381,7 @@ namespace ts.server { connect(session: InProcSession): void { this.server = session; } - + execute(command: string, args: any, callback: (resp: protocol.Response) => void): void { if (!this.server) { return; @@ -394,7 +396,7 @@ namespace ts.server { this.callbacks[this.seq] = callback; } }; - + it("can be constructed and respond to commands", (done) => { const cli = new InProcClient(); const session = new InProcSession(cli); @@ -402,23 +404,23 @@ namespace ts.server { data: true }; const toEvent = { - data: false + data: false }; let responses = 0; // Connect the client cli.connect(session); - + // Add an event handler cli.on("testevent", (eventinfo) => { expect(eventinfo).to.equal(toEvent); responses++; expect(responses).to.equal(1); }); - + // Trigger said event from the server session.event(toEvent, "testevent"); - + // Queue an echo command cli.execute("echo", toEcho, (resp) => { assert(resp.success, resp.message); @@ -426,7 +428,7 @@ namespace ts.server { expect(responses).to.equal(2); expect(resp.body).to.deep.equal(toEcho); }); - + // Queue a configure command cli.execute("configure", { hostInfo: "unit test", @@ -436,10 +438,10 @@ namespace ts.server { }, (resp) => { assert(resp.success, resp.message); responses++; - expect(responses).to.equal(3); + expect(responses).to.equal(3); done(); }); - + // Consume the queue and trigger the callbacks session.consumeQueue(); }); diff --git a/tslint.json b/tslint.json index 9b010d9a89..71efb21ad7 100644 --- a/tslint.json +++ b/tslint.json @@ -38,6 +38,7 @@ "no-trailing-whitespace": true, "no-inferrable-types": true, "no-null": true, + "no-unused-variable": true, "boolean-trivia": true, "type-operator-spacing": true, "prefer-const": true,