diff --git a/AUTHORS.md b/AUTHORS.md index 486a15bf47f6d..0501514d75865 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -2,9 +2,11 @@ TypeScript is authored by: * Adam Freidin * Ahmad Farid +* Akshar Patel * Anders Hejlsberg * Arnav Singh * Arthur Ozga +* Asad Saeeduddin * Basarat Ali Syed * Ben Duffield * Bill Ticehurst @@ -15,30 +17,39 @@ TypeScript is authored by: * Colby Russell * Colin Snover * Cyrus Najmabadi +* Dan Corder * Dan Quirk * Daniel Rosenwasser +* @dashaus * David Li * Denis Nedelyaev * Dick van den Brink * Dirk Bäumer +* Dirk Holtwick * Eyas Sharaiha +* @falsandtru * Frank Wallis * Gabriel Isenberg * Gilad Peleg * Graeme Wicksted * Guillaume Salles +* Guy Bedford * Harald Niesche +* Iain Monro * Ingvar Stepanyan * Ivo Gabe de Wolff * James Whitney * Jason Freeman +* Jason Killian * Jason Ramsay * Jed Mao +* Jeffrey Morlan * Johannes Rieken * John Vilk * Jonathan Bond-Caron * Jonathan Park * Jonathan Turner +* Jonathon Smith * Josh Kalderimis * Julian Williams * Kagami Sascha Rosylight @@ -46,21 +57,27 @@ TypeScript is authored by: * Ken Howard * Kenji Imamula * Lorant Pinter +* Lucien Greathouse * Martin Všetička * Masahiro Wakame +* Mattias Buelens * Max Deepfield * Micah Zoltu * Mohamed Hegazy * Nathan Shively-Sanders +* Nathan Yee * Oleg Mihailik * Oleksandr Chekhovskyi * Paul van Brenk +* @pcbro * Pedro Maltez * Philip Bulley * piloopin * @progre * Punya Biswal +* Richard Sentino * Ron Buckton +* Rowan Wyborn * Ryan Cavanaugh * Ryohei Ikegami * Sébastien Arod @@ -71,7 +88,9 @@ TypeScript is authored by: * Solal Pirelli * Stan Thomas * Steve Lucco +* Thomas Loubiou * Tien Hoanhtien +* Tim Perry * Tingan Ho * togru * Tomas Grubliauskas @@ -81,5 +100,6 @@ TypeScript is authored by: * Wesley Wigham * York Yao * Yui Tanglertsampan +* Yuichi Nukiyama * Zev Spitz * Zhengbo Li diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d9941d92e8704..1dba1281dd7c4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -30,7 +30,7 @@ You can try out the nightly build of TypeScript (`npm install typescript@next`) We also accept suggestions in the issue tracker. Be sure to [check the FAQ](https://github.com/Microsoft/TypeScript/wiki/FAQ) and [search](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=is%3Aissue) first. -In general, things we find useful when reviewing suggestins are: +In general, things we find useful when reviewing suggestions are: * A description of the problem you're trying to solve * An overview of the suggested solution * Examples of how the suggestion would work in various places @@ -71,7 +71,7 @@ Your pull request should: * Tests should include reasonable permutations of the target fix/change * Include baseline changes with your change * All changed code must have 100% code coverage -* Follow the code conventions descriped in [Coding guidelines](https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines) +* Follow the code conventions described in [Coding guidelines](https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines) * To avoid line ending issues, set `autocrlf = input` and `whitespace = cr-at-eol` in your git configuration ## Contributing `lib.d.ts` fixes diff --git a/doc/TypeScript Language Specification.docx b/doc/TypeScript Language Specification.docx index 78c869175512d..4b8d3998f905a 100644 Binary files a/doc/TypeScript Language Specification.docx and b/doc/TypeScript Language Specification.docx differ diff --git a/doc/spec.md b/doc/spec.md index 30de2c5a6b63f..fa69d32105663 100644 --- a/doc/spec.md +++ b/doc/spec.md @@ -3885,7 +3885,7 @@ function g(x: number) { the inferred return type for 'f' and 'g' is Any because the functions reference themselves through a cycle with no return type annotations. Adding an explicit return type 'number' to either breaks the cycle and causes the return type 'number' to be inferred for the other. -An explicitly typed function whose return type isn't the Void or the Any type must have at least one return statement somewhere in its body. An exception to this rule is if the function implementation consists of a single 'throw' statement. +An explicitly typed function whose return type isn't the Void type, the Any type, or a union type containing the Void or Any type as a constituent must have at least one return statement somewhere in its body. An exception to this rule is if the function implementation consists of a single 'throw' statement. The type of 'this' in a function implementation is the Any type. diff --git a/package.json b/package.json index 261cdfa64b7d1..cc74bf2c27c23 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "typescript", "author": "Microsoft Corp.", "homepage": "http://typescriptlang.org/", - "version": "1.8.0", + "version": "1.9.0", "license": "Apache-2.0", "description": "TypeScript is a language for application scale JavaScript development", "keywords": [ diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 88a1a62ce4cd2..0e169ca7aca12 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1110,7 +1110,7 @@ namespace ts { } function checkStrictModeNumericLiteral(node: LiteralExpression) { - if (inStrictMode && node.flags & NodeFlags.OctalLiteral) { + if (inStrictMode && node.isOctalLiteral) { file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode)); } } @@ -1384,7 +1384,7 @@ namespace ts { // Export assignment in some sort of block construct bindAnonymousDeclaration(node, SymbolFlags.Alias, getDeclarationName(node)); } - else if (boundExpression.kind === SyntaxKind.Identifier) { + else if (boundExpression.kind === SyntaxKind.Identifier && node.kind === SyntaxKind.ExportAssignment) { // An export default clause with an identifier exports all meanings of that identifier declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Alias, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes); } @@ -1435,7 +1435,8 @@ namespace ts { // Declare a 'member' in case it turns out the container was an ES5 class if (container.kind === SyntaxKind.FunctionExpression || container.kind === SyntaxKind.FunctionDeclaration) { container.symbol.members = container.symbol.members || {}; - declareSymbol(container.symbol.members, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + // It's acceptable for multiple 'this' assignments of the same identifier to occur + declareSymbol(container.symbol.members, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property); } } @@ -1444,8 +1445,16 @@ namespace ts { // Look up the function in the local scope, since prototype assignments should // follow the function declaration - const classId = ((node.left).expression).expression; - const funcSymbol = container.locals[classId.text]; + const leftSideOfAssignment = node.left as PropertyAccessExpression; + const classPrototype = leftSideOfAssignment.expression as PropertyAccessExpression; + const constructorFunction = classPrototype.expression as Identifier; + + // Fix up parent pointers since we're going to use these nodes before we bind into them + leftSideOfAssignment.parent = node; + constructorFunction.parent = classPrototype; + classPrototype.parent = leftSideOfAssignment; + + const funcSymbol = container.locals[constructorFunction.text]; if (!funcSymbol || !(funcSymbol.flags & SymbolFlags.Function)) { return; } @@ -1456,13 +1465,13 @@ namespace ts { } // Declare the method/property - declareSymbol(funcSymbol.members, funcSymbol, node.left, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, SymbolFlags.Property, SymbolFlags.PropertyExcludes); } function bindCallExpression(node: CallExpression) { // We're only inspecting call expressions to detect CommonJS modules, so we can skip // this check if we've already seen the module indicator - if (!file.commonJsModuleIndicator && isRequireCall(node)) { + if (!file.commonJsModuleIndicator && isRequireCall(node, /*checkArgumentIsStringLiteral*/false)) { setCommonJsModuleIndicator(node); } } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4ea8c71e0548a..07ec5023d5ba5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -134,6 +134,8 @@ namespace ts { const anySignature = createSignature(undefined, undefined, emptyArray, anyType, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false); const unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false); + const enumNumberIndexInfo = createIndexInfo(stringType, /*isReadonly*/ true); + const globals: SymbolTable = {}; let globalESSymbolConstructorSymbol: Symbol; @@ -143,6 +145,7 @@ namespace ts { let globalObjectType: ObjectType; let globalFunctionType: ObjectType; let globalArrayType: GenericType; + let globalReadonlyArrayType: GenericType; let globalStringType: ObjectType; let globalNumberType: ObjectType; let globalBooleanType: ObjectType; @@ -154,6 +157,7 @@ namespace ts { let globalIterableIteratorType: GenericType; let anyArrayType: Type; + let anyReadonlyArrayType: Type; let getGlobalClassDecoratorType: () => ObjectType; let getGlobalParameterDecoratorType: () => ObjectType; let getGlobalPropertyDecoratorType: () => ObjectType; @@ -376,8 +380,8 @@ namespace ts { const moduleAugmentation = moduleName.parent; if (moduleAugmentation.symbol.valueDeclaration !== moduleAugmentation) { // this is a combined symbol for multiple augmentations within the same file. - // its symbol already has accumulated information for all declarations - // so we need to add it just once - do the work only for first declaration + // its symbol already has accumulated information for all declarations + // so we need to add it just once - do the work only for first declaration Debug.assert(moduleAugmentation.symbol.declarations.length > 1); return; } @@ -386,15 +390,22 @@ namespace ts { mergeSymbolTable(globals, moduleAugmentation.symbol.exports); } else { - // find a module that about to be augmented + // find a module that about to be augmented let mainModule = resolveExternalModuleNameWorker(moduleName, moduleName, Diagnostics.Invalid_module_name_in_augmentation_module_0_cannot_be_found); if (!mainModule) { return; } - // if module symbol has already been merged - it is safe to use it. - // otherwise clone it - mainModule = mainModule.flags & SymbolFlags.Merged ? mainModule : cloneSymbol(mainModule); - mergeSymbol(mainModule, moduleAugmentation.symbol); + // obtain item referenced by 'export=' + mainModule = resolveExternalModuleSymbol(mainModule); + if (mainModule.flags & SymbolFlags.Namespace) { + // if module symbol has already been merged - it is safe to use it. + // otherwise clone it + mainModule = mainModule.flags & SymbolFlags.Merged ? mainModule : cloneSymbol(mainModule); + mergeSymbol(mainModule, moduleAugmentation.symbol); + } + else { + error(moduleName, Diagnostics.Cannot_augment_module_0_because_it_resolves_to_a_non_module_entity, moduleName.text); + } } } @@ -812,7 +823,7 @@ namespace ts { } // No static member is present. - // Check if we're in an instance method and look for a relevant instance member. + // Check if we're in an instance method and look for a relevant instance member. if (location === container && !(location.flags & NodeFlags.Static)) { const instanceType = (getDeclaredTypeOfSymbol(classSymbol)).thisType; if (getPropertyOfType(instanceType, name)) { @@ -887,7 +898,7 @@ namespace ts { error(node.name, Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol)); } else if (!exportDefaultSymbol && allowSyntheticDefaultImports) { - return resolveSymbol(moduleSymbol.exports["export="]) || resolveSymbol(moduleSymbol); + return resolveExternalModuleSymbol(moduleSymbol) || resolveSymbol(moduleSymbol); } return exportDefaultSymbol; } @@ -1163,7 +1174,7 @@ namespace ts { return getMergedSymbol(sourceFile.symbol); } if (moduleNotFoundError) { - // report errors only if it was requested + // report errors only if it was requested error(moduleReferenceLiteral, Diagnostics.File_0_is_not_a_module, sourceFile.fileName); } return undefined; @@ -1178,7 +1189,7 @@ namespace ts { // An external module with an 'export =' declaration resolves to the target of the 'export =' declaration, // and an external module with no 'export =' declaration resolves to the module itself. function resolveExternalModuleSymbol(moduleSymbol: Symbol): Symbol { - return moduleSymbol && resolveSymbol(moduleSymbol.exports["export="]) || moduleSymbol; + return moduleSymbol && getMergedSymbol(resolveSymbol(moduleSymbol.exports["export="])) || moduleSymbol; } // An external module with an 'export =' declaration may be referenced as an ES6 module provided the 'export =' @@ -1193,8 +1204,8 @@ namespace ts { return symbol; } - function getExportAssignmentSymbol(moduleSymbol: Symbol): Symbol { - return moduleSymbol.exports["export="]; + function hasExportAssignmentSymbol(moduleSymbol: Symbol): boolean { + return moduleSymbol.exports["export="] !== undefined; } function getExportsOfModuleAsArray(moduleSymbol: Symbol): Symbol[] { @@ -1382,19 +1393,19 @@ namespace ts { return result || emptyArray; } - function setObjectTypeMembers(type: ObjectType, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexType: Type, numberIndexType: Type): ResolvedType { + function setObjectTypeMembers(type: ObjectType, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexInfo: IndexInfo, numberIndexInfo: IndexInfo): ResolvedType { (type).members = members; (type).properties = getNamedMembers(members); (type).callSignatures = callSignatures; (type).constructSignatures = constructSignatures; - if (stringIndexType) (type).stringIndexType = stringIndexType; - if (numberIndexType) (type).numberIndexType = numberIndexType; + if (stringIndexInfo) (type).stringIndexInfo = stringIndexInfo; + if (numberIndexInfo) (type).numberIndexInfo = numberIndexInfo; return type; } - function createAnonymousType(symbol: Symbol, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexType: Type, numberIndexType: Type): ResolvedType { + function createAnonymousType(symbol: Symbol, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexInfo: IndexInfo, numberIndexInfo: IndexInfo): ResolvedType { return setObjectTypeMembers(createObjectType(TypeFlags.Anonymous, symbol), - members, callSignatures, constructSignatures, stringIndexType, numberIndexType); + members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); } function forEachSymbolTableInScope(enclosingDeclaration: Node, callback: (symbolTable: SymbolTable) => T): T { @@ -2022,20 +2033,40 @@ namespace ts { buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value, SymbolFormatFlags.None, typeFormatFlags); } - function getIndexerParameterName(type: ObjectType, indexKind: IndexKind, fallbackName: string): string { - const declaration = getIndexDeclarationOfSymbol(type.symbol, indexKind); - if (!declaration) { - // declaration might not be found if indexer was added from the contextual type. - // in this case use fallback name - return fallbackName; + function writeIndexSignature(info: IndexInfo, keyword: SyntaxKind) { + if (info) { + if (info.isReadonly) { + writeKeyword(writer, SyntaxKind.ReadonlyKeyword); + writeSpace(writer); + } + writePunctuation(writer, SyntaxKind.OpenBracketToken); + writer.writeParameter(info.declaration ? declarationNameToString(info.declaration.parameters[0].name) : "x"); + writePunctuation(writer, SyntaxKind.ColonToken); + writeSpace(writer); + writeKeyword(writer, keyword); + writePunctuation(writer, SyntaxKind.CloseBracketToken); + writePunctuation(writer, SyntaxKind.ColonToken); + writeSpace(writer); + writeType(info.type, TypeFormatFlags.None); + writePunctuation(writer, SyntaxKind.SemicolonToken); + writer.writeLine(); + } + } + + function writePropertyWithModifiers(prop: Symbol) { + if (isReadonlySymbol(prop)) { + writeKeyword(writer, SyntaxKind.ReadonlyKeyword); + writeSpace(writer); + } + buildSymbolDisplay(prop, writer); + if (prop.flags & SymbolFlags.Optional) { + writePunctuation(writer, SyntaxKind.QuestionToken); } - Debug.assert(declaration.parameters.length !== 0); - return declarationNameToString(declaration.parameters[0].name); } function writeLiteralType(type: ObjectType, flags: TypeFormatFlags) { const resolved = resolveStructuredTypeMembers(type); - if (!resolved.properties.length && !resolved.stringIndexType && !resolved.numberIndexType) { + if (!resolved.properties.length && !resolved.stringIndexInfo && !resolved.numberIndexInfo) { if (!resolved.callSignatures.length && !resolved.constructSignatures.length) { writePunctuation(writer, SyntaxKind.OpenBraceToken); writePunctuation(writer, SyntaxKind.CloseBraceToken); @@ -2081,53 +2112,21 @@ namespace ts { writePunctuation(writer, SyntaxKind.SemicolonToken); writer.writeLine(); } - if (resolved.stringIndexType) { - // [x: string]: - writePunctuation(writer, SyntaxKind.OpenBracketToken); - writer.writeParameter(getIndexerParameterName(resolved, IndexKind.String, /*fallbackName*/"x")); - writePunctuation(writer, SyntaxKind.ColonToken); - writeSpace(writer); - writeKeyword(writer, SyntaxKind.StringKeyword); - writePunctuation(writer, SyntaxKind.CloseBracketToken); - writePunctuation(writer, SyntaxKind.ColonToken); - writeSpace(writer); - writeType(resolved.stringIndexType, TypeFormatFlags.None); - writePunctuation(writer, SyntaxKind.SemicolonToken); - writer.writeLine(); - } - if (resolved.numberIndexType) { - // [x: number]: - writePunctuation(writer, SyntaxKind.OpenBracketToken); - writer.writeParameter(getIndexerParameterName(resolved, IndexKind.Number, /*fallbackName*/"x")); - writePunctuation(writer, SyntaxKind.ColonToken); - writeSpace(writer); - writeKeyword(writer, SyntaxKind.NumberKeyword); - writePunctuation(writer, SyntaxKind.CloseBracketToken); - writePunctuation(writer, SyntaxKind.ColonToken); - writeSpace(writer); - writeType(resolved.numberIndexType, TypeFormatFlags.None); - writePunctuation(writer, SyntaxKind.SemicolonToken); - writer.writeLine(); - } + writeIndexSignature(resolved.stringIndexInfo, SyntaxKind.StringKeyword); + writeIndexSignature(resolved.numberIndexInfo, SyntaxKind.NumberKeyword); for (const p of resolved.properties) { const t = getTypeOfSymbol(p); if (p.flags & (SymbolFlags.Function | SymbolFlags.Method) && !getPropertiesOfObjectType(t).length) { const signatures = getSignaturesOfType(t, SignatureKind.Call); for (const signature of signatures) { - buildSymbolDisplay(p, writer); - if (p.flags & SymbolFlags.Optional) { - writePunctuation(writer, SyntaxKind.QuestionToken); - } + writePropertyWithModifiers(p); buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, /*kind*/ undefined, symbolStack); writePunctuation(writer, SyntaxKind.SemicolonToken); writer.writeLine(); } } else { - buildSymbolDisplay(p, writer); - if (p.flags & SymbolFlags.Optional) { - writePunctuation(writer, SyntaxKind.QuestionToken); - } + writePropertyWithModifiers(p); writePunctuation(writer, SyntaxKind.ColonToken); writeSpace(writer); writeType(t, TypeFormatFlags.None); @@ -2473,10 +2472,21 @@ namespace ts { function getDeclarationContainer(node: Node): Node { node = getRootDeclaration(node); + while (node) { + switch (node.kind) { + case SyntaxKind.VariableDeclaration: + case SyntaxKind.VariableDeclarationList: + case SyntaxKind.ImportSpecifier: + case SyntaxKind.NamedImports: + case SyntaxKind.NamespaceImport: + case SyntaxKind.ImportClause: + node = node.parent; + break; - // Parent chain: - // VaribleDeclaration -> VariableDeclarationList -> VariableStatement -> 'Declaration Container' - return node.kind === SyntaxKind.VariableDeclaration ? node.parent.parent.parent : node.parent; + default: + return node.parent; + } + } } function getTypeOfPrototypeProperty(prototype: Symbol): Type { @@ -2484,7 +2494,7 @@ namespace ts { // Every class automatically contains a static property member named 'prototype', // the type of which is an instantiation of the class type with type Any supplied as a type argument for each type parameter. // It is an error to explicitly declare a static property member with the name 'prototype'. - const classType = getDeclaredTypeOfSymbol(getMergedSymbol(prototype.parent)); + const classType = getDeclaredTypeOfSymbol(getParentOfSymbol(prototype)); return classType.typeParameters ? createTypeReference(classType, map(classType.typeParameters, _ => anyType)) : classType; } @@ -2618,7 +2628,7 @@ namespace ts { } } else if (declaration.kind === SyntaxKind.Parameter) { - // If it's a parameter, see if the parent has a jsdoc comment with an @param + // If it's a parameter, see if the parent has a jsdoc comment with an @param // annotation. const paramTag = getCorrespondingJSDocParameterTag(declaration); if (paramTag && paramTag.typeExpression) { @@ -2631,9 +2641,9 @@ namespace ts { // Return the inferred type for a variable, parameter, or property declaration function getTypeForVariableLikeDeclaration(declaration: VariableLikeDeclaration): Type { - if (declaration.parserContextFlags & ParserContextFlags.JavaScriptFile) { + if (declaration.flags & NodeFlags.JavaScriptFile) { // If this is a variable in a JavaScript file, then use the JSDoc type (if it has - // one as its type), otherwise fallback to the below standard TS codepaths to + // one as its type), otherwise fallback to the below standard TS codepaths to // try to figure it out. const type = getTypeForVariableLikeDeclarationFromJSDocComment(declaration); if (type && type !== unknownType) { @@ -2827,7 +2837,7 @@ namespace ts { } // Handle module.exports = expr if (declaration.kind === SyntaxKind.BinaryExpression) { - return links.type = checkExpression((declaration).right); + return links.type = getUnionType(map(symbol.declarations, (decl: BinaryExpression) => checkExpressionCached(decl.right))); } if (declaration.kind === SyntaxKind.PropertyAccessExpression) { // Declarations only exist for property access expressions for certain @@ -3463,8 +3473,8 @@ namespace ts { (type).declaredProperties = getNamedMembers(symbol.members); (type).declaredCallSignatures = getSignaturesOfSymbol(symbol.members["__call"]); (type).declaredConstructSignatures = getSignaturesOfSymbol(symbol.members["__new"]); - (type).declaredStringIndexType = getIndexTypeOfSymbol(symbol, IndexKind.String); - (type).declaredNumberIndexType = getIndexTypeOfSymbol(symbol, IndexKind.Number); + (type).declaredStringIndexInfo = getIndexInfoOfSymbol(symbol, IndexKind.String); + (type).declaredNumberIndexInfo = getIndexInfoOfSymbol(symbol, IndexKind.Number); } return type; } @@ -3482,15 +3492,15 @@ namespace ts { let members = source.symbol.members; let callSignatures = source.declaredCallSignatures; let constructSignatures = source.declaredConstructSignatures; - let stringIndexType = source.declaredStringIndexType; - let numberIndexType = source.declaredNumberIndexType; + let stringIndexInfo = source.declaredStringIndexInfo; + let numberIndexInfo = source.declaredNumberIndexInfo; if (!rangeEquals(typeParameters, typeArguments, 0, typeParameters.length)) { mapper = createTypeMapper(typeParameters, typeArguments); members = createInstantiatedSymbolTable(source.declaredProperties, mapper, /*mappingThisOnly*/ typeParameters.length === 1); callSignatures = instantiateList(source.declaredCallSignatures, mapper, instantiateSignature); constructSignatures = instantiateList(source.declaredConstructSignatures, mapper, instantiateSignature); - stringIndexType = instantiateType(source.declaredStringIndexType, mapper); - numberIndexType = instantiateType(source.declaredNumberIndexType, mapper); + stringIndexInfo = instantiateIndexInfo(source.declaredStringIndexInfo, mapper); + numberIndexInfo = instantiateIndexInfo(source.declaredNumberIndexInfo, mapper); } const baseTypes = getBaseTypes(source); if (baseTypes.length) { @@ -3503,11 +3513,11 @@ namespace ts { addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType)); callSignatures = concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, SignatureKind.Call)); constructSignatures = concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, SignatureKind.Construct)); - stringIndexType = stringIndexType || getIndexTypeOfType(instantiatedBaseType, IndexKind.String); - numberIndexType = numberIndexType || getIndexTypeOfType(instantiatedBaseType, IndexKind.Number); + stringIndexInfo = stringIndexInfo || getIndexInfoOfType(instantiatedBaseType, IndexKind.String); + numberIndexInfo = numberIndexInfo || getIndexInfoOfType(instantiatedBaseType, IndexKind.Number); } } - setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); + setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); } function resolveClassOrInterfaceMembers(type: InterfaceType): void { @@ -3578,7 +3588,7 @@ namespace ts { const arrayType = resolveStructuredTypeMembers(createTypeFromGenericGlobalType(globalArrayType, [arrayElementType, type])); const members = createTupleTypeMemberSymbols(type.elementTypes); addInheritedMembers(members, arrayType.properties); - setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType); + setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexInfo, arrayType.numberIndexInfo); } function findMatchingSignature(signatureList: Signature[], signature: Signature, partialMatch: boolean, ignoreReturnTypes: boolean): Signature { @@ -3646,16 +3656,18 @@ namespace ts { return result || emptyArray; } - function getUnionIndexType(types: Type[], kind: IndexKind): Type { + function getUnionIndexInfo(types: Type[], kind: IndexKind): IndexInfo { const indexTypes: Type[] = []; + let isAnyReadonly = false; for (const type of types) { - const indexType = getIndexTypeOfType(type, kind); - if (!indexType) { + const indexInfo = getIndexInfoOfType(type, kind); + if (!indexInfo) { return undefined; } - indexTypes.push(indexType); + indexTypes.push(indexInfo.type); + isAnyReadonly = isAnyReadonly || indexInfo.isReadonly; } - return getUnionType(indexTypes); + return createIndexInfo(getUnionType(indexTypes), isAnyReadonly); } function resolveUnionTypeMembers(type: UnionType) { @@ -3663,29 +3675,34 @@ namespace ts { // type use getPropertiesOfType (only the language service uses this). const callSignatures = getUnionSignatures(type.types, SignatureKind.Call); const constructSignatures = getUnionSignatures(type.types, SignatureKind.Construct); - const stringIndexType = getUnionIndexType(type.types, IndexKind.String); - const numberIndexType = getUnionIndexType(type.types, IndexKind.Number); - setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexType, numberIndexType); + const stringIndexInfo = getUnionIndexInfo(type.types, IndexKind.String); + const numberIndexInfo = getUnionIndexInfo(type.types, IndexKind.Number); + setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); } function intersectTypes(type1: Type, type2: Type): Type { return !type1 ? type2 : !type2 ? type1 : getIntersectionType([type1, type2]); } + function intersectIndexInfos(info1: IndexInfo, info2: IndexInfo): IndexInfo { + return !info1 ? info2 : !info2 ? info1 : createIndexInfo( + getIntersectionType([info1.type, info2.type]), info1.isReadonly && info2.isReadonly); + } + function resolveIntersectionTypeMembers(type: IntersectionType) { // The members and properties collections are empty for intersection types. To get all properties of an // intersection type use getPropertiesOfType (only the language service uses this). let callSignatures: Signature[] = emptyArray; let constructSignatures: Signature[] = emptyArray; - let stringIndexType: Type = undefined; - let numberIndexType: Type = undefined; + let stringIndexInfo: IndexInfo = undefined; + let numberIndexInfo: IndexInfo = undefined; for (const t of type.types) { callSignatures = concatenate(callSignatures, getSignaturesOfType(t, SignatureKind.Call)); constructSignatures = concatenate(constructSignatures, getSignaturesOfType(t, SignatureKind.Construct)); - stringIndexType = intersectTypes(stringIndexType, getIndexTypeOfType(t, IndexKind.String)); - numberIndexType = intersectTypes(numberIndexType, getIndexTypeOfType(t, IndexKind.Number)); + stringIndexInfo = intersectIndexInfos(stringIndexInfo, getIndexInfoOfType(t, IndexKind.String)); + numberIndexInfo = intersectIndexInfos(numberIndexInfo, getIndexInfoOfType(t, IndexKind.Number)); } - setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexType, numberIndexType); + setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); } function resolveAnonymousTypeMembers(type: AnonymousType) { @@ -3694,17 +3711,17 @@ namespace ts { const members = createInstantiatedSymbolTable(getPropertiesOfObjectType(type.target), type.mapper, /*mappingThisOnly*/ false); const callSignatures = instantiateList(getSignaturesOfType(type.target, SignatureKind.Call), type.mapper, instantiateSignature); const constructSignatures = instantiateList(getSignaturesOfType(type.target, SignatureKind.Construct), type.mapper, instantiateSignature); - const stringIndexType = instantiateType(getIndexTypeOfType(type.target, IndexKind.String), type.mapper); - const numberIndexType = instantiateType(getIndexTypeOfType(type.target, IndexKind.Number), type.mapper); - setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); + const stringIndexInfo = instantiateIndexInfo(getIndexInfoOfType(type.target, IndexKind.String), type.mapper); + const numberIndexInfo = instantiateIndexInfo(getIndexInfoOfType(type.target, IndexKind.Number), type.mapper); + setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); } else if (symbol.flags & SymbolFlags.TypeLiteral) { const members = symbol.members; const callSignatures = getSignaturesOfSymbol(members["__call"]); const constructSignatures = getSignaturesOfSymbol(members["__new"]); - const stringIndexType = getIndexTypeOfSymbol(symbol, IndexKind.String); - const numberIndexType = getIndexTypeOfSymbol(symbol, IndexKind.Number); - setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); + const stringIndexInfo = getIndexInfoOfSymbol(symbol, IndexKind.String); + const numberIndexInfo = getIndexInfoOfSymbol(symbol, IndexKind.Number); + setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); } else { // Combinations of function, class, enum and module @@ -3725,8 +3742,8 @@ namespace ts { addInheritedMembers(members, getPropertiesOfObjectType(baseConstructorType)); } } - const numberIndexType = (symbol.flags & SymbolFlags.Enum) ? stringType : undefined; - setObjectTypeMembers(type, members, emptyArray, constructSignatures, undefined, numberIndexType); + const numberIndexInfo = symbol.flags & SymbolFlags.Enum ? enumNumberIndexInfo : undefined; + setObjectTypeMembers(type, members, emptyArray, constructSignatures, undefined, numberIndexInfo); // We resolve the members before computing the signatures because a signature may use // typeof with a qualified name expression that circularly references the type we are // in the process of resolving (see issue #6072). The temporarily empty signature list @@ -3945,13 +3962,25 @@ namespace ts { function getSignaturesOfType(type: Type, kind: SignatureKind): Signature[] { return getSignaturesOfStructuredType(getApparentType(type), kind); } - function getIndexTypeOfStructuredType(type: Type, kind: IndexKind): Type { + + function getIndexInfoOfStructuredType(type: Type, kind: IndexKind): IndexInfo { if (type.flags & TypeFlags.StructuredType) { const resolved = resolveStructuredTypeMembers(type); - return kind === IndexKind.String ? resolved.stringIndexType : resolved.numberIndexType; + return kind === IndexKind.String ? resolved.stringIndexInfo : resolved.numberIndexInfo; } } + function getIndexTypeOfStructuredType(type: Type, kind: IndexKind): Type { + const info = getIndexInfoOfStructuredType(type, kind); + return info && info.type; + } + + // Return the indexing info of the given kind in the given type. Creates synthetic union index types when necessary and + // maps primitive types and type parameters are to their apparent types. + function getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo { + return getIndexInfoOfStructuredType(getApparentType(type), kind); + } + // Return the index type of the given kind in the given type. Creates synthetic union index types when necessary and // maps primitive types and type parameters are to their apparent types. function getIndexTypeOfType(type: Type, kind: IndexKind): Type { @@ -3959,7 +3988,7 @@ namespace ts { } function getTypeParametersFromJSDocTemplate(declaration: SignatureDeclaration): TypeParameter[] { - if (declaration.parserContextFlags & ParserContextFlags.JavaScriptFile) { + if (declaration.flags & NodeFlags.JavaScriptFile) { const templateTag = getJSDocTemplateTag(declaration); if (templateTag) { return getTypeParametersFromDeclaration(templateTag.typeParameters); @@ -3993,7 +4022,7 @@ namespace ts { } function isOptionalParameter(node: ParameterDeclaration) { - if (node.parserContextFlags & ParserContextFlags.JavaScriptFile) { + if (node.flags & NodeFlags.JavaScriptFile) { if (node.type && node.type.kind === SyntaxKind.JSDocOptionalType) { return true; } @@ -4058,7 +4087,7 @@ namespace ts { const isJSConstructSignature = isJSDocConstructSignature(declaration); let returnType: Type = undefined; - // If this is a JSDoc construct signature, then skip the first parameter in the + // If this is a JSDoc construct signature, then skip the first parameter in the // parameter list. The first parameter represents the return type of the construct // signature. for (let i = isJSConstructSignature ? 1 : 0, n = declaration.parameters.length; i < n; i++) { @@ -4102,7 +4131,7 @@ namespace ts { returnType = getTypeFromTypeNode(declaration.type); } else { - if (declaration.parserContextFlags & ParserContextFlags.JavaScriptFile) { + if (declaration.flags & NodeFlags.JavaScriptFile) { const type = getReturnTypeFromJSDocComment(declaration); if (type && type !== unknownType) { returnType = type; @@ -4272,11 +4301,17 @@ namespace ts { return undefined; } - function getIndexTypeOfSymbol(symbol: Symbol, kind: IndexKind): Type { + function createIndexInfo(type: Type, isReadonly: boolean, declaration?: SignatureDeclaration): IndexInfo { + return { type, isReadonly, declaration }; + } + + function getIndexInfoOfSymbol(symbol: Symbol, kind: IndexKind): IndexInfo { const declaration = getIndexDeclarationOfSymbol(symbol, kind); - return declaration - ? declaration.type ? getTypeFromTypeNode(declaration.type) : anyType - : undefined; + if (declaration) { + return createIndexInfo(declaration.type ? getTypeFromTypeNode(declaration.type) : anyType, + (declaration.flags & NodeFlags.Readonly) !== 0, declaration); + } + return undefined; } function getConstraintDeclaration(type: TypeParameter) { @@ -4285,7 +4320,7 @@ namespace ts { function hasConstraintReferenceTo(type: Type, target: TypeParameter): boolean { let checked: Type[]; - while (type && type.flags & TypeFlags.TypeParameter && !contains(checked, type)) { + while (type && !(type.flags & TypeFlags.ThisType) && type.flags & TypeFlags.TypeParameter && !contains(checked, type)) { if (type === target) { return true; } @@ -4461,7 +4496,7 @@ namespace ts { } if (symbol.flags & SymbolFlags.Value && node.kind === SyntaxKind.JSDocTypeReference) { - // A JSDocTypeReference may have resolved to a value (as opposed to a type). In + // A JSDocTypeReference may have resolved to a value (as opposed to a type). In // that case, the type of this reference is just the type of the value we resolved // to. return getTypeOfSymbol(symbol); @@ -5112,6 +5147,10 @@ namespace ts { return type; } + function instantiateIndexInfo(info: IndexInfo, mapper: TypeMapper): IndexInfo { + return info && createIndexInfo(instantiateType(info.type, mapper), info.isReadonly, info.declaration); + } + // Returns true if the given expression contains (at any level of nesting) a function or arrow expression // that is subject to contextual typing. function isContextSensitive(node: Expression | MethodDeclaration | ObjectLiteralElement): boolean { @@ -5537,7 +5576,7 @@ namespace ts { if (type.flags & TypeFlags.ObjectType) { const resolved = resolveStructuredTypeMembers(type); if (relation === assignableRelation && (type === globalObjectType || resolved.properties.length === 0) || - resolved.stringIndexType || resolved.numberIndexType || getPropertyOfType(type, name)) { + resolved.stringIndexInfo || resolved.numberIndexInfo || getPropertyOfType(type, name)) { return true; } } @@ -5771,8 +5810,8 @@ namespace ts { } else if (targetPropFlags & NodeFlags.Protected) { const sourceDeclaredInClass = sourceProp.parent && sourceProp.parent.flags & SymbolFlags.Class; - const sourceClass = sourceDeclaredInClass ? getDeclaredTypeOfSymbol(sourceProp.parent) : undefined; - const targetClass = getDeclaredTypeOfSymbol(targetProp.parent); + const sourceClass = sourceDeclaredInClass ? getDeclaredTypeOfSymbol(getParentOfSymbol(sourceProp)) : undefined; + const targetClass = getDeclaredTypeOfSymbol(getParentOfSymbol(targetProp)); if (!sourceClass || !hasBaseType(sourceClass, targetClass)) { if (reportErrors) { reportError(Diagnostics.Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2, @@ -5866,29 +5905,24 @@ namespace ts { const saveErrorInfo = errorInfo; outer: for (const t of targetSignatures) { - if (!t.hasStringLiterals || target.flags & TypeFlags.FromSignature) { - // Only elaborate errors from the first failure - let shouldElaborateErrors = reportErrors; - for (const s of sourceSignatures) { - if (!s.hasStringLiterals || source.flags & TypeFlags.FromSignature) { - const related = signatureRelatedTo(s, t, shouldElaborateErrors); - if (related) { - result &= related; - errorInfo = saveErrorInfo; - continue outer; - } - shouldElaborateErrors = false; - } - } - // don't elaborate the primitive apparent types (like Number) - // because the actual primitives will have already been reported. - if (shouldElaborateErrors) { - reportError(Diagnostics.Type_0_provides_no_match_for_the_signature_1, - typeToString(source), - signatureToString(t, /*enclosingDeclaration*/ undefined, /*flags*/ undefined, kind)); + // Only elaborate errors from the first failure + let shouldElaborateErrors = reportErrors; + for (const s of sourceSignatures) { + const related = signatureRelatedTo(s, t, shouldElaborateErrors); + if (related) { + result &= related; + errorInfo = saveErrorInfo; + continue outer; } - return Ternary.False; + shouldElaborateErrors = false; } + + if (shouldElaborateErrors) { + reportError(Diagnostics.Type_0_provides_no_match_for_the_signature_1, + typeToString(source), + signatureToString(t, /*enclosingDeclaration*/ undefined, /*flags*/ undefined, kind)); + } + return Ternary.False; } return result; } @@ -5921,21 +5955,21 @@ namespace ts { if (relation === identityRelation) { return indexTypesIdenticalTo(IndexKind.String, source, target); } - const targetType = getIndexTypeOfType(target, IndexKind.String); - if (targetType) { - if ((targetType.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive)) { + const targetInfo = getIndexInfoOfType(target, IndexKind.String); + if (targetInfo) { + if ((targetInfo.type.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive)) { // non-primitive assignment to any is always allowed, eg // `var x: { [index: string]: any } = { property: 12 };` return Ternary.True; } - const sourceType = getIndexTypeOfType(source, IndexKind.String); - if (!sourceType) { + const sourceInfo = getIndexInfoOfType(source, IndexKind.String); + if (!sourceInfo) { if (reportErrors) { reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } return Ternary.False; } - const related = isRelatedTo(sourceType, targetType, reportErrors); + const related = isRelatedTo(sourceInfo.type, targetInfo.type, reportErrors); if (!related) { if (reportErrors) { reportError(Diagnostics.Index_signatures_are_incompatible); @@ -5951,28 +5985,29 @@ namespace ts { if (relation === identityRelation) { return indexTypesIdenticalTo(IndexKind.Number, source, target); } - const targetType = getIndexTypeOfType(target, IndexKind.Number); - if (targetType) { - if ((targetType.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive)) { + const targetInfo = getIndexInfoOfType(target, IndexKind.Number); + if (targetInfo) { + if ((targetInfo.type.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive)) { // non-primitive assignment to any is always allowed, eg // `var x: { [index: number]: any } = { property: 12 };` return Ternary.True; } - const sourceStringType = getIndexTypeOfType(source, IndexKind.String); - const sourceNumberType = getIndexTypeOfType(source, IndexKind.Number); - if (!(sourceStringType || sourceNumberType)) { + const sourceStringInfo = getIndexInfoOfType(source, IndexKind.String); + const sourceNumberInfo = getIndexInfoOfType(source, IndexKind.Number); + if (!(sourceStringInfo || sourceNumberInfo)) { if (reportErrors) { reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } return Ternary.False; } let related: Ternary; - if (sourceStringType && sourceNumberType) { + if (sourceStringInfo && sourceNumberInfo) { // If we know for sure we're testing both string and numeric index types then only report errors from the second one - related = isRelatedTo(sourceStringType, targetType, /*reportErrors*/ false) || isRelatedTo(sourceNumberType, targetType, reportErrors); + related = isRelatedTo(sourceStringInfo.type, targetInfo.type, /*reportErrors*/ false) || + isRelatedTo(sourceNumberInfo.type, targetInfo.type, reportErrors); } else { - related = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors); + related = isRelatedTo((sourceStringInfo || sourceNumberInfo).type, targetInfo.type, reportErrors); } if (!related) { if (reportErrors) { @@ -5986,13 +6021,13 @@ namespace ts { } function indexTypesIdenticalTo(indexKind: IndexKind, source: Type, target: Type): Ternary { - const targetType = getIndexTypeOfType(target, indexKind); - const sourceType = getIndexTypeOfType(source, indexKind); - if (!sourceType && !targetType) { + const targetInfo = getIndexInfoOfType(target, indexKind); + const sourceInfo = getIndexInfoOfType(source, indexKind); + if (!sourceInfo && !targetInfo) { return Ternary.True; } - if (sourceType && targetType) { - return isRelatedTo(sourceType, targetType); + if (sourceInfo && targetInfo && sourceInfo.isReadonly === targetInfo.isReadonly) { + return isRelatedTo(sourceInfo.type, targetInfo.type); } return Ternary.False; } @@ -6080,6 +6115,9 @@ namespace ts { return Ternary.False; } } + if (isReadonlySymbol(sourceProp) !== isReadonlySymbol(targetProp)) { + return Ternary.False; + } return compareTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); } @@ -6203,8 +6241,10 @@ namespace ts { } function isArrayLikeType(type: Type): boolean { - // A type is array-like if it is not the undefined or null type and if it is assignable to any[] - return !(type.flags & (TypeFlags.Undefined | TypeFlags.Null)) && isTypeAssignableTo(type, anyArrayType); + // A type is array-like if it is a reference to the global Array or global ReadonlyArray type, + // or if it is not the undefined or null type and if it is assignable to ReadonlyArray + return type.flags & TypeFlags.Reference && ((type).target === globalArrayType || (type).target === globalReadonlyArrayType) || + !(type.flags & (TypeFlags.Undefined | TypeFlags.Null)) && isTypeAssignableTo(type, anyReadonlyArrayType); } function isTupleLikeType(type: Type): boolean { @@ -6233,8 +6273,8 @@ namespace ts { regularType.properties = (type).properties; regularType.callSignatures = (type).callSignatures; regularType.constructSignatures = (type).constructSignatures; - regularType.stringIndexType = (type).stringIndexType; - regularType.numberIndexType = (type).numberIndexType; + regularType.stringIndexInfo = (type).stringIndexInfo; + regularType.numberIndexInfo = (type).numberIndexInfo; (type).regularType = regularType; } return regularType; @@ -6259,11 +6299,11 @@ namespace ts { } members[p.name] = p; }); - let stringIndexType = getIndexTypeOfType(type, IndexKind.String); - let numberIndexType = getIndexTypeOfType(type, IndexKind.Number); - if (stringIndexType) stringIndexType = getWidenedType(stringIndexType); - if (numberIndexType) numberIndexType = getWidenedType(numberIndexType); - return createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType); + const stringIndexInfo = getIndexInfoOfType(type, IndexKind.String); + const numberIndexInfo = getIndexInfoOfType(type, IndexKind.Number); + return createAnonymousType(type.symbol, members, emptyArray, emptyArray, + stringIndexInfo && createIndexInfo(getWidenedType(stringIndexInfo.type), stringIndexInfo.isReadonly), + numberIndexInfo && createIndexInfo(getWidenedType(numberIndexInfo.type), numberIndexInfo.isReadonly)); } function getWidenedType(type: Type): Type { @@ -7145,9 +7185,8 @@ namespace ts { } } - if (node.parserContextFlags & ParserContextFlags.Await) { + if (node.flags & NodeFlags.AwaitContext) { getNodeLinks(container).flags |= NodeCheckFlags.CaptureArguments; - getNodeLinks(node).flags |= NodeCheckFlags.LexicalArguments; } } @@ -7155,11 +7194,32 @@ namespace ts { markAliasSymbolAsReferenced(symbol); } + const localOrExportSymbol = getExportSymbolOfValueSymbolIfExported(symbol); + + // Due to the emit for class decorators, any reference to the class from inside of the class body + // must instead be rewritten to point to a temporary variable to avoid issues with the double-bind + // behavior of class names in ES6. + if (languageVersion === ScriptTarget.ES6 + && localOrExportSymbol.flags & SymbolFlags.Class + && localOrExportSymbol.valueDeclaration.kind === SyntaxKind.ClassDeclaration + && nodeIsDecorated(localOrExportSymbol.valueDeclaration)) { + let container = getContainingClass(node); + while (container !== undefined) { + if (container === localOrExportSymbol.valueDeclaration && container.name !== node) { + getNodeLinks(container).flags |= NodeCheckFlags.ClassWithBodyScopedClassBinding; + getNodeLinks(node).flags |= NodeCheckFlags.BodyScopedClassBinding; + break; + } + + container = getContainingClass(container); + } + } + checkCollisionWithCapturedSuperVariable(node, node); checkCollisionWithCapturedThisVariable(node, node); - checkBlockScopedBindingCapturedInLoop(node, symbol); + checkNestedBlockScopedBinding(node, symbol); - return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node); + return getNarrowedTypeOfSymbol(localOrExportSymbol, node); } function isInsideFunction(node: Node, threshold: Node): boolean { @@ -7174,7 +7234,7 @@ namespace ts { return false; } - function checkBlockScopedBindingCapturedInLoop(node: Identifier, symbol: Symbol): void { + function checkNestedBlockScopedBinding(node: Identifier, symbol: Symbol): void { if (languageVersion >= ScriptTarget.ES6 || (symbol.flags & (SymbolFlags.BlockScopedVariable | SymbolFlags.Class)) === 0 || symbol.valueDeclaration.parent.kind === SyntaxKind.CatchClause) { @@ -7186,40 +7246,31 @@ namespace ts { // 2. walk from the declaration up to the boundary of lexical environment and check // if there is an iteration statement in between declaration and boundary (is binding/class declared inside iteration statement) - let container: Node; - if (symbol.flags & SymbolFlags.Class) { - // get parent of class declaration - container = getClassLikeDeclarationOfSymbol(symbol).parent; - } - else { - // nesting structure: - // (variable declaration or binding element) -> variable declaration list -> container - container = symbol.valueDeclaration; - while (container.kind !== SyntaxKind.VariableDeclarationList) { - container = container.parent; - } - // get the parent of variable declaration list - container = container.parent; - if (container.kind === SyntaxKind.VariableStatement) { - // if parent is variable statement - get its parent - container = container.parent; - } - } - - const inFunction = isInsideFunction(node.parent, container); - + const container = getEnclosingBlockScopeContainer(symbol.valueDeclaration); + const usedInFunction = isInsideFunction(node.parent, container); let current = container; + + let containedInIterationStatement = false; while (current && !nodeStartsNewLexicalEnvironment(current)) { if (isIterationStatement(current, /*lookInLabeledStatements*/ false)) { - if (inFunction) { - getNodeLinks(current).flags |= NodeCheckFlags.LoopWithBlockScopedBindingCapturedInFunction; - } - // mark value declaration so during emit they can have a special handling - getNodeLinks(symbol.valueDeclaration).flags |= NodeCheckFlags.BlockScopedBindingInLoop; + containedInIterationStatement = true; break; } current = current.parent; } + + if (containedInIterationStatement) { + if (usedInFunction) { + // mark iteration statement as containing block-scoped binding captured in some function + getNodeLinks(current).flags |= NodeCheckFlags.LoopWithCapturedBlockScopedBinding; + } + // set 'declared inside loop' bit on the block-scoped binding + getNodeLinks(symbol.valueDeclaration).flags |= NodeCheckFlags.BlockScopedBindingInLoop; + } + + if (usedInFunction) { + getNodeLinks(symbol.valueDeclaration).flags |= NodeCheckFlags.CapturedBlockScopedBinding; + } } function captureLexicalThis(node: Node, container: Node): void { @@ -7239,6 +7290,14 @@ namespace ts { let container = getThisContainer(node, /* includeArrowFunctions */ true); let needToCaptureLexicalThis = false; + if (container.kind === SyntaxKind.Constructor) { + const baseTypeNode = getClassExtendsHeritageClauseElement(container.parent); + if (baseTypeNode && !(getNodeCheckFlags(container) & NodeCheckFlags.HasSeenSuperCall)) { + // In ES6, super inside constructor of class-declaration has to precede "this" accessing + error(node, Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class); + } + } + // Now skip arrow functions to get the "real" owner of 'this'. if (container.kind === SyntaxKind.ArrowFunction) { container = getThisContainer(container, /* includeArrowFunctions */ false); @@ -7379,6 +7438,71 @@ namespace ts { getNodeLinks(node).flags |= nodeCheckFlag; + // Due to how we emit async functions, we need to specialize the emit for an async method that contains a `super` reference. + // This is due to the fact that we emit the body of an async function inside of a generator function. As generator + // functions cannot reference `super`, we emit a helper inside of the method body, but outside of the generator. This helper + // uses an arrow function, which is permitted to reference `super`. + // + // There are two primary ways we can access `super` from within an async method. The first is getting the value of a property + // or indexed access on super, either as part of a right-hand-side expression or call expression. The second is when setting the value + // of a property or indexed access, either as part of an assignment expression or destructuring assignment. + // + // The simplest case is reading a value, in which case we will emit something like the following: + // + // // ts + // ... + // async asyncMethod() { + // let x = await super.asyncMethod(); + // return x; + // } + // ... + // + // // js + // ... + // asyncMethod() { + // const _super = name => super[name]; + // return __awaiter(this, arguments, Promise, function *() { + // let x = yield _super("asyncMethod").call(this); + // return x; + // }); + // } + // ... + // + // The more complex case is when we wish to assign a value, especially as part of a destructuring assignment. As both cases + // are legal in ES6, but also likely less frequent, we emit the same more complex helper for both scenarios: + // + // // ts + // ... + // async asyncMethod(ar: Promise) { + // [super.a, super.b] = await ar; + // } + // ... + // + // // js + // ... + // asyncMethod(ar) { + // const _super = (function (geti, seti) { + // const cache = Object.create(null); + // return name => cache[name] || (cache[name] = { get value() { return geti(name); }, set value(v) { seti(name, v); } }); + // })(name => super[name], (name, value) => super[name] = value); + // return __awaiter(this, arguments, Promise, function *() { + // [_super("a").value, _super("b").value] = yield ar; + // }); + // } + // ... + // + // This helper creates an object with a "value" property that wraps the `super` property or indexed access for both get and set. + // This is required for destructuring assignments, as a call expression cannot be used as the target of a destructuring assignment + // while a property access can. + if (container.kind === SyntaxKind.MethodDeclaration && container.flags & NodeFlags.Async) { + if (isSuperPropertyOrElementAccess(node.parent) && isAssignmentTarget(node.parent)) { + getNodeLinks(container).flags |= NodeCheckFlags.AsyncMethodWithSuperBinding; + } + else { + getNodeLinks(container).flags |= NodeCheckFlags.AsyncMethodWithSuper; + } + } + 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 - @@ -7658,7 +7782,7 @@ namespace ts { // Return true if the given contextual type provides an index signature of the given kind function contextualTypeHasIndexSignature(type: Type, kind: IndexKind): boolean { - return !!(type.flags & TypeFlags.Union ? forEach((type).types, t => getIndexTypeOfStructuredType(t, kind)) : getIndexTypeOfStructuredType(type, kind)); + return !!(type.flags & TypeFlags.Union ? forEach((type).types, t => getIndexInfoOfStructuredType(t, kind)) : getIndexInfoOfStructuredType(type, kind)); } // In an object literal contextually typed by a type T, the contextual type of a property assignment is the type of @@ -8153,9 +8277,9 @@ namespace ts { } } - const stringIndexType = getIndexType(IndexKind.String); - const numberIndexType = getIndexType(IndexKind.Number); - const result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType); + const stringIndexInfo = getIndexInfo(IndexKind.String); + const numberIndexInfo = getIndexInfo(IndexKind.Number); + const result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo); const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshObjectLiteral; result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags) | (patternWithComputedProperties ? TypeFlags.ObjectLiteralPatternWithComputedProperties : 0); if (inDestructuringPattern) { @@ -8163,7 +8287,7 @@ namespace ts { } return result; - function getIndexType(kind: IndexKind) { + function getIndexInfo(kind: IndexKind) { if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { const propTypes: Type[] = []; for (let i = 0; i < propertiesArray.length; i++) { @@ -8179,9 +8303,9 @@ namespace ts { } } } - const result = propTypes.length ? getUnionType(propTypes) : undefinedType; - typeFlags |= result.flags; - return result; + const unionType = propTypes.length ? getUnionType(propTypes) : undefinedType; + typeFlags |= unionType.flags; + return createIndexInfo(unionType, /*isReadonly*/ false); } return undefined; } @@ -8551,7 +8675,7 @@ namespace ts { return links.resolvedJsxType = getTypeOfSymbol(sym); } else if (links.jsxFlags & JsxFlags.IntrinsicIndexedElement) { - return links.resolvedJsxType = getIndexTypeOfSymbol(sym, IndexKind.String); + return links.resolvedJsxType = getIndexInfoOfSymbol(sym, IndexKind.String).type; } else { // Resolution failed, so we don't know @@ -8675,7 +8799,7 @@ namespace ts { */ function checkClassPropertyAccess(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, type: Type, prop: Symbol): boolean { const flags = getDeclarationFlagsFromSymbol(prop); - const declaringClass = getDeclaredTypeOfSymbol(prop.parent); + const declaringClass = getDeclaredTypeOfSymbol(getParentOfSymbol(prop)); if (left.kind === SyntaxKind.SuperKeyword) { const errorNode = node.kind === SyntaxKind.PropertyAccessExpression ? @@ -8918,16 +9042,18 @@ namespace ts { // Try to use a number indexer. if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.NumberLike) || isForInVariableForNumericPropertyNames(node.argumentExpression)) { - const numberIndexType = getIndexTypeOfType(objectType, IndexKind.Number); - if (numberIndexType) { - return numberIndexType; + const numberIndexInfo = getIndexInfoOfType(objectType, IndexKind.Number); + if (numberIndexInfo) { + getNodeLinks(node).resolvedIndexInfo = numberIndexInfo; + return numberIndexInfo.type; } } // Try to use string indexing. - const stringIndexType = getIndexTypeOfType(objectType, IndexKind.String); - if (stringIndexType) { - return stringIndexType; + const stringIndexInfo = getIndexInfoOfType(objectType, IndexKind.String); + if (stringIndexInfo) { + getNodeLinks(node).resolvedIndexInfo = stringIndexInfo; + return stringIndexInfo.type; } // Fall back to any. @@ -9186,7 +9312,7 @@ namespace ts { if (type.flags & TypeFlags.ObjectType) { const resolved = resolveStructuredTypeMembers(type); if (resolved.callSignatures.length === 1 && resolved.constructSignatures.length === 0 && - resolved.properties.length === 0 && !resolved.stringIndexType && !resolved.numberIndexType) { + resolved.properties.length === 0 && !resolved.stringIndexInfo && !resolved.numberIndexInfo) { return resolved.callSignatures[0]; } } @@ -10118,6 +10244,11 @@ namespace ts { const signature = getResolvedSignature(node); if (node.expression.kind === SyntaxKind.SuperKeyword) { + const containgFunction = getContainingFunction(node.expression); + + if (containgFunction && containgFunction.kind === SyntaxKind.Constructor) { + getNodeLinks(containgFunction).flags |= NodeCheckFlags.HasSeenSuperCall; + } return voidType; } if (node.kind === SyntaxKind.NewExpression) { @@ -10144,7 +10275,7 @@ namespace ts { } // In JavaScript files, calls to any identifier 'require' are treated as external module imports - if (isInJavaScriptFile(node) && isRequireCall(node)) { + if (isInJavaScriptFile(node) && isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) { return resolveExternalModuleTypeByLiteral(node.arguments[0]); } @@ -10249,9 +10380,11 @@ namespace ts { function getReturnTypeFromJSDocComment(func: SignatureDeclaration | FunctionDeclaration): Type { const returnTag = getJSDocReturnTag(func); - if (returnTag) { + if (returnTag && returnTag.typeExpression) { return getTypeFromTypeNode(returnTag.typeExpression.type); } + + return undefined; } function createPromiseType(promisedType: Type): Type { @@ -10326,7 +10459,8 @@ namespace ts { } else { error(func, Diagnostics.No_best_common_type_exists_among_return_expressions); - return unknownType; + // Defer to unioning the return types so we get a) downstream errors earlier and b) better Salsa experience + return getUnionType(types); } } @@ -10404,7 +10538,8 @@ namespace ts { /* *TypeScript Specification 1.0 (6.3) - July 2014 - * An explicitly typed function whose return type isn't the Void or the Any type + * An explicitly typed function whose return type isn't the Void type, + * the Any type, or a union type containing the Void or Any type as a constituent * must have at least one return statement somewhere in its body. * An exception to this rule is if the function implementation consists of a single 'throw' statement. * @param returnType - return type of the function, can be undefined if return type is not explicitly specified @@ -10415,7 +10550,7 @@ namespace ts { } // Functions with with an explicitly specified 'void' or 'any' return type don't need any return expressions. - if (returnType === voidType || isTypeAny(returnType)) { + if (returnType === voidType || isTypeAny(returnType) || (returnType && (returnType.flags & TypeFlags.Union) && someConstituentTypeHasKind(returnType, TypeFlags.Any | TypeFlags.Void))) { return; } @@ -10559,81 +10694,78 @@ namespace ts { return true; } - function checkReferenceExpression(n: Node, invalidReferenceMessage: DiagnosticMessage, constantVariableMessage: DiagnosticMessage): boolean { - function findSymbol(n: Node): Symbol { - const symbol = getNodeLinks(n).resolvedSymbol; - // Because we got the symbol from the resolvedSymbol property, it might be of kind - // SymbolFlags.ExportValue. In this case it is necessary to get the actual export - // symbol, which will have the correct flags set on it. - return symbol && getExportSymbolOfValueSymbolIfExported(symbol); - } - - function isReferenceOrErrorExpression(n: Node): boolean { - // TypeScript 1.0 spec (April 2014): - // Expressions are classified as values or references. - // References are the subset of expressions that are permitted as the target of an assignment. - // Specifically, references are combinations of identifiers(section 4.3), parentheses(section 4.7), - // and property accesses(section 4.10). - // All other expression constructs described in this chapter are classified as values. - switch (n.kind) { - case SyntaxKind.Identifier: { - const symbol = findSymbol(n); - // TypeScript 1.0 spec (April 2014): 4.3 - // An identifier expression that references a variable or parameter is classified as a reference. - // An identifier expression that references any other kind of entity is classified as a value(and therefore cannot be the target of an assignment). - return !symbol || symbol === unknownSymbol || symbol === argumentsSymbol || (symbol.flags & SymbolFlags.Variable) !== 0; - } - case SyntaxKind.PropertyAccessExpression: { - const symbol = findSymbol(n); - // TypeScript 1.0 spec (April 2014): 4.10 - // A property access expression is always classified as a reference. - // NOTE (not in spec): assignment to enum members should not be allowed - return !symbol || symbol === unknownSymbol || (symbol.flags & ~SymbolFlags.EnumMember) !== 0; - } - case SyntaxKind.ElementAccessExpression: - // old compiler doesn't check indexed access - return true; - case SyntaxKind.ParenthesizedExpression: - return isReferenceOrErrorExpression((n).expression); - default: - return false; + function isReadonlySymbol(symbol: Symbol): boolean { + // The following symbols are considered read-only: + // Properties with a 'readonly' modifier + // Variables declared with 'const' + // Get accessors without matching set accessors + // Enum members + return symbol.flags & SymbolFlags.Property && (getDeclarationFlagsFromSymbol(symbol) & NodeFlags.Readonly) !== 0 || + symbol.flags & SymbolFlags.Variable && (getDeclarationFlagsFromSymbol(symbol) & NodeFlags.Const) !== 0 || + symbol.flags & SymbolFlags.Accessor && !(symbol.flags & SymbolFlags.SetAccessor) || + (symbol.flags & SymbolFlags.EnumMember) !== 0; + } + + function isReferenceToReadonlyEntity(expr: Expression, symbol: Symbol): boolean { + if (isReadonlySymbol(symbol)) { + // Allow assignments to readonly properties within constructors of the same class declaration. + if (symbol.flags & SymbolFlags.Property && + (expr.kind === SyntaxKind.PropertyAccessExpression || expr.kind === SyntaxKind.ElementAccessExpression) && + (expr as PropertyAccessExpression | ElementAccessExpression).expression.kind === SyntaxKind.ThisKeyword) { + const func = getContainingFunction(expr); + return !(func && func.kind === SyntaxKind.Constructor && func.parent === symbol.valueDeclaration.parent); } + return true; } + return false; + } - function isConstVariableReference(n: Node): boolean { - switch (n.kind) { - case SyntaxKind.Identifier: - case SyntaxKind.PropertyAccessExpression: { - const symbol = findSymbol(n); - return symbol && (symbol.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & NodeFlags.Const) !== 0; - } - case SyntaxKind.ElementAccessExpression: { - const index = (n).argumentExpression; - const symbol = findSymbol((n).expression); - if (symbol && index && index.kind === SyntaxKind.StringLiteral) { - const name = (index).text; - const prop = getPropertyOfType(getTypeOfSymbol(symbol), name); - return prop && (prop.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(prop) & NodeFlags.Const) !== 0; - } - return false; + function isReferenceThroughNamespaceImport(expr: Expression): boolean { + if (expr.kind === SyntaxKind.PropertyAccessExpression || expr.kind === SyntaxKind.ElementAccessExpression) { + const node = skipParenthesizedNodes((expr as PropertyAccessExpression | ElementAccessExpression).expression); + if (node.kind === SyntaxKind.Identifier) { + const symbol = getNodeLinks(node).resolvedSymbol; + if (symbol.flags & SymbolFlags.Alias) { + const declaration = getDeclarationOfAliasSymbol(symbol); + return declaration && declaration.kind === SyntaxKind.NamespaceImport; } - case SyntaxKind.ParenthesizedExpression: - return isConstVariableReference((n).expression); - default: - return false; } } + return false; + } - if (!isReferenceOrErrorExpression(n)) { - error(n, invalidReferenceMessage); + function checkReferenceExpression(expr: Expression, invalidReferenceMessage: DiagnosticMessage, constantVariableMessage: DiagnosticMessage): boolean { + // References are combinations of identifiers, parentheses, and property accesses. + const node = skipParenthesizedNodes(expr); + if (node.kind !== SyntaxKind.Identifier && node.kind !== SyntaxKind.PropertyAccessExpression && node.kind !== SyntaxKind.ElementAccessExpression) { + error(expr, invalidReferenceMessage); return false; } - - if (isConstVariableReference(n)) { - error(n, constantVariableMessage); - return false; + // Because we get the symbol from the resolvedSymbol property, it might be of kind + // SymbolFlags.ExportValue. In this case it is necessary to get the actual export + // symbol, which will have the correct flags set on it. + const links = getNodeLinks(node); + const symbol = getExportSymbolOfValueSymbolIfExported(links.resolvedSymbol); + if (symbol) { + if (symbol !== unknownSymbol && symbol !== argumentsSymbol) { + // Only variables (and not functions, classes, namespaces, enum objects, or enum members) + // are considered references when referenced using a simple identifier. + if (node.kind === SyntaxKind.Identifier && !(symbol.flags & SymbolFlags.Variable)) { + error(expr, invalidReferenceMessage); + return false; + } + if (isReferenceToReadonlyEntity(node, symbol) || isReferenceThroughNamespaceImport(node)) { + error(expr, constantVariableMessage); + return false; + } + } + } + else if (node.kind === SyntaxKind.ElementAccessExpression) { + if (links.resolvedIndexInfo && links.resolvedIndexInfo.isReadonly) { + error(expr, constantVariableMessage); + return false; + } } - return true; } @@ -10655,7 +10787,7 @@ namespace ts { function checkAwaitExpression(node: AwaitExpression): Type { // Grammar checking if (produceDiagnostics) { - if (!(node.parserContextFlags & ParserContextFlags.Await)) { + if (!(node.flags & NodeFlags.AwaitContext)) { grammarErrorOnFirstToken(node, Diagnostics.await_expression_is_only_allowed_within_an_async_function); } @@ -10687,7 +10819,7 @@ namespace ts { // run check only if former checks succeeded to avoid reporting cascading errors checkReferenceExpression(node.operand, Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer, - Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant); + Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant_or_a_read_only_property); } return numberType; } @@ -10701,7 +10833,7 @@ namespace ts { // run check only if former checks succeeded to avoid reporting cascading errors checkReferenceExpression(node.operand, Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer, - Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant); + Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant_or_a_read_only_property); } return numberType; } @@ -10892,7 +11024,7 @@ namespace ts { function checkReferenceAssignment(target: Expression, sourceType: Type, contextualMapper?: TypeMapper): Type { const targetType = checkExpression(target, contextualMapper); - if (checkReferenceExpression(target, Diagnostics.Invalid_left_hand_side_of_assignment_expression, Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant)) { + if (checkReferenceExpression(target, Diagnostics.Invalid_left_hand_side_of_assignment_expression, Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant_or_a_read_only_property)) { checkTypeAssignableTo(sourceType, targetType, target, /*headMessage*/ undefined); } return sourceType; @@ -11074,7 +11206,9 @@ namespace ts { // requires VarExpr to be classified as a reference // A compound assignment furthermore requires VarExpr to be classified as a reference (section 4.1) // and the type of the non - compound operation to be assignable to the type of VarExpr. - const ok = checkReferenceExpression(left, Diagnostics.Invalid_left_hand_side_of_assignment_expression, Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); + const ok = checkReferenceExpression(left, + Diagnostics.Invalid_left_hand_side_of_assignment_expression, + Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant_or_a_read_only_property); // Use default messages if (ok) { // to avoid cascading errors check assignability only if 'isReference' check succeeded and no errors were reported @@ -11109,7 +11243,7 @@ namespace ts { function checkYieldExpression(node: YieldExpression): Type { // Grammar checking if (produceDiagnostics) { - if (!(node.parserContextFlags & ParserContextFlags.Yield) || isYieldExpressionInClass(node)) { + if (!(node.flags & NodeFlags.YieldContext) || isYieldExpressionInClass(node)) { grammarErrorOnFirstToken(node, Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_body); } @@ -11560,10 +11694,11 @@ namespace ts { checkTypeAssignableTo(iterableIteratorInstantiation, returnType, node.type); } } + else if (isAsyncFunctionLike(node)) { + checkAsyncFunctionReturnType(node); + } } } - - checkSpecializedSignatureDeclaration(node); } function checkTypeForDuplicateIndexSignatures(node: Node) { @@ -11731,10 +11866,6 @@ namespace ts { if (!superCallStatement) { error(node, Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties); } - else { - // In such a required super call, it is a compile-time error for argument expressions to reference this. - markThisReferencesAsErrors(superCallStatement.expression); - } } } else if (baseConstructorType !== nullType) { @@ -11878,48 +12009,6 @@ namespace ts { return (node.flags & NodeFlags.Private) && isInAmbientContext(node); } - function checkSpecializedSignatureDeclaration(signatureDeclarationNode: SignatureDeclaration): void { - if (!produceDiagnostics) { - return; - } - const signature = getSignatureFromDeclaration(signatureDeclarationNode); - if (!signature.hasStringLiterals) { - return; - } - - // TypeScript 1.0 spec (April 2014): 3.7.2.2 - // Specialized signatures are not permitted in conjunction with a function body - if (nodeIsPresent((signatureDeclarationNode).body)) { - error(signatureDeclarationNode, Diagnostics.A_signature_with_an_implementation_cannot_use_a_string_literal_type); - return; - } - - // TypeScript 1.0 spec (April 2014): 3.7.2.4 - // Every specialized call or construct signature in an object type must be assignable - // to at least one non-specialized call or construct signature in the same object type - let signaturesToCheck: Signature[]; - // Unnamed (call\construct) signatures in interfaces are inherited and not shadowed so examining just node symbol won't give complete answer. - // Use declaring type to obtain full list of signatures. - if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === SyntaxKind.InterfaceDeclaration) { - Debug.assert(signatureDeclarationNode.kind === SyntaxKind.CallSignature || signatureDeclarationNode.kind === SyntaxKind.ConstructSignature); - const signatureKind = signatureDeclarationNode.kind === SyntaxKind.CallSignature ? SignatureKind.Call : SignatureKind.Construct; - const containingSymbol = getSymbolOfNode(signatureDeclarationNode.parent); - const containingType = getDeclaredTypeOfSymbol(containingSymbol); - signaturesToCheck = getSignaturesOfType(containingType, signatureKind); - } - else { - signaturesToCheck = getSignaturesOfSymbol(getSymbolOfNode(signatureDeclarationNode)); - } - - for (const otherSignature of signaturesToCheck) { - if (!otherSignature.hasStringLiterals && isSignatureAssignableTo(signature, otherSignature, /*ignoreReturnTypes*/ false)) { - return; - } - } - - error(signatureDeclarationNode, Diagnostics.Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature); - } - function getEffectiveDeclarationFlags(n: Node, flagsToCheck: NodeFlags): NodeFlags { let flags = getCombinedNodeFlags(n); @@ -12141,28 +12230,10 @@ namespace ts { if (bodyDeclaration) { const signatures = getSignaturesOfSymbol(symbol); const bodySignature = getSignatureFromDeclaration(bodyDeclaration); - // If the implementation signature has string literals, we will have reported an error in - // checkSpecializedSignatureDeclaration - if (!bodySignature.hasStringLiterals) { - // TypeScript 1.0 spec (April 2014): 6.1 - // If a function declaration includes overloads, the overloads determine the call - // signatures of the type given to the function object - // and the function implementation signature must be assignable to that type - // - // TypeScript 1.0 spec (April 2014): 3.8.4 - // Note that specialized call and construct signatures (section 3.7.2.4) are not significant when determining assignment compatibility - // Consider checking against specialized signatures too. Not doing so creates a type hole: - // - // function g(x: "hi", y: boolean); - // function g(x: string, y: {}); - // function g(x: string, y: string) { } - // - // The implementation is completely unrelated to the specialized signature, yet we do not check this. - for (const signature of signatures) { - if (!signature.hasStringLiterals && !isImplementationCompatibleWithOverload(bodySignature, signature)) { - error(signature.declaration, Diagnostics.Overload_signature_is_not_compatible_with_function_implementation); - break; - } + for (const signature of signatures) { + if (!isImplementationCompatibleWithOverload(bodySignature, signature)) { + error(signature.declaration, Diagnostics.Overload_signature_is_not_compatible_with_function_implementation); + break; } } } @@ -12429,6 +12500,36 @@ namespace ts { } } + /** + * Checks that the return type provided is an instantiation of the global Promise type + * and returns the awaited type of the return type. + * + * @param returnType The return type of a FunctionLikeDeclaration + * @param location The node on which to report the error. + */ + function checkCorrectPromiseType(returnType: Type, location: Node) { + if (returnType === unknownType) { + // The return type already had some other error, so we ignore and return + // the unknown type. + return unknownType; + } + + const globalPromiseType = getGlobalPromiseType(); + if (globalPromiseType === emptyGenericType + || globalPromiseType === getTargetType(returnType)) { + // Either we couldn't resolve the global promise type, which would have already + // reported an error, or we could resolve it and the return type is a valid type + // reference to the global type. In either case, we return the awaited type for + // the return type. + return checkAwaitedType(returnType, location, Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type); + } + + // The promise type was not a valid type reference to the global promise type, so we + // report an error and return the unknown type. + error(location, Diagnostics.The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T_type); + return unknownType; + } + /** * Checks the return type of an async function to ensure it is a compatible * Promise implementation. @@ -12443,6 +12544,11 @@ namespace ts { * callable `then` signature. */ function checkAsyncFunctionReturnType(node: FunctionLikeDeclaration): Type { + if (languageVersion >= ScriptTarget.ES6) { + const returnType = getTypeFromTypeNode(node.type); + return checkCorrectPromiseType(returnType, node.type); + } + const globalPromiseConstructorLikeType = getGlobalPromiseConstructorLikeType(); if (globalPromiseConstructorLikeType === emptyObjectType) { // If we couldn't resolve the global PromiseConstructorLike type we cannot verify @@ -12658,6 +12764,7 @@ namespace ts { checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } } @@ -12842,6 +12949,25 @@ namespace ts { } } + function checkCollisionWithGlobalPromiseInGeneratedCode(node: Node, name: Identifier): void { + if (!needCollisionCheckForIdentifier(node, name, "Promise")) { + return; + } + + // Uninstantiated modules shouldnt do this check + if (node.kind === SyntaxKind.ModuleDeclaration && getModuleInstanceState(node) !== ModuleInstanceState.Instantiated) { + return; + } + + // In case of variable declaration, node.parent is variable statement so look at the variable statement's parent + const parent = getDeclarationContainer(node); + if (parent.kind === SyntaxKind.SourceFile && isExternalOrCommonJsModule(parent) && parent.flags & NodeFlags.HasAsyncFunctions) { + // If the declaration happens to be in external module, report error that Promise is a reserved identifier. + error(name, Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_a_module_containing_async_functions, + declarationNameToString(name), declarationNameToString(name)); + } + } + function checkVarDeclaredNamesNotShadowed(node: VariableDeclaration | BindingElement) { // - ScriptBody : StatementList // It is a Syntax Error if any element of the LexicallyDeclaredNames of StatementList @@ -13020,6 +13146,7 @@ namespace ts { checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } } @@ -13138,7 +13265,7 @@ namespace ts { else { const leftType = checkExpression(varExpr); checkReferenceExpression(varExpr, /*invalidReferenceMessage*/ Diagnostics.Invalid_left_hand_side_in_for_of_statement, - /*constantVariableMessage*/ Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_be_a_previously_defined_constant); + /*constantVariableMessage*/ Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_be_a_constant_or_a_read_only_property); // iteratedType will be undefined if the rightType was missing properties/signatures // required to get its iteratedType (like [Symbol.iterator] or next). This may be @@ -13185,7 +13312,8 @@ namespace ts { } else { // run check only former check succeeded to avoid cascading errors - checkReferenceExpression(varExpr, Diagnostics.Invalid_left_hand_side_in_for_in_statement, Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_previously_defined_constant); + checkReferenceExpression(varExpr, Diagnostics.Invalid_left_hand_side_in_for_in_statement, + Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_constant_or_a_read_only_property); } } @@ -13515,7 +13643,7 @@ namespace ts { function checkWithStatement(node: WithStatement) { // Grammar checking for withStatement if (!checkGrammarStatementInAmbientContext(node)) { - if (node.parserContextFlags & ParserContextFlags.Await) { + if (node.flags & NodeFlags.AwaitContext) { grammarErrorOnFirstToken(node, Diagnostics.with_statements_are_not_allowed_in_an_async_function_block); } } @@ -13785,6 +13913,7 @@ namespace ts { checkTypeNameIsReserved(node.name, Diagnostics.Class_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } checkTypeParameters(node.typeParameters); checkExportsOnMergedDeclarations(node); @@ -14291,6 +14420,7 @@ namespace ts { checkTypeNameIsReserved(node.name, Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); computeEnumMemberValues(node); @@ -14395,6 +14525,7 @@ namespace ts { checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); const symbol = getSymbolOfNode(node); @@ -14425,10 +14556,10 @@ namespace ts { if (isAmbientExternalModule) { if (isExternalModuleAugmentation(node)) { // body of the augmentation should be checked for consistency only if augmentation was applied to its target (either global scope or module) - // otherwise we'll be swamped in cascading errors. + // otherwise we'll be swamped in cascading errors. // We can detect if augmentation was applied using following rules: // - augmentation for a global scope is always applied - // - augmentation for some external module is applied if symbol for augmentation is merged (it was combined with target module). + // - augmentation for some external module is applied if symbol for augmentation is merged (it was combined with target module). const checkBody = isGlobalAugmentation || (getSymbolOfNode(node).flags & SymbolFlags.Merged); if (checkBody) { // body of ambient external module is always a module block @@ -14587,6 +14718,7 @@ namespace ts { function checkImportBinding(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | ImportSpecifier) { checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); checkAliasSymbol(node); } @@ -14676,7 +14808,7 @@ namespace ts { else { // export * from "foo" const moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier); - if (moduleSymbol && moduleSymbol.exports["export="]) { + if (moduleSymbol && hasExportAssignmentSymbol(moduleSymbol)) { error(node.moduleSpecifier, Diagnostics.Module_0_uses_export_and_cannot_be_used_with_export_Asterisk, symbolToString(moduleSymbol)); } } @@ -15199,6 +15331,20 @@ namespace ts { return getSymbolOfNode(entityName.parent); } + if (isInJavaScriptFile(entityName) && entityName.parent.kind === SyntaxKind.PropertyAccessExpression) { + const specialPropertyAssignmentKind = getSpecialPropertyAssignmentKind(entityName.parent.parent); + switch (specialPropertyAssignmentKind) { + case SpecialPropertyAssignmentKind.ExportsProperty: + case SpecialPropertyAssignmentKind.PrototypeProperty: + return getSymbolOfNode(entityName.parent); + case SpecialPropertyAssignmentKind.ThisProperty: + case SpecialPropertyAssignmentKind.ModuleExports: + return getSymbolOfNode(entityName.parent.parent); + default: + // Fall through if it is not a special property assignment + } + } + if (entityName.parent.kind === SyntaxKind.ExportAssignment) { return resolveEntityName(entityName, /*all meanings*/ SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias); @@ -15500,7 +15646,7 @@ namespace ts { return true; } - const hasExportAssignment = getExportAssignmentSymbol(moduleSymbol) !== undefined; + const hasExportAssignment = hasExportAssignmentSymbol(moduleSymbol); // if module has export assignment then 'resolveExternalModuleSymbol' will return resolved symbol for export assignment // otherwise it will return moduleSymbol itself moduleSymbol = resolveExternalModuleSymbol(moduleSymbol); @@ -15558,42 +15704,61 @@ namespace ts { return symbol && symbol.flags & SymbolFlags.Alias ? getDeclarationOfAliasSymbol(symbol) : undefined; } - function isStatementWithLocals(node: Node) { - switch (node.kind) { - case SyntaxKind.Block: - case SyntaxKind.CaseBlock: - case SyntaxKind.ForStatement: - case SyntaxKind.ForInStatement: - case SyntaxKind.ForOfStatement: - return true; - } - return false; - } - - function isNestedRedeclarationSymbol(symbol: Symbol): boolean { + function isSymbolOfDeclarationWithCollidingName(symbol: Symbol): boolean { if (symbol.flags & SymbolFlags.BlockScoped) { const links = getSymbolLinks(symbol); - if (links.isNestedRedeclaration === undefined) { + if (links.isDeclaratonWithCollidingName === undefined) { const container = getEnclosingBlockScopeContainer(symbol.valueDeclaration); - links.isNestedRedeclaration = isStatementWithLocals(container) && - !!resolveName(container.parent, symbol.name, SymbolFlags.Value, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined); + if (isStatementWithLocals(container)) { + const nodeLinks = getNodeLinks(symbol.valueDeclaration); + if (!!resolveName(container.parent, symbol.name, SymbolFlags.Value, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined)) { + // redeclaration - always should be renamed + links.isDeclaratonWithCollidingName = true; + } + else if (nodeLinks.flags & NodeCheckFlags.CapturedBlockScopedBinding) { + // binding is captured in the function + // should be renamed if: + // - binding is not top level - top level bindings never collide with anything + // AND + // - binding is not declared in loop, should be renamed to avoid name reuse across siblings + // let a, b + // { let x = 1; a = () => x; } + // { let x = 100; b = () => x; } + // console.log(a()); // should print '1' + // console.log(b()); // should print '100' + // OR + // - binding is declared inside loop but not in inside initializer of iteration statement or directly inside loop body + // * variables from initializer are passed to rewritted loop body as parameters so they are not captured directly + // * variables that are declared immediately in loop body will become top level variable after loop is rewritten and thus + // they will not collide with anything + const isDeclaredInLoop = nodeLinks.flags & NodeCheckFlags.BlockScopedBindingInLoop; + const inLoopInitializer = isIterationStatement(container, /*lookInLabeledStatements*/ false); + const inLoopBodyBlock = container.kind === SyntaxKind.Block && isIterationStatement(container.parent, /*lookInLabeledStatements*/ false); + + links.isDeclaratonWithCollidingName = !isBlockScopedContainerTopLevel(container) && (!isDeclaredInLoop || (!inLoopInitializer && !inLoopBodyBlock)); + } + else { + links.isDeclaratonWithCollidingName = false; + } + } } - return links.isNestedRedeclaration; + return links.isDeclaratonWithCollidingName; } return false; } // When resolved as an expression identifier, if the given node references a nested block scoped entity with - // a name that hides an existing name, return the declaration of that entity. Otherwise, return undefined. - function getReferencedNestedRedeclaration(node: Identifier): Declaration { + // a name that either hides an existing name or might hide it when compiled downlevel, + // return the declaration of that entity. Otherwise, return undefined. + function getReferencedDeclarationWithCollidingName(node: Identifier): Declaration { const symbol = getReferencedValueSymbol(node); - return symbol && isNestedRedeclarationSymbol(symbol) ? symbol.valueDeclaration : undefined; + return symbol && isSymbolOfDeclarationWithCollidingName(symbol) ? symbol.valueDeclaration : undefined; } - // Return true if the given node is a declaration of a nested block scoped entity with a name that hides an - // existing name. - function isNestedRedeclaration(node: Declaration): boolean { - return isNestedRedeclarationSymbol(getSymbolOfNode(node)); + // Return true if the given node is a declaration of a nested block scoped entity with a name that either hides an + // existing name or might hide a name when compiled downlevel + function isDeclarationWithCollidingName(node: Declaration): boolean { + return isSymbolOfDeclarationWithCollidingName(getSymbolOfNode(node)); } function isValueAliasDeclaration(node: Node): boolean { @@ -15794,8 +15959,8 @@ namespace ts { return { getReferencedExportContainer, getReferencedImportDeclaration, - getReferencedNestedRedeclaration, - isNestedRedeclaration, + getReferencedDeclarationWithCollidingName, + isDeclarationWithCollidingName, isValueAliasDeclaration, hasGlobalName, isReferencedAliasDeclaration, @@ -15840,7 +16005,7 @@ namespace ts { if (!isExternalOrCommonJsModule(file)) { mergeSymbolTable(globals, file.locals); } - if (file.moduleAugmentations) { + if (file.moduleAugmentations.length) { (augmentations || (augmentations = [])).push(file.moduleAugmentations); } }); @@ -15908,6 +16073,10 @@ namespace ts { } anyArrayType = createArrayType(anyType); + + const symbol = getGlobalSymbol("ReadonlyArray", SymbolFlags.Type, /*diagnostic*/ undefined); + globalReadonlyArrayType = symbol && getTypeOfGlobalSymbol(symbol, /*arity*/ 1); + anyReadonlyArrayType = globalReadonlyArrayType ? createTypeFromGenericGlobalType(globalReadonlyArrayType, [anyType]) : anyArrayType; } function createInstantiatedPromiseLikeType(): ObjectType { @@ -15999,9 +16168,17 @@ namespace ts { return; } - let lastStatic: Node, lastPrivate: Node, lastProtected: Node, lastDeclare: Node, lastAsync: Node; + let lastStatic: Node, lastPrivate: Node, lastProtected: Node, lastDeclare: Node, lastAsync: Node, lastReadonly: Node; let flags = 0; for (const modifier of node.modifiers) { + if (modifier.kind !== SyntaxKind.ReadonlyKeyword) { + if (node.kind === SyntaxKind.PropertySignature || node.kind === SyntaxKind.MethodSignature) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_type_member, tokenToString(modifier.kind)); + } + if (node.kind === SyntaxKind.IndexSignature) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_an_index_signature, tokenToString(modifier.kind)); + } + } switch (modifier.kind) { case SyntaxKind.ConstKeyword: if (node.kind !== SyntaxKind.EnumDeclaration && node.parent.kind === SyntaxKind.ClassDeclaration) { @@ -16030,6 +16207,9 @@ namespace ts { else if (flags & NodeFlags.Static) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, text, "static"); } + else if (flags & NodeFlags.Readonly) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, text, "readonly"); + } else if (flags & NodeFlags.Async) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, text, "async"); } @@ -16051,6 +16231,9 @@ namespace ts { if (flags & NodeFlags.Static) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "static"); } + else if (flags & NodeFlags.Readonly) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "static", "readonly"); + } else if (flags & NodeFlags.Async) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "static", "async"); } @@ -16067,6 +16250,17 @@ namespace ts { lastStatic = modifier; break; + case SyntaxKind.ReadonlyKeyword: + if (flags & NodeFlags.Readonly) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "readonly"); + } + else if (node.kind !== SyntaxKind.PropertyDeclaration && node.kind !== SyntaxKind.PropertySignature && node.kind !== SyntaxKind.IndexSignature) { + return grammarErrorOnNode(modifier, Diagnostics.readonly_modifier_can_only_appear_on_a_property_declaration_or_index_signature); + } + flags |= NodeFlags.Readonly; + lastReadonly = modifier; + break; + case SyntaxKind.ExportKeyword: if (flags & NodeFlags.Export) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "export"); @@ -16163,6 +16357,9 @@ namespace ts { else if (flags & NodeFlags.Async) { return grammarErrorOnNode(lastAsync, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "async"); } + else if (flags & NodeFlags.Readonly) { + return grammarErrorOnNode(lastReadonly, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "readonly"); + } return; } else if ((node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration) && flags & NodeFlags.Ambient) { @@ -16308,15 +16505,9 @@ namespace ts { } } - function checkGrammarForIndexSignatureModifier(node: SignatureDeclaration): void { - if (node.flags & NodeFlags.Modifier) { - grammarErrorOnFirstToken(node, Diagnostics.Modifiers_not_permitted_on_index_signature_members); - } - } - function checkGrammarIndexSignature(node: SignatureDeclaration) { // Prevent cascading error by short-circuit - return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarIndexSignatureParameters(node) || checkGrammarForIndexSignatureModifier(node); + return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarIndexSignatureParameters(node); } function checkGrammarForAtLeastOneTypeArgument(node: Node, typeArguments: NodeArray): boolean { @@ -16500,7 +16691,7 @@ namespace ts { // Grammar checking for computedPropertName and shorthandPropertyAssignment checkGrammarForInvalidQuestionMark(prop, (prop).questionToken, Diagnostics.An_object_member_cannot_be_declared_optional); if (name.kind === SyntaxKind.NumericLiteral) { - checkGrammarNumericLiteral(name); + checkGrammarNumericLiteral(name); } currentKind = Property; } @@ -17001,9 +17192,9 @@ namespace ts { } } - function checkGrammarNumericLiteral(node: Identifier): boolean { + function checkGrammarNumericLiteral(node: LiteralExpression): boolean { // Grammar checking - if (node.flags & NodeFlags.OctalLiteral && languageVersion >= ScriptTarget.ES5) { + if (node.isOctalLiteral && languageVersion >= ScriptTarget.ES5) { return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher); } } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 733e3158593df..d5bf95a64058a 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -255,7 +255,7 @@ namespace ts { name: "moduleResolution", type: { "node": ModuleResolutionKind.NodeJs, - "classic": ModuleResolutionKind.Classic + "classic": ModuleResolutionKind.Classic, }, description: Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6, error: Diagnostics.Argument_for_moduleResolution_option_must_be_node_or_classic, @@ -286,14 +286,40 @@ namespace ts { description: Diagnostics.Disallow_inconsistently_cased_references_to_the_same_file }, { - name: "allowSyntheticDefaultImports", + name: "baseUrl", + type: "string", + isFilePath: true, + description: Diagnostics.Base_directory_to_resolve_non_absolute_module_names + }, + { + // this option can only be specified in tsconfig.json + // use type = object to copy the value as-is + name: "paths", + type: "object", + isTSConfigOnly: true + }, + { + // this option can only be specified in tsconfig.json + // use type = object to copy the value as-is + name: "rootDirs", + type: "object", + isTSConfigOnly: true, + isFilePath: true + }, + { + name: "traceModuleResolution", type: "boolean", - description: Diagnostics.Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking + description: Diagnostics.Enable_tracing_of_the_module_resolution_process }, { name: "allowJs", type: "boolean", description: Diagnostics.Allow_javascript_files_to_be_compiled + }, + { + name: "allowSyntheticDefaultImports", + type: "boolean", + description: Diagnostics.Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking } ]; @@ -355,34 +381,39 @@ namespace ts { if (hasProperty(optionNameMap, s)) { const opt = optionNameMap[s]; - // Check to see if no argument was provided (e.g. "--locale" is the last command-line argument). - if (!args[i] && opt.type !== "boolean") { - errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_expects_an_argument, opt.name)); + if (opt.isTSConfigOnly) { + errors.push(createCompilerDiagnostic(Diagnostics.Option_0_can_only_be_specified_in_tsconfig_json_file, opt.name)); } + else { + // Check to see if no argument was provided (e.g. "--locale" is the last command-line argument). + if (!args[i] && opt.type !== "boolean") { + errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_expects_an_argument, opt.name)); + } - switch (opt.type) { - case "number": - options[opt.name] = parseInt(args[i]); - i++; - break; - case "boolean": - options[opt.name] = true; - break; - case "string": - options[opt.name] = args[i] || ""; - i++; - break; - // If not a primitive, the possible types are specified in what is effectively a map of options. - default: - let map = >opt.type; - let key = (args[i] || "").toLowerCase(); - i++; - if (hasProperty(map, key)) { - options[opt.name] = map[key]; - } - else { - errors.push(createCompilerDiagnostic((opt).error)); - } + switch (opt.type) { + case "number": + options[opt.name] = parseInt(args[i]); + i++; + break; + case "boolean": + options[opt.name] = true; + break; + case "string": + options[opt.name] = args[i] || ""; + i++; + break; + // If not a primitive, the possible types are specified in what is effectively a map of options. + default: + let map = >opt.type; + let key = (args[i] || "").toLowerCase(); + i++; + if (hasProperty(map, key)) { + options[opt.name] = map[key]; + } + else { + errors.push(createCompilerDiagnostic((opt).error)); + } + } } } else { @@ -485,7 +516,6 @@ namespace ts { return output; } - /** * Parse the contents of a config file (tsconfig.json). * @param json The contents of the config file to parse @@ -497,6 +527,7 @@ namespace ts { const { options: optionsFromJsonConfigFile, errors } = convertCompilerOptionsFromJson(json["compilerOptions"], basePath, configFileName); const options = extend(existingOptions, optionsFromJsonConfigFile); + return { options, fileNames: getFileNames(), @@ -580,7 +611,36 @@ namespace ts { } } if (opt.isFilePath) { - value = normalizePath(combinePaths(basePath, value)); + switch (typeof value) { + case "string": + value = normalizePath(combinePaths(basePath, value)); + break; + case "object": + // "object" options with 'isFilePath' = true expected to be string arrays + let paths: string[] = []; + let invalidOptionType = false; + if (!isArray(value)) { + invalidOptionType = true; + } + else { + for (const element of value) { + if (typeof element === "string") { + paths.push(normalizePath(combinePaths(basePath, element))); + } + else { + invalidOptionType = true; + break; + } + } + } + if (invalidOptionType) { + errors.push(createCompilerDiagnostic(Diagnostics.Option_0_should_have_array_of_strings_as_a_value, opt.name)); + } + else { + value = paths; + } + break; + } if (value === "") { value = "."; } diff --git a/src/compiler/core.ts b/src/compiler/core.ts index cfdcb2b930c63..21536da36ff26 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -74,8 +74,6 @@ namespace ts { GreaterThan = 1 } - export interface StringSet extends Map { } - /** * Iterates through 'array' by index and performs the callback on each element of array until the callback * returns a truthy value, then returns that value. @@ -441,6 +439,17 @@ namespace ts { }; } + /* internal */ + export function formatMessage(dummy: any, message: DiagnosticMessage): string { + let text = getLocaleSpecificMessage(message); + + if (arguments.length > 2) { + text = formatStringFromArgs(text, arguments, 2); + } + + return text; + } + export function createCompilerDiagnostic(message: DiagnosticMessage, ...args: any[]): Diagnostic; export function createCompilerDiagnostic(message: DiagnosticMessage): Diagnostic { let text = getLocaleSpecificMessage(message); diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 9a57b4b1a37c7..ab0b16947fc49 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -637,18 +637,21 @@ namespace ts { } } - function emitClassMemberDeclarationFlags(node: Declaration) { - if (node.flags & NodeFlags.Private) { + function emitClassMemberDeclarationFlags(flags: NodeFlags) { + if (flags & NodeFlags.Private) { write("private "); } - else if (node.flags & NodeFlags.Protected) { + else if (flags & NodeFlags.Protected) { write("protected "); } - if (node.flags & NodeFlags.Static) { + if (flags & NodeFlags.Static) { write("static "); } - if (node.flags & NodeFlags.Abstract) { + if (flags & NodeFlags.Readonly) { + write("readonly "); + } + if (flags & NodeFlags.Abstract) { write("abstract "); } } @@ -1074,7 +1077,7 @@ namespace ts { } emitJsDocComments(node); - emitClassMemberDeclarationFlags(node); + emitClassMemberDeclarationFlags(node.flags); emitVariableDeclaration(node); write(";"); writeLine(); @@ -1227,7 +1230,7 @@ namespace ts { if (node === accessors.firstAccessor) { emitJsDocComments(accessors.getAccessor); emitJsDocComments(accessors.setAccessor); - emitClassMemberDeclarationFlags(node); + emitClassMemberDeclarationFlags(node.flags | (accessors.setAccessor ? 0 : NodeFlags.Readonly)); writeTextOfNode(currentText, node.name); if (!(node.flags & NodeFlags.Private)) { accessorWithTypeAnnotation = node; @@ -1314,7 +1317,7 @@ namespace ts { emitModuleElementDeclarationFlags(node); } else if (node.kind === SyntaxKind.MethodDeclaration) { - emitClassMemberDeclarationFlags(node); + emitClassMemberDeclarationFlags(node.flags); } if (node.kind === SyntaxKind.FunctionDeclaration) { write("function "); @@ -1342,15 +1345,17 @@ namespace ts { const prevEnclosingDeclaration = enclosingDeclaration; enclosingDeclaration = node; - // Construct signature or constructor type write new Signature - if (node.kind === SyntaxKind.ConstructSignature || node.kind === SyntaxKind.ConstructorType) { - write("new "); - } - emitTypeParameters(node.typeParameters); if (node.kind === SyntaxKind.IndexSignature) { + // Index signature can have readonly modifier + emitClassMemberDeclarationFlags(node.flags); write("["); } else { + // Construct signature or constructor type write new Signature + if (node.kind === SyntaxKind.ConstructSignature || node.kind === SyntaxKind.ConstructorType) { + write("new "); + } + emitTypeParameters(node.typeParameters); write("("); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 8fd40f7b42169..c848ebc3a10d6 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -67,6 +67,10 @@ "category": "Error", "code": 1023 }, + "'readonly' modifier can only appear on a property declaration or index signature.": { + "category": "Error", + "code": 1024 + }, "Accessibility modifier already seen.": { "category": "Error", "code": 1028 @@ -195,6 +199,10 @@ "category": "Error", "code": 1063 }, + "The return type of an async function or method must be the global Promise type.": { + "category": "Error", + "code": 1064 + }, "In ambient enum declarations member initializer must be constant expression.": { "category": "Error", "code": 1066 @@ -203,6 +211,14 @@ "category": "Error", "code": 1068 }, + "'{0}' modifier cannot appear on a type member.": { + "category": "Error", + "code": 1070 + }, + "'{0}' modifier cannot appear on an index signature.": { + "category": "Error", + "code": 1071 + }, "A '{0}' modifier cannot be used with an import declaration.": { "category": "Error", "code": 1079 @@ -423,10 +439,6 @@ "category": "Error", "code": 1144 }, - "Modifiers not permitted on index signature members.": { - "category": "Error", - "code": 1145 - }, "Declaration expected.": { "category": "Error", "code": 1146 @@ -794,7 +806,7 @@ "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 @@ -1379,11 +1391,11 @@ "category": "Error", "code": 2448 }, - "The operand of an increment or decrement operator cannot be a constant.": { + "The operand of an increment or decrement operator cannot be a constant or a read-only property.": { "category": "Error", "code": 2449 }, - "Left-hand side of assignment expression cannot be a constant.": { + "Left-hand side of assignment expression cannot be a constant or a read-only property.": { "category": "Error", "code": 2450 }, @@ -1515,11 +1527,11 @@ "category": "Error", "code": 2484 }, - "The left-hand side of a 'for...of' statement cannot be a previously defined constant.": { + "The left-hand side of a 'for...of' statement cannot be a constant or a read-only property.": { "category": "Error", "code": 2485 }, - "The left-hand side of a 'for...in' statement cannot be a previously defined constant.": { + "The left-hand side of a 'for...in' statement cannot be a constant or a read-only property.": { "category": "Error", "code": 2486 }, @@ -1687,6 +1699,10 @@ "category": "Error", "code": 2528 }, + "Duplicate identifier '{0}'. Compiler reserves name '{1}' in top level scope of a module containing async functions.": { + "category": "Error", + "code": 2529 + }, "JSX element attributes type '{0}' may not be a union type.": { "category": "Error", "code": 2600 @@ -1803,6 +1819,10 @@ "category": "Error", "code": 2670 }, + "Cannot augment module '{0}' because it resolves to a non-module entity.": { + "category": "Error", + "code": 2671 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 @@ -2155,11 +2175,22 @@ "category": "Error", "code": 5058 }, - "Invalide value for '--reactNamespace'. '{0}' is not a valid identifier.": { + "Invalid value for '--reactNamespace'. '{0}' is not a valid identifier.": { "category": "Error", "code": 5059 }, - + "Option 'paths' cannot be used without specifying '--baseUrl' option.": { + "category": "Error", + "code": 5060 + }, + "Pattern '{0}' can have at most one '*' character": { + "category": "Error", + "code": 5061 + }, + "Substitution '{0}' in pattern '{1}' in can have at most one '*' character": { + "category": "Error", + "code": 5062 + }, "Concatenate and emit output to single file.": { "category": "Message", "code": 6001 @@ -2296,10 +2327,10 @@ "category": "Error", "code": 6046 }, - "Argument for '--target' option must be 'ES3', 'ES5', or 'ES2015'.": { - "category": "Error", - "code": 6047 - }, + "Argument for '--target' option must be 'ES3', 'ES5', or 'ES2015'.": { + "category": "Error", + "code": 6047 + }, "Locale must be of the form or -. For example '{0}' or '{1}'.": { "category": "Error", "code": 6048 @@ -2360,7 +2391,10 @@ "category": "Error", "code": 6063 }, - + "Option '{0}' can only be specified in 'tsconfig.json' file.": { + "category": "Error", + "code": 6064 + }, "Enables experimental support for ES7 decorators.": { "category": "Message", "code": 6065 @@ -2425,7 +2459,7 @@ "category": "Error", "code": 6082 }, - "Allow javascript files to be compiled.": { + "Base directory to resolve non-absolute module names.": { "category": "Message", "code": 6083 }, @@ -2433,7 +2467,114 @@ "category": "Message", "code": 6084 }, - + "Enable tracing of the module resolution process.": { + "category": "Message", + "code": 6085 + }, + "======== Resolving module '{0}' from '{1}'. ========": { + "category": "Message", + "code": 6086 + }, + "Explicitly specified module resolution kind: '{0}'.": { + "category": "Message", + "code": 6087 + }, + "Module resolution kind is not specified, using '{0}'.": { + "category": "Message", + "code": 6088 + }, + "======== Module name '{0}' was successfully resolved to '{1}'. ========": { + "category": "Message", + "code": 6089 + }, + "======== Module name '{0}' was not resolved. ========": { + "category": "Message", + "code": 6090 + }, + "'paths' option is specified, looking for a pattern to match module name '{0}'.": { + "category": "Message", + "code": 6091 + }, + "Module name '{0}', matched pattern '{1}'.": { + "category": "Message", + "code": 6092 + }, + "Trying substitution '{0}', candidate module location: '{1}'.": { + "category": "Message", + "code": 6093 + }, + "Resolving module name '{0}' relative to base url '{1}' - '{2}'.": { + "category": "Message", + "code": 6094 + }, + "Loading module as file / folder, candidate module location '{0}'.": { + "category": "Message", + "code": 6095 + }, + "File '{0}' does not exist.": { + "category": "Message", + "code": 6096 + }, + "File '{0}' exist - use it as a module resolution result.": { + "category": "Message", + "code": 6097 + }, + "Loading module '{0}' from 'node_modules' folder.": { + "category": "Message", + "code": 6098 + }, + "Found 'package.json' at '{0}'.": { + "category": "Message", + "code": 6099 + }, + "'package.json' does not have 'typings' field.": { + "category": "Message", + "code": 6100 + }, + "'package.json' has 'typings' field '{0}' that references '{1}'.": { + "category": "Message", + "code": 6101 + }, + "Allow javascript files to be compiled.": { + "category": "Message", + "code": 6102 + }, + "Option '{0}' should have array of strings as a value.": { + "category": "Error", + "code": 6103 + }, + "Checking if '{0}' is the longest matching prefix for '{1}' - '{2}'.": { + "category": "Message", + "code": 6104 + }, + "Expected type of 'typings' field in 'package.json' to be 'string', got '{0}'.": { + "category": "Message", + "code": 6105 + }, + "'baseUrl' option is set to '{0}', using this value to resolve non-relative module name '{1}'": { + "category": "Message", + "code": 6106 + }, + "'rootDirs' option is set, using it to resolve relative module name '{0}'": { + "category": "Message", + "code": 6107 + }, + "Longest matching prefix for '{0}' is '{1}'": { + "category": "Message", + "code": 6108 + }, + "Loading '{0}' from the root dir '{1}', candidate location '{2}'": { + "category": "Message", + "code": 6109 + }, + "Trying other entries in 'rootDirs'": { + "category": "Message", + "code": 6110 + }, + "Module resolution using 'rootDirs' has failed": { + "category": "Message", + "code": 6111 + }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", "code": 7005 @@ -2634,5 +2775,9 @@ "JSX element '{0}' has no corresponding closing tag.": { "category": "Error", "code": 17008 + }, + "'super' must be called before accessing 'this' in the constructor of a derived class.": { + "category": "Error", + "code": 17009 } } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 44cb0ea3ccfe1..e86d86603b46a 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -320,11 +320,11 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { const awaiterHelper = ` var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new P(function (resolve, reject) { + return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.call(thisArg, _arguments)).next()); + step((generator = generator.apply(thisArg, _arguments)).next()); }); };`; @@ -477,10 +477,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge // => // var x;... exporter("x", x = 1) let exportFunctionForFile: string; + let contextObjectForFile: string; let generatedNameSet: Map; let nodeToGeneratedName: string[]; let computedPropertyNamesToGeneratedNames: string[]; + let decoratedClassAliases: string[]; let convertedLoopState: ConvertedLoopState; @@ -531,6 +533,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge sourceMap.initialize(jsFilePath, sourceMapFilePath, sourceFiles, isBundledEmit); generatedNameSet = {}; nodeToGeneratedName = []; + decoratedClassAliases = []; isOwnFileEmit = !isBundledEmit; // Emit helpers from all the files @@ -557,8 +560,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge currentText = undefined; currentLineMap = undefined; exportFunctionForFile = undefined; + contextObjectForFile = undefined; generatedNameSet = undefined; nodeToGeneratedName = undefined; + decoratedClassAliases = undefined; computedPropertyNamesToGeneratedNames = undefined; convertedLoopState = undefined; extendsEmitted = false; @@ -585,6 +590,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge currentText = sourceFile.text; currentLineMap = getLineStarts(sourceFile); exportFunctionForFile = undefined; + contextObjectForFile = undefined; isEs6Module = sourceFile.symbol && sourceFile.symbol.exports && !!sourceFile.symbol.exports["___esModule"]; renamedDependencies = sourceFile.renamedDependencies; currentFileIdentifiers = sourceFile.identifiers; @@ -1257,26 +1263,50 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge // Children if (children) { - for (let i = 0; i < children.length; i++) { - // Don't emit empty expressions - if (children[i].kind === SyntaxKind.JsxExpression && !((children[i]).expression)) { - continue; - } + let firstChild: JsxChild; + let multipleEmittableChildren = false; - // Don't emit empty strings - if (children[i].kind === SyntaxKind.JsxText) { - const text = getTextToEmit(children[i]); - if (text !== undefined) { - write(", \""); - write(text); - write("\""); + for (let i = 0, n = children.length; i < n; i++) { + const jsxChild = children[i]; + + if (isJsxChildEmittable(jsxChild)) { + // we need to decide whether to emit in single line or multiple lines as indented list + // store firstChild reference, if we see another emittable child, then emit accordingly + if (!firstChild) { + write(", "); + firstChild = jsxChild; + } + else { + // more than one emittable child, emit indented list + if (!multipleEmittableChildren) { + multipleEmittableChildren = true; + increaseIndent(); + writeLine(); + emit(firstChild); + } + + write(", "); + writeLine(); + emit(jsxChild); } } + } + + if (multipleEmittableChildren) { + decreaseIndent(); + } + else if (firstChild) { + if (firstChild.kind !== SyntaxKind.JsxElement && firstChild.kind !== SyntaxKind.JsxSelfClosingElement) { + emit(firstChild); + } else { - write(", "); - emit(children[i]); + // If the only child is jsx element, put it on a new indented line + increaseIndent(); + writeLine(); + emit(firstChild); + writeLine(); + decreaseIndent(); } - } } @@ -1488,11 +1518,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } function emitExpressionIdentifier(node: Identifier) { - if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.LexicalArguments) { - write("_arguments"); - return; - } - const container = resolver.getReferencedExportContainer(node); if (container) { if (container.kind === SyntaxKind.SourceFile) { @@ -1534,13 +1559,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } } - if (languageVersion !== ScriptTarget.ES6) { - const declaration = resolver.getReferencedNestedRedeclaration(node); + if (languageVersion < ScriptTarget.ES6) { + const declaration = resolver.getReferencedDeclarationWithCollidingName(node); if (declaration) { write(getGeneratedNameForNode(declaration.name)); return; } } + else if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.BodyScopedClassBinding) { + // Due to the emit for class decorators, any reference to the class from inside of the class body + // must instead be rewritten to point to a temporary variable to avoid issues with the double-bind + // behavior of class names in ES6. + const declaration = resolver.getReferencedValueDeclaration(node); + if (declaration) { + const classAlias = decoratedClassAliases[getNodeId(declaration)]; + if (classAlias !== undefined) { + write(classAlias); + return; + } + } + } } if (nodeIsSynthesized(node)) { @@ -1551,7 +1589,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } } - function isNameOfNestedRedeclaration(node: Identifier) { + function isNameOfNestedBlockScopedRedeclarationOrCapturedBinding(node: Identifier) { if (languageVersion < ScriptTarget.ES6) { const parent = node.parent; switch (parent.kind) { @@ -1559,7 +1597,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge case SyntaxKind.ClassDeclaration: case SyntaxKind.EnumDeclaration: case SyntaxKind.VariableDeclaration: - return (parent).name === node && resolver.isNestedRedeclaration(parent); + return (parent).name === node && resolver.isDeclarationWithCollidingName(parent); } } return false; @@ -1581,7 +1619,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge else if (isExpressionIdentifier(node)) { emitExpressionIdentifier(node); } - else if (isNameOfNestedRedeclaration(node)) { + else if (isNameOfNestedBlockScopedRedeclarationOrCapturedBinding(node)) { write(getGeneratedNameForNode(node)); } else if (nodeIsSynthesized(node)) { @@ -1766,7 +1804,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge write("]"); } else { - emitListWithSpread(elements, /*needsUniqueCopy*/ true, /*multiLine*/(node.flags & NodeFlags.MultiLine) !== 0, + emitListWithSpread(elements, /*needsUniqueCopy*/ true, /*multiLine*/ node.multiLine, /*trailingComma*/ elements.hasTrailingComma, /*useConcat*/ true); } } @@ -1789,7 +1827,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge emitLinePreservingList(node, properties, /*allowTrailingComma*/ languageVersion >= ScriptTarget.ES5, /*spacesBetweenBraces*/ true); } else { - const multiLine = (node.flags & NodeFlags.MultiLine) !== 0; + const multiLine = node.multiLine; if (!multiLine) { write(" "); } @@ -1812,7 +1850,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } function emitDownlevelObjectLiteralWithComputedProperties(node: ObjectLiteralExpression, firstComputedPropertyIndex: number) { - const multiLine = (node.flags & NodeFlags.MultiLine) !== 0; + const multiLine = node.multiLine; const properties = node.properties; write("("); @@ -2122,6 +2160,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge return; } + if (languageVersion === ScriptTarget.ES6 && + node.expression.kind === SyntaxKind.SuperKeyword && + isInAsyncMethodWithSuperInES6(node)) { + const name = createSynthesizedNode(SyntaxKind.StringLiteral); + name.text = node.name.text; + emitSuperAccessInAsyncMethod(node.expression, name); + return; + } + emit(node.expression); const indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken); @@ -2207,6 +2254,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge if (tryEmitConstantValue(node)) { return; } + + if (languageVersion === ScriptTarget.ES6 && + node.expression.kind === SyntaxKind.SuperKeyword && + isInAsyncMethodWithSuperInES6(node)) { + emitSuperAccessInAsyncMethod(node.expression, node.argumentExpression); + return; + } + emit(node.expression); write("["); emit(node.argumentExpression); @@ -2282,23 +2337,47 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge write(")"); } + function isInAsyncMethodWithSuperInES6(node: Node) { + if (languageVersion === ScriptTarget.ES6) { + const container = getSuperContainer(node, /*includeFunctions*/ false); + if (container && resolver.getNodeCheckFlags(container) & (NodeCheckFlags.AsyncMethodWithSuper | NodeCheckFlags.AsyncMethodWithSuperBinding)) { + return true; + } + } + + return false; + } + + function emitSuperAccessInAsyncMethod(superNode: Node, argumentExpression: Expression) { + const container = getSuperContainer(superNode, /*includeFunctions*/ false); + const isSuperBinding = resolver.getNodeCheckFlags(container) & NodeCheckFlags.AsyncMethodWithSuperBinding; + write("_super("); + emit(argumentExpression); + write(isSuperBinding ? ").value" : ")"); + } + function emitCallExpression(node: CallExpression) { if (languageVersion < ScriptTarget.ES6 && hasSpreadElement(node.arguments)) { emitCallWithSpread(node); return; } + + const expression = node.expression; let superCall = false; - if (node.expression.kind === SyntaxKind.SuperKeyword) { - emitSuper(node.expression); + let isAsyncMethodWithSuper = false; + if (expression.kind === SyntaxKind.SuperKeyword) { + emitSuper(expression); superCall = true; } else { - emit(node.expression); - superCall = node.expression.kind === SyntaxKind.PropertyAccessExpression && (node.expression).expression.kind === SyntaxKind.SuperKeyword; + superCall = isSuperPropertyOrElementAccess(expression); + isAsyncMethodWithSuper = superCall && isInAsyncMethodWithSuperInES6(node); + emit(expression); } - if (superCall && languageVersion < ScriptTarget.ES6) { + + if (superCall && (languageVersion < ScriptTarget.ES6 || isAsyncMethodWithSuper)) { write(".call("); - emitThis(node.expression); + emitThis(expression); if (node.arguments.length) { write(", "); emitCommaList(node.arguments); @@ -2528,12 +2607,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge return false; } - let current: Node = node; + let current = getRootDeclaration(node).parent; while (current) { if (current.kind === SyntaxKind.SourceFile) { return !isExported || ((getCombinedNodeFlags(node) & NodeFlags.Export) !== 0); } - else if (isFunctionLike(current) || current.kind === SyntaxKind.ModuleBlock) { + else if (isDeclaration(current)) { return false; } else { @@ -2855,7 +2934,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge function shouldConvertLoopBody(node: IterationStatement): boolean { return languageVersion < ScriptTarget.ES6 && - (resolver.getNodeCheckFlags(node) & NodeCheckFlags.LoopWithBlockScopedBindingCapturedInFunction) !== 0; + (resolver.getNodeCheckFlags(node) & NodeCheckFlags.LoopWithCapturedBlockScopedBinding) !== 0; } function emitLoop(node: IterationStatement, loopEmitter: (n: IterationStatement, convertedLoop: ConvertedLoop) => void): void { @@ -3009,7 +3088,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge function collectNames(name: Identifier | BindingPattern): void { if (name.kind === SyntaxKind.Identifier) { - const nameText = isNameOfNestedRedeclaration(name) ? getGeneratedNameForNode(name) : (name).text; + const nameText = isNameOfNestedBlockScopedRedeclarationOrCapturedBinding(name) ? getGeneratedNameForNode(name) : (name).text; loopParameters.push(nameText); } else { @@ -3083,7 +3162,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } else { // top level converted loop - return unwrapped value - write(`return ${loopResult}.value`); + write(`return ${loopResult}.value;`); } writeLine(); } @@ -3853,7 +3932,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge // We create a synthetic copy of the identifier in order to avoid the rewriting that might // otherwise occur when the identifier is emitted. index = createSynthesizedNode(propName.kind); - (index).text = (propName).text; + // We need to unescape identifier here because when parsing an identifier prefixing with "__" + // the parser need to append "_" in order to escape colliding with magic identifiers such as "__proto__" + // Therefore, in order to correctly emit identifiers that are written in original TypeScript file, + // we will unescapeIdentifier to remove additional underscore (if no underscore is added, the function will return original input string) + (index).text = unescapeIdentifier((propName).text); } return !nameIsComputed && index.kind === SyntaxKind.Identifier @@ -4025,22 +4108,56 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } else { let initializer = node.initializer; - if (!initializer && languageVersion < ScriptTarget.ES6) { - - // downlevel emit for non-initialized let bindings defined in loops - // for (...) { let x; } - // should be - // for (...) { var = void 0; } - // this is necessary to preserve ES6 semantic in scenarios like - // for (...) { let x; console.log(x); x = 1 } // assignment on one iteration should not affect other iterations - const isLetDefinedInLoop = - (resolver.getNodeCheckFlags(node) & NodeCheckFlags.BlockScopedBindingInLoop) && - (getCombinedFlagsForIdentifier(node.name) & NodeFlags.Let); - - // NOTE: default initialization should not be added to let bindings in for-in\for-of statements - if (isLetDefinedInLoop && - node.parent.parent.kind !== SyntaxKind.ForInStatement && - node.parent.parent.kind !== SyntaxKind.ForOfStatement) { + if (!initializer && + languageVersion < ScriptTarget.ES6 && + // for names - binding patterns that lack initializer there is no point to emit explicit initializer + // since downlevel codegen for destructuring will fail in the absence of initializer so all binding elements will say uninitialized + node.name.kind === SyntaxKind.Identifier) { + + const container = getEnclosingBlockScopeContainer(node); + const flags = resolver.getNodeCheckFlags(node); + + // nested let bindings might need to be initialized explicitly to preserve ES6 semantic + // { let x = 1; } + // { let x; } // x here should be undefined. not 1 + // NOTES: + // Top level bindings never collide with anything and thus don't require explicit initialization. + // As for nested let bindings there are two cases: + // - nested let bindings that were not renamed definitely should be initialized explicitly + // { let x = 1; } + // { let x; if (some-condition) { x = 1}; if (x) { /*1*/ } } + // Without explicit initialization code in /*1*/ can be executed even if some-condition is evaluated to false + // - renaming introduces fresh name that should not collide with any existing names, however renamed bindings sometimes also should be + // explicitly initialized. One particular case: non-captured binding declared inside loop body (but not in loop initializer) + // let x; + // for (;;) { + // let x; + // } + // in downlevel codegen inner 'x' will be renamed so it won't collide with outer 'x' however it will should be reset on every iteration + // as if it was declared anew. + // * Why non-captured binding - because if loop contains block scoped binding captured in some function then loop body will be rewritten + // to have a fresh scope on every iteration so everything will just work. + // * Why loop initializer is excluded - since we've introduced a fresh name it already will be undefined. + const isCapturedInFunction = flags & NodeCheckFlags.CapturedBlockScopedBinding; + const isDeclaredInLoop = flags & NodeCheckFlags.BlockScopedBindingInLoop; + + const emittedAsTopLevel = + isBlockScopedContainerTopLevel(container) || + (isCapturedInFunction && isDeclaredInLoop && container.kind === SyntaxKind.Block && isIterationStatement(container.parent, /*lookInLabeledStatements*/ false)); + + const emittedAsNestedLetDeclaration = + getCombinedNodeFlags(node) & NodeFlags.Let && + !emittedAsTopLevel; + + const emitExplicitInitializer = + emittedAsNestedLetDeclaration && + container.kind !== SyntaxKind.ForInStatement && + container.kind !== SyntaxKind.ForOfStatement && + ( + !resolver.isDeclarationWithCollidingName(node) || + (isDeclaredInLoop && !isCapturedInFunction && !isIterationStatement(container, /*lookInLabeledStatements*/ false)) + ); + if (emitExplicitInitializer) { initializer = createVoidZero(); } } @@ -4075,14 +4192,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } } - function getCombinedFlagsForIdentifier(node: Identifier): NodeFlags { - if (!node.parent || (node.parent.kind !== SyntaxKind.VariableDeclaration && node.parent.kind !== SyntaxKind.BindingElement)) { - return 0; - } - - return getCombinedNodeFlags(node.parent); - } - function isES6ExportedDeclaration(node: Node) { return !!(node.flags & NodeFlags.Export) && modulekind === ModuleKind.ES6 && @@ -4470,6 +4579,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge write(" {"); increaseIndent(); writeLine(); + + if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.AsyncMethodWithSuperBinding) { + writeLines(` +const _super = (function (geti, seti) { + const cache = Object.create(null); + return name => cache[name] || (cache[name] = { get value() { return geti(name); }, set value(v) { seti(name, v); } }); +})(name => super[name], (name, value) => super[name] = value);`); + writeLine(); + } + else if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.AsyncMethodWithSuper) { + write(`const _super = name => super[name];`); + writeLine(); + } + write("return"); } @@ -4481,20 +4604,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge write(", void 0, "); } - if (promiseConstructor) { - emitEntityNameAsExpression(promiseConstructor, /*useFallback*/ false); + if (languageVersion >= ScriptTarget.ES6 || !promiseConstructor) { + write("void 0"); } else { - write("Promise"); + emitEntityNameAsExpression(promiseConstructor, /*useFallback*/ false); } // Emit the call to __awaiter. - if (hasLexicalArguments) { - write(", function* (_arguments)"); - } - else { - write(", function* ()"); - } + write(", function* ()"); // Emit the signature and body for the inner generator function. emitFunctionBody(node); @@ -5031,64 +5149,107 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } function emitClassLikeDeclarationForES6AndHigher(node: ClassLikeDeclaration) { + let decoratedClassAlias: string; const thisNodeIsDecorated = nodeIsDecorated(node); if (node.kind === SyntaxKind.ClassDeclaration) { if (thisNodeIsDecorated) { - // To preserve the correct runtime semantics when decorators are applied to the class, - // the emit needs to follow one of the following rules: - // - // * For a local class declaration: - // - // @dec class C { - // } - // - // The emit should be: - // - // let C = class { - // }; - // C = __decorate([dec], C); + // When we emit an ES6 class that has a class decorator, we must tailor the + // emit to certain specific cases. // - // * For an exported class declaration: + // In the simplest case, we emit the class declaration as a let declaration, and + // evaluate decorators after the close of the class body: // - // @dec export class C { - // } + // TypeScript | Javascript + // --------------------------------|------------------------------------ + // @dec | let C = class C { + // class C { | } + // } | C = __decorate([dec], C); + // --------------------------------|------------------------------------ + // @dec | export let C = class C { + // export class C { | } + // } | C = __decorate([dec], C); + // --------------------------------------------------------------------- + // [Example 1] // - // The emit should be: + // If a class declaration contains a reference to itself *inside* of the class body, + // this introduces two bindings to the class: One outside of the class body, and one + // inside of the class body. If we apply decorators as in [Example 1] above, there + // is the possibility that the decorator `dec` will return a new value for the + // constructor, which would result in the binding inside of the class no longer + // pointing to the same reference as the binding outside of the class. // - // export let C = class { - // }; - // C = __decorate([dec], C); + // As a result, we must instead rewrite all references to the class *inside* of the + // class body to instead point to a local temporary alias for the class: // - // * For a default export of a class declaration with a name: + // TypeScript | Javascript + // --------------------------------|------------------------------------ + // @dec | let C_1; + // class C { | let C = C_1 = class C { + // static x() { return C.y; } | static x() { return C_1.y; } + // static y = 1; | } + // } | C.y = 1; + // | C = C_1 = __decorate([dec], C); + // --------------------------------|------------------------------------ + // @dec | let C_1; + // export class C { | export let C = C_1 = class C { + // static x() { return C.y; } | static x() { return C_1.y; } + // static y = 1; | } + // } | C.y = 1; + // | C = C_1 = __decorate([dec], C); + // --------------------------------------------------------------------- + // [Example 2] // - // @dec default export class C { - // } + // If a class declaration is the default export of a module, we instead emit + // the export after the decorated declaration: // - // The emit should be: + // TypeScript | Javascript + // --------------------------------|------------------------------------ + // @dec | let default_1 = class { + // export default class { | } + // } | default_1 = __decorate([dec], default_1); + // | export default default_1; + // --------------------------------|------------------------------------ + // @dec | let C = class C { + // export default class { | } + // } | C = __decorate([dec], C); + // | export default C; + // --------------------------------------------------------------------- + // [Example 3] // - // let C = class { - // } - // C = __decorate([dec], C); - // export default C; + // If the class declaration is the default export and a reference to itself + // inside of the class body, we must emit both an alias for the class *and* + // move the export after the declaration: // - // * For a default export of a class declaration without a name: - // - // @dec default export class { - // } - // - // The emit should be: - // - // let _default = class { - // } - // _default = __decorate([dec], _default); - // export default _default; + // TypeScript | Javascript + // --------------------------------|------------------------------------ + // @dec | let C_1; + // export default class C { | let C = C_1 = class C { + // static x() { return C.y; } | static x() { return C_1.y; } + // static y = 1; | } + // } | C.y = 1; + // | C = C_1 = __decorate([dec], C); + // | export default C; + // --------------------------------------------------------------------- + // [Example 4] // + + if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.ClassWithBodyScopedClassBinding) { + decoratedClassAlias = unescapeIdentifier(makeUniqueName(node.name ? node.name.text : "default")); + decoratedClassAliases[getNodeId(node)] = decoratedClassAlias; + write(`let ${decoratedClassAlias};`); + writeLine(); + } + if (isES6ExportedDeclaration(node) && !(node.flags & NodeFlags.Default)) { write("export "); } write("let "); emitDeclarationName(node); + if (decoratedClassAlias !== undefined) { + write(` = ${decoratedClassAlias}`); + } + write(" = "); } else if (isES6ExportedDeclaration(node)) { @@ -5127,7 +5288,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge // emit name if // - node has a name // - this is default export with static initializers - if ((node.name || (node.flags & NodeFlags.Default && (staticProperties.length > 0 || modulekind !== ModuleKind.ES6))) && !thisNodeIsDecorated) { + if (node.name || (node.flags & NodeFlags.Default && (staticProperties.length > 0 || modulekind !== ModuleKind.ES6) && !thisNodeIsDecorated)) { write(" "); emitDeclarationName(node); } @@ -5147,16 +5308,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge writeLine(); emitToken(SyntaxKind.CloseBraceToken, node.members.end); - // TODO(rbuckton): Need to go back to `let _a = class C {}` approach, removing the defineProperty call for now. - - // For a decorated class, we need to assign its name (if it has one). This is because we emit - // the class as a class expression to avoid the double-binding of the identifier: - // - // let C = class { - // } - // Object.defineProperty(C, "name", { value: "C", configurable: true }); - // if (thisNodeIsDecorated) { + decoratedClassAliases[getNodeId(node)] = undefined; write(";"); } @@ -5181,7 +5334,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge else { writeLine(); emitPropertyDeclarations(node, staticProperties); - emitDecoratorsOfClass(node); + emitDecoratorsOfClass(node, decoratedClassAlias); } if (!(node.flags & NodeFlags.Export)) { @@ -5255,7 +5408,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge emitMemberFunctionsForES5AndLower(node); emitPropertyDeclarations(node, getInitializedProperties(node, /*isStatic*/ true)); writeLine(); - emitDecoratorsOfClass(node); + emitDecoratorsOfClass(node, /*decoratedClassAlias*/ undefined); writeLine(); emitToken(SyntaxKind.CloseBraceToken, node.members.end, () => { write("return "); @@ -5297,13 +5450,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } } - function emitDecoratorsOfClass(node: ClassLikeDeclaration) { + function emitDecoratorsOfClass(node: ClassLikeDeclaration, decoratedClassAlias: string) { emitDecoratorsOfMembers(node, /*staticFlag*/ 0); emitDecoratorsOfMembers(node, NodeFlags.Static); - emitDecoratorsOfConstructor(node); + emitDecoratorsOfConstructor(node, decoratedClassAlias); } - function emitDecoratorsOfConstructor(node: ClassLikeDeclaration) { + function emitDecoratorsOfConstructor(node: ClassLikeDeclaration, decoratedClassAlias: string) { const decorators = node.decorators; const constructor = getFirstConstructorWithBody(node); const firstParameterDecorator = constructor && forEach(constructor.parameters, parameter => parameter.decorators); @@ -5327,6 +5480,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge writeLine(); emitStart(node.decorators || firstParameterDecorator); emitDeclarationName(node); + if (decoratedClassAlias !== undefined) { + write(` = ${decoratedClassAlias}`); + } + write(" = __decorate(["); increaseIndent(); writeLine(); @@ -6100,6 +6257,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge if (contains(externalImports, node)) { const isExportedImport = node.kind === SyntaxKind.ImportEqualsDeclaration && (node.flags & NodeFlags.Export) !== 0; const namespaceDeclaration = getNamespaceDeclarationNode(node); + const varOrConst = (languageVersion <= ScriptTarget.ES5) ? "var " : "const "; if (modulekind !== ModuleKind.AMD) { emitLeadingComments(node); @@ -6107,7 +6265,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge if (namespaceDeclaration && !isDefaultImport(node)) { // import x = require("foo") // import * as x from "foo" - if (!isExportedImport) write("var "); + if (!isExportedImport) { + write(varOrConst); + }; emitModuleMemberName(namespaceDeclaration); write(" = "); } @@ -6119,7 +6279,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge // import d, { x, y } from "foo" const isNakedImport = SyntaxKind.ImportDeclaration && !(node).importClause; if (!isNakedImport) { - write("var "); + write(varOrConst); write(getGeneratedNameForNode(node)); write(" = "); } @@ -6146,7 +6306,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } else if (namespaceDeclaration && isDefaultImport(node)) { // import d, * as x from "foo" - write("var "); + write(varOrConst); emitModuleMemberName(namespaceDeclaration); write(" = "); write(getGeneratedNameForNode(node)); @@ -6980,6 +7140,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Debug.assert(!exportFunctionForFile); // make sure that name of 'exports' function does not conflict with existing identifiers exportFunctionForFile = makeUniqueName("exports"); + contextObjectForFile = makeUniqueName("context"); writeLine(); write("System.register("); writeModuleName(node, emitRelativePathAsModuleName); @@ -6990,14 +7151,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge for (let i = 0; i < externalImports.length; i++) { const text = getExternalModuleNameText(externalImports[i], emitRelativePathAsModuleName); - if (hasProperty(groupIndices, text)) { + if (text === undefined) { + continue; + } + + // text should be quoted string + // for deduplication purposes in key remove leading and trailing quotes so 'a' and "a" will be considered the same + const key = text.substr(1, text.length - 2); + + if (hasProperty(groupIndices, key)) { // deduplicate/group entries in dependency list by the dependency name - const groupIndex = groupIndices[text]; + const groupIndex = groupIndices[key]; dependencyGroups[groupIndex].push(externalImports[i]); continue; } else { - groupIndices[text] = dependencyGroups.length; + groupIndices[key] = dependencyGroups.length; dependencyGroups.push([externalImports[i]]); } @@ -7007,10 +7176,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge write(text); } - write(`], function(${exportFunctionForFile}) {`); + write(`], function(${exportFunctionForFile}, ${contextObjectForFile}) {`); writeLine(); increaseIndent(); const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true); + writeLine(); + write(`var __moduleName = ${contextObjectForFile} && ${contextObjectForFile}.id;`); + writeLine(); emitEmitHelpers(node); emitCaptureThisForNodeIfNecessary(node); emitSystemModuleBody(node, dependencyGroups, startIndex); @@ -7251,7 +7423,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge return result; } - function getTextToEmit(node: JsxText) { + function isJsxChildEmittable(child: JsxChild): boolean { + if (child.kind === SyntaxKind.JsxExpression) { + // Don't emit empty expressions + return !!(child).expression; + + } + else if (child.kind === SyntaxKind.JsxText) { + // Don't emit empty strings + return !!getTextToEmit(child); + } + + return true; + }; + + function getTextToEmit(node: JsxText): string { switch (compilerOptions.jsx) { case JsxEmit.React: let text = trimReactWhitespaceAndApplyEntities(node); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index ecf64392a9a73..b6ba02b987cf2 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -438,7 +438,7 @@ namespace ts { // Share a single scanner across all calls to parse a source file. This helps speed things // up by avoiding the cost of creating/compiling scanners over and over again. const scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ true); - const disallowInAndDecoratorContext = ParserContextFlags.DisallowIn | ParserContextFlags.Decorator; + const disallowInAndDecoratorContext = NodeFlags.DisallowInContext | NodeFlags.DecoratorContext; // capture constructors in 'initializeState' to avoid null checks let NodeConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node; @@ -502,7 +502,7 @@ namespace ts { // Note: it should not be necessary to save/restore these flags during speculative/lookahead // parsing. These context flags are naturally stored and restored through normal recursive // descent parsing and unwinding. - let contextFlags: ParserContextFlags; + let contextFlags: NodeFlags; // Whether or not we've had a parse error since creating the last AST node. If we have // encountered an error, it will be stored on the next AST node we create. Parse errors @@ -546,7 +546,7 @@ namespace ts { function getLanguageVariant(fileName: string) { // .tsx and .jsx files are treated as jsx language variant. - return fileExtensionIs(fileName, ".tsx") || fileExtensionIs(fileName, ".jsx") ? LanguageVariant.JSX : LanguageVariant.Standard; + return fileExtensionIs(fileName, ".tsx") || fileExtensionIs(fileName, ".jsx") || fileExtensionIs(fileName, ".js") ? LanguageVariant.JSX : LanguageVariant.Standard; } function initializeState(fileName: string, _sourceText: string, languageVersion: ScriptTarget, isJavaScriptFile: boolean, _syntaxCursor: IncrementalParser.SyntaxCursor) { @@ -562,7 +562,7 @@ namespace ts { identifierCount = 0; nodeCount = 0; - contextFlags = isJavaScriptFile ? ParserContextFlags.JavaScriptFile : ParserContextFlags.None; + contextFlags = isJavaScriptFile ? NodeFlags.JavaScriptFile : NodeFlags.None; parseErrorBeforeNextFinishedNode = false; // Initialize and prime the scanner before parsing the source elements. @@ -587,10 +587,7 @@ namespace ts { function parseSourceFileWorker(fileName: string, languageVersion: ScriptTarget, setParentNodes: boolean): SourceFile { sourceFile = createSourceFile(fileName, languageVersion); - - if (contextFlags & ParserContextFlags.JavaScriptFile) { - sourceFile.parserContextFlags = ParserContextFlags.JavaScriptFile; - } + sourceFile.flags = contextFlags; // Prime the scanner. token = nextToken(); @@ -616,7 +613,7 @@ namespace ts { function addJSDocComment(node: T): T { - if (contextFlags & ParserContextFlags.JavaScriptFile) { + if (contextFlags & NodeFlags.JavaScriptFile) { const comments = getLeadingCommentRangesOfNode(node, sourceFile); if (comments) { for (const comment of comments) { @@ -666,13 +663,13 @@ namespace ts { sourceFile.bindDiagnostics = []; sourceFile.languageVersion = languageVersion; sourceFile.fileName = normalizePath(fileName); - sourceFile.flags = fileExtensionIs(sourceFile.fileName, ".d.ts") ? NodeFlags.DeclarationFile : 0; sourceFile.languageVariant = getLanguageVariant(sourceFile.fileName); + sourceFile.isDeclarationFile = fileExtensionIs(sourceFile.fileName, ".d.ts"); return sourceFile; } - function setContextFlag(val: boolean, flag: ParserContextFlags) { + function setContextFlag(val: boolean, flag: NodeFlags) { if (val) { contextFlags |= flag; } @@ -682,22 +679,22 @@ namespace ts { } function setDisallowInContext(val: boolean) { - setContextFlag(val, ParserContextFlags.DisallowIn); + setContextFlag(val, NodeFlags.DisallowInContext); } function setYieldContext(val: boolean) { - setContextFlag(val, ParserContextFlags.Yield); + setContextFlag(val, NodeFlags.YieldContext); } function setDecoratorContext(val: boolean) { - setContextFlag(val, ParserContextFlags.Decorator); + setContextFlag(val, NodeFlags.DecoratorContext); } function setAwaitContext(val: boolean) { - setContextFlag(val, ParserContextFlags.Await); + setContextFlag(val, NodeFlags.AwaitContext); } - function doOutsideOfContext(context: ParserContextFlags, func: () => T): T { + function doOutsideOfContext(context: NodeFlags, func: () => T): T { // contextFlagsToClear will contain only the context flags that are // currently set that we need to temporarily clear // We don't just blindly reset to the previous flags to ensure @@ -718,7 +715,7 @@ namespace ts { return func(); } - function doInsideOfContext(context: ParserContextFlags, func: () => T): T { + function doInsideOfContext(context: NodeFlags, func: () => T): T { // contextFlagsToSet will contain only the context flags that // are not currently set that we need to temporarily enable. // We don't just blindly reset to the previous flags to ensure @@ -740,51 +737,51 @@ namespace ts { } function allowInAnd(func: () => T): T { - return doOutsideOfContext(ParserContextFlags.DisallowIn, func); + return doOutsideOfContext(NodeFlags.DisallowInContext, func); } function disallowInAnd(func: () => T): T { - return doInsideOfContext(ParserContextFlags.DisallowIn, func); + return doInsideOfContext(NodeFlags.DisallowInContext, func); } function doInYieldContext(func: () => T): T { - return doInsideOfContext(ParserContextFlags.Yield, func); + return doInsideOfContext(NodeFlags.YieldContext, func); } function doInDecoratorContext(func: () => T): T { - return doInsideOfContext(ParserContextFlags.Decorator, func); + return doInsideOfContext(NodeFlags.DecoratorContext, func); } function doInAwaitContext(func: () => T): T { - return doInsideOfContext(ParserContextFlags.Await, func); + return doInsideOfContext(NodeFlags.AwaitContext, func); } function doOutsideOfAwaitContext(func: () => T): T { - return doOutsideOfContext(ParserContextFlags.Await, func); + return doOutsideOfContext(NodeFlags.AwaitContext, func); } function doInYieldAndAwaitContext(func: () => T): T { - return doInsideOfContext(ParserContextFlags.Yield | ParserContextFlags.Await, func); + return doInsideOfContext(NodeFlags.YieldContext | NodeFlags.AwaitContext, func); } - function inContext(flags: ParserContextFlags) { + function inContext(flags: NodeFlags) { return (contextFlags & flags) !== 0; } function inYieldContext() { - return inContext(ParserContextFlags.Yield); + return inContext(NodeFlags.YieldContext); } function inDisallowInContext() { - return inContext(ParserContextFlags.DisallowIn); + return inContext(NodeFlags.DisallowInContext); } function inDecoratorContext() { - return inContext(ParserContextFlags.Decorator); + return inContext(NodeFlags.DecoratorContext); } function inAwaitContext() { - return inContext(ParserContextFlags.Await); + return inContext(NodeFlags.AwaitContext); } function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): void { @@ -996,7 +993,7 @@ namespace ts { node.end = end === undefined ? scanner.getStartPos() : end; if (contextFlags) { - node.parserContextFlags = contextFlags; + node.flags |= contextFlags; } // Keep track on the node if we encountered an error while parsing it. If we did, then @@ -1004,7 +1001,7 @@ namespace ts { // flag so that we don't mark any subsequent nodes. if (parseErrorBeforeNextFinishedNode) { parseErrorBeforeNextFinishedNode = false; - node.parserContextFlags |= ParserContextFlags.ThisNodeHasError; + node.flags |= NodeFlags.ThisNodeHasError; } return node; @@ -1172,7 +1169,7 @@ namespace ts { case ParsingContext.SwitchClauses: return token === SyntaxKind.CaseKeyword || token === SyntaxKind.DefaultKeyword; case ParsingContext.TypeMembers: - return isStartOfTypeMember(); + return lookAhead(isTypeMemberStart); case ParsingContext.ClassMembers: // We allow semicolons as class elements (as specified by ES6) as long as we're // not in error recovery. If we're in error recovery, we don't want an errant @@ -1453,7 +1450,7 @@ namespace ts { // differently depending on what mode it is in. // // This also applies to all our other context flags as well. - const nodeContextFlags = node.parserContextFlags & ParserContextFlags.ParserGeneratedFlags; + const nodeContextFlags = node.flags & NodeFlags.ContextFlags; if (nodeContextFlags !== contextFlags) { return undefined; } @@ -1922,7 +1919,7 @@ namespace ts { && sourceText.charCodeAt(tokenPos) === CharacterCodes._0 && isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) { - node.flags |= NodeFlags.OctalLiteral; + node.isOctalLiteral = true; } return node; @@ -2214,13 +2211,13 @@ namespace ts { return finishNode(node); } - function parsePropertyOrMethodSignature(): PropertySignature | MethodSignature { - const fullStart = scanner.getStartPos(); + function parsePropertyOrMethodSignature(fullStart: number, modifiers: ModifiersArray): PropertySignature | MethodSignature { const name = parsePropertyName(); const questionToken = parseOptionalToken(SyntaxKind.QuestionToken); if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { const method = createNode(SyntaxKind.MethodSignature, fullStart); + setModifiers(method, modifiers); method.name = name; method.questionToken = questionToken; @@ -2232,6 +2229,7 @@ namespace ts { } else { const property = createNode(SyntaxKind.PropertySignature, fullStart); + setModifiers(property, modifiers); property.name = name; property.questionToken = questionToken; property.type = parseTypeAnnotation(); @@ -2248,86 +2246,51 @@ namespace ts { } } - function isStartOfTypeMember(): boolean { - switch (token) { - case SyntaxKind.OpenParenToken: - case SyntaxKind.LessThanToken: - case SyntaxKind.OpenBracketToken: // Both for indexers and computed properties - return true; - default: - if (isModifierKind(token)) { - const result = lookAhead(isStartOfIndexSignatureDeclaration); - if (result) { - return result; - } - } - - return isLiteralPropertyName() && lookAhead(isTypeMemberWithLiteralPropertyName); + function isTypeMemberStart(): boolean { + let idToken: SyntaxKind; + // Return true if we have the start of a signature member + if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { + return true; } - } - - function isStartOfIndexSignatureDeclaration() { + // Eat up all modifiers, but hold on to the last one in case it is actually an identifier while (isModifierKind(token)) { + idToken = token; nextToken(); } - - return isIndexSignature(); - } - - function isTypeMemberWithLiteralPropertyName() { - nextToken(); - return token === SyntaxKind.OpenParenToken || - token === SyntaxKind.LessThanToken || - token === SyntaxKind.QuestionToken || - token === SyntaxKind.ColonToken || - canParseSemicolon(); + // Index signatures and computed property names are type members + if (token === SyntaxKind.OpenBracketToken) { + return true; + } + // Try to get the first property-like token following all modifiers + if (isLiteralPropertyName()) { + idToken = token; + nextToken(); + } + // If we were able to get any potential identifier, check that it is + // the start of a member declaration + if (idToken) { + return token === SyntaxKind.OpenParenToken || + token === SyntaxKind.LessThanToken || + token === SyntaxKind.QuestionToken || + token === SyntaxKind.ColonToken || + canParseSemicolon(); + } + return false; } function parseTypeMember(): TypeElement { - switch (token) { - case SyntaxKind.OpenParenToken: - case SyntaxKind.LessThanToken: - return parseSignatureMember(SyntaxKind.CallSignature); - case SyntaxKind.OpenBracketToken: - // Indexer or computed property - return isIndexSignature() - ? parseIndexSignatureDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined) - : parsePropertyOrMethodSignature(); - case SyntaxKind.NewKeyword: - if (lookAhead(isStartOfConstructSignature)) { - return parseSignatureMember(SyntaxKind.ConstructSignature); - } - // fall through. - case SyntaxKind.StringLiteral: - case SyntaxKind.NumericLiteral: - return parsePropertyOrMethodSignature(); - default: - // Index declaration as allowed as a type member. But as per the grammar, - // they also allow modifiers. So we have to check for an index declaration - // that might be following modifiers. This ensures that things work properly - // when incrementally parsing as the parser will produce the Index declaration - // if it has the same text regardless of whether it is inside a class or an - // object type. - if (isModifierKind(token)) { - const result = tryParse(parseIndexSignatureWithModifiers); - if (result) { - return result; - } - } - - if (tokenIsIdentifierOrKeyword(token)) { - return parsePropertyOrMethodSignature(); - } + if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { + return parseSignatureMember(SyntaxKind.CallSignature); } - } - - function parseIndexSignatureWithModifiers() { - const fullStart = scanner.getStartPos(); - const decorators = parseDecorators(); + if (token === SyntaxKind.NewKeyword && lookAhead(isStartOfConstructSignature)) { + return parseSignatureMember(SyntaxKind.ConstructSignature); + } + const fullStart = getNodePos(); const modifiers = parseModifiers(); - return isIndexSignature() - ? parseIndexSignatureDeclaration(fullStart, decorators, modifiers) - : undefined; + if (isIndexSignature()) { + return parseIndexSignatureDeclaration(fullStart, /*decorators*/ undefined, modifiers); + } + return parsePropertyOrMethodSignature(fullStart, modifiers); } function isStartOfConstructSignature() { @@ -2546,7 +2509,7 @@ namespace ts { function parseType(): TypeNode { // The rules about 'yield' only apply to actual code/expression contexts. They don't // apply to 'type' contexts. So we disable these parameters here before moving on. - return doOutsideOfContext(ParserContextFlags.TypeExcludesFlags, parseTypeWorker); + return doOutsideOfContext(NodeFlags.TypeExcludesFlags, parseTypeWorker); } function parseTypeWorker(): TypeNode { @@ -3941,7 +3904,9 @@ namespace ts { function parseArrayLiteralExpression(): ArrayLiteralExpression { const node = createNode(SyntaxKind.ArrayLiteralExpression); parseExpected(SyntaxKind.OpenBracketToken); - if (scanner.hasPrecedingLineBreak()) node.flags |= NodeFlags.MultiLine; + if (scanner.hasPrecedingLineBreak()) { + node.multiLine = true; + } node.elements = parseDelimitedList(ParsingContext.ArrayLiteralMembers, parseArgumentOrArrayLiteralElement); parseExpected(SyntaxKind.CloseBracketToken); return finishNode(node); @@ -4012,7 +3977,7 @@ namespace ts { const node = createNode(SyntaxKind.ObjectLiteralExpression); parseExpected(SyntaxKind.OpenBraceToken); if (scanner.hasPrecedingLineBreak()) { - node.flags |= NodeFlags.MultiLine; + node.multiLine = true; } node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralElement, /*considerSemicolonAsDelimeter*/ true); @@ -4051,7 +4016,7 @@ namespace ts { setDecoratorContext(/*val*/ true); } - return finishNode(node); + return addJSDocComment(finishNode(node)); } function parseOptionalIdentifier() { @@ -4335,13 +4300,13 @@ namespace ts { const labeledStatement = createNode(SyntaxKind.LabeledStatement, fullStart); labeledStatement.label = expression; labeledStatement.statement = parseStatement(); - return finishNode(labeledStatement); + return addJSDocComment(finishNode(labeledStatement)); } else { const expressionStatement = createNode(SyntaxKind.ExpressionStatement, fullStart); expressionStatement.expression = expression; parseSemicolon(); - return finishNode(expressionStatement); + return addJSDocComment(finishNode(expressionStatement)); } } @@ -4404,6 +4369,7 @@ namespace ts { case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: case SyntaxKind.PublicKeyword: + case SyntaxKind.ReadonlyKeyword: nextToken(); // ASI takes effect for this modifier. if (scanner.hasPrecedingLineBreak()) { @@ -4486,6 +4452,7 @@ namespace ts { case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: case SyntaxKind.StaticKeyword: + case SyntaxKind.ReadonlyKeyword: // When these don't start a declaration, they may be the start of a class member if an identifier // immediately follows. Otherwise they're an identifier in an expression statement. return isStartOfDeclaration() || !lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine); @@ -4567,6 +4534,7 @@ namespace ts { case SyntaxKind.PublicKeyword: case SyntaxKind.AbstractKeyword: case SyntaxKind.StaticKeyword: + case SyntaxKind.ReadonlyKeyword: case SyntaxKind.GlobalKeyword: if (isStartOfDeclaration()) { return parseDeclaration(); @@ -4778,7 +4746,7 @@ namespace ts { parseExpected(SyntaxKind.ConstructorKeyword); fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node); node.body = parseFunctionBlockOrSemicolon(/*isGenerator*/ false, /*isAsync*/ false, Diagnostics.or_expected); - return finishNode(node); + return addJSDocComment(finishNode(node)); } function parseMethodDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray, asteriskToken: Node, name: PropertyName, questionToken: Node, diagnosticMessage?: DiagnosticMessage): MethodDeclaration { @@ -4792,7 +4760,7 @@ namespace ts { const isAsync = !!(method.flags & NodeFlags.Async); fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, method); method.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, diagnosticMessage); - return finishNode(method); + return addJSDocComment(finishNode(method)); } function parsePropertyDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray, name: PropertyName, questionToken: Node): ClassElement { @@ -4814,7 +4782,7 @@ namespace ts { // The checker may still error in the static case to explicitly disallow the yield expression. property.initializer = modifiers && modifiers.flags & NodeFlags.Static ? allowInAnd(parseNonParameterInitializer) - : doOutsideOfContext(ParserContextFlags.Yield | ParserContextFlags.DisallowIn, parseNonParameterInitializer); + : doOutsideOfContext(NodeFlags.YieldContext | NodeFlags.DisallowInContext, parseNonParameterInitializer); parseSemicolon(); return finishNode(property); @@ -4855,6 +4823,7 @@ namespace ts { case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: case SyntaxKind.StaticKeyword: + case SyntaxKind.ReadonlyKeyword: return true; default: return false; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 398ce27ef48a3..9852b2354e2e5 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -12,7 +12,7 @@ namespace ts { const emptyArray: any[] = []; - export const version = "1.8.0"; + export const version = "1.9.0"; export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean): string { let fileName = "tsconfig.json"; @@ -36,37 +36,374 @@ namespace ts { return normalizePath(referencedFileName); } + function trace(host: ModuleResolutionHost, message: DiagnosticMessage, ...args: any[]): void; + function trace(host: ModuleResolutionHost, message: DiagnosticMessage): void { + host.trace(formatMessage.apply(undefined, arguments)); + } + + function isTraceEnabled(compilerOptions: CompilerOptions, host: ModuleResolutionHost): boolean { + return compilerOptions.traceModuleResolution && host.trace !== undefined; + } + + function startsWith(str: string, prefix: string): boolean { + return str.lastIndexOf(prefix, 0) === 0; + } + + function endsWith(str: string, suffix: string): boolean { + const expectedPos = str.length - suffix.length; + return str.indexOf(suffix, expectedPos) === expectedPos; + } + + function hasZeroOrOneAsteriskCharacter(str: string): boolean { + let seenAsterisk = false; + for (let i = 0; i < str.length; i++) { + if (str.charCodeAt(i) === CharacterCodes.asterisk) { + if (!seenAsterisk) { + seenAsterisk = true; + } + else { + // have already seen asterisk + return false; + } + } + } + return true; + } + + function createResolvedModule(resolvedFileName: string, isExternalLibraryImport: boolean, failedLookupLocations: string[]): ResolvedModuleWithFailedLookupLocations { + return { resolvedModule: resolvedFileName ? { resolvedFileName, isExternalLibraryImport } : undefined, failedLookupLocations }; + } + + function moduleHasNonRelativeName(moduleName: string): boolean { + if (isRootedDiskPath(moduleName)) { + return false; + } + + const i = moduleName.lastIndexOf("./", 1); + const startsWithDotSlashOrDotDotSlash = i === 0 || (i === 1 && moduleName.charCodeAt(0) === CharacterCodes.dot); + return !startsWithDotSlashOrDotDotSlash; + } + + interface ModuleResolutionState { + host: ModuleResolutionHost; + compilerOptions: CompilerOptions; + traceEnabled: boolean; + // skip .tsx files if jsx is not enabled + skipTsx: boolean; + } + export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { - const moduleResolution = compilerOptions.moduleResolution !== undefined - ? compilerOptions.moduleResolution - : compilerOptions.module === ModuleKind.CommonJS ? ModuleResolutionKind.NodeJs : ModuleResolutionKind.Classic; + const traceEnabled = isTraceEnabled(compilerOptions, host); + if (traceEnabled) { + trace(host, Diagnostics.Resolving_module_0_from_1, moduleName, containingFile); + } + + let moduleResolution = compilerOptions.moduleResolution; + if (moduleResolution === undefined) { + moduleResolution = compilerOptions.module === ModuleKind.CommonJS ? ModuleResolutionKind.NodeJs : ModuleResolutionKind.Classic; + if (traceEnabled) { + trace(host, Diagnostics.Module_resolution_kind_is_not_specified_using_0, ModuleResolutionKind[moduleResolution]); + } + } + else { + if (traceEnabled) { + trace(host, Diagnostics.Explicitly_specified_module_resolution_kind_Colon_0, ModuleResolutionKind[moduleResolution]); + } + } + let result: ResolvedModuleWithFailedLookupLocations; switch (moduleResolution) { - case ModuleResolutionKind.NodeJs: return nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host); - case ModuleResolutionKind.Classic: return classicNameResolver(moduleName, containingFile, compilerOptions, host); + case ModuleResolutionKind.NodeJs: + result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host); + break; + case ModuleResolutionKind.Classic: + result = classicNameResolver(moduleName, containingFile, compilerOptions, host); + break; + } + + if (traceEnabled) { + if (result.resolvedModule) { + trace(host, Diagnostics.Module_name_0_was_successfully_resolved_to_1, moduleName, result.resolvedModule.resolvedFileName); + } + else { + trace(host, Diagnostics.Module_name_0_was_not_resolved, moduleName); + } + } + + return result; + } + + /* + * Every module resolution kind can has its specific understanding how to load module from a specific path on disk + * I.e. for path '/a/b/c': + * - Node loader will first to try to check if '/a/b/c' points to a file with some supported extension and if this fails + * it will try to load module from directory: directory '/a/b/c' should exist and it should have either 'package.json' with + * 'typings' entry or file 'index' with some supported extension + * - Classic loader will only try to interpret '/a/b/c' as file. + */ + type ResolutionKindSpecificLoader = (candidate: string, extensions: string[], failedLookupLocations: string[], onlyRecordFalures: boolean, state: ModuleResolutionState) => string; + + /** + * Any module resolution kind can be augmented with optional settings: 'baseUrl', 'paths' and 'rootDirs' - they are used to + * mitigate differences between design time structure of the project and its runtime counterpart so the same import name + * can be resolved successfully by TypeScript compiler and runtime module loader. + * If these settings are set then loading procedure will try to use them to resolve module name and it can of failure it will + * fallback to standard resolution routine. + * + * - baseUrl - this setting controls how non-relative module names are resolved. If this setting is specified then non-relative + * names will be resolved relative to baseUrl: i.e. if baseUrl is '/a/b' then canditate location to resolve module name 'c/d' will + * be '/a/b/c/d' + * - paths - this setting can only be used when baseUrl is specified. allows to tune how non-relative module names + * will be resolved based on the content of the module name. + * Structure of 'paths' compiler options + * 'paths': { + * pattern-1: [...substitutions], + * pattern-2: [...substitutions], + * ... + * pattern-n: [...substitutions] + * } + * Pattern here is a string that can contain zero or one '*' character. During module resolution module name will be matched against + * all patterns in the list. Matching for patterns that don't contain '*' means that module name must be equal to pattern respecting the case. + * If pattern contains '*' then to match pattern "*" module name must start with the and end with . + * denotes part of the module name between and . + * If module name can be matches with multiple patterns then pattern with the longest prefix will be picked. + * After selecting pattern we'll use list of substitutions to get candidate locations of the module and the try to load module + * from the candidate location. + * Substitiution is a string that can contain zero or one '*'. To get candidate location from substitution we'll pick every + * substitution in the list and replace '*' with string. If candidate location is not rooted it + * will be converted to absolute using baseUrl. + * For example: + * baseUrl: /a/b/c + * "paths": { + * // match all module names + * "*": [ + * "*", // use matched name as is, + * // will be looked as /a/b/c/ + * + * "folder1/*" // substitution will convert matched name to 'folder1/', + * // since it is not rooted then final candidate location will be /a/b/c/folder1/ + * ], + * // match module names that start with 'components/' + * "components/*": [ "/root/components/*" ] // substitution will convert /components/folder1/ to '/root/components/folder1/', + * // it is rooted so it will be final candidate location + * } + * + * 'rootDirs' allows the project to be spreaded across multiple locations and resolve modules with relative names as if + * they were in the same location. For example lets say there are two files + * '/local/src/content/file1.ts' + * '/shared/components/contracts/src/content/protocols/file2.ts' + * After bundling content of '/shared/components/contracts/src' will be merged with '/local/src' so + * if file1 has the following import 'import {x} from "./protocols/file2"' it will be resolved successfully in runtime. + * 'rootDirs' provides the way to tell compiler that in order to get the whole project it should behave as if content of all + * root dirs were merged together. + * I.e. for the example above 'rootDirs' will have two entries: [ '/local/src', '/shared/components/contracts/src' ]. + * Compiler wil first convert './protocols/file2' into absolute path relative to the location of containing file: + * '/local/src/content/protocols/file2' and try to load it - failure. + * Then it will search 'rootDirs' looking for a longest matching prefix of this absolute path and if such prefix is found - absolute path will + * be converted to a path relative to found rootDir entry './content/protocols/file2' (*). As a last step compiler will check all remainining + * entries in 'rootDirs', use them to build absolute path out of (*) and try to resolve module from this location. + */ + function tryLoadModuleUsingOptionalResolutionSettings(moduleName: string, containingDirectory: string, loader: ResolutionKindSpecificLoader, + failedLookupLocations: string[], supportedExtensions: string[], state: ModuleResolutionState): string { + + if (moduleHasNonRelativeName(moduleName)) { + return tryLoadModuleUsingBaseUrl(moduleName, loader, failedLookupLocations, supportedExtensions, state); + } + else { + return tryLoadModuleUsingRootDirs(moduleName, containingDirectory, loader, failedLookupLocations, supportedExtensions, state); + } + } + + function tryLoadModuleUsingRootDirs(moduleName: string, containingDirectory: string, loader: ResolutionKindSpecificLoader, + failedLookupLocations: string[], supportedExtensions: string[], state: ModuleResolutionState): string { + + if (!state.compilerOptions.rootDirs) { + return undefined; + } + + if (state.traceEnabled) { + trace(state.host, Diagnostics.rootDirs_option_is_set_using_it_to_resolve_relative_module_name_0, moduleName); + } + + const candidate = normalizePath(combinePaths(containingDirectory, moduleName)); + + let matchedRootDir: string; + let matchedNormalizedPrefix: string; + for (const rootDir of state.compilerOptions.rootDirs) { + // rootDirs are expected to be absolute + // in case of tsconfig.json this will happen automatically - compiler will expand relative names + // using locaton of tsconfig.json as base location + let normalizedRoot = normalizePath(rootDir); + if (!endsWith(normalizedRoot, directorySeparator)) { + normalizedRoot += directorySeparator; + } + const isLongestMatchingPrefix = + startsWith(candidate, normalizedRoot) && + (matchedNormalizedPrefix === undefined || matchedNormalizedPrefix.length < normalizedRoot.length); + + if (state.traceEnabled) { + trace(state.host, Diagnostics.Checking_if_0_is_the_longest_matching_prefix_for_1_2, normalizedRoot, candidate, isLongestMatchingPrefix); + } + + if (isLongestMatchingPrefix) { + matchedNormalizedPrefix = normalizedRoot; + matchedRootDir = rootDir; + } + } + if (matchedNormalizedPrefix) { + if (state.traceEnabled) { + trace(state.host, Diagnostics.Longest_matching_prefix_for_0_is_1, candidate, matchedNormalizedPrefix); + } + const suffix = candidate.substr(matchedNormalizedPrefix.length); + + // first - try to load from a initial location + if (state.traceEnabled) { + trace(state.host, Diagnostics.Loading_0_from_the_root_dir_1_candidate_location_2, suffix, matchedNormalizedPrefix, candidate); + } + const resolvedFileName = loader(candidate, supportedExtensions, failedLookupLocations, !directoryProbablyExists(containingDirectory, state.host), state); + if (resolvedFileName) { + return resolvedFileName; + } + + if (state.traceEnabled) { + trace(state.host, Diagnostics.Trying_other_entries_in_rootDirs); + } + // then try to resolve using remaining entries in rootDirs + for (const rootDir of state.compilerOptions.rootDirs) { + if (rootDir === matchedRootDir) { + // skip the initially matched entry + continue; + } + const candidate = combinePaths(normalizePath(rootDir), suffix); + if (state.traceEnabled) { + trace(state.host, Diagnostics.Loading_0_from_the_root_dir_1_candidate_location_2, suffix, rootDir, candidate); + } + const baseDirectory = getDirectoryPath(candidate); + const resolvedFileName = loader(candidate, supportedExtensions, failedLookupLocations, !directoryProbablyExists(baseDirectory, state.host), state); + if (resolvedFileName) { + return resolvedFileName; + } + } + if (state.traceEnabled) { + trace(state.host, Diagnostics.Module_resolution_using_rootDirs_has_failed); + } + } + return undefined; + } + + function tryLoadModuleUsingBaseUrl(moduleName: string, loader: ResolutionKindSpecificLoader, failedLookupLocations: string[], + supportedExtensions: string[], state: ModuleResolutionState): string { + + if (!state.compilerOptions.baseUrl) { + return undefined; + } + if (state.traceEnabled) { + trace(state.host, Diagnostics.baseUrl_option_is_set_to_0_using_this_value_to_resolve_non_relative_module_name_1, state.compilerOptions.baseUrl, moduleName); + } + + let longestMatchPrefixLength = -1; + let matchedPattern: string; + let matchedStar: string; + + if (state.compilerOptions.paths) { + if (state.traceEnabled) { + trace(state.host, Diagnostics.paths_option_is_specified_looking_for_a_pattern_to_match_module_name_0, moduleName); + } + + for (const key in state.compilerOptions.paths) { + const pattern: string = key; + const indexOfStar = pattern.indexOf("*"); + if (indexOfStar !== -1) { + const prefix = pattern.substr(0, indexOfStar); + const suffix = pattern.substr(indexOfStar + 1); + if (moduleName.length >= prefix.length + suffix.length && + startsWith(moduleName, prefix) && + endsWith(moduleName, suffix)) { + + // use length of prefix as betterness criteria + if (prefix.length > longestMatchPrefixLength) { + longestMatchPrefixLength = prefix.length; + matchedPattern = pattern; + matchedStar = moduleName.substr(prefix.length, moduleName.length - suffix.length); + } + } + } + else if (pattern === moduleName) { + // pattern was matched as is - no need to seatch further + matchedPattern = pattern; + matchedStar = undefined; + break; + } + } + } + + if (matchedPattern) { + if (state.traceEnabled) { + trace(state.host, Diagnostics.Module_name_0_matched_pattern_1, moduleName, matchedPattern); + } + for (const subst of state.compilerOptions.paths[matchedPattern]) { + const path = matchedStar ? subst.replace("\*", matchedStar) : subst; + const candidate = normalizePath(combinePaths(state.compilerOptions.baseUrl, path)); + if (state.traceEnabled) { + trace(state.host, Diagnostics.Trying_substitution_0_candidate_module_location_Colon_1, subst, path); + } + const resolvedFileName = loader(candidate, supportedExtensions, failedLookupLocations, !directoryProbablyExists(getDirectoryPath(candidate), state.host), state); + if (resolvedFileName) { + return resolvedFileName; + } + } + return undefined; + } + else { + const candidate = normalizePath(combinePaths(state.compilerOptions.baseUrl, moduleName)); + + if (state.traceEnabled) { + trace(state.host, Diagnostics.Resolving_module_name_0_relative_to_base_url_1_2, moduleName, state.compilerOptions.baseUrl, candidate); + } + + return loader(candidate, supportedExtensions, failedLookupLocations, !directoryProbablyExists(getDirectoryPath(candidate), state.host), state); } } export function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { const containingDirectory = getDirectoryPath(containingFile); const supportedExtensions = getSupportedExtensions(compilerOptions); - if (getRootLength(moduleName) !== 0 || nameStartsWithDotSlashOrDotDotSlash(moduleName)) { - const failedLookupLocations: string[] = []; - const candidate = normalizePath(combinePaths(containingDirectory, moduleName)); - let resolvedFileName = loadNodeModuleFromFile(supportedExtensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, host); + const traceEnabled = isTraceEnabled(compilerOptions, host); - if (resolvedFileName) { - return { resolvedModule: { resolvedFileName }, failedLookupLocations }; - } + const failedLookupLocations: string[] = []; + const state = {compilerOptions, host, traceEnabled, skipTsx: false}; + let resolvedFileName = tryLoadModuleUsingOptionalResolutionSettings(moduleName, containingDirectory, nodeLoadModuleByRelativeName, + failedLookupLocations, supportedExtensions, state); - resolvedFileName = loadNodeModuleFromDirectory(supportedExtensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, host); - return resolvedFileName - ? { resolvedModule: { resolvedFileName }, failedLookupLocations } - : { resolvedModule: undefined, failedLookupLocations }; + if (resolvedFileName) { + return createResolvedModule(resolvedFileName, /*isExternalLibraryImport*/false, failedLookupLocations); + } + + let isExternalLibraryImport = false; + if (moduleHasNonRelativeName(moduleName)) { + if (traceEnabled) { + trace(host, Diagnostics.Loading_module_0_from_node_modules_folder, moduleName); + } + resolvedFileName = loadModuleFromNodeModules(moduleName, containingDirectory, failedLookupLocations, state); + isExternalLibraryImport = resolvedFileName !== undefined; } else { - return loadModuleFromNodeModules(moduleName, containingDirectory, host); + const candidate = normalizePath(combinePaths(containingDirectory, moduleName)); + resolvedFileName = nodeLoadModuleByRelativeName(candidate, supportedExtensions, failedLookupLocations, /*onlyRecordFailures*/ false, state); } + return createResolvedModule(resolvedFileName, isExternalLibraryImport, failedLookupLocations); + } + + function nodeLoadModuleByRelativeName(candidate: string, supportedExtensions: string[], failedLookupLocations: string[], + onlyRecordFailures: boolean, state: ModuleResolutionState): string { + + if (state.traceEnabled) { + trace(state.host, Diagnostics.Loading_module_as_file_Slash_folder_candidate_module_location_0, candidate); + } + + const resolvedFileName = loadModuleFromFile(candidate, supportedExtensions, failedLookupLocations, onlyRecordFailures, state); + + return resolvedFileName || loadNodeModuleFromDirectory(supportedExtensions, candidate, failedLookupLocations, onlyRecordFailures, state); } /* @internal */ @@ -77,73 +414,99 @@ namespace ts { /** * @param {boolean} onlyRecordFailures - if true then function won't try to actually load files but instead record all attempts as failures. This flag is necessary - * in cases when we know upfront that all load attempts will fail (because containing folder does not exists) however we still need to record all failed lookup locations. + * in cases when we know upfront that all load attempts will fail (because containing folder does not exists) however we still need to record all failed lookup locations. */ - function loadNodeModuleFromFile(extensions: string[], candidate: string, failedLookupLocation: string[], onlyRecordFailures: boolean, host: ModuleResolutionHost): string { + function loadModuleFromFile(candidate: string, extensions: string[], failedLookupLocation: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): string { return forEach(extensions, tryLoad); function tryLoad(ext: string): string { + if (ext === ".tsx" && state.skipTsx) { + return undefined; + } const fileName = fileExtensionIs(candidate, ext) ? candidate : candidate + ext; - if (!onlyRecordFailures && host.fileExists(fileName)) { + if (!onlyRecordFailures && state.host.fileExists(fileName)) { + if (state.traceEnabled) { + trace(state.host, Diagnostics.File_0_exist_use_it_as_a_module_resolution_result, fileName); + } return fileName; } else { + if (state.traceEnabled) { + trace(state.host, Diagnostics.File_0_does_not_exist, fileName); + } failedLookupLocation.push(fileName); return undefined; } } } - function loadNodeModuleFromDirectory(extensions: string[], candidate: string, failedLookupLocation: string[], onlyRecordFailures: boolean, host: ModuleResolutionHost): string { + function loadNodeModuleFromDirectory(extensions: string[], candidate: string, failedLookupLocation: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): string { const packageJsonPath = combinePaths(candidate, "package.json"); - const directoryExists = !onlyRecordFailures && directoryProbablyExists(candidate, host); - if (directoryExists && host.fileExists(packageJsonPath)) { + const directoryExists = !onlyRecordFailures && directoryProbablyExists(candidate, state.host); + if (directoryExists && state.host.fileExists(packageJsonPath)) { + if (state.traceEnabled) { + trace(state.host, Diagnostics.Found_package_json_at_0, packageJsonPath); + } let jsonContent: { typings?: string }; try { - const jsonText = host.readFile(packageJsonPath); + const jsonText = state.host.readFile(packageJsonPath); jsonContent = jsonText ? <{ typings?: string }>JSON.parse(jsonText) : { typings: undefined }; } catch (e) { - // gracefully handle if readFile fails or returns not JSON + // gracefully handle if readFile fails or returns not JSON jsonContent = { typings: undefined }; } - if (typeof jsonContent.typings === "string") { - const path = normalizePath(combinePaths(candidate, jsonContent.typings)); - const result = loadNodeModuleFromFile(extensions, path, failedLookupLocation, !directoryProbablyExists(getDirectoryPath(path), host), host); - if (result) { - return result; + if (jsonContent.typings) { + if (typeof jsonContent.typings === "string") { + const typingsFile = normalizePath(combinePaths(candidate, jsonContent.typings)); + if (state.traceEnabled) { + trace(state.host, Diagnostics.package_json_has_typings_field_0_that_references_1, jsonContent.typings, typingsFile); + } + const result = loadModuleFromFile(typingsFile, extensions, failedLookupLocation, !directoryProbablyExists(getDirectoryPath(typingsFile), state.host), state); + if (result) { + return result; + } + } + else if (state.traceEnabled) { + trace(state.host, Diagnostics.Expected_type_of_typings_field_in_package_json_to_be_string_got_0, typeof jsonContent.typings); + } + } + else { + if (state.traceEnabled) { + trace(state.host, Diagnostics.package_json_does_not_have_typings_field); } } } else { + if (state.traceEnabled) { + trace(state.host, Diagnostics.File_0_does_not_exist, packageJsonPath); + } // record package json as one of failed lookup locations - in the future if this file will appear it will invalidate resolution results failedLookupLocation.push(packageJsonPath); } - return loadNodeModuleFromFile(extensions, combinePaths(candidate, "index"), failedLookupLocation, !directoryExists, host); + return loadModuleFromFile(combinePaths(candidate, "index"), extensions, failedLookupLocation, !directoryExists, state); } - function loadModuleFromNodeModules(moduleName: string, directory: string, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { - const failedLookupLocations: string[] = []; + function loadModuleFromNodeModules(moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState): string { directory = normalizeSlashes(directory); while (true) { const baseName = getBaseFileName(directory); if (baseName !== "node_modules") { const nodeModulesFolder = combinePaths(directory, "node_modules"); - const nodeModulesFolderExists = directoryProbablyExists(nodeModulesFolder, host); + const nodeModulesFolderExists = directoryProbablyExists(nodeModulesFolder, state.host); const candidate = normalizePath(combinePaths(nodeModulesFolder, moduleName)); // Load only typescript files irrespective of allowJs option if loading from node modules - let result = loadNodeModuleFromFile(supportedTypeScriptExtensions, candidate, failedLookupLocations, !nodeModulesFolderExists, host); + let result = loadModuleFromFile(candidate, supportedTypeScriptExtensions, failedLookupLocations, !nodeModulesFolderExists, state); if (result) { - return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations }; + return result; } - - result = loadNodeModuleFromDirectory(supportedTypeScriptExtensions, candidate, failedLookupLocations, !nodeModulesFolderExists, host); + result = loadNodeModuleFromDirectory(supportedTypeScriptExtensions, candidate, failedLookupLocations, !nodeModulesFolderExists, state); if (result) { - return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations }; + return result; } } @@ -154,56 +517,33 @@ namespace ts { directory = parentPath; } - - return { resolvedModule: undefined, failedLookupLocations }; - } - - function nameStartsWithDotSlashOrDotDotSlash(name: string) { - const i = name.lastIndexOf("./", 1); - return i === 0 || (i === 1 && name.charCodeAt(0) === CharacterCodes.dot); + return undefined; } export function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { + const traceEnabled = isTraceEnabled(compilerOptions, host); + const state = { compilerOptions, host, traceEnabled, skipTsx: !compilerOptions.jsx }; + const failedLookupLocations: string[] = []; + const supportedExtensions = getSupportedExtensions(compilerOptions); + let containingDirectory = getDirectoryPath(containingFile); - // module names that contain '!' are used to reference resources and are not resolved to actual files on disk - if (moduleName.indexOf("!") != -1) { - return { resolvedModule: undefined, failedLookupLocations: [] }; + const resolvedFileName = tryLoadModuleUsingOptionalResolutionSettings(moduleName, containingDirectory, loadModuleFromFile, failedLookupLocations, supportedExtensions, state); + if (resolvedFileName) { + return createResolvedModule(resolvedFileName, /*isExternalLibraryImport*/false, failedLookupLocations); } - let searchPath = getDirectoryPath(containingFile); - let searchName: string; - - const failedLookupLocations: string[] = []; - let referencedSourceFile: string; - const supportedExtensions = getSupportedExtensions(compilerOptions); while (true) { - searchName = normalizePath(combinePaths(searchPath, moduleName)); - referencedSourceFile = forEach(supportedExtensions, extension => { - if (extension === ".tsx" && !compilerOptions.jsx) { - // resolve .tsx files only if jsx support is enabled - // 'logical not' handles both undefined and None cases - return undefined; - } - - const candidate = searchName + extension; - if (host.fileExists(candidate)) { - return candidate; - } - else { - failedLookupLocations.push(candidate); - } - }); - + const searchName = normalizePath(combinePaths(containingDirectory, moduleName)); + referencedSourceFile = loadModuleFromFile(searchName, supportedExtensions, failedLookupLocations, /*onlyRecordFailures*/ false, state); if (referencedSourceFile) { break; } - - const parentPath = getDirectoryPath(searchPath); - if (parentPath === searchPath) { + const parentPath = getDirectoryPath(containingDirectory); + if (parentPath === containingDirectory) { break; } - searchPath = parentPath; + containingDirectory = parentPath; } return referencedSourceFile @@ -295,6 +635,7 @@ namespace ts { getNewLine: () => newLine, fileExists: fileName => sys.fileExists(fileName), readFile: fileName => sys.readFile(fileName), + trace: (s: string) => sys.write(s + newLine), directoryExists: directoryName => sys.directoryExists(directoryName) }; } @@ -382,7 +723,7 @@ namespace ts { const filesByName = createFileMap(); // stores 'filename -> file association' ignoring case - // used to track cases when two file names differ only in casing + // used to track cases when two file names differ only in casing const filesByNameIgnoreCase = host.useCaseSensitiveFileNames() ? createFileMap(fileName => fileName.toLowerCase()) : undefined; if (oldProgram) { @@ -734,8 +1075,11 @@ namespace ts { diagnostics.push(createDiagnosticForNode(node, Diagnostics.import_can_only_be_used_in_a_ts_file)); return true; case SyntaxKind.ExportAssignment: - diagnostics.push(createDiagnosticForNode(node, Diagnostics.export_can_only_be_used_in_a_ts_file)); - return true; + if ((node).isExportEquals) { + diagnostics.push(createDiagnosticForNode(node, Diagnostics.export_can_only_be_used_in_a_ts_file)); + return true; + } + break; case SyntaxKind.ClassDeclaration: let classDeclaration = node; if (checkModifiers(classDeclaration.modifiers) || @@ -857,6 +1201,7 @@ namespace ts { case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: + case SyntaxKind.ReadonlyKeyword: case SyntaxKind.DeclareKeyword: diagnostics.push(createDiagnosticForNode(modifier, Diagnostics._0_can_only_be_used_in_a_ts_file, tokenToString(modifier.kind))); return true; @@ -957,7 +1302,7 @@ namespace ts { } // TypeScript 1.0 spec (April 2014): 12.1.6 - // An ExternalImportDeclaration in an AmbientExternalModuleDeclaration may reference other external modules + // An ExternalImportDeclaration in an AmbientExternalModuleDeclaration may reference other external modules // only through top - level external module names. Relative external module names are not permitted. if (!inAmbientModule || !isExternalModuleNameRelative((moduleNameExpr).text)) { (imports || (imports = [])).push(moduleNameExpr); @@ -975,7 +1320,7 @@ namespace ts { (moduleAugmentations || (moduleAugmentations = [])).push(moduleName); } else if (!inAmbientModule) { - // An AmbientExternalModuleDeclaration declares an external module. + // An AmbientExternalModuleDeclaration declares an external module. // This type of declaration is permitted only in the global module. // The StringLiteral must specify a top - level external module name. // Relative external module names are not permitted @@ -990,7 +1335,7 @@ namespace ts { } function collectRequireCalls(node: Node): void { - if (isRequireCall(node)) { + if (isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) { (imports || (imports = [])).push((node).arguments[0]); } else { @@ -1145,7 +1490,7 @@ namespace ts { if (importedFile && resolution.isExternalLibraryImport) { // Since currently irrespective of allowJs, we only look for supportedTypeScript extension external module files, // this check is ok. Otherwise this would be never true for javascript file - if (!isExternalModule(importedFile)) { + if (!isExternalModule(importedFile) && importedFile.statements.length) { const start = getTokenPosOfNode(file.imports[i], file); fileProcessingDiagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition, importedFile.fileName)); } @@ -1259,6 +1604,26 @@ namespace ts { } } + if (options.paths && options.baseUrl === undefined) { + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_paths_cannot_be_used_without_specifying_baseUrl_option)); + } + + if (options.paths) { + for (const key in options.paths) { + if (!hasProperty(options.paths, key)) { + continue; + } + if (!hasZeroOrOneAsteriskCharacter(key)) { + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Pattern_0_can_have_at_most_one_Asterisk_character, key)); + } + for (const subst of options.paths[key]) { + if (!hasZeroOrOneAsteriskCharacter(subst)) { + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character, subst, key)); + } + } + } + } + if (options.inlineSources) { if (!options.sourceMap && !options.inlineSourceMap) { programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided)); @@ -1355,11 +1720,11 @@ namespace ts { } if (options.reactNamespace && !isIdentifier(options.reactNamespace, languageVersion)) { - programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Invalide_value_for_reactNamespace_0_is_not_a_valid_identifier, options.reactNamespace)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Invalid_value_for_reactNamespace_0_is_not_a_valid_identifier, options.reactNamespace)); } // If the emit is enabled make sure that every output file is unique and not overwriting any of the input files - if (!options.noEmit) { + if (!options.noEmit && !options.suppressOutputPathCheck) { const emitHost = getEmitHost(); const emitFilesSeen = createFileMap(!host.useCaseSensitiveFileNames() ? key => key.toLocaleLowerCase() : undefined); forEachExpectedEmitFile(emitHost, (emitFileNames, sourceFiles, isBundledEmit) => { diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index e716da202505f..4470d7f623c73 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -98,6 +98,7 @@ namespace ts { "private": SyntaxKind.PrivateKeyword, "protected": SyntaxKind.ProtectedKeyword, "public": SyntaxKind.PublicKeyword, + "readonly": SyntaxKind.ReadonlyKeyword, "require": SyntaxKind.RequireKeyword, "global": SyntaxKind.GlobalKeyword, "return": SyntaxKind.ReturnKeyword, diff --git a/src/compiler/sourcemap.ts b/src/compiler/sourcemap.ts index 8abf1432b0c73..86bad38cb6e1f 100644 --- a/src/compiler/sourcemap.ts +++ b/src/compiler/sourcemap.ts @@ -16,6 +16,14 @@ namespace ts { } let nullSourceMapWriter: SourceMapWriter; + // Used for initialize lastEncodedSourceMapSpan and reset lastEncodedSourceMapSpan when updateLastEncodedAndRecordedSpans + const defaultLastEncodedSourceMapSpan: SourceMapSpan = { + emittedLine: 1, + emittedColumn: 1, + sourceLine: 1, + sourceColumn: 1, + sourceIndex: 0 + }; export function getNullSourceMapWriter(): SourceMapWriter { if (nullSourceMapWriter === undefined) { @@ -79,13 +87,7 @@ namespace ts { // Last recorded and encoded spans lastRecordedSourceMapSpan = undefined; - lastEncodedSourceMapSpan = { - emittedLine: 1, - emittedColumn: 1, - sourceLine: 1, - sourceColumn: 1, - sourceIndex: 0 - }; + lastEncodedSourceMapSpan = defaultLastEncodedSourceMapSpan; lastEncodedNameIndex = 0; // Initialize source map data @@ -159,10 +161,12 @@ namespace ts { // Pop sourceMapDecodedMappings to remove last entry sourceMapData.sourceMapDecodedMappings.pop(); - // Change the last encoded source map + // Point the lastEncodedSourceMapSpace to the previous encoded sourceMapSpan + // If the list is empty which indicates that we are at the beginning of the file, + // we have to reset it to default value (same value when we first initialize sourceMapWriter) lastEncodedSourceMapSpan = sourceMapData.sourceMapDecodedMappings.length ? sourceMapData.sourceMapDecodedMappings[sourceMapData.sourceMapDecodedMappings.length - 1] : - undefined; + defaultLastEncodedSourceMapSpan; // TODO: Update lastEncodedNameIndex // Since we dont support this any more, lets not worry about it right now. diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index bf25d39aa4395..9c3972b27566a 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -373,9 +373,6 @@ namespace ts { } } - /** - * @param watcherPath is the path from which the watcher is triggered. - */ function fileEventHandler(eventName: string, relativeFileName: string, baseDirPath: Path) { // When files are deleted from disk, the triggered "rename" event would have a relativefileName of "undefined" const filePath = typeof relativeFileName !== "string" diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 9b2457d091692..889810bebec54 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -376,7 +376,7 @@ namespace ts { sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); return; } - const configParseResult = parseJsonConfigFileContent(configObject, sys, getDirectoryPath(configFileName), commandLine.options); + const configParseResult = parseJsonConfigFileContent(configObject, sys, getNormalizedAbsolutePath(getDirectoryPath(configFileName), sys.getCurrentDirectory()), commandLine.options); if (configParseResult.errors.length > 0) { reportDiagnostics(configParseResult.errors, /* compilerHost */ undefined); sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); @@ -740,7 +740,9 @@ namespace ts { for (const name in options) { if (hasProperty(options, name)) { - const value = options[name]; + // tsconfig only options cannot be specified via command line, + // so we can assume that only types that can appear here string | number | boolean + const value = options[name]; switch (name) { case "init": case "watch": diff --git a/src/compiler/types.ts b/src/compiler/types.ts index ca94060d86900..5545fbd162e73 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -163,6 +163,7 @@ namespace ts { IsKeyword, ModuleKeyword, NamespaceKeyword, + ReadonlyKeyword, RequireKeyword, NumberKeyword, SetKeyword, @@ -369,32 +370,37 @@ namespace ts { } export const enum NodeFlags { - None = 0, - Export = 1 << 1, // Declarations - Ambient = 1 << 2, // Declarations - Public = 1 << 3, // Property/Method - Private = 1 << 4, // Property/Method - Protected = 1 << 5, // Property/Method - Static = 1 << 6, // Property/Method - Abstract = 1 << 7, // Class/Method/ConstructSignature - Async = 1 << 8, // Property/Method/Function - Default = 1 << 9, // Function/Class (export default declaration) - MultiLine = 1 << 10, // Multi-line array or object literal - Synthetic = 1 << 11, // Synthetic node (for full fidelity) - DeclarationFile = 1 << 12, // Node is a .d.ts file - Let = 1 << 13, // Variable declaration - Const = 1 << 14, // Variable declaration - OctalLiteral = 1 << 15, // Octal numeric literal - Namespace = 1 << 16, // Namespace declaration - ExportContext = 1 << 17, // Export context (initialized by binding) - ContainsThis = 1 << 18, // Interface contains references to "this" - HasImplicitReturn = 1 << 19, // If function implicitly returns on one of codepaths (initialized by binding) - HasExplicitReturn = 1 << 20, // If function has explicit reachable return on one of codepaths (initialized by binding) - GlobalAugmentation = 1 << 21, // Set if module declaration is an augmentation for the global scope - HasClassExtends = 1 << 22, // If the file has a non-ambient class with an extends clause in ES5 or lower (initialized by binding) - HasDecorators = 1 << 23, // If the file has decorators (initialized by binding) - HasParamDecorators = 1 << 24, // If the file has parameter decorators (initialized by binding) - HasAsyncFunctions = 1 << 25, // If the file has async functions (initialized by binding) + None = 0, + Export = 1 << 0, // Declarations + Ambient = 1 << 1, // Declarations + Public = 1 << 2, // Property/Method + Private = 1 << 3, // Property/Method + Protected = 1 << 4, // Property/Method + Static = 1 << 5, // Property/Method + Readonly = 1 << 6, // Property/Method + Abstract = 1 << 7, // Class/Method/ConstructSignature + Async = 1 << 8, // Property/Method/Function + Default = 1 << 9, // Function/Class (export default declaration) + Let = 1 << 10, // Variable declaration + Const = 1 << 11, // Variable declaration + Namespace = 1 << 12, // Namespace declaration + ExportContext = 1 << 13, // Export context (initialized by binding) + ContainsThis = 1 << 14, // Interface contains references to "this" + HasImplicitReturn = 1 << 15, // If function implicitly returns on one of codepaths (initialized by binding) + HasExplicitReturn = 1 << 16, // If function has explicit reachable return on one of codepaths (initialized by binding) + GlobalAugmentation = 1 << 17, // Set if module declaration is an augmentation for the global scope + HasClassExtends = 1 << 18, // If the file has a non-ambient class with an extends clause in ES5 or lower (initialized by binding) + HasDecorators = 1 << 19, // If the file has decorators (initialized by binding) + HasParamDecorators = 1 << 20, // If the file has parameter decorators (initialized by binding) + HasAsyncFunctions = 1 << 21, // If the file has async functions (initialized by binding) + DisallowInContext = 1 << 22, // If node was parsed in a context where 'in-expressions' are not allowed + YieldContext = 1 << 23, // If node was parsed in the 'yield' context created when parsing a generator + DecoratorContext = 1 << 24, // If node was parsed as part of a decorator + AwaitContext = 1 << 25, // If node was parsed in the 'await' context created when parsing an async function + ThisNodeHasError = 1 << 26, // If the parser encountered an error when parsing the code that created this node + JavaScriptFile = 1 << 27, // If node was parsed in a JavaScript + ThisNodeOrAnySubNodesHasError = 1 << 28, // If this node or any of its children had an error + HasAggregatedChildData = 1 << 29, // If we've computed data from children and cached it in this node Modifier = Export | Ambient | Public | Private | Protected | Static | Abstract | Default | Async, AccessibilityModifier = Public | Private | Protected, @@ -402,47 +408,12 @@ namespace ts { ReachabilityCheckFlags = HasImplicitReturn | HasExplicitReturn, EmitHelperFlags = HasClassExtends | HasDecorators | HasParamDecorators | HasAsyncFunctions, - } - - /* @internal */ - export const enum ParserContextFlags { - None = 0, - - // If this node was parsed in a context where 'in-expressions' are not allowed. - DisallowIn = 1 << 0, - - // If this node was parsed in the 'yield' context created when parsing a generator. - Yield = 1 << 1, - // If this node was parsed as part of a decorator - Decorator = 1 << 2, - - // If this node was parsed in the 'await' context created when parsing an async function. - Await = 1 << 3, - - // If the parser encountered an error when parsing the code that created this node. Note - // the parser only sets this directly on the node it creates right after encountering the - // error. - ThisNodeHasError = 1 << 4, - - // This node was parsed in a JavaScript file and can be processed differently. For example - // its type can be specified usign a JSDoc comment. - JavaScriptFile = 1 << 5, - - // Context flags set directly by the parser. - ParserGeneratedFlags = DisallowIn | Yield | Decorator | ThisNodeHasError | Await, + // Parsing context flags + ContextFlags = DisallowInContext | YieldContext | DecoratorContext | AwaitContext, // Exclude these flags when parsing a Type - TypeExcludesFlags = Yield | Await, - - // Context flags computed by aggregating child flags upwards. - - // Used during incremental parsing to determine if this node or any of its children had an - // error. Computed only once and then cached. - ThisNodeOrAnySubNodesHasError = 1 << 6, - - // Used to know if we've computed data from children and cached it in this node. - HasAggregatedChildData = 1 << 7 + TypeExcludesFlags = YieldContext | AwaitContext, } export const enum JsxFlags { @@ -470,9 +441,6 @@ namespace ts { export interface Node extends TextRange { kind: SyntaxKind; flags: NodeFlags; - // Specific context the parser was in when this node was created. Normally undefined. - // Only set when the parser was in some interesting context (like async/yield). - /* @internal */ parserContextFlags?: ParserContextFlags; decorators?: NodeArray; // Array of decorators (in document order) modifiers?: ModifiersArray; // Array of modifiers /* @internal */ id?: number; // Unique id (used to look up NodeLinks) @@ -936,6 +904,8 @@ namespace ts { text: string; isUnterminated?: boolean; hasExtendedUnicodeEscape?: boolean; + /* @internal */ + isOctalLiteral?: boolean; } // The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral, @@ -977,6 +947,8 @@ namespace ts { // @kind(SyntaxKind.ArrayLiteralExpression) export interface ArrayLiteralExpression extends PrimaryExpression { elements: NodeArray; + /* @internal */ + multiLine?: boolean; } // @kind(SyntaxKind.SpreadElementExpression) @@ -988,6 +960,8 @@ namespace ts { // @kind(SyntaxKind.ObjectLiteralExpression) export interface ObjectLiteralExpression extends PrimaryExpression, Declaration { properties: NodeArray; + /* @internal */ + multiLine?: boolean; } // @kind(SyntaxKind.PropertyAccessExpression) @@ -1544,6 +1518,7 @@ namespace ts { moduleName: string; referencedFiles: FileReference[]; languageVariant: LanguageVariant; + isDeclarationFile: boolean; // this map is used by transpiler to supply alternative names for dependencies (i.e. in case of bundling) /* @internal */ @@ -1901,8 +1876,8 @@ namespace ts { hasGlobalName(name: string): boolean; getReferencedExportContainer(node: Identifier): SourceFile | ModuleDeclaration | EnumDeclaration; getReferencedImportDeclaration(node: Identifier): Declaration; - getReferencedNestedRedeclaration(node: Identifier): Declaration; - isNestedRedeclaration(node: Declaration): boolean; + getReferencedDeclarationWithCollidingName(node: Identifier): Declaration; + isDeclarationWithCollidingName(node: Declaration): boolean; isValueAliasDeclaration(node: Node): boolean; isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; @@ -2038,7 +2013,7 @@ namespace ts { containingType?: UnionOrIntersectionType; // Containing union or intersection type for synthetic property resolvedExports?: SymbolTable; // Resolved exports of module exportsChecked?: boolean; // True if exports of external module have been checked - isNestedRedeclaration?: boolean; // True if symbol is block scoped redeclaration + isDeclaratonWithCollidingName?: boolean; // True if symbol is block scoped redeclaration bindingElement?: BindingElement; // Binding element associated with property symbol exportsSomeValue?: boolean; // true if module exports some value (not just types) } @@ -2052,20 +2027,23 @@ namespace ts { /* @internal */ export const enum NodeCheckFlags { - TypeChecked = 0x00000001, // Node has been type checked - LexicalThis = 0x00000002, // Lexical 'this' reference - CaptureThis = 0x00000004, // Lexical 'this' used in body - SuperInstance = 0x00000100, // Instance 'super' reference - SuperStatic = 0x00000200, // Static 'super' reference - ContextChecked = 0x00000400, // Contextual types have been assigned - LexicalArguments = 0x00000800, - CaptureArguments = 0x00001000, // Lexical 'arguments' used in body (for async functions) - - // Values for enum members have been computed, and any errors have been reported for them. - EnumValuesComputed = 0x00002000, - BlockScopedBindingInLoop = 0x00004000, - LexicalModuleMergesWithClass = 0x00008000, // Instantiated lexical module declaration is merged with a previous class declaration. - LoopWithBlockScopedBindingCapturedInFunction = 0x00010000, // Loop that contains block scoped variable captured in closure + TypeChecked = 0x00000001, // Node has been type checked + LexicalThis = 0x00000002, // Lexical 'this' reference + CaptureThis = 0x00000004, // Lexical 'this' used in body + SuperInstance = 0x00000100, // Instance 'super' reference + SuperStatic = 0x00000200, // Static 'super' reference + ContextChecked = 0x00000400, // Contextual types have been assigned + AsyncMethodWithSuper = 0x00000800, // An async method that reads a value from a member of 'super'. + AsyncMethodWithSuperBinding = 0x00001000, // An async method that assigns a value to a member of 'super'. + CaptureArguments = 0x00002000, // Lexical 'arguments' used in body (for async functions) + EnumValuesComputed = 0x00004000, // Values for enum members have been computed, and any errors have been reported for them. + LexicalModuleMergesWithClass = 0x00008000, // Instantiated lexical module declaration is merged with a previous class declaration. + LoopWithCapturedBlockScopedBinding = 0x00010000, // Loop that contains block scoped variable captured in closure + CapturedBlockScopedBinding = 0x00020000, // Block-scoped binding that is captured in some function + BlockScopedBindingInLoop = 0x00040000, // Block-scoped binding with declaration nested inside iteration statement + HasSeenSuperCall = 0x00080000, // Set during the binding when encounter 'super' + ClassWithBodyScopedClassBinding = 0x00100000, // Decorated class that contains a binding to itself inside of the class body. + BodyScopedClassBinding = 0x00200000, // Binding to a decorated class inside of the class's body. } /* @internal */ @@ -2074,6 +2052,7 @@ namespace ts { resolvedAwaitedType?: Type; // Cached awaited type of type node resolvedSignature?: Signature; // Cached signature of signature node or call expression resolvedSymbol?: Symbol; // Cached name resolution result + resolvedIndexInfo?: IndexInfo; // Cached indexing info resolution result flags?: NodeCheckFlags; // Set of flags specific to Node enumMemberValue?: number; // Constant value of enum member isVisible?: boolean; // Is this node visible @@ -2181,8 +2160,8 @@ namespace ts { declaredProperties: Symbol[]; // Declared members declaredCallSignatures: Signature[]; // Declared call signatures declaredConstructSignatures: Signature[]; // Declared construct signatures - declaredStringIndexType: Type; // Declared string index type - declaredNumberIndexType: Type; // Declared numeric index type + declaredStringIndexInfo: IndexInfo; // Declared string indexing info + declaredNumberIndexInfo: IndexInfo; // Declared numeric indexing info } // Type references (TypeFlags.Reference). When a class or interface has type parameters or @@ -2234,8 +2213,8 @@ namespace ts { properties: Symbol[]; // Properties callSignatures: Signature[]; // Call signatures of type constructSignatures: Signature[]; // Construct signatures of type - stringIndexType?: Type; // String index type - numberIndexType?: Type; // Numeric index type + stringIndexInfo?: IndexInfo; // String indexing info + numberIndexInfo?: IndexInfo; // Numeric indexing info } /* @internal */ @@ -2298,6 +2277,12 @@ namespace ts { Number, } + export interface IndexInfo { + type: Type; + isReadonly: boolean; + declaration?: SignatureDeclaration; + } + /* @internal */ export interface TypeMapper { (t: TypeParameter): Type; @@ -2374,11 +2359,15 @@ namespace ts { Message, } - export const enum ModuleResolutionKind { + export enum ModuleResolutionKind { Classic = 1, - NodeJs = 2 + NodeJs = 2 } + export type RootPaths = string[]; + export type PathSubstitutions = Map; + export type TsConfigOnlyOptions = RootPaths | PathSubstitutions; + export interface CompilerOptions { allowNonTsExtensions?: boolean; charset?: string; @@ -2427,17 +2416,23 @@ namespace ts { noImplicitReturns?: boolean; noFallthroughCasesInSwitch?: boolean; forceConsistentCasingInFileNames?: boolean; + baseUrl?: string; + paths?: PathSubstitutions; + rootDirs?: RootPaths; + traceModuleResolution?: boolean; allowSyntheticDefaultImports?: boolean; allowJs?: boolean; /* @internal */ stripInternal?: boolean; // Skip checking lib.d.ts to help speed up tests. /* @internal */ skipDefaultLibCheck?: boolean; + // Do not perform validation of output file name in transpile scenarios + /* @internal */ suppressOutputPathCheck?: boolean; - [option: string]: string | number | boolean; + [option: string]: string | number | boolean | TsConfigOnlyOptions; } - export const enum ModuleKind { + export enum ModuleKind { None = 0, CommonJS = 1, AMD = 2, @@ -2494,12 +2489,13 @@ namespace ts { /* @internal */ export interface CommandLineOptionBase { name: string; - type: "string" | "number" | "boolean" | Map; // a value of a primitive type, or an object literal mapping named values to actual values + type: "string" | "number" | "boolean" | "object" | Map; // a value of a primitive type, or an object literal mapping named values to actual values isFilePath?: boolean; // True if option value is a path or fileName shortName?: string; // A short mnemonic for convenience - for instance, 'h' can be used in place of 'help' description?: DiagnosticMessage; // The message describing what the command line switch does paramType?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter experimental?: boolean; + isTSConfigOnly?: boolean; // True if option can only be specified via tsconfig.json file } /* @internal */ @@ -2514,7 +2510,12 @@ namespace ts { } /* @internal */ - export type CommandLineOption = CommandLineOptionOfCustomType | CommandLineOptionOfPrimitiveType; + export interface TsConfigOnlyOption extends CommandLineOptionBase { + type: "object"; + } + + /* @internal */ + export type CommandLineOption = CommandLineOptionOfCustomType | CommandLineOptionOfPrimitiveType | TsConfigOnlyOption; /* @internal */ export const enum CharacterCodes { @@ -2658,7 +2659,7 @@ namespace ts { // readFile function is used to read arbitrary text files on disk, i.e. when resolution procedure needs the content of 'package.json' // to determine location of bundled typings for node module readFile(fileName: string): string; - + trace?(s: string): void; directoryExists?(directoryName: string): boolean; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 4622f92b5df21..02b8385d0ff6c 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -121,26 +121,26 @@ namespace ts { // Returns true if this node contains a parse error anywhere underneath it. export function containsParseError(node: Node): boolean { aggregateChildData(node); - return (node.parserContextFlags & ParserContextFlags.ThisNodeOrAnySubNodesHasError) !== 0; + return (node.flags & NodeFlags.ThisNodeOrAnySubNodesHasError) !== 0; } function aggregateChildData(node: Node): void { - if (!(node.parserContextFlags & ParserContextFlags.HasAggregatedChildData)) { + if (!(node.flags & NodeFlags.HasAggregatedChildData)) { // A node is considered to contain a parse error if: // a) the parser explicitly marked that it had an error // b) any of it's children reported that it had an error. - const thisNodeOrAnySubNodesHasError = ((node.parserContextFlags & ParserContextFlags.ThisNodeHasError) !== 0) || + const thisNodeOrAnySubNodesHasError = ((node.flags & NodeFlags.ThisNodeHasError) !== 0) || forEachChild(node, containsParseError); // If so, mark ourselves accordingly. if (thisNodeOrAnySubNodesHasError) { - node.parserContextFlags |= ParserContextFlags.ThisNodeOrAnySubNodesHasError; + node.flags |= NodeFlags.ThisNodeOrAnySubNodesHasError; } // Also mark that we've propogated the child information to this node. This way we can // always consult the bit directly on this node without needing to check its children // again. - node.parserContextFlags |= ParserContextFlags.HasAggregatedChildData; + node.flags |= NodeFlags.HasAggregatedChildData; } } @@ -151,6 +151,18 @@ namespace ts { return node; } + export function isStatementWithLocals(node: Node) { + switch (node.kind) { + case SyntaxKind.Block: + case SyntaxKind.CaseBlock: + case SyntaxKind.ForStatement: + case SyntaxKind.ForInStatement: + case SyntaxKind.ForOfStatement: + return true; + } + return false; + } + export function getStartPositionOfLine(line: number, sourceFile: SourceFile): number { Debug.assert(line >= 0); return getLineStarts(sourceFile)[line]; @@ -256,6 +268,13 @@ namespace ts { ((node).name.kind === SyntaxKind.StringLiteral || isGlobalScopeAugmentation(node)); } + export function isBlockScopedContainerTopLevel(node: Node): boolean { + return node.kind === SyntaxKind.SourceFile || + node.kind === SyntaxKind.ModuleDeclaration || + isFunctionLike(node) || + isFunctionBlock(node); + } + export function isGlobalScopeAugmentation(module: ModuleDeclaration): boolean { return !!(module.flags & NodeFlags.GlobalAugmentation); } @@ -395,7 +414,7 @@ namespace ts { } export function isDeclarationFile(file: SourceFile): boolean { - return (file.flags & NodeFlags.DeclarationFile) !== 0; + return file.isDeclarationFile; } export function isConstEnumDeclaration(node: Node): boolean { @@ -850,6 +869,16 @@ namespace ts { } } + /** + * Determines whether a node is a property or element access expression for super. + */ + export function isSuperPropertyOrElementAccess(node: Node) { + return (node.kind === SyntaxKind.PropertyAccessExpression + || node.kind === SyntaxKind.ElementAccessExpression) + && (node).expression.kind === SyntaxKind.SuperKeyword; + } + + export function getEntityNameFromTypeNode(node: TypeNode): EntityName | Expression { if (node) { switch (node.kind) { @@ -1049,7 +1078,7 @@ namespace ts { } export function isInJavaScriptFile(node: Node): boolean { - return node && !!(node.parserContextFlags & ParserContextFlags.JavaScriptFile); + return node && !!(node.flags & NodeFlags.JavaScriptFile); } /** @@ -1057,12 +1086,14 @@ namespace ts { * exactly one argument. * This function does not test if the node is in a JavaScript file or not. */ - export function isRequireCall(expression: Node): expression is CallExpression { + export function isRequireCall(expression: Node, checkArgumentIsStringLiteral: boolean): expression is CallExpression { // of the form 'require("name")' - return expression.kind === SyntaxKind.CallExpression && - (expression).expression.kind === SyntaxKind.Identifier && - ((expression).expression).text === "require" && - (expression).arguments.length === 1; + const isRequire = expression.kind === SyntaxKind.CallExpression && + (expression).expression.kind === SyntaxKind.Identifier && + ((expression).expression).text === "require" && + (expression).arguments.length === 1; + + return isRequire && (!checkArgumentIsStringLiteral || (expression).arguments[0].kind === SyntaxKind.StringLiteral); } /// Given a BinaryExpression, returns SpecialPropertyAssignmentKind for the various kinds of property @@ -1176,7 +1207,19 @@ namespace ts { node.parent.parent.parent.kind === SyntaxKind.VariableStatement; const variableStatementNode = isInitializerOfVariableDeclarationInStatement ? node.parent.parent.parent : undefined; - return variableStatementNode && variableStatementNode.jsDocComment; + if (variableStatementNode) { + return variableStatementNode.jsDocComment; + } + + // Also recognize when the node is the RHS of an assignment expression + const isSourceOfAssignmentExpressionStatement = + node.parent && node.parent.parent && + node.parent.kind === SyntaxKind.BinaryExpression && + (node.parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken && + node.parent.parent.kind === SyntaxKind.ExpressionStatement; + if (isSourceOfAssignmentExpressionStatement) { + return node.parent.parent.jsDocComment; + } } return undefined; @@ -1223,7 +1266,7 @@ namespace ts { export function isRestParameter(node: ParameterDeclaration) { if (node) { - if (node.parserContextFlags & ParserContextFlags.JavaScriptFile) { + if (node.flags & NodeFlags.JavaScriptFile) { if (node.type && node.type.kind === SyntaxKind.JSDocVariadicType) { return true; } @@ -1266,10 +1309,9 @@ namespace ts { export function isInAmbientContext(node: Node): boolean { while (node) { - if (node.flags & (NodeFlags.Ambient | NodeFlags.DeclarationFile)) { + if (node.flags & NodeFlags.Ambient || (node.kind === SyntaxKind.SourceFile && (node as SourceFile).isDeclarationFile)) { return true; } - node = node.parent; } return false; @@ -1582,6 +1624,7 @@ namespace ts { case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: + case SyntaxKind.ReadonlyKeyword: case SyntaxKind.StaticKeyword: return true; } @@ -2313,6 +2356,7 @@ namespace ts { case SyntaxKind.ConstKeyword: return NodeFlags.Const; case SyntaxKind.DefaultKeyword: return NodeFlags.Default; case SyntaxKind.AsyncKeyword: return NodeFlags.Async; + case SyntaxKind.ReadonlyKeyword: return NodeFlags.Readonly; } return 0; } diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index d1566c05d4e3c..8b19955941225 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -49,7 +49,6 @@ class CompilerBaselineRunner extends RunnerBase { // Mocha holds onto the closure environment of the describe callback even after the test is done. // Everything declared here should be cleared out in the "after" callback. let justName: string; - let lastUnit: Harness.TestCaseParser.TestUnitData; let harnessSettings: Harness.TestCaseParser.CompilerSettings; let hasNonDtsFiles: boolean; @@ -64,17 +63,31 @@ class CompilerBaselineRunner extends RunnerBase { before(() => { justName = fileName.replace(/^.*[\\\/]/, ""); // strips the fileName from the path. const content = Harness.IO.readFile(fileName); - const testCaseContent = Harness.TestCaseParser.makeUnitsFromTest(content, fileName); + const rootDir = fileName.indexOf("conformance") === -1 ? "tests/cases/compiler/" : ts.getDirectoryPath(fileName) + "/"; + const testCaseContent = Harness.TestCaseParser.makeUnitsFromTest(content, fileName, rootDir); const units = testCaseContent.testUnitData; harnessSettings = testCaseContent.settings; + let tsConfigOptions: ts.CompilerOptions; + if (testCaseContent.tsConfig) { + assert.equal(testCaseContent.tsConfig.fileNames.length, 0, `list of files in tsconfig is not currently supported`); + + tsConfigOptions = ts.clone(testCaseContent.tsConfig.options); + } + else { + const baseUrl = harnessSettings["baseUrl"]; + if (baseUrl !== undefined && !ts.isRootedDiskPath(baseUrl)) { + harnessSettings["baseUrl"] = ts.getNormalizedAbsolutePath(baseUrl, rootDir); + } + } + lastUnit = units[units.length - 1]; hasNonDtsFiles = ts.forEach(units, unit => !ts.fileExtensionIs(unit.name, ".d.ts")); - const rootDir = lastUnit.originalFilePath.indexOf("conformance") === -1 ? "tests/cases/compiler/" : lastUnit.originalFilePath.substring(0, lastUnit.originalFilePath.lastIndexOf("/")) + "/"; // We need to assemble the list of input files for the compiler and other related files on the 'filesystem' (ie in a multi-file test) // If the last file in a test uses require or a triple slash reference we'll assume all other files will be brought in via references, // otherwise, assume all files are just meant to be in the same compilation session without explicit references to one another. toBeCompiled = []; otherFiles = []; + if (/require\(/.test(lastUnit.content) || /reference\spath/.test(lastUnit.content)) { toBeCompiled.push({ unitName: this.makeUnitName(lastUnit.name, rootDir), content: lastUnit.content }); units.forEach(unit => { @@ -90,7 +103,7 @@ class CompilerBaselineRunner extends RunnerBase { } const output = Harness.Compiler.compileFiles( - toBeCompiled, otherFiles, harnessSettings, /* options */ undefined, /* currentDirectory */ undefined); + toBeCompiled, otherFiles, harnessSettings, /*options*/ tsConfigOptions, /*currentDirectory*/ undefined); options = output.options; result = output.result; @@ -126,6 +139,14 @@ class CompilerBaselineRunner extends RunnerBase { } }); + it (`Correct module resolution tracing for ${fileName}`, () => { + if (options.traceModuleResolution) { + Harness.Baseline.runBaseline("Correct sourcemap content for " + fileName, justName.replace(/\.tsx?$/, ".trace.json"), () => { + return JSON.stringify(result.traceResults || [], undefined, 4); + }); + } + }); + // Source maps? it("Correct sourcemap content for " + fileName, () => { if (options.sourceMap || options.inlineSourceMap) { diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 7fd819731721a..848b0d4e06391 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -245,7 +245,6 @@ namespace Utils { } function getNodeFlagName(f: number) { return getFlagName((ts).NodeFlags, f); } - function getParserContextFlagName(f: number) { return getFlagName((ts).ParserContextFlags, f); } function serializeNode(n: ts.Node): any { const o: any = { kind: getKindName(n.kind) }; @@ -274,19 +273,12 @@ namespace Utils { break; case "flags": - // Print out flags with their enum names. - if (n.flags) { - o[propertyName] = getNodeFlagName(n.flags); - } - break; - - case "parserContextFlags": - // Clear the flag that are produced by aggregating child values.. That is ephemeral - // data we don't care about in the dump. We only care what the parser set directly - // on the ast. - let value = n.parserContextFlags & ts.ParserContextFlags.ParserGeneratedFlags; - if (value) { - o[propertyName] = getParserContextFlagName(value); + // Clear the flags that are produced by aggregating child values. That is ephemeral + // data we don't care about in the dump. We only care what the parser set directly + // on the AST. + const flags = n.flags & ~(ts.NodeFlags.JavaScriptFile | ts.NodeFlags.HasAggregatedChildData); + if (flags) { + o[propertyName] = getNodeFlagName(flags); } break; @@ -353,12 +345,11 @@ namespace Utils { assert.equal(node1.pos, node2.pos, "node1.pos !== node2.pos"); assert.equal(node1.end, node2.end, "node1.end !== node2.end"); assert.equal(node1.kind, node2.kind, "node1.kind !== node2.kind"); - assert.equal(node1.flags, node2.flags, "node1.flags !== node2.flags"); // call this on both nodes to ensure all propagated flags have been set (and thus can be // compared). assert.equal(ts.containsParseError(node1), ts.containsParseError(node2)); - assert.equal(node1.parserContextFlags, node2.parserContextFlags, "node1.parserContextFlags !== node2.parserContextFlags"); + assert.equal(node1.flags, node2.flags, "node1.flags !== node2.flags"); ts.forEachChild(node1, child1 => { @@ -985,6 +976,9 @@ namespace Harness { if (harnessSettings) { setCompilerOptionsFromHarnessSetting(harnessSettings, options); } + if (options.rootDirs) { + options.rootDirs = ts.map(options.rootDirs, d => ts.getNormalizedAbsolutePath(d, currentDirectory)); + } const useCaseSensitiveFileNames = options.useCaseSensitiveFileNames !== undefined ? options.useCaseSensitiveFileNames : Harness.IO.useCaseSensitiveFileNames(); const programFiles: TestFile[] = inputFiles.slice(); @@ -1019,13 +1013,19 @@ namespace Harness { useCaseSensitiveFileNames, currentDirectory, options.newLine); + + let traceResults: string[]; + if (options.traceModuleResolution) { + traceResults = []; + compilerHost.trace = text => traceResults.push(text); + } const program = ts.createProgram(programFileNames, options, compilerHost); const emitResult = program.emit(); const errors = ts.getPreEmitDiagnostics(program); - const result = new CompilerResult(fileOutputs, errors, program, Harness.IO.getCurrentDirectory(), emitResult.sourceMaps); + const result = new CompilerResult(fileOutputs, errors, program, Harness.IO.getCurrentDirectory(), emitResult.sourceMaps, traceResults); return { result, options }; } @@ -1306,7 +1306,7 @@ namespace Harness { /** @param fileResults an array of strings for the fileName and an ITextWriter with its code */ constructor(fileResults: GeneratedFile[], errors: ts.Diagnostic[], public program: ts.Program, - public currentDirectoryForProgram: string, private sourceMapData: ts.SourceMapData[]) { + public currentDirectoryForProgram: string, private sourceMapData: ts.SourceMapData[], public traceResults: string[]) { for (const emittedFile of fileResults) { if (isDTS(emittedFile.fileName)) { @@ -1366,7 +1366,7 @@ namespace Harness { } /** Given a test file containing // @FileName directives, return an array of named units of code to be added to an existing compiler instance */ - export function makeUnitsFromTest(code: string, fileName: string): { settings: CompilerSettings; testUnitData: TestUnitData[]; } { + export function makeUnitsFromTest(code: string, fileName: string, rootDir?: string): { settings: CompilerSettings; testUnitData: TestUnitData[]; tsConfig: ts.ParsedCommandLine } { const settings = extractCompilerSettings(code); // List of all the subfiles we've parsed out @@ -1444,7 +1444,31 @@ namespace Harness { }; testUnitData.push(newTestFile2); - return { settings, testUnitData }; + // unit tests always list files explicitly + const parseConfigHost: ts.ParseConfigHost = { + readDirectory: (name) => [] + }; + + // check if project has tsconfig.json in the list of files + let tsConfig: ts.ParsedCommandLine; + for (let i = 0; i < testUnitData.length; i++) { + const data = testUnitData[i]; + if (ts.getBaseFileName(data.name).toLowerCase() === "tsconfig.json") { + const configJson = ts.parseConfigFileTextToJson(data.name, data.content); + assert.isTrue(configJson.config !== undefined); + let baseDir = ts.normalizePath(ts.getDirectoryPath(data.name)); + if (rootDir) { + baseDir = ts.getNormalizedAbsolutePath(baseDir, rootDir); + } + tsConfig = ts.parseJsonConfigFileContent(configJson.config, parseConfigHost, baseDir); + + // delete entry from the list + testUnitData.splice(i, 1); + + break; + } + } + return { settings, testUnitData, tsConfig }; } } diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index a0cac43972952..6ab9cd896c122 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -547,7 +547,8 @@ namespace Harness.LanguageService { } directoryExists(path: string): boolean { - return false; + // for tests assume that directory exists + return true; } getExecutingFilePath(): string { diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index dbd4d37ef966d..31cf0ca31369d 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -2,8 +2,8 @@ /// ECMAScript APIs ///////////////////////////// -declare var NaN: number; -declare var Infinity: number; +declare const NaN: number; +declare const Infinity: number; /** * Evaluates JavaScript code and executes it. @@ -113,7 +113,7 @@ interface ObjectConstructor { (value: any): any; /** A reference to the prototype for a class of objects. */ - prototype: Object; + readonly prototype: Object; /** * Returns the prototype of an object. @@ -204,7 +204,7 @@ interface ObjectConstructor { /** * Provides functionality common to all JavaScript objects. */ -declare var Object: ObjectConstructor; +declare const Object: ObjectConstructor; /** * Creates a new function. @@ -233,7 +233,7 @@ interface Function { bind(thisArg: any, ...argArray: any[]): any; prototype: any; - length: number; + readonly length: number; // Non-standard extensions arguments: any; @@ -247,10 +247,10 @@ interface FunctionConstructor { */ new (...args: string[]): Function; (...args: string[]): Function; - prototype: Function; + readonly prototype: Function; } -declare var Function: FunctionConstructor; +declare const Function: FunctionConstructor; interface IArguments { [index: number]: any; @@ -398,7 +398,7 @@ interface String { trim(): string; /** Returns the length of a String object. */ - length: number; + readonly length: number; // IE extensions /** @@ -411,20 +411,20 @@ interface String { /** Returns the primitive value of the specified object. */ valueOf(): string; - [index: number]: string; + readonly [index: number]: string; } interface StringConstructor { new (value?: any): String; (value?: any): string; - prototype: String; + readonly prototype: String; fromCharCode(...codes: number[]): string; } /** * Allows manipulation and formatting of text strings and determination and location of substrings within strings. */ -declare var String: StringConstructor; +declare const String: StringConstructor; interface Boolean { /** Returns the primitive value of the specified object. */ @@ -434,10 +434,10 @@ interface Boolean { interface BooleanConstructor { new (value?: any): Boolean; (value?: any): boolean; - prototype: Boolean; + readonly prototype: Boolean; } -declare var Boolean: BooleanConstructor; +declare const Boolean: BooleanConstructor; interface Number { /** @@ -471,57 +471,57 @@ interface Number { interface NumberConstructor { new (value?: any): Number; (value?: any): number; - prototype: Number; + readonly prototype: Number; /** The largest number that can be represented in JavaScript. Equal to approximately 1.79E+308. */ - MAX_VALUE: number; + readonly MAX_VALUE: number; /** The closest number to zero that can be represented in JavaScript. Equal to approximately 5.00E-324. */ - MIN_VALUE: number; + readonly MIN_VALUE: number; /** * A value that is not a number. * In equality comparisons, NaN does not equal any value, including itself. To test whether a value is equivalent to NaN, use the isNaN function. */ - NaN: number; + readonly NaN: number; /** * A value that is less than the largest negative number that can be represented in JavaScript. * JavaScript displays NEGATIVE_INFINITY values as -infinity. */ - NEGATIVE_INFINITY: number; + readonly NEGATIVE_INFINITY: number; /** * A value greater than the largest number that can be represented in JavaScript. * JavaScript displays POSITIVE_INFINITY values as infinity. */ - POSITIVE_INFINITY: number; + readonly POSITIVE_INFINITY: number; } /** An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers. */ -declare var Number: NumberConstructor; +declare const Number: NumberConstructor; interface TemplateStringsArray extends Array { - raw: string[]; + readonly raw: string[]; } interface Math { /** The mathematical constant e. This is Euler's number, the base of natural logarithms. */ - E: number; + readonly E: number; /** The natural logarithm of 10. */ - LN10: number; + readonly LN10: number; /** The natural logarithm of 2. */ - LN2: number; + readonly LN2: number; /** The base-2 logarithm of e. */ - LOG2E: number; + readonly LOG2E: number; /** The base-10 logarithm of e. */ - LOG10E: number; + readonly LOG10E: number; /** Pi. This is the ratio of the circumference of a circle to its diameter. */ - PI: number; + readonly PI: number; /** The square root of 0.5, or, equivalently, one divided by the square root of 2. */ - SQRT1_2: number; + readonly SQRT1_2: number; /** The square root of 2. */ - SQRT2: number; + readonly SQRT2: number; /** * Returns the absolute value of a number (the value without regard to whether it is positive or negative). * For example, the absolute value of -5 is the same as the absolute value of 5. @@ -614,7 +614,7 @@ interface Math { tan(x: number): number; } /** An intrinsic object that provides basic mathematics functionality and constants. */ -declare var Math: Math; +declare const Math: Math; /** Enables basic storage and retrieval of dates and times. */ interface Date { @@ -776,7 +776,7 @@ interface DateConstructor { new (value: string): Date; new (year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date; (): string; - prototype: Date; + readonly prototype: Date; /** * Parses a string containing a date, and returns the number of milliseconds between that date and midnight, January 1, 1970. * @param s A date string @@ -796,7 +796,7 @@ interface DateConstructor { now(): number; } -declare var Date: DateConstructor; +declare const Date: DateConstructor; interface RegExpMatchArray extends Array { index?: number; @@ -822,16 +822,16 @@ interface RegExp { test(string: string): boolean; /** Returns a copy of the text of the regular expression pattern. Read-only. The regExp argument is a Regular expression object. It can be a variable name or a literal. */ - source: string; + readonly source: string; /** Returns a Boolean value indicating the state of the global flag (g) used with a regular expression. Default is false. Read-only. */ - global: boolean; + readonly global: boolean; /** Returns a Boolean value indicating the state of the ignoreCase flag (i) used with a regular expression. Default is false. Read-only. */ - ignoreCase: boolean; + readonly ignoreCase: boolean; /** Returns a Boolean value indicating the state of the multiline flag (m) used with a regular expression. Default is false. Read-only. */ - multiline: boolean; + readonly multiline: boolean; lastIndex: number; @@ -842,7 +842,7 @@ interface RegExp { interface RegExpConstructor { new (pattern: string, flags?: string): RegExp; (pattern: string, flags?: string): RegExp; - prototype: RegExp; + readonly prototype: RegExp; // Non-standard extensions $1: string; @@ -857,7 +857,7 @@ interface RegExpConstructor { lastMatch: string; } -declare var RegExp: RegExpConstructor; +declare const RegExp: RegExpConstructor; interface Error { name: string; @@ -867,10 +867,10 @@ interface Error { interface ErrorConstructor { new (message?: string): Error; (message?: string): Error; - prototype: Error; + readonly prototype: Error; } -declare var Error: ErrorConstructor; +declare const Error: ErrorConstructor; interface EvalError extends Error { } @@ -878,10 +878,10 @@ interface EvalError extends Error { interface EvalErrorConstructor { new (message?: string): EvalError; (message?: string): EvalError; - prototype: EvalError; + readonly prototype: EvalError; } -declare var EvalError: EvalErrorConstructor; +declare const EvalError: EvalErrorConstructor; interface RangeError extends Error { } @@ -889,10 +889,10 @@ interface RangeError extends Error { interface RangeErrorConstructor { new (message?: string): RangeError; (message?: string): RangeError; - prototype: RangeError; + readonly prototype: RangeError; } -declare var RangeError: RangeErrorConstructor; +declare const RangeError: RangeErrorConstructor; interface ReferenceError extends Error { } @@ -900,10 +900,10 @@ interface ReferenceError extends Error { interface ReferenceErrorConstructor { new (message?: string): ReferenceError; (message?: string): ReferenceError; - prototype: ReferenceError; + readonly prototype: ReferenceError; } -declare var ReferenceError: ReferenceErrorConstructor; +declare const ReferenceError: ReferenceErrorConstructor; interface SyntaxError extends Error { } @@ -911,10 +911,10 @@ interface SyntaxError extends Error { interface SyntaxErrorConstructor { new (message?: string): SyntaxError; (message?: string): SyntaxError; - prototype: SyntaxError; + readonly prototype: SyntaxError; } -declare var SyntaxError: SyntaxErrorConstructor; +declare const SyntaxError: SyntaxErrorConstructor; interface TypeError extends Error { } @@ -922,10 +922,10 @@ interface TypeError extends Error { interface TypeErrorConstructor { new (message?: string): TypeError; (message?: string): TypeError; - prototype: TypeError; + readonly prototype: TypeError; } -declare var TypeError: TypeErrorConstructor; +declare const TypeError: TypeErrorConstructor; interface URIError extends Error { } @@ -933,10 +933,10 @@ interface URIError extends Error { interface URIErrorConstructor { new (message?: string): URIError; (message?: string): URIError; - prototype: URIError; + readonly prototype: URIError; } -declare var URIError: URIErrorConstructor; +declare const URIError: URIErrorConstructor; interface JSON { /** @@ -981,13 +981,115 @@ interface JSON { /** * An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format. */ -declare var JSON: JSON; +declare const JSON: JSON; ///////////////////////////// /// ECMAScript Array API (specially handled by compiler) ///////////////////////////// +interface ReadonlyArray { + /** + * Gets the length of the array. This is a number one higher than the highest element defined in an array. + */ + readonly length: number; + /** + * Returns a string representation of an array. + */ + toString(): string; + toLocaleString(): string; + /** + * Combines two or more arrays. + * @param items Additional items to add to the end of array1. + */ + concat>(...items: U[]): T[]; + /** + * Combines two or more arrays. + * @param items Additional items to add to the end of array1. + */ + concat(...items: T[]): T[]; + /** + * Adds all the elements of an array separated by the specified separator string. + * @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma. + */ + join(separator?: string): string; + /** + * Returns a section of an array. + * @param start The beginning of the specified portion of the array. + * @param end The end of the specified portion of the array. + */ + slice(start?: number, end?: number): T[]; + /** + * Returns the index of the first occurrence of a value in an array. + * @param searchElement The value to locate in the array. + * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0. + */ + indexOf(searchElement: T, fromIndex?: number): number; + + /** + * Returns the index of the last occurrence of a specified value in an array. + * @param searchElement The value to locate in the array. + * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array. + */ + lastIndexOf(searchElement: T, fromIndex?: number): number; + /** + * Determines whether all the members of an array satisfy the specified test. + * @param callbackfn A function that accepts up to three arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + every(callbackfn: (value: T, index: number, array: ReadonlyArray) => boolean, thisArg?: any): boolean; + /** + * Determines whether the specified callback function returns true for any element of an array. + * @param callbackfn A function that accepts up to three arguments. The some method calls the callbackfn function for each element in array1 until the callbackfn returns true, or until the end of the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + some(callbackfn: (value: T, index: number, array: ReadonlyArray) => boolean, thisArg?: any): boolean; + /** + * Performs the specified action for each element in an array. + * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + forEach(callbackfn: (value: T, index: number, array: ReadonlyArray) => void, thisArg?: any): void; + /** + * Calls a defined callback function on each element of an array, and returns an array that contains the results. + * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + map(callbackfn: (value: T, index: number, array: ReadonlyArray) => U, thisArg?: any): U[]; + /** + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + filter(callbackfn: (value: T, index: number, array: ReadonlyArray) => boolean, thisArg?: any): T[]; + /** + * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. + */ + reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ReadonlyArray) => T, initialValue?: T): T; + /** + * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. + */ + reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: ReadonlyArray) => U, initialValue: U): U; + /** + * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. + */ + reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ReadonlyArray) => T, initialValue?: T): T; + /** + * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. + */ + reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: ReadonlyArray) => U, initialValue: U): U; + + readonly [n: number]: T; +} + interface Array { /** * Gets or sets the length of the array. This is a number one higher than the highest element defined in an array. @@ -1036,19 +1138,16 @@ interface Array { * @param end The end of the specified portion of the array. */ slice(start?: number, end?: number): T[]; - /** * Sorts an array. * @param compareFn The name of the function used to determine the order of the elements. If omitted, the elements are sorted in ascending, ASCII character order. */ sort(compareFn?: (a: T, b: T) => number): T[]; - /** * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. * @param start The zero-based location in the array from which to start removing elements. */ splice(start: number): T[]; - /** * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. * @param start The zero-based location in the array from which to start removing elements. @@ -1056,62 +1155,53 @@ interface Array { * @param items Elements to insert into the array in place of the deleted elements. */ splice(start: number, deleteCount: number, ...items: T[]): T[]; - /** * Inserts new elements at the start of an array. * @param items Elements to insert at the start of the Array. */ unshift(...items: T[]): number; - /** * Returns the index of the first occurrence of a value in an array. * @param searchElement The value to locate in the array. * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0. */ indexOf(searchElement: T, fromIndex?: number): number; - /** * Returns the index of the last occurrence of a specified value in an array. * @param searchElement The value to locate in the array. * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array. */ lastIndexOf(searchElement: T, fromIndex?: number): number; - /** * Determines whether all the members of an array satisfy the specified test. * @param callbackfn A function that accepts up to three arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ every(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; - /** * Determines whether the specified callback function returns true for any element of an array. * @param callbackfn A function that accepts up to three arguments. The some method calls the callbackfn function for each element in array1 until the callbackfn returns true, or until the end of the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ some(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; - /** * Performs the specified action for each element in an array. * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; - /** * Calls a defined callback function on each element of an array, and returns an array that contains the results. * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ map(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; - /** * Returns the elements of an array that meet the condition specified in a callback function. * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ filter(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): T[]; - /** * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. @@ -1124,7 +1214,6 @@ interface Array { * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. */ reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; - /** * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. @@ -1149,10 +1238,10 @@ interface ArrayConstructor { (arrayLength: number): T[]; (...items: T[]): T[]; isArray(arg: any): arg is Array; - prototype: Array; + readonly prototype: Array; } -declare var Array: ArrayConstructor; +declare const Array: ArrayConstructor; interface TypedPropertyDescriptor { enumerable?: boolean; @@ -1182,11 +1271,10 @@ interface PromiseLike { } interface ArrayLike { - length: number; - [n: number]: T; + readonly length: number; + readonly [n: number]: T; } - /** * Represents a raw buffer of binary data, which is used to store data for the * different typed arrays. ArrayBuffers cannot be read from or written to directly, @@ -1197,7 +1285,7 @@ interface ArrayBuffer { /** * Read-only. The length of the ArrayBuffer (in bytes). */ - byteLength: number; + readonly byteLength: number; /** * Returns a section of an ArrayBuffer. @@ -1206,11 +1294,11 @@ interface ArrayBuffer { } interface ArrayBufferConstructor { - prototype: ArrayBuffer; + readonly prototype: ArrayBuffer; new (byteLength: number): ArrayBuffer; isView(arg: any): arg is ArrayBufferView; } -declare var ArrayBuffer: ArrayBufferConstructor; +declare const ArrayBuffer: ArrayBufferConstructor; interface ArrayBufferView { /** @@ -1230,9 +1318,9 @@ interface ArrayBufferView { } interface DataView { - buffer: ArrayBuffer; - byteLength: number; - byteOffset: number; + readonly buffer: ArrayBuffer; + readonly byteLength: number; + readonly byteOffset: number; /** * Gets the Float32 value at the specified byte offset from the start of the view. There is * no alignment constraint; multi-byte values may be fetched from any offset. @@ -1360,7 +1448,7 @@ interface DataView { interface DataViewConstructor { new (buffer: ArrayBuffer, byteOffset?: number, byteLength?: number): DataView; } -declare var DataView: DataViewConstructor; +declare const DataView: DataViewConstructor; /** * A typed array of 8-bit integer values. The contents are initialized to 0. If the requested @@ -1370,22 +1458,22 @@ interface Int8Array { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * The ArrayBuffer instance referenced by the array. */ - buffer: ArrayBuffer; + readonly buffer: ArrayBuffer; /** * The length in bytes of the array. */ - byteLength: number; + readonly byteLength: number; /** * The offset in bytes of the array. */ - byteOffset: number; + readonly byteOffset: number; /** * Returns the this object after copying a section of the array identified by start and end @@ -1484,7 +1572,7 @@ interface Int8Array { /** * The length of the array. */ - length: number; + readonly length: number; /** * Calls a defined callback function on each element of an array, and returns an array that @@ -1608,7 +1696,7 @@ interface Int8Array { [index: number]: number; } interface Int8ArrayConstructor { - prototype: Int8Array; + readonly prototype: Int8Array; new (length: number): Int8Array; new (array: ArrayLike): Int8Array; new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Int8Array; @@ -1616,7 +1704,7 @@ interface Int8ArrayConstructor { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * Returns a new array from a set of elements. @@ -1633,7 +1721,7 @@ interface Int8ArrayConstructor { from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Int8Array; } -declare var Int8Array: Int8ArrayConstructor; +declare const Int8Array: Int8ArrayConstructor; /** * A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the @@ -1643,22 +1731,22 @@ interface Uint8Array { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * The ArrayBuffer instance referenced by the array. */ - buffer: ArrayBuffer; + readonly buffer: ArrayBuffer; /** * The length in bytes of the array. */ - byteLength: number; + readonly byteLength: number; /** * The offset in bytes of the array. */ - byteOffset: number; + readonly byteOffset: number; /** * Returns the this object after copying a section of the array identified by start and end @@ -1757,7 +1845,7 @@ interface Uint8Array { /** * The length of the array. */ - length: number; + readonly length: number; /** * Calls a defined callback function on each element of an array, and returns an array that @@ -1882,7 +1970,7 @@ interface Uint8Array { } interface Uint8ArrayConstructor { - prototype: Uint8Array; + readonly prototype: Uint8Array; new (length: number): Uint8Array; new (array: ArrayLike): Uint8Array; new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint8Array; @@ -1890,7 +1978,7 @@ interface Uint8ArrayConstructor { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * Returns a new array from a set of elements. @@ -1907,7 +1995,7 @@ interface Uint8ArrayConstructor { from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint8Array; } -declare var Uint8Array: Uint8ArrayConstructor; +declare const Uint8Array: Uint8ArrayConstructor; /** * A typed array of 8-bit unsigned integer (clamped) values. The contents are initialized to 0. @@ -1917,22 +2005,22 @@ interface Uint8ClampedArray { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * The ArrayBuffer instance referenced by the array. */ - buffer: ArrayBuffer; + readonly buffer: ArrayBuffer; /** * The length in bytes of the array. */ - byteLength: number; + readonly byteLength: number; /** * The offset in bytes of the array. */ - byteOffset: number; + readonly byteOffset: number; /** * Returns the this object after copying a section of the array identified by start and end @@ -2031,7 +2119,7 @@ interface Uint8ClampedArray { /** * The length of the array. */ - length: number; + readonly length: number; /** * Calls a defined callback function on each element of an array, and returns an array that @@ -2156,7 +2244,7 @@ interface Uint8ClampedArray { } interface Uint8ClampedArrayConstructor { - prototype: Uint8ClampedArray; + readonly prototype: Uint8ClampedArray; new (length: number): Uint8ClampedArray; new (array: ArrayLike): Uint8ClampedArray; new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint8ClampedArray; @@ -2164,7 +2252,7 @@ interface Uint8ClampedArrayConstructor { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * Returns a new array from a set of elements. @@ -2180,7 +2268,7 @@ interface Uint8ClampedArrayConstructor { */ from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint8ClampedArray; } -declare var Uint8ClampedArray: Uint8ClampedArrayConstructor; +declare const Uint8ClampedArray: Uint8ClampedArrayConstructor; /** * A typed array of 16-bit signed integer values. The contents are initialized to 0. If the @@ -2190,22 +2278,22 @@ interface Int16Array { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * The ArrayBuffer instance referenced by the array. */ - buffer: ArrayBuffer; + readonly buffer: ArrayBuffer; /** * The length in bytes of the array. */ - byteLength: number; + readonly byteLength: number; /** * The offset in bytes of the array. */ - byteOffset: number; + readonly byteOffset: number; /** * Returns the this object after copying a section of the array identified by start and end @@ -2304,7 +2392,7 @@ interface Int16Array { /** * The length of the array. */ - length: number; + readonly length: number; /** * Calls a defined callback function on each element of an array, and returns an array that @@ -2429,7 +2517,7 @@ interface Int16Array { } interface Int16ArrayConstructor { - prototype: Int16Array; + readonly prototype: Int16Array; new (length: number): Int16Array; new (array: ArrayLike): Int16Array; new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Int16Array; @@ -2437,7 +2525,7 @@ interface Int16ArrayConstructor { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * Returns a new array from a set of elements. @@ -2454,7 +2542,7 @@ interface Int16ArrayConstructor { from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Int16Array; } -declare var Int16Array: Int16ArrayConstructor; +declare const Int16Array: Int16ArrayConstructor; /** * A typed array of 16-bit unsigned integer values. The contents are initialized to 0. If the @@ -2464,22 +2552,22 @@ interface Uint16Array { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * The ArrayBuffer instance referenced by the array. */ - buffer: ArrayBuffer; + readonly buffer: ArrayBuffer; /** * The length in bytes of the array. */ - byteLength: number; + readonly byteLength: number; /** * The offset in bytes of the array. */ - byteOffset: number; + readonly byteOffset: number; /** * Returns the this object after copying a section of the array identified by start and end @@ -2578,7 +2666,7 @@ interface Uint16Array { /** * The length of the array. */ - length: number; + readonly length: number; /** * Calls a defined callback function on each element of an array, and returns an array that @@ -2703,7 +2791,7 @@ interface Uint16Array { } interface Uint16ArrayConstructor { - prototype: Uint16Array; + readonly prototype: Uint16Array; new (length: number): Uint16Array; new (array: ArrayLike): Uint16Array; new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint16Array; @@ -2711,7 +2799,7 @@ interface Uint16ArrayConstructor { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * Returns a new array from a set of elements. @@ -2728,7 +2816,7 @@ interface Uint16ArrayConstructor { from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint16Array; } -declare var Uint16Array: Uint16ArrayConstructor; +declare const Uint16Array: Uint16ArrayConstructor; /** * A typed array of 32-bit signed integer values. The contents are initialized to 0. If the * requested number of bytes could not be allocated an exception is raised. @@ -2737,22 +2825,22 @@ interface Int32Array { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * The ArrayBuffer instance referenced by the array. */ - buffer: ArrayBuffer; + readonly buffer: ArrayBuffer; /** * The length in bytes of the array. */ - byteLength: number; + readonly byteLength: number; /** * The offset in bytes of the array. */ - byteOffset: number; + readonly byteOffset: number; /** * Returns the this object after copying a section of the array identified by start and end @@ -2851,7 +2939,7 @@ interface Int32Array { /** * The length of the array. */ - length: number; + readonly length: number; /** * Calls a defined callback function on each element of an array, and returns an array that @@ -2976,7 +3064,7 @@ interface Int32Array { } interface Int32ArrayConstructor { - prototype: Int32Array; + readonly prototype: Int32Array; new (length: number): Int32Array; new (array: ArrayLike): Int32Array; new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Int32Array; @@ -2984,7 +3072,7 @@ interface Int32ArrayConstructor { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * Returns a new array from a set of elements. @@ -3000,7 +3088,7 @@ interface Int32ArrayConstructor { */ from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Int32Array; } -declare var Int32Array: Int32ArrayConstructor; +declare const Int32Array: Int32ArrayConstructor; /** * A typed array of 32-bit unsigned integer values. The contents are initialized to 0. If the @@ -3010,22 +3098,22 @@ interface Uint32Array { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * The ArrayBuffer instance referenced by the array. */ - buffer: ArrayBuffer; + readonly buffer: ArrayBuffer; /** * The length in bytes of the array. */ - byteLength: number; + readonly byteLength: number; /** * The offset in bytes of the array. */ - byteOffset: number; + readonly byteOffset: number; /** * Returns the this object after copying a section of the array identified by start and end @@ -3124,7 +3212,7 @@ interface Uint32Array { /** * The length of the array. */ - length: number; + readonly length: number; /** * Calls a defined callback function on each element of an array, and returns an array that @@ -3249,7 +3337,7 @@ interface Uint32Array { } interface Uint32ArrayConstructor { - prototype: Uint32Array; + readonly prototype: Uint32Array; new (length: number): Uint32Array; new (array: ArrayLike): Uint32Array; new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint32Array; @@ -3257,7 +3345,7 @@ interface Uint32ArrayConstructor { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * Returns a new array from a set of elements. @@ -3273,7 +3361,7 @@ interface Uint32ArrayConstructor { */ from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint32Array; } -declare var Uint32Array: Uint32ArrayConstructor; +declare const Uint32Array: Uint32ArrayConstructor; /** * A typed array of 32-bit float values. The contents are initialized to 0. If the requested number @@ -3283,22 +3371,22 @@ interface Float32Array { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * The ArrayBuffer instance referenced by the array. */ - buffer: ArrayBuffer; + readonly buffer: ArrayBuffer; /** * The length in bytes of the array. */ - byteLength: number; + readonly byteLength: number; /** * The offset in bytes of the array. */ - byteOffset: number; + readonly byteOffset: number; /** * Returns the this object after copying a section of the array identified by start and end @@ -3397,7 +3485,7 @@ interface Float32Array { /** * The length of the array. */ - length: number; + readonly length: number; /** * Calls a defined callback function on each element of an array, and returns an array that @@ -3522,7 +3610,7 @@ interface Float32Array { } interface Float32ArrayConstructor { - prototype: Float32Array; + readonly prototype: Float32Array; new (length: number): Float32Array; new (array: ArrayLike): Float32Array; new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Float32Array; @@ -3530,7 +3618,7 @@ interface Float32ArrayConstructor { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * Returns a new array from a set of elements. @@ -3547,7 +3635,7 @@ interface Float32ArrayConstructor { from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Float32Array; } -declare var Float32Array: Float32ArrayConstructor; +declare const Float32Array: Float32ArrayConstructor; /** * A typed array of 64-bit float values. The contents are initialized to 0. If the requested @@ -3557,22 +3645,22 @@ interface Float64Array { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * The ArrayBuffer instance referenced by the array. */ - buffer: ArrayBuffer; + readonly buffer: ArrayBuffer; /** * The length in bytes of the array. */ - byteLength: number; + readonly byteLength: number; /** * The offset in bytes of the array. */ - byteOffset: number; + readonly byteOffset: number; /** * Returns the this object after copying a section of the array identified by start and end @@ -3671,7 +3759,7 @@ interface Float64Array { /** * The length of the array. */ - length: number; + readonly length: number; /** * Calls a defined callback function on each element of an array, and returns an array that @@ -3796,7 +3884,7 @@ interface Float64Array { } interface Float64ArrayConstructor { - prototype: Float64Array; + readonly prototype: Float64Array; new (length: number): Float64Array; new (array: ArrayLike): Float64Array; new (buffer: ArrayBuffer, byteOffset?: number, length?: number): Float64Array; @@ -3804,7 +3892,7 @@ interface Float64ArrayConstructor { /** * The size in bytes of each element in the array. */ - BYTES_PER_ELEMENT: number; + readonly BYTES_PER_ELEMENT: number; /** * Returns a new array from a set of elements. @@ -3820,4 +3908,4 @@ interface Float64ArrayConstructor { */ from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Float64Array; } -declare var Float64Array: Float64ArrayConstructor; +declare const Float64Array: Float64ArrayConstructor; diff --git a/src/lib/dom.generated.d.ts b/src/lib/dom.generated.d.ts index 9970749e5a8d1..ec71fa78e8d73 100644 --- a/src/lib/dom.generated.d.ts +++ b/src/lib/dom.generated.d.ts @@ -378,6 +378,8 @@ interface AudioNode extends EventTarget { numberOfOutputs: number; connect(destination: AudioNode, output?: number, input?: number): void; disconnect(output?: number): void; + disconnect(destination: AudioNode, output?: number, input?: number): void; + disconnect(destination: AudioParam, output?: number): void; } declare var AudioNode: { @@ -6894,7 +6896,7 @@ interface IDBCursor { direction: string; key: any; primaryKey: any; - source: any; + source: IDBObjectStore | IDBIndex; advance(count: number): void; continue(key?: any): void; delete(): IDBRequest; @@ -6932,7 +6934,7 @@ interface IDBDatabase extends EventTarget { close(): void; createObjectStore(name: string, optionalParameters?: IDBObjectStoreParameters): IDBObjectStore; deleteObjectStore(name: string): void; - transaction(storeNames: any, mode?: string): IDBTransaction; + transaction(storeNames: string | string[], mode?: string): IDBTransaction; addEventListener(type: "abort", listener: (ev: Event) => any, useCapture?: boolean): void; addEventListener(type: "error", listener: (ev: ErrorEvent) => any, useCapture?: boolean): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; @@ -6990,9 +6992,10 @@ declare var IDBKeyRange: { interface IDBObjectStore { indexNames: DOMStringList; - keyPath: string; + keyPath: string | string[]; name: string; transaction: IDBTransaction; + autoIncrement: boolean; add(value: any, key?: any): IDBRequest; clear(): IDBRequest; count(key?: any): IDBRequest; @@ -7031,7 +7034,7 @@ interface IDBRequest extends EventTarget { onsuccess: (ev: Event) => any; readyState: string; result: any; - source: any; + source: IDBObjectStore | IDBIndex | IDBCursor; transaction: IDBTransaction; addEventListener(type: "error", listener: (ev: ErrorEvent) => any, useCapture?: boolean): void; addEventListener(type: "success", listener: (ev: Event) => any, useCapture?: boolean): void; @@ -10218,11 +10221,14 @@ declare var SVGViewElement: { } interface SVGZoomAndPan { + zoomAndPan: number; +} + +declare var SVGZoomAndPan: { SVG_ZOOMANDPAN_DISABLE: number; SVG_ZOOMANDPAN_MAGNIFY: number; SVG_ZOOMANDPAN_UNKNOWN: number; } -declare var SVGZoomAndPan: SVGZoomAndPan; interface SVGZoomEvent extends UIEvent { newScale: number; @@ -12685,7 +12691,7 @@ interface DecodeSuccessCallback { (decodedData: AudioBuffer): void; } interface DecodeErrorCallback { - (): void; + (error: DOMException): void; } interface FunctionStringCallback { (data: string): void; diff --git a/src/lib/es6.d.ts b/src/lib/es6.d.ts index f5d6b06bc470a..5d71fba2b0b3b 100644 --- a/src/lib/es6.d.ts +++ b/src/lib/es6.d.ts @@ -7,14 +7,14 @@ interface Symbol { /** Returns the primitive value of the specified object. */ valueOf(): Object; - [Symbol.toStringTag]: "Symbol"; + readonly [Symbol.toStringTag]: "Symbol"; } interface SymbolConstructor { /** * A reference to the prototype. */ - prototype: Symbol; + readonly prototype: Symbol; /** * Returns a new unique Symbol value. @@ -42,67 +42,67 @@ interface SymbolConstructor { * A method that determines if a constructor object recognizes an object as one of the * constructor’s instances. Called by the semantics of the instanceof operator. */ - hasInstance: symbol; + readonly hasInstance: symbol; /** * A Boolean value that if true indicates that an object should flatten to its array elements * by Array.prototype.concat. */ - isConcatSpreadable: symbol; + readonly isConcatSpreadable: symbol; /** * A method that returns the default iterator for an object. Called by the semantics of the * for-of statement. */ - iterator: symbol; + readonly iterator: symbol; /** * A regular expression method that matches the regular expression against a string. Called * by the String.prototype.match method. */ - match: symbol; + readonly match: symbol; /** * A regular expression method that replaces matched substrings of a string. Called by the * String.prototype.replace method. */ - replace: symbol; + readonly replace: symbol; /** * A regular expression method that returns the index within a string that matches the * regular expression. Called by the String.prototype.search method. */ - search: symbol; + readonly search: symbol; /** * A function valued property that is the constructor function that is used to create * derived objects. */ - species: symbol; + readonly species: symbol; /** * A regular expression method that splits a string at the indices that match the regular * expression. Called by the String.prototype.split method. */ - split: symbol; + readonly split: symbol; /** * A method that converts an object to a corresponding primitive value. * Called by the ToPrimitive abstract operation. */ - toPrimitive: symbol; + readonly toPrimitive: symbol; /** * A String value that is used in the creation of the default string description of an object. * Called by the built-in method Object.prototype.toString. */ - toStringTag: symbol; + readonly toStringTag: symbol; /** * An Object whose own property names are property names that are excluded from the 'with' * environment bindings of the associated objects. */ - unscopables: symbol; + readonly unscopables: symbol; } declare var Symbol: SymbolConstructor; @@ -200,7 +200,7 @@ interface Function { /** * Returns the name of the function. Function names are read-only and can not be changed. */ - name: string; + readonly name: string; /** * Determines whether the given value inherits from this function if this function was used @@ -218,7 +218,7 @@ interface NumberConstructor { * that is representable as a Number value, which is approximately: * 2.2204460492503130808472633361816 x 10‍−‍16. */ - EPSILON: number; + readonly EPSILON: number; /** * Returns true if passed value is finite. @@ -253,14 +253,14 @@ interface NumberConstructor { * a Number value. * The value of Number.MIN_SAFE_INTEGER is 9007199254740991 2^53 − 1. */ - MAX_SAFE_INTEGER: number; + readonly MAX_SAFE_INTEGER: number; /** * The value of the smallest integer n such that n and n − 1 are both exactly representable as * a Number value. * The value of Number.MIN_SAFE_INTEGER is −9007199254740991 (−(2^53 − 1)). */ - MIN_SAFE_INTEGER: number; + readonly MIN_SAFE_INTEGER: number; /** * Converts a string to a floating-point number. @@ -565,7 +565,7 @@ interface IterableIterator extends Iterator { } interface GeneratorFunction extends Function { - [Symbol.toStringTag]: "GeneratorFunction"; + readonly [Symbol.toStringTag]: "GeneratorFunction"; } interface GeneratorFunctionConstructor { @@ -575,7 +575,7 @@ interface GeneratorFunctionConstructor { */ new (...args: string[]): GeneratorFunction; (...args: string[]): GeneratorFunction; - prototype: GeneratorFunction; + readonly prototype: GeneratorFunction; } declare var GeneratorFunction: GeneratorFunctionConstructor; @@ -690,7 +690,7 @@ interface Math { */ cbrt(x: number): number; - [Symbol.toStringTag]: "Math"; + readonly [Symbol.toStringTag]: "Math"; } interface Date { @@ -776,19 +776,19 @@ interface RegExp { * * If no flags are set, the value is the empty string. */ - flags: string; + readonly flags: string; /** * Returns a Boolean value indicating the state of the sticky flag (y) used with a regular * expression. Default is false. Read-only. */ - sticky: boolean; + readonly sticky: boolean; /** * Returns a Boolean value indicating the state of the Unicode flag (u) used with a regular * expression. Default is false. Read-only. */ - unicode: boolean; + readonly unicode: boolean; } interface RegExpConstructor { @@ -804,33 +804,34 @@ interface Map { has(key: K): boolean; keys(): IterableIterator; set(key: K, value?: V): Map; - size: number; + readonly size: number; values(): IterableIterator; [Symbol.iterator]():IterableIterator<[K,V]>; - [Symbol.toStringTag]: "Map"; + readonly [Symbol.toStringTag]: "Map"; } interface MapConstructor { new (): Map; new (): Map; new (iterable: Iterable<[K, V]>): Map; - prototype: Map; + readonly prototype: Map; } declare var Map: MapConstructor; interface WeakMap { + clear(): void; delete(key: K): boolean; get(key: K): V; has(key: K): boolean; set(key: K, value?: V): WeakMap; - [Symbol.toStringTag]: "WeakMap"; + readonly [Symbol.toStringTag]: "WeakMap"; } interface WeakMapConstructor { new (): WeakMap; new (): WeakMap; new (iterable: Iterable<[K, V]>): WeakMap; - prototype: WeakMap; + readonly prototype: WeakMap; } declare var WeakMap: WeakMapConstructor; @@ -842,37 +843,38 @@ interface Set { forEach(callbackfn: (value: T, index: T, set: Set) => void, thisArg?: any): void; has(value: T): boolean; keys(): IterableIterator; - size: number; + readonly size: number; values(): IterableIterator; [Symbol.iterator]():IterableIterator; - [Symbol.toStringTag]: "Set"; + readonly [Symbol.toStringTag]: "Set"; } interface SetConstructor { new (): Set; new (): Set; new (iterable: Iterable): Set; - prototype: Set; + readonly prototype: Set; } declare var Set: SetConstructor; interface WeakSet { add(value: T): WeakSet; + clear(): void; delete(value: T): boolean; has(value: T): boolean; - [Symbol.toStringTag]: "WeakSet"; + readonly [Symbol.toStringTag]: "WeakSet"; } interface WeakSetConstructor { new (): WeakSet; new (): WeakSet; new (iterable: Iterable): WeakSet; - prototype: WeakSet; + readonly prototype: WeakSet; } declare var WeakSet: WeakSetConstructor; interface JSON { - [Symbol.toStringTag]: "JSON"; + readonly [Symbol.toStringTag]: "JSON"; } /** @@ -882,11 +884,11 @@ interface JSON { * buffer as needed. */ interface ArrayBuffer { - [Symbol.toStringTag]: "ArrayBuffer"; + readonly [Symbol.toStringTag]: "ArrayBuffer"; } interface DataView { - [Symbol.toStringTag]: "DataView"; + readonly [Symbol.toStringTag]: "DataView"; } /** @@ -907,7 +909,7 @@ interface Int8Array { */ values(): IterableIterator; [Symbol.iterator](): IterableIterator; - [Symbol.toStringTag]: "Int8Array"; + readonly [Symbol.toStringTag]: "Int8Array"; } interface Int8ArrayConstructor { @@ -940,7 +942,7 @@ interface Uint8Array { */ values(): IterableIterator; [Symbol.iterator](): IterableIterator; - [Symbol.toStringTag]: "UInt8Array"; + readonly [Symbol.toStringTag]: "UInt8Array"; } interface Uint8ArrayConstructor { @@ -976,7 +978,7 @@ interface Uint8ClampedArray { values(): IterableIterator; [Symbol.iterator](): IterableIterator; - [Symbol.toStringTag]: "Uint8ClampedArray"; + readonly [Symbol.toStringTag]: "Uint8ClampedArray"; } interface Uint8ClampedArrayConstructor { @@ -1014,7 +1016,7 @@ interface Int16Array { [Symbol.iterator](): IterableIterator; - [Symbol.toStringTag]: "Int16Array"; + readonly [Symbol.toStringTag]: "Int16Array"; } interface Int16ArrayConstructor { @@ -1047,7 +1049,7 @@ interface Uint16Array { */ values(): IterableIterator; [Symbol.iterator](): IterableIterator; - [Symbol.toStringTag]: "Uint16Array"; + readonly [Symbol.toStringTag]: "Uint16Array"; } interface Uint16ArrayConstructor { @@ -1080,7 +1082,7 @@ interface Int32Array { */ values(): IterableIterator; [Symbol.iterator](): IterableIterator; - [Symbol.toStringTag]: "Int32Array"; + readonly [Symbol.toStringTag]: "Int32Array"; } interface Int32ArrayConstructor { @@ -1113,7 +1115,7 @@ interface Uint32Array { */ values(): IterableIterator; [Symbol.iterator](): IterableIterator; - [Symbol.toStringTag]: "Uint32Array"; + readonly [Symbol.toStringTag]: "Uint32Array"; } interface Uint32ArrayConstructor { @@ -1146,7 +1148,7 @@ interface Float32Array { */ values(): IterableIterator; [Symbol.iterator](): IterableIterator; - [Symbol.toStringTag]: "Float32Array"; + readonly [Symbol.toStringTag]: "Float32Array"; } interface Float32ArrayConstructor { @@ -1179,7 +1181,7 @@ interface Float64Array { */ values(): IterableIterator; [Symbol.iterator](): IterableIterator; - [Symbol.toStringTag]: "Float64Array"; + readonly [Symbol.toStringTag]: "Float64Array"; } interface Float64ArrayConstructor { @@ -1256,14 +1258,14 @@ interface Promise { catch(onrejected?: (reason: any) => T | PromiseLike): Promise; catch(onrejected?: (reason: any) => void): Promise; - [Symbol.toStringTag]: "Promise"; + readonly [Symbol.toStringTag]: "Promise"; } interface PromiseConstructor { /** * A reference to the prototype. */ - prototype: Promise; + readonly prototype: Promise; /** * Creates a new Promise. @@ -1325,7 +1327,7 @@ interface PromiseConstructor { */ resolve(): Promise; - [Symbol.species]: Function; + readonly [Symbol.species]: Function; } declare var Promise: PromiseConstructor; diff --git a/src/lib/webworker.generated.d.ts b/src/lib/webworker.generated.d.ts index d2008542cc65a..cd49a565f1238 100644 --- a/src/lib/webworker.generated.d.ts +++ b/src/lib/webworker.generated.d.ts @@ -275,7 +275,7 @@ interface IDBCursor { direction: string; key: any; primaryKey: any; - source: any; + source: IDBObjectStore | IDBIndex; advance(count: number): void; continue(key?: any): void; delete(): IDBRequest; @@ -313,7 +313,7 @@ interface IDBDatabase extends EventTarget { close(): void; createObjectStore(name: string, optionalParameters?: IDBObjectStoreParameters): IDBObjectStore; deleteObjectStore(name: string): void; - transaction(storeNames: any, mode?: string): IDBTransaction; + transaction(storeNames: string | string[], mode?: string): IDBTransaction; addEventListener(type: "abort", listener: (ev: Event) => any, useCapture?: boolean): void; addEventListener(type: "error", listener: (ev: ErrorEvent) => any, useCapture?: boolean): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; @@ -371,9 +371,10 @@ declare var IDBKeyRange: { interface IDBObjectStore { indexNames: DOMStringList; - keyPath: string; + keyPath: string | string[]; name: string; transaction: IDBTransaction; + autoIncrement: boolean; add(value: any, key?: any): IDBRequest; clear(): IDBRequest; count(key?: any): IDBRequest; @@ -412,7 +413,7 @@ interface IDBRequest extends EventTarget { onsuccess: (ev: Event) => any; readyState: string; result: any; - source: any; + source: IDBObjectStore | IDBIndex | IDBCursor; transaction: IDBTransaction; addEventListener(type: "error", listener: (ev: ErrorEvent) => any, useCapture?: boolean): void; addEventListener(type: "success", listener: (ev: Event) => any, useCapture?: boolean): void; @@ -959,7 +960,7 @@ interface DecodeSuccessCallback { (decodedData: AudioBuffer): void; } interface DecodeErrorCallback { - (): void; + (error: DOMException): void; } interface FunctionStringCallback { (data: string): void; diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index b7e909f69d8b9..4cd361734e371 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -10,7 +10,7 @@ namespace ts.BreakpointResolver { */ export function spanInSourceFileAtLocation(sourceFile: SourceFile, position: number) { // Cannot set breakpoint in dts file - if (sourceFile.flags & NodeFlags.DeclarationFile) { + if (sourceFile.isDeclarationFile) { return undefined; } diff --git a/src/services/services.ts b/src/services/services.ts index 28f7f8488355e..85b2bfb58e8a0 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -62,7 +62,7 @@ namespace ts { export interface SourceFile { /* @internal */ version: string; /* @internal */ scriptSnapshot: IScriptSnapshot; - /* @internal */ nameTable: Map; + /* @internal */ nameTable: Map; /* @internal */ getNamedDeclarations(): Map; @@ -237,14 +237,14 @@ namespace ts { while (pos < end) { const token = scanner.scan(); const textPos = scanner.getTextPos(); - nodes.push(createNode(token, pos, textPos, NodeFlags.Synthetic, this)); + nodes.push(createNode(token, pos, textPos, 0, this)); pos = textPos; } return pos; } private createSyntaxList(nodes: NodeArray): Node { - const list = createNode(SyntaxKind.SyntaxList, nodes.pos, nodes.end, NodeFlags.Synthetic, this); + const list = createNode(SyntaxKind.SyntaxList, nodes.pos, nodes.end, 0, this); list._children = []; let pos = nodes.pos; @@ -797,6 +797,7 @@ namespace ts { public parseDiagnostics: Diagnostic[]; public bindDiagnostics: Diagnostic[]; + public isDeclarationFile: boolean; public isDefaultLib: boolean; public hasNoDefaultLib: boolean; public externalModuleIndicator: Node; // The first node that causes this file to be an external module @@ -808,7 +809,7 @@ namespace ts { public languageVersion: ScriptTarget; public languageVariant: LanguageVariant; public identifiers: Map; - public nameTable: Map; + public nameTable: Map; public resolvedModules: Map; public imports: LiteralExpression[]; public moduleAugmentations: LiteralExpression[]; @@ -1875,6 +1876,9 @@ namespace ts { options.isolatedModules = true; + // transpileModule does not write anything to disk so there is no need to verify that there are no conflicts between input and output paths. + options.suppressOutputPathCheck = true; + // Filename can be non-ts file. options.allowNonTsExtensions = true; @@ -1954,8 +1958,6 @@ namespace ts { 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; return sourceFile; } @@ -2777,6 +2779,9 @@ namespace ts { return directoryProbablyExists(directoryName, host); } }; + if (host.trace) { + compilerHost.trace = message => host.trace(message); + } if (host.resolveModuleNames) { compilerHost.resolveModuleNames = (moduleNames, containingFile) => host.resolveModuleNames(moduleNames, containingFile); @@ -3831,7 +3836,7 @@ namespace ts { if (isRightOfDot && isSourceFileJavaScript(sourceFile)) { const uniqueNames = getCompletionEntriesFromSymbols(symbols, entries); - addRange(entries, getJavaScriptCompletionEntries(sourceFile, uniqueNames)); + addRange(entries, getJavaScriptCompletionEntries(sourceFile, location.pos, uniqueNames)); } else { if (!symbols || symbols.length === 0) { @@ -3864,12 +3869,17 @@ namespace ts { return { isMemberCompletion, isNewIdentifierLocation, entries }; - function getJavaScriptCompletionEntries(sourceFile: SourceFile, uniqueNames: Map): CompletionEntry[] { + function getJavaScriptCompletionEntries(sourceFile: SourceFile, position: number, uniqueNames: Map): CompletionEntry[] { const entries: CompletionEntry[] = []; const target = program.getCompilerOptions().target; const nameTable = getNameTable(sourceFile); for (const name in nameTable) { + // Skip identifiers produced only from the current location + if (nameTable[name] === position) { + continue; + } + if (!uniqueNames[name]) { uniqueNames[name] = name; const displayName = getCompletionEntryDisplayName(name, target, /*performCharacterChecks*/ true); @@ -5484,7 +5494,7 @@ namespace ts { const nameTable = getNameTable(sourceFile); - if (lookUp(nameTable, internedName)) { + if (lookUp(nameTable, internedName) !== undefined) { result = result || []; getReferencesInNode(sourceFile, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result, symbolToIndex); } @@ -6853,21 +6863,58 @@ namespace ts { } } - function classifyTokenOrJsxText(token: Node): void { - if (nodeIsMissing(token)) { - return; + /** + * Returns true if node should be treated as classified and no further processing is required. + * False will mean that node is not classified and traverse routine should recurse into node contents. + */ + function tryClassifyNode(node: Node): boolean { + if (nodeIsMissing(node)) { + return true; } - const tokenStart = token.kind === SyntaxKind.JsxText ? token.pos : classifyLeadingTriviaAndGetTokenStart(token); + const classifiedElementName = tryClassifyJsxElementName(node); + if (!isToken(node) && node.kind !== SyntaxKind.JsxText && classifiedElementName === undefined) { + return false; + } + + const tokenStart = node.kind === SyntaxKind.JsxText ? node.pos : classifyLeadingTriviaAndGetTokenStart(node); - const tokenWidth = token.end - tokenStart; + const tokenWidth = node.end - tokenStart; Debug.assert(tokenWidth >= 0); if (tokenWidth > 0) { - const type = classifyTokenType(token.kind, token); + const type = classifiedElementName || classifyTokenType(node.kind, node); if (type) { pushClassification(tokenStart, tokenWidth, type); } } + + return true; + } + + function tryClassifyJsxElementName(token: Node): ClassificationType { + switch (token.parent && token.parent.kind) { + case SyntaxKind.JsxOpeningElement: + if ((token.parent).tagName === token) { + return ClassificationType.jsxOpenTagName; + } + break; + case SyntaxKind.JsxClosingElement: + if ((token.parent).tagName === token) { + return ClassificationType.jsxCloseTagName; + } + break; + case SyntaxKind.JsxSelfClosingElement: + if ((token.parent).tagName === token) { + return ClassificationType.jsxSelfClosingTagName; + } + break; + case SyntaxKind.JsxAttribute: + if ((token.parent).name === token) { + return ClassificationType.jsxAttribute; + } + break; + } + return undefined; } // for accurate classification, the actual token should be passed in. however, for @@ -6960,28 +7007,6 @@ namespace ts { return ClassificationType.parameterName; } return; - - case SyntaxKind.JsxOpeningElement: - if ((token.parent).tagName === token) { - return ClassificationType.jsxOpenTagName; - } - return; - - case SyntaxKind.JsxClosingElement: - if ((token.parent).tagName === token) { - return ClassificationType.jsxCloseTagName; - } - return; - - case SyntaxKind.JsxSelfClosingElement: - if ((token.parent).tagName === token) { - return ClassificationType.jsxSelfClosingTagName; - } - return; - case SyntaxKind.JsxAttribute: - if ((token.parent).name === token) { - return ClassificationType.jsxAttribute; - } } } return ClassificationType.identifier; @@ -7000,10 +7025,7 @@ namespace ts { const children = element.getChildren(sourceFile); for (let i = 0, n = children.length; i < n; i++) { const child = children[i]; - if (isToken(child) || child.kind === SyntaxKind.JsxText) { - classifyTokenOrJsxText(child); - } - else { + if (!tryClassifyNode(child)) { // Recurse into our child nodes. processElement(child); } @@ -7510,7 +7532,7 @@ namespace ts { } /* @internal */ - export function getNameTable(sourceFile: SourceFile): Map { + export function getNameTable(sourceFile: SourceFile): Map { if (!sourceFile.nameTable) { initializeNameTable(sourceFile); } @@ -7519,7 +7541,7 @@ namespace ts { } function initializeNameTable(sourceFile: SourceFile): void { - const nameTable: Map = {}; + const nameTable: Map = {}; walk(sourceFile); sourceFile.nameTable = nameTable; @@ -7527,7 +7549,7 @@ namespace ts { function walk(node: Node) { switch (node.kind) { case SyntaxKind.Identifier: - nameTable[(node).text] = (node).text; + nameTable[(node).text] = nameTable[(node).text] === undefined ? node.pos : -1; break; case SyntaxKind.StringLiteral: case SyntaxKind.NumericLiteral: @@ -7539,7 +7561,7 @@ namespace ts { node.parent.kind === SyntaxKind.ExternalModuleReference || isArgumentOfElementAccessExpression(node)) { - nameTable[(node).text] = (node).text; + nameTable[(node).text] = nameTable[(node).text] === undefined ? node.pos : -1; } break; default: diff --git a/src/services/shims.ts b/src/services/shims.ts index 9ca3f19244d89..a4190d6752b3a 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -78,6 +78,8 @@ namespace ts { * when enumerating the directory. */ readDirectory(rootDir: string, extension: string, exclude?: string): string; + + trace(s: string): void; } /// @@ -1057,6 +1059,6 @@ namespace TypeScript.Services { // TODO: it should be moved into a namespace though. /* @internal */ -const toolsVersion = "1.8"; +const toolsVersion = "1.9"; /* tslint:enable:no-unused-variable */ \ No newline at end of file diff --git a/tests/baselines/reference/accessorWithES5.types b/tests/baselines/reference/accessorWithES5.types index cb54e92b1847d..29471548918eb 100644 --- a/tests/baselines/reference/accessorWithES5.types +++ b/tests/baselines/reference/accessorWithES5.types @@ -21,8 +21,8 @@ class D { } var x = { ->x : { a: number; } ->{ get a() { return 1 }} : { a: number; } +>x : { readonly a: number; } +>{ get a() { return 1 }} : { readonly a: number; } get a() { return 1 } >a : number diff --git a/tests/baselines/reference/aliasesInSystemModule1.js b/tests/baselines/reference/aliasesInSystemModule1.js index 43037c7634ca4..46d2b061dd3d0 100644 --- a/tests/baselines/reference/aliasesInSystemModule1.js +++ b/tests/baselines/reference/aliasesInSystemModule1.js @@ -17,8 +17,9 @@ module M { //// [aliasesInSystemModule1.js] -System.register(['foo'], function(exports_1) { +System.register(['foo'], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var alias; var cls, cls2, x, y, z, M; return { diff --git a/tests/baselines/reference/aliasesInSystemModule2.js b/tests/baselines/reference/aliasesInSystemModule2.js index 7effb2721be29..e30ba4fea5639 100644 --- a/tests/baselines/reference/aliasesInSystemModule2.js +++ b/tests/baselines/reference/aliasesInSystemModule2.js @@ -16,8 +16,9 @@ module M { } //// [aliasesInSystemModule2.js] -System.register(["foo"], function(exports_1) { +System.register(["foo"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var foo_1; var cls, cls2, x, y, z, M; return { diff --git a/tests/baselines/reference/allowSyntheticDefaultImports2.js b/tests/baselines/reference/allowSyntheticDefaultImports2.js index fcc029415cf84..87e47f9c9a15a 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports2.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports2.js @@ -10,8 +10,9 @@ export class Foo { } //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var Foo; return { setters:[], @@ -26,8 +27,9 @@ System.register([], function(exports_1) { } }); //// [a.js] -System.register(["./b"], function(exports_1) { +System.register(["./b"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var b_1; var x; return { diff --git a/tests/baselines/reference/allowSyntheticDefaultImports3.js b/tests/baselines/reference/allowSyntheticDefaultImports3.js index b14d25dbd61b0..348ce42a60adb 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports3.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports3.js @@ -11,8 +11,9 @@ export class Foo { //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var Foo; return { setters:[], @@ -27,8 +28,9 @@ System.register([], function(exports_1) { } }); //// [a.js] -System.register(["./b"], function(exports_1) { +System.register(["./b"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var b_1; var x; return { diff --git a/tests/baselines/reference/allowSyntheticDefaultImports5.js b/tests/baselines/reference/allowSyntheticDefaultImports5.js index c9121512b610c..f59226e152d5b 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports5.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports5.js @@ -12,8 +12,9 @@ export var x = new Foo(); //// [a.js] -System.register(["./b"], function(exports_1) { +System.register(["./b"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var b_1; var x; return { diff --git a/tests/baselines/reference/allowSyntheticDefaultImports6.js b/tests/baselines/reference/allowSyntheticDefaultImports6.js index 64d52e70af9d7..d2f25e538c527 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports6.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports6.js @@ -12,8 +12,9 @@ export var x = new Foo(); //// [a.js] -System.register(["./b"], function(exports_1) { +System.register(["./b"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var b_1; var x; return { diff --git a/tests/baselines/reference/ambientErrors.errors.txt b/tests/baselines/reference/ambientErrors.errors.txt index 5e257c2de3fbd..7b42085e0c20b 100644 --- a/tests/baselines/reference/ambientErrors.errors.txt +++ b/tests/baselines/reference/ambientErrors.errors.txt @@ -1,5 +1,4 @@ tests/cases/conformance/ambient/ambientErrors.ts(2,15): error TS1039: Initializers are not allowed in ambient contexts. -tests/cases/conformance/ambient/ambientErrors.ts(6,18): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. tests/cases/conformance/ambient/ambientErrors.ts(17,22): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. tests/cases/conformance/ambient/ambientErrors.ts(20,24): error TS1183: An implementation cannot be declared in ambient contexts. tests/cases/conformance/ambient/ambientErrors.ts(29,9): error TS1066: In ambient enum declarations member initializer must be constant expression. @@ -15,7 +14,7 @@ tests/cases/conformance/ambient/ambientErrors.ts(51,16): error TS2436: Ambient m tests/cases/conformance/ambient/ambientErrors.ts(57,5): error TS2309: An export assignment cannot be used in a module with other exported elements. -==== tests/cases/conformance/ambient/ambientErrors.ts (15 errors) ==== +==== tests/cases/conformance/ambient/ambientErrors.ts (14 errors) ==== // Ambient variable with an initializer declare var x = 4; ~ @@ -24,8 +23,6 @@ tests/cases/conformance/ambient/ambientErrors.ts(57,5): error TS2309: An export // Ambient functions with invalid overloads declare function fn(x: number): string; declare function fn(x: 'foo'): number; - ~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. // Ambient functions with duplicate signatures declare function fn1(x: number): string; diff --git a/tests/baselines/reference/anonymousDefaultExportsSystem.js b/tests/baselines/reference/anonymousDefaultExportsSystem.js index 74913a57a99b0..f9ff71dec0605 100644 --- a/tests/baselines/reference/anonymousDefaultExportsSystem.js +++ b/tests/baselines/reference/anonymousDefaultExportsSystem.js @@ -7,8 +7,9 @@ export default class {} export default function() {} //// [a.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var default_1; return { setters:[], @@ -20,8 +21,9 @@ System.register([], function(exports_1) { } }); //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; function default_1() { } exports_1("default", default_1); return { diff --git a/tests/baselines/reference/assignToEnum.errors.txt b/tests/baselines/reference/assignToEnum.errors.txt index 4846a96dbb7b8..d50daa3099f6a 100644 --- a/tests/baselines/reference/assignToEnum.errors.txt +++ b/tests/baselines/reference/assignToEnum.errors.txt @@ -1,7 +1,7 @@ tests/cases/compiler/assignToEnum.ts(2,1): error TS2364: Invalid left-hand side of assignment expression. tests/cases/compiler/assignToEnum.ts(3,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/compiler/assignToEnum.ts(4,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/compiler/assignToEnum.ts(5,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/assignToEnum.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/assignToEnum.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. ==== tests/cases/compiler/assignToEnum.ts (4 errors) ==== @@ -14,9 +14,9 @@ tests/cases/compiler/assignToEnum.ts(5,1): error TS2364: Invalid left-hand side !!! error TS2364: Invalid left-hand side of assignment expression. A.foo = 1; // invalid LHS ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. A.foo = A.bar; // invalid LHS ~~~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/assignments.errors.txt b/tests/baselines/reference/assignments.errors.txt index 9f89863f31f65..05bc4ce179418 100644 --- a/tests/baselines/reference/assignments.errors.txt +++ b/tests/baselines/reference/assignments.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(11,1): error TS2304: Cannot find name 'M'. tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(14,1): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(17,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(18,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(21,1): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(31,1): error TS2304: Cannot find name 'I'. @@ -32,7 +32,7 @@ tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(31,1): er !!! error TS2364: Invalid left-hand side of assignment expression. E.A = null; // OK per spec, Error per implementation (509581) ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. function fn() { } fn = null; // Should be error diff --git a/tests/baselines/reference/asyncAliasReturnType_es6.errors.txt b/tests/baselines/reference/asyncAliasReturnType_es6.errors.txt deleted file mode 100644 index ec532d1380d20..0000000000000 --- a/tests/baselines/reference/asyncAliasReturnType_es6.errors.txt +++ /dev/null @@ -1,10 +0,0 @@ -tests/cases/conformance/async/es6/asyncAliasReturnType_es6.ts(3,16): error TS1055: Type 'PromiseAlias' is not a valid async function return type. - - -==== tests/cases/conformance/async/es6/asyncAliasReturnType_es6.ts (1 errors) ==== - type PromiseAlias = Promise; - - async function f(): PromiseAlias { - ~ -!!! error TS1055: Type 'PromiseAlias' is not a valid async function return type. - } \ No newline at end of file diff --git a/tests/baselines/reference/asyncAliasReturnType_es6.js b/tests/baselines/reference/asyncAliasReturnType_es6.js index 0af63b0bfa604..45fe3228f6ebd 100644 --- a/tests/baselines/reference/asyncAliasReturnType_es6.js +++ b/tests/baselines/reference/asyncAliasReturnType_es6.js @@ -6,6 +6,6 @@ async function f(): PromiseAlias { //// [asyncAliasReturnType_es6.js] function f() { - return __awaiter(this, void 0, PromiseAlias, function* () { + return __awaiter(this, void 0, void 0, function* () { }); } diff --git a/tests/baselines/reference/asyncAliasReturnType_es6.symbols b/tests/baselines/reference/asyncAliasReturnType_es6.symbols new file mode 100644 index 0000000000000..4d6db6a1ef4c4 --- /dev/null +++ b/tests/baselines/reference/asyncAliasReturnType_es6.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/async/es6/asyncAliasReturnType_es6.ts === +type PromiseAlias = Promise; +>PromiseAlias : Symbol(PromiseAlias, Decl(asyncAliasReturnType_es6.ts, 0, 0)) +>T : Symbol(T, Decl(asyncAliasReturnType_es6.ts, 0, 18)) +>Promise : Symbol(Promise, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(asyncAliasReturnType_es6.ts, 0, 18)) + +async function f(): PromiseAlias { +>f : Symbol(f, Decl(asyncAliasReturnType_es6.ts, 0, 34)) +>PromiseAlias : Symbol(PromiseAlias, Decl(asyncAliasReturnType_es6.ts, 0, 0)) +} diff --git a/tests/baselines/reference/asyncAliasReturnType_es6.types b/tests/baselines/reference/asyncAliasReturnType_es6.types new file mode 100644 index 0000000000000..8426d2a3542f4 --- /dev/null +++ b/tests/baselines/reference/asyncAliasReturnType_es6.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/async/es6/asyncAliasReturnType_es6.ts === +type PromiseAlias = Promise; +>PromiseAlias : Promise +>T : T +>Promise : Promise +>T : T + +async function f(): PromiseAlias { +>f : () => Promise +>PromiseAlias : Promise +} diff --git a/tests/baselines/reference/asyncArrowFunction1_es6.js b/tests/baselines/reference/asyncArrowFunction1_es6.js index 4f03acc5ced43..0026cd91a7ef9 100644 --- a/tests/baselines/reference/asyncArrowFunction1_es6.js +++ b/tests/baselines/reference/asyncArrowFunction1_es6.js @@ -4,5 +4,5 @@ var foo = async (): Promise => { }; //// [asyncArrowFunction1_es6.js] -var foo = () => __awaiter(this, void 0, Promise, function* () { +var foo = () => __awaiter(this, void 0, void 0, function* () { }); diff --git a/tests/baselines/reference/asyncArrowFunction6_es6.js b/tests/baselines/reference/asyncArrowFunction6_es6.js index 54b8aa1f6b154..a01e53f5b114f 100644 --- a/tests/baselines/reference/asyncArrowFunction6_es6.js +++ b/tests/baselines/reference/asyncArrowFunction6_es6.js @@ -4,5 +4,5 @@ var foo = async (a = await): Promise => { } //// [asyncArrowFunction6_es6.js] -var foo = (a = yield ) => __awaiter(this, void 0, Promise, function* () { +var foo = (a = yield ) => __awaiter(this, void 0, void 0, function* () { }); diff --git a/tests/baselines/reference/asyncArrowFunction7_es6.js b/tests/baselines/reference/asyncArrowFunction7_es6.js index ac68a8fd2f865..fab705c0b76e2 100644 --- a/tests/baselines/reference/asyncArrowFunction7_es6.js +++ b/tests/baselines/reference/asyncArrowFunction7_es6.js @@ -7,8 +7,8 @@ var bar = async (): Promise => { } //// [asyncArrowFunction7_es6.js] -var bar = () => __awaiter(this, void 0, Promise, function* () { +var bar = () => __awaiter(this, void 0, void 0, function* () { // 'await' here is an identifier, and not an await expression. - var foo = (a = yield ) => __awaiter(this, void 0, Promise, function* () { + var foo = (a = yield ) => __awaiter(this, void 0, void 0, function* () { }); }); diff --git a/tests/baselines/reference/asyncArrowFunction8_es6.js b/tests/baselines/reference/asyncArrowFunction8_es6.js index 9cee5ee1525d7..0c33cfcfa2de0 100644 --- a/tests/baselines/reference/asyncArrowFunction8_es6.js +++ b/tests/baselines/reference/asyncArrowFunction8_es6.js @@ -5,6 +5,6 @@ var foo = async (): Promise => { } //// [asyncArrowFunction8_es6.js] -var foo = () => __awaiter(this, void 0, Promise, function* () { +var foo = () => __awaiter(this, void 0, void 0, function* () { var v = { [yield ]: foo }; }); diff --git a/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.js b/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.js index c24259cf0b528..ca79eed6c8eb0 100644 --- a/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.js +++ b/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.js @@ -11,6 +11,6 @@ class C { class C { method() { function other() { } - var fn = () => __awaiter(this, arguments, Promise, function* (_arguments) { return yield other.apply(this, _arguments); }); + var fn = () => __awaiter(this, arguments, void 0, function* () { return yield other.apply(this, arguments); }); } } diff --git a/tests/baselines/reference/asyncArrowFunctionCapturesThis_es6.js b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es6.js index 0f09e366ef3dc..de7eb23ed7811 100644 --- a/tests/baselines/reference/asyncArrowFunctionCapturesThis_es6.js +++ b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es6.js @@ -9,6 +9,6 @@ class C { //// [asyncArrowFunctionCapturesThis_es6.js] class C { method() { - var fn = () => __awaiter(this, void 0, Promise, function* () { return yield this; }); + var fn = () => __awaiter(this, void 0, void 0, function* () { return yield this; }); } } diff --git a/tests/baselines/reference/asyncAwaitIsolatedModules_es6.js b/tests/baselines/reference/asyncAwaitIsolatedModules_es6.js index 450ded9d4f534..4022fde7f54e8 100644 --- a/tests/baselines/reference/asyncAwaitIsolatedModules_es6.js +++ b/tests/baselines/reference/asyncAwaitIsolatedModules_es6.js @@ -41,73 +41,73 @@ module M { //// [asyncAwaitIsolatedModules_es6.js] var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new P(function (resolve, reject) { + return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.call(thisArg, _arguments)).next()); + step((generator = generator.apply(thisArg, _arguments)).next()); }); }; function f0() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } function f1() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } function f3() { - return __awaiter(this, void 0, MyPromise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } let f4 = function () { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); }; let f5 = function () { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); }; let f6 = function () { - return __awaiter(this, void 0, MyPromise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); }; -let f7 = () => __awaiter(this, void 0, Promise, function* () { }); -let f8 = () => __awaiter(this, void 0, Promise, function* () { }); -let f9 = () => __awaiter(this, void 0, MyPromise, function* () { }); -let f10 = () => __awaiter(this, void 0, Promise, function* () { return p; }); -let f11 = () => __awaiter(this, void 0, Promise, function* () { return mp; }); -let f12 = () => __awaiter(this, void 0, Promise, function* () { return mp; }); -let f13 = () => __awaiter(this, void 0, MyPromise, function* () { return p; }); +let f7 = () => __awaiter(this, void 0, void 0, function* () { }); +let f8 = () => __awaiter(this, void 0, void 0, function* () { }); +let f9 = () => __awaiter(this, void 0, void 0, function* () { }); +let f10 = () => __awaiter(this, void 0, void 0, function* () { return p; }); +let f11 = () => __awaiter(this, void 0, void 0, function* () { return mp; }); +let f12 = () => __awaiter(this, void 0, void 0, function* () { return mp; }); +let f13 = () => __awaiter(this, void 0, void 0, function* () { return p; }); let o = { m1() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); }, m2() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); }, m3() { - return __awaiter(this, void 0, MyPromise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } }; class C { m1() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } m2() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } m3() { - return __awaiter(this, void 0, MyPromise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } static m4() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } static m5() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } static m6() { - return __awaiter(this, void 0, MyPromise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } } var M; (function (M) { function f1() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } M.f1 = f1; })(M || (M = {})); diff --git a/tests/baselines/reference/asyncAwait_es6.js b/tests/baselines/reference/asyncAwait_es6.js index 61ed71198c84d..be2eb90e3e4fb 100644 --- a/tests/baselines/reference/asyncAwait_es6.js +++ b/tests/baselines/reference/asyncAwait_es6.js @@ -41,73 +41,73 @@ module M { //// [asyncAwait_es6.js] var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new P(function (resolve, reject) { + return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.call(thisArg, _arguments)).next()); + step((generator = generator.apply(thisArg, _arguments)).next()); }); }; function f0() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } function f1() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } function f3() { - return __awaiter(this, void 0, MyPromise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } let f4 = function () { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); }; let f5 = function () { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); }; let f6 = function () { - return __awaiter(this, void 0, MyPromise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); }; -let f7 = () => __awaiter(this, void 0, Promise, function* () { }); -let f8 = () => __awaiter(this, void 0, Promise, function* () { }); -let f9 = () => __awaiter(this, void 0, MyPromise, function* () { }); -let f10 = () => __awaiter(this, void 0, Promise, function* () { return p; }); -let f11 = () => __awaiter(this, void 0, Promise, function* () { return mp; }); -let f12 = () => __awaiter(this, void 0, Promise, function* () { return mp; }); -let f13 = () => __awaiter(this, void 0, MyPromise, function* () { return p; }); +let f7 = () => __awaiter(this, void 0, void 0, function* () { }); +let f8 = () => __awaiter(this, void 0, void 0, function* () { }); +let f9 = () => __awaiter(this, void 0, void 0, function* () { }); +let f10 = () => __awaiter(this, void 0, void 0, function* () { return p; }); +let f11 = () => __awaiter(this, void 0, void 0, function* () { return mp; }); +let f12 = () => __awaiter(this, void 0, void 0, function* () { return mp; }); +let f13 = () => __awaiter(this, void 0, void 0, function* () { return p; }); let o = { m1() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); }, m2() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); }, m3() { - return __awaiter(this, void 0, MyPromise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } }; class C { m1() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } m2() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } m3() { - return __awaiter(this, void 0, MyPromise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } static m4() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } static m5() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } static m6() { - return __awaiter(this, void 0, MyPromise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } } var M; (function (M) { function f1() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } M.f1 = f1; })(M || (M = {})); diff --git a/tests/baselines/reference/asyncFunctionDeclaration11_es6.js b/tests/baselines/reference/asyncFunctionDeclaration11_es6.js index a44343cef7822..6fe8921434c84 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration11_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration11_es6.js @@ -4,6 +4,6 @@ async function await(): Promise { //// [asyncFunctionDeclaration11_es6.js] function await() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { }); } diff --git a/tests/baselines/reference/asyncFunctionDeclaration13_es6.js b/tests/baselines/reference/asyncFunctionDeclaration13_es6.js index 4257c8691c25b..6fab6c39947d3 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration13_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration13_es6.js @@ -7,7 +7,7 @@ async function foo(): Promise { //// [asyncFunctionDeclaration13_es6.js] function foo() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { // Legal to use 'await' in a type context. var v; }); diff --git a/tests/baselines/reference/asyncFunctionDeclaration14_es6.js b/tests/baselines/reference/asyncFunctionDeclaration14_es6.js index f32d106f92e37..f584f9178426f 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration14_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration14_es6.js @@ -5,7 +5,7 @@ async function foo(): Promise { //// [asyncFunctionDeclaration14_es6.js] function foo() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { return; }); } diff --git a/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt b/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt index bc1ef24127a45..e8d3e7d79b1e8 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt +++ b/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt @@ -1,12 +1,8 @@ -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(6,16): error TS1055: Type '{}' is not a valid async function return type. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(7,16): error TS1055: Type 'any' is not a valid async function return type. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(8,16): error TS1055: Type 'number' is not a valid async function return type. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(9,16): error TS1055: Type 'PromiseLike' is not a valid async function return type. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(10,16): error TS1055: Type 'typeof Thenable' is not a valid async function return type. - Type 'Thenable' is not assignable to type 'PromiseLike'. - Types of property 'then' are incompatible. - Type '() => void' is not assignable to type '{ (onfulfilled?: (value: any) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): PromiseLike; (onfulfilled?: (value: any) => TResult | PromiseLike, onrejected?: (reason: any) => void): PromiseLike; }'. - Type 'void' is not assignable to type 'PromiseLike'. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(6,23): error TS1064: The return type of an async function or method must be the global Promise type. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(7,23): error TS1064: The return type of an async function or method must be the global Promise type. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(8,23): error TS1064: The return type of an async function or method must be the global Promise type. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(9,23): error TS1064: The return type of an async function or method must be the global Promise type. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(10,23): error TS1064: The return type of an async function or method must be the global Promise type. tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(17,16): error TS1059: Return expression in async function does not have a valid callable 'then' member. tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(23,25): error TS1058: Operand for 'await' does not have a valid callable 'then' member. @@ -18,24 +14,20 @@ tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration1 declare let thenable: Thenable; async function fn1() { } // valid: Promise async function fn2(): { } { } // error - ~~~ -!!! error TS1055: Type '{}' is not a valid async function return type. + ~~~ +!!! error TS1064: The return type of an async function or method must be the global Promise type. async function fn3(): any { } // error - ~~~ -!!! error TS1055: Type 'any' is not a valid async function return type. + ~~~ +!!! error TS1064: The return type of an async function or method must be the global Promise type. async function fn4(): number { } // error - ~~~ -!!! error TS1055: Type 'number' is not a valid async function return type. + ~~~~~~ +!!! error TS1064: The return type of an async function or method must be the global Promise type. async function fn5(): PromiseLike { } // error - ~~~ -!!! error TS1055: Type 'PromiseLike' is not a valid async function return type. + ~~~~~~~~~~~~~~~~~ +!!! error TS1064: The return type of an async function or method must be the global Promise type. async function fn6(): Thenable { } // error - ~~~ -!!! error TS1055: Type 'typeof Thenable' is not a valid async function return type. -!!! error TS1055: Type 'Thenable' is not assignable to type 'PromiseLike'. -!!! error TS1055: Types of property 'then' are incompatible. -!!! error TS1055: Type '() => void' is not assignable to type '{ (onfulfilled?: (value: any) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): PromiseLike; (onfulfilled?: (value: any) => TResult | PromiseLike, onrejected?: (reason: any) => void): PromiseLike; }'. -!!! error TS1055: Type 'void' is not assignable to type 'PromiseLike'. + ~~~~~~~~ +!!! error TS1064: The return type of an async function or method must be the global Promise type. async function fn7() { return; } // valid: Promise async function fn8() { return 1; } // valid: Promise async function fn9() { return null; } // valid: Promise diff --git a/tests/baselines/reference/asyncFunctionDeclaration15_es6.js b/tests/baselines/reference/asyncFunctionDeclaration15_es6.js index c72062e24b23a..174a95d6f669f 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration15_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration15_es6.js @@ -26,59 +26,59 @@ async function fn19() { await thenable; } // error //// [asyncFunctionDeclaration15_es6.js] function fn1() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } // valid: Promise function fn2() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } // error function fn3() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } // error function fn4() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } // error function fn5() { - return __awaiter(this, void 0, PromiseLike, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } // error function fn6() { - return __awaiter(this, void 0, Thenable, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } // error function fn7() { - return __awaiter(this, void 0, Promise, function* () { return; }); + return __awaiter(this, void 0, void 0, function* () { return; }); } // valid: Promise function fn8() { - return __awaiter(this, void 0, Promise, function* () { return 1; }); + return __awaiter(this, void 0, void 0, function* () { return 1; }); } // valid: Promise function fn9() { - return __awaiter(this, void 0, Promise, function* () { return null; }); + return __awaiter(this, void 0, void 0, function* () { return null; }); } // valid: Promise function fn10() { - return __awaiter(this, void 0, Promise, function* () { return undefined; }); + return __awaiter(this, void 0, void 0, function* () { return undefined; }); } // valid: Promise function fn11() { - return __awaiter(this, void 0, Promise, function* () { return a; }); + return __awaiter(this, void 0, void 0, function* () { return a; }); } // valid: Promise function fn12() { - return __awaiter(this, void 0, Promise, function* () { return obj; }); + return __awaiter(this, void 0, void 0, function* () { return obj; }); } // valid: Promise<{ then: string; }> function fn13() { - return __awaiter(this, void 0, Promise, function* () { return thenable; }); + return __awaiter(this, void 0, void 0, function* () { return thenable; }); } // error function fn14() { - return __awaiter(this, void 0, Promise, function* () { yield 1; }); + return __awaiter(this, void 0, void 0, function* () { yield 1; }); } // valid: Promise function fn15() { - return __awaiter(this, void 0, Promise, function* () { yield null; }); + return __awaiter(this, void 0, void 0, function* () { yield null; }); } // valid: Promise function fn16() { - return __awaiter(this, void 0, Promise, function* () { yield undefined; }); + return __awaiter(this, void 0, void 0, function* () { yield undefined; }); } // valid: Promise function fn17() { - return __awaiter(this, void 0, Promise, function* () { yield a; }); + return __awaiter(this, void 0, void 0, function* () { yield a; }); } // valid: Promise function fn18() { - return __awaiter(this, void 0, Promise, function* () { yield obj; }); + return __awaiter(this, void 0, void 0, function* () { yield obj; }); } // valid: Promise function fn19() { - return __awaiter(this, void 0, Promise, function* () { yield thenable; }); + return __awaiter(this, void 0, void 0, function* () { yield thenable; }); } // error diff --git a/tests/baselines/reference/asyncFunctionDeclaration1_es6.js b/tests/baselines/reference/asyncFunctionDeclaration1_es6.js index 263e27fa35efa..e92d55dc0e2ce 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration1_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration1_es6.js @@ -4,6 +4,6 @@ async function foo(): Promise { //// [asyncFunctionDeclaration1_es6.js] function foo() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { }); } diff --git a/tests/baselines/reference/asyncFunctionDeclaration6_es6.js b/tests/baselines/reference/asyncFunctionDeclaration6_es6.js index 8c37968ab4c22..a70316989b380 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration6_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration6_es6.js @@ -4,6 +4,6 @@ async function foo(a = await): Promise { //// [asyncFunctionDeclaration6_es6.js] function foo(a = yield ) { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { }); } diff --git a/tests/baselines/reference/asyncFunctionDeclaration7_es6.js b/tests/baselines/reference/asyncFunctionDeclaration7_es6.js index ef66df4e4133a..0d360fa866ccb 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration7_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration7_es6.js @@ -7,10 +7,10 @@ async function bar(): Promise { //// [asyncFunctionDeclaration7_es6.js] function bar() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { // 'await' here is an identifier, and not a yield expression. function foo(a = yield ) { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { }); } }); diff --git a/tests/baselines/reference/asyncFunctionDeclaration9_es6.js b/tests/baselines/reference/asyncFunctionDeclaration9_es6.js index 9723a69f2a23b..c57c0eb395a72 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration9_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration9_es6.js @@ -5,7 +5,7 @@ async function foo(): Promise { //// [asyncFunctionDeclaration9_es6.js] function foo() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { var v = { [yield ]: foo }; }); } diff --git a/tests/baselines/reference/asyncFunctionsAcrossFiles.js b/tests/baselines/reference/asyncFunctionsAcrossFiles.js index 05b8ca564217f..94ccff2358c28 100644 --- a/tests/baselines/reference/asyncFunctionsAcrossFiles.js +++ b/tests/baselines/reference/asyncFunctionsAcrossFiles.js @@ -17,31 +17,31 @@ export const b = { //// [b.js] var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new P(function (resolve, reject) { + return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.call(thisArg, _arguments)).next()); + step((generator = generator.apply(thisArg, _arguments)).next()); }); }; import { a } from './a'; export const b = { - f: () => __awaiter(this, void 0, Promise, function* () { + f: () => __awaiter(this, void 0, void 0, function* () { yield a.f(); }) }; //// [a.js] var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new P(function (resolve, reject) { + return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.call(thisArg, _arguments)).next()); + step((generator = generator.apply(thisArg, _arguments)).next()); }); }; import { b } from './b'; export const a = { - f: () => __awaiter(this, void 0, Promise, function* () { + f: () => __awaiter(this, void 0, void 0, function* () { yield b.f(); }) }; diff --git a/tests/baselines/reference/asyncImportedPromise_es6.errors.txt b/tests/baselines/reference/asyncImportedPromise_es6.errors.txt new file mode 100644 index 0000000000000..43b454826447c --- /dev/null +++ b/tests/baselines/reference/asyncImportedPromise_es6.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/async/es6/test.ts(3,25): error TS1064: The return type of an async function or method must be the global Promise type. + + +==== tests/cases/conformance/async/es6/task.ts (0 errors) ==== + export class Task extends Promise { } + +==== tests/cases/conformance/async/es6/test.ts (1 errors) ==== + import { Task } from "./task"; + class Test { + async example(): Task { return; } + ~~~~~~~ +!!! error TS1064: The return type of an async function or method must be the global Promise type. + } \ No newline at end of file diff --git a/tests/baselines/reference/asyncImportedPromise_es6.js b/tests/baselines/reference/asyncImportedPromise_es6.js index d861012488cff..56a41b0283f5b 100644 --- a/tests/baselines/reference/asyncImportedPromise_es6.js +++ b/tests/baselines/reference/asyncImportedPromise_es6.js @@ -17,16 +17,15 @@ exports.Task = Task; //// [test.js] "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new P(function (resolve, reject) { + return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.call(thisArg, _arguments)).next()); + step((generator = generator.apply(thisArg, _arguments)).next()); }); }; -var task_1 = require("./task"); class Test { example() { - return __awaiter(this, void 0, task_1.Task, function* () { return; }); + return __awaiter(this, void 0, void 0, function* () { return; }); } } diff --git a/tests/baselines/reference/asyncImportedPromise_es6.symbols b/tests/baselines/reference/asyncImportedPromise_es6.symbols deleted file mode 100644 index 45cf47d2b45b2..0000000000000 --- a/tests/baselines/reference/asyncImportedPromise_es6.symbols +++ /dev/null @@ -1,20 +0,0 @@ -=== tests/cases/conformance/async/es6/task.ts === -export class Task extends Promise { } ->Task : Symbol(Task, Decl(task.ts, 0, 0)) ->T : Symbol(T, Decl(task.ts, 0, 18)) ->Promise : Symbol(Promise, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) ->T : Symbol(T, Decl(task.ts, 0, 18)) - -=== tests/cases/conformance/async/es6/test.ts === -import { Task } from "./task"; ->Task : Symbol(Task, Decl(test.ts, 0, 8)) - -class Test { ->Test : Symbol(Test, Decl(test.ts, 0, 30)) - - async example(): Task { return; } ->example : Symbol(example, Decl(test.ts, 1, 12)) ->T : Symbol(T, Decl(test.ts, 2, 18)) ->Task : Symbol(Task, Decl(test.ts, 0, 8)) ->T : Symbol(T, Decl(test.ts, 2, 18)) -} diff --git a/tests/baselines/reference/asyncImportedPromise_es6.types b/tests/baselines/reference/asyncImportedPromise_es6.types deleted file mode 100644 index 424f14b34d37f..0000000000000 --- a/tests/baselines/reference/asyncImportedPromise_es6.types +++ /dev/null @@ -1,20 +0,0 @@ -=== tests/cases/conformance/async/es6/task.ts === -export class Task extends Promise { } ->Task : Task ->T : T ->Promise : Promise ->T : T - -=== tests/cases/conformance/async/es6/test.ts === -import { Task } from "./task"; ->Task : typeof Task - -class Test { ->Test : Test - - async example(): Task { return; } ->example : () => Task ->T : T ->Task : Task ->T : T -} diff --git a/tests/baselines/reference/asyncMethodWithSuper_es6.js b/tests/baselines/reference/asyncMethodWithSuper_es6.js new file mode 100644 index 0000000000000..eacb0a882b2f7 --- /dev/null +++ b/tests/baselines/reference/asyncMethodWithSuper_es6.js @@ -0,0 +1,99 @@ +//// [asyncMethodWithSuper_es6.ts] +class A { + x() { + } +} + +class B extends A { + // async method with only call/get on 'super' does not require a binding + async simple() { + // call with property access + super.x(); + + // call with element access + super["x"](); + + // property access (read) + const a = super.x; + + // element access (read) + const b = super["x"]; + } + + // async method with assignment/destructuring on 'super' requires a binding + async advanced() { + const f = () => {}; + + // call with property access + super.x(); + + // call with element access + super["x"](); + + // property access (read) + const a = super.x; + + // element access (read) + const b = super["x"]; + + // property access (assign) + super.x = f; + + // element access (assign) + super["x"] = f; + + // destructuring assign with property access + ({ f: super.x } = { f }); + + // destructuring assign with element access + ({ f: super["x"] } = { f }); + } +} + +//// [asyncMethodWithSuper_es6.js] +class A { + x() { + } +} +class B extends A { + // async method with only call/get on 'super' does not require a binding + simple() { + const _super = name => super[name]; + return __awaiter(this, void 0, void 0, function* () { + // call with property access + _super("x").call(this); + // call with element access + _super("x").call(this); + // property access (read) + const a = _super("x"); + // element access (read) + const b = _super("x"); + }); + } + // async method with assignment/destructuring on 'super' requires a binding + advanced() { + const _super = (function (geti, seti) { + const cache = Object.create(null); + return name => cache[name] || (cache[name] = { get value() { return geti(name); }, set value(v) { seti(name, v); } }); + })(name => super[name], (name, value) => super[name] = value); + return __awaiter(this, void 0, void 0, function* () { + const f = () => { }; + // call with property access + _super("x").value.call(this); + // call with element access + _super("x").value.call(this); + // property access (read) + const a = _super("x").value; + // element access (read) + const b = _super("x").value; + // property access (assign) + _super("x").value = f; + // element access (assign) + _super("x").value = f; + // destructuring assign with property access + ({ f: _super("x").value } = { f }); + // destructuring assign with element access + ({ f: _super("x").value } = { f }); + }); + } +} diff --git a/tests/baselines/reference/asyncMethodWithSuper_es6.symbols b/tests/baselines/reference/asyncMethodWithSuper_es6.symbols new file mode 100644 index 0000000000000..37937a061a8ec --- /dev/null +++ b/tests/baselines/reference/asyncMethodWithSuper_es6.symbols @@ -0,0 +1,102 @@ +=== tests/cases/conformance/async/es6/asyncMethodWithSuper_es6.ts === +class A { +>A : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) + + x() { +>x : Symbol(x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) + } +} + +class B extends A { +>B : Symbol(B, Decl(asyncMethodWithSuper_es6.ts, 3, 1)) +>A : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) + + // async method with only call/get on 'super' does not require a binding + async simple() { +>simple : Symbol(simple, Decl(asyncMethodWithSuper_es6.ts, 5, 19)) + + // call with property access + super.x(); +>super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) +>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) +>x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) + + // call with element access + super["x"](); +>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) +>"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) + + // property access (read) + const a = super.x; +>a : Symbol(a, Decl(asyncMethodWithSuper_es6.ts, 15, 13)) +>super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) +>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) +>x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) + + // element access (read) + const b = super["x"]; +>b : Symbol(b, Decl(asyncMethodWithSuper_es6.ts, 18, 13)) +>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) +>"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) + } + + // async method with assignment/destructuring on 'super' requires a binding + async advanced() { +>advanced : Symbol(advanced, Decl(asyncMethodWithSuper_es6.ts, 19, 5)) + + const f = () => {}; +>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 23, 13)) + + // call with property access + super.x(); +>super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) +>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) +>x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) + + // call with element access + super["x"](); +>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) +>"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) + + // property access (read) + const a = super.x; +>a : Symbol(a, Decl(asyncMethodWithSuper_es6.ts, 32, 13)) +>super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) +>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) +>x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) + + // element access (read) + const b = super["x"]; +>b : Symbol(b, Decl(asyncMethodWithSuper_es6.ts, 35, 13)) +>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) +>"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) + + // property access (assign) + super.x = f; +>super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) +>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) +>x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 23, 13)) + + // element access (assign) + super["x"] = f; +>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) +>"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 23, 13)) + + // destructuring assign with property access + ({ f: super.x } = { f }); +>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 44, 10)) +>super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) +>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) +>x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 44, 27)) + + // destructuring assign with element access + ({ f: super["x"] } = { f }); +>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 47, 10)) +>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) +>"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 47, 30)) + } +} diff --git a/tests/baselines/reference/asyncMethodWithSuper_es6.types b/tests/baselines/reference/asyncMethodWithSuper_es6.types new file mode 100644 index 0000000000000..04c5b5a9baf0e --- /dev/null +++ b/tests/baselines/reference/asyncMethodWithSuper_es6.types @@ -0,0 +1,123 @@ +=== tests/cases/conformance/async/es6/asyncMethodWithSuper_es6.ts === +class A { +>A : A + + x() { +>x : () => void + } +} + +class B extends A { +>B : B +>A : A + + // async method with only call/get on 'super' does not require a binding + async simple() { +>simple : () => Promise + + // call with property access + super.x(); +>super.x() : void +>super.x : () => void +>super : A +>x : () => void + + // call with element access + super["x"](); +>super["x"]() : void +>super["x"] : () => void +>super : A +>"x" : string + + // property access (read) + const a = super.x; +>a : () => void +>super.x : () => void +>super : A +>x : () => void + + // element access (read) + const b = super["x"]; +>b : () => void +>super["x"] : () => void +>super : A +>"x" : string + } + + // async method with assignment/destructuring on 'super' requires a binding + async advanced() { +>advanced : () => Promise + + const f = () => {}; +>f : () => void +>() => {} : () => void + + // call with property access + super.x(); +>super.x() : void +>super.x : () => void +>super : A +>x : () => void + + // call with element access + super["x"](); +>super["x"]() : void +>super["x"] : () => void +>super : A +>"x" : string + + // property access (read) + const a = super.x; +>a : () => void +>super.x : () => void +>super : A +>x : () => void + + // element access (read) + const b = super["x"]; +>b : () => void +>super["x"] : () => void +>super : A +>"x" : string + + // property access (assign) + super.x = f; +>super.x = f : () => void +>super.x : () => void +>super : A +>x : () => void +>f : () => void + + // element access (assign) + super["x"] = f; +>super["x"] = f : () => void +>super["x"] : () => void +>super : A +>"x" : string +>f : () => void + + // destructuring assign with property access + ({ f: super.x } = { f }); +>({ f: super.x } = { f }) : { f: () => void; } +>{ f: super.x } = { f } : { f: () => void; } +>{ f: super.x } : { f: () => void; } +>f : () => void +>super.x : () => void +>super : A +>x : () => void +>{ f } : { f: () => void; } +>f : () => void + + // destructuring assign with element access + ({ f: super["x"] } = { f }); +>({ f: super["x"] } = { f }) : { f: () => void; } +>{ f: super["x"] } = { f } : { f: () => void; } +>{ f: super["x"] } : { f: () => void; } +>f : () => void +>super["x"] : () => void +>super : A +>"x" : string +>{ f } : { f: () => void; } +>f : () => void + } +} diff --git a/tests/baselines/reference/asyncMultiFile.js b/tests/baselines/reference/asyncMultiFile.js index 95cf264f170b1..cbf3445ecc992 100644 --- a/tests/baselines/reference/asyncMultiFile.js +++ b/tests/baselines/reference/asyncMultiFile.js @@ -7,15 +7,15 @@ function g() { } //// [a.js] var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new P(function (resolve, reject) { + return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.call(thisArg, _arguments)).next()); + step((generator = generator.apply(thisArg, _arguments)).next()); }); }; function f() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } //// [b.js] function g() { } diff --git a/tests/baselines/reference/asyncQualifiedReturnType_es6.errors.txt b/tests/baselines/reference/asyncQualifiedReturnType_es6.errors.txt new file mode 100644 index 0000000000000..205ea01673631 --- /dev/null +++ b/tests/baselines/reference/asyncQualifiedReturnType_es6.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts(6,21): error TS1064: The return type of an async function or method must be the global Promise type. + + +==== tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts (1 errors) ==== + namespace X { + export class MyPromise extends Promise { + } + } + + async function f(): X.MyPromise { + ~~~~~~~~~~~~~~~~~ +!!! error TS1064: The return type of an async function or method must be the global Promise type. + } \ No newline at end of file diff --git a/tests/baselines/reference/asyncQualifiedReturnType_es6.js b/tests/baselines/reference/asyncQualifiedReturnType_es6.js index 1da37946254f6..4d5aa87bbffb4 100644 --- a/tests/baselines/reference/asyncQualifiedReturnType_es6.js +++ b/tests/baselines/reference/asyncQualifiedReturnType_es6.js @@ -15,6 +15,6 @@ var X; X.MyPromise = MyPromise; })(X || (X = {})); function f() { - return __awaiter(this, void 0, X.MyPromise, function* () { + return __awaiter(this, void 0, void 0, function* () { }); } diff --git a/tests/baselines/reference/asyncQualifiedReturnType_es6.symbols b/tests/baselines/reference/asyncQualifiedReturnType_es6.symbols deleted file mode 100644 index 5d27d04ea3bdc..0000000000000 --- a/tests/baselines/reference/asyncQualifiedReturnType_es6.symbols +++ /dev/null @@ -1,17 +0,0 @@ -=== tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts === -namespace X { ->X : Symbol(X, Decl(asyncQualifiedReturnType_es6.ts, 0, 0)) - - export class MyPromise extends Promise { ->MyPromise : Symbol(MyPromise, Decl(asyncQualifiedReturnType_es6.ts, 0, 13)) ->T : Symbol(T, Decl(asyncQualifiedReturnType_es6.ts, 1, 27)) ->Promise : Symbol(Promise, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) ->T : Symbol(T, Decl(asyncQualifiedReturnType_es6.ts, 1, 27)) - } -} - -async function f(): X.MyPromise { ->f : Symbol(f, Decl(asyncQualifiedReturnType_es6.ts, 3, 1)) ->X : Symbol(X, Decl(asyncQualifiedReturnType_es6.ts, 0, 0)) ->MyPromise : Symbol(X.MyPromise, Decl(asyncQualifiedReturnType_es6.ts, 0, 13)) -} diff --git a/tests/baselines/reference/asyncQualifiedReturnType_es6.types b/tests/baselines/reference/asyncQualifiedReturnType_es6.types deleted file mode 100644 index 3b438eb93b68a..0000000000000 --- a/tests/baselines/reference/asyncQualifiedReturnType_es6.types +++ /dev/null @@ -1,17 +0,0 @@ -=== tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts === -namespace X { ->X : typeof X - - export class MyPromise extends Promise { ->MyPromise : MyPromise ->T : T ->Promise : Promise ->T : T - } -} - -async function f(): X.MyPromise { ->f : () => X.MyPromise ->X : any ->MyPromise : X.MyPromise -} diff --git a/tests/baselines/reference/augmentExportEquals1.errors.txt b/tests/baselines/reference/augmentExportEquals1.errors.txt new file mode 100644 index 0000000000000..2d15e6d622a41 --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals1.errors.txt @@ -0,0 +1,26 @@ +tests/cases/compiler/file2.ts(6,16): error TS2671: Cannot augment module './file1' because it resolves to a non-module entity. +tests/cases/compiler/file3.ts(3,8): error TS2503: Cannot find namespace 'x'. + + +==== tests/cases/compiler/file3.ts (1 errors) ==== + import x = require("./file1"); + import "./file2"; + let a: x.A; // should not work + ~ +!!! error TS2503: Cannot find namespace 'x'. +==== tests/cases/compiler/file1.ts (0 errors) ==== + var x = 1; + export = x; + +==== tests/cases/compiler/file2.ts (1 errors) ==== + + import x = require("./file1"); + + // augmentation for './file1' + // should error since './file1' does not have namespace meaning + declare module "./file1" { + ~~~~~~~~~ +!!! error TS2671: Cannot augment module './file1' because it resolves to a non-module entity. + interface A { a } + } + \ No newline at end of file diff --git a/tests/baselines/reference/augmentExportEquals1.js b/tests/baselines/reference/augmentExportEquals1.js new file mode 100644 index 0000000000000..98322c01a34c9 --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals1.js @@ -0,0 +1,36 @@ +//// [tests/cases/compiler/augmentExportEquals1.ts] //// + +//// [file1.ts] +var x = 1; +export = x; + +//// [file2.ts] + +import x = require("./file1"); + +// augmentation for './file1' +// should error since './file1' does not have namespace meaning +declare module "./file1" { + interface A { a } +} + +//// [file3.ts] +import x = require("./file1"); +import "./file2"; +let a: x.A; // should not work + +//// [file1.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + var x = 1; + return x; +}); +//// [file2.js] +define(["require", "exports"], function (require, exports) { + "use strict"; +}); +//// [file3.js] +define(["require", "exports", "./file2"], function (require, exports) { + "use strict"; + var a; // should not work +}); diff --git a/tests/baselines/reference/augmentExportEquals1_1.errors.txt b/tests/baselines/reference/augmentExportEquals1_1.errors.txt new file mode 100644 index 0000000000000..aa89aa0c1d3e7 --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals1_1.errors.txt @@ -0,0 +1,29 @@ +tests/cases/compiler/file2.ts(6,16): error TS2671: Cannot augment module 'file1' because it resolves to a non-module entity. +tests/cases/compiler/file3.ts(3,8): error TS2503: Cannot find namespace 'x'. + + +==== tests/cases/compiler/file3.ts (1 errors) ==== + import x = require("file1"); + import "file2"; + let a: x.A; // should not work + ~ +!!! error TS2503: Cannot find namespace 'x'. +==== tests/cases/compiler/file1.d.ts (0 errors) ==== + + declare module "file1" { + var x: number; + export = x; + } + +==== tests/cases/compiler/file2.ts (1 errors) ==== + /// + import x = require("file1"); + + // augmentation for 'file1' + // should error since 'file1' does not have namespace meaning + declare module "file1" { + ~~~~~~~ +!!! error TS2671: Cannot augment module 'file1' because it resolves to a non-module entity. + interface A { a } + } + \ No newline at end of file diff --git a/tests/baselines/reference/augmentExportEquals1_1.js b/tests/baselines/reference/augmentExportEquals1_1.js new file mode 100644 index 0000000000000..08f032ff33f1c --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals1_1.js @@ -0,0 +1,33 @@ +//// [tests/cases/compiler/augmentExportEquals1_1.ts] //// + +//// [file1.d.ts] + +declare module "file1" { + var x: number; + export = x; +} + +//// [file2.ts] +/// +import x = require("file1"); + +// augmentation for 'file1' +// should error since 'file1' does not have namespace meaning +declare module "file1" { + interface A { a } +} + +//// [file3.ts] +import x = require("file1"); +import "file2"; +let a: x.A; // should not work + +//// [file2.js] +define(["require", "exports"], function (require, exports) { + "use strict"; +}); +//// [file3.js] +define(["require", "exports", "file2"], function (require, exports) { + "use strict"; + var a; // should not work +}); diff --git a/tests/baselines/reference/augmentExportEquals2.errors.txt b/tests/baselines/reference/augmentExportEquals2.errors.txt new file mode 100644 index 0000000000000..b078a6623d7c0 --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals2.errors.txt @@ -0,0 +1,25 @@ +tests/cases/compiler/file2.ts(4,16): error TS2671: Cannot augment module './file1' because it resolves to a non-module entity. +tests/cases/compiler/file3.ts(3,8): error TS2503: Cannot find namespace 'x'. + + +==== tests/cases/compiler/file3.ts (1 errors) ==== + import x = require("./file1"); + import "./file2"; + let a: x.A; // should not work + ~ +!!! error TS2503: Cannot find namespace 'x'. +==== tests/cases/compiler/file1.ts (0 errors) ==== + + function foo() {} + export = foo; + +==== tests/cases/compiler/file2.ts (1 errors) ==== + import x = require("./file1"); + + // should error since './file1' does not have namespace meaning + declare module "./file1" { + ~~~~~~~~~ +!!! error TS2671: Cannot augment module './file1' because it resolves to a non-module entity. + interface A { a } + } + \ No newline at end of file diff --git a/tests/baselines/reference/augmentExportEquals2.js b/tests/baselines/reference/augmentExportEquals2.js new file mode 100644 index 0000000000000..fc373173e3c44 --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals2.js @@ -0,0 +1,35 @@ +//// [tests/cases/compiler/augmentExportEquals2.ts] //// + +//// [file1.ts] + +function foo() {} +export = foo; + +//// [file2.ts] +import x = require("./file1"); + +// should error since './file1' does not have namespace meaning +declare module "./file1" { + interface A { a } +} + +//// [file3.ts] +import x = require("./file1"); +import "./file2"; +let a: x.A; // should not work + +//// [file1.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + function foo() { } + return foo; +}); +//// [file2.js] +define(["require", "exports"], function (require, exports) { + "use strict"; +}); +//// [file3.js] +define(["require", "exports", "./file2"], function (require, exports) { + "use strict"; + var a; // should not work +}); diff --git a/tests/baselines/reference/augmentExportEquals2_1.errors.txt b/tests/baselines/reference/augmentExportEquals2_1.errors.txt new file mode 100644 index 0000000000000..8e02f21176ae5 --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals2_1.errors.txt @@ -0,0 +1,29 @@ +tests/cases/compiler/file2.ts(6,16): error TS2671: Cannot augment module 'file1' because it resolves to a non-module entity. +tests/cases/compiler/file3.ts(3,8): error TS2503: Cannot find namespace 'x'. + + +==== tests/cases/compiler/file3.ts (1 errors) ==== + import x = require("file1"); + import "file2"; + let a: x.A; // should not work + ~ +!!! error TS2503: Cannot find namespace 'x'. +==== tests/cases/compiler/file1.d.ts (0 errors) ==== + + declare module "file1" { + function foo(): void; + export = foo; + } + +==== tests/cases/compiler/file2.ts (1 errors) ==== + + /// + import x = require("file1"); + + // should error since './file1' does not have namespace meaning + declare module "file1" { + ~~~~~~~ +!!! error TS2671: Cannot augment module 'file1' because it resolves to a non-module entity. + interface A { a } + } + \ No newline at end of file diff --git a/tests/baselines/reference/augmentExportEquals2_1.js b/tests/baselines/reference/augmentExportEquals2_1.js new file mode 100644 index 0000000000000..9046157bb2626 --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals2_1.js @@ -0,0 +1,33 @@ +//// [tests/cases/compiler/augmentExportEquals2_1.ts] //// + +//// [file1.d.ts] + +declare module "file1" { + function foo(): void; + export = foo; +} + +//// [file2.ts] + +/// +import x = require("file1"); + +// should error since './file1' does not have namespace meaning +declare module "file1" { + interface A { a } +} + +//// [file3.ts] +import x = require("file1"); +import "file2"; +let a: x.A; // should not work + +//// [file2.js] +define(["require", "exports"], function (require, exports) { + "use strict"; +}); +//// [file3.js] +define(["require", "exports", "file2"], function (require, exports) { + "use strict"; + var a; // should not work +}); diff --git a/tests/baselines/reference/augmentExportEquals3.errors.txt b/tests/baselines/reference/augmentExportEquals3.errors.txt new file mode 100644 index 0000000000000..9fe63d84fb625 --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals3.errors.txt @@ -0,0 +1,31 @@ +tests/cases/compiler/file2.ts(6,15): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/file2.ts(7,9): error TS2665: Module augmentation cannot introduce new names in the top level scope. + + +==== tests/cases/compiler/file1.ts (0 errors) ==== + + function foo() {} + namespace foo { + export var v = 1; + } + export = foo; + +==== tests/cases/compiler/file2.ts (2 errors) ==== + import x = require("./file1"); + x.b = 1; + + // OK - './file1' is a namespace + declare module "./file1" { + interface A { a } + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + let b: number; + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + } + +==== tests/cases/compiler/file3.ts (0 errors) ==== + import * as x from "./file1"; + import "./file2"; + let a: x.A; + let b = x.b; \ No newline at end of file diff --git a/tests/baselines/reference/augmentExportEquals3.js b/tests/baselines/reference/augmentExportEquals3.js new file mode 100644 index 0000000000000..82cfa5f216656 --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals3.js @@ -0,0 +1,47 @@ +//// [tests/cases/compiler/augmentExportEquals3.ts] //// + +//// [file1.ts] + +function foo() {} +namespace foo { + export var v = 1; +} +export = foo; + +//// [file2.ts] +import x = require("./file1"); +x.b = 1; + +// OK - './file1' is a namespace +declare module "./file1" { + interface A { a } + let b: number; +} + +//// [file3.ts] +import * as x from "./file1"; +import "./file2"; +let a: x.A; +let b = x.b; + +//// [file1.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + function foo() { } + var foo; + (function (foo) { + foo.v = 1; + })(foo || (foo = {})); + return foo; +}); +//// [file2.js] +define(["require", "exports", "./file1"], function (require, exports, x) { + "use strict"; + x.b = 1; +}); +//// [file3.js] +define(["require", "exports", "./file1", "./file2"], function (require, exports, x) { + "use strict"; + var a; + var b = x.b; +}); diff --git a/tests/baselines/reference/augmentExportEquals3_1.errors.txt b/tests/baselines/reference/augmentExportEquals3_1.errors.txt new file mode 100644 index 0000000000000..9fb0ce5f16924 --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals3_1.errors.txt @@ -0,0 +1,34 @@ +tests/cases/compiler/file2.ts(7,15): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/file2.ts(8,9): error TS2665: Module augmentation cannot introduce new names in the top level scope. + + +==== tests/cases/compiler/file1.d.ts (0 errors) ==== + declare module "file1" { + function foo(): void; + namespace foo { + export var v: number; + } + export = foo; + } + + +==== tests/cases/compiler/file2.ts (2 errors) ==== + /// + import x = require("file1"); + x.b = 1; + + // OK - './file1' is a namespace + declare module "file1" { + interface A { a } + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + let b: number; + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + } + +==== tests/cases/compiler/file3.ts (0 errors) ==== + import * as x from "file1"; + import "file2"; + let a: x.A; + let b = x.b; \ No newline at end of file diff --git a/tests/baselines/reference/augmentExportEquals3_1.js b/tests/baselines/reference/augmentExportEquals3_1.js new file mode 100644 index 0000000000000..fc6b7b1cec35e --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals3_1.js @@ -0,0 +1,40 @@ +//// [tests/cases/compiler/augmentExportEquals3_1.ts] //// + +//// [file1.d.ts] +declare module "file1" { + function foo(): void; + namespace foo { + export var v: number; + } + export = foo; +} + + +//// [file2.ts] +/// +import x = require("file1"); +x.b = 1; + +// OK - './file1' is a namespace +declare module "file1" { + interface A { a } + let b: number; +} + +//// [file3.ts] +import * as x from "file1"; +import "file2"; +let a: x.A; +let b = x.b; + +//// [file2.js] +define(["require", "exports", "file1"], function (require, exports, x) { + "use strict"; + x.b = 1; +}); +//// [file3.js] +define(["require", "exports", "file1", "file2"], function (require, exports, x) { + "use strict"; + var a; + var b = x.b; +}); diff --git a/tests/baselines/reference/augmentExportEquals4.errors.txt b/tests/baselines/reference/augmentExportEquals4.errors.txt new file mode 100644 index 0000000000000..20f7cc32d9ffd --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals4.errors.txt @@ -0,0 +1,31 @@ +tests/cases/compiler/file2.ts(6,15): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/file2.ts(7,9): error TS2665: Module augmentation cannot introduce new names in the top level scope. + + +==== tests/cases/compiler/file1.ts (0 errors) ==== + + class foo {} + namespace foo { + export var v = 1; + } + export = foo; + +==== tests/cases/compiler/file2.ts (2 errors) ==== + import x = require("./file1"); + x.b = 1; + + // OK - './file1' is a namespace + declare module "./file1" { + interface A { a } + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + let b: number; + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + } + +==== tests/cases/compiler/file3.ts (0 errors) ==== + import * as x from "./file1"; + import "./file2"; + let a: x.A; + let b = x.b; \ No newline at end of file diff --git a/tests/baselines/reference/augmentExportEquals4.js b/tests/baselines/reference/augmentExportEquals4.js new file mode 100644 index 0000000000000..ee0fc1892c2d1 --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals4.js @@ -0,0 +1,51 @@ +//// [tests/cases/compiler/augmentExportEquals4.ts] //// + +//// [file1.ts] + +class foo {} +namespace foo { + export var v = 1; +} +export = foo; + +//// [file2.ts] +import x = require("./file1"); +x.b = 1; + +// OK - './file1' is a namespace +declare module "./file1" { + interface A { a } + let b: number; +} + +//// [file3.ts] +import * as x from "./file1"; +import "./file2"; +let a: x.A; +let b = x.b; + +//// [file1.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + var foo = (function () { + function foo() { + } + return foo; + }()); + var foo; + (function (foo) { + foo.v = 1; + })(foo || (foo = {})); + return foo; +}); +//// [file2.js] +define(["require", "exports", "./file1"], function (require, exports, x) { + "use strict"; + x.b = 1; +}); +//// [file3.js] +define(["require", "exports", "./file1", "./file2"], function (require, exports, x) { + "use strict"; + var a; + var b = x.b; +}); diff --git a/tests/baselines/reference/augmentExportEquals4_1.errors.txt b/tests/baselines/reference/augmentExportEquals4_1.errors.txt new file mode 100644 index 0000000000000..a401f7a24cfed --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals4_1.errors.txt @@ -0,0 +1,35 @@ +tests/cases/compiler/file2.ts(7,15): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/file2.ts(8,9): error TS2665: Module augmentation cannot introduce new names in the top level scope. + + +==== tests/cases/compiler/file1.d.ts (0 errors) ==== + + declare module "file1" { + class foo {} + namespace foo { + export var v: number; + } + export = foo; + } + + +==== tests/cases/compiler/file2.ts (2 errors) ==== + /// + import x = require("file1"); + x.b = 1; + + // OK - './file1' is a namespace + declare module "file1" { + interface A { a } + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + let b: number; + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + } + +==== tests/cases/compiler/file3.ts (0 errors) ==== + import * as x from "file1"; + import "file2"; + let a: x.A; + let b = x.b; \ No newline at end of file diff --git a/tests/baselines/reference/augmentExportEquals4_1.js b/tests/baselines/reference/augmentExportEquals4_1.js new file mode 100644 index 0000000000000..b4ba932d44b4c --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals4_1.js @@ -0,0 +1,41 @@ +//// [tests/cases/compiler/augmentExportEquals4_1.ts] //// + +//// [file1.d.ts] + +declare module "file1" { + class foo {} + namespace foo { + export var v: number; + } + export = foo; +} + + +//// [file2.ts] +/// +import x = require("file1"); +x.b = 1; + +// OK - './file1' is a namespace +declare module "file1" { + interface A { a } + let b: number; +} + +//// [file3.ts] +import * as x from "file1"; +import "file2"; +let a: x.A; +let b = x.b; + +//// [file2.js] +define(["require", "exports", "file1"], function (require, exports, x) { + "use strict"; + x.b = 1; +}); +//// [file3.js] +define(["require", "exports", "file1", "file2"], function (require, exports, x) { + "use strict"; + var a; + var b = x.b; +}); diff --git a/tests/baselines/reference/augmentExportEquals5.js b/tests/baselines/reference/augmentExportEquals5.js new file mode 100644 index 0000000000000..49b6c3fed564a --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals5.js @@ -0,0 +1,94 @@ +//// [tests/cases/compiler/augmentExportEquals5.ts] //// + +//// [express.d.ts] + + +declare module Express { + export interface Request { } + export interface Response { } + export interface Application { } +} + +declare module "express" { + function e(): e.Express; + namespace e { + interface IRoute { + all(...handler: RequestHandler[]): IRoute; + } + + interface IRouterMatcher { + (name: string|RegExp, ...handlers: RequestHandler[]): T; + } + + interface IRouter extends RequestHandler { + route(path: string): IRoute; + } + + export function Router(options?: any): Router; + + export interface Router extends IRouter {} + + interface Errback { (err: Error): void; } + + interface Request extends Express.Request { + + get (name: string): string; + } + + interface Response extends Express.Response { + charset: string; + } + + interface ErrorRequestHandler { + (err: any, req: Request, res: Response, next: Function): any; + } + + interface RequestHandler { + (req: Request, res: Response, next: Function): any; + } + + interface Handler extends RequestHandler {} + + interface RequestParamHandler { + (req: Request, res: Response, next: Function, param: any): any; + } + + interface Application extends IRouter, Express.Application { + routes: any; + } + + interface Express extends Application { + createApplication(): Application; + } + + var static: any; + } + + export = e; +} + +//// [augmentation.ts] +/// +import * as e from "express"; +declare module "express" { + interface Request { + id: number; + } +} + +//// [consumer.ts] +import { Request } from "express"; +import "./augmentation"; +let x: Request; +const y = x.id; + +//// [augmentation.js] +define(["require", "exports"], function (require, exports) { + "use strict"; +}); +//// [consumer.js] +define(["require", "exports", "./augmentation"], function (require, exports) { + "use strict"; + var x; + var y = x.id; +}); diff --git a/tests/baselines/reference/augmentExportEquals5.symbols b/tests/baselines/reference/augmentExportEquals5.symbols new file mode 100644 index 0000000000000..f255bf8c065c9 --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals5.symbols @@ -0,0 +1,194 @@ +=== tests/cases/compiler/express.d.ts === + + +declare module Express { +>Express : Symbol(Express, Decl(express.d.ts, 0, 0)) + + export interface Request { } +>Request : Symbol(Request, Decl(express.d.ts, 2, 24)) + + export interface Response { } +>Response : Symbol(Response, Decl(express.d.ts, 3, 32)) + + export interface Application { } +>Application : Symbol(Application, Decl(express.d.ts, 4, 33)) +} + +declare module "express" { + function e(): e.Express; +>e : Symbol(, Decl(express.d.ts, 8, 26), Decl(express.d.ts, 9, 28), Decl(augmentation.ts, 1, 29)) +>e : Symbol(e, Decl(express.d.ts, 8, 26), Decl(express.d.ts, 9, 28)) +>Express : Symbol(Express, Decl(express.d.ts, 54, 9)) + + namespace e { +>e : Symbol(, Decl(express.d.ts, 8, 26), Decl(express.d.ts, 9, 28), Decl(augmentation.ts, 1, 29)) + + interface IRoute { +>IRoute : Symbol(IRoute, Decl(express.d.ts, 10, 17)) + + all(...handler: RequestHandler[]): IRoute; +>all : Symbol(all, Decl(express.d.ts, 11, 26)) +>handler : Symbol(handler, Decl(express.d.ts, 12, 16)) +>RequestHandler : Symbol(RequestHandler, Decl(express.d.ts, 40, 9)) +>IRoute : Symbol(IRoute, Decl(express.d.ts, 10, 17)) + } + + interface IRouterMatcher { +>IRouterMatcher : Symbol(IRouterMatcher, Decl(express.d.ts, 13, 9)) +>T : Symbol(T, Decl(express.d.ts, 15, 33)) + + (name: string|RegExp, ...handlers: RequestHandler[]): T; +>name : Symbol(name, Decl(express.d.ts, 16, 13)) +>RegExp : Symbol(RegExp, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>handlers : Symbol(handlers, Decl(express.d.ts, 16, 33)) +>RequestHandler : Symbol(RequestHandler, Decl(express.d.ts, 40, 9)) +>T : Symbol(T, Decl(express.d.ts, 15, 33)) + } + + interface IRouter extends RequestHandler { +>IRouter : Symbol(IRouter, Decl(express.d.ts, 17, 9)) +>T : Symbol(T, Decl(express.d.ts, 19, 26)) +>RequestHandler : Symbol(RequestHandler, Decl(express.d.ts, 40, 9)) + + route(path: string): IRoute; +>route : Symbol(route, Decl(express.d.ts, 19, 53)) +>path : Symbol(path, Decl(express.d.ts, 20, 18)) +>IRoute : Symbol(IRoute, Decl(express.d.ts, 10, 17)) + } + + export function Router(options?: any): Router; +>Router : Symbol(Router, Decl(express.d.ts, 21, 9), Decl(express.d.ts, 23, 54)) +>options : Symbol(options, Decl(express.d.ts, 23, 31)) +>Router : Symbol(Router, Decl(express.d.ts, 21, 9), Decl(express.d.ts, 23, 54)) + + export interface Router extends IRouter {} +>Router : Symbol(Router, Decl(express.d.ts, 21, 9), Decl(express.d.ts, 23, 54)) +>IRouter : Symbol(IRouter, Decl(express.d.ts, 17, 9)) +>Router : Symbol(Router, Decl(express.d.ts, 21, 9), Decl(express.d.ts, 23, 54)) + + interface Errback { (err: Error): void; } +>Errback : Symbol(Errback, Decl(express.d.ts, 25, 58)) +>err : Symbol(err, Decl(express.d.ts, 27, 29)) +>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + + interface Request extends Express.Request { +>Request : Symbol(Request, Decl(express.d.ts, 27, 49), Decl(augmentation.ts, 2, 26)) +>Express.Request : Symbol(Express.Request, Decl(express.d.ts, 2, 24)) +>Express : Symbol(Express, Decl(express.d.ts, 0, 0)) +>Request : Symbol(Express.Request, Decl(express.d.ts, 2, 24)) + + get (name: string): string; +>get : Symbol(get, Decl(express.d.ts, 29, 51)) +>name : Symbol(name, Decl(express.d.ts, 31, 17)) + } + + interface Response extends Express.Response { +>Response : Symbol(Response, Decl(express.d.ts, 32, 9)) +>Express.Response : Symbol(Express.Response, Decl(express.d.ts, 3, 32)) +>Express : Symbol(Express, Decl(express.d.ts, 0, 0)) +>Response : Symbol(Express.Response, Decl(express.d.ts, 3, 32)) + + charset: string; +>charset : Symbol(charset, Decl(express.d.ts, 34, 53)) + } + + interface ErrorRequestHandler { +>ErrorRequestHandler : Symbol(ErrorRequestHandler, Decl(express.d.ts, 36, 9)) + + (err: any, req: Request, res: Response, next: Function): any; +>err : Symbol(err, Decl(express.d.ts, 39, 13)) +>req : Symbol(req, Decl(express.d.ts, 39, 22)) +>Request : Symbol(Request, Decl(express.d.ts, 27, 49), Decl(augmentation.ts, 2, 26)) +>res : Symbol(res, Decl(express.d.ts, 39, 36)) +>Response : Symbol(Response, Decl(express.d.ts, 32, 9)) +>next : Symbol(next, Decl(express.d.ts, 39, 51)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + } + + interface RequestHandler { +>RequestHandler : Symbol(RequestHandler, Decl(express.d.ts, 40, 9)) + + (req: Request, res: Response, next: Function): any; +>req : Symbol(req, Decl(express.d.ts, 43, 13)) +>Request : Symbol(Request, Decl(express.d.ts, 27, 49), Decl(augmentation.ts, 2, 26)) +>res : Symbol(res, Decl(express.d.ts, 43, 26)) +>Response : Symbol(Response, Decl(express.d.ts, 32, 9)) +>next : Symbol(next, Decl(express.d.ts, 43, 41)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + } + + interface Handler extends RequestHandler {} +>Handler : Symbol(Handler, Decl(express.d.ts, 44, 9)) +>RequestHandler : Symbol(RequestHandler, Decl(express.d.ts, 40, 9)) + + interface RequestParamHandler { +>RequestParamHandler : Symbol(RequestParamHandler, Decl(express.d.ts, 46, 51)) + + (req: Request, res: Response, next: Function, param: any): any; +>req : Symbol(req, Decl(express.d.ts, 49, 13)) +>Request : Symbol(Request, Decl(express.d.ts, 27, 49), Decl(augmentation.ts, 2, 26)) +>res : Symbol(res, Decl(express.d.ts, 49, 26)) +>Response : Symbol(Response, Decl(express.d.ts, 32, 9)) +>next : Symbol(next, Decl(express.d.ts, 49, 41)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>param : Symbol(param, Decl(express.d.ts, 49, 57)) + } + + interface Application extends IRouter, Express.Application { +>Application : Symbol(Application, Decl(express.d.ts, 50, 9)) +>IRouter : Symbol(IRouter, Decl(express.d.ts, 17, 9)) +>Application : Symbol(Application, Decl(express.d.ts, 50, 9)) +>Express.Application : Symbol(Express.Application, Decl(express.d.ts, 4, 33)) +>Express : Symbol(Express, Decl(express.d.ts, 0, 0)) +>Application : Symbol(Express.Application, Decl(express.d.ts, 4, 33)) + + routes: any; +>routes : Symbol(routes, Decl(express.d.ts, 52, 81)) + } + + interface Express extends Application { +>Express : Symbol(Express, Decl(express.d.ts, 54, 9)) +>Application : Symbol(Application, Decl(express.d.ts, 50, 9)) + + createApplication(): Application; +>createApplication : Symbol(createApplication, Decl(express.d.ts, 56, 47)) +>Application : Symbol(Application, Decl(express.d.ts, 50, 9)) + } + + var static: any; +>static : Symbol(static, Decl(express.d.ts, 60, 11)) + } + + export = e; +>e : Symbol(e, Decl(express.d.ts, 8, 26), Decl(express.d.ts, 9, 28)) +} + +=== tests/cases/compiler/augmentation.ts === +/// +import * as e from "express"; +>e : Symbol(e, Decl(augmentation.ts, 1, 6)) + +declare module "express" { + interface Request { +>Request : Symbol(Request, Decl(express.d.ts, 27, 49), Decl(augmentation.ts, 2, 26)) + + id: number; +>id : Symbol(id, Decl(augmentation.ts, 3, 23)) + } +} + +=== tests/cases/compiler/consumer.ts === +import { Request } from "express"; +>Request : Symbol(Request, Decl(consumer.ts, 0, 8)) + +import "./augmentation"; +let x: Request; +>x : Symbol(x, Decl(consumer.ts, 2, 3)) +>Request : Symbol(Request, Decl(consumer.ts, 0, 8)) + +const y = x.id; +>y : Symbol(y, Decl(consumer.ts, 3, 5)) +>x.id : Symbol(Request.id, Decl(augmentation.ts, 3, 23)) +>x : Symbol(x, Decl(consumer.ts, 2, 3)) +>id : Symbol(Request.id, Decl(augmentation.ts, 3, 23)) + diff --git a/tests/baselines/reference/augmentExportEquals5.types b/tests/baselines/reference/augmentExportEquals5.types new file mode 100644 index 0000000000000..42b79674dfd70 --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals5.types @@ -0,0 +1,194 @@ +=== tests/cases/compiler/express.d.ts === + + +declare module Express { +>Express : any + + export interface Request { } +>Request : Request + + export interface Response { } +>Response : Response + + export interface Application { } +>Application : Application +} + +declare module "express" { + function e(): e.Express; +>e : typeof +>e : any +>Express : Express + + namespace e { +>e : typeof + + interface IRoute { +>IRoute : IRoute + + all(...handler: RequestHandler[]): IRoute; +>all : (...handler: RequestHandler[]) => IRoute +>handler : RequestHandler[] +>RequestHandler : RequestHandler +>IRoute : IRoute + } + + interface IRouterMatcher { +>IRouterMatcher : IRouterMatcher +>T : T + + (name: string|RegExp, ...handlers: RequestHandler[]): T; +>name : string | RegExp +>RegExp : RegExp +>handlers : RequestHandler[] +>RequestHandler : RequestHandler +>T : T + } + + interface IRouter extends RequestHandler { +>IRouter : IRouter +>T : T +>RequestHandler : RequestHandler + + route(path: string): IRoute; +>route : (path: string) => IRoute +>path : string +>IRoute : IRoute + } + + export function Router(options?: any): Router; +>Router : (options?: any) => Router +>options : any +>Router : Router + + export interface Router extends IRouter {} +>Router : Router +>IRouter : IRouter +>Router : Router + + interface Errback { (err: Error): void; } +>Errback : Errback +>err : Error +>Error : Error + + interface Request extends Express.Request { +>Request : Request +>Express.Request : any +>Express : any +>Request : Express.Request + + get (name: string): string; +>get : (name: string) => string +>name : string + } + + interface Response extends Express.Response { +>Response : Response +>Express.Response : any +>Express : any +>Response : Express.Response + + charset: string; +>charset : string + } + + interface ErrorRequestHandler { +>ErrorRequestHandler : ErrorRequestHandler + + (err: any, req: Request, res: Response, next: Function): any; +>err : any +>req : Request +>Request : Request +>res : Response +>Response : Response +>next : Function +>Function : Function + } + + interface RequestHandler { +>RequestHandler : RequestHandler + + (req: Request, res: Response, next: Function): any; +>req : Request +>Request : Request +>res : Response +>Response : Response +>next : Function +>Function : Function + } + + interface Handler extends RequestHandler {} +>Handler : Handler +>RequestHandler : RequestHandler + + interface RequestParamHandler { +>RequestParamHandler : RequestParamHandler + + (req: Request, res: Response, next: Function, param: any): any; +>req : Request +>Request : Request +>res : Response +>Response : Response +>next : Function +>Function : Function +>param : any + } + + interface Application extends IRouter, Express.Application { +>Application : Application +>IRouter : IRouter +>Application : Application +>Express.Application : any +>Express : any +>Application : Express.Application + + routes: any; +>routes : any + } + + interface Express extends Application { +>Express : Express +>Application : Application + + createApplication(): Application; +>createApplication : () => Application +>Application : Application + } + + var static: any; +>static : any + } + + export = e; +>e : typeof e +} + +=== tests/cases/compiler/augmentation.ts === +/// +import * as e from "express"; +>e : typeof e + +declare module "express" { + interface Request { +>Request : Request + + id: number; +>id : number + } +} + +=== tests/cases/compiler/consumer.ts === +import { Request } from "express"; +>Request : any + +import "./augmentation"; +let x: Request; +>x : Request +>Request : Request + +const y = x.id; +>y : number +>x.id : number +>x : Request +>id : number + diff --git a/tests/baselines/reference/augmentExportEquals6.js b/tests/baselines/reference/augmentExportEquals6.js new file mode 100644 index 0000000000000..94dfa389c6d1c --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals6.js @@ -0,0 +1,64 @@ +//// [tests/cases/compiler/augmentExportEquals6.ts] //// + +//// [file1.ts] + +class foo {} +namespace foo { + export class A {} + export namespace B { export let a; } +} +export = foo; + +//// [file2.ts] +import x = require("./file1"); +x.B.b = 1; + +// OK - './file1' is a namespace +declare module "./file1" { + interface A { a: number } + namespace B { + export let b: number; + } +} + +//// [file3.ts] +import * as x from "./file1"; +import "./file2"; +let a: x.A; +let b = a.a; +let c = x.B.b; + +//// [file1.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + var foo = (function () { + function foo() { + } + return foo; + }()); + var foo; + (function (foo) { + var A = (function () { + function A() { + } + return A; + }()); + foo.A = A; + var B; + (function (B) { + })(B = foo.B || (foo.B = {})); + })(foo || (foo = {})); + return foo; +}); +//// [file2.js] +define(["require", "exports", "./file1"], function (require, exports, x) { + "use strict"; + x.B.b = 1; +}); +//// [file3.js] +define(["require", "exports", "./file1", "./file2"], function (require, exports, x) { + "use strict"; + var a; + var b = a.a; + var c = x.B.b; +}); diff --git a/tests/baselines/reference/augmentExportEquals6.symbols b/tests/baselines/reference/augmentExportEquals6.symbols new file mode 100644 index 0000000000000..24f8ef7c9030e --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals6.symbols @@ -0,0 +1,67 @@ +=== tests/cases/compiler/file1.ts === + +class foo {} +>foo : Symbol(, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 12), Decl(file2.ts, 1, 10)) + +namespace foo { +>foo : Symbol(, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 12), Decl(file2.ts, 1, 10)) + + export class A {} +>A : Symbol(A, Decl(file1.ts, 2, 15), Decl(file2.ts, 4, 26)) + + export namespace B { export let a; } +>B : Symbol(B, Decl(file1.ts, 3, 21), Decl(file2.ts, 5, 29)) +>a : Symbol(a, Decl(file1.ts, 4, 35)) +} +export = foo; +>foo : Symbol(foo, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 12)) + +=== tests/cases/compiler/file2.ts === +import x = require("./file1"); +>x : Symbol(x, Decl(file2.ts, 0, 0)) + +x.B.b = 1; +>x.B.b : Symbol(x.B.b, Decl(file2.ts, 7, 18)) +>x.B : Symbol(x.B, Decl(file1.ts, 3, 21), Decl(file2.ts, 5, 29)) +>x : Symbol(x, Decl(file2.ts, 0, 0)) +>B : Symbol(x.B, Decl(file1.ts, 3, 21), Decl(file2.ts, 5, 29)) +>b : Symbol(x.B.b, Decl(file2.ts, 7, 18)) + +// OK - './file1' is a namespace +declare module "./file1" { + interface A { a: number } +>A : Symbol(A, Decl(file1.ts, 2, 15), Decl(file2.ts, 4, 26)) +>a : Symbol(a, Decl(file2.ts, 5, 17)) + + namespace B { +>B : Symbol(B, Decl(file1.ts, 3, 21), Decl(file2.ts, 5, 29)) + + export let b: number; +>b : Symbol(b, Decl(file2.ts, 7, 18)) + } +} + +=== tests/cases/compiler/file3.ts === +import * as x from "./file1"; +>x : Symbol(x, Decl(file3.ts, 0, 6)) + +import "./file2"; +let a: x.A; +>a : Symbol(a, Decl(file3.ts, 2, 3)) +>x : Symbol(x, Decl(file3.ts, 0, 6)) +>A : Symbol(x.A, Decl(file1.ts, 2, 15), Decl(file2.ts, 4, 26)) + +let b = a.a; +>b : Symbol(b, Decl(file3.ts, 3, 3)) +>a.a : Symbol(x.A.a, Decl(file2.ts, 5, 17)) +>a : Symbol(a, Decl(file3.ts, 2, 3)) +>a : Symbol(x.A.a, Decl(file2.ts, 5, 17)) + +let c = x.B.b; +>c : Symbol(c, Decl(file3.ts, 4, 3)) +>x.B.b : Symbol(x.B.b, Decl(file2.ts, 7, 18)) +>x.B : Symbol(x.B, Decl(file1.ts, 3, 21), Decl(file2.ts, 5, 29)) +>x : Symbol(x, Decl(file3.ts, 0, 6)) +>B : Symbol(x.B, Decl(file1.ts, 3, 21), Decl(file2.ts, 5, 29)) +>b : Symbol(x.B.b, Decl(file2.ts, 7, 18)) + diff --git a/tests/baselines/reference/augmentExportEquals6.types b/tests/baselines/reference/augmentExportEquals6.types new file mode 100644 index 0000000000000..1a2b2b22ccb2f --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals6.types @@ -0,0 +1,69 @@ +=== tests/cases/compiler/file1.ts === + +class foo {} +>foo : + +namespace foo { +>foo : typeof + + export class A {} +>A : A + + export namespace B { export let a; } +>B : typeof B +>a : any +} +export = foo; +>foo : foo + +=== tests/cases/compiler/file2.ts === +import x = require("./file1"); +>x : typeof x + +x.B.b = 1; +>x.B.b = 1 : number +>x.B.b : number +>x.B : typeof x.B +>x : typeof x +>B : typeof x.B +>b : number +>1 : number + +// OK - './file1' is a namespace +declare module "./file1" { + interface A { a: number } +>A : A +>a : number + + namespace B { +>B : typeof B + + export let b: number; +>b : number + } +} + +=== tests/cases/compiler/file3.ts === +import * as x from "./file1"; +>x : typeof x + +import "./file2"; +let a: x.A; +>a : x.A +>x : any +>A : x.A + +let b = a.a; +>b : number +>a.a : number +>a : x.A +>a : number + +let c = x.B.b; +>c : number +>x.B.b : number +>x.B : typeof x.B +>x : typeof x +>B : typeof x.B +>b : number + diff --git a/tests/baselines/reference/augmentExportEquals6_1.js b/tests/baselines/reference/augmentExportEquals6_1.js new file mode 100644 index 0000000000000..c7c560183cc2d --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals6_1.js @@ -0,0 +1,38 @@ +//// [tests/cases/compiler/augmentExportEquals6_1.ts] //// + +//// [file1.d.ts] + +declare module "file1" { + class foo {} + namespace foo { + class A {} + } + export = foo; +} + + +//// [file2.ts] +/// +import x = require("file1"); + +// OK - './file1' is a namespace +declare module "file1" { + interface A { a: number } +} + +//// [file3.ts] +import * as x from "file1"; +import "file2"; +let a: x.A; +let b = a.a; + +//// [file2.js] +define(["require", "exports"], function (require, exports) { + "use strict"; +}); +//// [file3.js] +define(["require", "exports", "file2"], function (require, exports) { + "use strict"; + var a; + var b = a.a; +}); diff --git a/tests/baselines/reference/augmentExportEquals6_1.symbols b/tests/baselines/reference/augmentExportEquals6_1.symbols new file mode 100644 index 0000000000000..5c45af00a48d7 --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals6_1.symbols @@ -0,0 +1,45 @@ +=== tests/cases/compiler/file1.d.ts === + +declare module "file1" { + class foo {} +>foo : Symbol(, Decl(file1.d.ts, 1, 24), Decl(file1.d.ts, 2, 16), Decl(file2.ts, 1, 28)) + + namespace foo { +>foo : Symbol(, Decl(file1.d.ts, 1, 24), Decl(file1.d.ts, 2, 16), Decl(file2.ts, 1, 28)) + + class A {} +>A : Symbol(A, Decl(file1.d.ts, 3, 19), Decl(file2.ts, 4, 24)) + } + export = foo; +>foo : Symbol(foo, Decl(file1.d.ts, 1, 24), Decl(file1.d.ts, 2, 16)) +} + + +=== tests/cases/compiler/file2.ts === +/// +import x = require("file1"); +>x : Symbol(x, Decl(file2.ts, 0, 0)) + +// OK - './file1' is a namespace +declare module "file1" { + interface A { a: number } +>A : Symbol(A, Decl(file1.d.ts, 3, 19), Decl(file2.ts, 4, 24)) +>a : Symbol(a, Decl(file2.ts, 5, 17)) +} + +=== tests/cases/compiler/file3.ts === +import * as x from "file1"; +>x : Symbol(x, Decl(file3.ts, 0, 6)) + +import "file2"; +let a: x.A; +>a : Symbol(a, Decl(file3.ts, 2, 3)) +>x : Symbol(x, Decl(file3.ts, 0, 6)) +>A : Symbol(x.A, Decl(file1.d.ts, 3, 19), Decl(file2.ts, 4, 24)) + +let b = a.a; +>b : Symbol(b, Decl(file3.ts, 3, 3)) +>a.a : Symbol(x.A.a, Decl(file2.ts, 5, 17)) +>a : Symbol(a, Decl(file3.ts, 2, 3)) +>a : Symbol(x.A.a, Decl(file2.ts, 5, 17)) + diff --git a/tests/baselines/reference/augmentExportEquals6_1.types b/tests/baselines/reference/augmentExportEquals6_1.types new file mode 100644 index 0000000000000..a9cc78056c860 --- /dev/null +++ b/tests/baselines/reference/augmentExportEquals6_1.types @@ -0,0 +1,45 @@ +=== tests/cases/compiler/file1.d.ts === + +declare module "file1" { + class foo {} +>foo : + + namespace foo { +>foo : typeof + + class A {} +>A : A + } + export = foo; +>foo : foo +} + + +=== tests/cases/compiler/file2.ts === +/// +import x = require("file1"); +>x : typeof x + +// OK - './file1' is a namespace +declare module "file1" { + interface A { a: number } +>A : A +>a : number +} + +=== tests/cases/compiler/file3.ts === +import * as x from "file1"; +>x : typeof x + +import "file2"; +let a: x.A; +>a : x.A +>x : any +>A : x.A + +let b = a.a; +>b : number +>a.a : number +>a : x.A +>a : number + diff --git a/tests/baselines/reference/awaitBinaryExpression1_es6.js b/tests/baselines/reference/awaitBinaryExpression1_es6.js index 8deb771f5abf2..a19e94353d595 100644 --- a/tests/baselines/reference/awaitBinaryExpression1_es6.js +++ b/tests/baselines/reference/awaitBinaryExpression1_es6.js @@ -9,7 +9,7 @@ async function func(): Promise { //// [awaitBinaryExpression1_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = (yield p) || a; "after"; diff --git a/tests/baselines/reference/awaitBinaryExpression2_es6.js b/tests/baselines/reference/awaitBinaryExpression2_es6.js index 506af50a0efba..7fb1a70446b26 100644 --- a/tests/baselines/reference/awaitBinaryExpression2_es6.js +++ b/tests/baselines/reference/awaitBinaryExpression2_es6.js @@ -9,7 +9,7 @@ async function func(): Promise { //// [awaitBinaryExpression2_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = (yield p) && a; "after"; diff --git a/tests/baselines/reference/awaitBinaryExpression3_es6.js b/tests/baselines/reference/awaitBinaryExpression3_es6.js index 4b298d7b94751..f845ce1242148 100644 --- a/tests/baselines/reference/awaitBinaryExpression3_es6.js +++ b/tests/baselines/reference/awaitBinaryExpression3_es6.js @@ -9,7 +9,7 @@ async function func(): Promise { //// [awaitBinaryExpression3_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = (yield p) + a; "after"; diff --git a/tests/baselines/reference/awaitBinaryExpression4_es6.js b/tests/baselines/reference/awaitBinaryExpression4_es6.js index 4d31358898442..b6e14c8248761 100644 --- a/tests/baselines/reference/awaitBinaryExpression4_es6.js +++ b/tests/baselines/reference/awaitBinaryExpression4_es6.js @@ -9,7 +9,7 @@ async function func(): Promise { //// [awaitBinaryExpression4_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = yield p, a; "after"; diff --git a/tests/baselines/reference/awaitBinaryExpression5_es6.js b/tests/baselines/reference/awaitBinaryExpression5_es6.js index 01d6c50f6f03e..65a5bbfee777f 100644 --- a/tests/baselines/reference/awaitBinaryExpression5_es6.js +++ b/tests/baselines/reference/awaitBinaryExpression5_es6.js @@ -10,7 +10,7 @@ async function func(): Promise { //// [awaitBinaryExpression5_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var o; o.a = yield p; diff --git a/tests/baselines/reference/awaitCallExpression1_es6.js b/tests/baselines/reference/awaitCallExpression1_es6.js index f9dad87a8b6b3..aeeb598e3bf18 100644 --- a/tests/baselines/reference/awaitCallExpression1_es6.js +++ b/tests/baselines/reference/awaitCallExpression1_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression1_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = fn(a, a, a); "after"; diff --git a/tests/baselines/reference/awaitCallExpression2_es6.js b/tests/baselines/reference/awaitCallExpression2_es6.js index 87d99cd079399..b41735275a842 100644 --- a/tests/baselines/reference/awaitCallExpression2_es6.js +++ b/tests/baselines/reference/awaitCallExpression2_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression2_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = fn(yield p, a, a); "after"; diff --git a/tests/baselines/reference/awaitCallExpression3_es6.js b/tests/baselines/reference/awaitCallExpression3_es6.js index f397d83c3a14e..74dee3e7e427c 100644 --- a/tests/baselines/reference/awaitCallExpression3_es6.js +++ b/tests/baselines/reference/awaitCallExpression3_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression3_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = fn(a, yield p, a); "after"; diff --git a/tests/baselines/reference/awaitCallExpression4_es6.js b/tests/baselines/reference/awaitCallExpression4_es6.js index d8824d7e7a007..682a1776ac53c 100644 --- a/tests/baselines/reference/awaitCallExpression4_es6.js +++ b/tests/baselines/reference/awaitCallExpression4_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression4_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = (yield pfn)(a, a, a); "after"; diff --git a/tests/baselines/reference/awaitCallExpression5_es6.js b/tests/baselines/reference/awaitCallExpression5_es6.js index f39a633765d88..30889b350115f 100644 --- a/tests/baselines/reference/awaitCallExpression5_es6.js +++ b/tests/baselines/reference/awaitCallExpression5_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression5_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = o.fn(a, a, a); "after"; diff --git a/tests/baselines/reference/awaitCallExpression6_es6.js b/tests/baselines/reference/awaitCallExpression6_es6.js index de8477fa9388a..55d86119d6495 100644 --- a/tests/baselines/reference/awaitCallExpression6_es6.js +++ b/tests/baselines/reference/awaitCallExpression6_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression6_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = o.fn(yield p, a, a); "after"; diff --git a/tests/baselines/reference/awaitCallExpression7_es6.js b/tests/baselines/reference/awaitCallExpression7_es6.js index 24edc3b9393e6..df805266ff3a2 100644 --- a/tests/baselines/reference/awaitCallExpression7_es6.js +++ b/tests/baselines/reference/awaitCallExpression7_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression7_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = o.fn(a, yield p, a); "after"; diff --git a/tests/baselines/reference/awaitCallExpression8_es6.js b/tests/baselines/reference/awaitCallExpression8_es6.js index 8bee6112a7a39..8d7bb4b83ce96 100644 --- a/tests/baselines/reference/awaitCallExpression8_es6.js +++ b/tests/baselines/reference/awaitCallExpression8_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression8_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = (yield po).fn(a, a, a); "after"; diff --git a/tests/baselines/reference/awaitUnion_es6.js b/tests/baselines/reference/awaitUnion_es6.js index 80c68f811ef95..9603454b969aa 100644 --- a/tests/baselines/reference/awaitUnion_es6.js +++ b/tests/baselines/reference/awaitUnion_es6.js @@ -14,7 +14,7 @@ async function f() { //// [awaitUnion_es6.js] function f() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { let await_a = yield a; let await_b = yield b; let await_c = yield c; diff --git a/tests/baselines/reference/baseCheck.errors.txt b/tests/baselines/reference/baseCheck.errors.txt index f52ba4b3dbd76..c31ba95476aee 100644 --- a/tests/baselines/reference/baseCheck.errors.txt +++ b/tests/baselines/reference/baseCheck.errors.txt @@ -1,9 +1,9 @@ tests/cases/compiler/baseCheck.ts(9,18): error TS2304: Cannot find name 'loc'. tests/cases/compiler/baseCheck.ts(17,53): error TS2346: Supplied parameters do not match any signature of call target. -tests/cases/compiler/baseCheck.ts(17,59): error TS2332: 'this' cannot be referenced in current location. -tests/cases/compiler/baseCheck.ts(18,62): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/baseCheck.ts(17,59): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/baseCheck.ts(18,62): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/baseCheck.ts(19,59): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. -tests/cases/compiler/baseCheck.ts(19,68): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/baseCheck.ts(19,68): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/baseCheck.ts(22,9): error TS2304: Cannot find name 'x'. tests/cases/compiler/baseCheck.ts(23,7): error TS2304: Cannot find name 'x'. tests/cases/compiler/baseCheck.ts(26,9): error TS2304: Cannot find name 'x'. @@ -32,15 +32,15 @@ tests/cases/compiler/baseCheck.ts(26,9): error TS2304: Cannot find name 'x'. ~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. class E extends C { constructor(public z: number) { super(0, this.z) } } ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. class F extends C { constructor(public z: number) { super("hello", this.z) } } // first param type ~~~~~~~ !!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. function f() { if (x<10) { diff --git a/tests/baselines/reference/bases.errors.txt b/tests/baselines/reference/bases.errors.txt index c03a47d753241..a61d35f664e52 100644 --- a/tests/baselines/reference/bases.errors.txt +++ b/tests/baselines/reference/bases.errors.txt @@ -4,6 +4,7 @@ tests/cases/compiler/bases.ts(7,17): error TS2304: Cannot find name 'any'. tests/cases/compiler/bases.ts(11,7): error TS2420: Class 'C' incorrectly implements interface 'I'. Property 'x' is missing in type 'C'. tests/cases/compiler/bases.ts(12,5): error TS2377: Constructors for derived classes must contain a 'super' call. +tests/cases/compiler/bases.ts(13,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/bases.ts(13,14): error TS2339: Property 'x' does not exist on type 'C'. tests/cases/compiler/bases.ts(13,15): error TS1005: ';' expected. tests/cases/compiler/bases.ts(13,17): error TS2304: Cannot find name 'any'. @@ -11,7 +12,7 @@ tests/cases/compiler/bases.ts(17,9): error TS2339: Property 'x' does not exist o tests/cases/compiler/bases.ts(18,9): error TS2339: Property 'y' does not exist on type 'C'. -==== tests/cases/compiler/bases.ts (10 errors) ==== +==== tests/cases/compiler/bases.ts (11 errors) ==== interface I { x; } @@ -36,6 +37,8 @@ tests/cases/compiler/bases.ts(18,9): error TS2339: Property 'y' does not exist o ~~~~~~~~~~~~~~~ this.x: any; ~~~~~~~~~~~~~~~~~~~~ + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. ~ !!! error TS2339: Property 'x' does not exist on type 'C'. ~ diff --git a/tests/baselines/reference/callbackArgsDifferByOptionality.errors.txt b/tests/baselines/reference/callbackArgsDifferByOptionality.errors.txt index 2df02c3018503..5ec083a685a0d 100644 --- a/tests/baselines/reference/callbackArgsDifferByOptionality.errors.txt +++ b/tests/baselines/reference/callbackArgsDifferByOptionality.errors.txt @@ -1,11 +1,8 @@ -tests/cases/compiler/callbackArgsDifferByOptionality.ts(1,23): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. tests/cases/compiler/callbackArgsDifferByOptionality.ts(4,5): error TS2304: Cannot find name 'cb'. -==== tests/cases/compiler/callbackArgsDifferByOptionality.ts (2 errors) ==== +==== tests/cases/compiler/callbackArgsDifferByOptionality.ts (1 errors) ==== function x3(callback: (x?: 'hi') => number); - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. function x3(callback: (x: string) => number); function x3(callback: (x: any) => number) { cb(); diff --git a/tests/baselines/reference/capturedLetConstInLoop1.js b/tests/baselines/reference/capturedLetConstInLoop1.js index 633b78af510f3..fe76bdd5c91a1 100644 --- a/tests/baselines/reference/capturedLetConstInLoop1.js +++ b/tests/baselines/reference/capturedLetConstInLoop1.js @@ -138,7 +138,7 @@ for (var x = 0; x < 1; ++x) { _loop_3(x); } var _loop_4 = function() { - var x = void 0; + var x; (function () { return x; }); (function () { return x; }); }; @@ -146,7 +146,7 @@ while (1 === 1) { _loop_4(); } var _loop_5 = function() { - var x = void 0; + var x; (function () { return x; }); (function () { return x; }); }; @@ -169,7 +169,7 @@ for (var x = 0, y = 1; x < 1; ++x) { _loop_7(x, y); } var _loop_8 = function() { - var x = void 0, y = void 0; + var x, y; (function () { return x + y; }); (function () { return x + y; }); }; @@ -177,7 +177,7 @@ while (1 === 1) { _loop_8(); } var _loop_9 = function() { - var x = void 0, y = void 0; + var x, y; (function () { return x + y; }); (function () { return x + y; }); }; diff --git a/tests/baselines/reference/capturedLetConstInLoop11.js b/tests/baselines/reference/capturedLetConstInLoop11.js index fa295739d020e..9190dd3ec02ef 100644 --- a/tests/baselines/reference/capturedLetConstInLoop11.js +++ b/tests/baselines/reference/capturedLetConstInLoop11.js @@ -30,6 +30,6 @@ function foo() { }; for (;;) { var state_2 = _loop_2(); - if (typeof state_2 === "object") return state_2.value + if (typeof state_2 === "object") return state_2.value; } } diff --git a/tests/baselines/reference/capturedLetConstInLoop2.js b/tests/baselines/reference/capturedLetConstInLoop2.js index b9fbcf46f57a4..b41dd380a2435 100644 --- a/tests/baselines/reference/capturedLetConstInLoop2.js +++ b/tests/baselines/reference/capturedLetConstInLoop2.js @@ -225,7 +225,7 @@ function foo2(x) { } function foo3(x) { var _loop_5 = function() { - var x_4 = void 0; + var x_4; var a = arguments_5.length; (function () { return x_4 + a; }); (function () { return x_4 + a; }); @@ -260,7 +260,7 @@ function foo5(x) { } function foo6(x) { var _loop_8 = function() { - var x_7 = void 0, y = void 0; + var x_7, y; var a = arguments_8.length; (function () { return x_7 + y + a; }); (function () { return x_7 + y + a; }); @@ -272,7 +272,7 @@ function foo6(x) { } function foo7(x) { var _loop_9 = function() { - var x_8 = void 0, y = void 0; + var x_8, y; var a = arguments_9.length; (function () { return x_8 + y + a; }); (function () { return x_8 + y + a; }); diff --git a/tests/baselines/reference/capturedLetConstInLoop3.js b/tests/baselines/reference/capturedLetConstInLoop3.js index b38c12967dd2b..233dfe9206c18 100644 --- a/tests/baselines/reference/capturedLetConstInLoop3.js +++ b/tests/baselines/reference/capturedLetConstInLoop3.js @@ -270,7 +270,7 @@ function foo2(x) { } function foo3(x) { var _loop_5 = function() { - var x_5 = void 0; + var x_5; (function () { return x_5 + v; }); (function () { return x_5 + v; }); }; @@ -307,7 +307,7 @@ function foo5(x) { } function foo6(x) { var _loop_8 = function() { - var x_8 = void 0, y = void 0; + var x_8, y; v = x_8; (function () { return x_8 + y + v; }); (function () { return x_8 + y + v; }); @@ -320,7 +320,7 @@ function foo6(x) { } function foo7(x) { var _loop_9 = function() { - var x_9 = void 0, y = void 0; + var x_9, y; v = x_9; (function () { return x_9 + y + v; }); (function () { return x_9 + y + v; }); diff --git a/tests/baselines/reference/capturedLetConstInLoop4.js b/tests/baselines/reference/capturedLetConstInLoop4.js index 724c84fe04f04..04f514b01e813 100644 --- a/tests/baselines/reference/capturedLetConstInLoop4.js +++ b/tests/baselines/reference/capturedLetConstInLoop4.js @@ -144,8 +144,9 @@ for (const y = 0; y < 1;) { //// [capturedLetConstInLoop4.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var v0, v00, v1, v2, v3, v4, v5, v6, v7, v8, v0_c, v00_c, v1_c, v2_c, v3_c, v4_c, v5_c, v6_c, v7_c, v8_c; //======let function exportedFoo() { @@ -186,7 +187,7 @@ System.register([], function(exports_1) { _loop_3(x); } var _loop_4 = function() { - var x = void 0; + var x; v2 = x; (function () { return x + v2; }); (function () { return x; }); @@ -195,7 +196,7 @@ System.register([], function(exports_1) { _loop_4(); } var _loop_5 = function() { - var x = void 0; + var x; v3 = x; (function () { return x + v3; }); (function () { return x; }); @@ -221,7 +222,7 @@ System.register([], function(exports_1) { _loop_7(x, y); } var _loop_8 = function() { - var x = void 0, y = void 0; + var x, y; v6 = x; (function () { return x + y + v6; }); (function () { return x + y; }); @@ -230,7 +231,7 @@ System.register([], function(exports_1) { _loop_8(); } var _loop_9 = function() { - var x = void 0, y = void 0; + var x, y; v7 = x; (function () { return x + y + v7; }); (function () { return x + y; }); diff --git a/tests/baselines/reference/capturedLetConstInLoop5.js b/tests/baselines/reference/capturedLetConstInLoop5.js index b73484cb430b0..a1a4d4b0a8f96 100644 --- a/tests/baselines/reference/capturedLetConstInLoop5.js +++ b/tests/baselines/reference/capturedLetConstInLoop5.js @@ -294,7 +294,7 @@ function foo0(x) { for (var _i = 0, _a = []; _i < _a.length; _i++) { var x_1 = _a[_i]; var state_1 = _loop_1(x_1); - if (typeof state_1 === "object") return state_1.value + if (typeof state_1 === "object") return state_1.value; } use(v); } @@ -310,7 +310,7 @@ function foo00(x) { var v; for (var x_2 in []) { var state_2 = _loop_2(x_2); - if (typeof state_2 === "object") return state_2.value + if (typeof state_2 === "object") return state_2.value; } use(v); } @@ -326,7 +326,7 @@ function foo1(x) { var v; for (var x_3 = 0; x_3 < 1; ++x_3) { var state_3 = _loop_3(x_3); - if (typeof state_3 === "object") return state_3.value + if (typeof state_3 === "object") return state_3.value; } use(v); } @@ -343,13 +343,13 @@ function foo2(x) { var v; while (1 === 1) { var state_4 = _loop_4(); - if (typeof state_4 === "object") return state_4.value + if (typeof state_4 === "object") return state_4.value; } use(v); } function foo3(x) { var _loop_5 = function() { - var x_5 = void 0; + var x_5; (function () { return x_5 + v; }); (function () { return x_5 + v; }); if (x_5 == 1) { @@ -359,7 +359,7 @@ function foo3(x) { var v; do { var state_5 = _loop_5(); - if (typeof state_5 === "object") return state_5.value + if (typeof state_5 === "object") return state_5.value; } while (1 === 1); use(v); } @@ -376,7 +376,7 @@ function foo4(x) { var v; for (var y = 0; y < 1; ++y) { var state_6 = _loop_6(y); - if (typeof state_6 === "object") return state_6.value + if (typeof state_6 === "object") return state_6.value; } use(v); } @@ -392,13 +392,13 @@ function foo5(x) { var v; for (var x_7 = 0, y = 1; x_7 < 1; ++x_7) { var state_7 = _loop_7(x_7, y); - if (typeof state_7 === "object") return state_7.value + if (typeof state_7 === "object") return state_7.value; } use(v); } function foo6(x) { var _loop_8 = function() { - var x_8 = void 0, y = void 0; + var x_8, y; v = x_8; (function () { return x_8 + y + v; }); (function () { return x_8 + y + v; }); @@ -409,14 +409,14 @@ function foo6(x) { var v; while (1 === 1) { var state_8 = _loop_8(); - if (typeof state_8 === "object") return state_8.value + if (typeof state_8 === "object") return state_8.value; } ; use(v); } function foo7(x) { var _loop_9 = function() { - var x_9 = void 0, y = void 0; + var x_9, y; v = x_9; (function () { return x_9 + y + v; }); (function () { return x_9 + y + v; }); @@ -427,7 +427,7 @@ function foo7(x) { var v; do { var state_9 = _loop_9(); - if (typeof state_9 === "object") return state_9.value + if (typeof state_9 === "object") return state_9.value; } while (1 === 1); use(v); } @@ -444,7 +444,7 @@ function foo8(x) { var v; for (var y = 0; y < 1; ++y) { var state_10 = _loop_10(y); - if (typeof state_10 === "object") return state_10.value + if (typeof state_10 === "object") return state_10.value; } use(v); } @@ -462,7 +462,7 @@ function foo0_c(x) { for (var _i = 0, _a = []; _i < _a.length; _i++) { var x_11 = _a[_i]; var state_11 = _loop_11(x_11); - if (typeof state_11 === "object") return state_11.value + if (typeof state_11 === "object") return state_11.value; } use(v); } @@ -478,7 +478,7 @@ function foo00_c(x) { var v; for (var x_12 in []) { var state_12 = _loop_12(x_12); - if (typeof state_12 === "object") return state_12.value + if (typeof state_12 === "object") return state_12.value; } use(v); } @@ -494,7 +494,7 @@ function foo1_c(x) { var v; for (var x_13 = 0; x_13 < 1;) { var state_13 = _loop_13(x_13); - if (typeof state_13 === "object") return state_13.value + if (typeof state_13 === "object") return state_13.value; } use(v); } @@ -511,7 +511,7 @@ function foo2_c(x) { var v; while (1 === 1) { var state_14 = _loop_14(); - if (typeof state_14 === "object") return state_14.value + if (typeof state_14 === "object") return state_14.value; } use(v); } @@ -527,7 +527,7 @@ function foo3_c(x) { var v; do { var state_15 = _loop_15(); - if (typeof state_15 === "object") return state_15.value + if (typeof state_15 === "object") return state_15.value; } while (1 === 1); use(v); } @@ -544,7 +544,7 @@ function foo4_c(x) { var v; for (var y = 0; y < 1;) { var state_16 = _loop_16(y); - if (typeof state_16 === "object") return state_16.value + if (typeof state_16 === "object") return state_16.value; } use(v); } @@ -560,7 +560,7 @@ function foo5_c(x) { var v; for (var x_17 = 0, y = 1; x_17 < 1;) { var state_17 = _loop_17(x_17, y); - if (typeof state_17 === "object") return state_17.value + if (typeof state_17 === "object") return state_17.value; } use(v); } @@ -577,7 +577,7 @@ function foo6_c(x) { var v; while (1 === 1) { var state_18 = _loop_18(); - if (typeof state_18 === "object") return state_18.value + if (typeof state_18 === "object") return state_18.value; } use(v); } @@ -594,7 +594,7 @@ function foo7_c(x) { var v; do { var state_19 = _loop_19(); - if (typeof state_19 === "object") return state_19.value + if (typeof state_19 === "object") return state_19.value; } while (1 === 1); use(v); } @@ -611,7 +611,7 @@ function foo8_c(x) { var v; for (var y = 0; y < 1;) { var state_20 = _loop_20(y); - if (typeof state_20 === "object") return state_20.value + if (typeof state_20 === "object") return state_20.value; } use(v); } diff --git a/tests/baselines/reference/capturedLetConstInLoop6.js b/tests/baselines/reference/capturedLetConstInLoop6.js index ca3b634ef18de..e196950e696ab 100644 --- a/tests/baselines/reference/capturedLetConstInLoop6.js +++ b/tests/baselines/reference/capturedLetConstInLoop6.js @@ -287,7 +287,7 @@ for (var x = 0; x < 1; ++x) { if (state_3 === "continue") continue; } var _loop_4 = function() { - var x = void 0; + var x; (function () { return x; }); (function () { return x; }); if (x == 1) { @@ -303,7 +303,7 @@ while (1 === 1) { if (state_4 === "continue") continue; } var _loop_5 = function() { - var x = void 0; + var x; (function () { return x; }); (function () { return x; }); if (x == 1) { @@ -350,7 +350,7 @@ for (var x = 0, y = 1; x < 1; ++x) { if (state_7 === "continue") continue; } var _loop_8 = function() { - var x = void 0, y = void 0; + var x, y; (function () { return x + y; }); (function () { return x + y; }); if (x == 1) { @@ -366,7 +366,7 @@ while (1 === 1) { if (state_8 === "continue") continue; } var _loop_9 = function() { - var x = void 0, y = void 0; + var x, y; (function () { return x + y; }); (function () { return x + y; }); if (x == 1) { diff --git a/tests/baselines/reference/capturedLetConstInLoop7.js b/tests/baselines/reference/capturedLetConstInLoop7.js index 6ec4ec1df447d..8df93bca60ff2 100644 --- a/tests/baselines/reference/capturedLetConstInLoop7.js +++ b/tests/baselines/reference/capturedLetConstInLoop7.js @@ -454,7 +454,7 @@ l1: for (var x = 0; x < 1; ++x) { } } var _loop_4 = function() { - var x = void 0; + var x; (function () { return x; }); (function () { return x; }); if (x == 1) { @@ -480,7 +480,7 @@ l2: while (1 === 1) { } } var _loop_5 = function() { - var x = void 0; + var x; (function () { return x; }); (function () { return x; }); if (x == 1) { @@ -557,7 +557,7 @@ l5: for (var x = 0, y = 1; x < 1; ++x) { } } var _loop_8 = function() { - var x = void 0, y = void 0; + var x, y; (function () { return x + y; }); (function () { return x + y; }); if (x == 1) { @@ -583,7 +583,7 @@ l6: while (1 === 1) { } } var _loop_9 = function() { - var x = void 0, y = void 0; + var x, y; (function () { return x + y; }); (function () { return x + y; }); if (x == 1) { diff --git a/tests/baselines/reference/capturedLetConstInLoop8.js b/tests/baselines/reference/capturedLetConstInLoop8.js index b10beb7b44e0d..560b99bb5667e 100644 --- a/tests/baselines/reference/capturedLetConstInLoop8.js +++ b/tests/baselines/reference/capturedLetConstInLoop8.js @@ -198,7 +198,7 @@ function foo() { }; l1: for (var x = 0; x < 1; ++x) { var state_2 = _loop_1(x); - if (typeof state_2 === "object") return state_2.value + if (typeof state_2 === "object") return state_2.value; if (state_2 === "break") break; if (state_2 === "continue") continue; switch(state_2) { @@ -280,7 +280,7 @@ function foo_c() { }; l1: for (var x = 0; x < 1;) { var state_4 = _loop_3(x); - if (typeof state_4 === "object") return state_4.value + if (typeof state_4 === "object") return state_4.value; if (state_4 === "break") break; if (state_4 === "continue") continue; switch(state_4) { diff --git a/tests/baselines/reference/capturedLetConstInLoop9.js b/tests/baselines/reference/capturedLetConstInLoop9.js index 9b31218a1e3d3..1f79b1694cb76 100644 --- a/tests/baselines/reference/capturedLetConstInLoop9.js +++ b/tests/baselines/reference/capturedLetConstInLoop9.js @@ -140,25 +140,25 @@ function foo3 () { //// [capturedLetConstInLoop9.js] var _loop_1 = function(x) { - var x_1 = void 0; + var x_1; (function () { return x_1; }); { - var x_2 = void 0; + var x_2; (function () { return x_2; }); } try { } catch (e) { - var x_3 = void 0; + var x_3; (function () { return x_3; }); } switch (x_1) { case 1: - var x_4 = void 0; + var x_4; (function () { return x_4; }); break; } var _loop_2 = function() { - var x_5 = void 0; + var x_5; (function () { return x_5; }); }; while (1 == 1) { @@ -225,7 +225,7 @@ function foo() { l0: for (var _f = 0, _g = []; _f < _g.length; _f++) { var a = _g[_f]; var state_4 = _loop_3(a); - if (typeof state_4 === "object") return state_4.value + if (typeof state_4 === "object") return state_4.value; if (state_4 === "break") break; switch(state_4) { case "break-l0": break l0; diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js new file mode 100644 index 0000000000000..cfb5726dac1f1 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js @@ -0,0 +1,33 @@ +//// [checkSuperCallBeforeThisAccessing1.ts] +class Based { } +class Derived extends Based { + public x: number; + constructor() { + super(); + this; + this.x = 10; + var that = this; + } +} + +//// [checkSuperCallBeforeThisAccessing1.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 Based = (function () { + function Based() { + } + return Based; +}()); +var Derived = (function (_super) { + __extends(Derived, _super); + function Derived() { + _super.call(this); + this; + this.x = 10; + var that = this; + } + return Derived; +}(Based)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.symbols b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.symbols new file mode 100644 index 0000000000000..008d1156b564d --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.symbols @@ -0,0 +1,28 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing1.ts === +class Based { } +>Based : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing1.ts, 0, 0)) + +class Derived extends Based { +>Derived : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing1.ts, 0, 15)) +>Based : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing1.ts, 0, 0)) + + public x: number; +>x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing1.ts, 1, 29)) + + constructor() { + super(); +>super : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing1.ts, 0, 0)) + + this; +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing1.ts, 0, 15)) + + this.x = 10; +>this.x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing1.ts, 1, 29)) +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing1.ts, 0, 15)) +>x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing1.ts, 1, 29)) + + var that = this; +>that : Symbol(that, Decl(checkSuperCallBeforeThisAccessing1.ts, 7, 11)) +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing1.ts, 0, 15)) + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.types new file mode 100644 index 0000000000000..d734b0c6ad091 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.types @@ -0,0 +1,31 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing1.ts === +class Based { } +>Based : Based + +class Derived extends Based { +>Derived : Derived +>Based : Based + + public x: number; +>x : number + + constructor() { + super(); +>super() : void +>super : typeof Based + + this; +>this : this + + this.x = 10; +>this.x = 10 : number +>this.x : number +>this : this +>x : number +>10 : number + + var that = this; +>that : this +>this : this + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt new file mode 100644 index 0000000000000..4e947e8630f58 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(5,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + + +==== tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts (1 errors) ==== + class Based { } + class Derived extends Based { + public x: number; + constructor() { + this.x = 100; + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + super(); + this.x = 10; + var that = this; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js new file mode 100644 index 0000000000000..afbc15cf912a9 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js @@ -0,0 +1,33 @@ +//// [checkSuperCallBeforeThisAccessing2.ts] +class Based { } +class Derived extends Based { + public x: number; + constructor() { + this.x = 100; + super(); + this.x = 10; + var that = this; + } +} + +//// [checkSuperCallBeforeThisAccessing2.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 Based = (function () { + function Based() { + } + return Based; +}()); +var Derived = (function (_super) { + __extends(Derived, _super); + function Derived() { + this.x = 100; + _super.call(this); + this.x = 10; + var that = this; + } + return Derived; +}(Based)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js new file mode 100644 index 0000000000000..7e9c23c1f8337 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js @@ -0,0 +1,43 @@ +//// [checkSuperCallBeforeThisAccessing3.ts] +class Based { } +class Derived extends Based { + public x: number; + constructor() { + class innver { + public y: boolean; + constructor() { + this.y = true; + } + } + super(); + this.x = 10; + var that = this; + } +} + +//// [checkSuperCallBeforeThisAccessing3.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 Based = (function () { + function Based() { + } + return Based; +}()); +var Derived = (function (_super) { + __extends(Derived, _super); + function Derived() { + var innver = (function () { + function innver() { + this.y = true; + } + return innver; + }()); + _super.call(this); + this.x = 10; + var that = this; + } + return Derived; +}(Based)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.symbols b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.symbols new file mode 100644 index 0000000000000..8dd68fc3b7494 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.symbols @@ -0,0 +1,38 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing3.ts === +class Based { } +>Based : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing3.ts, 0, 0)) + +class Derived extends Based { +>Derived : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing3.ts, 0, 15)) +>Based : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing3.ts, 0, 0)) + + public x: number; +>x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing3.ts, 1, 29)) + + constructor() { + class innver { +>innver : Symbol(innver, Decl(checkSuperCallBeforeThisAccessing3.ts, 3, 19)) + + public y: boolean; +>y : Symbol(y, Decl(checkSuperCallBeforeThisAccessing3.ts, 4, 22)) + + constructor() { + this.y = true; +>this.y : Symbol(y, Decl(checkSuperCallBeforeThisAccessing3.ts, 4, 22)) +>this : Symbol(innver, Decl(checkSuperCallBeforeThisAccessing3.ts, 3, 19)) +>y : Symbol(y, Decl(checkSuperCallBeforeThisAccessing3.ts, 4, 22)) + } + } + super(); +>super : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing3.ts, 0, 0)) + + this.x = 10; +>this.x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing3.ts, 1, 29)) +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing3.ts, 0, 15)) +>x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing3.ts, 1, 29)) + + var that = this; +>that : Symbol(that, Decl(checkSuperCallBeforeThisAccessing3.ts, 12, 11)) +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing3.ts, 0, 15)) + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.types new file mode 100644 index 0000000000000..c4e9e15ed8ef2 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.types @@ -0,0 +1,43 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing3.ts === +class Based { } +>Based : Based + +class Derived extends Based { +>Derived : Derived +>Based : Based + + public x: number; +>x : number + + constructor() { + class innver { +>innver : innver + + public y: boolean; +>y : boolean + + constructor() { + this.y = true; +>this.y = true : boolean +>this.y : boolean +>this : this +>y : boolean +>true : boolean + } + } + super(); +>super() : void +>super : typeof Based + + this.x = 10; +>this.x = 10 : number +>this.x : number +>this : this +>x : number +>10 : number + + var that = this; +>that : this +>this : this + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js new file mode 100644 index 0000000000000..1257b446ccbaa --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js @@ -0,0 +1,52 @@ +//// [checkSuperCallBeforeThisAccessing4.ts] +class Based { } +class Derived extends Based { + public x: number; + constructor() { + (() => { + this; // No error + }); + () => { + this; // No error + }; + (() => { + this; // No error + })(); + super(); + super(); + this.x = 10; + var that = this; + } +} + +//// [checkSuperCallBeforeThisAccessing4.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 Based = (function () { + function Based() { + } + return Based; +}()); +var Derived = (function (_super) { + __extends(Derived, _super); + function Derived() { + var _this = this; + (function () { + _this; // No error + }); + (function () { + _this; // No error + }); + (function () { + _this; // No error + })(); + _super.call(this); + _super.call(this); + this.x = 10; + var that = this; + } + return Derived; +}(Based)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.symbols b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.symbols new file mode 100644 index 0000000000000..7101280358dbe --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.symbols @@ -0,0 +1,43 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing4.ts === +class Based { } +>Based : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 0)) + +class Derived extends Based { +>Derived : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 15)) +>Based : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 0)) + + public x: number; +>x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing4.ts, 1, 29)) + + constructor() { + (() => { + this; // No error +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 15)) + + }); + () => { + this; // No error +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 15)) + + }; + (() => { + this; // No error +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 15)) + + })(); + super(); +>super : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 0)) + + super(); +>super : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 0)) + + this.x = 10; +>this.x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing4.ts, 1, 29)) +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 15)) +>x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing4.ts, 1, 29)) + + var that = this; +>that : Symbol(that, Decl(checkSuperCallBeforeThisAccessing4.ts, 16, 11)) +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 15)) + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.types new file mode 100644 index 0000000000000..f42a0ac8563ba --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.types @@ -0,0 +1,56 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing4.ts === +class Based { } +>Based : Based + +class Derived extends Based { +>Derived : Derived +>Based : Based + + public x: number; +>x : number + + constructor() { + (() => { +>(() => { this; // No error }) : () => void +>() => { this; // No error } : () => void + + this; // No error +>this : this + + }); + () => { +>() => { this; // No error } : () => void + + this; // No error +>this : this + + }; + (() => { +>(() => { this; // No error })() : void +>(() => { this; // No error }) : () => void +>() => { this; // No error } : () => void + + this; // No error +>this : this + + })(); + super(); +>super() : void +>super : typeof Based + + super(); +>super() : void +>super : typeof Based + + this.x = 10; +>this.x = 10 : number +>this.x : number +>this : this +>x : number +>10 : number + + var that = this; +>that : this +>this : this + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt new file mode 100644 index 0000000000000..a0b86e28cf002 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + + +==== tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts (1 errors) ==== + class Based { constructor(...arg) { } } + class Derived extends Based { + public x: number; + constructor() { + super(this.x); + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js new file mode 100644 index 0000000000000..1889ee998ca91 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js @@ -0,0 +1,31 @@ +//// [checkSuperCallBeforeThisAccessing5.ts] +class Based { constructor(...arg) { } } +class Derived extends Based { + public x: number; + constructor() { + super(this.x); + } +} + +//// [checkSuperCallBeforeThisAccessing5.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 Based = (function () { + function Based() { + var arg = []; + for (var _i = 0; _i < arguments.length; _i++) { + arg[_i - 0] = arguments[_i]; + } + } + return Based; +}()); +var Derived = (function (_super) { + __extends(Derived, _super); + function Derived() { + _super.call(this, this.x); + } + return Derived; +}(Based)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js new file mode 100644 index 0000000000000..39db4dec17467 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js @@ -0,0 +1,36 @@ +//// [checkSuperCallBeforeThisAccessing6.ts] +class Base { + constructor(...arg) { + } +} +class Super extends Base { + constructor() { + (() => this); // No Error + super(); + } +} + +//// [checkSuperCallBeforeThisAccessing6.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 Base = (function () { + function Base() { + var arg = []; + for (var _i = 0; _i < arguments.length; _i++) { + arg[_i - 0] = arguments[_i]; + } + } + return Base; +}()); +var Super = (function (_super) { + __extends(Super, _super); + function Super() { + var _this = this; + (function () { return _this; }); // No Error + _super.call(this); + } + return Super; +}(Base)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.symbols b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.symbols new file mode 100644 index 0000000000000..84bac5775ec25 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.symbols @@ -0,0 +1,20 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing6.ts === +class Base { +>Base : Symbol(Base, Decl(checkSuperCallBeforeThisAccessing6.ts, 0, 0)) + + constructor(...arg) { +>arg : Symbol(arg, Decl(checkSuperCallBeforeThisAccessing6.ts, 1, 16)) + } +} +class Super extends Base { +>Super : Symbol(Super, Decl(checkSuperCallBeforeThisAccessing6.ts, 3, 1)) +>Base : Symbol(Base, Decl(checkSuperCallBeforeThisAccessing6.ts, 0, 0)) + + constructor() { + (() => this); // No Error +>this : Symbol(Super, Decl(checkSuperCallBeforeThisAccessing6.ts, 3, 1)) + + super(); +>super : Symbol(Base, Decl(checkSuperCallBeforeThisAccessing6.ts, 0, 0)) + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.types new file mode 100644 index 0000000000000..826dab0c40055 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing6.ts === +class Base { +>Base : Base + + constructor(...arg) { +>arg : any[] + } +} +class Super extends Base { +>Super : Super +>Base : Base + + constructor() { + (() => this); // No Error +>(() => this) : () => this +>() => this : () => this +>this : this + + super(); +>super() : void +>super : typeof Base + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js new file mode 100644 index 0000000000000..d071c05db5d4e --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js @@ -0,0 +1,30 @@ +//// [checkSuperCallBeforeThisAccessing7.ts] +class Base { + constructor(func: ()=>Base) { + } +} +class Super extends Base { + constructor() { + super((() => this)); // No error + } +} + +//// [checkSuperCallBeforeThisAccessing7.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 Base = (function () { + function Base(func) { + } + return Base; +}()); +var Super = (function (_super) { + __extends(Super, _super); + function Super() { + var _this = this; + _super.call(this, (function () { return _this; })); // No error + } + return Super; +}(Base)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.symbols b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.symbols new file mode 100644 index 0000000000000..3611429d2b272 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing7.ts === +class Base { +>Base : Symbol(Base, Decl(checkSuperCallBeforeThisAccessing7.ts, 0, 0)) + + constructor(func: ()=>Base) { +>func : Symbol(func, Decl(checkSuperCallBeforeThisAccessing7.ts, 1, 16)) +>Base : Symbol(Base, Decl(checkSuperCallBeforeThisAccessing7.ts, 0, 0)) + } +} +class Super extends Base { +>Super : Symbol(Super, Decl(checkSuperCallBeforeThisAccessing7.ts, 3, 1)) +>Base : Symbol(Base, Decl(checkSuperCallBeforeThisAccessing7.ts, 0, 0)) + + constructor() { + super((() => this)); // No error +>super : Symbol(Base, Decl(checkSuperCallBeforeThisAccessing7.ts, 0, 0)) +>this : Symbol(Super, Decl(checkSuperCallBeforeThisAccessing7.ts, 3, 1)) + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.types new file mode 100644 index 0000000000000..11d2ab26d20a6 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing7.ts === +class Base { +>Base : Base + + constructor(func: ()=>Base) { +>func : () => Base +>Base : Base + } +} +class Super extends Base { +>Super : Super +>Base : Base + + constructor() { + super((() => this)); // No error +>super((() => this)) : void +>super : typeof Base +>(() => this) : () => this +>() => this : () => this +>this : this + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt new file mode 100644 index 0000000000000..2c8c8d9fb06db --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(7,20): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + + +==== tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts (1 errors) ==== + class Base { + constructor(...arg) { + } + } + class Super extends Base { + constructor() { + var that = this; + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + super(); + } + } \ No newline at end of file diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js new file mode 100644 index 0000000000000..f334cc7f42b86 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js @@ -0,0 +1,35 @@ +//// [checkSuperCallBeforeThisAccessing8.ts] +class Base { + constructor(...arg) { + } +} +class Super extends Base { + constructor() { + var that = this; + super(); + } +} + +//// [checkSuperCallBeforeThisAccessing8.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 Base = (function () { + function Base() { + var arg = []; + for (var _i = 0; _i < arguments.length; _i++) { + arg[_i - 0] = arguments[_i]; + } + } + return Base; +}()); +var Super = (function (_super) { + __extends(Super, _super); + function Super() { + var that = this; + _super.call(this); + } + return Super; +}(Base)); diff --git a/tests/baselines/reference/classdecl.js b/tests/baselines/reference/classdecl.js index 710c5166d3051..a8a440fa17d2a 100644 --- a/tests/baselines/reference/classdecl.js +++ b/tests/baselines/reference/classdecl.js @@ -211,12 +211,12 @@ declare class a { pgF(): void; pv: any; d: number; - static p2: { + static readonly p2: { x: number; y: number; }; private static d2(); - private static p3; + private static readonly p3; private pv3; private foo(n); private foo(s); diff --git a/tests/baselines/reference/commentsClassMembers.js b/tests/baselines/reference/commentsClassMembers.js index fe2dc0a63d093..dacbde7a27698 100644 --- a/tests/baselines/reference/commentsClassMembers.js +++ b/tests/baselines/reference/commentsClassMembers.js @@ -568,8 +568,8 @@ declare var i1_c: typeof c1; declare class cProperties { private val; /** getter only property*/ - p1: number; - nc_p1: number; + readonly p1: number; + readonly nc_p1: number; /**setter only property*/ p2: number; nc_p2: number; diff --git a/tests/baselines/reference/commentsInheritance.js b/tests/baselines/reference/commentsInheritance.js index b9d84b2475a7e..42df3cca3893b 100644 --- a/tests/baselines/reference/commentsInheritance.js +++ b/tests/baselines/reference/commentsInheritance.js @@ -316,19 +316,19 @@ declare class c2 { /** c2 c2_f1*/ c2_f1(): void; /** c2 c2_prop*/ - c2_prop: number; + readonly c2_prop: number; c2_nc_p1: number; c2_nc_f1(): void; - c2_nc_prop: number; + readonly c2_nc_prop: number; /** c2 p1*/ p1: number; /** c2 f1*/ f1(): void; /** c2 prop*/ - prop: number; + readonly prop: number; nc_p1: number; nc_f1(): void; - nc_prop: number; + readonly nc_prop: number; /** c2 constructor*/ constructor(a: number); } @@ -339,10 +339,10 @@ declare class c3 extends c2 { /** c3 f1*/ f1(): void; /** c3 prop*/ - prop: number; + readonly prop: number; nc_p1: number; nc_f1(): void; - nc_prop: number; + readonly nc_prop: number; } declare var c2_i: c2; declare var c3_i: c3; diff --git a/tests/baselines/reference/commentsOnObjectLiteral4.types b/tests/baselines/reference/commentsOnObjectLiteral4.types index 364df6e5ea1fd..f458d73ae3652 100644 --- a/tests/baselines/reference/commentsOnObjectLiteral4.types +++ b/tests/baselines/reference/commentsOnObjectLiteral4.types @@ -1,8 +1,8 @@ === tests/cases/compiler/commentsOnObjectLiteral4.ts === var v = { ->v : { bar: number; } ->{ /** * @type {number} */ get bar(): number { return this._bar; }} : { bar: number; } +>v : { readonly bar: number; } +>{ /** * @type {number} */ get bar(): number { return this._bar; }} : { readonly bar: number; } /** * @type {number} diff --git a/tests/baselines/reference/computedPropertyNames11_ES5.types b/tests/baselines/reference/computedPropertyNames11_ES5.types index e0787fc3ee712..ae626ec3cba28 100644 --- a/tests/baselines/reference/computedPropertyNames11_ES5.types +++ b/tests/baselines/reference/computedPropertyNames11_ES5.types @@ -9,8 +9,8 @@ var a: any; >a : any var v = { ->v : { [0]: number; [""]: any; } ->{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { [0]: number; [""]: any; } +>v : { readonly [0]: number; [""]: any; } +>{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { readonly [0]: number; [""]: any; } get [s]() { return 0; }, >s : string diff --git a/tests/baselines/reference/computedPropertyNames11_ES6.types b/tests/baselines/reference/computedPropertyNames11_ES6.types index 8ad31a7c2a14e..06dc26e984305 100644 --- a/tests/baselines/reference/computedPropertyNames11_ES6.types +++ b/tests/baselines/reference/computedPropertyNames11_ES6.types @@ -9,8 +9,8 @@ var a: any; >a : any var v = { ->v : { [0]: number; [""]: any; } ->{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { [0]: number; [""]: any; } +>v : { readonly [0]: number; [""]: any; } +>{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { readonly [0]: number; [""]: any; } get [s]() { return 0; }, >s : string diff --git a/tests/baselines/reference/constDeclarations-access.errors.txt b/tests/baselines/reference/constDeclarations-access.errors.txt index 04b942aec09ef..3c748cc4a5ff5 100644 --- a/tests/baselines/reference/constDeclarations-access.errors.txt +++ b/tests/baselines/reference/constDeclarations-access.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/file2.ts(1,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/file2.ts(1,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. ==== tests/cases/compiler/file1.ts (0 errors) ==== @@ -8,4 +8,4 @@ tests/cases/compiler/file2.ts(1,1): error TS2449: The operand of an increment or ==== tests/cases/compiler/file2.ts (1 errors) ==== x++; ~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. \ No newline at end of file +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-access2.errors.txt b/tests/baselines/reference/constDeclarations-access2.errors.txt index 6a360e11014e8..667f490a374a1 100644 --- a/tests/baselines/reference/constDeclarations-access2.errors.txt +++ b/tests/baselines/reference/constDeclarations-access2.errors.txt @@ -1,20 +1,20 @@ -tests/cases/compiler/constDeclarations-access2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(18,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(19,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(20,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(21,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access2.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(18,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(19,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(20,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(21,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access2.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. ==== tests/cases/compiler/constDeclarations-access2.ts (17 errors) ==== @@ -24,57 +24,57 @@ tests/cases/compiler/constDeclarations-access2.ts(23,3): error TS2449: The opera // Errors x = 1; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x += 2; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x -= 3; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x *= 4; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x /= 5; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x %= 6; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x <<= 7; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x >>= 8; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x >>>= 9; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x &= 10; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x |= 11; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x ^= 12; ~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. x++; ~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. x--; ~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. ++x; ~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. --x; ~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. ++((x)); ~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. // OK var a = x + 1; diff --git a/tests/baselines/reference/constDeclarations-access3.errors.txt b/tests/baselines/reference/constDeclarations-access3.errors.txt index 577b087dff09a..a6cb124d28c57 100644 --- a/tests/baselines/reference/constDeclarations-access3.errors.txt +++ b/tests/baselines/reference/constDeclarations-access3.errors.txt @@ -1,21 +1,21 @@ -tests/cases/compiler/constDeclarations-access3.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(21,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(22,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(24,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(26,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access3.ts(28,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(21,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(22,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(24,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(26,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access3.ts(28,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. ==== tests/cases/compiler/constDeclarations-access3.ts (18 errors) ==== @@ -28,61 +28,61 @@ tests/cases/compiler/constDeclarations-access3.ts(28,1): error TS2450: Left-hand // Errors M.x = 1; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x += 2; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x -= 3; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x *= 4; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x /= 5; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x %= 6; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x <<= 7; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x >>= 8; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x >>>= 9; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x &= 10; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x |= 11; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x ^= 12; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x++; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. M.x--; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. ++M.x; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. --M.x; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. ++((M.x)); ~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. M["x"] = 0; ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. // OK var a = M.x + 1; diff --git a/tests/baselines/reference/constDeclarations-access4.errors.txt b/tests/baselines/reference/constDeclarations-access4.errors.txt index 9745c0d262497..3d7d4a704a81e 100644 --- a/tests/baselines/reference/constDeclarations-access4.errors.txt +++ b/tests/baselines/reference/constDeclarations-access4.errors.txt @@ -1,21 +1,21 @@ -tests/cases/compiler/constDeclarations-access4.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(21,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(22,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(24,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(26,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-access4.ts(28,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(21,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(22,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(24,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(26,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations-access4.ts(28,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. ==== tests/cases/compiler/constDeclarations-access4.ts (18 errors) ==== @@ -28,61 +28,61 @@ tests/cases/compiler/constDeclarations-access4.ts(28,1): error TS2450: Left-hand // Errors M.x = 1; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x += 2; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x -= 3; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x *= 4; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x /= 5; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x %= 6; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x <<= 7; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x >>= 8; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x >>>= 9; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x &= 10; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x |= 11; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x ^= 12; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. M.x++; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. M.x--; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. ++M.x; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. --M.x; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. ++((M.x)); ~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. M["x"] = 0; ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. // OK var a = M.x + 1; diff --git a/tests/baselines/reference/constDeclarations-access5.errors.txt b/tests/baselines/reference/constDeclarations-access5.errors.txt index 23200e50ee42b..45160bbc7cede 100644 --- a/tests/baselines/reference/constDeclarations-access5.errors.txt +++ b/tests/baselines/reference/constDeclarations-access5.errors.txt @@ -1,21 +1,21 @@ -tests/cases/compiler/constDeclarations_access_2.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(17,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(18,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(19,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(20,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(22,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(17,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(18,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(19,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(20,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(22,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. ==== tests/cases/compiler/constDeclarations_access_2.ts (18 errors) ==== @@ -24,61 +24,61 @@ tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-han // Errors m.x = 1; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x += 2; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x -= 3; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x *= 4; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x /= 5; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x %= 6; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x <<= 7; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x >>= 8; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x >>>= 9; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x &= 10; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x |= 11; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m.x ^= 12; ~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. m m.x++; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. m.x--; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. ++m.x; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. --m.x; ~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. ++((m.x)); ~~~~~~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. m["x"] = 0; ~~~~~~ -!!! error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. // OK var a = m.x + 1; diff --git a/tests/baselines/reference/constDeclarations-errors.errors.txt b/tests/baselines/reference/constDeclarations-errors.errors.txt index 10501beb1a540..98b12b616f77c 100644 --- a/tests/baselines/reference/constDeclarations-errors.errors.txt +++ b/tests/baselines/reference/constDeclarations-errors.errors.txt @@ -4,7 +4,7 @@ tests/cases/compiler/constDeclarations-errors.ts(5,7): error TS1155: 'const' dec tests/cases/compiler/constDeclarations-errors.ts(5,11): error TS1155: 'const' declarations must be initialized tests/cases/compiler/constDeclarations-errors.ts(5,15): error TS1155: 'const' declarations must be initialized tests/cases/compiler/constDeclarations-errors.ts(5,27): error TS1155: 'const' declarations must be initialized -tests/cases/compiler/constDeclarations-errors.ts(10,27): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-errors.ts(10,27): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. tests/cases/compiler/constDeclarations-errors.ts(13,11): error TS1155: 'const' declarations must be initialized tests/cases/compiler/constDeclarations-errors.ts(16,20): error TS1155: 'const' declarations must be initialized @@ -33,7 +33,7 @@ tests/cases/compiler/constDeclarations-errors.ts(16,20): error TS1155: 'const' d // error, assigning to a const for(const c8 = 0; c8 < 1; c8++) { } ~~ -!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. // error, can not be unintalized for(const c9; c9 < 1;) { } diff --git a/tests/baselines/reference/constEnumPropertyAccess2.errors.txt b/tests/baselines/reference/constEnumPropertyAccess2.errors.txt index 19b273faffa00..a943ee0096236 100644 --- a/tests/baselines/reference/constEnumPropertyAccess2.errors.txt +++ b/tests/baselines/reference/constEnumPropertyAccess2.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(14,9): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment. tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(15,12): error TS2476: A const enum member can only be accessed using a string literal. tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(17,1): error TS2322: Type 'string' is not assignable to type 'G'. -tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(19,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. ==== tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts (4 errors) ==== @@ -31,5 +31,5 @@ tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(19,1): error TS23 function foo(x: G) { } G.B = 3; ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/constantOverloadFunctionNoSubtypeError.errors.txt b/tests/baselines/reference/constantOverloadFunctionNoSubtypeError.errors.txt deleted file mode 100644 index 3c5e6f8efca31..0000000000000 --- a/tests/baselines/reference/constantOverloadFunctionNoSubtypeError.errors.txt +++ /dev/null @@ -1,26 +0,0 @@ -tests/cases/compiler/constantOverloadFunctionNoSubtypeError.ts(6,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/constantOverloadFunctionNoSubtypeError.ts(7,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/constantOverloadFunctionNoSubtypeError.ts(8,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - - -==== tests/cases/compiler/constantOverloadFunctionNoSubtypeError.ts (3 errors) ==== - class Base { foo() { } } - class Derived1 extends Base { bar() { } } - class Derived2 extends Base { baz() { } } - class Derived3 extends Base { biz() { } } - - function foo(tagName: 'canvas'): Derived3; - ~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - function foo(tagName: 'div'): Derived2; - ~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - function foo(tagName: 'span'): Derived1; - ~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - function foo(tagName: number): Base; - function foo(tagName: any): Base { - - return null; - } - \ No newline at end of file diff --git a/tests/baselines/reference/constantOverloadFunctionNoSubtypeError.symbols b/tests/baselines/reference/constantOverloadFunctionNoSubtypeError.symbols new file mode 100644 index 0000000000000..3a604e4b30eea --- /dev/null +++ b/tests/baselines/reference/constantOverloadFunctionNoSubtypeError.symbols @@ -0,0 +1,48 @@ +=== tests/cases/compiler/constantOverloadFunctionNoSubtypeError.ts === +class Base { foo() { } } +>Base : Symbol(Base, Decl(constantOverloadFunctionNoSubtypeError.ts, 0, 0)) +>foo : Symbol(foo, Decl(constantOverloadFunctionNoSubtypeError.ts, 0, 12)) + +class Derived1 extends Base { bar() { } } +>Derived1 : Symbol(Derived1, Decl(constantOverloadFunctionNoSubtypeError.ts, 0, 24)) +>Base : Symbol(Base, Decl(constantOverloadFunctionNoSubtypeError.ts, 0, 0)) +>bar : Symbol(bar, Decl(constantOverloadFunctionNoSubtypeError.ts, 1, 29)) + +class Derived2 extends Base { baz() { } } +>Derived2 : Symbol(Derived2, Decl(constantOverloadFunctionNoSubtypeError.ts, 1, 41)) +>Base : Symbol(Base, Decl(constantOverloadFunctionNoSubtypeError.ts, 0, 0)) +>baz : Symbol(baz, Decl(constantOverloadFunctionNoSubtypeError.ts, 2, 29)) + +class Derived3 extends Base { biz() { } } +>Derived3 : Symbol(Derived3, Decl(constantOverloadFunctionNoSubtypeError.ts, 2, 41)) +>Base : Symbol(Base, Decl(constantOverloadFunctionNoSubtypeError.ts, 0, 0)) +>biz : Symbol(biz, Decl(constantOverloadFunctionNoSubtypeError.ts, 3, 29)) + +function foo(tagName: 'canvas'): Derived3; +>foo : Symbol(foo, Decl(constantOverloadFunctionNoSubtypeError.ts, 3, 41), Decl(constantOverloadFunctionNoSubtypeError.ts, 5, 42), Decl(constantOverloadFunctionNoSubtypeError.ts, 6, 40), Decl(constantOverloadFunctionNoSubtypeError.ts, 7, 40), Decl(constantOverloadFunctionNoSubtypeError.ts, 8, 36)) +>tagName : Symbol(tagName, Decl(constantOverloadFunctionNoSubtypeError.ts, 5, 13)) +>Derived3 : Symbol(Derived3, Decl(constantOverloadFunctionNoSubtypeError.ts, 2, 41)) + +function foo(tagName: 'div'): Derived2; +>foo : Symbol(foo, Decl(constantOverloadFunctionNoSubtypeError.ts, 3, 41), Decl(constantOverloadFunctionNoSubtypeError.ts, 5, 42), Decl(constantOverloadFunctionNoSubtypeError.ts, 6, 40), Decl(constantOverloadFunctionNoSubtypeError.ts, 7, 40), Decl(constantOverloadFunctionNoSubtypeError.ts, 8, 36)) +>tagName : Symbol(tagName, Decl(constantOverloadFunctionNoSubtypeError.ts, 6, 13)) +>Derived2 : Symbol(Derived2, Decl(constantOverloadFunctionNoSubtypeError.ts, 1, 41)) + +function foo(tagName: 'span'): Derived1; +>foo : Symbol(foo, Decl(constantOverloadFunctionNoSubtypeError.ts, 3, 41), Decl(constantOverloadFunctionNoSubtypeError.ts, 5, 42), Decl(constantOverloadFunctionNoSubtypeError.ts, 6, 40), Decl(constantOverloadFunctionNoSubtypeError.ts, 7, 40), Decl(constantOverloadFunctionNoSubtypeError.ts, 8, 36)) +>tagName : Symbol(tagName, Decl(constantOverloadFunctionNoSubtypeError.ts, 7, 13)) +>Derived1 : Symbol(Derived1, Decl(constantOverloadFunctionNoSubtypeError.ts, 0, 24)) + +function foo(tagName: number): Base; +>foo : Symbol(foo, Decl(constantOverloadFunctionNoSubtypeError.ts, 3, 41), Decl(constantOverloadFunctionNoSubtypeError.ts, 5, 42), Decl(constantOverloadFunctionNoSubtypeError.ts, 6, 40), Decl(constantOverloadFunctionNoSubtypeError.ts, 7, 40), Decl(constantOverloadFunctionNoSubtypeError.ts, 8, 36)) +>tagName : Symbol(tagName, Decl(constantOverloadFunctionNoSubtypeError.ts, 8, 13)) +>Base : Symbol(Base, Decl(constantOverloadFunctionNoSubtypeError.ts, 0, 0)) + +function foo(tagName: any): Base { +>foo : Symbol(foo, Decl(constantOverloadFunctionNoSubtypeError.ts, 3, 41), Decl(constantOverloadFunctionNoSubtypeError.ts, 5, 42), Decl(constantOverloadFunctionNoSubtypeError.ts, 6, 40), Decl(constantOverloadFunctionNoSubtypeError.ts, 7, 40), Decl(constantOverloadFunctionNoSubtypeError.ts, 8, 36)) +>tagName : Symbol(tagName, Decl(constantOverloadFunctionNoSubtypeError.ts, 9, 13)) +>Base : Symbol(Base, Decl(constantOverloadFunctionNoSubtypeError.ts, 0, 0)) + + return null; +} + diff --git a/tests/baselines/reference/constantOverloadFunctionNoSubtypeError.types b/tests/baselines/reference/constantOverloadFunctionNoSubtypeError.types new file mode 100644 index 0000000000000..121faab82d553 --- /dev/null +++ b/tests/baselines/reference/constantOverloadFunctionNoSubtypeError.types @@ -0,0 +1,49 @@ +=== tests/cases/compiler/constantOverloadFunctionNoSubtypeError.ts === +class Base { foo() { } } +>Base : Base +>foo : () => void + +class Derived1 extends Base { bar() { } } +>Derived1 : Derived1 +>Base : Base +>bar : () => void + +class Derived2 extends Base { baz() { } } +>Derived2 : Derived2 +>Base : Base +>baz : () => void + +class Derived3 extends Base { biz() { } } +>Derived3 : Derived3 +>Base : Base +>biz : () => void + +function foo(tagName: 'canvas'): Derived3; +>foo : { (tagName: "canvas"): Derived3; (tagName: "div"): Derived2; (tagName: "span"): Derived1; (tagName: number): Base; } +>tagName : "canvas" +>Derived3 : Derived3 + +function foo(tagName: 'div'): Derived2; +>foo : { (tagName: "canvas"): Derived3; (tagName: "div"): Derived2; (tagName: "span"): Derived1; (tagName: number): Base; } +>tagName : "div" +>Derived2 : Derived2 + +function foo(tagName: 'span'): Derived1; +>foo : { (tagName: "canvas"): Derived3; (tagName: "div"): Derived2; (tagName: "span"): Derived1; (tagName: number): Base; } +>tagName : "span" +>Derived1 : Derived1 + +function foo(tagName: number): Base; +>foo : { (tagName: "canvas"): Derived3; (tagName: "div"): Derived2; (tagName: "span"): Derived1; (tagName: number): Base; } +>tagName : number +>Base : Base + +function foo(tagName: any): Base { +>foo : { (tagName: "canvas"): Derived3; (tagName: "div"): Derived2; (tagName: "span"): Derived1; (tagName: number): Base; } +>tagName : any +>Base : Base + + return null; +>null : null +} + diff --git a/tests/baselines/reference/constructorsWithSpecializedSignatures.errors.txt b/tests/baselines/reference/constructorsWithSpecializedSignatures.errors.txt index c4d0c7ffb6695..4f869fd63a06f 100644 --- a/tests/baselines/reference/constructorsWithSpecializedSignatures.errors.txt +++ b/tests/baselines/reference/constructorsWithSpecializedSignatures.errors.txt @@ -1,22 +1,12 @@ -tests/cases/compiler/constructorsWithSpecializedSignatures.ts(3,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/constructorsWithSpecializedSignatures.ts(4,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/constructorsWithSpecializedSignatures.ts(17,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/constructorsWithSpecializedSignatures.ts(18,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/constructorsWithSpecializedSignatures.ts(20,5): error TS2381: A signature with an implementation cannot use a string literal type. -tests/cases/compiler/constructorsWithSpecializedSignatures.ts(28,5): error TS2381: A signature with an implementation cannot use a string literal type. -tests/cases/compiler/constructorsWithSpecializedSignatures.ts(33,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/constructorsWithSpecializedSignatures.ts(34,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. +tests/cases/compiler/constructorsWithSpecializedSignatures.ts(18,5): error TS2394: Overload signature is not compatible with function implementation. +tests/cases/compiler/constructorsWithSpecializedSignatures.ts(26,5): error TS2394: Overload signature is not compatible with function implementation. -==== tests/cases/compiler/constructorsWithSpecializedSignatures.ts (8 errors) ==== +==== tests/cases/compiler/constructorsWithSpecializedSignatures.ts (2 errors) ==== // errors declare class C { constructor(x: "hi"); - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. constructor(x: "foo"); - ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. constructor(x: number); } @@ -30,35 +20,27 @@ tests/cases/compiler/constructorsWithSpecializedSignatures.ts(34,5): error TS238 // errors class D { constructor(x: "hi"); - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. constructor(x: "foo"); ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. +!!! error TS2394: Overload signature is not compatible with function implementation. constructor(x: number); constructor(x: "hi") { } - ~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. } // overloads are ok class D2 { constructor(x: "hi"); constructor(x: "foo"); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2394: Overload signature is not compatible with function implementation. constructor(x: string); constructor(x: "hi") { } // error - ~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. } // errors interface I { new (x: "hi"); - ~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. new (x: "foo"); - ~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. new (x: number); } diff --git a/tests/baselines/reference/crashInsourcePropertyIsRelatableToTargetProperty.errors.txt b/tests/baselines/reference/crashInsourcePropertyIsRelatableToTargetProperty.errors.txt index 450d180e88485..2938f7bf18d2a 100644 --- a/tests/baselines/reference/crashInsourcePropertyIsRelatableToTargetProperty.errors.txt +++ b/tests/baselines/reference/crashInsourcePropertyIsRelatableToTargetProperty.errors.txt @@ -1,16 +1,13 @@ -tests/cases/compiler/crashInsourcePropertyIsRelatableToTargetProperty.ts(5,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. tests/cases/compiler/crashInsourcePropertyIsRelatableToTargetProperty.ts(9,5): error TS2322: Type '(x: "hi", items: string[]) => typeof foo' is not assignable to type 'D'. Property 'x' is missing in type '(x: "hi", items: string[]) => typeof foo'. -==== tests/cases/compiler/crashInsourcePropertyIsRelatableToTargetProperty.ts (2 errors) ==== +==== tests/cases/compiler/crashInsourcePropertyIsRelatableToTargetProperty.ts (1 errors) ==== class C { private x = 1; } class D extends C { } function foo(x: "hi", items: string[]): typeof foo; - ~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. function foo(x: string, items: string[]): typeof foo { return null; } diff --git a/tests/baselines/reference/declFileAccessors.js b/tests/baselines/reference/declFileAccessors.js index e3616c79e389f..2bd51bfbfb2dd 100644 --- a/tests/baselines/reference/declFileAccessors.js +++ b/tests/baselines/reference/declFileAccessors.js @@ -284,7 +284,7 @@ export declare class c1 { nc_p3: number; private nc_pp3; static nc_s3: string; - onlyGetter: number; + readonly onlyGetter: number; onlySetter: number; } //// [declFileAccessors_1.d.ts] @@ -302,6 +302,6 @@ declare class c2 { nc_p3: number; private nc_pp3; static nc_s3: string; - onlyGetter: number; + readonly onlyGetter: number; onlySetter: number; } diff --git a/tests/baselines/reference/declFileObjectLiteralWithOnlyGetter.js b/tests/baselines/reference/declFileObjectLiteralWithOnlyGetter.js index 396ee75422e71..eb440c028d582 100644 --- a/tests/baselines/reference/declFileObjectLiteralWithOnlyGetter.js +++ b/tests/baselines/reference/declFileObjectLiteralWithOnlyGetter.js @@ -22,9 +22,9 @@ var /*2*/ x = point.x; //// [declFileObjectLiteralWithOnlyGetter.d.ts] declare function makePoint(x: number): { - x: number; + readonly x: number; }; declare var point: { - x: number; + readonly x: number; }; declare var x: number; diff --git a/tests/baselines/reference/declFileObjectLiteralWithOnlyGetter.types b/tests/baselines/reference/declFileObjectLiteralWithOnlyGetter.types index c0fb7b763fcfb..dd3cbe20983ad 100644 --- a/tests/baselines/reference/declFileObjectLiteralWithOnlyGetter.types +++ b/tests/baselines/reference/declFileObjectLiteralWithOnlyGetter.types @@ -1,11 +1,11 @@ === tests/cases/compiler/declFileObjectLiteralWithOnlyGetter.ts === function /*1*/makePoint(x: number) { ->makePoint : (x: number) => { x: number; } +>makePoint : (x: number) => { readonly x: number; } >x : number return { ->{ get x() { return x; }, } : { x: number; } +>{ get x() { return x; }, } : { readonly x: number; } get x() { return x; }, >x : number @@ -14,14 +14,14 @@ function /*1*/makePoint(x: number) { }; }; var /*4*/point = makePoint(2); ->point : { x: number; } ->makePoint(2) : { x: number; } ->makePoint : (x: number) => { x: number; } +>point : { readonly x: number; } +>makePoint(2) : { readonly x: number; } +>makePoint : (x: number) => { readonly x: number; } >2 : number var /*2*/x = point./*3*/x; >x : number >point./*3*/x : number ->point : { x: number; } +>point : { readonly x: number; } >x : number diff --git a/tests/baselines/reference/declFilePrivateStatic.js b/tests/baselines/reference/declFilePrivateStatic.js index dd81d94b3c5d1..30cd85444cf7b 100644 --- a/tests/baselines/reference/declFilePrivateStatic.js +++ b/tests/baselines/reference/declFilePrivateStatic.js @@ -52,8 +52,8 @@ declare class C { static y: number; private static a(); static b(): void; - private static c; - static d: number; + private static readonly c; + static readonly d: number; private static e; static f: any; } diff --git a/tests/baselines/reference/declarationEmit_protectedMembers.js b/tests/baselines/reference/declarationEmit_protectedMembers.js index 5aad004939d74..192f0647ed6df 100644 --- a/tests/baselines/reference/declarationEmit_protectedMembers.js +++ b/tests/baselines/reference/declarationEmit_protectedMembers.js @@ -135,7 +135,7 @@ declare class C1 { protected static sx: number; protected static sf(): number; protected static staticSetter: number; - protected static staticGetter: number; + protected static readonly staticGetter: number; } declare class C2 extends C1 { protected f(): number; @@ -146,7 +146,7 @@ declare class C3 extends C2 { static sx: number; f(): number; static sf(): number; - static staticGetter: number; + static readonly staticGetter: number; } declare class C4 { protected a: number; diff --git a/tests/baselines/reference/declarationMerging1.js b/tests/baselines/reference/declarationMerging1.js new file mode 100644 index 0000000000000..6b863def1c7c5 --- /dev/null +++ b/tests/baselines/reference/declarationMerging1.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/declarationMerging1.ts] //// + +//// [file1.ts] +class A { + protected _f: number; + getF() { return this._f; } +} + +//// [file2.ts] +interface A { + run(); +} + +//// [file1.js] +var A = (function () { + function A() { + } + A.prototype.getF = function () { return this._f; }; + return A; +}()); +//// [file2.js] diff --git a/tests/baselines/reference/declarationMerging1.symbols b/tests/baselines/reference/declarationMerging1.symbols new file mode 100644 index 0000000000000..08fe0d4c1fdb3 --- /dev/null +++ b/tests/baselines/reference/declarationMerging1.symbols @@ -0,0 +1,21 @@ +=== tests/cases/compiler/file1.ts === +class A { +>A : Symbol(A, Decl(file1.ts, 0, 0), Decl(file2.ts, 0, 0)) + + protected _f: number; +>_f : Symbol(_f, Decl(file1.ts, 0, 9)) + + getF() { return this._f; } +>getF : Symbol(getF, Decl(file1.ts, 1, 25)) +>this._f : Symbol(_f, Decl(file1.ts, 0, 9)) +>this : Symbol(A, Decl(file1.ts, 0, 0), Decl(file2.ts, 0, 0)) +>_f : Symbol(_f, Decl(file1.ts, 0, 9)) +} + +=== tests/cases/compiler/file2.ts === +interface A { +>A : Symbol(A, Decl(file1.ts, 0, 0), Decl(file2.ts, 0, 0)) + + run(); +>run : Symbol(run, Decl(file2.ts, 0, 13)) +} diff --git a/tests/baselines/reference/declarationMerging1.types b/tests/baselines/reference/declarationMerging1.types new file mode 100644 index 0000000000000..9802d2ab542a5 --- /dev/null +++ b/tests/baselines/reference/declarationMerging1.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/file1.ts === +class A { +>A : A + + protected _f: number; +>_f : number + + getF() { return this._f; } +>getF : () => number +>this._f : number +>this : this +>_f : number +} + +=== tests/cases/compiler/file2.ts === +interface A { +>A : A + + run(); +>run : () => any +} diff --git a/tests/baselines/reference/declarationMerging2.js b/tests/baselines/reference/declarationMerging2.js new file mode 100644 index 0000000000000..3157445fa36f8 --- /dev/null +++ b/tests/baselines/reference/declarationMerging2.js @@ -0,0 +1,32 @@ +//// [tests/cases/compiler/declarationMerging2.ts] //// + +//// [a.ts] + +export class A { + protected _f: number; + getF() { return this._f; } +} + +//// [b.ts] +export {} +declare module "./a" { + interface A { + run(); + } +} + +//// [a.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + var A = (function () { + function A() { + } + A.prototype.getF = function () { return this._f; }; + return A; + }()); + exports.A = A; +}); +//// [b.js] +define(["require", "exports"], function (require, exports) { + "use strict"; +}); diff --git a/tests/baselines/reference/declarationMerging2.symbols b/tests/baselines/reference/declarationMerging2.symbols new file mode 100644 index 0000000000000..b3891374d327d --- /dev/null +++ b/tests/baselines/reference/declarationMerging2.symbols @@ -0,0 +1,25 @@ +=== tests/cases/compiler/a.ts === + +export class A { +>A : Symbol(A, Decl(a.ts, 0, 0), Decl(b.ts, 1, 22)) + + protected _f: number; +>_f : Symbol(_f, Decl(a.ts, 1, 16)) + + getF() { return this._f; } +>getF : Symbol(getF, Decl(a.ts, 2, 25)) +>this._f : Symbol(_f, Decl(a.ts, 1, 16)) +>this : Symbol(A, Decl(a.ts, 0, 0), Decl(b.ts, 1, 22)) +>_f : Symbol(_f, Decl(a.ts, 1, 16)) +} + +=== tests/cases/compiler/b.ts === +export {} +declare module "./a" { + interface A { +>A : Symbol(A, Decl(a.ts, 0, 0), Decl(b.ts, 1, 22)) + + run(); +>run : Symbol(run, Decl(b.ts, 2, 17)) + } +} diff --git a/tests/baselines/reference/declarationMerging2.types b/tests/baselines/reference/declarationMerging2.types new file mode 100644 index 0000000000000..79e2818cf52b0 --- /dev/null +++ b/tests/baselines/reference/declarationMerging2.types @@ -0,0 +1,25 @@ +=== tests/cases/compiler/a.ts === + +export class A { +>A : A + + protected _f: number; +>_f : number + + getF() { return this._f; } +>getF : () => number +>this._f : number +>this : this +>_f : number +} + +=== tests/cases/compiler/b.ts === +export {} +declare module "./a" { + interface A { +>A : A + + run(); +>run : () => any + } +} diff --git a/tests/baselines/reference/decoratedClassFromExternalModule.js b/tests/baselines/reference/decoratedClassFromExternalModule.js index 000fe2f37d6f2..ce397323d9ccd 100644 --- a/tests/baselines/reference/decoratedClassFromExternalModule.js +++ b/tests/baselines/reference/decoratedClassFromExternalModule.js @@ -17,7 +17,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, return c > 3 && r && Object.defineProperty(target, key, r), r; }; function decorate(target) { } -let Decorated = class { +let Decorated = class Decorated { }; Decorated = __decorate([ decorate diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.js b/tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.js index dbbe72ba52c22..14ede865a2f05 100644 --- a/tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.js +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.js @@ -23,7 +23,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, define(["require", "exports"], function (require, exports) { "use strict"; var decorator; - let Foo = class { + let Foo = class Foo { }; Foo = __decorate([ decorator diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.js b/tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.js index ab518d73cb9c3..ecc04859234c9 100644 --- a/tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.js +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.js @@ -22,7 +22,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, return c > 3 && r && Object.defineProperty(target, key, r), r; }; var decorator; -let Foo = class { +let Foo = class Foo { }; Foo = __decorate([ decorator diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.js b/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.js index ed322374799b6..e2d9d0f0a6d89 100644 --- a/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.js +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.js @@ -13,8 +13,9 @@ var decorator: ClassDecorator; export default class {} //// [a.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; 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); @@ -25,7 +26,7 @@ System.register([], function(exports_1) { return { setters:[], execute: function() { - let Foo = class { + let Foo = class Foo { }; Foo = __decorate([ decorator @@ -35,8 +36,9 @@ System.register([], function(exports_1) { } }); //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; 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); diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.js b/tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.js index f8cb770f1d2cb..c7b59d0146935 100644 --- a/tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.js +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.js @@ -30,7 +30,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, })(function (require, exports) { "use strict"; var decorator; - let Foo = class { + let Foo = class Foo { }; Foo = __decorate([ decorator diff --git a/tests/baselines/reference/decoratorOnClass1.es6.js b/tests/baselines/reference/decoratorOnClass1.es6.js new file mode 100644 index 0000000000000..7a02b9f5cd877 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass1.es6.js @@ -0,0 +1,22 @@ +//// [decoratorOnClass1.es6.ts] +declare function dec(target: T): T; + +@dec +class C { +} + +let c = new C(); + +//// [decoratorOnClass1.es6.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; +}; +let C = class C { +}; +C = __decorate([ + dec +], C); +let c = new C(); diff --git a/tests/baselines/reference/decoratorOnClass1.es6.symbols b/tests/baselines/reference/decoratorOnClass1.es6.symbols new file mode 100644 index 0000000000000..aac2535d9cfef --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass1.es6.symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/es6/decorators/class/decoratorOnClass1.es6.ts === +declare function dec(target: T): T; +>dec : Symbol(dec, Decl(decoratorOnClass1.es6.ts, 0, 0)) +>T : Symbol(T, Decl(decoratorOnClass1.es6.ts, 0, 21)) +>target : Symbol(target, Decl(decoratorOnClass1.es6.ts, 0, 24)) +>T : Symbol(T, Decl(decoratorOnClass1.es6.ts, 0, 21)) +>T : Symbol(T, Decl(decoratorOnClass1.es6.ts, 0, 21)) + +@dec +>dec : Symbol(dec, Decl(decoratorOnClass1.es6.ts, 0, 0)) + +class C { +>C : Symbol(C, Decl(decoratorOnClass1.es6.ts, 0, 38)) +} + +let c = new C(); +>c : Symbol(c, Decl(decoratorOnClass1.es6.ts, 6, 3)) +>C : Symbol(C, Decl(decoratorOnClass1.es6.ts, 0, 38)) + diff --git a/tests/baselines/reference/decoratorOnClass1.es6.types b/tests/baselines/reference/decoratorOnClass1.es6.types new file mode 100644 index 0000000000000..fe7ef79ea6283 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass1.es6.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/es6/decorators/class/decoratorOnClass1.es6.ts === +declare function dec(target: T): T; +>dec : (target: T) => T +>T : T +>target : T +>T : T +>T : T + +@dec +>dec : (target: T) => T + +class C { +>C : C +} + +let c = new C(); +>c : C +>new C() : C +>C : typeof C + diff --git a/tests/baselines/reference/decoratorOnClass2.es6.js b/tests/baselines/reference/decoratorOnClass2.es6.js new file mode 100644 index 0000000000000..872f241bc9c73 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass2.es6.js @@ -0,0 +1,22 @@ +//// [decoratorOnClass2.es6.ts] +declare function dec(target: T): T; + +@dec +export class C { +} + +let c = new C(); + +//// [decoratorOnClass2.es6.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; +}; +export let C = class C { +}; +C = __decorate([ + dec +], C); +let c = new C(); diff --git a/tests/baselines/reference/decoratorOnClass2.es6.symbols b/tests/baselines/reference/decoratorOnClass2.es6.symbols new file mode 100644 index 0000000000000..af0dc7c1fad75 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass2.es6.symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/es6/decorators/class/decoratorOnClass2.es6.ts === +declare function dec(target: T): T; +>dec : Symbol(dec, Decl(decoratorOnClass2.es6.ts, 0, 0)) +>T : Symbol(T, Decl(decoratorOnClass2.es6.ts, 0, 21)) +>target : Symbol(target, Decl(decoratorOnClass2.es6.ts, 0, 24)) +>T : Symbol(T, Decl(decoratorOnClass2.es6.ts, 0, 21)) +>T : Symbol(T, Decl(decoratorOnClass2.es6.ts, 0, 21)) + +@dec +>dec : Symbol(dec, Decl(decoratorOnClass2.es6.ts, 0, 0)) + +export class C { +>C : Symbol(C, Decl(decoratorOnClass2.es6.ts, 0, 38)) +} + +let c = new C(); +>c : Symbol(c, Decl(decoratorOnClass2.es6.ts, 6, 3)) +>C : Symbol(C, Decl(decoratorOnClass2.es6.ts, 0, 38)) + diff --git a/tests/baselines/reference/decoratorOnClass2.es6.types b/tests/baselines/reference/decoratorOnClass2.es6.types new file mode 100644 index 0000000000000..2845ab1b9770e --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass2.es6.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/es6/decorators/class/decoratorOnClass2.es6.ts === +declare function dec(target: T): T; +>dec : (target: T) => T +>T : T +>target : T +>T : T +>T : T + +@dec +>dec : (target: T) => T + +export class C { +>C : C +} + +let c = new C(); +>c : C +>new C() : C +>C : typeof C + diff --git a/tests/baselines/reference/decoratorOnClass3.es6.js b/tests/baselines/reference/decoratorOnClass3.es6.js new file mode 100644 index 0000000000000..a6b1d6e258997 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass3.es6.js @@ -0,0 +1,23 @@ +//// [decoratorOnClass3.es6.ts] +declare function dec(target: T): T; + +@dec +export default class C { +} + +let c = new C(); + +//// [decoratorOnClass3.es6.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; +}; +let C = class C { +}; +C = __decorate([ + dec +], C); +export default C; +let c = new C(); diff --git a/tests/baselines/reference/decoratorOnClass3.es6.symbols b/tests/baselines/reference/decoratorOnClass3.es6.symbols new file mode 100644 index 0000000000000..d769d1c97a1aa --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass3.es6.symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/es6/decorators/class/decoratorOnClass3.es6.ts === +declare function dec(target: T): T; +>dec : Symbol(dec, Decl(decoratorOnClass3.es6.ts, 0, 0)) +>T : Symbol(T, Decl(decoratorOnClass3.es6.ts, 0, 21)) +>target : Symbol(target, Decl(decoratorOnClass3.es6.ts, 0, 24)) +>T : Symbol(T, Decl(decoratorOnClass3.es6.ts, 0, 21)) +>T : Symbol(T, Decl(decoratorOnClass3.es6.ts, 0, 21)) + +@dec +>dec : Symbol(dec, Decl(decoratorOnClass3.es6.ts, 0, 0)) + +export default class C { +>C : Symbol(C, Decl(decoratorOnClass3.es6.ts, 0, 38)) +} + +let c = new C(); +>c : Symbol(c, Decl(decoratorOnClass3.es6.ts, 6, 3)) +>C : Symbol(C, Decl(decoratorOnClass3.es6.ts, 0, 38)) + diff --git a/tests/baselines/reference/decoratorOnClass3.es6.types b/tests/baselines/reference/decoratorOnClass3.es6.types new file mode 100644 index 0000000000000..7b19c4bad8edb --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass3.es6.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/es6/decorators/class/decoratorOnClass3.es6.ts === +declare function dec(target: T): T; +>dec : (target: T) => T +>T : T +>target : T +>T : T +>T : T + +@dec +>dec : (target: T) => T + +export default class C { +>C : C +} + +let c = new C(); +>c : C +>new C() : C +>C : typeof C + diff --git a/tests/baselines/reference/decoratorOnClass4.es6.js b/tests/baselines/reference/decoratorOnClass4.es6.js new file mode 100644 index 0000000000000..0435c822da6bc --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass4.es6.js @@ -0,0 +1,20 @@ +//// [decoratorOnClass4.es6.ts] +declare function dec(target: T): T; + +@dec +export default class { +} + +//// [decoratorOnClass4.es6.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; +}; +let default_1 = class { +}; +default_1 = __decorate([ + dec +], default_1); +export default default_1; diff --git a/tests/baselines/reference/decoratorOnClass4.es6.symbols b/tests/baselines/reference/decoratorOnClass4.es6.symbols new file mode 100644 index 0000000000000..fff39c72f1cb1 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass4.es6.symbols @@ -0,0 +1,13 @@ +=== tests/cases/conformance/es6/decorators/class/decoratorOnClass4.es6.ts === +declare function dec(target: T): T; +>dec : Symbol(dec, Decl(decoratorOnClass4.es6.ts, 0, 0)) +>T : Symbol(T, Decl(decoratorOnClass4.es6.ts, 0, 21)) +>target : Symbol(target, Decl(decoratorOnClass4.es6.ts, 0, 24)) +>T : Symbol(T, Decl(decoratorOnClass4.es6.ts, 0, 21)) +>T : Symbol(T, Decl(decoratorOnClass4.es6.ts, 0, 21)) + +@dec +>dec : Symbol(dec, Decl(decoratorOnClass4.es6.ts, 0, 0)) + +export default class { +} diff --git a/tests/baselines/reference/decoratorOnClass4.es6.types b/tests/baselines/reference/decoratorOnClass4.es6.types new file mode 100644 index 0000000000000..7dfce858076e4 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass4.es6.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/es6/decorators/class/decoratorOnClass4.es6.ts === +declare function dec(target: T): T; +>dec : (target: T) => T +>T : T +>target : T +>T : T +>T : T + +@dec +>dec : (target: T) => T + +export default class { +} diff --git a/tests/baselines/reference/decoratorOnClass5.es6.js b/tests/baselines/reference/decoratorOnClass5.es6.js new file mode 100644 index 0000000000000..58c5f0d4f29f2 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass5.es6.js @@ -0,0 +1,27 @@ +//// [decoratorOnClass5.es6.ts] +declare function dec(target: T): T; + +@dec +class C { + static x() { return C.y; } + static y = 1; +} + +let c = new C(); + +//// [decoratorOnClass5.es6.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; +}; +let C_1; +let C = C_1 = class C { + static x() { return C_1.y; } +}; +C.y = 1; +C = C_1 = __decorate([ + dec +], C); +let c = new C(); diff --git a/tests/baselines/reference/decoratorOnClass5.es6.symbols b/tests/baselines/reference/decoratorOnClass5.es6.symbols new file mode 100644 index 0000000000000..aa62a59301978 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass5.es6.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es6/decorators/class/decoratorOnClass5.es6.ts === +declare function dec(target: T): T; +>dec : Symbol(dec, Decl(decoratorOnClass5.es6.ts, 0, 0)) +>T : Symbol(T, Decl(decoratorOnClass5.es6.ts, 0, 21)) +>target : Symbol(target, Decl(decoratorOnClass5.es6.ts, 0, 24)) +>T : Symbol(T, Decl(decoratorOnClass5.es6.ts, 0, 21)) +>T : Symbol(T, Decl(decoratorOnClass5.es6.ts, 0, 21)) + +@dec +>dec : Symbol(dec, Decl(decoratorOnClass5.es6.ts, 0, 0)) + +class C { +>C : Symbol(C, Decl(decoratorOnClass5.es6.ts, 0, 38)) + + static x() { return C.y; } +>x : Symbol(C.x, Decl(decoratorOnClass5.es6.ts, 3, 9)) +>C.y : Symbol(C.y, Decl(decoratorOnClass5.es6.ts, 4, 30)) +>C : Symbol(C, Decl(decoratorOnClass5.es6.ts, 0, 38)) +>y : Symbol(C.y, Decl(decoratorOnClass5.es6.ts, 4, 30)) + + static y = 1; +>y : Symbol(C.y, Decl(decoratorOnClass5.es6.ts, 4, 30)) +} + +let c = new C(); +>c : Symbol(c, Decl(decoratorOnClass5.es6.ts, 8, 3)) +>C : Symbol(C, Decl(decoratorOnClass5.es6.ts, 0, 38)) + diff --git a/tests/baselines/reference/decoratorOnClass5.es6.types b/tests/baselines/reference/decoratorOnClass5.es6.types new file mode 100644 index 0000000000000..5532c50fe5255 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass5.es6.types @@ -0,0 +1,30 @@ +=== tests/cases/conformance/es6/decorators/class/decoratorOnClass5.es6.ts === +declare function dec(target: T): T; +>dec : (target: T) => T +>T : T +>target : T +>T : T +>T : T + +@dec +>dec : (target: T) => T + +class C { +>C : C + + static x() { return C.y; } +>x : () => number +>C.y : number +>C : typeof C +>y : number + + static y = 1; +>y : number +>1 : number +} + +let c = new C(); +>c : C +>new C() : C +>C : typeof C + diff --git a/tests/baselines/reference/decoratorOnClass6.es6.js b/tests/baselines/reference/decoratorOnClass6.es6.js new file mode 100644 index 0000000000000..03b8ace2b5bdf --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass6.es6.js @@ -0,0 +1,27 @@ +//// [decoratorOnClass6.es6.ts] +declare function dec(target: T): T; + +@dec +export class C { + static x() { return C.y; } + static y = 1; +} + +let c = new C(); + +//// [decoratorOnClass6.es6.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; +}; +let C_1; +export let C = C_1 = class C { + static x() { return C_1.y; } +}; +C.y = 1; +C = C_1 = __decorate([ + dec +], C); +let c = new C(); diff --git a/tests/baselines/reference/decoratorOnClass6.es6.symbols b/tests/baselines/reference/decoratorOnClass6.es6.symbols new file mode 100644 index 0000000000000..f778128e40bee --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass6.es6.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es6/decorators/class/decoratorOnClass6.es6.ts === +declare function dec(target: T): T; +>dec : Symbol(dec, Decl(decoratorOnClass6.es6.ts, 0, 0)) +>T : Symbol(T, Decl(decoratorOnClass6.es6.ts, 0, 21)) +>target : Symbol(target, Decl(decoratorOnClass6.es6.ts, 0, 24)) +>T : Symbol(T, Decl(decoratorOnClass6.es6.ts, 0, 21)) +>T : Symbol(T, Decl(decoratorOnClass6.es6.ts, 0, 21)) + +@dec +>dec : Symbol(dec, Decl(decoratorOnClass6.es6.ts, 0, 0)) + +export class C { +>C : Symbol(C, Decl(decoratorOnClass6.es6.ts, 0, 38)) + + static x() { return C.y; } +>x : Symbol(C.x, Decl(decoratorOnClass6.es6.ts, 3, 16)) +>C.y : Symbol(C.y, Decl(decoratorOnClass6.es6.ts, 4, 30)) +>C : Symbol(C, Decl(decoratorOnClass6.es6.ts, 0, 38)) +>y : Symbol(C.y, Decl(decoratorOnClass6.es6.ts, 4, 30)) + + static y = 1; +>y : Symbol(C.y, Decl(decoratorOnClass6.es6.ts, 4, 30)) +} + +let c = new C(); +>c : Symbol(c, Decl(decoratorOnClass6.es6.ts, 8, 3)) +>C : Symbol(C, Decl(decoratorOnClass6.es6.ts, 0, 38)) + diff --git a/tests/baselines/reference/decoratorOnClass6.es6.types b/tests/baselines/reference/decoratorOnClass6.es6.types new file mode 100644 index 0000000000000..0b335558400b4 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass6.es6.types @@ -0,0 +1,30 @@ +=== tests/cases/conformance/es6/decorators/class/decoratorOnClass6.es6.ts === +declare function dec(target: T): T; +>dec : (target: T) => T +>T : T +>target : T +>T : T +>T : T + +@dec +>dec : (target: T) => T + +export class C { +>C : C + + static x() { return C.y; } +>x : () => number +>C.y : number +>C : typeof C +>y : number + + static y = 1; +>y : number +>1 : number +} + +let c = new C(); +>c : C +>new C() : C +>C : typeof C + diff --git a/tests/baselines/reference/decoratorOnClass7.es6.js b/tests/baselines/reference/decoratorOnClass7.es6.js new file mode 100644 index 0000000000000..3ffd0f1574fc3 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass7.es6.js @@ -0,0 +1,28 @@ +//// [decoratorOnClass7.es6.ts] +declare function dec(target: T): T; + +@dec +export default class C { + static x() { return C.y; } + static y = 1; +} + +let c = new C(); + +//// [decoratorOnClass7.es6.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; +}; +let C_1; +let C = C_1 = class C { + static x() { return C_1.y; } +}; +C.y = 1; +C = C_1 = __decorate([ + dec +], C); +export default C; +let c = new C(); diff --git a/tests/baselines/reference/decoratorOnClass7.es6.symbols b/tests/baselines/reference/decoratorOnClass7.es6.symbols new file mode 100644 index 0000000000000..d010757a9dfdf --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass7.es6.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es6/decorators/class/decoratorOnClass7.es6.ts === +declare function dec(target: T): T; +>dec : Symbol(dec, Decl(decoratorOnClass7.es6.ts, 0, 0)) +>T : Symbol(T, Decl(decoratorOnClass7.es6.ts, 0, 21)) +>target : Symbol(target, Decl(decoratorOnClass7.es6.ts, 0, 24)) +>T : Symbol(T, Decl(decoratorOnClass7.es6.ts, 0, 21)) +>T : Symbol(T, Decl(decoratorOnClass7.es6.ts, 0, 21)) + +@dec +>dec : Symbol(dec, Decl(decoratorOnClass7.es6.ts, 0, 0)) + +export default class C { +>C : Symbol(C, Decl(decoratorOnClass7.es6.ts, 0, 38)) + + static x() { return C.y; } +>x : Symbol(C.x, Decl(decoratorOnClass7.es6.ts, 3, 24)) +>C.y : Symbol(C.y, Decl(decoratorOnClass7.es6.ts, 4, 30)) +>C : Symbol(C, Decl(decoratorOnClass7.es6.ts, 0, 38)) +>y : Symbol(C.y, Decl(decoratorOnClass7.es6.ts, 4, 30)) + + static y = 1; +>y : Symbol(C.y, Decl(decoratorOnClass7.es6.ts, 4, 30)) +} + +let c = new C(); +>c : Symbol(c, Decl(decoratorOnClass7.es6.ts, 8, 3)) +>C : Symbol(C, Decl(decoratorOnClass7.es6.ts, 0, 38)) + diff --git a/tests/baselines/reference/decoratorOnClass7.es6.types b/tests/baselines/reference/decoratorOnClass7.es6.types new file mode 100644 index 0000000000000..af7ae0516e398 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass7.es6.types @@ -0,0 +1,30 @@ +=== tests/cases/conformance/es6/decorators/class/decoratorOnClass7.es6.ts === +declare function dec(target: T): T; +>dec : (target: T) => T +>T : T +>target : T +>T : T +>T : T + +@dec +>dec : (target: T) => T + +export default class C { +>C : C + + static x() { return C.y; } +>x : () => number +>C.y : number +>C : typeof C +>y : number + + static y = 1; +>y : number +>1 : number +} + +let c = new C(); +>c : C +>new C() : C +>C : typeof C + diff --git a/tests/baselines/reference/decoratorOnClass8.es6.js b/tests/baselines/reference/decoratorOnClass8.es6.js new file mode 100644 index 0000000000000..7104098a5f5e6 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass8.es6.js @@ -0,0 +1,22 @@ +//// [decoratorOnClass8.es6.ts] +declare function dec(target: T): T; + +@dec +export default class { + static y = 1; +} + +//// [decoratorOnClass8.es6.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; +}; +let default_1 = class { +}; +default_1.y = 1; +default_1 = __decorate([ + dec +], default_1); +export default default_1; diff --git a/tests/baselines/reference/decoratorOnClass8.es6.symbols b/tests/baselines/reference/decoratorOnClass8.es6.symbols new file mode 100644 index 0000000000000..b219f50ff3d16 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass8.es6.symbols @@ -0,0 +1,15 @@ +=== tests/cases/conformance/es6/decorators/class/decoratorOnClass8.es6.ts === +declare function dec(target: T): T; +>dec : Symbol(dec, Decl(decoratorOnClass8.es6.ts, 0, 0)) +>T : Symbol(T, Decl(decoratorOnClass8.es6.ts, 0, 21)) +>target : Symbol(target, Decl(decoratorOnClass8.es6.ts, 0, 24)) +>T : Symbol(T, Decl(decoratorOnClass8.es6.ts, 0, 21)) +>T : Symbol(T, Decl(decoratorOnClass8.es6.ts, 0, 21)) + +@dec +>dec : Symbol(dec, Decl(decoratorOnClass8.es6.ts, 0, 0)) + +export default class { + static y = 1; +>y : Symbol(default.y, Decl(decoratorOnClass8.es6.ts, 3, 22)) +} diff --git a/tests/baselines/reference/decoratorOnClass8.es6.types b/tests/baselines/reference/decoratorOnClass8.es6.types new file mode 100644 index 0000000000000..045b036e33545 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass8.es6.types @@ -0,0 +1,16 @@ +=== tests/cases/conformance/es6/decorators/class/decoratorOnClass8.es6.ts === +declare function dec(target: T): T; +>dec : (target: T) => T +>T : T +>target : T +>T : T +>T : T + +@dec +>dec : (target: T) => T + +export default class { + static y = 1; +>y : number +>1 : number +} diff --git a/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt b/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt index a0c30e9dc93fa..29e06bc6a4e54 100644 --- a/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt +++ b/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt @@ -1,21 +1,27 @@ -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(7,23): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(6,25): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(7,23): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(10,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(12,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(12,7): error TS2304: Cannot find name 'A'. -==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts (3 errors) ==== +==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts (5 errors) ==== // -- operator on enum type enum ENUM1 { A, B, "" }; // expression var ResultIsNumber1 = --ENUM1["A"]; + ~~~~~~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. var ResultIsNumber2 = ENUM1.A--; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. // miss assignment operator --ENUM1["A"]; + ~~~~~~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. ENUM1[A]--; ~~~~~~~~ diff --git a/tests/baselines/reference/deduplicateImportsInSystem.errors.txt b/tests/baselines/reference/deduplicateImportsInSystem.errors.txt new file mode 100644 index 0000000000000..d1bfe88160e59 --- /dev/null +++ b/tests/baselines/reference/deduplicateImportsInSystem.errors.txt @@ -0,0 +1,32 @@ +tests/cases/compiler/deduplicateImportsInSystem.ts(1,17): error TS2307: Cannot find module 'f1'. +tests/cases/compiler/deduplicateImportsInSystem.ts(2,17): error TS2307: Cannot find module 'f2'. +tests/cases/compiler/deduplicateImportsInSystem.ts(3,17): error TS2307: Cannot find module 'f3'. +tests/cases/compiler/deduplicateImportsInSystem.ts(4,17): error TS2307: Cannot find module 'f2'. +tests/cases/compiler/deduplicateImportsInSystem.ts(5,17): error TS2307: Cannot find module 'f2'. +tests/cases/compiler/deduplicateImportsInSystem.ts(6,17): error TS2307: Cannot find module 'f1'. +tests/cases/compiler/deduplicateImportsInSystem.ts(8,1): error TS2304: Cannot find name 'console'. + + +==== tests/cases/compiler/deduplicateImportsInSystem.ts (7 errors) ==== + import {A} from "f1"; + ~~~~ +!!! error TS2307: Cannot find module 'f1'. + import {B} from "f2"; + ~~~~ +!!! error TS2307: Cannot find module 'f2'. + import {C} from "f3"; + ~~~~ +!!! error TS2307: Cannot find module 'f3'. + import {D} from 'f2'; + ~~~~ +!!! error TS2307: Cannot find module 'f2'. + import {E} from "f2"; + ~~~~ +!!! error TS2307: Cannot find module 'f2'. + import {F} from 'f1'; + ~~~~ +!!! error TS2307: Cannot find module 'f1'. + + console.log(A + B + C + D + E + F) + ~~~~~~~ +!!! error TS2304: Cannot find name 'console'. \ No newline at end of file diff --git a/tests/baselines/reference/deduplicateImportsInSystem.js b/tests/baselines/reference/deduplicateImportsInSystem.js new file mode 100644 index 0000000000000..accc4954e65a5 --- /dev/null +++ b/tests/baselines/reference/deduplicateImportsInSystem.js @@ -0,0 +1,34 @@ +//// [deduplicateImportsInSystem.ts] +import {A} from "f1"; +import {B} from "f2"; +import {C} from "f3"; +import {D} from 'f2'; +import {E} from "f2"; +import {F} from 'f1'; + +console.log(A + B + C + D + E + F) + +//// [deduplicateImportsInSystem.js] +System.register(["f1", "f2", "f3"], function(exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + var f1_1, f2_1, f3_1, f2_2, f2_3, f1_2; + return { + setters:[ + function (f1_1_1) { + f1_1 = f1_1_1; + f1_2 = f1_1_1; + }, + function (f2_1_1) { + f2_1 = f2_1_1; + f2_2 = f2_1_1; + f2_3 = f2_1_1; + }, + function (f3_1_1) { + f3_1 = f3_1_1; + }], + execute: function() { + console.log(f1_1.A + f2_1.B + f3_1.C + f2_2.D + f2_3.E + f1_2.F); + } + } +}); diff --git a/tests/baselines/reference/defaultExportsGetExportedSystem.js b/tests/baselines/reference/defaultExportsGetExportedSystem.js index 67dc47f4bd564..eac3d3c7c43ee 100644 --- a/tests/baselines/reference/defaultExportsGetExportedSystem.js +++ b/tests/baselines/reference/defaultExportsGetExportedSystem.js @@ -8,8 +8,9 @@ export default function foo() {} //// [a.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var Foo; return { setters:[], @@ -21,8 +22,9 @@ System.register([], function(exports_1) { } }); //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; function foo() { } exports_1("default", foo); return { diff --git a/tests/baselines/reference/derivedClassParameterProperties.errors.txt b/tests/baselines/reference/derivedClassParameterProperties.errors.txt index 0dba0d24cb0ff..27bb9af63a1a6 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.errors.txt +++ b/tests/baselines/reference/derivedClassParameterProperties.errors.txt @@ -1,10 +1,15 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(15,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(30,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(47,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(56,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(57,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(58,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(79,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(80,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(81,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts (4 errors) ==== +==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts (9 errors) ==== // ordering of super calls in derived constructors matters depending on other class contents class Base { @@ -62,8 +67,10 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP a: number; constructor(y: string) { this.a = 1; + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. var b = 2; - super(); // ok + super(); // error: "super" has to be called before "this" accessing } } @@ -74,8 +81,12 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP ~~~~~~~~~~~~~~~~~~~~~~~~ this.a = 3; ~~~~~~~~~~~~~~~~~~~ + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. this.b = 3; ~~~~~~~~~~~~~~~~~~~ + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. super(); // error ~~~~~~~~~~~~~~~~~~~~~~~~~ } @@ -103,8 +114,12 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP ~~~~~~~~~~~~~~~~~~~~~~~~ this.a = 3; ~~~~~~~~~~~~~~~~~~~ + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. this.b = 3; ~~~~~~~~~~~~~~~~~~~ + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. super(); // error ~~~~~~~~~~~~~~~~~~~~~~~~~ } diff --git a/tests/baselines/reference/derivedClassParameterProperties.js b/tests/baselines/reference/derivedClassParameterProperties.js index c0a1736a2a3e5..8e5fa82cf0f24 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.js +++ b/tests/baselines/reference/derivedClassParameterProperties.js @@ -47,7 +47,7 @@ class Derived6 extends Base { constructor(y: string) { this.a = 1; var b = 2; - super(); // ok + super(); // error: "super" has to be called before "this" accessing } } @@ -155,7 +155,7 @@ var Derived6 = (function (_super) { function Derived6(y) { this.a = 1; var b = 2; - _super.call(this); // ok + _super.call(this); // error: "super" has to be called before "this" accessing } return Derived6; }(Base)); diff --git a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt index ef43d1d6f528d..d381eff17dcca 100644 --- a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt +++ b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(14,15): error TS2332: 'this' cannot be referenced in current location. -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(20,21): error TS2332: 'this' cannot be referenced in current location. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(8,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(14,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. ==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts (2 errors) ==== @@ -11,6 +11,8 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS class Derived extends Base { constructor() { super(this); // ok + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -18,15 +20,13 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS constructor(public a: string) { super(this); // error ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } class Derived3 extends Base { constructor(public a: string) { super(() => this); // error - ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. } } diff --git a/tests/baselines/reference/dottedNamesInSystem.js b/tests/baselines/reference/dottedNamesInSystem.js new file mode 100644 index 0000000000000..4f1814f393dd6 --- /dev/null +++ b/tests/baselines/reference/dottedNamesInSystem.js @@ -0,0 +1,35 @@ +//// [dottedNamesInSystem.ts] +export namespace A.B.C { + export function foo() {} +} + +export function bar() { + return A.B.C.foo(); +} + +//// [dottedNamesInSystem.js] +System.register([], function(exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + var A; + function bar() { + return A.B.C.foo(); + } + exports_1("bar", bar); + return { + setters:[], + execute: function() { + (function (A) { + var B; + (function (B) { + var C; + (function (C) { + function foo() { } + C.foo = foo; + })(C = B.C || (B.C = {})); + })(B = A.B || (A.B = {})); + })(A = A || (A = {})); + exports_1("A", A); + } + } +}); diff --git a/tests/baselines/reference/dottedNamesInSystem.symbols b/tests/baselines/reference/dottedNamesInSystem.symbols new file mode 100644 index 0000000000000..bfbc57ed1baf7 --- /dev/null +++ b/tests/baselines/reference/dottedNamesInSystem.symbols @@ -0,0 +1,22 @@ +=== tests/cases/compiler/dottedNamesInSystem.ts === +export namespace A.B.C { +>A : Symbol(A, Decl(dottedNamesInSystem.ts, 0, 0)) +>B : Symbol(B, Decl(dottedNamesInSystem.ts, 0, 19)) +>C : Symbol(C, Decl(dottedNamesInSystem.ts, 0, 21)) + + export function foo() {} +>foo : Symbol(foo, Decl(dottedNamesInSystem.ts, 0, 24)) +} + +export function bar() { +>bar : Symbol(bar, Decl(dottedNamesInSystem.ts, 2, 1)) + + return A.B.C.foo(); +>A.B.C.foo : Symbol(A.B.C.foo, Decl(dottedNamesInSystem.ts, 0, 24)) +>A.B.C : Symbol(A.B.C, Decl(dottedNamesInSystem.ts, 0, 21)) +>A.B : Symbol(A.B, Decl(dottedNamesInSystem.ts, 0, 19)) +>A : Symbol(A, Decl(dottedNamesInSystem.ts, 0, 0)) +>B : Symbol(A.B, Decl(dottedNamesInSystem.ts, 0, 19)) +>C : Symbol(A.B.C, Decl(dottedNamesInSystem.ts, 0, 21)) +>foo : Symbol(A.B.C.foo, Decl(dottedNamesInSystem.ts, 0, 24)) +} diff --git a/tests/baselines/reference/dottedNamesInSystem.types b/tests/baselines/reference/dottedNamesInSystem.types new file mode 100644 index 0000000000000..78de0e338837e --- /dev/null +++ b/tests/baselines/reference/dottedNamesInSystem.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/dottedNamesInSystem.ts === +export namespace A.B.C { +>A : typeof A +>B : typeof B +>C : typeof C + + export function foo() {} +>foo : () => void +} + +export function bar() { +>bar : () => void + + return A.B.C.foo(); +>A.B.C.foo() : void +>A.B.C.foo : () => void +>A.B.C : typeof A.B.C +>A.B : typeof A.B +>A : typeof A +>B : typeof A.B +>C : typeof A.B.C +>foo : () => void +} diff --git a/tests/baselines/reference/downlevelLetConst16.js b/tests/baselines/reference/downlevelLetConst16.js index 4b9d4c438fc49..edc778209bef3 100644 --- a/tests/baselines/reference/downlevelLetConst16.js +++ b/tests/baselines/reference/downlevelLetConst16.js @@ -367,7 +367,7 @@ var M4; use(z); })(M4 || (M4 = {})); function foo3() { - for (var x_7 = void 0;;) { + for (var x_7;;) { use(x_7); } for (var y_7 = [][0];;) { diff --git a/tests/baselines/reference/downlevelLetConst17.js b/tests/baselines/reference/downlevelLetConst17.js index 56ab1e6df54c6..49212b267f0f0 100644 --- a/tests/baselines/reference/downlevelLetConst17.js +++ b/tests/baselines/reference/downlevelLetConst17.js @@ -86,7 +86,7 @@ for (;;) { var x_4 = 10; use(x_4); } -for (var x_5 = void 0;;) { +for (var x_5;;) { use(x_5); x_5 = 1; } diff --git a/tests/baselines/reference/downlevelLetConst18.types b/tests/baselines/reference/downlevelLetConst18.types index 42421aa80c065..1f7be6161247f 100644 --- a/tests/baselines/reference/downlevelLetConst18.types +++ b/tests/baselines/reference/downlevelLetConst18.types @@ -54,8 +54,8 @@ for (let x; ;) { >x : any ({ get foo() { return x } }) ->({ get foo() { return x } }) : { foo: any; } ->{ get foo() { return x } } : { foo: any; } +>({ get foo() { return x } }) : { readonly foo: any; } +>{ get foo() { return x } } : { readonly foo: any; } >foo : any >x : any } diff --git a/tests/baselines/reference/dynamicRequire.js b/tests/baselines/reference/dynamicRequire.js new file mode 100644 index 0000000000000..28b359706013f --- /dev/null +++ b/tests/baselines/reference/dynamicRequire.js @@ -0,0 +1,10 @@ +//// [a.js] + +function foo(name) { + var s = require("t/" + name) +} + +//// [a_out.js] +function foo(name) { + var s = require("t/" + name); +} diff --git a/tests/baselines/reference/dynamicRequire.symbols b/tests/baselines/reference/dynamicRequire.symbols new file mode 100644 index 0000000000000..c307d578de7d1 --- /dev/null +++ b/tests/baselines/reference/dynamicRequire.symbols @@ -0,0 +1,10 @@ +=== tests/cases/compiler/a.js === + +function foo(name) { +>foo : Symbol(foo, Decl(a.js, 0, 0)) +>name : Symbol(name, Decl(a.js, 1, 13)) + + var s = require("t/" + name) +>s : Symbol(s, Decl(a.js, 2, 7)) +>name : Symbol(name, Decl(a.js, 1, 13)) +} diff --git a/tests/baselines/reference/dynamicRequire.types b/tests/baselines/reference/dynamicRequire.types new file mode 100644 index 0000000000000..43eea88a05b26 --- /dev/null +++ b/tests/baselines/reference/dynamicRequire.types @@ -0,0 +1,14 @@ +=== tests/cases/compiler/a.js === + +function foo(name) { +>foo : (name: any) => void +>name : any + + var s = require("t/" + name) +>s : any +>require("t/" + name) : any +>require : any +>"t/" + name : string +>"t/" : string +>name : any +} diff --git a/tests/baselines/reference/enumBasics.js b/tests/baselines/reference/enumBasics.js index 25aec5a72d84d..4ac41c0f3d1b8 100644 --- a/tests/baselines/reference/enumBasics.js +++ b/tests/baselines/reference/enumBasics.js @@ -12,10 +12,10 @@ var x: number = E1.A; // Enum object type is anonymous with properties of the enum type and numeric indexer var e = E1; var e: { - A: E1; - B: E1; - C: E1; - [n: number]: string; + readonly A: E1; + readonly B: E1; + readonly C: E1; + readonly [n: number]: string; }; var e: typeof E1; diff --git a/tests/baselines/reference/enumBasics.symbols b/tests/baselines/reference/enumBasics.symbols index 23f2a400741fe..ce81a80ca5fa3 100644 --- a/tests/baselines/reference/enumBasics.symbols +++ b/tests/baselines/reference/enumBasics.symbols @@ -28,20 +28,20 @@ var e = E1; var e: { >e : Symbol(e, Decl(enumBasics.ts, 11, 3), Decl(enumBasics.ts, 12, 3), Decl(enumBasics.ts, 18, 3)) - A: E1; + readonly A: E1; >A : Symbol(A, Decl(enumBasics.ts, 12, 8)) >E1 : Symbol(E1, Decl(enumBasics.ts, 0, 0)) - B: E1; ->B : Symbol(B, Decl(enumBasics.ts, 13, 10)) + readonly B: E1; +>B : Symbol(B, Decl(enumBasics.ts, 13, 19)) >E1 : Symbol(E1, Decl(enumBasics.ts, 0, 0)) - C: E1; ->C : Symbol(C, Decl(enumBasics.ts, 14, 10)) + readonly C: E1; +>C : Symbol(C, Decl(enumBasics.ts, 14, 19)) >E1 : Symbol(E1, Decl(enumBasics.ts, 0, 0)) - [n: number]: string; ->n : Symbol(n, Decl(enumBasics.ts, 16, 5)) + readonly [n: number]: string; +>n : Symbol(n, Decl(enumBasics.ts, 16, 14)) }; var e: typeof E1; diff --git a/tests/baselines/reference/enumBasics.types b/tests/baselines/reference/enumBasics.types index 87f6f12b6b2ef..cecd8f5113606 100644 --- a/tests/baselines/reference/enumBasics.types +++ b/tests/baselines/reference/enumBasics.types @@ -28,19 +28,19 @@ var e = E1; var e: { >e : typeof E1 - A: E1; + readonly A: E1; >A : E1 >E1 : E1 - B: E1; + readonly B: E1; >B : E1 >E1 : E1 - C: E1; + readonly C: E1; >C : E1 >E1 : E1 - [n: number]: string; + readonly [n: number]: string; >n : number }; diff --git a/tests/baselines/reference/es5-system.js b/tests/baselines/reference/es5-system.js index a9633352b8b69..9cf5ea87f1f32 100644 --- a/tests/baselines/reference/es5-system.js +++ b/tests/baselines/reference/es5-system.js @@ -15,8 +15,9 @@ export default class A //// [es5-system.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var A; return { setters:[], diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js index d7dfe29208d0d..4bff2abf82d56 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js @@ -31,16 +31,16 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = {}; //// [es6ImportDefaultBindingFollowedWithNamedImport_1.js] "use strict"; -var es6ImportDefaultBindingFollowedWithNamedImport_0_1 = require("./es6ImportDefaultBindingFollowedWithNamedImport_0"); +const es6ImportDefaultBindingFollowedWithNamedImport_0_1 = require("./es6ImportDefaultBindingFollowedWithNamedImport_0"); var x1 = es6ImportDefaultBindingFollowedWithNamedImport_0_1.a; -var es6ImportDefaultBindingFollowedWithNamedImport_0_2 = require("./es6ImportDefaultBindingFollowedWithNamedImport_0"); +const es6ImportDefaultBindingFollowedWithNamedImport_0_2 = require("./es6ImportDefaultBindingFollowedWithNamedImport_0"); var x1 = es6ImportDefaultBindingFollowedWithNamedImport_0_2.a; -var es6ImportDefaultBindingFollowedWithNamedImport_0_3 = require("./es6ImportDefaultBindingFollowedWithNamedImport_0"); +const es6ImportDefaultBindingFollowedWithNamedImport_0_3 = require("./es6ImportDefaultBindingFollowedWithNamedImport_0"); var x1 = es6ImportDefaultBindingFollowedWithNamedImport_0_3.x; var x1 = es6ImportDefaultBindingFollowedWithNamedImport_0_3.a; -var es6ImportDefaultBindingFollowedWithNamedImport_0_4 = require("./es6ImportDefaultBindingFollowedWithNamedImport_0"); +const es6ImportDefaultBindingFollowedWithNamedImport_0_4 = require("./es6ImportDefaultBindingFollowedWithNamedImport_0"); var x1 = es6ImportDefaultBindingFollowedWithNamedImport_0_4.x; -var es6ImportDefaultBindingFollowedWithNamedImport_0_5 = require("./es6ImportDefaultBindingFollowedWithNamedImport_0"); +const es6ImportDefaultBindingFollowedWithNamedImport_0_5 = require("./es6ImportDefaultBindingFollowedWithNamedImport_0"); var x1 = es6ImportDefaultBindingFollowedWithNamedImport_0_5.m; diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.js b/tests/baselines/reference/es6ImportNameSpaceImport.js index 685e1cf643c24..8e109779f45fb 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImport.js +++ b/tests/baselines/reference/es6ImportNameSpaceImport.js @@ -15,7 +15,7 @@ import * as nameSpaceBinding2 from "./es6ImportNameSpaceImport_0"; // elide this exports.a = 10; //// [es6ImportNameSpaceImport_1.js] "use strict"; -var nameSpaceBinding = require("./es6ImportNameSpaceImport_0"); +const nameSpaceBinding = require("./es6ImportNameSpaceImport_0"); var x = nameSpaceBinding.a; diff --git a/tests/baselines/reference/es6ImportNamedImport.js b/tests/baselines/reference/es6ImportNamedImport.js index 73fe8f4ec1b4f..8dbdf7ce6f195 100644 --- a/tests/baselines/reference/es6ImportNamedImport.js +++ b/tests/baselines/reference/es6ImportNamedImport.js @@ -53,26 +53,26 @@ exports.z2 = 10; exports.aaaa = 10; //// [es6ImportNamedImport_1.js] "use strict"; -var es6ImportNamedImport_0_1 = require("./es6ImportNamedImport_0"); +const es6ImportNamedImport_0_1 = require("./es6ImportNamedImport_0"); var xxxx = es6ImportNamedImport_0_1.a; -var es6ImportNamedImport_0_2 = require("./es6ImportNamedImport_0"); +const es6ImportNamedImport_0_2 = require("./es6ImportNamedImport_0"); var xxxx = es6ImportNamedImport_0_2.a; -var es6ImportNamedImport_0_3 = require("./es6ImportNamedImport_0"); +const es6ImportNamedImport_0_3 = require("./es6ImportNamedImport_0"); var xxxx = es6ImportNamedImport_0_3.x; var xxxx = es6ImportNamedImport_0_3.a; -var es6ImportNamedImport_0_4 = require("./es6ImportNamedImport_0"); +const es6ImportNamedImport_0_4 = require("./es6ImportNamedImport_0"); var xxxx = es6ImportNamedImport_0_4.x; -var es6ImportNamedImport_0_5 = require("./es6ImportNamedImport_0"); +const es6ImportNamedImport_0_5 = require("./es6ImportNamedImport_0"); var xxxx = es6ImportNamedImport_0_5.m; -var es6ImportNamedImport_0_6 = require("./es6ImportNamedImport_0"); +const es6ImportNamedImport_0_6 = require("./es6ImportNamedImport_0"); var xxxx = es6ImportNamedImport_0_6.a1; var xxxx = es6ImportNamedImport_0_6.x1; -var es6ImportNamedImport_0_7 = require("./es6ImportNamedImport_0"); +const es6ImportNamedImport_0_7 = require("./es6ImportNamedImport_0"); var xxxx = es6ImportNamedImport_0_7.a1; var xxxx = es6ImportNamedImport_0_7.x1; -var es6ImportNamedImport_0_8 = require("./es6ImportNamedImport_0"); +const es6ImportNamedImport_0_8 = require("./es6ImportNamedImport_0"); var z111 = es6ImportNamedImport_0_8.z1; -var es6ImportNamedImport_0_9 = require("./es6ImportNamedImport_0"); +const es6ImportNamedImport_0_9 = require("./es6ImportNamedImport_0"); var z2 = es6ImportNamedImport_0_9.z2; // z2 shouldn't give redeclare error diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js index b67f61e88aece..38766d32cd900 100644 --- a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js @@ -13,7 +13,7 @@ export = a; exports.a = 10; //// [es6ImportNamedImportInExportAssignment_1.js] "use strict"; -var es6ImportNamedImportInExportAssignment_0_1 = require("./es6ImportNamedImportInExportAssignment_0"); +const es6ImportNamedImportInExportAssignment_0_1 = require("./es6ImportNamedImportInExportAssignment_0"); module.exports = es6ImportNamedImportInExportAssignment_0_1.a; diff --git a/tests/baselines/reference/exportDefaultInJsFile01.errors.txt b/tests/baselines/reference/exportDefaultInJsFile01.errors.txt new file mode 100644 index 0000000000000..34035e1e14e73 --- /dev/null +++ b/tests/baselines/reference/exportDefaultInJsFile01.errors.txt @@ -0,0 +1,7 @@ +error TS5055: Cannot write file 'tests/cases/conformance/salsa/myFile01.js' because it would overwrite input file. + + +!!! error TS5055: Cannot write file 'tests/cases/conformance/salsa/myFile01.js' because it would overwrite input file. +==== tests/cases/conformance/salsa/myFile01.js (0 errors) ==== + + export default "hello"; \ No newline at end of file diff --git a/tests/baselines/reference/exportDefaultInJsFile02.errors.txt b/tests/baselines/reference/exportDefaultInJsFile02.errors.txt new file mode 100644 index 0000000000000..5e17306e066f5 --- /dev/null +++ b/tests/baselines/reference/exportDefaultInJsFile02.errors.txt @@ -0,0 +1,7 @@ +error TS5055: Cannot write file 'tests/cases/conformance/salsa/myFile02.js' because it would overwrite input file. + + +!!! error TS5055: Cannot write file 'tests/cases/conformance/salsa/myFile02.js' because it would overwrite input file. +==== tests/cases/conformance/salsa/myFile02.js (0 errors) ==== + + export default "hello"; \ No newline at end of file diff --git a/tests/baselines/reference/exportNonInitializedVariablesSystem.js b/tests/baselines/reference/exportNonInitializedVariablesSystem.js index b5674bf5ce306..2a8e2022c9515 100644 --- a/tests/baselines/reference/exportNonInitializedVariablesSystem.js +++ b/tests/baselines/reference/exportNonInitializedVariablesSystem.js @@ -35,8 +35,9 @@ export let h1: D = new D; //// [exportNonInitializedVariablesSystem.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var a, b, c, d, A, e, f, B, C, a1, b1, c1, d1, D, e1, f1, g1, h1; return { setters:[], diff --git a/tests/baselines/reference/exportStarForValues10.js b/tests/baselines/reference/exportStarForValues10.js index dca5dad9b7a2d..d37ca3304f3fb 100644 --- a/tests/baselines/reference/exportStarForValues10.js +++ b/tests/baselines/reference/exportStarForValues10.js @@ -13,8 +13,9 @@ export * from "file1"; var x = 1; //// [file0.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var v; return { setters:[], @@ -24,8 +25,9 @@ System.register([], function(exports_1) { } }); //// [file1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { @@ -33,8 +35,9 @@ System.register([], function(exports_1) { } }); //// [file2.js] -System.register(["file0"], function(exports_1) { +System.register(["file0"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x; function exportStar_1(m) { var exports = {}; diff --git a/tests/baselines/reference/exportStarForValues6.js b/tests/baselines/reference/exportStarForValues6.js index 69357d87ee00b..8c31f6b4d16d2 100644 --- a/tests/baselines/reference/exportStarForValues6.js +++ b/tests/baselines/reference/exportStarForValues6.js @@ -9,8 +9,9 @@ export * from "file1" export var x = 1; //// [file1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { @@ -18,8 +19,9 @@ System.register([], function(exports_1) { } }); //// [file2.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x; return { setters:[], diff --git a/tests/baselines/reference/exportStarForValuesInSystem.js b/tests/baselines/reference/exportStarForValuesInSystem.js index a33465f7e2ee5..49c6877377aae 100644 --- a/tests/baselines/reference/exportStarForValuesInSystem.js +++ b/tests/baselines/reference/exportStarForValuesInSystem.js @@ -9,8 +9,9 @@ export * from "file1" var x = 1; //// [file1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { @@ -18,8 +19,9 @@ System.register([], function(exports_1) { } }); //// [file2.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x; return { setters:[], diff --git a/tests/baselines/reference/exportsAndImports1-es6.js b/tests/baselines/reference/exportsAndImports1-es6.js index ece98a80318c8..3ac5aeb0dc5e9 100644 --- a/tests/baselines/reference/exportsAndImports1-es6.js +++ b/tests/baselines/reference/exportsAndImports1-es6.js @@ -67,7 +67,7 @@ exports.M = t1_1.M; exports.a = t1_1.a; //// [t3.js] "use strict"; -var t1_1 = require("./t1"); +const t1_1 = require("./t1"); exports.v = t1_1.v; exports.f = t1_1.f; exports.C = t1_1.C; diff --git a/tests/baselines/reference/exportsAndImports2-es6.js b/tests/baselines/reference/exportsAndImports2-es6.js index 865534b285137..56639bdbecf2e 100644 --- a/tests/baselines/reference/exportsAndImports2-es6.js +++ b/tests/baselines/reference/exportsAndImports2-es6.js @@ -24,6 +24,6 @@ exports.y = t1_1.x; exports.x = t1_1.y; //// [t3.js] "use strict"; -var t1_1 = require("./t1"); +const t1_1 = require("./t1"); exports.y = t1_1.x; exports.x = t1_1.y; diff --git a/tests/baselines/reference/exportsAndImports3-es6.js b/tests/baselines/reference/exportsAndImports3-es6.js index ed509d31437b6..ea16836b1f202 100644 --- a/tests/baselines/reference/exportsAndImports3-es6.js +++ b/tests/baselines/reference/exportsAndImports3-es6.js @@ -69,7 +69,7 @@ exports.M = t1_1.M1; exports.a = t1_1.a1; //// [t3.js] "use strict"; -var t1_1 = require("./t1"); +const t1_1 = require("./t1"); exports.v = t1_1.v1; exports.f = t1_1.f1; exports.C = t1_1.C1; diff --git a/tests/baselines/reference/exportsAndImports4-es6.js b/tests/baselines/reference/exportsAndImports4-es6.js index 39c6583e9359f..8a8d4f812254e 100644 --- a/tests/baselines/reference/exportsAndImports4-es6.js +++ b/tests/baselines/reference/exportsAndImports4-es6.js @@ -45,24 +45,24 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = "hello"; //// [t3.js] "use strict"; -var a = require("./t1"); +const a = require("./t1"); exports.a = a; a.default; -var t1_1 = require("./t1"); +const t1_1 = require("./t1"); exports.b = t1_1.default; t1_1.default; -var c = require("./t1"); +const c = require("./t1"); exports.c = c; c.default; -var t1_2 = require("./t1"); +const t1_2 = require("./t1"); exports.d = t1_2.default; t1_2.default; -var t1_3 = require("./t1"), e2 = t1_3; +const t1_3 = require("./t1"), e2 = t1_3; exports.e1 = t1_3.default; exports.e2 = e2; t1_3.default; e2.default; -var t1_4 = require("./t1"); +const t1_4 = require("./t1"); exports.f1 = t1_4.default; exports.f2 = t1_4.default; t1_4.default; diff --git a/tests/baselines/reference/exportsAndImportsWithUnderscores1.errors.txt b/tests/baselines/reference/exportsAndImportsWithUnderscores1.errors.txt new file mode 100644 index 0000000000000..7a65dd62c2bdb --- /dev/null +++ b/tests/baselines/reference/exportsAndImportsWithUnderscores1.errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/es6/modules/m1.ts(6,5): error TS1005: ',' expected. + + +==== tests/cases/conformance/es6/modules/m1.ts (1 errors) ==== + + var R: any + export default R = { + "__": 20, + "_": 10 + "___": 30 + ~~~~~ +!!! error TS1005: ',' expected. + } + +==== tests/cases/conformance/es6/modules/m2.ts (0 errors) ==== + import R from "./m1"; + const { __, _, ___ } = R; + \ No newline at end of file diff --git a/tests/baselines/reference/exportsAndImportsWithUnderscores1.js b/tests/baselines/reference/exportsAndImportsWithUnderscores1.js new file mode 100644 index 0000000000000..d14eab3c25136 --- /dev/null +++ b/tests/baselines/reference/exportsAndImportsWithUnderscores1.js @@ -0,0 +1,29 @@ +//// [tests/cases/conformance/es6/modules/exportsAndImportsWithUnderscores1.ts] //// + +//// [m1.ts] + +var R: any +export default R = { + "__": 20, + "_": 10 + "___": 30 +} + +//// [m2.ts] +import R from "./m1"; +const { __, _, ___ } = R; + + +//// [m1.js] +"use strict"; +var R; +exports.__esModule = true; +exports["default"] = R = { + "__": 20, + "_": 10, + "___": 30 +}; +//// [m2.js] +"use strict"; +var m1_1 = require("./m1"); +var __ = m1_1["default"].__, _ = m1_1["default"]._, ___ = m1_1["default"].___; diff --git a/tests/baselines/reference/exportsAndImportsWithUnderscores2.js b/tests/baselines/reference/exportsAndImportsWithUnderscores2.js new file mode 100644 index 0000000000000..5d1dcbb93226d --- /dev/null +++ b/tests/baselines/reference/exportsAndImportsWithUnderscores2.js @@ -0,0 +1,27 @@ +//// [tests/cases/conformance/es6/modules/exportsAndImportsWithUnderscores2.ts] //// + +//// [m1.ts] + +var R: any +export default R = { + "__esmodule": true, + "__proto__": {} +} + +//// [m2.ts] +import R from "./m1"; +const { __esmodule, __proto__ } = R; + + +//// [m1.js] +"use strict"; +var R; +exports.__esModule = true; +exports["default"] = R = { + "__esmodule": true, + "__proto__": {} +}; +//// [m2.js] +"use strict"; +var m1_1 = require("./m1"); +var __esmodule = m1_1["default"].__esmodule, __proto__ = m1_1["default"].__proto__; diff --git a/tests/baselines/reference/exportsAndImportsWithUnderscores2.symbols b/tests/baselines/reference/exportsAndImportsWithUnderscores2.symbols new file mode 100644 index 0000000000000..d5f5ef17a62c2 --- /dev/null +++ b/tests/baselines/reference/exportsAndImportsWithUnderscores2.symbols @@ -0,0 +1,21 @@ +=== tests/cases/conformance/es6/modules/m1.ts === + +var R: any +>R : Symbol(R, Decl(m1.ts, 1, 3)) + +export default R = { +>R : Symbol(R, Decl(m1.ts, 1, 3)) + + "__esmodule": true, + "__proto__": {} +} + +=== tests/cases/conformance/es6/modules/m2.ts === +import R from "./m1"; +>R : Symbol(R, Decl(m2.ts, 0, 6)) + +const { __esmodule, __proto__ } = R; +>__esmodule : Symbol(__esmodule, Decl(m2.ts, 1, 7)) +>__proto__ : Symbol(__proto__, Decl(m2.ts, 1, 19)) +>R : Symbol(R, Decl(m2.ts, 0, 6)) + diff --git a/tests/baselines/reference/exportsAndImportsWithUnderscores2.types b/tests/baselines/reference/exportsAndImportsWithUnderscores2.types new file mode 100644 index 0000000000000..a684440f5bdf7 --- /dev/null +++ b/tests/baselines/reference/exportsAndImportsWithUnderscores2.types @@ -0,0 +1,26 @@ +=== tests/cases/conformance/es6/modules/m1.ts === + +var R: any +>R : any + +export default R = { +>R = { "__esmodule": true, "__proto__": {}} : { "__esmodule": boolean; "__proto__": {}; } +>R : any +>{ "__esmodule": true, "__proto__": {}} : { "__esmodule": boolean; "__proto__": {}; } + + "__esmodule": true, +>true : boolean + + "__proto__": {} +>{} : {} +} + +=== tests/cases/conformance/es6/modules/m2.ts === +import R from "./m1"; +>R : { "__esmodule": boolean; "__proto__": {}; } + +const { __esmodule, __proto__ } = R; +>__esmodule : boolean +>__proto__ : {} +>R : { "__esmodule": boolean; "__proto__": {}; } + diff --git a/tests/baselines/reference/exportsAndImportsWithUnderscores3.js b/tests/baselines/reference/exportsAndImportsWithUnderscores3.js new file mode 100644 index 0000000000000..477f870742daa --- /dev/null +++ b/tests/baselines/reference/exportsAndImportsWithUnderscores3.js @@ -0,0 +1,29 @@ +//// [tests/cases/conformance/es6/modules/exportsAndImportsWithUnderscores3.ts] //// + +//// [m1.ts] + +var R: any +export default R = { + "___": 30, + "___hello": 21, + "_hi": 40, +} + +//// [m2.ts] +import R from "./m1"; +const { ___, ___hello, _hi } = R; + + +//// [m1.js] +"use strict"; +var R; +exports.__esModule = true; +exports["default"] = R = { + "___": 30, + "___hello": 21, + "_hi": 40 +}; +//// [m2.js] +"use strict"; +var m1_1 = require("./m1"); +var ___ = m1_1["default"].___, ___hello = m1_1["default"].___hello, _hi = m1_1["default"]._hi; diff --git a/tests/baselines/reference/exportsAndImportsWithUnderscores3.symbols b/tests/baselines/reference/exportsAndImportsWithUnderscores3.symbols new file mode 100644 index 0000000000000..cd4ba38e8c9db --- /dev/null +++ b/tests/baselines/reference/exportsAndImportsWithUnderscores3.symbols @@ -0,0 +1,23 @@ +=== tests/cases/conformance/es6/modules/m1.ts === + +var R: any +>R : Symbol(R, Decl(m1.ts, 1, 3)) + +export default R = { +>R : Symbol(R, Decl(m1.ts, 1, 3)) + + "___": 30, + "___hello": 21, + "_hi": 40, +} + +=== tests/cases/conformance/es6/modules/m2.ts === +import R from "./m1"; +>R : Symbol(R, Decl(m2.ts, 0, 6)) + +const { ___, ___hello, _hi } = R; +>___ : Symbol(___, Decl(m2.ts, 1, 7)) +>___hello : Symbol(___hello, Decl(m2.ts, 1, 12)) +>_hi : Symbol(_hi, Decl(m2.ts, 1, 22)) +>R : Symbol(R, Decl(m2.ts, 0, 6)) + diff --git a/tests/baselines/reference/exportsAndImportsWithUnderscores3.types b/tests/baselines/reference/exportsAndImportsWithUnderscores3.types new file mode 100644 index 0000000000000..5addb44172d2f --- /dev/null +++ b/tests/baselines/reference/exportsAndImportsWithUnderscores3.types @@ -0,0 +1,30 @@ +=== tests/cases/conformance/es6/modules/m1.ts === + +var R: any +>R : any + +export default R = { +>R = { "___": 30, "___hello": 21, "_hi": 40,} : { "___": number; "___hello": number; "_hi": number; } +>R : any +>{ "___": 30, "___hello": 21, "_hi": 40,} : { "___": number; "___hello": number; "_hi": number; } + + "___": 30, +>30 : number + + "___hello": 21, +>21 : number + + "_hi": 40, +>40 : number +} + +=== tests/cases/conformance/es6/modules/m2.ts === +import R from "./m1"; +>R : { "___": number; "___hello": number; "_hi": number; } + +const { ___, ___hello, _hi } = R; +>___ : number +>___hello : number +>_hi : number +>R : { "___": number; "___hello": number; "_hi": number; } + diff --git a/tests/baselines/reference/exportsAndImportsWithUnderscores4.js b/tests/baselines/reference/exportsAndImportsWithUnderscores4.js new file mode 100644 index 0000000000000..22cd7c2e71a79 --- /dev/null +++ b/tests/baselines/reference/exportsAndImportsWithUnderscores4.js @@ -0,0 +1,75 @@ +//// [tests/cases/conformance/es6/modules/exportsAndImportsWithUnderscores4.ts] //// + +//// [m1.ts] + +declare var console: any; +export function _() { + console.log("_"); +} +export function __() { + console.log("__"); +} +export function ___() { + console.log("___"); +} +export function _hi() { + console.log("_hi"); +} +export function __proto() { + console.log("__proto"); +} +export function __esmodule() { + console.log("__esmodule"); +} +export function ___hello(){ + console.log("___hello"); +} + +//// [m2.ts] +import {_, __, ___hello, __esmodule, __proto, _hi} from "./m1"; +_(); +__(); +___hello(); +__esmodule(); +__proto(); +_hi(); + +//// [m1.js] +"use strict"; +function _() { + console.log("_"); +} +exports._ = _; +function __() { + console.log("__"); +} +exports.__ = __; +function ___() { + console.log("___"); +} +exports.___ = ___; +function _hi() { + console.log("_hi"); +} +exports._hi = _hi; +function __proto() { + console.log("__proto"); +} +exports.__proto = __proto; +function __esmodule() { + console.log("__esmodule"); +} +exports.__esmodule = __esmodule; +function ___hello() { + console.log("___hello"); +} +exports.___hello = ___hello; +//// [m2.js] +"use strict"; +var m1_1 = require("./m1"); +m1_1._(); +m1_1.__(); +m1_1.___hello(); +m1_1.__esmodule(); +m1_1.__proto(); +m1_1._hi(); diff --git a/tests/baselines/reference/exportsAndImportsWithUnderscores4.symbols b/tests/baselines/reference/exportsAndImportsWithUnderscores4.symbols new file mode 100644 index 0000000000000..a8fb3f307b5bf --- /dev/null +++ b/tests/baselines/reference/exportsAndImportsWithUnderscores4.symbols @@ -0,0 +1,75 @@ +=== tests/cases/conformance/es6/modules/m1.ts === + +declare var console: any; +>console : Symbol(console, Decl(m1.ts, 1, 11)) + +export function _() { +>_ : Symbol(_, Decl(m1.ts, 1, 25)) + + console.log("_"); +>console : Symbol(console, Decl(m1.ts, 1, 11)) +} +export function __() { +>__ : Symbol(__, Decl(m1.ts, 4, 1)) + + console.log("__"); +>console : Symbol(console, Decl(m1.ts, 1, 11)) +} +export function ___() { +>___ : Symbol(___, Decl(m1.ts, 7, 1)) + + console.log("___"); +>console : Symbol(console, Decl(m1.ts, 1, 11)) +} +export function _hi() { +>_hi : Symbol(_hi, Decl(m1.ts, 10, 1)) + + console.log("_hi"); +>console : Symbol(console, Decl(m1.ts, 1, 11)) +} +export function __proto() { +>__proto : Symbol(__proto, Decl(m1.ts, 13, 1)) + + console.log("__proto"); +>console : Symbol(console, Decl(m1.ts, 1, 11)) +} +export function __esmodule() { +>__esmodule : Symbol(__esmodule, Decl(m1.ts, 16, 1)) + + console.log("__esmodule"); +>console : Symbol(console, Decl(m1.ts, 1, 11)) +} +export function ___hello(){ +>___hello : Symbol(___hello, Decl(m1.ts, 19, 1)) + + console.log("___hello"); +>console : Symbol(console, Decl(m1.ts, 1, 11)) +} + +=== tests/cases/conformance/es6/modules/m2.ts === +import {_, __, ___hello, __esmodule, __proto, _hi} from "./m1"; +>_ : Symbol(_, Decl(m2.ts, 0, 8)) +>__ : Symbol(__, Decl(m2.ts, 0, 10)) +>___hello : Symbol(___hello, Decl(m2.ts, 0, 14)) +>__esmodule : Symbol(__esmodule, Decl(m2.ts, 0, 24)) +>__proto : Symbol(__proto, Decl(m2.ts, 0, 36)) +>_hi : Symbol(_hi, Decl(m2.ts, 0, 45)) + +_(); +>_ : Symbol(_, Decl(m2.ts, 0, 8)) + +__(); +>__ : Symbol(__, Decl(m2.ts, 0, 10)) + +___hello(); +>___hello : Symbol(___hello, Decl(m2.ts, 0, 14)) + +__esmodule(); +>__esmodule : Symbol(__esmodule, Decl(m2.ts, 0, 24)) + +__proto(); +>__proto : Symbol(__proto, Decl(m2.ts, 0, 36)) + +_hi(); +>_hi : Symbol(_hi, Decl(m2.ts, 0, 45)) + diff --git a/tests/baselines/reference/exportsAndImportsWithUnderscores4.types b/tests/baselines/reference/exportsAndImportsWithUnderscores4.types new file mode 100644 index 0000000000000..a90420422855d --- /dev/null +++ b/tests/baselines/reference/exportsAndImportsWithUnderscores4.types @@ -0,0 +1,109 @@ +=== tests/cases/conformance/es6/modules/m1.ts === + +declare var console: any; +>console : any + +export function _() { +>_ : () => void + + console.log("_"); +>console.log("_") : any +>console.log : any +>console : any +>log : any +>"_" : string +} +export function __() { +>__ : () => void + + console.log("__"); +>console.log("__") : any +>console.log : any +>console : any +>log : any +>"__" : string +} +export function ___() { +>___ : () => void + + console.log("___"); +>console.log("___") : any +>console.log : any +>console : any +>log : any +>"___" : string +} +export function _hi() { +>_hi : () => void + + console.log("_hi"); +>console.log("_hi") : any +>console.log : any +>console : any +>log : any +>"_hi" : string +} +export function __proto() { +>__proto : () => void + + console.log("__proto"); +>console.log("__proto") : any +>console.log : any +>console : any +>log : any +>"__proto" : string +} +export function __esmodule() { +>__esmodule : () => void + + console.log("__esmodule"); +>console.log("__esmodule") : any +>console.log : any +>console : any +>log : any +>"__esmodule" : string +} +export function ___hello(){ +>___hello : () => void + + console.log("___hello"); +>console.log("___hello") : any +>console.log : any +>console : any +>log : any +>"___hello" : string +} + +=== tests/cases/conformance/es6/modules/m2.ts === +import {_, __, ___hello, __esmodule, __proto, _hi} from "./m1"; +>_ : () => void +>__ : () => void +>___hello : () => void +>__esmodule : () => void +>__proto : () => void +>_hi : () => void + +_(); +>_() : void +>_ : () => void + +__(); +>__() : void +>__ : () => void + +___hello(); +>___hello() : void +>___hello : () => void + +__esmodule(); +>__esmodule() : void +>__esmodule : () => void + +__proto(); +>__proto() : void +>__proto : () => void + +_hi(); +>_hi() : void +>_hi : () => void + diff --git a/tests/baselines/reference/externalModuleImmutableBindings.errors.txt b/tests/baselines/reference/externalModuleImmutableBindings.errors.txt index a6040c154f097..c8c61b2dc816b 100644 --- a/tests/baselines/reference/externalModuleImmutableBindings.errors.txt +++ b/tests/baselines/reference/externalModuleImmutableBindings.errors.txt @@ -1,11 +1,23 @@ +tests/cases/compiler/f2.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/f2.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. tests/cases/compiler/f2.ts(9,7): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. +tests/cases/compiler/f2.ts(12,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/f2.ts(13,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/f2.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/f2.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. tests/cases/compiler/f2.ts(19,8): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. +tests/cases/compiler/f2.ts(22,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/compiler/f2.ts(23,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. tests/cases/compiler/f2.ts(27,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. +tests/cases/compiler/f2.ts(28,6): error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. tests/cases/compiler/f2.ts(29,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. +tests/cases/compiler/f2.ts(30,6): error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. tests/cases/compiler/f2.ts(31,12): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. tests/cases/compiler/f2.ts(32,12): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. tests/cases/compiler/f2.ts(36,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. +tests/cases/compiler/f2.ts(37,6): error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. tests/cases/compiler/f2.ts(38,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. +tests/cases/compiler/f2.ts(39,6): error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. tests/cases/compiler/f2.ts(40,13): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. tests/cases/compiler/f2.ts(41,13): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. @@ -13,7 +25,7 @@ tests/cases/compiler/f2.ts(41,13): error TS2339: Property 'blah' does not exist ==== tests/cases/compiler/f1.ts (0 errors) ==== export var x = 1; -==== tests/cases/compiler/f2.ts (10 errors) ==== +==== tests/cases/compiler/f2.ts (22 errors) ==== // all mutations below are illegal and should be fixed import * as stuff from './f1'; @@ -21,26 +33,42 @@ tests/cases/compiler/f2.ts(41,13): error TS2339: Property 'blah' does not exist var n = 'baz'; stuff.x = 0; + ~~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. stuff['x'] = 1; + ~~~~~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. stuff.blah = 2; ~~~~ !!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. stuff[n] = 3; stuff.x++; + ~~~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. stuff['x']++; + ~~~~~~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. stuff['blah']++; stuff[n]++; (stuff.x) = 0; + ~~~~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. (stuff['x']) = 1; + ~~~~~~~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. (stuff.blah) = 2; ~~~~ !!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. (stuff[n]) = 3; (stuff.x)++; + ~~~~~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. (stuff['x'])++; + ~~~~~~~~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. (stuff['blah'])++; (stuff[n])++; @@ -48,10 +76,14 @@ tests/cases/compiler/f2.ts(41,13): error TS2339: Property 'blah' does not exist ~~~~~~~ !!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. for (stuff.x of []) {} + ~~~~~~~ +!!! error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. for (stuff['x'] in []) {} ~~~~~~~~~~ !!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. for (stuff['x'] of []) {} + ~~~~~~~~~~ +!!! error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. for (stuff.blah in []) {} ~~~~ !!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. @@ -65,10 +97,14 @@ tests/cases/compiler/f2.ts(41,13): error TS2339: Property 'blah' does not exist ~~~~~~~~~ !!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. for ((stuff.x) of []) {} + ~~~~~~~~~ +!!! error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. for ((stuff['x']) in []) {} ~~~~~~~~~~~~ !!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. for ((stuff['x']) of []) {} + ~~~~~~~~~~~~ +!!! error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. for ((stuff.blah) in []) {} ~~~~ !!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. diff --git a/tests/baselines/reference/for-of2.errors.txt b/tests/baselines/reference/for-of2.errors.txt index 0b5133cde13ee..f4f39f60f670b 100644 --- a/tests/baselines/reference/for-of2.errors.txt +++ b/tests/baselines/reference/for-of2.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/for-ofStatements/for-of2.ts(1,7): error TS1155: 'const' declarations must be initialized -tests/cases/conformance/es6/for-ofStatements/for-of2.ts(2,6): error TS2485: The left-hand side of a 'for...of' statement cannot be a previously defined constant. +tests/cases/conformance/es6/for-ofStatements/for-of2.ts(2,6): error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. ==== tests/cases/conformance/es6/for-ofStatements/for-of2.ts (2 errors) ==== @@ -8,4 +8,4 @@ tests/cases/conformance/es6/for-ofStatements/for-of2.ts(2,6): error TS2485: The !!! error TS1155: 'const' declarations must be initialized for (v of []) { } ~ -!!! error TS2485: The left-hand side of a 'for...of' statement cannot be a previously defined constant. \ No newline at end of file +!!! error TS2485: The left-hand side of a 'for...of' statement cannot be a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/functionsMissingReturnStatementsAndExpressions.errors.txt b/tests/baselines/reference/functionsMissingReturnStatementsAndExpressions.errors.txt index 58ffd051d4d6b..1ccc296b75b8f 100644 --- a/tests/baselines/reference/functionsMissingReturnStatementsAndExpressions.errors.txt +++ b/tests/baselines/reference/functionsMissingReturnStatementsAndExpressions.errors.txt @@ -1,9 +1,10 @@ tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(3,16): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value. -tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(95,16): error TS2378: A 'get' accessor must return a value. -tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(118,5): error TS1003: Identifier expected. +tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(101,17): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value. +tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(106,16): error TS2378: A 'get' accessor must return a value. +tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(129,5): error TS1003: Identifier expected. -==== tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts (3 errors) ==== +==== tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts (4 errors) ==== function f1(): string { @@ -98,6 +99,19 @@ tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts(118,5): e return "Okay, not type annotated."; } + function f19(): void | number { + // Okay; function return type is union containing void + } + + function f20(): any | number { + // Okay; function return type is union containing any + } + + function f21(): number | string { + ~~~~~~~~~~~~~~~ +!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value. + // Not okay; union does not contain void or any + } class C { public get m1() { diff --git a/tests/baselines/reference/functionsMissingReturnStatementsAndExpressions.js b/tests/baselines/reference/functionsMissingReturnStatementsAndExpressions.js index 4dfe851683ac9..17468722e207d 100644 --- a/tests/baselines/reference/functionsMissingReturnStatementsAndExpressions.js +++ b/tests/baselines/reference/functionsMissingReturnStatementsAndExpressions.js @@ -91,6 +91,17 @@ function f18() { return "Okay, not type annotated."; } +function f19(): void | number { + // Okay; function return type is union containing void +} + +function f20(): any | number { + // Okay; function return type is union containing any +} + +function f21(): number | string { + // Not okay; union does not contain void or any +} class C { public get m1() { @@ -191,6 +202,15 @@ function f17() { function f18() { return "Okay, not type annotated."; } +function f19() { + // Okay; function return type is union containing void +} +function f20() { + // Okay; function return type is union containing any +} +function f21() { + // Not okay; union does not contain void or any +} var C = (function () { function C() { } diff --git a/tests/baselines/reference/generatorTypeCheck39.js b/tests/baselines/reference/generatorTypeCheck39.js index 43df3b8e205d8..1e0009d24ed7c 100644 --- a/tests/baselines/reference/generatorTypeCheck39.js +++ b/tests/baselines/reference/generatorTypeCheck39.js @@ -20,7 +20,7 @@ function decorator(x) { return y => { }; } function* g() { - let C = class { + let C = class C { constructor() { this.x = yield 0; } diff --git a/tests/baselines/reference/generatorTypeCheck61.js b/tests/baselines/reference/generatorTypeCheck61.js index b2434ee590c58..9cc157f26840d 100644 --- a/tests/baselines/reference/generatorTypeCheck61.js +++ b/tests/baselines/reference/generatorTypeCheck61.js @@ -12,7 +12,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, return c > 3 && r && Object.defineProperty(target, key, r), r; }; function* g() { - let C = class { + let C = class C { }; C = __decorate([ (yield 0) diff --git a/tests/baselines/reference/giant.js b/tests/baselines/reference/giant.js index 2a04541ef2818..149a975d413a2 100644 --- a/tests/baselines/reference/giant.js +++ b/tests/baselines/reference/giant.js @@ -1120,11 +1120,11 @@ export declare class eC { pF(): void; private rF(); pgF(): void; - pgF: any; + readonly pgF: any; psF(param: any): void; psF: any; private rgF(); - private rgF; + private readonly rgF; private rsF(param); private rsF; static tV: any; @@ -1132,7 +1132,7 @@ export declare class eC { static tsF(param: any): void; static tsF: any; static tgF(): void; - static tgF: any; + static readonly tgF: any; } export interface eI { (): any; @@ -1172,11 +1172,11 @@ export declare module eM { pF(): void; private rF(); pgF(): void; - pgF: any; + readonly pgF: any; psF(param: any): void; psF: any; private rgF(); - private rgF; + private readonly rgF; private rsF(param); private rsF; static tV: any; @@ -1184,7 +1184,7 @@ export declare module eM { static tsF(param: any): void; static tsF: any; static tgF(): void; - static tgF: any; + static readonly tgF: any; } interface eI { (): any; @@ -1239,11 +1239,11 @@ export declare module eM { pF(): void; private rF(); pgF(): void; - pgF: any; + readonly pgF: any; psF(param: any): void; psF: any; private rgF(); - private rgF; + private readonly rgF; private rsF(param); private rsF; static tV: any; @@ -1251,7 +1251,7 @@ export declare module eM { static tsF(param: any): void; static tsF: any; static tgF(): void; - static tgF: any; + static readonly tgF: any; } module eaM { var V: any; @@ -1281,11 +1281,11 @@ export declare class eaC { pF(): void; private rF(); pgF(): void; - pgF: any; + readonly pgF: any; psF(param: any): void; psF: any; private rgF(); - private rgF; + private readonly rgF; private rsF(param); private rsF; static tV: any; @@ -1293,7 +1293,7 @@ export declare class eaC { static tsF(param: any): void; static tsF: any; static tgF(): void; - static tgF: any; + static readonly tgF: any; } export declare module eaM { var V: any; diff --git a/tests/baselines/reference/importsImplicitlyReadonly.errors.txt b/tests/baselines/reference/importsImplicitlyReadonly.errors.txt new file mode 100644 index 0000000000000..cc6e1918020e5 --- /dev/null +++ b/tests/baselines/reference/importsImplicitlyReadonly.errors.txt @@ -0,0 +1,34 @@ +tests/cases/conformance/externalModules/b.ts(6,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/externalModules/b.ts(7,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/externalModules/b.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/conformance/externalModules/b.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + + +==== tests/cases/conformance/externalModules/b.ts (4 errors) ==== + import { x, y } from "./a"; + import * as a1 from "./a"; + import a2 = require("./a"); + const a3 = a1; + + x = 1; // Error + ~ +!!! error TS2364: Invalid left-hand side of assignment expression. + y = 1; // Error + ~ +!!! error TS2364: Invalid left-hand side of assignment expression. + a1.x = 1; // Error + ~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + a1.y = 1; // Error + ~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + a2.x = 1; + a2.y = 1; + a3.x = 1; + a3.y = 1; +==== tests/cases/conformance/externalModules/a.ts (0 errors) ==== + + export var x = 1; + var y = 1; + export { y }; + \ No newline at end of file diff --git a/tests/baselines/reference/importsImplicitlyReadonly.js b/tests/baselines/reference/importsImplicitlyReadonly.js new file mode 100644 index 0000000000000..4630de598cc46 --- /dev/null +++ b/tests/baselines/reference/importsImplicitlyReadonly.js @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/externalModules/importsImplicitlyReadonly.ts] //// + +//// [a.ts] + +export var x = 1; +var y = 1; +export { y }; + +//// [b.ts] +import { x, y } from "./a"; +import * as a1 from "./a"; +import a2 = require("./a"); +const a3 = a1; + +x = 1; // Error +y = 1; // Error +a1.x = 1; // Error +a1.y = 1; // Error +a2.x = 1; +a2.y = 1; +a3.x = 1; +a3.y = 1; + +//// [a.js] +"use strict"; +exports.x = 1; +var y = 1; +exports.y = y; +//// [b.js] +"use strict"; +var a_1 = require("./a"); +var a1 = require("./a"); +var a2 = require("./a"); +var a3 = a1; +a_1.x = 1; // Error +a_1.y = 1; // Error +a1.x = 1; // Error +a1.y = 1; // Error +a2.x = 1; +a2.y = 1; +a3.x = 1; +a3.y = 1; diff --git a/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt b/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt index 9bcf6c7612f66..fc8b682b59e86 100644 --- a/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt +++ b/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt @@ -1,21 +1,27 @@ -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(7,23): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. -tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(12,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(6,25): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(7,23): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(10,3): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(12,1): error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. -==== tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts (2 errors) ==== +==== tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts (4 errors) ==== // ++ operator on enum type enum ENUM1 { A, B, "" }; // expression var ResultIsNumber1 = ++ENUM1["B"]; + ~~~~~~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. var ResultIsNumber2 = ENUM1.B++; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. // miss assignment operator ++ENUM1["B"]; + ~~~~~~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. ENUM1.B++; ~~~~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. \ No newline at end of file +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/interfaceWithAccessibilityModifiers.errors.txt b/tests/baselines/reference/interfaceWithAccessibilityModifiers.errors.txt index ecf803d522bd6..1c6f8f1939dda 100644 --- a/tests/baselines/reference/interfaceWithAccessibilityModifiers.errors.txt +++ b/tests/baselines/reference/interfaceWithAccessibilityModifiers.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessibilityModifiers.ts(3,5): error TS1131: Property or signature expected. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessibilityModifiers.ts(4,5): error TS1131: Property or signature expected. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessibilityModifiers.ts(5,5): error TS1131: Property or signature expected. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessibilityModifiers.ts(3,5): error TS1070: 'public' modifier cannot appear on a type member. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessibilityModifiers.ts(4,5): error TS1070: 'private' modifier cannot appear on a type member. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessibilityModifiers.ts(5,5): error TS1070: 'protected' modifier cannot appear on a type member. ==== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessibilityModifiers.ts (3 errors) ==== @@ -8,11 +8,11 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessibil interface Foo { public a: any; ~~~~~~ -!!! error TS1131: Property or signature expected. +!!! error TS1070: 'public' modifier cannot appear on a type member. private b: any; ~~~~~~~ -!!! error TS1131: Property or signature expected. +!!! error TS1070: 'private' modifier cannot appear on a type member. protected c: any; ~~~~~~~~~ -!!! error TS1131: Property or signature expected. +!!! error TS1070: 'protected' modifier cannot appear on a type member. } \ No newline at end of file diff --git a/tests/baselines/reference/interfaceWithPrivateMember.errors.txt b/tests/baselines/reference/interfaceWithPrivateMember.errors.txt index dc1cfeabed5e3..ecbd9ec293c29 100644 --- a/tests/baselines/reference/interfaceWithPrivateMember.errors.txt +++ b/tests/baselines/reference/interfaceWithPrivateMember.errors.txt @@ -1,32 +1,26 @@ -tests/cases/conformance/types/namedTypes/interfaceWithPrivateMember.ts(5,5): error TS1131: Property or signature expected. -tests/cases/conformance/types/namedTypes/interfaceWithPrivateMember.ts(9,5): error TS1131: Property or signature expected. -tests/cases/conformance/types/namedTypes/interfaceWithPrivateMember.ts(13,5): error TS1131: Property or signature expected. -tests/cases/conformance/types/namedTypes/interfaceWithPrivateMember.ts(13,16): error TS2304: Cannot find name 'string'. -tests/cases/conformance/types/namedTypes/interfaceWithPrivateMember.ts(14,1): error TS1128: Declaration or statement expected. +tests/cases/conformance/types/namedTypes/interfaceWithPrivateMember.ts(5,5): error TS1070: 'private' modifier cannot appear on a type member. +tests/cases/conformance/types/namedTypes/interfaceWithPrivateMember.ts(9,5): error TS1070: 'private' modifier cannot appear on a type member. +tests/cases/conformance/types/namedTypes/interfaceWithPrivateMember.ts(13,5): error TS1070: 'private' modifier cannot appear on a type member. -==== tests/cases/conformance/types/namedTypes/interfaceWithPrivateMember.ts (5 errors) ==== +==== tests/cases/conformance/types/namedTypes/interfaceWithPrivateMember.ts (3 errors) ==== // interfaces do not permit private members, these are errors interface I { private x: string; ~~~~~~~ -!!! error TS1131: Property or signature expected. +!!! error TS1070: 'private' modifier cannot appear on a type member. } interface I2 { private y: T; ~~~~~~~ -!!! error TS1131: Property or signature expected. +!!! error TS1070: 'private' modifier cannot appear on a type member. } var x: { private y: string; ~~~~~~~ -!!! error TS1131: Property or signature expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'string'. - } - ~ -!!! error TS1128: Declaration or statement expected. \ No newline at end of file +!!! error TS1070: 'private' modifier cannot appear on a type member. + } \ No newline at end of file diff --git a/tests/baselines/reference/interfaceWithPrivateMember.js b/tests/baselines/reference/interfaceWithPrivateMember.js index ceb388b1eae26..d59037cf058cc 100644 --- a/tests/baselines/reference/interfaceWithPrivateMember.js +++ b/tests/baselines/reference/interfaceWithPrivateMember.js @@ -17,4 +17,3 @@ var x: { //// [interfaceWithPrivateMember.js] // interfaces do not permit private members, these are errors var x; -y: string; diff --git a/tests/baselines/reference/invalidUndefinedAssignments.errors.txt b/tests/baselines/reference/invalidUndefinedAssignments.errors.txt index 4c32b1a6c8ed6..5eff2e7ff1afa 100644 --- a/tests/baselines/reference/invalidUndefinedAssignments.errors.txt +++ b/tests/baselines/reference/invalidUndefinedAssignments.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(4,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(5,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(9,1): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(14,1): error TS2304: Cannot find name 'I'. tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(17,1): error TS2364: Invalid left-hand side of assignment expression. @@ -15,7 +15,7 @@ tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.t !!! error TS2364: Invalid left-hand side of assignment expression. E.A = x; ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. class C { foo: string } var f: C; diff --git a/tests/baselines/reference/isDeclarationVisibleNodeKinds.js b/tests/baselines/reference/isDeclarationVisibleNodeKinds.js index 99e1ac72acd25..e24032eb858c4 100644 --- a/tests/baselines/reference/isDeclarationVisibleNodeKinds.js +++ b/tests/baselines/reference/isDeclarationVisibleNodeKinds.js @@ -193,7 +193,7 @@ declare module schema { } declare module schema { class T { - createValidator9: (data: T) => T; + readonly createValidator9: (data: T) => T; createValidator10: (data: T) => T; } } diff --git a/tests/baselines/reference/isolatedModulesPlainFile-System.js b/tests/baselines/reference/isolatedModulesPlainFile-System.js index b66bd49781026..39320759740d1 100644 --- a/tests/baselines/reference/isolatedModulesPlainFile-System.js +++ b/tests/baselines/reference/isolatedModulesPlainFile-System.js @@ -5,8 +5,9 @@ run(1); //// [isolatedModulesPlainFile-System.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { diff --git a/tests/baselines/reference/jsFileCompilationBindMultipleDefaultExports.errors.txt b/tests/baselines/reference/jsFileCompilationBindMultipleDefaultExports.errors.txt index 733f66922abfd..05fecf03d3069 100644 --- a/tests/baselines/reference/jsFileCompilationBindMultipleDefaultExports.errors.txt +++ b/tests/baselines/reference/jsFileCompilationBindMultipleDefaultExports.errors.txt @@ -1,10 +1,9 @@ tests/cases/compiler/a.js(1,22): error TS2528: A module cannot have multiple default exports. tests/cases/compiler/a.js(3,1): error TS2528: A module cannot have multiple default exports. -tests/cases/compiler/a.js(3,1): error TS8003: 'export=' can only be used in a .ts file. tests/cases/compiler/a.js(3,16): error TS1109: Expression expected. -==== tests/cases/compiler/a.js (4 errors) ==== +==== tests/cases/compiler/a.js (3 errors) ==== export default class a { ~ !!! error TS2528: A module cannot have multiple default exports. @@ -12,7 +11,5 @@ tests/cases/compiler/a.js(3,16): error TS1109: Expression expected. export default var a = 10; ~~~~~~~~~~~~~~ !!! error TS2528: A module cannot have multiple default exports. - ~~~~~~~~~~~~~~ -!!! error TS8003: 'export=' can only be used in a .ts file. ~~~ !!! error TS1109: Expression expected. \ No newline at end of file diff --git a/tests/baselines/reference/jsFileCompilationTypeAssertions.errors.txt b/tests/baselines/reference/jsFileCompilationTypeAssertions.errors.txt index e73ee46fb89c9..662eea4d4050c 100644 --- a/tests/baselines/reference/jsFileCompilationTypeAssertions.errors.txt +++ b/tests/baselines/reference/jsFileCompilationTypeAssertions.errors.txt @@ -1,9 +1,12 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file. -tests/cases/compiler/a.js(1,10): error TS8016: 'type assertion expressions' can only be used in a .ts file. +tests/cases/compiler/a.js(1,10): error TS17008: JSX element 'string' has no corresponding closing tag. +tests/cases/compiler/a.js(1,27): error TS1005: 'undefined; ~~~~~~ -!!! error TS8016: 'type assertion expressions' can only be used in a .ts file. \ No newline at end of file +!!! error TS17008: JSX element 'string' has no corresponding closing tag. + +!!! error TS1005: 'A : Symbol(A, Decl(a.ts, 0, 0), Decl(b.ts, 0, 0)) + + protected foo() {} +>foo : Symbol(foo, Decl(a.ts, 0, 9)) +} +=== tests/cases/compiler/b.ts === +interface A { } +>A : Symbol(A, Decl(a.ts, 0, 0), Decl(b.ts, 0, 0)) + +class B extends A { +>B : Symbol(B, Decl(b.ts, 0, 15)) +>A : Symbol(A, Decl(a.ts, 0, 0), Decl(b.ts, 0, 0)) + + protected foo() {} +>foo : Symbol(foo, Decl(b.ts, 2, 19)) +} diff --git a/tests/baselines/reference/mergedDeclarations5.types b/tests/baselines/reference/mergedDeclarations5.types new file mode 100644 index 0000000000000..5c31617a92bf8 --- /dev/null +++ b/tests/baselines/reference/mergedDeclarations5.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/a.ts === +class A { +>A : A + + protected foo() {} +>foo : () => void +} +=== tests/cases/compiler/b.ts === +interface A { } +>A : A + +class B extends A { +>B : B +>A : A + + protected foo() {} +>foo : () => void +} diff --git a/tests/baselines/reference/mergedDeclarations6.js b/tests/baselines/reference/mergedDeclarations6.js new file mode 100644 index 0000000000000..696ad27b2a6e1 --- /dev/null +++ b/tests/baselines/reference/mergedDeclarations6.js @@ -0,0 +1,57 @@ +//// [tests/cases/compiler/mergedDeclarations6.ts] //// + +//// [a.ts] + +export class A { + protected protected: any; + + protected setProtected(val: any) { + this.protected = val; + } +} + +//// [b.ts] +import {A} from './a'; + +declare module "./a" { + interface A { } +} + +export class B extends A { + protected setProtected() { + + } +} + +//// [a.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + var A = (function () { + function A() { + } + A.prototype.setProtected = function (val) { + this.protected = val; + }; + return A; + }()); + exports.A = A; +}); +//// [b.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 __()); +}; +define(["require", "exports", './a'], function (require, exports, a_1) { + "use strict"; + var B = (function (_super) { + __extends(B, _super); + function B() { + _super.apply(this, arguments); + } + B.prototype.setProtected = function () { + }; + return B; + }(a_1.A)); + exports.B = B; +}); diff --git a/tests/baselines/reference/mergedDeclarations6.symbols b/tests/baselines/reference/mergedDeclarations6.symbols new file mode 100644 index 0000000000000..b0d49532384ee --- /dev/null +++ b/tests/baselines/reference/mergedDeclarations6.symbols @@ -0,0 +1,38 @@ +=== tests/cases/compiler/a.ts === + +export class A { +>A : Symbol(A, Decl(a.ts, 0, 0), Decl(b.ts, 2, 22)) + + protected protected: any; +>protected : Symbol(protected, Decl(a.ts, 1, 16)) + + protected setProtected(val: any) { +>setProtected : Symbol(setProtected, Decl(a.ts, 2, 29)) +>val : Symbol(val, Decl(a.ts, 4, 27)) + + this.protected = val; +>this.protected : Symbol(protected, Decl(a.ts, 1, 16)) +>this : Symbol(A, Decl(a.ts, 0, 0), Decl(b.ts, 2, 22)) +>protected : Symbol(protected, Decl(a.ts, 1, 16)) +>val : Symbol(val, Decl(a.ts, 4, 27)) + } +} + +=== tests/cases/compiler/b.ts === +import {A} from './a'; +>A : Symbol(A, Decl(b.ts, 0, 8)) + +declare module "./a" { + interface A { } +>A : Symbol(A, Decl(a.ts, 0, 0), Decl(b.ts, 2, 22)) +} + +export class B extends A { +>B : Symbol(B, Decl(b.ts, 4, 1)) +>A : Symbol(A, Decl(b.ts, 0, 8)) + + protected setProtected() { +>setProtected : Symbol(setProtected, Decl(b.ts, 6, 26)) + + } +} diff --git a/tests/baselines/reference/mergedDeclarations6.types b/tests/baselines/reference/mergedDeclarations6.types new file mode 100644 index 0000000000000..6198c08f6b5d2 --- /dev/null +++ b/tests/baselines/reference/mergedDeclarations6.types @@ -0,0 +1,39 @@ +=== tests/cases/compiler/a.ts === + +export class A { +>A : A + + protected protected: any; +>protected : any + + protected setProtected(val: any) { +>setProtected : (val: any) => void +>val : any + + this.protected = val; +>this.protected = val : any +>this.protected : any +>this : this +>protected : any +>val : any + } +} + +=== tests/cases/compiler/b.ts === +import {A} from './a'; +>A : typeof A + +declare module "./a" { + interface A { } +>A : A +} + +export class B extends A { +>B : B +>A : A + + protected setProtected() { +>setProtected : () => void + + } +} diff --git a/tests/baselines/reference/modifiersOnInterfaceIndexSignature1.errors.txt b/tests/baselines/reference/modifiersOnInterfaceIndexSignature1.errors.txt index b325710a9f066..e09a73ff68aeb 100644 --- a/tests/baselines/reference/modifiersOnInterfaceIndexSignature1.errors.txt +++ b/tests/baselines/reference/modifiersOnInterfaceIndexSignature1.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/modifiersOnInterfaceIndexSignature1.ts(2,3): error TS1145: Modifiers not permitted on index signature members. +tests/cases/compiler/modifiersOnInterfaceIndexSignature1.ts(2,3): error TS1071: 'public' modifier cannot appear on an index signature. ==== tests/cases/compiler/modifiersOnInterfaceIndexSignature1.ts (1 errors) ==== interface I { public [a: string]: number; ~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'public' modifier cannot appear on an index signature. } \ No newline at end of file diff --git a/tests/baselines/reference/modulePrologueSystem.js b/tests/baselines/reference/modulePrologueSystem.js index 80a46fb27fccb..13f7d35b0016d 100644 --- a/tests/baselines/reference/modulePrologueSystem.js +++ b/tests/baselines/reference/modulePrologueSystem.js @@ -4,8 +4,9 @@ export class Foo {} //// [modulePrologueSystem.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var Foo; return { setters:[], diff --git a/tests/baselines/reference/moduledecl.js b/tests/baselines/reference/moduledecl.js index 2e765e512d88e..f4efbadbf3ede 100644 --- a/tests/baselines/reference/moduledecl.js +++ b/tests/baselines/reference/moduledecl.js @@ -459,10 +459,10 @@ declare module exportTests { class C3_public { private getC2_private(); private setC2_private(arg); - private c2; + private readonly c2; getC1_public(): C1_public; setC1_public(arg: C1_public): void; - c1: C1_public; + readonly c1: C1_public; } } declare module mAmbient { diff --git a/tests/baselines/reference/nestedBlockScopedBindings1.js b/tests/baselines/reference/nestedBlockScopedBindings1.js new file mode 100644 index 0000000000000..ea2745c472ed4 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings1.js @@ -0,0 +1,97 @@ +//// [nestedBlockScopedBindings1.ts] +function a0() { + { + let x = 1; + } + { + let x = 1; + } +} + +function a1() { + { + let x; + } + { + let x = 1; + } +} + +function a2() { + { + let x = 1; + } + { + let x; + } +} + +function a3() { + { + let x = 1; + } + switch (1) { + case 1: + let x; + break; + } +} + + +function a4() { + { + let x; + } + switch (1) { + case 1: + let x = 1; + break; + } +} + + +//// [nestedBlockScopedBindings1.js] +function a0() { + { + var x = 1; + } + { + var x = 1; + } +} +function a1() { + { + var x = void 0; + } + { + var x = 1; + } +} +function a2() { + { + var x = 1; + } + { + var x = void 0; + } +} +function a3() { + { + var x = 1; + } + switch (1) { + case 1: + var x = void 0; + break; + } +} +function a4() { + { + var x = void 0; + } + switch (1) { + case 1: + var x = 1; + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings1.symbols b/tests/baselines/reference/nestedBlockScopedBindings1.symbols new file mode 100644 index 0000000000000..80348a1391105 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings1.symbols @@ -0,0 +1,68 @@ +=== tests/cases/compiler/nestedBlockScopedBindings1.ts === +function a0() { +>a0 : Symbol(a0, Decl(nestedBlockScopedBindings1.ts, 0, 0)) + { + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings1.ts, 2, 11)) + } + { + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings1.ts, 5, 11)) + } +} + +function a1() { +>a1 : Symbol(a1, Decl(nestedBlockScopedBindings1.ts, 7, 1)) + { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings1.ts, 11, 11)) + } + { + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings1.ts, 14, 11)) + } +} + +function a2() { +>a2 : Symbol(a2, Decl(nestedBlockScopedBindings1.ts, 16, 1)) + { + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings1.ts, 20, 11)) + } + { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings1.ts, 23, 11)) + } +} + +function a3() { +>a3 : Symbol(a3, Decl(nestedBlockScopedBindings1.ts, 25, 1)) + { + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings1.ts, 29, 11)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings1.ts, 33, 15)) + + break; + } +} + + +function a4() { +>a4 : Symbol(a4, Decl(nestedBlockScopedBindings1.ts, 36, 1)) + { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings1.ts, 41, 11)) + } + switch (1) { + case 1: + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings1.ts, 45, 15)) + + break; + } +} + diff --git a/tests/baselines/reference/nestedBlockScopedBindings1.types b/tests/baselines/reference/nestedBlockScopedBindings1.types new file mode 100644 index 0000000000000..6d5b47a348b64 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings1.types @@ -0,0 +1,82 @@ +=== tests/cases/compiler/nestedBlockScopedBindings1.ts === +function a0() { +>a0 : () => void + { + let x = 1; +>x : number +>1 : number + } + { + let x = 1; +>x : number +>1 : number + } +} + +function a1() { +>a1 : () => void + { + let x; +>x : any + } + { + let x = 1; +>x : number +>1 : number + } +} + +function a2() { +>a2 : () => void + { + let x = 1; +>x : number +>1 : number + } + { + let x; +>x : any + } +} + +function a3() { +>a3 : () => void + { + let x = 1; +>x : number +>1 : number + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } +} + + +function a4() { +>a4 : () => void + { + let x; +>x : any + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x = 1; +>x : number +>1 : number + + break; + } +} + diff --git a/tests/baselines/reference/nestedBlockScopedBindings10.js b/tests/baselines/reference/nestedBlockScopedBindings10.js new file mode 100644 index 0000000000000..4cac5bceeebc1 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings10.js @@ -0,0 +1,24 @@ +//// [nestedBlockScopedBindings10.ts] +{ + let x; + x = 1; +} + +switch (1) { + case 1: + let y; + y = 1; + break; +} + +//// [nestedBlockScopedBindings10.js] +{ + var x = void 0; + x = 1; +} +switch (1) { + case 1: + var y = void 0; + y = 1; + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings10.symbols b/tests/baselines/reference/nestedBlockScopedBindings10.symbols new file mode 100644 index 0000000000000..a569e1b1f927f --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings10.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/nestedBlockScopedBindings10.ts === +{ + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings10.ts, 1, 7)) + + x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings10.ts, 1, 7)) +} + +switch (1) { + case 1: + let y; +>y : Symbol(y, Decl(nestedBlockScopedBindings10.ts, 7, 11)) + + y = 1; +>y : Symbol(y, Decl(nestedBlockScopedBindings10.ts, 7, 11)) + + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings10.types b/tests/baselines/reference/nestedBlockScopedBindings10.types new file mode 100644 index 0000000000000..ee2701cdcf13c --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings10.types @@ -0,0 +1,27 @@ +=== tests/cases/compiler/nestedBlockScopedBindings10.ts === +{ + let x; +>x : any + + x = 1; +>x = 1 : number +>x : any +>1 : number +} + +switch (1) { +>1 : number + + case 1: +>1 : number + + let y; +>y : any + + y = 1; +>y = 1 : number +>y : any +>1 : number + + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings11.js b/tests/baselines/reference/nestedBlockScopedBindings11.js new file mode 100644 index 0000000000000..23a536bcbb1e8 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings11.js @@ -0,0 +1,28 @@ +//// [nestedBlockScopedBindings11.ts] +var x; +{ + let x; + () => x; +} + +var y; +switch (1) { + case 1: + let y; + () => y; + break; +} + +//// [nestedBlockScopedBindings11.js] +var x; +{ + var x_1; + (function () { return x_1; }); +} +var y; +switch (1) { + case 1: + var y_1; + (function () { return y_1; }); + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings11.symbols b/tests/baselines/reference/nestedBlockScopedBindings11.symbols new file mode 100644 index 0000000000000..fb3886fedeee9 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings11.symbols @@ -0,0 +1,24 @@ +=== tests/cases/compiler/nestedBlockScopedBindings11.ts === +var x; +>x : Symbol(x, Decl(nestedBlockScopedBindings11.ts, 0, 3)) +{ + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings11.ts, 2, 7)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings11.ts, 2, 7)) +} + +var y; +>y : Symbol(y, Decl(nestedBlockScopedBindings11.ts, 6, 3)) + +switch (1) { + case 1: + let y; +>y : Symbol(y, Decl(nestedBlockScopedBindings11.ts, 9, 11)) + + () => y; +>y : Symbol(y, Decl(nestedBlockScopedBindings11.ts, 9, 11)) + + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings11.types b/tests/baselines/reference/nestedBlockScopedBindings11.types new file mode 100644 index 0000000000000..ab7b4228278df --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings11.types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/nestedBlockScopedBindings11.ts === +var x; +>x : any +{ + let x; +>x : any + + () => x; +>() => x : () => any +>x : any +} + +var y; +>y : any + +switch (1) { +>1 : number + + case 1: +>1 : number + + let y; +>y : any + + () => y; +>() => y : () => any +>y : any + + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings12.js b/tests/baselines/reference/nestedBlockScopedBindings12.js new file mode 100644 index 0000000000000..0b3e323a2639c --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings12.js @@ -0,0 +1,28 @@ +//// [nestedBlockScopedBindings12.ts] +var x; +{ + let x; + x = 1; +} + +var y; +switch (1) { + case 1: + let y; + y = 1; + break; +} + +//// [nestedBlockScopedBindings12.js] +var x; +{ + var x_1; + x_1 = 1; +} +var y; +switch (1) { + case 1: + var y_1; + y_1 = 1; + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings12.symbols b/tests/baselines/reference/nestedBlockScopedBindings12.symbols new file mode 100644 index 0000000000000..bff0293e45ff6 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings12.symbols @@ -0,0 +1,24 @@ +=== tests/cases/compiler/nestedBlockScopedBindings12.ts === +var x; +>x : Symbol(x, Decl(nestedBlockScopedBindings12.ts, 0, 3)) +{ + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings12.ts, 2, 7)) + + x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings12.ts, 2, 7)) +} + +var y; +>y : Symbol(y, Decl(nestedBlockScopedBindings12.ts, 6, 3)) + +switch (1) { + case 1: + let y; +>y : Symbol(y, Decl(nestedBlockScopedBindings12.ts, 9, 11)) + + y = 1; +>y : Symbol(y, Decl(nestedBlockScopedBindings12.ts, 9, 11)) + + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings12.types b/tests/baselines/reference/nestedBlockScopedBindings12.types new file mode 100644 index 0000000000000..8c1fdda0ce0fc --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings12.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/nestedBlockScopedBindings12.ts === +var x; +>x : any +{ + let x; +>x : any + + x = 1; +>x = 1 : number +>x : any +>1 : number +} + +var y; +>y : any + +switch (1) { +>1 : number + + case 1: +>1 : number + + let y; +>y : any + + y = 1; +>y = 1 : number +>y : any +>1 : number + + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings13.js b/tests/baselines/reference/nestedBlockScopedBindings13.js new file mode 100644 index 0000000000000..86e5635df68d5 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings13.js @@ -0,0 +1,23 @@ +//// [nestedBlockScopedBindings13.ts] +for (; false;) { + let x; + () => x; +} + +for (; false;) { + let y; + y = 1; +} + +//// [nestedBlockScopedBindings13.js] +var _loop_1 = function() { + var x; + (function () { return x; }); +}; +for (; false;) { + _loop_1(); +} +for (; false;) { + var y = void 0; + y = 1; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings13.symbols b/tests/baselines/reference/nestedBlockScopedBindings13.symbols new file mode 100644 index 0000000000000..a5bc7ed7866a9 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings13.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/nestedBlockScopedBindings13.ts === +for (; false;) { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings13.ts, 1, 7)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings13.ts, 1, 7)) +} + +for (; false;) { + let y; +>y : Symbol(y, Decl(nestedBlockScopedBindings13.ts, 6, 7)) + + y = 1; +>y : Symbol(y, Decl(nestedBlockScopedBindings13.ts, 6, 7)) +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings13.types b/tests/baselines/reference/nestedBlockScopedBindings13.types new file mode 100644 index 0000000000000..2e7bc7de77ed5 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings13.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/nestedBlockScopedBindings13.ts === +for (; false;) { +>false : boolean + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any +} + +for (; false;) { +>false : boolean + + let y; +>y : any + + y = 1; +>y = 1 : number +>y : any +>1 : number +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings14.js b/tests/baselines/reference/nestedBlockScopedBindings14.js new file mode 100644 index 0000000000000..1180f587420a1 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings14.js @@ -0,0 +1,27 @@ +//// [nestedBlockScopedBindings14.ts] +var x; +for (; false;) { + let x; + () => x; +} + +var y; +for (; false;) { + let y; + y = 1; +} + +//// [nestedBlockScopedBindings14.js] +var x; +var _loop_1 = function() { + var x_1; + (function () { return x_1; }); +}; +for (; false;) { + _loop_1(); +} +var y; +for (; false;) { + var y_1 = void 0; + y_1 = 1; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings14.symbols b/tests/baselines/reference/nestedBlockScopedBindings14.symbols new file mode 100644 index 0000000000000..4a13b296e88b2 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings14.symbols @@ -0,0 +1,22 @@ +=== tests/cases/compiler/nestedBlockScopedBindings14.ts === +var x; +>x : Symbol(x, Decl(nestedBlockScopedBindings14.ts, 0, 3)) + +for (; false;) { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings14.ts, 2, 7)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings14.ts, 2, 7)) +} + +var y; +>y : Symbol(y, Decl(nestedBlockScopedBindings14.ts, 6, 3)) + +for (; false;) { + let y; +>y : Symbol(y, Decl(nestedBlockScopedBindings14.ts, 8, 7)) + + y = 1; +>y : Symbol(y, Decl(nestedBlockScopedBindings14.ts, 8, 7)) +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings14.types b/tests/baselines/reference/nestedBlockScopedBindings14.types new file mode 100644 index 0000000000000..966eaaaac7a88 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings14.types @@ -0,0 +1,29 @@ +=== tests/cases/compiler/nestedBlockScopedBindings14.ts === +var x; +>x : any + +for (; false;) { +>false : boolean + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any +} + +var y; +>y : any + +for (; false;) { +>false : boolean + + let y; +>y : any + + y = 1; +>y = 1 : number +>y : any +>1 : number +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings15.js b/tests/baselines/reference/nestedBlockScopedBindings15.js new file mode 100644 index 0000000000000..8e294de98e437 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings15.js @@ -0,0 +1,68 @@ +//// [nestedBlockScopedBindings15.ts] +for (; false;) { + { + let x; + () => x; + } +} + +for (; false;) { + { + let y; + y = 1; + } +} + +for (; false;) { + switch (1){ + case 1: + let z0; + () => z0; + break; + } +} + +for (; false;) { + switch (1){ + case 1: + let z; + z = 1; + break; + } +} + +//// [nestedBlockScopedBindings15.js] +var _loop_1 = function() { + { + var x_1; + (function () { return x_1; }); + } +}; +for (; false;) { + _loop_1(); +} +for (; false;) { + { + var y = void 0; + y = 1; + } +} +var _loop_2 = function() { + switch (1) { + case 1: + var z0_1; + (function () { return z0_1; }); + break; + } +}; +for (; false;) { + _loop_2(); +} +for (; false;) { + switch (1) { + case 1: + var z = void 0; + z = 1; + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings15.symbols b/tests/baselines/reference/nestedBlockScopedBindings15.symbols new file mode 100644 index 0000000000000..26ef28f60507b --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings15.symbols @@ -0,0 +1,46 @@ +=== tests/cases/compiler/nestedBlockScopedBindings15.ts === +for (; false;) { + { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings15.ts, 2, 11)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings15.ts, 2, 11)) + } +} + +for (; false;) { + { + let y; +>y : Symbol(y, Decl(nestedBlockScopedBindings15.ts, 9, 11)) + + y = 1; +>y : Symbol(y, Decl(nestedBlockScopedBindings15.ts, 9, 11)) + } +} + +for (; false;) { + switch (1){ + case 1: + let z0; +>z0 : Symbol(z0, Decl(nestedBlockScopedBindings15.ts, 17, 15)) + + () => z0; +>z0 : Symbol(z0, Decl(nestedBlockScopedBindings15.ts, 17, 15)) + + break; + } +} + +for (; false;) { + switch (1){ + case 1: + let z; +>z : Symbol(z, Decl(nestedBlockScopedBindings15.ts, 26, 15)) + + z = 1; +>z : Symbol(z, Decl(nestedBlockScopedBindings15.ts, 26, 15)) + + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings15.types b/tests/baselines/reference/nestedBlockScopedBindings15.types new file mode 100644 index 0000000000000..5173c0c5600b1 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings15.types @@ -0,0 +1,66 @@ +=== tests/cases/compiler/nestedBlockScopedBindings15.ts === +for (; false;) { +>false : boolean + { + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + } +} + +for (; false;) { +>false : boolean + { + let y; +>y : any + + y = 1; +>y = 1 : number +>y : any +>1 : number + } +} + +for (; false;) { +>false : boolean + + switch (1){ +>1 : number + + case 1: +>1 : number + + let z0; +>z0 : any + + () => z0; +>() => z0 : () => any +>z0 : any + + break; + } +} + +for (; false;) { +>false : boolean + + switch (1){ +>1 : number + + case 1: +>1 : number + + let z; +>z : any + + z = 1; +>z = 1 : number +>z : any +>1 : number + + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings16.js b/tests/baselines/reference/nestedBlockScopedBindings16.js new file mode 100644 index 0000000000000..91f67d0d8f20f --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings16.js @@ -0,0 +1,76 @@ +//// [nestedBlockScopedBindings16.ts] +var x; +for (; false;) { + { + let x; + () => x; + } +} + +var y; +for (; false;) { + { + let y; + y = 1; + } +} + +var z0; +for (; false;) { + switch (1){ + case 1: + let z0; + () => z0; + break; + } +} + +var z; +for (; false;) { + switch (1){ + case 1: + let z; + z = 1; + break; + } +} + +//// [nestedBlockScopedBindings16.js] +var x; +var _loop_1 = function() { + { + var x_1; + (function () { return x_1; }); + } +}; +for (; false;) { + _loop_1(); +} +var y; +for (; false;) { + { + var y_1 = void 0; + y_1 = 1; + } +} +var z0; +var _loop_2 = function() { + switch (1) { + case 1: + var z0_1; + (function () { return z0_1; }); + break; + } +}; +for (; false;) { + _loop_2(); +} +var z; +for (; false;) { + switch (1) { + case 1: + var z_1 = void 0; + z_1 = 1; + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings16.symbols b/tests/baselines/reference/nestedBlockScopedBindings16.symbols new file mode 100644 index 0000000000000..cbe8114cf14cc --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings16.symbols @@ -0,0 +1,58 @@ +=== tests/cases/compiler/nestedBlockScopedBindings16.ts === +var x; +>x : Symbol(x, Decl(nestedBlockScopedBindings16.ts, 0, 3)) + +for (; false;) { + { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings16.ts, 3, 11)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings16.ts, 3, 11)) + } +} + +var y; +>y : Symbol(y, Decl(nestedBlockScopedBindings16.ts, 8, 3)) + +for (; false;) { + { + let y; +>y : Symbol(y, Decl(nestedBlockScopedBindings16.ts, 11, 11)) + + y = 1; +>y : Symbol(y, Decl(nestedBlockScopedBindings16.ts, 11, 11)) + } +} + +var z0; +>z0 : Symbol(z0, Decl(nestedBlockScopedBindings16.ts, 16, 3)) + +for (; false;) { + switch (1){ + case 1: + let z0; +>z0 : Symbol(z0, Decl(nestedBlockScopedBindings16.ts, 20, 15)) + + () => z0; +>z0 : Symbol(z0, Decl(nestedBlockScopedBindings16.ts, 20, 15)) + + break; + } +} + +var z; +>z : Symbol(z, Decl(nestedBlockScopedBindings16.ts, 26, 3)) + +for (; false;) { + switch (1){ + case 1: + let z; +>z : Symbol(z, Decl(nestedBlockScopedBindings16.ts, 30, 15)) + + z = 1; +>z : Symbol(z, Decl(nestedBlockScopedBindings16.ts, 30, 15)) + + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings16.types b/tests/baselines/reference/nestedBlockScopedBindings16.types new file mode 100644 index 0000000000000..22698402a62df --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings16.types @@ -0,0 +1,78 @@ +=== tests/cases/compiler/nestedBlockScopedBindings16.ts === +var x; +>x : any + +for (; false;) { +>false : boolean + { + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + } +} + +var y; +>y : any + +for (; false;) { +>false : boolean + { + let y; +>y : any + + y = 1; +>y = 1 : number +>y : any +>1 : number + } +} + +var z0; +>z0 : any + +for (; false;) { +>false : boolean + + switch (1){ +>1 : number + + case 1: +>1 : number + + let z0; +>z0 : any + + () => z0; +>() => z0 : () => any +>z0 : any + + break; + } +} + +var z; +>z : any + +for (; false;) { +>false : boolean + + switch (1){ +>1 : number + + case 1: +>1 : number + + let z; +>z : any + + z = 1; +>z = 1 : number +>z : any +>1 : number + + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings2.js b/tests/baselines/reference/nestedBlockScopedBindings2.js new file mode 100644 index 0000000000000..f3a8d7f0f67da --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings2.js @@ -0,0 +1,244 @@ +//// [nestedBlockScopedBindings2.ts] +function a0() { + { + let x = 1; + () => x; + } + { + let x = 1; + } +} + +function a1() { + { + let x; + } + { + let x = 1; + () => x; + } +} + +function a2() { + { + let x = 1; + () => x; + } + { + let x; + () => x; + } +} + + +function a3() { + { + let x = 1; + () => x; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + + +function a4() { + { + let x; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + + +function a5() { + { + let x; + () => x; + } + switch (1) { + case 1: + let x; + break; + } +} + +function a6() { + switch (1) { + case 1: + let x; + break; + } + switch (1) { + case 1: + let x; + break; + } +} + +function a7() { + switch (1) { + case 1: + let x; + () => x; + break; + } + switch (1) { + case 1: + let x; + break; + } +} + +function a8() { + switch (1) { + case 1: + let x; + break; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + +function a9() { + switch (1) { + case 1: + let x; + () => x; + break; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + + +//// [nestedBlockScopedBindings2.js] +function a0() { + { + var x_1 = 1; + (function () { return x_1; }); + } + { + var x = 1; + } +} +function a1() { + { + var x = void 0; + } + { + var x_2 = 1; + (function () { return x_2; }); + } +} +function a2() { + { + var x_3 = 1; + (function () { return x_3; }); + } + { + var x_4; + (function () { return x_4; }); + } +} +function a3() { + { + var x_5 = 1; + (function () { return x_5; }); + } + switch (1) { + case 1: + var x_6; + (function () { return x_6; }); + break; + } +} +function a4() { + { + var x = void 0; + } + switch (1) { + case 1: + var x_7; + (function () { return x_7; }); + break; + } +} +function a5() { + { + var x_8; + (function () { return x_8; }); + } + switch (1) { + case 1: + var x = void 0; + break; + } +} +function a6() { + switch (1) { + case 1: + var x = void 0; + break; + } + switch (1) { + case 1: + var x = void 0; + break; + } +} +function a7() { + switch (1) { + case 1: + var x_9; + (function () { return x_9; }); + break; + } + switch (1) { + case 1: + var x = void 0; + break; + } +} +function a8() { + switch (1) { + case 1: + var x = void 0; + break; + } + switch (1) { + case 1: + var x_10; + (function () { return x_10; }); + break; + } +} +function a9() { + switch (1) { + case 1: + var x_11; + (function () { return x_11; }); + break; + } + switch (1) { + case 1: + var x_12; + (function () { return x_12; }); + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings2.symbols b/tests/baselines/reference/nestedBlockScopedBindings2.symbols new file mode 100644 index 0000000000000..e97e1539e95ee --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings2.symbols @@ -0,0 +1,197 @@ +=== tests/cases/compiler/nestedBlockScopedBindings2.ts === +function a0() { +>a0 : Symbol(a0, Decl(nestedBlockScopedBindings2.ts, 0, 0)) + { + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 2, 11)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 2, 11)) + } + { + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 6, 11)) + } +} + +function a1() { +>a1 : Symbol(a1, Decl(nestedBlockScopedBindings2.ts, 8, 1)) + { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 12, 11)) + } + { + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 15, 11)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 15, 11)) + } +} + +function a2() { +>a2 : Symbol(a2, Decl(nestedBlockScopedBindings2.ts, 18, 1)) + { + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 22, 11)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 22, 11)) + } + { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 26, 11)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 26, 11)) + } +} + + +function a3() { +>a3 : Symbol(a3, Decl(nestedBlockScopedBindings2.ts, 29, 1)) + { + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 34, 11)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 34, 11)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 39, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 39, 15)) + + break; + } +} + + +function a4() { +>a4 : Symbol(a4, Decl(nestedBlockScopedBindings2.ts, 43, 1)) + { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 48, 11)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 52, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 52, 15)) + + break; + } +} + + +function a5() { +>a5 : Symbol(a5, Decl(nestedBlockScopedBindings2.ts, 56, 1)) + { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 61, 11)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 61, 11)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 66, 15)) + + break; + } +} + +function a6() { +>a6 : Symbol(a6, Decl(nestedBlockScopedBindings2.ts, 69, 1)) + + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 74, 15)) + + break; + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 79, 15)) + + break; + } +} + +function a7() { +>a7 : Symbol(a7, Decl(nestedBlockScopedBindings2.ts, 82, 1)) + + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 87, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 87, 15)) + + break; + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 93, 15)) + + break; + } +} + +function a8() { +>a8 : Symbol(a8, Decl(nestedBlockScopedBindings2.ts, 96, 1)) + + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 101, 15)) + + break; + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 106, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 106, 15)) + + break; + } +} + +function a9() { +>a9 : Symbol(a9, Decl(nestedBlockScopedBindings2.ts, 110, 1)) + + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 115, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 115, 15)) + + break; + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 121, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 121, 15)) + + break; + } +} + diff --git a/tests/baselines/reference/nestedBlockScopedBindings2.types b/tests/baselines/reference/nestedBlockScopedBindings2.types new file mode 100644 index 0000000000000..adb33b4dc7685 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings2.types @@ -0,0 +1,258 @@ +=== tests/cases/compiler/nestedBlockScopedBindings2.ts === +function a0() { +>a0 : () => void + { + let x = 1; +>x : number +>1 : number + + () => x; +>() => x : () => number +>x : number + } + { + let x = 1; +>x : number +>1 : number + } +} + +function a1() { +>a1 : () => void + { + let x; +>x : any + } + { + let x = 1; +>x : number +>1 : number + + () => x; +>() => x : () => number +>x : number + } +} + +function a2() { +>a2 : () => void + { + let x = 1; +>x : number +>1 : number + + () => x; +>() => x : () => number +>x : number + } + { + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + } +} + + +function a3() { +>a3 : () => void + { + let x = 1; +>x : number +>1 : number + + () => x; +>() => x : () => number +>x : number + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } +} + + +function a4() { +>a4 : () => void + { + let x; +>x : any + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } +} + + +function a5() { +>a5 : () => void + { + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } +} + +function a6() { +>a6 : () => void + + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } +} + +function a7() { +>a7 : () => void + + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } +} + +function a8() { +>a8 : () => void + + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } +} + +function a9() { +>a9 : () => void + + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } +} + diff --git a/tests/baselines/reference/nestedBlockScopedBindings3.js b/tests/baselines/reference/nestedBlockScopedBindings3.js new file mode 100644 index 0000000000000..97fba2da3013b --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings3.js @@ -0,0 +1,150 @@ +//// [nestedBlockScopedBindings3.ts] +function a0() { + { + for (let x = 0; x < 1; ) { + () => x; + } + } + { + for (let x;;) { + () => x; + } + } +} + +function a1() { + for (let x; x < 1;) { + () => x; + } + for (let x;;) { + () => x; + } +} + +function a2() { + for (let x; x < 1;) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + } +} + + +function a3() { + for (let x; x < 1;) { + x = x + 1; + } + switch (1) { + case 1: + let x; + break; + } +} + +function a4() { + for (let x; x < 1;) { + x = x + 1; + () => x; + } + switch (1) { + case 1: + let x; + break; + } +} + + +function a5() { + for (let x; x < 1;) { + x = x + 1; + () => x; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + +//// [nestedBlockScopedBindings3.js] +function a0() { + { + var _loop_1 = function(x) { + (function () { return x; }); + }; + for (var x = 0; x < 1;) { + _loop_1(x); + } + } + { + var _loop_2 = function(x) { + (function () { return x; }); + }; + for (var x = void 0;;) { + _loop_2(x); + } + } +} +function a1() { + var _loop_3 = function(x) { + (function () { return x; }); + }; + for (var x = void 0; x < 1;) { + _loop_3(x); + } + var _loop_4 = function(x) { + (function () { return x; }); + }; + for (var x = void 0;;) { + _loop_4(x); + } +} +function a2() { + for (var x = void 0; x < 1;) { + x = x + 1; + } + for (var x = void 0;;) { + x = x + 2; + } +} +function a3() { + for (var x = void 0; x < 1;) { + x = x + 1; + } + switch (1) { + case 1: + var x = void 0; + break; + } +} +function a4() { + var _loop_5 = function(x) { + x = x + 1; + (function () { return x; }); + }; + for (var x = void 0; x < 1;) { + _loop_5(x); + } + switch (1) { + case 1: + var x = void 0; + break; + } +} +function a5() { + var _loop_6 = function(x) { + x = x + 1; + (function () { return x; }); + }; + for (var x = void 0; x < 1;) { + _loop_6(x); + } + switch (1) { + case 1: + var x_1; + (function () { return x_1; }); + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings3.symbols b/tests/baselines/reference/nestedBlockScopedBindings3.symbols new file mode 100644 index 0000000000000..160f40a047273 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings3.symbols @@ -0,0 +1,130 @@ +=== tests/cases/compiler/nestedBlockScopedBindings3.ts === +function a0() { +>a0 : Symbol(a0, Decl(nestedBlockScopedBindings3.ts, 0, 0)) + { + for (let x = 0; x < 1; ) { +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 2, 16)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 2, 16)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 2, 16)) + } + } + { + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 7, 16)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 7, 16)) + } + } +} + +function a1() { +>a1 : Symbol(a1, Decl(nestedBlockScopedBindings3.ts, 11, 1)) + + for (let x; x < 1;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 14, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 14, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 14, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 17, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 17, 12)) + } +} + +function a2() { +>a2 : Symbol(a2, Decl(nestedBlockScopedBindings3.ts, 20, 1)) + + for (let x; x < 1;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 23, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 23, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 23, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 23, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 26, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 26, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 26, 12)) + } +} + + +function a3() { +>a3 : Symbol(a3, Decl(nestedBlockScopedBindings3.ts, 29, 1)) + + for (let x; x < 1;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 33, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 33, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 33, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 33, 12)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 38, 15)) + + break; + } +} + +function a4() { +>a4 : Symbol(a4, Decl(nestedBlockScopedBindings3.ts, 41, 1)) + + for (let x; x < 1;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 44, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 44, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 44, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 44, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 44, 12)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 50, 15)) + + break; + } +} + + +function a5() { +>a5 : Symbol(a5, Decl(nestedBlockScopedBindings3.ts, 53, 1)) + + for (let x; x < 1;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 57, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 57, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 57, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 57, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 57, 12)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 63, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 63, 15)) + + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings3.types b/tests/baselines/reference/nestedBlockScopedBindings3.types new file mode 100644 index 0000000000000..37b89242f3e2c --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings3.types @@ -0,0 +1,177 @@ +=== tests/cases/compiler/nestedBlockScopedBindings3.ts === +function a0() { +>a0 : () => void + { + for (let x = 0; x < 1; ) { +>x : number +>0 : number +>x < 1 : boolean +>x : number +>1 : number + + () => x; +>() => x : () => number +>x : number + } + } + { + for (let x;;) { +>x : any + + () => x; +>() => x : () => any +>x : any + } + } +} + +function a1() { +>a1 : () => void + + for (let x; x < 1;) { +>x : any +>x < 1 : boolean +>x : any +>1 : number + + () => x; +>() => x : () => any +>x : any + } + for (let x;;) { +>x : any + + () => x; +>() => x : () => any +>x : any + } +} + +function a2() { +>a2 : () => void + + for (let x; x < 1;) { +>x : any +>x < 1 : boolean +>x : any +>1 : number + + x = x + 1; +>x = x + 1 : any +>x : any +>x + 1 : any +>x : any +>1 : number + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + } +} + + +function a3() { +>a3 : () => void + + for (let x; x < 1;) { +>x : any +>x < 1 : boolean +>x : any +>1 : number + + x = x + 1; +>x = x + 1 : any +>x : any +>x + 1 : any +>x : any +>1 : number + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } +} + +function a4() { +>a4 : () => void + + for (let x; x < 1;) { +>x : any +>x < 1 : boolean +>x : any +>1 : number + + x = x + 1; +>x = x + 1 : any +>x : any +>x + 1 : any +>x : any +>1 : number + + () => x; +>() => x : () => any +>x : any + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } +} + + +function a5() { +>a5 : () => void + + for (let x; x < 1;) { +>x : any +>x < 1 : boolean +>x : any +>1 : number + + x = x + 1; +>x = x + 1 : any +>x : any +>x + 1 : any +>x : any +>1 : number + + () => x; +>() => x : () => any +>x : any + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings4.js b/tests/baselines/reference/nestedBlockScopedBindings4.js new file mode 100644 index 0000000000000..51cddcf676d10 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings4.js @@ -0,0 +1,91 @@ +//// [nestedBlockScopedBindings4.ts] +function a0() { + for (let x; x < 1;) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + } +} + +function a1() { + for (let x; x < 1;) { + x = x + 1; + () => x; + } + for (let x;;) { + x = x + 2; + } +} + +function a2() { + for (let x; x < 1;) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + () => x; + } +} + + +function a3() { + for (let x; x < 1;) { + x = x + 1; + () => x; + } + for (let x;;) { + x = x + 2; + () => x; + } +} + +//// [nestedBlockScopedBindings4.js] +function a0() { + for (var x = void 0; x < 1;) { + x = x + 1; + } + for (var x = void 0;;) { + x = x + 2; + } +} +function a1() { + var _loop_1 = function(x) { + x = x + 1; + (function () { return x; }); + }; + for (var x = void 0; x < 1;) { + _loop_1(x); + } + for (var x = void 0;;) { + x = x + 2; + } +} +function a2() { + for (var x = void 0; x < 1;) { + x = x + 1; + } + var _loop_2 = function(x) { + x = x + 2; + (function () { return x; }); + }; + for (var x = void 0;;) { + _loop_2(x); + } +} +function a3() { + var _loop_3 = function(x) { + x = x + 1; + (function () { return x; }); + }; + for (var x = void 0; x < 1;) { + _loop_3(x); + } + var _loop_4 = function(x) { + x = x + 2; + (function () { return x; }); + }; + for (var x = void 0;;) { + _loop_4(x); + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings4.symbols b/tests/baselines/reference/nestedBlockScopedBindings4.symbols new file mode 100644 index 0000000000000..dac99d8158fa9 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings4.symbols @@ -0,0 +1,93 @@ +=== tests/cases/compiler/nestedBlockScopedBindings4.ts === +function a0() { +>a0 : Symbol(a0, Decl(nestedBlockScopedBindings4.ts, 0, 0)) + + for (let x; x < 1;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 1, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 1, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 1, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 1, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 4, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 4, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 4, 12)) + } +} + +function a1() { +>a1 : Symbol(a1, Decl(nestedBlockScopedBindings4.ts, 7, 1)) + + for (let x; x < 1;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 10, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 10, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 10, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 10, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 10, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 14, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 14, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 14, 12)) + } +} + +function a2() { +>a2 : Symbol(a2, Decl(nestedBlockScopedBindings4.ts, 17, 1)) + + for (let x; x < 1;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 20, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 20, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 20, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 20, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 23, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 23, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 23, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 23, 12)) + } +} + + +function a3() { +>a3 : Symbol(a3, Decl(nestedBlockScopedBindings4.ts, 27, 1)) + + for (let x; x < 1;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 31, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 31, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 31, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 31, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 31, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 35, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 35, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 35, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 35, 12)) + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings4.types b/tests/baselines/reference/nestedBlockScopedBindings4.types new file mode 100644 index 0000000000000..b38d61f3f4400 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings4.types @@ -0,0 +1,129 @@ +=== tests/cases/compiler/nestedBlockScopedBindings4.ts === +function a0() { +>a0 : () => void + + for (let x; x < 1;) { +>x : any +>x < 1 : boolean +>x : any +>1 : number + + x = x + 1; +>x = x + 1 : any +>x : any +>x + 1 : any +>x : any +>1 : number + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + } +} + +function a1() { +>a1 : () => void + + for (let x; x < 1;) { +>x : any +>x < 1 : boolean +>x : any +>1 : number + + x = x + 1; +>x = x + 1 : any +>x : any +>x + 1 : any +>x : any +>1 : number + + () => x; +>() => x : () => any +>x : any + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + } +} + +function a2() { +>a2 : () => void + + for (let x; x < 1;) { +>x : any +>x < 1 : boolean +>x : any +>1 : number + + x = x + 1; +>x = x + 1 : any +>x : any +>x + 1 : any +>x : any +>1 : number + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + + () => x; +>() => x : () => any +>x : any + } +} + + +function a3() { +>a3 : () => void + + for (let x; x < 1;) { +>x : any +>x < 1 : boolean +>x : any +>1 : number + + x = x + 1; +>x = x + 1 : any +>x : any +>x + 1 : any +>x : any +>1 : number + + () => x; +>() => x : () => any +>x : any + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + + () => x; +>() => x : () => any +>x : any + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings5.js b/tests/baselines/reference/nestedBlockScopedBindings5.js new file mode 100644 index 0000000000000..c80c72c0ed66e --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings5.js @@ -0,0 +1,169 @@ +//// [nestedBlockScopedBindings5.ts] +function a0() { + for (let x in []) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + } +} + +function a1() { + for (let x in []) { + x = x + 1; + () => x; + } + for (let x;;) { + x = x + 2; + } +} + +function a2() { + for (let x in []) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + () => x; + } +} + + +function a3() { + for (let x in []) { + x = x + 1; + () => x; + } + for (let x;false;) { + x = x + 2; + () => x; + } + switch (1) { + case 1: + let x; + () => x; + break; + } + +} + +function a4() { + for (let x in []) { + x = x + 1; + } + for (let x;false;) { + x = x + 2; + } + switch (1) { + case 1: + let x; + () => x; + break; + } + +} + +function a5() { + let y; + for (let x in []) { + x = x + 1; + } + for (let x;false;) { + x = x + 2; + () => x; + } + switch (1) { + case 1: + let x; + break; + } + +} + +//// [nestedBlockScopedBindings5.js] +function a0() { + for (var x in []) { + x = x + 1; + } + for (var x = void 0;;) { + x = x + 2; + } +} +function a1() { + var _loop_1 = function(x) { + x = x + 1; + (function () { return x; }); + }; + for (var x in []) { + _loop_1(x); + } + for (var x = void 0;;) { + x = x + 2; + } +} +function a2() { + for (var x in []) { + x = x + 1; + } + var _loop_2 = function(x) { + x = x + 2; + (function () { return x; }); + }; + for (var x = void 0;;) { + _loop_2(x); + } +} +function a3() { + var _loop_3 = function(x) { + x = x + 1; + (function () { return x; }); + }; + for (var x in []) { + _loop_3(x); + } + var _loop_4 = function(x) { + x = x + 2; + (function () { return x; }); + }; + for (var x = void 0; false;) { + _loop_4(x); + } + switch (1) { + case 1: + var x_1; + (function () { return x_1; }); + break; + } +} +function a4() { + for (var x in []) { + x = x + 1; + } + for (var x = void 0; false;) { + x = x + 2; + } + switch (1) { + case 1: + var x_2; + (function () { return x_2; }); + break; + } +} +function a5() { + var y; + for (var x in []) { + x = x + 1; + } + var _loop_5 = function(x) { + x = x + 2; + (function () { return x; }); + }; + for (var x = void 0; false;) { + _loop_5(x); + } + switch (1) { + case 1: + var x = void 0; + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings5.symbols b/tests/baselines/reference/nestedBlockScopedBindings5.symbols new file mode 100644 index 0000000000000..202a1d2e83f06 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings5.symbols @@ -0,0 +1,163 @@ +=== tests/cases/compiler/nestedBlockScopedBindings5.ts === +function a0() { +>a0 : Symbol(a0, Decl(nestedBlockScopedBindings5.ts, 0, 0)) + + for (let x in []) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 1, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 1, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 1, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 4, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 4, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 4, 12)) + } +} + +function a1() { +>a1 : Symbol(a1, Decl(nestedBlockScopedBindings5.ts, 7, 1)) + + for (let x in []) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 10, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 10, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 10, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 10, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 14, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 14, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 14, 12)) + } +} + +function a2() { +>a2 : Symbol(a2, Decl(nestedBlockScopedBindings5.ts, 17, 1)) + + for (let x in []) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 20, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 20, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 20, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 23, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 23, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 23, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 23, 12)) + } +} + + +function a3() { +>a3 : Symbol(a3, Decl(nestedBlockScopedBindings5.ts, 27, 1)) + + for (let x in []) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 31, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 31, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 31, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 31, 12)) + } + for (let x;false;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 35, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 35, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 35, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 35, 12)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 41, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 41, 15)) + + break; + } + +} + +function a4() { +>a4 : Symbol(a4, Decl(nestedBlockScopedBindings5.ts, 46, 1)) + + for (let x in []) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 49, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 49, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 49, 12)) + } + for (let x;false;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 52, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 52, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 52, 12)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 57, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 57, 15)) + + break; + } + +} + +function a5() { +>a5 : Symbol(a5, Decl(nestedBlockScopedBindings5.ts, 62, 1)) + + let y; +>y : Symbol(y, Decl(nestedBlockScopedBindings5.ts, 65, 7)) + + for (let x in []) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 66, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 66, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 66, 12)) + } + for (let x;false;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 69, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 69, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 69, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 69, 12)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 75, 15)) + + break; + } + +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings5.types b/tests/baselines/reference/nestedBlockScopedBindings5.types new file mode 100644 index 0000000000000..10ea0e5f902fd --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings5.types @@ -0,0 +1,227 @@ +=== tests/cases/compiler/nestedBlockScopedBindings5.ts === +function a0() { +>a0 : () => void + + for (let x in []) { +>x : string +>[] : undefined[] + + x = x + 1; +>x = x + 1 : string +>x : string +>x + 1 : string +>x : string +>1 : number + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + } +} + +function a1() { +>a1 : () => void + + for (let x in []) { +>x : string +>[] : undefined[] + + x = x + 1; +>x = x + 1 : string +>x : string +>x + 1 : string +>x : string +>1 : number + + () => x; +>() => x : () => string +>x : string + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + } +} + +function a2() { +>a2 : () => void + + for (let x in []) { +>x : string +>[] : undefined[] + + x = x + 1; +>x = x + 1 : string +>x : string +>x + 1 : string +>x : string +>1 : number + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + + () => x; +>() => x : () => any +>x : any + } +} + + +function a3() { +>a3 : () => void + + for (let x in []) { +>x : string +>[] : undefined[] + + x = x + 1; +>x = x + 1 : string +>x : string +>x + 1 : string +>x : string +>1 : number + + () => x; +>() => x : () => string +>x : string + } + for (let x;false;) { +>x : any +>false : boolean + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + + () => x; +>() => x : () => any +>x : any + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } + +} + +function a4() { +>a4 : () => void + + for (let x in []) { +>x : string +>[] : undefined[] + + x = x + 1; +>x = x + 1 : string +>x : string +>x + 1 : string +>x : string +>1 : number + } + for (let x;false;) { +>x : any +>false : boolean + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } + +} + +function a5() { +>a5 : () => void + + let y; +>y : any + + for (let x in []) { +>x : string +>[] : undefined[] + + x = x + 1; +>x = x + 1 : string +>x : string +>x + 1 : string +>x : string +>1 : number + } + for (let x;false;) { +>x : any +>false : boolean + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + + () => x; +>() => x : () => any +>x : any + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } + +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings6.js b/tests/baselines/reference/nestedBlockScopedBindings6.js new file mode 100644 index 0000000000000..78207b98fcd2e --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings6.js @@ -0,0 +1,197 @@ +//// [nestedBlockScopedBindings6.ts] +function a0() { + for (let x of [1]) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + } +} + +function a1() { + for (let x of [1]) { + x = x + 1; + () => x; + } + for (let x;;) { + x = x + 2; + } +} + +function a2() { + for (let x of [1]) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + () => x; + } +} + +function a3() { + for (let x of [1]) { + x = x + 1; + () => x; + } + for (let x;;) { + x = x + 2; + () => x; + } +} + +function a4() { + for (let x of [1]) { + x = x + 1; + () => x; + } + switch (1) { + case 1: + let x; + break; + } +} + + +function a5() { + for (let x of [1]) { + x = x + 1; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + +function a6() { + for (let x of [1]) { + x = x + 1; + } + switch (1) { + case 1: + let x; + break; + } +} + +function a7() { + for (let x of [1]) { + x = x + 1; + () => x; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + +//// [nestedBlockScopedBindings6.js] +function a0() { + for (var _i = 0, _a = [1]; _i < _a.length; _i++) { + var x = _a[_i]; + x = x + 1; + } + for (var x = void 0;;) { + x = x + 2; + } +} +function a1() { + var _loop_1 = function(x) { + x = x + 1; + (function () { return x; }); + }; + for (var _i = 0, _a = [1]; _i < _a.length; _i++) { + var x = _a[_i]; + _loop_1(x); + } + for (var x = void 0;;) { + x = x + 2; + } +} +function a2() { + for (var _i = 0, _a = [1]; _i < _a.length; _i++) { + var x = _a[_i]; + x = x + 1; + } + var _loop_2 = function(x) { + x = x + 2; + (function () { return x; }); + }; + for (var x = void 0;;) { + _loop_2(x); + } +} +function a3() { + var _loop_3 = function(x) { + x = x + 1; + (function () { return x; }); + }; + for (var _i = 0, _a = [1]; _i < _a.length; _i++) { + var x = _a[_i]; + _loop_3(x); + } + var _loop_4 = function(x) { + x = x + 2; + (function () { return x; }); + }; + for (var x = void 0;;) { + _loop_4(x); + } +} +function a4() { + var _loop_5 = function(x) { + x = x + 1; + (function () { return x; }); + }; + for (var _i = 0, _a = [1]; _i < _a.length; _i++) { + var x = _a[_i]; + _loop_5(x); + } + switch (1) { + case 1: + var x = void 0; + break; + } +} +function a5() { + for (var _i = 0, _a = [1]; _i < _a.length; _i++) { + var x = _a[_i]; + x = x + 1; + } + switch (1) { + case 1: + var x_1; + (function () { return x_1; }); + break; + } +} +function a6() { + for (var _i = 0, _a = [1]; _i < _a.length; _i++) { + var x = _a[_i]; + x = x + 1; + } + switch (1) { + case 1: + var x = void 0; + break; + } +} +function a7() { + var _loop_6 = function(x) { + x = x + 1; + (function () { return x; }); + }; + for (var _i = 0, _a = [1]; _i < _a.length; _i++) { + var x = _a[_i]; + _loop_6(x); + } + switch (1) { + case 1: + var x_2; + (function () { return x_2; }); + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings6.symbols b/tests/baselines/reference/nestedBlockScopedBindings6.symbols new file mode 100644 index 0000000000000..43cfcb4381409 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings6.symbols @@ -0,0 +1,177 @@ +=== tests/cases/compiler/nestedBlockScopedBindings6.ts === +function a0() { +>a0 : Symbol(a0, Decl(nestedBlockScopedBindings6.ts, 0, 0)) + + for (let x of [1]) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 1, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 1, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 1, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 4, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 4, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 4, 12)) + } +} + +function a1() { +>a1 : Symbol(a1, Decl(nestedBlockScopedBindings6.ts, 7, 1)) + + for (let x of [1]) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 10, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 10, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 10, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 10, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 14, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 14, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 14, 12)) + } +} + +function a2() { +>a2 : Symbol(a2, Decl(nestedBlockScopedBindings6.ts, 17, 1)) + + for (let x of [1]) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 20, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 20, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 20, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 23, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 23, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 23, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 23, 12)) + } +} + +function a3() { +>a3 : Symbol(a3, Decl(nestedBlockScopedBindings6.ts, 27, 1)) + + for (let x of [1]) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 30, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 30, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 30, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 30, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 34, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 34, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 34, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 34, 12)) + } +} + +function a4() { +>a4 : Symbol(a4, Decl(nestedBlockScopedBindings6.ts, 38, 1)) + + for (let x of [1]) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 41, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 41, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 41, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 41, 12)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 47, 15)) + + break; + } +} + + +function a5() { +>a5 : Symbol(a5, Decl(nestedBlockScopedBindings6.ts, 50, 1)) + + for (let x of [1]) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 54, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 54, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 54, 12)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 59, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 59, 15)) + + break; + } +} + +function a6() { +>a6 : Symbol(a6, Decl(nestedBlockScopedBindings6.ts, 63, 1)) + + for (let x of [1]) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 66, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 66, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 66, 12)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 71, 15)) + + break; + } +} + +function a7() { +>a7 : Symbol(a7, Decl(nestedBlockScopedBindings6.ts, 74, 1)) + + for (let x of [1]) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 77, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 77, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 77, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 77, 12)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 83, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 83, 15)) + + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings6.types b/tests/baselines/reference/nestedBlockScopedBindings6.types new file mode 100644 index 0000000000000..5c8c1fa68fadc --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings6.types @@ -0,0 +1,253 @@ +=== tests/cases/compiler/nestedBlockScopedBindings6.ts === +function a0() { +>a0 : () => void + + for (let x of [1]) { +>x : number +>[1] : number[] +>1 : number + + x = x + 1; +>x = x + 1 : number +>x : number +>x + 1 : number +>x : number +>1 : number + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + } +} + +function a1() { +>a1 : () => void + + for (let x of [1]) { +>x : number +>[1] : number[] +>1 : number + + x = x + 1; +>x = x + 1 : number +>x : number +>x + 1 : number +>x : number +>1 : number + + () => x; +>() => x : () => number +>x : number + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + } +} + +function a2() { +>a2 : () => void + + for (let x of [1]) { +>x : number +>[1] : number[] +>1 : number + + x = x + 1; +>x = x + 1 : number +>x : number +>x + 1 : number +>x : number +>1 : number + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + + () => x; +>() => x : () => any +>x : any + } +} + +function a3() { +>a3 : () => void + + for (let x of [1]) { +>x : number +>[1] : number[] +>1 : number + + x = x + 1; +>x = x + 1 : number +>x : number +>x + 1 : number +>x : number +>1 : number + + () => x; +>() => x : () => number +>x : number + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + + () => x; +>() => x : () => any +>x : any + } +} + +function a4() { +>a4 : () => void + + for (let x of [1]) { +>x : number +>[1] : number[] +>1 : number + + x = x + 1; +>x = x + 1 : number +>x : number +>x + 1 : number +>x : number +>1 : number + + () => x; +>() => x : () => number +>x : number + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } +} + + +function a5() { +>a5 : () => void + + for (let x of [1]) { +>x : number +>[1] : number[] +>1 : number + + x = x + 1; +>x = x + 1 : number +>x : number +>x + 1 : number +>x : number +>1 : number + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } +} + +function a6() { +>a6 : () => void + + for (let x of [1]) { +>x : number +>[1] : number[] +>1 : number + + x = x + 1; +>x = x + 1 : number +>x : number +>x + 1 : number +>x : number +>1 : number + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } +} + +function a7() { +>a7 : () => void + + for (let x of [1]) { +>x : number +>[1] : number[] +>1 : number + + x = x + 1; +>x = x + 1 : number +>x : number +>x + 1 : number +>x : number +>1 : number + + () => x; +>() => x : () => number +>x : number + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings7.js b/tests/baselines/reference/nestedBlockScopedBindings7.js new file mode 100644 index 0000000000000..df0e6c52a6261 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings7.js @@ -0,0 +1,19 @@ +//// [nestedBlockScopedBindings7.ts] +for (let x; false;) { + () => x; +} + +for (let y; false;) { + y = 1; +} + +//// [nestedBlockScopedBindings7.js] +var _loop_1 = function(x) { + (function () { return x; }); +}; +for (var x = void 0; false;) { + _loop_1(x); +} +for (var y = void 0; false;) { + y = 1; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings7.symbols b/tests/baselines/reference/nestedBlockScopedBindings7.symbols new file mode 100644 index 0000000000000..2d65af06a960e --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings7.symbols @@ -0,0 +1,14 @@ +=== tests/cases/compiler/nestedBlockScopedBindings7.ts === +for (let x; false;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings7.ts, 0, 8)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings7.ts, 0, 8)) +} + +for (let y; false;) { +>y : Symbol(y, Decl(nestedBlockScopedBindings7.ts, 4, 8)) + + y = 1; +>y : Symbol(y, Decl(nestedBlockScopedBindings7.ts, 4, 8)) +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings7.types b/tests/baselines/reference/nestedBlockScopedBindings7.types new file mode 100644 index 0000000000000..2fdb2d90e76a0 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings7.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/nestedBlockScopedBindings7.ts === +for (let x; false;) { +>x : any +>false : boolean + + () => x; +>() => x : () => any +>x : any +} + +for (let y; false;) { +>y : any +>false : boolean + + y = 1; +>y = 1 : number +>y : any +>1 : number +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings8.js b/tests/baselines/reference/nestedBlockScopedBindings8.js new file mode 100644 index 0000000000000..772dc020d6deb --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings8.js @@ -0,0 +1,23 @@ +//// [nestedBlockScopedBindings8.ts] +var x; +for (let x; false; ) { + () => x; +} + +var y; +for (let y; false; ) { + y = 1; +} + +//// [nestedBlockScopedBindings8.js] +var x; +var _loop_1 = function(x_1) { + (function () { return x_1; }); +}; +for (var x_1; false;) { + _loop_1(x_1); +} +var y; +for (var y_1; false;) { + y_1 = 1; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings8.symbols b/tests/baselines/reference/nestedBlockScopedBindings8.symbols new file mode 100644 index 0000000000000..a61df0502ec8a --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings8.symbols @@ -0,0 +1,20 @@ +=== tests/cases/compiler/nestedBlockScopedBindings8.ts === +var x; +>x : Symbol(x, Decl(nestedBlockScopedBindings8.ts, 0, 3)) + +for (let x; false; ) { +>x : Symbol(x, Decl(nestedBlockScopedBindings8.ts, 1, 8)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings8.ts, 1, 8)) +} + +var y; +>y : Symbol(y, Decl(nestedBlockScopedBindings8.ts, 5, 3)) + +for (let y; false; ) { +>y : Symbol(y, Decl(nestedBlockScopedBindings8.ts, 6, 8)) + + y = 1; +>y : Symbol(y, Decl(nestedBlockScopedBindings8.ts, 6, 8)) +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings8.types b/tests/baselines/reference/nestedBlockScopedBindings8.types new file mode 100644 index 0000000000000..9e4b98ffbf2f3 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings8.types @@ -0,0 +1,25 @@ +=== tests/cases/compiler/nestedBlockScopedBindings8.ts === +var x; +>x : any + +for (let x; false; ) { +>x : any +>false : boolean + + () => x; +>() => x : () => any +>x : any +} + +var y; +>y : any + +for (let y; false; ) { +>y : any +>false : boolean + + y = 1; +>y = 1 : number +>y : any +>1 : number +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings9.js b/tests/baselines/reference/nestedBlockScopedBindings9.js new file mode 100644 index 0000000000000..9f037924c6841 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings9.js @@ -0,0 +1,24 @@ +//// [nestedBlockScopedBindings9.ts] +{ + let x; + () => x; +} + +switch (1) { + case 1: + let y; + () => y; + break; +} + +//// [nestedBlockScopedBindings9.js] +{ + var x_1; + (function () { return x_1; }); +} +switch (1) { + case 1: + var y_1; + (function () { return y_1; }); + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings9.symbols b/tests/baselines/reference/nestedBlockScopedBindings9.symbols new file mode 100644 index 0000000000000..1564c9e893103 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings9.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/nestedBlockScopedBindings9.ts === +{ + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings9.ts, 1, 7)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings9.ts, 1, 7)) +} + +switch (1) { + case 1: + let y; +>y : Symbol(y, Decl(nestedBlockScopedBindings9.ts, 7, 11)) + + () => y; +>y : Symbol(y, Decl(nestedBlockScopedBindings9.ts, 7, 11)) + + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings9.types b/tests/baselines/reference/nestedBlockScopedBindings9.types new file mode 100644 index 0000000000000..b889421e7dd61 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings9.types @@ -0,0 +1,25 @@ +=== tests/cases/compiler/nestedBlockScopedBindings9.ts === +{ + let x; +>x : any + + () => x; +>() => x : () => any +>x : any +} + +switch (1) { +>1 : number + + case 1: +>1 : number + + let y; +>y : any + + () => y; +>() => y : () => any +>y : any + + break; +} diff --git a/tests/baselines/reference/noErrorOnEmptyDts.js b/tests/baselines/reference/noErrorOnEmptyDts.js new file mode 100644 index 0000000000000..83595e3d2ade0 --- /dev/null +++ b/tests/baselines/reference/noErrorOnEmptyDts.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/noErrorOnEmptyDts.ts] //// + +//// [test.d.ts] + + +// comment + +//// [main.ts] +import "test" + +//// [main.js] +"use strict"; +require("test"); diff --git a/tests/baselines/reference/noErrorOnEmptyDts.symbols b/tests/baselines/reference/noErrorOnEmptyDts.symbols new file mode 100644 index 0000000000000..78446a19fb87e --- /dev/null +++ b/tests/baselines/reference/noErrorOnEmptyDts.symbols @@ -0,0 +1,8 @@ +=== c:/node_modules/test.d.ts === + +No type information for this code. +No type information for this code.// comment +No type information for this code. +No type information for this code.=== c:/app/main.ts === +import "test" +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/noErrorOnEmptyDts.types b/tests/baselines/reference/noErrorOnEmptyDts.types new file mode 100644 index 0000000000000..78446a19fb87e --- /dev/null +++ b/tests/baselines/reference/noErrorOnEmptyDts.types @@ -0,0 +1,8 @@ +=== c:/node_modules/test.d.ts === + +No type information for this code. +No type information for this code.// comment +No type information for this code. +No type information for this code.=== c:/app/main.ts === +import "test" +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/objectLiteralGettersAndSetters.errors.txt b/tests/baselines/reference/objectLiteralGettersAndSetters.errors.txt index 4e04b856d8c5c..1290859fbf9f0 100644 --- a/tests/baselines/reference/objectLiteralGettersAndSetters.errors.txt +++ b/tests/baselines/reference/objectLiteralGettersAndSetters.errors.txt @@ -79,13 +79,13 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralGettersAndSetter var getter1 = { get x(): string { return undefined; } }; ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - var getter1: { x: string; } + var getter1: { readonly x: string; } // Get accessor only, type of the property is the inferred return type of the get accessor var getter2 = { get x() { return ''; } }; ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - var getter2: { x: string; } + var getter2: { readonly x: string; } // Set accessor only, type of the property is the param type of the set accessor var setter1 = { set x(n: number) { } }; diff --git a/tests/baselines/reference/objectLiteralGettersAndSetters.js b/tests/baselines/reference/objectLiteralGettersAndSetters.js index d226c2c55697f..d3a9d64308601 100644 --- a/tests/baselines/reference/objectLiteralGettersAndSetters.js +++ b/tests/baselines/reference/objectLiteralGettersAndSetters.js @@ -17,11 +17,11 @@ var callSig3: { num: (n: number) => string; }; // Get accessor only, type of the property is the annotated return type of the get accessor var getter1 = { get x(): string { return undefined; } }; -var getter1: { x: string; } +var getter1: { readonly x: string; } // Get accessor only, type of the property is the inferred return type of the get accessor var getter2 = { get x() { return ''; } }; -var getter2: { x: string; } +var getter2: { readonly x: string; } // Set accessor only, type of the property is the param type of the set accessor var setter1 = { set x(n: number) { } }; diff --git a/tests/baselines/reference/outFilerootDirModuleNamesSystem.js b/tests/baselines/reference/outFilerootDirModuleNamesSystem.js index 298ad52689fce..eb1ef2a4a5442 100644 --- a/tests/baselines/reference/outFilerootDirModuleNamesSystem.js +++ b/tests/baselines/reference/outFilerootDirModuleNamesSystem.js @@ -11,8 +11,9 @@ export default function foo() { new Foo(); } //// [output.js] -System.register("b", ["a"], function(exports_1) { +System.register("b", ["a"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var a_1; function foo() { new a_1.default(); } exports_1("default", foo); @@ -25,8 +26,9 @@ System.register("b", ["a"], function(exports_1) { } } }); -System.register("a", ["b"], function(exports_2) { +System.register("a", ["b"], function(exports_2, context_2) { "use strict"; + var __moduleName = context_2 && context_2.id; var b_1; var Foo; return { diff --git a/tests/baselines/reference/outModuleConcatSystem.js b/tests/baselines/reference/outModuleConcatSystem.js index d4552d331673f..59bbb3630224e 100644 --- a/tests/baselines/reference/outModuleConcatSystem.js +++ b/tests/baselines/reference/outModuleConcatSystem.js @@ -14,8 +14,9 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; -System.register("ref/a", [], function(exports_1) { +System.register("ref/a", [], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var A; return { setters:[], @@ -29,8 +30,9 @@ System.register("ref/a", [], function(exports_1) { } } }); -System.register("b", ["ref/a"], function(exports_2) { +System.register("b", ["ref/a"], function(exports_2, context_2) { "use strict"; + var __moduleName = context_2 && context_2.id; var a_1; var B; return { diff --git a/tests/baselines/reference/outModuleConcatSystem.js.map b/tests/baselines/reference/outModuleConcatSystem.js.map index 47d3ba2d39c98..be6e66c3cf4c8 100644 --- a/tests/baselines/reference/outModuleConcatSystem.js.map +++ b/tests/baselines/reference/outModuleConcatSystem.js.map @@ -1,2 +1,2 @@ //// [all.js.map] -{"version":3,"file":"all.js","sourceRoot":"","sources":["tests/cases/compiler/ref/a.ts","tests/cases/compiler/b.ts"],"names":[],"mappings":";;;;;;;;;;;YACA;gBAAA;gBAAiB,CAAC;gBAAD,QAAC;YAAD,CAAC,AAAlB,IAAkB;YAAlB,iBAAkB,CAAA;;;;;;;;;;;;;;YCAlB;gBAAuB,qBAAC;gBAAxB;oBAAuB,8BAAC;gBAAG,CAAC;gBAAD,QAAC;YAAD,CAAC,AAA5B,CAAuB,KAAC,GAAI;YAA5B,iBAA4B,CAAA"} \ No newline at end of file +{"version":3,"file":"all.js","sourceRoot":"","sources":["tests/cases/compiler/ref/a.ts","tests/cases/compiler/b.ts"],"names":[],"mappings":";;;;;;;;;;;;YACA;gBAAA;gBAAiB,CAAC;gBAAD,QAAC;YAAD,CAAC,AAAlB,IAAkB;YAAlB,iBAAkB,CAAA;;;;;;;;;;;;;;;YCAlB;gBAAuB,qBAAC;gBAAxB;oBAAuB,8BAAC;gBAAG,CAAC;gBAAD,QAAC;YAAD,CAAC,AAA5B,CAAuB,KAAC,GAAI;YAA5B,iBAA4B,CAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/outModuleConcatSystem.sourcemap.txt b/tests/baselines/reference/outModuleConcatSystem.sourcemap.txt index e3f521c828c69..0281bdec5bd1f 100644 --- a/tests/baselines/reference/outModuleConcatSystem.sourcemap.txt +++ b/tests/baselines/reference/outModuleConcatSystem.sourcemap.txt @@ -13,8 +13,9 @@ sourceFile:tests/cases/compiler/ref/a.ts >>> function __() { this.constructor = d; } >>> d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); >>>}; ->>>System.register("ref/a", [], function(exports_1) { +>>>System.register("ref/a", [], function(exports_1, context_1) { >>> "use strict"; +>>> var __moduleName = context_1 && context_1.id; >>> var A; >>> return { >>> setters:[], @@ -24,13 +25,13 @@ sourceFile:tests/cases/compiler/ref/a.ts 2 > ^^^^^^^^^^^^^^^^^^^-> 1 > > -1 >Emitted(12, 13) Source(2, 1) + SourceIndex(0) +1 >Emitted(13, 13) Source(2, 1) + SourceIndex(0) --- >>> function A() { 1->^^^^^^^^^^^^^^^^ 2 > ^^-> 1-> -1->Emitted(13, 17) Source(2, 1) + SourceIndex(0) +1->Emitted(14, 17) Source(2, 1) + SourceIndex(0) --- >>> } 1->^^^^^^^^^^^^^^^^ @@ -38,16 +39,16 @@ sourceFile:tests/cases/compiler/ref/a.ts 3 > ^^^^^^^^^-> 1->export class A { 2 > } -1->Emitted(14, 17) Source(2, 18) + SourceIndex(0) -2 >Emitted(14, 18) Source(2, 19) + SourceIndex(0) +1->Emitted(15, 17) Source(2, 18) + SourceIndex(0) +2 >Emitted(15, 18) Source(2, 19) + SourceIndex(0) --- >>> return A; 1->^^^^^^^^^^^^^^^^ 2 > ^^^^^^^^ 1-> 2 > } -1->Emitted(15, 17) Source(2, 18) + SourceIndex(0) -2 >Emitted(15, 25) Source(2, 19) + SourceIndex(0) +1->Emitted(16, 17) Source(2, 18) + SourceIndex(0) +2 >Emitted(16, 25) Source(2, 19) + SourceIndex(0) --- >>> }()); 1 >^^^^^^^^^^^^ @@ -59,10 +60,10 @@ sourceFile:tests/cases/compiler/ref/a.ts 2 > } 3 > 4 > export class A { } -1 >Emitted(16, 13) Source(2, 18) + SourceIndex(0) -2 >Emitted(16, 14) Source(2, 19) + SourceIndex(0) -3 >Emitted(16, 14) Source(2, 1) + SourceIndex(0) -4 >Emitted(16, 18) Source(2, 19) + SourceIndex(0) +1 >Emitted(17, 13) Source(2, 18) + SourceIndex(0) +2 >Emitted(17, 14) Source(2, 19) + SourceIndex(0) +3 >Emitted(17, 14) Source(2, 1) + SourceIndex(0) +4 >Emitted(17, 18) Source(2, 19) + SourceIndex(0) --- >>> exports_1("A", A); 1->^^^^^^^^^^^^ @@ -71,9 +72,9 @@ sourceFile:tests/cases/compiler/ref/a.ts 1-> 2 > export class A { } 3 > -1->Emitted(17, 13) Source(2, 1) + SourceIndex(0) -2 >Emitted(17, 30) Source(2, 19) + SourceIndex(0) -3 >Emitted(17, 31) Source(2, 19) + SourceIndex(0) +1->Emitted(18, 13) Source(2, 1) + SourceIndex(0) +2 >Emitted(18, 30) Source(2, 19) + SourceIndex(0) +3 >Emitted(18, 31) Source(2, 19) + SourceIndex(0) --- ------------------------------------------------------------------- emittedFile:all.js @@ -82,8 +83,9 @@ sourceFile:tests/cases/compiler/b.ts >>> } >>> } >>>}); ->>>System.register("b", ["ref/a"], function(exports_2) { +>>>System.register("b", ["ref/a"], function(exports_2, context_2) { >>> "use strict"; +>>> var __moduleName = context_2 && context_2.id; >>> var a_1; >>> var B; >>> return { @@ -97,29 +99,29 @@ sourceFile:tests/cases/compiler/b.ts 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 >import {A} from "./ref/a"; > -1 >Emitted(31, 13) Source(2, 1) + SourceIndex(1) +1 >Emitted(33, 13) Source(2, 1) + SourceIndex(1) --- >>> __extends(B, _super); 1->^^^^^^^^^^^^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^ 1->export class B extends 2 > A -1->Emitted(32, 17) Source(2, 24) + SourceIndex(1) -2 >Emitted(32, 38) Source(2, 25) + SourceIndex(1) +1->Emitted(34, 17) Source(2, 24) + SourceIndex(1) +2 >Emitted(34, 38) Source(2, 25) + SourceIndex(1) --- >>> function B() { 1 >^^^^^^^^^^^^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > -1 >Emitted(33, 17) Source(2, 1) + SourceIndex(1) +1 >Emitted(35, 17) Source(2, 1) + SourceIndex(1) --- >>> _super.apply(this, arguments); 1->^^^^^^^^^^^^^^^^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1->export class B extends 2 > A -1->Emitted(34, 21) Source(2, 24) + SourceIndex(1) -2 >Emitted(34, 51) Source(2, 25) + SourceIndex(1) +1->Emitted(36, 21) Source(2, 24) + SourceIndex(1) +2 >Emitted(36, 51) Source(2, 25) + SourceIndex(1) --- >>> } 1 >^^^^^^^^^^^^^^^^ @@ -127,16 +129,16 @@ sourceFile:tests/cases/compiler/b.ts 3 > ^^^^^^^^^-> 1 > { 2 > } -1 >Emitted(35, 17) Source(2, 28) + SourceIndex(1) -2 >Emitted(35, 18) Source(2, 29) + SourceIndex(1) +1 >Emitted(37, 17) Source(2, 28) + SourceIndex(1) +2 >Emitted(37, 18) Source(2, 29) + SourceIndex(1) --- >>> return B; 1->^^^^^^^^^^^^^^^^ 2 > ^^^^^^^^ 1-> 2 > } -1->Emitted(36, 17) Source(2, 28) + SourceIndex(1) -2 >Emitted(36, 25) Source(2, 29) + SourceIndex(1) +1->Emitted(38, 17) Source(2, 28) + SourceIndex(1) +2 >Emitted(38, 25) Source(2, 29) + SourceIndex(1) --- >>> }(a_1.A)); 1 >^^^^^^^^^^^^ @@ -152,12 +154,12 @@ sourceFile:tests/cases/compiler/b.ts 4 > export class B extends 5 > A 6 > { } -1 >Emitted(37, 13) Source(2, 28) + SourceIndex(1) -2 >Emitted(37, 14) Source(2, 29) + SourceIndex(1) -3 >Emitted(37, 14) Source(2, 1) + SourceIndex(1) -4 >Emitted(37, 15) Source(2, 24) + SourceIndex(1) -5 >Emitted(37, 20) Source(2, 25) + SourceIndex(1) -6 >Emitted(37, 23) Source(2, 29) + SourceIndex(1) +1 >Emitted(39, 13) Source(2, 28) + SourceIndex(1) +2 >Emitted(39, 14) Source(2, 29) + SourceIndex(1) +3 >Emitted(39, 14) Source(2, 1) + SourceIndex(1) +4 >Emitted(39, 15) Source(2, 24) + SourceIndex(1) +5 >Emitted(39, 20) Source(2, 25) + SourceIndex(1) +6 >Emitted(39, 23) Source(2, 29) + SourceIndex(1) --- >>> exports_2("B", B); 1->^^^^^^^^^^^^ @@ -166,9 +168,9 @@ sourceFile:tests/cases/compiler/b.ts 1-> 2 > export class B extends A { } 3 > -1->Emitted(38, 13) Source(2, 1) + SourceIndex(1) -2 >Emitted(38, 30) Source(2, 29) + SourceIndex(1) -3 >Emitted(38, 31) Source(2, 29) + SourceIndex(1) +1->Emitted(40, 13) Source(2, 1) + SourceIndex(1) +2 >Emitted(40, 30) Source(2, 29) + SourceIndex(1) +3 >Emitted(40, 31) Source(2, 29) + SourceIndex(1) --- >>> } >>> } diff --git a/tests/baselines/reference/overloadOnConstAsTypeAnnotation.errors.txt b/tests/baselines/reference/overloadOnConstAsTypeAnnotation.errors.txt deleted file mode 100644 index a78e0c8abcfaf..0000000000000 --- a/tests/baselines/reference/overloadOnConstAsTypeAnnotation.errors.txt +++ /dev/null @@ -1,11 +0,0 @@ -tests/cases/compiler/overloadOnConstAsTypeAnnotation.ts(2,8): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/overloadOnConstAsTypeAnnotation.ts(2,37): error TS1005: ';' expected. - - -==== tests/cases/compiler/overloadOnConstAsTypeAnnotation.ts (2 errors) ==== - - var f: (x: 'hi') => number = ('hi') => { return 1; }; - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - ~~ -!!! error TS1005: ';' expected. \ No newline at end of file diff --git a/tests/baselines/reference/overloadOnConstAsTypeAnnotation.js b/tests/baselines/reference/overloadOnConstAsTypeAnnotation.js index aa5c8701f2881..94250b48cbc8c 100644 --- a/tests/baselines/reference/overloadOnConstAsTypeAnnotation.js +++ b/tests/baselines/reference/overloadOnConstAsTypeAnnotation.js @@ -1,10 +1,6 @@ //// [overloadOnConstAsTypeAnnotation.ts] -var f: (x: 'hi') => number = ('hi') => { return 1; }; +var f: (x: 'hi') => number = (x: 'hi') => { return 1; }; //// [overloadOnConstAsTypeAnnotation.js] -var f = ('hi'); -{ - return 1; -} -; +var f = function (x) { return 1; }; diff --git a/tests/baselines/reference/overloadOnConstAsTypeAnnotation.symbols b/tests/baselines/reference/overloadOnConstAsTypeAnnotation.symbols new file mode 100644 index 0000000000000..c420e50cda247 --- /dev/null +++ b/tests/baselines/reference/overloadOnConstAsTypeAnnotation.symbols @@ -0,0 +1,7 @@ +=== tests/cases/compiler/overloadOnConstAsTypeAnnotation.ts === + +var f: (x: 'hi') => number = (x: 'hi') => { return 1; }; +>f : Symbol(f, Decl(overloadOnConstAsTypeAnnotation.ts, 1, 3)) +>x : Symbol(x, Decl(overloadOnConstAsTypeAnnotation.ts, 1, 8)) +>x : Symbol(x, Decl(overloadOnConstAsTypeAnnotation.ts, 1, 30)) + diff --git a/tests/baselines/reference/overloadOnConstAsTypeAnnotation.types b/tests/baselines/reference/overloadOnConstAsTypeAnnotation.types new file mode 100644 index 0000000000000..10a185708d4dd --- /dev/null +++ b/tests/baselines/reference/overloadOnConstAsTypeAnnotation.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/overloadOnConstAsTypeAnnotation.ts === + +var f: (x: 'hi') => number = (x: 'hi') => { return 1; }; +>f : (x: "hi") => number +>x : "hi" +>(x: 'hi') => { return 1; } : (x: "hi") => number +>x : "hi" +>1 : number + diff --git a/tests/baselines/reference/overloadOnConstDuplicateOverloads1.errors.txt b/tests/baselines/reference/overloadOnConstDuplicateOverloads1.errors.txt deleted file mode 100644 index 0f5126b592050..0000000000000 --- a/tests/baselines/reference/overloadOnConstDuplicateOverloads1.errors.txt +++ /dev/null @@ -1,19 +0,0 @@ -tests/cases/compiler/overloadOnConstDuplicateOverloads1.ts(1,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/overloadOnConstDuplicateOverloads1.ts(2,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - - -==== tests/cases/compiler/overloadOnConstDuplicateOverloads1.ts (2 errors) ==== - function foo(a: 'hi', x: string); - ~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - function foo(a: 'hi', x: string); - ~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - function foo(a: any, x: any) { - } - - function foo2(a: 'hi', x: string); - function foo2(a: 'hi', x: string); - function foo2(a: string, x: string); - function foo2(a: any, x: any) { - } \ No newline at end of file diff --git a/tests/baselines/reference/overloadOnConstDuplicateOverloads1.symbols b/tests/baselines/reference/overloadOnConstDuplicateOverloads1.symbols new file mode 100644 index 0000000000000..5ac0cfbd00cae --- /dev/null +++ b/tests/baselines/reference/overloadOnConstDuplicateOverloads1.symbols @@ -0,0 +1,37 @@ +=== tests/cases/compiler/overloadOnConstDuplicateOverloads1.ts === +function foo(a: 'hi', x: string); +>foo : Symbol(foo, Decl(overloadOnConstDuplicateOverloads1.ts, 0, 0), Decl(overloadOnConstDuplicateOverloads1.ts, 0, 33), Decl(overloadOnConstDuplicateOverloads1.ts, 1, 33)) +>a : Symbol(a, Decl(overloadOnConstDuplicateOverloads1.ts, 0, 13)) +>x : Symbol(x, Decl(overloadOnConstDuplicateOverloads1.ts, 0, 21)) + +function foo(a: 'hi', x: string); +>foo : Symbol(foo, Decl(overloadOnConstDuplicateOverloads1.ts, 0, 0), Decl(overloadOnConstDuplicateOverloads1.ts, 0, 33), Decl(overloadOnConstDuplicateOverloads1.ts, 1, 33)) +>a : Symbol(a, Decl(overloadOnConstDuplicateOverloads1.ts, 1, 13)) +>x : Symbol(x, Decl(overloadOnConstDuplicateOverloads1.ts, 1, 21)) + +function foo(a: any, x: any) { +>foo : Symbol(foo, Decl(overloadOnConstDuplicateOverloads1.ts, 0, 0), Decl(overloadOnConstDuplicateOverloads1.ts, 0, 33), Decl(overloadOnConstDuplicateOverloads1.ts, 1, 33)) +>a : Symbol(a, Decl(overloadOnConstDuplicateOverloads1.ts, 2, 13)) +>x : Symbol(x, Decl(overloadOnConstDuplicateOverloads1.ts, 2, 20)) +} + +function foo2(a: 'hi', x: string); +>foo2 : Symbol(foo2, Decl(overloadOnConstDuplicateOverloads1.ts, 3, 1), Decl(overloadOnConstDuplicateOverloads1.ts, 5, 34), Decl(overloadOnConstDuplicateOverloads1.ts, 6, 34), Decl(overloadOnConstDuplicateOverloads1.ts, 7, 36)) +>a : Symbol(a, Decl(overloadOnConstDuplicateOverloads1.ts, 5, 14)) +>x : Symbol(x, Decl(overloadOnConstDuplicateOverloads1.ts, 5, 22)) + +function foo2(a: 'hi', x: string); +>foo2 : Symbol(foo2, Decl(overloadOnConstDuplicateOverloads1.ts, 3, 1), Decl(overloadOnConstDuplicateOverloads1.ts, 5, 34), Decl(overloadOnConstDuplicateOverloads1.ts, 6, 34), Decl(overloadOnConstDuplicateOverloads1.ts, 7, 36)) +>a : Symbol(a, Decl(overloadOnConstDuplicateOverloads1.ts, 6, 14)) +>x : Symbol(x, Decl(overloadOnConstDuplicateOverloads1.ts, 6, 22)) + +function foo2(a: string, x: string); +>foo2 : Symbol(foo2, Decl(overloadOnConstDuplicateOverloads1.ts, 3, 1), Decl(overloadOnConstDuplicateOverloads1.ts, 5, 34), Decl(overloadOnConstDuplicateOverloads1.ts, 6, 34), Decl(overloadOnConstDuplicateOverloads1.ts, 7, 36)) +>a : Symbol(a, Decl(overloadOnConstDuplicateOverloads1.ts, 7, 14)) +>x : Symbol(x, Decl(overloadOnConstDuplicateOverloads1.ts, 7, 24)) + +function foo2(a: any, x: any) { +>foo2 : Symbol(foo2, Decl(overloadOnConstDuplicateOverloads1.ts, 3, 1), Decl(overloadOnConstDuplicateOverloads1.ts, 5, 34), Decl(overloadOnConstDuplicateOverloads1.ts, 6, 34), Decl(overloadOnConstDuplicateOverloads1.ts, 7, 36)) +>a : Symbol(a, Decl(overloadOnConstDuplicateOverloads1.ts, 8, 14)) +>x : Symbol(x, Decl(overloadOnConstDuplicateOverloads1.ts, 8, 21)) +} diff --git a/tests/baselines/reference/overloadOnConstDuplicateOverloads1.types b/tests/baselines/reference/overloadOnConstDuplicateOverloads1.types new file mode 100644 index 0000000000000..f74bb5bf958b9 --- /dev/null +++ b/tests/baselines/reference/overloadOnConstDuplicateOverloads1.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/overloadOnConstDuplicateOverloads1.ts === +function foo(a: 'hi', x: string); +>foo : { (a: "hi", x: string): any; (a: "hi", x: string): any; } +>a : "hi" +>x : string + +function foo(a: 'hi', x: string); +>foo : { (a: "hi", x: string): any; (a: "hi", x: string): any; } +>a : "hi" +>x : string + +function foo(a: any, x: any) { +>foo : { (a: "hi", x: string): any; (a: "hi", x: string): any; } +>a : any +>x : any +} + +function foo2(a: 'hi', x: string); +>foo2 : { (a: "hi", x: string): any; (a: "hi", x: string): any; (a: string, x: string): any; } +>a : "hi" +>x : string + +function foo2(a: 'hi', x: string); +>foo2 : { (a: "hi", x: string): any; (a: "hi", x: string): any; (a: string, x: string): any; } +>a : "hi" +>x : string + +function foo2(a: string, x: string); +>foo2 : { (a: "hi", x: string): any; (a: "hi", x: string): any; (a: string, x: string): any; } +>a : string +>x : string + +function foo2(a: any, x: any) { +>foo2 : { (a: "hi", x: string): any; (a: "hi", x: string): any; (a: string, x: string): any; } +>a : any +>x : any +} diff --git a/tests/baselines/reference/overloadOnConstInBaseWithBadImplementationInDerived.errors.txt b/tests/baselines/reference/overloadOnConstInBaseWithBadImplementationInDerived.errors.txt deleted file mode 100644 index e040559a05414..0000000000000 --- a/tests/baselines/reference/overloadOnConstInBaseWithBadImplementationInDerived.errors.txt +++ /dev/null @@ -1,17 +0,0 @@ -tests/cases/compiler/overloadOnConstInBaseWithBadImplementationInDerived.ts(2,29): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/overloadOnConstInBaseWithBadImplementationInDerived.ts(6,29): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - - -==== tests/cases/compiler/overloadOnConstInBaseWithBadImplementationInDerived.ts (2 errors) ==== - interface I { - x1(a: number, callback: (x: 'hi') => number); - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - } - - class C implements I { - x1(a: number, callback: (x: 'hi') => number) { // error - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - } - } \ No newline at end of file diff --git a/tests/baselines/reference/overloadOnConstInBaseWithBadImplementationInDerived.symbols b/tests/baselines/reference/overloadOnConstInBaseWithBadImplementationInDerived.symbols new file mode 100644 index 0000000000000..6e4429759e2d9 --- /dev/null +++ b/tests/baselines/reference/overloadOnConstInBaseWithBadImplementationInDerived.symbols @@ -0,0 +1,22 @@ +=== tests/cases/compiler/overloadOnConstInBaseWithBadImplementationInDerived.ts === +interface I { +>I : Symbol(I, Decl(overloadOnConstInBaseWithBadImplementationInDerived.ts, 0, 0)) + + x1(a: number, callback: (x: 'hi') => number); +>x1 : Symbol(x1, Decl(overloadOnConstInBaseWithBadImplementationInDerived.ts, 0, 13)) +>a : Symbol(a, Decl(overloadOnConstInBaseWithBadImplementationInDerived.ts, 1, 7)) +>callback : Symbol(callback, Decl(overloadOnConstInBaseWithBadImplementationInDerived.ts, 1, 17)) +>x : Symbol(x, Decl(overloadOnConstInBaseWithBadImplementationInDerived.ts, 1, 29)) +} + +class C implements I { +>C : Symbol(C, Decl(overloadOnConstInBaseWithBadImplementationInDerived.ts, 2, 1)) +>I : Symbol(I, Decl(overloadOnConstInBaseWithBadImplementationInDerived.ts, 0, 0)) + + x1(a: number, callback: (x: 'hi') => number) { // error +>x1 : Symbol(x1, Decl(overloadOnConstInBaseWithBadImplementationInDerived.ts, 4, 22)) +>a : Symbol(a, Decl(overloadOnConstInBaseWithBadImplementationInDerived.ts, 5, 7)) +>callback : Symbol(callback, Decl(overloadOnConstInBaseWithBadImplementationInDerived.ts, 5, 17)) +>x : Symbol(x, Decl(overloadOnConstInBaseWithBadImplementationInDerived.ts, 5, 29)) + } +} diff --git a/tests/baselines/reference/overloadOnConstInBaseWithBadImplementationInDerived.types b/tests/baselines/reference/overloadOnConstInBaseWithBadImplementationInDerived.types new file mode 100644 index 0000000000000..079ae80b364f7 --- /dev/null +++ b/tests/baselines/reference/overloadOnConstInBaseWithBadImplementationInDerived.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/overloadOnConstInBaseWithBadImplementationInDerived.ts === +interface I { +>I : I + + x1(a: number, callback: (x: 'hi') => number); +>x1 : (a: number, callback: (x: "hi") => number) => any +>a : number +>callback : (x: "hi") => number +>x : "hi" +} + +class C implements I { +>C : C +>I : I + + x1(a: number, callback: (x: 'hi') => number) { // error +>x1 : (a: number, callback: (x: "hi") => number) => void +>a : number +>callback : (x: "hi") => number +>x : "hi" + } +} diff --git a/tests/baselines/reference/overloadOnConstInCallback1.errors.txt b/tests/baselines/reference/overloadOnConstInCallback1.errors.txt deleted file mode 100644 index 5d59420493307..0000000000000 --- a/tests/baselines/reference/overloadOnConstInCallback1.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -tests/cases/compiler/overloadOnConstInCallback1.ts(2,29): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - - -==== tests/cases/compiler/overloadOnConstInCallback1.ts (1 errors) ==== - class C { - x1(a: number, callback: (x: 'hi') => number); // error - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - x1(a: number, callback: (x: any) => number) { - callback('hi'); - callback('bye'); - var hm = "hm"; - callback(hm); - } - } \ No newline at end of file diff --git a/tests/baselines/reference/overloadOnConstInCallback1.symbols b/tests/baselines/reference/overloadOnConstInCallback1.symbols new file mode 100644 index 0000000000000..923c726714e1f --- /dev/null +++ b/tests/baselines/reference/overloadOnConstInCallback1.symbols @@ -0,0 +1,30 @@ +=== tests/cases/compiler/overloadOnConstInCallback1.ts === +class C { +>C : Symbol(C, Decl(overloadOnConstInCallback1.ts, 0, 0)) + + x1(a: number, callback: (x: 'hi') => number); // error +>x1 : Symbol(x1, Decl(overloadOnConstInCallback1.ts, 0, 9), Decl(overloadOnConstInCallback1.ts, 1, 49)) +>a : Symbol(a, Decl(overloadOnConstInCallback1.ts, 1, 7)) +>callback : Symbol(callback, Decl(overloadOnConstInCallback1.ts, 1, 17)) +>x : Symbol(x, Decl(overloadOnConstInCallback1.ts, 1, 29)) + + x1(a: number, callback: (x: any) => number) { +>x1 : Symbol(x1, Decl(overloadOnConstInCallback1.ts, 0, 9), Decl(overloadOnConstInCallback1.ts, 1, 49)) +>a : Symbol(a, Decl(overloadOnConstInCallback1.ts, 2, 7)) +>callback : Symbol(callback, Decl(overloadOnConstInCallback1.ts, 2, 17)) +>x : Symbol(x, Decl(overloadOnConstInCallback1.ts, 2, 29)) + + callback('hi'); +>callback : Symbol(callback, Decl(overloadOnConstInCallback1.ts, 2, 17)) + + callback('bye'); +>callback : Symbol(callback, Decl(overloadOnConstInCallback1.ts, 2, 17)) + + var hm = "hm"; +>hm : Symbol(hm, Decl(overloadOnConstInCallback1.ts, 5, 11)) + + callback(hm); +>callback : Symbol(callback, Decl(overloadOnConstInCallback1.ts, 2, 17)) +>hm : Symbol(hm, Decl(overloadOnConstInCallback1.ts, 5, 11)) + } +} diff --git a/tests/baselines/reference/overloadOnConstInCallback1.types b/tests/baselines/reference/overloadOnConstInCallback1.types new file mode 100644 index 0000000000000..c8c123df1e8e3 --- /dev/null +++ b/tests/baselines/reference/overloadOnConstInCallback1.types @@ -0,0 +1,36 @@ +=== tests/cases/compiler/overloadOnConstInCallback1.ts === +class C { +>C : C + + x1(a: number, callback: (x: 'hi') => number); // error +>x1 : (a: number, callback: (x: "hi") => number) => any +>a : number +>callback : (x: "hi") => number +>x : "hi" + + x1(a: number, callback: (x: any) => number) { +>x1 : (a: number, callback: (x: "hi") => number) => any +>a : number +>callback : (x: any) => number +>x : any + + callback('hi'); +>callback('hi') : number +>callback : (x: any) => number +>'hi' : string + + callback('bye'); +>callback('bye') : number +>callback : (x: any) => number +>'bye' : string + + var hm = "hm"; +>hm : string +>"hm" : string + + callback(hm); +>callback(hm) : number +>callback : (x: any) => number +>hm : string + } +} diff --git a/tests/baselines/reference/overloadOnConstInObjectLiteralImplementingAnInterface.errors.txt b/tests/baselines/reference/overloadOnConstInObjectLiteralImplementingAnInterface.errors.txt deleted file mode 100644 index 5788a9e6bbed7..0000000000000 --- a/tests/baselines/reference/overloadOnConstInObjectLiteralImplementingAnInterface.errors.txt +++ /dev/null @@ -1,14 +0,0 @@ -tests/cases/compiler/overloadOnConstInObjectLiteralImplementingAnInterface.ts(2,29): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/overloadOnConstInObjectLiteralImplementingAnInterface.ts(5,35): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - - -==== tests/cases/compiler/overloadOnConstInObjectLiteralImplementingAnInterface.ts (2 errors) ==== - interface I { - x1(a: number, callback: (x: 'hi') => number); - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - } - - var i2: I = { x1: (a: number, cb: (x: 'hi') => number) => { } }; // error - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. \ No newline at end of file diff --git a/tests/baselines/reference/overloadOnConstInObjectLiteralImplementingAnInterface.symbols b/tests/baselines/reference/overloadOnConstInObjectLiteralImplementingAnInterface.symbols new file mode 100644 index 0000000000000..9ea93140085dd --- /dev/null +++ b/tests/baselines/reference/overloadOnConstInObjectLiteralImplementingAnInterface.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/overloadOnConstInObjectLiteralImplementingAnInterface.ts === +interface I { +>I : Symbol(I, Decl(overloadOnConstInObjectLiteralImplementingAnInterface.ts, 0, 0)) + + x1(a: number, callback: (x: 'hi') => number); +>x1 : Symbol(x1, Decl(overloadOnConstInObjectLiteralImplementingAnInterface.ts, 0, 13)) +>a : Symbol(a, Decl(overloadOnConstInObjectLiteralImplementingAnInterface.ts, 1, 7)) +>callback : Symbol(callback, Decl(overloadOnConstInObjectLiteralImplementingAnInterface.ts, 1, 17)) +>x : Symbol(x, Decl(overloadOnConstInObjectLiteralImplementingAnInterface.ts, 1, 29)) +} + +var i2: I = { x1: (a: number, cb: (x: 'hi') => number) => { } }; // error +>i2 : Symbol(i2, Decl(overloadOnConstInObjectLiteralImplementingAnInterface.ts, 4, 3)) +>I : Symbol(I, Decl(overloadOnConstInObjectLiteralImplementingAnInterface.ts, 0, 0)) +>x1 : Symbol(x1, Decl(overloadOnConstInObjectLiteralImplementingAnInterface.ts, 4, 13)) +>a : Symbol(a, Decl(overloadOnConstInObjectLiteralImplementingAnInterface.ts, 4, 19)) +>cb : Symbol(cb, Decl(overloadOnConstInObjectLiteralImplementingAnInterface.ts, 4, 29)) +>x : Symbol(x, Decl(overloadOnConstInObjectLiteralImplementingAnInterface.ts, 4, 35)) + diff --git a/tests/baselines/reference/overloadOnConstInObjectLiteralImplementingAnInterface.types b/tests/baselines/reference/overloadOnConstInObjectLiteralImplementingAnInterface.types new file mode 100644 index 0000000000000..e22162d1e7a9f --- /dev/null +++ b/tests/baselines/reference/overloadOnConstInObjectLiteralImplementingAnInterface.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/overloadOnConstInObjectLiteralImplementingAnInterface.ts === +interface I { +>I : I + + x1(a: number, callback: (x: 'hi') => number); +>x1 : (a: number, callback: (x: "hi") => number) => any +>a : number +>callback : (x: "hi") => number +>x : "hi" +} + +var i2: I = { x1: (a: number, cb: (x: 'hi') => number) => { } }; // error +>i2 : I +>I : I +>{ x1: (a: number, cb: (x: 'hi') => number) => { } } : { x1: (a: number, cb: (x: "hi") => number) => void; } +>x1 : (a: number, cb: (x: "hi") => number) => void +>(a: number, cb: (x: 'hi') => number) => { } : (a: number, cb: (x: "hi") => number) => void +>a : number +>cb : (x: "hi") => number +>x : "hi" + diff --git a/tests/baselines/reference/overloadOnConstInheritance2.errors.txt b/tests/baselines/reference/overloadOnConstInheritance2.errors.txt index 4b502f145a690..3e25a825d1a68 100644 --- a/tests/baselines/reference/overloadOnConstInheritance2.errors.txt +++ b/tests/baselines/reference/overloadOnConstInheritance2.errors.txt @@ -1,11 +1,11 @@ tests/cases/compiler/overloadOnConstInheritance2.ts(5,11): error TS2430: Interface 'Deriver' incorrectly extends interface 'Base'. Types of property 'addEventListener' are incompatible. Type '(x: "bar") => string' is not assignable to type '{ (x: string): any; (x: "foo"): string; }'. - Type '(x: "bar") => string' provides no match for the signature '(x: string): any' -tests/cases/compiler/overloadOnConstInheritance2.ts(6,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. + Types of parameters 'x' and 'x' are incompatible. + Type '"bar"' is not assignable to type '"foo"'. -==== tests/cases/compiler/overloadOnConstInheritance2.ts (2 errors) ==== +==== tests/cases/compiler/overloadOnConstInheritance2.ts (1 errors) ==== interface Base { addEventListener(x: string): any; addEventListener(x: 'foo'): string; @@ -15,9 +15,8 @@ tests/cases/compiler/overloadOnConstInheritance2.ts(6,5): error TS2382: Speciali !!! error TS2430: Interface 'Deriver' incorrectly extends interface 'Base'. !!! error TS2430: Types of property 'addEventListener' are incompatible. !!! error TS2430: Type '(x: "bar") => string' is not assignable to type '{ (x: string): any; (x: "foo"): string; }'. -!!! error TS2430: Type '(x: "bar") => string' provides no match for the signature '(x: string): any' +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type '"bar"' is not assignable to type '"foo"'. addEventListener(x: 'bar'): string; // shouldn't need to redeclare the string overload - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. } \ No newline at end of file diff --git a/tests/baselines/reference/overloadOnConstInheritance3.errors.txt b/tests/baselines/reference/overloadOnConstInheritance3.errors.txt deleted file mode 100644 index 6d9f9b00692fa..0000000000000 --- a/tests/baselines/reference/overloadOnConstInheritance3.errors.txt +++ /dev/null @@ -1,27 +0,0 @@ -tests/cases/compiler/overloadOnConstInheritance3.ts(4,11): error TS2430: Interface 'Deriver' incorrectly extends interface 'Base'. - Types of property 'addEventListener' are incompatible. - Type '{ (x: "bar"): string; (x: "foo"): string; }' is not assignable to type '(x: string) => any'. - Type '{ (x: "bar"): string; (x: "foo"): string; }' provides no match for the signature '(x: string): any' -tests/cases/compiler/overloadOnConstInheritance3.ts(6,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/overloadOnConstInheritance3.ts(7,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - - -==== tests/cases/compiler/overloadOnConstInheritance3.ts (3 errors) ==== - interface Base { - addEventListener(x: string): any; - } - interface Deriver extends Base { - ~~~~~~~ -!!! error TS2430: Interface 'Deriver' incorrectly extends interface 'Base'. -!!! error TS2430: Types of property 'addEventListener' are incompatible. -!!! error TS2430: Type '{ (x: "bar"): string; (x: "foo"): string; }' is not assignable to type '(x: string) => any'. -!!! error TS2430: Type '{ (x: "bar"): string; (x: "foo"): string; }' provides no match for the signature '(x: string): any' - // shouldn't need to redeclare the string overload - addEventListener(x: 'bar'): string; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - addEventListener(x: 'foo'): string; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - } - \ No newline at end of file diff --git a/tests/baselines/reference/overloadOnConstInheritance3.symbols b/tests/baselines/reference/overloadOnConstInheritance3.symbols new file mode 100644 index 0000000000000..32d07b19285d6 --- /dev/null +++ b/tests/baselines/reference/overloadOnConstInheritance3.symbols @@ -0,0 +1,22 @@ +=== tests/cases/compiler/overloadOnConstInheritance3.ts === +interface Base { +>Base : Symbol(Base, Decl(overloadOnConstInheritance3.ts, 0, 0)) + + addEventListener(x: string): any; +>addEventListener : Symbol(addEventListener, Decl(overloadOnConstInheritance3.ts, 0, 16)) +>x : Symbol(x, Decl(overloadOnConstInheritance3.ts, 1, 21)) +} +interface Deriver extends Base { +>Deriver : Symbol(Deriver, Decl(overloadOnConstInheritance3.ts, 2, 1)) +>Base : Symbol(Base, Decl(overloadOnConstInheritance3.ts, 0, 0)) + + // shouldn't need to redeclare the string overload + addEventListener(x: 'bar'): string; +>addEventListener : Symbol(addEventListener, Decl(overloadOnConstInheritance3.ts, 3, 32), Decl(overloadOnConstInheritance3.ts, 5, 39)) +>x : Symbol(x, Decl(overloadOnConstInheritance3.ts, 5, 21)) + + addEventListener(x: 'foo'): string; +>addEventListener : Symbol(addEventListener, Decl(overloadOnConstInheritance3.ts, 3, 32), Decl(overloadOnConstInheritance3.ts, 5, 39)) +>x : Symbol(x, Decl(overloadOnConstInheritance3.ts, 6, 21)) +} + diff --git a/tests/baselines/reference/overloadOnConstInheritance3.types b/tests/baselines/reference/overloadOnConstInheritance3.types new file mode 100644 index 0000000000000..bd8d4ba1917d1 --- /dev/null +++ b/tests/baselines/reference/overloadOnConstInheritance3.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/overloadOnConstInheritance3.ts === +interface Base { +>Base : Base + + addEventListener(x: string): any; +>addEventListener : (x: string) => any +>x : string +} +interface Deriver extends Base { +>Deriver : Deriver +>Base : Base + + // shouldn't need to redeclare the string overload + addEventListener(x: 'bar'): string; +>addEventListener : { (x: "bar"): string; (x: "foo"): string; } +>x : "bar" + + addEventListener(x: 'foo'): string; +>addEventListener : { (x: "bar"): string; (x: "foo"): string; } +>x : "foo" +} + diff --git a/tests/baselines/reference/overloadOnConstInheritance4.errors.txt b/tests/baselines/reference/overloadOnConstInheritance4.errors.txt deleted file mode 100644 index 5420002340893..0000000000000 --- a/tests/baselines/reference/overloadOnConstInheritance4.errors.txt +++ /dev/null @@ -1,21 +0,0 @@ -tests/cases/compiler/overloadOnConstInheritance4.ts(2,29): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/overloadOnConstInheritance4.ts(5,29): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/overloadOnConstInheritance4.ts(6,29): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - - -==== tests/cases/compiler/overloadOnConstInheritance4.ts (3 errors) ==== - interface I { - x1(a: number, callback: (x: 'hi') => number); - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - } - class C implements I { - x1(a: number, callback: (x: 'hi') => number); - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - x1(a: number, callback: (x: 'hi') => number) { - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/overloadOnConstInheritance4.symbols b/tests/baselines/reference/overloadOnConstInheritance4.symbols new file mode 100644 index 0000000000000..9bfa61e6aa902 --- /dev/null +++ b/tests/baselines/reference/overloadOnConstInheritance4.symbols @@ -0,0 +1,28 @@ +=== tests/cases/compiler/overloadOnConstInheritance4.ts === +interface I { +>I : Symbol(I, Decl(overloadOnConstInheritance4.ts, 0, 0)) + + x1(a: number, callback: (x: 'hi') => number); +>x1 : Symbol(x1, Decl(overloadOnConstInheritance4.ts, 0, 13)) +>a : Symbol(a, Decl(overloadOnConstInheritance4.ts, 1, 7)) +>callback : Symbol(callback, Decl(overloadOnConstInheritance4.ts, 1, 17)) +>x : Symbol(x, Decl(overloadOnConstInheritance4.ts, 1, 29)) +} +class C implements I { +>C : Symbol(C, Decl(overloadOnConstInheritance4.ts, 2, 1)) +>I : Symbol(I, Decl(overloadOnConstInheritance4.ts, 0, 0)) + + x1(a: number, callback: (x: 'hi') => number); +>x1 : Symbol(x1, Decl(overloadOnConstInheritance4.ts, 3, 22), Decl(overloadOnConstInheritance4.ts, 4, 49)) +>a : Symbol(a, Decl(overloadOnConstInheritance4.ts, 4, 7)) +>callback : Symbol(callback, Decl(overloadOnConstInheritance4.ts, 4, 17)) +>x : Symbol(x, Decl(overloadOnConstInheritance4.ts, 4, 29)) + + x1(a: number, callback: (x: 'hi') => number) { +>x1 : Symbol(x1, Decl(overloadOnConstInheritance4.ts, 3, 22), Decl(overloadOnConstInheritance4.ts, 4, 49)) +>a : Symbol(a, Decl(overloadOnConstInheritance4.ts, 5, 7)) +>callback : Symbol(callback, Decl(overloadOnConstInheritance4.ts, 5, 17)) +>x : Symbol(x, Decl(overloadOnConstInheritance4.ts, 5, 29)) + } +} + diff --git a/tests/baselines/reference/overloadOnConstInheritance4.types b/tests/baselines/reference/overloadOnConstInheritance4.types new file mode 100644 index 0000000000000..cacd3adfcc96d --- /dev/null +++ b/tests/baselines/reference/overloadOnConstInheritance4.types @@ -0,0 +1,28 @@ +=== tests/cases/compiler/overloadOnConstInheritance4.ts === +interface I { +>I : I + + x1(a: number, callback: (x: 'hi') => number); +>x1 : (a: number, callback: (x: "hi") => number) => any +>a : number +>callback : (x: "hi") => number +>x : "hi" +} +class C implements I { +>C : C +>I : I + + x1(a: number, callback: (x: 'hi') => number); +>x1 : (a: number, callback: (x: "hi") => number) => any +>a : number +>callback : (x: "hi") => number +>x : "hi" + + x1(a: number, callback: (x: 'hi') => number) { +>x1 : (a: number, callback: (x: "hi") => number) => any +>a : number +>callback : (x: "hi") => number +>x : "hi" + } +} + diff --git a/tests/baselines/reference/overloadOnConstNoAnyImplementation.errors.txt b/tests/baselines/reference/overloadOnConstNoAnyImplementation.errors.txt index 2827a97ca82dd..fe5219606ff90 100644 --- a/tests/baselines/reference/overloadOnConstNoAnyImplementation.errors.txt +++ b/tests/baselines/reference/overloadOnConstNoAnyImplementation.errors.txt @@ -1,16 +1,9 @@ -tests/cases/compiler/overloadOnConstNoAnyImplementation.ts(1,28): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/overloadOnConstNoAnyImplementation.ts(2,28): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. tests/cases/compiler/overloadOnConstNoAnyImplementation.ts(9,8): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. -tests/cases/compiler/overloadOnConstNoAnyImplementation.ts(14,7): error TS2381: A signature with an implementation cannot use a string literal type. -==== tests/cases/compiler/overloadOnConstNoAnyImplementation.ts (4 errors) ==== +==== tests/cases/compiler/overloadOnConstNoAnyImplementation.ts (1 errors) ==== function x1(a: number, cb: (x: 'hi') => number); - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. function x1(a: number, cb: (x: 'bye') => number); - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. function x1(a: number, cb: (x: string) => number) { cb('hi'); cb('bye'); @@ -25,6 +18,4 @@ tests/cases/compiler/overloadOnConstNoAnyImplementation.ts(14,7): error TS2381: var cb: (number) => number = (x: number) => 1; x1(1, cb); x1(1, (x: 'hi') => 1); // error - ~~~~~~~~~~~~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. x1(1, (x: string) => 1); \ No newline at end of file diff --git a/tests/baselines/reference/overloadOnConstNoAnyImplementation2.errors.txt b/tests/baselines/reference/overloadOnConstNoAnyImplementation2.errors.txt index aab390c48e8b8..bfd888c991260 100644 --- a/tests/baselines/reference/overloadOnConstNoAnyImplementation2.errors.txt +++ b/tests/baselines/reference/overloadOnConstNoAnyImplementation2.errors.txt @@ -1,21 +1,19 @@ -tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts(2,29): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts(6,29): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts(12,18): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. -tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts(17,9): error TS2381: A signature with an implementation cannot use a string literal type. -tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts(18,9): error TS2381: A signature with an implementation cannot use a string literal type. +tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts(18,9): error TS2345: Argument of type '(x: "bye") => number' is not assignable to parameter of type '(x: "hi") => number'. + Types of parameters 'x' and 'x' are incompatible. + Type '"bye"' is not assignable to type '"hi"'. +tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts(21,9): error TS2345: Argument of type '(x: number) => number' is not assignable to parameter of type '(x: "hi") => number'. + Types of parameters 'x' and 'x' are incompatible. + Type 'number' is not assignable to type '"hi"'. -==== tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts (5 errors) ==== +==== tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts (3 errors) ==== interface I { x1(a: number, callback: (x: 'hi') => number); - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. } class C { x1(a: number, callback: (x: 'hi') => number); - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. x1(a: number, callback: (x: string) => number) { callback('hi'); callback('bye'); @@ -29,11 +27,15 @@ tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts(18,9): error TS2381: var c: C; c.x1(1, (x: 'hi') => { return 1; } ); - ~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. c.x1(1, (x: 'bye') => { return 1; } ); ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. +!!! error TS2345: Argument of type '(x: "bye") => number' is not assignable to parameter of type '(x: "hi") => number'. +!!! error TS2345: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2345: Type '"bye"' is not assignable to type '"hi"'. c.x1(1, (x) => { return 1; } ); - c.x1(1, (x: number) => { return 1; } ); \ No newline at end of file + c.x1(1, (x: number) => { return 1; } ); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: number) => number' is not assignable to parameter of type '(x: "hi") => number'. +!!! error TS2345: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type '"hi"'. \ No newline at end of file diff --git a/tests/baselines/reference/overloadOnConstNoNonSpecializedSignature.errors.txt b/tests/baselines/reference/overloadOnConstNoNonSpecializedSignature.errors.txt deleted file mode 100644 index 6b96abce29e48..0000000000000 --- a/tests/baselines/reference/overloadOnConstNoNonSpecializedSignature.errors.txt +++ /dev/null @@ -1,11 +0,0 @@ -tests/cases/compiler/overloadOnConstNoNonSpecializedSignature.ts(2,4): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - - -==== tests/cases/compiler/overloadOnConstNoNonSpecializedSignature.ts (1 errors) ==== - class C { - x1(a: 'hi'); // error, no non-specialized signature in overload list - ~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - x1(a: string) { } - } - \ No newline at end of file diff --git a/tests/baselines/reference/overloadOnConstNoNonSpecializedSignature.symbols b/tests/baselines/reference/overloadOnConstNoNonSpecializedSignature.symbols new file mode 100644 index 0000000000000..ff7f88f43c383 --- /dev/null +++ b/tests/baselines/reference/overloadOnConstNoNonSpecializedSignature.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/overloadOnConstNoNonSpecializedSignature.ts === +class C { +>C : Symbol(C, Decl(overloadOnConstNoNonSpecializedSignature.ts, 0, 0)) + + x1(a: 'hi'); // error, no non-specialized signature in overload list +>x1 : Symbol(x1, Decl(overloadOnConstNoNonSpecializedSignature.ts, 0, 9), Decl(overloadOnConstNoNonSpecializedSignature.ts, 1, 15)) +>a : Symbol(a, Decl(overloadOnConstNoNonSpecializedSignature.ts, 1, 6)) + + x1(a: string) { } +>x1 : Symbol(x1, Decl(overloadOnConstNoNonSpecializedSignature.ts, 0, 9), Decl(overloadOnConstNoNonSpecializedSignature.ts, 1, 15)) +>a : Symbol(a, Decl(overloadOnConstNoNonSpecializedSignature.ts, 2, 6)) +} + diff --git a/tests/baselines/reference/overloadOnConstNoNonSpecializedSignature.types b/tests/baselines/reference/overloadOnConstNoNonSpecializedSignature.types new file mode 100644 index 0000000000000..09360b748c3a6 --- /dev/null +++ b/tests/baselines/reference/overloadOnConstNoNonSpecializedSignature.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/overloadOnConstNoNonSpecializedSignature.ts === +class C { +>C : C + + x1(a: 'hi'); // error, no non-specialized signature in overload list +>x1 : (a: "hi") => any +>a : "hi" + + x1(a: string) { } +>x1 : (a: "hi") => any +>a : string +} + diff --git a/tests/baselines/reference/overloadOnConstNoStringImplementation.errors.txt b/tests/baselines/reference/overloadOnConstNoStringImplementation.errors.txt deleted file mode 100644 index 12dcdaf97696d..0000000000000 --- a/tests/baselines/reference/overloadOnConstNoStringImplementation.errors.txt +++ /dev/null @@ -1,27 +0,0 @@ -tests/cases/compiler/overloadOnConstNoStringImplementation.ts(1,28): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/overloadOnConstNoStringImplementation.ts(2,28): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/overloadOnConstNoStringImplementation.ts(14,7): error TS2381: A signature with an implementation cannot use a string literal type. - - -==== tests/cases/compiler/overloadOnConstNoStringImplementation.ts (3 errors) ==== - function x2(a: number, cb: (x: 'hi') => number); - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - function x2(a: number, cb: (x: 'bye') => number); - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - function x2(a: number, cb: (x: any) => number) { - cb('hi'); - cb('bye'); - var hm = 'hm'; - cb(hm); // should this work without a string definition? - cb('uh'); - cb(1); - } - - var cb: (number) => number = (x: number) => 1; - x2(1, cb); // error - x2(1, (x: 'hi') => 1); // error - ~~~~~~~~~~~~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. - x2(1, (x: string) => 1); \ No newline at end of file diff --git a/tests/baselines/reference/overloadOnConstNoStringImplementation.symbols b/tests/baselines/reference/overloadOnConstNoStringImplementation.symbols new file mode 100644 index 0000000000000..a8d3bd7953d60 --- /dev/null +++ b/tests/baselines/reference/overloadOnConstNoStringImplementation.symbols @@ -0,0 +1,56 @@ +=== tests/cases/compiler/overloadOnConstNoStringImplementation.ts === +function x2(a: number, cb: (x: 'hi') => number); +>x2 : Symbol(x2, Decl(overloadOnConstNoStringImplementation.ts, 0, 0), Decl(overloadOnConstNoStringImplementation.ts, 0, 48), Decl(overloadOnConstNoStringImplementation.ts, 1, 49)) +>a : Symbol(a, Decl(overloadOnConstNoStringImplementation.ts, 0, 12)) +>cb : Symbol(cb, Decl(overloadOnConstNoStringImplementation.ts, 0, 22)) +>x : Symbol(x, Decl(overloadOnConstNoStringImplementation.ts, 0, 28)) + +function x2(a: number, cb: (x: 'bye') => number); +>x2 : Symbol(x2, Decl(overloadOnConstNoStringImplementation.ts, 0, 0), Decl(overloadOnConstNoStringImplementation.ts, 0, 48), Decl(overloadOnConstNoStringImplementation.ts, 1, 49)) +>a : Symbol(a, Decl(overloadOnConstNoStringImplementation.ts, 1, 12)) +>cb : Symbol(cb, Decl(overloadOnConstNoStringImplementation.ts, 1, 22)) +>x : Symbol(x, Decl(overloadOnConstNoStringImplementation.ts, 1, 28)) + +function x2(a: number, cb: (x: any) => number) { +>x2 : Symbol(x2, Decl(overloadOnConstNoStringImplementation.ts, 0, 0), Decl(overloadOnConstNoStringImplementation.ts, 0, 48), Decl(overloadOnConstNoStringImplementation.ts, 1, 49)) +>a : Symbol(a, Decl(overloadOnConstNoStringImplementation.ts, 2, 12)) +>cb : Symbol(cb, Decl(overloadOnConstNoStringImplementation.ts, 2, 22)) +>x : Symbol(x, Decl(overloadOnConstNoStringImplementation.ts, 2, 28)) + + cb('hi'); +>cb : Symbol(cb, Decl(overloadOnConstNoStringImplementation.ts, 2, 22)) + + cb('bye'); +>cb : Symbol(cb, Decl(overloadOnConstNoStringImplementation.ts, 2, 22)) + + var hm = 'hm'; +>hm : Symbol(hm, Decl(overloadOnConstNoStringImplementation.ts, 5, 7)) + + cb(hm); // should this work without a string definition? +>cb : Symbol(cb, Decl(overloadOnConstNoStringImplementation.ts, 2, 22)) +>hm : Symbol(hm, Decl(overloadOnConstNoStringImplementation.ts, 5, 7)) + + cb('uh'); +>cb : Symbol(cb, Decl(overloadOnConstNoStringImplementation.ts, 2, 22)) + + cb(1); +>cb : Symbol(cb, Decl(overloadOnConstNoStringImplementation.ts, 2, 22)) +} + +var cb: (number) => number = (x: number) => 1; +>cb : Symbol(cb, Decl(overloadOnConstNoStringImplementation.ts, 11, 3)) +>number : Symbol(number, Decl(overloadOnConstNoStringImplementation.ts, 11, 9)) +>x : Symbol(x, Decl(overloadOnConstNoStringImplementation.ts, 11, 30)) + +x2(1, cb); // error +>x2 : Symbol(x2, Decl(overloadOnConstNoStringImplementation.ts, 0, 0), Decl(overloadOnConstNoStringImplementation.ts, 0, 48), Decl(overloadOnConstNoStringImplementation.ts, 1, 49)) +>cb : Symbol(cb, Decl(overloadOnConstNoStringImplementation.ts, 11, 3)) + +x2(1, (x: 'hi') => 1); // error +>x2 : Symbol(x2, Decl(overloadOnConstNoStringImplementation.ts, 0, 0), Decl(overloadOnConstNoStringImplementation.ts, 0, 48), Decl(overloadOnConstNoStringImplementation.ts, 1, 49)) +>x : Symbol(x, Decl(overloadOnConstNoStringImplementation.ts, 13, 7)) + +x2(1, (x: string) => 1); +>x2 : Symbol(x2, Decl(overloadOnConstNoStringImplementation.ts, 0, 0), Decl(overloadOnConstNoStringImplementation.ts, 0, 48), Decl(overloadOnConstNoStringImplementation.ts, 1, 49)) +>x : Symbol(x, Decl(overloadOnConstNoStringImplementation.ts, 14, 7)) + diff --git a/tests/baselines/reference/overloadOnConstNoStringImplementation.types b/tests/baselines/reference/overloadOnConstNoStringImplementation.types new file mode 100644 index 0000000000000..9161620841fa7 --- /dev/null +++ b/tests/baselines/reference/overloadOnConstNoStringImplementation.types @@ -0,0 +1,78 @@ +=== tests/cases/compiler/overloadOnConstNoStringImplementation.ts === +function x2(a: number, cb: (x: 'hi') => number); +>x2 : { (a: number, cb: (x: "hi") => number): any; (a: number, cb: (x: "bye") => number): any; } +>a : number +>cb : (x: "hi") => number +>x : "hi" + +function x2(a: number, cb: (x: 'bye') => number); +>x2 : { (a: number, cb: (x: "hi") => number): any; (a: number, cb: (x: "bye") => number): any; } +>a : number +>cb : (x: "bye") => number +>x : "bye" + +function x2(a: number, cb: (x: any) => number) { +>x2 : { (a: number, cb: (x: "hi") => number): any; (a: number, cb: (x: "bye") => number): any; } +>a : number +>cb : (x: any) => number +>x : any + + cb('hi'); +>cb('hi') : number +>cb : (x: any) => number +>'hi' : string + + cb('bye'); +>cb('bye') : number +>cb : (x: any) => number +>'bye' : string + + var hm = 'hm'; +>hm : string +>'hm' : string + + cb(hm); // should this work without a string definition? +>cb(hm) : number +>cb : (x: any) => number +>hm : string + + cb('uh'); +>cb('uh') : number +>cb : (x: any) => number +>'uh' : string + + cb(1); +>cb(1) : number +>cb : (x: any) => number +>1 : number +} + +var cb: (number) => number = (x: number) => 1; +>cb : (number: any) => number +>number : any +>(x: number) => 1 : (x: number) => number +>x : number +>1 : number + +x2(1, cb); // error +>x2(1, cb) : any +>x2 : { (a: number, cb: (x: "hi") => number): any; (a: number, cb: (x: "bye") => number): any; } +>1 : number +>cb : (number: any) => number + +x2(1, (x: 'hi') => 1); // error +>x2(1, (x: 'hi') => 1) : any +>x2 : { (a: number, cb: (x: "hi") => number): any; (a: number, cb: (x: "bye") => number): any; } +>1 : number +>(x: 'hi') => 1 : (x: "hi") => number +>x : "hi" +>1 : number + +x2(1, (x: string) => 1); +>x2(1, (x: string) => 1) : any +>x2 : { (a: number, cb: (x: "hi") => number): any; (a: number, cb: (x: "bye") => number): any; } +>1 : number +>(x: string) => 1 : (x: string) => number +>x : string +>1 : number + diff --git a/tests/baselines/reference/overloadOnConstNoStringImplementation2.errors.txt b/tests/baselines/reference/overloadOnConstNoStringImplementation2.errors.txt index c85b004f16031..fddfa04eef721 100644 --- a/tests/baselines/reference/overloadOnConstNoStringImplementation2.errors.txt +++ b/tests/baselines/reference/overloadOnConstNoStringImplementation2.errors.txt @@ -1,20 +1,18 @@ -tests/cases/compiler/overloadOnConstNoStringImplementation2.ts(2,29): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/overloadOnConstNoStringImplementation2.ts(6,29): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/overloadOnConstNoStringImplementation2.ts(17,9): error TS2381: A signature with an implementation cannot use a string literal type. -tests/cases/compiler/overloadOnConstNoStringImplementation2.ts(18,9): error TS2381: A signature with an implementation cannot use a string literal type. +tests/cases/compiler/overloadOnConstNoStringImplementation2.ts(18,9): error TS2345: Argument of type '(x: "bye") => number' is not assignable to parameter of type '(x: "hi") => number'. + Types of parameters 'x' and 'x' are incompatible. + Type '"bye"' is not assignable to type '"hi"'. +tests/cases/compiler/overloadOnConstNoStringImplementation2.ts(20,9): error TS2345: Argument of type '(x: number) => number' is not assignable to parameter of type '(x: "hi") => number'. + Types of parameters 'x' and 'x' are incompatible. + Type 'number' is not assignable to type '"hi"'. -==== tests/cases/compiler/overloadOnConstNoStringImplementation2.ts (4 errors) ==== +==== tests/cases/compiler/overloadOnConstNoStringImplementation2.ts (2 errors) ==== interface I { x1(a: number, callback: (x: 'hi') => number); - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. } class C implements I { x1(a: number, callback: (x: 'hi') => number); - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. x1(a: number, callback: (x: any) => number) { callback('hi'); callback('bye'); @@ -26,10 +24,14 @@ tests/cases/compiler/overloadOnConstNoStringImplementation2.ts(18,9): error TS23 var c: C; c.x1(1, (x: 'hi') => { return 1; } ); - ~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. c.x1(1, (x: 'bye') => { return 1; } ); ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. +!!! error TS2345: Argument of type '(x: "bye") => number' is not assignable to parameter of type '(x: "hi") => number'. +!!! error TS2345: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2345: Type '"bye"' is not assignable to type '"hi"'. c.x1(1, (x: string) => { return 1; } ); - c.x1(1, (x: number) => { return 1; } ); \ No newline at end of file + c.x1(1, (x: number) => { return 1; } ); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: number) => number' is not assignable to parameter of type '(x: "hi") => number'. +!!! error TS2345: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type '"hi"'. \ No newline at end of file diff --git a/tests/baselines/reference/overloadOnConstantsInvalidOverload1.errors.txt b/tests/baselines/reference/overloadOnConstantsInvalidOverload1.errors.txt index 4fea7cc122795..3fe0a43d855c8 100644 --- a/tests/baselines/reference/overloadOnConstantsInvalidOverload1.errors.txt +++ b/tests/baselines/reference/overloadOnConstantsInvalidOverload1.errors.txt @@ -1,9 +1,8 @@ -tests/cases/compiler/overloadOnConstantsInvalidOverload1.ts(6,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/overloadOnConstantsInvalidOverload1.ts(7,10): error TS2381: A signature with an implementation cannot use a string literal type. +tests/cases/compiler/overloadOnConstantsInvalidOverload1.ts(6,10): error TS2394: Overload signature is not compatible with function implementation. tests/cases/compiler/overloadOnConstantsInvalidOverload1.ts(11,5): error TS2345: Argument of type '"HI"' is not assignable to parameter of type '"SPAN"'. -==== tests/cases/compiler/overloadOnConstantsInvalidOverload1.ts (3 errors) ==== +==== tests/cases/compiler/overloadOnConstantsInvalidOverload1.ts (2 errors) ==== class Base { foo() { } } class Derived1 extends Base { bar() { } } class Derived2 extends Base { baz() { } } @@ -11,10 +10,8 @@ tests/cases/compiler/overloadOnConstantsInvalidOverload1.ts(11,5): error TS2345: function foo(name: "SPAN"): Derived1; ~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. +!!! error TS2394: Overload signature is not compatible with function implementation. function foo(name: "DIV"): Derived2 { - ~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. return null; } diff --git a/tests/baselines/reference/overloadingOnConstants2.errors.txt b/tests/baselines/reference/overloadingOnConstants2.errors.txt index b448deaadc75b..f50a6bbd8c3a0 100644 --- a/tests/baselines/reference/overloadingOnConstants2.errors.txt +++ b/tests/baselines/reference/overloadingOnConstants2.errors.txt @@ -1,10 +1,9 @@ -tests/cases/compiler/overloadingOnConstants2.ts(8,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/overloadingOnConstants2.ts(9,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. +tests/cases/compiler/overloadingOnConstants2.ts(9,10): error TS2394: Overload signature is not compatible with function implementation. tests/cases/compiler/overloadingOnConstants2.ts(15,13): error TS2345: Argument of type '"um"' is not assignable to parameter of type '"bye"'. -tests/cases/compiler/overloadingOnConstants2.ts(19,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. +tests/cases/compiler/overloadingOnConstants2.ts(19,10): error TS2394: Overload signature is not compatible with function implementation. -==== tests/cases/compiler/overloadingOnConstants2.ts (4 errors) ==== +==== tests/cases/compiler/overloadingOnConstants2.ts (3 errors) ==== class C { private x = 1; } @@ -13,11 +12,9 @@ tests/cases/compiler/overloadingOnConstants2.ts(19,10): error TS2382: Specialize private y = 1; } function foo(x: "hi", items: string[]): D; - ~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. function foo(x: "bye", items: string[]): E; ~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. +!!! error TS2394: Overload signature is not compatible with function implementation. function foo(x: string, items: string[]): C { return null; } @@ -31,7 +28,7 @@ tests/cases/compiler/overloadingOnConstants2.ts(19,10): error TS2382: Specialize //function bar(x: "hi", items: string[]): D; function bar(x: "bye", items: string[]): E; ~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. +!!! error TS2394: Overload signature is not compatible with function implementation. function bar(x: string, items: string[]): C; function bar(x: string, items: string[]): C { return null; diff --git a/tests/baselines/reference/overloadingOnConstantsInImplementation.errors.txt b/tests/baselines/reference/overloadingOnConstantsInImplementation.errors.txt deleted file mode 100644 index 19afdb26806e3..0000000000000 --- a/tests/baselines/reference/overloadingOnConstantsInImplementation.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -tests/cases/compiler/overloadingOnConstantsInImplementation.ts(1,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/overloadingOnConstantsInImplementation.ts(2,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/overloadingOnConstantsInImplementation.ts(3,10): error TS2381: A signature with an implementation cannot use a string literal type. - - -==== tests/cases/compiler/overloadingOnConstantsInImplementation.ts (3 errors) ==== - function foo(a: 'hi', x: string); - ~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - function foo(a: 'hi', x: string); - ~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - function foo(a: 'hi', x: any) { - ~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. - } \ No newline at end of file diff --git a/tests/baselines/reference/overloadingOnConstantsInImplementation.symbols b/tests/baselines/reference/overloadingOnConstantsInImplementation.symbols new file mode 100644 index 0000000000000..5cf7b2ba92819 --- /dev/null +++ b/tests/baselines/reference/overloadingOnConstantsInImplementation.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/overloadingOnConstantsInImplementation.ts === +function foo(a: 'hi', x: string); +>foo : Symbol(foo, Decl(overloadingOnConstantsInImplementation.ts, 0, 0), Decl(overloadingOnConstantsInImplementation.ts, 0, 33), Decl(overloadingOnConstantsInImplementation.ts, 1, 33)) +>a : Symbol(a, Decl(overloadingOnConstantsInImplementation.ts, 0, 13)) +>x : Symbol(x, Decl(overloadingOnConstantsInImplementation.ts, 0, 21)) + +function foo(a: 'hi', x: string); +>foo : Symbol(foo, Decl(overloadingOnConstantsInImplementation.ts, 0, 0), Decl(overloadingOnConstantsInImplementation.ts, 0, 33), Decl(overloadingOnConstantsInImplementation.ts, 1, 33)) +>a : Symbol(a, Decl(overloadingOnConstantsInImplementation.ts, 1, 13)) +>x : Symbol(x, Decl(overloadingOnConstantsInImplementation.ts, 1, 21)) + +function foo(a: 'hi', x: any) { +>foo : Symbol(foo, Decl(overloadingOnConstantsInImplementation.ts, 0, 0), Decl(overloadingOnConstantsInImplementation.ts, 0, 33), Decl(overloadingOnConstantsInImplementation.ts, 1, 33)) +>a : Symbol(a, Decl(overloadingOnConstantsInImplementation.ts, 2, 13)) +>x : Symbol(x, Decl(overloadingOnConstantsInImplementation.ts, 2, 21)) +} diff --git a/tests/baselines/reference/overloadingOnConstantsInImplementation.types b/tests/baselines/reference/overloadingOnConstantsInImplementation.types new file mode 100644 index 0000000000000..0cdb13e995fcb --- /dev/null +++ b/tests/baselines/reference/overloadingOnConstantsInImplementation.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/overloadingOnConstantsInImplementation.ts === +function foo(a: 'hi', x: string); +>foo : { (a: "hi", x: string): any; (a: "hi", x: string): any; } +>a : "hi" +>x : string + +function foo(a: 'hi', x: string); +>foo : { (a: "hi", x: string): any; (a: "hi", x: string): any; } +>a : "hi" +>x : string + +function foo(a: 'hi', x: any) { +>foo : { (a: "hi", x: string): any; (a: "hi", x: string): any; } +>a : "hi" +>x : any +} diff --git a/tests/baselines/reference/parserIndexMemberDeclaration10.errors.txt b/tests/baselines/reference/parserIndexMemberDeclaration10.errors.txt index d448aaa3f294c..1e94ed36b231b 100644 --- a/tests/baselines/reference/parserIndexMemberDeclaration10.errors.txt +++ b/tests/baselines/reference/parserIndexMemberDeclaration10.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts(2,11): error TS1030: 'static' modifier already seen. +tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts(2,4): error TS1071: 'static' modifier cannot appear on an index signature. ==== tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts (1 errors) ==== class C { static static [x: string]: string; - ~~~~~~ -!!! error TS1030: 'static' modifier already seen. + ~~~~~~ +!!! error TS1071: 'static' modifier cannot appear on an index signature. } \ No newline at end of file diff --git a/tests/baselines/reference/parserIndexMemberDeclaration6.errors.txt b/tests/baselines/reference/parserIndexMemberDeclaration6.errors.txt index 713031dbe4fe7..df15ae5950e1c 100644 --- a/tests/baselines/reference/parserIndexMemberDeclaration6.errors.txt +++ b/tests/baselines/reference/parserIndexMemberDeclaration6.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration6.ts(2,4): error TS1145: Modifiers not permitted on index signature members. +tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration6.ts(2,4): error TS1071: 'static' modifier cannot appear on an index signature. ==== tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration6.ts (1 errors) ==== class C { static [x: string]: string; ~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'static' modifier cannot appear on an index signature. } \ No newline at end of file diff --git a/tests/baselines/reference/parserIndexMemberDeclaration7.errors.txt b/tests/baselines/reference/parserIndexMemberDeclaration7.errors.txt index 64984ee642f2b..ebbfaf8af4d94 100644 --- a/tests/baselines/reference/parserIndexMemberDeclaration7.errors.txt +++ b/tests/baselines/reference/parserIndexMemberDeclaration7.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration7.ts(2,4): error TS1145: Modifiers not permitted on index signature members. +tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration7.ts(2,4): error TS1071: 'public' modifier cannot appear on an index signature. ==== tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration7.ts (1 errors) ==== class C { public [x: string]: string; ~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'public' modifier cannot appear on an index signature. } \ No newline at end of file diff --git a/tests/baselines/reference/parserIndexMemberDeclaration8.errors.txt b/tests/baselines/reference/parserIndexMemberDeclaration8.errors.txt index 1fffaa299ceab..4a5eec13cb56c 100644 --- a/tests/baselines/reference/parserIndexMemberDeclaration8.errors.txt +++ b/tests/baselines/reference/parserIndexMemberDeclaration8.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration8.ts(2,4): error TS1145: Modifiers not permitted on index signature members. +tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration8.ts(2,4): error TS1071: 'private' modifier cannot appear on an index signature. ==== tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration8.ts (1 errors) ==== class C { private [x: string]: string; ~~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'private' modifier cannot appear on an index signature. } \ No newline at end of file diff --git a/tests/baselines/reference/parserIndexMemberDeclaration9.errors.txt b/tests/baselines/reference/parserIndexMemberDeclaration9.errors.txt index 493a7894499f2..88360adcd701a 100644 --- a/tests/baselines/reference/parserIndexMemberDeclaration9.errors.txt +++ b/tests/baselines/reference/parserIndexMemberDeclaration9.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration9.ts(2,4): error TS1031: 'export' modifier cannot appear on a class element. +tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration9.ts(2,4): error TS1071: 'export' modifier cannot appear on an index signature. ==== tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration9.ts (1 errors) ==== class C { export [x: string]: string; ~~~~~~ -!!! error TS1031: 'export' modifier cannot appear on a class element. +!!! error TS1071: 'export' modifier cannot appear on an index signature. } \ No newline at end of file diff --git a/tests/baselines/reference/parserModifierOnPropertySignature1.errors.txt b/tests/baselines/reference/parserModifierOnPropertySignature1.errors.txt index 4c8750a80c4bc..1ddb9712bf250 100644 --- a/tests/baselines/reference/parserModifierOnPropertySignature1.errors.txt +++ b/tests/baselines/reference/parserModifierOnPropertySignature1.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserModifierOnPropertySignature1.ts(2,5): error TS1131: Property or signature expected. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserModifierOnPropertySignature1.ts(2,5): error TS1070: 'public' modifier cannot appear on a type member. ==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserModifierOnPropertySignature1.ts (1 errors) ==== interface Foo{ public biz; ~~~~~~ -!!! error TS1131: Property or signature expected. +!!! error TS1070: 'public' modifier cannot appear on a type member. } \ No newline at end of file diff --git a/tests/baselines/reference/parserSymbolIndexer3.errors.txt b/tests/baselines/reference/parserSymbolIndexer3.errors.txt index 5484a096d4ce0..27d3a522b3ea2 100644 --- a/tests/baselines/reference/parserSymbolIndexer3.errors.txt +++ b/tests/baselines/reference/parserSymbolIndexer3.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer3.ts(2,13): error TS1023: An index signature parameter type must be 'string' or 'number'. +tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer3.ts(2,5): error TS1071: 'static' modifier cannot appear on an index signature. ==== tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer3.ts (1 errors) ==== class C { static [s: symbol]: string; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. + ~~~~~~ +!!! error TS1071: 'static' modifier cannot appear on an index signature. } \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution1_classic.errors.txt b/tests/baselines/reference/pathMappingBasedModuleResolution1_classic.errors.txt new file mode 100644 index 0000000000000..85e25ec99fb93 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution1_classic.errors.txt @@ -0,0 +1,7 @@ +error TS5060: Option 'paths' cannot be used without specifying '--baseUrl' option. + + +!!! error TS5060: Option 'paths' cannot be used without specifying '--baseUrl' option. +==== c:/root/f1.ts (0 errors) ==== + export var x = 1; + \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution1_classic.js b/tests/baselines/reference/pathMappingBasedModuleResolution1_classic.js new file mode 100644 index 0000000000000..1a1bd387dce94 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution1_classic.js @@ -0,0 +1,9 @@ +//// [f1.ts] +export var x = 1; + + +//// [f1.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.x = 1; +}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution1_classic.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution1_classic.trace.json new file mode 100644 index 0000000000000..0637a088a01e8 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution1_classic.trace.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution1_node.errors.txt b/tests/baselines/reference/pathMappingBasedModuleResolution1_node.errors.txt new file mode 100644 index 0000000000000..85e25ec99fb93 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution1_node.errors.txt @@ -0,0 +1,7 @@ +error TS5060: Option 'paths' cannot be used without specifying '--baseUrl' option. + + +!!! error TS5060: Option 'paths' cannot be used without specifying '--baseUrl' option. +==== c:/root/f1.ts (0 errors) ==== + export var x = 1; + \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution1_node.js b/tests/baselines/reference/pathMappingBasedModuleResolution1_node.js new file mode 100644 index 0000000000000..5fcaa23b976df --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution1_node.js @@ -0,0 +1,7 @@ +//// [f1.ts] +export var x = 1; + + +//// [f1.js] +"use strict"; +exports.x = 1; diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution1_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution1_node.trace.json new file mode 100644 index 0000000000000..0637a088a01e8 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution1_node.trace.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution2_classic.errors.txt b/tests/baselines/reference/pathMappingBasedModuleResolution2_classic.errors.txt new file mode 100644 index 0000000000000..ad954bd142b54 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution2_classic.errors.txt @@ -0,0 +1,8 @@ +error TS5061: Pattern '*1*' can have at most one '*' character +error TS5062: Substitution '*2*' in pattern '*1*' in can have at most one '*' character + + +!!! error TS5061: Pattern '*1*' can have at most one '*' character +!!! error TS5062: Substitution '*2*' in pattern '*1*' in can have at most one '*' character +==== tests/cases/compiler/root/src/folder1/file1.ts (0 errors) ==== + export var x = 1; \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution2_classic.js b/tests/baselines/reference/pathMappingBasedModuleResolution2_classic.js new file mode 100644 index 0000000000000..52dab845bb296 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution2_classic.js @@ -0,0 +1,8 @@ +//// [file1.ts] +export var x = 1; + +//// [file1.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.x = 1; +}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution2_classic.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution2_classic.trace.json new file mode 100644 index 0000000000000..0637a088a01e8 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution2_classic.trace.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution2_node.errors.txt b/tests/baselines/reference/pathMappingBasedModuleResolution2_node.errors.txt new file mode 100644 index 0000000000000..ad954bd142b54 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution2_node.errors.txt @@ -0,0 +1,8 @@ +error TS5061: Pattern '*1*' can have at most one '*' character +error TS5062: Substitution '*2*' in pattern '*1*' in can have at most one '*' character + + +!!! error TS5061: Pattern '*1*' can have at most one '*' character +!!! error TS5062: Substitution '*2*' in pattern '*1*' in can have at most one '*' character +==== tests/cases/compiler/root/src/folder1/file1.ts (0 errors) ==== + export var x = 1; \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution2_node.js b/tests/baselines/reference/pathMappingBasedModuleResolution2_node.js new file mode 100644 index 0000000000000..8c8b5c9a926fe --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution2_node.js @@ -0,0 +1,6 @@ +//// [file1.ts] +export var x = 1; + +//// [file1.js] +"use strict"; +exports.x = 1; diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution2_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution2_node.trace.json new file mode 100644 index 0000000000000..0637a088a01e8 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution2_node.trace.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.js b/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.js new file mode 100644 index 0000000000000..15867b085eae9 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.js @@ -0,0 +1,42 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution3_classic.ts] //// + +//// [file1.ts] + +// baseUrl set via command line + +import {x} from "folder2/file2" +declare function use(a: any): void; +use(x.toExponential()); + +//// [file2.ts] +import {x as a} from "./file3" // found with baseurl +import {y as b} from "file4" // found with fallback +export var x = a + b; + +//// [file3.ts] +export var x = 1; + +//// [file4.ts] +export var y = 100; + +//// [file3.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.x = 1; +}); +//// [file4.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.y = 100; +}); +//// [file2.js] +define(["require", "exports", "./file3", "file4"], function (require, exports, file3_1, file4_1) { + "use strict"; + exports.x = file3_1.x + file4_1.y; +}); +//// [file1.js] +// baseUrl set via command line +define(["require", "exports", "folder2/file2"], function (require, exports, file2_1) { + "use strict"; + use(file2_1.x.toExponential()); +}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.symbols new file mode 100644 index 0000000000000..97ec40d4cb4d4 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.symbols @@ -0,0 +1,39 @@ +=== c:/root/folder1/file1.ts === + +// baseUrl set via command line + +import {x} from "folder2/file2" +>x : Symbol(x, Decl(file1.ts, 3, 8)) + +declare function use(a: any): void; +>use : Symbol(use, Decl(file1.ts, 3, 31)) +>a : Symbol(a, Decl(file1.ts, 4, 21)) + +use(x.toExponential()); +>use : Symbol(use, Decl(file1.ts, 3, 31)) +>x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(file1.ts, 3, 8)) +>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) + +=== c:/root/folder2/file2.ts === +import {x as a} from "./file3" // found with baseurl +>x : Symbol(a, Decl(file2.ts, 0, 8)) +>a : Symbol(a, Decl(file2.ts, 0, 8)) + +import {y as b} from "file4" // found with fallback +>y : Symbol(b, Decl(file2.ts, 1, 8)) +>b : Symbol(b, Decl(file2.ts, 1, 8)) + +export var x = a + b; +>x : Symbol(x, Decl(file2.ts, 2, 10)) +>a : Symbol(a, Decl(file2.ts, 0, 8)) +>b : Symbol(b, Decl(file2.ts, 1, 8)) + +=== c:/root/folder2/file3.ts === +export var x = 1; +>x : Symbol(x, Decl(file3.ts, 0, 10)) + +=== c:/file4.ts === +export var y = 100; +>y : Symbol(y, Decl(file4.ts, 0, 10)) + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.trace.json new file mode 100644 index 0000000000000..513198c50b0c4 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.trace.json @@ -0,0 +1,24 @@ +[ + "======== Resolving module 'folder2/file2' from 'c:/root/folder1/file1.ts'. ========", + "Explicitly specified module resolution kind: 'Classic'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'folder2/file2'", + "Resolving module name 'folder2/file2' relative to base url 'c:/root' - 'c:/root/folder2/file2'.", + "File 'c:/root/folder2/file2.ts' exist - use it as a module resolution result.", + "======== Module name 'folder2/file2' was successfully resolved to 'c:/root/folder2/file2.ts'. ========", + "======== Resolving module './file3' from 'c:/root/folder2/file2.ts'. ========", + "Explicitly specified module resolution kind: 'Classic'.", + "File 'c:/root/folder2/file3.ts' exist - use it as a module resolution result.", + "======== Module name './file3' was successfully resolved to 'c:/root/folder2/file3.ts'. ========", + "======== Resolving module 'file4' from 'c:/root/folder2/file2.ts'. ========", + "Explicitly specified module resolution kind: 'Classic'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'file4'", + "Resolving module name 'file4' relative to base url 'c:/root' - 'c:/root/file4'.", + "File 'c:/root/file4.ts' does not exist.", + "File 'c:/root/file4.d.ts' does not exist.", + "File 'c:/root/folder2/file4.ts' does not exist.", + "File 'c:/root/folder2/file4.d.ts' does not exist.", + "File 'c:/root/file4.ts' does not exist.", + "File 'c:/root/file4.d.ts' does not exist.", + "File 'c:/file4.ts' exist - use it as a module resolution result.", + "======== Module name 'file4' was successfully resolved to 'c:/file4.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.types b/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.types new file mode 100644 index 0000000000000..359811ff3b20d --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.types @@ -0,0 +1,44 @@ +=== c:/root/folder1/file1.ts === + +// baseUrl set via command line + +import {x} from "folder2/file2" +>x : number + +declare function use(a: any): void; +>use : (a: any) => void +>a : any + +use(x.toExponential()); +>use(x.toExponential()) : void +>use : (a: any) => void +>x.toExponential() : string +>x.toExponential : (fractionDigits?: number) => string +>x : number +>toExponential : (fractionDigits?: number) => string + +=== c:/root/folder2/file2.ts === +import {x as a} from "./file3" // found with baseurl +>x : number +>a : number + +import {y as b} from "file4" // found with fallback +>y : number +>b : number + +export var x = a + b; +>x : number +>a + b : number +>a : number +>b : number + +=== c:/root/folder2/file3.ts === +export var x = 1; +>x : number +>1 : number + +=== c:/file4.ts === +export var y = 100; +>y : number +>100 : number + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_node.js b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.js new file mode 100644 index 0000000000000..cbff608753010 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.js @@ -0,0 +1,34 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution3_node.ts] //// + +//// [file1.ts] + +// baseUrl set via command line + +import {x} from "folder2/file2" +declare function use(a: any): void; +use(x.toExponential()); + +//// [file2.ts] +import {x as a} from "./file3" // found with baseurl +import {y as b} from "file4" // found with fallback +export var x = a + b; + +//// [file3.ts] +export var x = 1; + +//// [index.d.ts] +export var y: number; + +//// [file3.js] +"use strict"; +exports.x = 1; +//// [file2.js] +"use strict"; +var file3_1 = require("./file3"); // found with baseurl +var file4_1 = require("file4"); // found with fallback +exports.x = file3_1.x + file4_1.y; +//// [file1.js] +// baseUrl set via command line +"use strict"; +var file2_1 = require("folder2/file2"); +use(file2_1.x.toExponential()); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_node.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.symbols new file mode 100644 index 0000000000000..487dea2fb8983 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.symbols @@ -0,0 +1,39 @@ +=== c:/root/folder1/file1.ts === + +// baseUrl set via command line + +import {x} from "folder2/file2" +>x : Symbol(x, Decl(file1.ts, 3, 8)) + +declare function use(a: any): void; +>use : Symbol(use, Decl(file1.ts, 3, 31)) +>a : Symbol(a, Decl(file1.ts, 4, 21)) + +use(x.toExponential()); +>use : Symbol(use, Decl(file1.ts, 3, 31)) +>x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(file1.ts, 3, 8)) +>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) + +=== c:/root/folder2/file2.ts === +import {x as a} from "./file3" // found with baseurl +>x : Symbol(a, Decl(file2.ts, 0, 8)) +>a : Symbol(a, Decl(file2.ts, 0, 8)) + +import {y as b} from "file4" // found with fallback +>y : Symbol(b, Decl(file2.ts, 1, 8)) +>b : Symbol(b, Decl(file2.ts, 1, 8)) + +export var x = a + b; +>x : Symbol(x, Decl(file2.ts, 2, 10)) +>a : Symbol(a, Decl(file2.ts, 0, 8)) +>b : Symbol(b, Decl(file2.ts, 1, 8)) + +=== c:/root/folder2/file3.ts === +export var x = 1; +>x : Symbol(x, Decl(file3.ts, 0, 10)) + +=== c:/node_modules/file4/index.d.ts === +export var y: number; +>y : Symbol(y, Decl(index.d.ts, 0, 10)) + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.trace.json new file mode 100644 index 0000000000000..6d0de807bc03c --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.trace.json @@ -0,0 +1,49 @@ +[ + "======== Resolving module 'folder2/file2' from 'c:/root/folder1/file1.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'folder2/file2'", + "Resolving module name 'folder2/file2' relative to base url 'c:/root' - 'c:/root/folder2/file2'.", + "Loading module as file / folder, candidate module location 'c:/root/folder2/file2'.", + "File 'c:/root/folder2/file2.ts' exist - use it as a module resolution result.", + "======== Module name 'folder2/file2' was successfully resolved to 'c:/root/folder2/file2.ts'. ========", + "======== Resolving module './file3' from 'c:/root/folder2/file2.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module as file / folder, candidate module location 'c:/root/folder2/file3'.", + "File 'c:/root/folder2/file3.ts' exist - use it as a module resolution result.", + "======== Module name './file3' was successfully resolved to 'c:/root/folder2/file3.ts'. ========", + "======== Resolving module 'file4' from 'c:/root/folder2/file2.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'file4'", + "Resolving module name 'file4' relative to base url 'c:/root' - 'c:/root/file4'.", + "Loading module as file / folder, candidate module location 'c:/root/file4'.", + "File 'c:/root/file4.ts' does not exist.", + "File 'c:/root/file4.tsx' does not exist.", + "File 'c:/root/file4.d.ts' does not exist.", + "File 'c:/root/file4/package.json' does not exist.", + "File 'c:/root/file4/index.ts' does not exist.", + "File 'c:/root/file4/index.tsx' does not exist.", + "File 'c:/root/file4/index.d.ts' does not exist.", + "Loading module 'file4' from 'node_modules' folder.", + "File 'c:/root/folder2/node_modules/file4.ts' does not exist.", + "File 'c:/root/folder2/node_modules/file4.tsx' does not exist.", + "File 'c:/root/folder2/node_modules/file4.d.ts' does not exist.", + "File 'c:/root/folder2/node_modules/file4/package.json' does not exist.", + "File 'c:/root/folder2/node_modules/file4/index.ts' does not exist.", + "File 'c:/root/folder2/node_modules/file4/index.tsx' does not exist.", + "File 'c:/root/folder2/node_modules/file4/index.d.ts' does not exist.", + "File 'c:/root/node_modules/file4.ts' does not exist.", + "File 'c:/root/node_modules/file4.tsx' does not exist.", + "File 'c:/root/node_modules/file4.d.ts' does not exist.", + "File 'c:/root/node_modules/file4/package.json' does not exist.", + "File 'c:/root/node_modules/file4/index.ts' does not exist.", + "File 'c:/root/node_modules/file4/index.tsx' does not exist.", + "File 'c:/root/node_modules/file4/index.d.ts' does not exist.", + "File 'c:/node_modules/file4.ts' does not exist.", + "File 'c:/node_modules/file4.tsx' does not exist.", + "File 'c:/node_modules/file4.d.ts' does not exist.", + "File 'c:/node_modules/file4/package.json' does not exist.", + "File 'c:/node_modules/file4/index.ts' does not exist.", + "File 'c:/node_modules/file4/index.tsx' does not exist.", + "File 'c:/node_modules/file4/index.d.ts' exist - use it as a module resolution result.", + "======== Module name 'file4' was successfully resolved to 'c:/node_modules/file4/index.d.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_node.types b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.types new file mode 100644 index 0000000000000..78597cf50eff6 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.types @@ -0,0 +1,43 @@ +=== c:/root/folder1/file1.ts === + +// baseUrl set via command line + +import {x} from "folder2/file2" +>x : number + +declare function use(a: any): void; +>use : (a: any) => void +>a : any + +use(x.toExponential()); +>use(x.toExponential()) : void +>use : (a: any) => void +>x.toExponential() : string +>x.toExponential : (fractionDigits?: number) => string +>x : number +>toExponential : (fractionDigits?: number) => string + +=== c:/root/folder2/file2.ts === +import {x as a} from "./file3" // found with baseurl +>x : number +>a : number + +import {y as b} from "file4" // found with fallback +>y : number +>b : number + +export var x = a + b; +>x : number +>a + b : number +>a : number +>b : number + +=== c:/root/folder2/file3.ts === +export var x = 1; +>x : number +>1 : number + +=== c:/node_modules/file4/index.d.ts === +export var y: number; +>y : number + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.js b/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.js new file mode 100644 index 0000000000000..c1de8cea6c91a --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.js @@ -0,0 +1,38 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution4_classic.ts] //// + +//// [file1.ts] +import {x} from "folder2/file2" +declare function use(a: any): void; +use(x.toExponential()); + +//// [file2.ts] +import {x as a} from "./file3" // found with baseurl +import {y as b} from "file4" // found with fallback +export var x = a + b; + +//// [file3.ts] +export var x = 1; + +//// [file4.ts] +export var y = 100; + +//// [file3.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.x = 1; +}); +//// [file4.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.y = 100; +}); +//// [file2.js] +define(["require", "exports", "./file3", "file4"], function (require, exports, file3_1, file4_1) { + "use strict"; + exports.x = file3_1.x + file4_1.y; +}); +//// [file1.js] +define(["require", "exports", "folder2/file2"], function (require, exports, file2_1) { + "use strict"; + use(file2_1.x.toExponential()); +}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.symbols new file mode 100644 index 0000000000000..7c1943dae462b --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.symbols @@ -0,0 +1,36 @@ +=== c:/root/folder1/file1.ts === +import {x} from "folder2/file2" +>x : Symbol(x, Decl(file1.ts, 0, 8)) + +declare function use(a: any): void; +>use : Symbol(use, Decl(file1.ts, 0, 31)) +>a : Symbol(a, Decl(file1.ts, 1, 21)) + +use(x.toExponential()); +>use : Symbol(use, Decl(file1.ts, 0, 31)) +>x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(file1.ts, 0, 8)) +>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) + +=== c:/root/folder2/file2.ts === +import {x as a} from "./file3" // found with baseurl +>x : Symbol(a, Decl(file2.ts, 0, 8)) +>a : Symbol(a, Decl(file2.ts, 0, 8)) + +import {y as b} from "file4" // found with fallback +>y : Symbol(b, Decl(file2.ts, 1, 8)) +>b : Symbol(b, Decl(file2.ts, 1, 8)) + +export var x = a + b; +>x : Symbol(x, Decl(file2.ts, 2, 10)) +>a : Symbol(a, Decl(file2.ts, 0, 8)) +>b : Symbol(b, Decl(file2.ts, 1, 8)) + +=== c:/root/folder2/file3.ts === +export var x = 1; +>x : Symbol(x, Decl(file3.ts, 0, 10)) + +=== c:/file4.ts === +export var y = 100; +>y : Symbol(y, Decl(file4.ts, 0, 10)) + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.trace.json new file mode 100644 index 0000000000000..513198c50b0c4 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.trace.json @@ -0,0 +1,24 @@ +[ + "======== Resolving module 'folder2/file2' from 'c:/root/folder1/file1.ts'. ========", + "Explicitly specified module resolution kind: 'Classic'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'folder2/file2'", + "Resolving module name 'folder2/file2' relative to base url 'c:/root' - 'c:/root/folder2/file2'.", + "File 'c:/root/folder2/file2.ts' exist - use it as a module resolution result.", + "======== Module name 'folder2/file2' was successfully resolved to 'c:/root/folder2/file2.ts'. ========", + "======== Resolving module './file3' from 'c:/root/folder2/file2.ts'. ========", + "Explicitly specified module resolution kind: 'Classic'.", + "File 'c:/root/folder2/file3.ts' exist - use it as a module resolution result.", + "======== Module name './file3' was successfully resolved to 'c:/root/folder2/file3.ts'. ========", + "======== Resolving module 'file4' from 'c:/root/folder2/file2.ts'. ========", + "Explicitly specified module resolution kind: 'Classic'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'file4'", + "Resolving module name 'file4' relative to base url 'c:/root' - 'c:/root/file4'.", + "File 'c:/root/file4.ts' does not exist.", + "File 'c:/root/file4.d.ts' does not exist.", + "File 'c:/root/folder2/file4.ts' does not exist.", + "File 'c:/root/folder2/file4.d.ts' does not exist.", + "File 'c:/root/file4.ts' does not exist.", + "File 'c:/root/file4.d.ts' does not exist.", + "File 'c:/file4.ts' exist - use it as a module resolution result.", + "======== Module name 'file4' was successfully resolved to 'c:/file4.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.types b/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.types new file mode 100644 index 0000000000000..d225246e2f949 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.types @@ -0,0 +1,41 @@ +=== c:/root/folder1/file1.ts === +import {x} from "folder2/file2" +>x : number + +declare function use(a: any): void; +>use : (a: any) => void +>a : any + +use(x.toExponential()); +>use(x.toExponential()) : void +>use : (a: any) => void +>x.toExponential() : string +>x.toExponential : (fractionDigits?: number) => string +>x : number +>toExponential : (fractionDigits?: number) => string + +=== c:/root/folder2/file2.ts === +import {x as a} from "./file3" // found with baseurl +>x : number +>a : number + +import {y as b} from "file4" // found with fallback +>y : number +>b : number + +export var x = a + b; +>x : number +>a + b : number +>a : number +>b : number + +=== c:/root/folder2/file3.ts === +export var x = 1; +>x : number +>1 : number + +=== c:/file4.ts === +export var y = 100; +>y : number +>100 : number + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4_node.js b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.js new file mode 100644 index 0000000000000..c5a08d55d8bbe --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.js @@ -0,0 +1,30 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution4_node.ts] //// + +//// [file1.ts] +import {x} from "folder2/file2" +declare function use(a: any): void; +use(x.toExponential()); + +//// [file2.ts] +import {x as a} from "./file3" // found with baseurl +import {y as b} from "file4" // found with fallback +export var x = a + b; + +//// [file3.ts] +export var x = 1; + +//// [index.d.ts] +export var y: number; + +//// [file3.js] +"use strict"; +exports.x = 1; +//// [file2.js] +"use strict"; +var file3_1 = require("./file3"); // found with baseurl +var file4_1 = require("file4"); // found with fallback +exports.x = file3_1.x + file4_1.y; +//// [file1.js] +"use strict"; +var file2_1 = require("folder2/file2"); +use(file2_1.x.toExponential()); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4_node.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.symbols new file mode 100644 index 0000000000000..fb1c5be9de6bc --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.symbols @@ -0,0 +1,36 @@ +=== c:/root/folder1/file1.ts === +import {x} from "folder2/file2" +>x : Symbol(x, Decl(file1.ts, 0, 8)) + +declare function use(a: any): void; +>use : Symbol(use, Decl(file1.ts, 0, 31)) +>a : Symbol(a, Decl(file1.ts, 1, 21)) + +use(x.toExponential()); +>use : Symbol(use, Decl(file1.ts, 0, 31)) +>x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(file1.ts, 0, 8)) +>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) + +=== c:/root/folder2/file2.ts === +import {x as a} from "./file3" // found with baseurl +>x : Symbol(a, Decl(file2.ts, 0, 8)) +>a : Symbol(a, Decl(file2.ts, 0, 8)) + +import {y as b} from "file4" // found with fallback +>y : Symbol(b, Decl(file2.ts, 1, 8)) +>b : Symbol(b, Decl(file2.ts, 1, 8)) + +export var x = a + b; +>x : Symbol(x, Decl(file2.ts, 2, 10)) +>a : Symbol(a, Decl(file2.ts, 0, 8)) +>b : Symbol(b, Decl(file2.ts, 1, 8)) + +=== c:/root/folder2/file3.ts === +export var x = 1; +>x : Symbol(x, Decl(file3.ts, 0, 10)) + +=== c:/node_modules/file4/index.d.ts === +export var y: number; +>y : Symbol(y, Decl(index.d.ts, 0, 10)) + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.trace.json new file mode 100644 index 0000000000000..6d0de807bc03c --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.trace.json @@ -0,0 +1,49 @@ +[ + "======== Resolving module 'folder2/file2' from 'c:/root/folder1/file1.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'folder2/file2'", + "Resolving module name 'folder2/file2' relative to base url 'c:/root' - 'c:/root/folder2/file2'.", + "Loading module as file / folder, candidate module location 'c:/root/folder2/file2'.", + "File 'c:/root/folder2/file2.ts' exist - use it as a module resolution result.", + "======== Module name 'folder2/file2' was successfully resolved to 'c:/root/folder2/file2.ts'. ========", + "======== Resolving module './file3' from 'c:/root/folder2/file2.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module as file / folder, candidate module location 'c:/root/folder2/file3'.", + "File 'c:/root/folder2/file3.ts' exist - use it as a module resolution result.", + "======== Module name './file3' was successfully resolved to 'c:/root/folder2/file3.ts'. ========", + "======== Resolving module 'file4' from 'c:/root/folder2/file2.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'file4'", + "Resolving module name 'file4' relative to base url 'c:/root' - 'c:/root/file4'.", + "Loading module as file / folder, candidate module location 'c:/root/file4'.", + "File 'c:/root/file4.ts' does not exist.", + "File 'c:/root/file4.tsx' does not exist.", + "File 'c:/root/file4.d.ts' does not exist.", + "File 'c:/root/file4/package.json' does not exist.", + "File 'c:/root/file4/index.ts' does not exist.", + "File 'c:/root/file4/index.tsx' does not exist.", + "File 'c:/root/file4/index.d.ts' does not exist.", + "Loading module 'file4' from 'node_modules' folder.", + "File 'c:/root/folder2/node_modules/file4.ts' does not exist.", + "File 'c:/root/folder2/node_modules/file4.tsx' does not exist.", + "File 'c:/root/folder2/node_modules/file4.d.ts' does not exist.", + "File 'c:/root/folder2/node_modules/file4/package.json' does not exist.", + "File 'c:/root/folder2/node_modules/file4/index.ts' does not exist.", + "File 'c:/root/folder2/node_modules/file4/index.tsx' does not exist.", + "File 'c:/root/folder2/node_modules/file4/index.d.ts' does not exist.", + "File 'c:/root/node_modules/file4.ts' does not exist.", + "File 'c:/root/node_modules/file4.tsx' does not exist.", + "File 'c:/root/node_modules/file4.d.ts' does not exist.", + "File 'c:/root/node_modules/file4/package.json' does not exist.", + "File 'c:/root/node_modules/file4/index.ts' does not exist.", + "File 'c:/root/node_modules/file4/index.tsx' does not exist.", + "File 'c:/root/node_modules/file4/index.d.ts' does not exist.", + "File 'c:/node_modules/file4.ts' does not exist.", + "File 'c:/node_modules/file4.tsx' does not exist.", + "File 'c:/node_modules/file4.d.ts' does not exist.", + "File 'c:/node_modules/file4/package.json' does not exist.", + "File 'c:/node_modules/file4/index.ts' does not exist.", + "File 'c:/node_modules/file4/index.tsx' does not exist.", + "File 'c:/node_modules/file4/index.d.ts' exist - use it as a module resolution result.", + "======== Module name 'file4' was successfully resolved to 'c:/node_modules/file4/index.d.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4_node.types b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.types new file mode 100644 index 0000000000000..5478a601f0226 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.types @@ -0,0 +1,40 @@ +=== c:/root/folder1/file1.ts === +import {x} from "folder2/file2" +>x : number + +declare function use(a: any): void; +>use : (a: any) => void +>a : any + +use(x.toExponential()); +>use(x.toExponential()) : void +>use : (a: any) => void +>x.toExponential() : string +>x.toExponential : (fractionDigits?: number) => string +>x : number +>toExponential : (fractionDigits?: number) => string + +=== c:/root/folder2/file2.ts === +import {x as a} from "./file3" // found with baseurl +>x : number +>a : number + +import {y as b} from "file4" // found with fallback +>y : number +>b : number + +export var x = a + b; +>x : number +>a + b : number +>a : number +>b : number + +=== c:/root/folder2/file3.ts === +export var x = 1; +>x : number +>1 : number + +=== c:/node_modules/file4/index.d.ts === +export var y: number; +>y : number + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.js b/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.js new file mode 100644 index 0000000000000..24297f85e35bc --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.js @@ -0,0 +1,55 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution5_classic.ts] //// + +//// [file1.ts] +import {x} from "folder2/file1" +import {y} from "folder3/file2" +import {z} from "components/file3" +import {z1} from "file4" + +declare function use(a: any): void; + +use(x.toExponential()); +use(y.toExponential()); +use(z.toExponential()); +use(z1.toExponential()); + +//// [file1.ts] +export var x = 1; + +//// [file2.ts] +export var y = 1; + +//// [file3.ts] +export var z = 1; + +//// [file4.ts] +export var z1 = 1; + +//// [file1.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.x = 1; +}); +//// [file2.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.y = 1; +}); +//// [file3.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.z = 1; +}); +//// [file4.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.z1 = 1; +}); +//// [file1.js] +define(["require", "exports", "folder2/file1", "folder3/file2", "components/file3", "file4"], function (require, exports, file1_1, file2_1, file3_1, file4_1) { + "use strict"; + use(file1_1.x.toExponential()); + use(file2_1.y.toExponential()); + use(file3_1.z.toExponential()); + use(file4_1.z1.toExponential()); +}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.symbols new file mode 100644 index 0000000000000..057b5a622a1b9 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.symbols @@ -0,0 +1,57 @@ +=== c:/root/folder1/file1.ts === +import {x} from "folder2/file1" +>x : Symbol(x, Decl(file1.ts, 0, 8)) + +import {y} from "folder3/file2" +>y : Symbol(y, Decl(file1.ts, 1, 8)) + +import {z} from "components/file3" +>z : Symbol(z, Decl(file1.ts, 2, 8)) + +import {z1} from "file4" +>z1 : Symbol(z1, Decl(file1.ts, 3, 8)) + +declare function use(a: any): void; +>use : Symbol(use, Decl(file1.ts, 3, 24)) +>a : Symbol(a, Decl(file1.ts, 5, 21)) + +use(x.toExponential()); +>use : Symbol(use, Decl(file1.ts, 3, 24)) +>x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(file1.ts, 0, 8)) +>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) + +use(y.toExponential()); +>use : Symbol(use, Decl(file1.ts, 3, 24)) +>y.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) +>y : Symbol(y, Decl(file1.ts, 1, 8)) +>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) + +use(z.toExponential()); +>use : Symbol(use, Decl(file1.ts, 3, 24)) +>z.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) +>z : Symbol(z, Decl(file1.ts, 2, 8)) +>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) + +use(z1.toExponential()); +>use : Symbol(use, Decl(file1.ts, 3, 24)) +>z1.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) +>z1 : Symbol(z1, Decl(file1.ts, 3, 8)) +>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) + +=== c:/root/folder2/file1.ts === +export var x = 1; +>x : Symbol(x, Decl(file1.ts, 0, 10)) + +=== c:/root/generated/folder3/file2.ts === +export var y = 1; +>y : Symbol(y, Decl(file2.ts, 0, 10)) + +=== c:/root/shared/components/file3.ts === +export var z = 1; +>z : Symbol(z, Decl(file3.ts, 0, 10)) + +=== c:/file4.ts === +export var z1 = 1; +>z1 : Symbol(z1, Decl(file4.ts, 0, 10)) + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.trace.json new file mode 100644 index 0000000000000..099acae2aca50 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.trace.json @@ -0,0 +1,46 @@ +[ + "======== Resolving module 'folder2/file1' from 'c:/root/folder1/file1.ts'. ========", + "Module resolution kind is not specified, using 'Classic'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'folder2/file1'", + "'paths' option is specified, looking for a pattern to match module name 'folder2/file1'.", + "Module name 'folder2/file1', matched pattern '*'.", + "Trying substitution '*', candidate module location: 'folder2/file1'.", + "File 'c:/root/folder2/file1.ts' exist - use it as a module resolution result.", + "======== Module name 'folder2/file1' was successfully resolved to 'c:/root/folder2/file1.ts'. ========", + "======== Resolving module 'folder3/file2' from 'c:/root/folder1/file1.ts'. ========", + "Module resolution kind is not specified, using 'Classic'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'folder3/file2'", + "'paths' option is specified, looking for a pattern to match module name 'folder3/file2'.", + "Module name 'folder3/file2', matched pattern '*'.", + "Trying substitution '*', candidate module location: 'folder3/file2'.", + "File 'c:/root/folder3/file2.ts' does not exist.", + "File 'c:/root/folder3/file2.d.ts' does not exist.", + "Trying substitution 'generated/*', candidate module location: 'generated/folder3/file2'.", + "File 'c:/root/generated/folder3/file2.ts' exist - use it as a module resolution result.", + "======== Module name 'folder3/file2' was successfully resolved to 'c:/root/generated/folder3/file2.ts'. ========", + "======== Resolving module 'components/file3' from 'c:/root/folder1/file1.ts'. ========", + "Module resolution kind is not specified, using 'Classic'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'components/file3'", + "'paths' option is specified, looking for a pattern to match module name 'components/file3'.", + "Module name 'components/file3', matched pattern 'components/*'.", + "Trying substitution 'shared/components/*', candidate module location: 'shared/components/file3'.", + "File 'c:/root/shared/components/file3.ts' exist - use it as a module resolution result.", + "======== Module name 'components/file3' was successfully resolved to 'c:/root/shared/components/file3.ts'. ========", + "======== Resolving module 'file4' from 'c:/root/folder1/file1.ts'. ========", + "Module resolution kind is not specified, using 'Classic'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'file4'", + "'paths' option is specified, looking for a pattern to match module name 'file4'.", + "Module name 'file4', matched pattern '*'.", + "Trying substitution '*', candidate module location: 'file4'.", + "File 'c:/root/file4.ts' does not exist.", + "File 'c:/root/file4.d.ts' does not exist.", + "Trying substitution 'generated/*', candidate module location: 'generated/file4'.", + "File 'c:/root/generated/file4.ts' does not exist.", + "File 'c:/root/generated/file4.d.ts' does not exist.", + "File 'c:/root/folder1/file4.ts' does not exist.", + "File 'c:/root/folder1/file4.d.ts' does not exist.", + "File 'c:/root/file4.ts' does not exist.", + "File 'c:/root/file4.d.ts' does not exist.", + "File 'c:/file4.ts' exist - use it as a module resolution result.", + "======== Module name 'file4' was successfully resolved to 'c:/file4.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.types b/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.types new file mode 100644 index 0000000000000..32a1f42bc0fb4 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.types @@ -0,0 +1,69 @@ +=== c:/root/folder1/file1.ts === +import {x} from "folder2/file1" +>x : number + +import {y} from "folder3/file2" +>y : number + +import {z} from "components/file3" +>z : number + +import {z1} from "file4" +>z1 : number + +declare function use(a: any): void; +>use : (a: any) => void +>a : any + +use(x.toExponential()); +>use(x.toExponential()) : void +>use : (a: any) => void +>x.toExponential() : string +>x.toExponential : (fractionDigits?: number) => string +>x : number +>toExponential : (fractionDigits?: number) => string + +use(y.toExponential()); +>use(y.toExponential()) : void +>use : (a: any) => void +>y.toExponential() : string +>y.toExponential : (fractionDigits?: number) => string +>y : number +>toExponential : (fractionDigits?: number) => string + +use(z.toExponential()); +>use(z.toExponential()) : void +>use : (a: any) => void +>z.toExponential() : string +>z.toExponential : (fractionDigits?: number) => string +>z : number +>toExponential : (fractionDigits?: number) => string + +use(z1.toExponential()); +>use(z1.toExponential()) : void +>use : (a: any) => void +>z1.toExponential() : string +>z1.toExponential : (fractionDigits?: number) => string +>z1 : number +>toExponential : (fractionDigits?: number) => string + +=== c:/root/folder2/file1.ts === +export var x = 1; +>x : number +>1 : number + +=== c:/root/generated/folder3/file2.ts === +export var y = 1; +>y : number +>1 : number + +=== c:/root/shared/components/file3.ts === +export var z = 1; +>z : number +>1 : number + +=== c:/file4.ts === +export var z1 = 1; +>z1 : number +>1 : number + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution5_node.js b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.js new file mode 100644 index 0000000000000..1958800f91893 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.js @@ -0,0 +1,46 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution5_node.ts] //// + +//// [file1.ts] +import {x} from "folder2/file1" +import {y} from "folder3/file2" +import {z} from "components/file3" +import {z1} from "file4" + +declare function use(a: any): void; + +use(x.toExponential()); +use(y.toExponential()); +use(z.toExponential()); +use(z1.toExponential()); + +//// [file1.ts] +export var x = 1; + +//// [file2.ts] +export var y = 1; + +//// [index.d.ts] +export var z: number; + +//// [file4.ts] +export var z1 = 1; + +//// [file1.js] +"use strict"; +exports.x = 1; +//// [file2.js] +"use strict"; +exports.y = 1; +//// [file4.js] +"use strict"; +exports.z1 = 1; +//// [file1.js] +"use strict"; +var file1_1 = require("folder2/file1"); +var file2_1 = require("folder3/file2"); +var file3_1 = require("components/file3"); +var file4_1 = require("file4"); +use(file1_1.x.toExponential()); +use(file2_1.y.toExponential()); +use(file3_1.z.toExponential()); +use(file4_1.z1.toExponential()); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution5_node.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.symbols new file mode 100644 index 0000000000000..67bf14607dd10 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.symbols @@ -0,0 +1,57 @@ +=== c:/root/folder1/file1.ts === +import {x} from "folder2/file1" +>x : Symbol(x, Decl(file1.ts, 0, 8)) + +import {y} from "folder3/file2" +>y : Symbol(y, Decl(file1.ts, 1, 8)) + +import {z} from "components/file3" +>z : Symbol(z, Decl(file1.ts, 2, 8)) + +import {z1} from "file4" +>z1 : Symbol(z1, Decl(file1.ts, 3, 8)) + +declare function use(a: any): void; +>use : Symbol(use, Decl(file1.ts, 3, 24)) +>a : Symbol(a, Decl(file1.ts, 5, 21)) + +use(x.toExponential()); +>use : Symbol(use, Decl(file1.ts, 3, 24)) +>x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(file1.ts, 0, 8)) +>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) + +use(y.toExponential()); +>use : Symbol(use, Decl(file1.ts, 3, 24)) +>y.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) +>y : Symbol(y, Decl(file1.ts, 1, 8)) +>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) + +use(z.toExponential()); +>use : Symbol(use, Decl(file1.ts, 3, 24)) +>z.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) +>z : Symbol(z, Decl(file1.ts, 2, 8)) +>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) + +use(z1.toExponential()); +>use : Symbol(use, Decl(file1.ts, 3, 24)) +>z1.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) +>z1 : Symbol(z1, Decl(file1.ts, 3, 8)) +>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) + +=== c:/root/folder2/file1.ts === +export var x = 1; +>x : Symbol(x, Decl(file1.ts, 0, 10)) + +=== c:/root/generated/folder3/file2.ts === +export var y = 1; +>y : Symbol(y, Decl(file2.ts, 0, 10)) + +=== c:/root/shared/components/file3/index.d.ts === +export var z: number; +>z : Symbol(z, Decl(index.d.ts, 0, 10)) + +=== c:/node_modules/file4.ts === +export var z1 = 1; +>z1 : Symbol(z1, Decl(file4.ts, 0, 10)) + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json new file mode 100644 index 0000000000000..398d15839de92 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json @@ -0,0 +1,84 @@ +[ + "======== Resolving module 'folder2/file1' from 'c:/root/folder1/file1.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'folder2/file1'", + "'paths' option is specified, looking for a pattern to match module name 'folder2/file1'.", + "Module name 'folder2/file1', matched pattern '*'.", + "Trying substitution '*', candidate module location: 'folder2/file1'.", + "Loading module as file / folder, candidate module location 'c:/root/folder2/file1'.", + "File 'c:/root/folder2/file1.ts' exist - use it as a module resolution result.", + "======== Module name 'folder2/file1' was successfully resolved to 'c:/root/folder2/file1.ts'. ========", + "======== Resolving module 'folder3/file2' from 'c:/root/folder1/file1.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'folder3/file2'", + "'paths' option is specified, looking for a pattern to match module name 'folder3/file2'.", + "Module name 'folder3/file2', matched pattern '*'.", + "Trying substitution '*', candidate module location: 'folder3/file2'.", + "Loading module as file / folder, candidate module location 'c:/root/folder3/file2'.", + "File 'c:/root/folder3/file2.ts' does not exist.", + "File 'c:/root/folder3/file2.tsx' does not exist.", + "File 'c:/root/folder3/file2.d.ts' does not exist.", + "File 'c:/root/folder3/file2/package.json' does not exist.", + "File 'c:/root/folder3/file2/index.ts' does not exist.", + "File 'c:/root/folder3/file2/index.tsx' does not exist.", + "File 'c:/root/folder3/file2/index.d.ts' does not exist.", + "Trying substitution 'generated/*', candidate module location: 'generated/folder3/file2'.", + "Loading module as file / folder, candidate module location 'c:/root/generated/folder3/file2'.", + "File 'c:/root/generated/folder3/file2.ts' exist - use it as a module resolution result.", + "======== Module name 'folder3/file2' was successfully resolved to 'c:/root/generated/folder3/file2.ts'. ========", + "======== Resolving module 'components/file3' from 'c:/root/folder1/file1.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'components/file3'", + "'paths' option is specified, looking for a pattern to match module name 'components/file3'.", + "Module name 'components/file3', matched pattern 'components/*'.", + "Trying substitution 'shared/components/*', candidate module location: 'shared/components/file3'.", + "Loading module as file / folder, candidate module location 'c:/root/shared/components/file3'.", + "File 'c:/root/shared/components/file3.ts' does not exist.", + "File 'c:/root/shared/components/file3.tsx' does not exist.", + "File 'c:/root/shared/components/file3.d.ts' does not exist.", + "File 'c:/root/shared/components/file3/package.json' does not exist.", + "File 'c:/root/shared/components/file3/index.ts' does not exist.", + "File 'c:/root/shared/components/file3/index.tsx' does not exist.", + "File 'c:/root/shared/components/file3/index.d.ts' exist - use it as a module resolution result.", + "======== Module name 'components/file3' was successfully resolved to 'c:/root/shared/components/file3/index.d.ts'. ========", + "======== Resolving module 'file4' from 'c:/root/folder1/file1.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'file4'", + "'paths' option is specified, looking for a pattern to match module name 'file4'.", + "Module name 'file4', matched pattern '*'.", + "Trying substitution '*', candidate module location: 'file4'.", + "Loading module as file / folder, candidate module location 'c:/root/file4'.", + "File 'c:/root/file4.ts' does not exist.", + "File 'c:/root/file4.tsx' does not exist.", + "File 'c:/root/file4.d.ts' does not exist.", + "File 'c:/root/file4/package.json' does not exist.", + "File 'c:/root/file4/index.ts' does not exist.", + "File 'c:/root/file4/index.tsx' does not exist.", + "File 'c:/root/file4/index.d.ts' does not exist.", + "Trying substitution 'generated/*', candidate module location: 'generated/file4'.", + "Loading module as file / folder, candidate module location 'c:/root/generated/file4'.", + "File 'c:/root/generated/file4.ts' does not exist.", + "File 'c:/root/generated/file4.tsx' does not exist.", + "File 'c:/root/generated/file4.d.ts' does not exist.", + "File 'c:/root/generated/file4/package.json' does not exist.", + "File 'c:/root/generated/file4/index.ts' does not exist.", + "File 'c:/root/generated/file4/index.tsx' does not exist.", + "File 'c:/root/generated/file4/index.d.ts' does not exist.", + "Loading module 'file4' from 'node_modules' folder.", + "File 'c:/root/folder1/node_modules/file4.ts' does not exist.", + "File 'c:/root/folder1/node_modules/file4.tsx' does not exist.", + "File 'c:/root/folder1/node_modules/file4.d.ts' does not exist.", + "File 'c:/root/folder1/node_modules/file4/package.json' does not exist.", + "File 'c:/root/folder1/node_modules/file4/index.ts' does not exist.", + "File 'c:/root/folder1/node_modules/file4/index.tsx' does not exist.", + "File 'c:/root/folder1/node_modules/file4/index.d.ts' does not exist.", + "File 'c:/root/node_modules/file4.ts' does not exist.", + "File 'c:/root/node_modules/file4.tsx' does not exist.", + "File 'c:/root/node_modules/file4.d.ts' does not exist.", + "File 'c:/root/node_modules/file4/package.json' does not exist.", + "File 'c:/root/node_modules/file4/index.ts' does not exist.", + "File 'c:/root/node_modules/file4/index.tsx' does not exist.", + "File 'c:/root/node_modules/file4/index.d.ts' does not exist.", + "File 'c:/node_modules/file4.ts' exist - use it as a module resolution result.", + "======== Module name 'file4' was successfully resolved to 'c:/node_modules/file4.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution5_node.types b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.types new file mode 100644 index 0000000000000..1b96e3f4f22a9 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.types @@ -0,0 +1,68 @@ +=== c:/root/folder1/file1.ts === +import {x} from "folder2/file1" +>x : number + +import {y} from "folder3/file2" +>y : number + +import {z} from "components/file3" +>z : number + +import {z1} from "file4" +>z1 : number + +declare function use(a: any): void; +>use : (a: any) => void +>a : any + +use(x.toExponential()); +>use(x.toExponential()) : void +>use : (a: any) => void +>x.toExponential() : string +>x.toExponential : (fractionDigits?: number) => string +>x : number +>toExponential : (fractionDigits?: number) => string + +use(y.toExponential()); +>use(y.toExponential()) : void +>use : (a: any) => void +>y.toExponential() : string +>y.toExponential : (fractionDigits?: number) => string +>y : number +>toExponential : (fractionDigits?: number) => string + +use(z.toExponential()); +>use(z.toExponential()) : void +>use : (a: any) => void +>z.toExponential() : string +>z.toExponential : (fractionDigits?: number) => string +>z : number +>toExponential : (fractionDigits?: number) => string + +use(z1.toExponential()); +>use(z1.toExponential()) : void +>use : (a: any) => void +>z1.toExponential() : string +>z1.toExponential : (fractionDigits?: number) => string +>z1 : number +>toExponential : (fractionDigits?: number) => string + +=== c:/root/folder2/file1.ts === +export var x = 1; +>x : number +>1 : number + +=== c:/root/generated/folder3/file2.ts === +export var y = 1; +>y : number +>1 : number + +=== c:/root/shared/components/file3/index.d.ts === +export var z: number; +>z : number + +=== c:/node_modules/file4.ts === +export var z1 = 1; +>z1 : number +>1 : number + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.js b/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.js new file mode 100644 index 0000000000000..1e8f8807e2cf0 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.js @@ -0,0 +1,23 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution6_classic.ts] //// + +//// [file1.ts] +import {x} from "./project/file3"; +declare function use(x: string); +use(x.toExponential()); + +//// [file2.d.ts] +export let x: number; + +//// [file3.ts] +export {x} from "../file2"; + +//// [file3.js] +define(["require", "exports", "../file2"], function (require, exports, file2_1) { + "use strict"; + exports.x = file2_1.x; +}); +//// [file1.js] +define(["require", "exports", "./project/file3"], function (require, exports, file3_1) { + "use strict"; + use(file3_1.x.toExponential()); +}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.symbols new file mode 100644 index 0000000000000..a451ffb2584e9 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.symbols @@ -0,0 +1,22 @@ +=== c:/root/src/file1.ts === +import {x} from "./project/file3"; +>x : Symbol(x, Decl(file1.ts, 0, 8)) + +declare function use(x: string); +>use : Symbol(use, Decl(file1.ts, 0, 34)) +>x : Symbol(x, Decl(file1.ts, 1, 21)) + +use(x.toExponential()); +>use : Symbol(use, Decl(file1.ts, 0, 34)) +>x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(file1.ts, 0, 8)) +>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) + +=== c:/root/src/file2.d.ts === +export let x: number; +>x : Symbol(x, Decl(file2.d.ts, 0, 10)) + +=== c:/root/generated/src/project/file3.ts === +export {x} from "../file2"; +>x : Symbol(x, Decl(file3.ts, 0, 8)) + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.trace.json new file mode 100644 index 0000000000000..0493e9c216b3c --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.trace.json @@ -0,0 +1,29 @@ +[ + "======== Resolving module './project/file3' from 'c:/root/src/file1.ts'. ========", + "Module resolution kind is not specified, using 'Classic'.", + "'rootDirs' option is set, using it to resolve relative module name './project/file3'", + "Checking if 'c:/root/src/' is the longest matching prefix for 'c:/root/src/project/file3' - 'true'.", + "Checking if 'c:/root/generated/src/' is the longest matching prefix for 'c:/root/src/project/file3' - 'false'.", + "Longest matching prefix for 'c:/root/src/project/file3' is 'c:/root/src/'", + "Loading 'project/file3' from the root dir 'c:/root/src/', candidate location 'c:/root/src/project/file3'", + "File 'c:/root/src/project/file3.ts' does not exist.", + "File 'c:/root/src/project/file3.d.ts' does not exist.", + "Trying other entries in 'rootDirs'", + "Loading 'project/file3' from the root dir 'c:/root/generated/src', candidate location 'c:/root/generated/src/project/file3'", + "File 'c:/root/generated/src/project/file3.ts' exist - use it as a module resolution result.", + "======== Module name './project/file3' was successfully resolved to 'c:/root/generated/src/project/file3.ts'. ========", + "======== Resolving module '../file2' from 'c:/root/generated/src/project/file3.ts'. ========", + "Module resolution kind is not specified, using 'Classic'.", + "'rootDirs' option is set, using it to resolve relative module name '../file2'", + "Checking if 'c:/root/src/' is the longest matching prefix for 'c:/root/generated/src/file2' - 'false'.", + "Checking if 'c:/root/generated/src/' is the longest matching prefix for 'c:/root/generated/src/file2' - 'true'.", + "Longest matching prefix for 'c:/root/generated/src/file2' is 'c:/root/generated/src/'", + "Loading 'file2' from the root dir 'c:/root/generated/src/', candidate location 'c:/root/generated/src/file2'", + "File 'c:/root/generated/src/file2.ts' does not exist.", + "File 'c:/root/generated/src/file2.d.ts' does not exist.", + "Trying other entries in 'rootDirs'", + "Loading 'file2' from the root dir 'c:/root/src', candidate location 'c:/root/src/file2'", + "File 'c:/root/src/file2.ts' does not exist.", + "File 'c:/root/src/file2.d.ts' exist - use it as a module resolution result.", + "======== Module name '../file2' was successfully resolved to 'c:/root/src/file2.d.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.types b/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.types new file mode 100644 index 0000000000000..06d2cbdce34d4 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.types @@ -0,0 +1,24 @@ +=== c:/root/src/file1.ts === +import {x} from "./project/file3"; +>x : number + +declare function use(x: string); +>use : (x: string) => any +>x : string + +use(x.toExponential()); +>use(x.toExponential()) : any +>use : (x: string) => any +>x.toExponential() : string +>x.toExponential : (fractionDigits?: number) => string +>x : number +>toExponential : (fractionDigits?: number) => string + +=== c:/root/src/file2.d.ts === +export let x: number; +>x : number + +=== c:/root/generated/src/project/file3.ts === +export {x} from "../file2"; +>x : number + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution6_node.js b/tests/baselines/reference/pathMappingBasedModuleResolution6_node.js new file mode 100644 index 0000000000000..6db3fecf83fad --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution6_node.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution6_node.ts] //// + +//// [file1.ts] +import {x} from "./project/file3"; +declare function use(x: string); +use(x.toFixed()); + +//// [index.d.ts] +export let x: number; + +//// [file3.ts] +export {x} from "../file2"; + +//// [file3.js] +"use strict"; +var file2_1 = require("../file2"); +exports.x = file2_1.x; +//// [file1.js] +"use strict"; +var file3_1 = require("./project/file3"); +use(file3_1.x.toFixed()); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution6_node.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution6_node.symbols new file mode 100644 index 0000000000000..06554bae03989 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution6_node.symbols @@ -0,0 +1,22 @@ +=== c:/root/src/file1.ts === +import {x} from "./project/file3"; +>x : Symbol(x, Decl(file1.ts, 0, 8)) + +declare function use(x: string); +>use : Symbol(use, Decl(file1.ts, 0, 34)) +>x : Symbol(x, Decl(file1.ts, 1, 21)) + +use(x.toFixed()); +>use : Symbol(use, Decl(file1.ts, 0, 34)) +>x.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(file1.ts, 0, 8)) +>toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) + +=== c:/root/src/file2/index.d.ts === +export let x: number; +>x : Symbol(x, Decl(index.d.ts, 0, 10)) + +=== c:/root/generated/src/project/file3.ts === +export {x} from "../file2"; +>x : Symbol(x, Decl(file3.ts, 0, 8)) + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution6_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution6_node.trace.json new file mode 100644 index 0000000000000..4ea2f12a63c35 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution6_node.trace.json @@ -0,0 +1,48 @@ +[ + "======== Resolving module './project/file3' from 'c:/root/src/file1.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'rootDirs' option is set, using it to resolve relative module name './project/file3'", + "Checking if 'c:/root/src/' is the longest matching prefix for 'c:/root/src/project/file3' - 'true'.", + "Checking if 'c:/root/generated/src/' is the longest matching prefix for 'c:/root/src/project/file3' - 'false'.", + "Longest matching prefix for 'c:/root/src/project/file3' is 'c:/root/src/'", + "Loading 'project/file3' from the root dir 'c:/root/src/', candidate location 'c:/root/src/project/file3'", + "Loading module as file / folder, candidate module location 'c:/root/src/project/file3'.", + "File 'c:/root/src/project/file3.ts' does not exist.", + "File 'c:/root/src/project/file3.tsx' does not exist.", + "File 'c:/root/src/project/file3.d.ts' does not exist.", + "File 'c:/root/src/project/file3/package.json' does not exist.", + "File 'c:/root/src/project/file3/index.ts' does not exist.", + "File 'c:/root/src/project/file3/index.tsx' does not exist.", + "File 'c:/root/src/project/file3/index.d.ts' does not exist.", + "Trying other entries in 'rootDirs'", + "Loading 'project/file3' from the root dir 'c:/root/generated/src', candidate location 'c:/root/generated/src/project/file3'", + "Loading module as file / folder, candidate module location 'c:/root/generated/src/project/file3'.", + "File 'c:/root/generated/src/project/file3.ts' exist - use it as a module resolution result.", + "======== Module name './project/file3' was successfully resolved to 'c:/root/generated/src/project/file3.ts'. ========", + "======== Resolving module '../file2' from 'c:/root/generated/src/project/file3.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'rootDirs' option is set, using it to resolve relative module name '../file2'", + "Checking if 'c:/root/src/' is the longest matching prefix for 'c:/root/generated/src/file2' - 'false'.", + "Checking if 'c:/root/generated/src/' is the longest matching prefix for 'c:/root/generated/src/file2' - 'true'.", + "Longest matching prefix for 'c:/root/generated/src/file2' is 'c:/root/generated/src/'", + "Loading 'file2' from the root dir 'c:/root/generated/src/', candidate location 'c:/root/generated/src/file2'", + "Loading module as file / folder, candidate module location 'c:/root/generated/src/file2'.", + "File 'c:/root/generated/src/file2.ts' does not exist.", + "File 'c:/root/generated/src/file2.tsx' does not exist.", + "File 'c:/root/generated/src/file2.d.ts' does not exist.", + "File 'c:/root/generated/src/file2/package.json' does not exist.", + "File 'c:/root/generated/src/file2/index.ts' does not exist.", + "File 'c:/root/generated/src/file2/index.tsx' does not exist.", + "File 'c:/root/generated/src/file2/index.d.ts' does not exist.", + "Trying other entries in 'rootDirs'", + "Loading 'file2' from the root dir 'c:/root/src', candidate location 'c:/root/src/file2'", + "Loading module as file / folder, candidate module location 'c:/root/src/file2'.", + "File 'c:/root/src/file2.ts' does not exist.", + "File 'c:/root/src/file2.tsx' does not exist.", + "File 'c:/root/src/file2.d.ts' does not exist.", + "File 'c:/root/src/file2/package.json' does not exist.", + "File 'c:/root/src/file2/index.ts' does not exist.", + "File 'c:/root/src/file2/index.tsx' does not exist.", + "File 'c:/root/src/file2/index.d.ts' exist - use it as a module resolution result.", + "======== Module name '../file2' was successfully resolved to 'c:/root/src/file2/index.d.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution6_node.types b/tests/baselines/reference/pathMappingBasedModuleResolution6_node.types new file mode 100644 index 0000000000000..2fd10e8e1330d --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution6_node.types @@ -0,0 +1,24 @@ +=== c:/root/src/file1.ts === +import {x} from "./project/file3"; +>x : number + +declare function use(x: string); +>use : (x: string) => any +>x : string + +use(x.toFixed()); +>use(x.toFixed()) : any +>use : (x: string) => any +>x.toFixed() : string +>x.toFixed : (fractionDigits?: number) => string +>x : number +>toFixed : (fractionDigits?: number) => string + +=== c:/root/src/file2/index.d.ts === +export let x: number; +>x : number + +=== c:/root/generated/src/project/file3.ts === +export {x} from "../file2"; +>x : number + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.js b/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.js new file mode 100644 index 0000000000000..5670f41be0f11 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.js @@ -0,0 +1,45 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution7_classic.ts] //// + +//// [file1.ts] +import {x} from "./project/file2"; +import {y} from "module3"; + +declare function use(x: string); +use(x.toFixed()); +use(y.toFixed()); + +//// [file2.ts] +import {a} from "module1"; +import {b} from "templates/module2"; +import {x as c} from "../file3"; +export let x = a + b + c; + +//// [module1.d.ts] +export let a: number + +//// [module2.ts] +export let b: number; + +//// [file3.d.ts] +export let x: number; + +//// [module3.d.ts] +export let y: number; + + + +//// [module2.js] +define(["require", "exports"], function (require, exports) { + "use strict"; +}); +//// [file2.js] +define(["require", "exports", "module1", "templates/module2", "../file3"], function (require, exports, module1_1, module2_1, file3_1) { + "use strict"; + exports.x = module1_1.a + module2_1.b + file3_1.x; +}); +//// [file1.js] +define(["require", "exports", "./project/file2", "module3"], function (require, exports, file2_1, module3_1) { + "use strict"; + use(file2_1.x.toFixed()); + use(module3_1.y.toFixed()); +}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.symbols new file mode 100644 index 0000000000000..b1e4751c495d2 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.symbols @@ -0,0 +1,57 @@ +=== c:/root/src/file1.ts === +import {x} from "./project/file2"; +>x : Symbol(x, Decl(file1.ts, 0, 8)) + +import {y} from "module3"; +>y : Symbol(y, Decl(file1.ts, 1, 8)) + +declare function use(x: string); +>use : Symbol(use, Decl(file1.ts, 1, 26)) +>x : Symbol(x, Decl(file1.ts, 3, 21)) + +use(x.toFixed()); +>use : Symbol(use, Decl(file1.ts, 1, 26)) +>x.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(file1.ts, 0, 8)) +>toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) + +use(y.toFixed()); +>use : Symbol(use, Decl(file1.ts, 1, 26)) +>y.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) +>y : Symbol(y, Decl(file1.ts, 1, 8)) +>toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) + +=== c:/root/generated/src/project/file2.ts === +import {a} from "module1"; +>a : Symbol(a, Decl(file2.ts, 0, 8)) + +import {b} from "templates/module2"; +>b : Symbol(b, Decl(file2.ts, 1, 8)) + +import {x as c} from "../file3"; +>x : Symbol(c, Decl(file2.ts, 2, 8)) +>c : Symbol(c, Decl(file2.ts, 2, 8)) + +export let x = a + b + c; +>x : Symbol(x, Decl(file2.ts, 3, 10)) +>a : Symbol(a, Decl(file2.ts, 0, 8)) +>b : Symbol(b, Decl(file2.ts, 1, 8)) +>c : Symbol(c, Decl(file2.ts, 2, 8)) + +=== c:/shared/module1.d.ts === +export let a: number +>a : Symbol(a, Decl(module1.d.ts, 0, 10)) + +=== c:/root/generated/src/templates/module2.ts === +export let b: number; +>b : Symbol(b, Decl(module2.ts, 0, 10)) + +=== c:/root/src/file3.d.ts === +export let x: number; +>x : Symbol(x, Decl(file3.d.ts, 0, 10)) + +=== c:/module3.d.ts === +export let y: number; +>y : Symbol(y, Decl(module3.d.ts, 0, 10)) + + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.trace.json new file mode 100644 index 0000000000000..b45cd4754c7ef --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.trace.json @@ -0,0 +1,67 @@ +[ + "======== Resolving module './project/file2' from 'c:/root/src/file1.ts'. ========", + "Module resolution kind is not specified, using 'Classic'.", + "'rootDirs' option is set, using it to resolve relative module name './project/file2'", + "Checking if 'c:/root/src/' is the longest matching prefix for 'c:/root/src/project/file2' - 'true'.", + "Checking if 'c:/root/generated/src/' is the longest matching prefix for 'c:/root/src/project/file2' - 'false'.", + "Longest matching prefix for 'c:/root/src/project/file2' is 'c:/root/src/'", + "Loading 'project/file2' from the root dir 'c:/root/src/', candidate location 'c:/root/src/project/file2'", + "File 'c:/root/src/project/file2.ts' does not exist.", + "File 'c:/root/src/project/file2.d.ts' does not exist.", + "Trying other entries in 'rootDirs'", + "Loading 'project/file2' from the root dir 'c:/root/generated/src', candidate location 'c:/root/generated/src/project/file2'", + "File 'c:/root/generated/src/project/file2.ts' exist - use it as a module resolution result.", + "======== Module name './project/file2' was successfully resolved to 'c:/root/generated/src/project/file2.ts'. ========", + "======== Resolving module 'module3' from 'c:/root/src/file1.ts'. ========", + "Module resolution kind is not specified, using 'Classic'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'module3'", + "'paths' option is specified, looking for a pattern to match module name 'module3'.", + "Module name 'module3', matched pattern '*'.", + "Trying substitution '*', candidate module location: 'module3'.", + "File 'c:/root/module3.ts' does not exist.", + "File 'c:/root/module3.d.ts' does not exist.", + "Trying substitution 'c:/shared/*', candidate module location: 'c:/shared/module3'.", + "File 'c:/shared/module3.ts' does not exist.", + "File 'c:/shared/module3.d.ts' does not exist.", + "File 'c:/root/src/module3.ts' does not exist.", + "File 'c:/root/src/module3.d.ts' does not exist.", + "File 'c:/root/module3.ts' does not exist.", + "File 'c:/root/module3.d.ts' does not exist.", + "File 'c:/module3.ts' does not exist.", + "File 'c:/module3.d.ts' exist - use it as a module resolution result.", + "======== Module name 'module3' was successfully resolved to 'c:/module3.d.ts'. ========", + "======== Resolving module 'module1' from 'c:/root/generated/src/project/file2.ts'. ========", + "Module resolution kind is not specified, using 'Classic'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'module1'", + "'paths' option is specified, looking for a pattern to match module name 'module1'.", + "Module name 'module1', matched pattern '*'.", + "Trying substitution '*', candidate module location: 'module1'.", + "File 'c:/root/module1.ts' does not exist.", + "File 'c:/root/module1.d.ts' does not exist.", + "Trying substitution 'c:/shared/*', candidate module location: 'c:/shared/module1'.", + "File 'c:/shared/module1.ts' does not exist.", + "File 'c:/shared/module1.d.ts' exist - use it as a module resolution result.", + "======== Module name 'module1' was successfully resolved to 'c:/shared/module1.d.ts'. ========", + "======== Resolving module 'templates/module2' from 'c:/root/generated/src/project/file2.ts'. ========", + "Module resolution kind is not specified, using 'Classic'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'templates/module2'", + "'paths' option is specified, looking for a pattern to match module name 'templates/module2'.", + "Module name 'templates/module2', matched pattern 'templates/*'.", + "Trying substitution 'generated/src/templates/*', candidate module location: 'generated/src/templates/module2'.", + "File 'c:/root/generated/src/templates/module2.ts' exist - use it as a module resolution result.", + "======== Module name 'templates/module2' was successfully resolved to 'c:/root/generated/src/templates/module2.ts'. ========", + "======== Resolving module '../file3' from 'c:/root/generated/src/project/file2.ts'. ========", + "Module resolution kind is not specified, using 'Classic'.", + "'rootDirs' option is set, using it to resolve relative module name '../file3'", + "Checking if 'c:/root/src/' is the longest matching prefix for 'c:/root/generated/src/file3' - 'false'.", + "Checking if 'c:/root/generated/src/' is the longest matching prefix for 'c:/root/generated/src/file3' - 'true'.", + "Longest matching prefix for 'c:/root/generated/src/file3' is 'c:/root/generated/src/'", + "Loading 'file3' from the root dir 'c:/root/generated/src/', candidate location 'c:/root/generated/src/file3'", + "File 'c:/root/generated/src/file3.ts' does not exist.", + "File 'c:/root/generated/src/file3.d.ts' does not exist.", + "Trying other entries in 'rootDirs'", + "Loading 'file3' from the root dir 'c:/root/src', candidate location 'c:/root/src/file3'", + "File 'c:/root/src/file3.ts' does not exist.", + "File 'c:/root/src/file3.d.ts' exist - use it as a module resolution result.", + "======== Module name '../file3' was successfully resolved to 'c:/root/src/file3.d.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.types b/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.types new file mode 100644 index 0000000000000..26c4b425c8806 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.types @@ -0,0 +1,63 @@ +=== c:/root/src/file1.ts === +import {x} from "./project/file2"; +>x : number + +import {y} from "module3"; +>y : number + +declare function use(x: string); +>use : (x: string) => any +>x : string + +use(x.toFixed()); +>use(x.toFixed()) : any +>use : (x: string) => any +>x.toFixed() : string +>x.toFixed : (fractionDigits?: number) => string +>x : number +>toFixed : (fractionDigits?: number) => string + +use(y.toFixed()); +>use(y.toFixed()) : any +>use : (x: string) => any +>y.toFixed() : string +>y.toFixed : (fractionDigits?: number) => string +>y : number +>toFixed : (fractionDigits?: number) => string + +=== c:/root/generated/src/project/file2.ts === +import {a} from "module1"; +>a : number + +import {b} from "templates/module2"; +>b : number + +import {x as c} from "../file3"; +>x : number +>c : number + +export let x = a + b + c; +>x : number +>a + b + c : number +>a + b : number +>a : number +>b : number +>c : number + +=== c:/shared/module1.d.ts === +export let a: number +>a : number + +=== c:/root/generated/src/templates/module2.ts === +export let b: number; +>b : number + +=== c:/root/src/file3.d.ts === +export let x: number; +>x : number + +=== c:/module3.d.ts === +export let y: number; +>y : number + + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_node.js b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.js new file mode 100644 index 0000000000000..3be48cfc85c76 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.js @@ -0,0 +1,44 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution7_node.ts] //// + +//// [file1.ts] +import {x} from "./project/file2"; +import {y} from "module3"; + +declare function use(x: string); +use(x.toFixed()); +use(y.toFixed()); + +//// [file2.ts] +import {a} from "module1"; +import {b} from "templates/module2"; +import {x as c} from "../file3"; +export let x = a + b + c; + +//// [index.d.ts] +export let a: number + +//// [module2.ts] +export let b: number; + +//// [index.d.ts] +export let x: number; + +//// [module3.d.ts] +export let y: number; + + + +//// [module2.js] +"use strict"; +//// [file2.js] +"use strict"; +var module1_1 = require("module1"); +var module2_1 = require("templates/module2"); +var file3_1 = require("../file3"); +exports.x = module1_1.a + module2_1.b + file3_1.x; +//// [file1.js] +"use strict"; +var file2_1 = require("./project/file2"); +var module3_1 = require("module3"); +use(file2_1.x.toFixed()); +use(module3_1.y.toFixed()); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_node.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.symbols new file mode 100644 index 0000000000000..9cda76790ea01 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.symbols @@ -0,0 +1,57 @@ +=== c:/root/src/file1.ts === +import {x} from "./project/file2"; +>x : Symbol(x, Decl(file1.ts, 0, 8)) + +import {y} from "module3"; +>y : Symbol(y, Decl(file1.ts, 1, 8)) + +declare function use(x: string); +>use : Symbol(use, Decl(file1.ts, 1, 26)) +>x : Symbol(x, Decl(file1.ts, 3, 21)) + +use(x.toFixed()); +>use : Symbol(use, Decl(file1.ts, 1, 26)) +>x.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(file1.ts, 0, 8)) +>toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) + +use(y.toFixed()); +>use : Symbol(use, Decl(file1.ts, 1, 26)) +>y.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) +>y : Symbol(y, Decl(file1.ts, 1, 8)) +>toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) + +=== c:/root/generated/src/project/file2.ts === +import {a} from "module1"; +>a : Symbol(a, Decl(file2.ts, 0, 8)) + +import {b} from "templates/module2"; +>b : Symbol(b, Decl(file2.ts, 1, 8)) + +import {x as c} from "../file3"; +>x : Symbol(c, Decl(file2.ts, 2, 8)) +>c : Symbol(c, Decl(file2.ts, 2, 8)) + +export let x = a + b + c; +>x : Symbol(x, Decl(file2.ts, 3, 10)) +>a : Symbol(a, Decl(file2.ts, 0, 8)) +>b : Symbol(b, Decl(file2.ts, 1, 8)) +>c : Symbol(c, Decl(file2.ts, 2, 8)) + +=== c:/shared/module1/index.d.ts === +export let a: number +>a : Symbol(a, Decl(index.d.ts, 0, 10)) + +=== c:/root/generated/src/templates/module2.ts === +export let b: number; +>b : Symbol(b, Decl(module2.ts, 0, 10)) + +=== c:/root/src/file3/index.d.ts === +export let x: number; +>x : Symbol(x, Decl(index.d.ts, 0, 10)) + +=== c:/node_modules/module3.d.ts === +export let y: number; +>y : Symbol(y, Decl(module3.d.ts, 0, 10)) + + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json new file mode 100644 index 0000000000000..39d5c25c92a12 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json @@ -0,0 +1,123 @@ +[ + "======== Resolving module './project/file2' from 'c:/root/src/file1.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'rootDirs' option is set, using it to resolve relative module name './project/file2'", + "Checking if 'c:/root/src/' is the longest matching prefix for 'c:/root/src/project/file2' - 'true'.", + "Checking if 'c:/root/generated/src/' is the longest matching prefix for 'c:/root/src/project/file2' - 'false'.", + "Longest matching prefix for 'c:/root/src/project/file2' is 'c:/root/src/'", + "Loading 'project/file2' from the root dir 'c:/root/src/', candidate location 'c:/root/src/project/file2'", + "Loading module as file / folder, candidate module location 'c:/root/src/project/file2'.", + "File 'c:/root/src/project/file2.ts' does not exist.", + "File 'c:/root/src/project/file2.tsx' does not exist.", + "File 'c:/root/src/project/file2.d.ts' does not exist.", + "File 'c:/root/src/project/file2/package.json' does not exist.", + "File 'c:/root/src/project/file2/index.ts' does not exist.", + "File 'c:/root/src/project/file2/index.tsx' does not exist.", + "File 'c:/root/src/project/file2/index.d.ts' does not exist.", + "Trying other entries in 'rootDirs'", + "Loading 'project/file2' from the root dir 'c:/root/generated/src', candidate location 'c:/root/generated/src/project/file2'", + "Loading module as file / folder, candidate module location 'c:/root/generated/src/project/file2'.", + "File 'c:/root/generated/src/project/file2.ts' exist - use it as a module resolution result.", + "======== Module name './project/file2' was successfully resolved to 'c:/root/generated/src/project/file2.ts'. ========", + "======== Resolving module 'module3' from 'c:/root/src/file1.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'module3'", + "'paths' option is specified, looking for a pattern to match module name 'module3'.", + "Module name 'module3', matched pattern '*'.", + "Trying substitution '*', candidate module location: 'module3'.", + "Loading module as file / folder, candidate module location 'c:/root/module3'.", + "File 'c:/root/module3.ts' does not exist.", + "File 'c:/root/module3.tsx' does not exist.", + "File 'c:/root/module3.d.ts' does not exist.", + "File 'c:/root/module3/package.json' does not exist.", + "File 'c:/root/module3/index.ts' does not exist.", + "File 'c:/root/module3/index.tsx' does not exist.", + "File 'c:/root/module3/index.d.ts' does not exist.", + "Trying substitution 'c:/shared/*', candidate module location: 'c:/shared/module3'.", + "Loading module as file / folder, candidate module location 'c:/shared/module3'.", + "File 'c:/shared/module3.ts' does not exist.", + "File 'c:/shared/module3.tsx' does not exist.", + "File 'c:/shared/module3.d.ts' does not exist.", + "File 'c:/shared/module3/package.json' does not exist.", + "File 'c:/shared/module3/index.ts' does not exist.", + "File 'c:/shared/module3/index.tsx' does not exist.", + "File 'c:/shared/module3/index.d.ts' does not exist.", + "Loading module 'module3' from 'node_modules' folder.", + "File 'c:/root/src/node_modules/module3.ts' does not exist.", + "File 'c:/root/src/node_modules/module3.tsx' does not exist.", + "File 'c:/root/src/node_modules/module3.d.ts' does not exist.", + "File 'c:/root/src/node_modules/module3/package.json' does not exist.", + "File 'c:/root/src/node_modules/module3/index.ts' does not exist.", + "File 'c:/root/src/node_modules/module3/index.tsx' does not exist.", + "File 'c:/root/src/node_modules/module3/index.d.ts' does not exist.", + "File 'c:/root/node_modules/module3.ts' does not exist.", + "File 'c:/root/node_modules/module3.tsx' does not exist.", + "File 'c:/root/node_modules/module3.d.ts' does not exist.", + "File 'c:/root/node_modules/module3/package.json' does not exist.", + "File 'c:/root/node_modules/module3/index.ts' does not exist.", + "File 'c:/root/node_modules/module3/index.tsx' does not exist.", + "File 'c:/root/node_modules/module3/index.d.ts' does not exist.", + "File 'c:/node_modules/module3.ts' does not exist.", + "File 'c:/node_modules/module3.tsx' does not exist.", + "File 'c:/node_modules/module3.d.ts' exist - use it as a module resolution result.", + "======== Module name 'module3' was successfully resolved to 'c:/node_modules/module3.d.ts'. ========", + "======== Resolving module 'module1' from 'c:/root/generated/src/project/file2.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'module1'", + "'paths' option is specified, looking for a pattern to match module name 'module1'.", + "Module name 'module1', matched pattern '*'.", + "Trying substitution '*', candidate module location: 'module1'.", + "Loading module as file / folder, candidate module location 'c:/root/module1'.", + "File 'c:/root/module1.ts' does not exist.", + "File 'c:/root/module1.tsx' does not exist.", + "File 'c:/root/module1.d.ts' does not exist.", + "File 'c:/root/module1/package.json' does not exist.", + "File 'c:/root/module1/index.ts' does not exist.", + "File 'c:/root/module1/index.tsx' does not exist.", + "File 'c:/root/module1/index.d.ts' does not exist.", + "Trying substitution 'c:/shared/*', candidate module location: 'c:/shared/module1'.", + "Loading module as file / folder, candidate module location 'c:/shared/module1'.", + "File 'c:/shared/module1.ts' does not exist.", + "File 'c:/shared/module1.tsx' does not exist.", + "File 'c:/shared/module1.d.ts' does not exist.", + "File 'c:/shared/module1/package.json' does not exist.", + "File 'c:/shared/module1/index.ts' does not exist.", + "File 'c:/shared/module1/index.tsx' does not exist.", + "File 'c:/shared/module1/index.d.ts' exist - use it as a module resolution result.", + "======== Module name 'module1' was successfully resolved to 'c:/shared/module1/index.d.ts'. ========", + "======== Resolving module 'templates/module2' from 'c:/root/generated/src/project/file2.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'templates/module2'", + "'paths' option is specified, looking for a pattern to match module name 'templates/module2'.", + "Module name 'templates/module2', matched pattern 'templates/*'.", + "Trying substitution 'generated/src/templates/*', candidate module location: 'generated/src/templates/module2'.", + "Loading module as file / folder, candidate module location 'c:/root/generated/src/templates/module2'.", + "File 'c:/root/generated/src/templates/module2.ts' exist - use it as a module resolution result.", + "======== Module name 'templates/module2' was successfully resolved to 'c:/root/generated/src/templates/module2.ts'. ========", + "======== Resolving module '../file3' from 'c:/root/generated/src/project/file2.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'rootDirs' option is set, using it to resolve relative module name '../file3'", + "Checking if 'c:/root/src/' is the longest matching prefix for 'c:/root/generated/src/file3' - 'false'.", + "Checking if 'c:/root/generated/src/' is the longest matching prefix for 'c:/root/generated/src/file3' - 'true'.", + "Longest matching prefix for 'c:/root/generated/src/file3' is 'c:/root/generated/src/'", + "Loading 'file3' from the root dir 'c:/root/generated/src/', candidate location 'c:/root/generated/src/file3'", + "Loading module as file / folder, candidate module location 'c:/root/generated/src/file3'.", + "File 'c:/root/generated/src/file3.ts' does not exist.", + "File 'c:/root/generated/src/file3.tsx' does not exist.", + "File 'c:/root/generated/src/file3.d.ts' does not exist.", + "File 'c:/root/generated/src/file3/package.json' does not exist.", + "File 'c:/root/generated/src/file3/index.ts' does not exist.", + "File 'c:/root/generated/src/file3/index.tsx' does not exist.", + "File 'c:/root/generated/src/file3/index.d.ts' does not exist.", + "Trying other entries in 'rootDirs'", + "Loading 'file3' from the root dir 'c:/root/src', candidate location 'c:/root/src/file3'", + "Loading module as file / folder, candidate module location 'c:/root/src/file3'.", + "File 'c:/root/src/file3.ts' does not exist.", + "File 'c:/root/src/file3.tsx' does not exist.", + "File 'c:/root/src/file3.d.ts' does not exist.", + "File 'c:/root/src/file3/package.json' does not exist.", + "File 'c:/root/src/file3/index.ts' does not exist.", + "File 'c:/root/src/file3/index.tsx' does not exist.", + "File 'c:/root/src/file3/index.d.ts' exist - use it as a module resolution result.", + "======== Module name '../file3' was successfully resolved to 'c:/root/src/file3/index.d.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_node.types b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.types new file mode 100644 index 0000000000000..974f710b4c280 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.types @@ -0,0 +1,63 @@ +=== c:/root/src/file1.ts === +import {x} from "./project/file2"; +>x : number + +import {y} from "module3"; +>y : number + +declare function use(x: string); +>use : (x: string) => any +>x : string + +use(x.toFixed()); +>use(x.toFixed()) : any +>use : (x: string) => any +>x.toFixed() : string +>x.toFixed : (fractionDigits?: number) => string +>x : number +>toFixed : (fractionDigits?: number) => string + +use(y.toFixed()); +>use(y.toFixed()) : any +>use : (x: string) => any +>y.toFixed() : string +>y.toFixed : (fractionDigits?: number) => string +>y : number +>toFixed : (fractionDigits?: number) => string + +=== c:/root/generated/src/project/file2.ts === +import {a} from "module1"; +>a : number + +import {b} from "templates/module2"; +>b : number + +import {x as c} from "../file3"; +>x : number +>c : number + +export let x = a + b + c; +>x : number +>a + b + c : number +>a + b : number +>a : number +>b : number +>c : number + +=== c:/shared/module1/index.d.ts === +export let a: number +>a : number + +=== c:/root/generated/src/templates/module2.ts === +export let b: number; +>b : number + +=== c:/root/src/file3/index.d.ts === +export let x: number; +>x : number + +=== c:/node_modules/module3.d.ts === +export let y: number; +>y : number + + diff --git a/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.js b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.js index 5d414c97d05fb..cf88f4e9ba68b 100644 --- a/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.js +++ b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.js @@ -31,8 +31,9 @@ if (++y) { } //// [prefixUnaryOperatorsOnExportedVariables.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x, y; return { setters:[], diff --git a/tests/baselines/reference/privateIndexer.errors.txt b/tests/baselines/reference/privateIndexer.errors.txt index 5d8ae7c935198..5ee21d8e4e30b 100644 --- a/tests/baselines/reference/privateIndexer.errors.txt +++ b/tests/baselines/reference/privateIndexer.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer.ts(4,5): error TS1145: Modifiers not permitted on index signature members. -tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer.ts(8,5): error TS1145: Modifiers not permitted on index signature members. -tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer.ts(12,5): error TS1145: Modifiers not permitted on index signature members. +tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer.ts(4,5): error TS1071: 'private' modifier cannot appear on an index signature. +tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer.ts(8,5): error TS1071: 'private' modifier cannot appear on an index signature. +tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer.ts(12,5): error TS1071: 'private' modifier cannot appear on an index signature. ==== tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer.ts (3 errors) ==== @@ -9,17 +9,17 @@ tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer.ts(12,5): class C { private [x: string]: string; ~~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'private' modifier cannot appear on an index signature. } class D { private [x: number]: string; ~~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'private' modifier cannot appear on an index signature. } class E { private [x: string]: T; ~~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'private' modifier cannot appear on an index signature. } \ No newline at end of file diff --git a/tests/baselines/reference/publicIndexer.errors.txt b/tests/baselines/reference/publicIndexer.errors.txt index 860290ea25b3b..29454f2a20863 100644 --- a/tests/baselines/reference/publicIndexer.errors.txt +++ b/tests/baselines/reference/publicIndexer.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/classes/indexMemberDeclarations/publicIndexer.ts(4,5): error TS1145: Modifiers not permitted on index signature members. -tests/cases/conformance/classes/indexMemberDeclarations/publicIndexer.ts(8,5): error TS1145: Modifiers not permitted on index signature members. -tests/cases/conformance/classes/indexMemberDeclarations/publicIndexer.ts(12,5): error TS1145: Modifiers not permitted on index signature members. +tests/cases/conformance/classes/indexMemberDeclarations/publicIndexer.ts(4,5): error TS1071: 'public' modifier cannot appear on an index signature. +tests/cases/conformance/classes/indexMemberDeclarations/publicIndexer.ts(8,5): error TS1071: 'public' modifier cannot appear on an index signature. +tests/cases/conformance/classes/indexMemberDeclarations/publicIndexer.ts(12,5): error TS1071: 'public' modifier cannot appear on an index signature. ==== tests/cases/conformance/classes/indexMemberDeclarations/publicIndexer.ts (3 errors) ==== @@ -9,17 +9,17 @@ tests/cases/conformance/classes/indexMemberDeclarations/publicIndexer.ts(12,5): class C { public [x: string]: string; ~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'public' modifier cannot appear on an index signature. } class D { public [x: number]: string; ~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'public' modifier cannot appear on an index signature. } class E { public [x: string]: T; ~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'public' modifier cannot appear on an index signature. } \ No newline at end of file diff --git a/tests/baselines/reference/reachabilityChecks7.js b/tests/baselines/reference/reachabilityChecks7.js index 39b7b0149a5fb..0a6b5b0dac7b5 100644 --- a/tests/baselines/reference/reachabilityChecks7.js +++ b/tests/baselines/reference/reachabilityChecks7.js @@ -32,35 +32,35 @@ let x1 = () => { use("Test"); } //// [reachabilityChecks7.js] var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new P(function (resolve, reject) { + return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.call(thisArg, _arguments)).next()); + step((generator = generator.apply(thisArg, _arguments)).next()); }); }; // async function without return type annotation - error function f1() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { }); } let x = function () { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { }); }; // async function with which promised type is void - return can be omitted function f2() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { }); } function f3(x) { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { if (x) return 10; }); } function f4() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { }); } function voidFunc() { diff --git a/tests/baselines/reference/reactNamespaceInvalidInput.errors.txt b/tests/baselines/reference/reactNamespaceInvalidInput.errors.txt index e08ec52086789..2e72775fe9c23 100644 --- a/tests/baselines/reference/reactNamespaceInvalidInput.errors.txt +++ b/tests/baselines/reference/reactNamespaceInvalidInput.errors.txt @@ -1,8 +1,8 @@ -error TS5059: Invalide value for '--reactNamespace'. 'my-React-Lib' is not a valid identifier. +error TS5059: Invalid value for '--reactNamespace'. 'my-React-Lib' is not a valid identifier. tests/cases/compiler/reactNamespaceInvalidInput.tsx(2,2): error TS2304: Cannot find name 'my-React-Lib'. -!!! error TS5059: Invalide value for '--reactNamespace'. 'my-React-Lib' is not a valid identifier. +!!! error TS5059: Invalid value for '--reactNamespace'. 'my-React-Lib' is not a valid identifier. ==== tests/cases/compiler/reactNamespaceInvalidInput.tsx (1 errors) ==== ; diff --git a/tests/baselines/reference/readonlyInDeclarationFile.js b/tests/baselines/reference/readonlyInDeclarationFile.js new file mode 100644 index 0000000000000..71e48272ecc0c --- /dev/null +++ b/tests/baselines/reference/readonlyInDeclarationFile.js @@ -0,0 +1,180 @@ +//// [readonlyInDeclarationFile.ts] + +interface Foo { + readonly x: number; + readonly [x: string]: Object; +} + +class C { + readonly [x: string]: Object; + private readonly a1: number; + protected readonly a2: number; + public readonly a3: number; + private get b1() { return 1 } + protected get b2() { return 1 } + public get b3() { return 1 } + private get c1() { return 1 } + private set c1(value) { } + protected get c2() { return 1 } + protected set c2(value) { } + public get c3() { return 1 } + public set c3(value) { } + private static readonly s1: number; + protected static readonly s2: number; + public static readonly s3: number; + private static get t1() { return 1 } + protected static get t2() { return 1 } + public static get t3() { return 1 } + private static get u1() { return 1 } + private static set u1(value) { } + protected static get u2() { return 1 } + protected static set u2(value) { } + public static get u3() { return 1 } + public static set u3(value) { } +} + +var z: { + readonly a: string; + readonly [x: string]: Object; +} + +function f() { + return { + get x() { return 1; }, + get y() { return 1; }, + set y(value) { } + } +} + +function g() { + var x: { + readonly a: string; + readonly [x: string]: Object; + } + return x; +} + +//// [readonlyInDeclarationFile.js] +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, "b1", { + get: function () { return 1; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "b2", { + get: function () { return 1; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "b3", { + get: function () { return 1; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "c1", { + get: function () { return 1; }, + set: function (value) { }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "c2", { + get: function () { return 1; }, + set: function (value) { }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "c3", { + get: function () { return 1; }, + set: function (value) { }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, "t1", { + get: function () { return 1; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, "t2", { + get: function () { return 1; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, "t3", { + get: function () { return 1; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, "u1", { + get: function () { return 1; }, + set: function (value) { }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, "u2", { + get: function () { return 1; }, + set: function (value) { }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, "u3", { + get: function () { return 1; }, + set: function (value) { }, + enumerable: true, + configurable: true + }); + return C; +}()); +var z; +function f() { + return { + get x() { return 1; }, + get y() { return 1; }, + set y(value) { } + }; +} +function g() { + var x; + return x; +} + + +//// [readonlyInDeclarationFile.d.ts] +interface Foo { + readonly x: number; + readonly [x: string]: Object; +} +declare class C { + readonly [x: string]: Object; + private readonly a1; + protected readonly a2: number; + readonly a3: number; + private readonly b1; + protected readonly b2: number; + readonly b3: number; + private c1; + protected c2: number; + c3: number; + private static readonly s1; + protected static readonly s2: number; + static readonly s3: number; + private static readonly t1; + protected static readonly t2: number; + static readonly t3: number; + private static u1; + protected static u2: number; + static u3: number; +} +declare var z: { + readonly a: string; + readonly [x: string]: Object; +}; +declare function f(): { + readonly x: number; + y: number; +}; +declare function g(): { + readonly [x: string]: Object; + readonly a: string; +}; diff --git a/tests/baselines/reference/readonlyInDeclarationFile.symbols b/tests/baselines/reference/readonlyInDeclarationFile.symbols new file mode 100644 index 0000000000000..af979e4dacd82 --- /dev/null +++ b/tests/baselines/reference/readonlyInDeclarationFile.symbols @@ -0,0 +1,142 @@ +=== tests/cases/compiler/readonlyInDeclarationFile.ts === + +interface Foo { +>Foo : Symbol(Foo, Decl(readonlyInDeclarationFile.ts, 0, 0)) + + readonly x: number; +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 1, 15)) + + readonly [x: string]: Object; +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 3, 14)) +>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +} + +class C { +>C : Symbol(C, Decl(readonlyInDeclarationFile.ts, 4, 1)) + + readonly [x: string]: Object; +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 7, 14)) +>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + + private readonly a1: number; +>a1 : Symbol(a1, Decl(readonlyInDeclarationFile.ts, 7, 33)) + + protected readonly a2: number; +>a2 : Symbol(a2, Decl(readonlyInDeclarationFile.ts, 8, 32)) + + public readonly a3: number; +>a3 : Symbol(a3, Decl(readonlyInDeclarationFile.ts, 9, 34)) + + private get b1() { return 1 } +>b1 : Symbol(b1, Decl(readonlyInDeclarationFile.ts, 10, 31)) + + protected get b2() { return 1 } +>b2 : Symbol(b2, Decl(readonlyInDeclarationFile.ts, 11, 33)) + + public get b3() { return 1 } +>b3 : Symbol(b3, Decl(readonlyInDeclarationFile.ts, 12, 35)) + + private get c1() { return 1 } +>c1 : Symbol(c1, Decl(readonlyInDeclarationFile.ts, 13, 32), Decl(readonlyInDeclarationFile.ts, 14, 33)) + + private set c1(value) { } +>c1 : Symbol(c1, Decl(readonlyInDeclarationFile.ts, 13, 32), Decl(readonlyInDeclarationFile.ts, 14, 33)) +>value : Symbol(value, Decl(readonlyInDeclarationFile.ts, 15, 19)) + + protected get c2() { return 1 } +>c2 : Symbol(c2, Decl(readonlyInDeclarationFile.ts, 15, 29), Decl(readonlyInDeclarationFile.ts, 16, 35)) + + protected set c2(value) { } +>c2 : Symbol(c2, Decl(readonlyInDeclarationFile.ts, 15, 29), Decl(readonlyInDeclarationFile.ts, 16, 35)) +>value : Symbol(value, Decl(readonlyInDeclarationFile.ts, 17, 21)) + + public get c3() { return 1 } +>c3 : Symbol(c3, Decl(readonlyInDeclarationFile.ts, 17, 31), Decl(readonlyInDeclarationFile.ts, 18, 32)) + + public set c3(value) { } +>c3 : Symbol(c3, Decl(readonlyInDeclarationFile.ts, 17, 31), Decl(readonlyInDeclarationFile.ts, 18, 32)) +>value : Symbol(value, Decl(readonlyInDeclarationFile.ts, 19, 18)) + + private static readonly s1: number; +>s1 : Symbol(C.s1, Decl(readonlyInDeclarationFile.ts, 19, 28)) + + protected static readonly s2: number; +>s2 : Symbol(C.s2, Decl(readonlyInDeclarationFile.ts, 20, 39)) + + public static readonly s3: number; +>s3 : Symbol(C.s3, Decl(readonlyInDeclarationFile.ts, 21, 41)) + + private static get t1() { return 1 } +>t1 : Symbol(C.t1, Decl(readonlyInDeclarationFile.ts, 22, 38)) + + protected static get t2() { return 1 } +>t2 : Symbol(C.t2, Decl(readonlyInDeclarationFile.ts, 23, 40)) + + public static get t3() { return 1 } +>t3 : Symbol(C.t3, Decl(readonlyInDeclarationFile.ts, 24, 42)) + + private static get u1() { return 1 } +>u1 : Symbol(C.u1, Decl(readonlyInDeclarationFile.ts, 25, 39), Decl(readonlyInDeclarationFile.ts, 26, 40)) + + private static set u1(value) { } +>u1 : Symbol(C.u1, Decl(readonlyInDeclarationFile.ts, 25, 39), Decl(readonlyInDeclarationFile.ts, 26, 40)) +>value : Symbol(value, Decl(readonlyInDeclarationFile.ts, 27, 26)) + + protected static get u2() { return 1 } +>u2 : Symbol(C.u2, Decl(readonlyInDeclarationFile.ts, 27, 36), Decl(readonlyInDeclarationFile.ts, 28, 42)) + + protected static set u2(value) { } +>u2 : Symbol(C.u2, Decl(readonlyInDeclarationFile.ts, 27, 36), Decl(readonlyInDeclarationFile.ts, 28, 42)) +>value : Symbol(value, Decl(readonlyInDeclarationFile.ts, 29, 28)) + + public static get u3() { return 1 } +>u3 : Symbol(C.u3, Decl(readonlyInDeclarationFile.ts, 29, 38), Decl(readonlyInDeclarationFile.ts, 30, 39)) + + public static set u3(value) { } +>u3 : Symbol(C.u3, Decl(readonlyInDeclarationFile.ts, 29, 38), Decl(readonlyInDeclarationFile.ts, 30, 39)) +>value : Symbol(value, Decl(readonlyInDeclarationFile.ts, 31, 25)) +} + +var z: { +>z : Symbol(z, Decl(readonlyInDeclarationFile.ts, 34, 3)) + + readonly a: string; +>a : Symbol(a, Decl(readonlyInDeclarationFile.ts, 34, 8)) + + readonly [x: string]: Object; +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 36, 14)) +>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +} + +function f() { +>f : Symbol(f, Decl(readonlyInDeclarationFile.ts, 37, 1)) + + return { + get x() { return 1; }, +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 40, 12)) + + get y() { return 1; }, +>y : Symbol(y, Decl(readonlyInDeclarationFile.ts, 41, 30), Decl(readonlyInDeclarationFile.ts, 42, 30)) + + set y(value) { } +>y : Symbol(y, Decl(readonlyInDeclarationFile.ts, 41, 30), Decl(readonlyInDeclarationFile.ts, 42, 30)) +>value : Symbol(value, Decl(readonlyInDeclarationFile.ts, 43, 14)) + } +} + +function g() { +>g : Symbol(g, Decl(readonlyInDeclarationFile.ts, 45, 1)) + + var x: { +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 48, 7)) + + readonly a: string; +>a : Symbol(a, Decl(readonlyInDeclarationFile.ts, 48, 12)) + + readonly [x: string]: Object; +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 50, 18)) +>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + } + return x; +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 48, 7)) +} diff --git a/tests/baselines/reference/readonlyInDeclarationFile.types b/tests/baselines/reference/readonlyInDeclarationFile.types new file mode 100644 index 0000000000000..7a3e11577c87d --- /dev/null +++ b/tests/baselines/reference/readonlyInDeclarationFile.types @@ -0,0 +1,158 @@ +=== tests/cases/compiler/readonlyInDeclarationFile.ts === + +interface Foo { +>Foo : Foo + + readonly x: number; +>x : number + + readonly [x: string]: Object; +>x : string +>Object : Object +} + +class C { +>C : C + + readonly [x: string]: Object; +>x : string +>Object : Object + + private readonly a1: number; +>a1 : number + + protected readonly a2: number; +>a2 : number + + public readonly a3: number; +>a3 : number + + private get b1() { return 1 } +>b1 : number +>1 : number + + protected get b2() { return 1 } +>b2 : number +>1 : number + + public get b3() { return 1 } +>b3 : number +>1 : number + + private get c1() { return 1 } +>c1 : number +>1 : number + + private set c1(value) { } +>c1 : number +>value : number + + protected get c2() { return 1 } +>c2 : number +>1 : number + + protected set c2(value) { } +>c2 : number +>value : number + + public get c3() { return 1 } +>c3 : number +>1 : number + + public set c3(value) { } +>c3 : number +>value : number + + private static readonly s1: number; +>s1 : number + + protected static readonly s2: number; +>s2 : number + + public static readonly s3: number; +>s3 : number + + private static get t1() { return 1 } +>t1 : number +>1 : number + + protected static get t2() { return 1 } +>t2 : number +>1 : number + + public static get t3() { return 1 } +>t3 : number +>1 : number + + private static get u1() { return 1 } +>u1 : number +>1 : number + + private static set u1(value) { } +>u1 : number +>value : number + + protected static get u2() { return 1 } +>u2 : number +>1 : number + + protected static set u2(value) { } +>u2 : number +>value : number + + public static get u3() { return 1 } +>u3 : number +>1 : number + + public static set u3(value) { } +>u3 : number +>value : number +} + +var z: { +>z : { readonly [x: string]: Object; readonly a: string; } + + readonly a: string; +>a : string + + readonly [x: string]: Object; +>x : string +>Object : Object +} + +function f() { +>f : () => { readonly x: number; y: number; } + + return { +>{ get x() { return 1; }, get y() { return 1; }, set y(value) { } } : { readonly x: number; y: number; } + + get x() { return 1; }, +>x : number +>1 : number + + get y() { return 1; }, +>y : number +>1 : number + + set y(value) { } +>y : number +>value : number + } +} + +function g() { +>g : () => { readonly [x: string]: Object; readonly a: string; } + + var x: { +>x : { readonly [x: string]: Object; readonly a: string; } + + readonly a: string; +>a : string + + readonly [x: string]: Object; +>x : string +>Object : Object + } + return x; +>x : { readonly [x: string]: Object; readonly a: string; } +} diff --git a/tests/baselines/reference/readonlyMembers.errors.txt b/tests/baselines/reference/readonlyMembers.errors.txt new file mode 100644 index 0000000000000..7bc10aa374690 --- /dev/null +++ b/tests/baselines/reference/readonlyMembers.errors.txt @@ -0,0 +1,114 @@ +tests/cases/compiler/readonlyMembers.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(17,9): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(19,13): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(20,13): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(21,13): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(25,9): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(26,9): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(27,9): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(36,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(40,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(49,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(56,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(62,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. +tests/cases/compiler/readonlyMembers.ts(65,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + + +==== tests/cases/compiler/readonlyMembers.ts (15 errors) ==== + + interface X { + readonly a: number; + readonly b?: number; + } + var x: X = { a: 0 }; + x.a = 1; // Error + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + x.b = 1; // Error + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + + class C { + readonly a: number; + readonly b = 1; + get c() { return 1 } + constructor() { + this.a = 1; // Ok + this.b = 1; // Ok + this.c = 1; // Error + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + const f = () => { + this.a = 1; // Error + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + this.b = 1; // Error + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + this.c = 1; // Error + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + } + } + foo() { + this.a = 1; // Error + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + this.b = 1; // Error + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + this.c = 1; // Error + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + } + } + + var o = { + get a() { return 1 }, + get b() { return 1 }, + set b(value) { } + }; + o.a = 1; // Error + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + o.b = 1; + + var p: { readonly a: number, b: number } = { a: 1, b: 1 }; + p.a = 1; // Error + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + p.b = 1; + var q: { a: number, b: number } = p; + q.a = 1; + q.b = 1; + + enum E { + A, B, C + } + E.A = 1; // Error + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + + namespace N { + export const a = 1; + export let b = 1; + export var c = 1; + } + N.a = 1; // Error + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + N.b = 1; + N.c = 1; + + let xx: { readonly [x: string]: string }; + let s = xx["foo"]; + xx["foo"] = "abc"; // Error + ~~~~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + + let yy: { readonly [x: number]: string, [x: string]: string }; + yy[1] = "abc"; // Error + ~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. + yy["foo"] = "abc"; \ No newline at end of file diff --git a/tests/baselines/reference/readonlyMembers.js b/tests/baselines/reference/readonlyMembers.js new file mode 100644 index 0000000000000..899c52d86262c --- /dev/null +++ b/tests/baselines/reference/readonlyMembers.js @@ -0,0 +1,132 @@ +//// [readonlyMembers.ts] + +interface X { + readonly a: number; + readonly b?: number; +} +var x: X = { a: 0 }; +x.a = 1; // Error +x.b = 1; // Error + +class C { + readonly a: number; + readonly b = 1; + get c() { return 1 } + constructor() { + this.a = 1; // Ok + this.b = 1; // Ok + this.c = 1; // Error + const f = () => { + this.a = 1; // Error + this.b = 1; // Error + this.c = 1; // Error + } + } + foo() { + this.a = 1; // Error + this.b = 1; // Error + this.c = 1; // Error + } +} + +var o = { + get a() { return 1 }, + get b() { return 1 }, + set b(value) { } +}; +o.a = 1; // Error +o.b = 1; + +var p: { readonly a: number, b: number } = { a: 1, b: 1 }; +p.a = 1; // Error +p.b = 1; +var q: { a: number, b: number } = p; +q.a = 1; +q.b = 1; + +enum E { + A, B, C +} +E.A = 1; // Error + +namespace N { + export const a = 1; + export let b = 1; + export var c = 1; +} +N.a = 1; // Error +N.b = 1; +N.c = 1; + +let xx: { readonly [x: string]: string }; +let s = xx["foo"]; +xx["foo"] = "abc"; // Error + +let yy: { readonly [x: number]: string, [x: string]: string }; +yy[1] = "abc"; // Error +yy["foo"] = "abc"; + +//// [readonlyMembers.js] +var x = { a: 0 }; +x.a = 1; // Error +x.b = 1; // Error +var C = (function () { + function C() { + var _this = this; + this.b = 1; + this.a = 1; // Ok + this.b = 1; // Ok + this.c = 1; // Error + var f = function () { + _this.a = 1; // Error + _this.b = 1; // Error + _this.c = 1; // Error + }; + } + Object.defineProperty(C.prototype, "c", { + get: function () { return 1; }, + enumerable: true, + configurable: true + }); + C.prototype.foo = function () { + this.a = 1; // Error + this.b = 1; // Error + this.c = 1; // Error + }; + return C; +}()); +var o = { + get a() { return 1; }, + get b() { return 1; }, + set b(value) { } +}; +o.a = 1; // Error +o.b = 1; +var p = { a: 1, b: 1 }; +p.a = 1; // Error +p.b = 1; +var q = p; +q.a = 1; +q.b = 1; +var E; +(function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; +})(E || (E = {})); +E.A = 1; // Error +var N; +(function (N) { + N.a = 1; + N.b = 1; + N.c = 1; +})(N || (N = {})); +N.a = 1; // Error +N.b = 1; +N.c = 1; +var xx; +var s = xx["foo"]; +xx["foo"] = "abc"; // Error +var yy; +yy[1] = "abc"; // Error +yy["foo"] = "abc"; diff --git a/tests/baselines/reference/redefineArray.errors.txt b/tests/baselines/reference/redefineArray.errors.txt index b0062abff88bf..82ef91807c28b 100644 --- a/tests/baselines/reference/redefineArray.errors.txt +++ b/tests/baselines/reference/redefineArray.errors.txt @@ -1,9 +1,7 @@ -tests/cases/compiler/redefineArray.ts(1,1): error TS2322: Type '(n: number, s: string) => number' is not assignable to type 'ArrayConstructor'. - Property 'isArray' is missing in type '(n: number, s: string) => number'. +tests/cases/compiler/redefineArray.ts(1,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. ==== tests/cases/compiler/redefineArray.ts (1 errors) ==== Array = function (n:number, s:string) {return n;}; ~~~~~ -!!! error TS2322: Type '(n: number, s: string) => number' is not assignable to type 'ArrayConstructor'. -!!! error TS2322: Property 'isArray' is missing in type '(n: number, s: string) => number'. \ No newline at end of file +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/shorthandPropertyAssignmentInES6Module.js b/tests/baselines/reference/shorthandPropertyAssignmentInES6Module.js index cab16b96bc305..d52622dffc7d8 100644 --- a/tests/baselines/reference/shorthandPropertyAssignmentInES6Module.js +++ b/tests/baselines/reference/shorthandPropertyAssignmentInES6Module.js @@ -20,8 +20,8 @@ use(foo); exports.x = 1; //// [test.js] "use strict"; -var existingModule_1 = require('./existingModule'); -var missingModule_1 = require('./missingModule'); +const existingModule_1 = require('./existingModule'); +const missingModule_1 = require('./missingModule'); const test = { x: existingModule_1.x, foo: missingModule_1.foo }; use(existingModule_1.x); use(missingModule_1.foo); diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.js b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.js new file mode 100644 index 0000000000000..d4c419278c7e6 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.js @@ -0,0 +1,7 @@ +//// [sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.ts] + +var [x] = [1, 2]; + +//// [sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.js] +var x = [1, 2][0]; +//# sourceMappingURL=sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.js.map b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.js.map new file mode 100644 index 0000000000000..96fd86faa4ebc --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.js.map @@ -0,0 +1,2 @@ +//// [sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.js.map] +{"version":3,"file":"sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.js","sourceRoot":"","sources":["sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.ts"],"names":[],"mappings":"AACK,iBAAC,CAAW"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.sourcemap.txt b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.sourcemap.txt new file mode 100644 index 0000000000000..a52c7701db2c8 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.sourcemap.txt @@ -0,0 +1,24 @@ +=================================================================== +JsFile: sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.js +mapUrl: sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.js.map +sourceRoot: +sources: sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.js +sourceFile:sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.ts +------------------------------------------------------------------- +>>>var x = [1, 2][0]; +1 > +2 >^^^^^^^^^^^^^^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >var [ +2 >x +3 > ] = [1, 2]; +1 >Emitted(1, 1) Source(2, 6) + SourceIndex(0) +2 >Emitted(1, 18) Source(2, 7) + SourceIndex(0) +3 >Emitted(1, 19) Source(2, 18) + SourceIndex(0) +--- +>>>//# sourceMappingURL=sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.symbols b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.symbols new file mode 100644 index 0000000000000..4695a8cd598c5 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.ts === + +var [x] = [1, 2]; +>x : Symbol(x, Decl(sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.ts, 1, 5)) + diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.types b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.types new file mode 100644 index 0000000000000..461939a11aa2b --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.ts === + +var [x] = [1, 2]; +>x : number +>[1, 2] : [number, number] +>1 : number +>2 : number + diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.js b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.js new file mode 100644 index 0000000000000..10df853c22068 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.js @@ -0,0 +1,9 @@ +//// [sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.ts] + +var [x] = [1, 2]; +var [y, z] = [1, 2]; + +//// [sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.js] +var x = [1, 2][0]; +var _a = [1, 2], y = _a[0], z = _a[1]; +//# sourceMappingURL=sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.js.map b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.js.map new file mode 100644 index 0000000000000..337a73240b98e --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.js.map @@ -0,0 +1,2 @@ +//// [sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.js.map] +{"version":3,"file":"sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.js","sourceRoot":"","sources":["sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.ts"],"names":[],"mappings":"AACK,iBAAC,CAAW;AACjB,IAAA,WAAmB,EAAd,SAAC,EAAE,SAAC,CAAW"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.sourcemap.txt b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.sourcemap.txt new file mode 100644 index 0000000000000..338b64241852c --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.sourcemap.txt @@ -0,0 +1,52 @@ +=================================================================== +JsFile: sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.js +mapUrl: sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.js.map +sourceRoot: +sources: sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.js +sourceFile:sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.ts +------------------------------------------------------------------- +>>>var x = [1, 2][0]; +1 > +2 >^^^^^^^^^^^^^^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^^^^^^^^^-> +1 > + >var [ +2 >x +3 > ] = [1, 2]; +1 >Emitted(1, 1) Source(2, 6) + SourceIndex(0) +2 >Emitted(1, 18) Source(2, 7) + SourceIndex(0) +3 >Emitted(1, 19) Source(2, 18) + SourceIndex(0) +--- +>>>var _a = [1, 2], y = _a[0], z = _a[1]; +1-> +2 >^^^^ +3 > ^^^^^^^^^^^ +4 > ^^ +5 > ^^^^^^^^^ +6 > ^^ +7 > ^^^^^^^^^ +8 > ^ +9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> + > +2 > +3 > var [y, z] = [1, 2] +4 > +5 > y +6 > , +7 > z +8 > ] = [1, 2]; +1->Emitted(2, 1) Source(3, 1) + SourceIndex(0) +2 >Emitted(2, 5) Source(3, 1) + SourceIndex(0) +3 >Emitted(2, 16) Source(3, 20) + SourceIndex(0) +4 >Emitted(2, 18) Source(3, 6) + SourceIndex(0) +5 >Emitted(2, 27) Source(3, 7) + SourceIndex(0) +6 >Emitted(2, 29) Source(3, 9) + SourceIndex(0) +7 >Emitted(2, 38) Source(3, 10) + SourceIndex(0) +8 >Emitted(2, 39) Source(3, 21) + SourceIndex(0) +--- +>>>//# sourceMappingURL=sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.symbols b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.symbols new file mode 100644 index 0000000000000..5954329077267 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.symbols @@ -0,0 +1,9 @@ +=== tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.ts === + +var [x] = [1, 2]; +>x : Symbol(x, Decl(sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.ts, 1, 5)) + +var [y, z] = [1, 2]; +>y : Symbol(y, Decl(sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.ts, 2, 5)) +>z : Symbol(z, Decl(sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.ts, 2, 7)) + diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.types b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.types new file mode 100644 index 0000000000000..1ef747517e416 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.ts === + +var [x] = [1, 2]; +>x : number +>[1, 2] : [number, number] +>1 : number +>2 : number + +var [y, z] = [1, 2]; +>y : number +>z : number +>[1, 2] : [number, number] +>1 : number +>2 : number + diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.js b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.js new file mode 100644 index 0000000000000..d4baadb6562ed --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.js @@ -0,0 +1,7 @@ +//// [sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.ts] + +var [x = 20] = [1, 2]; + +//// [sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.js] +var _a = [1, 2][0], x = _a === void 0 ? 20 : _a; +//# sourceMappingURL=sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.js.map b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.js.map new file mode 100644 index 0000000000000..9594cc2280992 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.js.map @@ -0,0 +1,2 @@ +//// [sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.js.map] +{"version":3,"file":"sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.js","sourceRoot":"","sources":["sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.ts"],"names":[],"mappings":"AACK,kBAAM,EAAN,2BAAM,CAAW"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.sourcemap.txt b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.sourcemap.txt new file mode 100644 index 0000000000000..90ebe4dc9ac49 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.sourcemap.txt @@ -0,0 +1,30 @@ +=================================================================== +JsFile: sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.js +mapUrl: sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.js.map +sourceRoot: +sources: sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.js +sourceFile:sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.ts +------------------------------------------------------------------- +>>>var _a = [1, 2][0], x = _a === void 0 ? 20 : _a; +1 > +2 >^^^^^^^^^^^^^^^^^^ +3 > ^^ +4 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +5 > ^ +6 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >var [ +2 >x = 20 +3 > +4 > x = 20 +5 > ] = [1, 2]; +1 >Emitted(1, 1) Source(2, 6) + SourceIndex(0) +2 >Emitted(1, 19) Source(2, 12) + SourceIndex(0) +3 >Emitted(1, 21) Source(2, 6) + SourceIndex(0) +4 >Emitted(1, 48) Source(2, 12) + SourceIndex(0) +5 >Emitted(1, 49) Source(2, 23) + SourceIndex(0) +--- +>>>//# sourceMappingURL=sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.symbols b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.symbols new file mode 100644 index 0000000000000..6c368f4996e4f --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.ts === + +var [x = 20] = [1, 2]; +>x : Symbol(x, Decl(sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.ts, 1, 5)) + diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.types b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.types new file mode 100644 index 0000000000000..1b94874ae7cda --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.ts === + +var [x = 20] = [1, 2]; +>x : number +>20 : number +>[1, 2] : [number, number] +>1 : number +>2 : number + diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.js b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.js new file mode 100644 index 0000000000000..73d2e85e9daa1 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.js @@ -0,0 +1,7 @@ +//// [sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.ts] + +var [x = 20, j] = [1, 2]; + +//// [sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.js] +var _a = [1, 2], _b = _a[0], x = _b === void 0 ? 20 : _b, j = _a[1]; +//# sourceMappingURL=sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.js.map b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.js.map new file mode 100644 index 0000000000000..0def6b1a7301e --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.js.map @@ -0,0 +1,2 @@ +//// [sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.js.map] +{"version":3,"file":"sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.js","sourceRoot":"","sources":["sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.ts"],"names":[],"mappings":"AACA,IAAA,WAAwB,EAAnB,UAAM,EAAN,2BAAM,EAAE,SAAC,CAAW"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.sourcemap.txt b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.sourcemap.txt new file mode 100644 index 0000000000000..f2a95375f2ad3 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.sourcemap.txt @@ -0,0 +1,45 @@ +=================================================================== +JsFile: sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.js +mapUrl: sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.js.map +sourceRoot: +sources: sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.js +sourceFile:sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.ts +------------------------------------------------------------------- +>>>var _a = [1, 2], _b = _a[0], x = _b === void 0 ? 20 : _b, j = _a[1]; +1 > +2 >^^^^ +3 > ^^^^^^^^^^^ +4 > ^^ +5 > ^^^^^^^^^^ +6 > ^^ +7 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +8 > ^^ +9 > ^^^^^^^^^ +10> ^ +11> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > +2 > +3 > var [x = 20, j] = [1, 2] +4 > +5 > x = 20 +6 > +7 > x = 20 +8 > , +9 > j +10> ] = [1, 2]; +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(1, 5) Source(2, 1) + SourceIndex(0) +3 >Emitted(1, 16) Source(2, 25) + SourceIndex(0) +4 >Emitted(1, 18) Source(2, 6) + SourceIndex(0) +5 >Emitted(1, 28) Source(2, 12) + SourceIndex(0) +6 >Emitted(1, 30) Source(2, 6) + SourceIndex(0) +7 >Emitted(1, 57) Source(2, 12) + SourceIndex(0) +8 >Emitted(1, 59) Source(2, 14) + SourceIndex(0) +9 >Emitted(1, 68) Source(2, 15) + SourceIndex(0) +10>Emitted(1, 69) Source(2, 26) + SourceIndex(0) +--- +>>>//# sourceMappingURL=sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.symbols b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.symbols new file mode 100644 index 0000000000000..4f57dffff26d1 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.ts === + +var [x = 20, j] = [1, 2]; +>x : Symbol(x, Decl(sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.ts, 1, 5)) +>j : Symbol(j, Decl(sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.ts, 1, 12)) + diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.types b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.types new file mode 100644 index 0000000000000..9b369e410a411 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.types @@ -0,0 +1,10 @@ +=== tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.ts === + +var [x = 20, j] = [1, 2]; +>x : number +>20 : number +>j : number +>[1, 2] : [number, number] +>1 : number +>2 : number + diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.js b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.js new file mode 100644 index 0000000000000..8259981857ce0 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.js @@ -0,0 +1,7 @@ +//// [sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.ts] + +var {x} = { x: 20 }; + +//// [sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.js] +var x = { x: 20 }.x; +//# sourceMappingURL=sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.js.map b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.js.map new file mode 100644 index 0000000000000..5ecd598592796 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.js.map @@ -0,0 +1,2 @@ +//// [sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.js.map] +{"version":3,"file":"sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.js","sourceRoot":"","sources":["sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.ts"],"names":[],"mappings":"AACK,mBAAC,CAAc"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.sourcemap.txt b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.sourcemap.txt new file mode 100644 index 0000000000000..8e5860c7a77be --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.sourcemap.txt @@ -0,0 +1,24 @@ +=================================================================== +JsFile: sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.js +mapUrl: sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.js.map +sourceRoot: +sources: sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.js +sourceFile:sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.ts +------------------------------------------------------------------- +>>>var x = { x: 20 }.x; +1 > +2 >^^^^^^^^^^^^^^^^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >var { +2 >x +3 > } = { x: 20 }; +1 >Emitted(1, 1) Source(2, 6) + SourceIndex(0) +2 >Emitted(1, 20) Source(2, 7) + SourceIndex(0) +3 >Emitted(1, 21) Source(2, 21) + SourceIndex(0) +--- +>>>//# sourceMappingURL=sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.symbols b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.symbols new file mode 100644 index 0000000000000..950fca4eb00a4 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.ts === + +var {x} = { x: 20 }; +>x : Symbol(x, Decl(sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.ts, 1, 5)) +>x : Symbol(x, Decl(sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.ts, 1, 11)) + diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.types b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.types new file mode 100644 index 0000000000000..c975a9eaae55b --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.ts === + +var {x} = { x: 20 }; +>x : number +>{ x: 20 } : { x: number; } +>x : number +>20 : number + diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.js b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.js new file mode 100644 index 0000000000000..d4d52e5e8d9d1 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.js @@ -0,0 +1,9 @@ +//// [sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.ts] + +var {x} = { x: 20 }; +var { a, b } = { a: 30, b: 40 }; + +//// [sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.js] +var x = { x: 20 }.x; +var _a = { a: 30, b: 40 }, a = _a.a, b = _a.b; +//# sourceMappingURL=sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.js.map b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.js.map new file mode 100644 index 0000000000000..6d3a8b40d229d --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.js.map @@ -0,0 +1,2 @@ +//// [sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.js.map] +{"version":3,"file":"sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.js","sourceRoot":"","sources":["sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.ts"],"names":[],"mappings":"AACK,mBAAC,CAAc;AACpB,IAAA,qBAA+B,EAAzB,QAAC,EAAE,QAAC,CAAsB"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.sourcemap.txt b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.sourcemap.txt new file mode 100644 index 0000000000000..e9454cb2bfa9c --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.sourcemap.txt @@ -0,0 +1,52 @@ +=================================================================== +JsFile: sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.js +mapUrl: sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.js.map +sourceRoot: +sources: sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.js +sourceFile:sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.ts +------------------------------------------------------------------- +>>>var x = { x: 20 }.x; +1 > +2 >^^^^^^^^^^^^^^^^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >var { +2 >x +3 > } = { x: 20 }; +1 >Emitted(1, 1) Source(2, 6) + SourceIndex(0) +2 >Emitted(1, 20) Source(2, 7) + SourceIndex(0) +3 >Emitted(1, 21) Source(2, 21) + SourceIndex(0) +--- +>>>var _a = { a: 30, b: 40 }, a = _a.a, b = _a.b; +1-> +2 >^^^^ +3 > ^^^^^^^^^^^^^^^^^^^^^ +4 > ^^ +5 > ^^^^^^^^ +6 > ^^ +7 > ^^^^^^^^ +8 > ^ +9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> + > +2 > +3 > var { a, b } = { a: 30, b: 40 } +4 > +5 > a +6 > , +7 > b +8 > } = { a: 30, b: 40 }; +1->Emitted(2, 1) Source(3, 1) + SourceIndex(0) +2 >Emitted(2, 5) Source(3, 1) + SourceIndex(0) +3 >Emitted(2, 26) Source(3, 32) + SourceIndex(0) +4 >Emitted(2, 28) Source(3, 7) + SourceIndex(0) +5 >Emitted(2, 36) Source(3, 8) + SourceIndex(0) +6 >Emitted(2, 38) Source(3, 10) + SourceIndex(0) +7 >Emitted(2, 46) Source(3, 11) + SourceIndex(0) +8 >Emitted(2, 47) Source(3, 33) + SourceIndex(0) +--- +>>>//# sourceMappingURL=sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.symbols b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.symbols new file mode 100644 index 0000000000000..4fa80ecf05e40 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.symbols @@ -0,0 +1,12 @@ +=== tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.ts === + +var {x} = { x: 20 }; +>x : Symbol(x, Decl(sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.ts, 1, 5)) +>x : Symbol(x, Decl(sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.ts, 1, 11)) + +var { a, b } = { a: 30, b: 40 }; +>a : Symbol(a, Decl(sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.ts, 2, 5)) +>b : Symbol(b, Decl(sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.ts, 2, 8)) +>a : Symbol(a, Decl(sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.ts, 2, 16)) +>b : Symbol(b, Decl(sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.ts, 2, 23)) + diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.types b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.types new file mode 100644 index 0000000000000..a694d4ecd29c6 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.ts === + +var {x} = { x: 20 }; +>x : number +>{ x: 20 } : { x: number; } +>x : number +>20 : number + +var { a, b } = { a: 30, b: 40 }; +>a : number +>b : number +>{ a: 30, b: 40 } : { a: number; b: number; } +>a : number +>30 : number +>b : number +>40 : number + diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.js b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.js new file mode 100644 index 0000000000000..f146e4bb8a79c --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.js @@ -0,0 +1,7 @@ +//// [sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.ts] + +var {x = 500} = { x: 20 }; + +//// [sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.js] +var _a = { x: 20 }.x, x = _a === void 0 ? 500 : _a; +//# sourceMappingURL=sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.js.map b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.js.map new file mode 100644 index 0000000000000..975a48aa0ee29 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.js.map @@ -0,0 +1,2 @@ +//// [sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.js.map] +{"version":3,"file":"sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.js","sourceRoot":"","sources":["sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.ts"],"names":[],"mappings":"AACK,oBAAO,EAAP,4BAAO,CAAc"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.sourcemap.txt b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.sourcemap.txt new file mode 100644 index 0000000000000..2fa0c81199b47 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.sourcemap.txt @@ -0,0 +1,30 @@ +=================================================================== +JsFile: sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.js +mapUrl: sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.js.map +sourceRoot: +sources: sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.js +sourceFile:sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.ts +------------------------------------------------------------------- +>>>var _a = { x: 20 }.x, x = _a === void 0 ? 500 : _a; +1 > +2 >^^^^^^^^^^^^^^^^^^^^ +3 > ^^ +4 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +5 > ^ +6 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >var { +2 >x = 500 +3 > +4 > x = 500 +5 > } = { x: 20 }; +1 >Emitted(1, 1) Source(2, 6) + SourceIndex(0) +2 >Emitted(1, 21) Source(2, 13) + SourceIndex(0) +3 >Emitted(1, 23) Source(2, 6) + SourceIndex(0) +4 >Emitted(1, 51) Source(2, 13) + SourceIndex(0) +5 >Emitted(1, 52) Source(2, 27) + SourceIndex(0) +--- +>>>//# sourceMappingURL=sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.symbols b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.symbols new file mode 100644 index 0000000000000..a668ab8e73393 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.ts === + +var {x = 500} = { x: 20 }; +>x : Symbol(x, Decl(sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.ts, 1, 5)) +>x : Symbol(x, Decl(sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.ts, 1, 17)) + diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.types b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.types new file mode 100644 index 0000000000000..bec1b195c9853 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.ts === + +var {x = 500} = { x: 20 }; +>x : number +>500 : number +>{ x: 20 } : { x?: number; } +>x : number +>20 : number + diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.js b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.js new file mode 100644 index 0000000000000..d785d2dd1fd56 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.js @@ -0,0 +1,8 @@ +//// [sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.ts] + +var {x = 500, + y} = { x: 20, y: "hi" }; + +//// [sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.js] +var _a = { x: 20, y: "hi" }, _b = _a.x, x = _b === void 0 ? 500 : _b, y = _a.y; +//# sourceMappingURL=sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.js.map b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.js.map new file mode 100644 index 0000000000000..e0b108863b073 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.js.map @@ -0,0 +1,2 @@ +//// [sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.js.map] +{"version":3,"file":"sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.js","sourceRoot":"","sources":["sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.ts"],"names":[],"mappings":"AACA,IAAA,uBAC4B,EADvB,SAAO,EAAP,4BAAO,EACP,QAAC,CAAuB"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.sourcemap.txt b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.sourcemap.txt new file mode 100644 index 0000000000000..6ae979f8ade1b --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.sourcemap.txt @@ -0,0 +1,47 @@ +=================================================================== +JsFile: sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.js +mapUrl: sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.js.map +sourceRoot: +sources: sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.js +sourceFile:sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.ts +------------------------------------------------------------------- +>>>var _a = { x: 20, y: "hi" }, _b = _a.x, x = _b === void 0 ? 500 : _b, y = _a.y; +1 > +2 >^^^^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^ +4 > ^^ +5 > ^^^^^^^^^ +6 > ^^ +7 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +8 > ^^ +9 > ^^^^^^^^ +10> ^ +11> ^^^^^^^^^^^^^^^^^^-> +1 > + > +2 > +3 > var {x = 500, + > y} = { x: 20, y: "hi" } +4 > +5 > x = 500 +6 > +7 > x = 500 +8 > , + > +9 > y +10> } = { x: 20, y: "hi" }; +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(1, 5) Source(2, 1) + SourceIndex(0) +3 >Emitted(1, 28) Source(3, 29) + SourceIndex(0) +4 >Emitted(1, 30) Source(2, 6) + SourceIndex(0) +5 >Emitted(1, 39) Source(2, 13) + SourceIndex(0) +6 >Emitted(1, 41) Source(2, 6) + SourceIndex(0) +7 >Emitted(1, 69) Source(2, 13) + SourceIndex(0) +8 >Emitted(1, 71) Source(3, 6) + SourceIndex(0) +9 >Emitted(1, 79) Source(3, 7) + SourceIndex(0) +10>Emitted(1, 80) Source(3, 30) + SourceIndex(0) +--- +>>>//# sourceMappingURL=sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.symbols b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.symbols new file mode 100644 index 0000000000000..8404c342c0bf5 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.symbols @@ -0,0 +1,10 @@ +=== tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.ts === + +var {x = 500, +>x : Symbol(x, Decl(sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.ts, 1, 5)) + + y} = { x: 20, y: "hi" }; +>y : Symbol(y, Decl(sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.ts, 1, 13)) +>x : Symbol(x, Decl(sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.ts, 2, 11)) +>y : Symbol(y, Decl(sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.ts, 2, 18)) + diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.types b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.types new file mode 100644 index 0000000000000..1d00ac2d56b9a --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.types @@ -0,0 +1,14 @@ +=== tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.ts === + +var {x = 500, +>x : number +>500 : number + + y} = { x: 20, y: "hi" }; +>y : string +>{ x: 20, y: "hi" } : { x?: number; y: string; } +>x : number +>20 : number +>y : string +>"hi" : string + diff --git a/tests/baselines/reference/specializedOverloadWithRestParameters.errors.txt b/tests/baselines/reference/specializedOverloadWithRestParameters.errors.txt deleted file mode 100644 index 0e67cc37f32c0..0000000000000 --- a/tests/baselines/reference/specializedOverloadWithRestParameters.errors.txt +++ /dev/null @@ -1,21 +0,0 @@ -tests/cases/compiler/specializedOverloadWithRestParameters.ts(3,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/compiler/specializedOverloadWithRestParameters.ts(8,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - - -==== tests/cases/compiler/specializedOverloadWithRestParameters.ts (2 errors) ==== - class Base { foo() { } } - class Derived1 extends Base { bar() { } } - function f(tagName: 'span', ...args): Derived1; // error - ~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - function f(tagName: number, ...args): Base; - function f(tagName: any): Base { - return null; - } - function g(tagName: 'span', arg): Derived1; // error - ~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - function g(tagName: number, arg): Base; - function g(tagName: any): Base { - return null; - } \ No newline at end of file diff --git a/tests/baselines/reference/specializedOverloadWithRestParameters.symbols b/tests/baselines/reference/specializedOverloadWithRestParameters.symbols new file mode 100644 index 0000000000000..77e16aced4d70 --- /dev/null +++ b/tests/baselines/reference/specializedOverloadWithRestParameters.symbols @@ -0,0 +1,48 @@ +=== tests/cases/compiler/specializedOverloadWithRestParameters.ts === +class Base { foo() { } } +>Base : Symbol(Base, Decl(specializedOverloadWithRestParameters.ts, 0, 0)) +>foo : Symbol(foo, Decl(specializedOverloadWithRestParameters.ts, 0, 12)) + +class Derived1 extends Base { bar() { } } +>Derived1 : Symbol(Derived1, Decl(specializedOverloadWithRestParameters.ts, 0, 24)) +>Base : Symbol(Base, Decl(specializedOverloadWithRestParameters.ts, 0, 0)) +>bar : Symbol(bar, Decl(specializedOverloadWithRestParameters.ts, 1, 29)) + +function f(tagName: 'span', ...args): Derived1; // error +>f : Symbol(f, Decl(specializedOverloadWithRestParameters.ts, 1, 41), Decl(specializedOverloadWithRestParameters.ts, 2, 47), Decl(specializedOverloadWithRestParameters.ts, 3, 43)) +>tagName : Symbol(tagName, Decl(specializedOverloadWithRestParameters.ts, 2, 11)) +>args : Symbol(args, Decl(specializedOverloadWithRestParameters.ts, 2, 27)) +>Derived1 : Symbol(Derived1, Decl(specializedOverloadWithRestParameters.ts, 0, 24)) + +function f(tagName: number, ...args): Base; +>f : Symbol(f, Decl(specializedOverloadWithRestParameters.ts, 1, 41), Decl(specializedOverloadWithRestParameters.ts, 2, 47), Decl(specializedOverloadWithRestParameters.ts, 3, 43)) +>tagName : Symbol(tagName, Decl(specializedOverloadWithRestParameters.ts, 3, 11)) +>args : Symbol(args, Decl(specializedOverloadWithRestParameters.ts, 3, 27)) +>Base : Symbol(Base, Decl(specializedOverloadWithRestParameters.ts, 0, 0)) + +function f(tagName: any): Base { +>f : Symbol(f, Decl(specializedOverloadWithRestParameters.ts, 1, 41), Decl(specializedOverloadWithRestParameters.ts, 2, 47), Decl(specializedOverloadWithRestParameters.ts, 3, 43)) +>tagName : Symbol(tagName, Decl(specializedOverloadWithRestParameters.ts, 4, 11)) +>Base : Symbol(Base, Decl(specializedOverloadWithRestParameters.ts, 0, 0)) + + return null; +} +function g(tagName: 'span', arg): Derived1; // error +>g : Symbol(g, Decl(specializedOverloadWithRestParameters.ts, 6, 1), Decl(specializedOverloadWithRestParameters.ts, 7, 43), Decl(specializedOverloadWithRestParameters.ts, 8, 39)) +>tagName : Symbol(tagName, Decl(specializedOverloadWithRestParameters.ts, 7, 11)) +>arg : Symbol(arg, Decl(specializedOverloadWithRestParameters.ts, 7, 27)) +>Derived1 : Symbol(Derived1, Decl(specializedOverloadWithRestParameters.ts, 0, 24)) + +function g(tagName: number, arg): Base; +>g : Symbol(g, Decl(specializedOverloadWithRestParameters.ts, 6, 1), Decl(specializedOverloadWithRestParameters.ts, 7, 43), Decl(specializedOverloadWithRestParameters.ts, 8, 39)) +>tagName : Symbol(tagName, Decl(specializedOverloadWithRestParameters.ts, 8, 11)) +>arg : Symbol(arg, Decl(specializedOverloadWithRestParameters.ts, 8, 27)) +>Base : Symbol(Base, Decl(specializedOverloadWithRestParameters.ts, 0, 0)) + +function g(tagName: any): Base { +>g : Symbol(g, Decl(specializedOverloadWithRestParameters.ts, 6, 1), Decl(specializedOverloadWithRestParameters.ts, 7, 43), Decl(specializedOverloadWithRestParameters.ts, 8, 39)) +>tagName : Symbol(tagName, Decl(specializedOverloadWithRestParameters.ts, 9, 11)) +>Base : Symbol(Base, Decl(specializedOverloadWithRestParameters.ts, 0, 0)) + + return null; +} diff --git a/tests/baselines/reference/specializedOverloadWithRestParameters.types b/tests/baselines/reference/specializedOverloadWithRestParameters.types new file mode 100644 index 0000000000000..1f7fd391ec741 --- /dev/null +++ b/tests/baselines/reference/specializedOverloadWithRestParameters.types @@ -0,0 +1,50 @@ +=== tests/cases/compiler/specializedOverloadWithRestParameters.ts === +class Base { foo() { } } +>Base : Base +>foo : () => void + +class Derived1 extends Base { bar() { } } +>Derived1 : Derived1 +>Base : Base +>bar : () => void + +function f(tagName: 'span', ...args): Derived1; // error +>f : { (tagName: "span", ...args: any[]): Derived1; (tagName: number, ...args: any[]): Base; } +>tagName : "span" +>args : any[] +>Derived1 : Derived1 + +function f(tagName: number, ...args): Base; +>f : { (tagName: "span", ...args: any[]): Derived1; (tagName: number, ...args: any[]): Base; } +>tagName : number +>args : any[] +>Base : Base + +function f(tagName: any): Base { +>f : { (tagName: "span", ...args: any[]): Derived1; (tagName: number, ...args: any[]): Base; } +>tagName : any +>Base : Base + + return null; +>null : null +} +function g(tagName: 'span', arg): Derived1; // error +>g : { (tagName: "span", arg: any): Derived1; (tagName: number, arg: any): Base; } +>tagName : "span" +>arg : any +>Derived1 : Derived1 + +function g(tagName: number, arg): Base; +>g : { (tagName: "span", arg: any): Derived1; (tagName: number, arg: any): Base; } +>tagName : number +>arg : any +>Base : Base + +function g(tagName: any): Base { +>g : { (tagName: "span", arg: any): Derived1; (tagName: number, arg: any): Base; } +>tagName : any +>Base : Base + + return null; +>null : null +} diff --git a/tests/baselines/reference/specializedSignatureAsCallbackParameter1.errors.txt b/tests/baselines/reference/specializedSignatureAsCallbackParameter1.errors.txt index 1fb3082622ade..61b499e0aee7a 100644 --- a/tests/baselines/reference/specializedSignatureAsCallbackParameter1.errors.txt +++ b/tests/baselines/reference/specializedSignatureAsCallbackParameter1.errors.txt @@ -1,9 +1,8 @@ tests/cases/compiler/specializedSignatureAsCallbackParameter1.ts(7,4): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. tests/cases/compiler/specializedSignatureAsCallbackParameter1.ts(8,4): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. -tests/cases/compiler/specializedSignatureAsCallbackParameter1.ts(8,7): error TS2381: A signature with an implementation cannot use a string literal type. -==== tests/cases/compiler/specializedSignatureAsCallbackParameter1.ts (3 errors) ==== +==== tests/cases/compiler/specializedSignatureAsCallbackParameter1.ts (2 errors) ==== function x3(a: number, cb: (x: number) => number); function x3(a: string, cb: (x: number) => number); function x3(a: any, cb: (x: number) => number) { @@ -15,6 +14,4 @@ tests/cases/compiler/specializedSignatureAsCallbackParameter1.ts(8,7): error TS2 !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. x3(1, (x: 'hm') => 1); ~ -!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. - ~~~~~~~~~~~~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. \ No newline at end of file +!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.errors.txt b/tests/baselines/reference/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.errors.txt index a9293a83a1377..73318e782a311 100644 --- a/tests/baselines/reference/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.errors.txt +++ b/tests/baselines/reference/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.errors.txt @@ -1,91 +1,56 @@ -tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.ts(4,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.ts(8,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.ts(14,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.ts(20,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.ts(26,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.ts(28,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.ts(33,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.ts(35,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.ts(40,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.ts(42,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.ts(47,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.ts(49,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. +tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.ts(2,10): error TS2394: Overload signature is not compatible with function implementation. -==== tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.ts (12 errors) ==== - // Specialized signatures must be a subtype of a non-specialized signature - // All the below should be errors +==== tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.ts (1 errors) ==== function foo(x: 'a'); ~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. +!!! error TS2394: Overload signature is not compatible with function implementation. function foo(x: number) { } class C { foo(x: 'a'); - ~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. foo(x: number); foo(x: any) { } } class C2 { foo(x: 'a'); - ~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. foo(x: T); foo(x: any) { } } class C3 { foo(x: 'a'); - ~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. foo(x: T); foo(x: any) { } } interface I { (x: 'a'); - ~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. (x: number); foo(x: 'a'); - ~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. foo(x: number); } interface I2 { (x: 'a'); - ~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. (x: T); foo(x: 'a'); - ~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. foo(x: T); } interface I3 { (x: 'a'); - ~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. (x: T); foo(x: 'a'); - ~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. foo(x: T); } var a: { (x: 'a'); - ~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. (x: number); foo(x: 'a'); - ~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. foo(x: number); } diff --git a/tests/baselines/reference/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.js b/tests/baselines/reference/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.js index f2946cbeab8e8..bb2dab559576b 100644 --- a/tests/baselines/reference/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.js +++ b/tests/baselines/reference/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.js @@ -1,6 +1,4 @@ //// [specializedSignatureIsNotSubtypeOfNonSpecializedSignature.ts] -// Specialized signatures must be a subtype of a non-specialized signature -// All the below should be errors function foo(x: 'a'); function foo(x: number) { } @@ -67,8 +65,6 @@ var a3: { //// [specializedSignatureIsNotSubtypeOfNonSpecializedSignature.js] -// Specialized signatures must be a subtype of a non-specialized signature -// All the below should be errors function foo(x) { } var C = (function () { function C() { @@ -91,3 +87,55 @@ var C3 = (function () { var a; var a2; var a3; + + +//// [specializedSignatureIsNotSubtypeOfNonSpecializedSignature.d.ts] +declare function foo(x: 'a'): any; +declare class C { + foo(x: 'a'): any; + foo(x: number): any; +} +declare class C2 { + foo(x: 'a'): any; + foo(x: T): any; +} +declare class C3 { + foo(x: 'a'): any; + foo(x: T): any; +} +interface I { + (x: 'a'): any; + (x: number): any; + foo(x: 'a'): any; + foo(x: number): any; +} +interface I2 { + (x: 'a'): any; + (x: T): any; + foo(x: 'a'): any; + foo(x: T): any; +} +interface I3 { + (x: 'a'): any; + (x: T): any; + foo(x: 'a'): any; + foo(x: T): any; +} +declare var a: { + (x: 'a'); + (x: number); + foo(x: 'a'); + foo(x: number); +}; +declare var a2: { + (x: 'a'); + (x: T); + foo(x: 'a'); + foo(x: T); +}; +declare var a3: { + (x: 'a'); + (x: T); + foo(x: 'a'); + foo(x: T); +}; diff --git a/tests/baselines/reference/specializedSignatureOverloadReturnTypeWithIndexers.errors.txt b/tests/baselines/reference/specializedSignatureOverloadReturnTypeWithIndexers.errors.txt deleted file mode 100644 index 788a8092ec7de..0000000000000 --- a/tests/baselines/reference/specializedSignatureOverloadReturnTypeWithIndexers.errors.txt +++ /dev/null @@ -1,22 +0,0 @@ -tests/cases/compiler/specializedSignatureOverloadReturnTypeWithIndexers.ts(15,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - - -==== tests/cases/compiler/specializedSignatureOverloadReturnTypeWithIndexers.ts (1 errors) ==== - interface A { - f(p: string): { [p: string]: string; }; - f(p: "spec"): { [p: string]: any; } // Should be ok - } - interface B { - f(p: string): { [p: number]: string; }; - f(p: "spec"): { [p: string]: any; } // Should be ok - } - interface C { - f(p: string): { [p: number]: string; }; - f(p: "spec"): { [p: number]: any; } // Should be ok - } - interface D { - f(p: string): { [p: string]: string; }; - f(p: "spec"): { [p: number]: any; } // Should be error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - } \ No newline at end of file diff --git a/tests/baselines/reference/specializedSignatureOverloadReturnTypeWithIndexers.symbols b/tests/baselines/reference/specializedSignatureOverloadReturnTypeWithIndexers.symbols new file mode 100644 index 0000000000000..ea966cfda18c0 --- /dev/null +++ b/tests/baselines/reference/specializedSignatureOverloadReturnTypeWithIndexers.symbols @@ -0,0 +1,53 @@ +=== tests/cases/compiler/specializedSignatureOverloadReturnTypeWithIndexers.ts === +interface A { +>A : Symbol(A, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 0, 0)) + + f(p: string): { [p: string]: string; }; +>f : Symbol(f, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 0, 13), Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 1, 43)) +>p : Symbol(p, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 1, 6)) +>p : Symbol(p, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 1, 21)) + + f(p: "spec"): { [p: string]: any; } // Should be ok +>f : Symbol(f, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 0, 13), Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 1, 43)) +>p : Symbol(p, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 2, 6)) +>p : Symbol(p, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 2, 21)) +} +interface B { +>B : Symbol(B, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 3, 1)) + + f(p: string): { [p: number]: string; }; +>f : Symbol(f, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 4, 13), Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 5, 43)) +>p : Symbol(p, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 5, 6)) +>p : Symbol(p, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 5, 21)) + + f(p: "spec"): { [p: string]: any; } // Should be ok +>f : Symbol(f, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 4, 13), Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 5, 43)) +>p : Symbol(p, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 6, 6)) +>p : Symbol(p, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 6, 21)) +} +interface C { +>C : Symbol(C, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 7, 1)) + + f(p: string): { [p: number]: string; }; +>f : Symbol(f, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 8, 13), Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 9, 43)) +>p : Symbol(p, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 9, 6)) +>p : Symbol(p, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 9, 21)) + + f(p: "spec"): { [p: number]: any; } // Should be ok +>f : Symbol(f, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 8, 13), Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 9, 43)) +>p : Symbol(p, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 10, 6)) +>p : Symbol(p, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 10, 21)) +} +interface D { +>D : Symbol(D, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 11, 1)) + + f(p: string): { [p: string]: string; }; +>f : Symbol(f, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 12, 13), Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 13, 43)) +>p : Symbol(p, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 13, 6)) +>p : Symbol(p, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 13, 21)) + + f(p: "spec"): { [p: number]: any; } // Should be error +>f : Symbol(f, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 12, 13), Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 13, 43)) +>p : Symbol(p, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 14, 6)) +>p : Symbol(p, Decl(specializedSignatureOverloadReturnTypeWithIndexers.ts, 14, 21)) +} diff --git a/tests/baselines/reference/specializedSignatureOverloadReturnTypeWithIndexers.types b/tests/baselines/reference/specializedSignatureOverloadReturnTypeWithIndexers.types new file mode 100644 index 0000000000000..1a7e9549327fe --- /dev/null +++ b/tests/baselines/reference/specializedSignatureOverloadReturnTypeWithIndexers.types @@ -0,0 +1,53 @@ +=== tests/cases/compiler/specializedSignatureOverloadReturnTypeWithIndexers.ts === +interface A { +>A : A + + f(p: string): { [p: string]: string; }; +>f : { (p: string): { [p: string]: string; }; (p: "spec"): { [p: string]: any; }; } +>p : string +>p : string + + f(p: "spec"): { [p: string]: any; } // Should be ok +>f : { (p: string): { [p: string]: string; }; (p: "spec"): { [p: string]: any; }; } +>p : "spec" +>p : string +} +interface B { +>B : B + + f(p: string): { [p: number]: string; }; +>f : { (p: string): { [p: number]: string; }; (p: "spec"): { [p: string]: any; }; } +>p : string +>p : number + + f(p: "spec"): { [p: string]: any; } // Should be ok +>f : { (p: string): { [p: number]: string; }; (p: "spec"): { [p: string]: any; }; } +>p : "spec" +>p : string +} +interface C { +>C : C + + f(p: string): { [p: number]: string; }; +>f : { (p: string): { [p: number]: string; }; (p: "spec"): { [p: number]: any; }; } +>p : string +>p : number + + f(p: "spec"): { [p: number]: any; } // Should be ok +>f : { (p: string): { [p: number]: string; }; (p: "spec"): { [p: number]: any; }; } +>p : "spec" +>p : number +} +interface D { +>D : D + + f(p: string): { [p: string]: string; }; +>f : { (p: string): { [p: string]: string; }; (p: "spec"): { [p: number]: any; }; } +>p : string +>p : string + + f(p: "spec"): { [p: number]: any; } // Should be error +>f : { (p: string): { [p: string]: string; }; (p: "spec"): { [p: number]: any; }; } +>p : "spec" +>p : number +} diff --git a/tests/baselines/reference/staticAsIdentifier.errors.txt b/tests/baselines/reference/staticAsIdentifier.errors.txt index 52108a5a2214b..4173b0b14c5d3 100644 --- a/tests/baselines/reference/staticAsIdentifier.errors.txt +++ b/tests/baselines/reference/staticAsIdentifier.errors.txt @@ -1,10 +1,10 @@ -tests/cases/compiler/staticAsIdentifier.ts(2,12): error TS1030: 'static' modifier already seen. +tests/cases/compiler/staticAsIdentifier.ts(2,5): error TS1071: 'static' modifier cannot appear on an index signature. ==== tests/cases/compiler/staticAsIdentifier.ts (1 errors) ==== class C { static static - ~~~~~~ -!!! error TS1030: 'static' modifier already seen. + ~~~~~~ +!!! error TS1071: 'static' modifier cannot appear on an index signature. [x: string]: string; } \ No newline at end of file diff --git a/tests/baselines/reference/staticIndexer.errors.txt b/tests/baselines/reference/staticIndexer.errors.txt index 3e91012105116..19ed61df658f3 100644 --- a/tests/baselines/reference/staticIndexer.errors.txt +++ b/tests/baselines/reference/staticIndexer.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/staticIndexer.ts(2,5): error TS1145: Modifiers not permitted on index signature members. +tests/cases/compiler/staticIndexer.ts(2,5): error TS1071: 'static' modifier cannot appear on an index signature. ==== tests/cases/compiler/staticIndexer.ts (1 errors) ==== class C { static [s: string]: number; ~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'static' modifier cannot appear on an index signature. } \ No newline at end of file diff --git a/tests/baselines/reference/staticIndexers.errors.txt b/tests/baselines/reference/staticIndexers.errors.txt index 29c46d0ce8c50..8223a38a9ae40 100644 --- a/tests/baselines/reference/staticIndexers.errors.txt +++ b/tests/baselines/reference/staticIndexers.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(4,5): error TS1145: Modifiers not permitted on index signature members. -tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(8,5): error TS1145: Modifiers not permitted on index signature members. -tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(12,5): error TS1145: Modifiers not permitted on index signature members. +tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(4,5): error TS1071: 'static' modifier cannot appear on an index signature. +tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(8,5): error TS1071: 'static' modifier cannot appear on an index signature. +tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(12,5): error TS1071: 'static' modifier cannot appear on an index signature. tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(12,25): error TS2302: Static members cannot reference class type parameters. @@ -10,19 +10,19 @@ tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(12,25) class C { static [x: string]: string; ~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'static' modifier cannot appear on an index signature. } class D { static [x: number]: string; ~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'static' modifier cannot appear on an index signature. } class E { static [x: string]: T; ~~~~~~ -!!! error TS1145: Modifiers not permitted on index signature members. +!!! error TS1071: 'static' modifier cannot appear on an index signature. ~ !!! error TS2302: Static members cannot reference class type parameters. } \ No newline at end of file diff --git a/tests/baselines/reference/staticInstanceResolution5.errors.txt b/tests/baselines/reference/staticInstanceResolution5.errors.txt index 3c1cee93fd548..da6f0fde1433a 100644 --- a/tests/baselines/reference/staticInstanceResolution5.errors.txt +++ b/tests/baselines/reference/staticInstanceResolution5.errors.txt @@ -1,15 +1,21 @@ -tests/cases/compiler/staticInstanceResolution5_1.ts(1,24): error TS2307: Cannot find module 'staticInstanceResolution5_0.ts'. +tests/cases/compiler/staticInstanceResolution5_1.ts(4,14): error TS2304: Cannot find name 'WinJS'. +tests/cases/compiler/staticInstanceResolution5_1.ts(5,23): error TS2304: Cannot find name 'WinJS'. +tests/cases/compiler/staticInstanceResolution5_1.ts(6,16): error TS2304: Cannot find name 'WinJS'. -==== tests/cases/compiler/staticInstanceResolution5_1.ts (1 errors) ==== +==== tests/cases/compiler/staticInstanceResolution5_1.ts (3 errors) ==== import WinJS = require('staticInstanceResolution5_0.ts'); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2307: Cannot find module 'staticInstanceResolution5_0.ts'. // these 3 should be errors var x = (w1: WinJS) => { }; + ~~~~~ +!!! error TS2304: Cannot find name 'WinJS'. var y = function (w2: WinJS) { } + ~~~~~ +!!! error TS2304: Cannot find name 'WinJS'. function z(w3: WinJS) { } + ~~~~~ +!!! error TS2304: Cannot find name 'WinJS'. ==== tests/cases/compiler/staticInstanceResolution5_0.ts (0 errors) ==== export class Promise { diff --git a/tests/baselines/reference/staticInstanceResolution5.js b/tests/baselines/reference/staticInstanceResolution5.js index 58def522978b3..0809d1af5f059 100644 --- a/tests/baselines/reference/staticInstanceResolution5.js +++ b/tests/baselines/reference/staticInstanceResolution5.js @@ -16,6 +16,19 @@ var y = function (w2: WinJS) { } function z(w3: WinJS) { } +//// [staticInstanceResolution5_0.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + var Promise = (function () { + function Promise() { + } + Promise.timeout = function (delay) { + return null; + }; + return Promise; + }()); + exports.Promise = Promise; +}); //// [staticInstanceResolution5_1.js] define(["require", "exports"], function (require, exports) { "use strict"; diff --git a/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.errors.txt b/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.errors.txt deleted file mode 100644 index af75273ade3d5..0000000000000 --- a/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.errors.txt +++ /dev/null @@ -1,124 +0,0 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(22,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(26,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(30,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(34,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(38,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(77,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts(90,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - - -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts (7 errors) ==== - // string literal types are subtypes of string, any - - // ok - function f1(x: 'a'); - function f1(x: string); - function f1(x: string) { } - - // ok - function f2(x: 'a'); - function f2(x: any); - function f2(x: any) { } - - // errors - function f3(x: 'a'); - function f3(x: Object); - function f3(x: any) { } - - function f4(x: 'a'); - function f4(x: {}); - function f4(x: any) { } - - function f5(x: 'a'); - ~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - function f5(x: number); - function f5(x: any) { } - - function f6(x: 'a'); - ~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - function f6(x: boolean); - function f6(x: any) { } - - function f7(x: 'a'); - ~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - function f7(x: Date); - function f7(x: any) { } - - function f8(x: 'a'); - ~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - function f8(x: RegExp); - function f8(x: any) { } - - function f9(x: 'a'); - ~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - function f9(x: () => {}); - function f9(x: any) { } - - class C implements String { - toString(): string { return null; } - charAt(pos: number): string { return null; } - charCodeAt(index: number): number { return null; } - concat(...strings: string[]): string { return null; } - indexOf(searchString: string, position?: number): number { return null; } - lastIndexOf(searchString: string, position?: number): number { return null; } - localeCompare(that: string): number { return null; } - match(regexp: any): string[] { return null; } - replace(searchValue: any, replaceValue: any): string { return null; } - search(regexp: any): number { return null; } - slice(start?: number, end?: number): string { return null; } - split(separator: any, limit?: number): string[] { return null; } - substring(start: number, end?: number): string { return null; } - toLowerCase(): string { return null; } - toLocaleLowerCase(): string { return null; } - toUpperCase(): string { return null; } - toLocaleUpperCase(): string { return null; } - trim(): string { return null; } - length: number; - substr(from: number, length?: number): string { return null; } - valueOf(): string { return null; } - [index: number]: string; - } - - // BUG 831846 - function f10(x: 'a'); - function f10(x: C); - function f10(x: any) { } - - interface I extends String { - foo: string; - } - - // BUG 831846 - function f11(x: 'a'); - ~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - function f11(x: I); - function f11(x: any) { } - - function f12(x: 'a'); - function f12(x: T); - function f12(x: any) { } - - function f13(x: 'a'); - function f13(x: T); - function f13(x: any) { } - - enum E { A } - function f14(x: 'a'); - ~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - function f14(x: E); - function f14(x: any) { } - - function f15(x: 'a'); - function f15(x: U); - function f15(x: any) { } - - function f16(x: 'a'); - function f16(x: U); - function f16(x: any) { } \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.symbols b/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.symbols new file mode 100644 index 0000000000000..1a49a6a6c4786 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.symbols @@ -0,0 +1,343 @@ +=== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts === +// string literal types are subtypes of string, any + +// ok +function f1(x: 'a'); +>f1 : Symbol(f1, Decl(stringLiteralTypeIsSubtypeOfString.ts, 0, 0), Decl(stringLiteralTypeIsSubtypeOfString.ts, 3, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 4, 23)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 3, 12)) + +function f1(x: string); +>f1 : Symbol(f1, Decl(stringLiteralTypeIsSubtypeOfString.ts, 0, 0), Decl(stringLiteralTypeIsSubtypeOfString.ts, 3, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 4, 23)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 4, 12)) + +function f1(x: string) { } +>f1 : Symbol(f1, Decl(stringLiteralTypeIsSubtypeOfString.ts, 0, 0), Decl(stringLiteralTypeIsSubtypeOfString.ts, 3, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 4, 23)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 5, 12)) + +// ok +function f2(x: 'a'); +>f2 : Symbol(f2, Decl(stringLiteralTypeIsSubtypeOfString.ts, 5, 26), Decl(stringLiteralTypeIsSubtypeOfString.ts, 8, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 9, 20)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 8, 12)) + +function f2(x: any); +>f2 : Symbol(f2, Decl(stringLiteralTypeIsSubtypeOfString.ts, 5, 26), Decl(stringLiteralTypeIsSubtypeOfString.ts, 8, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 9, 20)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 9, 12)) + +function f2(x: any) { } +>f2 : Symbol(f2, Decl(stringLiteralTypeIsSubtypeOfString.ts, 5, 26), Decl(stringLiteralTypeIsSubtypeOfString.ts, 8, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 9, 20)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 10, 12)) + +// errors +function f3(x: 'a'); +>f3 : Symbol(f3, Decl(stringLiteralTypeIsSubtypeOfString.ts, 10, 23), Decl(stringLiteralTypeIsSubtypeOfString.ts, 13, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 14, 23)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 13, 12)) + +function f3(x: Object); +>f3 : Symbol(f3, Decl(stringLiteralTypeIsSubtypeOfString.ts, 10, 23), Decl(stringLiteralTypeIsSubtypeOfString.ts, 13, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 14, 23)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 14, 12)) +>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +function f3(x: any) { } +>f3 : Symbol(f3, Decl(stringLiteralTypeIsSubtypeOfString.ts, 10, 23), Decl(stringLiteralTypeIsSubtypeOfString.ts, 13, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 14, 23)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 15, 12)) + +function f4(x: 'a'); +>f4 : Symbol(f4, Decl(stringLiteralTypeIsSubtypeOfString.ts, 15, 23), Decl(stringLiteralTypeIsSubtypeOfString.ts, 17, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 18, 19)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 17, 12)) + +function f4(x: {}); +>f4 : Symbol(f4, Decl(stringLiteralTypeIsSubtypeOfString.ts, 15, 23), Decl(stringLiteralTypeIsSubtypeOfString.ts, 17, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 18, 19)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 18, 12)) + +function f4(x: any) { } +>f4 : Symbol(f4, Decl(stringLiteralTypeIsSubtypeOfString.ts, 15, 23), Decl(stringLiteralTypeIsSubtypeOfString.ts, 17, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 18, 19)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 19, 12)) + +function f5(x: 'a'); +>f5 : Symbol(f5, Decl(stringLiteralTypeIsSubtypeOfString.ts, 19, 23), Decl(stringLiteralTypeIsSubtypeOfString.ts, 21, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 22, 23)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 21, 12)) + +function f5(x: number); +>f5 : Symbol(f5, Decl(stringLiteralTypeIsSubtypeOfString.ts, 19, 23), Decl(stringLiteralTypeIsSubtypeOfString.ts, 21, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 22, 23)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 22, 12)) + +function f5(x: any) { } +>f5 : Symbol(f5, Decl(stringLiteralTypeIsSubtypeOfString.ts, 19, 23), Decl(stringLiteralTypeIsSubtypeOfString.ts, 21, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 22, 23)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 23, 12)) + +function f6(x: 'a'); +>f6 : Symbol(f6, Decl(stringLiteralTypeIsSubtypeOfString.ts, 23, 23), Decl(stringLiteralTypeIsSubtypeOfString.ts, 25, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 26, 24)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 25, 12)) + +function f6(x: boolean); +>f6 : Symbol(f6, Decl(stringLiteralTypeIsSubtypeOfString.ts, 23, 23), Decl(stringLiteralTypeIsSubtypeOfString.ts, 25, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 26, 24)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 26, 12)) + +function f6(x: any) { } +>f6 : Symbol(f6, Decl(stringLiteralTypeIsSubtypeOfString.ts, 23, 23), Decl(stringLiteralTypeIsSubtypeOfString.ts, 25, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 26, 24)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 27, 12)) + +function f7(x: 'a'); +>f7 : Symbol(f7, Decl(stringLiteralTypeIsSubtypeOfString.ts, 27, 23), Decl(stringLiteralTypeIsSubtypeOfString.ts, 29, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 30, 21)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 29, 12)) + +function f7(x: Date); +>f7 : Symbol(f7, Decl(stringLiteralTypeIsSubtypeOfString.ts, 27, 23), Decl(stringLiteralTypeIsSubtypeOfString.ts, 29, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 30, 21)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 30, 12)) +>Date : Symbol(Date, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +function f7(x: any) { } +>f7 : Symbol(f7, Decl(stringLiteralTypeIsSubtypeOfString.ts, 27, 23), Decl(stringLiteralTypeIsSubtypeOfString.ts, 29, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 30, 21)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 31, 12)) + +function f8(x: 'a'); +>f8 : Symbol(f8, Decl(stringLiteralTypeIsSubtypeOfString.ts, 31, 23), Decl(stringLiteralTypeIsSubtypeOfString.ts, 33, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 34, 23)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 33, 12)) + +function f8(x: RegExp); +>f8 : Symbol(f8, Decl(stringLiteralTypeIsSubtypeOfString.ts, 31, 23), Decl(stringLiteralTypeIsSubtypeOfString.ts, 33, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 34, 23)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 34, 12)) +>RegExp : Symbol(RegExp, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +function f8(x: any) { } +>f8 : Symbol(f8, Decl(stringLiteralTypeIsSubtypeOfString.ts, 31, 23), Decl(stringLiteralTypeIsSubtypeOfString.ts, 33, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 34, 23)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 35, 12)) + +function f9(x: 'a'); +>f9 : Symbol(f9, Decl(stringLiteralTypeIsSubtypeOfString.ts, 35, 23), Decl(stringLiteralTypeIsSubtypeOfString.ts, 37, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 38, 25)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 37, 12)) + +function f9(x: () => {}); +>f9 : Symbol(f9, Decl(stringLiteralTypeIsSubtypeOfString.ts, 35, 23), Decl(stringLiteralTypeIsSubtypeOfString.ts, 37, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 38, 25)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 38, 12)) + +function f9(x: any) { } +>f9 : Symbol(f9, Decl(stringLiteralTypeIsSubtypeOfString.ts, 35, 23), Decl(stringLiteralTypeIsSubtypeOfString.ts, 37, 20), Decl(stringLiteralTypeIsSubtypeOfString.ts, 38, 25)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 39, 12)) + +class C implements String { +>C : Symbol(C, Decl(stringLiteralTypeIsSubtypeOfString.ts, 39, 23)) +>String : Symbol(String, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + + toString(): string { return null; } +>toString : Symbol(toString, Decl(stringLiteralTypeIsSubtypeOfString.ts, 41, 27)) + + charAt(pos: number): string { return null; } +>charAt : Symbol(charAt, Decl(stringLiteralTypeIsSubtypeOfString.ts, 42, 39)) +>pos : Symbol(pos, Decl(stringLiteralTypeIsSubtypeOfString.ts, 43, 11)) + + charCodeAt(index: number): number { return null; } +>charCodeAt : Symbol(charCodeAt, Decl(stringLiteralTypeIsSubtypeOfString.ts, 43, 48)) +>index : Symbol(index, Decl(stringLiteralTypeIsSubtypeOfString.ts, 44, 15)) + + concat(...strings: string[]): string { return null; } +>concat : Symbol(concat, Decl(stringLiteralTypeIsSubtypeOfString.ts, 44, 54)) +>strings : Symbol(strings, Decl(stringLiteralTypeIsSubtypeOfString.ts, 45, 11)) + + indexOf(searchString: string, position?: number): number { return null; } +>indexOf : Symbol(indexOf, Decl(stringLiteralTypeIsSubtypeOfString.ts, 45, 57)) +>searchString : Symbol(searchString, Decl(stringLiteralTypeIsSubtypeOfString.ts, 46, 12)) +>position : Symbol(position, Decl(stringLiteralTypeIsSubtypeOfString.ts, 46, 33)) + + lastIndexOf(searchString: string, position?: number): number { return null; } +>lastIndexOf : Symbol(lastIndexOf, Decl(stringLiteralTypeIsSubtypeOfString.ts, 46, 77)) +>searchString : Symbol(searchString, Decl(stringLiteralTypeIsSubtypeOfString.ts, 47, 16)) +>position : Symbol(position, Decl(stringLiteralTypeIsSubtypeOfString.ts, 47, 37)) + + localeCompare(that: string): number { return null; } +>localeCompare : Symbol(localeCompare, Decl(stringLiteralTypeIsSubtypeOfString.ts, 47, 81)) +>that : Symbol(that, Decl(stringLiteralTypeIsSubtypeOfString.ts, 48, 18)) + + match(regexp: any): string[] { return null; } +>match : Symbol(match, Decl(stringLiteralTypeIsSubtypeOfString.ts, 48, 56)) +>regexp : Symbol(regexp, Decl(stringLiteralTypeIsSubtypeOfString.ts, 49, 10)) + + replace(searchValue: any, replaceValue: any): string { return null; } +>replace : Symbol(replace, Decl(stringLiteralTypeIsSubtypeOfString.ts, 49, 49)) +>searchValue : Symbol(searchValue, Decl(stringLiteralTypeIsSubtypeOfString.ts, 50, 12)) +>replaceValue : Symbol(replaceValue, Decl(stringLiteralTypeIsSubtypeOfString.ts, 50, 29)) + + search(regexp: any): number { return null; } +>search : Symbol(search, Decl(stringLiteralTypeIsSubtypeOfString.ts, 50, 73)) +>regexp : Symbol(regexp, Decl(stringLiteralTypeIsSubtypeOfString.ts, 51, 11)) + + slice(start?: number, end?: number): string { return null; } +>slice : Symbol(slice, Decl(stringLiteralTypeIsSubtypeOfString.ts, 51, 48)) +>start : Symbol(start, Decl(stringLiteralTypeIsSubtypeOfString.ts, 52, 10)) +>end : Symbol(end, Decl(stringLiteralTypeIsSubtypeOfString.ts, 52, 25)) + + split(separator: any, limit?: number): string[] { return null; } +>split : Symbol(split, Decl(stringLiteralTypeIsSubtypeOfString.ts, 52, 64)) +>separator : Symbol(separator, Decl(stringLiteralTypeIsSubtypeOfString.ts, 53, 10)) +>limit : Symbol(limit, Decl(stringLiteralTypeIsSubtypeOfString.ts, 53, 25)) + + substring(start: number, end?: number): string { return null; } +>substring : Symbol(substring, Decl(stringLiteralTypeIsSubtypeOfString.ts, 53, 68)) +>start : Symbol(start, Decl(stringLiteralTypeIsSubtypeOfString.ts, 54, 14)) +>end : Symbol(end, Decl(stringLiteralTypeIsSubtypeOfString.ts, 54, 28)) + + toLowerCase(): string { return null; } +>toLowerCase : Symbol(toLowerCase, Decl(stringLiteralTypeIsSubtypeOfString.ts, 54, 67)) + + toLocaleLowerCase(): string { return null; } +>toLocaleLowerCase : Symbol(toLocaleLowerCase, Decl(stringLiteralTypeIsSubtypeOfString.ts, 55, 42)) + + toUpperCase(): string { return null; } +>toUpperCase : Symbol(toUpperCase, Decl(stringLiteralTypeIsSubtypeOfString.ts, 56, 48)) + + toLocaleUpperCase(): string { return null; } +>toLocaleUpperCase : Symbol(toLocaleUpperCase, Decl(stringLiteralTypeIsSubtypeOfString.ts, 57, 42)) + + trim(): string { return null; } +>trim : Symbol(trim, Decl(stringLiteralTypeIsSubtypeOfString.ts, 58, 48)) + + length: number; +>length : Symbol(length, Decl(stringLiteralTypeIsSubtypeOfString.ts, 59, 35)) + + substr(from: number, length?: number): string { return null; } +>substr : Symbol(substr, Decl(stringLiteralTypeIsSubtypeOfString.ts, 60, 19)) +>from : Symbol(from, Decl(stringLiteralTypeIsSubtypeOfString.ts, 61, 11)) +>length : Symbol(length, Decl(stringLiteralTypeIsSubtypeOfString.ts, 61, 24)) + + valueOf(): string { return null; } +>valueOf : Symbol(valueOf, Decl(stringLiteralTypeIsSubtypeOfString.ts, 61, 66)) + + [index: number]: string; +>index : Symbol(index, Decl(stringLiteralTypeIsSubtypeOfString.ts, 63, 5)) +} + +// BUG 831846 +function f10(x: 'a'); +>f10 : Symbol(f10, Decl(stringLiteralTypeIsSubtypeOfString.ts, 64, 1), Decl(stringLiteralTypeIsSubtypeOfString.ts, 67, 21), Decl(stringLiteralTypeIsSubtypeOfString.ts, 68, 19)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 67, 13)) + +function f10(x: C); +>f10 : Symbol(f10, Decl(stringLiteralTypeIsSubtypeOfString.ts, 64, 1), Decl(stringLiteralTypeIsSubtypeOfString.ts, 67, 21), Decl(stringLiteralTypeIsSubtypeOfString.ts, 68, 19)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 68, 13)) +>C : Symbol(C, Decl(stringLiteralTypeIsSubtypeOfString.ts, 39, 23)) + +function f10(x: any) { } +>f10 : Symbol(f10, Decl(stringLiteralTypeIsSubtypeOfString.ts, 64, 1), Decl(stringLiteralTypeIsSubtypeOfString.ts, 67, 21), Decl(stringLiteralTypeIsSubtypeOfString.ts, 68, 19)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 69, 13)) + +interface I extends String { +>I : Symbol(I, Decl(stringLiteralTypeIsSubtypeOfString.ts, 69, 24)) +>String : Symbol(String, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + + foo: string; +>foo : Symbol(foo, Decl(stringLiteralTypeIsSubtypeOfString.ts, 71, 28)) +} + +// BUG 831846 +function f11(x: 'a'); +>f11 : Symbol(f11, Decl(stringLiteralTypeIsSubtypeOfString.ts, 73, 1), Decl(stringLiteralTypeIsSubtypeOfString.ts, 76, 21), Decl(stringLiteralTypeIsSubtypeOfString.ts, 77, 19)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 76, 13)) + +function f11(x: I); +>f11 : Symbol(f11, Decl(stringLiteralTypeIsSubtypeOfString.ts, 73, 1), Decl(stringLiteralTypeIsSubtypeOfString.ts, 76, 21), Decl(stringLiteralTypeIsSubtypeOfString.ts, 77, 19)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 77, 13)) +>I : Symbol(I, Decl(stringLiteralTypeIsSubtypeOfString.ts, 69, 24)) + +function f11(x: any) { } +>f11 : Symbol(f11, Decl(stringLiteralTypeIsSubtypeOfString.ts, 73, 1), Decl(stringLiteralTypeIsSubtypeOfString.ts, 76, 21), Decl(stringLiteralTypeIsSubtypeOfString.ts, 77, 19)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 78, 13)) + +function f12(x: 'a'); +>f12 : Symbol(f12, Decl(stringLiteralTypeIsSubtypeOfString.ts, 78, 24), Decl(stringLiteralTypeIsSubtypeOfString.ts, 80, 24), Decl(stringLiteralTypeIsSubtypeOfString.ts, 81, 22)) +>T : Symbol(T, Decl(stringLiteralTypeIsSubtypeOfString.ts, 80, 13)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 80, 16)) + +function f12(x: T); +>f12 : Symbol(f12, Decl(stringLiteralTypeIsSubtypeOfString.ts, 78, 24), Decl(stringLiteralTypeIsSubtypeOfString.ts, 80, 24), Decl(stringLiteralTypeIsSubtypeOfString.ts, 81, 22)) +>T : Symbol(T, Decl(stringLiteralTypeIsSubtypeOfString.ts, 81, 13)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 81, 16)) +>T : Symbol(T, Decl(stringLiteralTypeIsSubtypeOfString.ts, 81, 13)) + +function f12(x: any) { } +>f12 : Symbol(f12, Decl(stringLiteralTypeIsSubtypeOfString.ts, 78, 24), Decl(stringLiteralTypeIsSubtypeOfString.ts, 80, 24), Decl(stringLiteralTypeIsSubtypeOfString.ts, 81, 22)) +>T : Symbol(T, Decl(stringLiteralTypeIsSubtypeOfString.ts, 82, 13)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 82, 16)) + +function f13(x: 'a'); +>f13 : Symbol(f13, Decl(stringLiteralTypeIsSubtypeOfString.ts, 82, 27), Decl(stringLiteralTypeIsSubtypeOfString.ts, 84, 39), Decl(stringLiteralTypeIsSubtypeOfString.ts, 85, 37)) +>T : Symbol(T, Decl(stringLiteralTypeIsSubtypeOfString.ts, 84, 13)) +>String : Symbol(String, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 84, 31)) + +function f13(x: T); +>f13 : Symbol(f13, Decl(stringLiteralTypeIsSubtypeOfString.ts, 82, 27), Decl(stringLiteralTypeIsSubtypeOfString.ts, 84, 39), Decl(stringLiteralTypeIsSubtypeOfString.ts, 85, 37)) +>T : Symbol(T, Decl(stringLiteralTypeIsSubtypeOfString.ts, 85, 13)) +>String : Symbol(String, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 85, 31)) +>T : Symbol(T, Decl(stringLiteralTypeIsSubtypeOfString.ts, 85, 13)) + +function f13(x: any) { } +>f13 : Symbol(f13, Decl(stringLiteralTypeIsSubtypeOfString.ts, 82, 27), Decl(stringLiteralTypeIsSubtypeOfString.ts, 84, 39), Decl(stringLiteralTypeIsSubtypeOfString.ts, 85, 37)) +>T : Symbol(T, Decl(stringLiteralTypeIsSubtypeOfString.ts, 86, 13)) +>String : Symbol(String, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 86, 31)) + +enum E { A } +>E : Symbol(E, Decl(stringLiteralTypeIsSubtypeOfString.ts, 86, 42)) +>A : Symbol(E.A, Decl(stringLiteralTypeIsSubtypeOfString.ts, 88, 8)) + +function f14(x: 'a'); +>f14 : Symbol(f14, Decl(stringLiteralTypeIsSubtypeOfString.ts, 88, 12), Decl(stringLiteralTypeIsSubtypeOfString.ts, 89, 21), Decl(stringLiteralTypeIsSubtypeOfString.ts, 90, 19)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 89, 13)) + +function f14(x: E); +>f14 : Symbol(f14, Decl(stringLiteralTypeIsSubtypeOfString.ts, 88, 12), Decl(stringLiteralTypeIsSubtypeOfString.ts, 89, 21), Decl(stringLiteralTypeIsSubtypeOfString.ts, 90, 19)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 90, 13)) +>E : Symbol(E, Decl(stringLiteralTypeIsSubtypeOfString.ts, 86, 42)) + +function f14(x: any) { } +>f14 : Symbol(f14, Decl(stringLiteralTypeIsSubtypeOfString.ts, 88, 12), Decl(stringLiteralTypeIsSubtypeOfString.ts, 89, 21), Decl(stringLiteralTypeIsSubtypeOfString.ts, 90, 19)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 91, 13)) + +function f15(x: 'a'); +>f15 : Symbol(f15, Decl(stringLiteralTypeIsSubtypeOfString.ts, 91, 24), Decl(stringLiteralTypeIsSubtypeOfString.ts, 93, 37), Decl(stringLiteralTypeIsSubtypeOfString.ts, 94, 35)) +>T : Symbol(T, Decl(stringLiteralTypeIsSubtypeOfString.ts, 93, 13)) +>U : Symbol(U, Decl(stringLiteralTypeIsSubtypeOfString.ts, 93, 15)) +>T : Symbol(T, Decl(stringLiteralTypeIsSubtypeOfString.ts, 93, 13)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 93, 29)) + +function f15(x: U); +>f15 : Symbol(f15, Decl(stringLiteralTypeIsSubtypeOfString.ts, 91, 24), Decl(stringLiteralTypeIsSubtypeOfString.ts, 93, 37), Decl(stringLiteralTypeIsSubtypeOfString.ts, 94, 35)) +>T : Symbol(T, Decl(stringLiteralTypeIsSubtypeOfString.ts, 94, 13)) +>U : Symbol(U, Decl(stringLiteralTypeIsSubtypeOfString.ts, 94, 15)) +>T : Symbol(T, Decl(stringLiteralTypeIsSubtypeOfString.ts, 94, 13)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 94, 29)) +>U : Symbol(U, Decl(stringLiteralTypeIsSubtypeOfString.ts, 94, 15)) + +function f15(x: any) { } +>f15 : Symbol(f15, Decl(stringLiteralTypeIsSubtypeOfString.ts, 91, 24), Decl(stringLiteralTypeIsSubtypeOfString.ts, 93, 37), Decl(stringLiteralTypeIsSubtypeOfString.ts, 94, 35)) +>T : Symbol(T, Decl(stringLiteralTypeIsSubtypeOfString.ts, 95, 13)) +>U : Symbol(U, Decl(stringLiteralTypeIsSubtypeOfString.ts, 95, 15)) +>T : Symbol(T, Decl(stringLiteralTypeIsSubtypeOfString.ts, 95, 13)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 95, 29)) + +function f16(x: 'a'); +>f16 : Symbol(f16, Decl(stringLiteralTypeIsSubtypeOfString.ts, 95, 40), Decl(stringLiteralTypeIsSubtypeOfString.ts, 97, 52), Decl(stringLiteralTypeIsSubtypeOfString.ts, 98, 50)) +>T : Symbol(T, Decl(stringLiteralTypeIsSubtypeOfString.ts, 97, 13)) +>String : Symbol(String, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>U : Symbol(U, Decl(stringLiteralTypeIsSubtypeOfString.ts, 97, 30)) +>T : Symbol(T, Decl(stringLiteralTypeIsSubtypeOfString.ts, 97, 13)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 97, 44)) + +function f16(x: U); +>f16 : Symbol(f16, Decl(stringLiteralTypeIsSubtypeOfString.ts, 95, 40), Decl(stringLiteralTypeIsSubtypeOfString.ts, 97, 52), Decl(stringLiteralTypeIsSubtypeOfString.ts, 98, 50)) +>T : Symbol(T, Decl(stringLiteralTypeIsSubtypeOfString.ts, 98, 13)) +>String : Symbol(String, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>U : Symbol(U, Decl(stringLiteralTypeIsSubtypeOfString.ts, 98, 30)) +>T : Symbol(T, Decl(stringLiteralTypeIsSubtypeOfString.ts, 98, 13)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 98, 44)) +>U : Symbol(U, Decl(stringLiteralTypeIsSubtypeOfString.ts, 98, 30)) + +function f16(x: any) { } +>f16 : Symbol(f16, Decl(stringLiteralTypeIsSubtypeOfString.ts, 95, 40), Decl(stringLiteralTypeIsSubtypeOfString.ts, 97, 52), Decl(stringLiteralTypeIsSubtypeOfString.ts, 98, 50)) +>T : Symbol(T, Decl(stringLiteralTypeIsSubtypeOfString.ts, 99, 13)) +>String : Symbol(String, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>U : Symbol(U, Decl(stringLiteralTypeIsSubtypeOfString.ts, 99, 30)) +>T : Symbol(T, Decl(stringLiteralTypeIsSubtypeOfString.ts, 99, 13)) +>x : Symbol(x, Decl(stringLiteralTypeIsSubtypeOfString.ts, 99, 44)) + diff --git a/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.types b/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.types new file mode 100644 index 0000000000000..e518547617350 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypeIsSubtypeOfString.types @@ -0,0 +1,363 @@ +=== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts === +// string literal types are subtypes of string, any + +// ok +function f1(x: 'a'); +>f1 : { (x: "a"): any; (x: string): any; } +>x : "a" + +function f1(x: string); +>f1 : { (x: "a"): any; (x: string): any; } +>x : string + +function f1(x: string) { } +>f1 : { (x: "a"): any; (x: string): any; } +>x : string + +// ok +function f2(x: 'a'); +>f2 : { (x: "a"): any; (x: any): any; } +>x : "a" + +function f2(x: any); +>f2 : { (x: "a"): any; (x: any): any; } +>x : any + +function f2(x: any) { } +>f2 : { (x: "a"): any; (x: any): any; } +>x : any + +// errors +function f3(x: 'a'); +>f3 : { (x: "a"): any; (x: Object): any; } +>x : "a" + +function f3(x: Object); +>f3 : { (x: "a"): any; (x: Object): any; } +>x : Object +>Object : Object + +function f3(x: any) { } +>f3 : { (x: "a"): any; (x: Object): any; } +>x : any + +function f4(x: 'a'); +>f4 : { (x: "a"): any; (x: {}): any; } +>x : "a" + +function f4(x: {}); +>f4 : { (x: "a"): any; (x: {}): any; } +>x : {} + +function f4(x: any) { } +>f4 : { (x: "a"): any; (x: {}): any; } +>x : any + +function f5(x: 'a'); +>f5 : { (x: "a"): any; (x: number): any; } +>x : "a" + +function f5(x: number); +>f5 : { (x: "a"): any; (x: number): any; } +>x : number + +function f5(x: any) { } +>f5 : { (x: "a"): any; (x: number): any; } +>x : any + +function f6(x: 'a'); +>f6 : { (x: "a"): any; (x: boolean): any; } +>x : "a" + +function f6(x: boolean); +>f6 : { (x: "a"): any; (x: boolean): any; } +>x : boolean + +function f6(x: any) { } +>f6 : { (x: "a"): any; (x: boolean): any; } +>x : any + +function f7(x: 'a'); +>f7 : { (x: "a"): any; (x: Date): any; } +>x : "a" + +function f7(x: Date); +>f7 : { (x: "a"): any; (x: Date): any; } +>x : Date +>Date : Date + +function f7(x: any) { } +>f7 : { (x: "a"): any; (x: Date): any; } +>x : any + +function f8(x: 'a'); +>f8 : { (x: "a"): any; (x: RegExp): any; } +>x : "a" + +function f8(x: RegExp); +>f8 : { (x: "a"): any; (x: RegExp): any; } +>x : RegExp +>RegExp : RegExp + +function f8(x: any) { } +>f8 : { (x: "a"): any; (x: RegExp): any; } +>x : any + +function f9(x: 'a'); +>f9 : { (x: "a"): any; (x: () => {}): any; } +>x : "a" + +function f9(x: () => {}); +>f9 : { (x: "a"): any; (x: () => {}): any; } +>x : () => {} + +function f9(x: any) { } +>f9 : { (x: "a"): any; (x: () => {}): any; } +>x : any + +class C implements String { +>C : C +>String : String + + toString(): string { return null; } +>toString : () => string +>null : null + + charAt(pos: number): string { return null; } +>charAt : (pos: number) => string +>pos : number +>null : null + + charCodeAt(index: number): number { return null; } +>charCodeAt : (index: number) => number +>index : number +>null : null + + concat(...strings: string[]): string { return null; } +>concat : (...strings: string[]) => string +>strings : string[] +>null : null + + indexOf(searchString: string, position?: number): number { return null; } +>indexOf : (searchString: string, position?: number) => number +>searchString : string +>position : number +>null : null + + lastIndexOf(searchString: string, position?: number): number { return null; } +>lastIndexOf : (searchString: string, position?: number) => number +>searchString : string +>position : number +>null : null + + localeCompare(that: string): number { return null; } +>localeCompare : (that: string) => number +>that : string +>null : null + + match(regexp: any): string[] { return null; } +>match : (regexp: any) => string[] +>regexp : any +>null : null + + replace(searchValue: any, replaceValue: any): string { return null; } +>replace : (searchValue: any, replaceValue: any) => string +>searchValue : any +>replaceValue : any +>null : null + + search(regexp: any): number { return null; } +>search : (regexp: any) => number +>regexp : any +>null : null + + slice(start?: number, end?: number): string { return null; } +>slice : (start?: number, end?: number) => string +>start : number +>end : number +>null : null + + split(separator: any, limit?: number): string[] { return null; } +>split : (separator: any, limit?: number) => string[] +>separator : any +>limit : number +>null : null + + substring(start: number, end?: number): string { return null; } +>substring : (start: number, end?: number) => string +>start : number +>end : number +>null : null + + toLowerCase(): string { return null; } +>toLowerCase : () => string +>null : null + + toLocaleLowerCase(): string { return null; } +>toLocaleLowerCase : () => string +>null : null + + toUpperCase(): string { return null; } +>toUpperCase : () => string +>null : null + + toLocaleUpperCase(): string { return null; } +>toLocaleUpperCase : () => string +>null : null + + trim(): string { return null; } +>trim : () => string +>null : null + + length: number; +>length : number + + substr(from: number, length?: number): string { return null; } +>substr : (from: number, length?: number) => string +>from : number +>length : number +>null : null + + valueOf(): string { return null; } +>valueOf : () => string +>null : null + + [index: number]: string; +>index : number +} + +// BUG 831846 +function f10(x: 'a'); +>f10 : { (x: "a"): any; (x: C): any; } +>x : "a" + +function f10(x: C); +>f10 : { (x: "a"): any; (x: C): any; } +>x : C +>C : C + +function f10(x: any) { } +>f10 : { (x: "a"): any; (x: C): any; } +>x : any + +interface I extends String { +>I : I +>String : String + + foo: string; +>foo : string +} + +// BUG 831846 +function f11(x: 'a'); +>f11 : { (x: "a"): any; (x: I): any; } +>x : "a" + +function f11(x: I); +>f11 : { (x: "a"): any; (x: I): any; } +>x : I +>I : I + +function f11(x: any) { } +>f11 : { (x: "a"): any; (x: I): any; } +>x : any + +function f12(x: 'a'); +>f12 : { (x: "a"): any; (x: T): any; } +>T : T +>x : "a" + +function f12(x: T); +>f12 : { (x: "a"): any; (x: T): any; } +>T : T +>x : T +>T : T + +function f12(x: any) { } +>f12 : { (x: "a"): any; (x: T): any; } +>T : T +>x : any + +function f13(x: 'a'); +>f13 : { (x: "a"): any; (x: T): any; } +>T : T +>String : String +>x : "a" + +function f13(x: T); +>f13 : { (x: "a"): any; (x: T): any; } +>T : T +>String : String +>x : T +>T : T + +function f13(x: any) { } +>f13 : { (x: "a"): any; (x: T): any; } +>T : T +>String : String +>x : any + +enum E { A } +>E : E +>A : E + +function f14(x: 'a'); +>f14 : { (x: "a"): any; (x: E): any; } +>x : "a" + +function f14(x: E); +>f14 : { (x: "a"): any; (x: E): any; } +>x : E +>E : E + +function f14(x: any) { } +>f14 : { (x: "a"): any; (x: E): any; } +>x : any + +function f15(x: 'a'); +>f15 : { (x: "a"): any; (x: U): any; } +>T : T +>U : U +>T : T +>x : "a" + +function f15(x: U); +>f15 : { (x: "a"): any; (x: U): any; } +>T : T +>U : U +>T : T +>x : U +>U : U + +function f15(x: any) { } +>f15 : { (x: "a"): any; (x: U): any; } +>T : T +>U : U +>T : T +>x : any + +function f16(x: 'a'); +>f16 : { (x: "a"): any; (x: U): any; } +>T : T +>String : String +>U : U +>T : T +>x : "a" + +function f16(x: U); +>f16 : { (x: "a"): any; (x: U): any; } +>T : T +>String : String +>U : U +>T : T +>x : U +>U : U + +function f16(x: any) { } +>f16 : { (x: "a"): any; (x: U): any; } +>T : T +>String : String +>U : U +>T : T +>x : any + diff --git a/tests/baselines/reference/stringLiteralTypesAsTags02.errors.txt b/tests/baselines/reference/stringLiteralTypesAsTags02.errors.txt deleted file mode 100644 index 077113632d043..0000000000000 --- a/tests/baselines/reference/stringLiteralTypesAsTags02.errors.txt +++ /dev/null @@ -1,50 +0,0 @@ -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/stringLiteralTypesAsTags02.ts (2 errors) ==== - - 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; - ~~~~~~~ -!!! 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 = { - 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/baselines/reference/stringLiteralTypesAsTags02.symbols b/tests/baselines/reference/stringLiteralTypesAsTags02.symbols new file mode 100644 index 0000000000000..61d5023099372 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesAsTags02.symbols @@ -0,0 +1,106 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags02.ts === + +type Kind = "A" | "B" +>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags02.ts, 0, 0)) + +interface Entity { +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags02.ts, 1, 21)) + + kind: Kind; +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags02.ts, 3, 18)) +>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags02.ts, 0, 0)) +} + +interface A extends Entity { +>A : Symbol(A, Decl(stringLiteralTypesAsTags02.ts, 5, 1)) +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags02.ts, 1, 21)) + + kind: "A"; +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags02.ts, 7, 28)) + + a: number; +>a : Symbol(a, Decl(stringLiteralTypesAsTags02.ts, 8, 14)) +} + +interface B extends Entity { +>B : Symbol(B, Decl(stringLiteralTypesAsTags02.ts, 10, 1)) +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags02.ts, 1, 21)) + + kind: "B"; +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags02.ts, 12, 28)) + + b: string; +>b : Symbol(b, Decl(stringLiteralTypesAsTags02.ts, 13, 14)) +} + +function hasKind(entity: Entity, kind: "A"): entity is A; +>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags02.ts, 15, 1), Decl(stringLiteralTypesAsTags02.ts, 17, 57), Decl(stringLiteralTypesAsTags02.ts, 18, 57)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags02.ts, 17, 17)) +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags02.ts, 1, 21)) +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags02.ts, 17, 32)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags02.ts, 17, 17)) +>A : Symbol(A, Decl(stringLiteralTypesAsTags02.ts, 5, 1)) + +function hasKind(entity: Entity, kind: "B"): entity is B; +>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags02.ts, 15, 1), Decl(stringLiteralTypesAsTags02.ts, 17, 57), Decl(stringLiteralTypesAsTags02.ts, 18, 57)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags02.ts, 18, 17)) +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags02.ts, 1, 21)) +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags02.ts, 18, 32)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags02.ts, 18, 17)) +>B : Symbol(B, Decl(stringLiteralTypesAsTags02.ts, 10, 1)) + +function hasKind(entity: Entity, kind: Kind): entity is (A | B) { +>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags02.ts, 15, 1), Decl(stringLiteralTypesAsTags02.ts, 17, 57), Decl(stringLiteralTypesAsTags02.ts, 18, 57)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags02.ts, 19, 17)) +>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags02.ts, 1, 21)) +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags02.ts, 19, 32)) +>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags02.ts, 0, 0)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags02.ts, 19, 17)) +>A : Symbol(A, Decl(stringLiteralTypesAsTags02.ts, 5, 1)) +>B : Symbol(B, Decl(stringLiteralTypesAsTags02.ts, 10, 1)) + + return entity.kind === kind; +>entity.kind : Symbol(Entity.kind, Decl(stringLiteralTypesAsTags02.ts, 3, 18)) +>entity : Symbol(entity, Decl(stringLiteralTypesAsTags02.ts, 19, 17)) +>kind : Symbol(Entity.kind, Decl(stringLiteralTypesAsTags02.ts, 3, 18)) +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags02.ts, 19, 32)) +} + +let x: A = { +>x : Symbol(x, Decl(stringLiteralTypesAsTags02.ts, 23, 3)) +>A : Symbol(A, Decl(stringLiteralTypesAsTags02.ts, 5, 1)) + + kind: "A", +>kind : Symbol(kind, Decl(stringLiteralTypesAsTags02.ts, 23, 12)) + + a: 100, +>a : Symbol(a, Decl(stringLiteralTypesAsTags02.ts, 24, 14)) +} + +if (hasKind(x, "A")) { +>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags02.ts, 15, 1), Decl(stringLiteralTypesAsTags02.ts, 17, 57), Decl(stringLiteralTypesAsTags02.ts, 18, 57)) +>x : Symbol(x, Decl(stringLiteralTypesAsTags02.ts, 23, 3)) + + let a = x; +>a : Symbol(a, Decl(stringLiteralTypesAsTags02.ts, 29, 7)) +>x : Symbol(x, Decl(stringLiteralTypesAsTags02.ts, 23, 3)) +} +else { + let b = x; +>b : Symbol(b, Decl(stringLiteralTypesAsTags02.ts, 32, 7)) +>x : Symbol(x, Decl(stringLiteralTypesAsTags02.ts, 23, 3)) +} + +if (!hasKind(x, "B")) { +>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags02.ts, 15, 1), Decl(stringLiteralTypesAsTags02.ts, 17, 57), Decl(stringLiteralTypesAsTags02.ts, 18, 57)) +>x : Symbol(x, Decl(stringLiteralTypesAsTags02.ts, 23, 3)) + + let c = x; +>c : Symbol(c, Decl(stringLiteralTypesAsTags02.ts, 36, 7)) +>x : Symbol(x, Decl(stringLiteralTypesAsTags02.ts, 23, 3)) +} +else { + let d = x; +>d : Symbol(d, Decl(stringLiteralTypesAsTags02.ts, 39, 7)) +>x : Symbol(x, Decl(stringLiteralTypesAsTags02.ts, 23, 3)) +} diff --git a/tests/baselines/reference/stringLiteralTypesAsTags02.types b/tests/baselines/reference/stringLiteralTypesAsTags02.types new file mode 100644 index 0000000000000..0b8ea0faf674e --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesAsTags02.types @@ -0,0 +1,115 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags02.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 +>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 +>Entity : Entity +>kind : "B" +>entity : any +>B : B + +function hasKind(entity: Entity, kind: Kind): entity is (A | B) { +>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 +>A : A +>B : 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; } +>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/stringLiteralTypesAsTypeParameterConstraint01.js b/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint01.js index 558f6bdf4c2fd..4f49d326ec04f 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint01.js +++ b/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint01.js @@ -43,26 +43,3 @@ declare let g: (x: "foo") => "foo"; declare let gResult: "foo"; declare let h: (x: "foo" | "bar") => "foo" | "bar"; declare let hResult: "foo" | "bar"; - - -//// [DtsFileErrors] - - -tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTypeParameterConstraint01.d.ts(3,16): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTypeParameterConstraint01.d.ts(5,16): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - - -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTypeParameterConstraint01.d.ts (2 errors) ==== - declare function foo(f: (x: T) => T): (x: T) => T; - declare function bar(f: (x: T) => T): (x: T) => T; - declare let f: (x: "foo") => "foo"; - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - declare let fResult: "foo"; - declare let g: (x: "foo") => "foo"; - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - declare let gResult: "foo"; - declare let h: (x: "foo" | "bar") => "foo" | "bar"; - declare let hResult: "foo" | "bar"; - \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralTypesInImplementationSignatures.errors.txt b/tests/baselines/reference/stringLiteralTypesInImplementationSignatures.errors.txt deleted file mode 100644 index 2bff320197a2e..0000000000000 --- a/tests/baselines/reference/stringLiteralTypesInImplementationSignatures.errors.txt +++ /dev/null @@ -1,62 +0,0 @@ -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures.ts(3,10): error TS2381: A signature with an implementation cannot use a string literal type. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures.ts(4,18): error TS2381: A signature with an implementation cannot use a string literal type. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures.ts(5,10): error TS2381: A signature with an implementation cannot use a string literal type. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures.ts(8,5): error TS2381: A signature with an implementation cannot use a string literal type. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures.ts(12,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures.ts(13,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures.ts(17,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures.ts(18,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures.ts(22,5): error TS2381: A signature with an implementation cannot use a string literal type. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures.ts(23,17): error TS2381: A signature with an implementation cannot use a string literal type. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures.ts(24,8): error TS2381: A signature with an implementation cannot use a string literal type. - - -==== tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures.ts (11 errors) ==== - // String literal types are only valid in overload signatures - - function foo(x: 'hi') { } - ~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. - var f = function foo(x: 'hi') { } - ~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. - var f2 = (x: 'hi', y: 'hi') => { } - ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. - - class C { - foo(x: 'hi') { } - ~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. - } - - interface I { - (x: 'hi'); - ~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - foo(x: 'hi', y: 'hi'); - ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - } - - var a: { - (x: 'hi'); - ~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - foo(x: 'hi'); - ~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - } - - var b = { - foo(x: 'hi') { }, - ~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. - a: function foo(x: 'hi', y: 'hi') { }, - ~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. - b: (x: 'hi') => { } - ~~~~~~~~~~~~~~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. - } - \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralTypesInImplementationSignatures.symbols b/tests/baselines/reference/stringLiteralTypesInImplementationSignatures.symbols new file mode 100644 index 0000000000000..6f764b5c27140 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesInImplementationSignatures.symbols @@ -0,0 +1,66 @@ +=== tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures.ts === +// String literal types are only valid in overload signatures + +function foo(x: 'hi') { } +>foo : Symbol(foo, Decl(stringLiteralTypesInImplementationSignatures.ts, 0, 0)) +>x : Symbol(x, Decl(stringLiteralTypesInImplementationSignatures.ts, 2, 13)) + +var f = function foo(x: 'hi') { } +>f : Symbol(f, Decl(stringLiteralTypesInImplementationSignatures.ts, 3, 3)) +>foo : Symbol(foo, Decl(stringLiteralTypesInImplementationSignatures.ts, 3, 7)) +>x : Symbol(x, Decl(stringLiteralTypesInImplementationSignatures.ts, 3, 21)) + +var f2 = (x: 'hi', y: 'hi') => { } +>f2 : Symbol(f2, Decl(stringLiteralTypesInImplementationSignatures.ts, 4, 3)) +>x : Symbol(x, Decl(stringLiteralTypesInImplementationSignatures.ts, 4, 10)) +>y : Symbol(y, Decl(stringLiteralTypesInImplementationSignatures.ts, 4, 18)) + +class C { +>C : Symbol(C, Decl(stringLiteralTypesInImplementationSignatures.ts, 4, 34)) + + foo(x: 'hi') { } +>foo : Symbol(foo, Decl(stringLiteralTypesInImplementationSignatures.ts, 6, 9)) +>x : Symbol(x, Decl(stringLiteralTypesInImplementationSignatures.ts, 7, 8)) +} + +interface I { +>I : Symbol(I, Decl(stringLiteralTypesInImplementationSignatures.ts, 8, 1)) + + (x: 'hi'); +>x : Symbol(x, Decl(stringLiteralTypesInImplementationSignatures.ts, 11, 5)) + + foo(x: 'hi', y: 'hi'); +>foo : Symbol(foo, Decl(stringLiteralTypesInImplementationSignatures.ts, 11, 14)) +>x : Symbol(x, Decl(stringLiteralTypesInImplementationSignatures.ts, 12, 8)) +>y : Symbol(y, Decl(stringLiteralTypesInImplementationSignatures.ts, 12, 16)) +} + +var a: { +>a : Symbol(a, Decl(stringLiteralTypesInImplementationSignatures.ts, 15, 3)) + + (x: 'hi'); +>x : Symbol(x, Decl(stringLiteralTypesInImplementationSignatures.ts, 16, 5)) + + foo(x: 'hi'); +>foo : Symbol(foo, Decl(stringLiteralTypesInImplementationSignatures.ts, 16, 14)) +>x : Symbol(x, Decl(stringLiteralTypesInImplementationSignatures.ts, 17, 8)) +} + +var b = { +>b : Symbol(b, Decl(stringLiteralTypesInImplementationSignatures.ts, 20, 3)) + + foo(x: 'hi') { }, +>foo : Symbol(foo, Decl(stringLiteralTypesInImplementationSignatures.ts, 20, 9)) +>x : Symbol(x, Decl(stringLiteralTypesInImplementationSignatures.ts, 21, 8)) + + a: function foo(x: 'hi', y: 'hi') { }, +>a : Symbol(a, Decl(stringLiteralTypesInImplementationSignatures.ts, 21, 21)) +>foo : Symbol(foo, Decl(stringLiteralTypesInImplementationSignatures.ts, 22, 6)) +>x : Symbol(x, Decl(stringLiteralTypesInImplementationSignatures.ts, 22, 20)) +>y : Symbol(y, Decl(stringLiteralTypesInImplementationSignatures.ts, 22, 28)) + + b: (x: 'hi') => { } +>b : Symbol(b, Decl(stringLiteralTypesInImplementationSignatures.ts, 22, 42)) +>x : Symbol(x, Decl(stringLiteralTypesInImplementationSignatures.ts, 23, 8)) +} + diff --git a/tests/baselines/reference/stringLiteralTypesInImplementationSignatures.types b/tests/baselines/reference/stringLiteralTypesInImplementationSignatures.types new file mode 100644 index 0000000000000..356d19fce3a56 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesInImplementationSignatures.types @@ -0,0 +1,71 @@ +=== tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures.ts === +// String literal types are only valid in overload signatures + +function foo(x: 'hi') { } +>foo : (x: "hi") => void +>x : "hi" + +var f = function foo(x: 'hi') { } +>f : (x: "hi") => void +>function foo(x: 'hi') { } : (x: "hi") => void +>foo : (x: "hi") => void +>x : "hi" + +var f2 = (x: 'hi', y: 'hi') => { } +>f2 : (x: "hi", y: "hi") => void +>(x: 'hi', y: 'hi') => { } : (x: "hi", y: "hi") => void +>x : "hi" +>y : "hi" + +class C { +>C : C + + foo(x: 'hi') { } +>foo : (x: "hi") => void +>x : "hi" +} + +interface I { +>I : I + + (x: 'hi'); +>x : "hi" + + foo(x: 'hi', y: 'hi'); +>foo : (x: "hi", y: "hi") => any +>x : "hi" +>y : "hi" +} + +var a: { +>a : { (x: "hi"): any; foo(x: "hi"): any; } + + (x: 'hi'); +>x : "hi" + + foo(x: 'hi'); +>foo : (x: "hi") => any +>x : "hi" +} + +var b = { +>b : { foo(x: "hi"): void; a: (x: "hi", y: "hi") => void; b: (x: "hi") => void; } +>{ foo(x: 'hi') { }, a: function foo(x: 'hi', y: 'hi') { }, b: (x: 'hi') => { }} : { foo(x: "hi"): void; a: (x: "hi", y: "hi") => void; b: (x: "hi") => void; } + + foo(x: 'hi') { }, +>foo : (x: "hi") => void +>x : "hi" + + a: function foo(x: 'hi', y: 'hi') { }, +>a : (x: "hi", y: "hi") => void +>function foo(x: 'hi', y: 'hi') { } : (x: "hi", y: "hi") => void +>foo : (x: "hi", y: "hi") => void +>x : "hi" +>y : "hi" + + b: (x: 'hi') => { } +>b : (x: "hi") => void +>(x: 'hi') => { } : (x: "hi") => void +>x : "hi" +} + diff --git a/tests/baselines/reference/stringLiteralTypesInImplementationSignatures2.errors.txt b/tests/baselines/reference/stringLiteralTypesInImplementationSignatures2.errors.txt index 4f94bad74418f..b0ab5010ea5e8 100644 --- a/tests/baselines/reference/stringLiteralTypesInImplementationSignatures2.errors.txt +++ b/tests/baselines/reference/stringLiteralTypesInImplementationSignatures2.errors.txt @@ -1,74 +1,38 @@ -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(4,10): error TS2381: A signature with an implementation cannot use a string literal type. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(8,5): error TS2381: A signature with an implementation cannot use a string literal type. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(12,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(13,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(14,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(15,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(19,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(20,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(21,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(22,5): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(26,5): error TS2300: Duplicate identifier 'foo'. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(26,5): error TS2381: A signature with an implementation cannot use a string literal type. tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(27,5): error TS2300: Duplicate identifier 'foo'. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(27,5): error TS2381: A signature with an implementation cannot use a string literal type. -==== tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts (14 errors) ==== +==== tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts (2 errors) ==== // String literal types are only valid in overload signatures function foo(x: any); function foo(x: 'hi') { } - ~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. class C { foo(x: string); foo(x: 'hi') { } - ~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. } interface I { (x: 'a'); - ~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. (x: 'hi'); - ~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. foo(x: 'a', y: 'a'); - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. foo(x: 'hi', y: 'hi'); - ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. } var a: { (x: 'hi'); - ~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. (x: 'a'); - ~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. foo(x: 'hi'); - ~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. foo(x: 'a'); - ~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. } var b = { foo(x: 'hi') { }, ~~~ !!! error TS2300: Duplicate identifier 'foo'. - ~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. foo(x: 'a') { }, ~~~ !!! error TS2300: Duplicate identifier 'foo'. - ~~~ -!!! error TS2381: A signature with an implementation cannot use a string literal type. } \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralTypesOverloadAssignability01.errors.txt b/tests/baselines/reference/stringLiteralTypesOverloadAssignability01.errors.txt new file mode 100644 index 0000000000000..4c66c2000f971 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesOverloadAssignability01.errors.txt @@ -0,0 +1,33 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability01.ts(15,1): error TS2322: Type '(x: "bar") => number' is not assignable to type '(x: "foo") => number'. + Types of parameters 'x' and 'x' are incompatible. + Type '"bar"' is not assignable to type '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability01.ts(16,1): error TS2322: Type '(x: "foo") => number' is not assignable to type '(x: "bar") => number'. + Types of parameters 'x' and 'x' are incompatible. + Type '"foo"' is not assignable to type '"bar"'. + + +==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability01.ts (2 errors) ==== + + function f(x: "foo"): number; + function f(x: string): number { + return 0; + } + + function g(x: "bar"): number; + function g(x: string): number { + return 0; + } + + let a = f; + let b = g; + + a = b; + ~ +!!! error TS2322: Type '(x: "bar") => number' is not assignable to type '(x: "foo") => number'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type '"bar"' is not assignable to type '"foo"'. + b = a; + ~ +!!! error TS2322: Type '(x: "foo") => number' is not assignable to type '(x: "bar") => number'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type '"foo"' is not assignable to type '"bar"'. \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralTypesOverloadAssignability01.js b/tests/baselines/reference/stringLiteralTypesOverloadAssignability01.js new file mode 100644 index 0000000000000..7b7c84165f32c --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesOverloadAssignability01.js @@ -0,0 +1,36 @@ +//// [stringLiteralTypesOverloadAssignability01.ts] + +function f(x: "foo"): number; +function f(x: string): number { + return 0; +} + +function g(x: "bar"): number; +function g(x: string): number { + return 0; +} + +let a = f; +let b = g; + +a = b; +b = a; + +//// [stringLiteralTypesOverloadAssignability01.js] +function f(x) { + return 0; +} +function g(x) { + return 0; +} +var a = f; +var b = g; +a = b; +b = a; + + +//// [stringLiteralTypesOverloadAssignability01.d.ts] +declare function f(x: "foo"): number; +declare function g(x: "bar"): number; +declare let a: typeof f; +declare let b: typeof g; diff --git a/tests/baselines/reference/stringLiteralTypesOverloadAssignability02.errors.txt b/tests/baselines/reference/stringLiteralTypesOverloadAssignability02.errors.txt new file mode 100644 index 0000000000000..952fd7aae86e0 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesOverloadAssignability02.errors.txt @@ -0,0 +1,33 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability02.ts(15,1): error TS2322: Type '(x: "bar") => number' is not assignable to type '(x: "foo") => number'. + Types of parameters 'x' and 'x' are incompatible. + Type '"bar"' is not assignable to type '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability02.ts(16,1): error TS2322: Type '(x: "foo") => number' is not assignable to type '(x: "bar") => number'. + Types of parameters 'x' and 'x' are incompatible. + Type '"foo"' is not assignable to type '"bar"'. + + +==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability02.ts (2 errors) ==== + + function f(x: "foo"): number; + function f(x: "foo"): number { + return 0; + } + + function g(x: "bar"): number; + function g(x: "bar"): number { + return 0; + } + + let a = f; + let b = g; + + a = b; + ~ +!!! error TS2322: Type '(x: "bar") => number' is not assignable to type '(x: "foo") => number'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type '"bar"' is not assignable to type '"foo"'. + b = a; + ~ +!!! error TS2322: Type '(x: "foo") => number' is not assignable to type '(x: "bar") => number'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type '"foo"' is not assignable to type '"bar"'. \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralTypesOverloadAssignability02.js b/tests/baselines/reference/stringLiteralTypesOverloadAssignability02.js new file mode 100644 index 0000000000000..7a8db4722a61d --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesOverloadAssignability02.js @@ -0,0 +1,36 @@ +//// [stringLiteralTypesOverloadAssignability02.ts] + +function f(x: "foo"): number; +function f(x: "foo"): number { + return 0; +} + +function g(x: "bar"): number; +function g(x: "bar"): number { + return 0; +} + +let a = f; +let b = g; + +a = b; +b = a; + +//// [stringLiteralTypesOverloadAssignability02.js] +function f(x) { + return 0; +} +function g(x) { + return 0; +} +var a = f; +var b = g; +a = b; +b = a; + + +//// [stringLiteralTypesOverloadAssignability02.d.ts] +declare function f(x: "foo"): number; +declare function g(x: "bar"): number; +declare let a: typeof f; +declare let b: typeof g; diff --git a/tests/baselines/reference/stringLiteralTypesOverloadAssignability03.js b/tests/baselines/reference/stringLiteralTypesOverloadAssignability03.js new file mode 100644 index 0000000000000..1d9452a9c65c8 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesOverloadAssignability03.js @@ -0,0 +1,36 @@ +//// [stringLiteralTypesOverloadAssignability03.ts] + +function f(x: "foo"): number; +function f(x: string): number { + return 0; +} + +function g(x: "foo"): number; +function g(x: string): number { + return 0; +} + +let a = f; +let b = g; + +a = b; +b = a; + +//// [stringLiteralTypesOverloadAssignability03.js] +function f(x) { + return 0; +} +function g(x) { + return 0; +} +var a = f; +var b = g; +a = b; +b = a; + + +//// [stringLiteralTypesOverloadAssignability03.d.ts] +declare function f(x: "foo"): number; +declare function g(x: "foo"): number; +declare let a: typeof f; +declare let b: typeof g; diff --git a/tests/baselines/reference/stringLiteralTypesOverloadAssignability03.symbols b/tests/baselines/reference/stringLiteralTypesOverloadAssignability03.symbols new file mode 100644 index 0000000000000..361f9e9db4dc0 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesOverloadAssignability03.symbols @@ -0,0 +1,40 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability03.ts === + +function f(x: "foo"): number; +>f : Symbol(f, Decl(stringLiteralTypesOverloadAssignability03.ts, 0, 0), Decl(stringLiteralTypesOverloadAssignability03.ts, 1, 29)) +>x : Symbol(x, Decl(stringLiteralTypesOverloadAssignability03.ts, 1, 11)) + +function f(x: string): number { +>f : Symbol(f, Decl(stringLiteralTypesOverloadAssignability03.ts, 0, 0), Decl(stringLiteralTypesOverloadAssignability03.ts, 1, 29)) +>x : Symbol(x, Decl(stringLiteralTypesOverloadAssignability03.ts, 2, 11)) + + return 0; +} + +function g(x: "foo"): number; +>g : Symbol(g, Decl(stringLiteralTypesOverloadAssignability03.ts, 4, 1), Decl(stringLiteralTypesOverloadAssignability03.ts, 6, 29)) +>x : Symbol(x, Decl(stringLiteralTypesOverloadAssignability03.ts, 6, 11)) + +function g(x: string): number { +>g : Symbol(g, Decl(stringLiteralTypesOverloadAssignability03.ts, 4, 1), Decl(stringLiteralTypesOverloadAssignability03.ts, 6, 29)) +>x : Symbol(x, Decl(stringLiteralTypesOverloadAssignability03.ts, 7, 11)) + + return 0; +} + +let a = f; +>a : Symbol(a, Decl(stringLiteralTypesOverloadAssignability03.ts, 11, 3)) +>f : Symbol(f, Decl(stringLiteralTypesOverloadAssignability03.ts, 0, 0), Decl(stringLiteralTypesOverloadAssignability03.ts, 1, 29)) + +let b = g; +>b : Symbol(b, Decl(stringLiteralTypesOverloadAssignability03.ts, 12, 3)) +>g : Symbol(g, Decl(stringLiteralTypesOverloadAssignability03.ts, 4, 1), Decl(stringLiteralTypesOverloadAssignability03.ts, 6, 29)) + +a = b; +>a : Symbol(a, Decl(stringLiteralTypesOverloadAssignability03.ts, 11, 3)) +>b : Symbol(b, Decl(stringLiteralTypesOverloadAssignability03.ts, 12, 3)) + +b = a; +>b : Symbol(b, Decl(stringLiteralTypesOverloadAssignability03.ts, 12, 3)) +>a : Symbol(a, Decl(stringLiteralTypesOverloadAssignability03.ts, 11, 3)) + diff --git a/tests/baselines/reference/stringLiteralTypesOverloadAssignability03.types b/tests/baselines/reference/stringLiteralTypesOverloadAssignability03.types new file mode 100644 index 0000000000000..8150eedd7b81a --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesOverloadAssignability03.types @@ -0,0 +1,44 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability03.ts === + +function f(x: "foo"): number; +>f : (x: "foo") => number +>x : "foo" + +function f(x: string): number { +>f : (x: "foo") => number +>x : string + + return 0; +>0 : number +} + +function g(x: "foo"): number; +>g : (x: "foo") => number +>x : "foo" + +function g(x: string): number { +>g : (x: "foo") => number +>x : string + + return 0; +>0 : number +} + +let a = f; +>a : (x: "foo") => number +>f : (x: "foo") => number + +let b = g; +>b : (x: "foo") => number +>g : (x: "foo") => number + +a = b; +>a = b : (x: "foo") => number +>a : (x: "foo") => number +>b : (x: "foo") => number + +b = a; +>b = a : (x: "foo") => number +>b : (x: "foo") => number +>a : (x: "foo") => number + diff --git a/tests/baselines/reference/stringLiteralTypesOverloadAssignability04.js b/tests/baselines/reference/stringLiteralTypesOverloadAssignability04.js new file mode 100644 index 0000000000000..975c7d80cb5d1 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesOverloadAssignability04.js @@ -0,0 +1,36 @@ +//// [stringLiteralTypesOverloadAssignability04.ts] + +function f(x: "foo"): number; +function f(x: "foo"): number { + return 0; +} + +function g(x: "foo"): number; +function g(x: "foo"): number { + return 0; +} + +let a = f; +let b = g; + +a = b; +b = a; + +//// [stringLiteralTypesOverloadAssignability04.js] +function f(x) { + return 0; +} +function g(x) { + return 0; +} +var a = f; +var b = g; +a = b; +b = a; + + +//// [stringLiteralTypesOverloadAssignability04.d.ts] +declare function f(x: "foo"): number; +declare function g(x: "foo"): number; +declare let a: typeof f; +declare let b: typeof g; diff --git a/tests/baselines/reference/stringLiteralTypesOverloadAssignability04.symbols b/tests/baselines/reference/stringLiteralTypesOverloadAssignability04.symbols new file mode 100644 index 0000000000000..75f7d12c25f92 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesOverloadAssignability04.symbols @@ -0,0 +1,40 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability04.ts === + +function f(x: "foo"): number; +>f : Symbol(f, Decl(stringLiteralTypesOverloadAssignability04.ts, 0, 0), Decl(stringLiteralTypesOverloadAssignability04.ts, 1, 29)) +>x : Symbol(x, Decl(stringLiteralTypesOverloadAssignability04.ts, 1, 11)) + +function f(x: "foo"): number { +>f : Symbol(f, Decl(stringLiteralTypesOverloadAssignability04.ts, 0, 0), Decl(stringLiteralTypesOverloadAssignability04.ts, 1, 29)) +>x : Symbol(x, Decl(stringLiteralTypesOverloadAssignability04.ts, 2, 11)) + + return 0; +} + +function g(x: "foo"): number; +>g : Symbol(g, Decl(stringLiteralTypesOverloadAssignability04.ts, 4, 1), Decl(stringLiteralTypesOverloadAssignability04.ts, 6, 29)) +>x : Symbol(x, Decl(stringLiteralTypesOverloadAssignability04.ts, 6, 11)) + +function g(x: "foo"): number { +>g : Symbol(g, Decl(stringLiteralTypesOverloadAssignability04.ts, 4, 1), Decl(stringLiteralTypesOverloadAssignability04.ts, 6, 29)) +>x : Symbol(x, Decl(stringLiteralTypesOverloadAssignability04.ts, 7, 11)) + + return 0; +} + +let a = f; +>a : Symbol(a, Decl(stringLiteralTypesOverloadAssignability04.ts, 11, 3)) +>f : Symbol(f, Decl(stringLiteralTypesOverloadAssignability04.ts, 0, 0), Decl(stringLiteralTypesOverloadAssignability04.ts, 1, 29)) + +let b = g; +>b : Symbol(b, Decl(stringLiteralTypesOverloadAssignability04.ts, 12, 3)) +>g : Symbol(g, Decl(stringLiteralTypesOverloadAssignability04.ts, 4, 1), Decl(stringLiteralTypesOverloadAssignability04.ts, 6, 29)) + +a = b; +>a : Symbol(a, Decl(stringLiteralTypesOverloadAssignability04.ts, 11, 3)) +>b : Symbol(b, Decl(stringLiteralTypesOverloadAssignability04.ts, 12, 3)) + +b = a; +>b : Symbol(b, Decl(stringLiteralTypesOverloadAssignability04.ts, 12, 3)) +>a : Symbol(a, Decl(stringLiteralTypesOverloadAssignability04.ts, 11, 3)) + diff --git a/tests/baselines/reference/stringLiteralTypesOverloadAssignability04.types b/tests/baselines/reference/stringLiteralTypesOverloadAssignability04.types new file mode 100644 index 0000000000000..7187e276fe4b0 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesOverloadAssignability04.types @@ -0,0 +1,44 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability04.ts === + +function f(x: "foo"): number; +>f : (x: "foo") => number +>x : "foo" + +function f(x: "foo"): number { +>f : (x: "foo") => number +>x : "foo" + + return 0; +>0 : number +} + +function g(x: "foo"): number; +>g : (x: "foo") => number +>x : "foo" + +function g(x: "foo"): number { +>g : (x: "foo") => number +>x : "foo" + + return 0; +>0 : number +} + +let a = f; +>a : (x: "foo") => number +>f : (x: "foo") => number + +let b = g; +>b : (x: "foo") => number +>g : (x: "foo") => number + +a = b; +>a = b : (x: "foo") => number +>a : (x: "foo") => number +>b : (x: "foo") => number + +b = a; +>b = a : (x: "foo") => number +>b : (x: "foo") => number +>a : (x: "foo") => number + diff --git a/tests/baselines/reference/stringLiteralTypesOverloadAssignability05.js b/tests/baselines/reference/stringLiteralTypesOverloadAssignability05.js new file mode 100644 index 0000000000000..b08dbc040826b --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesOverloadAssignability05.js @@ -0,0 +1,38 @@ +//// [stringLiteralTypesOverloadAssignability05.ts] + +function f(x: "foo"): number; +function f(x: string): number; +function f(x: string): number { + return 0; +} + +function g(x: "foo"): number; +function g(x: string): number { + return 0; +} + +let a = f; +let b = g; + +a = b; +b = a; + +//// [stringLiteralTypesOverloadAssignability05.js] +function f(x) { + return 0; +} +function g(x) { + return 0; +} +var a = f; +var b = g; +a = b; +b = a; + + +//// [stringLiteralTypesOverloadAssignability05.d.ts] +declare function f(x: "foo"): number; +declare function f(x: string): number; +declare function g(x: "foo"): number; +declare let a: typeof f; +declare let b: typeof g; diff --git a/tests/baselines/reference/stringLiteralTypesOverloadAssignability05.symbols b/tests/baselines/reference/stringLiteralTypesOverloadAssignability05.symbols new file mode 100644 index 0000000000000..9a59a7c929a1c --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesOverloadAssignability05.symbols @@ -0,0 +1,44 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability05.ts === + +function f(x: "foo"): number; +>f : Symbol(f, Decl(stringLiteralTypesOverloadAssignability05.ts, 0, 0), Decl(stringLiteralTypesOverloadAssignability05.ts, 1, 29), Decl(stringLiteralTypesOverloadAssignability05.ts, 2, 30)) +>x : Symbol(x, Decl(stringLiteralTypesOverloadAssignability05.ts, 1, 11)) + +function f(x: string): number; +>f : Symbol(f, Decl(stringLiteralTypesOverloadAssignability05.ts, 0, 0), Decl(stringLiteralTypesOverloadAssignability05.ts, 1, 29), Decl(stringLiteralTypesOverloadAssignability05.ts, 2, 30)) +>x : Symbol(x, Decl(stringLiteralTypesOverloadAssignability05.ts, 2, 11)) + +function f(x: string): number { +>f : Symbol(f, Decl(stringLiteralTypesOverloadAssignability05.ts, 0, 0), Decl(stringLiteralTypesOverloadAssignability05.ts, 1, 29), Decl(stringLiteralTypesOverloadAssignability05.ts, 2, 30)) +>x : Symbol(x, Decl(stringLiteralTypesOverloadAssignability05.ts, 3, 11)) + + return 0; +} + +function g(x: "foo"): number; +>g : Symbol(g, Decl(stringLiteralTypesOverloadAssignability05.ts, 5, 1), Decl(stringLiteralTypesOverloadAssignability05.ts, 7, 29)) +>x : Symbol(x, Decl(stringLiteralTypesOverloadAssignability05.ts, 7, 11)) + +function g(x: string): number { +>g : Symbol(g, Decl(stringLiteralTypesOverloadAssignability05.ts, 5, 1), Decl(stringLiteralTypesOverloadAssignability05.ts, 7, 29)) +>x : Symbol(x, Decl(stringLiteralTypesOverloadAssignability05.ts, 8, 11)) + + return 0; +} + +let a = f; +>a : Symbol(a, Decl(stringLiteralTypesOverloadAssignability05.ts, 12, 3)) +>f : Symbol(f, Decl(stringLiteralTypesOverloadAssignability05.ts, 0, 0), Decl(stringLiteralTypesOverloadAssignability05.ts, 1, 29), Decl(stringLiteralTypesOverloadAssignability05.ts, 2, 30)) + +let b = g; +>b : Symbol(b, Decl(stringLiteralTypesOverloadAssignability05.ts, 13, 3)) +>g : Symbol(g, Decl(stringLiteralTypesOverloadAssignability05.ts, 5, 1), Decl(stringLiteralTypesOverloadAssignability05.ts, 7, 29)) + +a = b; +>a : Symbol(a, Decl(stringLiteralTypesOverloadAssignability05.ts, 12, 3)) +>b : Symbol(b, Decl(stringLiteralTypesOverloadAssignability05.ts, 13, 3)) + +b = a; +>b : Symbol(b, Decl(stringLiteralTypesOverloadAssignability05.ts, 13, 3)) +>a : Symbol(a, Decl(stringLiteralTypesOverloadAssignability05.ts, 12, 3)) + diff --git a/tests/baselines/reference/stringLiteralTypesOverloadAssignability05.types b/tests/baselines/reference/stringLiteralTypesOverloadAssignability05.types new file mode 100644 index 0000000000000..b7dd9262a67bc --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesOverloadAssignability05.types @@ -0,0 +1,48 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability05.ts === + +function f(x: "foo"): number; +>f : { (x: "foo"): number; (x: string): number; } +>x : "foo" + +function f(x: string): number; +>f : { (x: "foo"): number; (x: string): number; } +>x : string + +function f(x: string): number { +>f : { (x: "foo"): number; (x: string): number; } +>x : string + + return 0; +>0 : number +} + +function g(x: "foo"): number; +>g : (x: "foo") => number +>x : "foo" + +function g(x: string): number { +>g : (x: "foo") => number +>x : string + + return 0; +>0 : number +} + +let a = f; +>a : { (x: "foo"): number; (x: string): number; } +>f : { (x: "foo"): number; (x: string): number; } + +let b = g; +>b : (x: "foo") => number +>g : (x: "foo") => number + +a = b; +>a = b : (x: "foo") => number +>a : { (x: "foo"): number; (x: string): number; } +>b : (x: "foo") => number + +b = a; +>b = a : { (x: "foo"): number; (x: string): number; } +>b : (x: "foo") => number +>a : { (x: "foo"): number; (x: string): number; } + diff --git a/tests/baselines/reference/stringLiteralTypesOverloads05.errors.txt b/tests/baselines/reference/stringLiteralTypesOverloads05.errors.txt new file mode 100644 index 0000000000000..e57327ab0e01b --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesOverloads05.errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads05.ts(7,10): error TS2394: Overload signature is not compatible with function implementation. + + +==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads05.ts (1 errors) ==== + + interface Animal { animal: {} }; + interface Dog extends Animal { dog: {} } + interface Cat extends Animal { cat: {} } + interface Moose extends Animal { moose: {} } + + function doThing(x: "dog"): Dog; + ~~~~~~~ +!!! error TS2394: Overload signature is not compatible with function implementation. + function doThing(x: "cat"): Cat; + function doThing(x: string): Animal; + function doThing(x: string, y?: string): Moose { + return undefined; + } \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralTypesOverloads05.js b/tests/baselines/reference/stringLiteralTypesOverloads05.js new file mode 100644 index 0000000000000..23be3dac1e1b2 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesOverloads05.js @@ -0,0 +1,37 @@ +//// [stringLiteralTypesOverloads05.ts] + +interface Animal { animal: {} }; +interface Dog extends Animal { dog: {} } +interface Cat extends Animal { cat: {} } +interface Moose extends Animal { moose: {} } + +function doThing(x: "dog"): Dog; +function doThing(x: "cat"): Cat; +function doThing(x: string): Animal; +function doThing(x: string, y?: string): Moose { + return undefined; +} + +//// [stringLiteralTypesOverloads05.js] +; +function doThing(x, y) { + return undefined; +} + + +//// [stringLiteralTypesOverloads05.d.ts] +interface Animal { + animal: {}; +} +interface Dog extends Animal { + dog: {}; +} +interface Cat extends Animal { + cat: {}; +} +interface Moose extends Animal { + moose: {}; +} +declare function doThing(x: "dog"): Dog; +declare function doThing(x: "cat"): Cat; +declare function doThing(x: string): Animal; diff --git a/tests/baselines/reference/stringLiteralTypesTypePredicates01.errors.txt b/tests/baselines/reference/stringLiteralTypesTypePredicates01.errors.txt deleted file mode 100644 index b888c3ca77e40..0000000000000 --- a/tests/baselines/reference/stringLiteralTypesTypePredicates01.errors.txt +++ /dev/null @@ -1,33 +0,0 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypesTypePredicates01.ts(4,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesTypePredicates01.ts(5,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - - -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesTypePredicates01.ts (2 errors) ==== - - type Kind = "A" | "B" - - function kindIs(kind: Kind, is: "A"): kind is "A"; - ~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - function kindIs(kind: Kind, is: "B"): kind is "B"; - ~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. - function kindIs(kind: Kind, is: Kind): boolean { - return kind === is; - } - - var x: Kind = "A"; - - if (kindIs(x, "A")) { - let a = x; - } - else { - let b = x; - } - - if (!kindIs(x, "B")) { - let c = x; - } - else { - let d = x; - } \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralTypesTypePredicates01.symbols b/tests/baselines/reference/stringLiteralTypesTypePredicates01.symbols new file mode 100644 index 0000000000000..6b18cab743233 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesTypePredicates01.symbols @@ -0,0 +1,62 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesTypePredicates01.ts === + +type Kind = "A" | "B" +>Kind : Symbol(Kind, Decl(stringLiteralTypesTypePredicates01.ts, 0, 0)) + +function kindIs(kind: Kind, is: "A"): kind is "A"; +>kindIs : Symbol(kindIs, Decl(stringLiteralTypesTypePredicates01.ts, 1, 21), Decl(stringLiteralTypesTypePredicates01.ts, 3, 50), Decl(stringLiteralTypesTypePredicates01.ts, 4, 50)) +>kind : Symbol(kind, Decl(stringLiteralTypesTypePredicates01.ts, 3, 16)) +>Kind : Symbol(Kind, Decl(stringLiteralTypesTypePredicates01.ts, 0, 0)) +>is : Symbol(is, Decl(stringLiteralTypesTypePredicates01.ts, 3, 27)) +>kind : Symbol(kind, Decl(stringLiteralTypesTypePredicates01.ts, 3, 16)) + +function kindIs(kind: Kind, is: "B"): kind is "B"; +>kindIs : Symbol(kindIs, Decl(stringLiteralTypesTypePredicates01.ts, 1, 21), Decl(stringLiteralTypesTypePredicates01.ts, 3, 50), Decl(stringLiteralTypesTypePredicates01.ts, 4, 50)) +>kind : Symbol(kind, Decl(stringLiteralTypesTypePredicates01.ts, 4, 16)) +>Kind : Symbol(Kind, Decl(stringLiteralTypesTypePredicates01.ts, 0, 0)) +>is : Symbol(is, Decl(stringLiteralTypesTypePredicates01.ts, 4, 27)) +>kind : Symbol(kind, Decl(stringLiteralTypesTypePredicates01.ts, 4, 16)) + +function kindIs(kind: Kind, is: Kind): boolean { +>kindIs : Symbol(kindIs, Decl(stringLiteralTypesTypePredicates01.ts, 1, 21), Decl(stringLiteralTypesTypePredicates01.ts, 3, 50), Decl(stringLiteralTypesTypePredicates01.ts, 4, 50)) +>kind : Symbol(kind, Decl(stringLiteralTypesTypePredicates01.ts, 5, 16)) +>Kind : Symbol(Kind, Decl(stringLiteralTypesTypePredicates01.ts, 0, 0)) +>is : Symbol(is, Decl(stringLiteralTypesTypePredicates01.ts, 5, 27)) +>Kind : Symbol(Kind, Decl(stringLiteralTypesTypePredicates01.ts, 0, 0)) + + return kind === is; +>kind : Symbol(kind, Decl(stringLiteralTypesTypePredicates01.ts, 5, 16)) +>is : Symbol(is, Decl(stringLiteralTypesTypePredicates01.ts, 5, 27)) +} + +var x: Kind = "A"; +>x : Symbol(x, Decl(stringLiteralTypesTypePredicates01.ts, 9, 3)) +>Kind : Symbol(Kind, Decl(stringLiteralTypesTypePredicates01.ts, 0, 0)) + +if (kindIs(x, "A")) { +>kindIs : Symbol(kindIs, Decl(stringLiteralTypesTypePredicates01.ts, 1, 21), Decl(stringLiteralTypesTypePredicates01.ts, 3, 50), Decl(stringLiteralTypesTypePredicates01.ts, 4, 50)) +>x : Symbol(x, Decl(stringLiteralTypesTypePredicates01.ts, 9, 3)) + + let a = x; +>a : Symbol(a, Decl(stringLiteralTypesTypePredicates01.ts, 12, 7)) +>x : Symbol(x, Decl(stringLiteralTypesTypePredicates01.ts, 9, 3)) +} +else { + let b = x; +>b : Symbol(b, Decl(stringLiteralTypesTypePredicates01.ts, 15, 7)) +>x : Symbol(x, Decl(stringLiteralTypesTypePredicates01.ts, 9, 3)) +} + +if (!kindIs(x, "B")) { +>kindIs : Symbol(kindIs, Decl(stringLiteralTypesTypePredicates01.ts, 1, 21), Decl(stringLiteralTypesTypePredicates01.ts, 3, 50), Decl(stringLiteralTypesTypePredicates01.ts, 4, 50)) +>x : Symbol(x, Decl(stringLiteralTypesTypePredicates01.ts, 9, 3)) + + let c = x; +>c : Symbol(c, Decl(stringLiteralTypesTypePredicates01.ts, 19, 7)) +>x : Symbol(x, Decl(stringLiteralTypesTypePredicates01.ts, 9, 3)) +} +else { + let d = x; +>d : Symbol(d, Decl(stringLiteralTypesTypePredicates01.ts, 22, 7)) +>x : Symbol(x, Decl(stringLiteralTypesTypePredicates01.ts, 9, 3)) +} diff --git a/tests/baselines/reference/stringLiteralTypesTypePredicates01.types b/tests/baselines/reference/stringLiteralTypesTypePredicates01.types new file mode 100644 index 0000000000000..43c8271b76b3a --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesTypePredicates01.types @@ -0,0 +1,69 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesTypePredicates01.ts === + +type Kind = "A" | "B" +>Kind : "A" | "B" + +function kindIs(kind: Kind, is: "A"): kind is "A"; +>kindIs : { (kind: "A" | "B", is: "A"): kind is "A"; (kind: "A" | "B", is: "B"): kind is "B"; } +>kind : "A" | "B" +>Kind : "A" | "B" +>is : "A" +>kind : any + +function kindIs(kind: Kind, is: "B"): kind is "B"; +>kindIs : { (kind: "A" | "B", is: "A"): kind is "A"; (kind: "A" | "B", is: "B"): kind is "B"; } +>kind : "A" | "B" +>Kind : "A" | "B" +>is : "B" +>kind : any + +function kindIs(kind: Kind, is: Kind): boolean { +>kindIs : { (kind: "A" | "B", is: "A"): kind is "A"; (kind: "A" | "B", is: "B"): kind is "B"; } +>kind : "A" | "B" +>Kind : "A" | "B" +>is : "A" | "B" +>Kind : "A" | "B" + + return kind === is; +>kind === is : boolean +>kind : "A" | "B" +>is : "A" | "B" +} + +var x: Kind = "A"; +>x : "A" | "B" +>Kind : "A" | "B" +>"A" : "A" + +if (kindIs(x, "A")) { +>kindIs(x, "A") : kind is "A" +>kindIs : { (kind: "A" | "B", is: "A"): kind is "A"; (kind: "A" | "B", is: "B"): kind is "B"; } +>x : "A" | "B" +>"A" : "A" + + let a = x; +>a : "A" +>x : "A" +} +else { + let b = x; +>b : "B" +>x : "B" +} + +if (!kindIs(x, "B")) { +>!kindIs(x, "B") : boolean +>kindIs(x, "B") : kind is "B" +>kindIs : { (kind: "A" | "B", is: "A"): kind is "A"; (kind: "A" | "B", is: "B"): kind is "B"; } +>x : "A" | "B" +>"B" : "B" + + let c = x; +>c : "A" +>x : "A" +} +else { + let d = x; +>d : "B" +>x : "B" +} diff --git a/tests/baselines/reference/superSymbolIndexedAccess5.js b/tests/baselines/reference/superSymbolIndexedAccess5.js index 5bc46dbaed5ee..3acd26d297456 100644 --- a/tests/baselines/reference/superSymbolIndexedAccess5.js +++ b/tests/baselines/reference/superSymbolIndexedAccess5.js @@ -34,7 +34,7 @@ var Bar = (function (_super) { _super.apply(this, arguments); } Bar.prototype[symbol] = function () { - return _super.prototype[symbol](); + return _super.prototype[symbol].call(this); }; return Bar; }(Foo)); diff --git a/tests/baselines/reference/superSymbolIndexedAccess6.js b/tests/baselines/reference/superSymbolIndexedAccess6.js index 417edd9c33840..8b04075c41193 100644 --- a/tests/baselines/reference/superSymbolIndexedAccess6.js +++ b/tests/baselines/reference/superSymbolIndexedAccess6.js @@ -34,7 +34,7 @@ var Bar = (function (_super) { _super.apply(this, arguments); } Bar[symbol] = function () { - return _super[symbol](); + return _super[symbol].call(this); }; return Bar; }(Foo)); diff --git a/tests/baselines/reference/symbolDeclarationEmit13.js b/tests/baselines/reference/symbolDeclarationEmit13.js index 8111672866a56..bbd2c15cfcd1a 100644 --- a/tests/baselines/reference/symbolDeclarationEmit13.js +++ b/tests/baselines/reference/symbolDeclarationEmit13.js @@ -13,6 +13,6 @@ class C { //// [symbolDeclarationEmit13.d.ts] declare class C { - [Symbol.toPrimitive]: string; + readonly [Symbol.toPrimitive]: string; [Symbol.toStringTag]: any; } diff --git a/tests/baselines/reference/symbolDeclarationEmit14.js b/tests/baselines/reference/symbolDeclarationEmit14.js index b8a6b3e409286..d4ae3eeb43c35 100644 --- a/tests/baselines/reference/symbolDeclarationEmit14.js +++ b/tests/baselines/reference/symbolDeclarationEmit14.js @@ -13,6 +13,6 @@ class C { //// [symbolDeclarationEmit14.d.ts] declare class C { - [Symbol.toPrimitive]: string; - [Symbol.toStringTag]: string; + readonly [Symbol.toPrimitive]: string; + readonly [Symbol.toStringTag]: string; } diff --git a/tests/baselines/reference/symbolProperty5.types b/tests/baselines/reference/symbolProperty5.types index 4af020dca1ba3..b338f94f6d325 100644 --- a/tests/baselines/reference/symbolProperty5.types +++ b/tests/baselines/reference/symbolProperty5.types @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/Symbols/symbolProperty5.ts === var x = { ->x : { [Symbol.iterator]: number; [Symbol.toPrimitive](): void; [Symbol.toStringTag]: number; } ->{ [Symbol.iterator]: 0, [Symbol.toPrimitive]() { }, get [Symbol.toStringTag]() { return 0; }} : { [Symbol.iterator]: number; [Symbol.toPrimitive](): void; [Symbol.toStringTag]: number; } +>x : { [Symbol.iterator]: number; [Symbol.toPrimitive](): void; readonly [Symbol.toStringTag]: number; } +>{ [Symbol.iterator]: 0, [Symbol.toPrimitive]() { }, get [Symbol.toStringTag]() { return 0; }} : { [Symbol.iterator]: number; [Symbol.toPrimitive](): void; readonly [Symbol.toStringTag]: number; } [Symbol.iterator]: 0, >Symbol.iterator : symbol diff --git a/tests/baselines/reference/systemExportAssignment.js b/tests/baselines/reference/systemExportAssignment.js index 72962cf835cd1..1e87af1ca229b 100644 --- a/tests/baselines/reference/systemExportAssignment.js +++ b/tests/baselines/reference/systemExportAssignment.js @@ -10,8 +10,9 @@ import * as a from "a"; //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { diff --git a/tests/baselines/reference/systemExportAssignment2.js b/tests/baselines/reference/systemExportAssignment2.js index 0f4dd71249336..177f36f23d24e 100644 --- a/tests/baselines/reference/systemExportAssignment2.js +++ b/tests/baselines/reference/systemExportAssignment2.js @@ -10,8 +10,9 @@ import * as a from "a"; //// [a.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var a; return { setters:[], @@ -21,8 +22,9 @@ System.register([], function(exports_1) { } }); //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { diff --git a/tests/baselines/reference/systemExportAssignment3.js b/tests/baselines/reference/systemExportAssignment3.js index ca2492a54e106..78e330c646785 100644 --- a/tests/baselines/reference/systemExportAssignment3.js +++ b/tests/baselines/reference/systemExportAssignment3.js @@ -12,8 +12,9 @@ import * as a from "a"; //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { diff --git a/tests/baselines/reference/systemModule1.js b/tests/baselines/reference/systemModule1.js index 52f3b48206913..2b7e3e2c4dca5 100644 --- a/tests/baselines/reference/systemModule1.js +++ b/tests/baselines/reference/systemModule1.js @@ -3,8 +3,9 @@ export var x = 1; //// [systemModule1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x; return { setters:[], diff --git a/tests/baselines/reference/systemModule10.js b/tests/baselines/reference/systemModule10.js index ac32c4948e7b9..0c171ab6cc104 100644 --- a/tests/baselines/reference/systemModule10.js +++ b/tests/baselines/reference/systemModule10.js @@ -10,8 +10,9 @@ export {n2} export {n2 as n3} //// [systemModule10.js] -System.register(['file1', 'file2'], function(exports_1) { +System.register(['file1', 'file2'], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var file1_1, n2; return { setters:[ diff --git a/tests/baselines/reference/systemModule10_ES5.js b/tests/baselines/reference/systemModule10_ES5.js index 0c98df6ba99bf..711ca3ed7a39c 100644 --- a/tests/baselines/reference/systemModule10_ES5.js +++ b/tests/baselines/reference/systemModule10_ES5.js @@ -10,8 +10,9 @@ export {n2} export {n2 as n3} //// [systemModule10_ES5.js] -System.register(['file1', 'file2'], function(exports_1) { +System.register(['file1', 'file2'], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var file1_1, n2; return { setters:[ diff --git a/tests/baselines/reference/systemModule11.js b/tests/baselines/reference/systemModule11.js index 92b0576b91907..f7d47db1d7f60 100644 --- a/tests/baselines/reference/systemModule11.js +++ b/tests/baselines/reference/systemModule11.js @@ -42,8 +42,9 @@ export * from 'a'; //// [file1.js] // set of tests cases that checks generation of local storage for exported names -System.register(['bar'], function(exports_1) { +System.register(['bar'], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x; function foo() { } exports_1("foo", foo); @@ -68,8 +69,9 @@ System.register(['bar'], function(exports_1) { } }); //// [file2.js] -System.register(['bar'], function(exports_1) { +System.register(['bar'], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x, y; var exportedNames_1 = { 'x': true, @@ -94,8 +96,9 @@ System.register(['bar'], function(exports_1) { } }); //// [file3.js] -System.register(['a', 'bar'], function(exports_1) { +System.register(['a', 'bar'], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; function foo() { } exports_1("default", foo); var exportedNames_1 = { @@ -125,8 +128,9 @@ System.register(['a', 'bar'], function(exports_1) { } }); //// [file4.js] -System.register(['a'], function(exports_1) { +System.register(['a'], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x, z, z1; function foo() { } exports_1("foo", foo); @@ -147,8 +151,9 @@ System.register(['a'], function(exports_1) { } }); //// [file5.js] -System.register(['a'], function(exports_1) { +System.register(['a'], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; function foo() { } function exportStar_1(m) { var exports = {}; diff --git a/tests/baselines/reference/systemModule12.js b/tests/baselines/reference/systemModule12.js index d8961c3b0017c..45e7beaf21860 100644 --- a/tests/baselines/reference/systemModule12.js +++ b/tests/baselines/reference/systemModule12.js @@ -5,8 +5,9 @@ import n from 'file1' //// [systemModule12.js] -System.register("NamedModule", [], function(exports_1) { +System.register("NamedModule", [], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { diff --git a/tests/baselines/reference/systemModule13.js b/tests/baselines/reference/systemModule13.js index 0b81a946de4cb..e3ed2daf3a6e2 100644 --- a/tests/baselines/reference/systemModule13.js +++ b/tests/baselines/reference/systemModule13.js @@ -5,8 +5,9 @@ export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}}; for ([x] of [[1]]) {} //// [systemModule13.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x, y, z, z0, z1; return { setters:[], diff --git a/tests/baselines/reference/systemModule14.js b/tests/baselines/reference/systemModule14.js index 2ec8fc600f42c..5eaafd9ba6ba2 100644 --- a/tests/baselines/reference/systemModule14.js +++ b/tests/baselines/reference/systemModule14.js @@ -11,8 +11,9 @@ var x = 1; export {foo as b} //// [systemModule14.js] -System.register(["foo"], function(exports_1) { +System.register(["foo"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var foo_1; var x; function foo() { diff --git a/tests/baselines/reference/systemModule15.js b/tests/baselines/reference/systemModule15.js index f8dc11b0ac7c7..f2fefb344acc3 100644 --- a/tests/baselines/reference/systemModule15.js +++ b/tests/baselines/reference/systemModule15.js @@ -34,8 +34,9 @@ export default value; export var value2 = "v"; //// [file3.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var value; return { setters:[], @@ -46,8 +47,9 @@ System.register([], function(exports_1) { } }); //// [file4.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var value2; return { setters:[], @@ -57,8 +59,9 @@ System.register([], function(exports_1) { } }); //// [file2.js] -System.register(["./file3"], function(exports_1) { +System.register(["./file3"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var moduleCStar, file3_1, file3_2; return { setters:[ @@ -75,8 +78,9 @@ System.register(["./file3"], function(exports_1) { } }); //// [file1.js] -System.register(["./file2"], function(exports_1) { +System.register(["./file2"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var moduleB; return { setters:[ diff --git a/tests/baselines/reference/systemModule16.js b/tests/baselines/reference/systemModule16.js index 76fb85cd3aead..27fa77b9c761f 100644 --- a/tests/baselines/reference/systemModule16.js +++ b/tests/baselines/reference/systemModule16.js @@ -13,8 +13,9 @@ x,y,a1,b1,d1; //// [systemModule16.js] -System.register(["foo", "bar"], function(exports_1) { +System.register(["foo", "bar"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x, y, foo_1; var exportedNames_1 = { 'x': true, diff --git a/tests/baselines/reference/systemModule17.js b/tests/baselines/reference/systemModule17.js index 6daa119d2873f..6bf1ce25b8487 100644 --- a/tests/baselines/reference/systemModule17.js +++ b/tests/baselines/reference/systemModule17.js @@ -42,8 +42,9 @@ export {II}; export {II as II1}; //// [f1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var A; return { setters:[], @@ -58,8 +59,9 @@ System.register([], function(exports_1) { } }); //// [f2.js] -System.register(["f1"], function(exports_1) { +System.register(["f1"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var f1_1; var x, N, IX; return { diff --git a/tests/baselines/reference/systemModule2.js b/tests/baselines/reference/systemModule2.js index ee3dfd327ec71..95755421eaac7 100644 --- a/tests/baselines/reference/systemModule2.js +++ b/tests/baselines/reference/systemModule2.js @@ -4,8 +4,9 @@ var x = 1; export = x; //// [systemModule2.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x; return { setters:[], diff --git a/tests/baselines/reference/systemModule3.js b/tests/baselines/reference/systemModule3.js index dbef74f30364d..7800c8c220e56 100644 --- a/tests/baselines/reference/systemModule3.js +++ b/tests/baselines/reference/systemModule3.js @@ -18,8 +18,9 @@ export default class C {} export default class {} //// [file1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; function default_1() { } exports_1("default", default_1); return { @@ -29,8 +30,9 @@ System.register([], function(exports_1) { } }); //// [file2.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; function f() { } exports_1("default", f); return { @@ -40,8 +42,9 @@ System.register([], function(exports_1) { } }); //// [file3.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var C; return { setters:[], @@ -56,8 +59,9 @@ System.register([], function(exports_1) { } }); //// [file4.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var default_1; return { setters:[], diff --git a/tests/baselines/reference/systemModule4.js b/tests/baselines/reference/systemModule4.js index 192c87d49eab8..67990c63a5816 100644 --- a/tests/baselines/reference/systemModule4.js +++ b/tests/baselines/reference/systemModule4.js @@ -4,8 +4,9 @@ export var x = 1; export var y; //// [systemModule4.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x, y; return { setters:[], diff --git a/tests/baselines/reference/systemModule5.js b/tests/baselines/reference/systemModule5.js index 4a455f25b1395..d0b1f79b2f704 100644 --- a/tests/baselines/reference/systemModule5.js +++ b/tests/baselines/reference/systemModule5.js @@ -4,8 +4,9 @@ export function foo() {} //// [systemModule5.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; function foo() { } exports_1("foo", foo); return { diff --git a/tests/baselines/reference/systemModule6.js b/tests/baselines/reference/systemModule6.js index 51c8fbc68fb85..4848c82f7380a 100644 --- a/tests/baselines/reference/systemModule6.js +++ b/tests/baselines/reference/systemModule6.js @@ -7,8 +7,9 @@ function foo() { //// [systemModule6.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var C; function foo() { new C(); diff --git a/tests/baselines/reference/systemModule7.js b/tests/baselines/reference/systemModule7.js index d76d86a3b0f51..60114b54400cd 100644 --- a/tests/baselines/reference/systemModule7.js +++ b/tests/baselines/reference/systemModule7.js @@ -11,8 +11,9 @@ export module M { } //// [systemModule7.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var M; return { setters:[], diff --git a/tests/baselines/reference/systemModule8.js b/tests/baselines/reference/systemModule8.js index b6cdd677f007c..f099628facb4d 100644 --- a/tests/baselines/reference/systemModule8.js +++ b/tests/baselines/reference/systemModule8.js @@ -31,8 +31,9 @@ export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}}; for ([x] of [[1]]) {} //// [systemModule8.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x, y, z0, z1; function foo() { exports_1("x", x = 100); diff --git a/tests/baselines/reference/systemModule9.js b/tests/baselines/reference/systemModule9.js index 137dd019a023a..940b9e5975b71 100644 --- a/tests/baselines/reference/systemModule9.js +++ b/tests/baselines/reference/systemModule9.js @@ -22,8 +22,9 @@ export {x}; export {y as z}; //// [systemModule9.js] -System.register(['file1', 'file2', 'file3', 'file4', 'file5', 'file6', 'file7'], function(exports_1) { +System.register(['file1', 'file2', 'file3', 'file4', 'file5', 'file6', 'file7'], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var ns, file2_1, file3_1, file5_1, ns3; var x, y; var exportedNames_1 = { diff --git a/tests/baselines/reference/systemModuleAmbientDeclarations.js b/tests/baselines/reference/systemModuleAmbientDeclarations.js index 9bdde23a8427a..91bad620b77af 100644 --- a/tests/baselines/reference/systemModuleAmbientDeclarations.js +++ b/tests/baselines/reference/systemModuleAmbientDeclarations.js @@ -29,8 +29,9 @@ export declare module M { var v: number; } //// [file1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var promise, foo, c, e; return { setters:[], @@ -44,8 +45,9 @@ System.register([], function(exports_1) { } }); //// [file2.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { @@ -53,8 +55,9 @@ System.register([], function(exports_1) { } }); //// [file3.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { @@ -62,8 +65,9 @@ System.register([], function(exports_1) { } }); //// [file4.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { @@ -71,8 +75,9 @@ System.register([], function(exports_1) { } }); //// [file5.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { @@ -80,8 +85,9 @@ System.register([], function(exports_1) { } }); //// [file6.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { diff --git a/tests/baselines/reference/systemModuleConstEnums.js b/tests/baselines/reference/systemModuleConstEnums.js index 8b8707768d9cd..08df549a87b9f 100644 --- a/tests/baselines/reference/systemModuleConstEnums.js +++ b/tests/baselines/reference/systemModuleConstEnums.js @@ -13,8 +13,9 @@ module M { } //// [systemModuleConstEnums.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; function foo() { use(0 /* X */); use(0 /* X */); diff --git a/tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.js b/tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.js index 8466d399ac976..be2f07cc59e5c 100644 --- a/tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.js +++ b/tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.js @@ -13,8 +13,9 @@ module M { } //// [systemModuleConstEnumsSeparateCompilation.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var TopLevelConstEnum, M; function foo() { use(TopLevelConstEnum.X); diff --git a/tests/baselines/reference/systemModuleDeclarationMerging.js b/tests/baselines/reference/systemModuleDeclarationMerging.js index 5ed029a769af7..1196aa8898d0b 100644 --- a/tests/baselines/reference/systemModuleDeclarationMerging.js +++ b/tests/baselines/reference/systemModuleDeclarationMerging.js @@ -10,8 +10,9 @@ export enum E {} export module E { var x; } //// [systemModuleDeclarationMerging.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var F, C, E; function F() { } exports_1("F", F); diff --git a/tests/baselines/reference/systemModuleExportDefault.js b/tests/baselines/reference/systemModuleExportDefault.js index cf1a99a4ad758..eaa4e6ddaa779 100644 --- a/tests/baselines/reference/systemModuleExportDefault.js +++ b/tests/baselines/reference/systemModuleExportDefault.js @@ -16,8 +16,9 @@ export default class C {} //// [file1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; function default_1() { } exports_1("default", default_1); return { @@ -27,8 +28,9 @@ System.register([], function(exports_1) { } }); //// [file2.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; function foo() { } exports_1("default", foo); return { @@ -38,8 +40,9 @@ System.register([], function(exports_1) { } }); //// [file3.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var default_1; return { setters:[], @@ -54,8 +57,9 @@ System.register([], function(exports_1) { } }); //// [file4.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var C; return { setters:[], diff --git a/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.js b/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.js index ee9858a7fec83..1cf993baec000 100644 --- a/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.js +++ b/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.js @@ -13,8 +13,9 @@ export module TopLevelModule2 { } //// [systemModuleNonTopLevelModuleMembers.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var TopLevelClass, TopLevelModule, TopLevelEnum, TopLevelModule2; function TopLevelFunction() { } exports_1("TopLevelFunction", TopLevelFunction); diff --git a/tests/baselines/reference/systemModuleWithSuperClass.js b/tests/baselines/reference/systemModuleWithSuperClass.js index fe9c2742f2dd8..0aab851cc575a 100644 --- a/tests/baselines/reference/systemModuleWithSuperClass.js +++ b/tests/baselines/reference/systemModuleWithSuperClass.js @@ -13,8 +13,9 @@ export class Bar extends Foo { } //// [foo.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var Foo; return { setters:[], @@ -29,8 +30,9 @@ System.register([], function(exports_1) { } }); //// [bar.js] -System.register(['./foo'], function(exports_1) { +System.register(['./foo'], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; 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; } diff --git a/tests/baselines/reference/thisInInvalidContexts.errors.txt b/tests/baselines/reference/thisInInvalidContexts.errors.txt index 76b90ed7c207a..d33260fa108df 100644 --- a/tests/baselines/reference/thisInInvalidContexts.errors.txt +++ b/tests/baselines/reference/thisInInvalidContexts.errors.txt @@ -1,5 +1,6 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(22,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(14,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(22,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(38,25): error TS2507: Type 'any' is not a constructor function type. @@ -7,7 +8,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(44,9): tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts (7 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts (8 errors) ==== //'this' in static member initializer class ErrClass1 { static t = this; // Error @@ -23,7 +24,9 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): t; //'this' in optional super call constructor() { - super(this); // OK + super(this); // Error + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -33,7 +36,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): constructor() { super(this); // Error ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInInvalidContexts.js b/tests/baselines/reference/thisInInvalidContexts.js index 63a39b33b0e7b..75ccd12c2889c 100644 --- a/tests/baselines/reference/thisInInvalidContexts.js +++ b/tests/baselines/reference/thisInInvalidContexts.js @@ -12,7 +12,7 @@ class ClassWithNoInitializer extends BaseErrClass { t; //'this' in optional super call constructor() { - super(this); // OK + super(this); // Error } } @@ -70,7 +70,7 @@ var ClassWithNoInitializer = (function (_super) { __extends(ClassWithNoInitializer, _super); //'this' in optional super call function ClassWithNoInitializer() { - _super.call(this, this); // OK + _super.call(this, this); // Error } return ClassWithNoInitializer; }(BaseErrClass)); diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt index a1afdea661ba1..6c1a257b5ea43 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt @@ -1,5 +1,6 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(22,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(14,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(22,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(38,25): error TS2507: Type 'any' is not a constructor function type. @@ -8,7 +9,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(48,1): error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file. -==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (8 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (9 errors) ==== //'this' in static member initializer class ErrClass1 { static t = this; // Error @@ -24,7 +25,9 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod t; //'this' in optional super call constructor() { - super(this); // OK + super(this); // error: "super" has to be called before "this" accessing + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -34,7 +37,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod constructor() { super(this); // Error ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.js b/tests/baselines/reference/thisInInvalidContextsExternalModule.js index 3df51877d1399..2e7e6d8b47cca 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.js +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.js @@ -12,7 +12,7 @@ class ClassWithNoInitializer extends BaseErrClass { t; //'this' in optional super call constructor() { - super(this); // OK + super(this); // error: "super" has to be called before "this" accessing } } @@ -71,7 +71,7 @@ var ClassWithNoInitializer = (function (_super) { __extends(ClassWithNoInitializer, _super); //'this' in optional super call function ClassWithNoInitializer() { - _super.call(this, this); // OK + _super.call(this, this); // error: "super" has to be called before "this" accessing } return ClassWithNoInitializer; }(BaseErrClass)); diff --git a/tests/baselines/reference/thisInSuperCall.errors.txt b/tests/baselines/reference/thisInSuperCall.errors.txt index 57255aa958235..d1eeb1d2b2b3b 100644 --- a/tests/baselines/reference/thisInSuperCall.errors.txt +++ b/tests/baselines/reference/thisInSuperCall.errors.txt @@ -1,15 +1,18 @@ -tests/cases/compiler/thisInSuperCall.ts(14,15): error TS2332: 'this' cannot be referenced in current location. -tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/thisInSuperCall.ts(7,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/thisInSuperCall.ts(14,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/thisInSuperCall.ts(20,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall.ts (2 errors) ==== +==== tests/cases/compiler/thisInSuperCall.ts (3 errors) ==== class Base { constructor(x: any) {} } class Foo extends Base { constructor() { - super(this); // no error + super(this); // error: "super" has to be called before "this" accessing + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -18,7 +21,7 @@ tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be r constructor() { super(this); // error ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -26,6 +29,6 @@ tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be r constructor(public p) { super(this); // error ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/baselines/reference/thisInSuperCall.js b/tests/baselines/reference/thisInSuperCall.js index a867715957fa1..827d101c95aed 100644 --- a/tests/baselines/reference/thisInSuperCall.js +++ b/tests/baselines/reference/thisInSuperCall.js @@ -5,7 +5,7 @@ class Base { class Foo extends Base { constructor() { - super(this); // no error + super(this); // error: "super" has to be called before "this" accessing } } @@ -36,7 +36,7 @@ var Base = (function () { var Foo = (function (_super) { __extends(Foo, _super); function Foo() { - _super.call(this, this); // no error + _super.call(this, this); // error: "super" has to be called before "this" accessing } return Foo; }(Base)); diff --git a/tests/baselines/reference/thisInSuperCall1.errors.txt b/tests/baselines/reference/thisInSuperCall1.errors.txt index 7efc66d1666af..20bc502ab7915 100644 --- a/tests/baselines/reference/thisInSuperCall1.errors.txt +++ b/tests/baselines/reference/thisInSuperCall1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/thisInSuperCall1.ts(7,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/thisInSuperCall1.ts(7,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. ==== tests/cases/compiler/thisInSuperCall1.ts (1 errors) ==== @@ -10,7 +10,7 @@ tests/cases/compiler/thisInSuperCall1.ts(7,15): error TS2332: 'this' cannot be r constructor(public x: number) { super(this); ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/baselines/reference/thisInSuperCall2.errors.txt b/tests/baselines/reference/thisInSuperCall2.errors.txt index d3a94f79487ce..4e4e9b50a8ee6 100644 --- a/tests/baselines/reference/thisInSuperCall2.errors.txt +++ b/tests/baselines/reference/thisInSuperCall2.errors.txt @@ -1,7 +1,8 @@ -tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/thisInSuperCall2.ts(8,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall2.ts (1 errors) ==== +==== tests/cases/compiler/thisInSuperCall2.ts (2 errors) ==== class Base { constructor(a: any) {} } @@ -9,7 +10,9 @@ tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be class Foo extends Base { public x: number; constructor() { - super(this); // no error + super(this); // error: "super" has to be called before "this" accessing + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -19,7 +22,7 @@ tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be constructor() { super(this); // error ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/baselines/reference/thisInSuperCall2.js b/tests/baselines/reference/thisInSuperCall2.js index 82cae46b2d667..fdffdd27d6d4b 100644 --- a/tests/baselines/reference/thisInSuperCall2.js +++ b/tests/baselines/reference/thisInSuperCall2.js @@ -6,7 +6,7 @@ class Base { class Foo extends Base { public x: number; constructor() { - super(this); // no error + super(this); // error: "super" has to be called before "this" accessing } } @@ -33,7 +33,7 @@ var Base = (function () { var Foo = (function (_super) { __extends(Foo, _super); function Foo() { - _super.call(this, this); // no error + _super.call(this, this); // error: "super" has to be called before "this" accessing } return Foo; }(Base)); diff --git a/tests/baselines/reference/thisInSuperCall3.errors.txt b/tests/baselines/reference/thisInSuperCall3.errors.txt index df5c5f8b5a2dd..27a7dc8b25d98 100644 --- a/tests/baselines/reference/thisInSuperCall3.errors.txt +++ b/tests/baselines/reference/thisInSuperCall3.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/thisInSuperCall3.ts(9,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/thisInSuperCall3.ts(9,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. ==== tests/cases/compiler/thisInSuperCall3.ts (1 errors) ==== @@ -12,7 +12,7 @@ tests/cases/compiler/thisInSuperCall3.ts(9,15): error TS2332: 'this' cannot be r constructor() { super(this); ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/baselines/reference/thisTypeAsConstraint.js b/tests/baselines/reference/thisTypeAsConstraint.js new file mode 100644 index 0000000000000..b5a7113549dba --- /dev/null +++ b/tests/baselines/reference/thisTypeAsConstraint.js @@ -0,0 +1,14 @@ +//// [thisTypeAsConstraint.ts] +class C { + public m() { + } +} + +//// [thisTypeAsConstraint.js] +var C = (function () { + function C() { + } + C.prototype.m = function () { + }; + return C; +}()); diff --git a/tests/baselines/reference/thisTypeAsConstraint.symbols b/tests/baselines/reference/thisTypeAsConstraint.symbols new file mode 100644 index 0000000000000..020dd966cad19 --- /dev/null +++ b/tests/baselines/reference/thisTypeAsConstraint.symbols @@ -0,0 +1,9 @@ +=== tests/cases/compiler/thisTypeAsConstraint.ts === +class C { +>C : Symbol(C, Decl(thisTypeAsConstraint.ts, 0, 0)) + + public m() { +>m : Symbol(m, Decl(thisTypeAsConstraint.ts, 0, 9)) +>T : Symbol(T, Decl(thisTypeAsConstraint.ts, 1, 11)) + } +} diff --git a/tests/baselines/reference/thisTypeAsConstraint.types b/tests/baselines/reference/thisTypeAsConstraint.types new file mode 100644 index 0000000000000..e55fb1f0cca67 --- /dev/null +++ b/tests/baselines/reference/thisTypeAsConstraint.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/thisTypeAsConstraint.ts === +class C { +>C : C + + public m() { +>m : () => void +>T : T + } +} diff --git a/tests/baselines/reference/tsxReactEmit1.js b/tests/baselines/reference/tsxReactEmit1.js index 05781ab853054..f62a7bdc47db4 100644 --- a/tests/baselines/reference/tsxReactEmit1.js +++ b/tests/baselines/reference/tsxReactEmit1.js @@ -70,5 +70,8 @@ var SomeClass = (function () { return SomeClass; }()); var whitespace1 = React.createElement("div", null, " "); -var whitespace2 = React.createElement("div", null, " ", p, " "); +var whitespace2 = React.createElement("div", null, + " ", + p, + " "); var whitespace3 = React.createElement("div", null, p); diff --git a/tests/baselines/reference/tsxReactEmit3.js b/tests/baselines/reference/tsxReactEmit3.js index bd42177e18728..07a8f22761ff1 100644 --- a/tests/baselines/reference/tsxReactEmit3.js +++ b/tests/baselines/reference/tsxReactEmit3.js @@ -8,4 +8,11 @@ declare var Foo, Bar, baz; q s ; //// [test.js] -React.createElement(Foo, null, " ", React.createElement(Bar, null, " q "), " ", React.createElement(Bar, null), " s ", React.createElement(Bar, null), React.createElement(Bar, null)); +React.createElement(Foo, null, + " ", + React.createElement(Bar, null, " q "), + " ", + React.createElement(Bar, null), + " s ", + React.createElement(Bar, null), + React.createElement(Bar, null)); diff --git a/tests/baselines/reference/tsxReactEmitNesting.js b/tests/baselines/reference/tsxReactEmitNesting.js new file mode 100644 index 0000000000000..53abc04aa9bc9 --- /dev/null +++ b/tests/baselines/reference/tsxReactEmitNesting.js @@ -0,0 +1,60 @@ +//// [file.tsx] + +declare var vdom: any; +declare var ctrl: any; +declare var model: any; + +// A simple render function with nesting and control statements +let render = (ctrl, model) => +
+
+

todos <x>

+ +
+
+ +
    + {model.filteredTodos.map((todo) => +
  • +
    + {(!todo.editable) ? + + : null + } + + +
    +
    +
    +
    +
  • + )} +
+
+
+ + + +//// [file.js] +// A simple render function with nesting and control statements +var render = function (ctrl, model) { + return vdom.createElement("section", {class: "todoapp"}, + vdom.createElement("header", {class: "header"}, + vdom.createElement("h1", null, "todos "), + vdom.createElement("input", {class: "new-todo", autofocus: true, autocomplete: "off", placeholder: "What needs to be done?", value: model.newTodo, onKeyup: ctrl.addTodo.bind(ctrl, model)})), + vdom.createElement("section", {class: "main", style: { display: (model.todos && model.todos.length) ? "block" : "none" }}, + vdom.createElement("input", {class: "toggle-all", type: "checkbox", onChange: ctrl.toggleAll.bind(ctrl)}), + vdom.createElement("ul", {class: "todo-list"}, model.filteredTodos.map(function (todo) { + return vdom.createElement("li", {class: { todo: true, completed: todo.completed, editing: todo == model.editedTodo }}, + vdom.createElement("div", {class: "view"}, + (!todo.editable) ? + vdom.createElement("input", {class: "toggle", type: "checkbox"}) + : null, + vdom.createElement("label", {onDoubleClick: function () { ctrl.editTodo(todo); }}, todo.title), + vdom.createElement("button", {class: "destroy", onClick: ctrl.removeTodo.bind(ctrl, todo)}), + vdom.createElement("div", {class: "iconBorder"}, + vdom.createElement("div", {class: "icon"}) + )) + ); + })))); +}; diff --git a/tests/baselines/reference/tsxReactEmitNesting.symbols b/tests/baselines/reference/tsxReactEmitNesting.symbols new file mode 100644 index 0000000000000..efccb60274703 --- /dev/null +++ b/tests/baselines/reference/tsxReactEmitNesting.symbols @@ -0,0 +1,139 @@ +=== tests/cases/conformance/jsx/file.tsx === + +declare var vdom: any; +>vdom : Symbol(vdom, Decl(file.tsx, 1, 11)) + +declare var ctrl: any; +>ctrl : Symbol(ctrl, Decl(file.tsx, 2, 11)) + +declare var model: any; +>model : Symbol(model, Decl(file.tsx, 3, 11)) + +// A simple render function with nesting and control statements +let render = (ctrl, model) => +>render : Symbol(render, Decl(file.tsx, 6, 3)) +>ctrl : Symbol(ctrl, Decl(file.tsx, 6, 14)) +>model : Symbol(model, Decl(file.tsx, 6, 19)) + +
+>section : Symbol(unknown) +>class : Symbol(unknown) + +
+>header : Symbol(unknown) +>class : Symbol(unknown) + +

todos <x>

+>h1 : Symbol(unknown) +>h1 : Symbol(unknown) + + +>input : Symbol(unknown) +>class : Symbol(unknown) +>autofocus : Symbol(unknown) +>autocomplete : Symbol(unknown) +>placeholder : Symbol(unknown) +>value : Symbol(unknown) +>model : Symbol(model, Decl(file.tsx, 6, 19)) +>onKeyup : Symbol(unknown) +>ctrl : Symbol(ctrl, Decl(file.tsx, 6, 14)) +>ctrl : Symbol(ctrl, Decl(file.tsx, 6, 14)) +>model : Symbol(model, Decl(file.tsx, 6, 19)) + +
+>header : Symbol(unknown) + +
+>section : Symbol(unknown) +>class : Symbol(unknown) +>style : Symbol(unknown) +>display : Symbol(display, Decl(file.tsx, 12, 38)) +>model : Symbol(model, Decl(file.tsx, 6, 19)) +>model : Symbol(model, Decl(file.tsx, 6, 19)) + + +>input : Symbol(unknown) +>class : Symbol(unknown) +>type : Symbol(unknown) +>onChange : Symbol(unknown) +>ctrl : Symbol(ctrl, Decl(file.tsx, 6, 14)) +>ctrl : Symbol(ctrl, Decl(file.tsx, 6, 14)) + +
    +>ul : Symbol(unknown) +>class : Symbol(unknown) + + {model.filteredTodos.map((todo) => +>model : Symbol(model, Decl(file.tsx, 6, 19)) +>todo : Symbol(todo, Decl(file.tsx, 15, 42)) + +
  • +>li : Symbol(unknown) +>class : Symbol(unknown) +>todo : Symbol(todo, Decl(file.tsx, 16, 32)) +>completed : Symbol(completed, Decl(file.tsx, 16, 43)) +>todo : Symbol(todo, Decl(file.tsx, 15, 42)) +>editing : Symbol(editing, Decl(file.tsx, 16, 70)) +>todo : Symbol(todo, Decl(file.tsx, 15, 42)) +>model : Symbol(model, Decl(file.tsx, 6, 19)) + +
    +>div : Symbol(unknown) +>class : Symbol(unknown) + + {(!todo.editable) ? +>todo : Symbol(todo, Decl(file.tsx, 15, 42)) + + +>input : Symbol(unknown) +>class : Symbol(unknown) +>type : Symbol(unknown) +>input : Symbol(unknown) + + : null + } + +>label : Symbol(unknown) +>onDoubleClick : Symbol(unknown) +>ctrl : Symbol(ctrl, Decl(file.tsx, 6, 14)) +>todo : Symbol(todo, Decl(file.tsx, 15, 42)) +>todo : Symbol(todo, Decl(file.tsx, 15, 42)) +>label : Symbol(unknown) + + +>button : Symbol(unknown) +>class : Symbol(unknown) +>onClick : Symbol(unknown) +>ctrl : Symbol(ctrl, Decl(file.tsx, 6, 14)) +>ctrl : Symbol(ctrl, Decl(file.tsx, 6, 14)) +>todo : Symbol(todo, Decl(file.tsx, 15, 42)) +>button : Symbol(unknown) + +
    +>div : Symbol(unknown) +>class : Symbol(unknown) + +
    +>div : Symbol(unknown) +>class : Symbol(unknown) + +
    +>div : Symbol(unknown) + +
    +>div : Symbol(unknown) + +
  • +>li : Symbol(unknown) + + )} +
+>ul : Symbol(unknown) + +
+>section : Symbol(unknown) + +
+>section : Symbol(unknown) + + diff --git a/tests/baselines/reference/tsxReactEmitNesting.types b/tests/baselines/reference/tsxReactEmitNesting.types new file mode 100644 index 0000000000000..fff29c1152535 --- /dev/null +++ b/tests/baselines/reference/tsxReactEmitNesting.types @@ -0,0 +1,208 @@ +=== tests/cases/conformance/jsx/file.tsx === + +declare var vdom: any; +>vdom : any + +declare var ctrl: any; +>ctrl : any + +declare var model: any; +>model : any + +// A simple render function with nesting and control statements +let render = (ctrl, model) => +>render : (ctrl: any, model: any) => any +>(ctrl, model) =>

todos <x>

    {model.filteredTodos.map((todo) =>
  • {(!todo.editable) ? : null }
  • )}
: (ctrl: any, model: any) => any +>ctrl : any +>model : any + +
+>

todos <x>

    {model.filteredTodos.map((todo) =>
  • {(!todo.editable) ? : null }
  • )}
: any +>section : any +>class : any + +
+>

todos <x>

: any +>header : any +>class : any + +

todos <x>

+>

todos <x>

: any +>h1 : any +>h1 : any + + +> : any +>input : any +>class : any +>autofocus : any +>autocomplete : any +>placeholder : any +>value : any +>model.newTodo : any +>model : any +>newTodo : any +>onKeyup : any +>ctrl.addTodo.bind(ctrl, model) : any +>ctrl.addTodo.bind : any +>ctrl.addTodo : any +>ctrl : any +>addTodo : any +>bind : any +>ctrl : any +>model : any + +
+>header : any + +
+>
    {model.filteredTodos.map((todo) =>
  • {(!todo.editable) ? : null }
  • )}
: any +>section : any +>class : any +>style : any +>{display:(model.todos && model.todos.length) ? "block" : "none"} : { display: string; } +>display : string +>(model.todos && model.todos.length) ? "block" : "none" : string +>(model.todos && model.todos.length) : any +>model.todos && model.todos.length : any +>model.todos : any +>model : any +>todos : any +>model.todos.length : any +>model.todos : any +>model : any +>todos : any +>length : any +>"block" : string +>"none" : string + + +> : any +>input : any +>class : any +>type : any +>onChange : any +>ctrl.toggleAll.bind(ctrl) : any +>ctrl.toggleAll.bind : any +>ctrl.toggleAll : any +>ctrl : any +>toggleAll : any +>bind : any +>ctrl : any + +
    +>
      {model.filteredTodos.map((todo) =>
    • {(!todo.editable) ? : null }
    • )}
    : any +>ul : any +>class : any + + {model.filteredTodos.map((todo) => +>model.filteredTodos.map((todo) =>
  • {(!todo.editable) ? : null }
  • ) : any +>model.filteredTodos.map : any +>model.filteredTodos : any +>model : any +>filteredTodos : any +>map : any +>(todo) =>
  • {(!todo.editable) ? : null }
  • : (todo: any) => any +>todo : any + +
  • +>
  • {(!todo.editable) ? : null }
  • : any +>li : any +>class : any +>{todo: true, completed: todo.completed, editing: todo == model.editedTodo} : { todo: boolean; completed: any; editing: boolean; } +>todo : boolean +>true : boolean +>completed : any +>todo.completed : any +>todo : any +>completed : any +>editing : boolean +>todo == model.editedTodo : boolean +>todo : any +>model.editedTodo : any +>model : any +>editedTodo : any + +
    +>
    {(!todo.editable) ? : null }
    : any +>div : any +>class : any + + {(!todo.editable) ? +>(!todo.editable) ? : null : any +>(!todo.editable) : boolean +>!todo.editable : boolean +>todo.editable : any +>todo : any +>editable : any + + +> : any +>input : any +>class : any +>type : any +>input : any + + : null +>null : null + } + +> : any +>label : any +>onDoubleClick : any +>()=>{ctrl.editTodo(todo)} : () => void +>ctrl.editTodo(todo) : any +>ctrl.editTodo : any +>ctrl : any +>editTodo : any +>todo : any +>todo.title : any +>todo : any +>title : any +>label : any + + +> : any +>button : any +>class : any +>onClick : any +>ctrl.removeTodo.bind(ctrl,todo) : any +>ctrl.removeTodo.bind : any +>ctrl.removeTodo : any +>ctrl : any +>removeTodo : any +>bind : any +>ctrl : any +>todo : any +>button : any + +
    +>
    : any +>div : any +>class : any + +
    +>
    : any +>div : any +>class : any + +
    +>div : any + +
    +>div : any + + +>li : any + + )} +
+>ul : any + +
+>section : any + +
+>section : any + + diff --git a/tests/baselines/reference/tsxReactEmitWhitespace.js b/tests/baselines/reference/tsxReactEmitWhitespace.js index 9614cbf2f2cf4..9a157d242e3c2 100644 --- a/tests/baselines/reference/tsxReactEmitWhitespace.js +++ b/tests/baselines/reference/tsxReactEmitWhitespace.js @@ -59,7 +59,10 @@ var p = 0; // Emit " " React.createElement("div", null, " "); // Emit " ", p, " " -React.createElement("div", null, " ", p, " "); +React.createElement("div", null, + " ", + p, + " "); // Emit only p React.createElement("div", null, p); // Emit only p diff --git a/tests/baselines/reference/tsxReactEmitWhitespace2.js b/tests/baselines/reference/tsxReactEmitWhitespace2.js index f649ca43ebd4b..152d869fc03f6 100644 --- a/tests/baselines/reference/tsxReactEmitWhitespace2.js +++ b/tests/baselines/reference/tsxReactEmitWhitespace2.js @@ -18,8 +18,15 @@ declare var React: any; //// [file.js] // Emit ' word' in the last string -React.createElement("div", null, "word ", React.createElement("code", null, "code"), " word"); +React.createElement("div", null, + "word ", + React.createElement("code", null, "code"), + " word"); // Same here -React.createElement("div", null, React.createElement("code", null, "code"), " word"); +React.createElement("div", null, + React.createElement("code", null, "code"), + " word"); // And here -React.createElement("div", null, React.createElement("code", null), " word"); +React.createElement("div", null, + React.createElement("code", null), + " word"); diff --git a/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.errors.txt b/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.errors.txt index 49f17e7891de1..ef582ab9b265a 100644 --- a/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.errors.txt +++ b/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.errors.txt @@ -1,4 +1,3 @@ -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(4,18): error TS2382: Specialized overload signature is not assignable to any non-specialized signature. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(37,25): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(38,25): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(39,25): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. @@ -36,13 +35,11 @@ tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes0 Type '"World"' is not assignable to type '"Hello"'. -==== tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts (25 errors) ==== +==== tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts (24 errors) ==== declare function randBool(): boolean; declare function takeReturnString(str: string): string; declare function takeReturnHello(str: "Hello"): "Hello"; - ~~~~~~~~~~~~~~~ -!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature. declare function takeReturnHelloWorld(str: "Hello" | "World"): "Hello" | "World"; function fun1(x: T, y: T) { diff --git a/tests/baselines/reference/typeGuardOfFormThisMember.js b/tests/baselines/reference/typeGuardOfFormThisMember.js index 2f983d2cdf841..9d71613ed8ffe 100644 --- a/tests/baselines/reference/typeGuardOfFormThisMember.js +++ b/tests/baselines/reference/typeGuardOfFormThisMember.js @@ -170,7 +170,7 @@ declare namespace Test { path: string; isFSO: this is FileSystemObject; isFile: this is File; - isDirectory: this is Directory; + readonly isDirectory: this is Directory; isNetworked: this is (Networked & this); constructor(path: string); } diff --git a/tests/baselines/reference/typeGuardOfFormThisMemberErrors.js b/tests/baselines/reference/typeGuardOfFormThisMemberErrors.js index 6f681ab09cffc..5991fdd316971 100644 --- a/tests/baselines/reference/typeGuardOfFormThisMemberErrors.js +++ b/tests/baselines/reference/typeGuardOfFormThisMemberErrors.js @@ -95,7 +95,7 @@ declare namespace Test { path: string; isFSO: this is FileSystemObject; isFile: this is File; - isDirectory: this is Directory; + readonly isDirectory: this is Directory; isNetworked: this is (Networked & this); constructor(path: string); } diff --git a/tests/baselines/reference/typeOfEnumAndVarRedeclarations.errors.txt b/tests/baselines/reference/typeOfEnumAndVarRedeclarations.errors.txt index d97d33b010334..d7410ec04cb50 100644 --- a/tests/baselines/reference/typeOfEnumAndVarRedeclarations.errors.txt +++ b/tests/baselines/reference/typeOfEnumAndVarRedeclarations.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts(10,41): error TS2375: Duplicate number index signature. +tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts(10,70): error TS2375: Duplicate number index signature. ==== tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts (1 errors) ==== @@ -9,8 +9,8 @@ tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts(10,41): error TS2375: Dup b = 1 } var x = E; - var x: { a: E; b: E;[x: number]: string; }; // Shouldnt error + var x: { readonly a: E; readonly b: E; readonly [x: number]: string; }; // Shouldnt error var y = E; - var y: { a: E; b: E;[x: number]: string;[x: number]: string } // two errors: the types are not identical and duplicate signatures - ~~~~~~~~~~~~~~~~~~~ + var y: { readonly a: E; readonly b: E; readonly [x: number]: string; readonly [x: number]: string } // two errors: the types are not identical and duplicate signatures + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2375: Duplicate number index signature. \ No newline at end of file diff --git a/tests/baselines/reference/typeOfEnumAndVarRedeclarations.js b/tests/baselines/reference/typeOfEnumAndVarRedeclarations.js index ce77eac85e62f..391c9c1679a97 100644 --- a/tests/baselines/reference/typeOfEnumAndVarRedeclarations.js +++ b/tests/baselines/reference/typeOfEnumAndVarRedeclarations.js @@ -6,9 +6,9 @@ enum E { b = 1 } var x = E; -var x: { a: E; b: E;[x: number]: string; }; // Shouldnt error +var x: { readonly a: E; readonly b: E; readonly [x: number]: string; }; // Shouldnt error var y = E; -var y: { a: E; b: E;[x: number]: string;[x: number]: string } // two errors: the types are not identical and duplicate signatures +var y: { readonly a: E; readonly b: E; readonly [x: number]: string; readonly [x: number]: string } // two errors: the types are not identical and duplicate signatures //// [typeOfEnumAndVarRedeclarations.js] var E; diff --git a/tests/baselines/reference/validNullAssignments.errors.txt b/tests/baselines/reference/validNullAssignments.errors.txt index 042a7172b5204..057d6ce479198 100644 --- a/tests/baselines/reference/validNullAssignments.errors.txt +++ b/tests/baselines/reference/validNullAssignments.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/types/primitives/null/validNullAssignments.ts(10,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/conformance/types/primitives/null/validNullAssignments.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. tests/cases/conformance/types/primitives/null/validNullAssignments.ts(15,1): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/types/primitives/null/validNullAssignments.ts(20,1): error TS2304: Cannot find name 'I'. tests/cases/conformance/types/primitives/null/validNullAssignments.ts(23,1): error TS2364: Invalid left-hand side of assignment expression. @@ -17,7 +17,7 @@ tests/cases/conformance/types/primitives/null/validNullAssignments.ts(30,1): err enum E { A } E.A = null; // error ~~~ -!!! error TS2364: Invalid left-hand side of assignment expression. +!!! error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. class C { foo: string } var f: C; diff --git a/tests/cases/compiler/augmentExportEquals1.ts b/tests/cases/compiler/augmentExportEquals1.ts new file mode 100644 index 0000000000000..4479fd063b962 --- /dev/null +++ b/tests/cases/compiler/augmentExportEquals1.ts @@ -0,0 +1,19 @@ +// @module: amd +// @filename: file1.ts +var x = 1; +export = x; + +// @filename: file2.ts + +import x = require("./file1"); + +// augmentation for './file1' +// should error since './file1' does not have namespace meaning +declare module "./file1" { + interface A { a } +} + +// @filename: file3.ts +import x = require("./file1"); +import "./file2"; +let a: x.A; // should not work \ No newline at end of file diff --git a/tests/cases/compiler/augmentExportEquals1_1.ts b/tests/cases/compiler/augmentExportEquals1_1.ts new file mode 100644 index 0000000000000..6afc6e70910ba --- /dev/null +++ b/tests/cases/compiler/augmentExportEquals1_1.ts @@ -0,0 +1,22 @@ +// @module: amd + +// @filename: file1.d.ts +declare module "file1" { + var x: number; + export = x; +} + +// @filename: file2.ts +/// +import x = require("file1"); + +// augmentation for 'file1' +// should error since 'file1' does not have namespace meaning +declare module "file1" { + interface A { a } +} + +// @filename: file3.ts +import x = require("file1"); +import "file2"; +let a: x.A; // should not work \ No newline at end of file diff --git a/tests/cases/compiler/augmentExportEquals2.ts b/tests/cases/compiler/augmentExportEquals2.ts new file mode 100644 index 0000000000000..1d4c1fae35c61 --- /dev/null +++ b/tests/cases/compiler/augmentExportEquals2.ts @@ -0,0 +1,19 @@ +// @module: amd + +// @filename: file1.ts +function foo() {} +export = foo; + +// @filename: file2.ts +import x = require("./file1"); + +// should error since './file1' does not have namespace meaning +declare module "./file1" { + interface A { a } +} + +// @filename: file3.ts +// @filename: file3.ts +import x = require("./file1"); +import "./file2"; +let a: x.A; // should not work \ No newline at end of file diff --git a/tests/cases/compiler/augmentExportEquals2_1.ts b/tests/cases/compiler/augmentExportEquals2_1.ts new file mode 100644 index 0000000000000..b6aeb21efd051 --- /dev/null +++ b/tests/cases/compiler/augmentExportEquals2_1.ts @@ -0,0 +1,22 @@ +// @module: amd + +// @filename: file1.d.ts +declare module "file1" { + function foo(): void; + export = foo; +} + +// @filename: file2.ts + +/// +import x = require("file1"); + +// should error since './file1' does not have namespace meaning +declare module "file1" { + interface A { a } +} + +// @filename: file3.ts +import x = require("file1"); +import "file2"; +let a: x.A; // should not work \ No newline at end of file diff --git a/tests/cases/compiler/augmentExportEquals3.ts b/tests/cases/compiler/augmentExportEquals3.ts new file mode 100644 index 0000000000000..81a0e1d5448f2 --- /dev/null +++ b/tests/cases/compiler/augmentExportEquals3.ts @@ -0,0 +1,24 @@ +// @module: amd + +// @filename: file1.ts +function foo() {} +namespace foo { + export var v = 1; +} +export = foo; + +// @filename: file2.ts +import x = require("./file1"); +x.b = 1; + +// OK - './file1' is a namespace +declare module "./file1" { + interface A { a } + let b: number; +} + +// @filename: file3.ts +import * as x from "./file1"; +import "./file2"; +let a: x.A; +let b = x.b; \ No newline at end of file diff --git a/tests/cases/compiler/augmentExportEquals3_1.ts b/tests/cases/compiler/augmentExportEquals3_1.ts new file mode 100644 index 0000000000000..ad329643fa57c --- /dev/null +++ b/tests/cases/compiler/augmentExportEquals3_1.ts @@ -0,0 +1,27 @@ +// @module: amd +// @filename: file1.d.ts +declare module "file1" { + function foo(): void; + namespace foo { + export var v: number; + } + export = foo; +} + + +// @filename: file2.ts +/// +import x = require("file1"); +x.b = 1; + +// OK - './file1' is a namespace +declare module "file1" { + interface A { a } + let b: number; +} + +// @filename: file3.ts +import * as x from "file1"; +import "file2"; +let a: x.A; +let b = x.b; \ No newline at end of file diff --git a/tests/cases/compiler/augmentExportEquals4.ts b/tests/cases/compiler/augmentExportEquals4.ts new file mode 100644 index 0000000000000..85294682f5cc8 --- /dev/null +++ b/tests/cases/compiler/augmentExportEquals4.ts @@ -0,0 +1,24 @@ +// @module: amd + +// @filename: file1.ts +class foo {} +namespace foo { + export var v = 1; +} +export = foo; + +// @filename: file2.ts +import x = require("./file1"); +x.b = 1; + +// OK - './file1' is a namespace +declare module "./file1" { + interface A { a } + let b: number; +} + +// @filename: file3.ts +import * as x from "./file1"; +import "./file2"; +let a: x.A; +let b = x.b; \ No newline at end of file diff --git a/tests/cases/compiler/augmentExportEquals4_1.ts b/tests/cases/compiler/augmentExportEquals4_1.ts new file mode 100644 index 0000000000000..467d0af38ef39 --- /dev/null +++ b/tests/cases/compiler/augmentExportEquals4_1.ts @@ -0,0 +1,28 @@ +// @module: amd + +// @filename: file1.d.ts +declare module "file1" { + class foo {} + namespace foo { + export var v: number; + } + export = foo; +} + + +// @filename: file2.ts +/// +import x = require("file1"); +x.b = 1; + +// OK - './file1' is a namespace +declare module "file1" { + interface A { a } + let b: number; +} + +// @filename: file3.ts +import * as x from "file1"; +import "file2"; +let a: x.A; +let b = x.b; \ No newline at end of file diff --git a/tests/cases/compiler/augmentExportEquals5.ts b/tests/cases/compiler/augmentExportEquals5.ts new file mode 100644 index 0000000000000..3250a40f131ed --- /dev/null +++ b/tests/cases/compiler/augmentExportEquals5.ts @@ -0,0 +1,82 @@ +// @module: amd + +// @filename: express.d.ts + +declare module Express { + export interface Request { } + export interface Response { } + export interface Application { } +} + +declare module "express" { + function e(): e.Express; + namespace e { + interface IRoute { + all(...handler: RequestHandler[]): IRoute; + } + + interface IRouterMatcher { + (name: string|RegExp, ...handlers: RequestHandler[]): T; + } + + interface IRouter extends RequestHandler { + route(path: string): IRoute; + } + + export function Router(options?: any): Router; + + export interface Router extends IRouter {} + + interface Errback { (err: Error): void; } + + interface Request extends Express.Request { + + get (name: string): string; + } + + interface Response extends Express.Response { + charset: string; + } + + interface ErrorRequestHandler { + (err: any, req: Request, res: Response, next: Function): any; + } + + interface RequestHandler { + (req: Request, res: Response, next: Function): any; + } + + interface Handler extends RequestHandler {} + + interface RequestParamHandler { + (req: Request, res: Response, next: Function, param: any): any; + } + + interface Application extends IRouter, Express.Application { + routes: any; + } + + interface Express extends Application { + createApplication(): Application; + } + + var static: any; + } + + export = e; +} + +// @filename: augmentation.ts +/// +import * as e from "express"; +declare module "express" { + interface Request { + id: number; + } +} + +// @filename: consumer.ts +import { Request } from "express"; +import "./augmentation"; +let x: Request; +const y = x.id; \ No newline at end of file diff --git a/tests/cases/compiler/augmentExportEquals6.ts b/tests/cases/compiler/augmentExportEquals6.ts new file mode 100644 index 0000000000000..a0dd50c53f0fd --- /dev/null +++ b/tests/cases/compiler/augmentExportEquals6.ts @@ -0,0 +1,28 @@ +// @module: amd + +// @filename: file1.ts +class foo {} +namespace foo { + export class A {} + export namespace B { export let a; } +} +export = foo; + +// @filename: file2.ts +import x = require("./file1"); +x.B.b = 1; + +// OK - './file1' is a namespace +declare module "./file1" { + interface A { a: number } + namespace B { + export let b: number; + } +} + +// @filename: file3.ts +import * as x from "./file1"; +import "./file2"; +let a: x.A; +let b = a.a; +let c = x.B.b; \ No newline at end of file diff --git a/tests/cases/compiler/augmentExportEquals6_1.ts b/tests/cases/compiler/augmentExportEquals6_1.ts new file mode 100644 index 0000000000000..aaee43bae746f --- /dev/null +++ b/tests/cases/compiler/augmentExportEquals6_1.ts @@ -0,0 +1,26 @@ +// @module: amd + +// @filename: file1.d.ts +declare module "file1" { + class foo {} + namespace foo { + class A {} + } + export = foo; +} + + +// @filename: file2.ts +/// +import x = require("file1"); + +// OK - './file1' is a namespace +declare module "file1" { + interface A { a: number } +} + +// @filename: file3.ts +import * as x from "file1"; +import "file2"; +let a: x.A; +let b = a.a; \ No newline at end of file diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing1.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing1.ts new file mode 100644 index 0000000000000..e8dd78ef54651 --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing1.ts @@ -0,0 +1,10 @@ +class Based { } +class Derived extends Based { + public x: number; + constructor() { + super(); + this; + this.x = 10; + var that = this; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts new file mode 100644 index 0000000000000..e6545f242889c --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts @@ -0,0 +1,10 @@ +class Based { } +class Derived extends Based { + public x: number; + constructor() { + this.x = 100; + super(); + this.x = 10; + var that = this; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing3.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing3.ts new file mode 100644 index 0000000000000..fd9de120b057a --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing3.ts @@ -0,0 +1,15 @@ +class Based { } +class Derived extends Based { + public x: number; + constructor() { + class innver { + public y: boolean; + constructor() { + this.y = true; + } + } + super(); + this.x = 10; + var that = this; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing4.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing4.ts new file mode 100644 index 0000000000000..1fdee00c2f861 --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing4.ts @@ -0,0 +1,19 @@ +class Based { } +class Derived extends Based { + public x: number; + constructor() { + (() => { + this; // No error + }); + () => { + this; // No error + }; + (() => { + this; // No error + })(); + super(); + super(); + this.x = 10; + var that = this; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts new file mode 100644 index 0000000000000..65d1db6df7522 --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts @@ -0,0 +1,7 @@ +class Based { constructor(...arg) { } } +class Derived extends Based { + public x: number; + constructor() { + super(this.x); + } +} \ No newline at end of file diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing6.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing6.ts new file mode 100644 index 0000000000000..2cdcb9ad3a810 --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing6.ts @@ -0,0 +1,10 @@ +class Base { + constructor(...arg) { + } +} +class Super extends Base { + constructor() { + (() => this); // No Error + super(); + } +} \ No newline at end of file diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing7.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing7.ts new file mode 100644 index 0000000000000..1c4af98f0a294 --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing7.ts @@ -0,0 +1,9 @@ +class Base { + constructor(func: ()=>Base) { + } +} +class Super extends Base { + constructor() { + super((() => this)); // No error + } +} \ No newline at end of file diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts new file mode 100644 index 0000000000000..230b40fc24df6 --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts @@ -0,0 +1,10 @@ +class Base { + constructor(...arg) { + } +} +class Super extends Base { + constructor() { + var that = this; + super(); + } +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationMerging1.ts b/tests/cases/compiler/declarationMerging1.ts new file mode 100644 index 0000000000000..256cacf4a524b --- /dev/null +++ b/tests/cases/compiler/declarationMerging1.ts @@ -0,0 +1,10 @@ +// @filename: file1.ts +class A { + protected _f: number; + getF() { return this._f; } +} + +// @filename: file2.ts +interface A { + run(); +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationMerging2.ts b/tests/cases/compiler/declarationMerging2.ts new file mode 100644 index 0000000000000..6be5f4d0e4d91 --- /dev/null +++ b/tests/cases/compiler/declarationMerging2.ts @@ -0,0 +1,15 @@ +// @module: amd + +// @filename: a.ts +export class A { + protected _f: number; + getF() { return this._f; } +} + +// @filename: b.ts +export {} +declare module "./a" { + interface A { + run(); + } +} \ No newline at end of file diff --git a/tests/cases/compiler/deduplicateImportsInSystem.ts b/tests/cases/compiler/deduplicateImportsInSystem.ts new file mode 100644 index 0000000000000..2fcbc16be05b4 --- /dev/null +++ b/tests/cases/compiler/deduplicateImportsInSystem.ts @@ -0,0 +1,9 @@ +// @module: system +import {A} from "f1"; +import {B} from "f2"; +import {C} from "f3"; +import {D} from 'f2'; +import {E} from "f2"; +import {F} from 'f1'; + +console.log(A + B + C + D + E + F) \ No newline at end of file diff --git a/tests/cases/compiler/dottedNamesInSystem.ts b/tests/cases/compiler/dottedNamesInSystem.ts new file mode 100644 index 0000000000000..43b8eb233b943 --- /dev/null +++ b/tests/cases/compiler/dottedNamesInSystem.ts @@ -0,0 +1,8 @@ +// @module: system +export namespace A.B.C { + export function foo() {} +} + +export function bar() { + return A.B.C.foo(); +} \ No newline at end of file diff --git a/tests/cases/compiler/dynamicRequire.ts b/tests/cases/compiler/dynamicRequire.ts new file mode 100644 index 0000000000000..8d72a37dceb18 --- /dev/null +++ b/tests/cases/compiler/dynamicRequire.ts @@ -0,0 +1,8 @@ +// @allowJs: true +// @module: amd +// @out: a_out.js + +// @filename: a.js +function foo(name) { + var s = require("t/" + name) +} \ No newline at end of file diff --git a/tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts b/tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts index fde615af41db5..582940038c5e5 100644 --- a/tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts +++ b/tests/cases/compiler/functionsMissingReturnStatementsAndExpressions.ts @@ -92,6 +92,17 @@ function f18() { return "Okay, not type annotated."; } +function f19(): void | number { + // Okay; function return type is union containing void +} + +function f20(): any | number { + // Okay; function return type is union containing any +} + +function f21(): number | string { + // Not okay; union does not contain void or any +} class C { public get m1() { diff --git a/tests/cases/compiler/mergedDeclarations5.ts b/tests/cases/compiler/mergedDeclarations5.ts new file mode 100644 index 0000000000000..df5734453d3a5 --- /dev/null +++ b/tests/cases/compiler/mergedDeclarations5.ts @@ -0,0 +1,10 @@ +// @filename: a.ts +class A { + protected foo() {} +} +// @filename: b.ts +interface A { } + +class B extends A { + protected foo() {} +} \ No newline at end of file diff --git a/tests/cases/compiler/mergedDeclarations6.ts b/tests/cases/compiler/mergedDeclarations6.ts new file mode 100644 index 0000000000000..406bed518c111 --- /dev/null +++ b/tests/cases/compiler/mergedDeclarations6.ts @@ -0,0 +1,23 @@ +// @module: amd + +// @filename: a.ts +export class A { + protected protected: any; + + protected setProtected(val: any) { + this.protected = val; + } +} + +// @filename: b.ts +import {A} from './a'; + +declare module "./a" { + interface A { } +} + +export class B extends A { + protected setProtected() { + + } +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings1.ts b/tests/cases/compiler/nestedBlockScopedBindings1.ts new file mode 100644 index 0000000000000..9fd580044a586 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings1.ts @@ -0,0 +1,49 @@ +function a0() { + { + let x = 1; + } + { + let x = 1; + } +} + +function a1() { + { + let x; + } + { + let x = 1; + } +} + +function a2() { + { + let x = 1; + } + { + let x; + } +} + +function a3() { + { + let x = 1; + } + switch (1) { + case 1: + let x; + break; + } +} + + +function a4() { + { + let x; + } + switch (1) { + case 1: + let x = 1; + break; + } +} diff --git a/tests/cases/compiler/nestedBlockScopedBindings10.ts b/tests/cases/compiler/nestedBlockScopedBindings10.ts new file mode 100644 index 0000000000000..5b3e5ad34a659 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings10.ts @@ -0,0 +1,11 @@ +{ + let x; + x = 1; +} + +switch (1) { + case 1: + let y; + y = 1; + break; +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings11.ts b/tests/cases/compiler/nestedBlockScopedBindings11.ts new file mode 100644 index 0000000000000..5d3e527eaf0a1 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings11.ts @@ -0,0 +1,13 @@ +var x; +{ + let x; + () => x; +} + +var y; +switch (1) { + case 1: + let y; + () => y; + break; +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings12.ts b/tests/cases/compiler/nestedBlockScopedBindings12.ts new file mode 100644 index 0000000000000..05aa00c1b5b12 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings12.ts @@ -0,0 +1,13 @@ +var x; +{ + let x; + x = 1; +} + +var y; +switch (1) { + case 1: + let y; + y = 1; + break; +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings13.ts b/tests/cases/compiler/nestedBlockScopedBindings13.ts new file mode 100644 index 0000000000000..6cb1133a9f681 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings13.ts @@ -0,0 +1,9 @@ +for (; false;) { + let x; + () => x; +} + +for (; false;) { + let y; + y = 1; +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings14.ts b/tests/cases/compiler/nestedBlockScopedBindings14.ts new file mode 100644 index 0000000000000..879551a041aa3 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings14.ts @@ -0,0 +1,11 @@ +var x; +for (; false;) { + let x; + () => x; +} + +var y; +for (; false;) { + let y; + y = 1; +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings15.ts b/tests/cases/compiler/nestedBlockScopedBindings15.ts new file mode 100644 index 0000000000000..703494e0949bd --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings15.ts @@ -0,0 +1,31 @@ +for (; false;) { + { + let x; + () => x; + } +} + +for (; false;) { + { + let y; + y = 1; + } +} + +for (; false;) { + switch (1){ + case 1: + let z0; + () => z0; + break; + } +} + +for (; false;) { + switch (1){ + case 1: + let z; + z = 1; + break; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings16.ts b/tests/cases/compiler/nestedBlockScopedBindings16.ts new file mode 100644 index 0000000000000..c85a942110282 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings16.ts @@ -0,0 +1,35 @@ +var x; +for (; false;) { + { + let x; + () => x; + } +} + +var y; +for (; false;) { + { + let y; + y = 1; + } +} + +var z0; +for (; false;) { + switch (1){ + case 1: + let z0; + () => z0; + break; + } +} + +var z; +for (; false;) { + switch (1){ + case 1: + let z; + z = 1; + break; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings2.ts b/tests/cases/compiler/nestedBlockScopedBindings2.ts new file mode 100644 index 0000000000000..694f27d1a247b --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings2.ts @@ -0,0 +1,126 @@ +function a0() { + { + let x = 1; + () => x; + } + { + let x = 1; + } +} + +function a1() { + { + let x; + } + { + let x = 1; + () => x; + } +} + +function a2() { + { + let x = 1; + () => x; + } + { + let x; + () => x; + } +} + + +function a3() { + { + let x = 1; + () => x; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + + +function a4() { + { + let x; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + + +function a5() { + { + let x; + () => x; + } + switch (1) { + case 1: + let x; + break; + } +} + +function a6() { + switch (1) { + case 1: + let x; + break; + } + switch (1) { + case 1: + let x; + break; + } +} + +function a7() { + switch (1) { + case 1: + let x; + () => x; + break; + } + switch (1) { + case 1: + let x; + break; + } +} + +function a8() { + switch (1) { + case 1: + let x; + break; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + +function a9() { + switch (1) { + case 1: + let x; + () => x; + break; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} diff --git a/tests/cases/compiler/nestedBlockScopedBindings3.ts b/tests/cases/compiler/nestedBlockScopedBindings3.ts new file mode 100644 index 0000000000000..e073bebadb963 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings3.ts @@ -0,0 +1,68 @@ +function a0() { + { + for (let x = 0; x < 1; ) { + () => x; + } + } + { + for (let x;;) { + () => x; + } + } +} + +function a1() { + for (let x; x < 1;) { + () => x; + } + for (let x;;) { + () => x; + } +} + +function a2() { + for (let x; x < 1;) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + } +} + + +function a3() { + for (let x; x < 1;) { + x = x + 1; + } + switch (1) { + case 1: + let x; + break; + } +} + +function a4() { + for (let x; x < 1;) { + x = x + 1; + () => x; + } + switch (1) { + case 1: + let x; + break; + } +} + + +function a5() { + for (let x; x < 1;) { + x = x + 1; + () => x; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings4.ts b/tests/cases/compiler/nestedBlockScopedBindings4.ts new file mode 100644 index 0000000000000..33ad21e2c429d --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings4.ts @@ -0,0 +1,40 @@ +function a0() { + for (let x; x < 1;) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + } +} + +function a1() { + for (let x; x < 1;) { + x = x + 1; + () => x; + } + for (let x;;) { + x = x + 2; + } +} + +function a2() { + for (let x; x < 1;) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + () => x; + } +} + + +function a3() { + for (let x; x < 1;) { + x = x + 1; + () => x; + } + for (let x;;) { + x = x + 2; + () => x; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings5.ts b/tests/cases/compiler/nestedBlockScopedBindings5.ts new file mode 100644 index 0000000000000..65093bcc91fd4 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings5.ts @@ -0,0 +1,80 @@ +function a0() { + for (let x in []) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + } +} + +function a1() { + for (let x in []) { + x = x + 1; + () => x; + } + for (let x;;) { + x = x + 2; + } +} + +function a2() { + for (let x in []) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + () => x; + } +} + + +function a3() { + for (let x in []) { + x = x + 1; + () => x; + } + for (let x;false;) { + x = x + 2; + () => x; + } + switch (1) { + case 1: + let x; + () => x; + break; + } + +} + +function a4() { + for (let x in []) { + x = x + 1; + } + for (let x;false;) { + x = x + 2; + } + switch (1) { + case 1: + let x; + () => x; + break; + } + +} + +function a5() { + let y; + for (let x in []) { + x = x + 1; + } + for (let x;false;) { + x = x + 2; + () => x; + } + switch (1) { + case 1: + let x; + break; + } + +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings6.ts b/tests/cases/compiler/nestedBlockScopedBindings6.ts new file mode 100644 index 0000000000000..badf1db6e59ae --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings6.ts @@ -0,0 +1,88 @@ +function a0() { + for (let x of [1]) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + } +} + +function a1() { + for (let x of [1]) { + x = x + 1; + () => x; + } + for (let x;;) { + x = x + 2; + } +} + +function a2() { + for (let x of [1]) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + () => x; + } +} + +function a3() { + for (let x of [1]) { + x = x + 1; + () => x; + } + for (let x;;) { + x = x + 2; + () => x; + } +} + +function a4() { + for (let x of [1]) { + x = x + 1; + () => x; + } + switch (1) { + case 1: + let x; + break; + } +} + + +function a5() { + for (let x of [1]) { + x = x + 1; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + +function a6() { + for (let x of [1]) { + x = x + 1; + } + switch (1) { + case 1: + let x; + break; + } +} + +function a7() { + for (let x of [1]) { + x = x + 1; + () => x; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings7.ts b/tests/cases/compiler/nestedBlockScopedBindings7.ts new file mode 100644 index 0000000000000..67da827305b31 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings7.ts @@ -0,0 +1,7 @@ +for (let x; false;) { + () => x; +} + +for (let y; false;) { + y = 1; +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings8.ts b/tests/cases/compiler/nestedBlockScopedBindings8.ts new file mode 100644 index 0000000000000..14e33615dc208 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings8.ts @@ -0,0 +1,9 @@ +var x; +for (let x; false; ) { + () => x; +} + +var y; +for (let y; false; ) { + y = 1; +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings9.ts b/tests/cases/compiler/nestedBlockScopedBindings9.ts new file mode 100644 index 0000000000000..d7d749dcf7cd9 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings9.ts @@ -0,0 +1,11 @@ +{ + let x; + () => x; +} + +switch (1) { + case 1: + let y; + () => y; + break; +} \ No newline at end of file diff --git a/tests/cases/compiler/noErrorOnEmptyDts.ts b/tests/cases/compiler/noErrorOnEmptyDts.ts new file mode 100644 index 0000000000000..1266ea2bd753b --- /dev/null +++ b/tests/cases/compiler/noErrorOnEmptyDts.ts @@ -0,0 +1,8 @@ +// @module: commonjs + +// @filename: c:/node_modules/test.d.ts + +// comment + +// @filename: c:/app/main.ts +import "test" \ No newline at end of file diff --git a/tests/cases/compiler/overloadOnConstAsTypeAnnotation.ts b/tests/cases/compiler/overloadOnConstAsTypeAnnotation.ts index 12b99fb29ceae..4188d6919a70f 100644 --- a/tests/cases/compiler/overloadOnConstAsTypeAnnotation.ts +++ b/tests/cases/compiler/overloadOnConstAsTypeAnnotation.ts @@ -1,3 +1,3 @@ // @allowUnreachableCode: true -var f: (x: 'hi') => number = ('hi') => { return 1; }; \ No newline at end of file +var f: (x: 'hi') => number = (x: 'hi') => { return 1; }; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution1_classic.ts b/tests/cases/compiler/pathMappingBasedModuleResolution1_classic.ts new file mode 100644 index 0000000000000..20845a49372ab --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution1_classic.ts @@ -0,0 +1,19 @@ +// @module: amd +// @traceModuleResolution: true + +// paths should error in the absence of baseurl + +// @filename: c:/root/tsconfig.json +{ + "compilerOptions": { + "paths": { + "*": [ + "*", + "generated/*" + ] + } + } +} + +// @filename: c:/root/f1.ts +export var x = 1; diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution1_node.ts b/tests/cases/compiler/pathMappingBasedModuleResolution1_node.ts new file mode 100644 index 0000000000000..392e85bd7c39c --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution1_node.ts @@ -0,0 +1,18 @@ +// @module: commonjs +// @traceModuleResolution: true + +// paths should error in the absence of baseurl +// @filename: c:/root/tsconfig.json +{ + "compilerOptions": { + "paths": { + "*": [ + "*", + "generated/*" + ] + } + } +} + +// @filename: c:/root/f1.ts +export var x = 1; diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution2_classic.ts b/tests/cases/compiler/pathMappingBasedModuleResolution2_classic.ts new file mode 100644 index 0000000000000..6c84a197eeb13 --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution2_classic.ts @@ -0,0 +1,18 @@ +// @module: amd +// @traceModuleResolution: true + +// baseurl is defined in tsconfig.json +// paths has errors + +// @filename: root/tsconfig.json +{ + "compilerOptions": { + "baseUrl": "./src", + "paths": { + "*1*": [ "*2*" ] + } + } +} + +// @filename: root/src/folder1/file1.ts +export var x = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution2_node.ts b/tests/cases/compiler/pathMappingBasedModuleResolution2_node.ts new file mode 100644 index 0000000000000..78ef7215e737e --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution2_node.ts @@ -0,0 +1,18 @@ +// @module: commonjs +// @traceModuleResolution: true + +// baseurl is defined in tsconfig.json +// paths has errors + +// @filename: root/tsconfig.json +{ + "compilerOptions": { + "baseUrl": "./src", + "paths": { + "*1*": [ "*2*" ] + } + } +} + +// @filename: root/src/folder1/file1.ts +export var x = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution3_classic.ts b/tests/cases/compiler/pathMappingBasedModuleResolution3_classic.ts new file mode 100644 index 0000000000000..d46308d089fb0 --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution3_classic.ts @@ -0,0 +1,22 @@ +// @moduleResolution: classic +// @module: amd +// @baseUrl: c:/root +// @traceModuleResolution: true + +// baseUrl set via command line + +// @filename: c:/root/folder1/file1.ts +import {x} from "folder2/file2" +declare function use(a: any): void; +use(x.toExponential()); + +// @filename: c:/root/folder2/file2.ts +import {x as a} from "./file3" // found with baseurl +import {y as b} from "file4" // found with fallback +export var x = a + b; + +// @filename: c:/root/folder2/file3.ts +export var x = 1; + +// @filename: c:/file4.ts +export var y = 100; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution3_node.ts b/tests/cases/compiler/pathMappingBasedModuleResolution3_node.ts new file mode 100644 index 0000000000000..30e95c9303ee6 --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution3_node.ts @@ -0,0 +1,22 @@ +// @moduleResolution: node +// @module: commonjs +// @baseUrl: c:/root +// @traceModuleResolution: true + +// baseUrl set via command line + +// @filename: c:/root/folder1/file1.ts +import {x} from "folder2/file2" +declare function use(a: any): void; +use(x.toExponential()); + +// @filename: c:/root/folder2/file2.ts +import {x as a} from "./file3" // found with baseurl +import {y as b} from "file4" // found with fallback +export var x = a + b; + +// @filename: c:/root/folder2/file3.ts +export var x = 1; + +// @filename: c:/node_modules/file4/index.d.ts +export var y: number; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution4_classic.ts b/tests/cases/compiler/pathMappingBasedModuleResolution4_classic.ts new file mode 100644 index 0000000000000..723de05b70c14 --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution4_classic.ts @@ -0,0 +1,28 @@ +// @moduleResolution: classic +// @module: amd +// @traceModuleResolution: true + +// baseUrl set via command line + +// @filename: c:/root/tsconfig.json +{ + "compilerOptions": { + "baseUrl": "." + } +} + +// @filename: c:/root/folder1/file1.ts +import {x} from "folder2/file2" +declare function use(a: any): void; +use(x.toExponential()); + +// @filename: c:/root/folder2/file2.ts +import {x as a} from "./file3" // found with baseurl +import {y as b} from "file4" // found with fallback +export var x = a + b; + +// @filename: c:/root/folder2/file3.ts +export var x = 1; + +// @filename: c:/file4.ts +export var y = 100; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution4_node.ts b/tests/cases/compiler/pathMappingBasedModuleResolution4_node.ts new file mode 100644 index 0000000000000..e68635e205e57 --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution4_node.ts @@ -0,0 +1,28 @@ +// @moduleResolution: node +// @module: commonjs +// @traceModuleResolution: true + +// baseUrl set via command line + +// @filename: c:/root/tsconfig.json +{ + "compilerOptions": { + "baseUrl": "." + } +} + +// @filename: c:/root/folder1/file1.ts +import {x} from "folder2/file2" +declare function use(a: any): void; +use(x.toExponential()); + +// @filename: c:/root/folder2/file2.ts +import {x as a} from "./file3" // found with baseurl +import {y as b} from "file4" // found with fallback +export var x = a + b; + +// @filename: c:/root/folder2/file3.ts +export var x = 1; + +// @filename: c:/node_modules/file4/index.d.ts +export var y: number; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution5_classic.ts b/tests/cases/compiler/pathMappingBasedModuleResolution5_classic.ts new file mode 100644 index 0000000000000..a7662688e373a --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution5_classic.ts @@ -0,0 +1,43 @@ +// @module: amd +// @traceModuleResolution: true + +// paths is defined in tsconfig.json +// @filename: c:/root/tsconfig.json +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "*": [ + "*", + "generated/*" + ], + "components/*": [ + "shared/components/*" + ] + } + } +} +// @filename: c:/root/folder1/file1.ts +import {x} from "folder2/file1" +import {y} from "folder3/file2" +import {z} from "components/file3" +import {z1} from "file4" + +declare function use(a: any): void; + +use(x.toExponential()); +use(y.toExponential()); +use(z.toExponential()); +use(z1.toExponential()); + +// @filename: c:/root/folder2/file1.ts +export var x = 1; + +// @filename: c:/root/generated/folder3/file2.ts +export var y = 1; + +// @filename: c:/root/shared/components/file3.ts +export var z = 1; + +// @filename: c:/file4.ts +export var z1 = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution5_node.ts b/tests/cases/compiler/pathMappingBasedModuleResolution5_node.ts new file mode 100644 index 0000000000000..ef5ef0afd6a52 --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution5_node.ts @@ -0,0 +1,43 @@ +// @module: commonjs +// @traceModuleResolution: true + +// paths is defined in tsconfig.json +// @filename: c:/root/tsconfig.json +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "*": [ + "*", + "generated/*" + ], + "components/*": [ + "shared/components/*" + ] + } + } +} +// @filename: c:/root/folder1/file1.ts +import {x} from "folder2/file1" +import {y} from "folder3/file2" +import {z} from "components/file3" +import {z1} from "file4" + +declare function use(a: any): void; + +use(x.toExponential()); +use(y.toExponential()); +use(z.toExponential()); +use(z1.toExponential()); + +// @filename: c:/root/folder2/file1.ts +export var x = 1; + +// @filename: c:/root/generated/folder3/file2.ts +export var y = 1; + +// @filename: c:/root/shared/components/file3/index.d.ts +export var z: number; + +// @filename: c:/node_modules/file4.ts +export var z1 = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution6_classic.ts b/tests/cases/compiler/pathMappingBasedModuleResolution6_classic.ts new file mode 100644 index 0000000000000..adaba8478c997 --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution6_classic.ts @@ -0,0 +1,23 @@ +// @module: amd +// @traceModuleResolution: true + +// @filename: c:/root/src/tsconfig.json +{ + "compilerOptions": { + "rootDirs": [ + ".", + "../generated/src" + ] + } +} + +// @filename: c:/root/src/file1.ts +import {x} from "./project/file3"; +declare function use(x: string); +use(x.toExponential()); + +// @filename: c:/root/src/file2.d.ts +export let x: number; + +// @filename: c:/root/generated/src/project/file3.ts +export {x} from "../file2"; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution6_node.ts b/tests/cases/compiler/pathMappingBasedModuleResolution6_node.ts new file mode 100644 index 0000000000000..a3d0feadf7c9e --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution6_node.ts @@ -0,0 +1,23 @@ +// @module: commonjs +// @traceModuleResolution: true + +// @filename: c:/root/src/tsconfig.json +{ + "compilerOptions": { + "rootDirs": [ + ".", + "../generated/src" + ] + } +} + +// @filename: c:/root/src/file1.ts +import {x} from "./project/file3"; +declare function use(x: string); +use(x.toFixed()); + +// @filename: c:/root/src/file2/index.d.ts +export let x: number; + +// @filename: c:/root/generated/src/project/file3.ts +export {x} from "../file2"; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution7_classic.ts b/tests/cases/compiler/pathMappingBasedModuleResolution7_classic.ts new file mode 100644 index 0000000000000..af092df5ce95f --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution7_classic.ts @@ -0,0 +1,49 @@ +// @module: amd +// @traceModuleResolution: true + +// @filename: c:/root/src/tsconfig.json +{ + "compilerOptions": { + "baseUrl": "../", + "paths": { + "*": [ + "*", + "c:/shared/*" + ], + "templates/*": [ + "generated/src/templates/*" + ] + }, + "rootDirs": [ + ".", + "../generated/src" + ] + } +} + +// @filename: c:/root/src/file1.ts +import {x} from "./project/file2"; +import {y} from "module3"; + +declare function use(x: string); +use(x.toFixed()); +use(y.toFixed()); + +// @filename: c:/root/generated/src/project/file2.ts +import {a} from "module1"; +import {b} from "templates/module2"; +import {x as c} from "../file3"; +export let x = a + b + c; + +// @filename: c:/shared/module1.d.ts +export let a: number + +// @filename: c:/root/generated/src/templates/module2.ts +export let b: number; + +// @filename: c:/root/src/file3.d.ts +export let x: number; + +// @filename: c:/module3.d.ts +export let y: number; + diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution7_node.ts b/tests/cases/compiler/pathMappingBasedModuleResolution7_node.ts new file mode 100644 index 0000000000000..faecbe4adb91e --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution7_node.ts @@ -0,0 +1,49 @@ +// @module: commonjs +// @traceModuleResolution: true + +// @filename: c:/root/src/tsconfig.json +{ + "compilerOptions": { + "baseUrl": "../", + "paths": { + "*": [ + "*", + "c:/shared/*" + ], + "templates/*": [ + "generated/src/templates/*" + ] + }, + "rootDirs": [ + ".", + "../generated/src" + ] + } +} + +// @filename: c:/root/src/file1.ts +import {x} from "./project/file2"; +import {y} from "module3"; + +declare function use(x: string); +use(x.toFixed()); +use(y.toFixed()); + +// @filename: c:/root/generated/src/project/file2.ts +import {a} from "module1"; +import {b} from "templates/module2"; +import {x as c} from "../file3"; +export let x = a + b + c; + +// @filename: c:/shared/module1/index.d.ts +export let a: number + +// @filename: c:/root/generated/src/templates/module2.ts +export let b: number; + +// @filename: c:/root/src/file3/index.d.ts +export let x: number; + +// @filename: c:/node_modules/module3.d.ts +export let y: number; + diff --git a/tests/cases/compiler/readonlyInDeclarationFile.ts b/tests/cases/compiler/readonlyInDeclarationFile.ts new file mode 100644 index 0000000000000..03e643782f01e --- /dev/null +++ b/tests/cases/compiler/readonlyInDeclarationFile.ts @@ -0,0 +1,56 @@ +// @target: es5 +// @declaration: true + +interface Foo { + readonly x: number; + readonly [x: string]: Object; +} + +class C { + readonly [x: string]: Object; + private readonly a1: number; + protected readonly a2: number; + public readonly a3: number; + private get b1() { return 1 } + protected get b2() { return 1 } + public get b3() { return 1 } + private get c1() { return 1 } + private set c1(value) { } + protected get c2() { return 1 } + protected set c2(value) { } + public get c3() { return 1 } + public set c3(value) { } + private static readonly s1: number; + protected static readonly s2: number; + public static readonly s3: number; + private static get t1() { return 1 } + protected static get t2() { return 1 } + public static get t3() { return 1 } + private static get u1() { return 1 } + private static set u1(value) { } + protected static get u2() { return 1 } + protected static set u2(value) { } + public static get u3() { return 1 } + public static set u3(value) { } +} + +var z: { + readonly a: string; + readonly [x: string]: Object; +} + +function f() { + return { + get x() { return 1; }, + get y() { return 1; }, + set y(value) { } + } +} + +function g() { + var x: { + readonly a: string; + readonly [x: string]: Object; + } + return x; +} \ No newline at end of file diff --git a/tests/cases/compiler/readonlyMembers.ts b/tests/cases/compiler/readonlyMembers.ts new file mode 100644 index 0000000000000..f24b365772755 --- /dev/null +++ b/tests/cases/compiler/readonlyMembers.ts @@ -0,0 +1,67 @@ +// @target: es5 + +interface X { + readonly a: number; + readonly b?: number; +} +var x: X = { a: 0 }; +x.a = 1; // Error +x.b = 1; // Error + +class C { + readonly a: number; + readonly b = 1; + get c() { return 1 } + constructor() { + this.a = 1; // Ok + this.b = 1; // Ok + this.c = 1; // Error + const f = () => { + this.a = 1; // Error + this.b = 1; // Error + this.c = 1; // Error + } + } + foo() { + this.a = 1; // Error + this.b = 1; // Error + this.c = 1; // Error + } +} + +var o = { + get a() { return 1 }, + get b() { return 1 }, + set b(value) { } +}; +o.a = 1; // Error +o.b = 1; + +var p: { readonly a: number, b: number } = { a: 1, b: 1 }; +p.a = 1; // Error +p.b = 1; +var q: { a: number, b: number } = p; +q.a = 1; +q.b = 1; + +enum E { + A, B, C +} +E.A = 1; // Error + +namespace N { + export const a = 1; + export let b = 1; + export var c = 1; +} +N.a = 1; // Error +N.b = 1; +N.c = 1; + +let xx: { readonly [x: string]: string }; +let s = xx["foo"]; +xx["foo"] = "abc"; // Error + +let yy: { readonly [x: number]: string, [x: string]: string }; +yy[1] = "abc"; // Error +yy["foo"] = "abc"; \ No newline at end of file diff --git a/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.ts b/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.ts new file mode 100644 index 0000000000000..da41b8ca49ffd --- /dev/null +++ b/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.ts @@ -0,0 +1,3 @@ +// @sourcemap: true + +var [x] = [1, 2]; \ No newline at end of file diff --git a/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.ts b/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.ts new file mode 100644 index 0000000000000..8e9d05fadd556 --- /dev/null +++ b/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.ts @@ -0,0 +1,4 @@ +// @sourcemap: true + +var [x] = [1, 2]; +var [y, z] = [1, 2]; \ No newline at end of file diff --git a/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.ts b/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.ts new file mode 100644 index 0000000000000..6c3ea7bedd777 --- /dev/null +++ b/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern6.ts @@ -0,0 +1,3 @@ +// @sourcemap: true + +var [x = 20] = [1, 2]; \ No newline at end of file diff --git a/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.ts b/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.ts new file mode 100644 index 0000000000000..d9d91eb578b31 --- /dev/null +++ b/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern7.ts @@ -0,0 +1,3 @@ +// @sourcemap: true + +var [x = 20, j] = [1, 2]; \ No newline at end of file diff --git a/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.ts b/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.ts new file mode 100644 index 0000000000000..80adb1cf0c125 --- /dev/null +++ b/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern1.ts @@ -0,0 +1,3 @@ +// @sourcemap: true + +var {x} = { x: 20 }; \ No newline at end of file diff --git a/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.ts b/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.ts new file mode 100644 index 0000000000000..93465864cd623 --- /dev/null +++ b/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern2.ts @@ -0,0 +1,4 @@ +// @sourcemap: true + +var {x} = { x: 20 }; +var { a, b } = { a: 30, b: 40 }; \ No newline at end of file diff --git a/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.ts b/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.ts new file mode 100644 index 0000000000000..5af6b55272f92 --- /dev/null +++ b/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern3.ts @@ -0,0 +1,3 @@ +// @sourcemap: true + +var {x = 500} = { x: 20 }; \ No newline at end of file diff --git a/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.ts b/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.ts new file mode 100644 index 0000000000000..e0afcb60c27b6 --- /dev/null +++ b/tests/cases/compiler/sourceMapValidationDestructuringVariableStatementObjectBindingPattern4.ts @@ -0,0 +1,4 @@ +// @sourcemap: true + +var {x = 500, + y} = { x: 20, y: "hi" }; \ No newline at end of file diff --git a/tests/cases/compiler/thisInSuperCall.ts b/tests/cases/compiler/thisInSuperCall.ts index 6a54e9ac6f12e..b7df7cbafad74 100644 --- a/tests/cases/compiler/thisInSuperCall.ts +++ b/tests/cases/compiler/thisInSuperCall.ts @@ -4,7 +4,7 @@ class Base { class Foo extends Base { constructor() { - super(this); // no error + super(this); // error: "super" has to be called before "this" accessing } } diff --git a/tests/cases/compiler/thisInSuperCall2.ts b/tests/cases/compiler/thisInSuperCall2.ts index 5de7c34cf3252..2869ab9a80553 100644 --- a/tests/cases/compiler/thisInSuperCall2.ts +++ b/tests/cases/compiler/thisInSuperCall2.ts @@ -5,7 +5,7 @@ class Base { class Foo extends Base { public x: number; constructor() { - super(this); // no error + super(this); // error: "super" has to be called before "this" accessing } } diff --git a/tests/cases/compiler/thisTypeAsConstraint.ts b/tests/cases/compiler/thisTypeAsConstraint.ts new file mode 100644 index 0000000000000..fcab82bc7ccf2 --- /dev/null +++ b/tests/cases/compiler/thisTypeAsConstraint.ts @@ -0,0 +1,4 @@ +class C { + public m() { + } +} \ No newline at end of file diff --git a/tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts b/tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts index 996560385d847..2033ef743a4e1 100644 --- a/tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts +++ b/tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts @@ -5,6 +5,6 @@ enum E { b = 1 } var x = E; -var x: { a: E; b: E;[x: number]: string; }; // Shouldnt error +var x: { readonly a: E; readonly b: E; readonly [x: number]: string; }; // Shouldnt error var y = E; -var y: { a: E; b: E;[x: number]: string;[x: number]: string } // two errors: the types are not identical and duplicate signatures \ No newline at end of file +var y: { readonly a: E; readonly b: E; readonly [x: number]: string; readonly [x: number]: string } // two errors: the types are not identical and duplicate signatures \ No newline at end of file diff --git a/tests/cases/conformance/async/es6/asyncMethodWithSuper_es6.ts b/tests/cases/conformance/async/es6/asyncMethodWithSuper_es6.ts new file mode 100644 index 0000000000000..795fe7defb0b5 --- /dev/null +++ b/tests/cases/conformance/async/es6/asyncMethodWithSuper_es6.ts @@ -0,0 +1,52 @@ +// @target: ES6 +// @noEmitHelpers: true +class A { + x() { + } +} + +class B extends A { + // async method with only call/get on 'super' does not require a binding + async simple() { + // call with property access + super.x(); + + // call with element access + super["x"](); + + // property access (read) + const a = super.x; + + // element access (read) + const b = super["x"]; + } + + // async method with assignment/destructuring on 'super' requires a binding + async advanced() { + const f = () => {}; + + // call with property access + super.x(); + + // call with element access + super["x"](); + + // property access (read) + const a = super.x; + + // element access (read) + const b = super["x"]; + + // property access (assign) + super.x = f; + + // element access (assign) + super["x"] = f; + + // destructuring assign with property access + ({ f: super.x } = { f }); + + // destructuring assign with element access + ({ f: super["x"] } = { f }); + } +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts b/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts index edfd7ab4f8c17..a054ed0f6831b 100644 --- a/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts +++ b/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts @@ -46,7 +46,7 @@ class Derived6 extends Base { constructor(y: string) { this.a = 1; var b = 2; - super(); // ok + super(); // error: "super" has to be called before "this" accessing } } diff --git a/tests/cases/conformance/enums/enumBasics.ts b/tests/cases/conformance/enums/enumBasics.ts index 756e08e97afb2..1e134540713b6 100644 --- a/tests/cases/conformance/enums/enumBasics.ts +++ b/tests/cases/conformance/enums/enumBasics.ts @@ -11,10 +11,10 @@ var x: number = E1.A; // Enum object type is anonymous with properties of the enum type and numeric indexer var e = E1; var e: { - A: E1; - B: E1; - C: E1; - [n: number]: string; + readonly A: E1; + readonly B: E1; + readonly C: E1; + readonly [n: number]: string; }; var e: typeof E1; diff --git a/tests/cases/conformance/es6/decorators/class/decoratorOnClass1.es6.ts b/tests/cases/conformance/es6/decorators/class/decoratorOnClass1.es6.ts new file mode 100644 index 0000000000000..7dccedc5d1f2c --- /dev/null +++ b/tests/cases/conformance/es6/decorators/class/decoratorOnClass1.es6.ts @@ -0,0 +1,9 @@ +// @target:es6 +// @experimentaldecorators: true +declare function dec(target: T): T; + +@dec +class C { +} + +let c = new C(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/decorators/class/decoratorOnClass2.es6.ts b/tests/cases/conformance/es6/decorators/class/decoratorOnClass2.es6.ts new file mode 100644 index 0000000000000..62d6a15d0bcd3 --- /dev/null +++ b/tests/cases/conformance/es6/decorators/class/decoratorOnClass2.es6.ts @@ -0,0 +1,9 @@ +// @target:es6 +// @experimentaldecorators: true +declare function dec(target: T): T; + +@dec +export class C { +} + +let c = new C(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/decorators/class/decoratorOnClass3.es6.ts b/tests/cases/conformance/es6/decorators/class/decoratorOnClass3.es6.ts new file mode 100644 index 0000000000000..cc62befe2d815 --- /dev/null +++ b/tests/cases/conformance/es6/decorators/class/decoratorOnClass3.es6.ts @@ -0,0 +1,9 @@ +// @target:es6 +// @experimentaldecorators: true +declare function dec(target: T): T; + +@dec +export default class C { +} + +let c = new C(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/decorators/class/decoratorOnClass4.es6.ts b/tests/cases/conformance/es6/decorators/class/decoratorOnClass4.es6.ts new file mode 100644 index 0000000000000..050c8ae15fc2e --- /dev/null +++ b/tests/cases/conformance/es6/decorators/class/decoratorOnClass4.es6.ts @@ -0,0 +1,7 @@ +// @target:es6 +// @experimentaldecorators: true +declare function dec(target: T): T; + +@dec +export default class { +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/decorators/class/decoratorOnClass5.es6.ts b/tests/cases/conformance/es6/decorators/class/decoratorOnClass5.es6.ts new file mode 100644 index 0000000000000..daa21330c2b19 --- /dev/null +++ b/tests/cases/conformance/es6/decorators/class/decoratorOnClass5.es6.ts @@ -0,0 +1,11 @@ +// @target:es6 +// @experimentaldecorators: true +declare function dec(target: T): T; + +@dec +class C { + static x() { return C.y; } + static y = 1; +} + +let c = new C(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/decorators/class/decoratorOnClass6.es6.ts b/tests/cases/conformance/es6/decorators/class/decoratorOnClass6.es6.ts new file mode 100644 index 0000000000000..b28f89184954b --- /dev/null +++ b/tests/cases/conformance/es6/decorators/class/decoratorOnClass6.es6.ts @@ -0,0 +1,11 @@ +// @target:es6 +// @experimentaldecorators: true +declare function dec(target: T): T; + +@dec +export class C { + static x() { return C.y; } + static y = 1; +} + +let c = new C(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/decorators/class/decoratorOnClass7.es6.ts b/tests/cases/conformance/es6/decorators/class/decoratorOnClass7.es6.ts new file mode 100644 index 0000000000000..a69b7556d974b --- /dev/null +++ b/tests/cases/conformance/es6/decorators/class/decoratorOnClass7.es6.ts @@ -0,0 +1,11 @@ +// @target:es6 +// @experimentaldecorators: true +declare function dec(target: T): T; + +@dec +export default class C { + static x() { return C.y; } + static y = 1; +} + +let c = new C(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/decorators/class/decoratorOnClass8.es6.ts b/tests/cases/conformance/es6/decorators/class/decoratorOnClass8.es6.ts new file mode 100644 index 0000000000000..2e85fc801f243 --- /dev/null +++ b/tests/cases/conformance/es6/decorators/class/decoratorOnClass8.es6.ts @@ -0,0 +1,8 @@ +// @target:es6 +// @experimentaldecorators: true +declare function dec(target: T): T; + +@dec +export default class { + static y = 1; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/modules/exportsAndImportsWithUnderscores1.ts b/tests/cases/conformance/es6/modules/exportsAndImportsWithUnderscores1.ts new file mode 100644 index 0000000000000..8e38deaaf134b --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportsAndImportsWithUnderscores1.ts @@ -0,0 +1,14 @@ +//@module: commonjs +//@target: ES3 + +// @filename: m1.ts +var R: any +export default R = { + "__": 20, + "_": 10 + "___": 30 +} + +// @filename: m2.ts +import R from "./m1"; +const { __, _, ___ } = R; diff --git a/tests/cases/conformance/es6/modules/exportsAndImportsWithUnderscores2.ts b/tests/cases/conformance/es6/modules/exportsAndImportsWithUnderscores2.ts new file mode 100644 index 0000000000000..fac9f46754983 --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportsAndImportsWithUnderscores2.ts @@ -0,0 +1,13 @@ +//@module: commonjs +//@target: ES3 + +// @filename: m1.ts +var R: any +export default R = { + "__esmodule": true, + "__proto__": {} +} + +// @filename: m2.ts +import R from "./m1"; +const { __esmodule, __proto__ } = R; diff --git a/tests/cases/conformance/es6/modules/exportsAndImportsWithUnderscores3.ts b/tests/cases/conformance/es6/modules/exportsAndImportsWithUnderscores3.ts new file mode 100644 index 0000000000000..cd71808915cb7 --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportsAndImportsWithUnderscores3.ts @@ -0,0 +1,14 @@ +//@module: commonjs +//@target: ES3 + +// @filename: m1.ts +var R: any +export default R = { + "___": 30, + "___hello": 21, + "_hi": 40, +} + +// @filename: m2.ts +import R from "./m1"; +const { ___, ___hello, _hi } = R; diff --git a/tests/cases/conformance/es6/modules/exportsAndImportsWithUnderscores4.ts b/tests/cases/conformance/es6/modules/exportsAndImportsWithUnderscores4.ts new file mode 100644 index 0000000000000..340225975523a --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportsAndImportsWithUnderscores4.ts @@ -0,0 +1,35 @@ +//@module: commonjs +//@target: ES3 + +// @filename: m1.ts +declare var console: any; +export function _() { + console.log("_"); +} +export function __() { + console.log("__"); +} +export function ___() { + console.log("___"); +} +export function _hi() { + console.log("_hi"); +} +export function __proto() { + console.log("__proto"); +} +export function __esmodule() { + console.log("__esmodule"); +} +export function ___hello(){ + console.log("___hello"); +} + +// @filename: m2.ts +import {_, __, ___hello, __esmodule, __proto, _hi} from "./m1"; +_(); +__(); +___hello(); +__esmodule(); +__proto(); +_hi(); \ No newline at end of file diff --git a/tests/cases/conformance/expressions/objectLiterals/objectLiteralGettersAndSetters.ts b/tests/cases/conformance/expressions/objectLiterals/objectLiteralGettersAndSetters.ts index 5a6bc87af363d..af0622179ac7f 100644 --- a/tests/cases/conformance/expressions/objectLiterals/objectLiteralGettersAndSetters.ts +++ b/tests/cases/conformance/expressions/objectLiterals/objectLiteralGettersAndSetters.ts @@ -16,11 +16,11 @@ var callSig3: { num: (n: number) => string; }; // Get accessor only, type of the property is the annotated return type of the get accessor var getter1 = { get x(): string { return undefined; } }; -var getter1: { x: string; } +var getter1: { readonly x: string; } // Get accessor only, type of the property is the inferred return type of the get accessor var getter2 = { get x() { return ''; } }; -var getter2: { x: string; } +var getter2: { readonly x: string; } // Set accessor only, type of the property is the param type of the set accessor var setter1 = { set x(n: number) { } }; diff --git a/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts b/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts index 0afbc45004087..2b929318c13fe 100644 --- a/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts +++ b/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts @@ -11,7 +11,7 @@ class ClassWithNoInitializer extends BaseErrClass { t; //'this' in optional super call constructor() { - super(this); // OK + super(this); // Error } } diff --git a/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts b/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts index 513e56977df5e..e3d8ce9f5fcd2 100644 --- a/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts +++ b/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts @@ -11,7 +11,7 @@ class ClassWithNoInitializer extends BaseErrClass { t; //'this' in optional super call constructor() { - super(this); // OK + super(this); // error: "super" has to be called before "this" accessing } } diff --git a/tests/cases/conformance/externalModules/importsImplicitlyReadonly.ts b/tests/cases/conformance/externalModules/importsImplicitlyReadonly.ts new file mode 100644 index 0000000000000..f527606e57624 --- /dev/null +++ b/tests/cases/conformance/externalModules/importsImplicitlyReadonly.ts @@ -0,0 +1,21 @@ +// @module: commonjs + +// @filename: a.ts +export var x = 1; +var y = 1; +export { y }; + +// @filename: b.ts +import { x, y } from "./a"; +import * as a1 from "./a"; +import a2 = require("./a"); +const a3 = a1; + +x = 1; // Error +y = 1; // Error +a1.x = 1; // Error +a1.y = 1; // Error +a2.x = 1; +a2.y = 1; +a3.x = 1; +a3.y = 1; \ No newline at end of file diff --git a/tests/cases/conformance/jsx/tsxReactEmitNesting.tsx b/tests/cases/conformance/jsx/tsxReactEmitNesting.tsx new file mode 100644 index 0000000000000..6c56ed781a6da --- /dev/null +++ b/tests/cases/conformance/jsx/tsxReactEmitNesting.tsx @@ -0,0 +1,37 @@ +//@filename: file.tsx +//@jsx: react +//@reactNamespace: vdom + +declare var vdom: any; +declare var ctrl: any; +declare var model: any; + +// A simple render function with nesting and control statements +let render = (ctrl, model) => +
+
+

todos <x>

+ +
+
+ +
    + {model.filteredTodos.map((todo) => +
  • +
    + {(!todo.editable) ? + + : null + } + + +
    +
    +
    +
    +
  • + )} +
+
+
+ diff --git a/tests/cases/conformance/salsa/exportDefaultInJsFile01.ts b/tests/cases/conformance/salsa/exportDefaultInJsFile01.ts new file mode 100644 index 0000000000000..bf2f3a4e99bd2 --- /dev/null +++ b/tests/cases/conformance/salsa/exportDefaultInJsFile01.ts @@ -0,0 +1,6 @@ +// @allowJS: true +// @target: es3 +// @module: commonjs + +// @filename: myFile01.js +export default "hello"; \ No newline at end of file diff --git a/tests/cases/conformance/salsa/exportDefaultInJsFile02.ts b/tests/cases/conformance/salsa/exportDefaultInJsFile02.ts new file mode 100644 index 0000000000000..1075b135f174e --- /dev/null +++ b/tests/cases/conformance/salsa/exportDefaultInJsFile02.ts @@ -0,0 +1,6 @@ +// @allowJS: true +// @target: es2015 +// @module: es2015 + +// @filename: myFile02.js +export default "hello"; \ No newline at end of file diff --git a/tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.ts b/tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.ts index 46bb0ea2c8147..01f33fbd7bb50 100644 --- a/tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.ts +++ b/tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureIsNotSubtypeOfNonSpecializedSignature.ts @@ -1,5 +1,4 @@ -// Specialized signatures must be a subtype of a non-specialized signature -// All the below should be errors +// @declaration: true function foo(x: 'a'); function foo(x: number) { } diff --git a/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability01.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability01.ts new file mode 100644 index 0000000000000..fce073f16efd6 --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability01.ts @@ -0,0 +1,17 @@ +// @declaration: true + +function f(x: "foo"): number; +function f(x: string): number { + return 0; +} + +function g(x: "bar"): number; +function g(x: string): number { + return 0; +} + +let a = f; +let b = g; + +a = b; +b = a; \ No newline at end of file diff --git a/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability02.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability02.ts new file mode 100644 index 0000000000000..1a4f18430d513 --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability02.ts @@ -0,0 +1,17 @@ +// @declaration: true + +function f(x: "foo"): number; +function f(x: "foo"): number { + return 0; +} + +function g(x: "bar"): number; +function g(x: "bar"): number { + return 0; +} + +let a = f; +let b = g; + +a = b; +b = a; \ No newline at end of file diff --git a/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability03.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability03.ts new file mode 100644 index 0000000000000..0aacd899bcc8d --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability03.ts @@ -0,0 +1,17 @@ +// @declaration: true + +function f(x: "foo"): number; +function f(x: string): number { + return 0; +} + +function g(x: "foo"): number; +function g(x: string): number { + return 0; +} + +let a = f; +let b = g; + +a = b; +b = a; \ No newline at end of file diff --git a/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability04.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability04.ts new file mode 100644 index 0000000000000..eae4046286f04 --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability04.ts @@ -0,0 +1,17 @@ +// @declaration: true + +function f(x: "foo"): number; +function f(x: "foo"): number { + return 0; +} + +function g(x: "foo"): number; +function g(x: "foo"): number { + return 0; +} + +let a = f; +let b = g; + +a = b; +b = a; \ No newline at end of file diff --git a/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability05.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability05.ts new file mode 100644 index 0000000000000..9482ff02a1ede --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloadAssignability05.ts @@ -0,0 +1,18 @@ +// @declaration: true + +function f(x: "foo"): number; +function f(x: string): number; +function f(x: string): number { + return 0; +} + +function g(x: "foo"): number; +function g(x: string): number { + return 0; +} + +let a = f; +let b = g; + +a = b; +b = a; \ No newline at end of file diff --git a/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads05.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads05.ts new file mode 100644 index 0000000000000..182155790a6b3 --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads05.ts @@ -0,0 +1,13 @@ +// @declaration: true + +interface Animal { animal: {} }; +interface Dog extends Animal { dog: {} } +interface Cat extends Animal { cat: {} } +interface Moose extends Animal { moose: {} } + +function doThing(x: "dog"): Dog; +function doThing(x: "cat"): Cat; +function doThing(x: string): Animal; +function doThing(x: string, y?: string): Moose { + return undefined; +} \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptCompletions16.ts b/tests/cases/fourslash/getJavaScriptCompletions16.ts new file mode 100644 index 0000000000000..4d4b76d98d6c5 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptCompletions16.ts @@ -0,0 +1,35 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: file.js +//// "use strict"; +//// +//// class Something { +//// +//// /** +//// * @param {number} a +//// */ +//// constructor(a, b) { +//// a/*body*/ +//// } +//// +//// /** +//// * @param {number} a +//// */ +//// method(a) { +//// a/*method*/ +//// } +//// } +//// let x = new Something(/*sig*/); + +goTo.marker('body'); +edit.insert('.'); +verify.completionListContains('toFixed', undefined, undefined, 'method'); +edit.backspace(); + +goTo.marker('sig'); +verify.currentSignatureHelpIs('Something(a: number, b: any): Something'); + +goTo.marker('method'); +edit.insert('.'); +verify.completionListContains('toFixed', undefined, undefined, 'method'); diff --git a/tests/cases/fourslash/getJavaScriptCompletions18.ts b/tests/cases/fourslash/getJavaScriptCompletions18.ts new file mode 100644 index 0000000000000..a30d4943f4f08 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptCompletions18.ts @@ -0,0 +1,21 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: file.js +//// /** +//// * @param {number} a +//// * @param {string} b +//// */ +//// exports.foo = function(a, b) { +//// a/*a*/; +//// b/*b*/ +//// }; + +goTo.marker('a'); +edit.insert('.'); +verify.completionListContains('toFixed', undefined, undefined, 'method'); + + +goTo.marker('b'); +edit.insert('.'); +verify.completionListContains('substr', undefined, undefined, 'method'); diff --git a/tests/cases/fourslash/getJavaScriptCompletions19.ts b/tests/cases/fourslash/getJavaScriptCompletions19.ts new file mode 100644 index 0000000000000..5a361930e86b2 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptCompletions19.ts @@ -0,0 +1,25 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: file.js +//// function fn() { +//// if (foo) { +//// return 0; +//// } else { +//// return '0'; +//// } +//// } +//// let x = fn(); +//// if(typeof x === 'string') { +//// x/*str*/ +//// } else { +//// x/*num*/ +//// } + +goTo.marker('str'); +edit.insert('.'); +verify.completionListContains('substr', undefined, undefined, 'method'); + +goTo.marker('num'); +edit.insert('.'); +verify.completionListContains('toFixed', undefined, undefined, 'method'); diff --git a/tests/cases/fourslash/getJavaScriptCompletions20.ts b/tests/cases/fourslash/getJavaScriptCompletions20.ts new file mode 100644 index 0000000000000..d254705bb9132 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptCompletions20.ts @@ -0,0 +1,21 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: file.js +//// /** +//// * A person +//// * @constructor +//// * @param {string} name - The name of the person. +//// * @param {number} age - The age of the person. +//// */ +//// function Person(name, age) { +//// this.name = name; +//// this.age = age; +//// } +//// +//// +//// Person.getName = 10; +//// Person.getNa/**/ = 10; + +goTo.marker(); +verify.not.memberListContains('getNa'); diff --git a/tests/cases/fourslash/getJavaScriptQuickInfo7.ts b/tests/cases/fourslash/getJavaScriptQuickInfo7.ts new file mode 100644 index 0000000000000..5aa8474757d50 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptQuickInfo7.ts @@ -0,0 +1,20 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: file.js +//// /** +//// * This is a very cool function that is very nice. +//// * @returns something +//// * @param p anotherthing +//// */ +//// function a1(p) { +//// try { +//// throw new Error('x'); +//// } catch (x) { x--; } +//// return 23; +//// } +//// +//// x - /**/a1() + +goTo.marker(); +verify.quickInfoExists(); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts deleted file mode 100644 index c34f860b5fe4a..0000000000000 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics20.ts +++ /dev/null @@ -1,16 +0,0 @@ -/// - -// @allowJs: true -// @Filename: a.js -//// var v = undefined; - -verify.getSyntacticDiagnostics(`[]`); -verify.getSemanticDiagnostics(`[ - { - "message": "'type assertion expressions' can only be used in a .ts file.", - "start": 9, - "length": 6, - "category": "error", - "code": 8016 - } -]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics23.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics23.ts new file mode 100644 index 0000000000000..2524e50e668be --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics23.ts @@ -0,0 +1,14 @@ +/// + +// @allowJs: true +// @Filename: a.js +//// function Person(age) { +//// if (age >= 18) { +//// this.canVote = true; +//// } else { +//// this.canVote = false; +//// } +//// } + +verify.getSyntacticDiagnostics(`[]`); +verify.getSemanticDiagnostics(`[]`); diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics24.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics24.ts new file mode 100644 index 0000000000000..cf70f883e99f6 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics24.ts @@ -0,0 +1,16 @@ +/// + +// @allowJs: true +// @Filename: a.js +//// function Person(age) { +//// if (age >= 18) { +//// this.canVote = true; +//// } else { +//// this.canVote = 23; +//// } +//// } +//// let x = new Person(100); +//// x.canVote/**/; + +goTo.marker(); +verify.quickInfoIs('(property) Person.canVote: boolean | number'); diff --git a/tests/cases/fourslash/javaScriptModules13.ts b/tests/cases/fourslash/javaScriptModules13.ts index 4eed369836fe4..cb3ef36783f00 100644 --- a/tests/cases/fourslash/javaScriptModules13.ts +++ b/tests/cases/fourslash/javaScriptModules13.ts @@ -23,4 +23,6 @@ verify.completionListContains('y'); verify.not.completionListContains('invisible'); edit.insert('x.'); -verify.completionListContains('a'); +verify.memberListContains('a', undefined, undefined, 'property'); +edit.insert('a.'); +verify.memberListContains('toFixed', undefined, undefined, 'method'); diff --git a/tests/cases/fourslash/javaScriptModules19.ts b/tests/cases/fourslash/javaScriptModules19.ts new file mode 100644 index 0000000000000..91e2439dcc9b6 --- /dev/null +++ b/tests/cases/fourslash/javaScriptModules19.ts @@ -0,0 +1,26 @@ +/// + +// Assignments to 'module.exports' create an external module + +// @allowJs: true +// @Filename: myMod.js +//// var x = { a: 10 }; +//// module.exports = x; + +// @Filename: isGlobal.js +//// var y = 10; + +// @Filename: consumer.js +//// var x = require('myMod'); +//// /**/; + +goTo.file('consumer.js'); +goTo.marker(); + +verify.completionListContains('y'); +verify.not.completionListContains('invisible'); + +edit.insert('x.'); +verify.memberListContains('a', undefined, undefined, 'property'); +edit.insert('a.'); +verify.memberListContains('toFixed', undefined, undefined, 'method'); diff --git a/tests/cases/fourslash/quickInfoOnObjectLiteralWithOnlyGetter.ts b/tests/cases/fourslash/quickInfoOnObjectLiteralWithOnlyGetter.ts index 53f5e6988b7fe..a2e783d9ce03e 100644 --- a/tests/cases/fourslash/quickInfoOnObjectLiteralWithOnlyGetter.ts +++ b/tests/cases/fourslash/quickInfoOnObjectLiteralWithOnlyGetter.ts @@ -9,7 +9,7 @@ ////var /*2*/x = point./*3*/x; goTo.marker('1'); -verify.quickInfoIs("function makePoint(x: number): {\n x: number;\n}", undefined); +verify.quickInfoIs("function makePoint(x: number): {\n readonly x: number;\n}", undefined); goTo.marker('2'); verify.quickInfoIs("var x: number", undefined); @@ -18,4 +18,4 @@ goTo.marker('3'); verify.memberListContains("x", "(property) x: number", undefined); goTo.marker('4'); -verify.quickInfoIs("var point: {\n x: number;\n}", undefined); +verify.quickInfoIs("var point: {\n readonly x: number;\n}", undefined); diff --git a/tests/cases/fourslash/renameCrossJsTs01.ts b/tests/cases/fourslash/renameCrossJsTs01.ts new file mode 100644 index 0000000000000..52cb4c587d19c --- /dev/null +++ b/tests/cases/fourslash/renameCrossJsTs01.ts @@ -0,0 +1,12 @@ +/// + +// @allowJs: true +// @Filename: a.js +////exports.[|area|] = function (r) { return r * r; } + +// @Filename: b.ts +////import { [|area|] } from './a'; +////var t = /**/[|area|](10); + +goTo.marker(); +verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false); \ No newline at end of file diff --git a/tests/cases/fourslash/renameCrossJsTs02.ts b/tests/cases/fourslash/renameCrossJsTs02.ts new file mode 100644 index 0000000000000..7ff1ae96ff3ea --- /dev/null +++ b/tests/cases/fourslash/renameCrossJsTs02.ts @@ -0,0 +1,12 @@ +/// + +// @allowJs: true +// @Filename: a.js +////exports./**/[|area|] = function (r) { return r * r; } + +// @Filename: b.ts +////import { [|area|] } from './a'; +////var t = [|area|](10); + +goTo.marker(); +verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false); \ No newline at end of file diff --git a/tests/cases/fourslash/renameJsExports01.ts b/tests/cases/fourslash/renameJsExports01.ts new file mode 100644 index 0000000000000..923d30eedf96c --- /dev/null +++ b/tests/cases/fourslash/renameJsExports01.ts @@ -0,0 +1,12 @@ +/// + +// @allowJs: true +// @Filename: a.js +////exports.[|area|] = function (r) { return r * r; } + +// @Filename: b.js +////var mod = require('./a'); +////var t = mod./**/[|area|](10); + +goTo.marker(); +verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false); \ No newline at end of file diff --git a/tests/cases/fourslash/renameJsExports02.ts b/tests/cases/fourslash/renameJsExports02.ts new file mode 100644 index 0000000000000..86b0471dc1f4d --- /dev/null +++ b/tests/cases/fourslash/renameJsExports02.ts @@ -0,0 +1,12 @@ +/// + +// @allowJs: true +// @Filename: a.js +////exports./**/[|area|] = function (r) { return r * r; } + +// @Filename: b.js +////var mod = require('./a'); +////var t = mod.[|area|](10); + +goTo.marker(); +verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false); \ No newline at end of file diff --git a/tests/cases/fourslash/renameJsPrototypeProperty01.ts b/tests/cases/fourslash/renameJsPrototypeProperty01.ts new file mode 100644 index 0000000000000..f756f57edbf88 --- /dev/null +++ b/tests/cases/fourslash/renameJsPrototypeProperty01.ts @@ -0,0 +1,12 @@ +/// + +// @allowJs: true +// @Filename: a.js +////function bar() { +////} +////bar.prototype.[|x|] = 10; +////var t = new bar(); +////t./**/[|x|] = 11; + +goTo.marker(); +verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false); \ No newline at end of file diff --git a/tests/cases/fourslash/renameJsPrototypeProperty02.ts b/tests/cases/fourslash/renameJsPrototypeProperty02.ts new file mode 100644 index 0000000000000..721dc312eb624 --- /dev/null +++ b/tests/cases/fourslash/renameJsPrototypeProperty02.ts @@ -0,0 +1,12 @@ +/// + +// @allowJs: true +// @Filename: a.js +////function bar() { +////} +////bar.prototype./**/[|x|] = 10; +////var t = new bar(); +////t.[|x|] = 11; + +goTo.marker(); +verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false); \ No newline at end of file diff --git a/tests/cases/fourslash/renameJsThisProperty01.ts b/tests/cases/fourslash/renameJsThisProperty01.ts new file mode 100644 index 0000000000000..91338e0431dd5 --- /dev/null +++ b/tests/cases/fourslash/renameJsThisProperty01.ts @@ -0,0 +1,12 @@ +/// + +// @allowJs: true +// @Filename: a.js +////function bar() { +//// this.[|x|] = 10; +////} +////var t = new bar(); +////t./**/[|x|] = 11; + +goTo.marker(); +verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false); \ No newline at end of file diff --git a/tests/cases/fourslash/renameJsThisProperty02.ts b/tests/cases/fourslash/renameJsThisProperty02.ts new file mode 100644 index 0000000000000..8398507c9cabf --- /dev/null +++ b/tests/cases/fourslash/renameJsThisProperty02.ts @@ -0,0 +1,12 @@ +/// + +// @allowJs: true +// @Filename: a.js +////function bar() { +//// this./**/[|x|] = 10; +////} +////var t = new bar(); +////t.[|x|] = 11; + +goTo.marker(); +verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false); \ No newline at end of file diff --git a/tests/cases/fourslash/syntacticClassificationsJsx2.ts b/tests/cases/fourslash/syntacticClassificationsJsx2.ts new file mode 100644 index 0000000000000..9110c6ce4b934 --- /dev/null +++ b/tests/cases/fourslash/syntacticClassificationsJsx2.ts @@ -0,0 +1,27 @@ +/// + +// @Filename: file1.tsx +////let x = +//// some jsx text +////; +//// +////let y = + +const c = classification; +verify.syntacticClassificationsAre( + c.keyword("let"), c.identifier("x"), c.operator("="), + c.punctuation("<"), + c.jsxOpenTagName("div.name"), + c.jsxAttribute("b"), c.operator("="), c.jsxAttributeStringLiteralValue(`"some-value"`), + c.jsxAttribute("c"), c.operator("="), c.punctuation("{"), c.numericLiteral("1"), c.punctuation("}"), + c.punctuation(">"), + c.jsxText(` + some jsx text +`), + c.punctuation("<"), c.punctuation("/"), c.jsxCloseTagName("div.name"), c.punctuation(">"), c.punctuation(";"), + c.keyword("let"), c.identifier("y"), c.operator("="), + c.punctuation("<"), + c.jsxSelfClosingTagName("element.name"), + c.jsxAttribute("attr"), c.operator("="), c.jsxAttributeStringLiteralValue(`"123"`), + c.punctuation("/"), c.punctuation(">") +) \ No newline at end of file diff --git a/tests/cases/unittests/cachingInServerLSHost.ts b/tests/cases/unittests/cachingInServerLSHost.ts index 88b44a693b940..59f97f434e6cc 100644 --- a/tests/cases/unittests/cachingInServerLSHost.ts +++ b/tests/cases/unittests/cachingInServerLSHost.ts @@ -7,6 +7,10 @@ module ts { } function createDefaultServerHost(fileMap: Map): server.ServerHost { + const directories: Map = {}; + for (const f in fileMap) { + directories[getDirectoryPath(f)] = f; + } return { args: [], newLine: "\r\n", @@ -26,7 +30,7 @@ module ts { return hasProperty(fileMap, path); }, directoryExists: (path: string): boolean => { - throw new Error("NYI"); + return hasProperty(directories, path); }, createDirectory: (path: string) => { }, diff --git a/tests/cases/unittests/moduleResolution.ts b/tests/cases/unittests/moduleResolution.ts index 81d7c5f8b2e2f..1173f579f2c9c 100644 --- a/tests/cases/unittests/moduleResolution.ts +++ b/tests/cases/unittests/moduleResolution.ts @@ -459,6 +459,449 @@ import b = require("./moduleB.ts"); }) }); + describe("baseUrl augmented module resolution", () => { + + it("module resolution without path mappings/rootDirs", () => { + test(/*hasDirectoryExists*/ false); + test(/*hasDirectoryExists*/ true); + + function test(hasDirectoryExists: boolean) { + const file1: File = { name: "/root/folder1/file1.ts" }; + const file2: File = { name: "/root/folder2/file2.ts" }; + const file3: File = { name: "/root/folder2/file3.ts" }; + const host = createModuleResolutionHost(hasDirectoryExists, file1, file2, file3); + for (const moduleResolution of [ ModuleResolutionKind.NodeJs, ModuleResolutionKind.Classic ]) { + const options: CompilerOptions = { moduleResolution, baseUrl: "/root" }; + { + const result = resolveModuleName("folder2/file2", file1.name, options, host); + assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); + assert.equal(result.resolvedModule.resolvedFileName, file2.name); + assert.deepEqual(result.failedLookupLocations, []); + } + { + const result = resolveModuleName("./file3", file2.name, options, host); + assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); + assert.equal(result.resolvedModule.resolvedFileName, file3.name); + assert.deepEqual(result.failedLookupLocations, []); + } + { + const result = resolveModuleName("/root/folder1/file1", file2.name, options, host); + assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); + assert.equal(result.resolvedModule.resolvedFileName, file1.name); + assert.deepEqual(result.failedLookupLocations, []); + } + } + } + // add failure tests + }); + + it("node + baseUrl", () => { + test(/*hasDirectoryExists*/ false); + test(/*hasDirectoryExists*/ true); + + function test(hasDirectoryExists: boolean) { + const main: File = { name: "/root/a/b/main.ts" }; + const m1: File = { name: "/root/m1.ts" }; // load file as module + const m2: File = { name: "/root/m2/index.d.ts" }; // load folder as module + const m3: File = { name: "/root/m3/package.json", content: JSON.stringify({ typings: "dist/typings.d.ts" }) }; + const m3Typings: File = { name: "/root/m3/dist/typings.d.ts" }; + const m4: File = { name: "/root/node_modules/m4.ts" }; // fallback to node + + const options: CompilerOptions = { moduleResolution: ModuleResolutionKind.NodeJs, baseUrl: "/root" }; + const host = createModuleResolutionHost(hasDirectoryExists, main, m1, m2, m3, m3Typings, m4); + + check("m1", main, m1); + check("m2", main, m2); + check("m3", main, m3Typings); + check("m4", main, m4); + + function check(name: string, caller: File, expected: File) { + const result = resolveModuleName(name, caller.name, options, host); + assert.isTrue(result.resolvedModule !== undefined); + assert.equal(result.resolvedModule.resolvedFileName, expected.name); + } + } + }); + + it("classic + baseUrl", () => { + test(/*hasDirectoryExists*/ false); + test(/*hasDirectoryExists*/ true); + + function test(hasDirectoryExists: boolean) { + const main: File = { name: "/root/a/b/main.ts" }; + const m1: File = { name: "/root/x/m1.ts" }; // load from base url + const m2: File = { name: "/m2.ts" }; // fallback to classic + + const options: CompilerOptions = { moduleResolution: ModuleResolutionKind.Classic, baseUrl: "/root/x", jsx: JsxEmit.React }; + const host = createModuleResolutionHost(hasDirectoryExists, main, m1, m2); + + check("m1", main, m1); + check("m2", main, m2); + + function check(name: string, caller: File, expected: File) { + const result = resolveModuleName(name, caller.name, options, host); + assert.isTrue(result.resolvedModule !== undefined); + assert.equal(result.resolvedModule.resolvedFileName, expected.name); + } + } + }) + + it("node + baseUrl + path mappings", () => { + test(/*hasDirectoryExists*/ false); + test(/*hasDirectoryExists*/ true); + + function test(hasDirectoryExists: boolean) { + const main: File = { name: "/root/folder1/main.ts" }; + + const file1: File = { name: "/root/folder1/file1.ts" }; + const file2: File = { name: "/root/generated/folder1/file2.ts" } // load remapped file as module + const file3: File = { name: "/root/generated/folder2/file3/index.d.ts" } // load folder a module + const file4Typings: File = { name: "/root/generated/folder2/file4/package.json", content: JSON.stringify({ typings: "dist/types.d.ts" })}; + const file4: File = { name: "/root/generated/folder2/file4/dist/types.d.ts" }; // load file pointed by typings + const file5: File = { name: "/root/someanotherfolder/file5/index.d.ts" } // load remapped module from folder + const file6: File = { name: "/root/node_modules/file6.ts" }; // fallback to node + const host = createModuleResolutionHost(hasDirectoryExists, file1, file2, file3, file4, file4Typings, file5, file6); + + const options: CompilerOptions = { + moduleResolution: ModuleResolutionKind.NodeJs, + baseUrl: "/root", + jsx: JsxEmit.React, + paths: { + "*": [ + "*", + "generated/*" + ], + "somefolder/*": [ + "someanotherfolder/*" + ] + } + }; + check("folder1/file1", file1, []); + check("folder1/file2", file2, [ + // first try the '*' + "/root/folder1/file2.ts", + "/root/folder1/file2.tsx", + "/root/folder1/file2.d.ts", + "/root/folder1/file2/package.json", + "/root/folder1/file2/index.ts", + "/root/folder1/file2/index.tsx", + "/root/folder1/file2/index.d.ts" + // then first attempt on 'generated/*' was successful + ]); + check("folder2/file3", file3, [ + // first try '*' + "/root/folder2/file3.ts", + "/root/folder2/file3.tsx", + "/root/folder2/file3.d.ts", + "/root/folder2/file3/package.json", + "/root/folder2/file3/index.ts", + "/root/folder2/file3/index.tsx", + "/root/folder2/file3/index.d.ts", + // then use remapped location + "/root/generated/folder2/file3.ts", + "/root/generated/folder2/file3.tsx", + "/root/generated/folder2/file3.d.ts", + "/root/generated/folder2/file3/package.json", + "/root/generated/folder2/file3/index.ts", + "/root/generated/folder2/file3/index.tsx", + // success on index.d.ts + ]); + check("folder2/file4", file4, [ + // first try '*' + "/root/folder2/file4.ts", + "/root/folder2/file4.tsx", + "/root/folder2/file4.d.ts", + "/root/folder2/file4/package.json", + "/root/folder2/file4/index.ts", + "/root/folder2/file4/index.tsx", + "/root/folder2/file4/index.d.ts", + // try to load from file from remapped location + "/root/generated/folder2/file4.ts", + "/root/generated/folder2/file4.tsx", + "/root/generated/folder2/file4.d.ts" + // success on loading as from folder + ]); + check("somefolder/file5", file5, [ + // load from remapped location + // first load from fle + "/root/someanotherfolder/file5.ts", + "/root/someanotherfolder/file5.tsx", + "/root/someanotherfolder/file5.d.ts", + // load from folder + "/root/someanotherfolder/file5/package.json", + "/root/someanotherfolder/file5/index.ts", + "/root/someanotherfolder/file5/index.tsx", + // success on index.d.ts + ]); + check("file6", file6, [ + // first try * + // load from file + "/root/file6.ts", + "/root/file6.tsx", + "/root/file6.d.ts", + // load from folder + "/root/file6/package.json", + "/root/file6/index.ts", + "/root/file6/index.tsx", + "/root/file6/index.d.ts", + // then try 'generated/*' + // load from file + "/root/generated/file6.ts", + "/root/generated/file6.tsx", + "/root/generated/file6.d.ts", + // load from folder + "/root/generated/file6/package.json", + "/root/generated/file6/index.ts", + "/root/generated/file6/index.tsx", + "/root/generated/file6/index.d.ts", + // fallback to standard node behavior + // load from file + "/root/folder1/node_modules/file6.ts", + "/root/folder1/node_modules/file6.tsx", + "/root/folder1/node_modules/file6.d.ts", + // load from folder + "/root/folder1/node_modules/file6/package.json", + "/root/folder1/node_modules/file6/index.ts", + "/root/folder1/node_modules/file6/index.tsx", + "/root/folder1/node_modules/file6/index.d.ts", + // success on /root/node_modules/file6.ts + ]); + + function check(name: string, expected: File, expectedFailedLookups: string[]) { + const result = resolveModuleName(name, main.name, options, host); + assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); + assert.equal(result.resolvedModule.resolvedFileName, expected.name); + assert.deepEqual(result.failedLookupLocations, expectedFailedLookups); + } + } + }); + + it ("classic + baseUrl + path mappings", () => { + // classic mode does not use directoryExists + test(/*hasDirectoryExists*/ false); + + function test(hasDirectoryExists: boolean) { + const main: File = { name: "/root/folder1/main.ts" }; + + const file1: File = { name: "/root/folder1/file1.ts" }; + const file2: File = { name: "/root/generated/folder1/file2.ts" }; + const file3: File = { name: "/folder1/file3.ts" }; // fallback to classic + const host = createModuleResolutionHost(hasDirectoryExists, file1, file2, file3); + + const options: CompilerOptions = { + moduleResolution: ModuleResolutionKind.Classic, + baseUrl: "/root", + jsx: JsxEmit.React, + paths: { + "*": [ + "*", + "generated/*" + ], + "somefolder/*": [ + "someanotherfolder/*" + ] + } + }; + check("folder1/file1", file1, []); + check("folder1/file2", file2, [ + // first try '*' + "/root/folder1/file2.ts", + "/root/folder1/file2.tsx", + "/root/folder1/file2.d.ts", + // success when using 'generated/*' + ]); + check("folder1/file3", file3, [ + // first try '*' + "/root/folder1/file3.ts", + "/root/folder1/file3.tsx", + "/root/folder1/file3.d.ts", + // then try 'generated/*' + "/root/generated/folder1/file3.ts", + "/root/generated/folder1/file3.tsx", + "/root/generated/folder1/file3.d.ts", + // fallback to classic + "/root/folder1/folder1/file3.ts", + "/root/folder1/folder1/file3.tsx", + "/root/folder1/folder1/file3.d.ts", + "/root/folder1/file3.ts", + "/root/folder1/file3.tsx", + "/root/folder1/file3.d.ts", + ]); + + function check(name: string, expected: File, expectedFailedLookups: string[]) { + const result = resolveModuleName(name, main.name, options, host); + assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); + assert.equal(result.resolvedModule.resolvedFileName, expected.name); + assert.deepEqual(result.failedLookupLocations, expectedFailedLookups); + } + } + }) + + it ("node + rootDirs", () => { + test(/*hasDirectoryExists*/ false); + test(/*hasDirectoryExists*/ true); + + function test(hasDirectoryExists: boolean) { + let file1: File = { name: "/root/folder1/file1.ts" }; + let file1_1: File = { name: "/root/folder1/file1_1/index.d.ts" }; + let file2: File = { name: "/root/generated/folder1/file2.ts" }; + let file3: File = { name: "/root/generated/folder2/file3.ts" }; + const host = createModuleResolutionHost(hasDirectoryExists, file1, file1_1, file2, file3); + const options: CompilerOptions = { + moduleResolution: ModuleResolutionKind.NodeJs, + rootDirs: [ + "/root", + "/root/generated/" + ] + }; + check("./file2", file1, file2, [ + // first try current location + // load from file + "/root/folder1/file2.ts", + "/root/folder1/file2.tsx", + "/root/folder1/file2.d.ts", + // load from folder + "/root/folder1/file2/package.json", + "/root/folder1/file2/index.ts", + "/root/folder1/file2/index.tsx", + "/root/folder1/file2/index.d.ts", + // success after using alternative rootDir entry + ]); + check("../folder1/file1", file3, file1, [ + // first try current location + // load from file + "/root/generated/folder1/file1.ts", + "/root/generated/folder1/file1.tsx", + "/root/generated/folder1/file1.d.ts", + // load from module + "/root/generated/folder1/file1/package.json", + "/root/generated/folder1/file1/index.ts", + "/root/generated/folder1/file1/index.tsx", + "/root/generated/folder1/file1/index.d.ts", + // success after using alternative rootDir entry + ]); + check("../folder1/file1_1", file3, file1_1, [ + // first try current location + // load from file + "/root/generated/folder1/file1_1.ts", + "/root/generated/folder1/file1_1.tsx", + "/root/generated/folder1/file1_1.d.ts", + // load from folder + "/root/generated/folder1/file1_1/package.json", + "/root/generated/folder1/file1_1/index.ts", + "/root/generated/folder1/file1_1/index.tsx", + "/root/generated/folder1/file1_1/index.d.ts", + // try alternative rootDir entry + // load from file + "/root/folder1/file1_1.ts", + "/root/folder1/file1_1.tsx", + "/root/folder1/file1_1.d.ts", + // load from directory + "/root/folder1/file1_1/package.json", + "/root/folder1/file1_1/index.ts", + "/root/folder1/file1_1/index.tsx", + // success on loading '/root/folder1/file1_1/index.d.ts' + ]); + + function check(name: string, container: File, expected: File, expectedFailedLookups: string[]) { + const result = resolveModuleName(name, container.name, options, host); + assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); + assert.equal(result.resolvedModule.resolvedFileName, expected.name); + assert.deepEqual(result.failedLookupLocations,expectedFailedLookups); + } + } + }); + + it ("classic + rootDirs", () => { + test(/*hasDirectoryExists*/ false); + test(/*hasDirectoryExists*/ true); + + function test(hasDirectoryExists: boolean) { + let file1: File = { name: "/root/folder1/file1.ts" }; + let file2: File = { name: "/root/generated/folder1/file2.ts" }; + let file3: File = { name: "/root/generated/folder2/file3.ts" }; + let file4: File = { name: "/folder1/file1_1.ts" }; + const host = createModuleResolutionHost(hasDirectoryExists, file1, file2, file3, file4); + const options: CompilerOptions = { + moduleResolution: ModuleResolutionKind.Classic, + jsx: JsxEmit.React, + rootDirs: [ + "/root", + "/root/generated/" + ] + }; + check("./file2", file1, file2, [ + // first load from current location + "/root/folder1/file2.ts", + "/root/folder1/file2.tsx", + "/root/folder1/file2.d.ts", + // then try alternative rootDir entry + ]); + check("../folder1/file1", file3, file1, [ + // first load from current location + "/root/generated/folder1/file1.ts", + "/root/generated/folder1/file1.tsx", + "/root/generated/folder1/file1.d.ts", + // then try alternative rootDir entry + ]); + check("../folder1/file1_1", file3, file4, [ + // load from initial location + "/root/generated/folder1/file1_1.ts", + "/root/generated/folder1/file1_1.tsx", + "/root/generated/folder1/file1_1.d.ts", + // load from alternative rootDir entry + "/root/folder1/file1_1.ts", + "/root/folder1/file1_1.tsx", + "/root/folder1/file1_1.d.ts", + // fallback to classic + // step1: initial location + "/root/generated/folder1/file1_1.ts", + "/root/generated/folder1/file1_1.tsx", + "/root/generated/folder1/file1_1.d.ts", + // step2: walk 1 level up + "/root/folder1/file1_1.ts", + "/root/folder1/file1_1.tsx", + "/root/folder1/file1_1.d.ts", + ]); + + function check(name: string, container: File, expected: File, expectedFailedLookups: string[]) { + const result = resolveModuleName(name, container.name, options, host); + assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); + assert.equal(result.resolvedModule.resolvedFileName, expected.name); + assert.deepEqual(result.failedLookupLocations,expectedFailedLookups); + } + } + }); + + it ("nested node module", () => { + test(/*hasDirectoryExists*/ false); + test(/*hasDirectoryExists*/ true); + + function test(hasDirectoryExists: boolean) { + const app: File = { name: "/root/src/app.ts" } + const libsPackage: File = { name: "/root/src/libs/guid/package.json", content: JSON.stringify({ typings: "dist/guid.d.ts" }) }; + const libsTypings: File = { name: "/root/src/libs/guid/dist/guid.d.ts" }; + const host = createModuleResolutionHost(hasDirectoryExists, app, libsPackage, libsTypings); + const options: CompilerOptions = { + moduleResolution: ModuleResolutionKind.NodeJs, + baseUrl: "/root", + paths: { + "libs/guid": [ "src/libs/guid" ] + } + }; + const result = resolveModuleName("libs/guid", app.name, options, host); + assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); + assert.equal(result.resolvedModule.resolvedFileName, libsTypings.name); + assert.deepEqual(result.failedLookupLocations, [ + // first try to load module as file + "/root/src/libs/guid.ts", + "/root/src/libs/guid.tsx", + "/root/src/libs/guid.d.ts", + ]); + } + }) + }); + function notImplemented(name: string): () => any { return () => assert(`${name} is not implemented and should not be called`); } diff --git a/tests/cases/unittests/transpile.ts b/tests/cases/unittests/transpile.ts index 513d37673bb1a..6f46bb53405c5 100644 --- a/tests/cases/unittests/transpile.ts +++ b/tests/cases/unittests/transpile.ts @@ -134,7 +134,10 @@ var x = 0;`, it("Sets module name", () => { let output = - `System.register("NamedModule", [], function(exports_1) {\n "use strict";\n var x;\n` + + `System.register("NamedModule", [], function(exports_1, context_1) {\n` + + ` "use strict";\n` + + ` var __moduleName = context_1 && context_1.id;\n` + + ` var x;\n` + ` return {\n` + ` setters:[],\n` + ` execute: function() {\n` + @@ -159,8 +162,9 @@ var x = 0;`, `declare function use(a: any);\n` + `use(foo);` let output = - `System.register(["SomeOtherName"], function(exports_1) {\n` + + `System.register(["SomeOtherName"], function(exports_1, context_1) {\n` + ` "use strict";\n` + + ` var __moduleName = context_1 && context_1.id;\n` + ` var SomeName_1;\n` + ` return {\n` + ` setters:[\n` + @@ -287,5 +291,14 @@ var x = 0;`, options: { compilerOptions: { jsx: JsxEmit.React, newLine: NewLineKind.LineFeed } } }) }); + it("transpile .js files", () => { + const input = "const a = 10;"; + const output = `"use strict";\nvar a = 10;\n`; + test(input, { + expectedOutput: output, + options: { compilerOptions: { newLine: NewLineKind.LineFeed, module: ModuleKind.CommonJS }, fileName: "input.js", reportDiagnostics: true }, + expectedDiagnosticCodes: [] + }); + }) }); }