diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md index 735bf90b9ba..fe94434490c 100644 --- a/.github/ISSUE_TEMPLATE/Bug_report.md +++ b/.github/ISSUE_TEMPLATE/Bug_report.md @@ -16,10 +16,10 @@ Please fill in the *entire* template below. --> -**TypeScript Version:** 3.0.0-dev.201xxxxx +**TypeScript Version:** 3.1.0-dev.201xxxxx -**Search Terms:** +**Search Terms:** **Code** @@ -32,6 +32,6 @@ Please fill in the *entire* template below. **Actual behavior:** -**Playground Link:** +**Playground Link:** **Related Issues:** diff --git a/Jakefile.js b/Jakefile.js index 1dc4be82fae..4a650b612fe 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -817,7 +817,7 @@ function diagnosticsToString(diagnostics, pretty) { * Concatenate a list of sourceFiles to a destinationFile * @param {string} destinationFile * @param {string[]} sourceFiles - * @param {string} extraContent + * @param {string=} extraContent */ function concatenateFiles(destinationFile, sourceFiles, extraContent) { var temp = "temptemp"; diff --git a/package.json b/package.json index af7f0369a67..510d3aab53b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "typescript", "author": "Microsoft Corp.", "homepage": "http://typescriptlang.org/", - "version": "3.0.0", + "version": "3.1.0", "license": "Apache-2.0", "description": "TypeScript is a language for application scale JavaScript development", "keywords": [ diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 8791706396e..7fb79b2efa2 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -306,7 +306,7 @@ namespace ts { } function getDisplayName(node: Declaration): string { - return isNamedDeclaration(node) ? declarationNameToString(node.name) : unescapeLeadingUnderscores(getDeclarationName(node)!); // TODO: GH#18217 + return isNamedDeclaration(node) ? declarationNameToString(node.name) : unescapeLeadingUnderscores(Debug.assertDefined(getDeclarationName(node))); } /** @@ -383,9 +383,11 @@ namespace ts { let message = symbol.flags & SymbolFlags.BlockScopedVariable ? Diagnostics.Cannot_redeclare_block_scoped_variable_0 : Diagnostics.Duplicate_identifier_0; + let messageNeedsName = true; if (symbol.flags & SymbolFlags.Enum || includes & SymbolFlags.Enum) { message = Diagnostics.Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations; + messageNeedsName = false; } if (symbol.declarations && symbol.declarations.length) { @@ -394,6 +396,7 @@ namespace ts { // We'll know whether we have other default exports depending on if `symbol` already has a declaration list set. if (isDefaultExport) { message = Diagnostics.A_module_cannot_have_multiple_default_exports; + messageNeedsName = false; } else { // This is to properly report an error in the case "export default { }" is after export default of class declaration or function declaration. @@ -403,14 +406,16 @@ namespace ts { if (symbol.declarations && symbol.declarations.length && (node.kind === SyntaxKind.ExportAssignment && !(node).isExportEquals)) { message = Diagnostics.A_module_cannot_have_multiple_default_exports; + messageNeedsName = false; } } } - forEach(symbol.declarations, declaration => { - file.bindDiagnostics.push(createDiagnosticForNode(getNameOfDeclaration(declaration) || declaration, message, getDisplayName(declaration))); - }); - file.bindDiagnostics.push(createDiagnosticForNode(getNameOfDeclaration(node) || node, message, getDisplayName(node))); + const addError = (decl: Declaration): void => { + file.bindDiagnostics.push(createDiagnosticForNode(getNameOfDeclaration(decl) || decl, message, messageNeedsName ? getDisplayName(decl) : undefined)); + }; + forEach(symbol.declarations, addError); + addError(node); symbol = createSymbol(SymbolFlags.None, name); } @@ -1913,6 +1918,15 @@ namespace ts { } } + function checkStrictModeLabeledStatement(node: LabeledStatement) { + // Grammar checking for labeledStatement + if (inStrictMode && options.target! >= ScriptTarget.ES2015) { + if (isDeclarationStatement(node.statement) || isVariableStatement(node.statement)) { + errorOnFirstToken(node.label, Diagnostics.A_label_is_not_allowed_here); + } + } + } + function errorOnFirstToken(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any) { const span = getSpanOfTokenAtPosition(file, node.pos); file.bindDiagnostics.push(createFileDiagnostic(file, span.start, span.length, message, arg0, arg1, arg2)); @@ -2099,6 +2113,8 @@ namespace ts { return checkStrictModePrefixUnaryExpression(node); case SyntaxKind.WithStatement: return checkStrictModeWithStatement(node); + case SyntaxKind.LabeledStatement: + return checkStrictModeLabeledStatement(node); case SyntaxKind.ThisType: seenThisKeyword = true; return; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cd91f427248..e01c97af492 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4714,6 +4714,10 @@ namespace ts { // function/class/{} assignments are fresh declarations, not property assignments, so only add prototype assignments const specialDeclaration = getAssignedJavascriptInitializer(symbol.valueDeclaration); if (specialDeclaration) { + const tag = getJSDocTypeTag(specialDeclaration); + if (tag && tag.typeExpression) { + return getTypeFromTypeNode(tag.typeExpression); + } return getWidenedLiteralType(checkExpressionCached(specialDeclaration)); } const types: Type[] = []; @@ -5081,7 +5085,7 @@ namespace ts { } function getJSInitializerType(decl: Node, symbol: Symbol, init: Expression | undefined): Type | undefined { - if (init && isInJavaScriptFile(init) && isObjectLiteralExpression(init)) { + if (init && isInJavaScriptFile(init) && isObjectLiteralExpression(init) && init.properties.length === 0) { const exports = createSymbolTable(); while (isBinaryExpression(decl) || isPropertyAccessExpression(decl)) { const s = getSymbolOfNode(decl); @@ -11182,7 +11186,8 @@ namespace ts { if (reportErrors) { const bestMatchingType = findMatchingDiscriminantType(source, target) || - findMatchingTypeReferenceOrTypeAliasReference(source, target); + findMatchingTypeReferenceOrTypeAliasReference(source, target) || + findBestTypeForObjectLiteral(source, target); isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], /*reportErrors*/ true); } @@ -11207,6 +11212,11 @@ namespace ts { } } + function findBestTypeForObjectLiteral(source: Type, unionTarget: UnionOrIntersectionType) { + if (getObjectFlags(source) & ObjectFlags.ObjectLiteral && forEachType(unionTarget, isArrayLikeType)) { + return find(unionTarget.types, t => !isArrayLikeType(t)); + } + } // Keep this up-to-date with the same logic within `getApparentTypeOfContextualType`, since they should behave similarly function findMatchingDiscriminantType(source: Type, target: UnionOrIntersectionType) { @@ -19083,7 +19093,7 @@ namespace ts { else if (candidateForTypeArgumentError) { checkTypeArguments(candidateForTypeArgumentError, (node as CallExpression | TaggedTemplateExpression).typeArguments!, /*reportErrors*/ true, fallbackError); } - else if (typeArguments && every(signatures, sig => length(sig.typeParameters) !== typeArguments!.length)) { + else if (typeArguments && every(signatures, sig => typeArguments!.length < getMinTypeArgumentCount(sig.typeParameters) || typeArguments!.length > length(sig.typeParameters))) { diagnostics.add(getTypeArgumentArityError(node, signatures, typeArguments)); } else if (args) { diff --git a/src/compiler/core.ts b/src/compiler/core.ts index da72ebe7a37..5ddc706aa22 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -1,7 +1,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 = "3.0"; + export const versionMajorMinor = "3.1"; /** The version of the TypeScript compiler release */ export const version = `${versionMajorMinor}.0-dev`; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 73be2b46b79..ef310cf2717 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -983,6 +983,10 @@ "category": "Error", "code": 1343 }, + "'A label is not allowed here.": { + "category": "Error", + "code": 1344 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 1e4a793e566..ba266d6b217 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -494,9 +494,9 @@ namespace ts { case SyntaxKind.JSDocSignature: return visitNodes(cbNode, cbNodes, node.decorators) || visitNodes(cbNode, cbNodes, node.modifiers) || - visitNodes(cbNode, cbNodes, (node).typeParameters) || - visitNodes(cbNode, cbNodes, (node).parameters) || - visitNode(cbNode, (node).type); + forEach((node).typeParameters, cbNode) || + forEach((node).parameters, cbNode) || + visitNode(cbNode, (node).type); case SyntaxKind.JSDocTypeLiteral: if ((node as JSDocTypeLiteral).jsDocPropertyTags) { for (const tag of (node as JSDocTypeLiteral).jsDocPropertyTags!) { @@ -1509,7 +1509,9 @@ namespace ts { case ParsingContext.ArgumentExpressions: return token() === SyntaxKind.DotDotDotToken || isStartOfExpression(); case ParsingContext.Parameters: - return isStartOfParameter(); + return isStartOfParameter(/*isJSDocParameter*/ false); + case ParsingContext.JSDocParameters: + return isStartOfParameter(/*isJSDocParameter*/ true); case ParsingContext.TypeArguments: case ParsingContext.TupleElementTypes: return token() === SyntaxKind.CommaToken || isStartOfType(); @@ -1612,6 +1614,7 @@ namespace ts { case ParsingContext.TupleElementTypes: case ParsingContext.ArrayBindingElements: return token() === SyntaxKind.CloseBracketToken; + case ParsingContext.JSDocParameters: case ParsingContext.Parameters: case ParsingContext.RestProperties: // Tokens other than ')' and ']' (the latter for index signatures) are here for better error recovery @@ -1795,6 +1798,7 @@ namespace ts { case ParsingContext.VariableDeclarations: return isReusableVariableDeclaration(node); + case ParsingContext.JSDocParameters: case ParsingContext.Parameters: return isReusableParameter(node); @@ -2009,6 +2013,7 @@ namespace ts { case ParsingContext.ArgumentExpressions: return Diagnostics.Argument_expression_expected; case ParsingContext.ObjectLiteralMembers: return Diagnostics.Property_assignment_expected; case ParsingContext.ArrayLiteralMembers: return Diagnostics.Expression_or_comma_expected; + case ParsingContext.JSDocParameters: return Diagnostics.Parameter_declaration_expected; case ParsingContext.Parameters: return Diagnostics.Parameter_declaration_expected; case ParsingContext.TypeParameters: return Diagnostics.Type_parameter_declaration_expected; case ParsingContext.TypeArguments: return Diagnostics.Type_argument_expected; @@ -2430,12 +2435,12 @@ namespace ts { return undefined; } - function isStartOfParameter(): boolean { + function isStartOfParameter(isJSDocParameter: boolean): boolean { return token() === SyntaxKind.DotDotDotToken || isIdentifierOrPattern() || isModifierKind(token()) || token() === SyntaxKind.AtToken || - isStartOfType(/*inStartOfParameter*/ true); + isStartOfType(/*inStartOfParameter*/ !isJSDocParameter); } function parseParameter(): ParameterDeclaration { @@ -2534,7 +2539,9 @@ namespace ts { setYieldContext(!!(flags & SignatureFlags.Yield)); setAwaitContext(!!(flags & SignatureFlags.Await)); - signature.parameters = parseDelimitedList(ParsingContext.Parameters, flags & SignatureFlags.JSDoc ? parseJSDocParameter : parseParameter); + signature.parameters = flags & SignatureFlags.JSDoc ? + parseDelimitedList(ParsingContext.JSDocParameters, parseJSDocParameter) : + parseDelimitedList(ParsingContext.Parameters, parseParameter); setYieldContext(savedYieldContext); setAwaitContext(savedAwaitContext); @@ -2960,6 +2967,8 @@ namespace ts { case SyntaxKind.InferKeyword: case SyntaxKind.ImportKeyword: return true; + case SyntaxKind.FunctionKeyword: + return !inStartOfParameter; case SyntaxKind.MinusToken: return !inStartOfParameter && lookAhead(nextTokenIsNumericLiteral); case SyntaxKind.OpenParenToken: @@ -2973,7 +2982,7 @@ namespace ts { function isStartOfParenthesizedOrFunctionType() { nextToken(); - return token() === SyntaxKind.CloseParenToken || isStartOfParameter() || isStartOfType(); + return token() === SyntaxKind.CloseParenToken || isStartOfParameter(/*isJSDocParameter*/ false) || isStartOfType(); } function parsePostfixTypeOrHigher(): TypeNode { @@ -6255,6 +6264,7 @@ namespace ts { JsxChildren, // Things between opening and closing JSX tags ArrayLiteralMembers, // Members in array literal Parameters, // Parameters in parameter list + JSDocParameters, // JSDoc parameters in parameter list of JSDoc function type RestProperties, // Property names in a rest type list TypeParameters, // Type parameters in type parameter list TypeArguments, // Type arguments in type argument list diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 6935851a439..7b31d09ad68 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2366,7 +2366,7 @@ namespace ts { } function verifyCompilerOptions() { - if (options.strictPropertyInitialization && !options.strictNullChecks) { + if (options.strictPropertyInitialization && !getStrictOptionValue(options, "strictNullChecks")) { createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "strictPropertyInitialization", "strictNullChecks"); } diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index 619cc505c8b..b1f3a57999c 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -2207,7 +2207,7 @@ namespace ts { const statement = unwrapInnermostStatementOfLabel(node, convertedLoopState && recordLabel); return isIterationStatement(statement, /*lookInLabeledStatements*/ false) ? visitIterationStatement(statement, /*outermostLabeledStatement*/ node) - : restoreEnclosingLabel(visitNode(statement, visitor, isStatement), node, convertedLoopState && resetLabel); + : restoreEnclosingLabel(visitNode(statement, visitor, isStatement, liftToBlock), node, convertedLoopState && resetLabel); } function visitIterationStatement(node: IterationStatement, outermostLabeledStatement: LabeledStatement) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d0a5add280e..fbb83562f21 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -755,7 +755,7 @@ namespace ts { export interface TypeParameterDeclaration extends NamedDeclaration { kind: SyntaxKind.TypeParameter; - parent: DeclarationWithTypeParameters | InferTypeNode; + parent: DeclarationWithTypeParameterChildren | InferTypeNode; name: Identifier; constraint?: TypeNode; default?: TypeNode; @@ -2036,7 +2036,8 @@ namespace ts { export type ObjectTypeDeclaration = ClassLikeDeclaration | InterfaceDeclaration | TypeLiteralNode; - export type DeclarationWithTypeParameters = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag | JSDocTypedefTag | JSDocCallbackTag | JSDocSignature; + export type DeclarationWithTypeParameters = DeclarationWithTypeParameterChildren | JSDocTypedefTag | JSDocCallbackTag | JSDocSignature; + export type DeclarationWithTypeParameterChildren = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag; export interface ClassLikeDeclarationBase extends NamedDeclaration, JSDocContainer { kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression; @@ -4361,7 +4362,7 @@ namespace ts { strictFunctionTypes?: boolean; // Always combine with strict property strictNullChecks?: boolean; // Always combine with strict property strictPropertyInitialization?: boolean; // Always combine with strict property - /* @internal */ stripInternal?: boolean; + stripInternal?: boolean; suppressExcessPropertyErrors?: boolean; suppressImplicitAnyIndexErrors?: boolean; /* @internal */ suppressOutputPathCheck?: boolean; diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index b7da07f603d..4d9e653f27d 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2307,6 +2307,14 @@ Actual: ${stringify(fullActual)}`); } } + public verifyFormatDocumentChangesNothing(): void { + const { fileName } = this.activeFile; + const before = this.getFileContent(fileName); + this.formatDocument(); + const after = this.getFileContent(fileName); + this.assertObjectsEqual(after, before); + } + public verifyTextAtCaretIs(text: string) { const actual = this.getFileContent(this.activeFile.fileName).substring(this.currentCaretPosition, this.currentCaretPosition + text.length); if (actual !== text) { @@ -3357,9 +3365,9 @@ Actual: ${stringify(fullActual)}`); this.cancellationToken.resetCancelled(); } - public getEditsForFileRename({ oldPath, newPath, newFileContents }: FourSlashInterface.GetEditsForFileRenameOptions): void { + public getEditsForFileRename({ oldPath, newPath, newFileContents, preferences }: FourSlashInterface.GetEditsForFileRenameOptions): void { const test = (fileContents: { readonly [fileName: string]: string }, description: string): void => { - const changes = this.languageService.getEditsForFileRename(oldPath, newPath, this.formatCodeSettings, ts.emptyOptions); + const changes = this.languageService.getEditsForFileRename(oldPath, newPath, this.formatCodeSettings, preferences); this.testNewFileContents(changes, fileContents, description); }; @@ -4206,6 +4214,10 @@ namespace FourSlashInterface { this.state.verifyCurrentFileContent(text); } + public formatDocumentChangesNothing(): void { + this.state.verifyFormatDocumentChangesNothing(); + } + public goToDefinitionIs(endMarkers: ArrayOrSingle) { this.state.verifyGoToDefinitionIs(endMarkers); } @@ -4878,6 +4890,7 @@ namespace FourSlashInterface { readonly oldPath: string; readonly newPath: string; readonly newFileContents: { readonly [fileName: string]: string }; + readonly preferences?: ts.UserPreferences; } export interface MoveToNewFileOptions { diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 5047af5a38c..c00f37c260d 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1125,15 +1125,15 @@ interface Array { * Returns a string representation of an array. The elements are converted to string using their toLocalString methods. */ toLocaleString(): string; + /** + * Removes the last element from an array and returns it. + */ + pop(): T | undefined; /** * Appends new elements to an array, and returns the new length of the array. * @param items New elements of the Array. */ push(...items: T[]): number; - /** - * Removes the last element from an array and returns it. - */ - pop(): T | undefined; /** * Combines two or more arrays. * @param items Additional items to add to the end of array1. diff --git a/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl index 9126fe3661d..7dac9c42ec8 100644 --- a/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -487,7 +487,7 @@ - + @@ -496,7 +496,7 @@ - + diff --git a/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl index d0086211c52..e9e3bb6cf83 100644 --- a/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -480,7 +480,7 @@ - + diff --git a/src/server/session.ts b/src/server/session.ts index fe57abe6b98..385a1d3abe9 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1433,7 +1433,7 @@ namespace ts.server { return project.getLanguageService().getCompletionEntryDetails(file, position, name, formattingOptions, source, this.getPreferences(file)); }); return simplifiedResult - ? result.map(details => ({ ...details, codeActions: map(details.codeActions, action => this.mapCodeAction(project, action)) })) + ? result.map(details => ({ ...details, codeActions: map(details.codeActions, action => this.mapCodeAction(action)) })) : result; } @@ -1735,7 +1735,7 @@ namespace ts.server { const renameScriptInfo = project.getScriptInfoForNormalizedPath(toNormalizedPath(renameFilename))!; mappedRenameLocation = getLocationInNewDocument(getSnapshotText(renameScriptInfo.getSnapshot()), renameFilename, renameLocation, edits); } - return { renameLocation: mappedRenameLocation, renameFilename, edits: this.mapTextChangesToCodeEdits(project, edits) }; + return { renameLocation: mappedRenameLocation, renameFilename, edits: this.mapTextChangesToCodeEdits(edits) }; } else { return result; @@ -1747,7 +1747,7 @@ namespace ts.server { const { file, project } = this.getFileAndProject(scope.args); const changes = project.getLanguageService().organizeImports({ type: "file", fileName: file }, this.getFormatOptions(file), this.getPreferences(file)); if (simplifiedResult) { - return this.mapTextChangesToCodeEdits(project, changes); + return this.mapTextChangesToCodeEdits(changes); } else { return changes; @@ -1763,7 +1763,7 @@ namespace ts.server { this.projectService, project => project.getLanguageService().getEditsForFileRename(oldPath, newPath, formatOptions, preferences), (a, b) => a.fileName === b.fileName); - return simplifiedResult ? changes.map(c => this.mapTextChangeToCodeEditUsingScriptInfoOrConfigFile(c)) : changes; + return simplifiedResult ? changes.map(c => this.mapTextChangeToCodeEdit(c)) : changes; } private getCodeFixes(args: protocol.CodeFixRequestArgs, simplifiedResult: boolean): ReadonlyArray | ReadonlyArray | undefined { @@ -1776,7 +1776,7 @@ namespace ts.server { const { startPosition, endPosition } = this.getStartAndEndPosition(args, scriptInfo); const codeActions = project.getLanguageService().getCodeFixesAtPosition(file, startPosition, endPosition, args.errorCodes!, this.getFormatOptions(file), this.getPreferences(file)); - return simplifiedResult ? codeActions.map(codeAction => this.mapCodeFixAction(project, codeAction)) : codeActions; + return simplifiedResult ? codeActions.map(codeAction => this.mapCodeFixAction(codeAction)) : codeActions; } private getCombinedCodeFix({ scope, fixId }: protocol.GetCombinedCodeFixRequestArgs, simplifiedResult: boolean): protocol.CombinedCodeActions | CombinedCodeActions { @@ -1784,7 +1784,7 @@ namespace ts.server { const { file, project } = this.getFileAndProject(scope.args); const res = project.getLanguageService().getCombinedCodeFix({ type: "file", fileName: file }, fixId, this.getFormatOptions(file), this.getPreferences(file)); if (simplifiedResult) { - return { changes: this.mapTextChangesToCodeEdits(project, res.changes), commands: res.commands }; + return { changes: this.mapTextChangesToCodeEdits(res.changes), commands: res.commands }; } else { return res; @@ -1824,28 +1824,20 @@ namespace ts.server { return { startPosition, endPosition }; } - private mapCodeAction(project: Project, { description, changes, commands }: CodeAction): protocol.CodeAction { - return { description, changes: this.mapTextChangesToCodeEdits(project, changes), commands }; + private mapCodeAction({ description, changes, commands }: CodeAction): protocol.CodeAction { + return { description, changes: this.mapTextChangesToCodeEdits(changes), commands }; } - private mapCodeFixAction(project: Project, { fixName, description, changes, commands, fixId, fixAllDescription }: CodeFixAction): protocol.CodeFixAction { - return { fixName, description, changes: this.mapTextChangesToCodeEdits(project, changes), commands, fixId, fixAllDescription }; + private mapCodeFixAction({ fixName, description, changes, commands, fixId, fixAllDescription }: CodeFixAction): protocol.CodeFixAction { + return { fixName, description, changes: this.mapTextChangesToCodeEdits(changes), commands, fixId, fixAllDescription }; } - private mapTextChangesToCodeEdits(project: Project, textChanges: ReadonlyArray): protocol.FileCodeEdits[] { - return textChanges.map(change => this.mapTextChangeToCodeEdit(project, change)); + private mapTextChangesToCodeEdits(textChanges: ReadonlyArray): protocol.FileCodeEdits[] { + return textChanges.map(change => this.mapTextChangeToCodeEdit(change)); } - private mapTextChangeToCodeEdit(project: Project, change: FileTextChanges): protocol.FileCodeEdits { - return mapTextChangesToCodeEditsForFile(change, project.getSourceFileOrConfigFile(this.normalizePath(change.fileName))); - } - - private mapTextChangeToCodeEditUsingScriptInfoOrConfigFile(change: FileTextChanges): protocol.FileCodeEdits { - return mapTextChangesToCodeEditsUsingScriptInfoOrConfig(change, this.projectService.getScriptInfoOrConfig(this.normalizePath(change.fileName))); - } - - private normalizePath(fileName: string) { - return normalizedPathToPath(toNormalizedPath(fileName), this.host.getCurrentDirectory(), fileName => this.getCanonicalFileName(fileName)); + private mapTextChangeToCodeEdit(change: FileTextChanges): protocol.FileCodeEdits { + return mapTextChangesToCodeEdits(change, this.projectService.getScriptInfoOrConfig(change.fileName)); } private convertTextChangeToCodeEdit(change: TextChange, scriptInfo: ScriptInfo): protocol.CodeEdit { @@ -2357,35 +2349,14 @@ namespace ts.server { return { file: fileName, start: scriptInfo.positionToLineOffset(textSpan.start), end: scriptInfo.positionToLineOffset(textSpanEnd(textSpan)) }; } - function mapTextChangesToCodeEditsForFile(textChanges: FileTextChanges, sourceFile: SourceFile | undefined): protocol.FileCodeEdits { - Debug.assert(!!textChanges.isNewFile === !sourceFile, "Expected isNewFile for (only) new files", () => JSON.stringify({ isNewFile: !!textChanges.isNewFile, hasSourceFile: !!sourceFile })); - if (sourceFile) { - return { - fileName: textChanges.fileName, - textChanges: textChanges.textChanges.map(textChange => convertTextChangeToCodeEdit(textChange, sourceFile)), - }; - } - else { - return convertNewFileTextChangeToCodeEdit(textChanges); - } - } - - function mapTextChangesToCodeEditsUsingScriptInfoOrConfig(textChanges: FileTextChanges, scriptInfo: ScriptInfoOrConfig | undefined): protocol.FileCodeEdits { + function mapTextChangesToCodeEdits(textChanges: FileTextChanges, scriptInfo: ScriptInfoOrConfig | undefined): protocol.FileCodeEdits { Debug.assert(!!textChanges.isNewFile === !scriptInfo, "Expected isNewFile for (only) new files", () => JSON.stringify({ isNewFile: !!textChanges.isNewFile, hasScriptInfo: !!scriptInfo })); return scriptInfo - ? { fileName: textChanges.fileName, textChanges: textChanges.textChanges.map(textChange => convertTextChangeToCodeEditUsingScriptInfoOrConfig(textChange, scriptInfo)) } + ? { fileName: textChanges.fileName, textChanges: textChanges.textChanges.map(textChange => convertTextChangeToCodeEdit(textChange, scriptInfo)) } : convertNewFileTextChangeToCodeEdit(textChanges); } - function convertTextChangeToCodeEdit(change: TextChange, sourceFile: SourceFile): protocol.CodeEdit { - return { - start: convertToLocation(sourceFile.getLineAndCharacterOfPosition(change.span.start)), - end: convertToLocation(sourceFile.getLineAndCharacterOfPosition(change.span.start + change.span.length)), - newText: change.newText ? change.newText : "", - }; - } - - function convertTextChangeToCodeEditUsingScriptInfoOrConfig(change: TextChange, scriptInfo: ScriptInfoOrConfig): protocol.CodeEdit { + function convertTextChangeToCodeEdit(change: TextChange, scriptInfo: ScriptInfoOrConfig): protocol.CodeEdit { return { start: positionToLineOffset(scriptInfo, change.span.start), end: positionToLineOffset(scriptInfo, textSpanEnd(change.span)), newText: change.newText }; } diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index a745ef02fd4..38a8ab78418 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -482,7 +482,7 @@ namespace ts.codefix { } function addNamespaceQualifier(changes: textChanges.ChangeTracker, sourceFile: SourceFile, { namespacePrefix, symbolToken }: FixUseNamespaceImport): void { - changes.replaceNode(sourceFile, symbolToken, createPropertyAccess(createIdentifier(namespacePrefix), symbolToken)); + changes.replaceNode(sourceFile, symbolToken, createPropertyAccess(createIdentifier(namespacePrefix), createIdentifier(symbolToken.text))); } interface ImportsCollection { diff --git a/src/services/completions.ts b/src/services/completions.ts index 1353ba8be21..cf496e6e55e 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -921,6 +921,9 @@ namespace ts.Completions { case SyntaxKind.QualifiedName: node = (parent as QualifiedName).left; break; + case SyntaxKind.ModuleDeclaration: + node = (parent as ModuleDeclaration).name; + break; case SyntaxKind.ImportType: case SyntaxKind.MetaProperty: node = parent; @@ -1062,6 +1065,8 @@ namespace ts.Completions { const isRhsOfImportDeclaration = isInRightSideOfInternalImportEqualsDeclaration(node); const allowTypeOrValue = isRhsOfImportDeclaration || (!isTypeLocation && isPossiblyTypeArgumentPosition(contextToken, sourceFile, typeChecker)); if (isEntityName(node) || isImportType) { + const isNamespaceName = isModuleDeclaration(node.parent); + if (isNamespaceName) isNewIdentifierLocation = true; let symbol = typeChecker.getSymbolAtLocation(node); if (symbol) { symbol = skipAlias(symbol, typeChecker); @@ -1071,13 +1076,17 @@ namespace ts.Completions { const exportedSymbols = Debug.assertEachDefined(typeChecker.getExportsOfModule(symbol), "getExportsOfModule() should all be defined"); const isValidValueAccess = (symbol: Symbol) => typeChecker.isValidPropertyAccess(isImportType ? node : (node.parent), symbol.name); const isValidTypeAccess = (symbol: Symbol) => symbolCanBeReferencedAtTypeLocation(symbol); - const isValidAccess = allowTypeOrValue ? - // Any kind is allowed when dotting off namespace in internal import equals declaration - (symbol: Symbol) => isValidTypeAccess(symbol) || isValidValueAccess(symbol) : - isTypeLocation ? isValidTypeAccess : isValidValueAccess; - for (const symbol of exportedSymbols) { - if (isValidAccess(symbol)) { - symbols.push(symbol); + const isValidAccess: (symbol: Symbol) => boolean = + isNamespaceName + // At `namespace N.M/**/`, if this is the only declaration of `M`, don't include `M` as a completion. + ? symbol => !!(symbol.flags & SymbolFlags.Namespace) && !symbol.declarations.every(d => d.parent === node.parent) + : allowTypeOrValue ? + // Any kind is allowed when dotting off namespace in internal import equals declaration + symbol => isValidTypeAccess(symbol) || isValidValueAccess(symbol) : + isTypeLocation ? isValidTypeAccess : isValidValueAccess; + for (const exportedSymbol of exportedSymbols) { + if (isValidAccess(exportedSymbol)) { + symbols.push(exportedSymbol); } } @@ -1461,7 +1470,8 @@ namespace ts.Completions { function isNewIdentifierDefinitionLocation(previousToken: Node | undefined): boolean { if (previousToken) { const containingNodeKind = previousToken.parent.kind; - switch (previousToken.kind) { + // Previous token may have been a keyword that was converted to an identifier. + switch (keywordForNode(previousToken)) { case SyntaxKind.CommaToken: return containingNodeKind === SyntaxKind.CallExpression // func( a, | || containingNodeKind === SyntaxKind.Constructor // constructor( a, | /* public, protected, private keywords are allowed here, so show completion */ @@ -1507,14 +1517,6 @@ namespace ts.Completions { case SyntaxKind.ProtectedKeyword: return containingNodeKind === SyntaxKind.PropertyDeclaration; // class A{ public | } - - // Previous token may have been a keyword that was converted to an identifier. - switch (keywordForNode(previousToken)) { - case SyntaxKind.PublicKeyword: - case SyntaxKind.ProtectedKeyword: - case SyntaxKind.PrivateKeyword: - return true; - } } return false; diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 82f9f6796bb..c1de1574e88 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -717,7 +717,6 @@ namespace ts.formatting { Debug.assert(isNodeArray(nodes)); const listStartToken = getOpenTokenForList(parent, nodes); - const listEndToken = getCloseTokenForOpenToken(listStartToken); let listDynamicIndentation = parentDynamicIndentation; let startLine = parentStartLine; @@ -752,17 +751,21 @@ namespace ts.formatting { inheritedIndentation = processChildNode(child, inheritedIndentation, node, listDynamicIndentation, startLine, startLine, /*isListItem*/ true, /*isFirstListItem*/ i === 0); } - if (listEndToken !== SyntaxKind.Unknown) { - if (formattingScanner.isOnToken()) { - const tokenInfo = formattingScanner.readTokenInfo(parent); - // consume the list end token only if it is still belong to the parent - // there might be the case when current token matches end token but does not considered as one - // function (x: function) <-- - // without this check close paren will be interpreted as list end token for function expression which is wrong - if (tokenInfo.token.kind === listEndToken && rangeContainsRange(parent, tokenInfo.token)) { - // consume list end token - consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation, parent); - } + const listEndToken = getCloseTokenForOpenToken(listStartToken); + if (listEndToken !== SyntaxKind.Unknown && formattingScanner.isOnToken()) { + let tokenInfo = formattingScanner.readTokenInfo(parent); + if (tokenInfo.token.kind === SyntaxKind.CommaToken && isCallLikeExpression(parent)) { + formattingScanner.advance(); + tokenInfo = formattingScanner.readTokenInfo(parent); + } + + // consume the list end token only if it is still belong to the parent + // there might be the case when current token matches end token but does not considered as one + // function (x: function) <-- + // without this check close paren will be interpreted as list end token for function expression which is wrong + if (tokenInfo.token.kind === listEndToken && rangeContainsRange(parent, tokenInfo.token)) { + // consume list end token + consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation, parent); } } } diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index c578c38cbc1..b506dd5269f 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -579,17 +579,10 @@ namespace ts.formatting { function isControlFlowEndingStatement(kind: SyntaxKind, parent: TextRangeWithKind): boolean { switch (kind) { case SyntaxKind.ReturnStatement: - case SyntaxKind.ThrowStatement: { - if (parent.kind !== SyntaxKind.Block) { - return true; - } - const grandParent = (parent as Node).parent; - // In a function, we may want to write inner functions after this. - return !(grandParent && grandParent.kind === SyntaxKind.FunctionExpression || grandParent.kind === SyntaxKind.FunctionDeclaration); - } + case SyntaxKind.ThrowStatement: case SyntaxKind.ContinueStatement: case SyntaxKind.BreakStatement: - return true; + return parent.kind !== SyntaxKind.Block; default: return false; } diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index d6af6add125..bb90a601a49 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -11,7 +11,7 @@ namespace ts.JsDoc { "borrows", "callback", "class", - "classDesc", + "classdesc", "constant", "constructor", "constructs", @@ -28,16 +28,16 @@ namespace ts.JsDoc { "external", "field", "file", - "fileOverview", + "fileoverview", "fires", "function", "generator", "global", - "hideConstructor", + "hideconstructor", "host", "ignore", "implements", - "inheritDoc", + "inheritdoc", "inner", "instance", "interface", @@ -46,7 +46,7 @@ namespace ts.JsDoc { "license", "listens", "member", - "memberOf", + "memberof", "method", "mixes", "module", diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 2f928f52c7b..b4c7c5a2c24 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -133,7 +133,7 @@ namespace ts.NavigationBar { /** Call after calling `startNode` and adding children to it. */ function endNode(): void { if (parent.children) { - mergeChildren(parent.children); + mergeChildren(parent.children, parent); sortChildren(parent.children); } parent = parentsStack.pop()!; @@ -304,7 +304,7 @@ namespace ts.NavigationBar { } /** Merge declarations of the same kind. */ - function mergeChildren(children: NavigationBarNode[]): void { + function mergeChildren(children: NavigationBarNode[], node: NavigationBarNode): void { const nameToItems = createMap(); filterMutate(children, child => { const declName = getNameOfDeclaration(child.node); @@ -322,7 +322,7 @@ namespace ts.NavigationBar { if (itemsWithSameName instanceof Array) { for (const itemWithSameName of itemsWithSameName) { - if (tryMerge(itemWithSameName, child)) { + if (tryMerge(itemWithSameName, child, node)) { return false; } } @@ -331,7 +331,7 @@ namespace ts.NavigationBar { } else { const itemWithSameName = itemsWithSameName; - if (tryMerge(itemWithSameName, child)) { + if (tryMerge(itemWithSameName, child, node)) { return false; } nameToItems.set(name, [itemWithSameName, child]); @@ -340,8 +340,8 @@ namespace ts.NavigationBar { }); } - function tryMerge(a: NavigationBarNode, b: NavigationBarNode): boolean { - if (shouldReallyMerge(a.node, b.node)) { + function tryMerge(a: NavigationBarNode, b: NavigationBarNode, parent: NavigationBarNode): boolean { + if (shouldReallyMerge(a.node, b.node, parent)) { merge(a, b); return true; } @@ -349,8 +349,8 @@ namespace ts.NavigationBar { } /** a and b have the same name, but they may not be mergeable. */ - function shouldReallyMerge(a: Node, b: Node): boolean { - if (a.kind !== b.kind) { + function shouldReallyMerge(a: Node, b: Node, parent: NavigationBarNode): boolean { + if (a.kind !== b.kind || a.parent !== b.parent && !(isOwnChild(a, parent) && isOwnChild(b, parent))) { return false; } switch (a.kind) { @@ -366,6 +366,13 @@ namespace ts.NavigationBar { } } + // We want to merge own children like `I` in in `module A { interface I {} } module A { interface I {} }` + // We don't want to merge unrelated children like `m` in `const o = { a: { m() {} }, b: { m() {} } };` + function isOwnChild(n: Node, parent: NavigationBarNode): boolean { + const par = isModuleBlock(n.parent) ? n.parent.parent : n.parent; + return par === parent.node || contains(parent.additionalNodes, par); + } + // We use 1 NavNode to represent 'A.B.C', but there are multiple source nodes. // Only merge module nodes that have the same chain. Don't merge 'A.B.C' with 'A'! function areSameModule(a: ModuleDeclaration, b: ModuleDeclaration): boolean { @@ -383,7 +390,7 @@ namespace ts.NavigationBar { target.children = concatenate(target.children, source.children); if (target.children) { - mergeChildren(target.children); + mergeChildren(target.children, target); sortChildren(target.children); } } diff --git a/src/testRunner/unittests/tsserverProjectSystem.ts b/src/testRunner/unittests/tsserverProjectSystem.ts index 00cbda97151..ff5ee24bf5d 100644 --- a/src/testRunner/unittests/tsserverProjectSystem.ts +++ b/src/testRunner/unittests/tsserverProjectSystem.ts @@ -515,6 +515,10 @@ namespace ts.projectSystem { return session.executeCommand(makeSessionRequest(command, args)).response as TResponse["body"]; } + export function executeSessionRequestNoResponse(session: server.Session, command: TRequest["command"], args: TRequest["arguments"]): void { + session.executeCommand(makeSessionRequest(command, args)); + } + export function openFilesForSession(files: ReadonlyArray, session: server.Session): void { for (const file of files) { session.executeCommand(makeSessionRequest(CommandNames.Open, @@ -9256,6 +9260,50 @@ export function Test2() { }); }); + describe("Untitled files", () => { + it("Can convert positions to locations", () => { + const aTs: File = { path: "/proj/a.ts", content: "" }; + const tsconfig: File = { path: "/proj/tsconfig.json", content: "{}" }; + const session = createSession(createServerHost([aTs, tsconfig])); + + openFilesForSession([aTs], session); + + const untitledFile = "untitled:^Untitled-1"; + executeSessionRequestNoResponse(session, protocol.CommandTypes.Open, { + file: untitledFile, + fileContent: "let foo = 1;\nfooo/**/", + scriptKindName: "TS", + projectRootPath: "/proj", + }); + + const response = executeSessionRequest(session, protocol.CommandTypes.GetCodeFixes, { + file: untitledFile, + startLine: 2, + startOffset: 1, + endLine: 2, + endOffset: 5, + errorCodes: [Diagnostics.Cannot_find_name_0_Did_you_mean_1.code], + }); + assert.deepEqual | undefined>(response, [ + { + description: "Change spelling to 'foo'", + fixAllDescription: "Fix all detected spelling errors", + fixId: "fixSpelling", + fixName: "spelling", + changes: [{ + fileName: untitledFile, + textChanges: [{ + start: { line: 2, offset: 1 }, + end: { line: 2, offset: 5 }, + newText: "foo", + }], + }], + commands: undefined, + }, + ]); + }); + }); + function makeReferenceItem(file: File, isDefinition: boolean, text: string, lineText: string, options?: SpanFromSubstringOptions): protocol.ReferencesResponseItem { return { ...protocolFileSpanFromSubstring(file, text, options), diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 601e18578d1..fce185d4be2 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -14,7 +14,7 @@ and limitations under the License. ***************************************************************************** */ declare namespace ts { - const versionMajorMinor = "3.0"; + const versionMajorMinor = "3.1"; /** The version of the TypeScript compiler release */ const version: string; } @@ -545,7 +545,7 @@ declare namespace ts { } interface TypeParameterDeclaration extends NamedDeclaration { kind: SyntaxKind.TypeParameter; - parent: DeclarationWithTypeParameters | InferTypeNode; + parent: DeclarationWithTypeParameterChildren | InferTypeNode; name: Identifier; constraint?: TypeNode; default?: TypeNode; @@ -1317,7 +1317,8 @@ declare namespace ts { block: Block; } type ObjectTypeDeclaration = ClassLikeDeclaration | InterfaceDeclaration | TypeLiteralNode; - type DeclarationWithTypeParameters = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag | JSDocTypedefTag | JSDocCallbackTag | JSDocSignature; + type DeclarationWithTypeParameters = DeclarationWithTypeParameterChildren | JSDocTypedefTag | JSDocCallbackTag | JSDocSignature; + type DeclarationWithTypeParameterChildren = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag; interface ClassLikeDeclarationBase extends NamedDeclaration, JSDocContainer { kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression; name?: Identifier; @@ -2480,6 +2481,7 @@ declare namespace ts { strictFunctionTypes?: boolean; strictNullChecks?: boolean; strictPropertyInitialization?: boolean; + stripInternal?: boolean; suppressExcessPropertyErrors?: boolean; suppressImplicitAnyIndexErrors?: boolean; target?: ScriptTarget; @@ -8893,8 +8895,6 @@ declare namespace ts.server { private mapCodeFixAction; private mapTextChangesToCodeEdits; private mapTextChangeToCodeEdit; - private mapTextChangeToCodeEditUsingScriptInfoOrConfigFile; - private normalizePath; private convertTextChangeToCodeEdit; private getBraceMatching; private getDiagnosticsForProject; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index b7602798515..84fdcdee54e 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -14,7 +14,7 @@ and limitations under the License. ***************************************************************************** */ declare namespace ts { - const versionMajorMinor = "3.0"; + const versionMajorMinor = "3.1"; /** The version of the TypeScript compiler release */ const version: string; } @@ -545,7 +545,7 @@ declare namespace ts { } interface TypeParameterDeclaration extends NamedDeclaration { kind: SyntaxKind.TypeParameter; - parent: DeclarationWithTypeParameters | InferTypeNode; + parent: DeclarationWithTypeParameterChildren | InferTypeNode; name: Identifier; constraint?: TypeNode; default?: TypeNode; @@ -1317,7 +1317,8 @@ declare namespace ts { block: Block; } type ObjectTypeDeclaration = ClassLikeDeclaration | InterfaceDeclaration | TypeLiteralNode; - type DeclarationWithTypeParameters = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag | JSDocTypedefTag | JSDocCallbackTag | JSDocSignature; + type DeclarationWithTypeParameters = DeclarationWithTypeParameterChildren | JSDocTypedefTag | JSDocCallbackTag | JSDocSignature; + type DeclarationWithTypeParameterChildren = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag; interface ClassLikeDeclarationBase extends NamedDeclaration, JSDocContainer { kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression; name?: Identifier; @@ -2480,6 +2481,7 @@ declare namespace ts { strictFunctionTypes?: boolean; strictNullChecks?: boolean; strictPropertyInitialization?: boolean; + stripInternal?: boolean; suppressExcessPropertyErrors?: boolean; suppressImplicitAnyIndexErrors?: boolean; target?: ScriptTarget; diff --git a/tests/baselines/reference/arityAndOrderCompatibility01.errors.txt b/tests/baselines/reference/arityAndOrderCompatibility01.errors.txt index 4d6fbd063ae..f30dabd5689 100644 --- a/tests/baselines/reference/arityAndOrderCompatibility01.errors.txt +++ b/tests/baselines/reference/arityAndOrderCompatibility01.errors.txt @@ -21,7 +21,7 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(25,5): error Types of property '0' are incompatible. Type 'string' is not assignable to type 'number'. tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(26,5): error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number]'. - Property 'push' is missing in type '{ 0: string; 1: number; length: 2; }'. + Property 'pop' is missing in type '{ 0: string; 1: number; length: 2; }'. tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(27,5): error TS2322: Type '[string, number]' is not assignable to type '[string]'. Types of property 'length' are incompatible. Type '2' is not assignable to type '1'. @@ -29,14 +29,14 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(28,5): error Types of property 'length' are incompatible. Type '2' is not assignable to type '1'. tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(29,5): error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[string]'. - Property 'push' is missing in type '{ 0: string; 1: number; length: 2; }'. + Property 'pop' is missing in type '{ 0: string; 1: number; length: 2; }'. tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(30,5): error TS2322: Type '[string, number]' is not assignable to type '[number, string]'. Type 'string' is not assignable to type 'number'. tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(31,5): error TS2322: Type 'StrNum' is not assignable to type '[number, string]'. Types of property '0' are incompatible. Type 'string' is not assignable to type 'number'. tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(32,5): error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number, string]'. - Property 'push' is missing in type '{ 0: string; 1: number; length: 2; }'. + Property 'pop' is missing in type '{ 0: string; 1: number; length: 2; }'. ==== tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts (19 errors) ==== @@ -102,7 +102,7 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(32,5): error var l3: [number] = z; ~~ !!! error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number]'. -!!! error TS2322: Property 'push' is missing in type '{ 0: string; 1: number; length: 2; }'. +!!! error TS2322: Property 'pop' is missing in type '{ 0: string; 1: number; length: 2; }'. var m1: [string] = x; ~~ !!! error TS2322: Type '[string, number]' is not assignable to type '[string]'. @@ -116,7 +116,7 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(32,5): error var m3: [string] = z; ~~ !!! error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[string]'. -!!! error TS2322: Property 'push' is missing in type '{ 0: string; 1: number; length: 2; }'. +!!! error TS2322: Property 'pop' is missing in type '{ 0: string; 1: number; length: 2; }'. var n1: [number, string] = x; ~~ !!! error TS2322: Type '[string, number]' is not assignable to type '[number, string]'. @@ -129,7 +129,7 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(32,5): error var n3: [number, string] = z; ~~ !!! error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number, string]'. -!!! error TS2322: Property 'push' is missing in type '{ 0: string; 1: number; length: 2; }'. +!!! error TS2322: Property 'pop' is missing in type '{ 0: string; 1: number; length: 2; }'. var o1: [string, number] = x; var o2: [string, number] = y; var o3: [string, number] = y; diff --git a/tests/baselines/reference/arrayAssignmentTest1.errors.txt b/tests/baselines/reference/arrayAssignmentTest1.errors.txt index 3cce5658c13..e07306b19b2 100644 --- a/tests/baselines/reference/arrayAssignmentTest1.errors.txt +++ b/tests/baselines/reference/arrayAssignmentTest1.errors.txt @@ -34,7 +34,7 @@ tests/cases/compiler/arrayAssignmentTest1.ts(77,1): error TS2322: Type 'I1[]' is Type 'I1' is not assignable to type 'C3'. Property 'CM3M1' is missing in type 'I1'. tests/cases/compiler/arrayAssignmentTest1.ts(79,1): error TS2322: Type '() => C1' is not assignable to type 'any[]'. - Property 'push' is missing in type '() => C1'. + Property 'pop' is missing in type '() => C1'. tests/cases/compiler/arrayAssignmentTest1.ts(80,1): error TS2322: Type '{ one: number; }' is not assignable to type 'any[]'. Property 'length' is missing in type '{ one: number; }'. tests/cases/compiler/arrayAssignmentTest1.ts(82,1): error TS2322: Type 'C1' is not assignable to type 'any[]'. @@ -177,7 +177,7 @@ tests/cases/compiler/arrayAssignmentTest1.ts(85,1): error TS2322: Type 'I1' is n arr_any = f1; // should be an error - is ~~~~~~~ !!! error TS2322: Type '() => C1' is not assignable to type 'any[]'. -!!! error TS2322: Property 'push' is missing in type '() => C1'. +!!! error TS2322: Property 'pop' is missing in type '() => C1'. arr_any = o1; // should be an error - is ~~~~~~~ !!! error TS2322: Type '{ one: number; }' is not assignable to type 'any[]'. diff --git a/tests/baselines/reference/arrayAssignmentTest2.errors.txt b/tests/baselines/reference/arrayAssignmentTest2.errors.txt index a2cc6b3b954..eca2f8ad6f5 100644 --- a/tests/baselines/reference/arrayAssignmentTest2.errors.txt +++ b/tests/baselines/reference/arrayAssignmentTest2.errors.txt @@ -8,9 +8,9 @@ tests/cases/compiler/arrayAssignmentTest2.ts(49,1): error TS2322: Type 'I1[]' is Type 'I1' is not assignable to type 'C3'. Property 'CM3M1' is missing in type 'I1'. tests/cases/compiler/arrayAssignmentTest2.ts(51,1): error TS2322: Type '() => C1' is not assignable to type 'any[]'. - Property 'push' is missing in type '() => C1'. + Property 'pop' is missing in type '() => C1'. tests/cases/compiler/arrayAssignmentTest2.ts(52,1): error TS2322: Type '() => any' is not assignable to type 'any[]'. - Property 'push' is missing in type '() => any'. + Property 'pop' is missing in type '() => any'. tests/cases/compiler/arrayAssignmentTest2.ts(53,1): error TS2322: Type '{ one: number; }' is not assignable to type 'any[]'. Property 'length' is missing in type '{ one: number; }'. tests/cases/compiler/arrayAssignmentTest2.ts(55,1): error TS2322: Type 'C1' is not assignable to type 'any[]'. @@ -89,11 +89,11 @@ tests/cases/compiler/arrayAssignmentTest2.ts(58,1): error TS2322: Type 'I1' is n arr_any = f1; // should be an error - is ~~~~~~~ !!! error TS2322: Type '() => C1' is not assignable to type 'any[]'. -!!! error TS2322: Property 'push' is missing in type '() => C1'. +!!! error TS2322: Property 'pop' is missing in type '() => C1'. arr_any = function () { return null;} // should be an error - is ~~~~~~~ !!! error TS2322: Type '() => any' is not assignable to type 'any[]'. -!!! error TS2322: Property 'push' is missing in type '() => any'. +!!! error TS2322: Property 'pop' is missing in type '() => any'. arr_any = o1; // should be an error - is ~~~~~~~ !!! error TS2322: Type '{ one: number; }' is not assignable to type 'any[]'. diff --git a/tests/baselines/reference/arrayAssignmentTest4.errors.txt b/tests/baselines/reference/arrayAssignmentTest4.errors.txt index 0fb8112aa92..2546c6abf04 100644 --- a/tests/baselines/reference/arrayAssignmentTest4.errors.txt +++ b/tests/baselines/reference/arrayAssignmentTest4.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/arrayAssignmentTest4.ts(22,1): error TS2322: Type '() => any' is not assignable to type 'any[]'. - Property 'push' is missing in type '() => any'. + Property 'pop' is missing in type '() => any'. tests/cases/compiler/arrayAssignmentTest4.ts(23,1): error TS2322: Type 'C3' is not assignable to type 'any[]'. Property 'length' is missing in type 'C3'. @@ -29,7 +29,7 @@ tests/cases/compiler/arrayAssignmentTest4.ts(23,1): error TS2322: Type 'C3' is n arr_any = function () { return null;} // should be an error - is ~~~~~~~ !!! error TS2322: Type '() => any' is not assignable to type 'any[]'. -!!! error TS2322: Property 'push' is missing in type '() => any'. +!!! error TS2322: Property 'pop' is missing in type '() => any'. arr_any = c3; // should be an error - is ~~~~~~~ !!! error TS2322: Type 'C3' is not assignable to type 'any[]'. diff --git a/tests/baselines/reference/arrayLiterals3.errors.txt b/tests/baselines/reference/arrayLiterals3.errors.txt index 329c9061e0d..d1c99742a27 100644 --- a/tests/baselines/reference/arrayLiterals3.errors.txt +++ b/tests/baselines/reference/arrayLiterals3.errors.txt @@ -11,12 +11,10 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(32,5): error tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(33,5): error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'. Property '0' is missing in type 'number[]'. tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'. - Types of property 'push' are incompatible. - Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'. - Types of parameters 'items' and 'items' are incompatible. - Type 'Number' is not assignable to type 'string | number'. - Type 'Number' is not assignable to type 'number'. - 'number' is a primitive, but 'Number' is a wrapper object. Prefer using 'number' when possible. + Types of property 'pop' are incompatible. + Type '() => string | number' is not assignable to type '() => Number'. + Type 'string | number' is not assignable to type 'Number'. + Type 'string' is not assignable to type 'Number'. ==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts (8 errors) ==== @@ -75,10 +73,8 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error var c2: myArray = [...temp1, ...temp]; // Error cannot assign (number|string)[] to number[] ~~ !!! error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'. -!!! error TS2322: Types of property 'push' are incompatible. -!!! error TS2322: Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'. -!!! error TS2322: Types of parameters 'items' and 'items' are incompatible. -!!! error TS2322: Type 'Number' is not assignable to type 'string | number'. -!!! error TS2322: Type 'Number' is not assignable to type 'number'. -!!! error TS2322: 'number' is a primitive, but 'Number' is a wrapper object. Prefer using 'number' when possible. +!!! error TS2322: Types of property 'pop' are incompatible. +!!! error TS2322: Type '() => string | number' is not assignable to type '() => Number'. +!!! error TS2322: Type 'string | number' is not assignable to type 'Number'. +!!! error TS2322: Type 'string' is not assignable to type 'Number'. \ No newline at end of file diff --git a/tests/baselines/reference/chainedPrototypeAssignment.types b/tests/baselines/reference/chainedPrototypeAssignment.types index f0d9cc972ef..a893ae63022 100644 --- a/tests/baselines/reference/chainedPrototypeAssignment.types +++ b/tests/baselines/reference/chainedPrototypeAssignment.types @@ -86,9 +86,9 @@ A.prototype = B.prototype = { >A : typeof A >prototype : { [x: string]: any; m(n: number): number; } >B.prototype = { /** @param {number} n */ m(n) { return n + 1 }} : { [x: string]: any; m(n: number): number; } ->B.prototype : { [x: string]: any; } +>B.prototype : { [x: string]: any; m(n: number): number; } >B : typeof B ->prototype : { [x: string]: any; } +>prototype : { [x: string]: any; m(n: number): number; } >{ /** @param {number} n */ m(n) { return n + 1 }} : { [x: string]: any; m(n: number): number; } /** @param {number} n */ diff --git a/tests/baselines/reference/contextualTypedSpecialAssignment.errors.txt b/tests/baselines/reference/contextualTypedSpecialAssignment.errors.txt index e918ff187ae..c5851c46147 100644 --- a/tests/baselines/reference/contextualTypedSpecialAssignment.errors.txt +++ b/tests/baselines/reference/contextualTypedSpecialAssignment.errors.txt @@ -1,9 +1,8 @@ tests/cases/conformance/salsa/mod.js(5,7): error TS7006: Parameter 'n' implicitly has an 'any' type. tests/cases/conformance/salsa/test.js(52,7): error TS7006: Parameter 'n' implicitly has an 'any' type. -tests/cases/conformance/salsa/test.js(70,7): error TS7006: Parameter 'n' implicitly has an 'any' type. -==== tests/cases/conformance/salsa/test.js (2 errors) ==== +==== tests/cases/conformance/salsa/test.js (1 errors) ==== /** @typedef {{ status: 'done' m(n: number): void @@ -76,13 +75,11 @@ tests/cases/conformance/salsa/test.js(70,7): error TS7006: Parameter 'n' implici F.prototype = { status: "done", m(n) { } - ~ -!!! error TS7006: Parameter 'n' implicitly has an 'any' type. } ==== tests/cases/conformance/salsa/mod.js (1 errors) ==== // module.exports assignment - /** @type {{ status: 'done' }} */ + /** @type {{ status: 'done', m(n: number): void }} */ module.exports = { status: "done", m(n) { } diff --git a/tests/baselines/reference/contextualTypedSpecialAssignment.symbols b/tests/baselines/reference/contextualTypedSpecialAssignment.symbols index dac01d09bcc..2a8b1650ae7 100644 --- a/tests/baselines/reference/contextualTypedSpecialAssignment.symbols +++ b/tests/baselines/reference/contextualTypedSpecialAssignment.symbols @@ -158,7 +158,7 @@ F.prototype = { === tests/cases/conformance/salsa/mod.js === // module.exports assignment -/** @type {{ status: 'done' }} */ +/** @type {{ status: 'done', m(n: number): void }} */ module.exports = { >module : Symbol(export=, Decl(mod.js, 0, 0)) >exports : Symbol(export=, Decl(mod.js, 0, 0)) diff --git a/tests/baselines/reference/contextualTypedSpecialAssignment.types b/tests/baselines/reference/contextualTypedSpecialAssignment.types index 04f32e7a6fe..5bd81e65283 100644 --- a/tests/baselines/reference/contextualTypedSpecialAssignment.types +++ b/tests/baselines/reference/contextualTypedSpecialAssignment.types @@ -172,24 +172,24 @@ function F() { } /** @type {DoneStatus} */ F.prototype = { ->F.prototype = { status: "done", m(n) { }} : { status: string; m(n: any): void; } ->F.prototype : { [x: string]: any; } +>F.prototype = { status: "done", m(n) { }} : { status: "done"; m(n: number): void; } +>F.prototype : { status: "done"; m(n: number): void; } >F : typeof F ->prototype : { [x: string]: any; } ->{ status: "done", m(n) { }} : { status: string; m(n: any): void; } +>prototype : { status: "done"; m(n: number): void; } +>{ status: "done", m(n) { }} : { status: "done"; m(n: number): void; } status: "done", ->status : string +>status : "done" >"done" : "done" m(n) { } ->m : (n: any) => void ->n : any +>m : (n: number) => void +>n : number } === tests/cases/conformance/salsa/mod.js === // module.exports assignment -/** @type {{ status: 'done' }} */ +/** @type {{ status: 'done', m(n: number): void }} */ module.exports = { >module.exports = { status: "done", m(n) { }} : { status: string; m(n: any): void; } >module.exports : any diff --git a/tests/baselines/reference/duplicateDefaultExport.errors.txt b/tests/baselines/reference/duplicateDefaultExport.errors.txt new file mode 100644 index 00000000000..e35e416ff6b --- /dev/null +++ b/tests/baselines/reference/duplicateDefaultExport.errors.txt @@ -0,0 +1,12 @@ +tests/cases/compiler/duplicateDefaultExport.ts(1,1): error TS2528: A module cannot have multiple default exports. +tests/cases/compiler/duplicateDefaultExport.ts(2,1): error TS2528: A module cannot have multiple default exports. + + +==== tests/cases/compiler/duplicateDefaultExport.ts (2 errors) ==== + export default 0; + ~~~~~~~~~~~~~~~~~ +!!! error TS2528: A module cannot have multiple default exports. + export default function() {} + ~~~~~~ +!!! error TS2528: A module cannot have multiple default exports. + \ No newline at end of file diff --git a/tests/baselines/reference/duplicateDefaultExport.js b/tests/baselines/reference/duplicateDefaultExport.js new file mode 100644 index 00000000000..af0994bb833 --- /dev/null +++ b/tests/baselines/reference/duplicateDefaultExport.js @@ -0,0 +1,11 @@ +//// [duplicateDefaultExport.ts] +export default 0; +export default function() {} + + +//// [duplicateDefaultExport.js] +"use strict"; +exports.__esModule = true; +exports["default"] = 0; +function default_1() { } +exports["default"] = default_1; diff --git a/tests/baselines/reference/duplicateDefaultExport.symbols b/tests/baselines/reference/duplicateDefaultExport.symbols new file mode 100644 index 00000000000..6f978e28e78 --- /dev/null +++ b/tests/baselines/reference/duplicateDefaultExport.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/duplicateDefaultExport.ts === +export default 0; +No type information for this code.export default function() {} +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/duplicateDefaultExport.types b/tests/baselines/reference/duplicateDefaultExport.types new file mode 100644 index 00000000000..6f978e28e78 --- /dev/null +++ b/tests/baselines/reference/duplicateDefaultExport.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/duplicateDefaultExport.ts === +export default 0; +No type information for this code.export default function() {} +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/jsdocParseHigherOrderFunction.symbols b/tests/baselines/reference/jsdocParseHigherOrderFunction.symbols new file mode 100644 index 00000000000..2876b162687 --- /dev/null +++ b/tests/baselines/reference/jsdocParseHigherOrderFunction.symbols @@ -0,0 +1,9 @@ +=== tests/cases/conformance/jsdoc/paren.js === +/** @type {function((string), function((string)): string): string} */ +var x = (s, id) => id(s) +>x : Symbol(x, Decl(paren.js, 1, 3)) +>s : Symbol(s, Decl(paren.js, 1, 9)) +>id : Symbol(id, Decl(paren.js, 1, 11)) +>id : Symbol(id, Decl(paren.js, 1, 11)) +>s : Symbol(s, Decl(paren.js, 1, 9)) + diff --git a/tests/baselines/reference/jsdocParseHigherOrderFunction.types b/tests/baselines/reference/jsdocParseHigherOrderFunction.types new file mode 100644 index 00000000000..08e4e0bc6a4 --- /dev/null +++ b/tests/baselines/reference/jsdocParseHigherOrderFunction.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/jsdoc/paren.js === +/** @type {function((string), function((string)): string): string} */ +var x = (s, id) => id(s) +>x : (arg0: string, arg1: (arg0: string) => string) => string +>(s, id) => id(s) : (s: string, id: (arg0: string) => string) => string +>s : string +>id : (arg0: string) => string +>id(s) : string +>id : (arg0: string) => string +>s : string + diff --git a/tests/baselines/reference/jsdocParseParenthesizedJSDocParameter.symbols b/tests/baselines/reference/jsdocParseParenthesizedJSDocParameter.symbols new file mode 100644 index 00000000000..b870f8b7240 --- /dev/null +++ b/tests/baselines/reference/jsdocParseParenthesizedJSDocParameter.symbols @@ -0,0 +1,9 @@ +=== tests/cases/conformance/jsdoc/paren.js === +/** @type {function((string)): string} */ +var x = s => s.toString() +>x : Symbol(x, Decl(paren.js, 1, 3)) +>s : Symbol(s, Decl(paren.js, 1, 7)) +>s.toString : Symbol(String.toString, Decl(lib.es5.d.ts, --, --)) +>s : Symbol(s, Decl(paren.js, 1, 7)) +>toString : Symbol(String.toString, Decl(lib.es5.d.ts, --, --)) + diff --git a/tests/baselines/reference/jsdocParseParenthesizedJSDocParameter.types b/tests/baselines/reference/jsdocParseParenthesizedJSDocParameter.types new file mode 100644 index 00000000000..aa5a5d477e6 --- /dev/null +++ b/tests/baselines/reference/jsdocParseParenthesizedJSDocParameter.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/jsdoc/paren.js === +/** @type {function((string)): string} */ +var x = s => s.toString() +>x : (arg0: string) => string +>s => s.toString() : (s: string) => string +>s : string +>s.toString() : string +>s.toString : () => string +>s : string +>toString : () => string + diff --git a/tests/baselines/reference/keyofAndIndexedAccess.types b/tests/baselines/reference/keyofAndIndexedAccess.types index 1a65dbb0389..0c3939df6a8 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.types +++ b/tests/baselines/reference/keyofAndIndexedAccess.types @@ -88,7 +88,7 @@ type K10 = keyof Shape; // "name" | "width" | "height" | "visible" >Shape : Shape type K11 = keyof Shape[]; // "length" | "toString" | ... ->K11 : number | "length" | "toString" | "toLocaleString" | "push" | "pop" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" +>K11 : number | "length" | "toString" | "toLocaleString" | "pop" | "push" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" >Shape : Shape type K12 = keyof Dictionary; // string @@ -108,7 +108,7 @@ type K15 = keyof E; // "toString" | "toFixed" | "toExponential" | ... >E : E type K16 = keyof [string, number]; // "0" | "1" | "length" | "toString" | ... ->K16 : number | "0" | "1" | "length" | "toString" | "toLocaleString" | "push" | "pop" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" +>K16 : number | "0" | "1" | "length" | "toString" | "toLocaleString" | "pop" | "push" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" type K17 = keyof (Shape | Item); // "name" >K17 : "name" diff --git a/tests/baselines/reference/labeledStatementWithLabel.errors.txt b/tests/baselines/reference/labeledStatementWithLabel.errors.txt new file mode 100644 index 00000000000..c7259e484ea --- /dev/null +++ b/tests/baselines/reference/labeledStatementWithLabel.errors.txt @@ -0,0 +1,23 @@ +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel.ts(11,8): error TS1235: A namespace declaration is only allowed in a namespace or module. +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel.ts(12,8): error TS1235: A namespace declaration is only allowed in a namespace or module. + + +==== tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel.ts (2 errors) ==== + label: function fn() { } + label: function* gen() { } + label: async function gen1() { } + label: enum E {} + label: interface I {} + label: class C { } + label: var a = 1; + label: let b = 1; + label: const c = 1; + + label: module M { } + ~~~~~~ +!!! error TS1235: A namespace declaration is only allowed in a namespace or module. + label: namespace N {} + ~~~~~~~~~ +!!! error TS1235: A namespace declaration is only allowed in a namespace or module. + label: type T = {} + \ No newline at end of file diff --git a/tests/baselines/reference/labeledStatementWithLabel.js b/tests/baselines/reference/labeledStatementWithLabel.js new file mode 100644 index 00000000000..4d5dc499e25 --- /dev/null +++ b/tests/baselines/reference/labeledStatementWithLabel.js @@ -0,0 +1,80 @@ +//// [labeledStatementWithLabel.ts] +label: function fn() { } +label: function* gen() { } +label: async function gen1() { } +label: enum E {} +label: interface I {} +label: class C { } +label: var a = 1; +label: let b = 1; +label: const c = 1; + +label: module M { } +label: namespace N {} +label: type T = {} + + +//// [labeledStatementWithLabel.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 = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, 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 }; + } +}; +label: function fn() { } +label: function gen() { return __generator(this, function (_a) { + return [2 /*return*/]; +}); } +label: function gen1() { + return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { + return [2 /*return*/]; + }); }); +} +label: { + var E; + (function (E) { + })(E || (E = {})); +} +label: +label: { + var C = /** @class */ (function () { + function C() { + } + return C; + }()); +} +label: var a = 1; +label: var b = 1; +label: var c = 1; +label: +label: +label: diff --git a/tests/baselines/reference/labeledStatementWithLabel.symbols b/tests/baselines/reference/labeledStatementWithLabel.symbols new file mode 100644 index 00000000000..ab019c20d51 --- /dev/null +++ b/tests/baselines/reference/labeledStatementWithLabel.symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel.ts === +label: function fn() { } +>fn : Symbol(fn, Decl(labeledStatementWithLabel.ts, 0, 6)) + +label: function* gen() { } +>gen : Symbol(gen, Decl(labeledStatementWithLabel.ts, 1, 6)) + +label: async function gen1() { } +>gen1 : Symbol(gen1, Decl(labeledStatementWithLabel.ts, 2, 6)) + +label: enum E {} +>E : Symbol(E, Decl(labeledStatementWithLabel.ts, 3, 6)) + +label: interface I {} +>I : Symbol(I, Decl(labeledStatementWithLabel.ts, 4, 6)) + +label: class C { } +>C : Symbol(C, Decl(labeledStatementWithLabel.ts, 5, 6)) + +label: var a = 1; +>a : Symbol(a, Decl(labeledStatementWithLabel.ts, 6, 10)) + +label: let b = 1; +>b : Symbol(b, Decl(labeledStatementWithLabel.ts, 7, 10)) + +label: const c = 1; +>c : Symbol(c, Decl(labeledStatementWithLabel.ts, 8, 12)) + +label: module M { } +>M : Symbol(M, Decl(labeledStatementWithLabel.ts, 10, 6)) + +label: namespace N {} +>N : Symbol(N, Decl(labeledStatementWithLabel.ts, 11, 6)) + +label: type T = {} +>T : Symbol(T, Decl(labeledStatementWithLabel.ts, 12, 6)) + diff --git a/tests/baselines/reference/labeledStatementWithLabel.types b/tests/baselines/reference/labeledStatementWithLabel.types new file mode 100644 index 00000000000..9a1c12becf5 --- /dev/null +++ b/tests/baselines/reference/labeledStatementWithLabel.types @@ -0,0 +1,52 @@ +=== tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel.ts === +label: function fn() { } +>label : any +>fn : () => void + +label: function* gen() { } +>label : any +>gen : () => IterableIterator + +label: async function gen1() { } +>label : any +>gen1 : () => Promise + +label: enum E {} +>label : any +>E : E + +label: interface I {} +>label : any +>I : I + +label: class C { } +>label : any +>C : C + +label: var a = 1; +>label : any +>a : number +>1 : 1 + +label: let b = 1; +>label : any +>b : number +>1 : 1 + +label: const c = 1; +>label : any +>c : 1 +>1 : 1 + +label: module M { } +>label : any +>M : any + +label: namespace N {} +>label : any +>N : any + +label: type T = {} +>label : any +>T : {} + diff --git a/tests/baselines/reference/labeledStatementWithLabel_es2015.errors.txt b/tests/baselines/reference/labeledStatementWithLabel_es2015.errors.txt new file mode 100644 index 00000000000..95c136b953d --- /dev/null +++ b/tests/baselines/reference/labeledStatementWithLabel_es2015.errors.txt @@ -0,0 +1,23 @@ +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_es2015.ts(11,8): error TS1235: A namespace declaration is only allowed in a namespace or module. +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_es2015.ts(12,8): error TS1235: A namespace declaration is only allowed in a namespace or module. + + +==== tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_es2015.ts (2 errors) ==== + label: function fn() { } + label: function* gen() { } + label: async function gen1() { } + label: enum E {} + label: interface I {} + label: class C { } + label: var a = 1; + label: let b = 1; + label: const c = 1; + + label: module M { } + ~~~~~~ +!!! error TS1235: A namespace declaration is only allowed in a namespace or module. + label: namespace N {} + ~~~~~~~~~ +!!! error TS1235: A namespace declaration is only allowed in a namespace or module. + label: type T = {} + \ No newline at end of file diff --git a/tests/baselines/reference/labeledStatementWithLabel_es2015.js b/tests/baselines/reference/labeledStatementWithLabel_es2015.js new file mode 100644 index 00000000000..e2eea4c53be --- /dev/null +++ b/tests/baselines/reference/labeledStatementWithLabel_es2015.js @@ -0,0 +1,44 @@ +//// [labeledStatementWithLabel_es2015.ts] +label: function fn() { } +label: function* gen() { } +label: async function gen1() { } +label: enum E {} +label: interface I {} +label: class C { } +label: var a = 1; +label: let b = 1; +label: const c = 1; + +label: module M { } +label: namespace N {} +label: type T = {} + + +//// [labeledStatementWithLabel_es2015.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()); + }); +}; +label: function fn() { } +label: function* gen() { } +label: function gen1() { + return __awaiter(this, void 0, void 0, function* () { }); +} +label: { + var E; + (function (E) { + })(E || (E = {})); +} +label: +label: class C { +} +label: var a = 1; +label: let b = 1; +label: const c = 1; +label: +label: +label: diff --git a/tests/baselines/reference/labeledStatementWithLabel_es2015.symbols b/tests/baselines/reference/labeledStatementWithLabel_es2015.symbols new file mode 100644 index 00000000000..3e776d1152b --- /dev/null +++ b/tests/baselines/reference/labeledStatementWithLabel_es2015.symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_es2015.ts === +label: function fn() { } +>fn : Symbol(fn, Decl(labeledStatementWithLabel_es2015.ts, 0, 6)) + +label: function* gen() { } +>gen : Symbol(gen, Decl(labeledStatementWithLabel_es2015.ts, 1, 6)) + +label: async function gen1() { } +>gen1 : Symbol(gen1, Decl(labeledStatementWithLabel_es2015.ts, 2, 6)) + +label: enum E {} +>E : Symbol(E, Decl(labeledStatementWithLabel_es2015.ts, 3, 6)) + +label: interface I {} +>I : Symbol(I, Decl(labeledStatementWithLabel_es2015.ts, 4, 6)) + +label: class C { } +>C : Symbol(C, Decl(labeledStatementWithLabel_es2015.ts, 5, 6)) + +label: var a = 1; +>a : Symbol(a, Decl(labeledStatementWithLabel_es2015.ts, 6, 10)) + +label: let b = 1; +>b : Symbol(b, Decl(labeledStatementWithLabel_es2015.ts, 7, 10)) + +label: const c = 1; +>c : Symbol(c, Decl(labeledStatementWithLabel_es2015.ts, 8, 12)) + +label: module M { } +>M : Symbol(M, Decl(labeledStatementWithLabel_es2015.ts, 10, 6)) + +label: namespace N {} +>N : Symbol(N, Decl(labeledStatementWithLabel_es2015.ts, 11, 6)) + +label: type T = {} +>T : Symbol(T, Decl(labeledStatementWithLabel_es2015.ts, 12, 6)) + diff --git a/tests/baselines/reference/labeledStatementWithLabel_es2015.types b/tests/baselines/reference/labeledStatementWithLabel_es2015.types new file mode 100644 index 00000000000..7f59d4f0fed --- /dev/null +++ b/tests/baselines/reference/labeledStatementWithLabel_es2015.types @@ -0,0 +1,52 @@ +=== tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_es2015.ts === +label: function fn() { } +>label : any +>fn : () => void + +label: function* gen() { } +>label : any +>gen : () => IterableIterator + +label: async function gen1() { } +>label : any +>gen1 : () => Promise + +label: enum E {} +>label : any +>E : E + +label: interface I {} +>label : any +>I : I + +label: class C { } +>label : any +>C : C + +label: var a = 1; +>label : any +>a : number +>1 : 1 + +label: let b = 1; +>label : any +>b : number +>1 : 1 + +label: const c = 1; +>label : any +>c : 1 +>1 : 1 + +label: module M { } +>label : any +>M : any + +label: namespace N {} +>label : any +>N : any + +label: type T = {} +>label : any +>T : {} + diff --git a/tests/baselines/reference/labeledStatementWithLabel_strict.errors.txt b/tests/baselines/reference/labeledStatementWithLabel_strict.errors.txt new file mode 100644 index 00000000000..863604a0836 --- /dev/null +++ b/tests/baselines/reference/labeledStatementWithLabel_strict.errors.txt @@ -0,0 +1,60 @@ +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(2,1): error TS1344: 'A label is not allowed here. +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(3,1): error TS1344: 'A label is not allowed here. +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(4,1): error TS1344: 'A label is not allowed here. +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(5,1): error TS1344: 'A label is not allowed here. +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(6,1): error TS1344: 'A label is not allowed here. +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(7,1): error TS1344: 'A label is not allowed here. +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(8,1): error TS1344: 'A label is not allowed here. +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(9,1): error TS1344: 'A label is not allowed here. +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(10,1): error TS1344: 'A label is not allowed here. +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(12,1): error TS1344: 'A label is not allowed here. +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(12,8): error TS1235: A namespace declaration is only allowed in a namespace or module. +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(13,1): error TS1344: 'A label is not allowed here. +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(13,8): error TS1235: A namespace declaration is only allowed in a namespace or module. +tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts(14,1): error TS1344: 'A label is not allowed here. + + +==== tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts (14 errors) ==== + "use strict" + label: function fn() { } + ~~~~~ +!!! error TS1344: 'A label is not allowed here. + label: function* gen() { } + ~~~~~ +!!! error TS1344: 'A label is not allowed here. + label: async function gen1() { } + ~~~~~ +!!! error TS1344: 'A label is not allowed here. + label: enum E {} + ~~~~~ +!!! error TS1344: 'A label is not allowed here. + label: interface I {} + ~~~~~ +!!! error TS1344: 'A label is not allowed here. + label: class C { } + ~~~~~ +!!! error TS1344: 'A label is not allowed here. + label: var a = 1; + ~~~~~ +!!! error TS1344: 'A label is not allowed here. + label: let b = 1; + ~~~~~ +!!! error TS1344: 'A label is not allowed here. + label: const c = 1; + ~~~~~ +!!! error TS1344: 'A label is not allowed here. + + label: module M { } + ~~~~~ +!!! error TS1344: 'A label is not allowed here. + ~~~~~~ +!!! error TS1235: A namespace declaration is only allowed in a namespace or module. + label: namespace N {} + ~~~~~ +!!! error TS1344: 'A label is not allowed here. + ~~~~~~~~~ +!!! error TS1235: A namespace declaration is only allowed in a namespace or module. + label: type T = {} + ~~~~~ +!!! error TS1344: 'A label is not allowed here. + \ No newline at end of file diff --git a/tests/baselines/reference/labeledStatementWithLabel_strict.js b/tests/baselines/reference/labeledStatementWithLabel_strict.js new file mode 100644 index 00000000000..c4ac2caed06 --- /dev/null +++ b/tests/baselines/reference/labeledStatementWithLabel_strict.js @@ -0,0 +1,46 @@ +//// [labeledStatementWithLabel_strict.ts] +"use strict" +label: function fn() { } +label: function* gen() { } +label: async function gen1() { } +label: enum E {} +label: interface I {} +label: class C { } +label: var a = 1; +label: let b = 1; +label: const c = 1; + +label: module M { } +label: namespace N {} +label: type T = {} + + +//// [labeledStatementWithLabel_strict.js] +"use strict"; +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()); + }); +}; +label: function fn() { } +label: function* gen() { } +label: function gen1() { + return __awaiter(this, void 0, void 0, function* () { }); +} +label: { + var E; + (function (E) { + })(E || (E = {})); +} +label: +label: class C { +} +label: var a = 1; +label: let b = 1; +label: const c = 1; +label: +label: +label: diff --git a/tests/baselines/reference/labeledStatementWithLabel_strict.symbols b/tests/baselines/reference/labeledStatementWithLabel_strict.symbols new file mode 100644 index 00000000000..c5a721824cc --- /dev/null +++ b/tests/baselines/reference/labeledStatementWithLabel_strict.symbols @@ -0,0 +1,38 @@ +=== tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts === +"use strict" +label: function fn() { } +>fn : Symbol(fn, Decl(labeledStatementWithLabel_strict.ts, 1, 6)) + +label: function* gen() { } +>gen : Symbol(gen, Decl(labeledStatementWithLabel_strict.ts, 2, 6)) + +label: async function gen1() { } +>gen1 : Symbol(gen1, Decl(labeledStatementWithLabel_strict.ts, 3, 6)) + +label: enum E {} +>E : Symbol(E, Decl(labeledStatementWithLabel_strict.ts, 4, 6)) + +label: interface I {} +>I : Symbol(I, Decl(labeledStatementWithLabel_strict.ts, 5, 6)) + +label: class C { } +>C : Symbol(C, Decl(labeledStatementWithLabel_strict.ts, 6, 6)) + +label: var a = 1; +>a : Symbol(a, Decl(labeledStatementWithLabel_strict.ts, 7, 10)) + +label: let b = 1; +>b : Symbol(b, Decl(labeledStatementWithLabel_strict.ts, 8, 10)) + +label: const c = 1; +>c : Symbol(c, Decl(labeledStatementWithLabel_strict.ts, 9, 12)) + +label: module M { } +>M : Symbol(M, Decl(labeledStatementWithLabel_strict.ts, 11, 6)) + +label: namespace N {} +>N : Symbol(N, Decl(labeledStatementWithLabel_strict.ts, 12, 6)) + +label: type T = {} +>T : Symbol(T, Decl(labeledStatementWithLabel_strict.ts, 13, 6)) + diff --git a/tests/baselines/reference/labeledStatementWithLabel_strict.types b/tests/baselines/reference/labeledStatementWithLabel_strict.types new file mode 100644 index 00000000000..02bce60c5b1 --- /dev/null +++ b/tests/baselines/reference/labeledStatementWithLabel_strict.types @@ -0,0 +1,55 @@ +=== tests/cases/conformance/statements/labeledStatements/labeledStatementWithLabel_strict.ts === +"use strict" +>"use strict" : "use strict" + +label: function fn() { } +>label : any +>fn : () => void + +label: function* gen() { } +>label : any +>gen : () => IterableIterator + +label: async function gen1() { } +>label : any +>gen1 : () => Promise + +label: enum E {} +>label : any +>E : E + +label: interface I {} +>label : any +>I : I + +label: class C { } +>label : any +>C : C + +label: var a = 1; +>label : any +>a : number +>1 : 1 + +label: let b = 1; +>label : any +>b : number +>1 : 1 + +label: const c = 1; +>label : any +>c : 1 +>1 : 1 + +label: module M { } +>label : any +>M : any + +label: namespace N {} +>label : any +>N : any + +label: type T = {} +>label : any +>T : {} + diff --git a/tests/baselines/reference/nestedRecursiveArraysOrObjectsError01.errors.txt b/tests/baselines/reference/nestedRecursiveArraysOrObjectsError01.errors.txt new file mode 100644 index 00000000000..138a4a84158 --- /dev/null +++ b/tests/baselines/reference/nestedRecursiveArraysOrObjectsError01.errors.txt @@ -0,0 +1,46 @@ +tests/cases/compiler/nestedRecursiveArraysOrObjectsError01.ts(10,9): error TS2322: Type '{ foo: string; jj: number; }[][][]' is not assignable to type 'Style'. + Type '{ foo: string; jj: number; }[][][]' is not assignable to type 'StyleArray'. + Types of property 'pop' are incompatible. + Type '() => { foo: string; jj: number; }[][]' is not assignable to type '() => Style'. + Type '{ foo: string; jj: number; }[][]' is not assignable to type 'Style'. + Type '{ foo: string; jj: number; }[][]' is not assignable to type 'StyleArray'. + Types of property 'pop' are incompatible. + Type '() => { foo: string; jj: number; }[]' is not assignable to type '() => Style'. + Type '{ foo: string; jj: number; }[]' is not assignable to type 'Style'. + Type '{ foo: string; jj: number; }[]' is not assignable to type 'StyleArray'. + Types of property 'pop' are incompatible. + Type '() => { foo: string; jj: number; }' is not assignable to type '() => Style'. + Type '{ foo: string; jj: number; }' is not assignable to type 'Style'. + Object literal may only specify known properties, and 'jj' does not exist in type 'Style'. + + +==== tests/cases/compiler/nestedRecursiveArraysOrObjectsError01.ts (1 errors) ==== + type Style = StyleBase | StyleArray; + interface StyleArray extends Array