diff --git a/Jakefile.js b/Jakefile.js index c7f69bed8fa..2e29eac9381 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -594,7 +594,7 @@ task("configure-insiders", [configurePrereleaseJs], function () { }, { async: true }); desc("Configure, build, test, and publish the insiders release."); -task("publish-insiders", ["configure-nightly", "LKG", "clean", "setDebugMode", "runtests-parallel"], function () { +task("publish-insiders", ["configure-insiders", "LKG", "clean", "setDebugMode", "runtests-parallel"], function () { var cmd = "npm publish --tag insiders"; console.log(cmd); exec(cmd); diff --git a/package.json b/package.json index f6c9cac9792..aadb578a6de 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "typescript", "author": "Microsoft Corp.", "homepage": "http://typescriptlang.org/", - "version": "2.7.0", + "version": "2.8.0", "license": "Apache-2.0", "description": "TypeScript is a language for application scale JavaScript development", "keywords": [ diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 405fd11f138..ba3c3e6b83c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2424,12 +2424,15 @@ namespace ts { const visitedSymbolTables: SymbolTable[] = []; return forEachSymbolTableInScope(enclosingDeclaration, getAccessibleSymbolChainFromSymbolTable); - function getAccessibleSymbolChainFromSymbolTable(symbols: SymbolTable): Symbol[] | undefined { + /** + * @param {ignoreQualification} boolean Set when a symbol is being looked for through the exports of another symbol (meaning we have a route to qualify it already) + */ + function getAccessibleSymbolChainFromSymbolTable(symbols: SymbolTable, ignoreQualification?: boolean): Symbol[] | undefined { if (!pushIfUnique(visitedSymbolTables, symbols)) { return undefined; } - const result = trySymbolTable(symbols); + const result = trySymbolTable(symbols, ignoreQualification); visitedSymbolTables.pop(); return result; } @@ -2441,22 +2444,22 @@ namespace ts { !!getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning), useOnlyExternalAliasing); } - function isAccessible(symbolFromSymbolTable: Symbol, resolvedAliasSymbol?: Symbol) { + function isAccessible(symbolFromSymbolTable: Symbol, resolvedAliasSymbol?: Symbol, ignoreQualification?: boolean) { return symbol === (resolvedAliasSymbol || symbolFromSymbolTable) && // if the symbolFromSymbolTable is not external module (it could be if it was determined as ambient external module and would be in globals table) // and if symbolFromSymbolTable or alias resolution matches the symbol, // check the symbol can be qualified, it is only then this symbol is accessible !some(symbolFromSymbolTable.declarations, hasExternalModuleSymbol) && - canQualifySymbol(symbolFromSymbolTable, meaning); + (ignoreQualification || canQualifySymbol(symbolFromSymbolTable, meaning)); } function isUMDExportSymbol(symbol: Symbol) { return symbol && symbol.declarations && symbol.declarations[0] && isNamespaceExportDeclaration(symbol.declarations[0]); } - function trySymbolTable(symbols: SymbolTable) { + function trySymbolTable(symbols: SymbolTable, ignoreQualification: boolean | undefined) { // If symbol is directly available by its name in the symbol table - if (isAccessible(symbols.get(symbol.escapedName))) { + if (isAccessible(symbols.get(symbol.escapedName), /*resolvedAliasSymbol*/ undefined, ignoreQualification)) { return [symbol]; } @@ -2469,14 +2472,14 @@ namespace ts { && (!useOnlyExternalAliasing || some(symbolFromSymbolTable.declarations, isExternalModuleImportEqualsDeclaration))) { const resolvedImportedSymbol = resolveAlias(symbolFromSymbolTable); - if (isAccessible(symbolFromSymbolTable, resolvedImportedSymbol)) { + if (isAccessible(symbolFromSymbolTable, resolvedImportedSymbol, ignoreQualification)) { return [symbolFromSymbolTable]; } // Look in the exported members, if we can find accessibleSymbolChain, symbol is accessible using this chain // but only if the symbolFromSymbolTable can be qualified const candidateTable = getExportsOfSymbol(resolvedImportedSymbol); - const accessibleSymbolsFromExports = candidateTable && getAccessibleSymbolChainFromSymbolTable(candidateTable); + const accessibleSymbolsFromExports = candidateTable && getAccessibleSymbolChainFromSymbolTable(candidateTable, /*ignoreQualification*/ true); if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) { return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports); } @@ -5995,7 +5998,9 @@ namespace ts { for (const memberType of types) { for (const { escapedName } of getAugmentedPropertiesOfType(memberType)) { if (!props.has(escapedName)) { - props.set(escapedName, createUnionOrIntersectionProperty(unionType as UnionType, escapedName)); + const prop = createUnionOrIntersectionProperty(unionType as UnionType, escapedName); + // May be undefined if the property is private + if (prop) props.set(escapedName, prop); } } } @@ -6177,7 +6182,7 @@ namespace ts { t; } - function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: __String): Symbol { + function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: __String): Symbol | undefined { let props: Symbol[]; const isUnion = containingType.flags & TypeFlags.Union; const excludeModifiers = isUnion ? ModifierFlags.NonPublicAccessibilityModifier : 0; @@ -9220,7 +9225,8 @@ namespace ts { isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True; if (isObjectLiteralType(source) && source.flags & TypeFlags.FreshLiteral) { - if (hasExcessProperties(source, target, reportErrors)) { + const discriminantType = target.flags & TypeFlags.Union ? findMatchingDiscriminantType(source, target as UnionType) : undefined; + if (hasExcessProperties(source, target, discriminantType, reportErrors)) { if (reportErrors) { reportRelationError(headMessage, source, target); } @@ -9230,7 +9236,7 @@ namespace ts { // and intersection types are further deconstructed on the target side, we don't want to // make the check again (as it might fail for a partial target type). Therefore we obtain // the regular source type and proceed with that. - if (isUnionOrIntersectionTypeWithoutNullableConstituents(target)) { + if (isUnionOrIntersectionTypeWithoutNullableConstituents(target) && !discriminantType) { source = getRegularTypeOfObjectLiteral(source); } } @@ -9331,19 +9337,16 @@ namespace ts { return Ternary.False; } - function hasExcessProperties(source: FreshObjectLiteralType, target: Type, reportErrors: boolean): boolean { + function hasExcessProperties(source: FreshObjectLiteralType, target: Type, discriminant: Type | undefined, reportErrors: boolean): boolean { if (maybeTypeOfKind(target, TypeFlags.Object) && !(getObjectFlags(target) & ObjectFlags.ObjectLiteralPatternWithComputedProperties)) { const isComparingJsxAttributes = !!(source.flags & TypeFlags.JsxAttributes); if ((relation === assignableRelation || relation === comparableRelation) && (isTypeSubsetOf(globalObjectType, target) || (!isComparingJsxAttributes && isEmptyObjectType(target)))) { return false; } - if (target.flags & TypeFlags.Union) { - const discriminantType = findMatchingDiscriminantType(source, target as UnionType); - if (discriminantType) { - // check excess properties against discriminant type only, not the entire union - return hasExcessProperties(source, discriminantType, reportErrors); - } + if (discriminant) { + // check excess properties against discriminant type only, not the entire union + return hasExcessProperties(source, discriminant, /*discriminant*/ undefined, reportErrors); } for (const prop of getPropertiesOfObjectType(source)) { if (!isKnownProperty(target, prop.escapedName, isComparingJsxAttributes)) { @@ -13046,7 +13049,7 @@ namespace ts { node.parent.kind === SyntaxKind.NonNullExpression || declaration.kind === SyntaxKind.VariableDeclaration && (declaration).exclamationToken || declaration.flags & NodeFlags.Ambient; - const initialType = assumeInitialized ? (isParameter ? removeOptionalityFromDeclaredType(type, getRootDeclaration(declaration) as VariableLikeDeclaration) : type) : + const initialType = assumeInitialized ? (isParameter ? removeOptionalityFromDeclaredType(type, declaration as VariableLikeDeclaration) : type) : type === autoType || type === autoArrayType ? undefinedType : getOptionalType(type); const flowType = getFlowTypeOfReference(node, type, initialType, flowContainer, !assumeInitialized); @@ -15308,7 +15311,7 @@ namespace ts { // If the targetAttributesType is an emptyObjectType, indicating that there is no property named 'props' on this instance type. // but there exists a sourceAttributesType, we need to explicitly give an error as normal assignability check allow excess properties and will pass. - if (targetAttributesType === emptyObjectType && (isTypeAny(sourceAttributesType) || (sourceAttributesType).properties.length > 0)) { + if (targetAttributesType === emptyObjectType && (isTypeAny(sourceAttributesType) || getPropertiesOfType(sourceAttributesType).length > 0)) { error(openingLikeElement, Diagnostics.JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property, unescapeLeadingUnderscores(getJsxElementPropertiesName())); } else { @@ -16715,7 +16718,7 @@ namespace ts { const isDecorator = node.kind === SyntaxKind.Decorator; const isJsxOpeningOrSelfClosingElement = isJsxOpeningLikeElement(node); - let typeArguments: ReadonlyArray; + let typeArguments: NodeArray; if (!isTaggedTemplate && !isDecorator && !isJsxOpeningOrSelfClosingElement) { typeArguments = (node).typeArguments; @@ -16844,7 +16847,7 @@ namespace ts { max = Math.max(max, length(sig.typeParameters)); } const paramCount = min < max ? min + "-" + max : min; - diagnostics.add(createDiagnosticForNode(node, Diagnostics.Expected_0_type_arguments_but_got_1, paramCount, typeArguments.length)); + diagnostics.add(createDiagnosticForNodeArray(getSourceFileOfNode(node), typeArguments, Diagnostics.Expected_0_type_arguments_but_got_1, paramCount, typeArguments.length)); } else if (args) { let min = Number.POSITIVE_INFINITY; @@ -20964,7 +20967,7 @@ namespace ts { error(name, Diagnostics._0_is_declared_but_its_value_is_never_read, symbolName(local)); } } - else if (compilerOptions.noUnusedLocals) { + else if (local.flags & SymbolFlags.TypeParameter ? compilerOptions.noUnusedParameters : compilerOptions.noUnusedLocals) { forEach(local.declarations, d => errorUnusedLocal(d, symbolName(local))); } } @@ -21028,6 +21031,7 @@ namespace ts { } break; case SyntaxKind.IndexSignature: + case SyntaxKind.SemicolonClassElement: // Can't be private break; default: @@ -21038,7 +21042,7 @@ namespace ts { } function checkUnusedTypeParameters(node: ClassDeclaration | ClassExpression | FunctionDeclaration | MethodDeclaration | FunctionExpression | ArrowFunction | ConstructorDeclaration | SignatureDeclaration | InterfaceDeclaration | TypeAliasDeclaration) { - if (compilerOptions.noUnusedLocals && !(node.flags & NodeFlags.Ambient)) { + if (compilerOptions.noUnusedParameters && !(node.flags & NodeFlags.Ambient)) { if (node.typeParameters) { // Only report errors on the last declaration for the type parameter container; // this ensures that all uses have been accounted for. diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index eb9f1e3cf34..9c30cb87a4d 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -186,6 +186,12 @@ namespace ts { category: Diagnostics.Basic_Options, description: Diagnostics.Generates_corresponding_d_ts_file, }, + { + name: "emitDeclarationsOnly", + type: "boolean", + category: Diagnostics.Advanced_Options, + description: Diagnostics.Only_emit_d_ts_declaration_files, + }, { name: "sourceMap", type: "boolean", diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 9ce337001d6..1bdbbd456ff 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -4,7 +4,7 @@ namespace ts { // WARNING: The script `configureNightly.ts` uses a regexp to parse out these values. // If changing the text in this section, be sure to test `configureNightly` too. - export const versionMajorMinor = "2.7"; + export const versionMajorMinor = "2.8"; /** The version of the TypeScript compiler release */ export const version = `${versionMajorMinor}.0`; } @@ -16,6 +16,10 @@ namespace ts { // Update: We also consider a path like `C:\foo.ts` "relative" because we do not search for it in `node_modules` or treat it as an ambient module. return pathIsRelative(moduleName) || isRootedDiskPath(moduleName); } + + export function sortAndDeduplicateDiagnostics(diagnostics: ReadonlyArray): Diagnostic[] { + return sortAndDeduplicate(diagnostics, compareDiagnostics); + } } /* @internal */ @@ -340,6 +344,10 @@ namespace ts { return false; } + export function arraysEqual(a: ReadonlyArray, b: ReadonlyArray, equalityComparer: EqualityComparer = equateValues): boolean { + return a.length === b.length && a.every((x, i) => equalityComparer(x, b[i])); + } + export function indexOfAnyCharCode(text: string, charCodes: ReadonlyArray, start?: number): number { for (let i = start || 0; i < text.length; i++) { if (contains(charCodes, text.charCodeAt(i))) { @@ -1897,10 +1905,6 @@ namespace ts { return text1 ? Comparison.GreaterThan : Comparison.LessThan; } - export function sortAndDeduplicateDiagnostics(diagnostics: ReadonlyArray): Diagnostic[] { - return sortAndDeduplicate(diagnostics, compareDiagnostics); - } - export function normalizeSlashes(path: string): string { return path.replace(/\\/g, "/"); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 7a62d6d5aa4..6fffd576e7c 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2807,6 +2807,10 @@ "category": "Message", "code": 6013 }, + "Only emit '.d.ts' declaration files.": { + "category": "Message", + "code": 6014 + }, "Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'.": { "category": "Message", "code": 6015 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 63608eef49e..96b6cfac332 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -136,7 +136,7 @@ namespace ts { function emitSourceFileOrBundle({ jsFilePath, sourceMapFilePath, declarationFilePath }: EmitFileNames, sourceFileOrBundle: SourceFile | Bundle) { // Make sure not to write js file and source map file if any of them cannot be written - if (!host.isEmitBlocked(jsFilePath) && !compilerOptions.noEmit) { + if (!host.isEmitBlocked(jsFilePath) && !compilerOptions.noEmit && !compilerOptions.emitDeclarationsOnly) { if (!emitOnlyDtsFiles) { printSourceFileOrBundle(jsFilePath, sourceMapFilePath, sourceFileOrBundle); } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index bd45857fc51..23f9b08aa79 100755 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2201,6 +2201,16 @@ namespace ts { programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "checkJs", "allowJs")); } + if (options.emitDeclarationsOnly) { + if (!options.declaration) { + createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDeclarationsOnly", "declarations"); + } + + if (options.noEmit) { + createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "emitDeclarationsOnly", "noEmit"); + } + } + if (options.emitDecoratorMetadata && !options.experimentalDecorators) { createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators"); @@ -2223,7 +2233,9 @@ namespace ts { const emitHost = getEmitHost(); const emitFilesSeen = createMap(); forEachEmittedFile(emitHost, (emitFileNames) => { - verifyEmitFilePath(emitFileNames.jsFilePath, emitFilesSeen); + if (!options.emitDeclarationsOnly) { + verifyEmitFilePath(emitFileNames.jsFilePath, emitFilesSeen); + } verifyEmitFilePath(emitFileNames.declarationFilePath, emitFilesSeen); }); } diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 5001ea58336..6b0d10223fd 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -335,7 +335,10 @@ namespace ts { /* @internal */ export function computePositionOfLineAndCharacter(lineStarts: ReadonlyArray, line: number, character: number, debugText?: string): number { - Debug.assert(line >= 0 && line < lineStarts.length); + if (line < 0 || line >= lineStarts.length) { + Debug.fail(`Bad line number. Line: ${line}, lineStarts.length: ${lineStarts.length} , line map is correct? ${debugText !== undefined ? arraysEqual(lineStarts, computeLineStarts(debugText)) : "unknown"}`); + } + const res = lineStarts[line] + character; if (line < lineStarts.length - 1) { Debug.assert(res < lineStarts[line + 1]); diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 3256eef4dc2..ef1a3f8fd49 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -126,10 +126,32 @@ namespace ts { const _fs = require("fs"); const _path = require("path"); const _os = require("os"); - const _crypto = require("crypto"); + // crypto can be absent on reduced node installations + let _crypto: any; + try { + _crypto = require("crypto"); + } + catch { + _crypto = undefined; + } const useNonPollingWatchers = process.env.TSC_NONPOLLING_WATCHER; + /** + * djb2 hashing algorithm + * http://www.cse.yorku.ca/~oz/hash.html + */ + function generateDjb2Hash(data: string): string { + const chars = data.split("").map(str => str.charCodeAt(0)); + return `${chars.reduce((prev, curr) => ((prev << 5) + prev) + curr, 5381)}`; + } + + function createMD5HashUsingNativeCrypto(data: string) { + const hash = _crypto.createHash("md5"); + hash.update(data); + return hash.digest("hex"); + } + function createWatchedFileSet() { const dirWatchers = createMap(); // One file can have multiple watchers @@ -493,11 +515,7 @@ namespace ts { return undefined; } }, - createHash(data) { - const hash = _crypto.createHash("md5"); - hash.update(data); - return hash.digest("hex"); - }, + createHash: _crypto ? createMD5HashUsingNativeCrypto : generateDjb2Hash, getMemoryUsage() { if (global.gc) { global.gc(); diff --git a/src/compiler/transformers/esnext.ts b/src/compiler/transformers/esnext.ts index 5d46c8430d2..424371ad311 100644 --- a/src/compiler/transformers/esnext.ts +++ b/src/compiler/transformers/esnext.ts @@ -148,7 +148,7 @@ namespace ts { } function visitLabeledStatement(node: LabeledStatement) { - if (enclosingFunctionFlags & FunctionFlags.Async && enclosingFunctionFlags & FunctionFlags.Generator) { + if (enclosingFunctionFlags & FunctionFlags.Async) { const statement = unwrapInnermostStatementOfLabel(node); if (statement.kind === SyntaxKind.ForOfStatement && (statement).awaitModifier) { return visitForOfStatement(statement, node); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index f6ca2f45d34..481b91c9276 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3967,6 +3967,7 @@ namespace ts { /** configFile is set as non enumerable property so as to avoid checking of json source files */ /* @internal */ readonly configFile?: JsonSourceFile; declaration?: boolean; + emitDeclarationsOnly?: boolean; declarationDir?: string; /* @internal */ diagnostics?: boolean; /* @internal */ extendedDiagnostics?: boolean; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index bf6a086967c..f4ddf1d8319 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -599,6 +599,11 @@ namespace ts { return createDiagnosticForNodeInSourceFile(sourceFile, node, message, arg0, arg1, arg2, arg3); } + export function createDiagnosticForNodeArray(sourceFile: SourceFile, nodes: NodeArray, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number, arg3?: string | number): Diagnostic { + const start = skipTrivia(sourceFile.text, nodes.pos); + return createFileDiagnostic(sourceFile, start, nodes.end - start, message, arg0, arg1, arg2, arg3); + } + export function createDiagnosticForNodeInSourceFile(sourceFile: SourceFile, node: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number, arg3?: string | number): Diagnostic { const span = getErrorSpanForNode(sourceFile, node); return createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2, arg3); diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index beccb65f7b8..790295c2254 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -68,7 +68,7 @@ namespace ts { const host: ParseConfigFileHost = system; host.onConfigFileDiagnostic = reportDiagnostic; host.onUnRecoverableConfigFileDiagnostic = diagnostic => reportUnrecoverableDiagnostic(sys, reportDiagnostic, diagnostic); - const result = parseConfigFile(configFileName, optionsToExtend, host); + const result = getParsedCommandLineOfConfigFile(configFileName, optionsToExtend, host); host.onConfigFileDiagnostic = undefined; host.onUnRecoverableConfigFileDiagnostic = undefined; return result; @@ -77,7 +77,7 @@ namespace ts { /** * Reads the config file, reports errors if any and exits if the config file cannot be found */ - export function parseConfigFile(configFileName: string, optionsToExtend: CompilerOptions, host: ParseConfigFileHost): ParsedCommandLine | undefined { + export function getParsedCommandLineOfConfigFile(configFileName: string, optionsToExtend: CompilerOptions, host: ParseConfigFileHost): ParsedCommandLine | undefined { let configFileText: string; try { configFileText = host.readFile(configFileName); @@ -791,7 +791,7 @@ namespace ts { } function parseConfigFile() { - const configParseResult = ts.parseConfigFile(configFileName, optionsToExtendForConfigFile, parseConfigFileHost); + const configParseResult = ts.getParsedCommandLineOfConfigFile(configFileName, optionsToExtendForConfigFile, parseConfigFileHost); rootFileNames = configParseResult.fileNames; compilerOptions = configParseResult.options; configFileSpecs = configParseResult.configFileSpecs; diff --git a/src/harness/externalCompileRunner.ts b/src/harness/externalCompileRunner.ts index c829a6490bb..1f945cfcc9c 100644 --- a/src/harness/externalCompileRunner.ts +++ b/src/harness/externalCompileRunner.ts @@ -131,13 +131,13 @@ function removeExpectedErrors(errors: string, cwd: string): string { function isUnexpectedError(cwd: string) { return (error: string[]) => { ts.Debug.assertGreaterThanOrEqual(error.length, 1); - const match = error[0].match(/(.+\.ts)\((\d+),\d+\): error TS/); + const match = error[0].match(/(.+\.tsx?)\((\d+),\d+\): error TS/); if (!match) { return true; } const [, errorFile, lineNumberString] = match; const lines = fs.readFileSync(path.join(cwd, errorFile), { encoding: "utf8" }).split("\n"); - const lineNumber = parseInt(lineNumberString); + const lineNumber = parseInt(lineNumberString) - 1; ts.Debug.assertGreaterThanOrEqual(lineNumber, 0); ts.Debug.assertLessThan(lineNumber, lines.length); const previousLine = lineNumber - 1 > 0 ? lines[lineNumber - 1] : ""; diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 21985f360f4..8f0b7fa1023 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -24,7 +24,7 @@ namespace FourSlash { ts.disableIncrementalParsing = false; // Represents a parsed source file with metadata - export interface FourSlashFile { + interface FourSlashFile { // The contents of the file (with markers, etc stripped out) content: string; fileName: string; @@ -35,7 +35,7 @@ namespace FourSlash { } // Represents a set of parsed source files and options - export interface FourSlashData { + interface FourSlashData { // Global options (name/value pairs) globalOptions: Harness.TestCaseParser.CompilerSettings; @@ -60,7 +60,7 @@ namespace FourSlash { export interface Marker { fileName: string; position: number; - data?: any; + data?: {}; } export interface Range { @@ -90,21 +90,6 @@ namespace FourSlash { end: number; } - export import IndentStyle = ts.IndentStyle; - - const entityMap = ts.createMapFromTemplate({ - "&": "&", - "\"": """, - "'": "'", - "/": "/", - "<": "<", - ">": ">" - }); - - export function escapeXmlAttributeValue(s: string) { - return s.replace(/[&<>"'\/]/g, ch => entityMap.get(ch)); - } - // Name of testcase metadata including ts.CompilerOptions properties that will be used by globalOptions // To add additional option, add property into the testOptMetadataNames, refer the property in either globalMetadataNames or fileMetadataNames // Add cases into convertGlobalOptionsToCompilationsSettings function for the compiler to acknowledge such option from meta data @@ -1083,7 +1068,7 @@ namespace FourSlash { for (const reference of expectedReferences) { const { fileName, start, end } = reference; if (reference.marker && reference.marker.data) { - const { isWriteAccess, isDefinition } = reference.marker.data; + const { isWriteAccess, isDefinition } = reference.marker.data as { isWriteAccess?: boolean, isDefinition?: boolean }; this.verifyReferencesWorker(actualReferences, fileName, start, end, isWriteAccess, isDefinition); } else { @@ -1112,7 +1097,16 @@ namespace FourSlash { } const fullExpected = ts.map(parts, ({ definition, ranges }) => ({ definition: typeof definition === "string" ? definition : { ...definition, range: textSpanFromRange(definition.range) }, - references: ranges.map(rangeToReferenceEntry), + references: ranges.map(r => { + const { isWriteAccess = false, isDefinition = false, isInString } = (r.marker && r.marker.data || {}) as { isWriteAccess?: boolean, isDefinition?: boolean, isInString?: true }; + return { + isWriteAccess, + isDefinition, + fileName: r.fileName, + textSpan: textSpanFromRange(r), + ...(isInString ? { isInString: true } : undefined), + }; + }), })); for (const startRange of toArray(startRanges)) { @@ -1126,15 +1120,6 @@ namespace FourSlash { }); this.assertObjectsEqual(fullActual, fullExpected); } - - function rangeToReferenceEntry(r: Range): ts.ReferenceEntry { - const { isWriteAccess, isDefinition, isInString } = (r.marker && r.marker.data) || { isWriteAccess: false, isDefinition: false, isInString: undefined }; - const result: ts.ReferenceEntry = { fileName: r.fileName, textSpan: textSpanFromRange(r), isWriteAccess: !!isWriteAccess, isDefinition: !!isDefinition }; - if (isInString !== undefined) { - result.isInString = isInString; - } - return result; - } } public verifyNoReferences(markerNameOrRange?: string | Range) { @@ -2591,12 +2576,10 @@ Actual: ${stringify(fullActual)}`); actualTextArray.push(text); scriptInfo.updateContent(originalContent); } - const sortedExpectedArray = expectedTextArray.sort(); - const sortedActualArray = actualTextArray.sort(); - if (sortedExpectedArray.length !== sortedActualArray.length) { - this.raiseError(`Expected ${sortedExpectedArray.length} import fixes, got ${sortedActualArray.length}`); + if (expectedTextArray.length !== actualTextArray.length) { + this.raiseError(`Expected ${expectedTextArray.length} import fixes, got ${actualTextArray.length}`); } - ts.zipWith(sortedExpectedArray, sortedActualArray, (expected, actual, index) => { + ts.zipWith(expectedTextArray, actualTextArray, (expected, actual, index) => { if (expected !== actual) { this.raiseError(`Import fix at index ${index} doesn't match.\n${showTextDiff(expected, actual)}`); } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 770e7553167..13cb2b5dcfd 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1275,8 +1275,16 @@ namespace Harness { options: ts.CompilerOptions, // Current directory is needed for rwcRunner to be able to use currentDirectory defined in json file currentDirectory: string): DeclarationCompilationContext | undefined { - if (options.declaration && result.diagnostics.length === 0 && result.dts.size !== result.js.size) { - throw new Error("There were no errors and declFiles generated did not match number of js files generated"); + + if (options.declaration && result.diagnostics.length === 0) { + if (options.emitDeclarationsOnly) { + if (result.js.size > 0 || result.dts.size === 0) { + throw new Error("Only declaration files should be generated when emitDeclarationsOnly:true"); + } + } + else if (result.dts.size !== result.js.size) { + throw new Error("There were no errors and declFiles generated did not match number of js files generated"); + } } const declInputFiles: TestFile[] = []; @@ -1664,7 +1672,7 @@ namespace Harness { } export function doJsEmitBaseline(baselinePath: string, header: string, options: ts.CompilerOptions, result: compiler.CompilationResult, tsConfigFiles: ReadonlyArray, toBeCompiled: ReadonlyArray, otherFiles: ReadonlyArray, harnessSettings: Harness.TestCaseParser.CompilerSettings) { - if (!options.noEmit && result.js.size === 0 && result.diagnostics.length === 0) { + if (!options.noEmit && !options.emitDeclarationsOnly && result.js.size === 0 && result.diagnostics.length === 0) { throw new Error("Expected at least one js file to be emitted or at least one error to be created."); } diff --git a/src/harness/unittests/extractConstants.ts b/src/harness/unittests/extractConstants.ts index 71b550cba8f..9dfb1264a70 100644 --- a/src/harness/unittests/extractConstants.ts +++ b/src/harness/unittests/extractConstants.ts @@ -273,6 +273,13 @@ let i: I = [#|{ a: 1 }|]; const myObj: { member(x: number, y: string): void } = { member: [#|(x, y) => x + y|], } +`); + + testExtractConstant("extractConstant_CaseClauseExpression", ` +switch (1) { + case [#|1|]: + break; +} `); }); diff --git a/src/harness/unittests/extractRanges.ts b/src/harness/unittests/extractRanges.ts index 493c9639c3d..00fbf334b38 100644 --- a/src/harness/unittests/extractRanges.ts +++ b/src/harness/unittests/extractRanges.ts @@ -365,6 +365,58 @@ switch (x) { refactor.extractSymbol.Messages.cannotExtractRange.message ]); + testExtractRangeFailed("extractRangeFailed14", + ` + switch(1) { + case [#|1: + break;|] + } + `, + [ + refactor.extractSymbol.Messages.cannotExtractRange.message + ]); + + testExtractRangeFailed("extractRangeFailed15", + ` + switch(1) { + case [#|1: + break|]; + } + `, + [ + refactor.extractSymbol.Messages.cannotExtractRange.message + ]); + + // Documentation only - it would be nice if the result were [$|1|] + testExtractRangeFailed("extractRangeFailed16", + ` + switch(1) { + [#|case 1|]: + break; + } + `, + [ + refactor.extractSymbol.Messages.cannotExtractRange.message + ]); + + // Documentation only - it would be nice if the result were [$|1|] + testExtractRangeFailed("extractRangeFailed17", + ` + switch(1) { + [#|case 1:|] + break; + } + `, + [ + refactor.extractSymbol.Messages.cannotExtractRange.message + ]); + + testExtractRangeFailed("extractRangeFailed18", + `[#|{ 1;|] }`, + [ + refactor.extractSymbol.Messages.cannotExtractRange.message + ]); + testExtractRangeFailed("extract-method-not-for-token-expression-statement", `[#|a|]`, [refactor.extractSymbol.Messages.cannotExtractIdentifier.message]); }); } \ No newline at end of file diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index e6ebef377bb..6ca89feb012 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -1388,11 +1388,11 @@ namespace ts.projectSystem { service.checkNumberOfProjects({ externalProjects: 1 }); checkProjectActualFiles(service.externalProjects[0], [f1.path, f2.path, fakes.FakeServerHost.libPath]); - const completions1 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 0, { includeExternalModuleExports: false, includeInsertTextCompletions: false }); + const completions1 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 0, { includeExternalModuleExports: false, includeInsertTextCompletions: false }); assert.isTrue(completions1.entries.some(e => e.name === "somelongname"), "should contain 'somelongname'"); service.closeClientFile(f2.path); - const completions2 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 0, { includeExternalModuleExports: false, includeInsertTextCompletions: false }); + const completions2 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 0, { includeExternalModuleExports: false, includeInsertTextCompletions: false }); assert.isFalse(completions2.entries.some(e => e.name === "somelongname"), "should not contain 'somelongname'"); const sf2 = service.externalProjects[0].getLanguageService().getProgram().getSourceFile(f2.path); assert.equal(sf2.text, ""); @@ -2875,6 +2875,7 @@ namespace ts.projectSystem { watchedRecursiveDirectories.push(`${root}/a/b/src`, `${root}/a/b/node_modules`); host.checkWatchedDirectories(watchedRecursiveDirectories, /*recursive*/ true); }); + it("Properly handle Windows-style outDir", () => { const configFile: FileOrFolder = { path: "C:\\a\\tsconfig.json", @@ -2900,6 +2901,45 @@ namespace ts.projectSystem { const options = project.getCompilerOptions(); assert.equal(options.outDir, "C:/a/b", ""); }); + + it("dynamic file without external project", () => { + const file: FileOrFolder = { + path: "^walkThroughSnippet:/Users/UserName/projects/someProject/out/someFile#1.js", + content: "var x = 10;" + }; + const host = createServerHost([], { dos: true, lib: true }); + const projectService = createProjectService(host); + projectService.setCompilerOptionsForInferredProjects({ + module: ModuleKind.CommonJS, + allowJs: true, + allowSyntheticDefaultImports: true, + allowNonTsExtensions: true + }); + projectService.openClientFile(file.path, file.content); + + projectService.checkNumberOfProjects({ inferredProjects: 1 }); + const project = projectService.inferredProjects[0]; + checkProjectRootFiles(project, [file.path]); + checkProjectActualFiles(project, [file.path, fakes.FakeServerHost.dosLibPath]); + + assert.strictEqual(projectService.getDefaultProjectForFile(server.toNormalizedPath(file.path), /*ensureProject*/ true), project); + const indexOfX = file.content.indexOf("x"); + assert.deepEqual(project.getLanguageService(/*ensureSynchronized*/ true).getQuickInfoAtPosition(file.path, indexOfX), { + kind: ScriptElementKind.variableElement, + kindModifiers: "", + textSpan: { start: indexOfX, length: 1 }, + displayParts: [ + { text: "var", kind: "keyword" }, + { text: " ", kind: "space" }, + { text: "x", kind: "localName" }, + { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, + { text: "number", kind: "keyword" } + ], + documentation: [], + tags: [] + }); + }); }); describe("Proper errors", () => { diff --git a/src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl index a678f69e80e..5d67c5c6cdc 100644 --- a/src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -14,7 +14,7 @@ - + @@ -573,6 +573,15 @@ + + + + + + + + + @@ -3369,15 +3378,6 @@ - - - - - - - - - @@ -3564,6 +3564,15 @@ + + + + + + + + + @@ -6594,11 +6603,11 @@ - + - + - + diff --git a/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl index a58de23e3ff..c7e02a6c2cc 100644 --- a/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -14,7 +14,7 @@ - + @@ -573,6 +573,15 @@ + + + + + + + + + @@ -3369,15 +3378,6 @@ - - - - - - - - - @@ -3564,6 +3564,15 @@ + + + + + + + + + @@ -6594,11 +6603,11 @@ - + - + - + diff --git a/src/loc/lcl/csy/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/csy/diagnosticMessages/diagnosticMessages.generated.json.lcl index b6b35ec094b..3747e00c1f9 100644 --- a/src/loc/lcl/csy/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/csy/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -19,7 +19,7 @@ - + @@ -582,6 +582,15 @@ + + + + + + + + + @@ -3378,15 +3387,6 @@ - - - - - - - - - @@ -3573,6 +3573,15 @@ + + + + + + + + + @@ -6603,11 +6612,11 @@ - + - + - + diff --git a/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl index afee7120010..4d8f2721a08 100644 --- a/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -14,7 +14,7 @@ - + @@ -573,6 +573,15 @@ + + + + + + + + + @@ -3366,15 +3375,6 @@ - - - - - - - - - @@ -3561,6 +3561,15 @@ + + + + + + + + + @@ -6585,11 +6594,11 @@ - + - + - + diff --git a/src/loc/lcl/esn/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/esn/diagnosticMessages/diagnosticMessages.generated.json.lcl index 5d1bc276ee8..517b05df202 100644 --- a/src/loc/lcl/esn/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/esn/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -19,7 +19,7 @@ - + @@ -582,6 +582,15 @@ + + + + + + + + + @@ -3378,15 +3387,6 @@ - - - - - - - - - @@ -3573,6 +3573,15 @@ + + + + + + + + + @@ -6603,11 +6612,11 @@ - + - + - + diff --git a/src/loc/lcl/fra/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/fra/diagnosticMessages/diagnosticMessages.generated.json.lcl index d111d8f84b5..99776a461cc 100644 --- a/src/loc/lcl/fra/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/fra/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -19,7 +19,7 @@ - + @@ -582,6 +582,15 @@ + + + + + + + + + @@ -3378,15 +3387,6 @@ - - - - - - - - - @@ -3573,6 +3573,15 @@ + + + + + + + + + @@ -6603,11 +6612,11 @@ - + - + - + diff --git a/src/loc/lcl/ita/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/ita/diagnosticMessages/diagnosticMessages.generated.json.lcl index 63f0270005a..e13e8191eb2 100644 --- a/src/loc/lcl/ita/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/ita/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -14,7 +14,7 @@ - + @@ -573,6 +573,15 @@ + + + + + + + + + @@ -3369,15 +3378,6 @@ - - - - - - - - - @@ -3564,6 +3564,15 @@ + + + + + + + + + @@ -6594,11 +6603,11 @@ - + - + - + diff --git a/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl index 1f62aefc8ab..1a892b757cb 100644 --- a/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -14,7 +14,7 @@ - + @@ -573,6 +573,15 @@ + + + + + + + + + @@ -3369,15 +3378,6 @@ - - - - - - - - - @@ -3564,6 +3564,15 @@ + + + + + + + + + @@ -6594,11 +6603,11 @@ - + - + - + diff --git a/src/loc/lcl/kor/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/kor/diagnosticMessages/diagnosticMessages.generated.json.lcl index 2481a1b8752..b534bf56365 100644 --- a/src/loc/lcl/kor/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/kor/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -14,7 +14,7 @@ - + @@ -573,6 +573,15 @@ + + + + + + + + + @@ -3369,15 +3378,6 @@ - - - - - - - - - @@ -3564,6 +3564,15 @@ + + + + + + + + + @@ -6594,11 +6603,11 @@ - + - + - + diff --git a/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl index 74cf056e95a..c5473f41421 100644 --- a/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -7,7 +7,7 @@ - + @@ -566,6 +566,15 @@ + + + + + + + + + @@ -3359,15 +3368,6 @@ - - - - - - - - - @@ -3554,6 +3554,15 @@ + + + + + + + + + @@ -6578,11 +6587,11 @@ - + - + - + diff --git a/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl index 4be92ea0534..080b2e11402 100644 --- a/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -7,7 +7,7 @@ - + @@ -566,6 +566,15 @@ + + + + + + + + + @@ -3359,15 +3368,6 @@ - - - - - - - - - @@ -3554,6 +3554,15 @@ + + + + + + + + + @@ -6578,11 +6587,11 @@ - + - + - + diff --git a/src/loc/lcl/rus/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/rus/diagnosticMessages/diagnosticMessages.generated.json.lcl index ced875a6581..bb0b07794a3 100644 --- a/src/loc/lcl/rus/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/rus/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -13,7 +13,7 @@ - + @@ -572,6 +572,15 @@ + + + + + + + + + @@ -3368,15 +3377,6 @@ - - - - - - - - - @@ -3563,6 +3563,15 @@ + + + + + + + + + @@ -6593,11 +6602,11 @@ - + - + - + diff --git a/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl index 3b9a3824b9f..44a9f695fca 100644 --- a/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -7,7 +7,7 @@ - + @@ -566,6 +566,15 @@ + + + + + + + + + @@ -3362,15 +3371,6 @@ - - - - - - - - - @@ -3557,6 +3557,15 @@ + + + + + + + + + @@ -6587,11 +6596,11 @@ - + - + - + diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index b7cd2550d69..aad453e517f 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -902,7 +902,7 @@ namespace ts.server { const project = this.getOrCreateInferredProjectForProjectRootPathIfEnabled(info, projectRootPath) || this.getOrCreateSingleInferredProjectIfEnabled() || - this.createInferredProject(getDirectoryPath(info.path)); + this.createInferredProject(info.isDynamic ? this.currentDirectory : getDirectoryPath(info.path)); project.addRoot(info); project.updateGraph(); @@ -1659,7 +1659,7 @@ namespace ts.server { } private getOrCreateInferredProjectForProjectRootPathIfEnabled(info: ScriptInfo, projectRootPath: NormalizedPath | undefined): InferredProject | undefined { - if (!this.useInferredProjectPerProjectRoot) { + if (info.isDynamic || !this.useInferredProjectPerProjectRoot) { return undefined; } diff --git a/src/server/scriptInfo.ts b/src/server/scriptInfo.ts index dbadf5c88e7..6fc4f241f65 100644 --- a/src/server/scriptInfo.ts +++ b/src/server/scriptInfo.ts @@ -196,7 +196,7 @@ namespace ts.server { /*@internal*/ export function isDynamicFileName(fileName: NormalizedPath) { - return getBaseFileName(fileName)[0] === "^"; + return fileName[0] === "^" || getBaseFileName(fileName)[0] === "^"; } export class ScriptInfo { diff --git a/src/services/codefixes/disableJsDiagnostics.ts b/src/services/codefixes/disableJsDiagnostics.ts index a887878bac6..091ee07a9cc 100644 --- a/src/services/codefixes/disableJsDiagnostics.ts +++ b/src/services/codefixes/disableJsDiagnostics.ts @@ -1,8 +1,8 @@ /* @internal */ namespace ts.codefix { const fixId = "disableJsDiagnostics"; - const errorCodes = mapDefined(Object.keys(Diagnostics), key => { - const diag = (Diagnostics as MapLike)[key]; + const errorCodes = mapDefined(Object.keys(Diagnostics) as ReadonlyArray, key => { + const diag = Diagnostics[key]; return diag.category === DiagnosticCategory.Error ? diag.code : undefined; }); @@ -19,33 +19,35 @@ namespace ts.codefix { return [{ description: getLocaleSpecificMessage(Diagnostics.Ignore_this_error_message), - changes: [createFileTextChanges(sourceFile.fileName, [getIgnoreCommentLocationForLocation(sourceFile, span.start, newLineCharacter)])], + changes: [createFileTextChanges(sourceFile.fileName, [getIgnoreCommentLocationForLocation(sourceFile, span.start, newLineCharacter).change])], fixId, }, { description: getLocaleSpecificMessage(Diagnostics.Disable_checking_for_this_file), - changes: [createFileTextChanges(sourceFile.fileName, [{ - span: { - start: sourceFile.checkJsDirective ? sourceFile.checkJsDirective.pos : 0, - length: sourceFile.checkJsDirective ? sourceFile.checkJsDirective.end - sourceFile.checkJsDirective.pos : 0 - }, - newText: `// @ts-nocheck${newLineCharacter}` - }])], + changes: [createFileTextChanges(sourceFile.fileName, [ + createTextChange(sourceFile.checkJsDirective ? createTextSpanFromBounds(sourceFile.checkJsDirective.pos, sourceFile.checkJsDirective.end) : createTextSpan(0, 0), `// @ts-nocheck${newLineCharacter}`), + ])], // fixId unnecessary because adding `// @ts-nocheck` even once will ignore every error in the file. fixId: undefined, }]; }, - fixIds: [fixId], // No point applying as a group, doing it once will fix all errors - getAllCodeActions: context => codeFixAllWithTextChanges(context, errorCodes, (changes, err) => { - if (err.start !== undefined) { - changes.push(getIgnoreCommentLocationForLocation(err.file!, err.start, getNewLineOrDefaultFromHost(context.host, context.formatContext.options))); - } - }), + fixIds: [fixId], + getAllCodeActions: context => { + const seenLines = createMap(); // Only need to add `// @ts-ignore` for a line once. + return codeFixAllWithTextChanges(context, errorCodes, (changes, err) => { + if (err.start !== undefined) { + const { lineNumber, change } = getIgnoreCommentLocationForLocation(err.file!, err.start, getNewLineOrDefaultFromHost(context.host, context.formatContext.options)); + if (addToSeen(seenLines, lineNumber)) { + changes.push(change); + } + } + }); + }, }); - function getIgnoreCommentLocationForLocation(sourceFile: SourceFile, position: number, newLineCharacter: string): TextChange { - const { line } = getLineAndCharacterOfPosition(sourceFile, position); - const lineStartPosition = getStartPositionOfLine(line, sourceFile); + function getIgnoreCommentLocationForLocation(sourceFile: SourceFile, position: number, newLineCharacter: string): { lineNumber: number, change: TextChange } { + const { line: lineNumber } = getLineAndCharacterOfPosition(sourceFile, position); + const lineStartPosition = getStartPositionOfLine(lineNumber, sourceFile); const startPosition = getFirstNonSpaceCharacterPosition(sourceFile.text, lineStartPosition); // First try to see if we can put the '// @ts-ignore' on the previous line. @@ -54,19 +56,13 @@ namespace ts.codefix { // if so, we do not want to separate the node from its comment if we can. if (!isInComment(sourceFile, startPosition) && !isInString(sourceFile, startPosition) && !isInTemplateString(sourceFile, startPosition)) { const token = getTouchingToken(sourceFile, startPosition, /*includeJsDocComment*/ false); - const tokenLeadingCommnets = getLeadingCommentRangesOfNode(token, sourceFile); - if (!tokenLeadingCommnets || !tokenLeadingCommnets.length || tokenLeadingCommnets[0].pos >= startPosition) { - return { - span: { start: startPosition, length: 0 }, - newText: `// @ts-ignore${newLineCharacter}` - }; + const tokenLeadingComments = getLeadingCommentRangesOfNode(token, sourceFile); + if (!tokenLeadingComments || !tokenLeadingComments.length || tokenLeadingComments[0].pos >= startPosition) { + return { lineNumber, change: createTextChangeFromStartLength(startPosition, 0, `// @ts-ignore${newLineCharacter}`) }; } } // If all fails, add an extra new line immediately before the error span. - return { - span: { start: position, length: 0 }, - newText: `${position === startPosition ? "" : newLineCharacter}// @ts-ignore${newLineCharacter}` - }; + return { lineNumber, change: createTextChangeFromStartLength(position, 0, `${position === startPosition ? "" : newLineCharacter}// @ts-ignore${newLineCharacter}`) }; } } diff --git a/src/services/codefixes/fixJSDocTypes.ts b/src/services/codefixes/fixJSDocTypes.ts index 8c43ed0cc7f..3158e90ce96 100644 --- a/src/services/codefixes/fixJSDocTypes.ts +++ b/src/services/codefixes/fixJSDocTypes.ts @@ -50,7 +50,7 @@ namespace ts.codefix { } function createChange(declaration: TypeNode, sourceFile: SourceFile, newText: string): TextChange { - return { span: createTextSpanFromBounds(declaration.getStart(sourceFile), declaration.getEnd()), newText }; + return createTextChange(createTextSpanFromNode(declaration, sourceFile), newText); } function typeString(type: Type, checker: TypeChecker): string { diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index 4c536ce3fd2..ac88d98eba5 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -390,7 +390,7 @@ namespace ts.codefix { In this case we should prefer using the relative path "../a" instead of the baseUrl path "foo/a". */ const pathFromSourceToBaseUrl = getRelativePath(baseUrl, sourceDirectory, getCanonicalFileName); - const relativeFirst = getRelativePathNParents(pathFromSourceToBaseUrl) < getRelativePathNParents(relativePath); + const relativeFirst = getRelativePathNParents(relativePath) < getRelativePathNParents(pathFromSourceToBaseUrl); return relativeFirst ? [relativePath, importRelativeToBaseUrl] : [importRelativeToBaseUrl, relativePath]; })); // Only return results for the re-export with the shortest possible path (and also give the other path even if that's long.) diff --git a/src/services/codefixes/inferFromUsage.ts b/src/services/codefixes/inferFromUsage.ts index 6f6b2f3c61e..2f3dae01acf 100644 --- a/src/services/codefixes/inferFromUsage.ts +++ b/src/services/codefixes/inferFromUsage.ts @@ -191,7 +191,7 @@ namespace ts.codefix { function makeChange(declaration: Declaration, start: number, type: Type | undefined, program: Program): TextChange | undefined { const typeString = type && typeToString(type, declaration, program.getTypeChecker()); - return typeString === undefined ? undefined : { span: createTextSpan(start, 0), newText: `: ${typeString}` }; + return typeString === undefined ? undefined : createTextChangeFromStartLength(start, 0, `: ${typeString}`); } function getReferences(token: PropertyName | Token, sourceFile: SourceFile, program: Program, cancellationToken: CancellationToken): Identifier[] { diff --git a/src/services/completions.ts b/src/services/completions.ts index 80fdf6c280e..bce1eadaf26 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -20,7 +20,8 @@ namespace ts.Completions { None, ClassElementKeywords, // Keywords at class keyword ConstructorParameterKeywords, // Keywords at constructor parameter - FunctionLikeBodyKeywords // Keywords at function like body + FunctionLikeBodyKeywords, // Keywords at function like body + TypeKeywords, } export function getCompletionsAtPosition( @@ -77,7 +78,7 @@ namespace ts.Completions { } function completionInfoFromData(sourceFile: SourceFile, typeChecker: TypeChecker, compilerOptions: CompilerOptions, log: Log, completionData: CompletionData, includeInsertTextCompletions: boolean): CompletionInfo { - const { symbols, completionKind, isNewIdentifierLocation, location, propertyAccessToConvert, keywordFilters, symbolToOriginInfoMap, recommendedCompletion } = completionData; + const { symbols, completionKind, isNewIdentifierLocation, location, propertyAccessToConvert, keywordFilters, symbolToOriginInfoMap, recommendedCompletion, isJsxInitializer } = completionData; if (sourceFile.languageVariant === LanguageVariant.JSX && location && location.parent && isJsxClosingElement(location.parent)) { // In the TypeScript JSX element, if such element is not defined. When users query for completion at closing tag, @@ -98,7 +99,7 @@ namespace ts.Completions { const entries: CompletionEntry[] = []; if (isSourceFileJavaScript(sourceFile)) { - const uniqueNames = getCompletionEntriesFromSymbols(symbols, entries, location, sourceFile, typeChecker, compilerOptions.target, log, completionKind, includeInsertTextCompletions, propertyAccessToConvert, recommendedCompletion, symbolToOriginInfoMap); + const uniqueNames = getCompletionEntriesFromSymbols(symbols, entries, location, sourceFile, typeChecker, compilerOptions.target, log, completionKind, includeInsertTextCompletions, propertyAccessToConvert, isJsxInitializer, recommendedCompletion, symbolToOriginInfoMap); getJavaScriptCompletionEntries(sourceFile, location.pos, uniqueNames, compilerOptions.target, entries); } else { @@ -106,7 +107,7 @@ namespace ts.Completions { return undefined; } - getCompletionEntriesFromSymbols(symbols, entries, location, sourceFile, typeChecker, compilerOptions.target, log, completionKind, includeInsertTextCompletions, propertyAccessToConvert, recommendedCompletion, symbolToOriginInfoMap); + getCompletionEntriesFromSymbols(symbols, entries, location, sourceFile, typeChecker, compilerOptions.target, log, completionKind, includeInsertTextCompletions, propertyAccessToConvert, isJsxInitializer, recommendedCompletion, symbolToOriginInfoMap); } // TODO add filter for keyword based on type/value/namespace and also location @@ -166,6 +167,7 @@ namespace ts.Completions { origin: SymbolOriginInfo | undefined, recommendedCompletion: Symbol | undefined, propertyAccessToConvert: PropertyAccessExpression | undefined, + isJsxInitializer: boolean, includeInsertTextCompletions: boolean, ): CompletionEntry | undefined { const info = getCompletionEntryDisplayNameForSymbol(symbol, target, origin, kind); @@ -173,19 +175,27 @@ namespace ts.Completions { return undefined; } const { name, needsConvertPropertyAccess } = info; - if (needsConvertPropertyAccess && !includeInsertTextCompletions) { - return undefined; - } let insertText: string | undefined; let replacementSpan: TextSpan | undefined; - if (kind === CompletionKind.Global && origin && origin.type === "this-type") { - insertText = needsConvertPropertyAccess ? `this["${name}"]` : `this.${name}`; + if (includeInsertTextCompletions) { + if (origin && origin.type === "this-type") { + insertText = needsConvertPropertyAccess ? `this["${name}"]` : `this.${name}`; + } + else if (needsConvertPropertyAccess) { + // TODO: GH#20619 Use configured quote style + insertText = `["${name}"]`; + replacementSpan = createTextSpanFromBounds(findChildOfKind(propertyAccessToConvert!, SyntaxKind.DotToken, sourceFile)!.getStart(sourceFile), propertyAccessToConvert!.name.end); + } + + if (isJsxInitializer) { + if (insertText === undefined) insertText = name; + insertText = `{${insertText}}`; + } } - else if (needsConvertPropertyAccess) { - // TODO: GH#20619 Use configured quote style - insertText = `["${name}"]`; - replacementSpan = createTextSpanFromBounds(findChildOfKind(propertyAccessToConvert!, SyntaxKind.DotToken, sourceFile)!.getStart(sourceFile), propertyAccessToConvert!.name.end); + + if (insertText !== undefined && !includeInsertTextCompletions) { + return undefined; } // TODO(drosen): Right now we just permit *all* semantic meanings when calling @@ -234,6 +244,7 @@ namespace ts.Completions { kind: CompletionKind, includeInsertTextCompletions?: boolean, propertyAccessToConvert?: PropertyAccessExpression | undefined, + isJsxInitializer?: boolean, recommendedCompletion?: Symbol, symbolToOriginInfoMap?: SymbolOriginInfoMap, ): Map { @@ -245,7 +256,7 @@ namespace ts.Completions { const uniques = createMap(); for (const symbol of symbols) { const origin = symbolToOriginInfoMap ? symbolToOriginInfoMap[getSymbolId(symbol)] : undefined; - const entry = createCompletionEntry(symbol, location, sourceFile, typeChecker, target, kind, origin, recommendedCompletion, propertyAccessToConvert, includeInsertTextCompletions); + const entry = createCompletionEntry(symbol, location, sourceFile, typeChecker, target, kind, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, includeInsertTextCompletions); if (!entry) { continue; } @@ -482,6 +493,7 @@ namespace ts.Completions { location: Node; symbolToOriginInfoMap: SymbolOriginInfoMap; previousToken: Node; + readonly isJsxInitializer: boolean; } function getSymbolCompletionFromEntryId( typeChecker: TypeChecker, @@ -500,7 +512,7 @@ namespace ts.Completions { return { type: "request", request: completionData }; } - const { symbols, location, completionKind, symbolToOriginInfoMap, previousToken } = completionData; + const { symbols, location, completionKind, symbolToOriginInfoMap, previousToken, isJsxInitializer } = completionData; // Find the symbol with the matching entry name. // We don't need to perform character checks here because we're only comparing the @@ -509,7 +521,7 @@ namespace ts.Completions { return firstDefined(symbols, (symbol): SymbolCompletion => { // TODO: Shouldn't need return type annotation (GH#12632) const origin = symbolToOriginInfoMap[getSymbolId(symbol)]; const info = getCompletionEntryDisplayNameForSymbol(symbol, compilerOptions.target, origin, completionKind); - return info && info.name === name && getSourceFromOrigin(origin) === source ? { type: "symbol" as "symbol", symbol, location, symbolToOriginInfoMap, previousToken } : undefined; + return info && info.name === name && getSourceFromOrigin(origin) === source ? { type: "symbol" as "symbol", symbol, location, symbolToOriginInfoMap, previousToken, isJsxInitializer } : undefined; }) || { type: "none" }; } @@ -565,7 +577,7 @@ namespace ts.Completions { } case "none": { // Didn't find a symbol with this name. See if we can find a keyword instead. - if (some(getKeywordCompletions(KeywordCompletionFilters.None), c => c.name === name)) { + if (allKeywordsCompletions().some(c => c.name === name)) { return { name, kind: ScriptElementKind.keyword, @@ -677,11 +689,13 @@ namespace ts.Completions { readonly symbolToOriginInfoMap: SymbolOriginInfoMap; readonly recommendedCompletion: Symbol | undefined; readonly previousToken: Node | undefined; + readonly isJsxInitializer: boolean; } type Request = { readonly kind: CompletionDataKind.JsDocTagName | CompletionDataKind.JsDocTag } | { readonly kind: CompletionDataKind.JsDocParameterName, tag: JSDocParameterTag }; const enum CompletionKind { ObjectPropertyDeclaration, + /** Note that sometimes we access completions from global scope, but use "None" instead of this. See isGlobalCompletionScope. */ Global, PropertyAccess, MemberLike, @@ -857,6 +871,7 @@ namespace ts.Completions { let isRightOfDot = false; let isRightOfOpenTag = false; let isStartingCloseTag = false; + let isJsxInitializer = false; let location = getTouchingPropertyName(sourceFile, position, insideJsDocTagTypeExpression); // TODO: GH#15853 if (contextToken) { @@ -915,6 +930,10 @@ namespace ts.Completions { location = contextToken; } break; + + case SyntaxKind.JsxAttribute: + isJsxInitializer = previousToken.kind === SyntaxKind.EqualsToken; + break; } } } @@ -960,7 +979,7 @@ namespace ts.Completions { log("getCompletionData: Semantic work: " + (timestamp() - semanticStart)); const recommendedCompletion = previousToken && getRecommendedCompletion(previousToken, typeChecker); - return { kind: CompletionDataKind.Data, symbols, completionKind, propertyAccessToConvert, isNewIdentifierLocation, location, keywordFilters, symbolToOriginInfoMap, recommendedCompletion, previousToken }; + return { kind: CompletionDataKind.Data, symbols, completionKind, propertyAccessToConvert, isNewIdentifierLocation, location, keywordFilters, symbolToOriginInfoMap, recommendedCompletion, previousToken, isJsxInitializer }; type JSDocTagWithTypeExpression = JSDocParameterTag | JSDocPropertyTag | JSDocReturnTag | JSDocTypeTag | JSDocTypedefTag; @@ -1163,6 +1182,9 @@ namespace ts.Completions { } function filterGlobalCompletion(symbols: Symbol[]): void { + const isTypeCompletion = insideJsDocTagTypeExpression || !isContextTokenValueLocation(contextToken) && (isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken)); + if (isTypeCompletion) keywordFilters = KeywordCompletionFilters.TypeKeywords; + filterMutate(symbols, symbol => { if (!isSourceFile(location)) { // export = /**/ here we want to get all meanings, so any symbol is ok @@ -1170,19 +1192,14 @@ namespace ts.Completions { return true; } - // This is an alias, follow what it aliases - if (symbol && symbol.flags & SymbolFlags.Alias) { - symbol = typeChecker.getAliasedSymbol(symbol); - } + symbol = skipAlias(symbol, typeChecker); // import m = /**/ <-- It can only access namespace (if typing import = x. this would get member symbols and not namespace) if (isInRightSideOfInternalImportEqualsDeclaration(location)) { return !!(symbol.flags & SymbolFlags.Namespace); } - if (insideJsDocTagTypeExpression || - (!isContextTokenValueLocation(contextToken) && - (isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken)))) { + if (isTypeCompletion) { // Its a type, but you can reach it by namespace.type as well return symbolCanBeReferencedAtTypeLocation(symbol); } @@ -1199,7 +1216,7 @@ namespace ts.Completions { contextToken.parent.kind === SyntaxKind.TypeQuery; } - function isContextTokenTypeLocation(contextToken: Node) { + function isContextTokenTypeLocation(contextToken: Node): boolean { if (contextToken) { const parentKind = contextToken.parent.kind; switch (contextToken.kind) { @@ -1217,6 +1234,7 @@ namespace ts.Completions { return parentKind === SyntaxKind.AsExpression; } } + return false; } function symbolCanBeReferencedAtTypeLocation(symbol: Symbol): boolean { @@ -2112,13 +2130,13 @@ namespace ts.Completions { const validIdentiferResult: CompletionEntryDisplayNameForSymbol = { name, needsConvertPropertyAccess: false }; if (isIdentifierText(name, target)) return validIdentiferResult; switch (kind) { - case CompletionKind.None: case CompletionKind.MemberLike: return undefined; case CompletionKind.ObjectPropertyDeclaration: // TODO: GH#18169 return { name: JSON.stringify(name), needsConvertPropertyAccess: false }; case CompletionKind.PropertyAccess: + case CompletionKind.None: case CompletionKind.Global: // Don't add a completion for a name starting with a space. See https://github.com/Microsoft/TypeScript/pull/20547 return name.charCodeAt(0) === CharacterCodes.space ? undefined : { name, needsConvertPropertyAccess: true }; @@ -2130,51 +2148,38 @@ namespace ts.Completions { } // A cache of completion entries for keywords, these do not change between sessions - const _keywordCompletions: CompletionEntry[][] = []; - function getKeywordCompletions(keywordFilter: KeywordCompletionFilters): CompletionEntry[] { - const completions = _keywordCompletions[keywordFilter]; - if (completions) { - return completions; + const _keywordCompletions: ReadonlyArray[] = []; + const allKeywordsCompletions: () => ReadonlyArray = ts.memoize(() => { + const res: CompletionEntry[] = []; + for (let i = SyntaxKind.FirstKeyword; i <= SyntaxKind.LastKeyword; i++) { + res.push({ + name: tokenToString(i), + kind: ScriptElementKind.keyword, + kindModifiers: ScriptElementKindModifier.none, + sortText: "0" + }); } - return _keywordCompletions[keywordFilter] = generateKeywordCompletions(keywordFilter); - - type FilterKeywordCompletions = (entryName: string) => boolean; - function generateKeywordCompletions(keywordFilter: KeywordCompletionFilters): CompletionEntry[] { + return res; + }); + function getKeywordCompletions(keywordFilter: KeywordCompletionFilters): ReadonlyArray { + return _keywordCompletions[keywordFilter] || (_keywordCompletions[keywordFilter] = allKeywordsCompletions().filter(entry => { + const kind = stringToToken(entry.name); switch (keywordFilter) { case KeywordCompletionFilters.None: - return getAllKeywordCompletions(); + // "undefined" is a global variable, so don't need a keyword completion for it. + return kind !== SyntaxKind.UndefinedKeyword; case KeywordCompletionFilters.ClassElementKeywords: - return getFilteredKeywordCompletions(isClassMemberCompletionKeywordText); + return isClassMemberCompletionKeyword(kind); case KeywordCompletionFilters.ConstructorParameterKeywords: - return getFilteredKeywordCompletions(isConstructorParameterCompletionKeywordText); + return isConstructorParameterCompletionKeyword(kind); case KeywordCompletionFilters.FunctionLikeBodyKeywords: - return getFilteredKeywordCompletions(isFunctionLikeBodyCompletionKeywordText); + return isFunctionLikeBodyCompletionKeyword(kind); + case KeywordCompletionFilters.TypeKeywords: + return isTypeKeyword(kind); default: - Debug.assertNever(keywordFilter); + return Debug.assertNever(keywordFilter); } - } - - function getAllKeywordCompletions() { - const allKeywordsCompletions: CompletionEntry[] = []; - for (let i = SyntaxKind.FirstKeyword; i <= SyntaxKind.LastKeyword; i++) { - // "undefined" is a global variable, so don't need a keyword completion for it. - if (i === SyntaxKind.UndefinedKeyword) continue; - allKeywordsCompletions.push({ - name: tokenToString(i), - kind: ScriptElementKind.keyword, - kindModifiers: ScriptElementKindModifier.none, - sortText: "0" - }); - } - return allKeywordsCompletions; - } - - function getFilteredKeywordCompletions(filterFn: FilterKeywordCompletions) { - return filter( - getKeywordCompletions(KeywordCompletionFilters.None), - entry => filterFn(entry.name) - ); - } + })); } function isClassMemberCompletionKeyword(kind: SyntaxKind) { @@ -2222,15 +2227,12 @@ namespace ts.Completions { case SyntaxKind.AbstractKeyword: case SyntaxKind.GetKeyword: case SyntaxKind.SetKeyword: + case SyntaxKind.UndefinedKeyword: return false; } return true; } - function isFunctionLikeBodyCompletionKeywordText(text: string) { - return isFunctionLikeBodyCompletionKeyword(stringToToken(text)); - } - function isEqualityOperatorKind(kind: ts.SyntaxKind): kind is EqualityOperator { switch (kind) { case ts.SyntaxKind.EqualsEqualsEqualsToken: diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 818e2815944..22446a98ce2 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -1078,19 +1078,15 @@ namespace ts.formatting { trimTrailingWhitespacesForLines(startLine, endLine + 1, previousRange); } - function newTextChange(start: number, len: number, newText: string): TextChange { - return { span: createTextSpan(start, len), newText }; - } - function recordDelete(start: number, len: number) { if (len) { - edits.push(newTextChange(start, len, "")); + edits.push(createTextChangeFromStartLength(start, len, "")); } } function recordReplace(start: number, len: number, newText: string) { if (len || newText) { - edits.push(newTextChange(start, len, newText)); + edits.push(createTextChangeFromStartLength(start, len, newText)); } } diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 16270eda479..f6a9dee4cfe 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -321,6 +321,9 @@ namespace ts.formatting { rule("NoSpaceAfterCloseBracket", SyntaxKind.CloseBracketToken, anyToken, [isNonJsxSameLineTokenContext, isNotBeforeBlockInFunctionDeclarationContext], RuleAction.Delete), rule("SpaceAfterSemicolon", SyntaxKind.SemicolonToken, anyToken, [isNonJsxSameLineTokenContext], RuleAction.Space), + // Remove extra space between for and await + rule("SpaceBetweenForAndAwaitKeyword", SyntaxKind.ForKeyword, SyntaxKind.AwaitKeyword, [isNonJsxSameLineTokenContext], RuleAction.Space), + // Add a space between statements. All keywords except (do,else,case) has open/close parens after them. // So, we have a rule to add a space for [),Any], [do,Any], [else,Any], and [case,Any] rule( diff --git a/src/services/importTracker.ts b/src/services/importTracker.ts index d2ce802f177..a8f724cb4be 100644 --- a/src/services/importTracker.ts +++ b/src/services/importTracker.ts @@ -510,11 +510,32 @@ namespace ts.FindAllReferences { return undefined; } - const sym = useLhsSymbol ? checker.getSymbolAtLocation((node.left as ts.PropertyAccessExpression).name) : symbol; + const sym = useLhsSymbol ? checker.getSymbolAtLocation(cast(node.left, isPropertyAccessExpression).name) : symbol; + // Better detection for GH#20803 + if (sym && !(checker.getMergedSymbol(sym.parent).flags & SymbolFlags.Module)) { + Debug.fail(`Special property assignment kind does not have a module as its parent. Assignment is ${showSymbol(sym)}, parent is ${showSymbol(sym.parent)}`); + } return sym && exportInfo(sym, kind); } } + function showSymbol(s: Symbol): string { + const decls = s.declarations.map(d => (ts as any).SyntaxKind[d.kind]).join(","); + const flags = showFlags(s.flags, (ts as any).SymbolFlags); + return `{ declarations: ${decls}, flags: ${flags} }`; + } + + function showFlags(f: number, flags: any) { + const out = []; + for (let pow = 0; pow <= 30; pow++) { + const n = 1 << pow; + if (f & n) { + out.push(flags[n]); + } + } + return out.join("|"); + } + function getImport(): ImportedSymbol | undefined { const isImport = isNodeImport(node); if (!isImport) return undefined; diff --git a/src/services/refactors/extractSymbol.ts b/src/services/refactors/extractSymbol.ts index 479c387fc65..e3a2763b783 100644 --- a/src/services/refactors/extractSymbol.ts +++ b/src/services/refactors/extractSymbol.ts @@ -235,6 +235,16 @@ namespace ts.refactor.extractSymbol { break; } } + + if (!statements.length) { + // https://github.com/Microsoft/TypeScript/issues/20559 + // Ranges like [|case 1: break;|] will fail to populate `statements` because + // they will never find `start` in `start.parent.statements`. + // Consider: We could support ranges like [|case 1:|] by refining them to just + // the expression. + return { errors: [createFileDiagnostic(sourceFile, span.start, length, Messages.cannotExtractRange)] }; + } + return { targetRange: { range: statements, facts: rangeFacts, declarations } }; } @@ -1321,6 +1331,13 @@ namespace ts.refactor.extractSymbol { } prevStatement = statement; } + + if (!prevStatement && isCaseClause(curr)) { + // We must have been in the expression of the case clause. + Debug.assert(isSwitchStatement(curr.parent.parent)); + return curr.parent.parent; + } + // There must be at least one statement since we started in one. Debug.assert(prevStatement !== undefined); return prevStatement; diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index 3674cd31b97..83b434aac7d 100644 --- a/src/services/textChanges.ts +++ b/src/services/textChanges.ts @@ -620,10 +620,7 @@ namespace ts.textChanges { const sourceFile = changesInFile[0].sourceFile; const fileTextChanges: FileTextChanges = { fileName: sourceFile.fileName, textChanges: [] }; for (const c of ChangeTracker.normalize(changesInFile)) { - fileTextChanges.textChanges.push({ - span: this.computeSpan(c, sourceFile), - newText: this.computeNewText(c, sourceFile) - }); + fileTextChanges.textChanges.push(createTextChange(this.computeSpan(c, sourceFile), this.computeNewText(c, sourceFile))); } fileChangesList.push(fileTextChanges); }); diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 9bb35359523..e30fd8cfe2d 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1067,15 +1067,27 @@ namespace ts { return createTextSpanFromBounds(range.pos, range.end); } + export function createTextChangeFromStartLength(start: number, length: number, newText: string): TextChange { + return createTextChange(createTextSpan(start, length), newText); + } + + export function createTextChange(span: TextSpan, newText: string): TextChange { + return { span, newText }; + } + export const typeKeywords: ReadonlyArray = [ SyntaxKind.AnyKeyword, SyntaxKind.BooleanKeyword, + SyntaxKind.KeyOfKeyword, SyntaxKind.NeverKeyword, + SyntaxKind.NullKeyword, SyntaxKind.NumberKeyword, SyntaxKind.ObjectKeyword, SyntaxKind.StringKeyword, SyntaxKind.SymbolKeyword, SyntaxKind.VoidKeyword, + SyntaxKind.UndefinedKeyword, + SyntaxKind.UniqueKeyword, ]; export function isTypeKeyword(kind: SyntaxKind): boolean { diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index cd1b577b711..78f68a80c50 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2266,6 +2266,7 @@ declare namespace ts { charset?: string; checkJs?: boolean; declaration?: boolean; + emitDeclarationsOnly?: boolean; declarationDir?: string; disableSizeLimit?: boolean; downlevelIteration?: boolean; @@ -2808,12 +2809,13 @@ declare namespace ts { } } declare namespace ts { - const versionMajorMinor = "2.7"; + const versionMajorMinor = "2.8"; /** The version of the TypeScript compiler release */ const version: string; } declare namespace ts { function isExternalModuleNameRelative(moduleName: string): boolean; + function sortAndDeduplicateDiagnostics(diagnostics: ReadonlyArray): Diagnostic[]; } declare function setTimeout(handler: (...args: any[]) => void, timeout: number): any; declare function clearTimeout(handle: any): void; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 3cbca96f8fa..bdcc29af76e 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2266,6 +2266,7 @@ declare namespace ts { charset?: string; checkJs?: boolean; declaration?: boolean; + emitDeclarationsOnly?: boolean; declarationDir?: string; disableSizeLimit?: boolean; downlevelIteration?: boolean; @@ -2808,12 +2809,13 @@ declare namespace ts { } } declare namespace ts { - const versionMajorMinor = "2.7"; + const versionMajorMinor = "2.8"; /** The version of the TypeScript compiler release */ const version: string; } declare namespace ts { function isExternalModuleNameRelative(moduleName: string): boolean; + function sortAndDeduplicateDiagnostics(diagnostics: ReadonlyArray): Diagnostic[]; } declare function setTimeout(handler: (...args: any[]) => void, timeout: number): any; declare function clearTimeout(handle: any): void; diff --git a/tests/baselines/reference/assigningFromObjectToAnythingElse.errors.txt b/tests/baselines/reference/assigningFromObjectToAnythingElse.errors.txt index c8fb57e3616..bc92c376c7c 100644 --- a/tests/baselines/reference/assigningFromObjectToAnythingElse.errors.txt +++ b/tests/baselines/reference/assigningFromObjectToAnythingElse.errors.txt @@ -1,8 +1,8 @@ tests/cases/compiler/assigningFromObjectToAnythingElse.ts(3,1): error TS2322: Type 'Object' is not assignable to type 'RegExp'. The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? Property 'exec' is missing in type 'Object'. -tests/cases/compiler/assigningFromObjectToAnythingElse.ts(5,17): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/compiler/assigningFromObjectToAnythingElse.ts(6,17): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/assigningFromObjectToAnythingElse.ts(5,31): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/assigningFromObjectToAnythingElse.ts(6,31): error TS2558: Expected 0 type arguments, but got 1. tests/cases/compiler/assigningFromObjectToAnythingElse.ts(8,5): error TS2322: Type 'Object' is not assignable to type 'Error'. The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? Property 'name' is missing in type 'Object'. @@ -18,10 +18,10 @@ tests/cases/compiler/assigningFromObjectToAnythingElse.ts(8,5): error TS2322: Ty !!! error TS2322: Property 'exec' is missing in type 'Object'. var a: String = Object.create(""); - ~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var c: String = Object.create(1); - ~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var w: Error = new Object(); diff --git a/tests/baselines/reference/callGenericFunctionWithIncorrectNumberOfTypeArguments.errors.txt b/tests/baselines/reference/callGenericFunctionWithIncorrectNumberOfTypeArguments.errors.txt index 6d95b588ebf..d5809d677e4 100644 --- a/tests/baselines/reference/callGenericFunctionWithIncorrectNumberOfTypeArguments.errors.txt +++ b/tests/baselines/reference/callGenericFunctionWithIncorrectNumberOfTypeArguments.errors.txt @@ -1,17 +1,17 @@ -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(5,10): error TS2558: Expected 2 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(6,11): error TS2558: Expected 2 type arguments, but got 3. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(9,10): error TS2558: Expected 2 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(10,11): error TS2558: Expected 2 type arguments, but got 3. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(13,10): error TS2558: Expected 2 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(14,11): error TS2558: Expected 2 type arguments, but got 3. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(21,10): error TS2558: Expected 2 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(22,11): error TS2558: Expected 2 type arguments, but got 3. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(28,10): error TS2558: Expected 2 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(29,11): error TS2558: Expected 2 type arguments, but got 3. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(36,10): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(37,11): error TS2558: Expected 0 type arguments, but got 3. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(43,10): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(44,11): error TS2558: Expected 0 type arguments, but got 3. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(5,12): error TS2558: Expected 2 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(6,13): error TS2558: Expected 2 type arguments, but got 3. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(9,13): error TS2558: Expected 2 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(10,14): error TS2558: Expected 2 type arguments, but got 3. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(13,13): error TS2558: Expected 2 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(14,14): error TS2558: Expected 2 type arguments, but got 3. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(21,22): error TS2558: Expected 2 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(22,23): error TS2558: Expected 2 type arguments, but got 3. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(28,14): error TS2558: Expected 2 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(29,15): error TS2558: Expected 2 type arguments, but got 3. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(36,23): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(37,24): error TS2558: Expected 0 type arguments, but got 3. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(43,15): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts(44,16): error TS2558: Expected 0 type arguments, but got 3. ==== tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts (14 errors) ==== @@ -20,26 +20,26 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFuncti function f(x: T, y: U): T { return null; } var r1 = f(1, ''); - ~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 1. var r1b = f(1, ''); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 3. var f2 = (x: T, y: U): T => { return null; } var r2 = f2(1, ''); - ~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 1. var r2b = f2(1, ''); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 3. var f3: { (x: T, y: U): T; } var r3 = f3(1, ''); - ~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 1. var r3b = f3(1, ''); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 3. class C { @@ -48,10 +48,10 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFuncti } } var r4 = (new C()).f(1, ''); - ~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 1. var r4b = (new C()).f(1, ''); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 3. interface I { @@ -59,10 +59,10 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFuncti } var i: I; var r5 = i.f(1, ''); - ~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 1. var r5b = i.f(1, ''); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 3. class C2 { @@ -71,10 +71,10 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFuncti } } var r6 = (new C2()).f(1, ''); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var r6b = (new C2()).f(1, ''); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 3. interface I2 { @@ -82,8 +82,8 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callGenericFuncti } var i2: I2; var r7 = i2.f(1, ''); - ~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var r7b = i2.f(1, ''); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 3. \ No newline at end of file diff --git a/tests/baselines/reference/callNonGenericFunctionWithTypeArguments.errors.txt b/tests/baselines/reference/callNonGenericFunctionWithTypeArguments.errors.txt index b014eae0fd8..6bfb0c1113e 100644 --- a/tests/baselines/reference/callNonGenericFunctionWithTypeArguments.errors.txt +++ b/tests/baselines/reference/callNonGenericFunctionWithTypeArguments.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(5,9): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(8,10): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(11,10): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(18,10): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(24,10): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(31,10): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(37,10): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(5,11): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(8,13): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(11,13): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(18,22): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(24,14): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(31,23): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(37,15): error TS2558: Expected 0 type arguments, but got 1. tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(40,10): error TS2347: Untyped function calls may not accept type arguments. tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFunctionWithTypeArguments.ts(43,10): error TS2347: Untyped function calls may not accept type arguments. @@ -15,17 +15,17 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFun function f(x: number) { return null; } var r = f(1); - ~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var f2 = (x: number) => { return null; } var r2 = f2(1); - ~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var f3: { (x: number): any; } var r3 = f3(1); - ~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. class C { @@ -34,7 +34,7 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFun } } var r4 = (new C()).f(1); - ~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. interface I { @@ -42,7 +42,7 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFun } var i: I; var r5 = i.f(1); - ~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. class C2 { @@ -51,7 +51,7 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFun } } var r6 = (new C2()).f(1); - ~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. interface I2 { @@ -59,7 +59,7 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/callNonGenericFun } var i2: I2; var r7 = i2.f(1); - ~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var a; diff --git a/tests/baselines/reference/callWithWrongNumberOfTypeArguments.errors.txt b/tests/baselines/reference/callWithWrongNumberOfTypeArguments.errors.txt index e3fca9dff9c..c8553e8fc0d 100644 --- a/tests/baselines/reference/callWithWrongNumberOfTypeArguments.errors.txt +++ b/tests/baselines/reference/callWithWrongNumberOfTypeArguments.errors.txt @@ -1,14 +1,14 @@ -tests/cases/compiler/callWithWrongNumberOfTypeArguments.ts(3,1): error TS2558: Expected 2 type arguments, but got 1. -tests/cases/compiler/callWithWrongNumberOfTypeArguments.ts(5,1): error TS2558: Expected 2 type arguments, but got 3. +tests/cases/compiler/callWithWrongNumberOfTypeArguments.ts(3,3): error TS2558: Expected 2 type arguments, but got 1. +tests/cases/compiler/callWithWrongNumberOfTypeArguments.ts(5,3): error TS2558: Expected 2 type arguments, but got 3. ==== tests/cases/compiler/callWithWrongNumberOfTypeArguments.ts (2 errors) ==== function f() { } f(); - ~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 1. f(); f(); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 3. \ No newline at end of file diff --git a/tests/baselines/reference/constructorInvocationWithTooFewTypeArgs.errors.txt b/tests/baselines/reference/constructorInvocationWithTooFewTypeArgs.errors.txt index 265ce4686db..10dd4ad82fb 100644 --- a/tests/baselines/reference/constructorInvocationWithTooFewTypeArgs.errors.txt +++ b/tests/baselines/reference/constructorInvocationWithTooFewTypeArgs.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/constructorInvocationWithTooFewTypeArgs.ts(9,9): error TS2558: Expected 2 type arguments, but got 1. +tests/cases/compiler/constructorInvocationWithTooFewTypeArgs.ts(9,15): error TS2558: Expected 2 type arguments, but got 1. ==== tests/cases/compiler/constructorInvocationWithTooFewTypeArgs.ts (1 errors) ==== @@ -11,6 +11,6 @@ tests/cases/compiler/constructorInvocationWithTooFewTypeArgs.ts(9,9): error TS25 } var d = new D(); - ~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 1. \ No newline at end of file diff --git a/tests/baselines/reference/declFileEmitDeclarationsOnly.js b/tests/baselines/reference/declFileEmitDeclarationsOnly.js new file mode 100644 index 00000000000..78d9842fe88 --- /dev/null +++ b/tests/baselines/reference/declFileEmitDeclarationsOnly.js @@ -0,0 +1,26 @@ +//// [helloworld.ts] +const Log = { + info(msg: string) {} +} + +class HelloWorld { + constructor(private name: string) { + } + + public hello() { + Log.info(`Hello ${this.name}`); + } +} + + + + +//// [helloworld.d.ts] +declare const Log: { + info(msg: string): void; +}; +declare class HelloWorld { + private name; + constructor(name: string); + hello(): void; +} diff --git a/tests/baselines/reference/declFileEmitDeclarationsOnly.symbols b/tests/baselines/reference/declFileEmitDeclarationsOnly.symbols new file mode 100644 index 00000000000..e2a277fb603 --- /dev/null +++ b/tests/baselines/reference/declFileEmitDeclarationsOnly.symbols @@ -0,0 +1,29 @@ +=== tests/cases/compiler/helloworld.ts === +const Log = { +>Log : Symbol(Log, Decl(helloworld.ts, 0, 5)) + + info(msg: string) {} +>info : Symbol(info, Decl(helloworld.ts, 0, 13)) +>msg : Symbol(msg, Decl(helloworld.ts, 1, 7)) +} + +class HelloWorld { +>HelloWorld : Symbol(HelloWorld, Decl(helloworld.ts, 2, 1)) + + constructor(private name: string) { +>name : Symbol(HelloWorld.name, Decl(helloworld.ts, 5, 14)) + } + + public hello() { +>hello : Symbol(HelloWorld.hello, Decl(helloworld.ts, 6, 3)) + + Log.info(`Hello ${this.name}`); +>Log.info : Symbol(info, Decl(helloworld.ts, 0, 13)) +>Log : Symbol(Log, Decl(helloworld.ts, 0, 5)) +>info : Symbol(info, Decl(helloworld.ts, 0, 13)) +>this.name : Symbol(HelloWorld.name, Decl(helloworld.ts, 5, 14)) +>this : Symbol(HelloWorld, Decl(helloworld.ts, 2, 1)) +>name : Symbol(HelloWorld.name, Decl(helloworld.ts, 5, 14)) + } +} + diff --git a/tests/baselines/reference/declFileEmitDeclarationsOnly.types b/tests/baselines/reference/declFileEmitDeclarationsOnly.types new file mode 100644 index 00000000000..9a3cf8cfc70 --- /dev/null +++ b/tests/baselines/reference/declFileEmitDeclarationsOnly.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/helloworld.ts === +const Log = { +>Log : { info(msg: string): void; } +>{ info(msg: string) {}} : { info(msg: string): void; } + + info(msg: string) {} +>info : (msg: string) => void +>msg : string +} + +class HelloWorld { +>HelloWorld : HelloWorld + + constructor(private name: string) { +>name : string + } + + public hello() { +>hello : () => void + + Log.info(`Hello ${this.name}`); +>Log.info(`Hello ${this.name}`) : void +>Log.info : (msg: string) => void +>Log : { info(msg: string): void; } +>info : (msg: string) => void +>`Hello ${this.name}` : string +>this.name : string +>this : this +>name : string + } +} + diff --git a/tests/baselines/reference/declFileEmitDeclarationsOnlyError1.errors.txt b/tests/baselines/reference/declFileEmitDeclarationsOnlyError1.errors.txt new file mode 100644 index 00000000000..88a154cc508 --- /dev/null +++ b/tests/baselines/reference/declFileEmitDeclarationsOnlyError1.errors.txt @@ -0,0 +1,7 @@ +error TS5052: Option 'emitDeclarationsOnly' cannot be specified without specifying option 'declarations'. + + +!!! error TS5052: Option 'emitDeclarationsOnly' cannot be specified without specifying option 'declarations'. +==== tests/cases/compiler/hello.ts (0 errors) ==== + var hello = "yo!"; + \ No newline at end of file diff --git a/tests/baselines/reference/declFileEmitDeclarationsOnlyError1.symbols b/tests/baselines/reference/declFileEmitDeclarationsOnlyError1.symbols new file mode 100644 index 00000000000..52b2f9bbe64 --- /dev/null +++ b/tests/baselines/reference/declFileEmitDeclarationsOnlyError1.symbols @@ -0,0 +1,4 @@ +=== tests/cases/compiler/hello.ts === +var hello = "yo!"; +>hello : Symbol(hello, Decl(hello.ts, 0, 3)) + diff --git a/tests/baselines/reference/declFileEmitDeclarationsOnlyError1.types b/tests/baselines/reference/declFileEmitDeclarationsOnlyError1.types new file mode 100644 index 00000000000..e1603394d7c --- /dev/null +++ b/tests/baselines/reference/declFileEmitDeclarationsOnlyError1.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/hello.ts === +var hello = "yo!"; +>hello : string +>"yo!" : "yo!" + diff --git a/tests/baselines/reference/declFileEmitDeclarationsOnlyError2.errors.txt b/tests/baselines/reference/declFileEmitDeclarationsOnlyError2.errors.txt new file mode 100644 index 00000000000..7c067d83ba2 --- /dev/null +++ b/tests/baselines/reference/declFileEmitDeclarationsOnlyError2.errors.txt @@ -0,0 +1,9 @@ +error TS5052: Option 'emitDeclarationsOnly' cannot be specified without specifying option 'declarations'. +error TS5053: Option 'emitDeclarationsOnly' cannot be specified with option 'noEmit'. + + +!!! error TS5052: Option 'emitDeclarationsOnly' cannot be specified without specifying option 'declarations'. +!!! error TS5053: Option 'emitDeclarationsOnly' cannot be specified with option 'noEmit'. +==== tests/cases/compiler/hello.ts (0 errors) ==== + var hello = "yo!"; + \ No newline at end of file diff --git a/tests/baselines/reference/declFileEmitDeclarationsOnlyError2.symbols b/tests/baselines/reference/declFileEmitDeclarationsOnlyError2.symbols new file mode 100644 index 00000000000..52b2f9bbe64 --- /dev/null +++ b/tests/baselines/reference/declFileEmitDeclarationsOnlyError2.symbols @@ -0,0 +1,4 @@ +=== tests/cases/compiler/hello.ts === +var hello = "yo!"; +>hello : Symbol(hello, Decl(hello.ts, 0, 3)) + diff --git a/tests/baselines/reference/declFileEmitDeclarationsOnlyError2.types b/tests/baselines/reference/declFileEmitDeclarationsOnlyError2.types new file mode 100644 index 00000000000..e1603394d7c --- /dev/null +++ b/tests/baselines/reference/declFileEmitDeclarationsOnlyError2.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/hello.ts === +var hello = "yo!"; +>hello : string +>"yo!" : "yo!" + diff --git a/tests/baselines/reference/emitter.forAwait.es2015.js b/tests/baselines/reference/emitter.forAwait.es2015.js index 323d62f0ac8..6b6bdd739fd 100644 --- a/tests/baselines/reference/emitter.forAwait.es2015.js +++ b/tests/baselines/reference/emitter.forAwait.es2015.js @@ -24,6 +24,22 @@ async function* f4() { for await (x of y) { } } +//// [file5.ts] +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} +//// [file6.ts] +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} //// [file1.js] var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { @@ -161,3 +177,75 @@ function f4() { var e_1, _a; }); } +//// [file5.js] +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + 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.apply(thisArg, _arguments || [])).next()); + }); +}; +var __asyncValues = (this && this.__asyncValues) || function (o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator]; + return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator](); +}; +// https://github.com/Microsoft/TypeScript/issues/21363 +function f5() { + return __awaiter(this, void 0, void 0, function* () { + let y; + try { + outer: for (var y_1 = __asyncValues(y), y_1_1; y_1_1 = yield y_1.next(), !y_1_1.done;) { + const x = yield y_1_1.value; + continue outer; + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (y_1_1 && !y_1_1.done && (_a = y_1.return)) yield _a.call(y_1); + } + finally { if (e_1) throw e_1.error; } + } + var e_1, _a; + }); +} +//// [file6.js] +var __asyncValues = (this && this.__asyncValues) || function (o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator]; + return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator](); +}; +var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } +var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var g = generator.apply(thisArg, _arguments || []), i, q = []; + return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; + function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } + function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } + function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } + function fulfill(value) { resume("next", value); } + function reject(value) { resume("throw", value); } + function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } +}; +// https://github.com/Microsoft/TypeScript/issues/21363 +function f6() { + return __asyncGenerator(this, arguments, function* f6_1() { + let y; + try { + outer: for (var y_1 = __asyncValues(y), y_1_1; y_1_1 = yield __await(y_1.next()), !y_1_1.done;) { + const x = yield __await(y_1_1.value); + continue outer; + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (y_1_1 && !y_1_1.done && (_a = y_1.return)) yield __await(_a.call(y_1)); + } + finally { if (e_1) throw e_1.error; } + } + var e_1, _a; + }); +} diff --git a/tests/baselines/reference/emitter.forAwait.es2015.symbols b/tests/baselines/reference/emitter.forAwait.es2015.symbols index 6c4ed3b10e9..bc75908f601 100644 --- a/tests/baselines/reference/emitter.forAwait.es2015.symbols +++ b/tests/baselines/reference/emitter.forAwait.es2015.symbols @@ -48,3 +48,33 @@ async function* f4() { >y : Symbol(y, Decl(file4.ts, 1, 15)) } } +=== tests/cases/conformance/emitter/es2015/forAwait/file5.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { +>f5 : Symbol(f5, Decl(file5.ts, 0, 0)) + + let y: any; +>y : Symbol(y, Decl(file5.ts, 2, 7)) + + outer: for await (const x of y) { +>x : Symbol(x, Decl(file5.ts, 3, 27)) +>y : Symbol(y, Decl(file5.ts, 2, 7)) + + continue outer; + } +} +=== tests/cases/conformance/emitter/es2015/forAwait/file6.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { +>f6 : Symbol(f6, Decl(file6.ts, 0, 0)) + + let y: any; +>y : Symbol(y, Decl(file6.ts, 2, 7)) + + outer: for await (const x of y) { +>x : Symbol(x, Decl(file6.ts, 3, 27)) +>y : Symbol(y, Decl(file6.ts, 2, 7)) + + continue outer; + } +} diff --git a/tests/baselines/reference/emitter.forAwait.es2015.types b/tests/baselines/reference/emitter.forAwait.es2015.types index ac7321e43b4..e7d1c77f346 100644 --- a/tests/baselines/reference/emitter.forAwait.es2015.types +++ b/tests/baselines/reference/emitter.forAwait.es2015.types @@ -48,3 +48,37 @@ async function* f4() { >y : any } } +=== tests/cases/conformance/emitter/es2015/forAwait/file5.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { +>f5 : () => Promise + + let y: any; +>y : any + + outer: for await (const x of y) { +>outer : any +>x : any +>y : any + + continue outer; +>outer : any + } +} +=== tests/cases/conformance/emitter/es2015/forAwait/file6.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { +>f6 : () => AsyncIterableIterator + + let y: any; +>y : any + + outer: for await (const x of y) { +>outer : any +>x : any +>y : any + + continue outer; +>outer : any + } +} diff --git a/tests/baselines/reference/emitter.forAwait.es2017.js b/tests/baselines/reference/emitter.forAwait.es2017.js index 4b3770f02af..8eb21442558 100644 --- a/tests/baselines/reference/emitter.forAwait.es2017.js +++ b/tests/baselines/reference/emitter.forAwait.es2017.js @@ -24,6 +24,22 @@ async function* f4() { for await (x of y) { } } +//// [file5.ts] +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} +//// [file6.ts] +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} //// [file1.js] var __asyncValues = (this && this.__asyncValues) || function (o) { @@ -141,3 +157,65 @@ function f4() { var e_1, _a; }); } +//// [file5.js] +var __asyncValues = (this && this.__asyncValues) || function (o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator]; + return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator](); +}; +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { + let y; + try { + outer: for (var y_1 = __asyncValues(y), y_1_1; y_1_1 = await y_1.next(), !y_1_1.done;) { + const x = await y_1_1.value; + continue outer; + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (y_1_1 && !y_1_1.done && (_a = y_1.return)) await _a.call(y_1); + } + finally { if (e_1) throw e_1.error; } + } + var e_1, _a; +} +//// [file6.js] +var __asyncValues = (this && this.__asyncValues) || function (o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator]; + return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator](); +}; +var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } +var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var g = generator.apply(thisArg, _arguments || []), i, q = []; + return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; + function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } + function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } + function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } + function fulfill(value) { resume("next", value); } + function reject(value) { resume("throw", value); } + function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } +}; +// https://github.com/Microsoft/TypeScript/issues/21363 +function f6() { + return __asyncGenerator(this, arguments, function* f6_1() { + let y; + try { + outer: for (var y_1 = __asyncValues(y), y_1_1; y_1_1 = yield __await(y_1.next()), !y_1_1.done;) { + const x = yield __await(y_1_1.value); + continue outer; + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (y_1_1 && !y_1_1.done && (_a = y_1.return)) yield __await(_a.call(y_1)); + } + finally { if (e_1) throw e_1.error; } + } + var e_1, _a; + }); +} diff --git a/tests/baselines/reference/emitter.forAwait.es2017.symbols b/tests/baselines/reference/emitter.forAwait.es2017.symbols index a08e31f5553..184d26c1266 100644 --- a/tests/baselines/reference/emitter.forAwait.es2017.symbols +++ b/tests/baselines/reference/emitter.forAwait.es2017.symbols @@ -48,3 +48,33 @@ async function* f4() { >y : Symbol(y, Decl(file4.ts, 1, 15)) } } +=== tests/cases/conformance/emitter/es2017/forAwait/file5.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { +>f5 : Symbol(f5, Decl(file5.ts, 0, 0)) + + let y: any; +>y : Symbol(y, Decl(file5.ts, 2, 7)) + + outer: for await (const x of y) { +>x : Symbol(x, Decl(file5.ts, 3, 27)) +>y : Symbol(y, Decl(file5.ts, 2, 7)) + + continue outer; + } +} +=== tests/cases/conformance/emitter/es2017/forAwait/file6.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { +>f6 : Symbol(f6, Decl(file6.ts, 0, 0)) + + let y: any; +>y : Symbol(y, Decl(file6.ts, 2, 7)) + + outer: for await (const x of y) { +>x : Symbol(x, Decl(file6.ts, 3, 27)) +>y : Symbol(y, Decl(file6.ts, 2, 7)) + + continue outer; + } +} diff --git a/tests/baselines/reference/emitter.forAwait.es2017.types b/tests/baselines/reference/emitter.forAwait.es2017.types index 0d886cca4cc..f1dffdd280a 100644 --- a/tests/baselines/reference/emitter.forAwait.es2017.types +++ b/tests/baselines/reference/emitter.forAwait.es2017.types @@ -48,3 +48,37 @@ async function* f4() { >y : any } } +=== tests/cases/conformance/emitter/es2017/forAwait/file5.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { +>f5 : () => Promise + + let y: any; +>y : any + + outer: for await (const x of y) { +>outer : any +>x : any +>y : any + + continue outer; +>outer : any + } +} +=== tests/cases/conformance/emitter/es2017/forAwait/file6.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { +>f6 : () => AsyncIterableIterator + + let y: any; +>y : any + + outer: for await (const x of y) { +>outer : any +>x : any +>y : any + + continue outer; +>outer : any + } +} diff --git a/tests/baselines/reference/emitter.forAwait.es5.js b/tests/baselines/reference/emitter.forAwait.es5.js index 2b073a3f43a..b4ea4ddcf54 100644 --- a/tests/baselines/reference/emitter.forAwait.es5.js +++ b/tests/baselines/reference/emitter.forAwait.es5.js @@ -24,6 +24,22 @@ async function* f4() { for await (x of y) { } } +//// [file5.ts] +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} +//// [file6.ts] +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} //// [file1.js] var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { @@ -353,3 +369,169 @@ function f4() { }); }); } +//// [file5.js] +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + 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.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [0, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __asyncValues = (this && this.__asyncValues) || function (o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator]; + return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator](); +}; +// https://github.com/Microsoft/TypeScript/issues/21363 +function f5() { + return __awaiter(this, void 0, void 0, function () { + var y, y_1, y_1_1, x, e_1_1, e_1, _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _b.trys.push([0, 6, 7, 12]); + y_1 = __asyncValues(y); + _b.label = 1; + case 1: return [4 /*yield*/, y_1.next()]; + case 2: + if (!(y_1_1 = _b.sent(), !y_1_1.done)) return [3 /*break*/, 5]; + return [4 /*yield*/, y_1_1.value]; + case 3: + x = _b.sent(); + return [3 /*break*/, 4]; + case 4: return [3 /*break*/, 1]; + case 5: return [3 /*break*/, 12]; + case 6: + e_1_1 = _b.sent(); + e_1 = { error: e_1_1 }; + return [3 /*break*/, 12]; + case 7: + _b.trys.push([7, , 10, 11]); + if (!(y_1_1 && !y_1_1.done && (_a = y_1.return))) return [3 /*break*/, 9]; + return [4 /*yield*/, _a.call(y_1)]; + case 8: + _b.sent(); + _b.label = 9; + case 9: return [3 /*break*/, 11]; + case 10: + if (e_1) throw e_1.error; + return [7 /*endfinally*/]; + case 11: return [7 /*endfinally*/]; + case 12: return [2 /*return*/]; + } + }); + }); +} +//// [file6.js] +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [0, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __asyncValues = (this && this.__asyncValues) || function (o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator]; + return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator](); +}; +var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } +var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var g = generator.apply(thisArg, _arguments || []), i, q = []; + return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; + function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } + function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } + function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } + function fulfill(value) { resume("next", value); } + function reject(value) { resume("throw", value); } + function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } +}; +// https://github.com/Microsoft/TypeScript/issues/21363 +function f6() { + return __asyncGenerator(this, arguments, function f6_1() { + var y, y_1, y_1_1, x, e_1_1, e_1, _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _b.trys.push([0, 6, 7, 12]); + y_1 = __asyncValues(y); + _b.label = 1; + case 1: return [4 /*yield*/, __await(y_1.next())]; + case 2: + if (!(y_1_1 = _b.sent(), !y_1_1.done)) return [3 /*break*/, 5]; + return [4 /*yield*/, __await(y_1_1.value)]; + case 3: + x = _b.sent(); + return [3 /*break*/, 4]; + case 4: return [3 /*break*/, 1]; + case 5: return [3 /*break*/, 12]; + case 6: + e_1_1 = _b.sent(); + e_1 = { error: e_1_1 }; + return [3 /*break*/, 12]; + case 7: + _b.trys.push([7, , 10, 11]); + if (!(y_1_1 && !y_1_1.done && (_a = y_1.return))) return [3 /*break*/, 9]; + return [4 /*yield*/, __await(_a.call(y_1))]; + case 8: + _b.sent(); + _b.label = 9; + case 9: return [3 /*break*/, 11]; + case 10: + if (e_1) throw e_1.error; + return [7 /*endfinally*/]; + case 11: return [7 /*endfinally*/]; + case 12: return [2 /*return*/]; + } + }); + }); +} diff --git a/tests/baselines/reference/emitter.forAwait.es5.symbols b/tests/baselines/reference/emitter.forAwait.es5.symbols index 40c5562453c..05fb915c0fc 100644 --- a/tests/baselines/reference/emitter.forAwait.es5.symbols +++ b/tests/baselines/reference/emitter.forAwait.es5.symbols @@ -48,3 +48,33 @@ async function* f4() { >y : Symbol(y, Decl(file4.ts, 1, 15)) } } +=== tests/cases/conformance/emitter/es5/forAwait/file5.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { +>f5 : Symbol(f5, Decl(file5.ts, 0, 0)) + + let y: any; +>y : Symbol(y, Decl(file5.ts, 2, 7)) + + outer: for await (const x of y) { +>x : Symbol(x, Decl(file5.ts, 3, 27)) +>y : Symbol(y, Decl(file5.ts, 2, 7)) + + continue outer; + } +} +=== tests/cases/conformance/emitter/es5/forAwait/file6.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { +>f6 : Symbol(f6, Decl(file6.ts, 0, 0)) + + let y: any; +>y : Symbol(y, Decl(file6.ts, 2, 7)) + + outer: for await (const x of y) { +>x : Symbol(x, Decl(file6.ts, 3, 27)) +>y : Symbol(y, Decl(file6.ts, 2, 7)) + + continue outer; + } +} diff --git a/tests/baselines/reference/emitter.forAwait.es5.types b/tests/baselines/reference/emitter.forAwait.es5.types index 8c8f6dec723..fe0a49a9016 100644 --- a/tests/baselines/reference/emitter.forAwait.es5.types +++ b/tests/baselines/reference/emitter.forAwait.es5.types @@ -48,3 +48,37 @@ async function* f4() { >y : any } } +=== tests/cases/conformance/emitter/es5/forAwait/file5.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { +>f5 : () => Promise + + let y: any; +>y : any + + outer: for await (const x of y) { +>outer : any +>x : any +>y : any + + continue outer; +>outer : any + } +} +=== tests/cases/conformance/emitter/es5/forAwait/file6.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { +>f6 : () => AsyncIterableIterator + + let y: any; +>y : any + + outer: for await (const x of y) { +>outer : any +>x : any +>y : any + + continue outer; +>outer : any + } +} diff --git a/tests/baselines/reference/emitter.forAwait.esnext.js b/tests/baselines/reference/emitter.forAwait.esnext.js index 7a6c6837c9a..0042ae38fbd 100644 --- a/tests/baselines/reference/emitter.forAwait.esnext.js +++ b/tests/baselines/reference/emitter.forAwait.esnext.js @@ -24,6 +24,22 @@ async function* f4() { for await (x of y) { } } +//// [file5.ts] +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} +//// [file6.ts] +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} //// [file1.js] async function f1() { @@ -49,3 +65,19 @@ async function* f4() { for await (x of y) { } } +//// [file5.js] +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { + let y; + outer: for await (const x of y) { + continue outer; + } +} +//// [file6.js] +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { + let y; + outer: for await (const x of y) { + continue outer; + } +} diff --git a/tests/baselines/reference/emitter.forAwait.esnext.symbols b/tests/baselines/reference/emitter.forAwait.esnext.symbols index 137ebed0802..2910738102b 100644 --- a/tests/baselines/reference/emitter.forAwait.esnext.symbols +++ b/tests/baselines/reference/emitter.forAwait.esnext.symbols @@ -48,3 +48,33 @@ async function* f4() { >y : Symbol(y, Decl(file4.ts, 1, 15)) } } +=== tests/cases/conformance/emitter/esnext/forAwait/file5.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { +>f5 : Symbol(f5, Decl(file5.ts, 0, 0)) + + let y: any; +>y : Symbol(y, Decl(file5.ts, 2, 7)) + + outer: for await (const x of y) { +>x : Symbol(x, Decl(file5.ts, 3, 27)) +>y : Symbol(y, Decl(file5.ts, 2, 7)) + + continue outer; + } +} +=== tests/cases/conformance/emitter/esnext/forAwait/file6.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { +>f6 : Symbol(f6, Decl(file6.ts, 0, 0)) + + let y: any; +>y : Symbol(y, Decl(file6.ts, 2, 7)) + + outer: for await (const x of y) { +>x : Symbol(x, Decl(file6.ts, 3, 27)) +>y : Symbol(y, Decl(file6.ts, 2, 7)) + + continue outer; + } +} diff --git a/tests/baselines/reference/emitter.forAwait.esnext.types b/tests/baselines/reference/emitter.forAwait.esnext.types index ae52bd1080d..6339aeebeff 100644 --- a/tests/baselines/reference/emitter.forAwait.esnext.types +++ b/tests/baselines/reference/emitter.forAwait.esnext.types @@ -48,3 +48,37 @@ async function* f4() { >y : any } } +=== tests/cases/conformance/emitter/esnext/forAwait/file5.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { +>f5 : () => Promise + + let y: any; +>y : any + + outer: for await (const x of y) { +>outer : any +>x : any +>y : any + + continue outer; +>outer : any + } +} +=== tests/cases/conformance/emitter/esnext/forAwait/file6.ts === +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { +>f6 : () => AsyncIterableIterator + + let y: any; +>y : any + + outer: for await (const x of y) { +>outer : any +>x : any +>y : any + + continue outer; +>outer : any + } +} diff --git a/tests/baselines/reference/emptyTypeArgumentList.errors.txt b/tests/baselines/reference/emptyTypeArgumentList.errors.txt index 036f307447b..395c990a3d9 100644 --- a/tests/baselines/reference/emptyTypeArgumentList.errors.txt +++ b/tests/baselines/reference/emptyTypeArgumentList.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/emptyTypeArgumentList.ts(2,1): error TS2558: Expected 1 type arguments, but got 0. tests/cases/compiler/emptyTypeArgumentList.ts(2,4): error TS1099: Type argument list cannot be empty. +tests/cases/compiler/emptyTypeArgumentList.ts(2,5): error TS2558: Expected 1 type arguments, but got 0. ==== tests/cases/compiler/emptyTypeArgumentList.ts (2 errors) ==== function foo() { } foo<>(); - ~~~~~~~ -!!! error TS2558: Expected 1 type arguments, but got 0. ~~ -!!! error TS1099: Type argument list cannot be empty. \ No newline at end of file +!!! error TS1099: Type argument list cannot be empty. + +!!! error TS2558: Expected 1 type arguments, but got 0. \ No newline at end of file diff --git a/tests/baselines/reference/emptyTypeArgumentListWithNew.errors.txt b/tests/baselines/reference/emptyTypeArgumentListWithNew.errors.txt index 648aa7c6c50..92eb250291a 100644 --- a/tests/baselines/reference/emptyTypeArgumentListWithNew.errors.txt +++ b/tests/baselines/reference/emptyTypeArgumentListWithNew.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/emptyTypeArgumentListWithNew.ts(2,1): error TS2558: Expected 1 type arguments, but got 0. tests/cases/compiler/emptyTypeArgumentListWithNew.ts(2,8): error TS1099: Type argument list cannot be empty. +tests/cases/compiler/emptyTypeArgumentListWithNew.ts(2,9): error TS2558: Expected 1 type arguments, but got 0. ==== tests/cases/compiler/emptyTypeArgumentListWithNew.ts (2 errors) ==== class foo { } new foo<>(); - ~~~~~~~~~~~ -!!! error TS2558: Expected 1 type arguments, but got 0. ~~ -!!! error TS1099: Type argument list cannot be empty. \ No newline at end of file +!!! error TS1099: Type argument list cannot be empty. + +!!! error TS2558: Expected 1 type arguments, but got 0. \ No newline at end of file diff --git a/tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt b/tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt index 24940d173d0..f5e0550033d 100644 --- a/tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt +++ b/tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt @@ -21,9 +21,14 @@ tests/cases/compiler/excessPropertyCheckWithUnions.ts(49,35): error TS2322: Type Object literal may only specify known properties, and 'second' does not exist in type '{ a: 1; b: 1; first: string; }'. tests/cases/compiler/excessPropertyCheckWithUnions.ts(50,35): error TS2322: Type '{ a: 1; b: 1; first: string; third: string; }' is not assignable to type 'Overlapping'. Object literal may only specify known properties, and 'third' does not exist in type '{ a: 1; b: 1; first: string; }'. +tests/cases/compiler/excessPropertyCheckWithUnions.ts(66,9): error TS2322: Type '{ kind: "A"; n: { a: string; b: string; }; }' is not assignable to type 'AB'. + Type '{ kind: "A"; n: { a: string; b: string; }; }' is not assignable to type '{ kind: "A"; n: AN; }'. + Types of property 'n' are incompatible. + Type '{ a: string; b: string; }' is not assignable to type 'AN'. + Object literal may only specify known properties, and 'b' does not exist in type 'AN'. -==== tests/cases/compiler/excessPropertyCheckWithUnions.ts (9 errors) ==== +==== tests/cases/compiler/excessPropertyCheckWithUnions.ts (10 errors) ==== type ADT = { tag: "A", a1: string @@ -112,4 +117,29 @@ tests/cases/compiler/excessPropertyCheckWithUnions.ts(50,35): error TS2322: Type declare let t1: { a: any, b: any, c: any } | { c: any, d: any, e: any } let t2 = { ...t1 } t0 = t2 + + // Nested excess property checks work with discriminated unions + type AN = { a: string } | { c: string } + type BN = { b: string } + type AB = { kind: "A", n: AN } | { kind: "B", n: BN } + const abab: AB = { + kind: "A", + n: { + a: "a", + b: "b", // excess -- kind: "A" + ~~~~~~ +!!! error TS2322: Type '{ kind: "A"; n: { a: string; b: string; }; }' is not assignable to type 'AB'. +!!! error TS2322: Type '{ kind: "A"; n: { a: string; b: string; }; }' is not assignable to type '{ kind: "A"; n: AN; }'. +!!! error TS2322: Types of property 'n' are incompatible. +!!! error TS2322: Type '{ a: string; b: string; }' is not assignable to type 'AN'. +!!! error TS2322: Object literal may only specify known properties, and 'b' does not exist in type 'AN'. + } + } + const abac: AB = { + kind: "A", + n: { + a: "a", + c: "c", // ok -- kind: "A", an: { a: string } | { c: string } + } + } \ No newline at end of file diff --git a/tests/baselines/reference/excessPropertyCheckWithUnions.js b/tests/baselines/reference/excessPropertyCheckWithUnions.js index a20983e4b08..1ac4d7477d6 100644 --- a/tests/baselines/reference/excessPropertyCheckWithUnions.js +++ b/tests/baselines/reference/excessPropertyCheckWithUnions.js @@ -55,6 +55,25 @@ declare let t0: { a: any, b: any } | { d: any, e: any } declare let t1: { a: any, b: any, c: any } | { c: any, d: any, e: any } let t2 = { ...t1 } t0 = t2 + +// Nested excess property checks work with discriminated unions +type AN = { a: string } | { c: string } +type BN = { b: string } +type AB = { kind: "A", n: AN } | { kind: "B", n: BN } +const abab: AB = { + kind: "A", + n: { + a: "a", + b: "b", // excess -- kind: "A" + } +} +const abac: AB = { + kind: "A", + n: { + a: "a", + c: "c", // ok -- kind: "A", an: { a: string } | { c: string } + } +} //// [excessPropertyCheckWithUnions.js] @@ -89,3 +108,17 @@ over = { a: 1, b: 1, first: "ok", second: "error" }; over = { a: 1, b: 1, first: "ok", third: "error" }; var t2 = __assign({}, t1); t0 = t2; +var abab = { + kind: "A", + n: { + a: "a", + b: "b" + } +}; +var abac = { + kind: "A", + n: { + a: "a", + c: "c" + } +}; diff --git a/tests/baselines/reference/excessPropertyCheckWithUnions.symbols b/tests/baselines/reference/excessPropertyCheckWithUnions.symbols index 381681de384..beee933a2f1 100644 --- a/tests/baselines/reference/excessPropertyCheckWithUnions.symbols +++ b/tests/baselines/reference/excessPropertyCheckWithUnions.symbols @@ -167,3 +167,57 @@ t0 = t2 >t0 : Symbol(t0, Decl(excessPropertyCheckWithUnions.ts, 52, 11)) >t2 : Symbol(t2, Decl(excessPropertyCheckWithUnions.ts, 54, 3)) +// Nested excess property checks work with discriminated unions +type AN = { a: string } | { c: string } +>AN : Symbol(AN, Decl(excessPropertyCheckWithUnions.ts, 55, 7)) +>a : Symbol(a, Decl(excessPropertyCheckWithUnions.ts, 58, 11)) +>c : Symbol(c, Decl(excessPropertyCheckWithUnions.ts, 58, 27)) + +type BN = { b: string } +>BN : Symbol(BN, Decl(excessPropertyCheckWithUnions.ts, 58, 39)) +>b : Symbol(b, Decl(excessPropertyCheckWithUnions.ts, 59, 11)) + +type AB = { kind: "A", n: AN } | { kind: "B", n: BN } +>AB : Symbol(AB, Decl(excessPropertyCheckWithUnions.ts, 59, 23)) +>kind : Symbol(kind, Decl(excessPropertyCheckWithUnions.ts, 60, 11)) +>n : Symbol(n, Decl(excessPropertyCheckWithUnions.ts, 60, 22)) +>AN : Symbol(AN, Decl(excessPropertyCheckWithUnions.ts, 55, 7)) +>kind : Symbol(kind, Decl(excessPropertyCheckWithUnions.ts, 60, 34)) +>n : Symbol(n, Decl(excessPropertyCheckWithUnions.ts, 60, 45)) +>BN : Symbol(BN, Decl(excessPropertyCheckWithUnions.ts, 58, 39)) + +const abab: AB = { +>abab : Symbol(abab, Decl(excessPropertyCheckWithUnions.ts, 61, 5)) +>AB : Symbol(AB, Decl(excessPropertyCheckWithUnions.ts, 59, 23)) + + kind: "A", +>kind : Symbol(kind, Decl(excessPropertyCheckWithUnions.ts, 61, 18)) + + n: { +>n : Symbol(n, Decl(excessPropertyCheckWithUnions.ts, 62, 14)) + + a: "a", +>a : Symbol(a, Decl(excessPropertyCheckWithUnions.ts, 63, 8)) + + b: "b", // excess -- kind: "A" +>b : Symbol(b, Decl(excessPropertyCheckWithUnions.ts, 64, 15)) + } +} +const abac: AB = { +>abac : Symbol(abac, Decl(excessPropertyCheckWithUnions.ts, 68, 5)) +>AB : Symbol(AB, Decl(excessPropertyCheckWithUnions.ts, 59, 23)) + + kind: "A", +>kind : Symbol(kind, Decl(excessPropertyCheckWithUnions.ts, 68, 18)) + + n: { +>n : Symbol(n, Decl(excessPropertyCheckWithUnions.ts, 69, 14)) + + a: "a", +>a : Symbol(a, Decl(excessPropertyCheckWithUnions.ts, 70, 8)) + + c: "c", // ok -- kind: "A", an: { a: string } | { c: string } +>c : Symbol(c, Decl(excessPropertyCheckWithUnions.ts, 71, 15)) + } +} + diff --git a/tests/baselines/reference/excessPropertyCheckWithUnions.types b/tests/baselines/reference/excessPropertyCheckWithUnions.types index 4ef53e35ecc..41a8bb67a03 100644 --- a/tests/baselines/reference/excessPropertyCheckWithUnions.types +++ b/tests/baselines/reference/excessPropertyCheckWithUnions.types @@ -221,3 +221,67 @@ t0 = t2 >t0 : { a: any; b: any; } | { d: any; e: any; } >t2 : { a: any; b: any; c: any; } | { c: any; d: any; e: any; } +// Nested excess property checks work with discriminated unions +type AN = { a: string } | { c: string } +>AN : AN +>a : string +>c : string + +type BN = { b: string } +>BN : BN +>b : string + +type AB = { kind: "A", n: AN } | { kind: "B", n: BN } +>AB : AB +>kind : "A" +>n : AN +>AN : AN +>kind : "B" +>n : BN +>BN : BN + +const abab: AB = { +>abab : AB +>AB : AB +>{ kind: "A", n: { a: "a", b: "b", // excess -- kind: "A" }} : { kind: "A"; n: { a: string; b: string; }; } + + kind: "A", +>kind : "A" +>"A" : "A" + + n: { +>n : { a: string; b: string; } +>{ a: "a", b: "b", // excess -- kind: "A" } : { a: string; b: string; } + + a: "a", +>a : string +>"a" : "a" + + b: "b", // excess -- kind: "A" +>b : string +>"b" : "b" + } +} +const abac: AB = { +>abac : AB +>AB : AB +>{ kind: "A", n: { a: "a", c: "c", // ok -- kind: "A", an: { a: string } | { c: string } }} : { kind: "A"; n: { a: string; c: string; }; } + + kind: "A", +>kind : "A" +>"A" : "A" + + n: { +>n : { a: string; c: string; } +>{ a: "a", c: "c", // ok -- kind: "A", an: { a: string } | { c: string } } : { a: string; c: string; } + + a: "a", +>a : string +>"a" : "a" + + c: "c", // ok -- kind: "A", an: { a: string } | { c: string } +>c : string +>"c" : "c" + } +} + diff --git a/tests/baselines/reference/extractConstant/extractConstant_CaseClauseExpression.js b/tests/baselines/reference/extractConstant/extractConstant_CaseClauseExpression.js new file mode 100644 index 00000000000..0031ecdf0f9 --- /dev/null +++ b/tests/baselines/reference/extractConstant/extractConstant_CaseClauseExpression.js @@ -0,0 +1,13 @@ +// ==ORIGINAL== + +switch (1) { + case /*[#|*/1/*|]*/: + break; +} + +// ==SCOPE::Extract to constant in enclosing scope== +const newLocal = 1; +switch (1) { + case /*RENAME*/newLocal: + break; +} diff --git a/tests/baselines/reference/extractConstant/extractConstant_CaseClauseExpression.ts b/tests/baselines/reference/extractConstant/extractConstant_CaseClauseExpression.ts new file mode 100644 index 00000000000..0031ecdf0f9 --- /dev/null +++ b/tests/baselines/reference/extractConstant/extractConstant_CaseClauseExpression.ts @@ -0,0 +1,13 @@ +// ==ORIGINAL== + +switch (1) { + case /*[#|*/1/*|]*/: + break; +} + +// ==SCOPE::Extract to constant in enclosing scope== +const newLocal = 1; +switch (1) { + case /*RENAME*/newLocal: + break; +} diff --git a/tests/baselines/reference/genericCallbackInvokedInsideItsContainingFunction1.errors.txt b/tests/baselines/reference/genericCallbackInvokedInsideItsContainingFunction1.errors.txt index 7ff051bd63e..ff4c2235b49 100644 --- a/tests/baselines/reference/genericCallbackInvokedInsideItsContainingFunction1.errors.txt +++ b/tests/baselines/reference/genericCallbackInvokedInsideItsContainingFunction1.errors.txt @@ -1,32 +1,32 @@ -tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(2,14): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(2,16): error TS2558: Expected 0 type arguments, but got 1. tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(3,16): error TS2345: Argument of type '1' is not assignable to parameter of type 'T'. -tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(4,14): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(8,15): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(9,15): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(4,16): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(8,17): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(9,17): error TS2558: Expected 0 type arguments, but got 1. tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(12,17): error TS2345: Argument of type 'U' is not assignable to parameter of type 'T'. -tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(13,15): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(14,15): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(13,17): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(14,17): error TS2558: Expected 0 type arguments, but got 1. ==== tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts (8 errors) ==== function foo(x:T, y:U, f: (v: T) => U) { var r1 = f(1); - ~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var r2 = f(1); ~ !!! error TS2345: Argument of type '1' is not assignable to parameter of type 'T'. var r3 = f(null); - ~~~~~~~~~~~~ + ~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var r4 = f(null); var r11 = f(x); var r21 = f(x); - ~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var r31 = f(null); - ~~~~~~~~~~~~ + ~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var r41 = f(null); @@ -34,10 +34,10 @@ tests/cases/compiler/genericCallbackInvokedInsideItsContainingFunction1.ts(14,15 ~ !!! error TS2345: Argument of type 'U' is not assignable to parameter of type 'T'. var r22 = f(y); - ~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var r32 = f(null); - ~~~~~~~~~~~~ + ~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var r42 = f(null); } \ No newline at end of file diff --git a/tests/baselines/reference/genericDefaultsErrors.errors.txt b/tests/baselines/reference/genericDefaultsErrors.errors.txt index b1afd6f173b..e1dca77d958 100644 --- a/tests/baselines/reference/genericDefaultsErrors.errors.txt +++ b/tests/baselines/reference/genericDefaultsErrors.errors.txt @@ -3,8 +3,8 @@ tests/cases/compiler/genericDefaultsErrors.ts(4,59): error TS2344: Type 'T' does Type 'string' is not assignable to type 'number'. tests/cases/compiler/genericDefaultsErrors.ts(5,44): error TS2344: Type 'T' does not satisfy the constraint 'number'. tests/cases/compiler/genericDefaultsErrors.ts(6,39): error TS2344: Type 'number' does not satisfy the constraint 'T'. -tests/cases/compiler/genericDefaultsErrors.ts(10,1): error TS2558: Expected 2-3 type arguments, but got 1. -tests/cases/compiler/genericDefaultsErrors.ts(13,1): error TS2558: Expected 2-3 type arguments, but got 4. +tests/cases/compiler/genericDefaultsErrors.ts(10,5): error TS2558: Expected 2-3 type arguments, but got 1. +tests/cases/compiler/genericDefaultsErrors.ts(13,5): error TS2558: Expected 2-3 type arguments, but got 4. tests/cases/compiler/genericDefaultsErrors.ts(17,13): error TS2345: Argument of type '"a"' is not assignable to parameter of type 'number'. tests/cases/compiler/genericDefaultsErrors.ts(19,11): error TS2428: All declarations of 'i00' must have identical type parameters. tests/cases/compiler/genericDefaultsErrors.ts(20,11): error TS2428: All declarations of 'i00' must have identical type parameters. @@ -44,12 +44,12 @@ tests/cases/compiler/genericDefaultsErrors.ts(42,29): error TS2716: Type paramet declare function f11(): void; f11(); // ok f11<1>(); // error - ~~~~~~~~ + ~ !!! error TS2558: Expected 2-3 type arguments, but got 1. f11<1, 2>(); // ok f11<1, 2, 3>(); // ok f11<1, 2, 3, 4>(); // error - ~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~ !!! error TS2558: Expected 2-3 type arguments, but got 4. declare function f12(a?: U): void; diff --git a/tests/baselines/reference/genericWithOpenTypeParameters1.errors.txt b/tests/baselines/reference/genericWithOpenTypeParameters1.errors.txt index 9f8694d2fca..6a243650b1e 100644 --- a/tests/baselines/reference/genericWithOpenTypeParameters1.errors.txt +++ b/tests/baselines/reference/genericWithOpenTypeParameters1.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/genericWithOpenTypeParameters1.ts(7,40): error TS2345: Argument of type '1' is not assignable to parameter of type 'T'. -tests/cases/compiler/genericWithOpenTypeParameters1.ts(8,35): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/compiler/genericWithOpenTypeParameters1.ts(9,35): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/genericWithOpenTypeParameters1.ts(8,41): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/genericWithOpenTypeParameters1.ts(9,41): error TS2558: Expected 0 type arguments, but got 1. ==== tests/cases/compiler/genericWithOpenTypeParameters1.ts (3 errors) ==== @@ -14,10 +14,10 @@ tests/cases/compiler/genericWithOpenTypeParameters1.ts(9,35): error TS2558: Expe ~ !!! error TS2345: Argument of type '1' is not assignable to parameter of type 'T'. var f2 = (x: B) => { return x.foo(1); } // error - ~~~~~~~~~~~ + ~ !!! error TS2558: Expected 0 type arguments, but got 1. var f3 = (x: B) => { return x.foo(1); } // error - ~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var f4 = (x: B) => { return x.foo(1); } // no error \ No newline at end of file diff --git a/tests/baselines/reference/instantiateGenericClassWithWrongNumberOfTypeArguments.errors.txt b/tests/baselines/reference/instantiateGenericClassWithWrongNumberOfTypeArguments.errors.txt index 05cc1ee1cd0..a09b424b8e1 100644 --- a/tests/baselines/reference/instantiateGenericClassWithWrongNumberOfTypeArguments.errors.txt +++ b/tests/baselines/reference/instantiateGenericClassWithWrongNumberOfTypeArguments.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateGenericClassWithWrongNumberOfTypeArguments.ts(8,9): error TS2558: Expected 1 type arguments, but got 2. -tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateGenericClassWithWrongNumberOfTypeArguments.ts(16,9): error TS2558: Expected 2 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateGenericClassWithWrongNumberOfTypeArguments.ts(8,15): error TS2558: Expected 1 type arguments, but got 2. +tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateGenericClassWithWrongNumberOfTypeArguments.ts(16,15): error TS2558: Expected 2 type arguments, but got 1. ==== tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateGenericClassWithWrongNumberOfTypeArguments.ts (2 errors) ==== @@ -11,7 +11,7 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateGeneri } var c = new C(); - ~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~ !!! error TS2558: Expected 1 type arguments, but got 2. class D { @@ -21,5 +21,5 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateGeneri // BUG 794238 var d = new D(); - ~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 1. \ No newline at end of file diff --git a/tests/baselines/reference/instantiateNonGenericTypeWithTypeArguments.errors.txt b/tests/baselines/reference/instantiateNonGenericTypeWithTypeArguments.errors.txt index 196af18aa9a..5e70aa31249 100644 --- a/tests/baselines/reference/instantiateNonGenericTypeWithTypeArguments.errors.txt +++ b/tests/baselines/reference/instantiateNonGenericTypeWithTypeArguments.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateNonGenericTypeWithTypeArguments.ts(8,9): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateNonGenericTypeWithTypeArguments.ts(8,15): error TS2558: Expected 0 type arguments, but got 1. tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateNonGenericTypeWithTypeArguments.ts(11,9): error TS2350: Only a void function can be called with the 'new' keyword. -tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateNonGenericTypeWithTypeArguments.ts(11,9): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateNonGenericTypeWithTypeArguments.ts(11,17): error TS2558: Expected 0 type arguments, but got 1. tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateNonGenericTypeWithTypeArguments.ts(14,10): error TS2350: Only a void function can be called with the 'new' keyword. -tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateNonGenericTypeWithTypeArguments.ts(14,10): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateNonGenericTypeWithTypeArguments.ts(14,16): error TS2558: Expected 0 type arguments, but got 1. tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateNonGenericTypeWithTypeArguments.ts(18,10): error TS2347: Untyped function calls may not accept type arguments. @@ -15,21 +15,21 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiateNonGen } var c = new C(); - ~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. function Foo(): void { } var r = new Foo(); ~~~~~~~~~~~~~~~~~ !!! error TS2350: Only a void function can be called with the 'new' keyword. - ~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var f: { (): void }; var r2 = new f(); ~~~~~~~~~~~~~~~ !!! error TS2350: Only a void function can be called with the 'new' keyword. - ~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var a: any; diff --git a/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt b/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt index 9b95b143d64..f96dc69ee33 100644 --- a/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt +++ b/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt @@ -1,7 +1,7 @@ tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(10,30): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. Type 'string | number' is not assignable to type 'number'. Type 'string' is not assignable to type 'number'. -tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,11): error TS2558: Expected 2 type arguments, but got 1. +tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,15): error TS2558: Expected 2 type arguments, but got 1. ==== tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts (2 errors) ==== @@ -20,6 +20,6 @@ tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,11): e !!! error TS2345: Type 'string | number' is not assignable to type 'number'. !!! error TS2345: Type 'string' is not assignable to type 'number'. var r7b = map([1, ""], (x) => x.toString()); // error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 2 type arguments, but got 1. var r8 = map([1, ""], (x) => x.toString()); \ No newline at end of file diff --git a/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.js b/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.js new file mode 100644 index 00000000000..77b1b5f8ff4 --- /dev/null +++ b/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.js @@ -0,0 +1,60 @@ +//// [tests/cases/compiler/moduleDeclarationExportStarShadowingGlobalIsNameable.ts] //// + +//// [index.ts] +export * from "./account"; + +//// [account.ts] +export interface Account { + myAccNum: number; +} +interface Account2 { + myAccNum: number; +} +export { Account2 as Acc }; + +//// [index.ts] +declare global { + interface Account { + someProp: number; + } + interface Acc { + someProp: number; + } +} +import * as model from "./model"; +export const func = (account: model.Account, acc2: model.Acc) => {}; + + +//// [account.js] +"use strict"; +exports.__esModule = true; +//// [index.js] +"use strict"; +exports.__esModule = true; +//// [index.js] +"use strict"; +exports.__esModule = true; +exports.func = function (account, acc2) { }; + + +//// [account.d.ts] +export interface Account { + myAccNum: number; +} +interface Account2 { + myAccNum: number; +} +export { Account2 as Acc }; +//// [index.d.ts] +export * from "./account"; +//// [index.d.ts] +declare global { + interface Account { + someProp: number; + } + interface Acc { + someProp: number; + } +} +import * as model from "./model"; +export declare const func: (account: model.Account, acc2: model.Acc) => void; diff --git a/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.symbols b/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.symbols new file mode 100644 index 00000000000..add5fce7476 --- /dev/null +++ b/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.symbols @@ -0,0 +1,49 @@ +=== tests/cases/compiler/model/index.ts === +export * from "./account"; +No type information for this code. +No type information for this code.=== tests/cases/compiler/model/account.ts === +export interface Account { +>Account : Symbol(Account, Decl(account.ts, 0, 0)) + + myAccNum: number; +>myAccNum : Symbol(Account.myAccNum, Decl(account.ts, 0, 26)) +} +interface Account2 { +>Account2 : Symbol(Account2, Decl(account.ts, 2, 1)) + + myAccNum: number; +>myAccNum : Symbol(Account2.myAccNum, Decl(account.ts, 3, 20)) +} +export { Account2 as Acc }; +>Account2 : Symbol(Acc, Decl(account.ts, 6, 8)) +>Acc : Symbol(Acc, Decl(account.ts, 6, 8)) + +=== tests/cases/compiler/index.ts === +declare global { +>global : Symbol(global, Decl(index.ts, 0, 0)) + + interface Account { +>Account : Symbol(Account, Decl(index.ts, 0, 16)) + + someProp: number; +>someProp : Symbol(Account.someProp, Decl(index.ts, 1, 23)) + } + interface Acc { +>Acc : Symbol(Acc, Decl(index.ts, 3, 5)) + + someProp: number; +>someProp : Symbol(Acc.someProp, Decl(index.ts, 4, 19)) + } +} +import * as model from "./model"; +>model : Symbol(model, Decl(index.ts, 8, 6)) + +export const func = (account: model.Account, acc2: model.Acc) => {}; +>func : Symbol(func, Decl(index.ts, 9, 12)) +>account : Symbol(account, Decl(index.ts, 9, 21)) +>model : Symbol(model, Decl(index.ts, 8, 6)) +>Account : Symbol(model.Account, Decl(account.ts, 0, 0)) +>acc2 : Symbol(acc2, Decl(index.ts, 9, 44)) +>model : Symbol(model, Decl(index.ts, 8, 6)) +>Acc : Symbol(model.Acc, Decl(account.ts, 6, 8)) + diff --git a/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.types b/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.types new file mode 100644 index 00000000000..af27f7e3678 --- /dev/null +++ b/tests/baselines/reference/moduleDeclarationExportStarShadowingGlobalIsNameable.types @@ -0,0 +1,50 @@ +=== tests/cases/compiler/model/index.ts === +export * from "./account"; +No type information for this code. +No type information for this code.=== tests/cases/compiler/model/account.ts === +export interface Account { +>Account : Account + + myAccNum: number; +>myAccNum : number +} +interface Account2 { +>Account2 : Account2 + + myAccNum: number; +>myAccNum : number +} +export { Account2 as Acc }; +>Account2 : any +>Acc : any + +=== tests/cases/compiler/index.ts === +declare global { +>global : any + + interface Account { +>Account : Account + + someProp: number; +>someProp : number + } + interface Acc { +>Acc : Acc + + someProp: number; +>someProp : number + } +} +import * as model from "./model"; +>model : typeof model + +export const func = (account: model.Account, acc2: model.Acc) => {}; +>func : (account: model.Account, acc2: model.Acc) => void +>(account: model.Account, acc2: model.Acc) => {} : (account: model.Account, acc2: model.Acc) => void +>account : model.Account +>model : any +>Account : model.Account +>acc2 : model.Acc +>model : any +>Acc : model.Acc + diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt new file mode 100644 index 00000000000..b2fea589cb1 --- /dev/null +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt @@ -0,0 +1,92 @@ +tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(6,8): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. + Type 'undefined' is not assignable to type 'number'. +tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(16,7): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. + Type 'undefined' is not assignable to type 'number'. +tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(21,7): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. + Type 'undefined' is not assignable to type 'number'. +tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(31,8): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. + Type 'undefined' is not assignable to type 'number'. +tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(45,10): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. + Type 'undefined' is not assignable to type 'number'. +tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(53,11): error TS2345: Argument of type 'number | null' is not assignable to parameter of type 'number | undefined'. + Type 'null' is not assignable to type 'number | undefined'. + + +==== tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts (6 errors) ==== + // https://github.com/Microsoft/TypeScript/issues/17080 + + declare function f(a:number,b:number): void; + + function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { + f(a, b) + ~ +!!! error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. +!!! error TS2345: Type 'undefined' is not assignable to type 'number'. + // error + } + + function func2( {a, b = 3}: {a: number, b?:number} = {a: 1,b: 2} ) { + f(a, b) + // no error + } + + function func3( {a, b}: {a: number, b?: number} = {a: 1} ) { + f(a,b) + ~ +!!! error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. +!!! error TS2345: Type 'undefined' is not assignable to type 'number'. + // error + } + + function func4( {a: {b, c}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { + f(b,c) + ~ +!!! error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. +!!! error TS2345: Type 'undefined' is not assignable to type 'number'. + // error + } + + function func5({a: {b, c = 4}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { + f(b, c) + // no error + } + + function func6( {a: {b, c} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1,c: 2}, d: 3} ) { + f(b, c) + ~ +!!! error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. +!!! error TS2345: Type 'undefined' is not assignable to type 'number'. + // error + } + + function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1, c: 2}, d: 3} ) { + f(b, c) + // no error + } + + interface Foo { + readonly bar?: number; + } + + function performFoo({ bar }: Foo = {}) { + useBar(bar); + ~~~ +!!! error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. +!!! error TS2345: Type 'undefined' is not assignable to type 'number'. + } + + declare function useBar(bar: number): void; + + performFoo(); + + function performFoo2({ bar = null }: Foo = {}) { + useBar2(bar); + ~~~ +!!! error TS2345: Argument of type 'number | null' is not assignable to parameter of type 'number | undefined'. +!!! error TS2345: Type 'null' is not assignable to type 'number | undefined'. + } + + declare function useBar2(bar: number | undefined): void; + + performFoo2(); + \ No newline at end of file diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js new file mode 100644 index 00000000000..642f00a4f50 --- /dev/null +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js @@ -0,0 +1,108 @@ +//// [optionalParameterInDestructuringWithInitializer.ts] +// https://github.com/Microsoft/TypeScript/issues/17080 + +declare function f(a:number,b:number): void; + +function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { + f(a, b) + // error +} + +function func2( {a, b = 3}: {a: number, b?:number} = {a: 1,b: 2} ) { + f(a, b) + // no error +} + +function func3( {a, b}: {a: number, b?: number} = {a: 1} ) { + f(a,b) + // error +} + +function func4( {a: {b, c}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { + f(b,c) + // error +} + +function func5({a: {b, c = 4}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { + f(b, c) + // no error +} + +function func6( {a: {b, c} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1,c: 2}, d: 3} ) { + f(b, c) + // error +} + +function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1, c: 2}, d: 3} ) { + f(b, c) + // no error +} + +interface Foo { + readonly bar?: number; +} + +function performFoo({ bar }: Foo = {}) { + useBar(bar); +} + +declare function useBar(bar: number): void; + +performFoo(); + +function performFoo2({ bar = null }: Foo = {}) { + useBar2(bar); +} + +declare function useBar2(bar: number | undefined): void; + +performFoo2(); + + +//// [optionalParameterInDestructuringWithInitializer.js] +// https://github.com/Microsoft/TypeScript/issues/17080 +function func1(_a) { + var _b = _a === void 0 ? { a: 1, b: 2 } : _a, a = _b.a, b = _b.b; + f(a, b); + // error +} +function func2(_a) { + var _b = _a === void 0 ? { a: 1, b: 2 } : _a, a = _b.a, _c = _b.b, b = _c === void 0 ? 3 : _c; + f(a, b); + // no error +} +function func3(_a) { + var _b = _a === void 0 ? { a: 1 } : _a, a = _b.a, b = _b.b; + f(a, b); + // error +} +function func4(_a) { + var _b = _a === void 0 ? { a: { b: 1, c: 2 }, d: 3 } : _a, _c = _b.a, b = _c.b, c = _c.c, d = _b.d; + f(b, c); + // error +} +function func5(_a) { + var _b = _a === void 0 ? { a: { b: 1, c: 2 }, d: 3 } : _a, _c = _b.a, b = _c.b, _d = _c.c, c = _d === void 0 ? 4 : _d, d = _b.d; + f(b, c); + // no error +} +function func6(_a) { + var _b = _a === void 0 ? { a: { b: 1, c: 2 }, d: 3 } : _a, _c = _b.a, _d = _c === void 0 ? { b: 4, c: 5 } : _c, b = _d.b, c = _d.c, d = _b.d; + f(b, c); + // error +} +function func7(_a) { + var _b = _a === void 0 ? { a: { b: 1, c: 2 }, d: 3 } : _a, _c = _b.a, _d = _c === void 0 ? { b: 4, c: 5 } : _c, b = _d.b, _e = _d.c, c = _e === void 0 ? 6 : _e, d = _b.d; + f(b, c); + // no error +} +function performFoo(_a) { + var bar = (_a === void 0 ? {} : _a).bar; + useBar(bar); +} +performFoo(); +function performFoo2(_a) { + var _b = (_a === void 0 ? {} : _a).bar, bar = _b === void 0 ? null : _b; + useBar2(bar); +} +performFoo2(); diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols new file mode 100644 index 00000000000..6d4cf484d92 --- /dev/null +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols @@ -0,0 +1,195 @@ +=== tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts === +// https://github.com/Microsoft/TypeScript/issues/17080 + +declare function f(a:number,b:number): void; +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 2, 19)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 2, 28)) + +function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { +>func1 : Symbol(func1, Decl(optionalParameterInDestructuringWithInitializer.ts, 2, 44)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 17)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 19)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 25)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 35)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 51)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 56)) + + f(a, b) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 17)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 19)) + + // error +} + +function func2( {a, b = 3}: {a: number, b?:number} = {a: 1,b: 2} ) { +>func2 : Symbol(func2, Decl(optionalParameterInDestructuringWithInitializer.ts, 7, 1)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 17)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 19)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 29)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 39)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 54)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 59)) + + f(a, b) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 17)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 19)) + + // no error +} + +function func3( {a, b}: {a: number, b?: number} = {a: 1} ) { +>func3 : Symbol(func3, Decl(optionalParameterInDestructuringWithInitializer.ts, 12, 1)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 14, 17)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 14, 19)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 14, 25)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 14, 35)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 14, 51)) + + f(a,b) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 14, 17)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 14, 19)) + + // error +} + +function func4( {a: {b, c}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { +>func4 : Symbol(func4, Decl(optionalParameterInDestructuringWithInitializer.ts, 17, 1)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 33)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 21)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 23)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 27)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 33)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 37)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 47)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 59)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 73)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 77)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 82)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 88)) + + f(b,c) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 21)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 23)) + + // error +} + +function func5({a: {b, c = 4}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { +>func5 : Symbol(func5, Decl(optionalParameterInDestructuringWithInitializer.ts, 22, 1)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 36)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 20)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 22)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 30)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 36)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 40)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 50)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 62)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 76)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 80)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 85)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 91)) + + f(b, c) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 20)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 22)) + + // no error +} + +function func6( {a: {b, c} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1,c: 2}, d: 3} ) { +>func6 : Symbol(func6, Decl(optionalParameterInDestructuringWithInitializer.ts, 27, 1)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 48)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 21)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 23)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 30)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 35)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 42)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 48)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 52)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 62)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 75)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 90)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 94)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 99)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 105)) + + f(b, c) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 21)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 23)) + + // error +} + +function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1, c: 2}, d: 3} ) { +>func7 : Symbol(func7, Decl(optionalParameterInDestructuringWithInitializer.ts, 32, 1)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 52)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 21)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 23)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 34)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 39)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 46)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 52)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 56)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 66)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 79)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 94)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 98)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 103)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 110)) + + f(b, c) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 21)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 23)) + + // no error +} + +interface Foo { +>Foo : Symbol(Foo, Decl(optionalParameterInDestructuringWithInitializer.ts, 37, 1)) + + readonly bar?: number; +>bar : Symbol(Foo.bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 39, 15)) +} + +function performFoo({ bar }: Foo = {}) { +>performFoo : Symbol(performFoo, Decl(optionalParameterInDestructuringWithInitializer.ts, 41, 1)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 43, 21)) +>Foo : Symbol(Foo, Decl(optionalParameterInDestructuringWithInitializer.ts, 37, 1)) + + useBar(bar); +>useBar : Symbol(useBar, Decl(optionalParameterInDestructuringWithInitializer.ts, 45, 1)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 43, 21)) +} + +declare function useBar(bar: number): void; +>useBar : Symbol(useBar, Decl(optionalParameterInDestructuringWithInitializer.ts, 45, 1)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 47, 24)) + +performFoo(); +>performFoo : Symbol(performFoo, Decl(optionalParameterInDestructuringWithInitializer.ts, 41, 1)) + +function performFoo2({ bar = null }: Foo = {}) { +>performFoo2 : Symbol(performFoo2, Decl(optionalParameterInDestructuringWithInitializer.ts, 49, 13)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 51, 22)) +>Foo : Symbol(Foo, Decl(optionalParameterInDestructuringWithInitializer.ts, 37, 1)) + + useBar2(bar); +>useBar2 : Symbol(useBar2, Decl(optionalParameterInDestructuringWithInitializer.ts, 53, 1)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 51, 22)) +} + +declare function useBar2(bar: number | undefined): void; +>useBar2 : Symbol(useBar2, Decl(optionalParameterInDestructuringWithInitializer.ts, 53, 1)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 55, 25)) + +performFoo2(); +>performFoo2 : Symbol(performFoo2, Decl(optionalParameterInDestructuringWithInitializer.ts, 49, 13)) + diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types new file mode 100644 index 00000000000..26110e71051 --- /dev/null +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types @@ -0,0 +1,246 @@ +=== tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts === +// https://github.com/Microsoft/TypeScript/issues/17080 + +declare function f(a:number,b:number): void; +>f : (a: number, b: number) => void +>a : number +>b : number + +function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { +>func1 : ({ a, b }?: { a: number; b?: number | undefined; }) => void +>a : number +>b : number | undefined +>a : number +>b : number | undefined +>{a: 1, b: 2} : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>2 : 2 + + f(a, b) +>f(a, b) : void +>f : (a: number, b: number) => void +>a : number +>b : number | undefined + + // error +} + +function func2( {a, b = 3}: {a: number, b?:number} = {a: 1,b: 2} ) { +>func2 : ({ a, b }?: { a: number; b?: number | undefined; }) => void +>a : number +>b : number +>3 : 3 +>a : number +>b : number | undefined +>{a: 1,b: 2} : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>2 : 2 + + f(a, b) +>f(a, b) : void +>f : (a: number, b: number) => void +>a : number +>b : number + + // no error +} + +function func3( {a, b}: {a: number, b?: number} = {a: 1} ) { +>func3 : ({ a, b }?: { a: number; b?: number | undefined; }) => void +>a : number +>b : number | undefined +>a : number +>b : number | undefined +>{a: 1} : { a: number; } +>a : number +>1 : 1 + + f(a,b) +>f(a,b) : void +>f : (a: number, b: number) => void +>a : number +>b : number | undefined + + // error +} + +function func4( {a: {b, c}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { +>func4 : ({ a: { b, c }, d }?: { a: { b: number; c?: number | undefined; }; d: number; }) => void +>a : any +>b : number +>c : number | undefined +>d : number +>a : { b: number; c?: number | undefined; } +>b : number +>c : number | undefined +>d : number +>{a: {b: 1,c: 2},d: 3} : { a: { b: number; c: number; }; d: number; } +>a : { b: number; c: number; } +>{b: 1,c: 2} : { b: number; c: number; } +>b : number +>1 : 1 +>c : number +>2 : 2 +>d : number +>3 : 3 + + f(b,c) +>f(b,c) : void +>f : (a: number, b: number) => void +>b : number +>c : number | undefined + + // error +} + +function func5({a: {b, c = 4}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { +>func5 : ({ a: { b, c }, d }?: { a: { b: number; c?: number | undefined; }; d: number; }) => void +>a : any +>b : number +>c : number +>4 : 4 +>d : number +>a : { b: number; c?: number | undefined; } +>b : number +>c : number | undefined +>d : number +>{a: {b: 1,c: 2},d: 3} : { a: { b: number; c: number; }; d: number; } +>a : { b: number; c: number; } +>{b: 1,c: 2} : { b: number; c: number; } +>b : number +>1 : 1 +>c : number +>2 : 2 +>d : number +>3 : 3 + + f(b, c) +>f(b, c) : void +>f : (a: number, b: number) => void +>b : number +>c : number + + // no error +} + +function func6( {a: {b, c} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1,c: 2}, d: 3} ) { +>func6 : ({ a: { b, c }, d }?: { a: { b: number; c?: number | undefined; }; d: number; }) => void +>a : any +>b : number +>c : number | undefined +>{b: 4, c: 5} : { b: number; c: number; } +>b : number +>4 : 4 +>c : number +>5 : 5 +>d : number +>a : { b: number; c?: number | undefined; } +>b : number +>c : number | undefined +>d : number +>{a: {b: 1,c: 2}, d: 3} : { a: { b: number; c: number; }; d: number; } +>a : { b: number; c: number; } +>{b: 1,c: 2} : { b: number; c: number; } +>b : number +>1 : 1 +>c : number +>2 : 2 +>d : number +>3 : 3 + + f(b, c) +>f(b, c) : void +>f : (a: number, b: number) => void +>b : number +>c : number | undefined + + // error +} + +function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1, c: 2}, d: 3} ) { +>func7 : ({ a: { b, c }, d }?: { a: { b: number; c?: number | undefined; }; d: number; }) => void +>a : any +>b : number +>c : number +>6 : 6 +>{b: 4, c: 5} : { b: number; c?: number; } +>b : number +>4 : 4 +>c : number +>5 : 5 +>d : number +>a : { b: number; c?: number | undefined; } +>b : number +>c : number | undefined +>d : number +>{a: {b: 1, c: 2}, d: 3} : { a: { b: number; c: number; }; d: number; } +>a : { b: number; c: number; } +>{b: 1, c: 2} : { b: number; c: number; } +>b : number +>1 : 1 +>c : number +>2 : 2 +>d : number +>3 : 3 + + f(b, c) +>f(b, c) : void +>f : (a: number, b: number) => void +>b : number +>c : number + + // no error +} + +interface Foo { +>Foo : Foo + + readonly bar?: number; +>bar : number | undefined +} + +function performFoo({ bar }: Foo = {}) { +>performFoo : ({ bar }?: Foo) => void +>bar : number | undefined +>Foo : Foo +>{} : {} + + useBar(bar); +>useBar(bar) : void +>useBar : (bar: number) => void +>bar : number | undefined +} + +declare function useBar(bar: number): void; +>useBar : (bar: number) => void +>bar : number + +performFoo(); +>performFoo() : void +>performFoo : ({ bar }?: Foo) => void + +function performFoo2({ bar = null }: Foo = {}) { +>performFoo2 : ({ bar }?: Foo) => void +>bar : number | null +>null : null +>Foo : Foo +>{} : {} + + useBar2(bar); +>useBar2(bar) : void +>useBar2 : (bar: number | undefined) => void +>bar : number | null +} + +declare function useBar2(bar: number | undefined): void; +>useBar2 : (bar: number | undefined) => void +>bar : number | undefined + +performFoo2(); +>performFoo2() : void +>performFoo2 : ({ bar }?: Foo) => void + diff --git a/tests/baselines/reference/overloadResolution.errors.txt b/tests/baselines/reference/overloadResolution.errors.txt index 37cea935e66..6710f697b3c 100644 --- a/tests/baselines/reference/overloadResolution.errors.txt +++ b/tests/baselines/reference/overloadResolution.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(27,5): error TS2345: Argument of type '{}' is not assignable to parameter of type 'number'. tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(41,11): error TS2345: Argument of type '""' is not assignable to parameter of type 'number'. -tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(63,1): error TS2558: Expected 1-3 type arguments, but got 4. +tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(63,5): error TS2558: Expected 1-3 type arguments, but got 4. tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(70,21): error TS2345: Argument of type '3' is not assignable to parameter of type 'string'. tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(71,21): error TS2345: Argument of type '""' is not assignable to parameter of type 'number'. tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(81,5): error TS2344: Type 'boolean' does not satisfy the constraint 'number'. @@ -78,7 +78,7 @@ tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(91,22): // Generic overloads with differing arity called with type argument count that doesn't match any overload fn3(); // Error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 1-3 type arguments, but got 4. // Generic overloads with constraints called with type arguments that satisfy the constraints diff --git a/tests/baselines/reference/overloadResolutionClassConstructors.errors.txt b/tests/baselines/reference/overloadResolutionClassConstructors.errors.txt index 92f3a7cfa90..cfbc2605559 100644 --- a/tests/baselines/reference/overloadResolutionClassConstructors.errors.txt +++ b/tests/baselines/reference/overloadResolutionClassConstructors.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(27,9): error TS2345: Argument of type '{}' is not assignable to parameter of type 'number'. -tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(60,1): error TS2558: Expected 3 type arguments, but got 1. -tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(61,1): error TS2558: Expected 3 type arguments, but got 2. -tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(65,1): error TS2558: Expected 3 type arguments, but got 4. +tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(60,9): error TS2558: Expected 3 type arguments, but got 1. +tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(61,9): error TS2558: Expected 3 type arguments, but got 2. +tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(65,9): error TS2558: Expected 3 type arguments, but got 4. tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(73,25): error TS2345: Argument of type '3' is not assignable to parameter of type 'string'. tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(74,9): error TS2344: Type 'number' does not satisfy the constraint 'string'. tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstructors.ts(75,9): error TS2344: Type 'number' does not satisfy the constraint 'string'. @@ -77,16 +77,16 @@ tests/cases/conformance/expressions/functionCalls/overloadResolutionClassConstru // Generic overloads with differing arity called with type arguments matching each overload type parameter count new fn3(4); // Error - ~~~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 3 type arguments, but got 1. new fn3('', '', ''); // Error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~ !!! error TS2558: Expected 3 type arguments, but got 2. new fn3('', '', 3); // Generic overloads with differing arity called with type argument count that doesn't match any overload new fn3(); // Error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 3 type arguments, but got 4. // Generic overloads with constraints called with type arguments that satisfy the constraints diff --git a/tests/baselines/reference/overloadResolutionConstructors.errors.txt b/tests/baselines/reference/overloadResolutionConstructors.errors.txt index 9b09992228e..fe1c955651b 100644 --- a/tests/baselines/reference/overloadResolutionConstructors.errors.txt +++ b/tests/baselines/reference/overloadResolutionConstructors.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(27,9): error TS2345: Argument of type '{}' is not assignable to parameter of type 'number'. tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(43,15): error TS2345: Argument of type '""' is not assignable to parameter of type 'number'. -tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(67,1): error TS2558: Expected 1-3 type arguments, but got 4. +tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(67,9): error TS2558: Expected 1-3 type arguments, but got 4. tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(77,25): error TS2345: Argument of type '3' is not assignable to parameter of type 'string'. tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(78,25): error TS2345: Argument of type '""' is not assignable to parameter of type 'number'. tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(88,9): error TS2344: Type 'boolean' does not satisfy the constraint 'number'. @@ -82,7 +82,7 @@ tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors // Generic overloads with differing arity called with type argument count that doesn't match any overload new fn3(); // Error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 1-3 type arguments, but got 4. // Generic overloads with constraints called with type arguments that satisfy the constraints diff --git a/tests/baselines/reference/overloadsAndTypeArgumentArityErrors.errors.txt b/tests/baselines/reference/overloadsAndTypeArgumentArityErrors.errors.txt index 52bcaaf790b..45a5616d188 100644 --- a/tests/baselines/reference/overloadsAndTypeArgumentArityErrors.errors.txt +++ b/tests/baselines/reference/overloadsAndTypeArgumentArityErrors.errors.txt @@ -1,6 +1,6 @@ -tests/cases/compiler/overloadsAndTypeArgumentArityErrors.ts(5,1): error TS2558: Expected 0-2 type arguments, but got 3. +tests/cases/compiler/overloadsAndTypeArgumentArityErrors.ts(5,11): error TS2558: Expected 0-2 type arguments, but got 3. tests/cases/compiler/overloadsAndTypeArgumentArityErrors.ts(6,1): error TS2350: Only a void function can be called with the 'new' keyword. -tests/cases/compiler/overloadsAndTypeArgumentArityErrors.ts(6,1): error TS2558: Expected 0-2 type arguments, but got 3. +tests/cases/compiler/overloadsAndTypeArgumentArityErrors.ts(6,15): error TS2558: Expected 0-2 type arguments, but got 3. ==== tests/cases/compiler/overloadsAndTypeArgumentArityErrors.ts (3 errors) ==== @@ -9,10 +9,10 @@ tests/cases/compiler/overloadsAndTypeArgumentArityErrors.ts(6,1): error TS2558: declare function Callbacks(flags?: string): void; Callbacks('s'); // wrong number of type arguments - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 0-2 type arguments, but got 3. new Callbacks('s'); // wrong number of type arguments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2350: Only a void function can be called with the 'new' keyword. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2558: Expected 0-2 type arguments, but got 3. \ No newline at end of file diff --git a/tests/baselines/reference/parserConstructorAmbiguity3.errors.txt b/tests/baselines/reference/parserConstructorAmbiguity3.errors.txt index c13916fa39d..cd58ed117f6 100644 --- a/tests/baselines/reference/parserConstructorAmbiguity3.errors.txt +++ b/tests/baselines/reference/parserConstructorAmbiguity3.errors.txt @@ -1,13 +1,13 @@ -tests/cases/conformance/parser/ecmascript5/Generics/parserConstructorAmbiguity3.ts(1,1): error TS2558: Expected 0 type arguments, but got 1. tests/cases/conformance/parser/ecmascript5/Generics/parserConstructorAmbiguity3.ts(1,10): error TS2304: Cannot find name 'A'. +tests/cases/conformance/parser/ecmascript5/Generics/parserConstructorAmbiguity3.ts(1,10): error TS2558: Expected 0 type arguments, but got 1. tests/cases/conformance/parser/ecmascript5/Generics/parserConstructorAmbiguity3.ts(1,12): error TS1005: '(' expected. ==== tests/cases/conformance/parser/ecmascript5/Generics/parserConstructorAmbiguity3.ts (3 errors) ==== new Date - ~~~~~~~~~~~ -!!! error TS2558: Expected 0 type arguments, but got 1. ~ !!! error TS2304: Cannot find name 'A'. + ~ +!!! error TS2558: Expected 0 type arguments, but got 1. !!! error TS1005: '(' expected. \ No newline at end of file diff --git a/tests/baselines/reference/thisExpressionInCallExpressionWithTypeArguments.errors.txt b/tests/baselines/reference/thisExpressionInCallExpressionWithTypeArguments.errors.txt index 1dac3478c63..22f4632cef8 100644 --- a/tests/baselines/reference/thisExpressionInCallExpressionWithTypeArguments.errors.txt +++ b/tests/baselines/reference/thisExpressionInCallExpressionWithTypeArguments.errors.txt @@ -1,10 +1,10 @@ -tests/cases/compiler/thisExpressionInCallExpressionWithTypeArguments.ts(2,20): error TS2558: Expected 1 type arguments, but got 2. +tests/cases/compiler/thisExpressionInCallExpressionWithTypeArguments.ts(2,32): error TS2558: Expected 1 type arguments, but got 2. ==== tests/cases/compiler/thisExpressionInCallExpressionWithTypeArguments.ts (1 errors) ==== class C { public foo() { [1,2,3].map((x) => { return this; })} - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~ !!! error TS2558: Expected 1 type arguments, but got 2. } \ No newline at end of file diff --git a/tests/baselines/reference/tooManyTypeParameters1.errors.txt b/tests/baselines/reference/tooManyTypeParameters1.errors.txt index 7997e68b575..b966225bef5 100644 --- a/tests/baselines/reference/tooManyTypeParameters1.errors.txt +++ b/tests/baselines/reference/tooManyTypeParameters1.errors.txt @@ -1,23 +1,23 @@ -tests/cases/compiler/tooManyTypeParameters1.ts(2,1): error TS2558: Expected 1 type arguments, but got 2. -tests/cases/compiler/tooManyTypeParameters1.ts(5,1): error TS2558: Expected 1 type arguments, but got 2. -tests/cases/compiler/tooManyTypeParameters1.ts(8,9): error TS2558: Expected 1 type arguments, but got 2. +tests/cases/compiler/tooManyTypeParameters1.ts(2,3): error TS2558: Expected 1 type arguments, but got 2. +tests/cases/compiler/tooManyTypeParameters1.ts(5,3): error TS2558: Expected 1 type arguments, but got 2. +tests/cases/compiler/tooManyTypeParameters1.ts(8,15): error TS2558: Expected 1 type arguments, but got 2. tests/cases/compiler/tooManyTypeParameters1.ts(11,8): error TS2314: Generic type 'I' requires 1 type argument(s). ==== tests/cases/compiler/tooManyTypeParameters1.ts (4 errors) ==== function f() { } f(); - ~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~ !!! error TS2558: Expected 1 type arguments, but got 2. var x = () => {}; x(); - ~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ !!! error TS2558: Expected 1 type arguments, but got 2. class C {} var c = new C(); - ~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~ !!! error TS2558: Expected 1 type arguments, but got 2. interface I {} diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution17.js b/tests/baselines/reference/tsxSpreadAttributesResolution17.js new file mode 100644 index 00000000000..81b1f073514 --- /dev/null +++ b/tests/baselines/reference/tsxSpreadAttributesResolution17.js @@ -0,0 +1,47 @@ +//// [file.tsx] +declare global { + namespace JSX { + interface Element {} + interface ElementAttributesProperty { props: {} } + } +} +declare var React: any; + +export class Empty extends React.Component<{}, {}> { + render() { + return
Hello
; + } +} + +declare const obj: { a: number | undefined } | undefined; + +// OK +let unionedSpread = ; + + +//// [file.jsx] +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +exports.__esModule = true; +var Empty = /** @class */ (function (_super) { + __extends(Empty, _super); + function Empty() { + return _super !== null && _super.apply(this, arguments) || this; + } + Empty.prototype.render = function () { + return
Hello
; + }; + return Empty; +}(React.Component)); +exports.Empty = Empty; +// OK +var unionedSpread = ; diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution17.symbols b/tests/baselines/reference/tsxSpreadAttributesResolution17.symbols new file mode 100644 index 00000000000..6f346ccdcb1 --- /dev/null +++ b/tests/baselines/reference/tsxSpreadAttributesResolution17.symbols @@ -0,0 +1,41 @@ +=== tests/cases/conformance/jsx/file.tsx === +declare global { +>global : Symbol(global, Decl(file.tsx, 0, 0)) + + namespace JSX { +>JSX : Symbol(JSX, Decl(file.tsx, 0, 16)) + + interface Element {} +>Element : Symbol(Element, Decl(file.tsx, 1, 19)) + + interface ElementAttributesProperty { props: {} } +>ElementAttributesProperty : Symbol(ElementAttributesProperty, Decl(file.tsx, 2, 28)) +>props : Symbol(ElementAttributesProperty.props, Decl(file.tsx, 3, 45)) + } +} +declare var React: any; +>React : Symbol(React, Decl(file.tsx, 6, 11)) + +export class Empty extends React.Component<{}, {}> { +>Empty : Symbol(Empty, Decl(file.tsx, 6, 23)) +>React : Symbol(React, Decl(file.tsx, 6, 11)) + + render() { +>render : Symbol(Empty.render, Decl(file.tsx, 8, 52)) + + return
Hello
; +>div : Symbol(unknown) +>div : Symbol(unknown) + } +} + +declare const obj: { a: number | undefined } | undefined; +>obj : Symbol(obj, Decl(file.tsx, 14, 13)) +>a : Symbol(a, Decl(file.tsx, 14, 20)) + +// OK +let unionedSpread = ; +>unionedSpread : Symbol(unionedSpread, Decl(file.tsx, 17, 3)) +>Empty : Symbol(Empty, Decl(file.tsx, 6, 23)) +>obj : Symbol(obj, Decl(file.tsx, 14, 13)) + diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution17.types b/tests/baselines/reference/tsxSpreadAttributesResolution17.types new file mode 100644 index 00000000000..9477e7366ee --- /dev/null +++ b/tests/baselines/reference/tsxSpreadAttributesResolution17.types @@ -0,0 +1,45 @@ +=== tests/cases/conformance/jsx/file.tsx === +declare global { +>global : any + + namespace JSX { +>JSX : any + + interface Element {} +>Element : Element + + interface ElementAttributesProperty { props: {} } +>ElementAttributesProperty : ElementAttributesProperty +>props : {} + } +} +declare var React: any; +>React : any + +export class Empty extends React.Component<{}, {}> { +>Empty : Empty +>React.Component : any +>React : any +>Component : any + + render() { +>render : () => JSX.Element + + return
Hello
; +>
Hello
: JSX.Element +>div : any +>div : any + } +} + +declare const obj: { a: number | undefined } | undefined; +>obj : { a: number | undefined; } | undefined +>a : number | undefined + +// OK +let unionedSpread = ; +>unionedSpread : JSX.Element +> : JSX.Element +>Empty : typeof Empty +>obj : { a: number | undefined; } | undefined + diff --git a/tests/baselines/reference/typeArgumentsOnFunctionsWithNoTypeParameters.errors.txt b/tests/baselines/reference/typeArgumentsOnFunctionsWithNoTypeParameters.errors.txt index 5c916331950..a162b997c0f 100644 --- a/tests/baselines/reference/typeArgumentsOnFunctionsWithNoTypeParameters.errors.txt +++ b/tests/baselines/reference/typeArgumentsOnFunctionsWithNoTypeParameters.errors.txt @@ -1,18 +1,18 @@ -tests/cases/compiler/typeArgumentsOnFunctionsWithNoTypeParameters.ts(2,13): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/typeArgumentsOnFunctionsWithNoTypeParameters.ts(2,15): error TS2558: Expected 0 type arguments, but got 1. tests/cases/compiler/typeArgumentsOnFunctionsWithNoTypeParameters.ts(3,15): error TS2345: Argument of type '1' is not assignable to parameter of type 'T'. -tests/cases/compiler/typeArgumentsOnFunctionsWithNoTypeParameters.ts(4,13): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/typeArgumentsOnFunctionsWithNoTypeParameters.ts(4,15): error TS2558: Expected 0 type arguments, but got 1. ==== tests/cases/compiler/typeArgumentsOnFunctionsWithNoTypeParameters.ts (3 errors) ==== function foo(f: (v: T) => U) { var r1 = f(1); - ~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var r2 = f(1); ~ !!! error TS2345: Argument of type '1' is not assignable to parameter of type 'T'. var r3 = f(null); - ~~~~~~~~~~~~ + ~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var r4 = f(null); } diff --git a/tests/baselines/reference/typeAssertions.errors.txt b/tests/baselines/reference/typeAssertions.errors.txt index 45f20437860..cefc15b8e23 100644 --- a/tests/baselines/reference/typeAssertions.errors.txt +++ b/tests/baselines/reference/typeAssertions.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(5,5): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(5,9): error TS2558: Expected 0 type arguments, but got 1. tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(31,12): error TS2352: Type 'SomeOther' cannot be converted to type 'SomeBase'. Property 'p' is missing in type 'SomeOther'. tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(35,15): error TS2352: Type 'SomeOther' cannot be converted to type 'SomeDerived'. @@ -29,7 +29,7 @@ tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,50): err function fn2(t: any) { } fn1(fn2(4)); // Error - ~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var a: any; diff --git a/tests/baselines/reference/untypedFunctionCallsWithTypeParameters1.errors.txt b/tests/baselines/reference/untypedFunctionCallsWithTypeParameters1.errors.txt index 6b6594fc1ed..d1a1b0f08f9 100644 --- a/tests/baselines/reference/untypedFunctionCallsWithTypeParameters1.errors.txt +++ b/tests/baselines/reference/untypedFunctionCallsWithTypeParameters1.errors.txt @@ -1,20 +1,20 @@ -tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(3,10): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(3,12): error TS2558: Expected 0 type arguments, but got 1. tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(5,10): error TS2347: Untyped function calls may not accept type arguments. tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(8,10): error TS2347: Untyped function calls may not accept type arguments. tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(10,7): error TS2420: Class 'C' incorrectly implements interface 'Function'. Property 'apply' is missing in type 'C'. tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(18,10): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'C' has no compatible call signatures. tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(22,10): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(28,10): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(35,1): error TS2558: Expected 0 type arguments, but got 1. -tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(41,1): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(28,12): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(35,4): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(41,4): error TS2558: Expected 0 type arguments, but got 1. ==== tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts (9 errors) ==== // none of these function calls should be allowed var x = function () { return; }; var r1 = x(); - ~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. var y: any = x; var r2 = y(); @@ -52,7 +52,7 @@ tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(41,1): error TS2 } var z: I; var r6 = z(1); // error - ~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. interface callable2 { @@ -61,7 +61,7 @@ tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(41,1): error TS2 var c4: callable2; c4(1); - ~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. interface callable3 { (a: T): T; @@ -69,7 +69,7 @@ tests/cases/compiler/untypedFunctionCallsWithTypeParameters1.ts(41,1): error TS2 var c5: callable3; c5(1); // error - ~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2558: Expected 0 type arguments, but got 1. \ No newline at end of file diff --git a/tests/baselines/reference/unusedSemicolonInClass.js b/tests/baselines/reference/unusedSemicolonInClass.js new file mode 100644 index 00000000000..c33f799fec4 --- /dev/null +++ b/tests/baselines/reference/unusedSemicolonInClass.js @@ -0,0 +1,13 @@ +//// [unusedSemicolonInClass.ts] +class Unused { + ; +} + + +//// [unusedSemicolonInClass.js] +var Unused = /** @class */ (function () { + function Unused() { + } + ; + return Unused; +}()); diff --git a/tests/baselines/reference/unusedSemicolonInClass.symbols b/tests/baselines/reference/unusedSemicolonInClass.symbols new file mode 100644 index 00000000000..0e1832d1f3a --- /dev/null +++ b/tests/baselines/reference/unusedSemicolonInClass.symbols @@ -0,0 +1,7 @@ +=== tests/cases/compiler/unusedSemicolonInClass.ts === +class Unused { +>Unused : Symbol(Unused, Decl(unusedSemicolonInClass.ts, 0, 0)) + + ; +} + diff --git a/tests/baselines/reference/unusedSemicolonInClass.types b/tests/baselines/reference/unusedSemicolonInClass.types new file mode 100644 index 00000000000..118259662f4 --- /dev/null +++ b/tests/baselines/reference/unusedSemicolonInClass.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/unusedSemicolonInClass.ts === +class Unused { +>Unused : Unused + + ; +} + diff --git a/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.errors.txt b/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.errors.txt new file mode 100644 index 00000000000..e5bc774b706 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.errors.txt @@ -0,0 +1,33 @@ +tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts(1,12): error TS6133: 'T' is declared but its value is never read. +tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts(3,8): error TS6133: 'T' is declared but its value is never read. +tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts(5,13): error TS6133: 'T' is declared but its value is never read. +tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts(7,9): error TS6133: 'T' is declared but its value is never read. +tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts(8,14): error TS6133: 'V' is declared but its value is never read. +tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts(11,10): error TS6133: 'T' is declared but its value is never read. + + +==== tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts (6 errors) ==== + function f() { } + ~ +!!! error TS6133: 'T' is declared but its value is never read. + + type T = { }; + ~ +!!! error TS6133: 'T' is declared but its value is never read. + + interface I { }; + ~ +!!! error TS6133: 'T' is declared but its value is never read. + + class C { + ~ +!!! error TS6133: 'T' is declared but its value is never read. + public m() { } + ~ +!!! error TS6133: 'V' is declared but its value is never read. + }; + + let l = () => { }; + ~ +!!! error TS6133: 'T' is declared but its value is never read. + \ No newline at end of file diff --git a/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.js b/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.js new file mode 100644 index 00000000000..50a7dfcfeac --- /dev/null +++ b/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.js @@ -0,0 +1,25 @@ +//// [unusedTypeParametersCheckedByNoUnusedParameters.ts] +function f() { } + +type T = { }; + +interface I { }; + +class C { + public m() { } +}; + +let l = () => { }; + + +//// [unusedTypeParametersCheckedByNoUnusedParameters.js] +function f() { } +; +var C = /** @class */ (function () { + function C() { + } + C.prototype.m = function () { }; + return C; +}()); +; +var l = function () { }; diff --git a/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.symbols b/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.symbols new file mode 100644 index 00000000000..916329800ef --- /dev/null +++ b/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts === +function f() { } +>f : Symbol(f, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 0, 0)) +>T : Symbol(T, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 0, 11)) + +type T = { }; +>T : Symbol(T, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 0, 19)) +>T : Symbol(T, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 2, 7)) + +interface I { }; +>I : Symbol(I, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 2, 16)) +>T : Symbol(T, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 4, 12)) + +class C { +>C : Symbol(C, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 4, 19)) +>T : Symbol(T, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 6, 8)) + + public m() { } +>m : Symbol(C.m, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 6, 12)) +>V : Symbol(V, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 7, 13)) + +}; + +let l = () => { }; +>l : Symbol(l, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 10, 3)) +>T : Symbol(T, Decl(unusedTypeParametersCheckedByNoUnusedParameters.ts, 10, 9)) + diff --git a/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.types b/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.types new file mode 100644 index 00000000000..eb49d0a731f --- /dev/null +++ b/tests/baselines/reference/unusedTypeParametersCheckedByNoUnusedParameters.types @@ -0,0 +1,28 @@ +=== tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts === +function f() { } +>f : () => void +>T : T + +type T = { }; +>T : {} +>T : T + +interface I { }; +>I : I +>T : T + +class C { +>C : C +>T : T + + public m() { } +>m : () => void +>V : V + +}; + +let l = () => { }; +>l : () => void +>() => { } : () => void +>T : T + diff --git a/tests/baselines/reference/unusedTypeParametersNotCheckedByNoUnusedLocals.js b/tests/baselines/reference/unusedTypeParametersNotCheckedByNoUnusedLocals.js new file mode 100644 index 00000000000..2b215504bda --- /dev/null +++ b/tests/baselines/reference/unusedTypeParametersNotCheckedByNoUnusedLocals.js @@ -0,0 +1,25 @@ +//// [unusedTypeParametersNotCheckedByNoUnusedLocals.ts] +function f() { } + +type T = { }; + +interface I { }; + +class C { + public m() { } +}; + +let l = () => { }; + + +//// [unusedTypeParametersNotCheckedByNoUnusedLocals.js] +function f() { } +; +var C = /** @class */ (function () { + function C() { + } + C.prototype.m = function () { }; + return C; +}()); +; +var l = function () { }; diff --git a/tests/baselines/reference/unusedTypeParametersNotCheckedByNoUnusedLocals.symbols b/tests/baselines/reference/unusedTypeParametersNotCheckedByNoUnusedLocals.symbols new file mode 100644 index 00000000000..27bc52564d5 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParametersNotCheckedByNoUnusedLocals.symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/unusedTypeParametersNotCheckedByNoUnusedLocals.ts === +function f() { } +>f : Symbol(f, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 0, 0)) +>T : Symbol(T, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 0, 11)) + +type T = { }; +>T : Symbol(T, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 0, 19)) +>T : Symbol(T, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 2, 7)) + +interface I { }; +>I : Symbol(I, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 2, 16)) +>T : Symbol(T, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 4, 12)) + +class C { +>C : Symbol(C, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 4, 19)) +>T : Symbol(T, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 6, 8)) + + public m() { } +>m : Symbol(C.m, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 6, 12)) +>V : Symbol(V, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 7, 13)) + +}; + +let l = () => { }; +>l : Symbol(l, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 10, 3)) +>T : Symbol(T, Decl(unusedTypeParametersNotCheckedByNoUnusedLocals.ts, 10, 9)) + diff --git a/tests/baselines/reference/unusedTypeParametersNotCheckedByNoUnusedLocals.types b/tests/baselines/reference/unusedTypeParametersNotCheckedByNoUnusedLocals.types new file mode 100644 index 00000000000..bed3e964d2c --- /dev/null +++ b/tests/baselines/reference/unusedTypeParametersNotCheckedByNoUnusedLocals.types @@ -0,0 +1,28 @@ +=== tests/cases/compiler/unusedTypeParametersNotCheckedByNoUnusedLocals.ts === +function f() { } +>f : () => void +>T : T + +type T = { }; +>T : {} +>T : T + +interface I { }; +>I : I +>T : T + +class C { +>C : C +>T : T + + public m() { } +>m : () => void +>V : V + +}; + +let l = () => { }; +>l : () => void +>() => { } : () => void +>T : T + diff --git a/tests/baselines/reference/unusedTypeParametersWithUnderscore.errors.txt b/tests/baselines/reference/unusedTypeParametersWithUnderscore.errors.txt index cd44a68b78c..b41b62694f8 100644 --- a/tests/baselines/reference/unusedTypeParametersWithUnderscore.errors.txt +++ b/tests/baselines/reference/unusedTypeParametersWithUnderscore.errors.txt @@ -2,9 +2,11 @@ tests/cases/compiler/unusedTypeParametersWithUnderscore.ts(1,16): error TS6133: tests/cases/compiler/unusedTypeParametersWithUnderscore.ts(3,12): error TS6133: 'U' is declared but its value is never read. tests/cases/compiler/unusedTypeParametersWithUnderscore.ts(5,17): error TS6133: 'U' is declared but its value is never read. tests/cases/compiler/unusedTypeParametersWithUnderscore.ts(7,13): error TS6133: 'U' is declared but its value is never read. +tests/cases/compiler/unusedTypeParametersWithUnderscore.ts(8,18): error TS6133: 'W' is declared but its value is never read. +tests/cases/compiler/unusedTypeParametersWithUnderscore.ts(11,14): error TS6133: 'U' is declared but its value is never read. -==== tests/cases/compiler/unusedTypeParametersWithUnderscore.ts (4 errors) ==== +==== tests/cases/compiler/unusedTypeParametersWithUnderscore.ts (6 errors) ==== function f<_T, U>() { } ~ !!! error TS6133: 'U' is declared but its value is never read. @@ -17,7 +19,15 @@ tests/cases/compiler/unusedTypeParametersWithUnderscore.ts(7,13): error TS6133: ~ !!! error TS6133: 'U' is declared but its value is never read. - class C<_T, U> { }; + class C<_T, U> { ~ !!! error TS6133: 'U' is declared but its value is never read. + public m<_V, W>() { } + ~ +!!! error TS6133: 'W' is declared but its value is never read. + }; + + let l = <_T, U>() => { }; + ~ +!!! error TS6133: 'U' is declared but its value is never read. \ No newline at end of file diff --git a/tests/baselines/reference/unusedTypeParametersWithUnderscore.js b/tests/baselines/reference/unusedTypeParametersWithUnderscore.js index 095cf2da85f..bade5f6f95f 100644 --- a/tests/baselines/reference/unusedTypeParametersWithUnderscore.js +++ b/tests/baselines/reference/unusedTypeParametersWithUnderscore.js @@ -5,7 +5,11 @@ type T<_T, U> = { }; interface I<_T, U> { }; -class C<_T, U> { }; +class C<_T, U> { + public m<_V, W>() { } +}; + +let l = <_T, U>() => { }; //// [unusedTypeParametersWithUnderscore.js] @@ -14,6 +18,8 @@ function f() { } var C = /** @class */ (function () { function C() { } + C.prototype.m = function () { }; return C; }()); ; +var l = function () { }; diff --git a/tests/baselines/reference/unusedTypeParametersWithUnderscore.symbols b/tests/baselines/reference/unusedTypeParametersWithUnderscore.symbols index 4429bc1bd25..3f8444d7069 100644 --- a/tests/baselines/reference/unusedTypeParametersWithUnderscore.symbols +++ b/tests/baselines/reference/unusedTypeParametersWithUnderscore.symbols @@ -14,8 +14,20 @@ interface I<_T, U> { }; >_T : Symbol(_T, Decl(unusedTypeParametersWithUnderscore.ts, 4, 12)) >U : Symbol(U, Decl(unusedTypeParametersWithUnderscore.ts, 4, 15)) -class C<_T, U> { }; +class C<_T, U> { >C : Symbol(C, Decl(unusedTypeParametersWithUnderscore.ts, 4, 23)) >_T : Symbol(_T, Decl(unusedTypeParametersWithUnderscore.ts, 6, 8)) >U : Symbol(U, Decl(unusedTypeParametersWithUnderscore.ts, 6, 11)) + public m<_V, W>() { } +>m : Symbol(C.m, Decl(unusedTypeParametersWithUnderscore.ts, 6, 16)) +>_V : Symbol(_V, Decl(unusedTypeParametersWithUnderscore.ts, 7, 13)) +>W : Symbol(W, Decl(unusedTypeParametersWithUnderscore.ts, 7, 16)) + +}; + +let l = <_T, U>() => { }; +>l : Symbol(l, Decl(unusedTypeParametersWithUnderscore.ts, 10, 3)) +>_T : Symbol(_T, Decl(unusedTypeParametersWithUnderscore.ts, 10, 9)) +>U : Symbol(U, Decl(unusedTypeParametersWithUnderscore.ts, 10, 12)) + diff --git a/tests/baselines/reference/unusedTypeParametersWithUnderscore.types b/tests/baselines/reference/unusedTypeParametersWithUnderscore.types index bfafa3c9b38..9fbb3b974df 100644 --- a/tests/baselines/reference/unusedTypeParametersWithUnderscore.types +++ b/tests/baselines/reference/unusedTypeParametersWithUnderscore.types @@ -14,8 +14,21 @@ interface I<_T, U> { }; >_T : _T >U : U -class C<_T, U> { }; +class C<_T, U> { >C : C<_T, U> >_T : _T +>U : U + + public m<_V, W>() { } +>m : <_V, W>() => void +>_V : _V +>W : W + +}; + +let l = <_T, U>() => { }; +>l : <_T, U>() => void +><_T, U>() => { } : <_T, U>() => void +>_T : _T >U : U diff --git a/tests/cases/compiler/declFileEmitDeclarationsOnly.ts b/tests/cases/compiler/declFileEmitDeclarationsOnly.ts new file mode 100644 index 00000000000..e55496e4ca3 --- /dev/null +++ b/tests/cases/compiler/declFileEmitDeclarationsOnly.ts @@ -0,0 +1,16 @@ +// @declaration: true +// @emitDeclarationsOnly: true + +// @filename: helloworld.ts +const Log = { + info(msg: string) {} +} + +class HelloWorld { + constructor(private name: string) { + } + + public hello() { + Log.info(`Hello ${this.name}`); + } +} diff --git a/tests/cases/compiler/declFileEmitDeclarationsOnlyError1.ts b/tests/cases/compiler/declFileEmitDeclarationsOnlyError1.ts new file mode 100644 index 00000000000..477934a7b2a --- /dev/null +++ b/tests/cases/compiler/declFileEmitDeclarationsOnlyError1.ts @@ -0,0 +1,4 @@ +// @emitDeclarationsOnly: true + +// @filename: hello.ts +var hello = "yo!"; diff --git a/tests/cases/compiler/declFileEmitDeclarationsOnlyError2.ts b/tests/cases/compiler/declFileEmitDeclarationsOnlyError2.ts new file mode 100644 index 00000000000..994a6a5dbd8 --- /dev/null +++ b/tests/cases/compiler/declFileEmitDeclarationsOnlyError2.ts @@ -0,0 +1,5 @@ +// @noEmit: true +// @emitDeclarationsOnly: true + +// @filename: hello.ts +var hello = "yo!"; diff --git a/tests/cases/compiler/excessPropertyCheckWithUnions.ts b/tests/cases/compiler/excessPropertyCheckWithUnions.ts index 240af391cf5..027e67e4ec9 100644 --- a/tests/cases/compiler/excessPropertyCheckWithUnions.ts +++ b/tests/cases/compiler/excessPropertyCheckWithUnions.ts @@ -55,3 +55,22 @@ declare let t0: { a: any, b: any } | { d: any, e: any } declare let t1: { a: any, b: any, c: any } | { c: any, d: any, e: any } let t2 = { ...t1 } t0 = t2 + +// Nested excess property checks work with discriminated unions +type AN = { a: string } | { c: string } +type BN = { b: string } +type AB = { kind: "A", n: AN } | { kind: "B", n: BN } +const abab: AB = { + kind: "A", + n: { + a: "a", + b: "b", // excess -- kind: "A" + } +} +const abac: AB = { + kind: "A", + n: { + a: "a", + c: "c", // ok -- kind: "A", an: { a: string } | { c: string } + } +} diff --git a/tests/cases/compiler/moduleDeclarationExportStarShadowingGlobalIsNameable.ts b/tests/cases/compiler/moduleDeclarationExportStarShadowingGlobalIsNameable.ts new file mode 100644 index 00000000000..9113e6e329b --- /dev/null +++ b/tests/cases/compiler/moduleDeclarationExportStarShadowingGlobalIsNameable.ts @@ -0,0 +1,24 @@ +// @declaration: true +// @filename: model/index.ts +export * from "./account"; + +// @filename: model/account.ts +export interface Account { + myAccNum: number; +} +interface Account2 { + myAccNum: number; +} +export { Account2 as Acc }; + +// @filename: index.ts +declare global { + interface Account { + someProp: number; + } + interface Acc { + someProp: number; + } +} +import * as model from "./model"; +export const func = (account: model.Account, acc2: model.Acc) => {}; diff --git a/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts b/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts new file mode 100644 index 00000000000..d3ebd99efa1 --- /dev/null +++ b/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts @@ -0,0 +1,59 @@ +// @strictNullChecks: true +// https://github.com/Microsoft/TypeScript/issues/17080 + +declare function f(a:number,b:number): void; + +function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { + f(a, b) + // error +} + +function func2( {a, b = 3}: {a: number, b?:number} = {a: 1,b: 2} ) { + f(a, b) + // no error +} + +function func3( {a, b}: {a: number, b?: number} = {a: 1} ) { + f(a,b) + // error +} + +function func4( {a: {b, c}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { + f(b,c) + // error +} + +function func5({a: {b, c = 4}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { + f(b, c) + // no error +} + +function func6( {a: {b, c} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1,c: 2}, d: 3} ) { + f(b, c) + // error +} + +function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1, c: 2}, d: 3} ) { + f(b, c) + // no error +} + +interface Foo { + readonly bar?: number; +} + +function performFoo({ bar }: Foo = {}) { + useBar(bar); +} + +declare function useBar(bar: number): void; + +performFoo(); + +function performFoo2({ bar = null }: Foo = {}) { + useBar2(bar); +} + +declare function useBar2(bar: number | undefined): void; + +performFoo2(); diff --git a/tests/cases/compiler/unusedSemicolonInClass.ts b/tests/cases/compiler/unusedSemicolonInClass.ts new file mode 100644 index 00000000000..5cd62690ba9 --- /dev/null +++ b/tests/cases/compiler/unusedSemicolonInClass.ts @@ -0,0 +1,4 @@ +// @noUnusedLocals: true +class Unused { + ; +} diff --git a/tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts b/tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts new file mode 100644 index 00000000000..b2c132a399e --- /dev/null +++ b/tests/cases/compiler/unusedTypeParametersCheckedByNoUnusedParameters.ts @@ -0,0 +1,13 @@ +//@noUnusedParameters:true + +function f() { } + +type T = { }; + +interface I { }; + +class C { + public m() { } +}; + +let l = () => { }; diff --git a/tests/cases/compiler/unusedTypeParametersNotCheckedByNoUnusedLocals.ts b/tests/cases/compiler/unusedTypeParametersNotCheckedByNoUnusedLocals.ts new file mode 100644 index 00000000000..b305f7a8d72 --- /dev/null +++ b/tests/cases/compiler/unusedTypeParametersNotCheckedByNoUnusedLocals.ts @@ -0,0 +1,13 @@ +//@noUnusedLocals:true + +function f() { } + +type T = { }; + +interface I { }; + +class C { + public m() { } +}; + +let l = () => { }; diff --git a/tests/cases/compiler/unusedTypeParametersWithUnderscore.ts b/tests/cases/compiler/unusedTypeParametersWithUnderscore.ts index dc66534118f..ed4c23411db 100644 --- a/tests/cases/compiler/unusedTypeParametersWithUnderscore.ts +++ b/tests/cases/compiler/unusedTypeParametersWithUnderscore.ts @@ -1,4 +1,4 @@ -//@noUnusedLocals:true +//@noUnusedParameters:true function f<_T, U>() { } @@ -6,4 +6,8 @@ type T<_T, U> = { }; interface I<_T, U> { }; -class C<_T, U> { }; +class C<_T, U> { + public m<_V, W>() { } +}; + +let l = <_T, U>() => { }; diff --git a/tests/cases/conformance/emitter/es2015/forAwait/emitter.forAwait.es2015.ts b/tests/cases/conformance/emitter/es2015/forAwait/emitter.forAwait.es2015.ts index 2069f08af30..64b44e901e2 100644 --- a/tests/cases/conformance/emitter/es2015/forAwait/emitter.forAwait.es2015.ts +++ b/tests/cases/conformance/emitter/es2015/forAwait/emitter.forAwait.es2015.ts @@ -23,4 +23,20 @@ async function* f4() { let x: any, y: any; for await (x of y) { } +} +// @filename: file5.ts +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} +// @filename: file6.ts +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { + let y: any; + outer: for await (const x of y) { + continue outer; + } } \ No newline at end of file diff --git a/tests/cases/conformance/emitter/es2017/forAwait/emitter.forAwait.es2017.ts b/tests/cases/conformance/emitter/es2017/forAwait/emitter.forAwait.es2017.ts index f2d1f46873d..f9d9fc3d4d9 100644 --- a/tests/cases/conformance/emitter/es2017/forAwait/emitter.forAwait.es2017.ts +++ b/tests/cases/conformance/emitter/es2017/forAwait/emitter.forAwait.es2017.ts @@ -23,4 +23,20 @@ async function* f4() { let x: any, y: any; for await (x of y) { } +} +// @filename: file5.ts +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} +// @filename: file6.ts +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { + let y: any; + outer: for await (const x of y) { + continue outer; + } } \ No newline at end of file diff --git a/tests/cases/conformance/emitter/es5/forAwait/emitter.forAwait.es5.ts b/tests/cases/conformance/emitter/es5/forAwait/emitter.forAwait.es5.ts index beb9ac9c2ca..a441b0da2bd 100644 --- a/tests/cases/conformance/emitter/es5/forAwait/emitter.forAwait.es5.ts +++ b/tests/cases/conformance/emitter/es5/forAwait/emitter.forAwait.es5.ts @@ -23,4 +23,20 @@ async function* f4() { let x: any, y: any; for await (x of y) { } +} +// @filename: file5.ts +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} +// @filename: file6.ts +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { + let y: any; + outer: for await (const x of y) { + continue outer; + } } \ No newline at end of file diff --git a/tests/cases/conformance/emitter/esnext/forAwait/emitter.forAwait.esnext.ts b/tests/cases/conformance/emitter/esnext/forAwait/emitter.forAwait.esnext.ts index 2f532f55ed5..ea1b030599e 100644 --- a/tests/cases/conformance/emitter/esnext/forAwait/emitter.forAwait.esnext.ts +++ b/tests/cases/conformance/emitter/esnext/forAwait/emitter.forAwait.esnext.ts @@ -23,4 +23,20 @@ async function* f4() { let x: any, y: any; for await (x of y) { } +} +// @filename: file5.ts +// https://github.com/Microsoft/TypeScript/issues/21363 +async function f5() { + let y: any; + outer: for await (const x of y) { + continue outer; + } +} +// @filename: file6.ts +// https://github.com/Microsoft/TypeScript/issues/21363 +async function* f6() { + let y: any; + outer: for await (const x of y) { + continue outer; + } } \ No newline at end of file diff --git a/tests/cases/conformance/jsx/tsxSpreadAttributesResolution17.tsx b/tests/cases/conformance/jsx/tsxSpreadAttributesResolution17.tsx new file mode 100644 index 00000000000..da5638d3e2a --- /dev/null +++ b/tests/cases/conformance/jsx/tsxSpreadAttributesResolution17.tsx @@ -0,0 +1,25 @@ +// @strictNullChecks: true +// @filename: file.tsx +// @jsx: preserve +// @noLib: true +// @skipLibCheck: true +// @libFiles: lib.d.ts + +declare global { + namespace JSX { + interface Element {} + interface ElementAttributesProperty { props: {} } + } +} +declare var React: any; + +export class Empty extends React.Component<{}, {}> { + render() { + return
Hello
; + } +} + +declare const obj: { a: number | undefined } | undefined; + +// OK +let unionedSpread = ; diff --git a/tests/cases/fourslash/codeFixDisableJsDiagnosticsInFile_all.ts b/tests/cases/fourslash/codeFixDisableJsDiagnosticsInFile_all.ts index 9c3785cf2ae..89f94520374 100644 --- a/tests/cases/fourslash/codeFixDisableJsDiagnosticsInFile_all.ts +++ b/tests/cases/fourslash/codeFixDisableJsDiagnosticsInFile_all.ts @@ -6,15 +6,15 @@ // @Filename: a.js ////let x = ""; -////x = 1; -////x = true; +////x = 1; x = true; +////x = []; verify.codeFixAll({ fixId: "disableJsDiagnostics", newFileContent: `let x = ""; // @ts-ignore -x = 1; +x = 1; x = true; // @ts-ignore -x = true;`, +x = [];`, }); diff --git a/tests/cases/fourslash/completionsImportBaseUrl.ts b/tests/cases/fourslash/completionsImportBaseUrl.ts new file mode 100644 index 00000000000..e5f5b07b9f4 --- /dev/null +++ b/tests/cases/fourslash/completionsImportBaseUrl.ts @@ -0,0 +1,21 @@ +/// + +// @Filename: /tsconfig.json +////{ +//// "compilerOptions": { +//// "baseUrl": "." +//// } +////} + +// @Filename: /src/a.ts +////export const foo = 0; + +// @Filename: /src/b.ts +////fo/**/ + +// Test that it prefers a relative import (see sourceDisplay). +goTo.marker(""); +verify.completionListContains({ name: "foo", source: "/src/a" }, "const foo: 0", "", "const", undefined, /*hasAction*/ true, { + includeExternalModuleExports: true, + sourceDisplay: "./a", +}); diff --git a/tests/cases/fourslash/completionsJsxAttributeInitializer.ts b/tests/cases/fourslash/completionsJsxAttributeInitializer.ts new file mode 100644 index 00000000000..510e0630de9 --- /dev/null +++ b/tests/cases/fourslash/completionsJsxAttributeInitializer.ts @@ -0,0 +1,23 @@ +/// + +// @Filename: /a.tsx +////function f(this: { p: number; "a b": number }, x: number): void { +////
; +////} + +goTo.marker(); + +verify.completionListContains("x", "(parameter) x: number", "", "parameter", undefined, undefined, { + includeInsertTextCompletions: true, + insertText: "{x}", +}); + +verify.completionListContains("p", "(property) p: number", "", "property", undefined, undefined, { + includeInsertTextCompletions: true, + insertText: "{this.p}", +}); + +verify.completionListContains("a b", '(property) "a b": number', "", "property", undefined, undefined, { + includeInsertTextCompletions: true, + insertText: '{this["a b"]}', +}); diff --git a/tests/cases/fourslash/completionsThisType.ts b/tests/cases/fourslash/completionsThisType.ts index 58325182a22..471251d2134 100644 --- a/tests/cases/fourslash/completionsThisType.ts +++ b/tests/cases/fourslash/completionsThisType.ts @@ -3,7 +3,7 @@ ////class C { //// "foo bar": number; //// xyz() { -//// /**/ +//// return (/**/) //// } ////} //// @@ -11,7 +11,7 @@ goTo.marker(""); -verify.completionListContains("xyz", "(method) C.xyz(): void", "", "method", undefined, undefined, { +verify.completionListContains("xyz", "(method) C.xyz(): any", "", "method", undefined, undefined, { includeInsertTextCompletions: true, insertText: "this.xyz", }); diff --git a/tests/cases/fourslash/completionsTypeKeywords.ts b/tests/cases/fourslash/completionsTypeKeywords.ts new file mode 100644 index 00000000000..198d6dddab4 --- /dev/null +++ b/tests/cases/fourslash/completionsTypeKeywords.ts @@ -0,0 +1,7 @@ +/// + +////type T = /**/ + +goTo.marker(); +verify.completionListContains("undefined", "undefined", undefined, "keyword"); +verify.not.completionListContains("await"); diff --git a/tests/cases/fourslash/completionsUnion.ts b/tests/cases/fourslash/completionsUnion.ts index ed449936680..d9d1d3c792f 100644 --- a/tests/cases/fourslash/completionsUnion.ts +++ b/tests/cases/fourslash/completionsUnion.ts @@ -2,7 +2,9 @@ ////interface I { x: number; } ////interface Many extends ReadonlyArray { extra: number; } -////const x: I | I[] | Many = { /**/ }; +////class C { private priv: number; } +////const x: I | I[] | Many | C = { /**/ }; // We specifically filter out any array-like types. +// Private members will be excluded by `createUnionOrIntersectionProperty`. verify.completionsAt("", ["x"]); diff --git a/tests/cases/fourslash/formattingAwait.ts b/tests/cases/fourslash/formattingAwait.ts new file mode 100644 index 00000000000..e6a86f92d08 --- /dev/null +++ b/tests/cases/fourslash/formattingAwait.ts @@ -0,0 +1,18 @@ +/// + +////async function f() { +//// for await (const x of g()) { +//// console.log(x); +//// } +////} + + +format.document(); + +verify.currentFileContentIs( +`async function f() { + for await (const x of g()) { + console.log(x); + } +}` +); \ No newline at end of file diff --git a/tests/cases/fourslash/importNameCodeFixExistingImport2.ts b/tests/cases/fourslash/importNameCodeFixExistingImport2.ts index 1146f24aeae..dbf34f4389e 100644 --- a/tests/cases/fourslash/importNameCodeFixExistingImport2.ts +++ b/tests/cases/fourslash/importNameCodeFixExistingImport2.ts @@ -9,8 +9,8 @@ verify.importFixAtPosition([ `import * as ns from "./module"; +ns.f1();`, +`import * as ns from "./module"; import { f1 } from "./module"; f1();`, -`import * as ns from "./module"; -ns.f1();`, ]); diff --git a/tests/cases/fourslash/importNameCodeFixNewImportBaseUrl0.ts b/tests/cases/fourslash/importNameCodeFixNewImportBaseUrl0.ts index bc852b5c47c..fba8875a610 100644 --- a/tests/cases/fourslash/importNameCodeFixNewImportBaseUrl0.ts +++ b/tests/cases/fourslash/importNameCodeFixNewImportBaseUrl0.ts @@ -13,10 +13,10 @@ //// export function f1() { }; verify.importFixAtPosition([ +`import { f1 } from "b"; + +f1();`, `import { f1 } from "./a/b"; f1();`, -`import { f1 } from "b"; - -f1();` ]); diff --git a/tests/cases/fourslash/importNameCodeFixOptionalImport0.ts b/tests/cases/fourslash/importNameCodeFixOptionalImport0.ts index 218ec4fabb7..3fbae01fab0 100644 --- a/tests/cases/fourslash/importNameCodeFixOptionalImport0.ts +++ b/tests/cases/fourslash/importNameCodeFixOptionalImport0.ts @@ -12,9 +12,9 @@ verify.importFixAtPosition([ `import * as ns from "./foo"; -import { foo } from "./foo"; -foo();`, +ns.foo();`, `import * as ns from "./foo"; -ns.foo();`, +import { foo } from "./foo"; +foo();`, ]); diff --git a/tests/cases/fourslash/importNameCodeFixOptionalImport1.ts b/tests/cases/fourslash/importNameCodeFixOptionalImport1.ts index 7a3d19e1532..11204b3c4d2 100644 --- a/tests/cases/fourslash/importNameCodeFixOptionalImport1.ts +++ b/tests/cases/fourslash/importNameCodeFixOptionalImport1.ts @@ -7,14 +7,14 @@ //// export function foo() {}; // @Filename: a/foo.ts -//// export { foo } from "bar"; +//// export { foo } from "bar"; verify.importFixAtPosition([ -`import { foo } from "./foo"; - -foo();`, - `import { foo } from "bar"; +foo();`, + +`import { foo } from "./foo"; + foo();`, ]); diff --git a/tests/cases/fourslash/unusedTypeParametersInClass1.ts b/tests/cases/fourslash/unusedTypeParametersInClass1.ts index 327558922e7..86beb10a445 100644 --- a/tests/cases/fourslash/unusedTypeParametersInClass1.ts +++ b/tests/cases/fourslash/unusedTypeParametersInClass1.ts @@ -1,6 +1,6 @@ /// -// @noUnusedLocals: true +// @noUnusedParameters: true ////[|class greeter |] { ////} diff --git a/tests/cases/fourslash/unusedTypeParametersInClass2.ts b/tests/cases/fourslash/unusedTypeParametersInClass2.ts index 4f78aa3fbe9..23a4c39602d 100644 --- a/tests/cases/fourslash/unusedTypeParametersInClass2.ts +++ b/tests/cases/fourslash/unusedTypeParametersInClass2.ts @@ -1,6 +1,6 @@ /// -// @noUnusedLocals: true +// @noUnusedParameters: true ////[|class greeter |] { //// public a: X; ////} diff --git a/tests/cases/fourslash/unusedTypeParametersInClass3.ts b/tests/cases/fourslash/unusedTypeParametersInClass3.ts index f0b12f868f1..8312830407b 100644 --- a/tests/cases/fourslash/unusedTypeParametersInClass3.ts +++ b/tests/cases/fourslash/unusedTypeParametersInClass3.ts @@ -1,7 +1,7 @@ /// -// @noUnusedLocals: true +// @noUnusedParameters: true ////[|class greeter |] { //// public a: X; //// public b: Z; diff --git a/tests/cases/fourslash/unusedTypeParametersInFunction1.ts b/tests/cases/fourslash/unusedTypeParametersInFunction1.ts index a33ecf60ea6..686ced26503 100644 --- a/tests/cases/fourslash/unusedTypeParametersInFunction1.ts +++ b/tests/cases/fourslash/unusedTypeParametersInFunction1.ts @@ -1,6 +1,6 @@ /// -// @noUnusedLocals: true +// @noUnusedParameters: true //// [|function f1() {}|] verify.codeFix({ diff --git a/tests/cases/fourslash/unusedTypeParametersInFunction2.ts b/tests/cases/fourslash/unusedTypeParametersInFunction2.ts index 9c0d9e7b098..87d7e90207b 100644 --- a/tests/cases/fourslash/unusedTypeParametersInFunction2.ts +++ b/tests/cases/fourslash/unusedTypeParametersInFunction2.ts @@ -1,6 +1,6 @@ /// -// @noUnusedLocals: true +// @noUnusedParameters: true //// [|function f1(a: X) {a}|] verify.codeFix({ diff --git a/tests/cases/fourslash/unusedTypeParametersInFunction3.ts b/tests/cases/fourslash/unusedTypeParametersInFunction3.ts index 0c8ea449731..0a3bc6bb79b 100644 --- a/tests/cases/fourslash/unusedTypeParametersInFunction3.ts +++ b/tests/cases/fourslash/unusedTypeParametersInFunction3.ts @@ -1,6 +1,6 @@ /// -// @noUnusedLocals: true +// @noUnusedParameters: true //// [|function f1(a: X) {a;var b:Z;b}|] verify.codeFix({ diff --git a/tests/cases/fourslash/unusedTypeParametersInLambda4.ts b/tests/cases/fourslash/unusedTypeParametersInLambda4.ts index b3e3f4b11f3..b9a258bac3d 100644 --- a/tests/cases/fourslash/unusedTypeParametersInLambda4.ts +++ b/tests/cases/fourslash/unusedTypeParametersInLambda4.ts @@ -1,6 +1,6 @@ /// -// @noUnusedLocals: true +// @noUnusedParameters: true //// class A { //// public x: T; //// } diff --git a/tests/cases/fourslash/unusedTypeParametersInMethod1.ts b/tests/cases/fourslash/unusedTypeParametersInMethod1.ts index 260a9399650..a3afd76251d 100644 --- a/tests/cases/fourslash/unusedTypeParametersInMethod1.ts +++ b/tests/cases/fourslash/unusedTypeParametersInMethod1.ts @@ -1,6 +1,6 @@ /// -// @noUnusedLocals: true +// @noUnusedParameters: true //// class C1 { //// [|f1()|] {} //// } diff --git a/tests/cases/fourslash/unusedTypeParametersInMethod2.ts b/tests/cases/fourslash/unusedTypeParametersInMethod2.ts index 377642c5bd5..3ca7a0f8a87 100644 --- a/tests/cases/fourslash/unusedTypeParametersInMethod2.ts +++ b/tests/cases/fourslash/unusedTypeParametersInMethod2.ts @@ -1,6 +1,6 @@ /// -// @noUnusedLocals: true +// @noUnusedParameters: true //// class C1 { //// [|f1(a: U)|] {a;} //// } diff --git a/tests/cases/fourslash/unusedTypeParametersInMethods1.ts b/tests/cases/fourslash/unusedTypeParametersInMethods1.ts index 4a538fb4b39..d394d9af772 100644 --- a/tests/cases/fourslash/unusedTypeParametersInMethods1.ts +++ b/tests/cases/fourslash/unusedTypeParametersInMethods1.ts @@ -1,6 +1,6 @@ /// -// @noUnusedLocals: true +// @noUnusedParameters: true //// class A { //// [|public f1(a: X)|] { a; var b: Z; b } //// }